From aca4fd017536d7b02abf4711b80e0a6ba0166fb9 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Thu, 5 Dec 2024 22:35:43 +0000 Subject: [PATCH] test(transformer/class-properties): override fixtures --- .../private/derived-multiple-supers/output.js | 16 ++++ .../private/regression-T7364/output.mjs | 27 ++++++ .../fixtures/public-loose/foobar/options.json | 10 +++ .../fixtures/public-loose/foobar/reason.txt | 2 + .../public-loose/super-expression/output.js | 10 +++ .../public/computed-toPrimitive/output.js | 48 ++++++++++ .../public/derived-multiple-supers/output.js | 15 ++++ .../output.js | 7 ++ .../output.js | 9 ++ .../derived-super-in-default-params/output.js | 7 ++ .../public/super-expression/output.js | 10 +++ .../fixtures/regression/7371/options.json | 5 ++ .../test/fixtures/regression/7371/output.js | 89 +++++++++++++++++++ .../test/fixtures/regression/7371/reason.txt | 2 + .../multiple-super-in-termary/output.js | 10 +++ .../snapshots/babel.snap.md | 84 +++++++++++------ .../snapshots/babel_exec.snap.md | 5 +- 17 files changed, 324 insertions(+), 32 deletions(-) create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/private/derived-multiple-supers/output.js create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/private/regression-T7364/output.mjs create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public-loose/foobar/options.json create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public-loose/foobar/reason.txt create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public-loose/super-expression/output.js create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/computed-toPrimitive/output.js create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-multiple-supers/output.js create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-super-in-default-params-complex/output.js create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-super-in-default-params-in-arrow/output.js create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-super-in-default-params/output.js create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/super-expression/output.js create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/options.json create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/output.js create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/reason.txt create mode 100644 tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/multiple-super-in-termary/output.js diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/private/derived-multiple-supers/output.js b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/private/derived-multiple-supers/output.js new file mode 100644 index 00000000000000..affc219260cdc9 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/private/derived-multiple-supers/output.js @@ -0,0 +1,16 @@ +var _bar = /*#__PURE__*/new WeakMap(); +class Foo extends Bar { + constructor() { + var _super = (..._args) => { + super(..._args); + babelHelpers.classPrivateFieldInitSpec(this, _bar, "foo"); + return this; + }; + + if (condition) { + _super(); + } else { + _super(); + } + } +} diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/private/regression-T7364/output.mjs b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/private/regression-T7364/output.mjs new file mode 100644 index 00000000000000..2af5c97b636108 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/private/regression-T7364/output.mjs @@ -0,0 +1,27 @@ +var _myAsyncMethod2; +var _myAsyncMethod = new WeakMap(); +class MyClass { + constructor() { + var _this = this; + babelHelpers.classPrivateFieldInitSpec(this, _myAsyncMethod, babelHelpers.asyncToGenerator(function* () { + console.log(_this); + })); + } +} +_myAsyncMethod2 = new WeakMap(), class MyClass2 { + constructor() { + var _this2 = this; + babelHelpers.classPrivateFieldInitSpec(this, _myAsyncMethod2, babelHelpers.asyncToGenerator(function* () { + console.log(_this2); + })); + } +}; +var _myAsyncMethod3 = new WeakMap(); +export default class MyClass3 { + constructor() { + var _this3 = this; + babelHelpers.classPrivateFieldInitSpec(this, _myAsyncMethod3, babelHelpers.asyncToGenerator(function* () { + console.log(_this3); + })); + } +} diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public-loose/foobar/options.json b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public-loose/foobar/options.json new file mode 100644 index 00000000000000..af5c06805e8025 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public-loose/foobar/options.json @@ -0,0 +1,10 @@ +{ + "plugins": [ + [ + "transform-class-properties", + { + "loose": true + } + ] + ] +} diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public-loose/foobar/reason.txt b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public-loose/foobar/reason.txt new file mode 100644 index 00000000000000..2637988f084f02 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public-loose/foobar/reason.txt @@ -0,0 +1,2 @@ +Disable arrow functions transform in `options.json` because it malfunctions. +But these fixtures aren't to test arrow functions transform. diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public-loose/super-expression/output.js b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public-loose/super-expression/output.js new file mode 100644 index 00000000000000..c99d089e21f939 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public-loose/super-expression/output.js @@ -0,0 +1,10 @@ +class Foo extends Bar { + constructor() { + var _super = (..._args) => { + super(..._args); + this.bar = "foo"; + return this; + }; + foo(_super()); + } +} diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/computed-toPrimitive/output.js b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/computed-toPrimitive/output.js new file mode 100644 index 00000000000000..00d308430eda1e --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/computed-toPrimitive/output.js @@ -0,0 +1,48 @@ +var _Class; +const foo = { [Symbol.toPrimitive]: () => "foo" }; +expect((_Class = class {}, babelHelpers.defineProperty(_Class, foo, 0), _Class).foo).toBe(0); +expect(class { + static [foo]() { + return 0; + } +}.foo()).toBe(0); +expect(class { + static get [foo]() { + return 0; + } +}.foo).toBe(0); +expect(class { + static set [foo](v) { + return v; + } +}.foo = 0).toBe(0); +expect(new class { + constructor() { + babelHelpers.defineProperty(this, foo, 0); + } +}().foo).toBe(0); +const arrayLike = { [Symbol.toPrimitive]: () => [] }; +expect(() => { + var _Class2; + return _Class2 = class {}, babelHelpers.defineProperty(_Class2, arrayLike, 0), _Class2; +}).toThrow("@@toPrimitive must return a primitive value."); +expect(() => class { + static [arrayLike]() { + return 0; + } +}).toThrow("@@toPrimitive must return a primitive value."); +expect(() => class { + static get [arrayLike]() { + return 0; + } +}).toThrow("@@toPrimitive must return a primitive value."); +expect(() => class { + static set [arrayLike](v) { + return v; + } +}).toThrow("@@toPrimitive must return a primitive value."); +expect(() => new class { + constructor() { + babelHelpers.defineProperty(this, arrayLike, 0); + } +}()).toThrow("@@toPrimitive must return a primitive value."); diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-multiple-supers/output.js b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-multiple-supers/output.js new file mode 100644 index 00000000000000..78bb48487b6154 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-multiple-supers/output.js @@ -0,0 +1,15 @@ +class Foo extends Bar { + constructor() { + var _super = (..._args) => { + super(..._args); + babelHelpers.defineProperty(this, "bar", "foo"); + return this; + }; + + if (condition) { + _super(); + } else { + _super(); + } + } +} diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-super-in-default-params-complex/output.js b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-super-in-default-params-complex/output.js new file mode 100644 index 00000000000000..9c789497f69fd3 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-super-in-default-params-complex/output.js @@ -0,0 +1,7 @@ +let _super = function() { + babelHelpers.defineProperty(this, "bar", "foo"); + return this; +}; +class Foo extends Bar { + constructor(x = test ? _super.call(super()) : 0) {} +} diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-super-in-default-params-in-arrow/output.js b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-super-in-default-params-in-arrow/output.js new file mode 100644 index 00000000000000..48b8e56378f94f --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-super-in-default-params-in-arrow/output.js @@ -0,0 +1,9 @@ +let _super = function() { + babelHelpers.defineProperty(this, "bar", "foo"); + return this; +}; +class Foo extends Bar { + constructor(x = () => { + check(_super.call(super())); + }) {} +} diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-super-in-default-params/output.js b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-super-in-default-params/output.js new file mode 100644 index 00000000000000..985fbb012ab074 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived-super-in-default-params/output.js @@ -0,0 +1,7 @@ +let _super = function() { + babelHelpers.defineProperty(this, "bar", "foo"); + return this; +}; +class Foo extends Bar { + constructor(x = _super.call(super())) {} +} diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/super-expression/output.js b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/super-expression/output.js new file mode 100644 index 00000000000000..0cc3f1ca0e0c78 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/public/super-expression/output.js @@ -0,0 +1,10 @@ +class Foo extends Bar { + constructor() { + var _super = (..._args) => { + super(..._args); + babelHelpers.defineProperty(this, "bar", "foo"); + return this; + }; + foo(_super()); + } +} diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/options.json b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/options.json new file mode 100644 index 00000000000000..6f801200552934 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/options.json @@ -0,0 +1,5 @@ +{ + "plugins": [ + "transform-class-properties" + ] +} diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/output.js b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/output.js new file mode 100644 index 00000000000000..af8cc7e0f3d294 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/output.js @@ -0,0 +1,89 @@ +"use strict"; + +class C {} + +class A extends C { + constructor() { + super(); + babelHelpers.defineProperty(this, "field", 1); + class B extends C { + constructor() { + super(); + expect(this.field).toBeUndefined(); + } + } + expect(this.field).toBe(1); + new B(); + } +} +new A(); + +class Obj { + constructor() { + return {}; + } +} + +// ensure superClass is still transformed +class SuperClass extends Obj { + constructor() { + var _super = (..._args) => { + super(..._args); + babelHelpers.defineProperty(this, "field", 1); + return this; + }; + class B extends (_super(), Obj) { + constructor() { + super(); + expect(this.field).toBeUndefined(); + } + } + expect(this.field).toBe(1); + new B(); + } +} +new SuperClass(); + +// ensure ComputedKey Method is still transformed +class ComputedMethod extends Obj { + constructor() { + var _super2 = (..._args2) => { + super(..._args2); + babelHelpers.defineProperty(this, "field", 1); + return this; + }; + class B extends Obj { + constructor() { + super(); + expect(this.field).toBeUndefined(); + } + [_super2()]() {} + } + expect(this.field).toBe(1); + new B(); + } +} +new ComputedMethod(); + +// ensure ComputedKey Field is still transformed +class ComputedField extends Obj { + constructor() { + let _super4; + var _super3 = (..._args3) => { + super(..._args3); + babelHelpers.defineProperty(this, "field", 1); + return this; + }; + _super4 = _super3(); + class B extends Obj { + constructor() { + super(); + babelHelpers.defineProperty(this, _super4, 1); + expect(this.field).toBeUndefined(); + } + } + expect(this.field).toBe(1); + new B(); + } +} +new ComputedField(); diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/reason.txt b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/reason.txt new file mode 100644 index 00000000000000..2637988f084f02 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/reason.txt @@ -0,0 +1,2 @@ +Disable arrow functions transform in `options.json` because it malfunctions. +But these fixtures aren't to test arrow functions transform. diff --git a/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/multiple-super-in-termary/output.js b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/multiple-super-in-termary/output.js new file mode 100644 index 00000000000000..2bda1d4d7495c7 --- /dev/null +++ b/tasks/transform_conformance/overrides/babel-plugin-transform-class-properties/test/fixtures/regression/multiple-super-in-termary/output.js @@ -0,0 +1,10 @@ +class A extends B { + constructor() { + var _super = (..._args) => { + super(..._args); + babelHelpers.defineProperty(this, "x", 2); + return this; + }; + x ? _super(a) : _super(b); + } +} diff --git a/tasks/transform_conformance/snapshots/babel.snap.md b/tasks/transform_conformance/snapshots/babel.snap.md index 9dec5816de3334..73697f9a71a303 100644 --- a/tasks/transform_conformance/snapshots/babel.snap.md +++ b/tasks/transform_conformance/snapshots/babel.snap.md @@ -1,6 +1,6 @@ commit: 54a8389f -Passed: 427/846 +Passed: 434/846 # All Passed: * babel-plugin-transform-class-static-block @@ -276,7 +276,7 @@ x Output mismatch x Output mismatch -# babel-plugin-transform-class-properties (100/264) +# babel-plugin-transform-class-properties (107/264) * assumption-constantSuper/complex-super-class/input.js x Output mismatch @@ -429,9 +429,6 @@ x Output mismatch * private/constructor-collision/input.js x Output mismatch -* private/derived-multiple-supers/input.js -x Output mismatch - * private/extracted-this/input.js x Output mismatch @@ -518,7 +515,33 @@ rebuilt : ScopeId(5): Some(ScopeId(0)) x Output mismatch * private/regression-T7364/input.mjs -x Output mismatch +Scope children mismatch: +after transform: ScopeId(1): [ScopeId(2), ScopeId(7)] +rebuilt : ScopeId(1): [ScopeId(2)] +Scope children mismatch: +after transform: ScopeId(7): [] +rebuilt : ScopeId(2): [ScopeId(3)] +Scope parent mismatch: +after transform: ScopeId(2): Some(ScopeId(1)) +rebuilt : ScopeId(3): Some(ScopeId(2)) +Scope children mismatch: +after transform: ScopeId(3): [ScopeId(4), ScopeId(8)] +rebuilt : ScopeId(4): [ScopeId(5)] +Scope children mismatch: +after transform: ScopeId(8): [] +rebuilt : ScopeId(5): [ScopeId(6)] +Scope parent mismatch: +after transform: ScopeId(4): Some(ScopeId(3)) +rebuilt : ScopeId(6): Some(ScopeId(5)) +Scope children mismatch: +after transform: ScopeId(5): [ScopeId(6), ScopeId(9)] +rebuilt : ScopeId(7): [ScopeId(8)] +Scope children mismatch: +after transform: ScopeId(9): [] +rebuilt : ScopeId(8): [ScopeId(9)] +Scope parent mismatch: +after transform: ScopeId(6): Some(ScopeId(5)) +rebuilt : ScopeId(9): Some(ScopeId(8)) * private/static-call/input.js Scope children mismatch: @@ -792,26 +815,35 @@ x Output mismatch * public/computed/input.js x Output mismatch -* public/computed-toPrimitive/input.js -x Output mismatch - * public/constructor-collision/input.js x Output mismatch * public/delete-super-property/input.js x Output mismatch -* public/derived-multiple-supers/input.js -x Output mismatch - * public/derived-super-in-default-params/input.js -x Output mismatch +Scope flags mismatch: +after transform: ScopeId(3): ScopeFlags(StrictMode | Function | Arrow) +rebuilt : ScopeId(1): ScopeFlags(Function) +Symbol flags mismatch for "_super": +after transform: SymbolId(2): SymbolFlags(FunctionScopedVariable) +rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable) * public/derived-super-in-default-params-complex/input.js -x Output mismatch +Scope flags mismatch: +after transform: ScopeId(3): ScopeFlags(StrictMode | Function | Arrow) +rebuilt : ScopeId(1): ScopeFlags(Function) +Symbol flags mismatch for "_super": +after transform: SymbolId(2): SymbolFlags(FunctionScopedVariable) +rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable) * public/derived-super-in-default-params-in-arrow/input.js -x Output mismatch +Scope flags mismatch: +after transform: ScopeId(4): ScopeFlags(StrictMode | Function | Arrow) +rebuilt : ScopeId(1): ScopeFlags(Function) +Symbol flags mismatch for "_super": +after transform: SymbolId(2): SymbolFlags(FunctionScopedVariable) +rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable) * public/extracted-this/input.js x Output mismatch @@ -890,9 +922,6 @@ Scope parent mismatch: after transform: ScopeId(2): Some(ScopeId(1)) rebuilt : ScopeId(2): Some(ScopeId(0)) -* public/super-expression/input.js -x Output mismatch - * public/super-with-collision/input.js x Output mismatch @@ -909,7 +938,15 @@ x Output mismatch x Output mismatch * public-loose/foobar/input.js -x Output mismatch +Scope children mismatch: +after transform: ScopeId(1): [ScopeId(2), ScopeId(3)] +rebuilt : ScopeId(1): [ScopeId(2)] +Scope children mismatch: +after transform: ScopeId(2): [] +rebuilt : ScopeId(2): [ScopeId(3)] +Scope parent mismatch: +after transform: ScopeId(3): Some(ScopeId(1)) +rebuilt : ScopeId(3): Some(ScopeId(2)) * public-loose/regression-T7364/input.mjs Scope children mismatch: @@ -974,9 +1011,6 @@ Scope parent mismatch: after transform: ScopeId(2): Some(ScopeId(1)) rebuilt : ScopeId(2): Some(ScopeId(0)) -* public-loose/super-expression/input.js -x Output mismatch - * public-loose/super-with-collision/input.js x Output mismatch @@ -986,9 +1020,6 @@ x Output mismatch * regression/6154/input.js x Output mismatch -* regression/7371/input.js -x Output mismatch - * regression/7951/input.mjs x Output mismatch @@ -1035,9 +1066,6 @@ Scope parent mismatch: after transform: ScopeId(6): Some(ScopeId(5)) rebuilt : ScopeId(9): Some(ScopeId(8)) -* regression/multiple-super-in-termary/input.js -x Output mismatch - # babel-plugin-transform-nullish-coalescing-operator (5/12) * assumption-noDocumentAll/transform/input.js diff --git a/tasks/transform_conformance/snapshots/babel_exec.snap.md b/tasks/transform_conformance/snapshots/babel_exec.snap.md index c77c0a24aacd3d..fcbc6425e8893f 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: 187 of 215 (86.98%) +Passed: 188 of 215 (87.44%) Failures: @@ -100,9 +100,6 @@ AssertionError: expected '_Class' to be 'Foo' // Object.is equality ./fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-public-static-super-exec.test.js Invalid access to super -./fixtures/babel/babel-plugin-transform-class-properties-test-fixtures-regression-7371-exec.test.js -'super' keyword unexpected here - ./fixtures/babel/babel-plugin-transform-optional-chaining-test-fixtures-assumption-noDocumentAll-parenthesized-expression-member-call-exec.test.js TypeError: Cannot read properties of undefined (reading 'x') at m (./tasks/transform_conformance/fixtures/babel/babel-plugin-transform-optional-chaining-test-fixtures-assumption-noDocumentAll-parenthesized-expression-member-call-exec.test.js:10:16)