summaryrefslogtreecommitdiff
path: root/node_modules/@babel/traverse/lib/scope/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@babel/traverse/lib/scope/index.js')
-rw-r--r--node_modules/@babel/traverse/lib/scope/index.js149
1 files changed, 81 insertions, 68 deletions
diff --git a/node_modules/@babel/traverse/lib/scope/index.js b/node_modules/@babel/traverse/lib/scope/index.js
index f0c9748c..ae34a63f 100644
--- a/node_modules/@babel/traverse/lib/scope/index.js
+++ b/node_modules/@babel/traverse/lib/scope/index.js
@@ -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