@babel/traverse
Advanced tools
Comparing version 7.12.12 to 7.12.13
@@ -23,2 +23,3 @@ "use strict"; | ||
this.queue = null; | ||
this.priorityQueue = null; | ||
this.parentPath = parentPath; | ||
@@ -25,0 +26,0 @@ this.scope = scope; |
@@ -6,3 +6,2 @@ "use strict"; | ||
}); | ||
exports.default = traverse; | ||
Object.defineProperty(exports, "NodePath", { | ||
@@ -26,3 +25,3 @@ enumerable: true, | ||
}); | ||
exports.visitors = void 0; | ||
exports.visitors = exports.default = void 0; | ||
@@ -51,5 +50,4 @@ var _context = _interopRequireDefault(require("./context")); | ||
function traverse(parent, opts, scope, state, parentPath) { | ||
function traverse(parent, opts = {}, scope, state, parentPath) { | ||
if (!parent) return; | ||
if (!opts) opts = {}; | ||
@@ -70,2 +68,4 @@ if (!opts.noScope && !scope) { | ||
var _default = traverse; | ||
exports.default = _default; | ||
traverse.visitors = visitors; | ||
@@ -72,0 +72,0 @@ traverse.verify = visitors.verify; |
@@ -170,7 +170,7 @@ "use strict"; | ||
function inType() { | ||
function inType(...candidateTypes) { | ||
let path = this; | ||
while (path) { | ||
for (const type of arguments) { | ||
for (const type of candidateTypes) { | ||
if (path.node.type === type) return true; | ||
@@ -177,0 +177,0 @@ } |
@@ -23,9 +23,8 @@ "use strict"; | ||
function toComputedKey() { | ||
const node = this.node; | ||
let key; | ||
if (this.isMemberExpression()) { | ||
key = node.property; | ||
key = this.node.property; | ||
} else if (this.isProperty() || this.isMethod()) { | ||
key = node.key; | ||
key = this.node.key; | ||
} else { | ||
@@ -35,3 +34,3 @@ throw new ReferenceError("todo"); | ||
if (!node.computed) { | ||
if (!this.node.computed) { | ||
if (t.isIdentifier(key)) key = t.stringLiteral(key.name); | ||
@@ -38,0 +37,0 @@ } |
@@ -58,5 +58,2 @@ "use strict"; | ||
if (!state.confident) return; | ||
const { | ||
node | ||
} = path; | ||
@@ -69,3 +66,3 @@ if (path.isSequenceExpression()) { | ||
if (path.isStringLiteral() || path.isNumericLiteral() || path.isBooleanLiteral()) { | ||
return node.value; | ||
return path.node.value; | ||
} | ||
@@ -78,3 +75,3 @@ | ||
if (path.isTemplateLiteral()) { | ||
return evaluateQuasis(path, node.quasis, state); | ||
return evaluateQuasis(path, path.node.quasis, state); | ||
} | ||
@@ -91,4 +88,4 @@ | ||
if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name, true) && property.isIdentifier && property.node.name === "raw") { | ||
return evaluateQuasis(path, node.quasi.quasis, state, true); | ||
if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name) && property.isIdentifier() && property.node.name === "raw") { | ||
return evaluateQuasis(path, path.node.quasi.quasis, state, true); | ||
} | ||
@@ -113,3 +110,3 @@ } | ||
if (path.isMemberExpression() && !path.parentPath.isCallExpression({ | ||
callee: node | ||
callee: path.node | ||
})) { | ||
@@ -130,3 +127,3 @@ const property = path.get("property"); | ||
if (path.isReferencedIdentifier()) { | ||
const binding = path.scope.getBinding(node.name); | ||
const binding = path.scope.getBinding(path.node.name); | ||
@@ -144,7 +141,7 @@ if (binding && binding.constantViolations.length > 0) { | ||
} else { | ||
if (node.name === "undefined") { | ||
if (path.node.name === "undefined") { | ||
return binding ? deopt(binding.path, state) : undefined; | ||
} else if (node.name === "Infinity") { | ||
} else if (path.node.name === "Infinity") { | ||
return binding ? deopt(binding.path, state) : Infinity; | ||
} else if (node.name === "NaN") { | ||
} else if (path.node.name === "NaN") { | ||
return binding ? deopt(binding.path, state) : NaN; | ||
@@ -166,3 +163,3 @@ } | ||
})) { | ||
if (node.operator === "void") { | ||
if (path.node.operator === "void") { | ||
return undefined; | ||
@@ -173,3 +170,3 @@ } | ||
if (node.operator === "typeof" && (argument.isFunction() || argument.isClass())) { | ||
if (path.node.operator === "typeof" && (argument.isFunction() || argument.isClass())) { | ||
return "function"; | ||
@@ -181,3 +178,3 @@ } | ||
switch (node.operator) { | ||
switch (path.node.operator) { | ||
case "!": | ||
@@ -265,3 +262,3 @@ return !arg; | ||
switch (node.operator) { | ||
switch (path.node.operator) { | ||
case "||": | ||
@@ -285,3 +282,3 @@ state.confident = leftConfident && (!!left || rightConfident); | ||
switch (node.operator) { | ||
switch (path.node.operator) { | ||
case "-": | ||
@@ -354,4 +351,4 @@ return left - right; | ||
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) && VALID_CALLEES.indexOf(callee.node.name) >= 0) { | ||
func = global[node.callee.name]; | ||
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && VALID_CALLEES.indexOf(callee.node.name) >= 0) { | ||
func = global[callee.node.name]; | ||
} | ||
@@ -358,0 +355,0 @@ |
@@ -37,2 +37,4 @@ "use strict"; | ||
} | ||
return null; | ||
} | ||
@@ -39,0 +41,0 @@ |
@@ -224,3 +224,2 @@ "use strict"; | ||
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); | ||
@@ -251,2 +250,5 @@ | ||
}; | ||
} | ||
} | ||
var _default = NodePath; | ||
exports.default = _default; |
@@ -126,5 +126,5 @@ "use strict"; | ||
function baseTypeStrictlyMatches(right) { | ||
function baseTypeStrictlyMatches(rightArg) { | ||
const left = this.getTypeAnnotation(); | ||
right = right.getTypeAnnotation(); | ||
const right = rightArg.getTypeAnnotation(); | ||
@@ -134,2 +134,4 @@ if (!t.isAnyTypeAnnotation(left) && t.isFlowBaseAnnotation(left)) { | ||
} | ||
return false; | ||
} | ||
@@ -136,0 +138,0 @@ |
@@ -135,3 +135,5 @@ "use strict"; | ||
if (path.isImportSpecifier() && path.node.imported.name === importName) { | ||
if (path.isImportSpecifier() && t.isIdentifier(path.node.imported, { | ||
name: importName | ||
})) { | ||
return true; | ||
@@ -381,3 +383,3 @@ } | ||
if (this.isUnaryExpression()) { | ||
if (this.get("operator").node !== "void") { | ||
if (this.node.operator !== "void") { | ||
return false; | ||
@@ -409,8 +411,5 @@ } | ||
let { | ||
node | ||
} = path; | ||
if (path.isFunction()) node = node.body; | ||
const body = path.isFunction() ? path.node.body : path.node; | ||
for (const directive of node.directives) { | ||
for (const directive of body.directives) { | ||
if (directive.value.value === "use strict") { | ||
@@ -417,0 +416,0 @@ return true; |
@@ -51,2 +51,9 @@ "use strict"; | ||
constructor(path, scope) { | ||
this.breakOnScopePaths = void 0; | ||
this.bindings = void 0; | ||
this.mutableBinding = void 0; | ||
this.scopes = void 0; | ||
this.scope = void 0; | ||
this.path = void 0; | ||
this.attachAfter = void 0; | ||
this.breakOnScopePaths = []; | ||
@@ -185,3 +192,3 @@ this.bindings = {}; | ||
if (parent.isJSXElement() && this.path.container === parent.node.children) { | ||
uid = t.JSXExpressionContainer(uid); | ||
uid = t.jsxExpressionContainer(uid); | ||
} | ||
@@ -188,0 +195,0 @@ |
@@ -31,6 +31,7 @@ "use strict"; | ||
function insertBefore(nodes) { | ||
function insertBefore(nodes_) { | ||
this._assertUnremoved(); | ||
nodes = this._verifyNodeList(nodes); | ||
const nodes = this._verifyNodeList(nodes_); | ||
const { | ||
@@ -48,4 +49,5 @@ parentPath | ||
} else if (this.isStatementOrBlock()) { | ||
const shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null); | ||
this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [this.node] : [])); | ||
const node = this.node; | ||
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null); | ||
this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [node] : [])); | ||
return this.unshiftContainer("body", nodes); | ||
@@ -94,6 +96,7 @@ } else { | ||
function insertAfter(nodes) { | ||
function insertAfter(nodes_) { | ||
this._assertUnremoved(); | ||
nodes = this._verifyNodeList(nodes); | ||
const nodes = this._verifyNodeList(nodes_); | ||
const { | ||
@@ -109,2 +112,3 @@ parentPath | ||
if (this.node) { | ||
const node = this.node; | ||
let { | ||
@@ -114,5 +118,12 @@ scope | ||
if (scope.path.isPattern()) { | ||
t.assertExpression(node); | ||
this.replaceWith(t.callExpression(t.arrowFunctionExpression([], node), [])); | ||
this.get("callee.body").insertAfter(nodes); | ||
return [this]; | ||
} | ||
if (parentPath.isMethod({ | ||
computed: true, | ||
key: this.node | ||
key: node | ||
})) { | ||
@@ -123,3 +134,3 @@ scope = scope.parent; | ||
const temp = scope.generateDeclaredUidIdentifier(); | ||
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(temp), this.node))); | ||
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(temp), node))); | ||
nodes.push(t.expressionStatement(t.cloneNode(temp))); | ||
@@ -132,4 +143,5 @@ } | ||
} else if (this.isStatementOrBlock()) { | ||
const shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null); | ||
this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [this.node] : [])); | ||
const node = this.node; | ||
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null); | ||
this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [node] : [])); | ||
return this.pushContainer("body", nodes); | ||
@@ -158,3 +170,3 @@ } else { | ||
if (nodes.constructor !== Array) { | ||
if (!Array.isArray(nodes)) { | ||
nodes = [nodes]; | ||
@@ -205,3 +217,4 @@ } | ||
nodes = this._verifyNodeList(nodes); | ||
const verifiedNodes = this._verifyNodeList(nodes); | ||
const container = this.node[listKey]; | ||
@@ -217,3 +230,3 @@ | ||
return path.replaceWithMultiple(nodes); | ||
return path.replaceWithMultiple(verifiedNodes); | ||
} | ||
@@ -220,0 +233,0 @@ |
@@ -17,4 +17,8 @@ "use strict"; | ||
var _index = require("./index"); | ||
var _index = _interopRequireWildcard(require("./index")); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function remove() { | ||
@@ -21,0 +25,0 @@ var _this$opts; |
@@ -15,2 +15,6 @@ "use strict"; | ||
}) { | ||
this.identifier = void 0; | ||
this.scope = void 0; | ||
this.path = void 0; | ||
this.kind = void 0; | ||
this.constantViolations = []; | ||
@@ -17,0 +21,0 @@ this.constant = true; |
@@ -30,7 +30,7 @@ "use strict"; | ||
if (t.isModuleDeclaration(node)) { | ||
if (node.source) { | ||
if ((t.isExportAllDeclaration(node) || t.isExportNamedDeclaration(node) || t.isImportDeclaration(node)) && node.source) { | ||
gatherNodeParts(node.source, parts); | ||
} else if (node.specifiers && node.specifiers.length) { | ||
} else if ((t.isExportNamedDeclaration(node) || t.isImportDeclaration(node)) && node.specifiers && node.specifiers.length) { | ||
for (const e of node.specifiers) gatherNodeParts(e, parts); | ||
} else if (node.declaration) { | ||
} else if ((t.isExportDefaultDeclaration(node) || t.isExportNamedDeclaration(node)) && node.declaration) { | ||
gatherNodeParts(node.declaration, parts); | ||
@@ -297,2 +297,13 @@ } | ||
constructor(path) { | ||
this.uid = void 0; | ||
this.path = void 0; | ||
this.block = void 0; | ||
this.labels = void 0; | ||
this.inited = void 0; | ||
this.bindings = void 0; | ||
this.references = void 0; | ||
this.globals = void 0; | ||
this.uids = void 0; | ||
this.data = void 0; | ||
this.crawling = void 0; | ||
const { | ||
@@ -853,6 +864,6 @@ node | ||
getAllBindingsOfKind() { | ||
getAllBindingsOfKind(...kinds) { | ||
const ids = Object.create(null); | ||
for (const kind of arguments) { | ||
for (const kind of kinds) { | ||
let scope = this; | ||
@@ -859,0 +870,0 @@ |
@@ -123,4 +123,2 @@ "use strict"; | ||
if (binding.type === "hoisted") {} | ||
if (parentDeclar) { | ||
@@ -127,0 +125,0 @@ this.maybeConvertFromClassFunctionDeclaration(parentDeclar); |
{ | ||
"name": "@babel/traverse", | ||
"version": "7.12.12", | ||
"version": "7.12.13", | ||
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes", | ||
"author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"homepage": "https://babeljs.io/", | ||
"homepage": "https://babel.dev/docs/en/next/babel-traverse", | ||
"bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20traverse%22+is%3Aopen", | ||
"license": "MIT", | ||
@@ -18,8 +19,8 @@ "publishConfig": { | ||
"dependencies": { | ||
"@babel/code-frame": "^7.12.11", | ||
"@babel/generator": "^7.12.11", | ||
"@babel/helper-function-name": "^7.12.11", | ||
"@babel/helper-split-export-declaration": "^7.12.11", | ||
"@babel/parser": "^7.12.11", | ||
"@babel/types": "^7.12.12", | ||
"@babel/code-frame": "^7.12.13", | ||
"@babel/generator": "^7.12.13", | ||
"@babel/helper-function-name": "^7.12.13", | ||
"@babel/helper-split-export-declaration": "^7.12.13", | ||
"@babel/parser": "^7.12.13", | ||
"@babel/types": "^7.12.13", | ||
"debug": "^4.1.0", | ||
@@ -30,4 +31,4 @@ "globals": "^11.1.0", | ||
"devDependencies": { | ||
"@babel/helper-plugin-test-runner": "7.10.4" | ||
"@babel/helper-plugin-test-runner": "7.12.13" | ||
} | ||
} |
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
167371
36
4537