@babel/traverse 7.17.9 → 7.17.10

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.

Potentially problematic release.


This version of @babel/traverse might be problematic. Click here for more details.

@@ -164,8 +164,8 @@ const Generated = {
164
164
  };
165
165
  exports.Generated = Generated;
166
166
  const Pure = {
167
- checkPath(path, opts) {
168
- return path.scope.isPure(path.node, opts);
167
+ checkPath(path, constantsOnly) {
168
+ return path.scope.isPure(path.node, constantsOnly);
169
169
  }
170
170
 
171
171
  };
@@ -53,7 +53,13 @@ const {
53
53
  toIdentifier,
54
54
  unaryExpression,
55
55
  variableDeclaration,
56
- variableDeclarator
56
+ variableDeclarator,
57
+ isRecordExpression,
58
+ isTupleExpression,
59
+ isObjectProperty,
60
+ isTopicReference,
61
+ isMetaProperty,
62
+ isPrivateName
57
63
  } = _t;
58
64
 
59
65
  function gatherNodeParts(node, parts) {
@@ -430,7 +436,7 @@ class Scope {
430
436
  }
431
437
 
432
438
  isStatic(node) {
433
- if (isThisExpression(node) || isSuper(node)) {
439
+ if (isThisExpression(node) || isSuper(node) || isTopicReference(node)) {
434
440
  return true;
435
441
  }
436
442
 
@@ -682,11 +688,19 @@ class Scope {
682
688
  if (!binding) return false;
683
689
  if (constantsOnly) return binding.constant;
684
690
  return true;
691
+ } else if (isThisExpression(node) || isMetaProperty(node) || isTopicReference(node) || isPrivateName(node)) {
692
+ return true;
685
693
  } else if (isClass(node)) {
694
+ var _node$decorators;
695
+
686
696
  if (node.superClass && !this.isPure(node.superClass, constantsOnly)) {
687
697
  return false;
688
698
  }
689
699
 
700
+ if (((_node$decorators = node.decorators) == null ? void 0 : _node$decorators.length) > 0) {
701
+ return false;
702
+ }
703
+
690
704
  return this.isPure(node.body, constantsOnly);
691
705
  } else if (isClassBody(node)) {
692
706
  for (const method of node.body) {
@@ -696,25 +710,44 @@ class Scope {
696
710
  return true;
697
711
  } else if (isBinary(node)) {
698
712
  return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
699
- } else if (isArrayExpression(node)) {
713
+ } else if (isArrayExpression(node) || isTupleExpression(node)) {
700
714
  for (const elem of node.elements) {
701
- if (!this.isPure(elem, constantsOnly)) return false;
715
+ if (elem !== null && !this.isPure(elem, constantsOnly)) return false;
702
716
  }
703
717
 
704
718
  return true;
705
- } else if (isObjectExpression(node)) {
719
+ } else if (isObjectExpression(node) || isRecordExpression(node)) {
706
720
  for (const prop of node.properties) {
707
721
  if (!this.isPure(prop, constantsOnly)) return false;
708
722
  }
709
723
 
710
724
  return true;
711
725
  } else if (isMethod(node)) {
726
+ var _node$decorators2;
727
+
712
728
  if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
713
- if (node.kind === "get" || node.kind === "set") return false;
729
+
730
+ if (((_node$decorators2 = node.decorators) == null ? void 0 : _node$decorators2.length) > 0) {
731
+ return false;
732
+ }
733
+
714
734
  return true;
715
735
  } else if (isProperty(node)) {
736
+ var _node$decorators3;
737
+
716
738
  if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
717
- return this.isPure(node.value, constantsOnly);
739
+
740
+ if (((_node$decorators3 = node.decorators) == null ? void 0 : _node$decorators3.length) > 0) {
741
+ return false;
742
+ }
743
+
744
+ if (isObjectProperty(node) || node.static) {
745
+ if (node.value !== null && !this.isPure(node.value, constantsOnly)) {
746
+ return false;
747
+ }
748
+ }
749
+
750
+ return true;
718
751
  } else if (isUnaryExpression(node)) {
719
752
  return this.isPure(node.argument, constantsOnly);
720
753
  } else if (isTaggedTemplateExpression(node)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.17.9",
3
+ "version": "7.17.10",
4
4
  "description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
5
5
  "author": "The Babel Team (https://babel.dev/team)",
6
6
  "homepage": "https://babel.dev/docs/en/next/babel-traverse",
@@ -17,13 +17,13 @@
17
17
  "main": "./lib/index.js",
18
18
  "dependencies": {
19
19
  "@babel/code-frame": "^7.16.7",
20
- "@babel/generator": "^7.17.9",
20
+ "@babel/generator": "^7.17.10",
21
21
  "@babel/helper-environment-visitor": "^7.16.7",
22
22
  "@babel/helper-function-name": "^7.17.9",
23
23
  "@babel/helper-hoist-variables": "^7.16.7",
24
24
  "@babel/helper-split-export-declaration": "^7.16.7",
25
- "@babel/parser": "^7.17.9",
26
- "@babel/types": "^7.17.0",
25
+ "@babel/parser": "^7.17.10",
26
+ "@babel/types": "^7.17.10",
27
27
  "debug": "^4.1.0",
28
28
  "globals": "^11.1.0"
29
29
  },
@@ -24,6 +24,8 @@ export interface NodePathValidators {
24
24
  output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
25
25
  } else if (types /* in VirtualTypeAliases */) {
26
26
  output += `is${type}(opts?: object): this is NodePath<VirtualTypeAliases["${type}"]>;`;
27
+ } else if (type === "Pure") {
28
+ output += `isPure(constantsOnly?: boolean): boolean;`;
27
29
  } else {
28
30
  // if it don't have types, then VirtualTypeAliases[type] is t.Node
29
31
  // which TS marked as always true