diff --git a/src/ast/nodes/AwaitExpression.ts b/src/ast/nodes/AwaitExpression.ts index 2182b597e10..cacaaeb42b8 100644 --- a/src/ast/nodes/AwaitExpression.ts +++ b/src/ast/nodes/AwaitExpression.ts @@ -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; } diff --git a/test/form/samples/handles-async-await/_config.js b/test/form/samples/handles-async-await/_config.js new file mode 100644 index 00000000000..9c17f942ab8 --- /dev/null +++ b/test/form/samples/handles-async-await/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'properly handles exporting async functions' +}; diff --git a/test/form/samples/handles-async-await/_expected.js b/test/form/samples/handles-async-await/_expected.js new file mode 100644 index 00000000000..f4caa8c4de2 --- /dev/null +++ b/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 }; diff --git a/test/form/samples/handles-async-await/main.js b/test/form/samples/handles-async-await/main.js new file mode 100644 index 00000000000..8d3c3f5c177 --- /dev/null +++ b/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; +}