forked from babel/babel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix redeclaringing private in nested class's superClass
If a nested class's `superClass` redeclares the outer class's private field and access it in a computed key, that should fail. Follow up to babel#11405.
- Loading branch information
1 parent
9b48a8e
commit df89c49
Showing
17 changed files
with
415 additions
and
2 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
19 changes: 19 additions & 0 deletions
19
...sal-class-properties/test/fixtures/private-loose/nested-class-computed-redeclared/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,19 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested { | ||
#foo = 2; | ||
|
||
[this.#foo]() { | ||
} | ||
} | ||
|
||
return new Nested(); | ||
} | ||
} | ||
|
||
const f = new Foo(); | ||
expect(() => { | ||
f.test(); | ||
}).toThrow(); |
17 changes: 17 additions & 0 deletions
17
...lugin-proposal-class-properties/test/fixtures/private-loose/nested-class-computed/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 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested { | ||
[this.#foo]() { | ||
} | ||
} | ||
|
||
return new Nested(); | ||
} | ||
} | ||
|
||
const f = new Foo(); | ||
expect(() => { | ||
f.test(); | ||
}).not.toThrow(); |
18 changes: 18 additions & 0 deletions
18
...s-properties/test/fixtures/private-loose/nested-class-extends-computed-redeclared/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,18 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested extends class { | ||
#foo = 2; | ||
|
||
[this.#foo] = 2; | ||
} { | ||
#foo = 3; | ||
} | ||
} | ||
} | ||
|
||
const f = new Foo(); | ||
expect(() => { | ||
f.test(); | ||
}).toThrow(); |
12 changes: 12 additions & 0 deletions
12
...-properties/test/fixtures/private-loose/nested-class-extends-computed-redeclared/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,12 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested extends class { | ||
#foo = 2; | ||
[this.#foo] = 2; | ||
} { | ||
#foo = 3; | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...properties/test/fixtures/private-loose/nested-class-extends-computed-redeclared/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,56 @@ | ||
var Foo = /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function Foo() { | ||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, _foo, { | ||
writable: true, | ||
value: 1 | ||
}); | ||
} | ||
|
||
babelHelpers.createClass(Foo, [{ | ||
key: "test", | ||
value: function test() { | ||
var _temp, _foo3; | ||
|
||
var _babelHelpers$classPr; | ||
|
||
var Nested = /*#__PURE__*/function (_ref) { | ||
babelHelpers.inherits(Nested, _ref); | ||
|
||
var _super = babelHelpers.createSuper(Nested); | ||
|
||
function Nested(...args) { | ||
var _this; | ||
|
||
babelHelpers.classCallCheck(this, Nested); | ||
_this = _super.call(this, ...args); | ||
Object.defineProperty(babelHelpers.assertThisInitialized(_this), _foo2, { | ||
writable: true, | ||
value: 3 | ||
}); | ||
return _this; | ||
} | ||
|
||
return Nested; | ||
}((_temp = (_babelHelpers$classPr = babelHelpers.classPrivateFieldLooseBase(this, _foo3)[_foo3], /*#__PURE__*/function () { | ||
function _class2() { | ||
babelHelpers.classCallCheck(this, _class2); | ||
Object.defineProperty(this, _foo3, { | ||
writable: true, | ||
value: 2 | ||
}); | ||
this[_babelHelpers$classPr] = 2; | ||
} | ||
|
||
return _class2; | ||
}()), _foo3 = babelHelpers.classPrivateFieldLooseKey("foo"), _temp)); | ||
|
||
var _foo2 = babelHelpers.classPrivateFieldLooseKey("foo"); | ||
} | ||
}]); | ||
return Foo; | ||
}(); | ||
|
||
var _foo = babelHelpers.classPrivateFieldLooseKey("foo"); |
18 changes: 18 additions & 0 deletions
18
...oposal-class-properties/test/fixtures/private-loose/nested-class-extends-computed/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,18 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested extends class { | ||
[this.#foo] = 2; | ||
} { | ||
#foo = 3; | ||
} | ||
|
||
return new Nested(); | ||
} | ||
} | ||
|
||
const f = new Foo(); | ||
expect(() => { | ||
f.test(); | ||
}).not.toThrow(); |
11 changes: 11 additions & 0 deletions
11
...posal-class-properties/test/fixtures/private-loose/nested-class-extends-computed/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 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested extends class { | ||
[this.#foo] = 2; | ||
} { | ||
#foo = 3; | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...osal-class-properties/test/fixtures/private-loose/nested-class-extends-computed/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,52 @@ | ||
var Foo = /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function Foo() { | ||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, _foo, { | ||
writable: true, | ||
value: 1 | ||
}); | ||
} | ||
|
||
babelHelpers.createClass(Foo, [{ | ||
key: "test", | ||
value: function test() { | ||
var _temp; | ||
|
||
var _babelHelpers$classPr; | ||
|
||
var Nested = /*#__PURE__*/function (_ref) { | ||
babelHelpers.inherits(Nested, _ref); | ||
|
||
var _super = babelHelpers.createSuper(Nested); | ||
|
||
function Nested(...args) { | ||
var _this; | ||
|
||
babelHelpers.classCallCheck(this, Nested); | ||
_this = _super.call(this, ...args); | ||
Object.defineProperty(babelHelpers.assertThisInitialized(_this), _foo2, { | ||
writable: true, | ||
value: 3 | ||
}); | ||
return _this; | ||
} | ||
|
||
return Nested; | ||
}((_temp = (_babelHelpers$classPr = babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo], /*#__PURE__*/function () { | ||
function _class2() { | ||
babelHelpers.classCallCheck(this, _class2); | ||
this[_babelHelpers$classPr] = 2; | ||
} | ||
|
||
return _class2; | ||
}()), _temp)); | ||
|
||
var _foo2 = babelHelpers.classPrivateFieldLooseKey("foo"); | ||
} | ||
}]); | ||
return Foo; | ||
}(); | ||
|
||
var _foo = babelHelpers.classPrivateFieldLooseKey("foo"); |
19 changes: 19 additions & 0 deletions
19
...-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/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,19 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested { | ||
#foo = 2; | ||
|
||
[this.#foo]() { | ||
} | ||
} | ||
|
||
return new Nested(); | ||
} | ||
} | ||
|
||
const f = new Foo(); | ||
expect(() => { | ||
f.test(); | ||
}).toThrow(); |
17 changes: 17 additions & 0 deletions
17
...abel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed/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 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested { | ||
[this.#foo]() { | ||
} | ||
} | ||
|
||
return new Nested(); | ||
} | ||
} | ||
|
||
const f = new Foo(); | ||
expect(() => { | ||
f.test(); | ||
}).not.toThrow(); |
18 changes: 18 additions & 0 deletions
18
...l-class-properties/test/fixtures/private/nested-class-extends-computed-redeclared/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,18 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested extends class { | ||
#foo = 2; | ||
|
||
[this.#foo] = 2; | ||
} { | ||
#foo = 3; | ||
} | ||
} | ||
} | ||
|
||
const f = new Foo(); | ||
expect(() => { | ||
f.test(); | ||
}).toThrow(); |
12 changes: 12 additions & 0 deletions
12
...-class-properties/test/fixtures/private/nested-class-extends-computed-redeclared/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,12 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested extends class { | ||
#foo = 2; | ||
[this.#foo] = 2; | ||
} { | ||
#foo = 3; | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...class-properties/test/fixtures/private/nested-class-extends-computed-redeclared/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,61 @@ | ||
var Foo = /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function Foo() { | ||
babelHelpers.classCallCheck(this, Foo); | ||
|
||
_foo.set(this, { | ||
writable: true, | ||
value: 1 | ||
}); | ||
} | ||
|
||
babelHelpers.createClass(Foo, [{ | ||
key: "test", | ||
value: function test() { | ||
var _temp, _foo3; | ||
|
||
var _babelHelpers$classPr; | ||
|
||
var Nested = /*#__PURE__*/function (_ref) { | ||
babelHelpers.inherits(Nested, _ref); | ||
|
||
var _super = babelHelpers.createSuper(Nested); | ||
|
||
function Nested(...args) { | ||
var _this; | ||
|
||
babelHelpers.classCallCheck(this, Nested); | ||
_this = _super.call(this, ...args); | ||
|
||
_foo2.set(babelHelpers.assertThisInitialized(_this), { | ||
writable: true, | ||
value: 3 | ||
}); | ||
|
||
return _this; | ||
} | ||
|
||
return Nested; | ||
}((_temp = (_babelHelpers$classPr = babelHelpers.classPrivateFieldGet(this, _foo3), /*#__PURE__*/function () { | ||
function _class2() { | ||
babelHelpers.classCallCheck(this, _class2); | ||
|
||
_foo3.set(this, { | ||
writable: true, | ||
value: 2 | ||
}); | ||
|
||
babelHelpers.defineProperty(this, _babelHelpers$classPr, 2); | ||
} | ||
|
||
return _class2; | ||
}()), _foo3 = new WeakMap(), _temp)); | ||
|
||
var _foo2 = new WeakMap(); | ||
} | ||
}]); | ||
return Foo; | ||
}(); | ||
|
||
var _foo = new WeakMap(); |
18 changes: 18 additions & 0 deletions
18
...gin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed/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,18 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested extends class { | ||
[this.#foo] = 2; | ||
} { | ||
#foo = 3; | ||
} | ||
|
||
return new Nested(); | ||
} | ||
} | ||
|
||
const f = new Foo(); | ||
expect(() => { | ||
f.test(); | ||
}).not.toThrow(); |
11 changes: 11 additions & 0 deletions
11
...in-proposal-class-properties/test/fixtures/private/nested-class-extends-computed/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 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested extends class { | ||
[this.#foo] = 2; | ||
} { | ||
#foo = 3; | ||
} | ||
} | ||
} |
Oops, something went wrong.