Updating NPM dependencies

This commit is contained in:
Drew Heavner
2020-11-11 13:30:52 +00:00
committed by GitHub
parent 7a6fb66c63
commit bd487ef324
9068 changed files with 1400893 additions and 587661 deletions

View File

@@ -12,15 +12,15 @@ class Binding {
path,
kind
}) {
this.identifier = identifier;
this.scope = scope;
this.path = path;
this.kind = kind;
this.constantViolations = [];
this.constant = true;
this.referencePaths = [];
this.referenced = false;
this.references = 0;
this.identifier = identifier;
this.scope = scope;
this.path = path;
this.kind = kind;
this.clearValue();
}

View File

@@ -5,16 +5,10 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = void 0;
var _includes = _interopRequireDefault(require("lodash/includes"));
var _repeat = _interopRequireDefault(require("lodash/repeat"));
var _renamer = _interopRequireDefault(require("./lib/renamer"));
var _index = _interopRequireDefault(require("../index"));
var _defaults = _interopRequireDefault(require("lodash/defaults"));
var _binding = _interopRequireDefault(require("./binding"));
var _globals = _interopRequireDefault(require("globals"));
@@ -30,37 +24,143 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
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;
}
}
@@ -164,6 +264,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);
}
}
};
@@ -177,7 +299,7 @@ class Scope {
const cached = _cache.scope.get(node);
if (cached && cached.path === path) {
if ((cached == null ? void 0 : cached.path) === path) {
return cached;
}
@@ -187,11 +309,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() {
@@ -221,7 +344,7 @@ class Scope {
generateUid(name = "temp") {
name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
let uid;
let i = 0;
let i = 1;
do {
uid = this._generateUid(name, i);
@@ -240,17 +363,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("$");
@@ -258,8 +371,8 @@ 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) {
@@ -324,7 +437,7 @@ class Scope {
}
dump() {
const sep = (0, _repeat.default)("-", 60);
const sep = "-".repeat(60);
console.log(sep);
let scope = this;
@@ -345,11 +458,11 @@ class Scope {
console.log(sep);
}
toArray(node, i) {
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;
}
}
@@ -376,6 +489,11 @@ class Scope {
helperName = "toArray";
}
if (allowArrayLike) {
args.unshift(this.hub.addHelper(helperName));
helperName = "maybeArrayLike";
}
return t.callExpression(this.hub.addHelper(helperName), args);
}
@@ -451,6 +569,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);
@@ -459,8 +579,6 @@ class Scope {
this.checkBlockScopedCollisions(local, kind, name, id);
}
parent.references[name] = true;
if (local) {
this.registerConstantViolation(bindingPath);
} else {
@@ -500,13 +618,7 @@ 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) {
@@ -541,7 +653,7 @@ class Scope {
}
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;
@@ -586,7 +698,10 @@ class Scope {
}
init() {
if (!this.references) this.crawl();
if (!this.inited) {
this.inited = true;
this.crawl();
}
}
crawl() {
@@ -597,26 +712,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) {
@@ -624,12 +724,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: [],
@@ -641,11 +737,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]);
}
@@ -658,7 +752,7 @@ class Scope {
if (binding) {
binding.reference(ref);
} else {
ref.scope.getProgramParent().addGlobal(ref.node);
programParent.addGlobal(ref.node);
}
}
@@ -742,7 +836,12 @@ class Scope {
let scope = this;
do {
(0, _defaults.default)(ids, scope.bindings);
for (const key of Object.keys(scope.bindings)) {
if (key in ids === false) {
ids[key] = scope.bindings[key];
}
}
scope = scope.parent;
} while (scope);
@@ -780,7 +879,9 @@ class Scope {
const binding = scope.getOwnBinding(name);
if (binding) {
if (previousPath && previousPath.isPattern() && previousPath.parentPath.isFunction() && binding.kind !== "param") {} else {
var _previousPath;
if (((_previousPath = previousPath) == null ? void 0 : _previousPath.isPattern()) && binding.kind !== "param") {} else {
return binding;
}
}
@@ -794,13 +895,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) {
@@ -812,13 +914,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) {
@@ -836,12 +940,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 {

View File

@@ -32,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) {