dillon1000/react
Commit
Browse files 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.Changed paths10 files
First-parent comparisoncompiler/forget/package.json ModifiedA compiler/forget/src/BackEnd/PostCodegenValidator.ts AddedM compiler/forget/src/BackEnd/index.ts ModifiedM compiler/forget/src/CompilerDriver.ts ModifiedM compiler/forget/src/CompilerOptions.ts ModifiedM compiler/forget/src/Pass.ts ModifiedM compiler/forget/src/__tests__/CompilerOptions-test.ts ModifiedA compiler/forget/src/__tests__/test-utils/validateNoUseBeforeDefine.ts AddedM compiler/forget/src/__tests__/transform-test.ts ModifiedM compiler/forget/yarn.lock ModifiedPatch
Files changed
Rendering syntax-highlighted changes…