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
Changes from 4 commits
808445b
995a6be
d450792
27a09f1
3a673dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} | ||
} |
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"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Foo { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 class Foo {
#foo = 1;
test() {
class Nested {
#foo = 2;
[this.#foo] = 3;
}
new Nested;
}
}
(new Foo).test(); 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 commentThe 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 commentThe 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 commentThe 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! 😄 |
||
#foo = 1; | ||
|
||
test() { | ||
class Nested { | ||
#foo = 2; | ||
|
||
test() { | ||
this.#foo; | ||
} | ||
} | ||
|
||
this.#foo; | ||
} | ||
} |
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"); |
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; | ||
} | ||
} |
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"); |
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; | ||
} | ||
} |
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); | ||
|
||
_foo.set(this, { | ||
writable: true, | ||
value: 1 | ||
}); | ||
|
||
_bar.set(this, { | ||
writable: true, | ||
value: 1 | ||
}); | ||
} | ||
|
||
babelHelpers.createClass(Foo, [{ | ||
key: "test", | ||
value: function test() { | ||
var Nested = /*#__PURE__*/function () { | ||
function Nested() { | ||
babelHelpers.classCallCheck(this, Nested); | ||
|
||
_bar2.set(this, { | ||
writable: true, | ||
value: 2 | ||
}); | ||
} | ||
|
||
babelHelpers.createClass(Nested, [{ | ||
key: "test", | ||
value: function test() { | ||
babelHelpers.classPrivateFieldGet(this, _foo); | ||
babelHelpers.classPrivateFieldGet(this, _bar2); | ||
} | ||
}]); | ||
return Nested; | ||
}(); | ||
|
||
var _bar2 = new WeakMap(); | ||
|
||
babelHelpers.classPrivateFieldGet(this, _foo); | ||
babelHelpers.classPrivateFieldGet(this, _bar); | ||
} | ||
}]); | ||
return Foo; | ||
}(); | ||
|
||
var _foo = new WeakMap(); | ||
|
||
var _bar = new WeakMap(); |
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; | ||
} | ||
} |
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); | ||
|
||
_foo.set(this, { | ||
writable: true, | ||
value: 1 | ||
}); | ||
} | ||
|
||
babelHelpers.createClass(Foo, [{ | ||
key: "test", | ||
value: function test() { | ||
var Nested = /*#__PURE__*/function () { | ||
function Nested() { | ||
babelHelpers.classCallCheck(this, Nested); | ||
|
||
_foo2.set(this, { | ||
writable: true, | ||
value: 2 | ||
}); | ||
} | ||
|
||
babelHelpers.createClass(Nested, [{ | ||
key: "test", | ||
value: function test() { | ||
babelHelpers.classPrivateFieldGet(this, _foo2); | ||
} | ||
}]); | ||
return Nested; | ||
}(); | ||
|
||
var _foo2 = new WeakMap(); | ||
|
||
babelHelpers.classPrivateFieldGet(this, _foo); | ||
} | ||
}]); | ||
return Foo; | ||
}(); | ||
|
||
var _foo = new WeakMap(); |
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; | ||
} | ||
} |
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.
@JLHwung Maybe it would be enough to remove this line to fix it?
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.
I don't think so but I haven't tried. The nested private name is still allowed as long as it does not access outer class private names. I think we shall whitelist computed element names for proper resolving behaviour.