Skip to content

Commit

Permalink
Fix unintended early return in await inclusion handling. (#2899)
Browse files Browse the repository at this point in the history
* Fix unintended early return in await inclusion handling.

* Move to form test
  • Loading branch information
lukastaegert committed Jun 5, 2019
1 parent 71f2fa8 commit af1748d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ast/nodes/AwaitExpression.ts
Expand Up @@ -15,10 +15,11 @@ export default class AwaitExpression extends NodeBase {
}

include(includeChildrenRecursively: IncludeChildren) {
if (!this.included && !this.context.usesTopLevelAwait) {
checkTopLevelAwait: if (!this.included && !this.context.usesTopLevelAwait) {
let parent = this.parent;
do {
if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression) return;
if (parent instanceof FunctionNode || parent instanceof ArrowFunctionExpression)
break checkTopLevelAwait;
} while ((parent = (parent as Node).parent as Node));
this.context.usesTopLevelAwait = true;
}
Expand Down
3 changes: 3 additions & 0 deletions test/form/samples/handles-async-await/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'properly handles exporting async functions'
};
6 changes: 6 additions & 0 deletions test/form/samples/handles-async-await/_expected.js
@@ -0,0 +1,6 @@
async function callback() {
const response = await Promise.resolve(43);
return response - 1;
}

export { callback };
4 changes: 4 additions & 0 deletions test/form/samples/handles-async-await/main.js
@@ -0,0 +1,4 @@
export async function callback() {
const response = await Promise.resolve(43);
return response - 1;
}

0 comments on commit af1748d

Please sign in to comment.