Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Deleting super property should throw (#15223)
Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com> Fixes #15169
- Loading branch information
1 parent
00783f5
commit 2bba4a5
Showing
13 changed files
with
305 additions
and
5 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
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
15 changes: 15 additions & 0 deletions
15
...babel-plugin-proposal-class-properties/test/fixtures/public/delete-super-property/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,15 @@ | ||
expect(() => { | ||
new class { y = delete super.x; }; | ||
}).toThrow(ReferenceError); | ||
|
||
expect(() => { | ||
new class { y = delete super[0]; }; | ||
}).toThrow(ReferenceError); | ||
|
||
expect(() => { | ||
class X1 { static y = delete super.x; } | ||
}).toThrow(ReferenceError); | ||
|
||
expect(() => { | ||
class X2 { static y = delete super[0]; } | ||
}).toThrow(ReferenceError); |
7 changes: 7 additions & 0 deletions
7
...abel-plugin-proposal-class-properties/test/fixtures/public/delete-super-property/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,7 @@ | ||
new class { y = delete super.x; }; | ||
|
||
new class { y = delete super[0]; }; | ||
|
||
class X1 { static y = delete super.x; } | ||
|
||
class X2 { static y = delete super[0]; } |
38 changes: 38 additions & 0 deletions
38
...bel-plugin-proposal-class-properties/test/fixtures/public/delete-super-property/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,38 @@ | ||
new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class2() { | ||
babelHelpers.classCallCheck(this, _class2); | ||
babelHelpers.defineProperty(this, "y", function () { | ||
throw new ReferenceError("'delete super.prop' is invalid"); | ||
}()); | ||
} | ||
return babelHelpers.createClass(_class2); | ||
}())(); | ||
new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class4() { | ||
babelHelpers.classCallCheck(this, _class4); | ||
babelHelpers.defineProperty(this, "y", (babelHelpers.toPropertyKey(0), function () { | ||
throw new ReferenceError("'delete super[expr]' is invalid"); | ||
}())); | ||
} | ||
return babelHelpers.createClass(_class4); | ||
}())(); | ||
var X1 = /*#__PURE__*/babelHelpers.createClass(function X1() { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, X1); | ||
}); | ||
babelHelpers.defineProperty(X1, "y", function () { | ||
throw new ReferenceError("'delete super.prop' is invalid"); | ||
}()); | ||
var X2 = /*#__PURE__*/babelHelpers.createClass(function X2() { | ||
"use strict"; | ||
|
||
babelHelpers.classCallCheck(this, X2); | ||
}); | ||
babelHelpers.defineProperty(X2, "y", (babelHelpers.toPropertyKey(0), function () { | ||
throw new ReferenceError("'delete super[expr]' is invalid"); | ||
}())); |
23 changes: 23 additions & 0 deletions
23
...plugin-transform-classes/test/fixtures/spec/delete-super-property-to-property-key/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,23 @@ | ||
// [Symbol.toPrimitive] must be called if exist | ||
var counter = 0; | ||
expect(() => { | ||
(new class { | ||
f() { | ||
delete super[{ | ||
[Symbol.toPrimitive]: function() { ++counter; return 0; }, | ||
}]; | ||
} | ||
}).f(); | ||
}).toThrow(ReferenceError); | ||
expect(counter).toBe(1); | ||
|
||
// [Symbol.toPrimitive] must return a primitive value | ||
expect(() => { | ||
(new class { | ||
f() { | ||
delete super[{ | ||
[Symbol.toPrimitive]: function() { return {}; }, | ||
}]; | ||
} | ||
}).f(); | ||
}).toThrow(TypeError); |
18 changes: 18 additions & 0 deletions
18
...lugin-transform-classes/test/fixtures/spec/delete-super-property-to-property-key/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,18 @@ | ||
// [Symbol.toPrimitive] must be called if exist | ||
var counter = 0; | ||
(new class { | ||
f() { | ||
delete super[{ | ||
[Symbol.toPrimitive]: function() { ++counter; return 0; }, | ||
}]; | ||
} | ||
}).f(); | ||
|
||
// [Symbol.toPrimitive] must return a primitive value | ||
(new class { | ||
f() { | ||
delete super[{ | ||
[Symbol.toPrimitive]: function() { return {}; }, | ||
}]; | ||
} | ||
}).f(); |
45 changes: 45 additions & 0 deletions
45
...ugin-transform-classes/test/fixtures/spec/delete-super-property-to-property-key/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,45 @@ | ||
// [Symbol.toPrimitive] must be called if exist | ||
var counter = 0; | ||
new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class() { | ||
babelHelpers.classCallCheck(this, _class); | ||
} | ||
babelHelpers.createClass(_class, [{ | ||
key: "f", | ||
value: function f() { | ||
babelHelpers.toPropertyKey({ | ||
[Symbol.toPrimitive]: function () { | ||
++counter; | ||
return 0; | ||
} | ||
}), function () { | ||
throw new ReferenceError("'delete super[expr]' is invalid"); | ||
}(); | ||
} | ||
}]); | ||
return _class; | ||
}())().f(); | ||
|
||
// [Symbol.toPrimitive] must return a primitive value | ||
new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class2() { | ||
babelHelpers.classCallCheck(this, _class2); | ||
} | ||
babelHelpers.createClass(_class2, [{ | ||
key: "f", | ||
value: function f() { | ||
babelHelpers.toPropertyKey({ | ||
[Symbol.toPrimitive]: function () { | ||
return {}; | ||
} | ||
}), function () { | ||
throw new ReferenceError("'delete super[expr]' is invalid"); | ||
}(); | ||
} | ||
}]); | ||
return _class2; | ||
}())().f(); |
27 changes: 27 additions & 0 deletions
27
packages/babel-plugin-transform-classes/test/fixtures/spec/delete-super-property/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,27 @@ | ||
expect(() => { | ||
(new class { | ||
f() { delete super.x; } | ||
}).f(); | ||
}).toThrow(ReferenceError); | ||
|
||
expect(() => { | ||
(new class { | ||
f() { delete super[0]; } | ||
}).f(); | ||
}).toThrow(ReferenceError); | ||
|
||
// [expr] should be evaluated | ||
var counter = 0; | ||
expect(() => { | ||
(new class { | ||
f() { delete super[++counter]; } | ||
}).f(); | ||
}).toThrow(ReferenceError); | ||
expect(counter).toBe(1); | ||
|
||
// TypeError before ReferenceError | ||
expect(() => { | ||
(new class { | ||
f() { delete super[0()]; } | ||
}).f(); | ||
}).toThrow(TypeError); |
18 changes: 18 additions & 0 deletions
18
packages/babel-plugin-transform-classes/test/fixtures/spec/delete-super-property/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,18 @@ | ||
(new class { | ||
f() { delete super.x; } | ||
}).f(); | ||
|
||
(new class { | ||
f() { delete super[0]; } | ||
}).f(); | ||
|
||
// [expr] should be evaluated | ||
var counter = 0; | ||
(new class { | ||
f() { delete super[++counter]; } | ||
}).f(); | ||
|
||
// TypeError before ReferenceError | ||
(new class { | ||
f() { delete super[0()]; } | ||
}).f(); |
69 changes: 69 additions & 0 deletions
69
packages/babel-plugin-transform-classes/test/fixtures/spec/delete-super-property/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,69 @@ | ||
new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class() { | ||
babelHelpers.classCallCheck(this, _class); | ||
} | ||
babelHelpers.createClass(_class, [{ | ||
key: "f", | ||
value: function f() { | ||
(function () { | ||
throw new ReferenceError("'delete super.prop' is invalid"); | ||
})(); | ||
} | ||
}]); | ||
return _class; | ||
}())().f(); | ||
new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class2() { | ||
babelHelpers.classCallCheck(this, _class2); | ||
} | ||
babelHelpers.createClass(_class2, [{ | ||
key: "f", | ||
value: function f() { | ||
babelHelpers.toPropertyKey(0), function () { | ||
throw new ReferenceError("'delete super[expr]' is invalid"); | ||
}(); | ||
} | ||
}]); | ||
return _class2; | ||
}())().f(); | ||
|
||
// [expr] should be evaluated | ||
var counter = 0; | ||
new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class3() { | ||
babelHelpers.classCallCheck(this, _class3); | ||
} | ||
babelHelpers.createClass(_class3, [{ | ||
key: "f", | ||
value: function f() { | ||
babelHelpers.toPropertyKey(++counter), function () { | ||
throw new ReferenceError("'delete super[expr]' is invalid"); | ||
}(); | ||
} | ||
}]); | ||
return _class3; | ||
}())().f(); | ||
|
||
// TypeError before ReferenceError | ||
new ( /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function _class4() { | ||
babelHelpers.classCallCheck(this, _class4); | ||
} | ||
babelHelpers.createClass(_class4, [{ | ||
key: "f", | ||
value: function f() { | ||
babelHelpers.toPropertyKey(0()), function () { | ||
throw new ReferenceError("'delete super[expr]' is invalid"); | ||
}(); | ||
} | ||
}]); | ||
return _class4; | ||
}())().f(); |
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