Skip to content

Commit 76c0d32

Browse files
committed
Moved async functions for ES6 behind experimental flag
1 parent 5b32903 commit 76c0d32

File tree

57 files changed

+85
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+85
-1
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9863,6 +9863,10 @@ namespace ts {
98639863
checkSignatureDeclaration(node);
98649864
let isAsync = isAsyncFunctionLike(node);
98659865
if (isAsync) {
9866+
if (!compilerOptions.experimentalAsyncFunctions) {
9867+
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);
9868+
}
9869+
98669870
emitAwaiter = true;
98679871
}
98689872

src/compiler/commandLineParser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ namespace ts {
192192
type: "boolean",
193193
description: Diagnostics.Watch_input_files,
194194
},
195+
{
196+
name: "experimentalAsyncFunctions",
197+
type: "boolean",
198+
description: Diagnostics.Enables_experimental_support_for_ES7_async_functions
199+
},
195200
{
196201
name: "experimentalDecorators",
197202
type: "boolean",

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ namespace ts {
201201
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." },
202202
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." },
203203
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." },
204+
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." },
204205
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." },
205206
await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." },
206207
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." },
@@ -547,6 +548,8 @@ namespace ts {
547548
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." },
548549
Enables_experimental_support_for_ES7_decorators: { code: 6065, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." },
549550
Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." },
551+
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." },
552+
Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." },
550553
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
551554
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
552555
Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },

src/compiler/diagnosticMessages.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,10 @@
791791
"category": "Error",
792792
"code": 1235
793793
},
794+
"Experimental support for async functions is a feature that is subject to change in a future release. Specify '--experimentalAsyncFunctions' to remove this warning.": {
795+
"category": "Error",
796+
"code": 1236
797+
},
794798

795799

796800
"'with' statements are not allowed in an async function block.": {
@@ -2180,6 +2184,14 @@
21802184
"category": "Message",
21812185
"code": 6066
21822186
},
2187+
"Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower.": {
2188+
"category": "Message",
2189+
"code": 6067
2190+
},
2191+
"Enables experimental support for ES7 async functions.": {
2192+
"category": "Message",
2193+
"code": 6068
2194+
},
21832195

21842196
"Variable '{0}' implicitly has an '{1}' type.": {
21852197
"category": "Error",

src/compiler/program.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ namespace ts {
144144
let program: Program;
145145
let files: SourceFile[] = [];
146146
let diagnostics = createDiagnosticCollection();
147-
147+
148148
let commonSourceDirectory: string;
149149
let diagnosticsProducingTypeChecker: TypeChecker;
150150
let noDiagnosticsTypeChecker: TypeChecker;
@@ -676,6 +676,11 @@ namespace ts {
676676
!options.experimentalDecorators) {
677677
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified));
678678
}
679+
680+
if (options.experimentalAsyncFunctions &&
681+
options.target !== ScriptTarget.ES6) {
682+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower));
683+
}
679684
}
680685
}
681686
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,7 @@ namespace ts {
18781878
watch?: boolean;
18791879
isolatedModules?: boolean;
18801880
experimentalDecorators?: boolean;
1881+
experimentalAsyncFunctions?: boolean;
18811882
emitDecoratorMetadata?: boolean;
18821883
/* @internal */ stripInternal?: boolean;
18831884

src/harness/harness.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,10 @@ module Harness {
10551055
case 'emitdecoratormetadata':
10561056
options.emitDecoratorMetadata = setting.value === 'true';
10571057
break;
1058+
1059+
case 'experimentalasyncfunctions':
1060+
options.experimentalAsyncFunctions = setting.value === 'true';
1061+
break;
10581062

10591063
case 'noemithelpers':
10601064
options.noEmitHelpers = setting.value === 'true';

tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction10_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34

45
var foo = async foo(): Promise<void> => {
56
// Legal to use 'await' in a type context.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34

45
var foo = async (): Promise<void> => {
56
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
var f = (await) => {
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
function f(await = await) {
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
var await = () => {
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34

45
var foo = async (await): Promise<void> => {
56
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34

45
var foo = async (a = await): Promise<void> => {
56
}

tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction7_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34

45
var bar = async (): Promise<void> => {
56
// 'await' here is an identifier, and not an await expression.

tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction8_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34

45
var foo = async (): Promise<void> => {
56
var v = { [await]: foo }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
var foo = async (a = await => await): Promise<void> => {
45
}

tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunctionCapturesArguments_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
class C {
45
method() {
56
function other() {}

tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunctionCapturesThis_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
class C {
45
method() {
56
var fn = async () => await this;

tests/cases/conformance/async/es6/asyncAwaitIsolatedModules_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @isolatedModules: true
3+
// @experimentalAsyncFunctions: true
34
import { MyPromise } from "missing";
45

56
declare var p: Promise<number>;

tests/cases/conformance/async/es6/asyncAwait_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @target: ES6
2+
// @experimentalAsyncFunctions: true
23
type MyPromise<T> = Promise<T>;
34
declare var MyPromise: typeof Promise;
45
declare var p: Promise<number>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
async class C {
45
}

tests/cases/conformance/async/es6/asyncConstructor_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
class C {
45
async constructor() {
56
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare async function foo(): Promise<void>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
async enum E {
45
Value
56
}

tests/cases/conformance/async/es6/asyncGetter_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
class C {
45
async get foo() {
56
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
async interface I {
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
async module M {
45
}

tests/cases/conformance/async/es6/asyncSetter_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
class C {
45
async set foo(value) {
56
}

tests/cases/conformance/async/es6/awaitBinaryExpression/awaitBinaryExpression1_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: boolean;
45
declare var p: Promise<boolean>;
56
async function func(): Promise<void> {

tests/cases/conformance/async/es6/awaitBinaryExpression/awaitBinaryExpression2_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: boolean;
45
declare var p: Promise<boolean>;
56
async function func(): Promise<void> {

tests/cases/conformance/async/es6/awaitBinaryExpression/awaitBinaryExpression3_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: number;
45
declare var p: Promise<number>;
56
async function func(): Promise<void> {

tests/cases/conformance/async/es6/awaitBinaryExpression/awaitBinaryExpression4_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: boolean;
45
declare var p: Promise<boolean>;
56
async function func(): Promise<void> {

tests/cases/conformance/async/es6/awaitBinaryExpression/awaitBinaryExpression5_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: boolean;
45
declare var p: Promise<boolean>;
56
async function func(): Promise<void> {

tests/cases/conformance/async/es6/awaitCallExpression/awaitCallExpression1_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: boolean;
45
declare var p: Promise<boolean>;
56
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;

tests/cases/conformance/async/es6/awaitCallExpression/awaitCallExpression2_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: boolean;
45
declare var p: Promise<boolean>;
56
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;

tests/cases/conformance/async/es6/awaitCallExpression/awaitCallExpression3_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: boolean;
45
declare var p: Promise<boolean>;
56
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;

tests/cases/conformance/async/es6/awaitCallExpression/awaitCallExpression4_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: boolean;
45
declare var p: Promise<boolean>;
56
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;

tests/cases/conformance/async/es6/awaitCallExpression/awaitCallExpression5_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: boolean;
45
declare var p: Promise<boolean>;
56
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;

tests/cases/conformance/async/es6/awaitCallExpression/awaitCallExpression6_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: boolean;
45
declare var p: Promise<boolean>;
56
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;

tests/cases/conformance/async/es6/awaitCallExpression/awaitCallExpression7_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: boolean;
45
declare var p: Promise<boolean>;
56
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;

tests/cases/conformance/async/es6/awaitCallExpression/awaitCallExpression8_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare var a: boolean;
45
declare var p: Promise<boolean>;
56
declare function fn(arg0: boolean, arg1: boolean, arg2: boolean): void;

tests/cases/conformance/async/es6/awaitUnion_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
declare let a: number | string;
45
declare let b: PromiseLike<number> | PromiseLike<string>;
56
declare let c: PromiseLike<number | string>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
async function foo(a = await => await): Promise<void> {
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
async function await(): Promise<void> {
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
var v = async function await(): Promise<void> { }

tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration13_es6.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
async function foo(): Promise<void> {
45
// Legal to use 'await' in a type context.
56
var v: await;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @target: ES6
22
// @noEmitHelpers: true
3+
// @experimentalAsyncFunctions: true
34
async function foo(): Promise<void> {
45
return;
56
}

0 commit comments

Comments
 (0)