mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #9445 from Microsoft/export_default_async_function
Parse `export default async function` as a declaration
This commit is contained in:
@@ -1155,12 +1155,12 @@ namespace ts {
|
||||
if (token === SyntaxKind.ExportKeyword) {
|
||||
nextToken();
|
||||
if (token === SyntaxKind.DefaultKeyword) {
|
||||
return lookAhead(nextTokenIsClassOrFunction);
|
||||
return lookAhead(nextTokenIsClassOrFunctionOrAsync);
|
||||
}
|
||||
return token !== SyntaxKind.AsteriskToken && token !== SyntaxKind.AsKeyword && token !== SyntaxKind.OpenBraceToken && canFollowModifier();
|
||||
}
|
||||
if (token === SyntaxKind.DefaultKeyword) {
|
||||
return nextTokenIsClassOrFunction();
|
||||
return nextTokenIsClassOrFunctionOrAsync();
|
||||
}
|
||||
if (token === SyntaxKind.StaticKeyword) {
|
||||
nextToken();
|
||||
@@ -1182,9 +1182,9 @@ namespace ts {
|
||||
|| isLiteralPropertyName();
|
||||
}
|
||||
|
||||
function nextTokenIsClassOrFunction(): boolean {
|
||||
function nextTokenIsClassOrFunctionOrAsync(): boolean {
|
||||
nextToken();
|
||||
return token === SyntaxKind.ClassKeyword || token === SyntaxKind.FunctionKeyword;
|
||||
return token === SyntaxKind.ClassKeyword || token === SyntaxKind.FunctionKeyword || token === SyntaxKind.AsyncKeyword;
|
||||
}
|
||||
|
||||
// True if positioned at the start of a list element
|
||||
@@ -5070,7 +5070,7 @@ namespace ts {
|
||||
* In such situations, 'permitInvalidConstAsModifier' should be set to true.
|
||||
*/
|
||||
function parseModifiers(permitInvalidConstAsModifier?: boolean): ModifiersArray {
|
||||
let flags = 0;
|
||||
let flags: NodeFlags = 0;
|
||||
let modifiers: ModifiersArray;
|
||||
while (true) {
|
||||
const modifierStart = scanner.getStartPos();
|
||||
|
||||
@@ -469,7 +469,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export interface ModifiersArray extends NodeArray<Modifier> {
|
||||
flags: number;
|
||||
flags: NodeFlags;
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.AbstractKeyword)
|
||||
|
||||
18
tests/baselines/reference/exportDefaultAsyncFunction.js
Normal file
18
tests/baselines/reference/exportDefaultAsyncFunction.js
Normal file
@@ -0,0 +1,18 @@
|
||||
//// [exportDefaultAsyncFunction.ts]
|
||||
export default async function foo(): Promise<void> {}
|
||||
foo();
|
||||
|
||||
|
||||
//// [exportDefaultAsyncFunction.js]
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments)).next());
|
||||
});
|
||||
};
|
||||
export default function foo() {
|
||||
return __awaiter(this, void 0, void 0, function* () { });
|
||||
}
|
||||
foo();
|
||||
@@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/exportDefaultAsyncFunction.ts ===
|
||||
export default async function foo(): Promise<void> {}
|
||||
>foo : Symbol(foo, Decl(exportDefaultAsyncFunction.ts, 0, 0))
|
||||
>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, --, --))
|
||||
|
||||
foo();
|
||||
>foo : Symbol(foo, Decl(exportDefaultAsyncFunction.ts, 0, 0))
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
=== tests/cases/compiler/exportDefaultAsyncFunction.ts ===
|
||||
export default async function foo(): Promise<void> {}
|
||||
>foo : () => Promise<void>
|
||||
>Promise : Promise<T>
|
||||
|
||||
foo();
|
||||
>foo() : Promise<void>
|
||||
>foo : () => Promise<void>
|
||||
|
||||
3
tests/cases/compiler/exportDefaultAsyncFunction.ts
Normal file
3
tests/cases/compiler/exportDefaultAsyncFunction.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
// @target: es6
|
||||
export default async function foo(): Promise<void> {}
|
||||
foo();
|
||||
Reference in New Issue
Block a user