@babel/traverse 7.17.0 → 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.

@@ -120,7 +120,7 @@ function isStatementOrBlock() {
120
120
 
121
121
  function referencesImport(moduleSource, importName) {
122
122
  if (!this.isReferencedIdentifier()) {
123
- if ((this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? isStringLiteral(this.node.property, {
123
+ if (this.isJSXMemberExpression() && this.node.property.name === importName || (this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? isStringLiteral(this.node.property, {
124
124
  value: importName
125
125
  }) : this.node.property.name === importName)) {
126
126
  const object = this.get("object");
@@ -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
  };
@@ -30,7 +30,13 @@ const {
30
30
  callExpression,
31
31
  cloneNode,
32
32
  expressionStatement,
33
- isExpression
33
+ isAssignmentExpression,
34
+ isCallExpression,
35
+ isExpression,
36
+ isIdentifier,
37
+ isSequenceExpression,
38
+ isSuper,
39
+ thisExpression
34
40
  } = _t;
35
41
 
36
42
  function insertBefore(nodes_) {
@@ -96,9 +102,28 @@ function _containerInsertAfter(nodes) {
96
102
  return this._containerInsert(this.key + 1, nodes);
97
103
  }
98
104
 
105
+ const last = arr => arr[arr.length - 1];
106
+
107
+ function isHiddenInSequenceExpression(path) {
108
+ return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
109
+ }
110
+
111
+ function isAlmostConstantAssignment(node, scope) {
112
+ if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
113
+ return false;
114
+ }
115
+
116
+ const blockScope = scope.getBlockParent();
117
+ return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
118
+ }
119
+
99
120
  function insertAfter(nodes_) {
100
121
  this._assertUnremoved();
101
122
 
123
+ if (this.isSequenceExpression()) {
124
+ return last(this.get("expressions")).insertAfter(nodes_);
125
+ }
126
+
102
127
  const nodes = this._verifyNodeList(nodes_);
103
128
 
104
129
  const {
@@ -123,16 +148,28 @@ function insertAfter(nodes_) {
123
148
  return [this];
124
149
  }
125
150
 
126
- if (parentPath.isMethod({
127
- computed: true,
128
- key: node
129
- })) {
130
- scope = scope.parent;
151
+ if (isHiddenInSequenceExpression(this)) {
152
+ nodes.unshift(node);
153
+ } else if (isCallExpression(node) && isSuper(node.callee)) {
154
+ nodes.unshift(node);
155
+ nodes.push(thisExpression());
156
+ } else if (isAlmostConstantAssignment(node, scope)) {
157
+ nodes.unshift(node);
158
+ nodes.push(cloneNode(node.left));
159
+ } else if (scope.isPure(node, true)) {
160
+ nodes.push(node);
161
+ } else {
162
+ if (parentPath.isMethod({
163
+ computed: true,
164
+ key: node
165
+ })) {
166
+ scope = scope.parent;
167
+ }
168
+
169
+ const temp = scope.generateDeclaredUidIdentifier();
170
+ nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
171
+ nodes.push(expressionStatement(cloneNode(temp)));
131
172
  }
132
-
133
- const temp = scope.generateDeclaredUidIdentifier();
134
- nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
135
- nodes.push(expressionStatement(cloneNode(temp)));
136
173
  }
137
174
 
138
175
  return this.replaceExpressionWithStatements(nodes);
@@ -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)) {
@@ -848,8 +881,8 @@ class Scope {
848
881
  }
849
882
 
850
883
  const declarator = variableDeclarator(opts.id, opts.init);
851
- declarPath.node.declarations.push(declarator);
852
- this.registerBinding(kind, declarPath.get("declarations").pop());
884
+ const len = declarPath.node.declarations.push(declarator);
885
+ path.scope.registerBinding(kind, declarPath.get("declarations")[len - 1]);
853
886
  }
854
887
 
855
888
  getProgramParent() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.17.0",
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.0",
20
+ "@babel/generator": "^7.17.10",
21
21
  "@babel/helper-environment-visitor": "^7.16.7",
22
- "@babel/helper-function-name": "^7.16.7",
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.0",
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