Skip to content

Commit

Permalink
feat(transformer/class-properties): insert statements after statement…
Browse files Browse the repository at this point in the history
… of class expression
  • Loading branch information
Dunqing committed Dec 29, 2024
1 parent ee6a73f commit 00bab9e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
15 changes: 15 additions & 0 deletions crates/oxc_transformer/src/es2022/class_properties/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,21 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
}
}

// Insert private methods
if !self.insert_after_stmts.is_empty() {
// Find address of statement of class expression
let position = ctx
.ancestors()
.position(Ancestor::is_parent_of_statement)
.expect("Expression always inside a statement.");
// Position points to parent of statement, we need to find the statement itself,
// so `position - 1`.
let stmt_ancestor = ctx.ancestor(position - 1);
self.ctx
.statement_injector
.insert_many_after(&stmt_ancestor, self.insert_after_stmts.drain(..));
}

// Insert computed key initializers
exprs.extend(self.insert_before.drain(..));

Expand Down
7 changes: 2 additions & 5 deletions tasks/transform_conformance/snapshots/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 54a8389f

Passed: 631/1095
Passed: 632/1095

# All Passed:
* babel-plugin-transform-logical-assignment-operators
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions tasks/transform_conformance/snapshots/babel_exec.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ 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: _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
TypeError: Private element is not present on this object
at _assertClassBrand (./node_modules/.pnpm/@babel[email protected]/node_modules/@babel/runtime/helpers/assertClassBrand.js:3:9)
at Function.extract (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-self-method-exec.test.js:13:10)
at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-self-method-exec.test.js:34:45

./fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-shadow-exec.test.js
TypeError: e.has is not a function
Expand Down
2 changes: 1 addition & 1 deletion tasks/transform_conformance/snapshots/oxc_exec.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AssertionError: expected [Function] to throw error including 'Receiver must be a
at Proxy.<anonymous> (./node_modules/.pnpm/@vitest[email protected]/node_modules/@vitest/expect/dist/index.js:1438:21)
at Proxy.<anonymous> (./node_modules/.pnpm/@vitest[email protected]/node_modules/@vitest/expect/dist/index.js:923:17)
at Proxy.methodWrapper (./node_modules/.pnpm/[email protected]/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:87: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:96: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
Expand Down

0 comments on commit 00bab9e

Please sign in to comment.