Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,8 @@ namespace ts {

function nextTokenIsClassOrFunctionOrAsync(): boolean {
nextToken();
return token === SyntaxKind.ClassKeyword || token === SyntaxKind.FunctionKeyword || token === SyntaxKind.AsyncKeyword;
return token === SyntaxKind.ClassKeyword || token === SyntaxKind.FunctionKeyword ||
(token === SyntaxKind.AsyncKeyword && lookAhead(nextTokenIsFunctionKeywordOnSameLine));
}

// True if positioned at the start of a list element
Expand Down
56 changes: 56 additions & 0 deletions tests/baselines/reference/exportDefaultAsyncFunction2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//// [tests/cases/compiler/exportDefaultAsyncFunction2.ts] ////

//// [asyncawait.ts]

export function async<T>(...args: any[]): any { }
export function await(...args: any[]): any { }

//// [a.ts]
import { async, await } from 'asyncawait';
export default async(() => await(Promise.resolve(1)));

//// [b.ts]
export default async () => { return 0; };

//// [c.ts]
import { async, await } from 'asyncawait';
export default async<number>();

//// [d.ts]
import { async, await } from 'asyncawait';

export default async;

//// [e.ts]
import { async, await } from 'asyncawait';

export default async

export function foo() { }

//// [asyncawait.js]
export function async(...args) { }
export function await(...args) { }
//// [a.js]
import { async, await } from 'asyncawait';
export default async(() => await(Promise.resolve(1)));
//// [b.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 () => __awaiter(this, void 0, void 0, function* () { return 0; });
//// [c.js]
import { async } from 'asyncawait';
export default async();
//// [d.js]
import { async } from 'asyncawait';
export default async;
//// [e.js]
import { async } from 'asyncawait';
export default async;
export function foo() { }
53 changes: 53 additions & 0 deletions tests/baselines/reference/exportDefaultAsyncFunction2.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
=== tests/cases/compiler/asyncawait.ts ===

export function async<T>(...args: any[]): any { }
>async : Symbol(async, Decl(asyncawait.ts, 0, 0))
>T : Symbol(T, Decl(asyncawait.ts, 1, 22))
>args : Symbol(args, Decl(asyncawait.ts, 1, 25))

export function await(...args: any[]): any { }
>await : Symbol(await, Decl(asyncawait.ts, 1, 49))
>args : Symbol(args, Decl(asyncawait.ts, 2, 22))

=== tests/cases/compiler/a.ts ===
import { async, await } from 'asyncawait';
>async : Symbol(async, Decl(a.ts, 0, 8))
>await : Symbol(await, Decl(a.ts, 0, 15))

export default async(() => await(Promise.resolve(1)));
>async : Symbol(async, Decl(a.ts, 0, 8))
>await : Symbol(await, Decl(a.ts, 0, 15))
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>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, --, --))
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))

=== tests/cases/compiler/b.ts ===
export default async () => { return 0; };
No type information for this code.
No type information for this code.=== tests/cases/compiler/c.ts ===
import { async, await } from 'asyncawait';
>async : Symbol(async, Decl(c.ts, 0, 8))
>await : Symbol(await, Decl(c.ts, 0, 15))

export default async<number>();
>async : Symbol(async, Decl(c.ts, 0, 8))

=== tests/cases/compiler/d.ts ===
import { async, await } from 'asyncawait';
>async : Symbol(async, Decl(d.ts, 0, 8))
>await : Symbol(await, Decl(d.ts, 0, 15))

export default async;
>async : Symbol(async, Decl(d.ts, 0, 8))

=== tests/cases/compiler/e.ts ===
import { async, await } from 'asyncawait';
>async : Symbol(async, Decl(e.ts, 0, 8))
>await : Symbol(await, Decl(e.ts, 0, 15))

export default async
>async : Symbol(async, Decl(e.ts, 0, 8))

export function foo() { }
>foo : Symbol(foo, Decl(e.ts, 2, 20))

61 changes: 61 additions & 0 deletions tests/baselines/reference/exportDefaultAsyncFunction2.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
=== tests/cases/compiler/asyncawait.ts ===

export function async<T>(...args: any[]): any { }
>async : <T>(...args: any[]) => any
>T : T
>args : any[]

export function await(...args: any[]): any { }
>await : (...args: any[]) => any
>args : any[]

=== tests/cases/compiler/a.ts ===
import { async, await } from 'asyncawait';
>async : <T>(...args: any[]) => any
>await : (...args: any[]) => any

export default async(() => await(Promise.resolve(1)));
>async(() => await(Promise.resolve(1))) : any
>async : <T>(...args: any[]) => any
>() => await(Promise.resolve(1)) : () => any
>await(Promise.resolve(1)) : any
>await : (...args: any[]) => any
>Promise.resolve(1) : Promise<number>
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
>Promise : PromiseConstructor
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
>1 : number

=== tests/cases/compiler/b.ts ===
export default async () => { return 0; };
>async () => { return 0; } : () => Promise<number>
>0 : number

=== tests/cases/compiler/c.ts ===
import { async, await } from 'asyncawait';
>async : <T>(...args: any[]) => any
>await : (...args: any[]) => any

export default async<number>();
>async<number>() : any
>async : <T>(...args: any[]) => any

=== tests/cases/compiler/d.ts ===
import { async, await } from 'asyncawait';
>async : <T>(...args: any[]) => any
>await : (...args: any[]) => any

export default async;
>async : <T>(...args: any[]) => any

=== tests/cases/compiler/e.ts ===
import { async, await } from 'asyncawait';
>async : <T>(...args: any[]) => any
>await : (...args: any[]) => any

export default async
>async : <T>(...args: any[]) => any

export function foo() { }
>foo : () => void

28 changes: 28 additions & 0 deletions tests/cases/compiler/exportDefaultAsyncFunction2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @target: es6

// @filename: asyncawait.ts
export function async<T>(...args: any[]): any { }
export function await(...args: any[]): any { }

// @filename: a.ts
import { async, await } from 'asyncawait';
export default async(() => await(Promise.resolve(1)));

// @filename: b.ts
export default async () => { return 0; };

// @filename: c.ts
import { async, await } from 'asyncawait';
export default async<number>();

// @filename: d.ts
import { async, await } from 'asyncawait';

export default async;

// @filename: e.ts
import { async, await } from 'asyncawait';

export default async

export function foo() { }