8000 Async Functions for ES6 by rbuckton · Pull Request #3078 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

Async Functions for ES6 #3078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 46 commits into from
Jul 1, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d19a200
Added types, scan, parse, and check for async functions
rbuckton May 6, 2015
e82e841
Added emit for async functions in ES6
rbuckton May 7, 2015
80edb2d
Bug fixes and baselines
rbuckton May 7, 2015
1718ff2
Merge branch 'master' into asyncFunctions
rbuckton May 8, 2015
bca21ec
Updated baselines
rbuckton May 8, 2015
655f2ec
Cleanup and PR feedback
rbuckton May 8, 2015
2391666
Updated declaration and symbol baselines
rbuckton May 9, 2015
39a6cce
Cleaned up diagnostic messages
rbuckton May 9, 2015
daa7793
Additional clean up of diagnostic messages
rbuckton May 9, 2015
2ee5beb
PR feedback
rbuckton May 9, 2015
3d0991d
Better name for bitmask in ParserContextFlags
rbuckton May 13, 2015
9a6d308
Simplified parenthesis check for await as yield.
rbuckton May 13, 2015
117b07 8000 b
Added comments for emitAsyncSignatureAndBodyForES6
rbuckton May 13, 2015
e5df2e2
Merge branch 'asyncFunctions' of https://github.com/Microsoft/TypeScr…
rbuckton May 13, 2015
5e2d48c
Merge branch 'master' into asyncFunctions
rbuckton May 13, 2015
379704f
Cleaned up checker, added comments to parser based on PR feedback.
rbuckton May 13, 2015
b70e6a1
Added parseModifiersForArrowFunction
rbuckton May 13, 2015
890a5d8
Fixed missing call to nextToken()
rbuckton May 13, 2015
a565a02
Fixes missing check in isParenthesizedArrowFunctionExpressionWorker
rbuckton May 14, 2015
a2c5073
Some cleanup and additional comments following PR feedback
rbuckton May 19, 2015
b5df4b1
Merge branch 'master' into asyncFunctions
rbuckton May 21, 2015
9560d6f
Merge branch 'master' into asyncFunctions
rbuckton Jun 4, 2015
72a6865
Updated emit to align with current proposal for ES7 async functions
rbuckton Jun 4, 2015
02557b1
Emit awaiter arguments on new line
weswigham Jun 9, 2015
371583b
Update baselines for emit change
weswigham Jun 10, 2015
6fc07e6
Merged branch 'master' into asyncFunctions
rbuckton Jun 10, 2015
c259d7e
Merge pull request #3455 from weswigham/asyncFunctions
rbuckton Jun 10, 2015
5ebad58
Merge branch 'master' into asyncFunctions
rbuckton Jun 15, 2015
9a57e6f
Updated baselines
rbuckton Jun 15, 2015
f1c99f3
Remove generatorParameter and asyncParameter contexts.
CyrusNajmabadi Jun 16, 2015
009c3ee
Merge branch 'master' into removeGeneratorParameter
CyrusNajmabadi Jun 16, 2015
2e16680
Re-number enum.
CyrusNajmabadi Jun 16, 2015
1b93265
Merge pull request #3526 from Microsoft/removeGeneratorParameter
CyrusNajmabadi Jun 16, 2015
b25d855
Removed unused getContainingParameter function
rbuckton Jun 17, 2015
82eae19
Inlined checks for NodeFlags.Async in parser
rbuckton Jun 17, 2015
c74bb84
Moved getContainingFunction call in checkIdentifier
rbuckton Jun 17, 2015
b00a957
Removed unneeded capture for lexical this
rbuckton Jun 17, 2015
02f6622
Changed createPromiseType to return emptyObjectType
rbuckton Jun 17, 2015
7443ecc
Cleaned up diagnostics
rbuckton Jun 17, 2015
2891a1d
Cleaned up async return type check
rbuckton Jun 18, 2015
c4876d5
Add support for awaiting union types with mixed promise and non-promi…
rbuckton Jun 18, 2015
379d74a
Minor function rename
rbuckton Jun 18, 2015
eb03ae8
Added shortcut in checkAwaitedType for isolatedModules
rbuckton Jun 18, 2015
5b32903
Fix async function emit for lexical arguments
rbuckton Jun 19, 2015
76c0d32
Moved async functions for ES6 behind experimental flag
rbuckton Jun 20, 2015
4b4a96b
Merge branch 'master' into asyncFunctions
rbuckton Jul 1, 2015
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved async functions for ES6 behind experimental flag
  • Loading branch information
rbuckton committed Jun 20, 2015
commit 76c0d32f9da2a378f12e427b52edade900576915
4 changes: 4 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9863,6 +9863,10 @@ namespace ts {
checkSignatureDeclaration(node);
let isAsync = isAsyncFunctionLike(node);
if (isAsync) {
if (!compilerOptions.experimentalAsyncFunctions) {
error(node, Diagnostics.Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning);
}

emitAwaiter = true;
}

Expand Down
5 changes: 5 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ namespace ts {
type: "boolean",
description: Diagnostics.Watch_input_files,
},
{
name: "experimentalAsyncFunctions",
type: "boolean",
description: Diagnostics.Enables_experimental_support_for_ES7_async_functions
},
{
name: "experimentalDecorators",
type: "boolean",
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ namespace ts {
An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: DiagnosticCategory.Error, key: "An export declaration can only be used in a module." },
An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." },
A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." },
Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning: { code: 1236, category: DiagnosticCategory.Error, key: "Experimental support for async functions is a feature that is subject to change in a future release. Specify '--experimentalAsyncFunctions' to remove this warning." },
with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: DiagnosticCategory.Error, key: "'with' statements are not allowed in an async function block." },
await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." },
Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: DiagnosticCategory.Error, key: "Async functions are only available when targeting ECMAScript 6 and higher." },
Expand Down Expand Up @@ -547,6 +548,8 @@ namespace ts {
Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified: { code: 6064, category: DiagnosticCategory.Error, key: "Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified." },
Enables_experimental_support_for_ES7_decorators: { code: 6065, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." },
Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." },
Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." },
Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." },
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },
Expand Down
12 changes: 12 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,10 @@
"category": "Error",
"code": 1235
},
"Experimental support for async functions is a feature that is subject to change in a future release. Specify '--experimentalAsyncFunctions' to remove this warning.": {
"category": "Error",
"code": 1236
},


"'with' statements are not allowed in an async function block.": {
Expand Down Expand Up @@ -2180,6 +2184,14 @@
"category": "Message",
"code": 6066
},
"Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower.": {
"category": "Message",
"code": 6067
},
"Enables experimental support for ES7 async functions.": {
"category": "Message",
"code": 6068
},

"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
Expand Down
7 changes: 6 additions & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace ts {
let program: Program;
let files: SourceFile[] = [];
let diagnostics = createDiagnosticCollection();

let commonSourceDirectory: string;
let diagnosticsProducingTypeChecker: TypeChecker;
let noDiagnosticsTypeChecker: TypeChecker;
Expand Down Expand Up @@ -676,6 +676,11 @@ namespace ts {
!options.experimentalDecorators) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified));
}

if (options.experimentalAsyncFunctions &&
options.target !== ScriptTarget.ES6) {
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower));
}
}
}
}
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,7 @@ namespace ts {
watch?: boolean;
isolatedModules?: boolean;
experimentalDecorators?: boolean;
experimentalAsyncFunctions?: boolean;
emitDecoratorMetadata?: boolean;
/* @internal */ stripInternal?: boolean;

Expand Down
4 changes: 4 additions & 0 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,10 @@ module Harness {
case 'emitdecoratormetadata':
options.emitDecoratorMetadata = setting.value === 'true';
break;

case 'experimentalasyncfunctions':
options.experimentalAsyncFunctions = setting.value === 'true';
break;

case 'noemithelpers':
options.noEmitHelpers = setting.value === 'true';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true

var foo = async foo(): Promise<void> => {
// Legal to use 'await' in a type context.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true

var foo = async (): Promise<void> => {
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
var f = (await) => {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
function f(await = await) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
var await = () => {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true

var foo = async (await): Promise<void> => {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true

var foo = async (a = await): Promise<void> => {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true

var bar = async (): Promise<void> => {
// 'await' here is an identifier, and not an await expression.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true

var foo = async (): Promise<void> => {
var v = { [await]: foo }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
var foo = async (a = await => await): Promise<void> => {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
class C {
method() {
function other() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
class C {
method() {
var fn = async () => await this;
Expand Down
10000
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @isolatedModules: true
// @experimentalAsyncFunctions: true
import { MyPromise } from "missing";

declare var p: Promise<number>;
Expand Down
1 change: 1 addition & 0 deletions tests/cases/conformance/async/es6/asyncAwait_es6.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @target: ES6
// @experimentalAsyncFunctions: true
type MyPromise<T> = Promise<T>;
declare var MyPromise: typeof Promise;
declare var p: Promise<number>;
Expand Down
1 change: 1 addition & 0 deletions tests/cases/conformance/async/es6/asyncClass_es6.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
async class C {
}
1 change: 1 addition & 0 deletions tests/cases/conformance/async/es6/asyncConstructor_es6.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
class C {
async constructor() {
}
Expand Down
1 change: 1 addition & 0 deletions tests/cases/conformance/async/es6/asyncDeclare_es6.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare async function foo(): Promise<void>;
1 change: 1 addition & 0 deletions tests/cases/conformance/async/es6/asyncEnum_es6.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
async enum E {
Value
}
1 change: 1 addition & 0 deletions tests/cases/conformance/async/es6/asyncGetter_es6.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
class C {
async get foo() {
}
Expand Down
1 change: 1 addition & 0 deletions tests/cases/conformance/async/es6/asyncInterface_es6.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
async interface I {
}
1 change: 1 addition & 0 deletions tests/cases/conformance/async/es6/asyncModule_es6.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
async module M {
}
1 change: 1 addition & 0 deletions tests/cases/conformance/async/es6/asyncSetter_es6.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
class C {
async set foo(value) {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: boolean;
declare var p: Promise<boolean>;
async function func(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: boolean;
declare var p: Promise<boolean>;
async function func(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: number;
declare var p: Promise<number>;
async function func(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: boolean;
declare var p: Promise<boolean>;
async function func(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: boolean;
declare var p: Promise<boolean>;
async function func(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: boolean;
declare var p: Promise<boolean>;
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: boolean;
declare var p: Promise<boolean>;
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: boolean;
declare var p: Promise<boolean>;
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: boolean;
declare var p: Promise<boolean>;
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: boolean;
declare var p: Promise<boolean>;
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: boolean;
declare var p: Promise<boolean>;
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: boolean;
declare var p: Promise<boolean>;
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare var a: boolean;
declare var p: Promise<boolean>;
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;
Expand Down
1 change: 1 addition & 0 deletions tests/cases/conformance/async/es6/awaitUnion_es6.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
declare let a: number | string;
declare let b: PromiseLike<number> | PromiseLike<string>;
declare let c: PromiseLike<number | string>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
async function foo(a = await => await): Promise<void> {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
async function await(): Promise<void> {
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
var v = async function await(): Promise<void> { }
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
async function foo(): Promise<void> {
// Legal to use 'await' in a type context.
var v: await;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @target: ES6
// @noEmitHelpers: true
// @experimentalAsyncFunctions: true
async function foo(): Promise<void> {
return;
}
Loading
0