Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: apply toPropertyKey when defining class members (#15182)
Fixes #15178
- Loading branch information
Showing
14 changed files
with
295 additions
and
8 deletions.
There are no files selected for viewing
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
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
17 changes: 17 additions & 0 deletions
17
.../babel-plugin-proposal-class-properties/test/fixtures/public/computed-toPrimitive/exec.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,17 @@ | ||
const foo = { [Symbol.toPrimitive]: () => "foo" }; | ||
|
||
expect((class { static [foo] = 0 }).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 { [foo] = 0 }).foo).toBe(0); | ||
|
||
const arrayLike = { [Symbol.toPrimitive] : () => [] }; | ||
|
||
expect(() => class { static [arrayLike] = 0 }).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => class { static [arrayLike](){ return 0; } }).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => class { static get [arrayLike](){ return 0; } }).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => class { static set [arrayLike](v){ return v; } }).toThrowError("@@toPrimitive must return a primitive value."); | ||
|
||
expect(() => new class { [arrayLike] = 0 }).toThrowError("@@toPrimitive must return a primitive value."); |
17 changes: 17 additions & 0 deletions
17
...babel-plugin-proposal-class-properties/test/fixtures/public/computed-toPrimitive/input.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,17 @@ | ||
const foo = { [Symbol.toPrimitive]: () => "foo" }; | ||
|
||
expect((class { static [foo] = 0 }).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 { [foo] = 0 }).foo).toBe(0); | ||
|
||
const arrayLike = { [Symbol.toPrimitive] : () => [] }; | ||
|
||
expect(() => class { static [arrayLike] = 0 }).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => class { static [arrayLike](){ return 0; } }).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => class { static get [arrayLike](){ return 0; } }).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => class { static set [arrayLike](v){ return v; } }).toThrowError("@@toPrimitive must return a primitive value."); | ||
|
||
expect(() => new class { [arrayLike] = 0 }).toThrowError("@@toPrimitive must return a primitive value."); |
122 changes: 122 additions & 0 deletions
122
...abel-plugin-proposal-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,122 @@ | ||
var _class; | ||
var foo = { | ||
[Symbol.toPrimitive]: () => "foo" | ||
}; | ||
expect((_class = /*#__PURE__*/babelHelpers.createClass(function _class() { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, _class); | ||
}), babelHelpers.defineProperty(_class, foo, 0), _class).foo).toBe(0); | ||
expect( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class2() { | ||
babelHelpers.classCallCheck(this, _class2); | ||
} | ||
babelHelpers.createClass(_class2, null, [{ | ||
key: foo, | ||
value: function () { | ||
return 0; | ||
} | ||
}]); | ||
return _class2; | ||
}().foo()).toBe(0); | ||
expect( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class3() { | ||
babelHelpers.classCallCheck(this, _class3); | ||
} | ||
babelHelpers.createClass(_class3, null, [{ | ||
key: foo, | ||
get: function () { | ||
return 0; | ||
} | ||
}]); | ||
return _class3; | ||
}().foo).toBe(0); | ||
expect( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class4() { | ||
babelHelpers.classCallCheck(this, _class4); | ||
} | ||
babelHelpers.createClass(_class4, null, [{ | ||
key: foo, | ||
set: function (v) { | ||
return v; | ||
} | ||
}]); | ||
return _class4; | ||
}().foo = 0).toBe(0); | ||
expect(new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class6() { | ||
babelHelpers.classCallCheck(this, _class6); | ||
babelHelpers.defineProperty(this, foo, 0); | ||
} | ||
return babelHelpers.createClass(_class6); | ||
}())().foo).toBe(0); | ||
var arrayLike = { | ||
[Symbol.toPrimitive]: () => [] | ||
}; | ||
expect(() => { | ||
var _class7; | ||
return _class7 = /*#__PURE__*/babelHelpers.createClass(function _class7() { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, _class7); | ||
}), babelHelpers.defineProperty(_class7, arrayLike, 0), _class7; | ||
}).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class8() { | ||
babelHelpers.classCallCheck(this, _class8); | ||
} | ||
babelHelpers.createClass(_class8, null, [{ | ||
key: arrayLike, | ||
value: function () { | ||
return 0; | ||
} | ||
}]); | ||
return _class8; | ||
}()).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class9() { | ||
babelHelpers.classCallCheck(this, _class9); | ||
} | ||
babelHelpers.createClass(_class9, null, [{ | ||
key: arrayLike, | ||
get: function () { | ||
return 0; | ||
} | ||
}]); | ||
return _class9; | ||
}()).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class10() { | ||
babelHelpers.classCallCheck(this, _class10); | ||
} | ||
babelHelpers.createClass(_class10, null, [{ | ||
key: arrayLike, | ||
set: function (v) { | ||
return v; | ||
} | ||
}]); | ||
return _class10; | ||
}()).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class12() { | ||
babelHelpers.classCallCheck(this, _class12); | ||
babelHelpers.defineProperty(this, arrayLike, 0); | ||
} | ||
return babelHelpers.createClass(_class12); | ||
}())()).toThrowError("@@toPrimitive must return a primitive value."); |
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
11 changes: 11 additions & 0 deletions
11
packages/babel-plugin-transform-classes/test/fixtures/spec/computed-toPrimitive/exec.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,11 @@ | ||
const foo = { [Symbol.toPrimitive]: () => "foo" }; | ||
|
||
expect((new class { [foo](){ return 0; } }).foo()).toBe(0); | ||
expect((new class { get [foo](){ return 0; } }).foo).toBe(0); | ||
expect((new class { set [foo](v){ return v; } }).foo = 0).toBe(0); | ||
|
||
const arrayLike = { [Symbol.toPrimitive] : () => [] }; | ||
|
||
expect(() => new class { [arrayLike](){ return 0; } }).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => new class { get [arrayLike](){ return 0; } }).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => new class { set [arrayLike](v){ return v; } }).toThrowError("@@toPrimitive must return a primitive value."); |
11 changes: 11 additions & 0 deletions
11
packages/babel-plugin-transform-classes/test/fixtures/spec/computed-toPrimitive/input.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,11 @@ | ||
const foo = { [Symbol.toPrimitive]: () => "foo" }; | ||
|
||
expect((new class { [foo](){ return 0; } }).foo()).toBe(0); | ||
expect((new class { get [foo](){ return 0; } }).foo).toBe(0); | ||
expect((new class { set [foo](v){ return v; } }).foo = 0).toBe(0); | ||
|
||
const arrayLike = { [Symbol.toPrimitive] : () => [] }; | ||
|
||
expect(() => new class { [arrayLike](){ return 0; } }).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => new class { get [arrayLike](){ return 0; } }).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => new class { set [arrayLike](v){ return v; } }).toThrowError("@@toPrimitive must return a primitive value."); |
90 changes: 90 additions & 0 deletions
90
packages/babel-plugin-transform-classes/test/fixtures/spec/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,90 @@ | ||
var foo = { | ||
[Symbol.toPrimitive]: () => "foo" | ||
}; | ||
expect(new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class() { | ||
babelHelpers.classCallCheck(this, _class); | ||
} | ||
babelHelpers.createClass(_class, [{ | ||
key: foo, | ||
value: function value() { | ||
return 0; | ||
} | ||
}]); | ||
return _class; | ||
}())().foo()).toBe(0); | ||
expect(new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class2() { | ||
babelHelpers.classCallCheck(this, _class2); | ||
} | ||
babelHelpers.createClass(_class2, [{ | ||
key: foo, | ||
get: function get() { | ||
return 0; | ||
} | ||
}]); | ||
return _class2; | ||
}())().foo).toBe(0); | ||
expect(new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class3() { | ||
babelHelpers.classCallCheck(this, _class3); | ||
} | ||
babelHelpers.createClass(_class3, [{ | ||
key: foo, | ||
set: function set(v) { | ||
return v; | ||
} | ||
}]); | ||
return _class3; | ||
}())().foo = 0).toBe(0); | ||
var arrayLike = { | ||
[Symbol.toPrimitive]: () => [] | ||
}; | ||
expect(() => new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class4() { | ||
babelHelpers.classCallCheck(this, _class4); | ||
} | ||
babelHelpers.createClass(_class4, [{ | ||
key: arrayLike, | ||
value: function value() { | ||
return 0; | ||
} | ||
}]); | ||
return _class4; | ||
}())()).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class5() { | ||
babelHelpers.classCallCheck(this, _class5); | ||
} | ||
babelHelpers.createClass(_class5, [{ | ||
key: arrayLike, | ||
get: function get() { | ||
return 0; | ||
} | ||
}]); | ||
return _class5; | ||
}())()).toThrowError("@@toPrimitive must return a primitive value."); | ||
expect(() => new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class6() { | ||
babelHelpers.classCallCheck(this, _class6); | ||
} | ||
babelHelpers.createClass(_class6, [{ | ||
key: arrayLike, | ||
set: function set(v) { | ||
return v; | ||
} | ||
}]); | ||
return _class6; | ||
}())()).toThrowError("@@toPrimitive must return a primitive value."); |
5 changes: 4 additions & 1 deletion
5
packages/babel-plugin-transform-runtime/test/fixtures/runtime-corejs2/no-helpers/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 4 additions & 1 deletion
5
packages/babel-plugin-transform-runtime/test/fixtures/runtime-corejs3/no-helpers/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 3 additions & 1 deletion
4
packages/babel-plugin-transform-runtime/test/fixtures/runtime/no-helpers/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.