forked from babel/babel
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly access shadowed class binding in
super.*
(babel#12544)
* rename own binding inside methods if it collides with class ref. fix babel#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
- Loading branch information
Showing
13 changed files
with
253 additions
and
5 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
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
6 changes: 6 additions & 0 deletions
6
...es/babel-helper-create-class-features-plugin/test/fixtures/replace-supers/method/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,6 @@ | ||
class A extends B { | ||
#foo() { | ||
let A; | ||
super.x; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...abel-helper-create-class-features-plugin/test/fixtures/replace-supers/method/options.json
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,3 @@ | ||
{ | ||
"plugins": ["proposal-private-methods"] | ||
} |
22 changes: 22 additions & 0 deletions
22
...s/babel-helper-create-class-features-plugin/test/fixtures/replace-supers/method/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,22 @@ | ||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); } | ||
|
||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } | ||
|
||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
|
||
var _foo = new WeakSet(); | ||
|
||
class A extends B { | ||
constructor(...args) { | ||
super(...args); | ||
|
||
_foo.add(this); | ||
} | ||
|
||
} | ||
|
||
var _foo2 = function _foo2() { | ||
let _A; | ||
|
||
_get(_getPrototypeOf(A.prototype), "x", this); | ||
}; |
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
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
11 changes: 11 additions & 0 deletions
11
...nsform-classes/test/fixtures/spec/name-collisions-with-class-ref-in-computed-key/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,11 @@ | ||
class Foo extends Bar { | ||
constructor() { | ||
super(); | ||
class X { | ||
[(() => { | ||
let Foo; | ||
super.method(); | ||
})()]() {} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...sform-classes/test/fixtures/spec/name-collisions-with-class-ref-in-computed-key/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,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); |
16 changes: 16 additions & 0 deletions
16
...ansform-classes/test/fixtures/spec/name-collisions-with-class-ref-in-constructor/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,16 @@ | ||
class Base { | ||
method() {} | ||
} | ||
|
||
class Foo extends Base { | ||
constructor() { | ||
super(); | ||
|
||
if (true) { | ||
let Foo; | ||
super.method(); | ||
} | ||
} | ||
|
||
method() { } | ||
} |
42 changes: 42 additions & 0 deletions
42
...nsform-classes/test/fixtures/spec/name-collisions-with-class-ref-in-constructor/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,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); |
27 changes: 27 additions & 0 deletions
27
...in-transform-classes/test/fixtures/spec/name-collisions-with-class-ref-in-method/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,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) | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...n-transform-classes/test/fixtures/spec/name-collisions-with-class-ref-in-method/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,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; | ||
}(); |