From fa38824ece31f7a86c2ea672e6067ccb84485338 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Wed, 25 Dec 2024 12:56:12 +0800 Subject: [PATCH] feat(transformer/class-properties): transform private field expression which refers to private method --- .../es2022/class_properties/private_field.rs | 40 +++-- .../snapshots/babel.snap.md | 10 +- .../snapshots/babel_exec.snap.md | 153 +++++++++++++----- .../snapshots/oxc_exec.snap.md | 6 +- 4 files changed, 142 insertions(+), 67 deletions(-) diff --git a/crates/oxc_transformer/src/es2022/class_properties/private_field.rs b/crates/oxc_transformer/src/es2022/class_properties/private_field.rs index 85270a563ef6a..e2e3f22c07912 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/private_field.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/private_field.rs @@ -60,11 +60,18 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { is_declaration, } = self.classes_stack.find_private_prop(&field_expr.field); + let span = field_expr.span; + if is_method || is_accessor { - return None; + let prop_ident = prop_binding.create_read_expression(ctx); + return if is_assignment { + // TODO: Handle assignment to private method or accessor + None + } else { + Some(self.create_assert_class_brand_for_private_method(prop_ident, span, ctx)) + }; }; - let span = field_expr.span; let object = ctx.ast.move_expression(&mut field_expr.object); if self.private_fields_as_properties { @@ -268,11 +275,12 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { is_declaration, } = self.classes_stack.find_private_prop(&field_expr.field); + let span = field_expr.span; let prop_ident = prop_binding.create_read_expression(ctx); if is_method || is_accessor { return ( - self.create_assert_class_brand_for_private_method(prop_ident, ctx), + self.create_assert_class_brand_for_private_method(prop_ident, span, ctx), ctx.ast.expression_this(SPAN), ); }; @@ -301,8 +309,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { .is_some() { // `_prop._` - let callee = - Self::create_underscore_member_expression(prop_ident, field_expr.span, ctx); + let callee = Self::create_underscore_member_expression(prop_ident, span, ctx); (callee, object) } else { let class_binding = class_bindings.get_or_init_static_binding(ctx); @@ -316,7 +323,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { class_ident, object1, prop_ident, - field_expr.span, + span, ctx, ); (assert_obj, object2) @@ -327,7 +334,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { let (object1, object2) = self.duplicate_object(object, ctx); // `_classPrivateFieldGet2(_prop, object)` - let get_call = self.create_private_field_get(prop_ident, object1, field_expr.span, ctx); + let get_call = self.create_private_field_get(prop_ident, object1, span, ctx); (get_call, object2) }; @@ -533,7 +540,8 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { // Replace right side of assignment with `_assertClassBrand(Class, object, _prop)` // TODO: Ensure there are tests for nested classes with references to private static props // of outer class inside inner class, to make sure we're getting the right `class_binding`. - assign_expr.right = self.create_assert_class_brand(class_ident, object, value, ctx); + assign_expr.right = + self.create_assert_class_brand(class_ident, object, value, SPAN, ctx); } else { let class_ident = class_binding.create_read_expression(ctx); let value = ctx.ast.move_expression(&mut assign_expr.right); @@ -563,7 +571,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { let value = ctx.ast.expression_binary(SPAN, get_expr, operator, value); // `_assertClassBrand(Class, object, _assertClassBrand(Class, object, _prop)._ + value)` assign_expr.right = - self.create_assert_class_brand(class_ident2, object1, value, ctx); + self.create_assert_class_brand(class_ident2, object1, value, SPAN, ctx); } else if let Some(operator) = operator.to_logical_operator() { // `object.#prop &&= value` // -> `_assertClassBrand(Class, object, _prop)._ && (_prop._ = _assertClassBrand(Class, object, value))` @@ -585,7 +593,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { assign_expr.span = SPAN; assign_expr.operator = AssignmentOperator::Assign; assign_expr.right = - self.create_assert_class_brand(class_ident2, object2, value, ctx); + self.create_assert_class_brand(class_ident2, object2, value, SPAN, ctx); let right = ctx.ast.move_expression(expr); // `_assertClassBrand(Class, object, _prop)._ && (_prop._ = _assertClassBrand(Class, object, value))` *expr = ctx.ast.expression_logical(span, left, operator, right); @@ -869,7 +877,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { // If no shortcut, wrap in `_assertClassBrand(Class, object, )` if let Some(class_ident) = class_ident { - value = self.create_assert_class_brand(class_ident, object, value, ctx); + value = self.create_assert_class_brand(class_ident, object, value, SPAN, ctx); } // `_prop._ = ` @@ -899,7 +907,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { // If no shortcut, wrap in `_assertClassBrand(Class, object, )` if let Some(class_ident) = class_ident { - value = self.create_assert_class_brand(class_ident, object, value, ctx); + value = self.create_assert_class_brand(class_ident, object, value, SPAN, ctx); } // `_prop._ = ` @@ -1772,11 +1780,12 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { class_ident: Expression<'a>, object: Expression<'a>, value_or_prop_ident: Expression<'a>, + span: Span, ctx: &mut TraverseCtx<'a>, ) -> Expression<'a> { self.ctx.helper_call_expr( Helper::AssertClassBrand, - SPAN, + span, ctx.ast.vec_from_array([ Argument::from(class_ident), Argument::from(object), @@ -1791,11 +1800,12 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { fn create_assert_class_brand_for_private_method( &self, value_or_prop_ident: Expression<'a>, + span: Span, ctx: &mut TraverseCtx<'a>, ) -> Expression<'a> { let class_ident = self.current_class().bindings.brand().create_read_expression(ctx); let object = ctx.ast.expression_this(SPAN); - self.create_assert_class_brand(class_ident, object, value_or_prop_ident, ctx) + self.create_assert_class_brand(class_ident, object, value_or_prop_ident, span, ctx) } /// `_assertClassBrand(Class, object, _prop)._` @@ -1807,7 +1817,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { span: Span, ctx: &mut TraverseCtx<'a>, ) -> Expression<'a> { - let func_call = self.create_assert_class_brand(class_ident, object, prop_ident, ctx); + let func_call = self.create_assert_class_brand(class_ident, object, prop_ident, SPAN, ctx); Self::create_underscore_member_expression(func_call, span, ctx) } diff --git a/tasks/transform_conformance/snapshots/babel.snap.md b/tasks/transform_conformance/snapshots/babel.snap.md index e7752d07b284d..61a78ae3bb6fb 100644 --- a/tasks/transform_conformance/snapshots/babel.snap.md +++ b/tasks/transform_conformance/snapshots/babel.snap.md @@ -1,6 +1,6 @@ commit: 54a8389f -Passed: 628/1095 +Passed: 630/1095 # All Passed: * babel-plugin-transform-logical-assignment-operators @@ -462,7 +462,7 @@ x Output mismatch x Output mismatch -# babel-plugin-transform-private-methods (13/148) +# babel-plugin-transform-private-methods (15/148) * accessors/arguments/input.js x Output mismatch @@ -571,15 +571,9 @@ x Output mismatch * private-method/class-expression/input.js x Output mismatch -* private-method/context/input.js -x Output mismatch - * private-method/destructuring/input.js x Output mismatch -* private-method/exfiltrated/input.js -x Output mismatch - * private-method/read-only/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 df3224a0c7a50..4676413d9c972 100644 --- a/tasks/transform_conformance/snapshots/babel_exec.snap.md +++ b/tasks/transform_conformance/snapshots/babel_exec.snap.md @@ -2,7 +2,7 @@ commit: 54a8389f node: v22.12.0 -Passed: 225 of 362 (62.15%) +Passed: 227 of 362 (62.71%) Failures: @@ -53,7 +53,9 @@ 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 -Private field '#bar' must be declared in an enclosing class +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:12:28) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-self-method-exec.test.js:18:45 ./fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-private-static-shadow-exec.test.js TypeError: e.has is not a function @@ -85,7 +87,9 @@ AssertionError: expected '_Class' to be 'Foo' // Object.is equality Private field '#bar' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-class-static-block-test-fixtures-integration-loose-private-methods-access-exec.test.js -Private field '#foo' must be declared in an enclosing class +ReferenceError: _Foo_brand is not defined + at getFoo (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-static-block-test-fixtures-integration-loose-private-methods-access-exec.test.js:17:35) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-class-static-block-test-fixtures-integration-loose-private-methods-access-exec.test.js:18:9 ./fixtures/babel/babel-plugin-transform-class-static-block-test-fixtures-integration-new-target-exec.test.js AssertionError: expected [Function Base] to be undefined // Object.is equality @@ -124,10 +128,13 @@ Private field '#privateFieldValue' must be declared in an enclosing class Private field '#privateFieldValue' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-class-binding-exec.test.js -Private field '#getA' must be declared in an enclosing class +AssertionError: expected [Function _get_getA] to be [Function A] // Object.is equality + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-class-binding-exec.test.js:20:26 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-get-only-setter-exec.test.js -Private field '#privateFieldValue' must be declared in an enclosing class +AssertionError: expected function to throw an error, but it didn't + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-get-only-setter-exec.test.js:14:77) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-get-only-setter-exec.test.js:20:13 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-helper-exec.test.js Private field '#foo' must be declared in an enclosing class @@ -136,10 +143,14 @@ Private field '#foo' must be declared in an enclosing class Private field '#privateFieldValue' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-loose-class-binding-exec.test.js -Private field '#getA' must be declared in an enclosing class +ReferenceError: _A_brand is not defined + at new A (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-loose-class-binding-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-loose-class-binding-exec.test.js:19:9 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-loose-get-only-setter-exec.test.js -Private field '#privateFieldValue' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-loose-get-only-setter-exec.test.js:11:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-loose-get-only-setter-exec.test.js:22:13 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-loose-helper-exec.test.js Private field '#foo' must be declared in an enclosing class @@ -157,10 +168,14 @@ Private field '#privateFieldValue' must be declared in an enclosing class Private field '#privateFieldValue' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsProperties-class-binding-exec.test.js -Private field '#getA' must be declared in an enclosing class +ReferenceError: _A_brand is not defined + at new A (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsProperties-class-binding-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsProperties-class-binding-exec.test.js:19:9 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsProperties-get-only-setter-exec.test.js -Private field '#privateFieldValue' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsProperties-get-only-setter-exec.test.js:11:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsProperties-get-only-setter-exec.test.js:22:13 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsProperties-helper-exec.test.js Private field '#foo' must be declared in an enclosing class @@ -175,10 +190,16 @@ Private field '#privateFieldValue' must be declared in an enclosing class Private field '#privateFieldValue' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsSymbols-class-binding-exec.test.js -Private field '#getA' must be declared in an enclosing class +AssertionError: expected [Function _get_getA] to be [Function A] // Object.is equality + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsSymbols-class-binding-exec.test.js:20:26 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsSymbols-get-only-setter-exec.test.js -Private field '#privateFieldValue' must be declared in an enclosing class +AssertionError: expected [Function _set_privateFieldValue] to be undefined + at Proxy. (./node_modules/.pnpm/@vitest+expect@2.1.2/node_modules/@vitest/expect/dist/index.js:1236:20) + 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 new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsSymbols-get-only-setter-exec.test.js:14:71) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsSymbols-get-only-setter-exec.test.js:20:13 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-accessors-privateFieldsAsSymbols-helper-exec.test.js Private field '#foo' must be declared in an enclosing class @@ -208,26 +229,33 @@ AssertionError: expected null to be [Function A] // Object.is equality ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-context-exec.test.js Private field '#getStatus' must be declared in an enclosing class -./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-exfiltrated-exec.test.js -Private field '#privateMethod' must be declared in an enclosing class - ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-assignment-exec.test.js -Private field '#privateMethod' must be declared in an enclosing class +ReferenceError: _Foo_brand is not defined + at new Foo (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-assignment-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-assignment-exec.test.js:15:9 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-before-fields-exec.test.js -Private field '#method' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-before-fields-exec.test.js:11:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-before-fields-exec.test.js:25:9 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-class-binding-exec.test.js -Private field '#getA' must be declared in an enclosing class +ReferenceError: _A_brand is not defined + at new A (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-class-binding-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-class-binding-exec.test.js:19:9 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-context-exec.test.js Private field '#getStatus' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-exfiltrated-exec.test.js -Private field '#privateMethod' must be declared in an enclosing class +ReferenceError: _Foo_brand is not defined + at new Foo (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-exfiltrated-exec.test.js:9:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-exfiltrated-exec.test.js:17:2 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-generator-exec.test.js -Private field '#foo' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-generator-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-generator-exec.test.js:18:14 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-loose-reassignment-exec.test.js Private field '#privateMethod' must be declared in an enclosing class @@ -236,22 +264,32 @@ Private field '#privateMethod' must be declared in an enclosing class Invalid access to super ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-assignment-exec.test.js -Private field '#privateMethod' must be declared in an enclosing class +ReferenceError: _Foo_brand is not defined + at new Foo (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-assignment-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-assignment-exec.test.js:15:9 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-before-fields-exec.test.js -Private field '#method' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-before-fields-exec.test.js:12:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-before-fields-exec.test.js:26:9 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-class-binding-exec.test.js -Private field '#getA' must be declared in an enclosing class +ReferenceError: _A_brand is not defined + at new A (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-class-binding-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-class-binding-exec.test.js:19:9 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-context-exec.test.js Private field '#getStatus' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-exfiltrated-exec.test.js -Private field '#privateMethod' must be declared in an enclosing class +ReferenceError: _Foo_brand is not defined + at new Foo (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-exfiltrated-exec.test.js:9:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-exfiltrated-exec.test.js:17:2 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-generator-exec.test.js -Private field '#foo' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-generator-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-generator-exec.test.js:18:14 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsProperties-super-exec.test.js Invalid access to super @@ -263,9 +301,6 @@ AssertionError: expected null to be [Function A] // Object.is equality ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsSymbols-context-exec.test.js Private field '#getStatus' must be declared in an enclosing class -./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsSymbols-exfiltrated-exec.test.js -Private field '#privateMethod' must be declared in an enclosing class - ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-method-privateFieldsAsSymbols-super-exec.test.js Invalid access to super @@ -289,7 +324,9 @@ ReferenceError: _Cl_brand is not defined at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-class-check-exec.test.js:17:13 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-exfiltrated-exec.test.js -Private field '#privateStaticMethod' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-exfiltrated-exec.test.js:9:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-exfiltrated-exec.test.js:19:2 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-generator-exec.test.js ReferenceError: _Cl_brand is not defined @@ -297,22 +334,32 @@ ReferenceError: _Cl_brand is not defined at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-generator-exec.test.js:18:14 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-basic-exec.test.js -Private field '#privateStaticMethod' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-basic-exec.test.js:21:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-basic-exec.test.js:28:9 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-class-check-exec.test.js -Private field '#privateStaticMethod' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-class-check-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-class-check-exec.test.js:17:13 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-exfiltrated-exec.test.js -Private field '#privateStaticMethod' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-exfiltrated-exec.test.js:9:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-exfiltrated-exec.test.js:19:2 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-generator-exec.test.js -Private field '#foo' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-generator-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-generator-exec.test.js:18:14 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-reassignment-exec.test.js Private field '#privateStaticMethod' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-scopable-exec.test.js -Private field '#privateMethodA' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-scopable-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-scopable-exec.test.js:22:9 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-loose-super-exec.test.js Invalid access to super @@ -321,22 +368,32 @@ Invalid access to super Invalid access to super ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-basic-exec.test.js -Private field '#privateStaticMethod' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-basic-exec.test.js:21:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-basic-exec.test.js:28:9 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-class-check-exec.test.js -Private field '#privateStaticMethod' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-class-check-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-class-check-exec.test.js:17:13 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-exfiltrated-exec.test.js -Private field '#privateStaticMethod' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-exfiltrated-exec.test.js:9:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-exfiltrated-exec.test.js:19:2 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-generator-exec.test.js -Private field '#foo' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-generator-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-generator-exec.test.js:18:14 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-reassignment-exec.test.js Private field '#privateStaticMethod' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-scopable-exec.test.js -Private field '#privateMethodA' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-scopable-exec.test.js:8:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-scopable-exec.test.js:22:9 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsProperties-super-exec.test.js Invalid access to super @@ -355,7 +412,9 @@ ReferenceError: _Cl_brand is not defined at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsSymbols-class-check-exec.test.js:17:13 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsSymbols-exfiltrated-exec.test.js -Private field '#privateStaticMethod' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at new Cl (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsSymbols-exfiltrated-exec.test.js:9:38) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsSymbols-exfiltrated-exec.test.js:19:2 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-private-static-method-privateFieldsAsSymbols-generator-exec.test.js ReferenceError: _Cl_brand is not defined @@ -408,7 +467,9 @@ Private field '#privateStaticFieldValue' must be declared in an enclosing class Private field '#p' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-get-only-setter-exec.test.js -Private field '#privateStaticFieldValue' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at Function.getPrivateStaticFieldValue (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-get-only-setter-exec.test.js:11:29) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-get-only-setter-exec.test.js:18:12 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-loose-access-in-static-field-initializer-exec.test.js Private field '#p' must be declared in an enclosing class @@ -420,7 +481,9 @@ Private field '#privateStaticFieldValue' must be declared in an enclosing class Private field '#p' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-loose-get-only-setter-exec.test.js -Private field '#privateStaticFieldValue' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at Function.getPrivateStaticFieldValue (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-loose-get-only-setter-exec.test.js:14:29) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-loose-get-only-setter-exec.test.js:24:12 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-loose-set-only-getter-exec.test.js Private field '#privateFieldValue' must be declared in an enclosing class @@ -438,7 +501,9 @@ Private field '#privateStaticFieldValue' must be declared in an enclosing class Private field '#p' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-privateFieldsAsProperties-get-only-setter-exec.test.js -Private field '#privateStaticFieldValue' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at Function.getPrivateStaticFieldValue (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-privateFieldsAsProperties-get-only-setter-exec.test.js:14:29) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-privateFieldsAsProperties-get-only-setter-exec.test.js:24:12 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-privateFieldsAsProperties-set-only-getter-exec.test.js Private field '#privateFieldValue' must be declared in an enclosing class @@ -456,7 +521,9 @@ Private field '#privateStaticFieldValue' must be declared in an enclosing class Private field '#p' must be declared in an enclosing class ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-privateFieldsAsSymbols-get-only-setter-exec.test.js -Private field '#privateStaticFieldValue' must be declared in an enclosing class +ReferenceError: _Cl_brand is not defined + at Function.getPrivateStaticFieldValue (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-privateFieldsAsSymbols-get-only-setter-exec.test.js:11:29) + at ./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-privateFieldsAsSymbols-get-only-setter-exec.test.js:18:12 ./fixtures/babel/babel-plugin-transform-private-methods-test-fixtures-static-accessors-privateFieldsAsSymbols-set-only-getter-exec.test.js Private field '#privateFieldValue' must be declared in an enclosing class diff --git a/tasks/transform_conformance/snapshots/oxc_exec.snap.md b/tasks/transform_conformance/snapshots/oxc_exec.snap.md index f2c7e0b449cf4..96216a55a1388 100644 --- a/tasks/transform_conformance/snapshots/oxc_exec.snap.md +++ b/tasks/transform_conformance/snapshots/oxc_exec.snap.md @@ -7,7 +7,11 @@ Passed: 3 of 5 (60.00%) Failures: ./fixtures/oxc/babel-plugin-transform-class-properties-test-fixtures-private-field-resolve-to-method-in-computed-key-exec.test.js -Private field '#shadowed' must be declared in an enclosing class +AssertionError: expected [Function] to throw error including 'Receiver must be an instance of class…' but got 'Private element is not present on thi…' + 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 ./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