-
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(transformer/class-properties): override fixtures (#7689)
Override some transform conformance test fixtures for class properties transform, where: * Our output differs from Babel in cosmetic manner only. * Our transform intentionally works differently from Babel. * Babel's fixtures enable arrow functions transform, which malfunctions in our implementation. But we're not trying to test arrow functions transform here, so disable it.
- Loading branch information
1 parent
efaaa97
commit 5fd1361
Showing
17 changed files
with
324 additions
and
32 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...plugin-transform-class-properties/test/fixtures/private/derived-multiple-supers/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...babel-plugin-transform-class-properties/test/fixtures/private/regression-T7364/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
})); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...es/babel-plugin-transform-class-properties/test/fixtures/public-loose/foobar/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"transform-class-properties", | ||
{ | ||
"loose": true | ||
} | ||
] | ||
] | ||
} |
2 changes: 2 additions & 0 deletions
2
...ides/babel-plugin-transform-class-properties/test/fixtures/public-loose/foobar/reason.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Disable arrow functions transform in `options.json` because it malfunctions. | ||
But these fixtures aren't to test arrow functions transform. |
10 changes: 10 additions & 0 deletions
10
...l-plugin-transform-class-properties/test/fixtures/public-loose/super-expression/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Foo extends Bar { | ||
constructor() { | ||
var _super = (..._args) => { | ||
super(..._args); | ||
this.bar = "foo"; | ||
return this; | ||
}; | ||
foo(_super()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...bel-plugin-transform-class-properties/test/fixtures/public/computed-toPrimitive/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); |
15 changes: 15 additions & 0 deletions
15
...-plugin-transform-class-properties/test/fixtures/public/derived-multiple-supers/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...m-class-properties/test/fixtures/public/derived-super-in-default-params-complex/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) {} | ||
} |
9 changes: 9 additions & 0 deletions
9
...-class-properties/test/fixtures/public/derived-super-in-default-params-in-arrow/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
let _super = function() { | ||
babelHelpers.defineProperty(this, "bar", "foo"); | ||
return this; | ||
}; | ||
class Foo extends Bar { | ||
constructor(x = () => { | ||
check(_super.call(super())); | ||
}) {} | ||
} |
7 changes: 7 additions & 0 deletions
7
...transform-class-properties/test/fixtures/public/derived-super-in-default-params/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
let _super = function() { | ||
babelHelpers.defineProperty(this, "bar", "foo"); | ||
return this; | ||
}; | ||
class Foo extends Bar { | ||
constructor(x = _super.call(super())) {} | ||
} |
10 changes: 10 additions & 0 deletions
10
...s/babel-plugin-transform-class-properties/test/fixtures/public/super-expression/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Foo extends Bar { | ||
constructor() { | ||
var _super = (..._args) => { | ||
super(..._args); | ||
babelHelpers.defineProperty(this, "bar", "foo"); | ||
return this; | ||
}; | ||
foo(_super()); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...rrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"plugins": [ | ||
"transform-class-properties" | ||
] | ||
} |
89 changes: 89 additions & 0 deletions
89
...overrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
2 changes: 2 additions & 0 deletions
2
...verrides/babel-plugin-transform-class-properties/test/fixtures/regression/7371/reason.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Disable arrow functions transform in `options.json` because it malfunctions. | ||
But these fixtures aren't to test arrow functions transform. |
10 changes: 10 additions & 0 deletions
10
...n-transform-class-properties/test/fixtures/regression/multiple-super-in-termary/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.