Fix class fields when super() is in a default param (#12729)
* Fix class fields when `super()` is in a default param * Use assertion instead of type cast
This commit is contained in:
parent
60ef190d05
commit
bab5c62f90
@ -0,0 +1,6 @@
|
|||||||
|
class Foo extends Bar {
|
||||||
|
bar = "foo";
|
||||||
|
|
||||||
|
constructor(x = test ? super() : 0) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
["external-helpers", { "helperVersion": "7.100.0" }],
|
||||||
|
"proposal-class-properties"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo extends Bar {
|
||||||
|
constructor(x = test ? (() => {
|
||||||
|
var _temp;
|
||||||
|
|
||||||
|
return _temp = super(), babelHelpers.defineProperty(this, "bar", "foo"), _temp;
|
||||||
|
})() : 0) {}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
class Foo extends Bar {
|
||||||
|
bar = "foo";
|
||||||
|
|
||||||
|
constructor(x = () => { check(super()) }) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
["external-helpers", { "helperVersion": "7.100.0" }],
|
||||||
|
"proposal-class-properties"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo extends Bar {
|
||||||
|
constructor(x = () => {
|
||||||
|
var _temp;
|
||||||
|
|
||||||
|
check((_temp = super(), babelHelpers.defineProperty(this, "bar", "foo"), _temp));
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
class Foo extends Bar {
|
||||||
|
bar = "foo";
|
||||||
|
|
||||||
|
constructor(x = super()) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
["external-helpers", { "helperVersion": "7.100.0" }],
|
||||||
|
"proposal-class-properties"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo extends Bar {
|
||||||
|
constructor(x = (() => {
|
||||||
|
var _temp;
|
||||||
|
|
||||||
|
return _temp = super(), babelHelpers.defineProperty(this, "bar", "foo"), _temp;
|
||||||
|
})()) {}
|
||||||
|
|
||||||
|
}
|
||||||
@ -95,7 +95,10 @@ export function _containerInsertAfter(this: NodePath, nodes) {
|
|||||||
* expression, ensure that the completion record is correct by pushing the current node.
|
* expression, ensure that the completion record is correct by pushing the current node.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function insertAfter(this: NodePath, nodes_: t.Node | t.Node[]) {
|
export function insertAfter(
|
||||||
|
this: NodePath,
|
||||||
|
nodes_: t.Node | t.Node[],
|
||||||
|
): NodePath[] {
|
||||||
this._assertUnremoved();
|
this._assertUnremoved();
|
||||||
|
|
||||||
const nodes = this._verifyNodeList(nodes_);
|
const nodes = this._verifyNodeList(nodes_);
|
||||||
@ -127,6 +130,17 @@ export function insertAfter(this: NodePath, nodes_: t.Node | t.Node[]) {
|
|||||||
if (this.node) {
|
if (this.node) {
|
||||||
const node = this.node as t.Expression | t.VariableDeclaration;
|
const node = this.node as t.Expression | t.VariableDeclaration;
|
||||||
let { scope } = this;
|
let { scope } = this;
|
||||||
|
|
||||||
|
if (scope.path.isPattern()) {
|
||||||
|
t.assertExpression(node);
|
||||||
|
|
||||||
|
this.replaceWith(
|
||||||
|
t.callExpression(t.arrowFunctionExpression([], node), []),
|
||||||
|
);
|
||||||
|
(this.get("callee.body") as NodePath).insertAfter(nodes);
|
||||||
|
return [this];
|
||||||
|
}
|
||||||
|
|
||||||
// Inserting after the computed key of a method should insert the
|
// Inserting after the computed key of a method should insert the
|
||||||
// temporary binding in the method's parent's scope.
|
// temporary binding in the method's parent's scope.
|
||||||
if (parentPath.isMethod({ computed: true, key: node })) {
|
if (parentPath.isMethod({ computed: true, key: node })) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user