Correctly access shadowed class binding in super.* (#12544)

* rename own binding inside methods if it collides with class ref. fix #11994

* fix name collisions in constructor

* do fix name collisions in constructor

* move logic in ReplaceSupers

* fix tests of helper-create-class-features-plugin

* remove replaceSupers in pushConstructor

* use environmentVisitor

* skip classLike nodes

* fix super ref in computed key
This commit is contained in:
Zen
2021-01-12 09:31:06 +08:00
committed by GitHub
parent 4f83a09dd8
commit cba64f9a09
13 changed files with 253 additions and 5 deletions

View File

@@ -0,0 +1,11 @@
class Foo extends Bar {
constructor() {
super();
class X {
[(() => {
let Foo;
super.method();
})()]() {}
}
}
}

View File

@@ -0,0 +1,34 @@
var Foo = /*#__PURE__*/function (_Bar) {
"use strict";
babelHelpers.inherits(Foo, _Bar);
var _super = babelHelpers.createSuper(Foo);
function Foo() {
var _thisSuper, _this;
babelHelpers.classCallCheck(this, Foo);
_this = _super.call(this);
var X = /*#__PURE__*/function () {
function X() {
babelHelpers.classCallCheck(this, X);
}
babelHelpers.createClass(X, [{
key: (() => {
var _Foo;
babelHelpers.get((_thisSuper = babelHelpers.assertThisInitialized(_this), babelHelpers.getPrototypeOf(Foo.prototype)), "method", _thisSuper).call(_thisSuper);
})(),
value: function value() {}
}]);
return X;
}();
return _this;
}
return Foo;
}(Bar);

View File

@@ -0,0 +1,16 @@
class Base {
method() {}
}
class Foo extends Base {
constructor() {
super();
if (true) {
let Foo;
super.method();
}
}
method() { }
}

View File

@@ -0,0 +1,42 @@
var Base = /*#__PURE__*/function () {
"use strict";
function Base() {
babelHelpers.classCallCheck(this, Base);
}
babelHelpers.createClass(Base, [{
key: "method",
value: function method() {}
}]);
return Base;
}();
var Foo = /*#__PURE__*/function (_Base) {
"use strict";
babelHelpers.inherits(Foo, _Base);
var _super = babelHelpers.createSuper(Foo);
function Foo() {
var _thisSuper, _this;
babelHelpers.classCallCheck(this, Foo);
_this = _super.call(this);
if (true) {
var _Foo2;
babelHelpers.get((_thisSuper = babelHelpers.assertThisInitialized(_this), babelHelpers.getPrototypeOf(Foo.prototype)), "method", _thisSuper).call(_thisSuper);
}
return _this;
}
babelHelpers.createClass(Foo, [{
key: "method",
value: function method() {}
}]);
return Foo;
}(Base);

View File

@@ -0,0 +1,27 @@
class Foo {
method(Foo) {
return super.method(Foo);
}
}
class Bar {
method() {
return () => {
let Bar;
return super.method(Bar);
};
}
}
class Baz {
method() {
class Baz {
f() {
let Baz = 1;
return Baz;
}
}
return super.method(Baz)
}
}

View File

@@ -0,0 +1,66 @@
var Foo = /*#__PURE__*/function () {
"use strict";
function Foo() {
babelHelpers.classCallCheck(this, Foo);
}
babelHelpers.createClass(Foo, [{
key: "method",
value: function method(_Foo) {
return babelHelpers.get(babelHelpers.getPrototypeOf(Foo.prototype), "method", this).call(this, _Foo);
}
}]);
return Foo;
}();
var Bar = /*#__PURE__*/function () {
"use strict";
function Bar() {
babelHelpers.classCallCheck(this, Bar);
}
babelHelpers.createClass(Bar, [{
key: "method",
value: function method() {
return () => {
var _Bar;
return babelHelpers.get(babelHelpers.getPrototypeOf(Bar.prototype), "method", this).call(this, _Bar);
};
}
}]);
return Bar;
}();
var Baz = /*#__PURE__*/function () {
"use strict";
function Baz() {
babelHelpers.classCallCheck(this, Baz);
}
babelHelpers.createClass(Baz, [{
key: "method",
value: function method() {
var _Baz = /*#__PURE__*/function () {
function _Baz() {
babelHelpers.classCallCheck(this, _Baz);
}
babelHelpers.createClass(_Baz, [{
key: "f",
value: function f() {
var Baz = 1;
return Baz;
}
}]);
return _Baz;
}();
return babelHelpers.get(babelHelpers.getPrototypeOf(Baz.prototype), "method", this).call(this, _Baz);
}
}]);
return Baz;
}();