Commit Graph

3 Commits

Author SHA1 Message Date
Joseph Savona
00a58cdab1 Option to validate output with ESLint
Adds a new compiler option `validateNoUseBeforeDefine`, which enables a 
post-codegen pass to validate that there are no usages of values before they are 
defined (which causes a ReferenceError at runtime). This can occur when a value 
is accessed when its in the TDZ (temporary dead zone), after the hoisted 
_declaration_ but before the variable is defined: 

```javascript 

function foo() { 

x; // x is in the TDX here: the binding from the subsequent statement is 
hoisted, but x is not yet defined. 

let x; 

} 

``` 

* The validation is off by default, but enabled in transform-test 

* The validation crashes compilation, rather than bailout, because the code has 
already been mangled and we can't roll back at the point the validation runs. 

* The validator uses ESLint's no-use-before-define rule by printing the program 
to source and then configuring ESLint to use Hermes parser. 

* transform-test now supports tests prefixed with "error." to indicate tests for 
which compilation is expected to crash (not just bailout), and the expect file 
includes the error message.
2022-10-19 13:00:47 -07:00
Jan Kassens
b1006e12cd Invariant for use before definition of reactive values (#662) 2022-10-13 16:17:39 -04:00
Xuan Huang (黄玄)
a33c0b897c Initial commit 2024-03-25 10:39:47 +00:00