Skip to content

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Sep 15, 2025

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.

Copy link
Member Author

Dunqing commented Sep 15, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler C-bug Category - Bug labels Sep 15, 2025
@Dunqing Dunqing changed the title fix(transformer): handle declare fields in class properties transformation fix(transformer/class-propeties): handle declare fields in class properties transformation Sep 15, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Sep 15, 2025

CodSpeed Instrumentation Performance Report

Merging #13766 will not alter performance

Comparing 09-15-fix_transformer_handle_declare_fields_in_class_properties_transformation (5ec9209) with main (7e0d736)

Summary

✅ 37 untouched

@Dunqing Dunqing changed the base branch from main to graphite-base/13766 September 15, 2025 14:33
@Dunqing Dunqing force-pushed the 09-15-fix_transformer_handle_declare_fields_in_class_properties_transformation branch from b3ec73b to 15962c2 Compare September 15, 2025 14:34
@Dunqing Dunqing force-pushed the graphite-base/13766 branch from 369287a to f7381ba Compare September 15, 2025 14:34
@Dunqing Dunqing changed the base branch from graphite-base/13766 to 09-15-fix_transformer_typescript_panics_when_declare_property_and_definite_property_with_initializer September 15, 2025 14:34
@Dunqing Dunqing marked this pull request as ready for review September 15, 2025 14:40
@Dunqing Dunqing changed the title fix(transformer/class-propeties): handle declare fields in class properties transformation fix(transformer/class-properties): don't transform properties that have declare modifier Sep 15, 2025
@graphite-app graphite-app bot changed the base branch from 09-15-fix_transformer_typescript_panics_when_declare_property_and_definite_property_with_initializer to graphite-base/13766 September 16, 2025 12:56
graphite-app bot pushed a commit that referenced this pull request Sep 16, 2025
… `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;
}
```
@graphite-app graphite-app bot force-pushed the graphite-base/13766 branch from f7381ba to 7d0b8a1 Compare September 16, 2025 13:03
@graphite-app graphite-app bot force-pushed the 09-15-fix_transformer_handle_declare_fields_in_class_properties_transformation branch from 15962c2 to d3098e1 Compare September 16, 2025 13:03
@graphite-app graphite-app bot changed the base branch from graphite-base/13766 to main September 16, 2025 13:04
@graphite-app graphite-app bot force-pushed the 09-15-fix_transformer_handle_declare_fields_in_class_properties_transformation branch from d3098e1 to c10949d Compare September 16, 2025 13:04
Copilot AI review requested due to automatic review settings September 16, 2025 13:49
Copy link
Contributor

Copilot AI left a 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 declare modifier during the enter phase
  • Ensures declare fields 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.

Copy link
Member

@overlookmotel overlookmotel left a 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.

@Dunqing Dunqing force-pushed the 09-15-fix_transformer_handle_declare_fields_in_class_properties_transformation branch from 349afdf to 71fd874 Compare September 17, 2025 14:02
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Sep 17, 2025
Copy link
Member Author

Dunqing commented Sep 17, 2025

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.
@graphite-app graphite-app bot force-pushed the 09-15-fix_transformer_handle_declare_fields_in_class_properties_transformation branch from 71fd874 to 5ec9209 Compare September 17, 2025 14:50
@graphite-app graphite-app bot merged commit 5ec9209 into main Sep 17, 2025
26 checks passed
@graphite-app graphite-app bot deleted the 09-15-fix_transformer_handle_declare_fields_in_class_properties_transformation branch September 17, 2025 14:55
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transfomer: When the target is earlier than 2022, class declare fields are not transformed correctly

3 participants