Simplify _initProto injection for existing super()
This commit is contained in:
parent
5ba1365f9a
commit
9a876a2a64
File diff suppressed because one or more lines are too long
@ -518,9 +518,12 @@ function pushInitializers(ret, initializers) {
|
||||
for (var i = 0; i < initializers.length; i++) {
|
||||
initializers[i].call(instance, instance);
|
||||
}
|
||||
return instance;
|
||||
});
|
||||
} else {
|
||||
ret.push(function () {});
|
||||
ret.push(function (instance) {
|
||||
return instance;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -796,11 +796,7 @@ function transformClass(
|
||||
if (!path.get("callee").isSuper()) return;
|
||||
|
||||
path.replaceWith(
|
||||
t.sequenceExpression([
|
||||
path.node,
|
||||
t.cloneNode(protoInitCall),
|
||||
t.thisExpression(),
|
||||
]),
|
||||
t.callExpression(t.cloneNode(protoInitLocal), [path.node]),
|
||||
);
|
||||
|
||||
path.skip();
|
||||
|
||||
@ -7,9 +7,9 @@ class A extends B {
|
||||
|
||||
constructor() {
|
||||
if (Math.random() > 0.5) {
|
||||
super(true), _initProto(this), this;
|
||||
_initProto(super(true));
|
||||
} else {
|
||||
super(false), _initProto(this), this;
|
||||
_initProto(super(false));
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ class C extends B {
|
||||
|
||||
constructor() {
|
||||
try {
|
||||
super((super(), _initProto2(this), this), null.x), _initProto2(this), this;
|
||||
_initProto2(super(_initProto2(super()), null.x));
|
||||
} catch {}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
let self, a, initCalled;
|
||||
|
||||
function deco(_, context) {
|
||||
context.addInitializer(() => {
|
||||
initCalled = true;
|
||||
})
|
||||
}
|
||||
|
||||
class B {
|
||||
constructor(s) {
|
||||
a = s;
|
||||
}
|
||||
}
|
||||
|
||||
class A extends B {
|
||||
constructor() {
|
||||
let a = 2;
|
||||
self = super(a);
|
||||
}
|
||||
|
||||
@deco
|
||||
method() {}
|
||||
}
|
||||
|
||||
let instance = new A();
|
||||
expect(self).toBe(instance);
|
||||
expect(a).toBe(2);
|
||||
expect(initCalled).toBe(true);
|
||||
@ -7,7 +7,9 @@ class A extends B {
|
||||
|
||||
constructor() {
|
||||
let a = 2;
|
||||
super(a), _initProto(this), this;
|
||||
|
||||
_initProto(super(a));
|
||||
|
||||
foo();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user