Fix _initProto injection
This commit is contained in:
parent
b7dfda8209
commit
0f7463e77d
@ -790,25 +790,21 @@ function transformClass(
|
|||||||
value.replaceWith(t.sequenceExpression(body));
|
value.replaceWith(t.sequenceExpression(body));
|
||||||
} else if (constructorPath) {
|
} else if (constructorPath) {
|
||||||
if (path.node.superClass) {
|
if (path.node.superClass) {
|
||||||
let found = false;
|
|
||||||
|
|
||||||
path.traverse({
|
path.traverse({
|
||||||
Super(path) {
|
CallExpression: {
|
||||||
const { parentPath } = path;
|
exit(path) {
|
||||||
|
if (!path.get("callee").isSuper()) return;
|
||||||
|
|
||||||
if (found || parentPath.node.type !== "CallExpression") return;
|
path.replaceWith(
|
||||||
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
const prop =
|
|
||||||
path.scope.parent.generateDeclaredUidIdentifier("super");
|
|
||||||
parentPath.replaceWith(
|
|
||||||
t.sequenceExpression([
|
t.sequenceExpression([
|
||||||
t.assignmentExpression("=", t.cloneNode(prop), parentPath.node),
|
path.node,
|
||||||
protoInitCall,
|
t.cloneNode(protoInitCall),
|
||||||
t.cloneNode(prop),
|
t.thisExpression(),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
path.skip();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -10,3 +10,14 @@ class A extends B {
|
|||||||
@deco
|
@deco
|
||||||
method() {}
|
method() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class C extends B {
|
||||||
|
constructor() {
|
||||||
|
try {
|
||||||
|
super(super(), null.x);
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@deco
|
||||||
|
method() {}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
var _initProto;
|
var _initProto, _initProto2;
|
||||||
|
|
||||||
class A extends B {
|
class A extends B {
|
||||||
static {
|
static {
|
||||||
@ -6,15 +6,28 @@ class A extends B {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
var _super;
|
|
||||||
|
|
||||||
if (Math.random() > 0.5) {
|
if (Math.random() > 0.5) {
|
||||||
_super = super(true), _initProto(this), _super;
|
super(true), _initProto(this), this;
|
||||||
} else {
|
} else {
|
||||||
super(false);
|
super(false), _initProto(this), this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
method() {}
|
method() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class C extends B {
|
||||||
|
static {
|
||||||
|
[_initProto2] = babelHelpers.applyDecs(this, [[deco, 2, "method"]], []);
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
try {
|
||||||
|
super((super(), _initProto2(this), this), null.x), _initProto2(this), this;
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
method() {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
var _initProto, _super;
|
var _initProto;
|
||||||
|
|
||||||
class A extends B {
|
class A extends B {
|
||||||
static {
|
static {
|
||||||
@ -7,7 +7,7 @@ class A extends B {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
let a = 2;
|
let a = 2;
|
||||||
_super = super(a), _initProto(this), _super;
|
super(a), _initProto(this), this;
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user