dillon1000/react
Commit
Browse files Fix variable-resolution hoisting issues
Fixes one category of bugs with const hoisting. The algorithm finds all consts that need to be hoisted, then looks through the statements of a block to find the first statement which references that const, delaying the emission of the HoistedConst instruction until its actually used. To determine if a statement references a const we find every identifier in the statement and check if its binding is one of the hoisted bindings. There's a very small bug here: when we resolve the binding of each identifier, we need to resolve it in its own scope. We're currently resolving these identifiers agains the outer block statement's scope, which can cause us to misattribute identifiers when there is shadowing: ``` const items = props.items.map(x => x); // we scan this statement, resolve 'x' in the block statement scope, and mis-attribute it to the outer x. const x = 42; // (1) this x is a candidate for hoisting, so the binding is in the set of hoisted consts ```
Changed paths10 files
First-parent comparisoncompiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts ModifiedD compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting.expect.md DeletedD compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo.repro-hoisting-variable-collision.expect.md DeletedD compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo.repro-hoisting-variable-collision.js DeletedR compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting-nested-block-statements.expect.md →compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/hoisting-nested-block-statements.expect.md RenamedR compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting-nested-block-statements.js →compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/hoisting-nested-block-statements.js RenamedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-hoisting-variable-collision.expect.md AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-hoisting-variable-collision.js AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-hoisting.expect.md AddedR compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.bug-hoisting.js →compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-hoisting.js RenamedPatch
Files changed
Rendering syntax-highlighted changes…