From bfbb405c69098e0dd637a0bfa59bb2d16b2468c7 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 5 Jun 2019 15:13:37 +0200 Subject: [PATCH 1/2] Fix unintended early return in await inclusion handling. --- src/ast/nodes/AwaitExpression.ts | 5 +++-- test/function/samples/handles-async-await/_config.js | 8 ++++++++ test/function/samples/handles-async-await/main.js | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/function/samples/handles-async-await/_config.js create mode 100644 test/function/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/function/samples/handles-async-await/_config.js b/test/function/samples/handles-async-await/_config.js new file mode 100644 index 00000000000..576c85cdc63 --- /dev/null +++ b/test/function/samples/handles-async-await/_config.js @@ -0,0 +1,8 @@ +const assert = require('assert'); + +module.exports = { + description: 'properly handles exporting async functions', + exports(exports) { + return exports.callback().then(response => assert.strictEqual(response, 42)); + } +}; diff --git a/test/function/samples/handles-async-await/main.js b/test/function/samples/handles-async-await/main.js new file mode 100644 index 00000000000..8d3c3f5c177 --- /dev/null +++ b/test/function/samples/handles-async-await/main.js @@ -0,0 +1,4 @@ +export async function callback() { + const response = await Promise.resolve(43); + return response - 1; +} From f760d5864dbb0a839d693a78db16bfe49e6aa69e Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 5 Jun 2019 15:25:41 +0200 Subject: [PATCH 2/2] Move to form test --- test/form/samples/handles-async-await/_config.js | 3 +++ test/form/samples/handles-async-await/_expected.js | 6 ++++++ .../samples/handles-async-await/main.js | 0 test/function/samples/handles-async-await/_config.js | 8 -------- 4 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 test/form/samples/handles-async-await/_config.js create mode 100644 test/form/samples/handles-async-await/_expected.js rename test/{function => form}/samples/handles-async-await/main.js (100%) delete mode 100644 test/function/samples/handles-async-await/_config.js 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/function/samples/handles-async-await/main.js b/test/form/samples/handles-async-await/main.js similarity index 100% rename from test/function/samples/handles-async-await/main.js rename to test/form/samples/handles-async-await/main.js diff --git a/test/function/samples/handles-async-await/_config.js b/test/function/samples/handles-async-await/_config.js deleted file mode 100644 index 576c85cdc63..00000000000 --- a/test/function/samples/handles-async-await/_config.js +++ /dev/null @@ -1,8 +0,0 @@ -const assert = require('assert'); - -module.exports = { - description: 'properly handles exporting async functions', - exports(exports) { - return exports.callback().then(response => assert.strictEqual(response, 42)); - } -};