Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unintended early return in await inclusion handling. #2899

Merged
merged 2 commits into from Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}