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

@@ -53,7 +53,7 @@ function _call(fns) {
53
53
  const ret = fn.call(this.state, this, this.state);
54
54
 
55
55
  if (ret && typeof ret === "object" && typeof ret.then === "function") {
56
- throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support.` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
56
+ throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
57
57
  }
58
58
 
59
59
  if (ret) {
package/lib/path/index.js CHANGED
@@ -76,7 +76,7 @@ class NodePath {
76
76
  this.parent = parent;
77
77
  this.hub = hub;
78
78
  this.contexts = [];
79
- this.data = {};
79
+ this.data = Object.create(null);
80
80
  this.shouldSkip = false;
81
81
  this.shouldStop = false;
82
82
  this.removed = false;
@@ -149,7 +149,7 @@ class NodePath {
149
149
 
150
150
  getData(key, def) {
151
151
  let val = this.data[key];
152
- if (!val && def) val = this.data[key] = def;
152
+ if (val === undefined && def !== undefined) val = this.data[key] = def;
153
153
  return val;
154
154
  }
155
155
 
@@ -44,7 +44,7 @@ function insertBefore(nodes) {
44
44
 
45
45
  if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
46
46
  return parentPath.insertBefore(nodes);
47
- } else if (this.isNodeType("Expression") && this.listKey !== "params" && this.listKey !== "arguments" || parentPath.isForStatement() && this.key === "init") {
47
+ } else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
48
48
  if (this.node) nodes.push(this.node);
49
49
  return this.replaceExpressionWithStatements(nodes);
50
50
  } else if (Array.isArray(this.container)) {
@@ -196,7 +196,7 @@ function unshiftContainer(listKey, nodes) {
196
196
  key: 0
197
197
  });
198
198
 
199
- return path.insertBefore(nodes);
199
+ return path._containerInsertBefore(nodes);
200
200
  }
201
201
 
202
202
  function pushContainer(listKey, nodes) {
@@ -206,6 +206,8 @@ function replaceExpressionWithStatements(nodes) {
206
206
  return this.replaceWith(toSequenceExpression)[0].get("expressions");
207
207
  }
208
208
 
209
+ const functionParent = this.getFunctionParent();
210
+ const isParentAsync = functionParent && functionParent.is("async");
209
211
  const container = t().arrowFunctionExpression([], t().blockStatement(nodes));
210
212
  this.replaceWith(t().callExpression(container, []));
211
213
  this.traverse(hoistVariablesVisitor);
@@ -235,6 +237,12 @@ function replaceExpressionWithStatements(nodes) {
235
237
 
236
238
  const callee = this.get("callee");
237
239
  callee.arrowFunctionToExpression();
240
+
241
+ if (isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", t().FUNCTION_TYPES)) {
242
+ callee.set("async", true);
243
+ this.replaceWith(t().awaitExpression(this.node));
244
+ }
245
+
238
246
  return callee.get("body.body");
239
247
  }
240
248
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/traverse",
3
- "version": "7.4.0",
3
+ "version": "7.5.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": "Sebastian McKenzie <sebmck@gmail.com>",
6
6
  "homepage": "https://babeljs.io/",
@@ -12,11 +12,11 @@
12
12
  "main": "lib/index.js",
13
13
  "dependencies": {
14
14
  "@babel/code-frame": "^7.0.0",
15
- "@babel/generator": "^7.4.0",
15
+ "@babel/generator": "^7.5.0",
16
16
  "@babel/helper-function-name": "^7.1.0",
17
- "@babel/helper-split-export-declaration": "^7.4.0",
18
- "@babel/parser": "^7.4.0",
19
- "@babel/types": "^7.4.0",
17
+ "@babel/helper-split-export-declaration": "^7.4.4",
18
+ "@babel/parser": "^7.5.0",
19
+ "@babel/types": "^7.5.0",
20
20
  "debug": "^4.1.0",
21
21
  "globals": "^11.1.0",
22
22
  "lodash": "^4.17.11"
@@ -24,5 +24,5 @@
24
24
  "devDependencies": {
25
25
  "@babel/helper-plugin-test-runner": "^7.0.0"
26
26
  },
27
- "gitHead": "f1328fb913b5a93d54dfc6e3728b1f56c8f4a804"
27
+ "gitHead": "49da9a07c81156e997e60146eb001ea77b7044c4"
28
28
  }