mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
df42058237fdc0420116529a257f9550bce3312f
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 ```
Description
Languages
JavaScript
67.1%
TypeScript
29.4%
HTML
1.5%
CSS
1.1%
C++
0.6%
Other
0.2%