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 {