@babel/helper-replace-supers
Advanced tools
Comparing version 7.0.0-beta.43 to 7.0.0-beta.44
114
lib/index.js
@@ -9,5 +9,5 @@ "use strict"; | ||
function _helperOptimiseCallExpression() { | ||
const data = _interopRequireDefault(require("@babel/helper-optimise-call-expression")); | ||
var data = _interopRequireDefault(require("@babel/helper-optimise-call-expression")); | ||
_helperOptimiseCallExpression = function () { | ||
_helperOptimiseCallExpression = function _helperOptimiseCallExpression() { | ||
return data; | ||
@@ -20,5 +20,5 @@ }; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
t = function t() { | ||
return data; | ||
@@ -34,3 +34,3 @@ }; | ||
const HARDCORE_THIS_REF = new WeakSet(); | ||
var HARDCORE_THIS_REF = new WeakSet(); | ||
@@ -53,16 +53,14 @@ function isIllegalBareSuper(node, parent) { | ||
function getPrototypeOfExpression(objectRef, isStatic) { | ||
const targetRef = isStatic ? objectRef : t().memberExpression(objectRef, t().identifier("prototype")); | ||
var targetRef = isStatic ? objectRef : t().memberExpression(objectRef, t().identifier("prototype")); | ||
return t().logicalExpression("||", t().memberExpression(targetRef, t().identifier("__proto__")), t().callExpression(t().memberExpression(t().identifier("Object"), t().identifier("getPrototypeOf")), [t().cloneNode(targetRef)])); | ||
} | ||
const visitor = { | ||
Function(path) { | ||
var visitor = { | ||
Function: function Function(path) { | ||
if (!path.isArrowFunctionExpression()) path.skip(); | ||
}, | ||
ClassProperty(path) { | ||
ClassProperty: function ClassProperty(path) { | ||
if (!path.node.static) path.skip(); | ||
}, | ||
ReturnStatement(path, state) { | ||
ReturnStatement: function ReturnStatement(path, state) { | ||
if (!path.getFunctionParent().isArrowFunctionExpression()) { | ||
@@ -72,4 +70,3 @@ state.returns.push(path); | ||
}, | ||
ThisExpression(path, state) { | ||
ThisExpression: function ThisExpression(path, state) { | ||
if (!HARDCORE_THIS_REF.has(path.node)) { | ||
@@ -79,8 +76,7 @@ state.thises.push(path); | ||
}, | ||
enter(path, state) { | ||
let callback = state.specHandle; | ||
enter: function enter(path, state) { | ||
var callback = state.specHandle; | ||
if (state.isLoose) callback = state.looseHandle; | ||
const isBareSuper = path.isCallExpression() && path.get("callee").isSuper(); | ||
const result = callback.call(state, path); | ||
var isBareSuper = path.isCallExpression() && path.get("callee").isSuper(); | ||
var result = callback.call(state, path); | ||
@@ -107,7 +103,10 @@ if (result) { | ||
} | ||
}; | ||
class ReplaceSupers { | ||
constructor(opts, inClass = false) { | ||
var ReplaceSupers = function () { | ||
function ReplaceSupers(opts, inClass) { | ||
if (inClass === void 0) { | ||
inClass = false; | ||
} | ||
this.forceSuperMemoisation = opts.forceSuperMemoisation; | ||
@@ -130,12 +129,14 @@ this.methodPath = opts.methodPath; | ||
getObjectRef() { | ||
var _proto = ReplaceSupers.prototype; | ||
_proto.getObjectRef = function getObjectRef() { | ||
return t().cloneNode(this.opts.objectRef || this.opts.getObjectRef()); | ||
} | ||
}; | ||
setSuperProperty(property, value, isComputed) { | ||
_proto.setSuperProperty = function setSuperProperty(property, value, isComputed) { | ||
return t().callExpression(this.file.addHelper("set"), [getPrototypeOfExpression(this.getObjectRef(), this.isStatic), isComputed ? property : t().stringLiteral(property.name), value, t().thisExpression()]); | ||
} | ||
}; | ||
getSuperProperty(property, isComputed) { | ||
let thisExpr = t().thisExpression(); | ||
_proto.getSuperProperty = function getSuperProperty(property, isComputed) { | ||
var thisExpr = t().thisExpression(); | ||
@@ -147,11 +148,11 @@ if (this.inConstructor) { | ||
return t().callExpression(this.file.addHelper("get"), [getPrototypeOfExpression(this.getObjectRef(), this.isStatic), isComputed ? property : t().stringLiteral(property.name), thisExpr]); | ||
} | ||
}; | ||
replace() { | ||
_proto.replace = function replace() { | ||
this.methodPath.traverse(visitor, this); | ||
} | ||
}; | ||
getLooseSuperProperty(id, parent) { | ||
const methodNode = this.methodNode; | ||
const superRef = this.superRef || t().identifier("Function"); | ||
_proto.getLooseSuperProperty = function getLooseSuperProperty(id, parent) { | ||
var methodNode = this.methodNode; | ||
var superRef = this.superRef || t().identifier("Function"); | ||
@@ -169,6 +170,6 @@ if (parent.property === id) { | ||
} | ||
} | ||
}; | ||
looseHandle(path) { | ||
const node = path.node; | ||
_proto.looseHandle = function looseHandle(path) { | ||
var node = path.node; | ||
@@ -178,3 +179,3 @@ if (path.isSuper()) { | ||
} else if (path.isCallExpression()) { | ||
const callee = node.callee; | ||
var callee = node.callee; | ||
if (!t().isMemberExpression(callee)) return; | ||
@@ -186,5 +187,5 @@ if (!t().isSuper(callee.object)) return; | ||
} | ||
} | ||
}; | ||
specHandleAssignmentExpression(ref, path, node) { | ||
_proto.specHandleAssignmentExpression = function specHandleAssignmentExpression(ref, path, node) { | ||
if (node.operator === "=") { | ||
@@ -196,10 +197,10 @@ return this.setSuperProperty(node.left.property, node.right, node.left.computed); | ||
} | ||
} | ||
}; | ||
specHandle(path) { | ||
let property; | ||
let computed; | ||
let args; | ||
const parent = path.parent; | ||
const node = path.node; | ||
_proto.specHandle = function specHandle(path) { | ||
var property; | ||
var computed; | ||
var args; | ||
var parent = path.parent; | ||
var node = path.node; | ||
@@ -211,3 +212,3 @@ if (isIllegalBareSuper(node, parent)) { | ||
if (t().isCallExpression(node)) { | ||
const callee = node.callee; | ||
var callee = node.callee; | ||
@@ -225,3 +226,3 @@ if (t().isSuper(callee)) { | ||
} else if (t().isUpdateExpression(node) && isMemberExpressionSuper(node.argument)) { | ||
const binary = t().assignmentExpression(node.operator[0] + "=", node.argument, t().numericLiteral(1)); | ||
var binary = t().assignmentExpression(node.operator[0] + "=", node.argument, t().numericLiteral(1)); | ||
@@ -231,3 +232,3 @@ if (node.prefix) { | ||
} else { | ||
const ref = path.scope.generateUidIdentifier("ref"); | ||
var ref = path.scope.generateUidIdentifier("ref"); | ||
return this.specHandleAssignmentExpression(ref, path, binary).concat(t().expressionStatement(ref)); | ||
@@ -240,3 +241,3 @@ } | ||
if (!property) return; | ||
const superProperty = this.getSuperProperty(property, computed); | ||
var superProperty = this.getSuperProperty(property, computed); | ||
@@ -248,12 +249,13 @@ if (args) { | ||
} | ||
} | ||
}; | ||
optimiseCall(callee, args) { | ||
const thisNode = t().thisExpression(); | ||
_proto.optimiseCall = function optimiseCall(callee, args) { | ||
var thisNode = t().thisExpression(); | ||
HARDCORE_THIS_REF.add(thisNode); | ||
return (0, _helperOptimiseCallExpression().default)(callee, thisNode, args); | ||
} | ||
}; | ||
} | ||
return ReplaceSupers; | ||
}(); | ||
exports.default = ReplaceSupers; |
{ | ||
"name": "@babel/helper-replace-supers", | ||
"version": "7.0.0-beta.43", | ||
"version": "7.0.0-beta.44", | ||
"description": "Helper function to replace supers", | ||
@@ -9,7 +9,7 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-replace-supers", | ||
"dependencies": { | ||
"@babel/helper-optimise-call-expression": "7.0.0-beta.43", | ||
"@babel/template": "7.0.0-beta.43", | ||
"@babel/traverse": "7.0.0-beta.43", | ||
"@babel/types": "7.0.0-beta.43" | ||
"@babel/helper-optimise-call-expression": "7.0.0-beta.44", | ||
"@babel/template": "7.0.0-beta.44", | ||
"@babel/traverse": "7.0.0-beta.44", | ||
"@babel/types": "7.0.0-beta.44" | ||
} | ||
} |
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
8635
201
+ Added@babel/code-frame@7.0.0-beta.44(transitive)
+ Added@babel/generator@7.0.0-beta.44(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.44(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.44(transitive)
+ Added@babel/helper-optimise-call-expression@7.0.0-beta.44(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.44(transitive)
+ Added@babel/highlight@7.0.0-beta.44(transitive)
+ Added@babel/template@7.0.0-beta.44(transitive)
+ Added@babel/traverse@7.0.0-beta.44(transitive)
+ Added@babel/types@7.0.0-beta.44(transitive)
+ Addedbabylon@7.0.0-beta.44(transitive)
- Removed@babel/code-frame@7.0.0-beta.43(transitive)
- Removed@babel/generator@7.0.0-beta.43(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.43(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.43(transitive)
- Removed@babel/helper-optimise-call-expression@7.0.0-beta.43(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.43(transitive)
- Removed@babel/highlight@7.0.0-beta.43(transitive)
- Removed@babel/template@7.0.0-beta.43(transitive)
- Removed@babel/traverse@7.0.0-beta.43(transitive)
- Removed@babel/types@7.0.0-beta.43(transitive)
- Removedbabylon@7.0.0-beta.43(transitive)
Updated@babel/types@7.0.0-beta.44