Skip to content

Commit

Permalink
use hasType
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Jun 14, 2019
1 parent 2cbd4f6 commit 9a99cc3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
18 changes: 0 additions & 18 deletions packages/babel-traverse/src/path/introspection.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,6 @@ export function canSwapBetweenExpressionAndStatement(replacement) {
return false;
}

/**
* Check whether the current path contains an `await` expression
*/

export function containsAwaitExpression(): boolean {
let foundAwait = false;
this.traverse({
Function(path) {
path.skip();
},
AwaitExpression(path) {
foundAwait = true;
path.stop();
},
});
return foundAwait;
}

/**
* Check whether the current path references a completion record
*/
Expand Down
9 changes: 8 additions & 1 deletion packages/babel-traverse/src/path/replacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,14 @@ export function replaceExpressionWithStatements(nodes: Array<Object>) {
callee.arrowFunctionToExpression();

// (() => await xxx)() -> await (async () => await xxx)();
if (isParentAsync && this.get("callee.body").containsAwaitExpression()) {
if (
isParentAsync &&
traverse.hasType(
this.get("callee.body").node,
"AwaitExpression",
t.FUNCTION_TYPES,
)
) {
callee.set("async", true);
this.replaceWith(t.awaitExpression(this.node));
}
Expand Down

0 comments on commit 9a99cc3

Please sign in to comment.