Fix _initProto injection

This commit is contained in:
Nicolò Ribaudo 2022-01-09 00:30:41 +01:00
parent b7dfda8209
commit 0f7463e77d
4 changed files with 43 additions and 23 deletions

View File

@ -790,25 +790,21 @@ function transformClass(
value.replaceWith(t.sequenceExpression(body));
} else if (constructorPath) {
if (path.node.superClass) {
let found = false;
path.traverse({
Super(path) {
const { parentPath } = path;
CallExpression: {
exit(path) {
if (!path.get("callee").isSuper()) return;
if (found || parentPath.node.type !== "CallExpression") return;
path.replaceWith(
t.sequenceExpression([
path.node,
t.cloneNode(protoInitCall),
t.thisExpression(),
]),
);
found = true;
const prop =
path.scope.parent.generateDeclaredUidIdentifier("super");
parentPath.replaceWith(
t.sequenceExpression([
t.assignmentExpression("=", t.cloneNode(prop), parentPath.node),
protoInitCall,
t.cloneNode(prop),
]),
);
path.skip();
},
},
});
} else {

View File

@ -10,3 +10,14 @@ class A extends B {
@deco
method() {}
}
class C extends B {
constructor() {
try {
super(super(), null.x);
} catch {}
}
@deco
method() {}
}

View File

@ -1,4 +1,4 @@
var _initProto;
var _initProto, _initProto2;
class A extends B {
static {
@ -6,15 +6,28 @@ class A extends B {
}
constructor() {
var _super;
if (Math.random() > 0.5) {
_super = super(true), _initProto(this), _super;
super(true), _initProto(this), this;
} else {
super(false);
super(false), _initProto(this), this;
}
}
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() {}
}

View File

@ -1,4 +1,4 @@
var _initProto, _super;
var _initProto;
class A extends B {
static {
@ -7,7 +7,7 @@ class A extends B {
constructor() {
let a = 2;
_super = super(a), _initProto(this), _super;
super(a), _initProto(this), this;
foo();
}