@babel/traverse 8.0.0-alpha.6 → 8.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -63,7 +63,7 @@ const {
63
63
  isImportSpecifier,
64
64
  isJSXIdentifier,
65
65
  isJSXMemberExpression,
66
- isMemberExpression,
66
+ isMemberExpression: isMemberExpression$1,
67
67
  isRestElement: nodeIsRestElement,
68
68
  isReferenced: nodeIsReferenced,
69
69
  isScope: nodeIsScope,
@@ -95,7 +95,7 @@ function isReferencedMemberExpression() {
95
95
  node,
96
96
  parent
97
97
  } = this;
98
- return isMemberExpression(node) && nodeIsReferenced(node, parent);
98
+ return isMemberExpression$1(node) && nodeIsReferenced(node, parent);
99
99
  }
100
100
  function isBindingIdentifier() {
101
101
  const {
@@ -632,6 +632,7 @@ const {
632
632
  identifier: identifier$3,
633
633
  isArrayExpression,
634
634
  isBinary,
635
+ isCallExpression: isCallExpression$1,
635
636
  isClass,
636
637
  isClassBody,
637
638
  isClassDeclaration,
@@ -642,6 +643,7 @@ const {
642
643
  isIdentifier: isIdentifier$5,
643
644
  isImportDeclaration,
644
645
  isLiteral: isLiteral$1,
646
+ isMemberExpression,
645
647
  isMethod,
646
648
  isModuleSpecifier,
647
649
  isNullLiteral,
@@ -1230,13 +1232,23 @@ class Scope {
1230
1232
  return true;
1231
1233
  } else if (isUnaryExpression(node)) {
1232
1234
  return this.isPure(node.argument, constantsOnly);
1233
- } else if (isTaggedTemplateExpression(node)) {
1234
- return matchesPattern$1(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly);
1235
1235
  } else if (isTemplateLiteral(node)) {
1236
1236
  for (const expression of node.expressions) {
1237
1237
  if (!this.isPure(expression, constantsOnly)) return false;
1238
1238
  }
1239
1239
  return true;
1240
+ } else if (isTaggedTemplateExpression(node)) {
1241
+ return matchesPattern$1(node.tag, "String.raw") && !this.hasBinding("String", {
1242
+ noGlobals: true
1243
+ }) && this.isPure(node.quasi, constantsOnly);
1244
+ } else if (isMemberExpression(node)) {
1245
+ return !node.computed && isIdentifier$5(node.object) && node.object.name === "Symbol" && isIdentifier$5(node.property) && node.property.name !== "for" && !this.hasBinding("Symbol", {
1246
+ noGlobals: true
1247
+ });
1248
+ } else if (isCallExpression$1(node)) {
1249
+ return matchesPattern$1(node.callee, "Symbol.for") && !this.hasBinding("Symbol", {
1250
+ noGlobals: true
1251
+ }) && node.arguments.length === 1 && _t.isStringLiteral(node.arguments[0]);
1240
1252
  } else {
1241
1253
  return isPureish(node);
1242
1254
  }
@@ -1328,9 +1340,9 @@ class Scope {
1328
1340
  kind = "var",
1329
1341
  id
1330
1342
  } = opts;
1331
- if (!init && !unique && (kind === "var" || kind === "let") && path.isFunction() && !path.node.name && _t.isCallExpression(path.parent, {
1343
+ if (!init && !unique && (kind === "var" || kind === "let") && path.isFunction() && !path.node.name && isCallExpression$1(path.parent, {
1332
1344
  callee: path.node
1333
- }) && path.parent.arguments.length <= path.node.params.length && _t.isIdentifier(id)) {
1345
+ }) && path.parent.arguments.length <= path.node.params.length && isIdentifier$5(id)) {
1334
1346
  path.pushContainer("params", id);
1335
1347
  path.scope.registerBinding("param", path.get("params")[path.node.params.length - 1]);
1336
1348
  return;
@@ -2672,7 +2684,7 @@ function _evaluate(path, state) {
2672
2684
  if (object.isIdentifier() && property.isIdentifier() && isValidObjectCallee(object.node.name) && !isInvalidMethod(property.node.name)) {
2673
2685
  context = global[object.node.name];
2674
2686
  const key = property.node.name;
2675
- if (Object.hasOwnProperty.call(context, key)) {
2687
+ if (Object.hasOwn(context, key)) {
2676
2688
  func = context[key];
2677
2689
  }
2678
2690
  }
@@ -3510,6 +3522,18 @@ function isConstantExpression() {
3510
3522
  } = this.node;
3511
3523
  return operator !== "in" && operator !== "instanceof" && this.get("left").isConstantExpression() && this.get("right").isConstantExpression();
3512
3524
  }
3525
+ if (this.isMemberExpression()) {
3526
+ return !this.node.computed && this.get("object").isIdentifier({
3527
+ name: "Symbol"
3528
+ }) && !this.scope.hasBinding("Symbol", {
3529
+ noGlobals: true
3530
+ });
3531
+ }
3532
+ if (this.isCallExpression()) {
3533
+ return this.node.arguments.length === 1 && this.get("callee").matchesPattern("Symbol.for") && !this.scope.hasBinding("Symbol", {
3534
+ noGlobals: true
3535
+ }) && this.get("arguments")[0].isStringLiteral();
3536
+ }
3513
3537
  return false;
3514
3538
  }
3515
3539
  function isInStrictMode() {
@@ -4850,7 +4874,10 @@ class TraversalContext {
4850
4874
  this.priorityQueue = [];
4851
4875
  const visited = new WeakSet();
4852
4876
  let stop = false;
4853
- for (const path of queue) {
4877
+ let visitIndex = 0;
4878
+ for (; visitIndex < queue.length;) {
4879
+ const path = queue[visitIndex];
4880
+ visitIndex++;
4854
4881
  path.resync();
4855
4882
  if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
4856
4883
  path.pushContext(this);
@@ -4872,8 +4899,8 @@ class TraversalContext {
4872
4899
  if (stop) break;
4873
4900
  }
4874
4901
  }
4875
- for (const path of queue) {
4876
- path.popContext();
4902
+ for (let i = 0; i < visitIndex; i++) {
4903
+ queue[i].popContext();
4877
4904
  }
4878
4905
  this.queue = null;
4879
4906
  return stop;