fix(es/react-compiler): Scope ClassStaticBlock and TsModuleBlock as var boundaries#11943
Conversation
Merging this PR will degrade performance by 2.13%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: accc1ad2e7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
🦋 Changeset detectedLatest commit: 21230c1 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1b866bfd1a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Description:
This PR fixes scope analysis edge cases in the React Compiler where
vardeclarations and TypeScript constructs were incorrectly hoisted or leaked across scope boundaries.Design Notes:
declareandglobalare TypeScript type-system annotations that don't affect runtime emission, yet they still create declarations that downstream code can reference. The analyzer must walk their bodies normally and create bindings accordingly, rather than skipping traversal.Changes:
Class static blocks as
varboundariesvardeclarations insidestatic { }blocks are now scoped to the block itself, matching ECMAScript semantics, instead of leaking into the enclosing function.TypeScript namespace / module scopes
namespaceandmodulebodies now create properTsModuleBlockscopes. Their members are no longer incorrectly hoisted to the Program scope.Consistent binding for
declare enumdeclare enumis now registered as a local binding so references resolve correctly.Refactoring
Renamed
enclosing_function_scope()→enclosing_var_scope()and updatedScopeFlagsdefinitions to make scope-kind checks clearer.Known Limitations:
TypeScript namespace merging is not yet supported. The scope collector treats each
namespace/moduledeclaration as an isolated lexical scope. Exported members in one block are not visible to later merged blocks, and they are modeled as plain local bindings. This is a similar issue described in #11607.BREAKING CHANGE:
Related issue (if exists):