Skip to content

Commit ae4bb62

Browse files
author
Andy
authored
Merge pull request #9445 from Microsoft/export_default_async_function
Parse `export default async function` as a declaration
2 parents 594ad64 + 4195eb3 commit ae4bb62

File tree

6 files changed

+44
-6
lines changed

6 files changed

+44
-6
lines changed

src/compiler/parser.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,12 +1155,12 @@ namespace ts {
11551155
if (token === SyntaxKind.ExportKeyword) {
11561156
nextToken();
11571157
if (token === SyntaxKind.DefaultKeyword) {
1158-
return lookAhead(nextTokenIsClassOrFunction);
1158+
return lookAhead(nextTokenIsClassOrFunctionOrAsync);
11591159
}
11601160
return token !== SyntaxKind.AsteriskToken && token !== SyntaxKind.AsKeyword && token !== SyntaxKind.OpenBraceToken && canFollowModifier();
11611161
}
11621162
if (token === SyntaxKind.DefaultKeyword) {
1163-
return nextTokenIsClassOrFunction();
1163+
return nextTokenIsClassOrFunctionOrAsync();
11641164
}
11651165
if (token === SyntaxKind.StaticKeyword) {
11661166
nextToken();
@@ -1182,9 +1182,9 @@ namespace ts {
11821182
|| isLiteralPropertyName();
11831183
}
11841184

1185-
function nextTokenIsClassOrFunction(): boolean {
1185+
function nextTokenIsClassOrFunctionOrAsync(): boolean {
11861186
nextToken();
1187-
return token === SyntaxKind.ClassKeyword || token === SyntaxKind.FunctionKeyword;
1187+
return token === SyntaxKind.ClassKeyword || token === SyntaxKind.FunctionKeyword || token === SyntaxKind.AsyncKeyword;
11881188
}
11891189

11901190
// True if positioned at the start of a list element
@@ -5070,7 +5070,7 @@ namespace ts {
50705070
* In such situations, 'permitInvalidConstAsModifier' should be set to true.
50715071
*/
50725072
function parseModifiers(permitInvalidConstAsModifier?: boolean): ModifiersArray {
5073-
let flags = 0;
5073+
let flags: NodeFlags = 0;
50745074
let modifiers: ModifiersArray;
50755075
while (true) {
50765076
const modifierStart = scanner.getStartPos();

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ namespace ts {
469469
}
470470

471471
export interface ModifiersArray extends NodeArray<Modifier> {
472-
flags: number;
472+
flags: NodeFlags;
473473
}
474474

475475
// @kind(SyntaxKind.AbstractKeyword)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [exportDefaultAsyncFunction.ts]
2+
export default async function foo(): Promise<void> {}
3+
foo();
4+
5+
6+
//// [exportDefaultAsyncFunction.js]
7+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8+
return new (P || (P = Promise))(function (resolve, reject) {
9+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10+
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
11+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
12+
step((generator = generator.apply(thisArg, _arguments)).next());
13+
});
14+
};
15+
export default function foo() {
16+
return __awaiter(this, void 0, void 0, function* () { });
17+
}
18+
foo();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/exportDefaultAsyncFunction.ts ===
2+
export default async function foo(): Promise<void> {}
3+
>foo : Symbol(foo, Decl(exportDefaultAsyncFunction.ts, 0, 0))
4+
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
5+
6+
foo();
7+
>foo : Symbol(foo, Decl(exportDefaultAsyncFunction.ts, 0, 0))
8+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/exportDefaultAsyncFunction.ts ===
2+
export default async function foo(): Promise<void> {}
3+
>foo : () => Promise<void>
4+
>Promise : Promise<T>
5+
6+
foo();
7+
>foo() : Promise<void>
8+
>foo : () => Promise<void>
9+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @target: es6
2+
export default async function foo(): Promise<void> {}
3+
foo();

0 commit comments

Comments
 (0)