Super property eval order (#11480)

This commit is contained in:
Justin Ridgewell
2020-04-25 12:34:07 -04:00
committed by GitHub
parent 2e4f18ac92
commit 0bbf2da568
19 changed files with 93 additions and 63 deletions

View File

@@ -101,29 +101,47 @@ const specHandlers = {
},
get(superMember) {
return this._get(superMember, this._getThisRefs());
},
_get(superMember, thisRefs) {
const proto = getPrototypeOfExpression(
this.getObjectRef(),
this.isStatic,
this.file,
this.isPrivateMethod,
);
return t.callExpression(this.file.addHelper("get"), [
getPrototypeOfExpression(
this.getObjectRef(),
this.isStatic,
this.file,
this.isPrivateMethod,
),
thisRefs.memo ? t.sequenceExpression([thisRefs.memo, proto]) : proto,
this.prop(superMember),
t.thisExpression(),
thisRefs.this,
]);
},
_getThisRefs() {
if (!this.isDerivedConstructor) {
return { this: t.thisExpression() };
}
const thisRef = this.scope.generateDeclaredUidIdentifier("thisSuper");
return {
memo: t.assignmentExpression("=", thisRef, t.thisExpression()),
this: t.cloneNode(thisRef),
};
},
set(superMember, value) {
const thisRefs = this._getThisRefs();
const proto = getPrototypeOfExpression(
this.getObjectRef(),
this.isStatic,
this.file,
this.isPrivateMethod,
);
return t.callExpression(this.file.addHelper("set"), [
getPrototypeOfExpression(
this.getObjectRef(),
this.isStatic,
this.file,
this.isPrivateMethod,
),
thisRefs.memo ? t.sequenceExpression([thisRefs.memo, proto]) : proto,
this.prop(superMember),
value,
t.thisExpression(),
thisRefs.this,
t.booleanLiteral(superMember.isInStrictMode()),
]);
},
@@ -135,7 +153,12 @@ const specHandlers = {
},
call(superMember, args) {
return optimiseCall(this.get(superMember), t.thisExpression(), args);
const thisRefs = this._getThisRefs();
return optimiseCall(
this._get(superMember, thisRefs),
t.cloneNode(thisRefs.this),
args,
);
},
};
@@ -190,6 +213,10 @@ const looseHandlers = {
return t.memberExpression(t.thisExpression(), prop, computed);
},
call(superMember, args) {
return optimiseCall(this.get(superMember), t.thisExpression(), args);
},
};
type ReplaceSupersOptionsBase = {|
@@ -214,6 +241,8 @@ export default class ReplaceSupers {
const path = opts.methodPath;
this.methodPath = path;
this.isDerivedConstructor =
path.isClassMethod({ kind: "constructor" }) && !!opts.superRef;
this.isStatic = path.isObjectMethod() || path.node.static;
this.isPrivateMethod = path.isPrivate() && path.isMethod();
@@ -224,6 +253,7 @@ export default class ReplaceSupers {
}
file: HubInterface;
isDerivedConstructor: boolean;
isLoose: boolean;
isPrivateMethod: boolean;
isStatic: boolean;
@@ -240,6 +270,8 @@ export default class ReplaceSupers {
memberExpressionToFunctions(this.methodPath, visitor, {
file: this.file,
scope: this.methodPath.scope,
isDerivedConstructor: this.isDerivedConstructor,
isStatic: this.isStatic,
isPrivateMethod: this.isPrivateMethod,
getObjectRef: this.getObjectRef.bind(this),