@babel/traverse 7.14.2 → 7.14.5

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.

@@ -22,33 +22,7 @@ var _parser = require("@babel/parser");
22
22
 
23
23
  var t = require("@babel/types");
24
24
 
25
- const hoistVariablesVisitor = {
26
- Function(path) {
27
- path.skip();
28
- },
29
-
30
- VariableDeclaration(path) {
31
- if (path.node.kind !== "var") return;
32
- const bindings = path.getBindingIdentifiers();
33
-
34
- for (const key of Object.keys(bindings)) {
35
- path.scope.push({
36
- id: bindings[key]
37
- });
38
- }
39
-
40
- const exprs = [];
41
-
42
- for (const declar of path.node.declarations) {
43
- if (declar.init) {
44
- exprs.push(t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init)));
45
- }
46
- }
47
-
48
- path.replaceWithMultiple(exprs);
49
- }
50
-
51
- };
25
+ var _helperHoistVariables = require("@babel/helper-hoist-variables");
52
26
 
53
27
  function replaceWithMultiple(nodes) {
54
28
  var _pathCache$get;
@@ -191,7 +165,12 @@ function replaceExpressionWithStatements(nodes) {
191
165
  const isParentGenerator = functionParent == null ? void 0 : functionParent.is("generator");
192
166
  const container = t.arrowFunctionExpression([], t.blockStatement(nodes));
193
167
  this.replaceWith(t.callExpression(container, []));
194
- this.traverse(hoistVariablesVisitor);
168
+ const callee = this.get("callee");
169
+ (0, _helperHoistVariables.default)(callee.get("body"), id => {
170
+ this.scope.push({
171
+ id
172
+ });
173
+ }, "var");
195
174
  const completionRecords = this.get("callee").getCompletionRecords();
196
175
 
197
176
  for (const path of completionRecords) {
@@ -202,7 +181,6 @@ function replaceExpressionWithStatements(nodes) {
202
181
  let uid = loop.getData("expressionReplacementReturnUid");
203
182
 
204
183
  if (!uid) {
205
- const callee = this.get("callee");
206
184
  uid = callee.scope.generateDeclaredUidIdentifier("ret");
207
185
  callee.get("body").pushContainer("body", t.returnStatement(t.cloneNode(uid)));
208
186
  loop.setData("expressionReplacementReturnUid", uid);
@@ -216,15 +194,15 @@ function replaceExpressionWithStatements(nodes) {
216
194
  }
217
195
  }
218
196
 
219
- const callee = this.get("callee");
220
197
  callee.arrowFunctionToExpression();
198
+ const newCallee = callee;
221
199
 
222
200
  const needToAwaitFunction = isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", t.FUNCTION_TYPES);
223
201
 
224
202
  const needToYieldFunction = isParentGenerator && _index.default.hasType(this.get("callee.body").node, "YieldExpression", t.FUNCTION_TYPES);
225
203
 
226
204
  if (needToAwaitFunction) {
227
- callee.set("async", true);
205
+ newCallee.set("async", true);
228
206
 
229
207
  if (!needToYieldFunction) {
230
208
  this.replaceWith(t.awaitExpression(this.node));
@@ -232,11 +210,11 @@ function replaceExpressionWithStatements(nodes) {
232
210
  }
233
211
 
234
212
  if (needToYieldFunction) {
235
- callee.set("generator", true);
213
+ newCallee.set("generator", true);
236
214
  this.replaceWith(t.yieldExpression(this.node, true));
237
215
  }
238
216
 
239
- return callee.get("body.body");
217
+ return newCallee.get("body.body");
240
218
  }
241
219
 
242
220
  function replaceInline(nodes) {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.14.2",
3
+ "version": "7.14.5",
4
4
  "description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
5
- "author": "Sebastian McKenzie <sebmck@gmail.com>",
5
+ "author": "The Babel Team (https://babel.dev/team)",
6
6
  "homepage": "https://babel.dev/docs/en/next/babel-traverse",
7
7
  "bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20traverse%22+is%3Aopen",
8
8
  "license": "MIT",
@@ -14,18 +14,22 @@
14
14
  "url": "https://github.com/babel/babel.git",
15
15
  "directory": "packages/babel-traverse"
16
16
  },
17
- "main": "lib/index.js",
17
+ "main": "./lib/index.js",
18
18
  "dependencies": {
19
- "@babel/code-frame": "^7.12.13",
20
- "@babel/generator": "^7.14.2",
21
- "@babel/helper-function-name": "^7.14.2",
22
- "@babel/helper-split-export-declaration": "^7.12.13",
23
- "@babel/parser": "^7.14.2",
24
- "@babel/types": "^7.14.2",
19
+ "@babel/code-frame": "^7.14.5",
20
+ "@babel/generator": "^7.14.5",
21
+ "@babel/helper-function-name": "^7.14.5",
22
+ "@babel/helper-hoist-variables": "^7.14.5",
23
+ "@babel/helper-split-export-declaration": "^7.14.5",
24
+ "@babel/parser": "^7.14.5",
25
+ "@babel/types": "^7.14.5",
25
26
  "debug": "^4.1.0",
26
27
  "globals": "^11.1.0"
27
28
  },
28
29
  "devDependencies": {
29
- "@babel/helper-plugin-test-runner": "7.13.10"
30
+ "@babel/helper-plugin-test-runner": "7.14.5"
31
+ },
32
+ "engines": {
33
+ "node": ">=6.9.0"
30
34
  }
31
35
  }