fix(es/transforms): rewrite class references in non-static members#11772
fix(es/transforms): rewrite class references in non-static members#11772
Conversation
🦋 Changeset detectedLatest commit: 90e1c27 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 |
Binary Sizes
Commit: 65ebca5 |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Fixes a decorators (2022-03) transformation bug where class self-references inside non-static members were not rewritten when static members are lifted, causing instance methods to read the pre-decoration class binding and observe undefined instead of the decorated class’s static fields.
Changes:
- Rewrite class self-references inside all class methods/private methods (not just static ones) during the lifted-static-member path of the decorator transform.
- Add a regression fixture for issue #11744, covering the instance-method
ScrollView.scrollIntervalaccess case.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/swc_ecma_transforms_proposal/src/decorator_impl.rs | Extends replace_ident rewriting to non-static Method/PrivateMethod members so instance methods refer to the decorated class binding. |
| crates/swc/tests/fixture/issues-11xxx/11744/input/index.js | Adds minimal repro input for #11744. |
| crates/swc/tests/fixture/issues-11xxx/11744/input/.swcrc | Configures decorators 2022-03 transform for the fixture. |
| crates/swc/tests/fixture/issues-11xxx/11744/output/index.js | Updates expected output to ensure instance method references rewritten to _ScrollView. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 13d5b93204
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ClassMember::Method(method) => { | ||
| replace_ident(method, c.ident.to_id(), &new_class_name); |
There was a problem hiding this comment.
Skip renaming class refs in instance method keys
Removing the is_static guard here makes replace_ident run on the entire ClassMethod, which includes computed keys. For decorated class declarations with static members, an instance method like [@dec class C { static x = 1; [C]() {} }] now has its key rewritten to [_C], but _C is assigned later in the decorator init flow, so the computed key evaluates to undefined instead of the class reference. This regression is introduced by broadening the match from static-only methods to all methods.
Useful? React with 👍 / 👎.
PR Review: fix(es/transforms): rewrite class references in non-static membersSummaryClean, minimal fix for #11744. The bug was that FeedbackCode change — Looks correct. The other arms in the same Test coverage — The fixture test reproduces the exact scenario from the issue (decorated class with a static field referenced from an instance method). The expected output correctly shows Minor nit — The input file No concerns on performance or security — the change only removes a guard condition, so it's strictly additive in what gets processed and the operation ( Overall this is a well-scoped, correct fix. LGTM. |
Description:
Decorated class declarations with lifted static members failed to rewrite class self-references inside instance methods. As a result, instance methods could still read the pre-decoration class binding and observe undefined instead of the decorated class’s static fields.
Related issue (if exists):
fixes #11744