Skip to content
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 redeclaring private in nested class's superClass #11424

Merged
merged 1 commit into from Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -103,7 +103,6 @@ const privateNameVisitor = {
// This class redeclares some private field. We need to process the outer
// environment with access to all the outer privates, then we can process
// the inner environment with only the still-visible outer privates.
path.get("superClass").traverse(privateNameVisitor, this);
path.get("body").traverse(privateNameNestedVisitor, {
...this,
redeclared,
Expand All @@ -115,7 +114,7 @@ const privateNameVisitor = {

// We'll eventually hit this class node again with the overall Class
// Features visitor, which'll process the redeclared privates.
path.skip();
path.skipKey("body");
},
};

Expand Down
@@ -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();
@@ -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();
@@ -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();
@@ -0,0 +1,12 @@
class Foo {
#foo = 1;

test() {
class Nested extends class {
#foo = 2;
[this.#foo] = 2;
} {
#foo = 3;
}
}
}
@@ -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");
@@ -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();
@@ -0,0 +1,11 @@
class Foo {
#foo = 1;

test() {
class Nested extends class {
[this.#foo] = 2;
} {
#foo = 3;
}
}
}
@@ -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");
@@ -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();
@@ -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();
@@ -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();
@@ -0,0 +1,12 @@
class Foo {
#foo = 1;

test() {
class Nested extends class {
#foo = 2;
[this.#foo] = 2;
} {
#foo = 3;
}
}
}
@@ -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();
@@ -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();
@@ -0,0 +1,11 @@
class Foo {
#foo = 1;

test() {
class Nested extends class {
[this.#foo] = 2;
} {
#foo = 3;
}
}
}