@babel/traverse
Advanced tools
Comparing version 7.6.2 to 7.6.3
@@ -10,12 +10,4 @@ "use strict"; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -42,3 +34,3 @@ | ||
if (opts[node.type]) return true; | ||
const keys = t().VISITOR_KEYS[node.type]; | ||
const keys = t.VISITOR_KEYS[node.type]; | ||
if (!keys || !keys.length) return false; | ||
@@ -45,0 +37,0 @@ |
@@ -33,22 +33,6 @@ "use strict"; | ||
function _includes() { | ||
const data = _interopRequireDefault(require("lodash/includes")); | ||
var _includes = _interopRequireDefault(require("lodash/includes")); | ||
_includes = function () { | ||
return data; | ||
}; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
return data; | ||
} | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var cache = _interopRequireWildcard(require("./cache")); | ||
@@ -87,7 +71,7 @@ | ||
traverse.cheap = function (node, enter) { | ||
return t().traverseFast(node, enter); | ||
return t.traverseFast(node, enter); | ||
}; | ||
traverse.node = function (node, opts, scope, state, parentPath, skipKeys) { | ||
const keys = t().VISITOR_KEYS[node.type]; | ||
const keys = t.VISITOR_KEYS[node.type]; | ||
if (!keys) return; | ||
@@ -103,3 +87,3 @@ const context = new _context.default(scope, opts, state, parentPath); | ||
traverse.clearNode = function (node, opts) { | ||
t().removeProperties(node, opts); | ||
t.removeProperties(node, opts); | ||
cache.path.delete(node); | ||
@@ -109,3 +93,3 @@ }; | ||
traverse.removeProperties = function (tree, opts) { | ||
t().traverseFast(tree, traverse.clearNode, opts); | ||
t.traverseFast(tree, traverse.clearNode, opts); | ||
return tree; | ||
@@ -122,3 +106,3 @@ }; | ||
traverse.hasType = function (tree, type, blacklistTypes) { | ||
if ((0, _includes().default)(blacklistTypes, tree.type)) return false; | ||
if ((0, _includes.default)(blacklistTypes, tree.type)) return false; | ||
if (tree.type === type) return true; | ||
@@ -125,0 +109,0 @@ const state = { |
@@ -17,12 +17,4 @@ "use strict"; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _index = _interopRequireDefault(require("./index")); | ||
@@ -81,3 +73,3 @@ | ||
let earliest; | ||
const keys = t().VISITOR_KEYS[deepest.type]; | ||
const keys = t.VISITOR_KEYS[deepest.type]; | ||
@@ -84,0 +76,0 @@ for (const ancestry of ancestries) { |
@@ -10,12 +10,4 @@ "use strict"; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -45,7 +37,7 @@ | ||
function addComment(type, content, line) { | ||
t().addComment(this.node, type, content, line); | ||
t.addComment(this.node, type, content, line); | ||
} | ||
function addComments(type, comments) { | ||
t().addComments(this.node, type, comments); | ||
t.addComments(this.node, type, comments); | ||
} |
@@ -12,22 +12,6 @@ "use strict"; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
var _helperFunctionName = _interopRequireDefault(require("@babel/helper-function-name")); | ||
return data; | ||
} | ||
function _helperFunctionName() { | ||
const data = _interopRequireDefault(require("@babel/helper-function-name")); | ||
_helperFunctionName = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -52,3 +36,3 @@ | ||
if (!node.computed) { | ||
if (t().isIdentifier(key)) key = t().stringLiteral(key.name); | ||
if (t.isIdentifier(key)) key = t.stringLiteral(key.name); | ||
} | ||
@@ -89,10 +73,10 @@ | ||
key = "argument"; | ||
statements.push(t().returnStatement(body.node)); | ||
statements.push(t.returnStatement(body.node)); | ||
} else { | ||
key = "expression"; | ||
statements.push(t().expressionStatement(body.node)); | ||
statements.push(t.expressionStatement(body.node)); | ||
} | ||
} | ||
this.node.body = t().blockStatement(statements); | ||
this.node.body = t.blockStatement(statements); | ||
const parentPath = this.get(stringPath); | ||
@@ -134,8 +118,8 @@ body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key); | ||
id: checkBinding, | ||
init: t().objectExpression([]) | ||
init: t.objectExpression([]) | ||
}); | ||
} | ||
this.get("body").unshiftContainer("body", t().expressionStatement(t().callExpression(this.hub.addHelper("newArrowCheck"), [t().thisExpression(), checkBinding ? t().identifier(checkBinding.name) : t().identifier(thisBinding)]))); | ||
this.replaceWith(t().callExpression(t().memberExpression((0, _helperFunctionName().default)(this, true) || this.node, t().identifier("bind")), [checkBinding ? t().identifier(checkBinding.name) : t().thisExpression()])); | ||
this.get("body").unshiftContainer("body", t.expressionStatement(t.callExpression(this.hub.addHelper("newArrowCheck"), [t.thisExpression(), checkBinding ? t.identifier(checkBinding.name) : t.identifier(thisBinding)]))); | ||
this.replaceWith(t.callExpression(t.memberExpression((0, _helperFunctionName.default)(this, true) || this.node, t.identifier("bind")), [checkBinding ? t.identifier(checkBinding.name) : t.thisExpression()])); | ||
} | ||
@@ -188,3 +172,3 @@ } | ||
allSuperCalls.forEach(superCall => { | ||
const callee = t().identifier(superBinding); | ||
const callee = t.identifier(superBinding); | ||
callee.loc = superCall.node.callee.loc; | ||
@@ -202,3 +186,3 @@ superCall.get("callee").replaceWith(callee); | ||
thisPaths.forEach(thisChild => { | ||
const thisRef = thisChild.isJSX() ? t().jsxIdentifier(thisBinding) : t().identifier(thisBinding); | ||
const thisRef = thisChild.isJSX() ? t.jsxIdentifier(thisBinding) : t.identifier(thisBinding); | ||
thisRef.loc = thisChild.node.loc; | ||
@@ -212,5 +196,5 @@ thisChild.replaceWith(thisRef); | ||
if (argumentsPaths.length > 0) { | ||
const argumentsBinding = getBinding(thisEnvFn, "arguments", () => t().identifier("arguments")); | ||
const argumentsBinding = getBinding(thisEnvFn, "arguments", () => t.identifier("arguments")); | ||
argumentsPaths.forEach(argumentsChild => { | ||
const argsRef = t().identifier(argumentsBinding); | ||
const argsRef = t.identifier(argumentsBinding); | ||
argsRef.loc = argumentsChild.node.loc; | ||
@@ -222,5 +206,5 @@ argumentsChild.replaceWith(argsRef); | ||
if (newTargetPaths.length > 0) { | ||
const newTargetBinding = getBinding(thisEnvFn, "newtarget", () => t().metaProperty(t().identifier("new"), t().identifier("target"))); | ||
const newTargetBinding = getBinding(thisEnvFn, "newtarget", () => t.metaProperty(t.identifier("new"), t.identifier("target"))); | ||
newTargetPaths.forEach(targetChild => { | ||
const targetRef = t().identifier(newTargetBinding); | ||
const targetRef = t.identifier(newTargetBinding); | ||
targetRef.loc = targetChild.node.loc; | ||
@@ -247,6 +231,6 @@ targetChild.replaceWith(targetRef); | ||
const prop = superProp.get("property").node; | ||
superProp.replaceWith(t().identifier(superBinding)); | ||
superProp.replaceWith(t.identifier(superBinding)); | ||
superProp.parentPath.node.arguments.unshift(prop); | ||
} else { | ||
superProp.replaceWith(t().identifier(superBinding)); | ||
superProp.replaceWith(t.identifier(superBinding)); | ||
} | ||
@@ -267,5 +251,5 @@ } else { | ||
args.push(value); | ||
superProp.parentPath.replaceWith(t().callExpression(t().identifier(superBinding), args)); | ||
superProp.parentPath.replaceWith(t.callExpression(t.identifier(superBinding), args)); | ||
} else { | ||
superProp.replaceWith(t().callExpression(t().identifier(superBinding), args)); | ||
superProp.replaceWith(t.callExpression(t.identifier(superBinding), args)); | ||
} | ||
@@ -288,7 +272,7 @@ } | ||
const 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)); | ||
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)); | ||
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)); | ||
} | ||
@@ -301,9 +285,9 @@ | ||
const computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null; | ||
const 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)))]; | ||
const 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)))]; | ||
if (!superProp.parentPath.node.prefix) { | ||
parts.push(t().identifier(tmp.name)); | ||
parts.push(t.identifier(tmp.name)); | ||
} | ||
updateExpr.replaceWith(t().sequenceExpression(parts)); | ||
updateExpr.replaceWith(t.sequenceExpression(parts)); | ||
const left = updateExpr.get("expressions.0.right"); | ||
@@ -323,3 +307,3 @@ const right = updateExpr.get("expressions.1.left"); | ||
return getBinding(thisEnvFn, "this", thisBinding => { | ||
if (!inConstructor || !hasSuperClass(thisEnvFn)) return t().thisExpression(); | ||
if (!inConstructor || !hasSuperClass(thisEnvFn)) return t.thisExpression(); | ||
const supers = new WeakSet(); | ||
@@ -340,3 +324,3 @@ thisEnvFn.traverse({ | ||
supers.add(child.node); | ||
child.replaceWithMultiple([child.node, t().assignmentExpression("=", t().identifier(thisBinding), t().identifier("this"))]); | ||
child.replaceWithMultiple([child.node, t.assignmentExpression("=", t.identifier(thisBinding), t.identifier("this"))]); | ||
} | ||
@@ -351,3 +335,3 @@ | ||
const argsBinding = thisEnvFn.scope.generateUidIdentifier("args"); | ||
return t().arrowFunctionExpression([t().restElement(argsBinding)], t().callExpression(t().super(), [t().spreadElement(t().identifier(argsBinding.name))])); | ||
return t.arrowFunctionExpression([t.restElement(argsBinding)], t.callExpression(t.super(), [t.spreadElement(t.identifier(argsBinding.name))])); | ||
}); | ||
@@ -359,14 +343,14 @@ } | ||
const argsBinding = thisEnvFn.scope.generateUidIdentifier("args"); | ||
const argsList = [t().restElement(argsBinding)]; | ||
const argsList = [t.restElement(argsBinding)]; | ||
let fnBody; | ||
if (propName) { | ||
fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(propName)), [t().spreadElement(t().identifier(argsBinding.name))]); | ||
fnBody = t.callExpression(t.memberExpression(t.super(), t.identifier(propName)), [t.spreadElement(t.identifier(argsBinding.name))]); | ||
} else { | ||
const method = thisEnvFn.scope.generateUidIdentifier("prop"); | ||
argsList.unshift(method); | ||
fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(method.name), true), [t().spreadElement(t().identifier(argsBinding.name))]); | ||
fnBody = t.callExpression(t.memberExpression(t.super(), t.identifier(method.name), true), [t.spreadElement(t.identifier(argsBinding.name))]); | ||
} | ||
return t().arrowFunctionExpression(argsList, fnBody); | ||
return t.arrowFunctionExpression(argsList, fnBody); | ||
}); | ||
@@ -382,7 +366,7 @@ } | ||
if (propName) { | ||
fnBody = t().memberExpression(t().super(), t().identifier(propName)); | ||
fnBody = t.memberExpression(t.super(), t.identifier(propName)); | ||
} else { | ||
const method = thisEnvFn.scope.generateUidIdentifier("prop"); | ||
argsList.unshift(method); | ||
fnBody = t().memberExpression(t().super(), t().identifier(method.name), true); | ||
fnBody = t.memberExpression(t.super(), t.identifier(method.name), true); | ||
} | ||
@@ -393,6 +377,6 @@ | ||
argsList.push(valueIdent); | ||
fnBody = t().assignmentExpression("=", fnBody, t().identifier(valueIdent.name)); | ||
fnBody = t.assignmentExpression("=", fnBody, t.identifier(valueIdent.name)); | ||
} | ||
return t().arrowFunctionExpression(argsList, fnBody); | ||
return t.arrowFunctionExpression(argsList, fnBody); | ||
}); | ||
@@ -399,0 +383,0 @@ } |
@@ -23,12 +23,4 @@ "use strict"; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -228,7 +220,7 @@ | ||
function getBindingIdentifiers(duplicates) { | ||
return t().getBindingIdentifiers(this.node, duplicates); | ||
return t.getBindingIdentifiers(this.node, duplicates); | ||
} | ||
function getOuterBindingIdentifiers(duplicates) { | ||
return t().getOuterBindingIdentifiers(this.node, duplicates); | ||
return t.getOuterBindingIdentifiers(this.node, duplicates); | ||
} | ||
@@ -245,3 +237,3 @@ | ||
if (!id.node) continue; | ||
const keys = t().getBindingIdentifiers.keys[id.node.type]; | ||
const keys = t.getBindingIdentifiers.keys[id.node.type]; | ||
@@ -248,0 +240,0 @@ if (id.isIdentifier()) { |
@@ -10,12 +10,4 @@ "use strict"; | ||
function _debug() { | ||
const data = _interopRequireDefault(require("debug")); | ||
var _debug = _interopRequireDefault(require("debug")); | ||
_debug = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _index = _interopRequireDefault(require("../index")); | ||
@@ -25,24 +17,8 @@ | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _cache = require("../cache"); | ||
function _generator() { | ||
const data = _interopRequireDefault(require("@babel/generator")); | ||
var _generator = _interopRequireDefault(require("@babel/generator")); | ||
_generator = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var NodePath_ancestry = _interopRequireWildcard(require("./ancestry")); | ||
@@ -76,3 +52,3 @@ | ||
const debug = (0, _debug().default)("babel"); | ||
const debug = (0, _debug.default)("babel"); | ||
@@ -170,3 +146,3 @@ class NodePath { | ||
set(key, node) { | ||
t().validate(this.node, key, node); | ||
t.validate(this.node, key, node); | ||
this.node[key] = node; | ||
@@ -194,3 +170,3 @@ } | ||
toString() { | ||
return (0, _generator().default)(this.node).code; | ||
return (0, _generator.default)(this.node).code; | ||
} | ||
@@ -203,5 +179,5 @@ | ||
for (const type of t().TYPES) { | ||
for (const type of t.TYPES) { | ||
const typeKey = `is${type}`; | ||
const fn = t()[typeKey]; | ||
const fn = t[typeKey]; | ||
@@ -221,3 +197,3 @@ NodePath.prototype[typeKey] = function (opts) { | ||
if (type[0] === "_") continue; | ||
if (t().TYPES.indexOf(type) < 0) t().TYPES.push(type); | ||
if (t.TYPES.indexOf(type) < 0) t.TYPES.push(type); | ||
const virtualType = virtualTypes[type]; | ||
@@ -224,0 +200,0 @@ |
@@ -15,12 +15,4 @@ "use strict"; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -32,4 +24,4 @@ | ||
if (this.typeAnnotation) return this.typeAnnotation; | ||
let type = this._getTypeAnnotation() || t().anyTypeAnnotation(); | ||
if (t().isTypeAnnotation(type)) type = type.typeAnnotation; | ||
let type = this._getTypeAnnotation() || t.anyTypeAnnotation(); | ||
if (t.isTypeAnnotation(type)) type = type.typeAnnotation; | ||
return this.typeAnnotation = type; | ||
@@ -47,10 +39,10 @@ } | ||
if (declar.key === "left" && declarParent.isForInStatement()) { | ||
return t().stringTypeAnnotation(); | ||
return t.stringTypeAnnotation(); | ||
} | ||
if (declar.key === "left" && declarParent.isForOfStatement()) { | ||
return t().anyTypeAnnotation(); | ||
return t.anyTypeAnnotation(); | ||
} | ||
return t().voidTypeAnnotation(); | ||
return t.voidTypeAnnotation(); | ||
} else { | ||
@@ -84,15 +76,15 @@ return; | ||
if (baseName === "string") { | ||
return t().isStringTypeAnnotation(type); | ||
return t.isStringTypeAnnotation(type); | ||
} else if (baseName === "number") { | ||
return t().isNumberTypeAnnotation(type); | ||
return t.isNumberTypeAnnotation(type); | ||
} else if (baseName === "boolean") { | ||
return t().isBooleanTypeAnnotation(type); | ||
return t.isBooleanTypeAnnotation(type); | ||
} else if (baseName === "any") { | ||
return t().isAnyTypeAnnotation(type); | ||
return t.isAnyTypeAnnotation(type); | ||
} else if (baseName === "mixed") { | ||
return t().isMixedTypeAnnotation(type); | ||
return t.isMixedTypeAnnotation(type); | ||
} else if (baseName === "empty") { | ||
return t().isEmptyTypeAnnotation(type); | ||
return t.isEmptyTypeAnnotation(type); | ||
} else if (baseName === "void") { | ||
return t().isVoidTypeAnnotation(type); | ||
return t.isVoidTypeAnnotation(type); | ||
} else { | ||
@@ -109,7 +101,7 @@ if (soft) { | ||
const type = this.getTypeAnnotation(); | ||
if (t().isAnyTypeAnnotation(type)) return true; | ||
if (t.isAnyTypeAnnotation(type)) return true; | ||
if (t().isUnionTypeAnnotation(type)) { | ||
if (t.isUnionTypeAnnotation(type)) { | ||
for (const type2 of type.types) { | ||
if (t().isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) { | ||
if (t.isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) { | ||
return true; | ||
@@ -129,3 +121,3 @@ } | ||
if (!t().isAnyTypeAnnotation(left) && t().isFlowBaseAnnotation(left)) { | ||
if (!t.isAnyTypeAnnotation(left) && t.isFlowBaseAnnotation(left)) { | ||
return right.type === left.type; | ||
@@ -137,5 +129,5 @@ } | ||
const type = this.getTypeAnnotation(); | ||
return t().isGenericTypeAnnotation(type) && t().isIdentifier(type.id, { | ||
return t.isGenericTypeAnnotation(type) && t.isIdentifier(type.id, { | ||
name: genericName | ||
}); | ||
} |
@@ -8,12 +8,4 @@ "use strict"; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -36,5 +28,5 @@ | ||
if (node.name === "undefined") { | ||
return t().voidTypeAnnotation(); | ||
return t.voidTypeAnnotation(); | ||
} else if (node.name === "NaN" || node.name === "Infinity") { | ||
return t().numberTypeAnnotation(); | ||
return t.numberTypeAnnotation(); | ||
} else if (node.name === "arguments") {} | ||
@@ -64,3 +56,3 @@ } | ||
if (types.length) { | ||
return t().createUnionTypeAnnotation(types); | ||
return t.createUnionTypeAnnotation(types); | ||
} | ||
@@ -103,4 +95,4 @@ } | ||
if (t().BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t().numberTypeAnnotation(); | ||
if (t.BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t.numberTypeAnnotation(); | ||
} | ||
@@ -135,3 +127,3 @@ | ||
if (typeof typeValue !== "string") return; | ||
return t().createTypeAnnotationBasedOnTypeof(typeValue); | ||
return t.createTypeAnnotationBasedOnTypeof(typeValue); | ||
} | ||
@@ -182,3 +174,3 @@ | ||
return { | ||
typeAnnotation: t().createUnionTypeAnnotation(types), | ||
typeAnnotation: t.createUnionTypeAnnotation(types), | ||
ifStatement | ||
@@ -185,0 +177,0 @@ }; |
@@ -36,12 +36,4 @@ "use strict"; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _infererReference = _interopRequireDefault(require("./inferer-reference")); | ||
@@ -80,3 +72,3 @@ | ||
if (this.get("callee").isIdentifier()) { | ||
return t().genericTypeAnnotation(node.callee); | ||
return t.genericTypeAnnotation(node.callee); | ||
} | ||
@@ -86,3 +78,3 @@ } | ||
function TemplateLiteral() { | ||
return t().stringTypeAnnotation(); | ||
return t.stringTypeAnnotation(); | ||
} | ||
@@ -94,9 +86,9 @@ | ||
if (operator === "void") { | ||
return t().voidTypeAnnotation(); | ||
} else if (t().NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t().numberTypeAnnotation(); | ||
} else if (t().STRING_UNARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t().stringTypeAnnotation(); | ||
} else if (t().BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t().booleanTypeAnnotation(); | ||
return t.voidTypeAnnotation(); | ||
} else if (t.NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t.numberTypeAnnotation(); | ||
} else if (t.STRING_UNARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t.stringTypeAnnotation(); | ||
} else if (t.BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t.booleanTypeAnnotation(); | ||
} | ||
@@ -108,6 +100,6 @@ } | ||
if (t().NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t().numberTypeAnnotation(); | ||
} else if (t().BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t().booleanTypeAnnotation(); | ||
if (t.NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t.numberTypeAnnotation(); | ||
} else if (t.BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t.booleanTypeAnnotation(); | ||
} else if (operator === "+") { | ||
@@ -118,8 +110,8 @@ const right = this.get("right"); | ||
if (left.isBaseType("number") && right.isBaseType("number")) { | ||
return t().numberTypeAnnotation(); | ||
return t.numberTypeAnnotation(); | ||
} else if (left.isBaseType("string") || right.isBaseType("string")) { | ||
return t().stringTypeAnnotation(); | ||
return t.stringTypeAnnotation(); | ||
} | ||
return t().unionTypeAnnotation([t().stringTypeAnnotation(), t().numberTypeAnnotation()]); | ||
return t.unionTypeAnnotation([t.stringTypeAnnotation(), t.numberTypeAnnotation()]); | ||
} | ||
@@ -129,7 +121,7 @@ } | ||
function LogicalExpression() { | ||
return t().createUnionTypeAnnotation([this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]); | ||
return t.createUnionTypeAnnotation([this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]); | ||
} | ||
function ConditionalExpression() { | ||
return t().createUnionTypeAnnotation([this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]); | ||
return t.createUnionTypeAnnotation([this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]); | ||
} | ||
@@ -153,3 +145,3 @@ | ||
if (operator === "++" || operator === "--") { | ||
return t().numberTypeAnnotation(); | ||
return t.numberTypeAnnotation(); | ||
} | ||
@@ -159,27 +151,27 @@ } | ||
function StringLiteral() { | ||
return t().stringTypeAnnotation(); | ||
return t.stringTypeAnnotation(); | ||
} | ||
function NumericLiteral() { | ||
return t().numberTypeAnnotation(); | ||
return t.numberTypeAnnotation(); | ||
} | ||
function BooleanLiteral() { | ||
return t().booleanTypeAnnotation(); | ||
return t.booleanTypeAnnotation(); | ||
} | ||
function NullLiteral() { | ||
return t().nullLiteralTypeAnnotation(); | ||
return t.nullLiteralTypeAnnotation(); | ||
} | ||
function RegExpLiteral() { | ||
return t().genericTypeAnnotation(t().identifier("RegExp")); | ||
return t.genericTypeAnnotation(t.identifier("RegExp")); | ||
} | ||
function ObjectExpression() { | ||
return t().genericTypeAnnotation(t().identifier("Object")); | ||
return t.genericTypeAnnotation(t.identifier("Object")); | ||
} | ||
function ArrayExpression() { | ||
return t().genericTypeAnnotation(t().identifier("Array")); | ||
return t.genericTypeAnnotation(t.identifier("Array")); | ||
} | ||
@@ -194,9 +186,9 @@ | ||
function Func() { | ||
return t().genericTypeAnnotation(t().identifier("Function")); | ||
return t.genericTypeAnnotation(t.identifier("Function")); | ||
} | ||
const isArrayFrom = t().buildMatchMemberExpression("Array.from"); | ||
const isObjectKeys = t().buildMatchMemberExpression("Object.keys"); | ||
const isObjectValues = t().buildMatchMemberExpression("Object.values"); | ||
const isObjectEntries = t().buildMatchMemberExpression("Object.entries"); | ||
const isArrayFrom = t.buildMatchMemberExpression("Array.from"); | ||
const isObjectKeys = t.buildMatchMemberExpression("Object.keys"); | ||
const isObjectValues = t.buildMatchMemberExpression("Object.values"); | ||
const isObjectEntries = t.buildMatchMemberExpression("Object.entries"); | ||
@@ -209,7 +201,7 @@ function CallExpression() { | ||
if (isObjectKeys(callee)) { | ||
return t().arrayTypeAnnotation(t().stringTypeAnnotation()); | ||
return t.arrayTypeAnnotation(t.stringTypeAnnotation()); | ||
} else if (isArrayFrom(callee) || isObjectValues(callee)) { | ||
return t().arrayTypeAnnotation(t().anyTypeAnnotation()); | ||
return t.arrayTypeAnnotation(t.anyTypeAnnotation()); | ||
} else if (isObjectEntries(callee)) { | ||
return t().arrayTypeAnnotation(t().tupleTypeAnnotation([t().stringTypeAnnotation(), t().anyTypeAnnotation()])); | ||
return t.arrayTypeAnnotation(t.tupleTypeAnnotation([t.stringTypeAnnotation(), t.anyTypeAnnotation()])); | ||
} | ||
@@ -230,5 +222,5 @@ | ||
if (callee.is("generator")) { | ||
return t().genericTypeAnnotation(t().identifier("AsyncIterator")); | ||
return t.genericTypeAnnotation(t.identifier("AsyncIterator")); | ||
} else { | ||
return t().genericTypeAnnotation(t().identifier("Promise")); | ||
return t.genericTypeAnnotation(t.identifier("Promise")); | ||
} | ||
@@ -235,0 +227,0 @@ } else { |
@@ -27,22 +27,6 @@ "use strict"; | ||
function _includes() { | ||
const data = _interopRequireDefault(require("lodash/includes")); | ||
var _includes = _interopRequireDefault(require("lodash/includes")); | ||
_includes = function () { | ||
return data; | ||
}; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
return data; | ||
} | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -55,3 +39,3 @@ | ||
function matchesPattern(pattern, allowPartial) { | ||
return t().matchesPattern(this.node, pattern, allowPartial); | ||
return t.matchesPattern(this.node, pattern, allowPartial); | ||
} | ||
@@ -85,3 +69,3 @@ | ||
function isNodeType(type) { | ||
return t().isType(this.type, type); | ||
return t.isType(this.type, type); | ||
} | ||
@@ -99,5 +83,5 @@ | ||
if (this.isExpression()) { | ||
return t().isBlockStatement(replacement); | ||
return t.isBlockStatement(replacement); | ||
} else if (this.isBlockStatement()) { | ||
return t().isExpression(replacement); | ||
return t.isExpression(replacement); | ||
} | ||
@@ -130,6 +114,6 @@ | ||
function isStatementOrBlock() { | ||
if (this.parentPath.isLabeledStatement() || t().isBlockStatement(this.container)) { | ||
if (this.parentPath.isLabeledStatement() || t.isBlockStatement(this.container)) { | ||
return false; | ||
} else { | ||
return (0, _includes().default)(t().STATEMENT_OR_BLOCK_KEYS, this.key); | ||
return (0, _includes.default)(t.STATEMENT_OR_BLOCK_KEYS, this.key); | ||
} | ||
@@ -286,3 +270,3 @@ } | ||
const keys = t().VISITOR_KEYS[commonPath.type]; | ||
const keys = t.VISITOR_KEYS[commonPath.type]; | ||
const keyPosition = { | ||
@@ -360,3 +344,3 @@ this: keys.indexOf(divergence.this.parentKey), | ||
const targetKey = this.toComputedKey(); | ||
if (!t().isLiteral(targetKey)) return; | ||
if (!t.isLiteral(targetKey)) return; | ||
const targetName = targetKey.value; | ||
@@ -363,0 +347,0 @@ const target = this.get("object").resolve(dangerous, resolved); |
@@ -8,12 +8,4 @@ "use strict"; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -25,3 +17,3 @@ | ||
ReferencedIdentifier(path, state) { | ||
if (path.isJSXIdentifier() && t().react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) { | ||
if (path.isJSXIdentifier() && t.react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) { | ||
return; | ||
@@ -44,2 +36,11 @@ } | ||
if (!binding) return; | ||
for (const violation of binding.constantViolations) { | ||
if (violation.scope !== binding.path.scope) { | ||
state.mutableBinding = true; | ||
path.stop(); | ||
return; | ||
} | ||
} | ||
if (binding !== state.scope.getBinding(path.node.name)) return; | ||
@@ -55,2 +56,3 @@ state.bindings[path.node.name] = binding; | ||
this.bindings = {}; | ||
this.mutableBinding = false; | ||
this.scopes = []; | ||
@@ -174,2 +176,3 @@ this.scope = scope; | ||
this.path.traverse(referenceVisitor, this); | ||
if (this.mutableBinding) return; | ||
this.getCompatibleScopes(); | ||
@@ -180,12 +183,12 @@ const attachTo = this.getAttachmentPath(); | ||
let uid = attachTo.scope.generateUidIdentifier("ref"); | ||
const declarator = t().variableDeclarator(uid, this.path.node); | ||
const declarator = t.variableDeclarator(uid, this.path.node); | ||
const insertFn = this.attachAfter ? "insertAfter" : "insertBefore"; | ||
const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t().variableDeclaration("var", [declarator])]); | ||
const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t.variableDeclaration("var", [declarator])]); | ||
const parent = this.path.parentPath; | ||
if (parent.isJSXElement() && this.path.container === parent.node.children) { | ||
uid = t().JSXExpressionContainer(uid); | ||
uid = t.JSXExpressionContainer(uid); | ||
} | ||
this.path.replaceWith(t().cloneNode(uid)); | ||
this.path.replaceWith(t.cloneNode(uid)); | ||
return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init"); | ||
@@ -192,0 +195,0 @@ } |
@@ -8,12 +8,4 @@ "use strict"; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -32,5 +24,5 @@ | ||
if (!t().isIdentifier(node, opts) && !t().isJSXMemberExpression(parent, opts)) { | ||
if (t().isJSXIdentifier(node, opts)) { | ||
if (t().react.isCompatTag(node.name)) return false; | ||
if (!t.isIdentifier(node, opts) && !t.isJSXMemberExpression(parent, opts)) { | ||
if (t.isJSXIdentifier(node, opts)) { | ||
if (t.react.isCompatTag(node.name)) return false; | ||
} else { | ||
@@ -41,3 +33,3 @@ return false; | ||
return t().isReferenced(node, parent, path.parentPath.parent); | ||
return t.isReferenced(node, parent, path.parentPath.parent); | ||
} | ||
@@ -54,3 +46,3 @@ | ||
}) { | ||
return t().isMemberExpression(node) && t().isReferenced(node, parent); | ||
return t.isMemberExpression(node) && t.isReferenced(node, parent); | ||
} | ||
@@ -69,3 +61,3 @@ | ||
const grandparent = path.parentPath.parent; | ||
return t().isIdentifier(node) && t().isBinding(node, parent, grandparent); | ||
return t.isIdentifier(node) && t.isBinding(node, parent, grandparent); | ||
} | ||
@@ -82,8 +74,8 @@ | ||
}) { | ||
if (t().isStatement(node)) { | ||
if (t().isVariableDeclaration(node)) { | ||
if (t().isForXStatement(parent, { | ||
if (t.isStatement(node)) { | ||
if (t.isVariableDeclaration(node)) { | ||
if (t.isForXStatement(parent, { | ||
left: node | ||
})) return false; | ||
if (t().isForStatement(parent, { | ||
if (t.isForStatement(parent, { | ||
init: node | ||
@@ -108,3 +100,3 @@ })) return false; | ||
} else { | ||
return t().isExpression(path.node); | ||
return t.isExpression(path.node); | ||
} | ||
@@ -119,3 +111,3 @@ } | ||
checkPath(path) { | ||
return t().isScope(path.node, path.parent); | ||
return t.isScope(path.node, path.parent); | ||
} | ||
@@ -127,3 +119,3 @@ | ||
checkPath(path) { | ||
return t().isReferenced(path.node, path.parent); | ||
return t.isReferenced(path.node, path.parent); | ||
} | ||
@@ -135,3 +127,3 @@ | ||
checkPath(path) { | ||
return t().isBlockScoped(path.node); | ||
return t.isBlockScoped(path.node); | ||
} | ||
@@ -145,3 +137,3 @@ | ||
checkPath(path) { | ||
return t().isVar(path.node); | ||
return t.isVar(path.node); | ||
} | ||
@@ -178,9 +170,9 @@ | ||
}) { | ||
if (t().isFlow(node)) { | ||
if (t.isFlow(node)) { | ||
return true; | ||
} else if (t().isImportDeclaration(node)) { | ||
} else if (t.isImportDeclaration(node)) { | ||
return node.importKind === "type" || node.importKind === "typeof"; | ||
} else if (t().isExportDeclaration(node)) { | ||
} else if (t.isExportDeclaration(node)) { | ||
return node.exportKind === "type"; | ||
} else if (t().isImportSpecifier(node)) { | ||
} else if (t.isImportSpecifier(node)) { | ||
return node.importKind === "type" || node.importKind === "typeof"; | ||
@@ -187,0 +179,0 @@ } else { |
@@ -23,12 +23,4 @@ "use strict"; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -57,3 +49,3 @@ | ||
const shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null); | ||
this.replaceWith(t().blockStatement(shouldInsertCurrentNode ? [this.node] : [])); | ||
this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [this.node] : [])); | ||
return this.unshiftContainer("body", nodes); | ||
@@ -112,3 +104,3 @@ } else { | ||
return parentPath.insertAfter(nodes.map(node => { | ||
return t().isExpression(node) ? t().expressionStatement(node) : node; | ||
return t.isExpression(node) ? t.expressionStatement(node) : node; | ||
})); | ||
@@ -129,4 +121,4 @@ } else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") { | ||
const temp = scope.generateDeclaredUidIdentifier(); | ||
nodes.unshift(t().expressionStatement(t().assignmentExpression("=", t().cloneNode(temp), this.node))); | ||
nodes.push(t().expressionStatement(t().cloneNode(temp))); | ||
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(temp), this.node))); | ||
nodes.push(t.expressionStatement(t.cloneNode(temp))); | ||
} | ||
@@ -139,3 +131,3 @@ | ||
const shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null); | ||
this.replaceWith(t().blockStatement(shouldInsertCurrentNode ? [this.node] : [])); | ||
this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [this.node] : [])); | ||
return this.pushContainer("body", nodes); | ||
@@ -142,0 +134,0 @@ } else { |
@@ -13,12 +13,4 @@ "use strict"; | ||
function _codeFrame() { | ||
const data = require("@babel/code-frame"); | ||
var _codeFrame = require("@babel/code-frame"); | ||
_codeFrame = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _index = _interopRequireDefault(require("../index")); | ||
@@ -28,22 +20,6 @@ | ||
function _parser() { | ||
const data = require("@babel/parser"); | ||
var _parser = require("@babel/parser"); | ||
_parser = function () { | ||
return data; | ||
}; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
return data; | ||
} | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -74,3 +50,3 @@ | ||
if (declar.init) { | ||
exprs.push(t().expressionStatement(t().assignmentExpression("=", declar.id, declar.init))); | ||
exprs.push(t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init))); | ||
} | ||
@@ -87,4 +63,4 @@ } | ||
nodes = this._verifyNodeList(nodes); | ||
t().inheritLeadingComments(nodes[0], this.node); | ||
t().inheritTrailingComments(nodes[nodes.length - 1], this.node); | ||
t.inheritLeadingComments(nodes[0], this.node); | ||
t.inheritTrailingComments(nodes[nodes.length - 1], this.node); | ||
this.node = this.container[this.key] = null; | ||
@@ -107,3 +83,3 @@ const paths = this.insertAfter(nodes); | ||
replacement = `(${replacement})`; | ||
replacement = (0, _parser().parse)(replacement); | ||
replacement = (0, _parser.parse)(replacement); | ||
} catch (err) { | ||
@@ -113,3 +89,3 @@ const loc = err.loc; | ||
if (loc) { | ||
err.message += " - make sure this is an expression.\n" + (0, _codeFrame().codeFrameColumns)(replacement, { | ||
err.message += " - make sure this is an expression.\n" + (0, _codeFrame.codeFrameColumns)(replacement, { | ||
start: { | ||
@@ -152,3 +128,3 @@ line: loc.line, | ||
if (this.isProgram() && !t().isProgram(replacement)) { | ||
if (this.isProgram() && !t.isProgram(replacement)) { | ||
throw new Error("You can only replace a Program root node with another Program node"); | ||
@@ -167,5 +143,5 @@ } | ||
if (this.isNodeType("Statement") && t().isExpression(replacement)) { | ||
if (this.isNodeType("Statement") && t.isExpression(replacement)) { | ||
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) { | ||
replacement = t().expressionStatement(replacement); | ||
replacement = t.expressionStatement(replacement); | ||
nodePath = "expression"; | ||
@@ -175,3 +151,3 @@ } | ||
if (this.isNodeType("Expression") && t().isStatement(replacement)) { | ||
if (this.isNodeType("Expression") && t.isStatement(replacement)) { | ||
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) { | ||
@@ -185,4 +161,4 @@ return this.replaceExpressionWithStatements([replacement]); | ||
if (oldNode) { | ||
t().inheritsComments(replacement, oldNode); | ||
t().removeComments(oldNode); | ||
t.inheritsComments(replacement, oldNode); | ||
t.removeComments(oldNode); | ||
} | ||
@@ -204,5 +180,5 @@ | ||
if (this.inList) { | ||
t().validate(this.parent, this.key, [node]); | ||
t.validate(this.parent, this.key, [node]); | ||
} else { | ||
t().validate(this.parent, this.key, node); | ||
t.validate(this.parent, this.key, node); | ||
} | ||
@@ -216,3 +192,3 @@ | ||
this.resync(); | ||
const toSequenceExpression = t().toSequenceExpression(nodes, this.scope); | ||
const toSequenceExpression = t.toSequenceExpression(nodes, this.scope); | ||
@@ -225,4 +201,4 @@ if (toSequenceExpression) { | ||
const isParentAsync = functionParent && functionParent.is("async"); | ||
const container = t().arrowFunctionExpression([], t().blockStatement(nodes)); | ||
this.replaceWith(t().callExpression(container, [])); | ||
const container = t.arrowFunctionExpression([], t.blockStatement(nodes)); | ||
this.replaceWith(t.callExpression(container, [])); | ||
this.traverse(hoistVariablesVisitor); | ||
@@ -241,11 +217,11 @@ const completionRecords = this.get("callee").getCompletionRecords(); | ||
uid = callee.scope.generateDeclaredUidIdentifier("ret"); | ||
callee.get("body").pushContainer("body", t().returnStatement(t().cloneNode(uid))); | ||
callee.get("body").pushContainer("body", t.returnStatement(t.cloneNode(uid))); | ||
loop.setData("expressionReplacementReturnUid", uid); | ||
} else { | ||
uid = t().identifier(uid.name); | ||
uid = t.identifier(uid.name); | ||
} | ||
path.get("expression").replaceWith(t().assignmentExpression("=", t().cloneNode(uid), path.node.expression)); | ||
path.get("expression").replaceWith(t.assignmentExpression("=", t.cloneNode(uid), path.node.expression)); | ||
} else { | ||
path.replaceWith(t().returnStatement(path.node.expression)); | ||
path.replaceWith(t.returnStatement(path.node.expression)); | ||
} | ||
@@ -257,5 +233,5 @@ } | ||
if (isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", t().FUNCTION_TYPES)) { | ||
if (isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", t.FUNCTION_TYPES)) { | ||
callee.set("async", true); | ||
this.replaceWith(t().awaitExpression(this.node)); | ||
this.replaceWith(t.awaitExpression(this.node)); | ||
} | ||
@@ -262,0 +238,0 @@ |
@@ -8,22 +8,6 @@ "use strict"; | ||
function _includes() { | ||
const data = _interopRequireDefault(require("lodash/includes")); | ||
var _includes = _interopRequireDefault(require("lodash/includes")); | ||
_includes = function () { | ||
return data; | ||
}; | ||
var _repeat = _interopRequireDefault(require("lodash/repeat")); | ||
return data; | ||
} | ||
function _repeat() { | ||
const data = _interopRequireDefault(require("lodash/repeat")); | ||
_repeat = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _renamer = _interopRequireDefault(require("./lib/renamer")); | ||
@@ -33,34 +17,10 @@ | ||
function _defaults() { | ||
const data = _interopRequireDefault(require("lodash/defaults")); | ||
var _defaults = _interopRequireDefault(require("lodash/defaults")); | ||
_defaults = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _binding = _interopRequireDefault(require("./binding")); | ||
function _globals() { | ||
const data = _interopRequireDefault(require("globals")); | ||
var _globals = _interopRequireDefault(require("globals")); | ||
_globals = function () { | ||
return data; | ||
}; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
return data; | ||
} | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _cache = require("../cache"); | ||
@@ -75,3 +35,3 @@ | ||
function gatherNodeParts(node, parts) { | ||
if (t().isModuleDeclaration(node)) { | ||
if (t.isModuleDeclaration(node)) { | ||
if (node.source) { | ||
@@ -86,22 +46,22 @@ gatherNodeParts(node.source, parts); | ||
} | ||
} else if (t().isModuleSpecifier(node)) { | ||
} else if (t.isModuleSpecifier(node)) { | ||
gatherNodeParts(node.local, parts); | ||
} else if (t().isMemberExpression(node)) { | ||
} else if (t.isMemberExpression(node)) { | ||
gatherNodeParts(node.object, parts); | ||
gatherNodeParts(node.property, parts); | ||
} else if (t().isIdentifier(node)) { | ||
} else if (t.isIdentifier(node)) { | ||
parts.push(node.name); | ||
} else if (t().isLiteral(node)) { | ||
} else if (t.isLiteral(node)) { | ||
parts.push(node.value); | ||
} else if (t().isCallExpression(node)) { | ||
} else if (t.isCallExpression(node)) { | ||
gatherNodeParts(node.callee, parts); | ||
} else if (t().isObjectExpression(node) || t().isObjectPattern(node)) { | ||
} else if (t.isObjectExpression(node) || t.isObjectPattern(node)) { | ||
for (const prop of node.properties) { | ||
gatherNodeParts(prop.key || prop.argument, parts); | ||
} | ||
} else if (t().isPrivateName(node)) { | ||
} else if (t.isPrivateName(node)) { | ||
gatherNodeParts(node.id, parts); | ||
} else if (t().isThisExpression(node)) { | ||
} else if (t.isThisExpression(node)) { | ||
parts.push("this"); | ||
} else if (t().isSuper(node)) { | ||
} else if (t.isSuper(node)) { | ||
parts.push("super"); | ||
@@ -113,3 +73,3 @@ } | ||
For(path) { | ||
for (const key of t().FOR_INIT_KEYS) { | ||
for (const key of t.FOR_INIT_KEYS) { | ||
const declar = path.get(key); | ||
@@ -155,3 +115,3 @@ | ||
if (t().isClassDeclaration(declar) || t().isFunctionDeclaration(declar)) { | ||
if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) { | ||
const id = declar.id; | ||
@@ -161,5 +121,5 @@ if (!id) return; | ||
if (binding) binding.reference(path); | ||
} else if (t().isVariableDeclaration(declar)) { | ||
} else if (t.isVariableDeclaration(declar)) { | ||
for (const decl of declar.declarations) { | ||
for (const name of Object.keys(t().getBindingIdentifiers(decl))) { | ||
for (const name of Object.keys(t.getBindingIdentifiers(decl))) { | ||
const binding = scope.getBinding(name); | ||
@@ -261,11 +221,11 @@ if (binding) binding.reference(path); | ||
}); | ||
return t().cloneNode(id); | ||
return t.cloneNode(id); | ||
} | ||
generateUidIdentifier(name) { | ||
return t().identifier(this.generateUid(name)); | ||
return t.identifier(this.generateUid(name)); | ||
} | ||
generateUid(name = "temp") { | ||
name = t().toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, ""); | ||
name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, ""); | ||
let uid; | ||
@@ -294,7 +254,7 @@ let i = 0; | ||
if (t().isAssignmentExpression(parent)) { | ||
if (t.isAssignmentExpression(parent)) { | ||
node = parent.left; | ||
} else if (t().isVariableDeclarator(parent)) { | ||
} else if (t.isVariableDeclarator(parent)) { | ||
node = parent.id; | ||
} else if (t().isObjectProperty(node) || t().isObjectMethod(node)) { | ||
} else if (t.isObjectProperty(node) || t.isObjectMethod(node)) { | ||
node = node.key; | ||
@@ -311,11 +271,11 @@ } | ||
generateUidIdentifierBasedOnNode(parent, defaultName) { | ||
return t().identifier(this.generateUidBasedOnNode(parent, defaultName)); | ||
return t.identifier(this.generateUidBasedOnNode(parent, defaultName)); | ||
} | ||
isStatic(node) { | ||
if (t().isThisExpression(node) || t().isSuper(node)) { | ||
if (t.isThisExpression(node) || t.isSuper(node)) { | ||
return true; | ||
} | ||
if (t().isIdentifier(node)) { | ||
if (t.isIdentifier(node)) { | ||
const binding = this.getBinding(node.name); | ||
@@ -343,3 +303,3 @@ | ||
}); | ||
return t().cloneNode(id); | ||
return t.cloneNode(id); | ||
} | ||
@@ -378,3 +338,3 @@ | ||
dump() { | ||
const sep = (0, _repeat().default)("-", 60); | ||
const sep = (0, _repeat.default)("-", 60); | ||
console.log(sep); | ||
@@ -401,3 +361,3 @@ let scope = this; | ||
toArray(node, i) { | ||
if (t().isIdentifier(node)) { | ||
if (t.isIdentifier(node)) { | ||
const binding = this.getBinding(node.name); | ||
@@ -410,10 +370,10 @@ | ||
if (t().isArrayExpression(node)) { | ||
if (t.isArrayExpression(node)) { | ||
return node; | ||
} | ||
if (t().isIdentifier(node, { | ||
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]); | ||
return t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Array"), t.identifier("prototype")), t.identifier("slice")), t.identifier("call")), [node]); | ||
} | ||
@@ -427,3 +387,3 @@ | ||
} else if (i) { | ||
args.push(t().numericLiteral(i)); | ||
args.push(t.numericLiteral(i)); | ||
helperName = "slicedToArray"; | ||
@@ -434,3 +394,3 @@ } else { | ||
return t().callExpression(this.hub.addHelper(helperName), args); | ||
return t.callExpression(this.hub.addHelper(helperName), args); | ||
} | ||
@@ -481,3 +441,3 @@ | ||
buildUndefinedNode() { | ||
return t().unaryExpression("void", t().numericLiteral(0), true); | ||
return t.unaryExpression("void", t.numericLiteral(0), true); | ||
} | ||
@@ -570,3 +530,3 @@ | ||
isPure(node, constantsOnly) { | ||
if (t().isIdentifier(node)) { | ||
if (t.isIdentifier(node)) { | ||
const binding = this.getBinding(node.name); | ||
@@ -576,3 +536,3 @@ if (!binding) return false; | ||
return true; | ||
} else if (t().isClass(node)) { | ||
} else if (t.isClass(node)) { | ||
if (node.superClass && !this.isPure(node.superClass, constantsOnly)) { | ||
@@ -583,3 +543,3 @@ return false; | ||
return this.isPure(node.body, constantsOnly); | ||
} else if (t().isClassBody(node)) { | ||
} else if (t.isClassBody(node)) { | ||
for (const method of node.body) { | ||
@@ -590,5 +550,5 @@ if (!this.isPure(method, constantsOnly)) return false; | ||
return true; | ||
} else if (t().isBinary(node)) { | ||
} else if (t.isBinary(node)) { | ||
return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly); | ||
} else if (t().isArrayExpression(node)) { | ||
} else if (t.isArrayExpression(node)) { | ||
for (const elem of node.elements) { | ||
@@ -599,3 +559,3 @@ if (!this.isPure(elem, constantsOnly)) return false; | ||
return true; | ||
} else if (t().isObjectExpression(node)) { | ||
} else if (t.isObjectExpression(node)) { | ||
for (const prop of node.properties) { | ||
@@ -606,14 +566,14 @@ if (!this.isPure(prop, constantsOnly)) return false; | ||
return true; | ||
} else if (t().isClassMethod(node)) { | ||
} else if (t.isClassMethod(node)) { | ||
if (node.computed && !this.isPure(node.key, constantsOnly)) return false; | ||
if (node.kind === "get" || node.kind === "set") return false; | ||
return true; | ||
} else if (t().isProperty(node)) { | ||
} else if (t.isProperty(node)) { | ||
if (node.computed && !this.isPure(node.key, constantsOnly)) return false; | ||
return this.isPure(node.value, constantsOnly); | ||
} else if (t().isUnaryExpression(node)) { | ||
} else if (t.isUnaryExpression(node)) { | ||
return this.isPure(node.argument, constantsOnly); | ||
} else if (t().isTaggedTemplateExpression(node)) { | ||
return t().matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly); | ||
} else if (t().isTemplateLiteral(node)) { | ||
} else if (t.isTaggedTemplateExpression(node)) { | ||
return t.matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly); | ||
} else if (t.isTemplateLiteral(node)) { | ||
for (const expression of node.expressions) { | ||
@@ -625,3 +585,3 @@ if (!this.isPure(expression, constantsOnly)) return false; | ||
} else { | ||
return t().isPureish(node); | ||
return t.isPureish(node); | ||
} | ||
@@ -665,3 +625,3 @@ } | ||
if (path.isLoop()) { | ||
for (const key of t().FOR_INIT_KEYS) { | ||
for (const key of t.FOR_INIT_KEYS) { | ||
const node = path.get(key); | ||
@@ -673,3 +633,3 @@ if (node.isBlockScoped()) this.registerBinding(node.node.kind, node); | ||
if (path.isFunctionExpression() && path.has("id")) { | ||
if (!path.get("id").node[t().NOT_LOCAL_BINDING]) { | ||
if (!path.get("id").node[t.NOT_LOCAL_BINDING]) { | ||
this.registerBinding("local", path.get("id"), path); | ||
@@ -680,3 +640,3 @@ } | ||
if (path.isClassExpression() && path.has("id")) { | ||
if (!path.get("id").node[t().NOT_LOCAL_BINDING]) { | ||
if (!path.get("id").node[t.NOT_LOCAL_BINDING]) { | ||
this.registerBinding("local", path); | ||
@@ -760,3 +720,3 @@ } | ||
if (!declarPath) { | ||
const declar = t().variableDeclaration(kind, []); | ||
const declar = t.variableDeclaration(kind, []); | ||
declar._blockHoist = blockHoist; | ||
@@ -767,3 +727,3 @@ [declarPath] = path.unshiftContainer("body", [declar]); | ||
const declarator = t().variableDeclarator(opts.id, opts.init); | ||
const declarator = t.variableDeclarator(opts.id, opts.init); | ||
declarPath.node.declarations.push(declarator); | ||
@@ -814,3 +774,3 @@ this.registerBinding(kind, declarPath.get("declarations").pop()); | ||
do { | ||
(0, _defaults().default)(ids, scope.bindings); | ||
(0, _defaults.default)(ids, scope.bindings); | ||
scope = scope.parent; | ||
@@ -877,4 +837,4 @@ } while (scope); | ||
if (this.hasUid(name)) return true; | ||
if (!noGlobals && (0, _includes().default)(Scope.globals, name)) return true; | ||
if (!noGlobals && (0, _includes().default)(Scope.contextVariables, name)) return true; | ||
if (!noGlobals && (0, _includes.default)(Scope.globals, name)) return true; | ||
if (!noGlobals && (0, _includes.default)(Scope.contextVariables, name)) return true; | ||
return false; | ||
@@ -920,3 +880,3 @@ } | ||
exports.default = Scope; | ||
Scope.globals = Object.keys(_globals().default.builtin); | ||
Scope.globals = Object.keys(_globals.default.builtin); | ||
Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"]; |
@@ -10,22 +10,6 @@ "use strict"; | ||
function _helperSplitExportDeclaration() { | ||
const data = _interopRequireDefault(require("@babel/helper-split-export-declaration")); | ||
var _helperSplitExportDeclaration = _interopRequireDefault(require("@babel/helper-split-export-declaration")); | ||
_helperSplitExportDeclaration = function () { | ||
return data; | ||
}; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
return data; | ||
} | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -80,3 +64,3 @@ | ||
(0, _helperSplitExportDeclaration().default)(maybeExportDeclar); | ||
(0, _helperSplitExportDeclaration.default)(maybeExportDeclar); | ||
} | ||
@@ -88,5 +72,5 @@ | ||
if (this.binding.kind !== "hoisted") return; | ||
path.node.id = t().identifier(this.oldName); | ||
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))])); | ||
path.replaceWith(t.variableDeclaration("let", [t.variableDeclarator(t.identifier(this.newName), t.toExpression(path.node))])); | ||
} | ||
@@ -98,7 +82,7 @@ | ||
if (this.binding.kind !== "local") return; | ||
path.node.id = t().identifier(this.oldName); | ||
path.node.id = t.identifier(this.oldName); | ||
this.binding.scope.parent.push({ | ||
id: t().identifier(this.newName) | ||
id: t.identifier(this.newName) | ||
}); | ||
path.replaceWith(t().assignmentExpression("=", t().identifier(this.newName), path.node)); | ||
path.replaceWith(t.assignmentExpression("=", t.identifier(this.newName), path.node)); | ||
} | ||
@@ -105,0 +89,0 @@ |
@@ -12,22 +12,6 @@ "use strict"; | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
var _clone = _interopRequireDefault(require("lodash/clone")); | ||
return data; | ||
} | ||
function _clone() { | ||
const data = _interopRequireDefault(require("lodash/clone")); | ||
_clone = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -88,4 +72,4 @@ | ||
const fns = visitor[nodeType]; | ||
let aliases = t().FLIPPED_ALIAS_KEYS[nodeType]; | ||
const deprecratedKey = t().DEPRECATED_KEYS[nodeType]; | ||
let aliases = t.FLIPPED_ALIAS_KEYS[nodeType]; | ||
const deprecratedKey = t.DEPRECATED_KEYS[nodeType]; | ||
@@ -106,3 +90,3 @@ if (deprecratedKey) { | ||
} else { | ||
visitor[alias] = (0, _clone().default)(fns); | ||
visitor[alias] = (0, _clone.default)(fns); | ||
} | ||
@@ -134,3 +118,3 @@ } | ||
if (t().TYPES.indexOf(nodeType) < 0) { | ||
if (t.TYPES.indexOf(nodeType) < 0) { | ||
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type`); | ||
@@ -137,0 +121,0 @@ } |
{ | ||
"name": "@babel/traverse", | ||
"version": "7.6.2", | ||
"version": "7.6.3", | ||
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes", | ||
@@ -15,7 +15,7 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"@babel/code-frame": "^7.5.5", | ||
"@babel/generator": "^7.6.2", | ||
"@babel/generator": "^7.6.3", | ||
"@babel/helper-function-name": "^7.1.0", | ||
"@babel/helper-split-export-declaration": "^7.4.4", | ||
"@babel/parser": "^7.6.2", | ||
"@babel/types": "^7.6.0", | ||
"@babel/parser": "^7.6.3", | ||
"@babel/types": "^7.6.3", | ||
"debug": "^4.1.0", | ||
@@ -28,3 +28,3 @@ "globals": "^11.1.0", | ||
}, | ||
"gitHead": "b9cb4af953afb1a5aeed9b18526192ab15bb45c1" | ||
"gitHead": "d329156ebc17da01382acb83e212cb4328534ebc" | ||
} |
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
151889
4236
Updated@babel/generator@^7.6.3
Updated@babel/parser@^7.6.3
Updated@babel/types@^7.6.3