committed by
GitHub
parent
20d2b4f98d
commit
e4f3964f67
8
node_modules/@babel/traverse/lib/context.js
generated
vendored
8
node_modules/@babel/traverse/lib/context.js
generated
vendored
@ -31,17 +31,19 @@ class TraversalContext {
|
||||
if (!(keys != null && keys.length)) return false;
|
||||
|
||||
for (const key of keys) {
|
||||
if (node[key]) return true;
|
||||
if (node[key]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
create(node, obj, key, listKey) {
|
||||
create(node, container, key, listKey) {
|
||||
return _path.default.get({
|
||||
parentPath: this.parentPath,
|
||||
parent: node,
|
||||
container: obj,
|
||||
container,
|
||||
key: key,
|
||||
listKey
|
||||
});
|
||||
|
11
node_modules/@babel/traverse/lib/path/context.js
generated
vendored
11
node_modules/@babel/traverse/lib/path/context.js
generated
vendored
@ -129,7 +129,11 @@ function stop() {
|
||||
function setScope() {
|
||||
if (this.opts && this.opts.noScope) return;
|
||||
let path = this.parentPath;
|
||||
if (this.key === "key" && path.isMethod()) path = path.parentPath;
|
||||
|
||||
if ((this.key === "key" || this.listKey === "decorators") && path.isMethod()) {
|
||||
path = path.parentPath;
|
||||
}
|
||||
|
||||
let target;
|
||||
|
||||
while (path && !target) {
|
||||
@ -177,7 +181,10 @@ function _resyncParent() {
|
||||
|
||||
function _resyncKey() {
|
||||
if (!this.container) return;
|
||||
if (this.node === this.container[this.key]) return;
|
||||
|
||||
if (this.node === this.container[this.key]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Array.isArray(this.container)) {
|
||||
for (let i = 0; i < this.container.length; i++) {
|
||||
|
13
node_modules/@babel/traverse/lib/path/conversion.js
generated
vendored
13
node_modules/@babel/traverse/lib/path/conversion.js
generated
vendored
@ -251,10 +251,11 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
|
||||
const flatSuperProps = superProps.reduce((acc, superProp) => acc.concat(standardizeSuperProperty(superProp)), []);
|
||||
flatSuperProps.forEach(superProp => {
|
||||
const key = superProp.node.computed ? "" : superProp.get("property").node.name;
|
||||
const isAssignment = superProp.parentPath.isAssignmentExpression({
|
||||
const superParentPath = superProp.parentPath;
|
||||
const isAssignment = superParentPath.isAssignmentExpression({
|
||||
left: superProp.node
|
||||
});
|
||||
const isCall = superProp.parentPath.isCallExpression({
|
||||
const isCall = superParentPath.isCallExpression({
|
||||
callee: superProp.node
|
||||
});
|
||||
const superBinding = getSuperPropBinding(thisEnvFn, isAssignment, key);
|
||||
@ -265,18 +266,18 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
|
||||
}
|
||||
|
||||
if (isAssignment) {
|
||||
const value = superProp.parentPath.node.right;
|
||||
const value = superParentPath.node.right;
|
||||
args.push(value);
|
||||
}
|
||||
|
||||
const call = callExpression(identifier(superBinding), args);
|
||||
|
||||
if (isCall) {
|
||||
superProp.parentPath.unshiftContainer("arguments", thisExpression());
|
||||
superParentPath.unshiftContainer("arguments", thisExpression());
|
||||
superProp.replaceWith(memberExpression(call, identifier("call")));
|
||||
thisPaths.push(superProp.parentPath.get("arguments.0"));
|
||||
thisPaths.push(superParentPath.get("arguments.0"));
|
||||
} else if (isAssignment) {
|
||||
superProp.parentPath.replaceWith(call);
|
||||
superParentPath.replaceWith(call);
|
||||
} else {
|
||||
superProp.replaceWith(call);
|
||||
}
|
||||
|
12
node_modules/@babel/traverse/lib/path/evaluation.js
generated
vendored
12
node_modules/@babel/traverse/lib/path/evaluation.js
generated
vendored
@ -8,6 +8,14 @@ exports.evaluateTruthy = evaluateTruthy;
|
||||
const VALID_CALLEES = ["String", "Number", "Math"];
|
||||
const INVALID_METHODS = ["random"];
|
||||
|
||||
function isValidCallee(val) {
|
||||
return VALID_CALLEES.includes(val);
|
||||
}
|
||||
|
||||
function isInvalidMethod(val) {
|
||||
return INVALID_METHODS.includes(val);
|
||||
}
|
||||
|
||||
function evaluateTruthy() {
|
||||
const res = this.evaluate();
|
||||
if (res.confident) return !!res.value;
|
||||
@ -336,7 +344,7 @@ function _evaluate(path, state) {
|
||||
let context;
|
||||
let func;
|
||||
|
||||
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && VALID_CALLEES.indexOf(callee.node.name) >= 0) {
|
||||
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name) && isValidCallee(callee.node.name)) {
|
||||
func = global[callee.node.name];
|
||||
}
|
||||
|
||||
@ -344,7 +352,7 @@ function _evaluate(path, state) {
|
||||
const object = callee.get("object");
|
||||
const property = callee.get("property");
|
||||
|
||||
if (object.isIdentifier() && property.isIdentifier() && VALID_CALLEES.indexOf(object.node.name) >= 0 && INVALID_METHODS.indexOf(property.node.name) < 0) {
|
||||
if (object.isIdentifier() && property.isIdentifier() && isValidCallee(object.node.name) && !isInvalidMethod(property.node.name)) {
|
||||
context = global[object.node.name];
|
||||
func = context[property.node.name];
|
||||
}
|
||||
|
7
node_modules/@babel/traverse/lib/path/index.js
generated
vendored
7
node_modules/@babel/traverse/lib/path/index.js
generated
vendored
@ -135,6 +135,10 @@ class NodePath {
|
||||
return val;
|
||||
}
|
||||
|
||||
hasNode() {
|
||||
return this.node != null;
|
||||
}
|
||||
|
||||
buildCodeFrameError(msg, Error = SyntaxError) {
|
||||
return this.hub.buildError(this.node, msg, Error);
|
||||
}
|
||||
@ -223,6 +227,9 @@ class NodePath {
|
||||
}
|
||||
|
||||
Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
|
||||
{
|
||||
NodePath.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
|
||||
}
|
||||
|
||||
for (const type of t.TYPES) {
|
||||
const typeKey = `is${type}`;
|
||||
|
12
node_modules/@babel/traverse/lib/path/inference/index.js
generated
vendored
12
node_modules/@babel/traverse/lib/path/inference/index.js
generated
vendored
@ -33,10 +33,16 @@ const {
|
||||
} = _t;
|
||||
|
||||
function getTypeAnnotation() {
|
||||
if (this.typeAnnotation) return this.typeAnnotation;
|
||||
let type = this._getTypeAnnotation() || anyTypeAnnotation();
|
||||
let type = this.getData("typeAnnotation");
|
||||
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
|
||||
type = this._getTypeAnnotation() || anyTypeAnnotation();
|
||||
if (isTypeAnnotation(type)) type = type.typeAnnotation;
|
||||
return this.typeAnnotation = type;
|
||||
this.setData("typeAnnotation", type);
|
||||
return type;
|
||||
}
|
||||
|
||||
const typeAnnotationInferringNodes = new WeakSet();
|
||||
|
2
node_modules/@babel/traverse/lib/path/inference/inferer-reference.js
generated
vendored
2
node_modules/@babel/traverse/lib/path/inference/inferer-reference.js
generated
vendored
@ -202,5 +202,5 @@ function getConditionalAnnotation(binding, path, name) {
|
||||
};
|
||||
}
|
||||
|
||||
return getConditionalAnnotation(ifStatement, name);
|
||||
return getConditionalAnnotation(binding, ifStatement, name);
|
||||
}
|
2
node_modules/@babel/traverse/lib/path/inference/inferers.js
generated
vendored
2
node_modules/@babel/traverse/lib/path/inference/inferers.js
generated
vendored
@ -87,7 +87,7 @@ function TypeCastExpression(node) {
|
||||
TypeCastExpression.validParent = true;
|
||||
|
||||
function NewExpression(node) {
|
||||
if (this.get("callee").isIdentifier()) {
|
||||
if (node.callee.type === "Identifier") {
|
||||
return genericTypeAnnotation(node.callee);
|
||||
}
|
||||
}
|
||||
|
59
node_modules/@babel/traverse/lib/path/introspection.js
generated
vendored
59
node_modules/@babel/traverse/lib/path/introspection.js
generated
vendored
@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports._guessExecutionStatusRelativeTo = _guessExecutionStatusRelativeTo;
|
||||
exports._guessExecutionStatusRelativeToDifferentFunctions = _guessExecutionStatusRelativeToDifferentFunctions;
|
||||
exports._resolve = _resolve;
|
||||
exports.canHaveVariableDeclarationOrExpression = canHaveVariableDeclarationOrExpression;
|
||||
exports.canSwapBetweenExpressionAndStatement = canSwapBetweenExpressionAndStatement;
|
||||
@ -94,9 +93,12 @@ function isCompletionRecord(allowInsideFunction) {
|
||||
let first = true;
|
||||
|
||||
do {
|
||||
const container = path.container;
|
||||
const {
|
||||
type,
|
||||
container
|
||||
} = path;
|
||||
|
||||
if (path.isFunction() && !first) {
|
||||
if (!first && (path.isFunction() || type === "StaticBlock")) {
|
||||
return !!allowInsideFunction;
|
||||
}
|
||||
|
||||
@ -105,7 +107,7 @@ function isCompletionRecord(allowInsideFunction) {
|
||||
if (Array.isArray(container) && path.key !== container.length - 1) {
|
||||
return false;
|
||||
}
|
||||
} while ((path = path.parentPath) && !path.isProgram());
|
||||
} while ((path = path.parentPath) && !path.isProgram() && !path.isDoExpression());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -120,7 +122,7 @@ function isStatementOrBlock() {
|
||||
|
||||
function referencesImport(moduleSource, importName) {
|
||||
if (!this.isReferencedIdentifier()) {
|
||||
if ((this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? isStringLiteral(this.node.property, {
|
||||
if (this.isJSXMemberExpression() && this.node.property.name === importName || (this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? isStringLiteral(this.node.property, {
|
||||
value: importName
|
||||
}) : this.node.property.name === importName)) {
|
||||
const object = this.get("object");
|
||||
@ -229,20 +231,24 @@ function isExecutionUncertainInList(paths, maxIndex) {
|
||||
}
|
||||
|
||||
function _guessExecutionStatusRelativeTo(target) {
|
||||
return _guessExecutionStatusRelativeToCached(this, target, new Map());
|
||||
}
|
||||
|
||||
function _guessExecutionStatusRelativeToCached(base, target, cache) {
|
||||
const funcParent = {
|
||||
this: getOuterFunction(this),
|
||||
this: getOuterFunction(base),
|
||||
target: getOuterFunction(target)
|
||||
};
|
||||
|
||||
if (funcParent.target.node !== funcParent.this.node) {
|
||||
return this._guessExecutionStatusRelativeToDifferentFunctions(funcParent.target);
|
||||
return _guessExecutionStatusRelativeToDifferentFunctionsCached(base, funcParent.target, cache);
|
||||
}
|
||||
|
||||
const paths = {
|
||||
target: target.getAncestry(),
|
||||
this: this.getAncestry()
|
||||
this: base.getAncestry()
|
||||
};
|
||||
if (paths.target.indexOf(this) >= 0) return "after";
|
||||
if (paths.target.indexOf(base) >= 0) return "after";
|
||||
if (paths.this.indexOf(target) >= 0) return "before";
|
||||
let commonPath;
|
||||
const commonIndex = {
|
||||
@ -286,9 +292,9 @@ function _guessExecutionStatusRelativeTo(target) {
|
||||
return keyPosition.target > keyPosition.this ? "before" : "after";
|
||||
}
|
||||
|
||||
const executionOrderCheckedNodes = new WeakSet();
|
||||
const executionOrderCheckedNodes = new Set();
|
||||
|
||||
function _guessExecutionStatusRelativeToDifferentFunctions(target) {
|
||||
function _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache) {
|
||||
if (!target.isFunctionDeclaration() || target.parentPath.isExportDeclaration()) {
|
||||
return "unknown";
|
||||
}
|
||||
@ -309,20 +315,37 @@ function _guessExecutionStatusRelativeToDifferentFunctions(target) {
|
||||
if (executionOrderCheckedNodes.has(path.node)) continue;
|
||||
executionOrderCheckedNodes.add(path.node);
|
||||
|
||||
const status = this._guessExecutionStatusRelativeTo(path);
|
||||
try {
|
||||
const status = _guessExecutionStatusRelativeToCached(base, path, cache);
|
||||
|
||||
executionOrderCheckedNodes.delete(path.node);
|
||||
|
||||
if (allStatus && allStatus !== status) {
|
||||
return "unknown";
|
||||
} else {
|
||||
allStatus = status;
|
||||
if (allStatus && allStatus !== status) {
|
||||
return "unknown";
|
||||
} else {
|
||||
allStatus = status;
|
||||
}
|
||||
} finally {
|
||||
executionOrderCheckedNodes.delete(path.node);
|
||||
}
|
||||
}
|
||||
|
||||
return allStatus;
|
||||
}
|
||||
|
||||
function _guessExecutionStatusRelativeToDifferentFunctionsCached(base, target, cache) {
|
||||
let nodeMap = cache.get(base.node);
|
||||
|
||||
if (!nodeMap) {
|
||||
cache.set(base.node, nodeMap = new Map());
|
||||
} else if (nodeMap.has(target.node)) {
|
||||
return nodeMap.get(target.node);
|
||||
}
|
||||
|
||||
const result = _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache);
|
||||
|
||||
nodeMap.set(target.node, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
function resolve(dangerous, resolved) {
|
||||
return this._resolve(dangerous, resolved) || this;
|
||||
}
|
||||
|
3
node_modules/@babel/traverse/lib/path/lib/removal-hooks.js
generated
vendored
3
node_modules/@babel/traverse/lib/path/lib/removal-hooks.js
generated
vendored
@ -4,6 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.hooks = void 0;
|
||||
|
||||
var _ = require("..");
|
||||
|
||||
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();
|
||||
|
||||
|
4
node_modules/@babel/traverse/lib/path/lib/virtual-types.js
generated
vendored
4
node_modules/@babel/traverse/lib/path/lib/virtual-types.js
generated
vendored
@ -164,8 +164,8 @@ const Generated = {
|
||||
};
|
||||
exports.Generated = Generated;
|
||||
const Pure = {
|
||||
checkPath(path, opts) {
|
||||
return path.scope.isPure(path.node, opts);
|
||||
checkPath(path, constantsOnly) {
|
||||
return path.scope.isPure(path.node, constantsOnly);
|
||||
}
|
||||
|
||||
};
|
||||
|
57
node_modules/@babel/traverse/lib/path/modification.js
generated
vendored
57
node_modules/@babel/traverse/lib/path/modification.js
generated
vendored
@ -30,7 +30,13 @@ const {
|
||||
callExpression,
|
||||
cloneNode,
|
||||
expressionStatement,
|
||||
isExpression
|
||||
isAssignmentExpression,
|
||||
isCallExpression,
|
||||
isExpression,
|
||||
isIdentifier,
|
||||
isSequenceExpression,
|
||||
isSuper,
|
||||
thisExpression
|
||||
} = _t;
|
||||
|
||||
function insertBefore(nodes_) {
|
||||
@ -96,9 +102,28 @@ 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) {
|
||||
if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const blockScope = scope.getBlockParent();
|
||||
return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
|
||||
}
|
||||
|
||||
function insertAfter(nodes_) {
|
||||
this._assertUnremoved();
|
||||
|
||||
if (this.isSequenceExpression()) {
|
||||
return last(this.get("expressions")).insertAfter(nodes_);
|
||||
}
|
||||
|
||||
const nodes = this._verifyNodeList(nodes_);
|
||||
|
||||
const {
|
||||
@ -123,16 +148,28 @@ function insertAfter(nodes_) {
|
||||
return [this];
|
||||
}
|
||||
|
||||
if (parentPath.isMethod({
|
||||
computed: true,
|
||||
key: node
|
||||
})) {
|
||||
scope = scope.parent;
|
||||
}
|
||||
if (isHiddenInSequenceExpression(this)) {
|
||||
nodes.unshift(node);
|
||||
} else if (isCallExpression(node) && isSuper(node.callee)) {
|
||||
nodes.unshift(node);
|
||||
nodes.push(thisExpression());
|
||||
} else if (isAlmostConstantAssignment(node, scope)) {
|
||||
nodes.unshift(node);
|
||||
nodes.push(cloneNode(node.left));
|
||||
} else if (scope.isPure(node, true)) {
|
||||
nodes.push(node);
|
||||
} else {
|
||||
if (parentPath.isMethod({
|
||||
computed: true,
|
||||
key: node
|
||||
})) {
|
||||
scope = scope.parent;
|
||||
}
|
||||
|
||||
const temp = scope.generateDeclaredUidIdentifier();
|
||||
nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
|
||||
nodes.push(expressionStatement(cloneNode(temp)));
|
||||
const temp = scope.generateDeclaredUidIdentifier();
|
||||
nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
|
||||
nodes.push(expressionStatement(cloneNode(temp)));
|
||||
}
|
||||
}
|
||||
|
||||
return this.replaceExpressionWithStatements(nodes);
|
||||
|
15
node_modules/@babel/traverse/lib/path/replacement.js
generated
vendored
15
node_modules/@babel/traverse/lib/path/replacement.js
generated
vendored
@ -69,10 +69,11 @@ function replaceWithMultiple(nodes) {
|
||||
|
||||
function replaceWithSourceString(replacement) {
|
||||
this.resync();
|
||||
let ast;
|
||||
|
||||
try {
|
||||
replacement = `(${replacement})`;
|
||||
replacement = (0, _parser.parse)(replacement);
|
||||
ast = (0, _parser.parse)(replacement);
|
||||
} catch (err) {
|
||||
const loc = err.loc;
|
||||
|
||||
@ -89,23 +90,21 @@ function replaceWithSourceString(replacement) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
replacement = replacement.program.body[0].expression;
|
||||
const expressionAST = ast.program.body[0].expression;
|
||||
|
||||
_index.default.removeProperties(replacement);
|
||||
_index.default.removeProperties(expressionAST);
|
||||
|
||||
return this.replaceWith(replacement);
|
||||
return this.replaceWith(expressionAST);
|
||||
}
|
||||
|
||||
function replaceWith(replacement) {
|
||||
function replaceWith(replacementPath) {
|
||||
this.resync();
|
||||
|
||||
if (this.removed) {
|
||||
throw new Error("You can't replace this node, we've already removed it");
|
||||
}
|
||||
|
||||
if (replacement instanceof _index2.default) {
|
||||
replacement = replacement.node;
|
||||
}
|
||||
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");
|
||||
|
77
node_modules/@babel/traverse/lib/scope/index.js
generated
vendored
77
node_modules/@babel/traverse/lib/scope/index.js
generated
vendored
@ -38,9 +38,11 @@ const {
|
||||
isMethod,
|
||||
isModuleDeclaration,
|
||||
isModuleSpecifier,
|
||||
isNullLiteral,
|
||||
isObjectExpression,
|
||||
isProperty,
|
||||
isPureish,
|
||||
isRegExpLiteral,
|
||||
isSuper,
|
||||
isTaggedTemplateExpression,
|
||||
isTemplateLiteral,
|
||||
@ -53,7 +55,13 @@ const {
|
||||
toIdentifier,
|
||||
unaryExpression,
|
||||
variableDeclaration,
|
||||
variableDeclarator
|
||||
variableDeclarator,
|
||||
isRecordExpression,
|
||||
isTupleExpression,
|
||||
isObjectProperty,
|
||||
isTopicReference,
|
||||
isMetaProperty,
|
||||
isPrivateName
|
||||
} = _t;
|
||||
|
||||
function gatherNodeParts(node, parts) {
|
||||
@ -69,7 +77,7 @@ function gatherNodeParts(node, parts) {
|
||||
}
|
||||
} else if (isModuleSpecifier(node)) {
|
||||
gatherNodeParts(node.local, parts);
|
||||
} else if (isLiteral(node)) {
|
||||
} else if (isLiteral(node) && !isNullLiteral(node) && !isRegExpLiteral(node) && !isTemplateLiteral(node)) {
|
||||
parts.push(node.value);
|
||||
}
|
||||
|
||||
@ -179,7 +187,7 @@ function gatherNodeParts(node, parts) {
|
||||
break;
|
||||
|
||||
case "JSXOpeningElement":
|
||||
parts.push(node.name);
|
||||
gatherNodeParts(node.name, parts);
|
||||
break;
|
||||
|
||||
case "JSXFragment":
|
||||
@ -362,9 +370,9 @@ class Scope {
|
||||
path = this.path;
|
||||
|
||||
do {
|
||||
const isKey = path.key === "key";
|
||||
const shouldSkip = path.key === "key" || path.listKey === "decorators";
|
||||
path = path.parentPath;
|
||||
if (isKey && path.isMethod()) path = path.parentPath;
|
||||
if (shouldSkip && path.isMethod()) path = path.parentPath;
|
||||
if (path && path.isScope()) parent = path;
|
||||
} while (path && !parent);
|
||||
|
||||
@ -430,7 +438,7 @@ class Scope {
|
||||
}
|
||||
|
||||
isStatic(node) {
|
||||
if (isThisExpression(node) || isSuper(node)) {
|
||||
if (isThisExpression(node) || isSuper(node) || isTopicReference(node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -682,11 +690,19 @@ class Scope {
|
||||
if (!binding) return false;
|
||||
if (constantsOnly) return binding.constant;
|
||||
return true;
|
||||
} else if (isThisExpression(node) || isMetaProperty(node) || isTopicReference(node) || isPrivateName(node)) {
|
||||
return true;
|
||||
} else if (isClass(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);
|
||||
} else if (isClassBody(node)) {
|
||||
for (const method of node.body) {
|
||||
@ -696,25 +712,44 @@ class Scope {
|
||||
return true;
|
||||
} else if (isBinary(node)) {
|
||||
return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
|
||||
} else if (isArrayExpression(node)) {
|
||||
} else if (isArrayExpression(node) || isTupleExpression(node)) {
|
||||
for (const elem of node.elements) {
|
||||
if (!this.isPure(elem, constantsOnly)) return false;
|
||||
if (elem !== null && !this.isPure(elem, constantsOnly)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (isObjectExpression(node)) {
|
||||
} else if (isObjectExpression(node) || isRecordExpression(node)) {
|
||||
for (const prop of node.properties) {
|
||||
if (!this.isPure(prop, constantsOnly)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (isMethod(node)) {
|
||||
var _node$decorators2;
|
||||
|
||||
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
||||
if (node.kind === "get" || node.kind === "set") 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;
|
||||
return this.isPure(node.value, constantsOnly);
|
||||
|
||||
if (((_node$decorators3 = node.decorators) == null ? void 0 : _node$decorators3.length) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isObjectProperty(node) || node.static) {
|
||||
if (node.value !== null && !this.isPure(node.value, constantsOnly)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (isUnaryExpression(node)) {
|
||||
return this.isPure(node.argument, constantsOnly);
|
||||
} else if (isTaggedTemplateExpression(node)) {
|
||||
@ -821,7 +856,9 @@ class Scope {
|
||||
push(opts) {
|
||||
let path = this.path;
|
||||
|
||||
if (!path.isBlockStatement() && !path.isProgram()) {
|
||||
if (path.isPattern()) {
|
||||
path = this.getPatternParent().path;
|
||||
} else if (!path.isBlockStatement() && !path.isProgram()) {
|
||||
path = this.getBlockParent().path;
|
||||
}
|
||||
|
||||
@ -848,8 +885,8 @@ class Scope {
|
||||
}
|
||||
|
||||
const declarator = variableDeclarator(opts.id, opts.init);
|
||||
declarPath.node.declarations.push(declarator);
|
||||
this.registerBinding(kind, declarPath.get("declarations").pop());
|
||||
const len = declarPath.node.declarations.push(declarator);
|
||||
path.scope.registerBinding(kind, declarPath.get("declarations")[len - 1]);
|
||||
}
|
||||
|
||||
getProgramParent() {
|
||||
@ -888,6 +925,18 @@ class Scope {
|
||||
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
|
||||
}
|
||||
|
||||
getPatternParent() {
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
if (!scope.path.isPattern()) {
|
||||
return scope.getBlockParent();
|
||||
}
|
||||
} while (scope = scope.parent.parent);
|
||||
|
||||
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
|
||||
}
|
||||
|
||||
getAllBindings() {
|
||||
const ids = Object.create(null);
|
||||
let scope = this;
|
||||
|
65
node_modules/@babel/traverse/lib/scope/lib/renamer.js
generated
vendored
65
node_modules/@babel/traverse/lib/scope/lib/renamer.js
generated
vendored
@ -9,16 +9,10 @@ var _binding = require("../binding");
|
||||
|
||||
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
|
||||
|
||||
var _t = require("@babel/types");
|
||||
var t = require("@babel/types");
|
||||
|
||||
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
|
||||
|
||||
const {
|
||||
VISITOR_KEYS,
|
||||
assignmentExpression,
|
||||
identifier,
|
||||
toExpression,
|
||||
variableDeclaration,
|
||||
variableDeclarator
|
||||
} = _t;
|
||||
const renameVisitor = {
|
||||
ReferencedIdentifier({
|
||||
node
|
||||
@ -30,7 +24,11 @@ const renameVisitor = {
|
||||
|
||||
Scope(path, state) {
|
||||
if (!path.scope.bindingIdentifierEquals(state.oldName, state.binding.identifier)) {
|
||||
skipAllButComputedMethodKey(path);
|
||||
path.skip();
|
||||
|
||||
if (path.isMethod()) {
|
||||
(0, _helperEnvironmentVisitor.requeueComputedKeyAndDecorators)(path);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -59,7 +57,17 @@ class Renamer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (maybeExportDeclar.isExportDefaultDeclaration() && !maybeExportDeclar.get("declaration").node.id) {
|
||||
if (maybeExportDeclar.isExportDefaultDeclaration()) {
|
||||
const {
|
||||
declaration
|
||||
} = maybeExportDeclar.node;
|
||||
|
||||
if (t.isDeclaration(declaration) && !declaration.id) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (maybeExportDeclar.isExportAllDeclaration()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -67,23 +75,11 @@ class Renamer {
|
||||
}
|
||||
|
||||
maybeConvertFromClassFunctionDeclaration(path) {
|
||||
return;
|
||||
if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;
|
||||
if (this.binding.kind !== "hoisted") return;
|
||||
path.node.id = identifier(this.oldName);
|
||||
path.node._blockHoist = 3;
|
||||
path.replaceWith(variableDeclaration("let", [variableDeclarator(identifier(this.newName), toExpression(path.node))]));
|
||||
return path;
|
||||
}
|
||||
|
||||
maybeConvertFromClassFunctionExpression(path) {
|
||||
return;
|
||||
if (!path.isFunctionExpression() && !path.isClassExpression()) return;
|
||||
if (this.binding.kind !== "local") return;
|
||||
path.node.id = identifier(this.oldName);
|
||||
this.binding.scope.parent.push({
|
||||
id: identifier(this.newName)
|
||||
});
|
||||
path.replaceWith(assignmentExpression("=", identifier(this.newName), path.node));
|
||||
return path;
|
||||
}
|
||||
|
||||
rename(block) {
|
||||
@ -123,24 +119,11 @@ class Renamer {
|
||||
}
|
||||
|
||||
if (parentDeclar) {
|
||||
this.maybeConvertFromClassFunctionDeclaration(parentDeclar);
|
||||
this.maybeConvertFromClassFunctionExpression(parentDeclar);
|
||||
this.maybeConvertFromClassFunctionDeclaration(path);
|
||||
this.maybeConvertFromClassFunctionExpression(path);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = Renamer;
|
||||
|
||||
function skipAllButComputedMethodKey(path) {
|
||||
if (!path.isMethod() || !path.node.computed) {
|
||||
path.skip();
|
||||
return;
|
||||
}
|
||||
|
||||
const keys = VISITOR_KEYS[path.type];
|
||||
|
||||
for (const key of keys) {
|
||||
if (key !== "key") path.skipKey(key);
|
||||
}
|
||||
}
|
||||
exports.default = Renamer;
|
Reference in New Issue
Block a user