mirror of
https://github.com/actions/labeler
synced 2026-05-10 20:21:01 +02:00
build
This commit is contained in:
440
node_modules/@babel/traverse/lib/scope/index.js
generated
vendored
440
node_modules/@babel/traverse/lib/scope/index.js
generated
vendored
@@ -5,106 +5,170 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
function _includes() {
|
||||
const data = _interopRequireDefault(require("lodash/includes"));
|
||||
|
||||
_includes = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _repeat() {
|
||||
const data = _interopRequireDefault(require("lodash/repeat"));
|
||||
|
||||
_repeat = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _renamer = _interopRequireDefault(require("./lib/renamer"));
|
||||
|
||||
var _index = _interopRequireDefault(require("../index"));
|
||||
|
||||
function _defaults() {
|
||||
const data = _interopRequireDefault(require("lodash/defaults"));
|
||||
|
||||
_defaults = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
var _defaults = _interopRequireDefault(require("lodash/defaults"));
|
||||
|
||||
var _binding = _interopRequireDefault(require("./binding"));
|
||||
|
||||
function _globals() {
|
||||
const data = _interopRequireDefault(require("globals"));
|
||||
var _globals = _interopRequireDefault(require("globals"));
|
||||
|
||||
_globals = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function t() {
|
||||
const data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
var t = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
var _cache = require("../cache");
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function gatherNodeParts(node, parts) {
|
||||
if (t().isModuleDeclaration(node)) {
|
||||
if (node.source) {
|
||||
gatherNodeParts(node.source, parts);
|
||||
} else if (node.specifiers && node.specifiers.length) {
|
||||
for (const specifier of node.specifiers) {
|
||||
gatherNodeParts(specifier, parts);
|
||||
switch (node == null ? void 0 : node.type) {
|
||||
default:
|
||||
if (t.isModuleDeclaration(node)) {
|
||||
if (node.source) {
|
||||
gatherNodeParts(node.source, parts);
|
||||
} else if (node.specifiers && node.specifiers.length) {
|
||||
for (const e of node.specifiers) gatherNodeParts(e, parts);
|
||||
} else if (node.declaration) {
|
||||
gatherNodeParts(node.declaration, parts);
|
||||
}
|
||||
} else if (t.isModuleSpecifier(node)) {
|
||||
gatherNodeParts(node.local, parts);
|
||||
} else if (t.isLiteral(node)) {
|
||||
parts.push(node.value);
|
||||
}
|
||||
} else if (node.declaration) {
|
||||
gatherNodeParts(node.declaration, parts);
|
||||
}
|
||||
} else if (t().isModuleSpecifier(node)) {
|
||||
gatherNodeParts(node.local, parts);
|
||||
} else if (t().isMemberExpression(node)) {
|
||||
gatherNodeParts(node.object, parts);
|
||||
gatherNodeParts(node.property, parts);
|
||||
} else if (t().isIdentifier(node)) {
|
||||
parts.push(node.name);
|
||||
} else if (t().isLiteral(node)) {
|
||||
parts.push(node.value);
|
||||
} else if (t().isCallExpression(node)) {
|
||||
gatherNodeParts(node.callee, parts);
|
||||
} else if (t().isObjectExpression(node) || t().isObjectPattern(node)) {
|
||||
for (const prop of node.properties) {
|
||||
gatherNodeParts(prop.key || prop.argument, parts);
|
||||
}
|
||||
} else if (t().isPrivateName(node)) {
|
||||
gatherNodeParts(node.id, parts);
|
||||
} else if (t().isThisExpression(node)) {
|
||||
parts.push("this");
|
||||
} else if (t().isSuper(node)) {
|
||||
parts.push("super");
|
||||
|
||||
break;
|
||||
|
||||
case "MemberExpression":
|
||||
case "OptionalMemberExpression":
|
||||
case "JSXMemberExpression":
|
||||
gatherNodeParts(node.object, parts);
|
||||
gatherNodeParts(node.property, parts);
|
||||
break;
|
||||
|
||||
case "Identifier":
|
||||
case "JSXIdentifier":
|
||||
parts.push(node.name);
|
||||
break;
|
||||
|
||||
case "CallExpression":
|
||||
case "OptionalCallExpression":
|
||||
case "NewExpression":
|
||||
gatherNodeParts(node.callee, parts);
|
||||
break;
|
||||
|
||||
case "ObjectExpression":
|
||||
case "ObjectPattern":
|
||||
for (const e of node.properties) {
|
||||
gatherNodeParts(e, parts);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "SpreadElement":
|
||||
case "RestElement":
|
||||
gatherNodeParts(node.argument, parts);
|
||||
break;
|
||||
|
||||
case "ObjectProperty":
|
||||
case "ObjectMethod":
|
||||
case "ClassProperty":
|
||||
case "ClassMethod":
|
||||
case "ClassPrivateProperty":
|
||||
case "ClassPrivateMethod":
|
||||
gatherNodeParts(node.key, parts);
|
||||
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":
|
||||
parts.push("yield");
|
||||
gatherNodeParts(node.argument, parts);
|
||||
break;
|
||||
|
||||
case "AwaitExpression":
|
||||
parts.push("await");
|
||||
gatherNodeParts(node.argument, parts);
|
||||
break;
|
||||
|
||||
case "AssignmentExpression":
|
||||
gatherNodeParts(node.left, parts);
|
||||
break;
|
||||
|
||||
case "VariableDeclarator":
|
||||
gatherNodeParts(node.id, parts);
|
||||
break;
|
||||
|
||||
case "FunctionExpression":
|
||||
case "FunctionDeclaration":
|
||||
case "ClassExpression":
|
||||
case "ClassDeclaration":
|
||||
gatherNodeParts(node.id, parts);
|
||||
break;
|
||||
|
||||
case "PrivateName":
|
||||
gatherNodeParts(node.id, parts);
|
||||
break;
|
||||
|
||||
case "ParenthesizedExpression":
|
||||
gatherNodeParts(node.expression, parts);
|
||||
break;
|
||||
|
||||
case "UnaryExpression":
|
||||
case "UpdateExpression":
|
||||
gatherNodeParts(node.argument, parts);
|
||||
break;
|
||||
|
||||
case "MetaProperty":
|
||||
gatherNodeParts(node.meta, parts);
|
||||
gatherNodeParts(node.property, parts);
|
||||
break;
|
||||
|
||||
case "JSXElement":
|
||||
gatherNodeParts(node.openingElement, parts);
|
||||
break;
|
||||
|
||||
case "JSXOpeningElement":
|
||||
parts.push(node.name);
|
||||
break;
|
||||
|
||||
case "JSXFragment":
|
||||
gatherNodeParts(node.openingFragment, parts);
|
||||
break;
|
||||
|
||||
case "JSXOpeningFragment":
|
||||
parts.push("Fragment");
|
||||
break;
|
||||
|
||||
case "JSXNamespacedName":
|
||||
gatherNodeParts(node.namespace, parts);
|
||||
gatherNodeParts(node.name, parts);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const collectorVisitor = {
|
||||
For(path) {
|
||||
for (const key of t().FOR_INIT_KEYS) {
|
||||
for (const key of t.FOR_INIT_KEYS) {
|
||||
const declar = path.get(key);
|
||||
|
||||
if (declar.isVar()) {
|
||||
@@ -145,14 +209,14 @@ const collectorVisitor = {
|
||||
} = path;
|
||||
const declar = node.declaration;
|
||||
|
||||
if (t().isClassDeclaration(declar) || t().isFunctionDeclaration(declar)) {
|
||||
if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) {
|
||||
const id = declar.id;
|
||||
if (!id) return;
|
||||
const binding = scope.getBinding(id.name);
|
||||
if (binding) binding.reference(path);
|
||||
} else if (t().isVariableDeclaration(declar)) {
|
||||
} else if (t.isVariableDeclaration(declar)) {
|
||||
for (const decl of declar.declarations) {
|
||||
for (const name of Object.keys(t().getBindingIdentifiers(decl))) {
|
||||
for (const name of Object.keys(t.getBindingIdentifiers(decl))) {
|
||||
const binding = scope.getBinding(name);
|
||||
if (binding) binding.reference(path);
|
||||
}
|
||||
@@ -184,14 +248,14 @@ const collectorVisitor = {
|
||||
BlockScoped(path) {
|
||||
let scope = path.scope;
|
||||
if (scope.path === path) scope = scope.parent;
|
||||
scope.getBlockParent().registerDeclaration(path);
|
||||
},
|
||||
const parent = scope.getBlockParent();
|
||||
parent.registerDeclaration(path);
|
||||
|
||||
ClassDeclaration(path) {
|
||||
const id = path.node.id;
|
||||
if (!id) return;
|
||||
const name = id.name;
|
||||
path.scope.bindings[name] = path.scope.getBinding(name);
|
||||
if (path.isClassDeclaration() && path.node.id) {
|
||||
const id = path.node.id;
|
||||
const name = id.name;
|
||||
path.scope.bindings[name] = path.scope.parent.getBinding(name);
|
||||
}
|
||||
},
|
||||
|
||||
Block(path) {
|
||||
@@ -202,6 +266,28 @@ const collectorVisitor = {
|
||||
path.scope.getBlockParent().registerDeclaration(bodyPath);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
CatchClause(path) {
|
||||
path.scope.registerBinding("let", path);
|
||||
},
|
||||
|
||||
Function(path) {
|
||||
if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[t.NOT_LOCAL_BINDING]) {
|
||||
path.scope.registerBinding("local", path.get("id"), path);
|
||||
}
|
||||
|
||||
const params = path.get("params");
|
||||
|
||||
for (const param of params) {
|
||||
path.scope.registerBinding("param", param);
|
||||
}
|
||||
},
|
||||
|
||||
ClassExpression(path) {
|
||||
if (path.has("id") && !path.get("id").node[t.NOT_LOCAL_BINDING]) {
|
||||
path.scope.registerBinding("local", path);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@@ -215,7 +301,7 @@ class Scope {
|
||||
|
||||
const cached = _cache.scope.get(node);
|
||||
|
||||
if (cached && cached.path === path) {
|
||||
if ((cached == null ? void 0 : cached.path) === path) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
@@ -225,11 +311,12 @@ class Scope {
|
||||
this.block = node;
|
||||
this.path = path;
|
||||
this.labels = new Map();
|
||||
this.inited = false;
|
||||
}
|
||||
|
||||
get parent() {
|
||||
const parent = this.path.findParent(p => p.isScope());
|
||||
return parent && parent.scope;
|
||||
return parent == null ? void 0 : parent.scope;
|
||||
}
|
||||
|
||||
get parentBlock() {
|
||||
@@ -249,15 +336,15 @@ class Scope {
|
||||
this.push({
|
||||
id
|
||||
});
|
||||
return t().cloneNode(id);
|
||||
return t.cloneNode(id);
|
||||
}
|
||||
|
||||
generateUidIdentifier(name) {
|
||||
return t().identifier(this.generateUid(name));
|
||||
return t.identifier(this.generateUid(name));
|
||||
}
|
||||
|
||||
generateUid(name = "temp") {
|
||||
name = t().toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
|
||||
name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
|
||||
let uid;
|
||||
let i = 0;
|
||||
|
||||
@@ -278,17 +365,7 @@ class Scope {
|
||||
return `_${id}`;
|
||||
}
|
||||
|
||||
generateUidBasedOnNode(parent, defaultName) {
|
||||
let node = parent;
|
||||
|
||||
if (t().isAssignmentExpression(parent)) {
|
||||
node = parent.left;
|
||||
} else if (t().isVariableDeclarator(parent)) {
|
||||
node = parent.id;
|
||||
} else if (t().isObjectProperty(node) || t().isObjectMethod(node)) {
|
||||
node = node.key;
|
||||
}
|
||||
|
||||
generateUidBasedOnNode(node, defaultName) {
|
||||
const parts = [];
|
||||
gatherNodeParts(node, parts);
|
||||
let id = parts.join("$");
|
||||
@@ -296,16 +373,16 @@ class Scope {
|
||||
return this.generateUid(id.slice(0, 20));
|
||||
}
|
||||
|
||||
generateUidIdentifierBasedOnNode(parent, defaultName) {
|
||||
return t().identifier(this.generateUidBasedOnNode(parent, defaultName));
|
||||
generateUidIdentifierBasedOnNode(node, defaultName) {
|
||||
return t.identifier(this.generateUidBasedOnNode(node, defaultName));
|
||||
}
|
||||
|
||||
isStatic(node) {
|
||||
if (t().isThisExpression(node) || t().isSuper(node)) {
|
||||
if (t.isThisExpression(node) || t.isSuper(node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t().isIdentifier(node)) {
|
||||
if (t.isIdentifier(node)) {
|
||||
const binding = this.getBinding(node.name);
|
||||
|
||||
if (binding) {
|
||||
@@ -328,7 +405,7 @@ class Scope {
|
||||
this.push({
|
||||
id
|
||||
});
|
||||
return t().cloneNode(id);
|
||||
return t.cloneNode(id);
|
||||
}
|
||||
|
||||
return id;
|
||||
@@ -362,7 +439,7 @@ class Scope {
|
||||
}
|
||||
|
||||
dump() {
|
||||
const sep = (0, _repeat().default)("-", 60);
|
||||
const sep = "-".repeat(60);
|
||||
console.log(sep);
|
||||
let scope = this;
|
||||
|
||||
@@ -383,23 +460,23 @@ class Scope {
|
||||
console.log(sep);
|
||||
}
|
||||
|
||||
toArray(node, i) {
|
||||
if (t().isIdentifier(node)) {
|
||||
toArray(node, i, allowArrayLike) {
|
||||
if (t.isIdentifier(node)) {
|
||||
const binding = this.getBinding(node.name);
|
||||
|
||||
if (binding && binding.constant && binding.path.isGenericType("Array")) {
|
||||
if ((binding == null ? void 0 : binding.constant) && binding.path.isGenericType("Array")) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
if (t().isArrayExpression(node)) {
|
||||
if (t.isArrayExpression(node)) {
|
||||
return node;
|
||||
}
|
||||
|
||||
if (t().isIdentifier(node, {
|
||||
if (t.isIdentifier(node, {
|
||||
name: "arguments"
|
||||
})) {
|
||||
return t().callExpression(t().memberExpression(t().memberExpression(t().memberExpression(t().identifier("Array"), t().identifier("prototype")), t().identifier("slice")), t().identifier("call")), [node]);
|
||||
return t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Array"), t.identifier("prototype")), t.identifier("slice")), t.identifier("call")), [node]);
|
||||
}
|
||||
|
||||
let helperName;
|
||||
@@ -408,13 +485,18 @@ class Scope {
|
||||
if (i === true) {
|
||||
helperName = "toConsumableArray";
|
||||
} else if (i) {
|
||||
args.push(t().numericLiteral(i));
|
||||
args.push(t.numericLiteral(i));
|
||||
helperName = "slicedToArray";
|
||||
} else {
|
||||
helperName = "toArray";
|
||||
}
|
||||
|
||||
return t().callExpression(this.hub.addHelper(helperName), args);
|
||||
if (allowArrayLike) {
|
||||
args.unshift(this.hub.addHelper(helperName));
|
||||
helperName = "maybeArrayLike";
|
||||
}
|
||||
|
||||
return t.callExpression(this.hub.addHelper(helperName), args);
|
||||
}
|
||||
|
||||
hasLabel(name) {
|
||||
@@ -460,11 +542,7 @@ class Scope {
|
||||
}
|
||||
|
||||
buildUndefinedNode() {
|
||||
if (this.hasBinding("undefined")) {
|
||||
return t().unaryExpression("void", t().numericLiteral(0), true);
|
||||
} else {
|
||||
return t().identifier("undefined");
|
||||
}
|
||||
return t.unaryExpression("void", t.numericLiteral(0), true);
|
||||
}
|
||||
|
||||
registerConstantViolation(path) {
|
||||
@@ -493,6 +571,8 @@ class Scope {
|
||||
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);
|
||||
|
||||
@@ -501,8 +581,6 @@ class Scope {
|
||||
this.checkBlockScopedCollisions(local, kind, name, id);
|
||||
}
|
||||
|
||||
parent.references[name] = true;
|
||||
|
||||
if (local) {
|
||||
this.registerConstantViolation(bindingPath);
|
||||
} else {
|
||||
@@ -542,66 +620,60 @@ class Scope {
|
||||
}
|
||||
|
||||
hasReference(name) {
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
if (scope.references[name]) return true;
|
||||
} while (scope = scope.parent);
|
||||
|
||||
return false;
|
||||
return !!this.getProgramParent().references[name];
|
||||
}
|
||||
|
||||
isPure(node, constantsOnly) {
|
||||
if (t().isIdentifier(node)) {
|
||||
if (t.isIdentifier(node)) {
|
||||
const binding = this.getBinding(node.name);
|
||||
if (!binding) return false;
|
||||
if (constantsOnly) return binding.constant;
|
||||
return true;
|
||||
} else if (t().isClass(node)) {
|
||||
} else if (t.isClass(node)) {
|
||||
if (node.superClass && !this.isPure(node.superClass, constantsOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.isPure(node.body, constantsOnly);
|
||||
} else if (t().isClassBody(node)) {
|
||||
} else if (t.isClassBody(node)) {
|
||||
for (const method of node.body) {
|
||||
if (!this.isPure(method, constantsOnly)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (t().isBinary(node)) {
|
||||
} else if (t.isBinary(node)) {
|
||||
return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
|
||||
} else if (t().isArrayExpression(node)) {
|
||||
} else if (t.isArrayExpression(node)) {
|
||||
for (const elem of node.elements) {
|
||||
if (!this.isPure(elem, constantsOnly)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (t().isObjectExpression(node)) {
|
||||
} else if (t.isObjectExpression(node)) {
|
||||
for (const prop of node.properties) {
|
||||
if (!this.isPure(prop, constantsOnly)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (t().isClassMethod(node)) {
|
||||
} else if (t.isMethod(node)) {
|
||||
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
||||
if (node.kind === "get" || node.kind === "set") return false;
|
||||
return true;
|
||||
} else if (t().isProperty(node)) {
|
||||
} else if (t.isProperty(node)) {
|
||||
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
||||
return this.isPure(node.value, constantsOnly);
|
||||
} else if (t().isUnaryExpression(node)) {
|
||||
} else if (t.isUnaryExpression(node)) {
|
||||
return this.isPure(node.argument, constantsOnly);
|
||||
} else if (t().isTaggedTemplateExpression(node)) {
|
||||
return t().matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
|
||||
} else if (t().isTemplateLiteral(node)) {
|
||||
} else if (t.isTaggedTemplateExpression(node)) {
|
||||
return t.matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
|
||||
} else if (t.isTemplateLiteral(node)) {
|
||||
for (const expression of node.expressions) {
|
||||
if (!this.isPure(expression, constantsOnly)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return t().isPureish(node);
|
||||
return t.isPureish(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -628,7 +700,10 @@ class Scope {
|
||||
}
|
||||
|
||||
init() {
|
||||
if (!this.references) this.crawl();
|
||||
if (!this.inited) {
|
||||
this.inited = true;
|
||||
this.crawl();
|
||||
}
|
||||
}
|
||||
|
||||
crawl() {
|
||||
@@ -639,26 +714,11 @@ class Scope {
|
||||
this.uids = Object.create(null);
|
||||
this.data = Object.create(null);
|
||||
|
||||
if (path.isLoop()) {
|
||||
for (const key of t().FOR_INIT_KEYS) {
|
||||
const node = path.get(key);
|
||||
if (node.isBlockScoped()) this.registerBinding(node.node.kind, node);
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isFunctionExpression() && path.has("id")) {
|
||||
if (!path.get("id").node[t().NOT_LOCAL_BINDING]) {
|
||||
if (path.isFunction()) {
|
||||
if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[t.NOT_LOCAL_BINDING]) {
|
||||
this.registerBinding("local", path.get("id"), path);
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isClassExpression() && path.has("id")) {
|
||||
if (!path.get("id").node[t().NOT_LOCAL_BINDING]) {
|
||||
this.registerBinding("local", path);
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isFunction()) {
|
||||
const params = path.get("params");
|
||||
|
||||
for (const param of params) {
|
||||
@@ -666,12 +726,8 @@ class Scope {
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isCatchClause()) {
|
||||
this.registerBinding("let", path);
|
||||
}
|
||||
|
||||
const parent = this.getProgramParent();
|
||||
if (parent.crawling) return;
|
||||
const programParent = this.getProgramParent();
|
||||
if (programParent.crawling) return;
|
||||
const state = {
|
||||
references: [],
|
||||
constantViolations: [],
|
||||
@@ -683,11 +739,9 @@ class Scope {
|
||||
|
||||
for (const path of state.assignments) {
|
||||
const ids = path.getBindingIdentifiers();
|
||||
let programParent;
|
||||
|
||||
for (const name of Object.keys(ids)) {
|
||||
if (path.scope.getBinding(name)) continue;
|
||||
programParent = programParent || path.scope.getProgramParent();
|
||||
programParent.addGlobal(ids[name]);
|
||||
}
|
||||
|
||||
@@ -700,7 +754,7 @@ class Scope {
|
||||
if (binding) {
|
||||
binding.reference(ref);
|
||||
} else {
|
||||
ref.scope.getProgramParent().addGlobal(ref.node);
|
||||
programParent.addGlobal(ref.node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -732,13 +786,13 @@ class Scope {
|
||||
let declarPath = !unique && path.getData(dataKey);
|
||||
|
||||
if (!declarPath) {
|
||||
const declar = t().variableDeclaration(kind, []);
|
||||
const declar = t.variableDeclaration(kind, []);
|
||||
declar._blockHoist = blockHoist;
|
||||
[declarPath] = path.unshiftContainer("body", [declar]);
|
||||
if (!unique) path.setData(dataKey, declarPath);
|
||||
}
|
||||
|
||||
const declarator = t().variableDeclarator(opts.id, opts.init);
|
||||
const declarator = t.variableDeclarator(opts.id, opts.init);
|
||||
declarPath.node.declarations.push(declarator);
|
||||
this.registerBinding(kind, declarPath.get("declarations").pop());
|
||||
}
|
||||
@@ -784,7 +838,7 @@ class Scope {
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
(0, _defaults().default)(ids, scope.bindings);
|
||||
(0, _defaults.default)(ids, scope.bindings);
|
||||
scope = scope.parent;
|
||||
} while (scope);
|
||||
|
||||
@@ -816,10 +870,18 @@ class Scope {
|
||||
|
||||
getBinding(name) {
|
||||
let scope = this;
|
||||
let previousPath;
|
||||
|
||||
do {
|
||||
const binding = scope.getOwnBinding(name);
|
||||
if (binding) return binding;
|
||||
|
||||
if (binding) {
|
||||
if (previousPath && previousPath.isPattern() && previousPath.parentPath.isFunction() && binding.kind !== "param") {} else {
|
||||
return binding;
|
||||
}
|
||||
}
|
||||
|
||||
previousPath = scope.path;
|
||||
} while (scope = scope.parent);
|
||||
}
|
||||
|
||||
@@ -828,13 +890,14 @@ class Scope {
|
||||
}
|
||||
|
||||
getBindingIdentifier(name) {
|
||||
const info = this.getBinding(name);
|
||||
return info && info.identifier;
|
||||
var _this$getBinding;
|
||||
|
||||
return (_this$getBinding = this.getBinding(name)) == null ? void 0 : _this$getBinding.identifier;
|
||||
}
|
||||
|
||||
getOwnBindingIdentifier(name) {
|
||||
const binding = this.bindings[name];
|
||||
return binding && binding.identifier;
|
||||
return binding == null ? void 0 : binding.identifier;
|
||||
}
|
||||
|
||||
hasOwnBinding(name) {
|
||||
@@ -846,13 +909,15 @@ class Scope {
|
||||
if (this.hasOwnBinding(name)) return true;
|
||||
if (this.parentHasBinding(name, noGlobals)) return true;
|
||||
if (this.hasUid(name)) return true;
|
||||
if (!noGlobals && (0, _includes().default)(Scope.globals, name)) return true;
|
||||
if (!noGlobals && (0, _includes().default)(Scope.contextVariables, name)) return true;
|
||||
if (!noGlobals && Scope.globals.includes(name)) return true;
|
||||
if (!noGlobals && Scope.contextVariables.includes(name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
parentHasBinding(name, noGlobals) {
|
||||
return this.parent && this.parent.hasBinding(name, noGlobals);
|
||||
var _this$parent;
|
||||
|
||||
return (_this$parent = this.parent) == null ? void 0 : _this$parent.hasBinding(name, noGlobals);
|
||||
}
|
||||
|
||||
moveBindingTo(name, scope) {
|
||||
@@ -870,12 +935,9 @@ class Scope {
|
||||
}
|
||||
|
||||
removeBinding(name) {
|
||||
const info = this.getBinding(name);
|
||||
|
||||
if (info) {
|
||||
info.scope.removeOwnBinding(name);
|
||||
}
|
||||
var _this$getBinding2;
|
||||
|
||||
(_this$getBinding2 = this.getBinding(name)) == null ? void 0 : _this$getBinding2.scope.removeOwnBinding(name);
|
||||
let scope = this;
|
||||
|
||||
do {
|
||||
@@ -888,5 +950,5 @@ class Scope {
|
||||
}
|
||||
|
||||
exports.default = Scope;
|
||||
Scope.globals = Object.keys(_globals().default.builtin);
|
||||
Scope.globals = Object.keys(_globals.default.builtin);
|
||||
Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
|
||||
37
node_modules/@babel/traverse/lib/scope/lib/renamer.js
generated
vendored
37
node_modules/@babel/traverse/lib/scope/lib/renamer.js
generated
vendored
@@ -7,27 +7,13 @@ exports.default = void 0;
|
||||
|
||||
var _binding = _interopRequireDefault(require("../binding"));
|
||||
|
||||
function _helperSplitExportDeclaration() {
|
||||
const data = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
|
||||
var _helperSplitExportDeclaration = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
|
||||
|
||||
_helperSplitExportDeclaration = function () {
|
||||
return data;
|
||||
};
|
||||
var t = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
return data;
|
||||
}
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function t() {
|
||||
const data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
@@ -46,7 +32,8 @@ const renameVisitor = {
|
||||
}
|
||||
},
|
||||
|
||||
"AssignmentExpression|Declaration"(path, state) {
|
||||
"AssignmentExpression|Declaration|VariableDeclarator"(path, state) {
|
||||
if (path.isVariableDeclaration()) return;
|
||||
const ids = path.getOuterBindingIdentifiers();
|
||||
|
||||
for (const name in ids) {
|
||||
@@ -74,27 +61,27 @@ class Renamer {
|
||||
return;
|
||||
}
|
||||
|
||||
(0, _helperSplitExportDeclaration().default)(maybeExportDeclar);
|
||||
(0, _helperSplitExportDeclaration.default)(maybeExportDeclar);
|
||||
}
|
||||
|
||||
maybeConvertFromClassFunctionDeclaration(path) {
|
||||
return;
|
||||
if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;
|
||||
if (this.binding.kind !== "hoisted") return;
|
||||
path.node.id = t().identifier(this.oldName);
|
||||
path.node.id = t.identifier(this.oldName);
|
||||
path.node._blockHoist = 3;
|
||||
path.replaceWith(t().variableDeclaration("let", [t().variableDeclarator(t().identifier(this.newName), t().toExpression(path.node))]));
|
||||
path.replaceWith(t.variableDeclaration("let", [t.variableDeclarator(t.identifier(this.newName), t.toExpression(path.node))]));
|
||||
}
|
||||
|
||||
maybeConvertFromClassFunctionExpression(path) {
|
||||
return;
|
||||
if (!path.isFunctionExpression() && !path.isClassExpression()) return;
|
||||
if (this.binding.kind !== "local") return;
|
||||
path.node.id = t().identifier(this.oldName);
|
||||
path.node.id = t.identifier(this.oldName);
|
||||
this.binding.scope.parent.push({
|
||||
id: t().identifier(this.newName)
|
||||
id: t.identifier(this.newName)
|
||||
});
|
||||
path.replaceWith(t().assignmentExpression("=", t().identifier(this.newName), path.node));
|
||||
path.replaceWith(t.assignmentExpression("=", t.identifier(this.newName), path.node));
|
||||
}
|
||||
|
||||
rename(block) {
|
||||
|
||||
Reference in New Issue
Block a user