babel-traverse
Advanced tools
Comparing version 7.0.0-alpha.15 to 7.0.0-alpha.16
@@ -18,4 +18,2 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var testing = process.env.NODE_ENV === "test"; | ||
@@ -25,6 +23,3 @@ | ||
function TraversalContext(scope, opts, state, parentPath) { | ||
_classCallCheck(this, TraversalContext); | ||
this.queue = null; | ||
this.parentPath = parentPath; | ||
@@ -39,5 +34,3 @@ this.scope = scope; | ||
if (opts.enter || opts.exit) return true; | ||
if (opts[node.type]) return true; | ||
var keys = t.VISITOR_KEYS[node.type]; | ||
@@ -59,3 +52,2 @@ if (!keys || !keys.length) return false; | ||
var key = _ref; | ||
if (node[key]) return true; | ||
@@ -93,3 +85,2 @@ } | ||
if (container.length === 0) return false; | ||
var queue = []; | ||
@@ -99,2 +90,3 @@ | ||
var node = container[key]; | ||
if (node && this.shouldVisit(node)) { | ||
@@ -119,3 +111,2 @@ queue.push(this.create(parent, container, key, listKey)); | ||
this.priorityQueue = []; | ||
var visited = []; | ||
@@ -137,3 +128,2 @@ var stop = false; | ||
var path = _ref2; | ||
path.resync(); | ||
@@ -185,3 +175,2 @@ | ||
this.queue = null; | ||
return stop; | ||
@@ -188,0 +177,0 @@ }; |
@@ -5,7 +5,3 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Hub = function Hub(file, options) { | ||
_classCallCheck(this, Hub); | ||
this.file = file; | ||
@@ -12,0 +8,0 @@ this.options = options; |
@@ -63,2 +63,3 @@ "use strict"; | ||
exports.visitors = visitors; | ||
function traverse(parent, opts, scope, state, parentPath) { | ||
@@ -75,3 +76,2 @@ if (!parent) return; | ||
visitors.explode(opts); | ||
traverse.node(parent, opts, scope, state, parentPath); | ||
@@ -83,3 +83,2 @@ } | ||
traverse.explode = visitors.explode; | ||
traverse.NodePath = require("./path"); | ||
@@ -96,4 +95,4 @@ traverse.Scope = require("./scope"); | ||
if (!keys) return; | ||
var context = new _context2.default(scope, opts, state, parentPath); | ||
var context = new _context2.default(scope, opts, state, parentPath); | ||
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
@@ -112,3 +111,2 @@ var _ref; | ||
var key = _ref; | ||
if (skipKeys && skipKeys[key]) continue; | ||
@@ -121,3 +119,2 @@ if (context.visit(node, key)) return; | ||
t.removeProperties(node, opts); | ||
cache.path.delete(node); | ||
@@ -140,5 +137,3 @@ }; | ||
if ((0, _includes2.default)(blacklistTypes, tree.type)) return false; | ||
if (tree.type === type) return true; | ||
var state = { | ||
@@ -148,3 +143,2 @@ has: false, | ||
}; | ||
traverse(tree, { | ||
@@ -154,3 +148,2 @@ blacklist: blacklistTypes, | ||
}, scope, state); | ||
return state.has; | ||
@@ -157,0 +150,0 @@ }; |
@@ -29,5 +29,7 @@ "use strict"; | ||
var path = this; | ||
while (path = path.parentPath) { | ||
if (callback(path)) return path; | ||
} | ||
return null; | ||
@@ -38,5 +40,7 @@ } | ||
var path = this; | ||
do { | ||
if (callback(path)) return path; | ||
} while (path = path.parentPath); | ||
return null; | ||
@@ -73,17 +77,6 @@ } | ||
var keys = t.VISITOR_KEYS[deepest.type]; | ||
var _arr = ancestries; | ||
for (var _iterator = ancestries, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var ancestry = _ref; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var ancestry = _arr[_i]; | ||
var path = ancestry[i + 1]; | ||
@@ -105,2 +98,3 @@ | ||
var currentKeyIndex = keys.indexOf(path.parentKey); | ||
if (earliestKeyIndex > currentKeyIndex) { | ||
@@ -127,6 +121,4 @@ earliest = path; | ||
var minDepth = Infinity; | ||
var lastCommonIndex = void 0, | ||
lastCommon = void 0; | ||
var ancestries = paths.map(function (path) { | ||
@@ -145,3 +137,2 @@ var ancestry = []; | ||
}); | ||
var first = ancestries[0]; | ||
@@ -151,17 +142,7 @@ | ||
var shouldMatch = first[i]; | ||
var _arr2 = ancestries; | ||
for (var _iterator2 = ancestries, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | ||
var ancestry = _arr2[_i2]; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
} | ||
var ancestry = _ref2; | ||
if (ancestry[i] !== shouldMatch) { | ||
@@ -190,5 +171,7 @@ break depthLoop; | ||
var paths = []; | ||
do { | ||
paths.push(path); | ||
} while (path = path.parentPath); | ||
return paths; | ||
@@ -209,19 +192,11 @@ } | ||
var path = this; | ||
while (path) { | ||
for (var _iterator3 = arguments, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
var _arr3 = arguments; | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i3++]; | ||
} else { | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref3 = _i3.value; | ||
} | ||
var type = _ref3; | ||
for (var _i3 = 0; _i3 < _arr3.length; _i3++) { | ||
var type = _arr3[_i3]; | ||
if (path.node.type === type) return true; | ||
} | ||
path = path.parentPath; | ||
@@ -228,0 +203,0 @@ } |
@@ -7,12 +7,10 @@ "use strict"; | ||
exports.addComments = addComments; | ||
function shareCommentsWithSiblings() { | ||
if (typeof this.key === "string") return; | ||
var node = this.node; | ||
if (!node) return; | ||
var trailing = node.trailingComments; | ||
var leading = node.leadingComments; | ||
if (!trailing && !leading) return; | ||
var prev = this.getSibling(this.key - 1); | ||
@@ -22,2 +20,3 @@ var next = this.getSibling(this.key + 1); | ||
var hasNext = Boolean(next.node); | ||
if (hasPrev && hasNext) {} else if (hasPrev) { | ||
@@ -39,6 +38,4 @@ prev.addComments("trailing", trailing); | ||
if (!comments) return; | ||
var node = this.node; | ||
if (!node) return; | ||
var key = type + "Comments"; | ||
@@ -45,0 +42,0 @@ |
@@ -33,3 +33,2 @@ "use strict"; | ||
var opts = this.opts; | ||
this.debug(function () { | ||
@@ -66,9 +65,7 @@ return key; | ||
var fn = _ref; | ||
if (!fn) continue; | ||
var node = this.node; | ||
if (!node) return true; | ||
var ret = fn.call(this.state, this, this.state); | ||
var ret = fn.call(this.state, this, this.state); | ||
if (ret) { | ||
@@ -79,3 +76,2 @@ throw new Error("Unexpected return value from visitor method " + fn); | ||
if (this.node !== node) return true; | ||
if (this.shouldStop || this.shouldSkip || this.removed) return true; | ||
@@ -115,6 +111,6 @@ } | ||
}); | ||
_index2.default.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys); | ||
this.call("exit"); | ||
return this.shouldStop; | ||
@@ -138,3 +134,2 @@ } | ||
if (this.opts && this.opts.noScope) return; | ||
var target = this.context && this.context.scope; | ||
@@ -144,5 +139,5 @@ | ||
var path = this.parentPath; | ||
while (path && !target) { | ||
if (path.opts && path.opts.noScope) return; | ||
target = path.scope; | ||
@@ -170,3 +165,2 @@ path = path.parentPath; | ||
this.setScope(); | ||
return this; | ||
@@ -179,3 +173,5 @@ } | ||
this._resyncParent(); | ||
this._resyncList(); | ||
this._resyncKey(); | ||
@@ -192,3 +188,2 @@ } | ||
if (!this.container) return; | ||
if (this.node === this.container[this.key]) return; | ||
@@ -215,6 +210,4 @@ | ||
if (!this.parent || !this.inList) return; | ||
var newContainer = this.parent[this.listKey]; | ||
if (this.container === newContainer) return; | ||
this.container = newContainer || null; | ||
@@ -244,3 +237,2 @@ } | ||
this.container = container; | ||
this.parentPath = parentPath || this.parentPath; | ||
@@ -258,5 +250,3 @@ this.setKey(key); | ||
var pathToQueue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this; | ||
if (pathToQueue.removed) return; | ||
var contexts = this.contexts; | ||
@@ -277,3 +267,2 @@ | ||
var context = _ref2; | ||
context.maybeQueue(pathToQueue); | ||
@@ -286,7 +275,10 @@ } | ||
var contexts = this.contexts; | ||
while (!contexts.length) { | ||
path = path.parentPath; | ||
if (!path) break; | ||
contexts = path.contexts; | ||
} | ||
return contexts; | ||
} |
@@ -24,4 +24,4 @@ "use strict"; | ||
var node = this.node; | ||
var key = void 0; | ||
var key = void 0; | ||
if (this.isMemberExpression()) { | ||
@@ -48,3 +48,2 @@ key = node.property; | ||
if (!this.isArrowFunctionExpression()) return; | ||
this.arrowFunctionToExpression(); | ||
@@ -73,7 +72,8 @@ } | ||
var thisBinding = hoistFunctionEnvironment(this, specCompliant, allowInsertArrow); | ||
this.ensureBlock(); | ||
this.node.type = "FunctionExpression"; | ||
if (specCompliant) { | ||
var checkBinding = thisBinding ? null : this.parentPath.scope.generateUidIdentifier("arrowCheckId"); | ||
if (checkBinding) { | ||
@@ -87,3 +87,2 @@ this.parentPath.scope.push({ | ||
this.get("body").unshiftContainer("body", t.expressionStatement(t.callExpression(this.hub.file.addHelper("newArrowCheck"), [t.thisExpression(), checkBinding ? t.identifier(checkBinding.name) : t.identifier(thisBinding)]))); | ||
this.replaceWith(t.callExpression(t.memberExpression((0, _babelHelperFunctionName2.default)(this) || this.node, t.identifier("bind")), [checkBinding ? t.identifier(checkBinding.name) : t.thisExpression()])); | ||
@@ -96,3 +95,2 @@ } | ||
var allowInsertArrow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
var thisEnvFn = fnPath.findParent(function (p) { | ||
@@ -125,2 +123,3 @@ return p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty(); | ||
} | ||
child.skip(); | ||
@@ -130,9 +129,6 @@ }, | ||
if (!child.get("callee").isSuper()) return; | ||
allSuperCalls.push(child); | ||
} | ||
}); | ||
var superBinding = getSuperBinding(thisEnvFn); | ||
allSuperCalls.forEach(function (superCall) { | ||
@@ -144,2 +140,3 @@ return superCall.get("callee").replaceWith(t.identifier(superBinding)); | ||
var thisBinding = void 0; | ||
if (thisPaths.length > 0 || specCompliant) { | ||
@@ -152,3 +149,2 @@ thisBinding = getThisBinding(thisEnvFn, inConstructor); | ||
}); | ||
if (specCompliant) thisBinding = null; | ||
@@ -162,3 +158,2 @@ } | ||
}); | ||
argumentsPaths.forEach(function (argumentsChild) { | ||
@@ -173,3 +168,2 @@ argumentsChild.replaceWith(t.identifier(argumentsBinding)); | ||
}); | ||
newTargetPaths.forEach(function (argumentsChild) { | ||
@@ -188,7 +182,8 @@ argumentsChild.replaceWith(t.identifier(newTargetBinding)); | ||
}, []); | ||
flatSuperProps.forEach(function (superProp) { | ||
var key = superProp.node.computed ? "" : superProp.get("property").node.name; | ||
if (superProp.parentPath.isCallExpression({ callee: superProp.node })) { | ||
if (superProp.parentPath.isCallExpression({ | ||
callee: superProp.node | ||
})) { | ||
var _superBinding = getSuperPropCallBinding(thisEnvFn, key); | ||
@@ -207,5 +202,7 @@ | ||
}); | ||
var _superBinding2 = getSuperPropBinding(thisEnvFn, isAssignment, key); | ||
var args = []; | ||
if (superProp.node.computed) { | ||
@@ -232,18 +229,15 @@ args.push(superProp.get("property").node); | ||
var assignmentPath = superProp.parentPath; | ||
var op = assignmentPath.node.operator.slice(0, -1); | ||
var value = assignmentPath.node.right; | ||
assignmentPath.node.operator = "="; | ||
assignmentPath.node.operator = "="; | ||
if (superProp.node.computed) { | ||
var tmp = superProp.scope.generateDeclaredUidIdentifier("tmp"); | ||
assignmentPath.get("left").replaceWith(t.memberExpression(superProp.node.object, t.assignmentExpression("=", tmp, superProp.node.property), true)); | ||
assignmentPath.get("right").replaceWith(t.binaryExpression(op, t.memberExpression(superProp.node.object, t.identifier(tmp.name), true), value)); | ||
} else { | ||
assignmentPath.get("left").replaceWith(t.memberExpression(superProp.node.object, superProp.node.property)); | ||
assignmentPath.get("right").replaceWith(t.binaryExpression(op, t.memberExpression(superProp.node.object, t.identifier(superProp.node.property.name)), value)); | ||
} | ||
return [assignmentPath.get("left"), assignmentPath.get("right").get("left")]; | ||
@@ -254,4 +248,4 @@ } else if (superProp.parentPath.isUpdateExpression()) { | ||
var _tmp = superProp.scope.generateDeclaredUidIdentifier("tmp"); | ||
var computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null; | ||
var parts = [t.assignmentExpression("=", _tmp, t.memberExpression(superProp.node.object, computedKey ? t.assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), t.assignmentExpression("=", t.memberExpression(superProp.node.object, computedKey ? t.identifier(computedKey.name) : superProp.node.property, superProp.node.computed), t.binaryExpression("+", t.identifier(_tmp.name), t.numericLiteral(1)))]; | ||
@@ -264,3 +258,2 @@ | ||
updateExpr.replaceWith(t.sequenceExpression(parts)); | ||
var left = updateExpr.get("expressions.0.right"); | ||
@@ -283,3 +276,2 @@ var right = updateExpr.get("expressions.1.left"); | ||
if (!inConstructor || !hasSuperClass(thisEnvFn)) return t.thisExpression(); | ||
var supers = new WeakSet(); | ||
@@ -298,3 +290,2 @@ thisEnvFn.traverse({ | ||
supers.add(child.node); | ||
child.replaceWith(t.assignmentExpression("=", t.identifier(thisBinding), child.node)); | ||
@@ -317,4 +308,4 @@ } | ||
var argsList = [t.restElement(argsBinding)]; | ||
var fnBody = void 0; | ||
var fnBody = void 0; | ||
if (propName) { | ||
@@ -324,3 +315,2 @@ fnBody = t.callExpression(t.memberExpression(t.super(), t.identifier(propName)), [t.spreadElement(t.identifier(argsBinding.name))]); | ||
var method = thisEnvFn.scope.generateUidIdentifier("prop"); | ||
argsList.unshift(method); | ||
@@ -336,7 +326,6 @@ fnBody = t.callExpression(t.memberExpression(t.super(), t.identifier(method.name), true), [t.spreadElement(t.identifier(argsBinding.name))]); | ||
var op = isAssignment ? "set" : "get"; | ||
return getBinding(thisEnvFn, "superprop_" + op + ":" + (propName || ""), function () { | ||
var argsList = []; | ||
var fnBody = void 0; | ||
var fnBody = void 0; | ||
if (propName) { | ||
@@ -346,3 +335,2 @@ fnBody = t.memberExpression(t.super(), t.identifier(propName)); | ||
var method = thisEnvFn.scope.generateUidIdentifier("prop"); | ||
argsList.unshift(method); | ||
@@ -355,3 +343,2 @@ fnBody = t.memberExpression(t.super(), t.identifier(method.name), true); | ||
argsList.push(valueIdent); | ||
fnBody = t.assignmentExpression("=", fnBody, t.identifier(valueIdent.name)); | ||
@@ -367,2 +354,3 @@ } | ||
var data = thisEnvFn.getData(cacheKey); | ||
if (!data) { | ||
@@ -372,3 +360,2 @@ var id = thisEnvFn.scope.generateUidIdentifier(key); | ||
thisEnvFn.setData(cacheKey, data); | ||
thisEnvFn.scope.push({ | ||
@@ -389,3 +376,2 @@ id: id, | ||
var superCalls = []; | ||
fnPath.traverse({ | ||
@@ -401,3 +387,8 @@ Function: function Function(child) { | ||
if (child.node.name !== "this") return; | ||
if (!child.parentPath.isJSXMemberExpression({ object: child.node }) && !child.parentPath.isJSXOpeningElement({ name: child.node })) { | ||
if (!child.parentPath.isJSXMemberExpression({ | ||
object: child.node | ||
}) && !child.parentPath.isJSXOpeningElement({ | ||
name: child.node | ||
})) { | ||
return; | ||
@@ -416,13 +407,14 @@ } | ||
if (child.node.name !== "arguments") return; | ||
argumentsPaths.push(child); | ||
}, | ||
MetaProperty: function MetaProperty(child) { | ||
if (!child.get("meta").isIdentifier({ name: "new" })) return; | ||
if (!child.get("property").isIdentifier({ name: "target" })) return; | ||
if (!child.get("meta").isIdentifier({ | ||
name: "new" | ||
})) return; | ||
if (!child.get("property").isIdentifier({ | ||
name: "target" | ||
})) return; | ||
newTargetPaths.push(child); | ||
} | ||
}); | ||
return { | ||
@@ -429,0 +421,0 @@ thisPaths: thisPaths, |
@@ -9,4 +9,2 @@ "use strict"; | ||
exports.evaluate = evaluate; | ||
var VALID_CALLEES = ["String", "Number", "Math"]; | ||
@@ -30,5 +28,5 @@ var INVALID_METHODS = ["random"]; | ||
if (seen.has(node)) { | ||
var existing = seen.get(node); | ||
if (existing.resolved) { | ||
@@ -41,6 +39,9 @@ return existing.value; | ||
} else { | ||
var item = { resolved: false }; | ||
var item = { | ||
resolved: false | ||
}; | ||
seen.set(node, item); | ||
var val = _evaluate(path, state); | ||
if (state.confident) { | ||
@@ -50,2 +51,3 @@ item.resolved = true; | ||
} | ||
return val; | ||
@@ -57,6 +59,4 @@ } | ||
if (!state.confident) return; | ||
var node = path.node; | ||
if (path.isSequenceExpression()) { | ||
@@ -82,3 +82,2 @@ var exprs = path.get("expressions"); | ||
var name = object.node.name; | ||
var property = path.get("tag.property"); | ||
@@ -94,2 +93,3 @@ | ||
if (!state.confident) return; | ||
if (testResult) { | ||
@@ -106,4 +106,7 @@ return evaluateCached(path.get("consequent"), state); | ||
if (path.isMemberExpression() && !path.parentPath.isCallExpression({ callee: node })) { | ||
if (path.isMemberExpression() && !path.parentPath.isCallExpression({ | ||
callee: node | ||
})) { | ||
var _property = path.get("property"); | ||
var _object = path.get("object"); | ||
@@ -114,2 +117,3 @@ | ||
var type = typeof value === "undefined" ? "undefined" : _typeof(value); | ||
if (type === "number" || type === "string") { | ||
@@ -144,2 +148,3 @@ return value[_property.node.name]; | ||
var resolved = path.resolve(); | ||
if (resolved === path) { | ||
@@ -153,3 +158,5 @@ return deopt(path, state); | ||
if (path.isUnaryExpression({ prefix: true })) { | ||
if (path.isUnaryExpression({ | ||
prefix: true | ||
})) { | ||
if (node.operator === "void") { | ||
@@ -160,2 +167,3 @@ return undefined; | ||
var argument = path.get("argument"); | ||
if (node.operator === "typeof" && (argument.isFunction() || argument.isClass())) { | ||
@@ -167,11 +175,16 @@ return "function"; | ||
if (!state.confident) return; | ||
switch (node.operator) { | ||
case "!": | ||
return !arg; | ||
case "+": | ||
return +arg; | ||
case "-": | ||
return -arg; | ||
case "~": | ||
return ~arg; | ||
case "typeof": | ||
@@ -185,2 +198,3 @@ return typeof arg === "undefined" ? "undefined" : _typeof(arg); | ||
var elems = path.get("elements"); | ||
for (var _iterator = elems, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
@@ -199,3 +213,2 @@ var _ref; | ||
var elem = _ref; | ||
elem = elem.evaluate(); | ||
@@ -209,2 +222,3 @@ | ||
} | ||
return arr; | ||
@@ -216,2 +230,3 @@ } | ||
var props = path.get("properties"); | ||
for (var _iterator2 = props, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
@@ -234,9 +249,13 @@ var _ref2; | ||
} | ||
var keyPath = prop.get("key"); | ||
var key = keyPath; | ||
if (prop.node.computed) { | ||
key = key.evaluate(); | ||
if (!key.confident) { | ||
return deopt(keyPath, state); | ||
} | ||
key = key.value; | ||
@@ -248,10 +267,15 @@ } else if (key.isIdentifier()) { | ||
} | ||
var valuePath = prop.get("value"); | ||
var _value = valuePath.evaluate(); | ||
if (!_value.confident) { | ||
return deopt(valuePath, state); | ||
} | ||
_value = _value.value; | ||
obj[key] = _value; | ||
} | ||
return obj; | ||
@@ -277,4 +301,4 @@ } | ||
if (!state.confident) return; | ||
return left || right; | ||
return left || right; | ||
case "&&": | ||
@@ -286,3 +310,2 @@ if (!left && leftConfident || !right && rightConfident) { | ||
if (!state.confident) return; | ||
return left && right; | ||
@@ -294,4 +317,7 @@ } | ||
var _left = evaluateCached(path.get("left"), state); | ||
if (!state.confident) return; | ||
var _right = evaluateCached(path.get("right"), state); | ||
if (!state.confident) return; | ||
@@ -302,38 +328,57 @@ | ||
return _left - _right; | ||
case "+": | ||
return _left + _right; | ||
case "/": | ||
return _left / _right; | ||
case "*": | ||
return _left * _right; | ||
case "%": | ||
return _left % _right; | ||
case "**": | ||
return Math.pow(_left, _right); | ||
case "<": | ||
return _left < _right; | ||
case ">": | ||
return _left > _right; | ||
case "<=": | ||
return _left <= _right; | ||
case ">=": | ||
return _left >= _right; | ||
case "==": | ||
return _left == _right; | ||
case "!=": | ||
return _left != _right; | ||
case "===": | ||
return _left === _right; | ||
case "!==": | ||
return _left !== _right; | ||
case "|": | ||
return _left | _right; | ||
case "&": | ||
return _left & _right; | ||
case "^": | ||
return _left ^ _right; | ||
case "<<": | ||
return _left << _right; | ||
case ">>": | ||
return _left >> _right; | ||
case ">>>": | ||
@@ -355,2 +400,3 @@ return _left >>> _right; | ||
var _object2 = callee.get("object"); | ||
var _property2 = callee.get("property"); | ||
@@ -365,2 +411,3 @@ | ||
var _type = _typeof(_object2.node.value); | ||
if (_type === "string" || _type === "number") { | ||
@@ -378,3 +425,2 @@ context = _object2.node.value; | ||
if (!state.confident) return; | ||
return func.apply(context, args); | ||
@@ -389,5 +435,3 @@ } | ||
var raw = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
var str = ""; | ||
var i = 0; | ||
@@ -409,7 +453,4 @@ var exprs = path.get("expressions"); | ||
var elem = _ref3; | ||
if (!state.confident) break; | ||
str += raw ? elem.value.raw : elem.value.cooked; | ||
var expr = exprs[i++]; | ||
@@ -431,3 +472,2 @@ if (expr) str += String(evaluateCached(expr, state)); | ||
if (!state.confident) value = undefined; | ||
return { | ||
@@ -434,0 +474,0 @@ confident: state.confident, |
@@ -89,2 +89,3 @@ "use strict"; | ||
var siblings = []; | ||
while (sibling.node) { | ||
@@ -94,2 +95,3 @@ siblings.push(sibling); | ||
} | ||
return siblings; | ||
@@ -102,2 +104,3 @@ } | ||
var siblings = []; | ||
while (sibling.node) { | ||
@@ -107,2 +110,3 @@ siblings.push(sibling); | ||
} | ||
return siblings; | ||
@@ -114,2 +118,3 @@ } | ||
var parts = key.split("."); | ||
if (parts.length === 1) { | ||
@@ -150,16 +155,7 @@ return this._getKey(key, context); | ||
var path = this; | ||
for (var _iterator = parts, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
var _arr = parts; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var part = _arr[_i]; | ||
var part = _ref; | ||
if (part === ".") { | ||
@@ -175,2 +171,3 @@ path = path.parentPath; | ||
} | ||
return path; | ||
@@ -190,3 +187,2 @@ } | ||
var outerOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var path = this; | ||
@@ -200,3 +196,2 @@ var search = [].concat(path); | ||
if (!id.node) continue; | ||
var keys = t.getBindingIdentifiers.keys[id.node.type]; | ||
@@ -207,2 +202,3 @@ | ||
var _ids = ids[id.node.name] = ids[id.node.name] || []; | ||
_ids.push(id); | ||
@@ -212,2 +208,3 @@ } else { | ||
} | ||
continue; | ||
@@ -218,5 +215,7 @@ } | ||
var declaration = id.get("declaration"); | ||
if (declaration.isDeclaration()) { | ||
search.push(declaration); | ||
} | ||
continue; | ||
@@ -230,2 +229,3 @@ } | ||
} | ||
if (id.isFunctionExpression()) { | ||
@@ -240,2 +240,3 @@ continue; | ||
var child = id.get(key); | ||
if (Array.isArray(child) || child.node) { | ||
@@ -242,0 +243,0 @@ search = search.concat(child); |
@@ -80,4 +80,2 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _debug = (0, _debug3.default)("babel"); | ||
@@ -87,4 +85,2 @@ | ||
function NodePath(hub, parent) { | ||
_classCallCheck(this, NodePath); | ||
this.parent = parent; | ||
@@ -126,6 +122,5 @@ this.hub = hub; | ||
(0, _invariant2.default)(parent, "To get a node path the parent needs to exist"); | ||
var targetNode = container[key]; | ||
var paths = _cache.path.get(parent) || []; | ||
var paths = _cache.path.get(parent) || []; | ||
if (!_cache.path.has(parent)) { | ||
@@ -139,2 +134,3 @@ _cache.path.set(parent, paths); | ||
var pathCheck = paths[i]; | ||
if (pathCheck.node === targetNode) { | ||
@@ -152,3 +148,2 @@ path = pathCheck; | ||
path.setup(parentPath, container, listKey, key); | ||
return path; | ||
@@ -179,3 +174,2 @@ }; | ||
var Error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SyntaxError; | ||
return this.hub.file.buildCodeFrameError(this.node, msg, Error); | ||
@@ -204,2 +198,3 @@ }; | ||
var path = this; | ||
do { | ||
@@ -210,2 +205,3 @@ var key = path.key; | ||
} while (path = path.parentPath); | ||
return parts.join("."); | ||
@@ -216,2 +212,3 @@ }; | ||
if (!_debug.enabled) return; | ||
_debug(this.getPathLocation() + " " + this.type + ": " + buildMessage()); | ||
@@ -224,4 +221,2 @@ }; | ||
exports.default = NodePath; | ||
Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments); | ||
@@ -231,2 +226,3 @@ | ||
var typeKey = "is" + type; | ||
NodePath.prototype[typeKey] = function (opts) { | ||
@@ -243,16 +239,7 @@ return t[typeKey](this.node, opts); | ||
for (var _iterator = t.TYPES, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref2; | ||
var _arr = t.TYPES; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref2 = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref2 = _i.value; | ||
} | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var type = _arr[_i]; | ||
var type = _ref2; | ||
_loop(type); | ||
@@ -264,3 +251,2 @@ } | ||
if (t.TYPES.indexOf(type) < 0) t.TYPES.push(type); | ||
var virtualType = virtualTypes[type]; | ||
@@ -267,0 +253,0 @@ |
@@ -23,3 +23,2 @@ "use strict"; | ||
if (this.typeAnnotation) return this.typeAnnotation; | ||
var type = this._getTypeAnnotation() || t.anyTypeAnnotation(); | ||
@@ -57,2 +56,3 @@ if (t.isTypeAnnotation(type)) type = type.typeAnnotation; | ||
var inferer = inferers[node.type]; | ||
if (inferer) { | ||
@@ -63,2 +63,3 @@ return inferer.call(this, node); | ||
inferer = inferers[this.parentPath.type]; | ||
if (inferer && inferer.validParent) { | ||
@@ -102,16 +103,7 @@ return this.parentPath.getTypeAnnotation(); | ||
if (t.isUnionTypeAnnotation(type)) { | ||
for (var _iterator = type.types, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
var _arr = type.types; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var type2 = _arr[_i]; | ||
var type2 = _ref; | ||
if (t.isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) { | ||
@@ -121,2 +113,3 @@ return true; | ||
} | ||
return false; | ||
@@ -139,3 +132,5 @@ } else { | ||
var type = this.getTypeAnnotation(); | ||
return t.isGenericTypeAnnotation(type) && t.isIdentifier(type.id, { name: genericName }); | ||
return t.isGenericTypeAnnotation(type) && t.isIdentifier(type.id, { | ||
name: genericName | ||
}); | ||
} |
@@ -7,4 +7,4 @@ "use strict"; | ||
if (!this.isReferenced()) return; | ||
var binding = this.scope.getBinding(node.name); | ||
var binding = this.scope.getBinding(node.name); | ||
if (binding) { | ||
@@ -14,3 +14,3 @@ if (binding.identifier.typeAnnotation) { | ||
} else { | ||
return getTypeAnnotationBindingConstantViolations(this, node.name); | ||
return getTypeAnnotationBindingConstantViolations(binding, this, node.name); | ||
} | ||
@@ -32,19 +32,13 @@ } | ||
function getTypeAnnotationBindingConstantViolations(path, name) { | ||
var binding = path.scope.getBinding(name); | ||
function getTypeAnnotationBindingConstantViolations(binding, path, name) { | ||
var types = []; | ||
path.typeAnnotation = t.unionTypeAnnotation(types); | ||
var functionConstantViolations = []; | ||
var constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations); | ||
var testType = getConditionalAnnotation(binding, path, name); | ||
var testType = getConditionalAnnotation(path, name); | ||
if (testType) { | ||
var testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement); | ||
constantViolations = constantViolations.filter(function (path) { | ||
return testConstantViolations.indexOf(path) < 0; | ||
}); | ||
types.push(testType.typeAnnotation); | ||
@@ -55,17 +49,6 @@ } | ||
constantViolations = constantViolations.concat(functionConstantViolations); | ||
var _arr = constantViolations; | ||
for (var _iterator = constantViolations, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var violation = _ref; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var violation = _arr[_i]; | ||
types.push(violation.getTypeAnnotation()); | ||
@@ -85,3 +68,5 @@ } | ||
violation = violation.resolve(); | ||
var status = violation._guessExecutionStatusRelativeTo(path); | ||
if (functions && status === "function") functions.push(violation); | ||
@@ -94,48 +79,58 @@ return status === "before"; | ||
var operator = path.node.operator; | ||
var right = path.get("right").resolve(); | ||
var left = path.get("left").resolve(); | ||
var target = void 0; | ||
var target = void 0; | ||
if (left.isIdentifier({ name: name })) { | ||
if (left.isIdentifier({ | ||
name: name | ||
})) { | ||
target = right; | ||
} else if (right.isIdentifier({ name: name })) { | ||
} else if (right.isIdentifier({ | ||
name: name | ||
})) { | ||
target = left; | ||
} | ||
if (target) { | ||
if (operator === "===") { | ||
return target.getTypeAnnotation(); | ||
} else if (t.BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) { | ||
} | ||
if (t.BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t.numberTypeAnnotation(); | ||
} else { | ||
return; | ||
} | ||
} else { | ||
if (operator !== "===") return; | ||
return; | ||
} | ||
if (operator !== "===" && operator !== "==") return; | ||
var typeofPath = void 0; | ||
var typePath = void 0; | ||
if (left.isUnaryExpression({ operator: "typeof" })) { | ||
if (left.isUnaryExpression({ | ||
operator: "typeof" | ||
})) { | ||
typeofPath = left; | ||
typePath = right; | ||
} else if (right.isUnaryExpression({ operator: "typeof" })) { | ||
} else if (right.isUnaryExpression({ | ||
operator: "typeof" | ||
})) { | ||
typeofPath = right; | ||
typePath = left; | ||
} | ||
if (!typePath && !typeofPath) return; | ||
if (!typeofPath) return; | ||
if (!typeofPath.get("argument").isIdentifier({ | ||
name: name | ||
})) return; | ||
typePath = typePath.resolve(); | ||
if (!typePath.isLiteral()) return; | ||
var typeValue = typePath.node.value; | ||
if (typeof typeValue !== "string") return; | ||
if (!typeofPath.get("argument").isIdentifier({ name: name })) return; | ||
return t.createTypeAnnotationBasedOnTypeof(typePath.node.value); | ||
return t.createTypeAnnotationBasedOnTypeof(typeValue); | ||
} | ||
function getParentConditionalPath(path) { | ||
function getParentConditionalPath(binding, path, name) { | ||
var parentPath = void 0; | ||
while (parentPath = path.parentPath) { | ||
@@ -145,15 +140,18 @@ if (parentPath.isIfStatement() || parentPath.isConditionalExpression()) { | ||
return; | ||
} else { | ||
return parentPath; | ||
} | ||
} else { | ||
path = parentPath; | ||
return parentPath; | ||
} | ||
if (parentPath.isFunction()) { | ||
if (parentPath.parentPath.scope.getBinding(name) !== binding) return; | ||
} | ||
path = parentPath; | ||
} | ||
} | ||
function getConditionalAnnotation(path, name) { | ||
var ifStatement = getParentConditionalPath(path); | ||
function getConditionalAnnotation(binding, path, name) { | ||
var ifStatement = getParentConditionalPath(binding, path, name); | ||
if (!ifStatement) return; | ||
var test = ifStatement.get("test"); | ||
@@ -163,15 +161,15 @@ var paths = [test]; | ||
do { | ||
var _path = paths.shift().resolve(); | ||
for (var i = 0; i < paths.length; i++) { | ||
var _path = paths[i]; | ||
if (_path.isLogicalExpression()) { | ||
paths.push(_path.get("left")); | ||
paths.push(_path.get("right")); | ||
} | ||
if (_path.isBinaryExpression()) { | ||
if (_path.node.operator === "&&") { | ||
paths.push(_path.get("left")); | ||
paths.push(_path.get("right")); | ||
} | ||
} else if (_path.isBinaryExpression()) { | ||
var type = inferAnnotationFromBinaryExpression(name, _path); | ||
if (type) types.push(type); | ||
} | ||
} while (paths.length); | ||
} | ||
@@ -183,5 +181,5 @@ if (types.length) { | ||
}; | ||
} else { | ||
return getConditionalAnnotation(ifStatement, name); | ||
} | ||
return getConditionalAnnotation(ifStatement, name); | ||
} |
@@ -123,2 +123,3 @@ "use strict"; | ||
var operator = node.operator; | ||
if (operator === "++" || operator === "--") { | ||
@@ -172,3 +173,18 @@ return t.numberTypeAnnotation(); | ||
exports.ClassDeclaration = Func; | ||
var isArrayFrom = t.buildMatchMemberExpression("Array.from"); | ||
var isObjectKeys = t.buildMatchMemberExpression("Object.keys"); | ||
var isObjectValues = t.buildMatchMemberExpression("Object.values"); | ||
var isObjectEntries = t.buildMatchMemberExpression("Object.entries"); | ||
function CallExpression() { | ||
var callee = this.node.callee; | ||
if (isObjectKeys(callee)) { | ||
return t.arrayTypeAnnotation(t.stringTypeAnnotation()); | ||
} else if (isArrayFrom(callee) || isObjectValues(callee)) { | ||
return t.arrayTypeAnnotation(t.anyTypeAnnotation()); | ||
} else if (isObjectEntries(callee)) { | ||
return t.arrayTypeAnnotation(t.tupleTypeAnnotation([t.stringTypeAnnotation(), t.anyTypeAnnotation()])); | ||
} | ||
return resolveCall(this.get("callee")); | ||
@@ -175,0 +191,0 @@ } |
@@ -41,2 +41,3 @@ "use strict"; | ||
var val = this.node && this.node[key]; | ||
if (val && Array.isArray(val)) { | ||
@@ -116,6 +117,4 @@ return !!val.length; | ||
if (!this.isReferencedIdentifier()) return false; | ||
var binding = this.scope.getBinding(this.node.name); | ||
if (!binding || binding.kind !== "module") return false; | ||
var path = binding.path; | ||
@@ -148,2 +147,3 @@ var parent = path.parentPath; | ||
var node = this.node; | ||
if (node.end) { | ||
@@ -166,2 +166,3 @@ return this.hub.file.code.slice(node.start, node.end); | ||
var status = this._guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent); | ||
if (status) { | ||
@@ -176,11 +177,11 @@ return status; | ||
if (targetPaths.indexOf(this) >= 0) return "after"; | ||
var selfPaths = this.getAncestry(); | ||
var commonPath = void 0; | ||
var targetIndex = void 0; | ||
var selfIndex = void 0; | ||
for (selfIndex = 0; selfIndex < selfPaths.length; selfIndex++) { | ||
var selfPath = selfPaths[selfIndex]; | ||
targetIndex = targetPaths.indexOf(selfPath); | ||
if (targetIndex >= 0) { | ||
@@ -191,2 +192,3 @@ commonPath = selfPath; | ||
} | ||
if (!commonPath) { | ||
@@ -198,2 +200,3 @@ return "before"; | ||
var selfRelationship = selfPaths[selfIndex - 1]; | ||
if (!targetRelationship || !selfRelationship) { | ||
@@ -215,7 +218,4 @@ return "before"; | ||
if (!targetFuncPath.isFunctionDeclaration()) return; | ||
var binding = targetFuncPath.scope.getBinding(targetFuncPath.node.id.name); | ||
if (!binding.references) return "before"; | ||
var referencePaths = binding.referencePaths; | ||
@@ -257,3 +257,2 @@ | ||
var _path = _ref2; | ||
var childOfFunction = !!_path.find(function (path) { | ||
@@ -282,3 +281,2 @@ return path.node === targetFuncPath.node; | ||
if (resolved && resolved.indexOf(this) >= 0) return; | ||
resolved = resolved || []; | ||
@@ -294,5 +292,3 @@ resolved.push(this); | ||
if (!binding) return; | ||
if (!binding.constant) return; | ||
if (binding.kind === "module") return; | ||
@@ -302,3 +298,2 @@ | ||
var ret = binding.path.resolve(dangerous, resolved); | ||
if (this.find(function (parent) { | ||
@@ -312,8 +307,5 @@ return parent.node === ret.node; | ||
} else if (dangerous && this.isMemberExpression()) { | ||
var targetKey = this.toComputedKey(); | ||
if (!t.isLiteral(targetKey)) return; | ||
var targetName = targetKey.value; | ||
var target = this.get("object").resolve(dangerous, resolved); | ||
@@ -323,24 +315,14 @@ | ||
var props = target.get("properties"); | ||
for (var _iterator3 = props, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
var _arr = props; | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i3++]; | ||
} else { | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref3 = _i3.value; | ||
} | ||
var prop = _ref3; | ||
for (var _i3 = 0; _i3 < _arr.length; _i3++) { | ||
var prop = _arr[_i3]; | ||
if (!prop.isProperty()) continue; | ||
var key = prop.get("key"); | ||
var match = prop.isnt("computed") && key.isIdentifier({ name: targetName }); | ||
match = match || key.isLiteral({ value: targetName }); | ||
var match = prop.isnt("computed") && key.isIdentifier({ | ||
name: targetName | ||
}); | ||
match = match || key.isLiteral({ | ||
value: targetName | ||
}); | ||
if (match) return prop.get("value").resolve(dangerous, resolved); | ||
@@ -347,0 +329,0 @@ } |
@@ -12,4 +12,2 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var referenceVisitor = { | ||
@@ -23,2 +21,3 @@ ReferencedIdentifier: function ReferencedIdentifier(path, state) { | ||
var scope = path.scope; | ||
do { | ||
@@ -29,2 +28,3 @@ if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) { | ||
} while (scope = scope.parent); | ||
if (scope) state.breakOnScopePaths.push(scope.path); | ||
@@ -35,5 +35,3 @@ } | ||
if (!binding) return; | ||
if (binding !== state.scope.getBinding(path.node.name)) return; | ||
state.bindings[path.node.name] = binding; | ||
@@ -45,13 +43,7 @@ } | ||
function PathHoister(path, scope) { | ||
_classCallCheck(this, PathHoister); | ||
this.breakOnScopePaths = []; | ||
this.bindings = {}; | ||
this.scopes = []; | ||
this.scope = scope; | ||
this.path = path; | ||
this.attachAfter = false; | ||
@@ -63,2 +55,3 @@ } | ||
var binding = this.bindings[key]; | ||
if (!scope.bindingIdentifierEquals(key, binding.identifier)) { | ||
@@ -74,2 +67,3 @@ return false; | ||
var scope = this.path.scope; | ||
do { | ||
@@ -90,4 +84,4 @@ if (this.isCompatibleScope(scope)) { | ||
var path = this._getAttachmentPath(); | ||
if (!path) return; | ||
var targetScope = path.scope; | ||
@@ -102,3 +96,2 @@ | ||
if (!targetScope.hasOwnBinding(name)) continue; | ||
var binding = this.bindings[name]; | ||
@@ -115,17 +108,7 @@ | ||
path = binding.path; | ||
var _arr = binding.constantViolations; | ||
for (var _iterator = binding.constantViolations, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var violationPath = _arr[_i]; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var violationPath = _ref; | ||
if (this.getAttachmentParentForPath(violationPath).key > path.key) { | ||
@@ -148,5 +131,3 @@ path = violationPath; | ||
var scopes = this.scopes; | ||
var scope = scopes.pop(); | ||
if (!scope) return; | ||
@@ -157,4 +138,4 @@ | ||
if (this.scope === scope) return; | ||
var bodies = scope.path.get("body").get("body"); | ||
var bodies = scope.path.get("body").get("body"); | ||
for (var i = 0; i < bodies.length; i++) { | ||
@@ -188,7 +169,6 @@ if (bodies[i].node._blockHoist) continue; | ||
if (!scope.hasOwnBinding(name)) continue; | ||
var binding = this.bindings[name]; | ||
if (binding.kind === "param" && binding.constant) return true; | ||
} | ||
return false; | ||
@@ -198,22 +178,13 @@ }; | ||
PathHoister.prototype.run = function run() { | ||
var node = this.path.node; | ||
if (node._hoisted) return; | ||
node._hoisted = true; | ||
this.path.traverse(referenceVisitor, this); | ||
this.getCompatibleScopes(); | ||
var attachTo = this.getAttachmentPath(); | ||
if (!attachTo) return; | ||
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return; | ||
var uid = attachTo.scope.generateUidIdentifier("ref"); | ||
var declarator = t.variableDeclarator(uid, this.path.node); | ||
var insertFn = this.attachAfter ? "insertAfter" : "insertBefore"; | ||
attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t.variableDeclaration("var", [declarator])]); | ||
var parent = this.path.parentPath; | ||
var parent = this.path.parentPath; | ||
if (parent.isJSXElement() && this.path.container === parent.node.children) { | ||
@@ -220,0 +191,0 @@ uid = t.JSXExpressionContainer(uid); |
@@ -23,2 +23,3 @@ "use strict"; | ||
} | ||
return true; | ||
@@ -25,0 +26,0 @@ } |
@@ -29,3 +29,2 @@ "use strict"; | ||
}; | ||
var ReferencedMemberExpression = exports.ReferencedMemberExpression = { | ||
@@ -36,7 +35,5 @@ types: ["MemberExpression"], | ||
parent = _ref2.parent; | ||
return t.isMemberExpression(node) && t.isReferenced(node, parent); | ||
} | ||
}; | ||
var BindingIdentifier = exports.BindingIdentifier = { | ||
@@ -47,7 +44,5 @@ types: ["Identifier"], | ||
parent = _ref3.parent; | ||
return t.isIdentifier(node) && t.isBinding(node, parent); | ||
} | ||
}; | ||
var Statement = exports.Statement = { | ||
@@ -61,4 +56,8 @@ types: ["Statement"], | ||
if (t.isVariableDeclaration(node)) { | ||
if (t.isForXStatement(parent, { left: node })) return false; | ||
if (t.isForStatement(parent, { init: node })) return false; | ||
if (t.isForXStatement(parent, { | ||
left: node | ||
})) return false; | ||
if (t.isForStatement(parent, { | ||
init: node | ||
})) return false; | ||
} | ||
@@ -72,3 +71,2 @@ | ||
}; | ||
var Expression = exports.Expression = { | ||
@@ -84,3 +82,2 @@ types: ["Expression"], | ||
}; | ||
var Scope = exports.Scope = { | ||
@@ -92,3 +89,2 @@ types: ["Scopable"], | ||
}; | ||
var Referenced = exports.Referenced = { | ||
@@ -99,3 +95,2 @@ checkPath: function checkPath(path) { | ||
}; | ||
var BlockScoped = exports.BlockScoped = { | ||
@@ -106,3 +101,2 @@ checkPath: function checkPath(path) { | ||
}; | ||
var Var = exports.Var = { | ||
@@ -114,3 +108,2 @@ types: ["VariableDeclaration"], | ||
}; | ||
var User = exports.User = { | ||
@@ -121,3 +114,2 @@ checkPath: function checkPath(path) { | ||
}; | ||
var Generated = exports.Generated = { | ||
@@ -128,3 +120,2 @@ checkPath: function checkPath(path) { | ||
}; | ||
var Pure = exports.Pure = { | ||
@@ -135,3 +126,2 @@ checkPath: function checkPath(path, opts) { | ||
}; | ||
var Flow = exports.Flow = { | ||
@@ -155,3 +145,2 @@ types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"], | ||
}; | ||
var RestProperty = exports.RestProperty = { | ||
@@ -163,3 +152,2 @@ types: ["RestElement"], | ||
}; | ||
var SpreadProperty = exports.SpreadProperty = { | ||
@@ -171,11 +159,8 @@ types: ["RestElement"], | ||
}; | ||
var ExistentialTypeParam = exports.ExistentialTypeParam = { | ||
types: ["ExistsTypeAnnotation"] | ||
}; | ||
var NumericLiteralTypeAnnotation = exports.NumericLiteralTypeAnnotation = { | ||
types: ["NumberLiteralTypeAnnotation"] | ||
}; | ||
var ForAwaitStatement = exports.ForAwaitStatement = { | ||
@@ -185,5 +170,4 @@ types: ["ForOfStatement"], | ||
var node = _ref6.node; | ||
return node.await === true; | ||
} | ||
}; |
@@ -11,3 +11,2 @@ "use strict"; | ||
exports._containerInsertAfter = _containerInsertAfter; | ||
exports._maybePopFromStatements = _maybePopFromStatements; | ||
exports.insertAfter = insertAfter; | ||
@@ -45,15 +44,13 @@ exports.updateSiblingKeys = updateSiblingKeys; | ||
return this.parentPath.insertBefore(nodes); | ||
} else if (this.isNodeType("Expression") || this.parentPath.isForStatement() && this.key === "init") { | ||
} else if (this.isNodeType("Expression") && this.listKey !== "params" || this.parentPath.isForStatement() && this.key === "init") { | ||
if (this.node) nodes.push(this.node); | ||
this.replaceExpressionWithStatements(nodes); | ||
} else if (Array.isArray(this.container)) { | ||
return this._containerInsertBefore(nodes); | ||
} else if (this.isStatementOrBlock()) { | ||
if (this.node) nodes.push(this.node); | ||
this._replaceWith(t.blockStatement(nodes)); | ||
} else { | ||
this._maybePopFromStatements(nodes); | ||
if (Array.isArray(this.container)) { | ||
return this._containerInsertBefore(nodes); | ||
} else if (this.isStatementOrBlock()) { | ||
if (this.node) nodes.push(this.node); | ||
this._replaceWith(t.blockStatement(nodes)); | ||
} else { | ||
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?"); | ||
} | ||
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?"); | ||
} | ||
@@ -66,3 +63,2 @@ | ||
this.updateSiblingKeys(from, nodes.length); | ||
var paths = []; | ||
@@ -77,3 +73,2 @@ | ||
var path = this.context.create(this.parent, this.container, to, this.listKey); | ||
if (this.context.queue) path.pushContext(this.context); | ||
@@ -94,17 +89,7 @@ paths.push(path); | ||
for (var _iterator = paths, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
for (var _i = 0; _i < paths.length; _i++) { | ||
var _path = paths[_i]; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
_path.setScope(); | ||
var _path = _ref; | ||
_path.setScope(); | ||
_path.debug(function () { | ||
@@ -114,16 +99,15 @@ return "Inserted."; | ||
for (var _iterator2 = contexts, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
for (var _iterator = contexts, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
if (_isArray) { | ||
if (_i2 >= _iterator.length) break; | ||
_ref = _iterator[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
_i2 = _iterator.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
_ref = _i2.value; | ||
} | ||
var context = _ref2; | ||
var context = _ref; | ||
context.maybeQueue(_path, true); | ||
@@ -144,11 +128,2 @@ } | ||
function _maybePopFromStatements(nodes) { | ||
var last = nodes[nodes.length - 1]; | ||
var isIdentifier = t.isIdentifier(last) || t.isExpressionStatement(last) && t.isIdentifier(last.expression); | ||
if (isIdentifier && !this.isCompletionRecord()) { | ||
nodes.pop(); | ||
} | ||
} | ||
function insertAfter(nodes) { | ||
@@ -167,15 +142,14 @@ this._assertUnremoved(); | ||
} | ||
this.replaceExpressionWithStatements(nodes); | ||
} else if (Array.isArray(this.container)) { | ||
return this._containerInsertAfter(nodes); | ||
} else if (this.isStatementOrBlock()) { | ||
if (this.node && (!this.isExpressionStatement() || this.node.expression != null)) { | ||
nodes.unshift(this.node); | ||
} | ||
this._replaceWith(t.blockStatement(nodes)); | ||
} else { | ||
this._maybePopFromStatements(nodes); | ||
if (Array.isArray(this.container)) { | ||
return this._containerInsertAfter(nodes); | ||
} else if (this.isStatementOrBlock()) { | ||
if (this.node && (!this.isExpressionStatement() || this.node.expression != null)) { | ||
nodes.unshift(this.node); | ||
} | ||
this._replaceWith(t.blockStatement(nodes)); | ||
} else { | ||
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?"); | ||
} | ||
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?"); | ||
} | ||
@@ -190,4 +164,6 @@ | ||
var paths = _cache.path.get(this.parent); | ||
for (var i = 0; i < paths.length; i++) { | ||
var path = paths[i]; | ||
if (path.key >= fromIndex) { | ||
@@ -251,4 +227,4 @@ path.key += incrementBy; | ||
nodes = this._verifyNodeList(nodes); | ||
var container = this.node[listKey]; | ||
var container = this.node[listKey]; | ||
var path = _index2.default.get({ | ||
@@ -267,5 +243,4 @@ parentPath: this, | ||
var scope = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.scope; | ||
var hoister = new _hoister2.default(this, scope); | ||
return hoister.run(); | ||
} |
@@ -19,2 +19,3 @@ "use strict"; | ||
this._markRemoved(); | ||
return; | ||
@@ -24,3 +25,5 @@ } | ||
this.shareCommentsWithSiblings(); | ||
this._remove(); | ||
this._markRemoved(); | ||
@@ -30,16 +33,6 @@ } | ||
function _callRemovalHooks() { | ||
for (var _iterator = _removalHooks.hooks, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
var _arr = _removalHooks.hooks; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var fn = _ref; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var fn = _arr[_i]; | ||
if (fn(this, this.parentPath)) return true; | ||
@@ -46,0 +39,0 @@ } |
@@ -37,24 +37,16 @@ "use strict"; | ||
if (path.node.kind !== "var") return; | ||
var bindings = path.getBindingIdentifiers(); | ||
var bindings = path.getBindingIdentifiers(); | ||
for (var key in bindings) { | ||
path.scope.push({ id: bindings[key] }); | ||
path.scope.push({ | ||
id: bindings[key] | ||
}); | ||
} | ||
var exprs = []; | ||
var _arr = path.node.declarations; | ||
for (var _iterator = path.node.declarations, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var declar = _arr[_i]; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var declar = _ref; | ||
if (declar.init) { | ||
@@ -71,3 +63,2 @@ exprs.push(t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init))); | ||
this.resync(); | ||
nodes = this._verifyNodeList(nodes); | ||
@@ -94,2 +85,3 @@ t.inheritLeadingComments(nodes[0], this.node); | ||
var loc = err.loc; | ||
if (loc) { | ||
@@ -105,2 +97,3 @@ var location = { | ||
} | ||
throw err; | ||
@@ -110,3 +103,5 @@ } | ||
replacement = replacement.program.body[0].expression; | ||
_index2.default.removeProperties(replacement); | ||
return this.replaceWith(replacement); | ||
@@ -159,2 +154,3 @@ } | ||
var oldNode = this.node; | ||
if (oldNode) { | ||
@@ -166,6 +162,5 @@ t.inheritsComments(replacement, oldNode); | ||
this._replaceWith(replacement); | ||
this.type = replacement.type; | ||
this.setScope(); | ||
this.requeue(); | ||
@@ -188,3 +183,2 @@ } | ||
}); | ||
this.node = this.container[this.key] = node; | ||
@@ -195,45 +189,30 @@ } | ||
this.resync(); | ||
var toSequenceExpression = t.toSequenceExpression(nodes, this.scope); | ||
if (t.isSequenceExpression(toSequenceExpression)) { | ||
var exprs = toSequenceExpression.expressions; | ||
if (exprs.length >= 2 && this.parentPath.isExpressionStatement()) { | ||
this._maybePopFromStatements(exprs); | ||
} | ||
if (exprs.length === 1) { | ||
this.replaceWith(exprs[0]); | ||
} else { | ||
this.replaceWith(toSequenceExpression); | ||
} | ||
} else if (toSequenceExpression) { | ||
if (toSequenceExpression) { | ||
this.replaceWith(toSequenceExpression); | ||
} else { | ||
var container = t.arrowFunctionExpression([], t.blockStatement(nodes)); | ||
this.replaceWith(t.callExpression(container, [])); | ||
this.traverse(hoistVariablesVisitor); | ||
var completionRecords = this.get("callee").getCompletionRecords(); | ||
for (var _iterator2 = completionRecords, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
for (var _iterator = completionRecords, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i2 >= _iterator.length) break; | ||
_ref = _iterator[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
_i2 = _iterator.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
_ref = _i2.value; | ||
} | ||
var path = _ref2; | ||
var path = _ref; | ||
if (!path.isExpressionStatement()) continue; | ||
var loop = path.findParent(function (path) { | ||
return path.isLoop(); | ||
}); | ||
if (loop) { | ||
@@ -258,3 +237,2 @@ var uid = loop.getData("expressionReplacementReturnUid"); | ||
this.get("callee").arrowFunctionToExpression(); | ||
return this.node; | ||
@@ -270,3 +248,5 @@ } | ||
nodes = this._verifyNodeList(nodes); | ||
this._containerInsertAfter(nodes); | ||
return this.remove(); | ||
@@ -273,0 +253,0 @@ } else { |
@@ -5,4 +5,2 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Binding = function () { | ||
@@ -16,3 +14,6 @@ function Binding(_ref) { | ||
_classCallCheck(this, Binding); | ||
if (existing) { | ||
existing.constantViolations = existing.constantViolations.concat(path); | ||
return existing; | ||
} | ||
@@ -23,15 +24,8 @@ this.identifier = identifier; | ||
this.kind = kind; | ||
this.constantViolations = []; | ||
this.constant = true; | ||
this.referencePaths = []; | ||
this.referenced = false; | ||
this.references = 0; | ||
this.clearValue(); | ||
if (existing) { | ||
this.constantViolations = [].concat(existing.path, existing.constantViolations, this.constantViolations); | ||
} | ||
} | ||
@@ -58,5 +52,7 @@ | ||
this.constant = false; | ||
if (this.constantViolations.indexOf(path) !== -1) { | ||
return; | ||
} | ||
this.constantViolations.push(path); | ||
@@ -69,2 +65,3 @@ }; | ||
} | ||
this.referenced = true; | ||
@@ -71,0 +68,0 @@ this.references++; |
@@ -50,4 +50,2 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _crawlCallsCount = 0; | ||
@@ -71,3 +69,2 @@ | ||
var scope = _ref; | ||
if (scope.parent === parentScope && scope.path === path) return scope; | ||
@@ -88,16 +85,6 @@ } | ||
} else if (node.specifiers && node.specifiers.length) { | ||
for (var _iterator2 = node.specifiers, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
var _arr = node.specifiers; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
} | ||
var specifier = _ref2; | ||
for (var _i2 = 0; _i2 < _arr.length; _i2++) { | ||
var specifier = _arr[_i2]; | ||
gatherNodeParts(specifier, parts); | ||
@@ -120,16 +107,6 @@ } | ||
} else if (t.isObjectExpression(node) || t.isObjectPattern(node)) { | ||
for (var _iterator3 = node.properties, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
var _arr2 = node.properties; | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i3++]; | ||
} else { | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref3 = _i3.value; | ||
} | ||
var prop = _ref3; | ||
for (var _i3 = 0; _i3 < _arr2.length; _i3++) { | ||
var prop = _arr2[_i3]; | ||
gatherNodeParts(prop.key || prop.argument, parts); | ||
@@ -142,17 +119,8 @@ } | ||
For: function For(path) { | ||
for (var _iterator4 = t.FOR_INIT_KEYS, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref4; | ||
var _arr3 = t.FOR_INIT_KEYS; | ||
if (_isArray4) { | ||
if (_i4 >= _iterator4.length) break; | ||
_ref4 = _iterator4[_i4++]; | ||
} else { | ||
_i4 = _iterator4.next(); | ||
if (_i4.done) break; | ||
_ref4 = _i4.value; | ||
} | ||
for (var _i4 = 0; _i4 < _arr3.length; _i4++) { | ||
var key = _arr3[_i4]; | ||
var declar = path.get(key); | ||
var key = _ref4; | ||
var declar = path.get(key); | ||
if (declar.isVar()) { | ||
@@ -177,2 +145,3 @@ path.scope.getFunctionParent().registerBinding("var", declar); | ||
var left = path.get("left"); | ||
if (left.isPattern() || left.isIdentifier()) { | ||
@@ -182,4 +151,2 @@ state.constantViolations.push(left); | ||
}, | ||
ExportDeclaration: { | ||
@@ -189,28 +156,19 @@ exit: function exit(path) { | ||
scope = path.scope; | ||
var declar = node.declaration; | ||
var declar = node.declaration; | ||
if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) { | ||
var _id = declar.id; | ||
if (!_id) return; | ||
var binding = scope.getBinding(_id.name); | ||
if (binding) binding.reference(path); | ||
} else if (t.isVariableDeclaration(declar)) { | ||
for (var _iterator5 = declar.declarations, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref5; | ||
var _arr4 = declar.declarations; | ||
if (_isArray5) { | ||
if (_i5 >= _iterator5.length) break; | ||
_ref5 = _iterator5[_i5++]; | ||
} else { | ||
_i5 = _iterator5.next(); | ||
if (_i5.done) break; | ||
_ref5 = _i5.value; | ||
} | ||
for (var _i5 = 0; _i5 < _arr4.length; _i5++) { | ||
var decl = _arr4[_i5]; | ||
var ids = t.getBindingIdentifiers(decl); | ||
var decl = _ref5; | ||
var ids = t.getBindingIdentifiers(decl); | ||
for (var name in ids) { | ||
var _binding = scope.getBinding(name); | ||
if (_binding) _binding.reference(path); | ||
@@ -222,3 +180,2 @@ } | ||
}, | ||
LabeledStatement: function LabeledStatement(path) { | ||
@@ -247,3 +204,2 @@ path.scope.getProgramParent().addGlobal(path.node); | ||
if (!id) return; | ||
var name = id.name; | ||
@@ -254,16 +210,7 @@ path.scope.bindings[name] = path.scope.getBinding(name); | ||
var paths = path.get("body"); | ||
for (var _iterator6 = paths, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { | ||
var _ref6; | ||
var _arr5 = paths; | ||
if (_isArray6) { | ||
if (_i6 >= _iterator6.length) break; | ||
_ref6 = _iterator6[_i6++]; | ||
} else { | ||
_i6 = _iterator6.next(); | ||
if (_i6.done) break; | ||
_ref6 = _i6.value; | ||
} | ||
for (var _i6 = 0; _i6 < _arr5.length; _i6++) { | ||
var bodyPath = _arr5[_i6]; | ||
var bodyPath = _ref6; | ||
if (bodyPath.isFunctionDeclaration()) { | ||
@@ -275,9 +222,5 @@ path.scope.getBlockParent().registerDeclaration(bodyPath); | ||
}; | ||
var uid = 0; | ||
var Scope = (_temp = _class = function () { | ||
function Scope(path, parentScope) { | ||
_classCallCheck(this, Scope); | ||
if (parentScope && parentScope.block === path.node) { | ||
@@ -289,11 +232,8 @@ return parentScope; | ||
if (cached) return cached; | ||
this.uid = uid++; | ||
this.parent = parentScope; | ||
this.hub = path.hub; | ||
this.parentBlock = path.parent; | ||
this.block = path.node; | ||
this.path = path; | ||
this.labels = new Map(); | ||
@@ -308,5 +248,6 @@ } | ||
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "temp"; | ||
var id = this.generateUidIdentifier(name); | ||
this.push({ id: id }); | ||
this.push({ | ||
id: id | ||
}); | ||
return id; | ||
@@ -317,3 +258,2 @@ }; | ||
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "temp"; | ||
return t.identifier(this.generateUid(name)); | ||
@@ -324,7 +264,6 @@ }; | ||
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "temp"; | ||
name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, ""); | ||
var uid = void 0; | ||
var i = 0; | ||
do { | ||
@@ -338,3 +277,2 @@ uid = this._generateUid(name, i); | ||
program.uids[uid] = true; | ||
return uid; | ||
@@ -362,6 +300,4 @@ }; | ||
gatherNodeParts(node, parts); | ||
var id = parts.join("$"); | ||
id = id.replace(/^_/, "") || defaultName || "ref"; | ||
return this.generateUidIdentifier(id.slice(0, 20)); | ||
@@ -377,2 +313,3 @@ }; | ||
var binding = this.getBinding(node.name); | ||
if (binding) { | ||
@@ -393,3 +330,6 @@ return binding.constant; | ||
var _id2 = this.generateUidIdentifierBasedOnNode(node); | ||
if (!dontPush) this.push({ id: _id2 }); | ||
if (!dontPush) this.push({ | ||
id: _id2 | ||
}); | ||
return _id2; | ||
@@ -401,5 +341,3 @@ } | ||
if (kind === "param") return; | ||
if (kind === "hoisted" && local.kind === "let") return; | ||
var duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && (kind === "let" || kind === "const"); | ||
@@ -414,2 +352,3 @@ | ||
var binding = this.getBinding(oldName); | ||
if (binding) { | ||
@@ -432,4 +371,6 @@ newName = newName || this.generateUidIdentifier(oldName).name; | ||
var scope = this; | ||
do { | ||
console.log("#", scope.block.type); | ||
for (var name in scope.bindings) { | ||
@@ -445,2 +386,3 @@ var binding = scope.bindings[name]; | ||
} while (scope = scope.parent); | ||
console.log(sep); | ||
@@ -454,2 +396,3 @@ }; | ||
var binding = this.getBinding(node.name); | ||
if (binding && binding.constant && binding.path.isGenericType("Array")) { | ||
@@ -464,3 +407,5 @@ return node; | ||
if (t.isIdentifier(node, { name: "arguments" })) { | ||
if (t.isIdentifier(node, { | ||
name: "arguments" | ||
})) { | ||
return t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Array"), t.identifier("prototype")), t.identifier("slice")), t.identifier("call")), [node]); | ||
@@ -471,2 +416,3 @@ } | ||
var args = [node]; | ||
if (i === true) { | ||
@@ -478,2 +424,3 @@ helperName = "toConsumableArray"; | ||
} | ||
return t.callExpression(file.addHelper(helperName), args); | ||
@@ -501,16 +448,6 @@ }; | ||
var declarations = path.get("declarations"); | ||
for (var _iterator7 = declarations, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { | ||
var _ref7; | ||
var _arr6 = declarations; | ||
if (_isArray7) { | ||
if (_i7 >= _iterator7.length) break; | ||
_ref7 = _iterator7[_i7++]; | ||
} else { | ||
_i7 = _iterator7.next(); | ||
if (_i7.done) break; | ||
_ref7 = _i7.value; | ||
} | ||
var declar = _ref7; | ||
for (var _i7 = 0; _i7 < _arr6.length; _i7++) { | ||
var declar = _arr6[_i7]; | ||
this.registerBinding(path.node.kind, declar); | ||
@@ -522,16 +459,6 @@ } | ||
var specifiers = path.get("specifiers"); | ||
for (var _iterator8 = specifiers, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) { | ||
var _ref8; | ||
var _arr7 = specifiers; | ||
if (_isArray8) { | ||
if (_i8 >= _iterator8.length) break; | ||
_ref8 = _iterator8[_i8++]; | ||
} else { | ||
_i8 = _iterator8.next(); | ||
if (_i8.done) break; | ||
_ref8 = _i8.value; | ||
} | ||
var specifier = _ref8; | ||
for (var _i8 = 0; _i8 < _arr7.length; _i8++) { | ||
var specifier = _arr7[_i8]; | ||
this.registerBinding("module", specifier); | ||
@@ -541,2 +468,3 @@ } | ||
var _declar = path.get("declaration"); | ||
if (_declar.isClassDeclaration() || _declar.isFunctionDeclaration() || _declar.isVariableDeclaration()) { | ||
@@ -560,2 +488,3 @@ this.registerDeclaration(_declar); | ||
var ids = path.getBindingIdentifiers(); | ||
for (var name in ids) { | ||
@@ -569,3 +498,2 @@ var binding = this.getBinding(name); | ||
var bindingPath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : path; | ||
if (!kind) throw new ReferenceError("no `kind`"); | ||
@@ -575,18 +503,19 @@ | ||
var declarators = path.get("declarations"); | ||
for (var _iterator9 = declarators, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) { | ||
var _ref9; | ||
if (_isArray9) { | ||
if (_i9 >= _iterator9.length) break; | ||
_ref9 = _iterator9[_i9++]; | ||
for (var _iterator2 = declarators, _isArray2 = Array.isArray(_iterator2), _i9 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray2) { | ||
if (_i9 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i9++]; | ||
} else { | ||
_i9 = _iterator9.next(); | ||
_i9 = _iterator2.next(); | ||
if (_i9.done) break; | ||
_ref9 = _i9.value; | ||
_ref2 = _i9.value; | ||
} | ||
var declar = _ref9; | ||
var declar = _ref2; | ||
this.registerBinding(kind, declar); | ||
} | ||
return; | ||
@@ -599,20 +528,10 @@ } | ||
for (var name in ids) { | ||
for (var _iterator10 = ids[name], _isArray10 = Array.isArray(_iterator10), _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) { | ||
var _ref10; | ||
var _arr8 = ids[name]; | ||
if (_isArray10) { | ||
if (_i10 >= _iterator10.length) break; | ||
_ref10 = _iterator10[_i10++]; | ||
} else { | ||
_i10 = _iterator10.next(); | ||
if (_i10.done) break; | ||
_ref10 = _i10.value; | ||
} | ||
for (var _i10 = 0; _i10 < _arr8.length; _i10++) { | ||
var _id3 = _arr8[_i10]; | ||
var local = this.getOwnBinding(name); | ||
var _id3 = _ref10; | ||
var local = this.getOwnBinding(name); | ||
if (local) { | ||
if (local.identifier === _id3) continue; | ||
this.checkBlockScopedCollisions(local, kind, name, _id3); | ||
@@ -622,5 +541,3 @@ } | ||
if (local && local.path.isFlow()) local = null; | ||
parent.references[name] = true; | ||
this.bindings[name] = new _binding3.default({ | ||
@@ -681,20 +598,21 @@ identifier: _id3, | ||
} | ||
return this.isPure(node.body, constantsOnly); | ||
} else if (t.isClassBody(node)) { | ||
for (var _iterator11 = node.body, _isArray11 = Array.isArray(_iterator11), _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : _iterator11[Symbol.iterator]();;) { | ||
var _ref11; | ||
for (var _iterator3 = node.body, _isArray3 = Array.isArray(_iterator3), _i11 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
if (_isArray11) { | ||
if (_i11 >= _iterator11.length) break; | ||
_ref11 = _iterator11[_i11++]; | ||
if (_isArray3) { | ||
if (_i11 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i11++]; | ||
} else { | ||
_i11 = _iterator11.next(); | ||
_i11 = _iterator3.next(); | ||
if (_i11.done) break; | ||
_ref11 = _i11.value; | ||
_ref3 = _i11.value; | ||
} | ||
var method = _ref11; | ||
var method = _ref3; | ||
if (!this.isPure(method, constantsOnly)) return false; | ||
} | ||
return true; | ||
@@ -704,36 +622,18 @@ } else if (t.isBinary(node)) { | ||
} else if (t.isArrayExpression(node)) { | ||
for (var _iterator12 = node.elements, _isArray12 = Array.isArray(_iterator12), _i12 = 0, _iterator12 = _isArray12 ? _iterator12 : _iterator12[Symbol.iterator]();;) { | ||
var _ref12; | ||
var _arr9 = node.elements; | ||
if (_isArray12) { | ||
if (_i12 >= _iterator12.length) break; | ||
_ref12 = _iterator12[_i12++]; | ||
} else { | ||
_i12 = _iterator12.next(); | ||
if (_i12.done) break; | ||
_ref12 = _i12.value; | ||
} | ||
var elem = _ref12; | ||
for (var _i12 = 0; _i12 < _arr9.length; _i12++) { | ||
var elem = _arr9[_i12]; | ||
if (!this.isPure(elem, constantsOnly)) return false; | ||
} | ||
return true; | ||
} else if (t.isObjectExpression(node)) { | ||
for (var _iterator13 = node.properties, _isArray13 = Array.isArray(_iterator13), _i13 = 0, _iterator13 = _isArray13 ? _iterator13 : _iterator13[Symbol.iterator]();;) { | ||
var _ref13; | ||
var _arr10 = node.properties; | ||
if (_isArray13) { | ||
if (_i13 >= _iterator13.length) break; | ||
_ref13 = _iterator13[_i13++]; | ||
} else { | ||
_i13 = _iterator13.next(); | ||
if (_i13.done) break; | ||
_ref13 = _i13.value; | ||
} | ||
var prop = _ref13; | ||
for (var _i13 = 0; _i13 < _arr10.length; _i13++) { | ||
var prop = _arr10[_i13]; | ||
if (!this.isPure(prop, constantsOnly)) return false; | ||
} | ||
return true; | ||
@@ -752,18 +652,9 @@ } else if (t.isClassMethod(node)) { | ||
} else if (t.isTemplateLiteral(node)) { | ||
for (var _iterator14 = node.expressions, _isArray14 = Array.isArray(_iterator14), _i14 = 0, _iterator14 = _isArray14 ? _iterator14 : _iterator14[Symbol.iterator]();;) { | ||
var _ref14; | ||
var _arr11 = node.expressions; | ||
if (_isArray14) { | ||
if (_i14 >= _iterator14.length) break; | ||
_ref14 = _iterator14[_i14++]; | ||
} else { | ||
_i14 = _iterator14.next(); | ||
if (_i14.done) break; | ||
_ref14 = _i14.value; | ||
} | ||
var expression = _ref14; | ||
for (var _i14 = 0; _i14 < _arr11.length; _i14++) { | ||
var expression = _arr11[_i14]; | ||
if (!this.isPure(expression, constantsOnly)) return false; | ||
} | ||
return true; | ||
@@ -781,2 +672,3 @@ } else { | ||
var scope = this; | ||
do { | ||
@@ -790,2 +682,3 @@ var data = scope.data[key]; | ||
var scope = this; | ||
do { | ||
@@ -803,3 +696,5 @@ var data = scope.data[key]; | ||
_crawlCallsCount++; | ||
this._crawl(); | ||
_crawlCallsCount--; | ||
@@ -810,3 +705,2 @@ }; | ||
var path = this.path; | ||
this.references = Object.create(null); | ||
@@ -819,16 +713,6 @@ this.bindings = Object.create(null); | ||
if (path.isLoop()) { | ||
for (var _iterator15 = t.FOR_INIT_KEYS, _isArray15 = Array.isArray(_iterator15), _i15 = 0, _iterator15 = _isArray15 ? _iterator15 : _iterator15[Symbol.iterator]();;) { | ||
var _ref15; | ||
var _arr12 = t.FOR_INIT_KEYS; | ||
if (_isArray15) { | ||
if (_i15 >= _iterator15.length) break; | ||
_ref15 = _iterator15[_i15++]; | ||
} else { | ||
_i15 = _iterator15.next(); | ||
if (_i15.done) break; | ||
_ref15 = _i15.value; | ||
} | ||
var key = _ref15; | ||
for (var _i15 = 0; _i15 < _arr12.length; _i15++) { | ||
var key = _arr12[_i15]; | ||
var node = path.get(key); | ||
@@ -853,16 +737,16 @@ if (node.isBlockScoped()) this.registerBinding(node.node.kind, node); | ||
var params = path.get("params"); | ||
for (var _iterator16 = params, _isArray16 = Array.isArray(_iterator16), _i16 = 0, _iterator16 = _isArray16 ? _iterator16 : _iterator16[Symbol.iterator]();;) { | ||
var _ref16; | ||
if (_isArray16) { | ||
if (_i16 >= _iterator16.length) break; | ||
_ref16 = _iterator16[_i16++]; | ||
for (var _iterator4 = params, _isArray4 = Array.isArray(_iterator4), _i16 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref4; | ||
if (_isArray4) { | ||
if (_i16 >= _iterator4.length) break; | ||
_ref4 = _iterator4[_i16++]; | ||
} else { | ||
_i16 = _iterator16.next(); | ||
_i16 = _iterator4.next(); | ||
if (_i16.done) break; | ||
_ref16 = _i16.value; | ||
_ref4 = _i16.value; | ||
} | ||
var param = _ref16; | ||
var param = _ref4; | ||
this.registerBinding("param", param); | ||
@@ -878,3 +762,2 @@ } | ||
if (parent.crawling) return; | ||
var state = { | ||
@@ -885,3 +768,2 @@ references: [], | ||
}; | ||
this.crawling = true; | ||
@@ -891,21 +773,22 @@ path.traverse(collectorVisitor, state); | ||
for (var _iterator17 = state.assignments, _isArray17 = Array.isArray(_iterator17), _i17 = 0, _iterator17 = _isArray17 ? _iterator17 : _iterator17[Symbol.iterator]();;) { | ||
var _ref17; | ||
for (var _iterator5 = state.assignments, _isArray5 = Array.isArray(_iterator5), _i17 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref5; | ||
if (_isArray17) { | ||
if (_i17 >= _iterator17.length) break; | ||
_ref17 = _iterator17[_i17++]; | ||
if (_isArray5) { | ||
if (_i17 >= _iterator5.length) break; | ||
_ref5 = _iterator5[_i17++]; | ||
} else { | ||
_i17 = _iterator17.next(); | ||
_i17 = _iterator5.next(); | ||
if (_i17.done) break; | ||
_ref17 = _i17.value; | ||
_ref5 = _i17.value; | ||
} | ||
var _path = _ref17; | ||
var _path = _ref5; | ||
var ids = _path.getBindingIdentifiers(); | ||
var programParent = void 0; | ||
for (var name in ids) { | ||
if (_path.scope.getBinding(name)) continue; | ||
programParent = programParent || _path.scope.getProgramParent(); | ||
@@ -918,17 +801,17 @@ programParent.addGlobal(ids[name]); | ||
for (var _iterator18 = state.references, _isArray18 = Array.isArray(_iterator18), _i18 = 0, _iterator18 = _isArray18 ? _iterator18 : _iterator18[Symbol.iterator]();;) { | ||
var _ref18; | ||
for (var _iterator6 = state.references, _isArray6 = Array.isArray(_iterator6), _i18 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { | ||
var _ref6; | ||
if (_isArray18) { | ||
if (_i18 >= _iterator18.length) break; | ||
_ref18 = _iterator18[_i18++]; | ||
if (_isArray6) { | ||
if (_i18 >= _iterator6.length) break; | ||
_ref6 = _iterator6[_i18++]; | ||
} else { | ||
_i18 = _iterator18.next(); | ||
_i18 = _iterator6.next(); | ||
if (_i18.done) break; | ||
_ref18 = _i18.value; | ||
_ref6 = _i18.value; | ||
} | ||
var ref = _ref18; | ||
var ref = _ref6; | ||
var binding = ref.scope.getBinding(ref.node.name); | ||
var binding = ref.scope.getBinding(ref.node.name); | ||
if (binding) { | ||
@@ -941,15 +824,15 @@ binding.reference(ref); | ||
for (var _iterator19 = state.constantViolations, _isArray19 = Array.isArray(_iterator19), _i19 = 0, _iterator19 = _isArray19 ? _iterator19 : _iterator19[Symbol.iterator]();;) { | ||
var _ref19; | ||
for (var _iterator7 = state.constantViolations, _isArray7 = Array.isArray(_iterator7), _i19 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) { | ||
var _ref7; | ||
if (_isArray19) { | ||
if (_i19 >= _iterator19.length) break; | ||
_ref19 = _iterator19[_i19++]; | ||
if (_isArray7) { | ||
if (_i19 >= _iterator7.length) break; | ||
_ref7 = _iterator7[_i19++]; | ||
} else { | ||
_i19 = _iterator19.next(); | ||
_i19 = _iterator7.next(); | ||
if (_i19.done) break; | ||
_ref19 = _i19.value; | ||
_ref7 = _i19.value; | ||
} | ||
var _path2 = _ref19; | ||
var _path2 = _ref7; | ||
@@ -979,3 +862,2 @@ _path2.scope.registerConstantViolation(_path2); | ||
var blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist; | ||
var dataKey = "declaration:" + kind + ":" + blockHoist; | ||
@@ -986,3 +868,2 @@ var declarPath = !unique && path.getData(dataKey); | ||
var declar = t.variableDeclaration(kind, []); | ||
declar._generated = true; | ||
declar._blockHoist = blockHoist; | ||
@@ -993,3 +874,2 @@ | ||
declarPath = _path$unshiftContaine[0]; | ||
if (!unique) path.setData(dataKey, declarPath); | ||
@@ -1005,2 +885,3 @@ } | ||
var scope = this; | ||
do { | ||
@@ -1011,2 +892,3 @@ if (scope.path.isProgram()) { | ||
} while (scope = scope.parent); | ||
throw new Error("We couldn't find a Function or Program..."); | ||
@@ -1017,2 +899,3 @@ }; | ||
var scope = this; | ||
do { | ||
@@ -1023,2 +906,3 @@ if (scope.path.isFunctionParent()) { | ||
} while (scope = scope.parent); | ||
throw new Error("We couldn't find a Function or Program..."); | ||
@@ -1029,2 +913,3 @@ }; | ||
var scope = this; | ||
do { | ||
@@ -1035,2 +920,3 @@ if (scope.path.isBlockParent()) { | ||
} while (scope = scope.parent); | ||
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program..."); | ||
@@ -1041,4 +927,4 @@ }; | ||
var ids = Object.create(null); | ||
var scope = this; | ||
var scope = this; | ||
do { | ||
@@ -1054,18 +940,8 @@ (0, _defaults2.default)(ids, scope.bindings); | ||
var ids = Object.create(null); | ||
var _arr13 = arguments; | ||
for (var _iterator20 = arguments, _isArray20 = Array.isArray(_iterator20), _i20 = 0, _iterator20 = _isArray20 ? _iterator20 : _iterator20[Symbol.iterator]();;) { | ||
var _ref20; | ||
for (var _i20 = 0; _i20 < _arr13.length; _i20++) { | ||
var kind = _arr13[_i20]; | ||
var scope = this; | ||
if (_isArray20) { | ||
if (_i20 >= _iterator20.length) break; | ||
_ref20 = _iterator20[_i20++]; | ||
} else { | ||
_i20 = _iterator20.next(); | ||
if (_i20.done) break; | ||
_ref20 = _i20.value; | ||
} | ||
var kind = _ref20; | ||
var scope = this; | ||
do { | ||
@@ -1076,2 +952,3 @@ for (var name in scope.bindings) { | ||
} | ||
scope = scope.parent; | ||
@@ -1092,2 +969,3 @@ } while (scope); | ||
} | ||
return binding; | ||
@@ -1139,2 +1017,3 @@ }; | ||
var info = this.getBinding(name); | ||
if (info) { | ||
@@ -1153,2 +1032,3 @@ info.scope.removeOwnBinding(name); | ||
var info = this.getBinding(name); | ||
if (info) { | ||
@@ -1159,2 +1039,3 @@ info.scope.removeOwnBinding(name); | ||
var scope = this; | ||
do { | ||
@@ -1161,0 +1042,0 @@ if (scope.uids[name]) { |
@@ -18,4 +18,2 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var renameVisitor = { | ||
@@ -45,4 +43,2 @@ ReferencedIdentifier: function ReferencedIdentifier(_ref, state) { | ||
function Renamer(binding, oldName, newName) { | ||
_classCallCheck(this, Renamer); | ||
this.newName = newName; | ||
@@ -56,3 +52,2 @@ this.oldName = oldName; | ||
if (!exportDeclar) return; | ||
var isDefault = exportDeclar.isExportDefaultDeclaration(); | ||
@@ -87,9 +82,6 @@ | ||
return; | ||
if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return; | ||
if (this.binding.kind !== "hoisted") return; | ||
path.node.id = t.identifier(this.oldName); | ||
path.node._blockHoist = 3; | ||
path.replaceWith(t.variableDeclaration("let", [t.variableDeclarator(t.identifier(this.newName), t.toExpression(path.node))])); | ||
@@ -100,12 +92,8 @@ }; | ||
return; | ||
if (!path.isFunctionExpression() && !path.isClassExpression()) return; | ||
if (this.binding.kind !== "local") return; | ||
path.node.id = t.identifier(this.oldName); | ||
this.binding.scope.parent.push({ | ||
id: t.identifier(this.newName) | ||
}); | ||
path.replaceWith(t.assignmentExpression("=", t.identifier(this.newName), path.node)); | ||
@@ -120,7 +108,6 @@ }; | ||
path = binding.path; | ||
var parentDeclar = path.find(function (path) { | ||
return path.isDeclaration() || path.isFunctionExpression(); | ||
}); | ||
if (parentDeclar) { | ||
@@ -127,0 +114,0 @@ this.maybeConvertFromExportDeclaration(parentDeclar); |
@@ -37,6 +37,4 @@ "use strict"; | ||
if (shouldIgnoreKey(nodeType)) continue; | ||
var parts = nodeType.split("|"); | ||
if (parts.length === 1) continue; | ||
var fns = visitor[nodeType]; | ||
@@ -58,3 +56,2 @@ delete visitor[nodeType]; | ||
var part = _ref; | ||
visitor[part] = fns; | ||
@@ -65,29 +62,15 @@ } | ||
verify(visitor); | ||
delete visitor.__esModule; | ||
ensureEntranceObjects(visitor); | ||
ensureCallbackArrays(visitor); | ||
for (var _iterator2 = Object.keys(visitor), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
var _arr = Object.keys(visitor); | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
} | ||
var _nodeType = _ref2; | ||
for (var _i2 = 0; _i2 < _arr.length; _i2++) { | ||
var _nodeType = _arr[_i2]; | ||
if (shouldIgnoreKey(_nodeType)) continue; | ||
var wrapper = virtualTypes[_nodeType]; | ||
if (!wrapper) continue; | ||
var _fns = visitor[_nodeType]; | ||
var _fns = visitor[_nodeType]; | ||
for (var type in _fns) { | ||
@@ -100,16 +83,7 @@ _fns[type] = wrapCheck(wrapper, _fns[type]); | ||
if (wrapper.types) { | ||
for (var _iterator4 = wrapper.types, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref4; | ||
var _arr2 = wrapper.types; | ||
if (_isArray4) { | ||
if (_i4 >= _iterator4.length) break; | ||
_ref4 = _iterator4[_i4++]; | ||
} else { | ||
_i4 = _iterator4.next(); | ||
if (_i4.done) break; | ||
_ref4 = _i4.value; | ||
} | ||
for (var _i4 = 0; _i4 < _arr2.length; _i4++) { | ||
var _type = _arr2[_i4]; | ||
var _type = _ref4; | ||
if (visitor[_type]) { | ||
@@ -128,8 +102,6 @@ mergePair(visitor[_type], _fns); | ||
if (shouldIgnoreKey(_nodeType2)) continue; | ||
var _fns2 = visitor[_nodeType2]; | ||
var aliases = t.FLIPPED_ALIAS_KEYS[_nodeType2]; | ||
var deprecratedKey = t.DEPRECATED_KEYS[_nodeType2]; | ||
var deprecratedKey = t.DEPRECATED_KEYS[_nodeType2]; | ||
if (deprecratedKey) { | ||
@@ -141,20 +113,19 @@ console.trace("Visitor defined for " + _nodeType2 + " but it has been renamed to " + deprecratedKey); | ||
if (!aliases) continue; | ||
delete visitor[_nodeType2]; | ||
for (var _iterator3 = aliases, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
for (var _iterator2 = aliases, _isArray2 = Array.isArray(_iterator2), _i3 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i3++]; | ||
if (_isArray2) { | ||
if (_i3 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i3++]; | ||
} else { | ||
_i3 = _iterator3.next(); | ||
_i3 = _iterator2.next(); | ||
if (_i3.done) break; | ||
_ref3 = _i3.value; | ||
_ref2 = _i3.value; | ||
} | ||
var alias = _ref3; | ||
var alias = _ref2; | ||
var existing = visitor[alias]; | ||
var existing = visitor[alias]; | ||
if (existing) { | ||
@@ -170,3 +141,2 @@ mergePair(existing, _fns2); | ||
if (shouldIgnoreKey(_nodeType3)) continue; | ||
ensureCallbackArrays(visitor[_nodeType3]); | ||
@@ -197,2 +167,3 @@ } | ||
var visitors = visitor[nodeType]; | ||
if ((typeof visitors === "undefined" ? "undefined" : _typeof(visitors)) === "object") { | ||
@@ -214,15 +185,16 @@ for (var visitorKey in visitors) { | ||
var fns = [].concat(val); | ||
for (var _iterator5 = fns, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref5; | ||
if (_isArray5) { | ||
if (_i5 >= _iterator5.length) break; | ||
_ref5 = _iterator5[_i5++]; | ||
for (var _iterator3 = fns, _isArray3 = Array.isArray(_iterator3), _i5 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
if (_isArray3) { | ||
if (_i5 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i5++]; | ||
} else { | ||
_i5 = _iterator5.next(); | ||
_i5 = _iterator3.next(); | ||
if (_i5.done) break; | ||
_ref5 = _i5.value; | ||
_ref3 = _i5.value; | ||
} | ||
var fn = _ref5; | ||
var fn = _ref3; | ||
@@ -238,3 +210,2 @@ if (typeof fn !== "function") { | ||
var wrapper = arguments[2]; | ||
var rootVisitor = {}; | ||
@@ -245,3 +216,2 @@ | ||
var state = states[i]; | ||
explode(visitor); | ||
@@ -269,5 +239,3 @@ | ||
var fns = oldVisitor[key]; | ||
if (!Array.isArray(fns)) return "continue"; | ||
fns = fns.map(function (fn) { | ||
@@ -288,3 +256,2 @@ var newFn = fn; | ||
}); | ||
newVisitor[key] = fns; | ||
@@ -305,6 +272,8 @@ }; | ||
if (shouldIgnoreKey(key)) continue; | ||
var fns = obj[key]; | ||
var fns = obj[key]; | ||
if (typeof fns === "function") { | ||
obj[key] = { enter: fns }; | ||
obj[key] = { | ||
enter: fns | ||
}; | ||
} | ||
@@ -325,5 +294,7 @@ } | ||
}; | ||
newFn.toString = function () { | ||
return fn.toString(); | ||
}; | ||
return newFn; | ||
@@ -334,3 +305,2 @@ } | ||
if (key[0] === "_") return true; | ||
if (key === "enter" || key === "exit" || key === "shouldSkip") return true; | ||
@@ -337,0 +307,0 @@ |
{ | ||
"name": "babel-traverse", | ||
"version": "7.0.0-alpha.15", | ||
"version": "7.0.0-alpha.16", | ||
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes", | ||
@@ -11,9 +11,9 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"dependencies": { | ||
"babel-code-frame": "7.0.0-alpha.15", | ||
"babel-helper-function-name": "7.0.0-alpha.15", | ||
"babel-messages": "7.0.0-alpha.15", | ||
"babel-types": "7.0.0-alpha.15", | ||
"babylon": "7.0.0-beta.15", | ||
"babel-code-frame": "7.0.0-alpha.16", | ||
"babel-helper-function-name": "7.0.0-alpha.16", | ||
"babel-messages": "7.0.0-alpha.16", | ||
"babel-types": "7.0.0-alpha.16", | ||
"babylon": "7.0.0-beta.17", | ||
"debug": "^2.2.0", | ||
"globals": "^9.0.0", | ||
"globals": "^10.0.0", | ||
"invariant": "^2.2.0", | ||
@@ -23,5 +23,5 @@ "lodash": "^4.2.0" | ||
"devDependencies": { | ||
"babel-generator": "7.0.0-alpha.15", | ||
"babel-helper-plugin-test-runner": "7.0.0-alpha.15" | ||
"babel-generator": "7.0.0-alpha.16", | ||
"babel-helper-plugin-test-runner": "7.0.0-alpha.16" | ||
} | ||
} |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1
152202
4296
+ Addedansi-styles@3.2.1(transitive)
+ Addedbabel-code-frame@7.0.0-alpha.16(transitive)
+ Addedbabel-helper-function-name@7.0.0-alpha.16(transitive)
+ Addedbabel-helper-get-function-arity@7.0.0-alpha.16(transitive)
+ Addedbabel-messages@7.0.0-alpha.16(transitive)
+ Addedbabel-template@7.0.0-alpha.16(transitive)
+ Addedbabel-types@7.0.0-alpha.16(transitive)
+ Addedbabylon@7.0.0-beta.17(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedglobals@10.4.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedto-fast-properties@2.0.0(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedbabel-code-frame@7.0.0-alpha.15(transitive)
- Removedbabel-helper-function-name@7.0.0-alpha.15(transitive)
- Removedbabel-helper-get-function-arity@7.0.0-alpha.15(transitive)
- Removedbabel-messages@7.0.0-alpha.15(transitive)
- Removedbabel-template@7.0.0-alpha.15(transitive)
- Removedbabel-types@7.0.0-alpha.15(transitive)
- Removedbabylon@7.0.0-beta.15(transitive)
- Removedchalk@1.1.3(transitive)
- Removedglobals@9.18.0(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedto-fast-properties@1.0.3(transitive)
Updatedbabel-types@7.0.0-alpha.16
Updatedbabylon@7.0.0-beta.17
Updatedglobals@^10.0.0