@babel/traverse
Advanced tools
Comparing version 7.20.0 to 7.20.1
@@ -14,3 +14,2 @@ "use strict"; | ||
exports.scope = scope; | ||
function clear() { | ||
@@ -20,7 +19,5 @@ clearPath(); | ||
} | ||
function clearPath() { | ||
exports.path = path = new WeakMap(); | ||
} | ||
function clearScope() { | ||
@@ -27,0 +24,0 @@ exports.scope = scope = new WeakMap(); |
@@ -7,11 +7,7 @@ "use strict"; | ||
exports.default = void 0; | ||
var _path = require("./path"); | ||
var _t = require("@babel/types"); | ||
const { | ||
VISITOR_KEYS | ||
} = _t; | ||
class TraversalContext { | ||
@@ -30,3 +26,5 @@ constructor(scope, opts, state, parentPath) { | ||
if (opts.enter || opts.exit) return true; | ||
if (opts[node.type]) return true; | ||
const keys = VISITOR_KEYS[node.type]; | ||
@@ -36,10 +34,9 @@ if (!(keys != null && keys.length)) return false; | ||
for (const key of keys) { | ||
if (node[key]) { | ||
if ( | ||
node[key]) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
create(node, container, key, listKey) { | ||
@@ -54,3 +51,2 @@ return _path.default.get({ | ||
} | ||
maybeQueue(path, notPriority) { | ||
@@ -65,3 +61,2 @@ if (this.queue) { | ||
} | ||
visitMultiple(container, parent, listKey) { | ||
@@ -73,3 +68,2 @@ if (container.length === 0) return false; | ||
const node = container[key]; | ||
if (node && this.shouldVisit(node)) { | ||
@@ -79,8 +73,7 @@ queue.push(this.create(parent, container, key, listKey)); | ||
} | ||
return this.visitQueue(queue); | ||
} | ||
visitSingle(node, key) { | ||
if (this.shouldVisit(node[key])) { | ||
if (this.shouldVisit( | ||
node[key])) { | ||
return this.visitQueue([this.create(node, node, key)]); | ||
@@ -91,3 +84,2 @@ } else { | ||
} | ||
visitQueue(queue) { | ||
@@ -101,3 +93,2 @@ this.queue = queue; | ||
path.resync(); | ||
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) { | ||
@@ -108,2 +99,3 @@ path.pushContext(this); | ||
if (path.key === null) continue; | ||
const { | ||
@@ -114,3 +106,2 @@ node | ||
if (node) visited.add(node); | ||
if (path.visit()) { | ||
@@ -120,3 +111,2 @@ stop = true; | ||
} | ||
if (this.priorityQueue.length) { | ||
@@ -137,7 +127,5 @@ stop = this.visitQueue(this.priorityQueue); | ||
} | ||
visit(node, key) { | ||
const nodes = node[key]; | ||
if (!nodes) return false; | ||
if (Array.isArray(nodes)) { | ||
@@ -149,7 +137,5 @@ return this.visitMultiple(nodes, node, key); | ||
} | ||
} | ||
exports.default = TraversalContext; | ||
//# sourceMappingURL=context.js.map |
@@ -7,20 +7,14 @@ "use strict"; | ||
exports.default = void 0; | ||
class Hub { | ||
getCode() {} | ||
getScope() {} | ||
addHelper() { | ||
throw new Error("Helpers are not supported by the default hub."); | ||
} | ||
buildError(node, msg, Error = TypeError) { | ||
return new Error(msg); | ||
} | ||
} | ||
exports.default = Hub; | ||
//# sourceMappingURL=hub.js.map |
@@ -25,19 +25,10 @@ "use strict"; | ||
exports.visitors = exports.default = void 0; | ||
var visitors = require("./visitors"); | ||
exports.visitors = visitors; | ||
var _t = require("@babel/types"); | ||
var cache = require("./cache"); | ||
var _traverseNode = require("./traverse-node"); | ||
var _path = require("./path"); | ||
var _scope = require("./scope"); | ||
var _hub = require("./hub"); | ||
const { | ||
@@ -48,6 +39,5 @@ VISITOR_KEYS, | ||
} = _t; | ||
function traverse(parent, opts = {}, scope, state, parentPath) { | ||
function traverse(parent, | ||
opts = {}, scope, state, parentPath) { | ||
if (!parent) return; | ||
if (!opts.noScope && !scope) { | ||
@@ -58,11 +48,8 @@ if (parent.type !== "Program" && parent.type !== "File") { | ||
} | ||
if (!VISITOR_KEYS[parent.type]) { | ||
return; | ||
} | ||
visitors.explode(opts); | ||
(0, _traverseNode.traverseNode)(parent, opts, scope, state, parentPath); | ||
} | ||
var _default = traverse; | ||
@@ -73,7 +60,5 @@ exports.default = _default; | ||
traverse.explode = visitors.explode; | ||
traverse.cheap = function (node, enter) { | ||
return traverseFast(node, enter); | ||
}; | ||
traverse.node = function (node, opts, scope, state, path, skipKeys) { | ||
@@ -87,3 +72,2 @@ (0, _traverseNode.traverseNode)(node, opts, scope, state, path, skipKeys); | ||
}; | ||
traverse.removeProperties = function (tree, opts) { | ||
@@ -93,3 +77,2 @@ traverseFast(tree, traverse.clearNode, opts); | ||
}; | ||
function hasDenylistedType(path, state) { | ||
@@ -101,5 +84,5 @@ if (path.node.type === state.type) { | ||
} | ||
traverse.hasType = function (tree, type, denylistTypes) { | ||
if (denylistTypes != null && denylistTypes.includes(tree.type)) return false; | ||
if (tree.type === type) return true; | ||
@@ -117,5 +100,4 @@ const state = { | ||
}; | ||
traverse.cache = cache; | ||
//# sourceMappingURL=index.js.map |
@@ -16,5 +16,3 @@ "use strict"; | ||
exports.isDescendant = isDescendant; | ||
var _t = require("@babel/types"); | ||
const { | ||
@@ -26,7 +24,5 @@ VISITOR_KEYS | ||
let path = this; | ||
while (path = path.parentPath) { | ||
if (callback(path)) return path; | ||
} | ||
return null; | ||
@@ -37,7 +33,5 @@ } | ||
let path = this; | ||
do { | ||
if (callback(path)) return path; | ||
} while (path = path.parentPath); | ||
return null; | ||
@@ -52,3 +46,2 @@ } | ||
let path = this; | ||
do { | ||
@@ -61,7 +54,5 @@ if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) { | ||
} while (path); | ||
if (path && (path.isProgram() || path.isFile())) { | ||
throw new Error("File/Program node, we can't possibly find a statement parent to this"); | ||
} | ||
return path; | ||
@@ -74,3 +65,2 @@ } | ||
const keys = VISITOR_KEYS[deepest.type]; | ||
for (const ancestry of ancestries) { | ||
@@ -93,3 +83,2 @@ const path = ancestry[i + 1]; | ||
const currentKeyIndex = keys.indexOf(path.parentKey); | ||
if (earliestKeyIndex > currentKeyIndex) { | ||
@@ -99,3 +88,2 @@ earliest = path; | ||
} | ||
return earliest; | ||
@@ -109,3 +97,2 @@ }); | ||
} | ||
if (paths.length === 1) { | ||
@@ -116,6 +103,7 @@ return paths[0]; | ||
let minDepth = Infinity; | ||
let lastCommonIndex, lastCommon; | ||
const ancestries = paths.map(path => { | ||
const ancestry = []; | ||
do { | ||
@@ -128,5 +116,5 @@ ancestry.unshift(path); | ||
} | ||
return ancestry; | ||
}); | ||
const first = ancestries[0]; | ||
@@ -136,3 +124,2 @@ | ||
const shouldMatch = first[i]; | ||
for (const ancestry of ancestries) { | ||
@@ -147,3 +134,2 @@ if (ancestry[i] !== shouldMatch) { | ||
} | ||
if (lastCommon) { | ||
@@ -163,7 +149,5 @@ if (filter) { | ||
const paths = []; | ||
do { | ||
paths.push(path); | ||
} while (path = path.parentPath); | ||
return paths; | ||
@@ -179,6 +163,4 @@ } | ||
} | ||
function inType(...candidateTypes) { | ||
let path = this; | ||
while (path) { | ||
@@ -188,6 +170,4 @@ for (const type of candidateTypes) { | ||
} | ||
path = path.parentPath; | ||
} | ||
return false; | ||
@@ -194,0 +174,0 @@ } |
@@ -9,5 +9,3 @@ "use strict"; | ||
exports.shareCommentsWithSiblings = shareCommentsWithSiblings; | ||
var _t = require("@babel/types"); | ||
const { | ||
@@ -29,3 +27,2 @@ addComment: _addComment, | ||
const hasNext = Boolean(next.node); | ||
if (hasPrev && !hasNext) { | ||
@@ -37,3 +34,2 @@ prev.addComments("trailing", trailing); | ||
} | ||
function addComment(type, content, line) { | ||
@@ -40,0 +36,0 @@ _addComment(this.node, type, content, line); |
@@ -26,5 +26,3 @@ "use strict"; | ||
exports.visit = visit; | ||
var _traverseNode = require("../traverse-node"); | ||
var _index = require("./index"); | ||
@@ -35,17 +33,12 @@ | ||
this.debug(key); | ||
if (this.node) { | ||
if (this._call(opts[key])) return true; | ||
} | ||
if (this.node) { | ||
return this._call(opts[this.node.type] && opts[this.node.type][key]); | ||
} | ||
return false; | ||
} | ||
function _call(fns) { | ||
if (!fns) return false; | ||
for (const fn of fns) { | ||
@@ -56,7 +49,5 @@ if (!fn) continue; | ||
const ret = fn.call(this.state, this, this.state); | ||
if (ret && typeof ret === "object" && typeof ret.then === "function") { | ||
throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`); | ||
} | ||
if (ret) { | ||
@@ -67,11 +58,9 @@ throw new Error(`Unexpected return value from visitor method ${fn}`); | ||
if (this.node !== node) return true; | ||
if (this._traverseFlags > 0) return true; | ||
} | ||
return false; | ||
} | ||
function isDenylisted() { | ||
var _this$opts$denylist; | ||
const denylist = (_this$opts$denylist = this.opts.denylist) != null ? _this$opts$denylist : this.opts.blacklist; | ||
@@ -88,3 +77,2 @@ return denylist && denylist.indexOf(this.node.type) > -1; | ||
} | ||
function visit() { | ||
@@ -94,13 +82,9 @@ if (!this.node) { | ||
} | ||
if (this.isDenylisted()) { | ||
return false; | ||
} | ||
if (this.opts.shouldSkip && this.opts.shouldSkip(this)) { | ||
return false; | ||
} | ||
const currentContext = this.context; | ||
if (this.shouldSkip || this.call("enter")) { | ||
@@ -110,3 +94,2 @@ this.debug("Skip..."); | ||
} | ||
restoreContext(this, currentContext); | ||
@@ -119,7 +102,5 @@ this.debug("Recursing into..."); | ||
} | ||
function skip() { | ||
this.shouldSkip = true; | ||
} | ||
function skipKey(key) { | ||
@@ -129,10 +110,7 @@ if (this.skipKeys == null) { | ||
} | ||
this.skipKeys[key] = true; | ||
} | ||
function stop() { | ||
this._traverseFlags |= _index.SHOULD_SKIP | _index.SHOULD_STOP; | ||
} | ||
function setScope() { | ||
@@ -145,5 +123,3 @@ if (this.opts && this.opts.noScope) return; | ||
} | ||
let target; | ||
while (path && !target) { | ||
@@ -154,7 +130,5 @@ if (path.opts && path.opts.noScope) return; | ||
} | ||
this.scope = this.getScope(target); | ||
if (this.scope) this.scope.init(); | ||
} | ||
function setContext(context) { | ||
@@ -164,5 +138,3 @@ if (this.skipKeys != null) { | ||
} | ||
this._traverseFlags = 0; | ||
if (context) { | ||
@@ -173,3 +145,2 @@ this.context = context; | ||
} | ||
this.setScope(); | ||
@@ -181,7 +152,4 @@ return this; | ||
if (this.removed) return; | ||
this._resyncParent(); | ||
this._resyncList(); | ||
this._resyncKey(); | ||
@@ -195,7 +163,6 @@ } | ||
} | ||
function _resyncKey() { | ||
if (!this.container) return; | ||
if (this.node === this.container[this.key]) { | ||
if (this.node === | ||
this.container[this.key]) { | ||
return; | ||
@@ -220,19 +187,18 @@ } | ||
} | ||
function _resyncList() { | ||
if (!this.parent || !this.inList) return; | ||
const newContainer = this.parent[this.listKey]; | ||
const newContainer = | ||
this.parent[this.listKey]; | ||
if (this.container === newContainer) return; | ||
this.container = newContainer || null; | ||
} | ||
function _resyncRemoved() { | ||
if (this.key == null || !this.container || this.container[this.key] !== this.node) { | ||
if (this.key == null || !this.container || | ||
this.container[this.key] !== this.node) { | ||
this._markRemoved(); | ||
} | ||
} | ||
function popContext() { | ||
this.contexts.pop(); | ||
if (this.contexts.length > 0) { | ||
@@ -244,3 +210,2 @@ this.setContext(this.contexts[this.contexts.length - 1]); | ||
} | ||
function pushContext(context) { | ||
@@ -250,3 +215,2 @@ this.contexts.push(context); | ||
} | ||
function setup(parentPath, container, listKey, key) { | ||
@@ -258,16 +222,14 @@ this.listKey = listKey; | ||
} | ||
function setKey(key) { | ||
var _this$node; | ||
this.key = key; | ||
this.node = this.container[this.key]; | ||
this.node = | ||
this.container[this.key]; | ||
this.type = (_this$node = this.node) == null ? void 0 : _this$node.type; | ||
} | ||
function requeue(pathToQueue = this) { | ||
if (pathToQueue.removed) return; | ||
; | ||
const contexts = this.contexts; | ||
for (const context of contexts) { | ||
@@ -277,7 +239,5 @@ context.maybeQueue(pathToQueue); | ||
} | ||
function _getQueueContexts() { | ||
let path = this; | ||
let contexts = this.contexts; | ||
while (!contexts.length) { | ||
@@ -288,3 +248,2 @@ path = path.parentPath; | ||
} | ||
return contexts; | ||
@@ -291,0 +250,0 @@ } |
@@ -11,11 +11,6 @@ "use strict"; | ||
exports.unwrapFunctionEnvironment = unwrapFunctionEnvironment; | ||
var _t = require("@babel/types"); | ||
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor"); | ||
var _helperFunctionName = require("@babel/helper-function-name"); | ||
var _visitors = require("../visitors"); | ||
const { | ||
@@ -48,6 +43,4 @@ arrowFunctionExpression, | ||
} = _t; | ||
function toComputedKey() { | ||
let key; | ||
if (this.isMemberExpression()) { | ||
@@ -64,22 +57,16 @@ key = this.node.property; | ||
} | ||
return key; | ||
} | ||
function ensureBlock() { | ||
const body = this.get("body"); | ||
const bodyNode = body.node; | ||
if (Array.isArray(body)) { | ||
throw new Error("Can't convert array path to a block statement"); | ||
} | ||
if (!bodyNode) { | ||
throw new Error("Can't convert node without a body"); | ||
} | ||
if (body.isBlockStatement()) { | ||
return bodyNode; | ||
} | ||
const statements = []; | ||
@@ -89,3 +76,2 @@ let stringPath = "body"; | ||
let listKey; | ||
if (body.isStatement()) { | ||
@@ -97,3 +83,2 @@ listKey = "body"; | ||
stringPath += ".body.0"; | ||
if (this.isFunction()) { | ||
@@ -107,6 +92,6 @@ key = "argument"; | ||
} | ||
this.node.body = blockStatement(statements); | ||
const parentPath = this.get(stringPath); | ||
body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key); | ||
body.setup(parentPath, listKey ? | ||
parentPath.node[listKey] : parentPath.node, listKey, key); | ||
return this.node; | ||
@@ -124,6 +109,4 @@ } | ||
} | ||
hoistFunctionEnvironment(this); | ||
} | ||
function setType(path, type) { | ||
@@ -141,3 +124,2 @@ path.node.type = type; | ||
} | ||
const { | ||
@@ -147,8 +129,7 @@ thisBinding, | ||
} = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow); | ||
fn.ensureBlock(); | ||
setType(fn, "FunctionExpression"); | ||
if (!noNewArrows) { | ||
const checkBinding = thisBinding ? null : fn.scope.generateUidIdentifier("arrowCheckId"); | ||
if (checkBinding) { | ||
@@ -160,11 +141,9 @@ fn.parentPath.scope.push({ | ||
} | ||
fn.get("body").unshiftContainer("body", expressionStatement(callExpression(this.hub.addHelper("newArrowCheck"), [thisExpression(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)]))); | ||
fn.replaceWith(callExpression(memberExpression((0, _helperFunctionName.default)(this, true) || fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()])); | ||
fn.replaceWith(callExpression(memberExpression( | ||
(0, _helperFunctionName.default)(this, true) || fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()])); | ||
return fn.get("callee.object"); | ||
} | ||
return fn; | ||
} | ||
const getSuperCallsVisitor = (0, _visitors.merge)([{ | ||
@@ -177,6 +156,6 @@ CallExpression(child, { | ||
} | ||
}, _helperEnvironmentVisitor.default]); | ||
function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true) { | ||
function hoistFunctionEnvironment(fnPath, | ||
noNewArrows = true, allowInsertArrow = true) { | ||
let arrowParent; | ||
@@ -186,7 +165,5 @@ let thisEnvFn = fnPath.findParent(p => { | ||
var _arrowParent; | ||
(_arrowParent = arrowParent) != null ? _arrowParent : arrowParent = p; | ||
return false; | ||
} | ||
return p.isFunction() || p.isProgram() || p.isClassProperty({ | ||
@@ -201,3 +178,2 @@ static: false | ||
}); | ||
if (thisEnvFn.isClassProperty() || thisEnvFn.isClassPrivateProperty()) { | ||
@@ -214,3 +190,2 @@ if (arrowParent) { | ||
} | ||
const { | ||
@@ -228,3 +203,2 @@ thisPaths, | ||
} | ||
const allSuperCalls = []; | ||
@@ -245,3 +219,2 @@ thisEnvFn.traverse(getSuperCallsVisitor, { | ||
const args = () => identifier("arguments"); | ||
if (thisEnvFn.scope.path.isProgram()) { | ||
@@ -273,6 +246,6 @@ return conditionalExpression(binaryExpression("===", unaryExpression("typeof", args()), stringLiteral("undefined")), thisEnvFn.scope.buildUndefinedNode(), args()); | ||
} | ||
const flatSuperProps = superProps.reduce((acc, superProp) => acc.concat(standardizeSuperProperty(superProp)), []); | ||
flatSuperProps.forEach(superProp => { | ||
const key = superProp.node.computed ? "" : superProp.get("property").node.name; | ||
const key = superProp.node.computed ? "" : | ||
superProp.get("property").node.name; | ||
const superParentPath = superProp.parentPath; | ||
@@ -290,7 +263,5 @@ const isAssignment = superParentPath.isAssignmentExpression({ | ||
const args = []; | ||
if (superProp.node.computed) { | ||
args.push(superProp.get("property").node); | ||
} | ||
if (isAssignment) { | ||
@@ -300,5 +271,3 @@ const value = superParentPath.node.right; | ||
} | ||
const call = callExpression(identifier(superBinding), args); | ||
if (isCall) { | ||
@@ -320,7 +289,6 @@ superParentPath.unshiftContainer("arguments", thisExpression()); | ||
let thisBinding; | ||
if (thisPaths.length > 0 || !noNewArrows) { | ||
thisBinding = getThisBinding(thisEnvFn, inConstructor); | ||
if (noNewArrows || inConstructor && hasSuperClass(thisEnvFn)) { | ||
if (noNewArrows || | ||
inConstructor && hasSuperClass(thisEnvFn)) { | ||
thisPaths.forEach(thisChild => { | ||
@@ -334,3 +302,2 @@ const thisRef = thisChild.isJSX() ? jsxIdentifier(thisBinding) : identifier(thisBinding); | ||
} | ||
return { | ||
@@ -341,7 +308,5 @@ thisBinding, | ||
} | ||
function isLogicalOp(op) { | ||
return LOGICAL_OPERATORS.includes(op); | ||
} | ||
function standardizeSuperProperty(superProp) { | ||
@@ -353,4 +318,4 @@ if (superProp.parentPath.isAssignmentExpression() && superProp.parentPath.node.operator !== "=") { | ||
const isLogicalAssignment = isLogicalOp(op); | ||
if (superProp.node.computed) { | ||
if (superProp.node.computed) { | ||
const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp"); | ||
@@ -360,4 +325,6 @@ const object = superProp.node.object; | ||
assignmentPath.get("left").replaceWith(memberExpression(object, assignmentExpression("=", tmp, property), true)); | ||
assignmentPath.get("right").replaceWith(rightExpression(isLogicalAssignment ? "=" : op, memberExpression(object, identifier(tmp.name), true), value)); | ||
} else { | ||
const object = superProp.node.object; | ||
@@ -368,3 +335,2 @@ const property = superProp.node.property; | ||
} | ||
if (isLogicalAssignment) { | ||
@@ -375,3 +341,2 @@ assignmentPath.replaceWith(logicalExpression(op, assignmentPath.node.left, assignmentPath.node.right)); | ||
} | ||
return [assignmentPath.get("left"), assignmentPath.get("right").get("left")]; | ||
@@ -382,8 +347,7 @@ } else if (superProp.parentPath.isUpdateExpression()) { | ||
const computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null; | ||
const parts = [assignmentExpression("=", tmp, memberExpression(superProp.node.object, computedKey ? assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), assignmentExpression("=", memberExpression(superProp.node.object, computedKey ? identifier(computedKey.name) : superProp.node.property, superProp.node.computed), binaryExpression(superProp.parentPath.node.operator[0], identifier(tmp.name), numericLiteral(1)))]; | ||
const parts = [assignmentExpression("=", tmp, memberExpression(superProp.node.object, computedKey ? assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), assignmentExpression("=", memberExpression(superProp.node.object, computedKey ? identifier(computedKey.name) : superProp.node.property, superProp.node.computed), binaryExpression( | ||
superProp.parentPath.node.operator[0], identifier(tmp.name), numericLiteral(1)))]; | ||
if (!superProp.parentPath.node.prefix) { | ||
parts.push(identifier(tmp.name)); | ||
} | ||
updateExpr.replaceWith(sequenceExpression(parts)); | ||
@@ -394,5 +358,3 @@ const left = updateExpr.get("expressions.0.right"); | ||
} | ||
return [superProp]; | ||
function rightExpression(op, left, right) { | ||
@@ -406,7 +368,5 @@ if (op === "=") { | ||
} | ||
function hasSuperClass(thisEnvFn) { | ||
return thisEnvFn.isClassMethod() && !!thisEnvFn.parentPath.parentPath.node.superClass; | ||
} | ||
const assignSuperThisVisitor = (0, _visitors.merge)([{ | ||
@@ -422,3 +382,2 @@ CallExpression(child, { | ||
} | ||
}, _helperEnvironmentVisitor.default]); | ||
@@ -448,3 +407,2 @@ | ||
let fnBody; | ||
if (propName) { | ||
@@ -463,11 +421,8 @@ fnBody = memberExpression(_super(), identifier(propName)); | ||
} | ||
return arrowFunctionExpression(argsList, fnBody); | ||
}); | ||
} | ||
function getBinding(thisEnvFn, key, init) { | ||
const cacheKey = "binding:" + key; | ||
let data = thisEnvFn.getData(cacheKey); | ||
if (!data) { | ||
@@ -482,6 +437,4 @@ const id = thisEnvFn.scope.generateUidIdentifier(key); | ||
} | ||
return data; | ||
} | ||
const getScopeInformationVisitor = (0, _visitors.merge)([{ | ||
@@ -493,3 +446,2 @@ ThisExpression(child, { | ||
}, | ||
JSXIdentifier(child, { | ||
@@ -499,3 +451,2 @@ thisPaths | ||
if (child.node.name !== "this") return; | ||
if (!child.parentPath.isJSXMemberExpression({ | ||
@@ -508,6 +459,4 @@ object: child.node | ||
} | ||
thisPaths.push(child); | ||
}, | ||
CallExpression(child, { | ||
@@ -518,3 +467,2 @@ superCalls | ||
}, | ||
MemberExpression(child, { | ||
@@ -525,3 +473,2 @@ superProps | ||
}, | ||
Identifier(child, { | ||
@@ -534,3 +481,2 @@ argumentsPaths | ||
let curr = child.scope; | ||
do { | ||
@@ -541,3 +487,2 @@ if (curr.hasOwnBinding("arguments")) { | ||
} | ||
if (curr.path.isFunction() && !curr.path.isArrowFunctionExpression()) { | ||
@@ -547,6 +492,4 @@ break; | ||
} while (curr = curr.parent); | ||
argumentsPaths.push(child); | ||
}, | ||
MetaProperty(child, { | ||
@@ -563,5 +506,3 @@ newTargetPaths | ||
} | ||
}, _helperEnvironmentVisitor.default]); | ||
function getScopeInformation(fnPath) { | ||
@@ -568,0 +509,0 @@ const thisPaths = []; |
@@ -8,11 +8,12 @@ "use strict"; | ||
exports.evaluateTruthy = evaluateTruthy; | ||
const VALID_CALLEES = ["String", "Number", "Math"]; | ||
const INVALID_METHODS = ["random"]; | ||
function isValidCallee(val) { | ||
return VALID_CALLEES.includes(val); | ||
return VALID_CALLEES.includes( | ||
val); | ||
} | ||
function isInvalidMethod(val) { | ||
return INVALID_METHODS.includes(val); | ||
return INVALID_METHODS.includes( | ||
val); | ||
} | ||
@@ -24,3 +25,2 @@ | ||
} | ||
function deopt(path, state) { | ||
@@ -39,6 +39,4 @@ if (!state.confident) return; | ||
} = state; | ||
if (seen.has(node)) { | ||
const existing = seen.get(node); | ||
if (existing.resolved) { | ||
@@ -55,5 +53,3 @@ return existing.value; | ||
seen.set(node, item); | ||
const val = _evaluate(path, state); | ||
if (state.confident) { | ||
@@ -63,10 +59,7 @@ item.resolved = true; | ||
} | ||
return val; | ||
} | ||
} | ||
function _evaluate(path, state) { | ||
if (!state.confident) return; | ||
if (path.isSequenceExpression()) { | ||
@@ -76,15 +69,11 @@ const exprs = path.get("expressions"); | ||
} | ||
if (path.isStringLiteral() || path.isNumericLiteral() || path.isBooleanLiteral()) { | ||
return path.node.value; | ||
} | ||
if (path.isNullLiteral()) { | ||
return null; | ||
} | ||
if (path.isTemplateLiteral()) { | ||
return evaluateQuasis(path, path.node.quasis, state); | ||
} | ||
if (path.isTaggedTemplateExpression() && path.get("tag").isMemberExpression()) { | ||
@@ -98,12 +87,10 @@ const object = path.get("tag.object"); | ||
const property = path.get("tag.property"); | ||
if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name) && property.isIdentifier() && property.node.name === "raw") { | ||
if (object.isIdentifier() && name === "String" && | ||
!path.scope.getBinding(name) && property.isIdentifier() && property.node.name === "raw") { | ||
return evaluateQuasis(path, path.node.quasi.quasis, state, true); | ||
} | ||
} | ||
if (path.isConditionalExpression()) { | ||
const testResult = evaluateCached(path.get("test"), state); | ||
if (!state.confident) return; | ||
if (testResult) { | ||
@@ -115,3 +102,2 @@ return evaluateCached(path.get("consequent"), state); | ||
} | ||
if (path.isExpressionWrapper()) { | ||
@@ -126,7 +112,5 @@ return evaluateCached(path.get("expression"), state); | ||
const object = path.get("object"); | ||
if (object.isLiteral() && property.isIdentifier()) { | ||
const value = object.node.value; | ||
const type = typeof value; | ||
if (type === "number" || type === "string") { | ||
@@ -137,14 +121,10 @@ return value[property.node.name]; | ||
} | ||
if (path.isReferencedIdentifier()) { | ||
const binding = path.scope.getBinding(path.node.name); | ||
if (binding && binding.constantViolations.length > 0) { | ||
return deopt(binding.path, state); | ||
} | ||
if (binding && path.node.start < binding.path.node.end) { | ||
return deopt(binding.path, state); | ||
} | ||
if (binding != null && binding.hasValue) { | ||
@@ -160,5 +140,3 @@ return binding.value; | ||
} | ||
const resolved = path.resolve(); | ||
if (resolved === path) { | ||
@@ -171,3 +149,2 @@ return deopt(path, state); | ||
} | ||
if (path.isUnaryExpression({ | ||
@@ -179,25 +156,17 @@ prefix: true | ||
} | ||
const argument = path.get("argument"); | ||
if (path.node.operator === "typeof" && (argument.isFunction() || argument.isClass())) { | ||
return "function"; | ||
} | ||
const arg = evaluateCached(argument, state); | ||
if (!state.confident) return; | ||
switch (path.node.operator) { | ||
case "!": | ||
return !arg; | ||
case "+": | ||
return +arg; | ||
case "-": | ||
return -arg; | ||
case "~": | ||
return ~arg; | ||
case "typeof": | ||
@@ -207,10 +176,7 @@ return typeof arg; | ||
} | ||
if (path.isArrayExpression()) { | ||
const arr = []; | ||
const elems = path.get("elements"); | ||
for (const elem of elems) { | ||
const elemValue = elem.evaluate(); | ||
if (elemValue.confident) { | ||
@@ -222,10 +188,7 @@ arr.push(elemValue.value); | ||
} | ||
return arr; | ||
} | ||
if (path.isObjectExpression()) { | ||
const obj = {}; | ||
const props = path.get("properties"); | ||
for (const prop of props) { | ||
@@ -235,13 +198,9 @@ if (prop.isObjectMethod() || prop.isSpreadElement()) { | ||
} | ||
const keyPath = prop.get("key"); | ||
let key; | ||
if (prop.node.computed) { | ||
key = keyPath.evaluate(); | ||
if (!key.confident) { | ||
return deopt(key.deopt, state); | ||
} | ||
key = key.value; | ||
@@ -253,17 +212,12 @@ } else if (keyPath.isIdentifier()) { | ||
} | ||
const valuePath = prop.get("value"); | ||
let value = valuePath.evaluate(); | ||
if (!value.confident) { | ||
return deopt(value.deopt, state); | ||
} | ||
value = value.value; | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
if (path.isLogicalExpression()) { | ||
@@ -276,3 +230,2 @@ const wasConfident = state.confident; | ||
const rightConfident = state.confident; | ||
switch (path.node.operator) { | ||
@@ -283,3 +236,2 @@ case "||": | ||
return left || right; | ||
case "&&": | ||
@@ -289,3 +241,2 @@ state.confident = leftConfident && (!left || rightConfident); | ||
return left && right; | ||
case "??": | ||
@@ -297,3 +248,2 @@ state.confident = leftConfident && (left != null || rightConfident); | ||
} | ||
if (path.isBinaryExpression()) { | ||
@@ -304,61 +254,41 @@ const left = evaluateCached(path.get("left"), state); | ||
if (!state.confident) return; | ||
switch (path.node.operator) { | ||
case "-": | ||
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 ">>>": | ||
@@ -368,3 +298,2 @@ return left >>> right; | ||
} | ||
if (path.isCallExpression()) { | ||
@@ -378,3 +307,2 @@ const callee = path.get("callee"); | ||
} | ||
if (callee.isMemberExpression()) { | ||
@@ -391,3 +319,2 @@ const object = callee.get("object"); | ||
const type = typeof object.node.value; | ||
if (type === "string" || type === "number") { | ||
@@ -399,3 +326,2 @@ context = object.node.value; | ||
} | ||
if (func) { | ||
@@ -407,6 +333,4 @@ const args = path.get("arguments").map(arg => evaluateCached(arg, state)); | ||
} | ||
deopt(path, state); | ||
} | ||
function evaluateQuasis(path, quasis, state, raw = false) { | ||
@@ -416,10 +340,10 @@ let str = ""; | ||
const exprs = path.get("expressions"); | ||
for (const elem of quasis) { | ||
if (!state.confident) break; | ||
str += raw ? elem.value.raw : elem.value.cooked; | ||
const expr = exprs[i++]; | ||
if (expr) str += String(evaluateCached(expr, state)); | ||
} | ||
if (!state.confident) return; | ||
@@ -426,0 +350,0 @@ return str; |
@@ -20,7 +20,4 @@ "use strict"; | ||
exports.getSibling = getSibling; | ||
var _index = require("./index"); | ||
var _t = require("@babel/types"); | ||
const { | ||
@@ -35,3 +32,2 @@ getBindingIdentifiers: _getBindingIdentifiers, | ||
const BREAK_COMPLETION = 1; | ||
function NormalCompletion(path) { | ||
@@ -43,3 +39,2 @@ return { | ||
} | ||
function BreakCompletion(path) { | ||
@@ -51,3 +46,2 @@ return { | ||
} | ||
function getOpposite() { | ||
@@ -59,6 +53,4 @@ if (this.key === "left") { | ||
} | ||
return null; | ||
} | ||
function addCompletionRecords(path, records, context) { | ||
@@ -68,17 +60,11 @@ if (path) { | ||
} | ||
return records; | ||
} | ||
function completionRecordForSwitch(cases, records, context) { | ||
let lastNormalCompletions = []; | ||
for (let i = 0; i < cases.length; i++) { | ||
const casePath = cases[i]; | ||
const caseCompletions = _getCompletionRecords(casePath, context); | ||
const normalCompletions = []; | ||
const breakCompletions = []; | ||
for (const c of caseCompletions) { | ||
@@ -88,3 +74,2 @@ if (c.type === NORMAL_COMPLETION) { | ||
} | ||
if (c.type === BREAK_COMPLETION) { | ||
@@ -94,14 +79,10 @@ breakCompletions.push(c); | ||
} | ||
if (normalCompletions.length) { | ||
lastNormalCompletions = normalCompletions; | ||
} | ||
records.push(...breakCompletions); | ||
} | ||
records.push(...lastNormalCompletions); | ||
return records; | ||
} | ||
function normalCompletionToBreak(completions) { | ||
@@ -126,9 +107,6 @@ completions.forEach(c => { | ||
} | ||
function getStatementListCompletion(paths, context) { | ||
const completions = []; | ||
if (context.canHaveBreak) { | ||
let lastNormalCompletions = []; | ||
for (let i = 0; i < paths.length; i++) { | ||
@@ -139,4 +117,4 @@ const path = paths[i]; | ||
}); | ||
if (path.isBlockStatement() && (context.inCaseClause || context.shouldPopulateBreak)) { | ||
if (path.isBlockStatement() && (context.inCaseClause || | ||
context.shouldPopulateBreak)) { | ||
newContext.shouldPopulateBreak = true; | ||
@@ -146,6 +124,5 @@ } else { | ||
} | ||
const statementCompletions = _getCompletionRecords(path, newContext); | ||
if (statementCompletions.length > 0 && statementCompletions.every(c => c.type === BREAK_COMPLETION)) { | ||
if (statementCompletions.length > 0 && | ||
statementCompletions.every(c => c.type === BREAK_COMPLETION)) { | ||
if (lastNormalCompletions.length > 0 && statementCompletions.every(c => c.path.isBreakStatement({ | ||
@@ -156,3 +133,2 @@ label: null | ||
completions.push(...lastNormalCompletions); | ||
if (lastNormalCompletions.some(c => c.path.isDeclaration())) { | ||
@@ -162,7 +138,5 @@ completions.push(...statementCompletions); | ||
} | ||
replaceBreakStatementInBreakCompletion(statementCompletions, false); | ||
} else { | ||
completions.push(...statementCompletions); | ||
if (!context.shouldPopulateBreak) { | ||
@@ -172,6 +146,4 @@ replaceBreakStatementInBreakCompletion(statementCompletions, true); | ||
} | ||
break; | ||
} | ||
if (i === paths.length - 1) { | ||
@@ -181,10 +153,7 @@ completions.push(...statementCompletions); | ||
lastNormalCompletions = []; | ||
for (let i = 0; i < statementCompletions.length; i++) { | ||
const c = statementCompletions[i]; | ||
if (c.type === BREAK_COMPLETION) { | ||
completions.push(c); | ||
} | ||
if (c.type === NORMAL_COMPLETION) { | ||
@@ -199,3 +168,2 @@ lastNormalCompletions.push(c); | ||
const pathCompletions = _getCompletionRecords(paths[i], context); | ||
if (pathCompletions.length > 1 || pathCompletions.length === 1 && !pathCompletions[0].path.isVariableDeclaration()) { | ||
@@ -207,9 +175,6 @@ completions.push(...pathCompletions); | ||
} | ||
return completions; | ||
} | ||
function _getCompletionRecords(path, context) { | ||
let records = []; | ||
if (path.isIfStatement()) { | ||
@@ -242,3 +207,2 @@ records = addCompletionRecords(path.get("consequent"), records, context); | ||
} | ||
return records; | ||
@@ -253,6 +217,4 @@ } | ||
}); | ||
return records.map(r => r.path); | ||
} | ||
function getSibling(key) { | ||
@@ -267,11 +229,8 @@ return _index.default.get({ | ||
} | ||
function getPrevSibling() { | ||
return this.getSibling(this.key - 1); | ||
} | ||
function getNextSibling() { | ||
return this.getSibling(this.key + 1); | ||
} | ||
function getAllNextSiblings() { | ||
@@ -281,3 +240,2 @@ let _key = this.key; | ||
const siblings = []; | ||
while (sibling.node) { | ||
@@ -287,6 +245,4 @@ siblings.push(sibling); | ||
} | ||
return siblings; | ||
} | ||
function getAllPrevSiblings() { | ||
@@ -296,3 +252,2 @@ let _key = this.key; | ||
const siblings = []; | ||
while (sibling.node) { | ||
@@ -302,3 +257,2 @@ siblings.push(sibling); | ||
} | ||
return siblings; | ||
@@ -310,3 +264,2 @@ } | ||
const parts = key.split("."); | ||
if (parts.length === 1) { | ||
@@ -318,7 +271,5 @@ return this._getKey(key, context); | ||
} | ||
function _getKey(key, context) { | ||
const node = this.node; | ||
const container = node[key]; | ||
if (Array.isArray(container)) { | ||
@@ -343,6 +294,4 @@ return container.map((_, i) => { | ||
} | ||
function _getPattern(parts, context) { | ||
let path = this; | ||
for (const part of parts) { | ||
@@ -359,14 +308,10 @@ if (part === ".") { | ||
} | ||
return path; | ||
} | ||
function getBindingIdentifiers(duplicates) { | ||
return _getBindingIdentifiers(this.node, duplicates); | ||
} | ||
function getOuterBindingIdentifiers(duplicates) { | ||
return _getOuterBindingIdentifiers(this.node, duplicates); | ||
} | ||
function getBindingIdentifierPaths(duplicates = false, outerOnly = false) { | ||
@@ -376,3 +321,2 @@ const path = this; | ||
const ids = Object.create(null); | ||
while (search.length) { | ||
@@ -382,8 +326,7 @@ const id = search.shift(); | ||
if (!id.node) continue; | ||
const keys = _getBindingIdentifiers.keys[id.node.type]; | ||
const keys = | ||
_getBindingIdentifiers.keys[id.node.type]; | ||
if (id.isIdentifier()) { | ||
if (duplicates) { | ||
const _ids = ids[id.node.name] = ids[id.node.name] || []; | ||
_ids.push(id); | ||
@@ -393,16 +336,11 @@ } else { | ||
} | ||
continue; | ||
} | ||
if (id.isExportDeclaration()) { | ||
const declaration = id.get("declaration"); | ||
if (isDeclaration(declaration)) { | ||
search.push(declaration); | ||
} | ||
continue; | ||
} | ||
if (outerOnly) { | ||
@@ -413,3 +351,2 @@ if (id.isFunctionDeclaration()) { | ||
} | ||
if (id.isFunctionExpression()) { | ||
@@ -419,3 +356,2 @@ continue; | ||
} | ||
if (keys) { | ||
@@ -425,3 +361,2 @@ for (let i = 0; i < keys.length; i++) { | ||
const child = id.get(key); | ||
if (Array.isArray(child)) { | ||
@@ -435,6 +370,4 @@ search.push(...child); | ||
} | ||
return ids; | ||
} | ||
function getOuterBindingIdentifierPaths(duplicates = false) { | ||
@@ -441,0 +374,0 @@ return this.getBindingIdentifierPaths(duplicates, true); |
@@ -7,49 +7,26 @@ "use strict"; | ||
exports.default = exports.SHOULD_STOP = exports.SHOULD_SKIP = exports.REMOVED = void 0; | ||
var virtualTypes = require("./lib/virtual-types"); | ||
var _debug = require("debug"); | ||
var _index = require("../index"); | ||
var _scope = require("../scope"); | ||
var _t = require("@babel/types"); | ||
var t = _t; | ||
var _cache = require("../cache"); | ||
var _generator = require("@babel/generator"); | ||
var NodePath_ancestry = require("./ancestry"); | ||
var NodePath_inference = require("./inference"); | ||
var NodePath_replacement = require("./replacement"); | ||
var NodePath_evaluation = require("./evaluation"); | ||
var NodePath_conversion = require("./conversion"); | ||
var NodePath_introspection = require("./introspection"); | ||
var NodePath_context = require("./context"); | ||
var NodePath_removal = require("./removal"); | ||
var NodePath_modification = require("./modification"); | ||
var NodePath_family = require("./family"); | ||
var NodePath_comments = require("./comments"); | ||
var NodePath_virtual_types_validator = require("./lib/virtual-types-validator"); | ||
const { | ||
validate | ||
} = _t; | ||
const debug = _debug("babel"); | ||
const REMOVED = 1 << 0; | ||
@@ -61,3 +38,2 @@ exports.REMOVED = REMOVED; | ||
exports.SHOULD_SKIP = SHOULD_SKIP; | ||
class NodePath { | ||
@@ -82,3 +58,2 @@ constructor(hub, parent) { | ||
} | ||
static get({ | ||
@@ -95,19 +70,13 @@ hub, | ||
} | ||
if (!parent) { | ||
throw new Error("To get a node path the parent needs to exist"); | ||
} | ||
const targetNode = container[key]; | ||
const targetNode = | ||
container[key]; | ||
let paths = _cache.path.get(parent); | ||
if (!paths) { | ||
paths = new Map(); | ||
_cache.path.set(parent, paths); | ||
} | ||
let path = paths.get(targetNode); | ||
if (!path) { | ||
@@ -117,11 +86,8 @@ path = new NodePath(hub, parent); | ||
} | ||
path.setup(parentPath, container, listKey, key); | ||
return path; | ||
} | ||
getScope(scope) { | ||
return this.isScope() ? new _scope.default(this) : scope; | ||
} | ||
setData(key, val) { | ||
@@ -131,6 +97,4 @@ if (this.data == null) { | ||
} | ||
return this.data[key] = val; | ||
} | ||
getData(key, def) { | ||
@@ -140,3 +104,2 @@ if (this.data == null) { | ||
} | ||
let val = this.data[key]; | ||
@@ -146,15 +109,11 @@ if (val === undefined && def !== undefined) val = this.data[key] = def; | ||
} | ||
hasNode() { | ||
return this.node != null; | ||
} | ||
buildCodeFrameError(msg, Error = SyntaxError) { | ||
return this.hub.buildError(this.node, msg, Error); | ||
} | ||
traverse(visitor, state) { | ||
(0, _index.default)(this.node, visitor, this.scope, state, this); | ||
} | ||
set(key, node) { | ||
@@ -164,7 +123,5 @@ validate(this.node, key, node); | ||
} | ||
getPathLocation() { | ||
const parts = []; | ||
let path = this; | ||
do { | ||
@@ -175,6 +132,4 @@ let key = path.key; | ||
} while (path = path.parentPath); | ||
return parts.join("."); | ||
} | ||
debug(message) { | ||
@@ -184,11 +139,8 @@ if (!debug.enabled) return; | ||
} | ||
toString() { | ||
return (0, _generator.default)(this.node).code; | ||
} | ||
get inList() { | ||
return !!this.listKey; | ||
} | ||
set inList(inList) { | ||
@@ -203,7 +155,5 @@ if (!inList) { | ||
} | ||
get shouldSkip() { | ||
return !!(this._traverseFlags & SHOULD_SKIP); | ||
} | ||
set shouldSkip(v) { | ||
@@ -216,7 +166,5 @@ if (v) { | ||
} | ||
get shouldStop() { | ||
return !!(this._traverseFlags & SHOULD_STOP); | ||
} | ||
set shouldStop(v) { | ||
@@ -229,7 +177,5 @@ if (v) { | ||
} | ||
get removed() { | ||
return !!(this._traverseFlags & REMOVED); | ||
} | ||
set removed(v) { | ||
@@ -242,5 +188,3 @@ if (v) { | ||
} | ||
} | ||
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); | ||
@@ -254,3 +198,2 @@ { | ||
const fn = t[typeKey]; | ||
NodePath.prototype[typeKey] = function (opts) { | ||
@@ -268,3 +211,2 @@ return fn(this.node, opts); | ||
Object.assign(NodePath.prototype, NodePath_virtual_types_validator); | ||
for (const type of Object.keys(virtualTypes)) { | ||
@@ -274,3 +216,2 @@ if (type[0] === "_") continue; | ||
} | ||
var _default = NodePath; | ||
@@ -277,0 +218,0 @@ exports.default = _default; |
@@ -12,7 +12,4 @@ "use strict"; | ||
exports.isGenericType = isGenericType; | ||
var inferers = require("./inferers"); | ||
var _t = require("@babel/types"); | ||
const { | ||
@@ -43,13 +40,9 @@ anyTypeAnnotation, | ||
let type = this.getData("typeAnnotation"); | ||
if (type != null) { | ||
return type; | ||
} | ||
type = this._getTypeAnnotation() || anyTypeAnnotation(); | ||
if (isTypeAnnotation(type) || isTSTypeAnnotation(type)) { | ||
type = type.typeAnnotation; | ||
} | ||
this.setData("typeAnnotation", type); | ||
@@ -63,3 +56,2 @@ return type; | ||
const node = this.node; | ||
if (!node) { | ||
@@ -77,3 +69,2 @@ if (this.key === "init" && this.parentPath.isVariableDeclarator()) { | ||
} | ||
return voidTypeAnnotation(); | ||
@@ -88,14 +79,10 @@ } else { | ||
} | ||
if (typeAnnotationInferringNodes.has(node)) { | ||
return; | ||
} | ||
typeAnnotationInferringNodes.add(node); | ||
try { | ||
var _inferer; | ||
let inferer = inferers[node.type]; | ||
let inferer = | ||
inferers[node.type]; | ||
if (inferer) { | ||
@@ -106,3 +93,2 @@ return inferer.call(this, node); | ||
inferer = inferers[this.parentPath.type]; | ||
if ((_inferer = inferer) != null && _inferer.validParent) { | ||
@@ -115,7 +101,5 @@ return this.parentPath.getTypeAnnotation(); | ||
} | ||
function isBaseType(baseName, soft) { | ||
return _isBaseType(baseName, this.getTypeAnnotation(), soft); | ||
} | ||
function _isBaseType(baseName, type, soft) { | ||
@@ -144,7 +128,5 @@ if (baseName === "string") { | ||
} | ||
function couldBeBaseType(name) { | ||
const type = this.getTypeAnnotation(); | ||
if (isAnyTypeAnnotation(type)) return true; | ||
if (isUnionTypeAnnotation(type)) { | ||
@@ -156,3 +138,2 @@ for (const type2 of type.types) { | ||
} | ||
return false; | ||
@@ -163,17 +144,12 @@ } else { | ||
} | ||
function baseTypeStrictlyMatches(rightArg) { | ||
const left = this.getTypeAnnotation(); | ||
const right = rightArg.getTypeAnnotation(); | ||
if (!isAnyTypeAnnotation(left) && isFlowBaseAnnotation(left)) { | ||
return right.type === left.type; | ||
} | ||
return false; | ||
} | ||
function isGenericType(genericName) { | ||
const type = this.getTypeAnnotation(); | ||
if (genericName === "Array") { | ||
@@ -184,3 +160,2 @@ if (isTSArrayType(type) || isArrayTypeAnnotation(type) || isTupleTypeAnnotation(type)) { | ||
} | ||
return isGenericTypeAnnotation(type) && isIdentifier(type.id, { | ||
@@ -187,0 +162,0 @@ name: genericName |
@@ -7,7 +7,4 @@ "use strict"; | ||
exports.default = _default; | ||
var _t = require("@babel/types"); | ||
var _util = require("./util"); | ||
const { | ||
@@ -19,7 +16,6 @@ BOOLEAN_NUMBER_BINARY_OPERATORS, | ||
} = _t; | ||
function _default(node) { | ||
if (!this.isReferenced()) return; | ||
const binding = this.scope.getBinding(node.name); | ||
if (binding) { | ||
@@ -37,5 +33,5 @@ if (binding.identifier.typeAnnotation) { | ||
return numberTypeAnnotation(); | ||
} else if (node.name === "arguments") {} | ||
} else if (node.name === "arguments") { | ||
} | ||
} | ||
function getTypeAnnotationBindingConstantViolations(binding, path, name) { | ||
@@ -46,10 +42,11 @@ const types = []; | ||
const testType = getConditionalAnnotation(binding, path, name); | ||
if (testType) { | ||
const testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement); | ||
constantViolations = constantViolations.filter(path => testConstantViolations.indexOf(path) < 0); | ||
types.push(testType.typeAnnotation); | ||
} | ||
if (constantViolations.length) { | ||
if (constantViolations.length) { | ||
constantViolations.push(...functionConstantViolations); | ||
@@ -61,10 +58,7 @@ | ||
} | ||
if (!types.length) { | ||
return; | ||
} | ||
return (0, _util.createUnionType)(types); | ||
} | ||
function getConstantViolationsBefore(binding, path, functions) { | ||
@@ -75,5 +69,3 @@ const violations = binding.constantViolations.slice(); | ||
violation = violation.resolve(); | ||
const status = violation._guessExecutionStatusRelativeTo(path); | ||
if (functions && status === "unknown") functions.push(violation); | ||
@@ -83,3 +75,2 @@ return status === "before"; | ||
} | ||
function inferAnnotationFromBinaryExpression(name, path) { | ||
@@ -90,3 +81,2 @@ const operator = path.node.operator; | ||
let target; | ||
if (left.isIdentifier({ | ||
@@ -101,3 +91,2 @@ name | ||
} | ||
if (target) { | ||
@@ -107,14 +96,11 @@ if (operator === "===") { | ||
} | ||
if (BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) { | ||
return numberTypeAnnotation(); | ||
} | ||
return; | ||
} | ||
if (operator !== "===" && operator !== "==") return; | ||
if (operator !== "===" && operator !== "==") return; | ||
let typeofPath; | ||
let typePath; | ||
if (left.isUnaryExpression({ | ||
@@ -131,3 +117,2 @@ operator: "typeof" | ||
} | ||
if (!typeofPath) return; | ||
@@ -137,12 +122,13 @@ if (!typeofPath.get("argument").isIdentifier({ | ||
})) return; | ||
typePath = typePath.resolve(); | ||
if (!typePath.isLiteral()) return; | ||
const typeValue = typePath.node.value; | ||
if (typeof typeValue !== "string") return; | ||
return createTypeAnnotationBasedOnTypeof(typeValue); | ||
} | ||
function getParentConditionalPath(binding, path, name) { | ||
let parentPath; | ||
while (parentPath = path.parentPath) { | ||
@@ -153,14 +139,10 @@ if (parentPath.isIfStatement() || parentPath.isConditionalExpression()) { | ||
} | ||
return parentPath; | ||
} | ||
if (parentPath.isFunction()) { | ||
if (parentPath.parentPath.scope.getBinding(name) !== binding) return; | ||
} | ||
path = parentPath; | ||
} | ||
} | ||
function getConditionalAnnotation(binding, path, name) { | ||
@@ -172,6 +154,4 @@ const ifStatement = getParentConditionalPath(binding, path, name); | ||
const types = []; | ||
for (let i = 0; i < paths.length; i++) { | ||
const path = paths[i]; | ||
if (path.isLogicalExpression()) { | ||
@@ -187,3 +167,2 @@ if (path.node.operator === "&&") { | ||
} | ||
if (types.length) { | ||
@@ -195,3 +174,2 @@ return { | ||
} | ||
return getConditionalAnnotation(binding, ifStatement, name); | ||
@@ -198,0 +176,0 @@ } |
@@ -37,9 +37,5 @@ "use strict"; | ||
exports.VariableDeclarator = VariableDeclarator; | ||
var _t = require("@babel/types"); | ||
var _infererReference = require("./inferer-reference"); | ||
var _util = require("./util"); | ||
const { | ||
@@ -65,3 +61,2 @@ BOOLEAN_BINARY_OPERATORS, | ||
} = _t; | ||
function VariableDeclarator() { | ||
@@ -71,19 +66,13 @@ if (!this.get("id").isIdentifier()) return; | ||
} | ||
function TypeCastExpression(node) { | ||
return node.typeAnnotation; | ||
} | ||
TypeCastExpression.validParent = true; | ||
function TSAsExpression(node) { | ||
return node.typeAnnotation; | ||
} | ||
TSAsExpression.validParent = true; | ||
function TSNonNullExpression() { | ||
return this.get("expression").getTypeAnnotation(); | ||
} | ||
function NewExpression(node) { | ||
@@ -94,10 +83,7 @@ if (node.callee.type === "Identifier") { | ||
} | ||
function TemplateLiteral() { | ||
return stringTypeAnnotation(); | ||
} | ||
function UnaryExpression(node) { | ||
const operator = node.operator; | ||
if (operator === "void") { | ||
@@ -113,6 +99,4 @@ return voidTypeAnnotation(); | ||
} | ||
function BinaryExpression(node) { | ||
const operator = node.operator; | ||
if (NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) { | ||
@@ -125,3 +109,2 @@ return numberTypeAnnotation(); | ||
const left = this.get("left"); | ||
if (left.isBaseType("number") && right.isBaseType("number")) { | ||
@@ -136,3 +119,2 @@ return numberTypeAnnotation(); | ||
} | ||
function LogicalExpression() { | ||
@@ -142,3 +124,2 @@ const argumentTypes = [this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]; | ||
} | ||
function ConditionalExpression() { | ||
@@ -148,18 +129,13 @@ const argumentTypes = [this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]; | ||
} | ||
function SequenceExpression() { | ||
return this.get("expressions").pop().getTypeAnnotation(); | ||
} | ||
function ParenthesizedExpression() { | ||
return this.get("expression").getTypeAnnotation(); | ||
} | ||
function AssignmentExpression() { | ||
return this.get("right").getTypeAnnotation(); | ||
} | ||
function UpdateExpression(node) { | ||
const operator = node.operator; | ||
if (operator === "++" || operator === "--") { | ||
@@ -169,41 +145,30 @@ return numberTypeAnnotation(); | ||
} | ||
function StringLiteral() { | ||
return stringTypeAnnotation(); | ||
} | ||
function NumericLiteral() { | ||
return numberTypeAnnotation(); | ||
} | ||
function BooleanLiteral() { | ||
return booleanTypeAnnotation(); | ||
} | ||
function NullLiteral() { | ||
return nullLiteralTypeAnnotation(); | ||
} | ||
function RegExpLiteral() { | ||
return genericTypeAnnotation(identifier("RegExp")); | ||
} | ||
function ObjectExpression() { | ||
return genericTypeAnnotation(identifier("Object")); | ||
} | ||
function ArrayExpression() { | ||
return genericTypeAnnotation(identifier("Array")); | ||
} | ||
function RestElement() { | ||
return ArrayExpression(); | ||
} | ||
RestElement.validParent = true; | ||
function Func() { | ||
return genericTypeAnnotation(identifier("Function")); | ||
} | ||
const isArrayFrom = buildMatchMemberExpression("Array.from"); | ||
@@ -213,3 +178,2 @@ const isObjectKeys = buildMatchMemberExpression("Object.keys"); | ||
const isObjectEntries = buildMatchMemberExpression("Object.entries"); | ||
function CallExpression() { | ||
@@ -219,6 +183,6 @@ const { | ||
} = this.node; | ||
if (isObjectKeys(callee)) { | ||
return arrayTypeAnnotation(stringTypeAnnotation()); | ||
} else if (isArrayFrom(callee) || isObjectValues(callee) || isIdentifier(callee, { | ||
} else if (isArrayFrom(callee) || isObjectValues(callee) || | ||
isIdentifier(callee, { | ||
name: "Array" | ||
@@ -230,13 +194,9 @@ })) { | ||
} | ||
return resolveCall(this.get("callee")); | ||
} | ||
function TaggedTemplateExpression() { | ||
return resolveCall(this.get("tag")); | ||
} | ||
function resolveCall(callee) { | ||
callee = callee.resolve(); | ||
if (callee.isFunction()) { | ||
@@ -246,3 +206,2 @@ const { | ||
} = callee; | ||
if (node.async) { | ||
@@ -259,3 +218,4 @@ if (node.generator) { | ||
return callee.node.returnType; | ||
} else {} | ||
} else { | ||
} | ||
} | ||
@@ -262,0 +222,0 @@ } |
@@ -7,5 +7,3 @@ "use strict"; | ||
exports.createUnionType = createUnionType; | ||
var _t = require("@babel/types"); | ||
const { | ||
@@ -18,3 +16,2 @@ createFlowUnionType, | ||
} = _t; | ||
function createUnionType(types) { | ||
@@ -26,3 +23,2 @@ { | ||
} | ||
return createUnionTypeAnnotation(types); | ||
@@ -29,0 +25,0 @@ } else { |
@@ -25,5 +25,3 @@ "use strict"; | ||
exports.willIMaybeExecuteBefore = willIMaybeExecuteBefore; | ||
var _t = require("@babel/types"); | ||
const { | ||
@@ -47,3 +45,2 @@ STATEMENT_OR_BLOCK_KEYS, | ||
const val = this.node && this.node[key]; | ||
if (val && Array.isArray(val)) { | ||
@@ -61,2 +58,3 @@ return !!val.length; | ||
const is = has; | ||
exports.is = is; | ||
@@ -84,3 +82,2 @@ | ||
} | ||
if (this.isExpression()) { | ||
@@ -91,3 +88,2 @@ return isBlockStatement(replacement); | ||
} | ||
return false; | ||
@@ -99,3 +95,2 @@ } | ||
let first = true; | ||
do { | ||
@@ -110,3 +105,2 @@ const { | ||
} | ||
first = false; | ||
@@ -118,3 +112,2 @@ | ||
} while ((path = path.parentPath) && !path.isProgram() && !path.isDoExpression()); | ||
return true; | ||
@@ -139,6 +132,4 @@ } | ||
} | ||
return false; | ||
} | ||
const binding = this.scope.getBinding(this.node.name); | ||
@@ -155,11 +146,8 @@ if (!binding || binding.kind !== "module") return false; | ||
} | ||
if (path.isImportDefaultSpecifier() && importName === "default") { | ||
return true; | ||
} | ||
if (path.isImportNamespaceSpecifier() && importName === "*") { | ||
return true; | ||
} | ||
if (path.isImportSpecifier() && isIdentifier(path.node.imported, { | ||
@@ -170,3 +158,2 @@ name: importName | ||
} | ||
return false; | ||
@@ -177,3 +164,2 @@ } | ||
const node = this.node; | ||
if (node.end) { | ||
@@ -183,14 +169,10 @@ const code = this.hub.getCode(); | ||
} | ||
return ""; | ||
} | ||
function willIMaybeExecuteBefore(target) { | ||
return this._guessExecutionStatusRelativeTo(target) !== "after"; | ||
} | ||
function getOuterFunction(path) { | ||
return (path.scope.getFunctionParent() || path.scope.getProgramParent()).path; | ||
} | ||
function isExecutionUncertain(type, key) { | ||
@@ -228,3 +210,2 @@ switch (type) { | ||
return key === "arguments"; | ||
default: | ||
@@ -234,7 +215,5 @@ return false; | ||
} | ||
function isExecutionUncertainInList(paths, maxIndex) { | ||
for (let i = 0; i < maxIndex; i++) { | ||
const path = paths[i]; | ||
if (isExecutionUncertain(path.parent.type, path.parentKey)) { | ||
@@ -244,3 +223,2 @@ return true; | ||
} | ||
return false; | ||
@@ -252,3 +230,2 @@ } | ||
} | ||
function _guessExecutionStatusRelativeToCached(base, target, cache) { | ||
@@ -263,3 +240,2 @@ const funcParent = { | ||
} | ||
const paths = { | ||
@@ -269,4 +245,6 @@ target: target.getAncestry(), | ||
}; | ||
if (paths.target.indexOf(base) >= 0) return "after"; | ||
if (paths.this.indexOf(target) >= 0) return "before"; | ||
let commonPath; | ||
@@ -277,7 +255,5 @@ const commonIndex = { | ||
}; | ||
while (!commonPath && commonIndex.this < paths.this.length) { | ||
const path = paths.this[commonIndex.this]; | ||
commonIndex.target = paths.target.indexOf(path); | ||
if (commonIndex.target >= 0) { | ||
@@ -289,11 +265,8 @@ commonPath = path; | ||
} | ||
if (!commonPath) { | ||
throw new Error("Internal Babel error - The two compared nodes" + " don't appear to belong to the same program."); | ||
} | ||
if (isExecutionUncertainInList(paths.this, commonIndex.this - 1) || isExecutionUncertainInList(paths.target, commonIndex.target - 1)) { | ||
return "unknown"; | ||
} | ||
const divergence = { | ||
@@ -317,3 +290,2 @@ this: paths.this[commonIndex.this - 1], | ||
const executionOrderCheckedNodes = new Set(); | ||
function _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache) { | ||
@@ -325,2 +297,3 @@ if (!target.isFunctionDeclaration() || target.parentPath.isExportDeclaration()) { | ||
const binding = target.scope.getBinding(target.node.id.name); | ||
if (!binding.references) return "before"; | ||
@@ -333,3 +306,2 @@ const referencePaths = binding.referencePaths; | ||
if (childOfFunction) continue; | ||
if (path.key !== "callee" || !path.parentPath.isCallExpression()) { | ||
@@ -341,6 +313,4 @@ return "unknown"; | ||
executionOrderCheckedNodes.add(path.node); | ||
try { | ||
const status = _guessExecutionStatusRelativeToCached(base, path, cache); | ||
if (allStatus && allStatus !== status) { | ||
@@ -355,9 +325,6 @@ return "unknown"; | ||
} | ||
return allStatus; | ||
} | ||
function _guessExecutionStatusRelativeToDifferentFunctionsCached(base, target, cache) { | ||
let nodeMap = cache.get(base.node); | ||
if (!nodeMap) { | ||
@@ -368,5 +335,3 @@ cache.set(base.node, nodeMap = new Map()); | ||
} | ||
const result = _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache); | ||
nodeMap.set(target.node, result); | ||
@@ -379,18 +344,19 @@ return result; | ||
} | ||
function _resolve(dangerous, resolved) { | ||
if (resolved && resolved.indexOf(this) >= 0) return; | ||
resolved = resolved || []; | ||
resolved.push(this); | ||
if (this.isVariableDeclarator()) { | ||
if (this.get("id").isIdentifier()) { | ||
return this.get("init").resolve(dangerous, resolved); | ||
} else {} | ||
} else { | ||
} | ||
} else if (this.isReferencedIdentifier()) { | ||
const binding = this.scope.getBinding(this.node.name); | ||
if (!binding) return; | ||
if (!binding.constant) return; | ||
if (binding.kind === "module") return; | ||
if (binding.path !== this) { | ||
@@ -404,16 +370,18 @@ const ret = binding.path.resolve(dangerous, resolved); | ||
} else if (dangerous && this.isMemberExpression()) { | ||
const targetKey = this.toComputedKey(); | ||
if (!isLiteral(targetKey)) return; | ||
const targetName = targetKey.value; | ||
const target = this.get("object").resolve(dangerous, resolved); | ||
if (target.isObjectExpression()) { | ||
const props = target.get("properties"); | ||
for (const prop of props) { | ||
if (!prop.isProperty()) continue; | ||
const key = prop.get("key"); | ||
let match = prop.isnt("computed") && key.isIdentifier({ | ||
name: targetName | ||
}); | ||
match = match || key.isLiteral({ | ||
@@ -431,3 +399,2 @@ value: targetName | ||
} | ||
function isConstantExpression() { | ||
@@ -439,3 +406,2 @@ if (this.isIdentifier()) { | ||
} | ||
if (this.isLiteral()) { | ||
@@ -445,10 +411,7 @@ if (this.isRegExpLiteral()) { | ||
} | ||
if (this.isTemplateLiteral()) { | ||
return this.get("expressions").every(expression => expression.isConstantExpression()); | ||
} | ||
return true; | ||
} | ||
if (this.isUnaryExpression()) { | ||
@@ -458,13 +421,12 @@ if (this.node.operator !== "void") { | ||
} | ||
return this.get("argument").isConstantExpression(); | ||
} | ||
if (this.isBinaryExpression()) { | ||
return this.get("left").isConstantExpression() && this.get("right").isConstantExpression(); | ||
const { | ||
operator | ||
} = this.node; | ||
return operator !== "in" && operator !== "instanceof" && this.get("left").isConstantExpression() && this.get("right").isConstantExpression(); | ||
} | ||
return false; | ||
} | ||
function isInStrictMode() { | ||
@@ -477,9 +439,6 @@ const start = this.isProgram() ? this : this.parentPath; | ||
if (path.isClass()) return true; | ||
if (path.isArrowFunctionExpression() && !path.get("body").isBlockStatement()) { | ||
return false; | ||
} | ||
let body; | ||
if (path.isFunction()) { | ||
@@ -492,3 +451,2 @@ body = path.node.body; | ||
} | ||
for (const directive of body.directives) { | ||
@@ -495,0 +453,0 @@ if (directive.value.value === "use strict") { |
@@ -7,5 +7,3 @@ "use strict"; | ||
exports.default = void 0; | ||
var _t = require("@babel/types"); | ||
var _t2 = _t; | ||
@@ -29,3 +27,2 @@ const { | ||
let scope = path.scope; | ||
do { | ||
@@ -36,3 +33,2 @@ if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) { | ||
} while (scope = scope.parent); | ||
if (scope) state.breakOnScopePaths.push(scope.path); | ||
@@ -55,5 +51,3 @@ } | ||
} | ||
}; | ||
class PathHoister { | ||
@@ -80,3 +74,2 @@ constructor(path, scope) { | ||
const binding = this.bindings[key]; | ||
if (!scope.bindingIdentifierEquals(key, binding.identifier)) { | ||
@@ -86,3 +79,2 @@ return false; | ||
} | ||
return true; | ||
@@ -93,3 +85,2 @@ } | ||
let scope = this.path.scope; | ||
do { | ||
@@ -107,6 +98,4 @@ if (this.isCompatibleScope(scope)) { | ||
} | ||
getAttachmentPath() { | ||
let path = this._getAttachmentPath(); | ||
if (!path) return; | ||
@@ -142,6 +131,4 @@ let targetScope = path.scope; | ||
} | ||
return path; | ||
} | ||
_getAttachmentPath() { | ||
@@ -151,8 +138,7 @@ const scopes = this.scopes; | ||
if (!scope) return; | ||
if (scope.path.isFunction()) { | ||
if (this.hasOwnParamBindings(scope)) { | ||
if (this.scope === scope) return; | ||
const bodies = scope.path.get("body").get("body"); | ||
for (let i = 0; i < bodies.length; i++) { | ||
@@ -169,3 +155,2 @@ if (bodies[i].node._blockHoist) continue; | ||
} | ||
getNextScopeAttachmentParent() { | ||
@@ -178,3 +163,5 @@ const scope = this.scopes.pop(); | ||
do { | ||
if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) { | ||
if ( | ||
!path.parentPath || | ||
Array.isArray(path.container) && path.isStatement()) { | ||
return path; | ||
@@ -191,6 +178,4 @@ } | ||
} | ||
return false; | ||
} | ||
run() { | ||
@@ -202,4 +187,7 @@ this.path.traverse(referenceVisitor, this); | ||
if (!attachTo) return; | ||
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return; | ||
let uid = attachTo.scope.generateUidIdentifier("ref"); | ||
const declarator = variableDeclarator(uid, this.path.node); | ||
@@ -209,15 +197,11 @@ const insertFn = this.attachAfter ? "insertAfter" : "insertBefore"; | ||
const parent = this.path.parentPath; | ||
if (parent.isJSXElement() && this.path.container === parent.node.children) { | ||
uid = jsxExpressionContainer(uid); | ||
} | ||
this.path.replaceWith(cloneNode(uid)); | ||
return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init"); | ||
} | ||
} | ||
exports.default = PathHoister; | ||
//# sourceMappingURL=hoister.js.map |
@@ -7,5 +7,10 @@ "use strict"; | ||
exports.hooks = void 0; | ||
const hooks = [function (self, parent) { | ||
const removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement(); | ||
const removeParent = | ||
self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || | ||
self.key === "declaration" && parent.isExportDeclaration() || | ||
self.key === "body" && parent.isLabeledStatement() || | ||
self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || | ||
self.key === "expression" && parent.isExpressionStatement(); | ||
if (removeParent) { | ||
@@ -27,3 +32,2 @@ parent.remove(); | ||
} | ||
return true; | ||
@@ -30,0 +34,0 @@ } |
@@ -24,5 +24,3 @@ "use strict"; | ||
exports.isVar = isVar; | ||
var _t = require("@babel/types"); | ||
const { | ||
@@ -54,3 +52,2 @@ isBinding, | ||
} = react; | ||
function isReferencedIdentifier(opts) { | ||
@@ -61,3 +58,2 @@ const { | ||
} = this; | ||
if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) { | ||
@@ -73,3 +69,2 @@ if (isJSXIdentifier(node, opts)) { | ||
} | ||
function isReferencedMemberExpression() { | ||
@@ -82,3 +77,2 @@ const { | ||
} | ||
function isBindingIdentifier() { | ||
@@ -92,3 +86,2 @@ const { | ||
} | ||
function isStatement() { | ||
@@ -99,3 +92,2 @@ const { | ||
} = this; | ||
if (nodeIsStatement(node)) { | ||
@@ -110,3 +102,2 @@ if (isVariableDeclaration(node)) { | ||
} | ||
return true; | ||
@@ -117,3 +108,2 @@ } else { | ||
} | ||
function isExpression() { | ||
@@ -126,31 +116,23 @@ if (this.isIdentifier()) { | ||
} | ||
function isScope() { | ||
return nodeIsScope(this.node, this.parent); | ||
} | ||
function isReferenced() { | ||
return nodeIsReferenced(this.node, this.parent); | ||
} | ||
function isBlockScoped() { | ||
return nodeIsBlockScoped(this.node); | ||
} | ||
function isVar() { | ||
return nodeIsVar(this.node); | ||
} | ||
function isUser() { | ||
return this.node && !!this.node.loc; | ||
} | ||
function isGenerated() { | ||
return !this.isUser(); | ||
} | ||
function isPure(constantsOnly) { | ||
return this.scope.isPure(this.node, constantsOnly); | ||
} | ||
function isFlow() { | ||
@@ -160,3 +142,2 @@ const { | ||
} = this; | ||
if (nodeIsFlow(node)) { | ||
@@ -178,7 +159,5 @@ return true; | ||
} | ||
function isSpreadProperty() { | ||
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectExpression(); | ||
} | ||
function isForAwaitStatement() { | ||
@@ -189,7 +168,5 @@ return isForOfStatement(this.node, { | ||
} | ||
function isExistentialTypeParam() { | ||
throw new Error("`path.isExistentialTypeParam` has been renamed to `path.isExistsTypeAnnotation()` in Babel 7."); | ||
} | ||
function isNumericLiteralTypeAnnotation() { | ||
@@ -196,0 +173,0 @@ throw new Error("`path.isNumericLiteralTypeAnnotation()` has been renamed to `path.isNumberLiteralTypeAnnotation()` in Babel 7."); |
@@ -32,2 +32,3 @@ "use strict"; | ||
const Flow = ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"]; | ||
exports.Flow = Flow; | ||
@@ -34,0 +35,0 @@ const RestProperty = ["RestElement"]; |
@@ -16,11 +16,6 @@ "use strict"; | ||
exports.updateSiblingKeys = updateSiblingKeys; | ||
var _cache = require("../cache"); | ||
var _hoister = require("./lib/hoister"); | ||
var _index = require("./index"); | ||
var _t = require("@babel/types"); | ||
const { | ||
@@ -45,9 +40,6 @@ arrowFunctionExpression, | ||
this._assertUnremoved(); | ||
const nodes = this._verifyNodeList(nodes_); | ||
const { | ||
parentPath | ||
} = this; | ||
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) { | ||
@@ -64,3 +56,4 @@ return parentPath.insertBefore(nodes); | ||
this.replaceWith(blockStatement(shouldInsertCurrentNode ? [node] : [])); | ||
return this.unshiftContainer("body", nodes); | ||
return this.unshiftContainer("body", | ||
nodes); | ||
} else { | ||
@@ -70,8 +63,7 @@ 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?"); | ||
} | ||
function _containerInsert(from, nodes) { | ||
this.updateSiblingKeys(from, nodes.length); | ||
const paths = []; | ||
this.container.splice(from, 0, ...nodes); | ||
for (let i = 0; i < nodes.length; i++) { | ||
@@ -81,3 +73,2 @@ const to = from + i; | ||
paths.push(path); | ||
if (this.context && this.context.queue) { | ||
@@ -87,9 +78,6 @@ path.pushContext(this.context); | ||
} | ||
const contexts = this._getQueueContexts(); | ||
for (const path of paths) { | ||
path.setScope(); | ||
path.debug("Inserted."); | ||
for (const context of contexts) { | ||
@@ -99,20 +87,14 @@ context.maybeQueue(path, true); | ||
} | ||
return paths; | ||
} | ||
function _containerInsertBefore(nodes) { | ||
return this._containerInsert(this.key, nodes); | ||
} | ||
function _containerInsertAfter(nodes) { | ||
return this._containerInsert(this.key + 1, nodes); | ||
} | ||
const last = arr => arr[arr.length - 1]; | ||
function isHiddenInSequenceExpression(path) { | ||
return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath)); | ||
} | ||
function isAlmostConstantAssignment(node, scope) { | ||
@@ -124,2 +106,3 @@ if (!isAssignmentExpression(node) || !isIdentifier(node.left)) { | ||
const blockScope = scope.getBlockParent(); | ||
return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1; | ||
@@ -130,13 +113,9 @@ } | ||
this._assertUnremoved(); | ||
if (this.isSequenceExpression()) { | ||
return last(this.get("expressions")).insertAfter(nodes_); | ||
} | ||
const nodes = this._verifyNodeList(nodes_); | ||
const { | ||
parentPath | ||
} = this; | ||
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) { | ||
@@ -152,3 +131,2 @@ return parentPath.insertAfter(nodes.map(node => { | ||
} = this; | ||
if (scope.path.isPattern()) { | ||
@@ -160,6 +138,6 @@ assertExpression(node); | ||
} | ||
if (isHiddenInSequenceExpression(this)) { | ||
nodes.unshift(node); | ||
} else if (isCallExpression(node) && isSuper(node.callee)) { | ||
} | ||
else if (isCallExpression(node) && isSuper(node.callee)) { | ||
nodes.unshift(node); | ||
@@ -179,9 +157,8 @@ nodes.push(thisExpression()); | ||
} | ||
const temp = scope.generateDeclaredUidIdentifier(); | ||
nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node))); | ||
nodes.unshift(expressionStatement( | ||
assignmentExpression("=", cloneNode(temp), node))); | ||
nodes.push(expressionStatement(cloneNode(temp))); | ||
} | ||
} | ||
return this.replaceExpressionWithStatements(nodes); | ||
@@ -202,5 +179,3 @@ } else if (Array.isArray(this.container)) { | ||
if (!this.parent) return; | ||
const paths = _cache.path.get(this.parent); | ||
for (const [, path] of paths) { | ||
@@ -212,3 +187,2 @@ if (path.key >= fromIndex) { | ||
} | ||
function _verifyNodeList(nodes) { | ||
@@ -218,11 +192,8 @@ if (!nodes) { | ||
} | ||
if (!Array.isArray(nodes)) { | ||
nodes = [nodes]; | ||
} | ||
for (let i = 0; i < nodes.length; i++) { | ||
const node = nodes[i]; | ||
let msg; | ||
if (!node) { | ||
@@ -237,3 +208,2 @@ msg = "has falsy node"; | ||
} | ||
if (msg) { | ||
@@ -244,6 +214,4 @@ const type = Array.isArray(node) ? "array" : typeof node; | ||
} | ||
return nodes; | ||
} | ||
function unshiftContainer(listKey, nodes) { | ||
@@ -261,13 +229,11 @@ this._assertUnremoved(); | ||
}).setContext(this.context); | ||
return path._containerInsertBefore(nodes); | ||
return path._containerInsertBefore( | ||
nodes); | ||
} | ||
function pushContainer(listKey, nodes) { | ||
this._assertUnremoved(); | ||
const verifiedNodes = this._verifyNodeList( | ||
nodes); | ||
const verifiedNodes = this._verifyNodeList(nodes); | ||
const container = this.node[listKey]; | ||
const path = _index.default.get({ | ||
@@ -280,3 +246,2 @@ parentPath: this, | ||
}).setContext(this.context); | ||
return path.replaceWithMultiple(verifiedNodes); | ||
@@ -283,0 +248,0 @@ } |
@@ -12,7 +12,4 @@ "use strict"; | ||
exports.remove = remove; | ||
var _removalHooks = require("./lib/removal-hooks"); | ||
var _cache = require("../cache"); | ||
var _index = require("./index"); | ||
@@ -22,24 +19,15 @@ | ||
var _this$opts; | ||
this._assertUnremoved(); | ||
this.resync(); | ||
if (!((_this$opts = this.opts) != null && _this$opts.noScope)) { | ||
this._removeFromScope(); | ||
} | ||
if (this._callRemovalHooks()) { | ||
this._markRemoved(); | ||
return; | ||
} | ||
this.shareCommentsWithSiblings(); | ||
this._remove(); | ||
this._markRemoved(); | ||
} | ||
function _removeFromScope() { | ||
@@ -49,3 +37,2 @@ const bindings = this.getBindingIdentifiers(); | ||
} | ||
function _callRemovalHooks() { | ||
@@ -56,3 +43,2 @@ for (const fn of _removalHooks.hooks) { | ||
} | ||
function _remove() { | ||
@@ -66,3 +52,2 @@ if (Array.isArray(this.container)) { | ||
} | ||
function _markRemoved() { | ||
@@ -73,3 +58,2 @@ this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED; | ||
} | ||
function _assertUnremoved() { | ||
@@ -76,0 +60,0 @@ if (this.removed) { |
@@ -12,17 +12,9 @@ "use strict"; | ||
exports.replaceWithSourceString = replaceWithSourceString; | ||
var _codeFrame = require("@babel/code-frame"); | ||
var _index = require("../index"); | ||
var _index2 = require("./index"); | ||
var _cache = require("../cache"); | ||
var _parser = require("@babel/parser"); | ||
var _t = require("@babel/types"); | ||
var _helperHoistVariables = require("@babel/helper-hoist-variables"); | ||
const { | ||
@@ -53,3 +45,2 @@ FUNCTION_TYPES, | ||
var _pathCache$get; | ||
this.resync(); | ||
@@ -60,5 +51,5 @@ nodes = this._verifyNodeList(nodes); | ||
(_pathCache$get = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get.delete(this.node); | ||
this.node = this.container[this.key] = null; | ||
this.node = | ||
this.container[this.key] = null; | ||
const paths = this.insertAfter(nodes); | ||
if (this.node) { | ||
@@ -69,3 +60,2 @@ this.requeue(); | ||
} | ||
return paths; | ||
@@ -77,3 +67,2 @@ } | ||
let ast; | ||
try { | ||
@@ -84,3 +73,2 @@ replacement = `(${replacement})`; | ||
const loc = err.loc; | ||
if (loc) { | ||
@@ -95,10 +83,6 @@ err.message += " - make sure this is an expression.\n" + (0, _codeFrame.codeFrameColumns)(replacement, { | ||
} | ||
throw err; | ||
} | ||
const expressionAST = ast.program.body[0].expression; | ||
_index.default.removeProperties(expressionAST); | ||
return this.replaceWith(expressionAST); | ||
@@ -109,31 +93,22 @@ } | ||
this.resync(); | ||
if (this.removed) { | ||
throw new Error("You can't replace this node, we've already removed it"); | ||
} | ||
let replacement = replacementPath instanceof _index2.default ? replacementPath.node : replacementPath; | ||
if (!replacement) { | ||
throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead"); | ||
} | ||
if (this.node === replacement) { | ||
return [this]; | ||
} | ||
if (this.isProgram() && !isProgram(replacement)) { | ||
throw new Error("You can only replace a Program root node with another Program node"); | ||
} | ||
if (Array.isArray(replacement)) { | ||
throw new Error("Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`"); | ||
} | ||
if (typeof replacement === "string") { | ||
throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`"); | ||
} | ||
let nodePath = ""; | ||
if (this.isNodeType("Statement") && isExpression(replacement)) { | ||
@@ -145,3 +120,2 @@ if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) { | ||
} | ||
if (this.isNodeType("Expression") && isStatement(replacement)) { | ||
@@ -152,5 +126,3 @@ if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) { | ||
} | ||
const oldNode = this.node; | ||
if (oldNode) { | ||
@@ -162,5 +134,6 @@ inheritsComments(replacement, oldNode); | ||
this._replaceWith(replacement); | ||
this.type = replacement.type; | ||
this.type = replacement.type; | ||
this.setScope(); | ||
this.requeue(); | ||
@@ -172,7 +145,5 @@ return [nodePath ? this.get(nodePath) : this]; | ||
var _pathCache$get2; | ||
if (!this.container) { | ||
throw new ReferenceError("Container is falsy"); | ||
} | ||
if (this.inList) { | ||
@@ -183,6 +154,6 @@ validate(this.parent, this.key, [node]); | ||
} | ||
this.debug(`Replace with ${node == null ? void 0 : node.type}`); | ||
(_pathCache$get2 = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get2.set(node, this).delete(this.node); | ||
this.node = this.container[this.key] = node; | ||
this.node = | ||
this.container[this.key] = node; | ||
} | ||
@@ -193,7 +164,5 @@ | ||
const nodesAsSequenceExpression = toSequenceExpression(nodes, this.scope); | ||
if (nodesAsSequenceExpression) { | ||
return this.replaceWith(nodesAsSequenceExpression)[0].get("expressions"); | ||
} | ||
const functionParent = this.getFunctionParent(); | ||
@@ -204,2 +173,3 @@ const isParentAsync = functionParent == null ? void 0 : functionParent.is("async"); | ||
this.replaceWith(callExpression(container, [])); | ||
const callee = this.get("callee"); | ||
@@ -211,11 +181,9 @@ (0, _helperHoistVariables.default)(callee.get("body"), id => { | ||
}, "var"); | ||
const completionRecords = this.get("callee").getCompletionRecords(); | ||
for (const path of completionRecords) { | ||
if (!path.isExpressionStatement()) continue; | ||
const loop = path.findParent(path => path.isLoop()); | ||
if (loop) { | ||
let uid = loop.getData("expressionReplacementReturnUid"); | ||
if (!uid) { | ||
@@ -228,3 +196,2 @@ uid = callee.scope.generateDeclaredUidIdentifier("ret"); | ||
} | ||
path.get("expression").replaceWith(assignmentExpression("=", cloneNode(uid), path.node.expression)); | ||
@@ -240,8 +207,5 @@ } else { | ||
const needToAwaitFunction = isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", FUNCTION_TYPES); | ||
const needToYieldFunction = isParentGenerator && _index.default.hasType(this.get("callee.body").node, "YieldExpression", FUNCTION_TYPES); | ||
if (needToAwaitFunction) { | ||
newCallee.set("async", true); | ||
if (!needToYieldFunction) { | ||
@@ -251,3 +215,2 @@ this.replaceWith(awaitExpression(this.node)); | ||
} | ||
if (needToYieldFunction) { | ||
@@ -257,15 +220,10 @@ newCallee.set("generator", true); | ||
} | ||
return newCallee.get("body.body"); | ||
} | ||
function replaceInline(nodes) { | ||
this.resync(); | ||
if (Array.isArray(nodes)) { | ||
if (Array.isArray(this.container)) { | ||
nodes = this._verifyNodeList(nodes); | ||
const paths = this._containerInsertAfter(nodes); | ||
this.remove(); | ||
@@ -272,0 +230,0 @@ return paths; |
@@ -28,4 +28,4 @@ "use strict"; | ||
this.kind = kind; | ||
if ((kind === "var" || kind === "hoisted") && isDeclaredInLoop(path || (() => { | ||
if ((kind === "var" || kind === "hoisted") && | ||
isDeclaredInLoop(path || (() => { | ||
throw new Error("Internal Babel error: unreachable "); | ||
@@ -35,6 +35,4 @@ })())) { | ||
} | ||
this.clearValue(); | ||
} | ||
deoptValue() { | ||
@@ -44,3 +42,2 @@ this.clearValue(); | ||
} | ||
setValue(value) { | ||
@@ -51,3 +48,2 @@ if (this.hasDeoptedValue) return; | ||
} | ||
clearValue() { | ||
@@ -61,7 +57,5 @@ this.hasDeoptedValue = false; | ||
this.constant = false; | ||
if (this.constantViolations.indexOf(path) !== -1) { | ||
return; | ||
} | ||
this.constantViolations.push(path); | ||
@@ -74,3 +68,2 @@ } | ||
} | ||
this.referenced = true; | ||
@@ -85,7 +78,4 @@ this.references++; | ||
} | ||
} | ||
exports.default = Binding; | ||
function isDeclaredInLoop(path) { | ||
@@ -100,3 +90,2 @@ for (let { | ||
if (parentPath.isFunctionParent()) return false; | ||
if (parentPath.isWhile() || parentPath.isForXStatement() || parentPath.isForStatement() && key === "body") { | ||
@@ -106,3 +95,2 @@ return true; | ||
} | ||
return false; | ||
@@ -109,0 +97,0 @@ } |
@@ -7,15 +7,8 @@ "use strict"; | ||
exports.default = void 0; | ||
var _renamer = require("./lib/renamer"); | ||
var _index = require("../index"); | ||
var _binding = require("./binding"); | ||
var _globals = require("globals"); | ||
var _t = require("@babel/types"); | ||
var _cache = require("../cache"); | ||
const { | ||
@@ -67,3 +60,2 @@ NOT_LOCAL_BINDING, | ||
} = _t; | ||
function gatherNodeParts(node, parts) { | ||
@@ -85,5 +77,3 @@ switch (node == null ? void 0 : node.type) { | ||
} | ||
break; | ||
case "MemberExpression": | ||
@@ -95,3 +85,2 @@ case "OptionalMemberExpression": | ||
break; | ||
case "Identifier": | ||
@@ -101,3 +90,2 @@ case "JSXIdentifier": | ||
break; | ||
case "CallExpression": | ||
@@ -108,3 +96,2 @@ case "OptionalCallExpression": | ||
break; | ||
case "ObjectExpression": | ||
@@ -115,5 +102,3 @@ case "ObjectPattern": | ||
} | ||
break; | ||
case "SpreadElement": | ||
@@ -123,3 +108,2 @@ case "RestElement": | ||
break; | ||
case "ObjectProperty": | ||
@@ -133,19 +117,14 @@ case "ObjectMethod": | ||
break; | ||
case "ThisExpression": | ||
parts.push("this"); | ||
break; | ||
case "Super": | ||
parts.push("super"); | ||
break; | ||
case "Import": | ||
parts.push("import"); | ||
break; | ||
case "DoExpression": | ||
parts.push("do"); | ||
break; | ||
case "YieldExpression": | ||
@@ -155,3 +134,2 @@ parts.push("yield"); | ||
break; | ||
case "AwaitExpression": | ||
@@ -161,11 +139,8 @@ parts.push("await"); | ||
break; | ||
case "AssignmentExpression": | ||
gatherNodeParts(node.left, parts); | ||
break; | ||
case "VariableDeclarator": | ||
gatherNodeParts(node.id, parts); | ||
break; | ||
case "FunctionExpression": | ||
@@ -177,11 +152,8 @@ case "FunctionDeclaration": | ||
break; | ||
case "PrivateName": | ||
gatherNodeParts(node.id, parts); | ||
break; | ||
case "ParenthesizedExpression": | ||
gatherNodeParts(node.expression, parts); | ||
break; | ||
case "UnaryExpression": | ||
@@ -191,3 +163,2 @@ case "UpdateExpression": | ||
break; | ||
case "MetaProperty": | ||
@@ -197,19 +168,14 @@ gatherNodeParts(node.meta, parts); | ||
break; | ||
case "JSXElement": | ||
gatherNodeParts(node.openingElement, parts); | ||
break; | ||
case "JSXOpeningElement": | ||
gatherNodeParts(node.name, parts); | ||
break; | ||
case "JSXFragment": | ||
gatherNodeParts(node.openingFragment, parts); | ||
break; | ||
case "JSXOpeningFragment": | ||
parts.push("Fragment"); | ||
break; | ||
case "JSXNamespacedName": | ||
@@ -225,3 +191,2 @@ gatherNodeParts(node.namespace, parts); | ||
const declar = path.get("init"); | ||
if (declar.isVar()) { | ||
@@ -235,11 +200,12 @@ const { | ||
}, | ||
Declaration(path) { | ||
if (path.isBlockScoped()) return; | ||
if (path.isImportDeclaration()) return; | ||
if (path.isExportDeclaration()) return; | ||
const parent = path.scope.getFunctionParent() || path.scope.getProgramParent(); | ||
parent.registerDeclaration(path); | ||
}, | ||
ImportDeclaration(path) { | ||
@@ -249,13 +215,11 @@ const parent = path.scope.getBlockParent(); | ||
}, | ||
ReferencedIdentifier(path, state) { | ||
state.references.push(path); | ||
}, | ||
ForXStatement(path, state) { | ||
const left = path.get("left"); | ||
if (left.isPattern() || left.isIdentifier()) { | ||
state.constantViolations.push(path); | ||
} else if (left.isVar()) { | ||
} | ||
else if (left.isVar()) { | ||
const { | ||
@@ -268,3 +232,2 @@ scope | ||
}, | ||
ExportDeclaration: { | ||
@@ -278,3 +241,2 @@ exit(path) { | ||
const declar = node.declaration; | ||
if (isClassDeclaration(declar) || isFunctionDeclaration(declar)) { | ||
@@ -294,17 +256,12 @@ const id = declar.id; | ||
} | ||
}, | ||
LabeledStatement(path) { | ||
path.scope.getBlockParent().registerDeclaration(path); | ||
}, | ||
AssignmentExpression(path, state) { | ||
state.assignments.push(path); | ||
}, | ||
UpdateExpression(path, state) { | ||
state.constantViolations.push(path); | ||
}, | ||
UnaryExpression(path, state) { | ||
@@ -315,3 +272,2 @@ if (path.node.operator === "delete") { | ||
}, | ||
BlockScoped(path) { | ||
@@ -329,10 +285,7 @@ let scope = path.scope; | ||
}, | ||
CatchClause(path) { | ||
path.scope.registerBinding("let", path); | ||
}, | ||
Function(path) { | ||
const params = path.get("params"); | ||
for (const param of params) { | ||
@@ -342,16 +295,15 @@ path.scope.registerBinding("param", param); | ||
if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) { | ||
if (path.isFunctionExpression() && path.has("id") && | ||
!path.get("id").node[NOT_LOCAL_BINDING]) { | ||
path.scope.registerBinding("local", path.get("id"), path); | ||
} | ||
}, | ||
ClassExpression(path) { | ||
if (path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) { | ||
if (path.has("id") && | ||
!path.get("id").node[NOT_LOCAL_BINDING]) { | ||
path.scope.registerBinding("local", path); | ||
} | ||
} | ||
}; | ||
let uid = 0; | ||
class Scope { | ||
@@ -373,11 +325,7 @@ constructor(path) { | ||
} = path; | ||
const cached = _cache.scope.get(node); | ||
if ((cached == null ? void 0 : cached.path) === path) { | ||
return cached; | ||
} | ||
_cache.scope.set(node, this); | ||
this.uid = uid++; | ||
@@ -392,6 +340,4 @@ this.block = node; | ||
var _parent; | ||
let parent, | ||
path = this.path; | ||
path = this.path; | ||
do { | ||
@@ -403,14 +349,10 @@ const shouldSkip = path.key === "key" || path.listKey === "decorators"; | ||
} while (path && !parent); | ||
return (_parent = parent) == null ? void 0 : _parent.scope; | ||
} | ||
get parentBlock() { | ||
return this.path.parent; | ||
} | ||
get hub() { | ||
return this.path.hub; | ||
} | ||
traverse(node, opts, state) { | ||
@@ -436,3 +378,2 @@ (0, _index.default)(node, opts, this, state, this.path); | ||
let i = 1; | ||
do { | ||
@@ -442,3 +383,2 @@ uid = this._generateUid(name, i); | ||
} while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid)); | ||
const program = this.getProgramParent(); | ||
@@ -455,3 +395,2 @@ program.references[uid] = true; | ||
} | ||
generateUidBasedOnNode(node, defaultName) { | ||
@@ -473,6 +412,4 @@ const parts = []; | ||
} | ||
if (isIdentifier(node)) { | ||
const binding = this.getBinding(node.name); | ||
if (binding) { | ||
@@ -484,3 +421,2 @@ return binding.constant; | ||
} | ||
return false; | ||
@@ -494,3 +430,2 @@ } | ||
const id = this.generateUidIdentifierBasedOnNode(node); | ||
if (!dontPush) { | ||
@@ -502,12 +437,12 @@ this.push({ | ||
} | ||
return id; | ||
} | ||
} | ||
checkBlockScopedCollisions(local, kind, name, id) { | ||
if (kind === "param") return; | ||
if (local.kind === "local") return; | ||
const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && kind === "const"; | ||
const duplicate = | ||
kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || | ||
local.kind === "param" && kind === "const"; | ||
if (duplicate) { | ||
@@ -517,6 +452,4 @@ throw this.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError); | ||
} | ||
rename(oldName, newName, block) { | ||
const binding = this.getBinding(oldName); | ||
if (binding) { | ||
@@ -534,3 +467,2 @@ newName = newName || this.generateUidIdentifier(oldName).name; | ||
} | ||
dump() { | ||
@@ -540,6 +472,4 @@ const sep = "-".repeat(60); | ||
let scope = this; | ||
do { | ||
console.log("#", scope.block.type); | ||
for (const name of Object.keys(scope.bindings)) { | ||
@@ -555,3 +485,2 @@ const binding = scope.bindings[name]; | ||
} while (scope = scope.parent); | ||
console.log(sep); | ||
@@ -563,3 +492,2 @@ } | ||
const binding = this.getBinding(node.name); | ||
if (binding != null && binding.constant && binding.path.isGenericType("Array")) { | ||
@@ -569,7 +497,5 @@ return node; | ||
} | ||
if (isArrayExpression(node)) { | ||
return node; | ||
} | ||
if (isIdentifier(node, { | ||
@@ -580,6 +506,4 @@ name: "arguments" | ||
} | ||
let helperName; | ||
const args = [node]; | ||
if (i === true) { | ||
@@ -589,2 +513,3 @@ helperName = "toConsumableArray"; | ||
args.push(numericLiteral(i)); | ||
helperName = "slicedToArray"; | ||
@@ -594,3 +519,2 @@ } else { | ||
} | ||
if (arrayLikeIsIterable) { | ||
@@ -603,15 +527,11 @@ args.unshift(this.hub.addHelper(helperName)); | ||
} | ||
hasLabel(name) { | ||
return !!this.getLabel(name); | ||
} | ||
getLabel(name) { | ||
return this.labels.get(name); | ||
} | ||
registerLabel(path) { | ||
this.labels.set(path.node.label.name, path); | ||
} | ||
registerDeclaration(path) { | ||
@@ -627,3 +547,2 @@ if (path.isLabeledStatement()) { | ||
} = path.node; | ||
for (const declar of declarations) { | ||
@@ -637,3 +556,2 @@ this.registerBinding(kind === "using" ? "const" : kind, declar); | ||
const specifiers = path.get("specifiers"); | ||
for (const specifier of specifiers) { | ||
@@ -644,3 +562,2 @@ this.registerBinding("module", specifier); | ||
const declar = path.get("declaration"); | ||
if (declar.isClassDeclaration() || declar.isFunctionDeclaration() || declar.isVariableDeclaration()) { | ||
@@ -653,10 +570,7 @@ this.registerDeclaration(declar); | ||
} | ||
buildUndefinedNode() { | ||
return unaryExpression("void", numericLiteral(0), true); | ||
} | ||
registerConstantViolation(path) { | ||
const ids = path.getBindingIdentifiers(); | ||
for (const name of Object.keys(ids)) { | ||
@@ -667,25 +581,17 @@ const binding = this.getBinding(name); | ||
} | ||
registerBinding(kind, path, bindingPath = path) { | ||
if (!kind) throw new ReferenceError("no `kind`"); | ||
if (path.isVariableDeclaration()) { | ||
const declarators = path.get("declarations"); | ||
for (const declar of declarators) { | ||
this.registerBinding(kind, declar); | ||
} | ||
return; | ||
} | ||
const parent = this.getProgramParent(); | ||
const ids = path.getOuterBindingIdentifiers(true); | ||
for (const name of Object.keys(ids)) { | ||
parent.references[name] = true; | ||
for (const id of ids[name]) { | ||
const local = this.getOwnBinding(name); | ||
if (local) { | ||
@@ -709,31 +615,22 @@ if (local.identifier === id) continue; | ||
} | ||
addGlobal(node) { | ||
this.globals[node.name] = node; | ||
} | ||
hasUid(name) { | ||
let scope = this; | ||
do { | ||
if (scope.uids[name]) return true; | ||
} while (scope = scope.parent); | ||
return false; | ||
} | ||
hasGlobal(name) { | ||
let scope = this; | ||
do { | ||
if (scope.globals[name]) return true; | ||
} while (scope = scope.parent); | ||
return false; | ||
} | ||
hasReference(name) { | ||
return !!this.getProgramParent().references[name]; | ||
} | ||
isPure(node, constantsOnly) { | ||
@@ -749,11 +646,8 @@ if (isIdentifier(node)) { | ||
var _node$decorators; | ||
if (node.superClass && !this.isPure(node.superClass, constantsOnly)) { | ||
return false; | ||
} | ||
if (((_node$decorators = node.decorators) == null ? void 0 : _node$decorators.length) > 0) { | ||
return false; | ||
} | ||
return this.isPure(node.body, constantsOnly); | ||
@@ -764,3 +658,2 @@ } else if (isClassBody(node)) { | ||
} | ||
return true; | ||
@@ -773,3 +666,2 @@ } else if (isBinary(node)) { | ||
} | ||
return true; | ||
@@ -780,23 +672,16 @@ } else if (isObjectExpression(node) || isRecordExpression(node)) { | ||
} | ||
return true; | ||
} else if (isMethod(node)) { | ||
var _node$decorators2; | ||
if (node.computed && !this.isPure(node.key, constantsOnly)) return false; | ||
if (((_node$decorators2 = node.decorators) == null ? void 0 : _node$decorators2.length) > 0) { | ||
return false; | ||
} | ||
return true; | ||
} else if (isProperty(node)) { | ||
var _node$decorators3; | ||
if (node.computed && !this.isPure(node.key, constantsOnly)) return false; | ||
if (((_node$decorators3 = node.decorators) == null ? void 0 : _node$decorators3.length) > 0) { | ||
return false; | ||
} | ||
if (isObjectProperty(node) || node.static) { | ||
@@ -807,3 +692,2 @@ if (node.value !== null && !this.isPure(node.value, constantsOnly)) { | ||
} | ||
return true; | ||
@@ -818,3 +702,2 @@ } else if (isUnaryExpression(node)) { | ||
} | ||
return true; | ||
@@ -832,3 +715,2 @@ } else { | ||
let scope = this; | ||
do { | ||
@@ -842,3 +724,2 @@ const data = scope.data[key]; | ||
let scope = this; | ||
do { | ||
@@ -849,3 +730,2 @@ const data = scope.data[key]; | ||
} | ||
init() { | ||
@@ -857,3 +737,2 @@ if (!this.inited) { | ||
} | ||
crawl() { | ||
@@ -874,3 +753,2 @@ const path = this.path; | ||
this.crawling = true; | ||
if (path.type !== "Program" && collectorVisitor._exploded) { | ||
@@ -880,5 +758,3 @@ for (const visit of collectorVisitor.enter) { | ||
} | ||
const typeVisitors = collectorVisitor[path.type]; | ||
if (typeVisitors) { | ||
@@ -890,3 +766,2 @@ for (const visit of typeVisitors.enter) { | ||
} | ||
path.traverse(collectorVisitor, state); | ||
@@ -897,3 +772,2 @@ this.crawling = false; | ||
const ids = path.getBindingIdentifiers(); | ||
for (const name of Object.keys(ids)) { | ||
@@ -909,3 +783,2 @@ if (path.scope.getBinding(name)) continue; | ||
const binding = ref.scope.getBinding(ref.node.name); | ||
if (binding) { | ||
@@ -922,6 +795,4 @@ binding.reference(ref); | ||
} | ||
push(opts) { | ||
let path = this.path; | ||
if (path.isPattern()) { | ||
@@ -932,7 +803,5 @@ path = this.getPatternParent().path; | ||
} | ||
if (path.isSwitchStatement()) { | ||
path = (this.getFunctionParent() || this.getProgramParent()).path; | ||
} | ||
if (path.isLoop() || path.isCatchClause() || path.isFunction()) { | ||
@@ -942,3 +811,2 @@ path.ensureBlock(); | ||
} | ||
const unique = opts.unique; | ||
@@ -949,3 +817,2 @@ const kind = opts.kind || "var"; | ||
let declarPath = !unique && path.getData(dataKey); | ||
if (!declarPath) { | ||
@@ -957,3 +824,2 @@ const declar = variableDeclaration(kind, []); | ||
} | ||
const declarator = variableDeclarator(opts.id, opts.init); | ||
@@ -966,3 +832,2 @@ const len = declarPath.node.declarations.push(declarator); | ||
let scope = this; | ||
do { | ||
@@ -973,3 +838,2 @@ if (scope.path.isProgram()) { | ||
} while (scope = scope.parent); | ||
throw new Error("Couldn't find a Program"); | ||
@@ -980,3 +844,2 @@ } | ||
let scope = this; | ||
do { | ||
@@ -987,3 +850,2 @@ if (scope.path.isFunctionParent()) { | ||
} while (scope = scope.parent); | ||
return null; | ||
@@ -994,3 +856,2 @@ } | ||
let scope = this; | ||
do { | ||
@@ -1001,3 +862,2 @@ if (scope.path.isBlockParent()) { | ||
} while (scope = scope.parent); | ||
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program..."); | ||
@@ -1008,3 +868,2 @@ } | ||
let scope = this; | ||
do { | ||
@@ -1015,3 +874,2 @@ if (!scope.path.isPattern()) { | ||
} while (scope = scope.parent.parent); | ||
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program..."); | ||
@@ -1023,3 +881,2 @@ } | ||
let scope = this; | ||
do { | ||
@@ -1031,6 +888,4 @@ for (const key of Object.keys(scope.bindings)) { | ||
} | ||
scope = scope.parent; | ||
} while (scope); | ||
return ids; | ||
@@ -1041,6 +896,4 @@ } | ||
const ids = Object.create(null); | ||
for (const kind of kinds) { | ||
let scope = this; | ||
do { | ||
@@ -1051,25 +904,20 @@ for (const name of Object.keys(scope.bindings)) { | ||
} | ||
scope = scope.parent; | ||
} while (scope); | ||
} | ||
return ids; | ||
} | ||
bindingIdentifierEquals(name, node) { | ||
return this.getBindingIdentifier(name) === node; | ||
} | ||
getBinding(name) { | ||
let scope = this; | ||
let previousPath; | ||
do { | ||
const binding = scope.getOwnBinding(name); | ||
if (binding) { | ||
var _previousPath; | ||
if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param" && binding.kind !== "local") {} else { | ||
if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param" && binding.kind !== "local") { | ||
} else { | ||
return binding; | ||
@@ -1080,7 +928,5 @@ } | ||
} | ||
previousPath = scope.path; | ||
} while (scope = scope.parent); | ||
} | ||
getOwnBinding(name) { | ||
@@ -1092,3 +938,2 @@ return this.bindings[name]; | ||
var _this$getBinding; | ||
return (_this$getBinding = this.getBinding(name)) == null ? void 0 : _this$getBinding.identifier; | ||
@@ -1101,7 +946,5 @@ } | ||
} | ||
hasOwnBinding(name) { | ||
return !!this.getOwnBinding(name); | ||
} | ||
hasBinding(name, noGlobals) { | ||
@@ -1116,6 +959,4 @@ if (!name) return false; | ||
} | ||
parentHasBinding(name, noGlobals) { | ||
var _this$parent; | ||
return (_this$parent = this.parent) == null ? void 0 : _this$parent.hasBinding(name, noGlobals); | ||
@@ -1126,3 +967,2 @@ } | ||
const info = this.getBinding(name); | ||
if (info) { | ||
@@ -1134,13 +974,10 @@ info.scope.removeOwnBinding(name); | ||
} | ||
removeOwnBinding(name) { | ||
delete this.bindings[name]; | ||
} | ||
removeBinding(name) { | ||
var _this$getBinding2; | ||
(_this$getBinding2 = this.getBinding(name)) == null ? void 0 : _this$getBinding2.scope.removeOwnBinding(name); | ||
(_this$getBinding2 = this.getBinding(name)) == null ? void 0 : _this$getBinding2.scope.removeOwnBinding(name); | ||
let scope = this; | ||
do { | ||
@@ -1152,5 +989,3 @@ if (scope.uids[name]) { | ||
} | ||
} | ||
exports.default = Scope; | ||
@@ -1157,0 +992,0 @@ Scope.globals = Object.keys(_globals.builtin); |
@@ -7,9 +7,5 @@ "use strict"; | ||
exports.default = void 0; | ||
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration"); | ||
var t = require("@babel/types"); | ||
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor"); | ||
const renameVisitor = { | ||
@@ -23,7 +19,5 @@ ReferencedIdentifier({ | ||
}, | ||
Scope(path, state) { | ||
if (!path.scope.bindingIdentifierEquals(state.oldName, state.binding.identifier)) { | ||
path.skip(); | ||
if (path.isMethod()) { | ||
@@ -34,7 +28,5 @@ (0, _helperEnvironmentVisitor.requeueComputedKeyAndDecorators)(path); | ||
}, | ||
"AssignmentExpression|Declaration|VariableDeclarator"(path, state) { | ||
if (path.isVariableDeclaration()) return; | ||
const ids = path.getOuterBindingIdentifiers(); | ||
for (const name in ids) { | ||
@@ -44,5 +36,3 @@ if (name === state.oldName) ids[name].name = state.newName; | ||
} | ||
}; | ||
class Renamer { | ||
@@ -54,10 +44,7 @@ constructor(binding, oldName, newName) { | ||
} | ||
maybeConvertFromExportDeclaration(parentDeclar) { | ||
const maybeExportDeclar = parentDeclar.parentPath; | ||
if (!maybeExportDeclar.isExportDeclaration()) { | ||
return; | ||
} | ||
if (maybeExportDeclar.isExportDefaultDeclaration()) { | ||
@@ -67,3 +54,2 @@ const { | ||
} = maybeExportDeclar.node; | ||
if (t.isDeclaration(declaration) && !declaration.id) { | ||
@@ -73,12 +59,10 @@ return; | ||
} | ||
if (maybeExportDeclar.isExportAllDeclaration()) { | ||
return; | ||
} | ||
(0, _helperSplitExportDeclaration.default)(maybeExportDeclar); | ||
} | ||
maybeConvertFromClassFunctionDeclaration(path) { | ||
return path; | ||
} | ||
@@ -88,2 +72,3 @@ | ||
return path; | ||
} | ||
@@ -102,6 +87,4 @@ | ||
const parentDeclar = path.find(path => path.isDeclaration() || path.isFunctionExpression() || path.isClassExpression()); | ||
if (parentDeclar) { | ||
const bindingIds = parentDeclar.getOuterBindingIdentifiers(); | ||
if (bindingIds[oldName] === binding.identifier) { | ||
@@ -111,5 +94,3 @@ this.maybeConvertFromExportDeclaration(parentDeclar); | ||
} | ||
const blockToTraverse = block || scope.block; | ||
if ((blockToTraverse == null ? void 0 : blockToTraverse.type) === "SwitchStatement") { | ||
@@ -122,3 +103,2 @@ blockToTraverse.cases.forEach(c => { | ||
} | ||
if (!block) { | ||
@@ -129,3 +109,2 @@ scope.removeOwnBinding(oldName); | ||
} | ||
if (parentDeclar) { | ||
@@ -136,7 +115,5 @@ this.maybeConvertFromClassFunctionDeclaration(path); | ||
} | ||
} | ||
exports.default = Renamer; | ||
//# sourceMappingURL=renamer.js.map |
@@ -7,11 +7,7 @@ "use strict"; | ||
exports.traverseNode = traverseNode; | ||
var _context = require("./context"); | ||
var _t = require("@babel/types"); | ||
const { | ||
VISITOR_KEYS | ||
} = _t; | ||
function traverseNode(node, opts, scope, state, path, skipKeys) { | ||
@@ -21,6 +17,4 @@ const keys = VISITOR_KEYS[node.type]; | ||
const context = new _context.default(scope, opts, state, path); | ||
for (const key of keys) { | ||
if (skipKeys && skipKeys[key]) continue; | ||
if (context.visit(node, key)) { | ||
@@ -30,3 +24,2 @@ return true; | ||
} | ||
return false; | ||
@@ -33,0 +26,0 @@ } |
@@ -9,7 +9,4 @@ "use strict"; | ||
exports.verify = verify; | ||
var virtualTypes = require("./path/lib/virtual-types"); | ||
var _t = require("@babel/types"); | ||
const { | ||
@@ -20,3 +17,2 @@ DEPRECATED_KEYS, | ||
} = _t; | ||
function isVirtualType(type) { | ||
@@ -36,3 +32,2 @@ return type in virtualTypes; | ||
delete visitor[nodeType]; | ||
for (const part of parts) { | ||
@@ -44,4 +39,7 @@ visitor[part] = fns; | ||
verify(visitor); | ||
delete visitor.__esModule; | ||
ensureEntranceObjects(visitor); | ||
ensureCallbackArrays(visitor); | ||
@@ -52,4 +50,4 @@ | ||
if (!isVirtualType(nodeType)) continue; | ||
const fns = visitor[nodeType]; | ||
for (const type of Object.keys(fns)) { | ||
@@ -61,3 +59,2 @@ fns[type] = wrapCheck(nodeType, fns[type]); | ||
const types = virtualTypes[nodeType]; | ||
if (types !== null) { | ||
@@ -81,3 +78,2 @@ for (const type of types) { | ||
const deprecatedKey = DEPRECATED_KEYS[nodeType]; | ||
if (deprecatedKey) { | ||
@@ -87,9 +83,7 @@ console.trace(`Visitor defined for ${nodeType} but it has been renamed to ${deprecatedKey}`); | ||
} | ||
if (!aliases) continue; | ||
if (!aliases) continue; | ||
delete visitor[nodeType]; | ||
for (const alias of aliases) { | ||
const existing = visitor[alias]; | ||
if (existing) { | ||
@@ -102,18 +96,14 @@ mergePair(existing, fns); | ||
} | ||
for (const nodeType of Object.keys(visitor)) { | ||
if (shouldIgnoreKey(nodeType)) continue; | ||
ensureCallbackArrays(visitor[nodeType]); | ||
ensureCallbackArrays( | ||
visitor[nodeType]); | ||
} | ||
return visitor; | ||
} | ||
function verify(visitor) { | ||
if (visitor._verified) return; | ||
if (typeof visitor === "function") { | ||
throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?"); | ||
} | ||
for (const nodeType of Object.keys(visitor)) { | ||
@@ -123,11 +113,7 @@ if (nodeType === "enter" || nodeType === "exit") { | ||
} | ||
if (shouldIgnoreKey(nodeType)) continue; | ||
if (TYPES.indexOf(nodeType) < 0) { | ||
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type`); | ||
} | ||
const visitors = visitor[nodeType]; | ||
if (typeof visitors === "object") { | ||
@@ -143,9 +129,6 @@ for (const visitorKey of Object.keys(visitors)) { | ||
} | ||
visitor._verified = true; | ||
} | ||
function validateVisitorMethods(path, val) { | ||
const fns = [].concat(val); | ||
for (const fn of fns) { | ||
@@ -157,6 +140,4 @@ if (typeof fn !== "function") { | ||
} | ||
function merge(visitors, states = [], wrapper) { | ||
const rootVisitor = {}; | ||
for (let i = 0; i < visitors.length; i++) { | ||
@@ -166,3 +147,2 @@ const visitor = visitors[i]; | ||
explode(visitor); | ||
for (const type of Object.keys(visitor)) { | ||
@@ -179,15 +159,13 @@ let visitorType = visitor[type]; | ||
} | ||
return rootVisitor; | ||
} | ||
function wrapWithStateOrWrapper(oldVisitor, state, wrapper) { | ||
const newVisitor = {}; | ||
for (const key of Object.keys(oldVisitor)) { | ||
let fns = oldVisitor[key]; | ||
if (!Array.isArray(fns)) continue; | ||
fns = fns.map(function (fn) { | ||
let newFn = fn; | ||
if (state) { | ||
@@ -198,3 +176,2 @@ newFn = function (path) { | ||
} | ||
if (wrapper) { | ||
@@ -207,11 +184,9 @@ newFn = wrapper(state.key, key, newFn); | ||
} | ||
return newFn; | ||
}); | ||
newVisitor[key] = fns; | ||
} | ||
return newVisitor; | ||
} | ||
function ensureEntranceObjects(obj) { | ||
@@ -221,3 +196,2 @@ for (const key of Object.keys(obj)) { | ||
const fns = obj[key]; | ||
if (typeof fns === "function") { | ||
@@ -230,3 +204,2 @@ obj[key] = { | ||
} | ||
function ensureCallbackArrays(obj) { | ||
@@ -236,3 +209,2 @@ if (obj.enter && !Array.isArray(obj.enter)) obj.enter = [obj.enter]; | ||
} | ||
function wrapCheck(nodeType, fn) { | ||
@@ -244,19 +216,16 @@ const newFn = function (path) { | ||
}; | ||
newFn.toString = () => fn.toString(); | ||
return newFn; | ||
} | ||
function shouldIgnoreKey(key) { | ||
if (key[0] === "_") return true; | ||
if (key === "enter" || key === "exit" || key === "shouldSkip") return true; | ||
if (key === "denylist" || key === "noScope" || key === "skipKeys" || key === "blacklist") { | ||
if (key === "denylist" || key === "noScope" || key === "skipKeys" || | ||
key === "blacklist") { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function mergePair(dest, src) { | ||
@@ -263,0 +232,0 @@ for (const key of Object.keys(src)) { |
{ | ||
"name": "@babel/traverse", | ||
"version": "7.20.0", | ||
"version": "7.20.1", | ||
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes", | ||
@@ -20,3 +20,3 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
"@babel/code-frame": "^7.18.6", | ||
"@babel/generator": "^7.20.0", | ||
"@babel/generator": "^7.20.1", | ||
"@babel/helper-environment-visitor": "^7.18.9", | ||
@@ -26,3 +26,3 @@ "@babel/helper-function-name": "^7.19.0", | ||
"@babel/helper-split-export-declaration": "^7.18.6", | ||
"@babel/parser": "^7.20.0", | ||
"@babel/parser": "^7.20.1", | ||
"@babel/types": "^7.20.0", | ||
@@ -29,0 +29,0 @@ "debug": "^4.1.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
571169
5052
Updated@babel/generator@^7.20.1
Updated@babel/parser@^7.20.1