-
-
Notifications
You must be signed in to change notification settings - Fork 720
fix(transformer/class-properties): don't transform properties that have declare modifier
#13766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(transformer/class-properties): don't transform properties that have declare modifier
#13766
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #13766 will not alter performanceComparing Summary
|
b3ec73b to
15962c2
Compare
369287a to
f7381ba
Compare
declare modifier
… `definite` property that has initializer (#13785) Remove two incorrect assertions, which cause panic in the #13766. The `declare` property with an initializer is allowed in [TypeScript](https://www.typescriptlang.org/play/?useDefineForClassFields=true&target=7&noCheck=false&stripInternal=true&ts=5.9.2#code/MYGwhgzhAEAiCmowCd4FEAeYC2AHE80A3gFDTQAmi4q0qYFA9gHYgCe0ARitALzQAiAC7wIQgQG4ylaikL0mrDgDNGjPtACMUgL4kSSKHHjKAls1MjMOfIVLk68Bi3ZcUAQg3DR4qQ4UuKmqe-NokekA) ```ts class DeclareExample { declare readonly bar = "test"; declare readonly foo = 1; } ``` The `!` (definite) with an initializer isn't allowed in [TypeScript](https://www.typescriptlang.org/play/?useDefineForClassFields=true&target=7&noCheck=false&stripInternal=true&ts=5.9.2#code/MYGwhgzhAEAiCmowCd4FEAeYC2AHE80A3gFDTQAmi4q0qYFA9gHYgCe0ARitALzQAiAC7wIQgQG4ylaikL0mrDgDNGjPtACMUgL5A), but this is a recoverable error, so the AST can have such. ```ts class DefiniteExample { readonly bar! = "test"; readonly foo! = 1; } ```
f7381ba to
7d0b8a1
Compare
15962c2 to
d3098e1
Compare
d3098e1 to
c10949d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where TypeScript declare fields were incorrectly being transformed by the class properties transformer instead of being properly ignored, causing inheritance problems where child declare fields would interfere with parent class property initialization.
- Adds checks to skip transformation of properties with the
declaremodifier during the enter phase - Ensures
declarefields are properly ignored in both static and instance property handling - Adds comprehensive test coverage for both regular and computed key scenarios
Reviewed Changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_transformer/src/es2022/class_properties/mod.rs | Adds declare modifier checks in property enter/exit handlers |
| crates/oxc_transformer/src/es2022/class_properties/class.rs | Implements core logic to skip declare properties during transformation |
| tasks/transform_conformance/tests/.../declare-fields/input.ts | Test case for basic declare field inheritance scenario |
| tasks/transform_conformance/tests/.../declare-fields/output.js | Expected output showing proper inheritance behavior |
| tasks/transform_conformance/tests/.../declare-fields/exec.ts | Executable test variant |
| tasks/transform_conformance/tests/.../declare-computed-keys/input.ts | Test case for declare fields with computed keys |
| tasks/transform_conformance/tests/.../declare-computed-keys/output.js | Expected output for computed key scenarios |
| tasks/transform_conformance/snapshots/oxc_exec.snap.md | Updated test pass count |
| tasks/transform_conformance/snapshots/oxc.snap.md | Updated conformance test results |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
overlookmotel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a couple of trivial commits with changes to comments. Hope that's OK.
Please see comment below. If you prefer to address that in follow-up, feel free to merge this PR as is, because I think the code is redundant anyway.
I just realised that we don't debug assert that classes_stack is emptied in exit_program as we should. I think that'd be a good idea, to make sure the stack doesn't get out of sync due to skipping push or pop due to declare == true.
349afdf to
71fd874
Compare
Merge activity
|
…ve `declare` modifier (#13766) * Fixes #13733 Fixes the issue where `declare` fields were incorrectly transformed instead of being removed, causing inheritance issues where child `declare` fields would interfere with parent class property initialization. Only in the `enter_*` phase do we have to skip the `declare` field; in the exit phase, the `declare` fields have already been removed in the `TypeScript` plugin.
71fd874 to
5ec9209
Compare

Fixes the issue where
declarefields were incorrectly transformed instead of being removed, causing inheritance issues where childdeclarefields would interfere with parent class property initialization.Only in the
enter_*phase do we have to skip thedeclarefield; in the exit phase, thedeclarefields have already been removed in theTypeScriptplugin.