@babel/traverse 7.14.5 → 7.15.0

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.

package/lib/context.js CHANGED
@@ -9,8 +9,6 @@ var _path = require("./path");
9
9
 
10
10
  var t = require("@babel/types");
11
11
 
12
- const testing = process.env.NODE_ENV === "test";
13
-
14
12
  class TraversalContext {
15
13
  constructor(scope, opts, state, parentPath) {
16
14
  this.queue = null;
@@ -46,10 +44,6 @@ class TraversalContext {
46
44
  }
47
45
 
48
46
  maybeQueue(path, notPriority) {
49
- if (this.trap) {
50
- throw new Error("Infinite cycle detected");
51
- }
52
-
53
47
  if (this.queue) {
54
48
  if (notPriority) {
55
49
  this.queue.push(path);
@@ -96,11 +90,6 @@ class TraversalContext {
96
90
  }
97
91
 
98
92
  if (path.key === null) continue;
99
-
100
- if (testing && queue.length >= 10000) {
101
- this.trap = true;
102
- }
103
-
104
93
  const {
105
94
  node
106
95
  } = path;
@@ -166,7 +166,15 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
166
166
  }
167
167
 
168
168
  if (argumentsPaths.length > 0) {
169
- const argumentsBinding = getBinding(thisEnvFn, "arguments", () => t.identifier("arguments"));
169
+ const argumentsBinding = getBinding(thisEnvFn, "arguments", () => {
170
+ const args = () => t.identifier("arguments");
171
+
172
+ if (thisEnvFn.scope.path.isProgram()) {
173
+ return t.conditionalExpression(t.binaryExpression("===", t.unaryExpression("typeof", args()), t.stringLiteral("undefined")), thisEnvFn.scope.buildUndefinedNode(), args());
174
+ } else {
175
+ return args();
176
+ }
177
+ });
170
178
  argumentsPaths.forEach(argumentsChild => {
171
179
  const argsRef = t.identifier(argumentsBinding);
172
180
  argsRef.loc = argumentsChild.node.loc;
@@ -398,6 +406,19 @@ function getScopeInformation(fnPath) {
398
406
 
399
407
  ReferencedIdentifier(child) {
400
408
  if (child.node.name !== "arguments") return;
409
+ let curr = child.scope;
410
+
411
+ do {
412
+ if (curr.hasOwnBinding("arguments")) {
413
+ curr.rename("arguments");
414
+ return;
415
+ }
416
+
417
+ if (curr.path.isFunction() && !curr.path.isArrowFunctionExpression()) {
418
+ break;
419
+ }
420
+ } while (curr = curr.parent);
421
+
401
422
  argumentsPaths.push(child);
402
423
  },
403
424
 
@@ -158,7 +158,14 @@ function getStatementListCompletion(paths, context) {
158
158
  }
159
159
  }
160
160
  } else if (paths.length) {
161
- completions = completions.concat(_getCompletionRecords(paths[paths.length - 1], context));
161
+ for (let i = paths.length - 1; i >= 0; i--) {
162
+ const pathCompletions = _getCompletionRecords(paths[i], context);
163
+
164
+ if (pathCompletions.length > 1 || pathCompletions.length === 1 && !pathCompletions[0].path.isVariableDeclaration()) {
165
+ completions = completions.concat(pathCompletions);
166
+ break;
167
+ }
168
+ }
162
169
  }
163
170
 
164
171
  return completions;
@@ -172,11 +172,17 @@ const collectorVisitor = {
172
172
 
173
173
  Declaration(path) {
174
174
  if (path.isBlockScoped()) return;
175
+ if (path.isImportDeclaration()) return;
175
176
  if (path.isExportDeclaration()) return;
176
177
  const parent = path.scope.getFunctionParent() || path.scope.getProgramParent();
177
178
  parent.registerDeclaration(path);
178
179
  },
179
180
 
181
+ ImportDeclaration(path) {
182
+ const parent = path.scope.getBlockParent();
183
+ parent.registerDeclaration(path);
184
+ },
185
+
180
186
  ReferencedIdentifier(path, state) {
181
187
  state.references.push(path);
182
188
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.14.5",
3
+ "version": "7.15.0",
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,12 +17,12 @@
17
17
  "main": "./lib/index.js",
18
18
  "dependencies": {
19
19
  "@babel/code-frame": "^7.14.5",
20
- "@babel/generator": "^7.14.5",
20
+ "@babel/generator": "^7.15.0",
21
21
  "@babel/helper-function-name": "^7.14.5",
22
22
  "@babel/helper-hoist-variables": "^7.14.5",
23
23
  "@babel/helper-split-export-declaration": "^7.14.5",
24
- "@babel/parser": "^7.14.5",
25
- "@babel/types": "^7.14.5",
24
+ "@babel/parser": "^7.15.0",
25
+ "@babel/types": "^7.15.0",
26
26
  "debug": "^4.1.0",
27
27
  "globals": "^11.1.0"
28
28
  },
@@ -9,6 +9,7 @@ export default function generateValidators() {
9
9
  */
10
10
  import * as t from "@babel/types";
11
11
  import NodePath from "../index";
12
+ import type { VirtualTypeAliases } from "./virtual-types";
12
13
 
13
14
  export interface NodePathValidators {
14
15
  `;
@@ -18,10 +19,18 @@ export interface NodePathValidators {
18
19
  }
19
20
 
20
21
  for (const type of Object.keys(virtualTypes)) {
22
+ const { types } = virtualTypes[type];
21
23
  if (type[0] === "_") continue;
22
24
  if (definitions.NODE_FIELDS[type] || definitions.FLIPPED_ALIAS_KEYS[type]) {
23
25
  output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
26
+ } else if (types /* in VirtualTypeAliases */) {
27
+ output += `is${type}(opts?: object): this is NodePath<VirtualTypeAliases["${type}"]>;`;
24
28
  } else {
29
+ // if it don't have types, then VirtualTypeAliases[type] is t.Node
30
+ // which TS marked as always true
31
+ // eg. if (path.isBlockScope()) return;
32
+ // path resolved to `never` here
33
+ // so we have to return boolean instead of this is NodePath<t.Node> here
25
34
  output += `is${type}(opts?: object): boolean;`;
26
35
  }
27
36
  }