Skip to content

fix(transformer/legacy-decorator): static class fields cannot be accessed in static field initializer when class-properties plugin is not enabled#11143

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-19-fix_transformer_legacy-decorator_static_class_fields_cannot_be_accessed_in_static_field_initializer_when_class-properties_plugin_is_not_enabled
May 19, 2025
Merged

fix(transformer/legacy-decorator): static class fields cannot be accessed in static field initializer when class-properties plugin is not enabled#11143
graphite-app[bot] merged 1 commit intomainfrom
05-19-fix_transformer_legacy-decorator_static_class_fields_cannot_be_accessed_in_static_field_initializer_when_class-properties_plugin_is_not_enabled

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented May 19, 2025

close: #11111

This is the missing part we were ported from TypeScript.

Copy link
Member Author

Dunqing commented May 19, 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.

@codspeed-hq
Copy link

codspeed-hq bot commented May 19, 2025

CodSpeed Instrumentation Performance Report

Merging #11143 will not alter performance

Comparing 05-19-fix_transformer_legacy-decorator_static_class_fields_cannot_be_accessed_in_static_field_initializer_when_class-properties_plugin_is_not_enabled (468ddf4) with main (20a4a8c)

Summary

✅ 38 untouched benchmarks

@Dunqing Dunqing force-pushed the 05-19-fix_transformer_legacy-decorator_static_class_fields_cannot_be_accessed_in_static_field_initializer_when_class-properties_plugin_is_not_enabled branch 2 times, most recently from 404cdd4 to 38387b7 Compare May 19, 2025 09:22
@Dunqing Dunqing marked this pull request as ready for review May 19, 2025 10:09
Copilot AI review requested due to automatic review settings May 19, 2025 10:09
@Dunqing Dunqing requested a review from overlookmotel as a code owner May 19, 2025 10:09
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

Adds missing legacy-decorator logic for static class field initializers when the transform-class-properties plugin is not enabled, matching TypeScript’s behavior.

  • Tracks whether class-properties plugin is enabled in the transform context
  • Updates the TypeScript transformer to use the new context flag instead of a constructor parameter
  • Injects a static block alias assignment (_Class = this) before evaluating static fields when needed
  • Adds/updates conformance tests and snapshots for both “static-field” and “static-field-with-class-properties” cases

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tasks/transform_conformance/tests/legacy-decorators/static-field/input.ts New test input for decorator + static-field scenario
tasks/transform_conformance/tests/legacy-decorators/static-field/output.js Expected transformed output including static block alias logic
tasks/transform_conformance/tests/legacy-decorators/static-field/options.json Plugin config for legacy-decorator only
tasks/transform_conformance/tests/legacy-decorators/static-field/exec.ts Execution test case
tasks/transform_conformance/tests/legacy-decorators/static-field-with-class-properties/* Same as above but with transform-class-properties enabled
tasks/transform_conformance/snapshots/oxc_exec.snap.md Updated pass counts for new tests
tasks/transform_conformance/snapshots/oxc.snap.md Updated legacy-decorators test counts and symbol mismatches
crates/oxc_transformer/src/context.rs Added is_class_properties_plugin_enabled flag in context
crates/oxc_transformer/src/lib.rs Simplified TypeScript::new call by removing plugin arg
crates/oxc_transformer/src/typescript/mod.rs Removed old flag field; switched to context-based check
crates/oxc_transformer/src/decorator/legacy/mod.rs Ported TS logic to insert _Class = this static block
Comments suppressed due to low confidence (1)

crates/oxc_transformer/src/context.rs:50

  • [nitpick] The field is_class_properties_plugin_enabled conflates environment support and plugin presence. Consider renaming it (e.g., class_properties_env_supported or class_properties_plugin_enabled) to clearly communicate whether it reflects target-level support or actual plugin activation.
pub is_class_properties_plugin_enabled: bool,

@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label May 19, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented May 19, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the 05-19-fix_transformer_legacy-decorator_static_class_fields_cannot_be_accessed_in_static_field_initializer_when_class-properties_plugin_is_not_enabled branch from 38387b7 to 468ddf4 Compare May 19, 2025 13:54
@graphite-app graphite-app bot merged commit 468ddf4 into main May 19, 2025
23 of 24 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 19, 2025
@graphite-app graphite-app bot deleted the 05-19-fix_transformer_legacy-decorator_static_class_fields_cannot_be_accessed_in_static_field_initializer_when_class-properties_plugin_is_not_enabled branch May 19, 2025 14:01
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.

oxc_transform with estarget >= 2022 causes TypeError on static property initialization referencing class name

2 participants