Skip to content

Commit db44b5d

Browse files
committed
feat(transformer/class-properties): insert statements after statement of class expression
1 parent 97f4174 commit db44b5d

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

crates/oxc_transformer/src/es2022/class_properties/class.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,21 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
617617
}
618618
}
619619

620+
// Insert private methods
621+
if !self.insert_after_stmts.is_empty() {
622+
// Find address of statement of class expression
623+
let position = ctx
624+
.ancestors()
625+
.position(Ancestor::is_parent_of_statement)
626+
.expect("Expression always inside a statement.");
627+
// Position points to parent of statement, we need to find the statement itself,
628+
// so `position - 1`.
629+
let stmt_ancestor = ctx.ancestor(position - 1);
630+
self.ctx
631+
.statement_injector
632+
.insert_many_after(&stmt_ancestor, self.insert_after_stmts.drain(..));
633+
}
634+
620635
// Insert computed key initializers
621636
exprs.extend(self.insert_before.drain(..));
622637

tasks/transform_conformance/snapshots/babel.snap.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
commit: 54a8389f
22

3-
Passed: 631/1095
3+
Passed: 632/1095
44

55
# All Passed:
66
* babel-plugin-transform-logical-assignment-operators
@@ -462,7 +462,7 @@ x Output mismatch
462462
x Output mismatch
463463

464464

465-
# babel-plugin-transform-private-methods (16/148)
465+
# babel-plugin-transform-private-methods (17/148)
466466
* accessors/arguments/input.js
467467
x Output mismatch
468468

@@ -565,9 +565,6 @@ x Output mismatch
565565
* misc/multiple/input.js
566566
x Output mismatch
567567

568-
* private-method/class-expression/input.js
569-
x Output mismatch
570-
571568
* private-method/destructuring/input.js
572569
x Output mismatch
573570

tasks/transform_conformance/snapshots/babel_exec.snap.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ TypeError: Cannot read properties of undefined (reading 'bind')
5353
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
5454

5555
./fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-self-method-exec.test.js
56-
ReferenceError: _bar is not defined
57-
at Function.extract (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-self-method-exec.test.js:13:46)
58-
at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-self-method-exec.test.js:19:45
56+
TypeError: Private element is not present on this object
57+
at _assertClassBrand (./node_modules/.pnpm/@babel+runtime@7.26.0/node_modules/@babel/runtime/helpers/assertClassBrand.js:3:9)
58+
at Function.extract (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-self-method-exec.test.js:13:10)
59+
at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-self-method-exec.test.js:34:45
5960

6061
./fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-shadow-exec.test.js
6162
TypeError: e.has is not a function

tasks/transform_conformance/snapshots/oxc_exec.snap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ AssertionError: expected [Function] to throw error including 'Receiver must be a
1111
at Proxy.<anonymous> (./node_modules/.pnpm/@vitest+expect@2.1.2/node_modules/@vitest/expect/dist/index.js:1438:21)
1212
at Proxy.<anonymous> (./node_modules/.pnpm/@vitest+expect@2.1.2/node_modules/@vitest/expect/dist/index.js:923:17)
1313
at Proxy.methodWrapper (./node_modules/.pnpm/chai@5.1.2/node_modules/chai/chai.js:1610:25)
14-
at ./tasks/transform_conformance/fixtures/oxc/babel-plugin-transform-class-properties-test-fixtures-private-field-resolve-to-method-in-computed-key-exec.test.js:87:33
14+
at ./tasks/transform_conformance/fixtures/oxc/babel-plugin-transform-class-properties-test-fixtures-private-field-resolve-to-method-in-computed-key-exec.test.js:96:33
1515

1616
./fixtures/oxc/babel-plugin-transform-class-properties-test-fixtures-static-super-tagged-template-exec.test.js
1717
AssertionError: expected undefined to be [Function C] // Object.is equality

0 commit comments

Comments
 (0)