Merge pull request #9445 from Microsoft/export_default_async_function

Parse `export default async function` as a declaration
This commit is contained in:
Andy
2016-06-30 13:55:24 -07:00
committed by GitHub
6 changed files with 44 additions and 6 deletions

View File

@@ -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();

View File

@@ -469,7 +469,7 @@ namespace ts {
}
export interface ModifiersArray extends NodeArray<Modifier> {
flags: number;
flags: NodeFlags;
}
// @kind(SyntaxKind.AbstractKeyword)

View 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();

View File

@@ -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))

View File

@@ -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>

View File

@@ -0,0 +1,3 @@
// @target: es6
export default async function foo(): Promise<void> {}
foo();