From 48332a210a4934d6bbba935f6d659ff2176ff659 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Wed, 25 Dec 2024 20:41:23 +0800 Subject: [PATCH] feat(transformer/class-properties): insert statements after statement of class expression --- .../src/es2022/class_properties/class.rs | 12 ++++++++++++ tasks/transform_conformance/snapshots/babel.snap.md | 7 ++----- .../snapshots/babel_exec.snap.md | 4 ++-- .../transform_conformance/snapshots/oxc_exec.snap.md | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/oxc_transformer/src/es2022/class_properties/class.rs b/crates/oxc_transformer/src/es2022/class_properties/class.rs index 493814fff0fcaa..d59b5f9e1444c3 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/class.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/class.rs @@ -615,6 +615,18 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { } } + if !self.insert_after_stmts.is_empty() { + // Find address of statement of class expression + let position = ctx + .ancestors() + .position(Ancestor::is_parent_of_expression) + .expect("Expression always inside a statement."); + let stmt_ancestor = ctx.ancestor(position); + self.ctx + .statement_injector + .insert_many_after(&stmt_ancestor, self.insert_after_stmts.drain(..)); + } + // Insert computed key initializers exprs.extend(self.insert_before.drain(..)); diff --git a/tasks/transform_conformance/snapshots/babel.snap.md b/tasks/transform_conformance/snapshots/babel.snap.md index 53dea0aad032c9..7b71201c4d214a 100644 --- a/tasks/transform_conformance/snapshots/babel.snap.md +++ b/tasks/transform_conformance/snapshots/babel.snap.md @@ -1,6 +1,6 @@ commit: 54a8389f -Passed: 631/1095 +Passed: 632/1095 # All Passed: * babel-plugin-transform-logical-assignment-operators @@ -462,7 +462,7 @@ x Output mismatch x Output mismatch -# babel-plugin-transform-private-methods (16/148) +# babel-plugin-transform-private-methods (17/148) * accessors/arguments/input.js x Output mismatch @@ -565,9 +565,6 @@ x Output mismatch * misc/multiple/input.js x Output mismatch -* private-method/class-expression/input.js -x Output mismatch - * private-method/destructuring/input.js x Output mismatch diff --git a/tasks/transform_conformance/snapshots/babel_exec.snap.md b/tasks/transform_conformance/snapshots/babel_exec.snap.md index 548ca8889ce56d..e5737b715b30ee 100644 --- a/tasks/transform_conformance/snapshots/babel_exec.snap.md +++ b/tasks/transform_conformance/snapshots/babel_exec.snap.md @@ -53,8 +53,8 @@ TypeError: Cannot read properties of undefined (reading 'bind') at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-loose-parenthesized-optional-member-call-with-transform-exec.test.js:78:12 ./fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-self-method-exec.test.js -ReferenceError: _Foo_brand is not defined - at Function.extract (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-self-method-exec.test.js:13:28) +ReferenceError: _bar is not defined + at Function.extract (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-self-method-exec.test.js:13:46) at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-self-method-exec.test.js:19:45 ./fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-shadow-exec.test.js diff --git a/tasks/transform_conformance/snapshots/oxc_exec.snap.md b/tasks/transform_conformance/snapshots/oxc_exec.snap.md index 96216a55a1388a..0193450f6e29b2 100644 --- a/tasks/transform_conformance/snapshots/oxc_exec.snap.md +++ b/tasks/transform_conformance/snapshots/oxc_exec.snap.md @@ -11,7 +11,7 @@ AssertionError: expected [Function] to throw error including 'Receiver must be a at Proxy. (./node_modules/.pnpm/@vitest+expect@2.1.2/node_modules/@vitest/expect/dist/index.js:1438:21) at Proxy. (./node_modules/.pnpm/@vitest+expect@2.1.2/node_modules/@vitest/expect/dist/index.js:923:17) at Proxy.methodWrapper (./node_modules/.pnpm/chai@5.1.2/node_modules/chai/chai.js:1610:25) - at ./tasks/transform_conformance/fixtures/oxc/babel-plugin-transform-class-properties-test-fixtures-private-field-resolve-to-method-in-computed-key-exec.test.js:86:33 + at ./tasks/transform_conformance/fixtures/oxc/babel-plugin-transform-class-properties-test-fixtures-private-field-resolve-to-method-in-computed-key-exec.test.js:93:33 ./fixtures/oxc/babel-plugin-transform-class-properties-test-fixtures-static-super-tagged-template-exec.test.js AssertionError: expected undefined to be [Function C] // Object.is equality