Skip to content

Commit

Permalink
Fix unintended early return in await inclusion handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 5, 2019
1 parent 71f2fa8 commit bfbb405
Show file tree
Hide file tree
Showing 3 changed files with 15 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
8 changes: 8 additions & 0 deletions 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));
}
};
4 changes: 4 additions & 0 deletions 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;
}

0 comments on commit bfbb405

Please sign in to comment.