Skip to content

Commit b2a871d

Browse files
committed
Merge pull request #3078 from Microsoft/asyncFunctions
Async Functions for ES6
2 parents 5208bde + 4b4a96b commit b2a871d

File tree

315 files changed

+5110
-918
lines changed

Some content is hidden

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

315 files changed

+5110
-918
lines changed

Diff for: src/compiler/checker.ts

+563-29
Large diffs are not rendered by default.

Diff for: src/compiler/commandLineParser.ts

+5
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ namespace ts {
203203
type: "boolean",
204204
description: Diagnostics.Watch_input_files,
205205
},
206+
{
207+
name: "experimentalAsyncFunctions",
208+
type: "boolean",
209+
description: Diagnostics.Enables_experimental_support_for_ES7_async_functions
210+
},
206211
{
207212
name: "experimentalDecorators",
208213
type: "boolean",

Diff for: src/compiler/diagnosticInformationMap.generated.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ namespace ts {
2929
Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: DiagnosticCategory.Error, key: "Statements are not allowed in ambient contexts." },
3030
A_declare_modifier_cannot_be_used_in_an_already_ambient_context: { code: 1038, category: DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used in an already ambient context." },
3131
Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: DiagnosticCategory.Error, key: "Initializers are not allowed in ambient contexts." },
32+
_0_modifier_cannot_be_used_in_an_ambient_context: { code: 1040, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot be used in an ambient context." },
33+
_0_modifier_cannot_be_used_with_a_class_declaration: { code: 1041, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot be used with a class declaration." },
34+
_0_modifier_cannot_be_used_here: { code: 1042, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot be used here." },
35+
_0_modifier_cannot_appear_on_a_data_property: { code: 1043, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a data property." },
3236
_0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a module element." },
37+
A_0_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: DiagnosticCategory.Error, key: "A '{0}' modifier cannot be used with an interface declaration." },
3338
A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file: { code: 1046, category: DiagnosticCategory.Error, key: "A 'declare' modifier is required for a top level declaration in a .d.ts file." },
3439
A_rest_parameter_cannot_be_optional: { code: 1047, category: DiagnosticCategory.Error, key: "A rest parameter cannot be optional." },
3540
A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: DiagnosticCategory.Error, key: "A rest parameter cannot have an initializer." },
@@ -38,12 +43,18 @@ namespace ts {
3843
A_set_accessor_parameter_cannot_have_an_initializer: { code: 1052, category: DiagnosticCategory.Error, key: "A 'set' accessor parameter cannot have an initializer." },
3944
A_set_accessor_cannot_have_rest_parameter: { code: 1053, category: DiagnosticCategory.Error, key: "A 'set' accessor cannot have rest parameter." },
4045
A_get_accessor_cannot_have_parameters: { code: 1054, category: DiagnosticCategory.Error, key: "A 'get' accessor cannot have parameters." },
46+
Type_0_is_not_a_valid_async_function_return_type: { code: 1055, category: DiagnosticCategory.Error, key: "Type '{0}' is not a valid async function return type." },
4147
Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1056, category: DiagnosticCategory.Error, key: "Accessors are only available when targeting ECMAScript 5 and higher." },
48+
An_async_function_or_method_must_have_a_valid_awaitable_return_type: { code: 1057, category: DiagnosticCategory.Error, key: "An async function or method must have a valid awaitable return type." },
49+
Operand_for_await_does_not_have_a_valid_callable_then_member: { code: 1058, category: DiagnosticCategory.Error, key: "Operand for 'await' does not have a valid callable 'then' member." },
50+
Return_expression_in_async_function_does_not_have_a_valid_callable_then_member: { code: 1059, category: DiagnosticCategory.Error, key: "Return expression in async function does not have a valid callable 'then' member." },
51+
Expression_body_for_async_arrow_function_does_not_have_a_valid_callable_then_member: { code: 1060, category: DiagnosticCategory.Error, key: "Expression body for async arrow function does not have a valid callable 'then' member." },
4252
Enum_member_must_have_initializer: { code: 1061, category: DiagnosticCategory.Error, key: "Enum member must have initializer." },
53+
_0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method: { code: 1062, category: DiagnosticCategory.Error, key: "{0} is referenced directly or indirectly in the fulfillment callback of its own 'then' method." },
4354
An_export_assignment_cannot_be_used_in_a_namespace: { code: 1063, category: DiagnosticCategory.Error, key: "An export assignment cannot be used in a namespace." },
4455
Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: DiagnosticCategory.Error, key: "Ambient enum elements can only have integer literal initializers." },
4556
Unexpected_token_A_constructor_method_accessor_or_property_was_expected: { code: 1068, category: DiagnosticCategory.Error, key: "Unexpected token. A constructor, method, accessor, or property was expected." },
46-
A_declare_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used with an import declaration." },
57+
A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: DiagnosticCategory.Error, key: "A '{0}' modifier cannot be used with an import declaration." },
4758
Invalid_reference_directive_syntax: { code: 1084, category: DiagnosticCategory.Error, key: "Invalid 'reference' directive syntax." },
4859
Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: DiagnosticCategory.Error, key: "Octal literals are not available when targeting ECMAScript 5 and higher." },
4960
An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: DiagnosticCategory.Error, key: "An accessor cannot be declared in an ambient context." },
@@ -179,6 +190,10 @@ namespace ts {
179190
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." },
180191
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." },
181192
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." },
193+
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." },
194+
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." },
195+
await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." },
196+
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." },
182197
The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." },
183198
The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." },
184199
Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." },
@@ -382,6 +397,11 @@ namespace ts {
382397
No_base_constructor_has_the_specified_number_of_type_arguments: { code: 2508, category: DiagnosticCategory.Error, key: "No base constructor has the specified number of type arguments." },
383398
Base_constructor_return_type_0_is_not_a_class_or_interface_type: { code: 2509, category: DiagnosticCategory.Error, key: "Base constructor return type '{0}' is not a class or interface type." },
384399
Base_constructors_must_all_have_the_same_return_type: { code: 2510, category: DiagnosticCategory.Error, key: "Base constructors must all have the same return type." },
400+
Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." },
401+
Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." },
402+
The_arguments_object_cannot_be_referenced_in_an_async_arrow_function_Consider_using_a_standard_async_function_expression: { code: 2522, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression." },
403+
yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." },
404+
await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." },
385405
JSX_element_attributes_type_0_must_be_an_object_type: { code: 2600, category: DiagnosticCategory.Error, key: "JSX element attributes type '{0}' must be an object type." },
386406
The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: { code: 2601, category: DiagnosticCategory.Error, key: "The return type of a JSX element constructor must return an object type." },
387407
JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: { code: 2602, category: DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist." },
@@ -538,6 +558,8 @@ namespace ts {
538558
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." },
539559
Enables_experimental_support_for_ES7_decorators: { code: 6065, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." },
540560
Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." },
561+
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." },
562+
Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." },
541563
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
542564
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
543565
Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },

Diff for: src/compiler/diagnosticMessages.json

+91-1
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,30 @@
103103
"category": "Error",
104104
"code": 1039
105105
},
106+
"'{0}' modifier cannot be used in an ambient context.": {
107+
"category": "Error",
108+
"code": 1040
109+
},
110+
"'{0}' modifier cannot be used with a class declaration.": {
111+
"category": "Error",
112+
"code": 1041
113+
},
114+
"'{0}' modifier cannot be used here.": {
115+
"category": "Error",
116+
"code": 1042
117+
},
118+
"'{0}' modifier cannot appear on a data property.": {
119+
"category": "Error",
120+
"code": 1043
121+
},
106122
"'{0}' modifier cannot appear on a module element.": {
107123
"category": "Error",
108124
"code": 1044
109125
},
126+
"A '{0}' modifier cannot be used with an interface declaration.": {
127+
"category": "Error",
128+
"code": 1045
129+
},
110130
"A 'declare' modifier is required for a top level declaration in a .d.ts file.": {
111131
"category": "Error",
112132
"code": 1046
@@ -139,14 +159,38 @@
139159
"category": "Error",
140160
"code": 1054
141161
},
162+
"Type '{0}' is not a valid async function return type.": {
163+
"category": "Error",
164+
"code": 1055
165+
},
142166
"Accessors are only available when targeting ECMAScript 5 and higher.": {
143167
"category": "Error",
144168
"code": 1056
145169
},
170+
"An async function or method must have a valid awaitable return type.": {
171+
"category": "Error",
172+
"code": 1057
173+
},
174+
"Operand for 'await' does not have a valid callable 'then' member.": {
175+
"category": "Error",
176+
"code": 1058
177+
},
178+
"Return expression in async function does not have a valid callable 'then' member.": {
179+
"category": "Error",
180+
"code": 1059
181+
},
182+
"Expression body for async arrow function does not have a valid callable 'then' member.": {
183+
"category": "Error",
184+
"code": 1060
185+
},
146186
"Enum member must have initializer.": {
147187
"category": "Error",
148188
"code": 1061
149189
},
190+
"{0} is referenced directly or indirectly in the fulfillment callback of its own 'then' method.": {
191+
"category": "Error",
192+
"code": 1062
193+
},
150194
"An export assignment cannot be used in a namespace.": {
151195
"category": "Error",
152196
"code": 1063
@@ -159,7 +203,7 @@
159203
"category": "Error",
160204
"code": 1068
161205
},
162-
"A 'declare' modifier cannot be used with an import declaration.": {
206+
"A '{0}' modifier cannot be used with an import declaration.": {
163207
"category": "Error",
164208
"code": 1079
165209
},
@@ -703,7 +747,24 @@
703747
"category": "Error",
704748
"code": 1235
705749
},
750+
"Experimental support for async functions is a feature that is subject to change in a future release. Specify '--experimentalAsyncFunctions' to remove this warning.": {
751+
"category": "Error",
752+
"code": 1236
753+
},
754+
706755

756+
"'with' statements are not allowed in an async function block.": {
757+
"category": "Error",
758+
"code": 1300
759+
},
760+
"'await' expression is only allowed within an async function.": {
761+
"category": "Error",
762+
"code": 1308
763+
},
764+
"Async functions are only available when targeting ECMAScript 6 and higher.": {
765+
"category": "Error",
766+
"code": 1311
767+
},
707768

708769
"The return type of a property decorator function must be either 'void' or 'any'.": {
709770
"category": "Error",
@@ -1519,6 +1580,27 @@
15191580
"code": 2510
15201581
},
15211582

1583+
"Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": {
1584+
"category": "Error",
1585+
"code": 2520
1586+
},
1587+
"Expression resolves to variable declaration '{0}' that compiler uses to support async functions.": {
1588+
"category": "Error",
1589+
"code": 2521
1590+
},
1591+
"The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression.": {
1592+
"category": "Error",
1593+
"code": 2522
1594+
},
1595+
"'yield' expressions cannot be used in a parameter initializer.": {
1596+
"category": "Error",
1597+
"code": 2523
1598+
},
1599+
"'await' expressions cannot be used in a parameter initializer.": {
1600+
"category": "Error",
1601+
"code": 2524
1602+
},
1603+
15221604
"JSX element attributes type '{0}' must be an object type.": {
15231605
"category": "Error",
15241606
"code": 2600
@@ -2145,6 +2227,14 @@
21452227
"category": "Message",
21462228
"code": 6066
21472229
},
2230+
"Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower.": {
2231+
"category": "Message",
2232+
"code": 6067
2233+
},
2234+
"Enables experimental support for ES7 async functions.": {
2235+
"category": "Message",
2236+
"code": 6068
2237+
},
21482238

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

0 commit comments

Comments
 (0)