New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix nested classes reference private fields #11405
Merged
nicolo-ribaudo
merged 5 commits into
babel:master
from
jridgewell:nested-private-redeclare
Apr 14, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
808445b
Fix nested classes reference private fields
jridgewell 995a6be
Process only visible private fields when redeclaring
jridgewell d450792
Comments
jridgewell 27a09f1
Skip class traversal if there are no private fields
jridgewell 3a673dc
Handle redeclared private field in computed key
jridgewell File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a case on redeclared private names with computed key reference? The following case should throw since
#foo
is shadowed.Given that it is not directly related to this PR, we can fix it in a separate one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we wait till the other PR to add the test case? It's going to be much harder to fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I have a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I meant we can add the new case and the fixes in a separate PR, my bad. As long as you come up with a fix, that's awesome! 😄