Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix nested classes reference private fields (#11405)
* Fix nested classes reference private fields * Process only visible private fields when redeclaring * Comments * Skip class traversal if there are no private fields * Handle redeclared private field in computed key
- Loading branch information
1 parent
aaced01
commit 9b48a8e
Showing
21 changed files
with
597 additions
and
10 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
14 changes: 14 additions & 0 deletions
14
...al-class-properties/test/fixtures/private-loose/nested-class-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,14 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested { | ||
#foo = 2; | ||
|
||
[this.#foo]() { | ||
} | ||
} | ||
|
||
this.#foo; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...l-class-properties/test/fixtures/private-loose/nested-class-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,43 @@ | ||
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 _babelHelpers$classPr; | ||
|
||
_babelHelpers$classPr = babelHelpers.classPrivateFieldLooseBase(this, _foo2)[_foo2]; | ||
|
||
var Nested = /*#__PURE__*/function () { | ||
function Nested() { | ||
babelHelpers.classCallCheck(this, Nested); | ||
Object.defineProperty(this, _foo2, { | ||
writable: true, | ||
value: 2 | ||
}); | ||
} | ||
|
||
babelHelpers.createClass(Nested, [{ | ||
key: _babelHelpers$classPr, | ||
value: function () {} | ||
}]); | ||
return Nested; | ||
}(); | ||
|
||
var _foo2 = babelHelpers.classPrivateFieldLooseKey("foo"); | ||
|
||
babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo]; | ||
} | ||
}]); | ||
return Foo; | ||
}(); | ||
|
||
var _foo = babelHelpers.classPrivateFieldLooseKey("foo"); |
12 changes: 12 additions & 0 deletions
12
...ugin-proposal-class-properties/test/fixtures/private-loose/nested-class-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,12 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested { | ||
[this.#foo]() { | ||
} | ||
} | ||
|
||
this.#foo; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...gin-proposal-class-properties/test/fixtures/private-loose/nested-class-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,35 @@ | ||
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 _this = this; | ||
|
||
var Nested = /*#__PURE__*/function () { | ||
function Nested() { | ||
babelHelpers.classCallCheck(this, Nested); | ||
} | ||
|
||
babelHelpers.createClass(Nested, [{ | ||
key: babelHelpers.classPrivateFieldLooseBase(_this, _foo)[_foo], | ||
value: function () {} | ||
}]); | ||
return Nested; | ||
}(); | ||
|
||
babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo]; | ||
} | ||
}]); | ||
return Foo; | ||
}(); | ||
|
||
var _foo = babelHelpers.classPrivateFieldLooseKey("foo"); |
18 changes: 18 additions & 0 deletions
18
...posal-class-properties/test/fixtures/private-loose/nested-class-other-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,18 @@ | ||
class Foo { | ||
#foo = 1; | ||
#bar = 1; | ||
|
||
test() { | ||
class Nested { | ||
#bar = 2; | ||
|
||
test() { | ||
this.#foo; | ||
this.#bar; | ||
} | ||
} | ||
|
||
this.#foo; | ||
this.#bar; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...osal-class-properties/test/fixtures/private-loose/nested-class-other-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,49 @@ | ||
var Foo = /*#__PURE__*/function () { | ||
"use strict"; | ||
|
||
function Foo() { | ||
babelHelpers.classCallCheck(this, Foo); | ||
Object.defineProperty(this, _foo, { | ||
writable: true, | ||
value: 1 | ||
}); | ||
Object.defineProperty(this, _bar, { | ||
writable: true, | ||
value: 1 | ||
}); | ||
} | ||
|
||
babelHelpers.createClass(Foo, [{ | ||
key: "test", | ||
value: function test() { | ||
var Nested = /*#__PURE__*/function () { | ||
function Nested() { | ||
babelHelpers.classCallCheck(this, Nested); | ||
Object.defineProperty(this, _bar2, { | ||
writable: true, | ||
value: 2 | ||
}); | ||
} | ||
|
||
babelHelpers.createClass(Nested, [{ | ||
key: "test", | ||
value: function test() { | ||
babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo]; | ||
babelHelpers.classPrivateFieldLooseBase(this, _bar2)[_bar2]; | ||
} | ||
}]); | ||
return Nested; | ||
}(); | ||
|
||
var _bar2 = babelHelpers.classPrivateFieldLooseKey("bar"); | ||
|
||
babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo]; | ||
babelHelpers.classPrivateFieldLooseBase(this, _bar)[_bar]; | ||
} | ||
}]); | ||
return Foo; | ||
}(); | ||
|
||
var _foo = babelHelpers.classPrivateFieldLooseKey("foo"); | ||
|
||
var _bar = babelHelpers.classPrivateFieldLooseKey("bar"); |
15 changes: 15 additions & 0 deletions
15
...in-proposal-class-properties/test/fixtures/private-loose/nested-class-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,15 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested { | ||
#foo = 2; | ||
|
||
test() { | ||
this.#foo; | ||
} | ||
} | ||
|
||
this.#foo; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...n-proposal-class-properties/test/fixtures/private-loose/nested-class-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,41 @@ | ||
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 Nested = /*#__PURE__*/function () { | ||
function Nested() { | ||
babelHelpers.classCallCheck(this, Nested); | ||
Object.defineProperty(this, _foo2, { | ||
writable: true, | ||
value: 2 | ||
}); | ||
} | ||
|
||
babelHelpers.createClass(Nested, [{ | ||
key: "test", | ||
value: function test() { | ||
babelHelpers.classPrivateFieldLooseBase(this, _foo2)[_foo2]; | ||
} | ||
}]); | ||
return Nested; | ||
}(); | ||
|
||
var _foo2 = babelHelpers.classPrivateFieldLooseKey("foo"); | ||
|
||
babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo]; | ||
} | ||
}]); | ||
return Foo; | ||
}(); | ||
|
||
var _foo = babelHelpers.classPrivateFieldLooseKey("foo"); |
13 changes: 13 additions & 0 deletions
13
.../babel-plugin-proposal-class-properties/test/fixtures/private-loose/nested-class/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,13 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested { | ||
test() { | ||
this.#foo; | ||
} | ||
} | ||
|
||
this.#foo; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...babel-plugin-proposal-class-properties/test/fixtures/private-loose/nested-class/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,35 @@ | ||
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 Nested = /*#__PURE__*/function () { | ||
function Nested() { | ||
babelHelpers.classCallCheck(this, Nested); | ||
} | ||
|
||
babelHelpers.createClass(Nested, [{ | ||
key: "test", | ||
value: function test() { | ||
babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo]; | ||
} | ||
}]); | ||
return Nested; | ||
}(); | ||
|
||
babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo]; | ||
} | ||
}]); | ||
return Foo; | ||
}(); | ||
|
||
var _foo = babelHelpers.classPrivateFieldLooseKey("foo"); |
14 changes: 14 additions & 0 deletions
14
...proposal-class-properties/test/fixtures/private/nested-class-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,14 @@ | ||
class Foo { | ||
#foo = 1; | ||
|
||
test() { | ||
class Nested { | ||
#foo = 2; | ||
|
||
[this.#foo]() { | ||
} | ||
} | ||
|
||
this.#foo; | ||
} | ||
} |
Oops, something went wrong.