[compiler][ez] Only fail gating hoisting check for referenced identifiers
Reduce false positive bailouts by using the same `isReferencedIdentifier` logic that the compiler also uses for determining context variables and a function's own hoisted declarations. Details: Previously, we counted every babel identifier as a reference. This is problematic because babel counts most string symbols as an identifier. ```js print(x); // x is an identifier as expected obj.x // x is.. also an identifier here {x: 2} // x is also an identifier here ``` This PR adds a check for `isReferencedIdentifier`. Note that only non-lval references pass this check. This should be fine as we don't need to hoist function declarations before writes to the same lvalue (which should error in strict mode anyways) ```js print(x); // isReferencedIdentifier(x) -> true obj.x // isReferencedIdentifier(x) -> false {x: 2} // isReferencedIdentifier(x) -> false x = 2 // isReferencedIdentifier(x) -> false ```
Showing
- compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts 1 addition, 1 deletion...ges/babel-plugin-react-compiler/src/Entrypoint/Program.ts
- compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-nonreferenced-identifier-collision.expect.md 60 additions, 0 deletions...ating/gating-nonreferenced-identifier-collision.expect.md
- compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-nonreferenced-identifier-collision.js 16 additions, 0 deletions...piler/gating/gating-nonreferenced-identifier-collision.js
Please register or sign in to comment