@babel/helper-replace-supers
Advanced tools
Comparing version 8.0.0-alpha.11 to 8.0.0-alpha.12
@@ -1,9 +0,8 @@ | ||
import environmentVisitor from '@babel/helper-environment-visitor'; | ||
import memberExpressionToFunctions from '@babel/helper-member-expression-to-functions'; | ||
import optimiseCall from '@babel/helper-optimise-call-expression'; | ||
import { traverse, types, template } from '@babel/core'; | ||
import { types, template } from '@babel/core'; | ||
import { visitors } from '@babel/traverse'; | ||
const { | ||
assignmentExpression, | ||
booleanLiteral, | ||
callExpression, | ||
@@ -17,8 +16,3 @@ cloneNode, | ||
} = types; | ||
function getPrototypeOfExpression(objectRef, isStatic, file, isPrivateMethod) { | ||
objectRef = cloneNode(objectRef); | ||
const targetRef = isStatic || isPrivateMethod ? objectRef : memberExpression(objectRef, identifier("prototype")); | ||
return callExpression(file.addHelper("getPrototypeOf"), [targetRef]); | ||
} | ||
const visitor = traverse.visitors.merge([environmentVisitor, { | ||
const visitor = visitors.environmentVisitor({ | ||
Super(path, state) { | ||
@@ -34,4 +28,4 @@ const { | ||
} | ||
}]); | ||
const unshadowSuperBindingVisitor = traverse.visitors.merge([environmentVisitor, { | ||
}); | ||
const unshadowSuperBindingVisitor = visitors.environmentVisitor({ | ||
Scopable(path, { | ||
@@ -45,3 +39,3 @@ refName | ||
} | ||
}]); | ||
}); | ||
const specHandlers = { | ||
@@ -79,19 +73,28 @@ memoise(superMember, count) { | ||
}, | ||
_getPrototypeOfExpression() { | ||
const objectRef = cloneNode(this.getObjectRef()); | ||
const targetRef = this.isStatic || this.isPrivateMethod ? objectRef : memberExpression(objectRef, identifier("prototype")); | ||
return callExpression(this.file.addHelper("getPrototypeOf"), [targetRef]); | ||
}, | ||
get(superMember) { | ||
return this._get(superMember, this._getThisRefs()); | ||
const objectRef = cloneNode(this.getObjectRef()); | ||
return callExpression(this.file.addHelper("superPropGet"), [this.isDerivedConstructor ? sequenceExpression([thisExpression(), objectRef]) : objectRef, this.prop(superMember), thisExpression(), ...(this.isStatic || this.isPrivateMethod ? [] : [types.numericLiteral(1)])]); | ||
}, | ||
_get(superMember, thisRefs) { | ||
const proto = getPrototypeOfExpression(this.getObjectRef(), this.isStatic, this.file, this.isPrivateMethod); | ||
return callExpression(this.file.addHelper("get"), [thisRefs.needAccessFirst ? sequenceExpression([thisRefs.this, proto]) : proto, this.prop(superMember), thisRefs.this]); | ||
_call(superMember, args, optional) { | ||
const objectRef = cloneNode(this.getObjectRef()); | ||
let argsNode; | ||
if (args.length === 1 && types.isSpreadElement(args[0]) && (types.isIdentifier(args[0].argument) || types.isArrayExpression(args[0].argument))) { | ||
argsNode = args[0].argument; | ||
} else { | ||
argsNode = types.arrayExpression(args); | ||
} | ||
const call = types.callExpression(this.file.addHelper("superPropGet"), [this.isDerivedConstructor ? sequenceExpression([thisExpression(), objectRef]) : objectRef, this.prop(superMember), thisExpression(), types.numericLiteral(2 | (this.isStatic || this.isPrivateMethod ? 0 : 1))]); | ||
if (optional) { | ||
return types.optionalCallExpression(call, [argsNode], true); | ||
} | ||
return callExpression(call, [argsNode]); | ||
}, | ||
_getThisRefs() { | ||
return { | ||
needAccessFirst: this.isDerivedConstructor, | ||
this: thisExpression() | ||
}; | ||
}, | ||
set(superMember, value) { | ||
const thisRefs = this._getThisRefs(); | ||
const proto = getPrototypeOfExpression(this.getObjectRef(), this.isStatic, this.file, this.isPrivateMethod); | ||
return callExpression(this.file.addHelper("set"), [thisRefs.needAccessFirst ? sequenceExpression([thisRefs.this, proto]) : proto, this.prop(superMember), value, thisRefs.this, booleanLiteral(superMember.isInStrictMode())]); | ||
const objectRef = cloneNode(this.getObjectRef()); | ||
return callExpression(this.file.addHelper("superPropSet"), [this.isDerivedConstructor ? sequenceExpression([thisExpression(), objectRef]) : objectRef, this.prop(superMember), value, thisExpression(), types.numericLiteral(superMember.isInStrictMode() ? 1 : 0), ...(this.isStatic || this.isPrivateMethod ? [] : [types.numericLiteral(1)])]); | ||
}, | ||
@@ -102,8 +105,6 @@ destructureSet(superMember) { | ||
call(superMember, args) { | ||
const thisRefs = this._getThisRefs(); | ||
return optimiseCall(this._get(superMember, thisRefs), cloneNode(thisRefs.this), args, false); | ||
return this._call(superMember, args, false); | ||
}, | ||
optionalCall(superMember, args) { | ||
const thisRefs = this._getThisRefs(); | ||
return optimiseCall(this._get(superMember, thisRefs), cloneNode(thisRefs.this), args, true); | ||
return this._call(superMember, args, true); | ||
}, | ||
@@ -110,0 +111,0 @@ delete(superMember) { |
{ | ||
"name": "@babel/helper-replace-supers", | ||
"version": "8.0.0-alpha.11", | ||
"version": "8.0.0-alpha.12", | ||
"description": "Helper function to replace supers", | ||
@@ -17,11 +17,11 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-environment-visitor": "^8.0.0-alpha.11", | ||
"@babel/helper-member-expression-to-functions": "^8.0.0-alpha.11", | ||
"@babel/helper-optimise-call-expression": "^8.0.0-alpha.11" | ||
"@babel/helper-member-expression-to-functions": "^8.0.0-alpha.12", | ||
"@babel/helper-optimise-call-expression": "^8.0.0-alpha.12", | ||
"@babel/traverse": "^8.0.0-alpha.12" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^8.0.0-alpha.11" | ||
"@babel/core": "^8.0.0-alpha.12" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "^8.0.0-alpha.11" | ||
"@babel/core": "^8.0.0-alpha.12" | ||
}, | ||
@@ -28,0 +28,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101122
275