react/compiler/packages
mofeiZ f457d0b4c6
[compiler][ez] Only fail gating hoisting check for referenced identifiers (#32596)
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
```
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32596).
* __->__ #32596
* #32595
* #32594
* #32593
* #32522
* #32521
2025-03-13 12:10:22 -04:00
..
babel-plugin-react-compiler [compiler][ez] Only fail gating hoisting check for referenced identifiers (#32596) 2025-03-13 12:10:22 -04:00
eslint-plugin-react-compiler [ez] Run Prettier on eslint-plugin-react-compiler/src/types (#32590) 2025-03-12 19:12:22 -04:00
make-read-only-util [compiler] Migrate compiler packages to tsup (#32550) 2025-03-07 16:41:55 -05:00
react-compiler-healthcheck fix: clarify which mobx libs are not compatible with compiler (#32570) 2025-03-13 11:46:26 -04:00
react-compiler-runtime [rcr] Fix incorrect output platform (#32569) 2025-03-11 10:41:48 -04:00
react-forgive [forgive][ez] Ignore test file (#32477) 2025-02-25 19:09:21 -05:00
snap [compiler][ez] Move compiler gating tests (#32595) 2025-03-13 12:06:48 -04:00