diff --git a/crates/oxc_transformer/src/common/statement_injector.rs b/crates/oxc_transformer/src/common/statement_injector.rs index 5724ce4e5e532..f36c4cc9bb6d5 100644 --- a/crates/oxc_transformer/src/common/statement_injector.rs +++ b/crates/oxc_transformer/src/common/statement_injector.rs @@ -158,7 +158,6 @@ impl<'a> StatementInjectorStore<'a> { /// /// Use this if you convert one statement to another, and other code may have attached /// insertions to the original statement. - #[expect(dead_code)] #[inline] pub fn move_insertions( &self, diff --git a/crates/oxc_transformer/src/decorator/legacy/mod.rs b/crates/oxc_transformer/src/decorator/legacy/mod.rs index 194ba51ced891..2336afebf8da4 100644 --- a/crates/oxc_transformer/src/decorator/legacy/mod.rs +++ b/crates/oxc_transformer/src/decorator/legacy/mod.rs @@ -279,6 +279,7 @@ impl<'a> LegacyDecorator<'a, '_> { if class_or_constructor_parameter_is_decorated { return Some(self.transform_class_declaration_with_class_decorators( class, + stmt_address, has_private_in_expression_in_decorator, ctx, )); @@ -300,6 +301,7 @@ impl<'a> LegacyDecorator<'a, '_> { fn transform_class_declaration_with_class_decorators( &self, class: &mut Class<'a>, + stmt_address: Address, has_private_in_expression_in_decorator: bool, ctx: &mut TraverseCtx<'a>, ) -> (BoundIdentifier<'a>, Statement<'a>) { @@ -448,6 +450,8 @@ impl<'a> LegacyDecorator<'a, '_> { ); let statement = Statement::from(var_declaration); + // Move any insertions attached to the old statement to the new one + self.ctx.statement_injector.move_insertions(&stmt_address, &statement); self.ctx.statement_injector.insert_many_after(&statement, decoration_stmts); (class_binding, statement) diff --git a/tasks/transform_conformance/snapshots/oxc.snap.md b/tasks/transform_conformance/snapshots/oxc.snap.md index 921cd3d4002d9..c36c1f74b9963 100644 --- a/tasks/transform_conformance/snapshots/oxc.snap.md +++ b/tasks/transform_conformance/snapshots/oxc.snap.md @@ -1,6 +1,6 @@ commit: 578ac4df -Passed: 138/227 +Passed: 138/229 # All Passed: * babel-plugin-transform-class-static-block @@ -362,7 +362,7 @@ after transform: SymbolId(4): ScopeId(1) rebuilt : SymbolId(5): ScopeId(4) -# legacy-decorators (2/66) +# legacy-decorators (2/68) * oxc/metadata/bound-type-reference/input.ts Symbol reference IDs mismatch for "BoundTypeReference": after transform: SymbolId(0): [ReferenceId(1), ReferenceId(3), ReferenceId(4), ReferenceId(5), ReferenceId(6)] @@ -385,6 +385,31 @@ Unresolved reference IDs mismatch for "UnboundTypeReference": after transform: [ReferenceId(1), ReferenceId(2), ReferenceId(3)] rebuilt : [ReferenceId(4), ReferenceId(5)] +* oxc/with-class-private-properties/input.ts +Symbol span mismatch for "C": +after transform: SymbolId(0): Span { start: 11, end: 12 } +rebuilt : SymbolId(0): Span { start: 0, end: 0 } +Symbol span mismatch for "C": +after transform: SymbolId(3): Span { start: 0, end: 0 } +rebuilt : SymbolId(1): Span { start: 11, end: 12 } +Symbol span mismatch for "D": +after transform: SymbolId(1): Span { start: 87, end: 88 } +rebuilt : SymbolId(2): Span { start: 0, end: 0 } +Symbol span mismatch for "D": +after transform: SymbolId(4): Span { start: 0, end: 0 } +rebuilt : SymbolId(3): Span { start: 87, end: 88 } +Symbol span mismatch for "E": +after transform: SymbolId(2): Span { start: 171, end: 172 } +rebuilt : SymbolId(4): Span { start: 0, end: 0 } +Symbol span mismatch for "E": +after transform: SymbolId(5): Span { start: 0, end: 0 } +rebuilt : SymbolId(5): Span { start: 171, end: 172 } + +* oxc/with-class-private-properties-unnamed-default-export/input.ts +Symbol flags mismatch for "_default": +after transform: SymbolId(0): SymbolFlags(Class) +rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable) + * typescript/accessor/decoratorOnClassAccessor1/input.ts Scope children mismatch: after transform: ScopeId(0): [ScopeId(1), ScopeId(2)] diff --git a/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/with-class-private-properties-unnamed-default-export/input.ts b/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/with-class-private-properties-unnamed-default-export/input.ts new file mode 100644 index 0000000000000..bd8090122d78c --- /dev/null +++ b/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/with-class-private-properties-unnamed-default-export/input.ts @@ -0,0 +1,7 @@ +@dec +export default class { + #prop = 0; + meth() { + return this.#prop; + } +} diff --git a/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/with-class-private-properties-unnamed-default-export/output.js b/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/with-class-private-properties-unnamed-default-export/output.js new file mode 100644 index 0000000000000..0c780ec95805f --- /dev/null +++ b/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/with-class-private-properties-unnamed-default-export/output.js @@ -0,0 +1,8 @@ +let _default = class { + #prop = 0; + meth() { + return this.#prop; + } +}; +_default = babelHelpers.decorate([dec], _default); +export default _default; diff --git a/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/with-class-private-properties/input.ts b/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/with-class-private-properties/input.ts new file mode 100644 index 0000000000000..2c27879776113 --- /dev/null +++ b/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/with-class-private-properties/input.ts @@ -0,0 +1,23 @@ +@dec +class C { + #prop = 0; + meth() { + return this.#prop; + } +} + +@dec +export class D { + #prop = 0; + meth() { + return this.#prop; + } +} + +@dec +export default class E { + #prop = 0; + meth() { + return this.#prop; + } +} diff --git a/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/with-class-private-properties/output.js b/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/with-class-private-properties/output.js new file mode 100644 index 0000000000000..ba8fef817aa6e --- /dev/null +++ b/tasks/transform_conformance/tests/legacy-decorators/test/fixtures/oxc/with-class-private-properties/output.js @@ -0,0 +1,25 @@ +let C = class C { + #prop = 0; + meth() { + return this.#prop; + } +}; +C = babelHelpers.decorate([dec], C); + +let D = class D { + #prop = 0; + meth() { + return this.#prop; + } +}; +D = babelHelpers.decorate([dec], D); + +export { D }; +let E = class E { + #prop = 0; + meth() { + return this.#prop; + } +}; +E = babelHelpers.decorate([dec], E); +export default E;