feat: refactoring project
This commit is contained in:
153
node_modules/@babel/traverse/lib/scope/index.js
generated
vendored
153
node_modules/@babel/traverse/lib/scope/index.js
generated
vendored
@@ -271,12 +271,12 @@ const collectorVisitor = {
|
||||
for (const param of params) {
|
||||
path.scope.registerBinding("param", param);
|
||||
}
|
||||
if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
|
||||
if (path.isFunctionExpression() && path.node.id && !path.node.id[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.node.id && !path.node.id[NOT_LOCAL_BINDING]) {
|
||||
path.scope.registerBinding("local", path.get("id"), path);
|
||||
}
|
||||
},
|
||||
@@ -290,8 +290,8 @@ class Scope {
|
||||
this.uid = void 0;
|
||||
this.path = void 0;
|
||||
this.block = void 0;
|
||||
this.labels = void 0;
|
||||
this.inited = void 0;
|
||||
this.labels = void 0;
|
||||
this.bindings = void 0;
|
||||
this.references = void 0;
|
||||
this.globals = void 0;
|
||||
@@ -325,15 +325,6 @@ class Scope {
|
||||
} 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) {
|
||||
(0, _index.default)(node, opts, this, state, this.path);
|
||||
}
|
||||
generateDeclaredUidIdentifier(name) {
|
||||
const id = this.generateUidIdentifier(name);
|
||||
this.push({
|
||||
@@ -349,7 +340,8 @@ class Scope {
|
||||
let uid;
|
||||
let i = 1;
|
||||
do {
|
||||
uid = this._generateUid(name, i);
|
||||
uid = `_${name}`;
|
||||
if (i > 1) uid += i;
|
||||
i++;
|
||||
} while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid));
|
||||
const program = this.getProgramParent();
|
||||
@@ -357,11 +349,6 @@ class Scope {
|
||||
program.uids[uid] = true;
|
||||
return uid;
|
||||
}
|
||||
_generateUid(name, i) {
|
||||
let id = name;
|
||||
if (i > 1) id += i;
|
||||
return `_${id}`;
|
||||
}
|
||||
generateUidBasedOnNode(node, defaultName) {
|
||||
const parts = [];
|
||||
gatherNodeParts(node, parts);
|
||||
@@ -405,7 +392,7 @@ class Scope {
|
||||
if (local.kind === "local") return;
|
||||
const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && kind === "const";
|
||||
if (duplicate) {
|
||||
throw this.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);
|
||||
throw this.path.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);
|
||||
}
|
||||
}
|
||||
rename(oldName, newName) {
|
||||
@@ -418,12 +405,6 @@ class Scope {
|
||||
}
|
||||
}
|
||||
}
|
||||
_renameFromMap(map, oldName, newName, value) {
|
||||
if (map[oldName]) {
|
||||
map[newName] = value;
|
||||
map[oldName] = null;
|
||||
}
|
||||
}
|
||||
dump() {
|
||||
const sep = "-".repeat(60);
|
||||
console.log(sep);
|
||||
@@ -442,37 +423,6 @@ class Scope {
|
||||
} while (scope = scope.parent);
|
||||
console.log(sep);
|
||||
}
|
||||
toArray(node, i, arrayLikeIsIterable) {
|
||||
if (isIdentifier(node)) {
|
||||
const binding = this.getBinding(node.name);
|
||||
if (binding != null && binding.constant && binding.path.isGenericType("Array")) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
if (isArrayExpression(node)) {
|
||||
return node;
|
||||
}
|
||||
if (isIdentifier(node, {
|
||||
name: "arguments"
|
||||
})) {
|
||||
return callExpression(memberExpression(memberExpression(memberExpression(identifier("Array"), identifier("prototype")), identifier("slice")), identifier("call")), [node]);
|
||||
}
|
||||
let helperName;
|
||||
const args = [node];
|
||||
if (i === true) {
|
||||
helperName = "toConsumableArray";
|
||||
} else if (typeof i === "number") {
|
||||
args.push(numericLiteral(i));
|
||||
helperName = "slicedToArray";
|
||||
} else {
|
||||
helperName = "toArray";
|
||||
}
|
||||
if (arrayLikeIsIterable) {
|
||||
args.unshift(this.hub.addHelper(helperName));
|
||||
helperName = "maybeArrayLike";
|
||||
}
|
||||
return callExpression(this.hub.addHelper(helperName), args);
|
||||
}
|
||||
hasLabel(name) {
|
||||
return !!this.getLabel(name);
|
||||
}
|
||||
@@ -812,20 +762,6 @@ class Scope {
|
||||
} while (scope);
|
||||
return ids;
|
||||
}
|
||||
getAllBindingsOfKind(...kinds) {
|
||||
const ids = Object.create(null);
|
||||
for (const kind of kinds) {
|
||||
let scope = this;
|
||||
do {
|
||||
for (const name of Object.keys(scope.bindings)) {
|
||||
const binding = scope.bindings[name];
|
||||
if (binding.kind === kind) ids[name] = binding;
|
||||
}
|
||||
scope = scope.parent;
|
||||
} while (scope);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
bindingIdentifierEquals(name, node) {
|
||||
return this.getBindingIdentifier(name) === node;
|
||||
}
|
||||
@@ -958,5 +894,82 @@ class Scope {
|
||||
exports.default = Scope;
|
||||
Scope.globals = Object.keys(_globals.builtin);
|
||||
Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
|
||||
{
|
||||
Scope.prototype._renameFromMap = function _renameFromMap(map, oldName, newName, value) {
|
||||
if (map[oldName]) {
|
||||
map[newName] = value;
|
||||
map[oldName] = null;
|
||||
}
|
||||
};
|
||||
Scope.prototype.traverse = function (node, opts, state) {
|
||||
(0, _index.default)(node, opts, this, state, this.path);
|
||||
};
|
||||
Scope.prototype._generateUid = function _generateUid(name, i) {
|
||||
let id = name;
|
||||
if (i > 1) id += i;
|
||||
return `_${id}`;
|
||||
};
|
||||
Scope.prototype.toArray = function toArray(node, i, arrayLikeIsIterable) {
|
||||
if (isIdentifier(node)) {
|
||||
const binding = this.getBinding(node.name);
|
||||
if (binding != null && binding.constant && binding.path.isGenericType("Array")) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
if (isArrayExpression(node)) {
|
||||
return node;
|
||||
}
|
||||
if (isIdentifier(node, {
|
||||
name: "arguments"
|
||||
})) {
|
||||
return callExpression(memberExpression(memberExpression(memberExpression(identifier("Array"), identifier("prototype")), identifier("slice")), identifier("call")), [node]);
|
||||
}
|
||||
let helperName;
|
||||
const args = [node];
|
||||
if (i === true) {
|
||||
helperName = "toConsumableArray";
|
||||
} else if (typeof i === "number") {
|
||||
args.push(numericLiteral(i));
|
||||
helperName = "slicedToArray";
|
||||
} else {
|
||||
helperName = "toArray";
|
||||
}
|
||||
if (arrayLikeIsIterable) {
|
||||
args.unshift(this.path.hub.addHelper(helperName));
|
||||
helperName = "maybeArrayLike";
|
||||
}
|
||||
return callExpression(this.path.hub.addHelper(helperName), args);
|
||||
};
|
||||
Scope.prototype.getAllBindingsOfKind = function getAllBindingsOfKind(...kinds) {
|
||||
const ids = Object.create(null);
|
||||
for (const kind of kinds) {
|
||||
let scope = this;
|
||||
do {
|
||||
for (const name of Object.keys(scope.bindings)) {
|
||||
const binding = scope.bindings[name];
|
||||
if (binding.kind === kind) ids[name] = binding;
|
||||
}
|
||||
scope = scope.parent;
|
||||
} while (scope);
|
||||
}
|
||||
return ids;
|
||||
};
|
||||
Object.defineProperties(Scope.prototype, {
|
||||
parentBlock: {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return this.path.parent;
|
||||
}
|
||||
},
|
||||
hub: {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
return this.path.hub;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
|
||||
Reference in New Issue
Block a user