From af1748dbc3f93094a7e6df1227a093dd6964d9cc Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 5 Jun 2019 15:28:24 +0200 Subject: [PATCH] Fix unintended early return in await inclusion handling. (#2899) * Fix unintended early return in await inclusion handling. * Move to form test --- src/ast/nodes/AwaitExpression.ts | 5 +++-- test/form/samples/handles-async-await/_config.js | 3 +++ test/form/samples/handles-async-await/_expected.js | 6 ++++++ test/form/samples/handles-async-await/main.js | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/form/samples/handles-async-await/_config.js create mode 100644 test/form/samples/handles-async-await/_expected.js create mode 100644 test/form/samples/handles-async-await/main.js 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; +}