10000 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
117b07b
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

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'master' into asyncFunctions
  • Loading branch information
rbuckton committed Jul 1, 2015
commit 4b4a96b9dce97d02f9bcf5db3ff49e3045f3d23b
9 changes: 5 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ namespace ts {
let getGlobalParameterDecoratorType: () => ObjectType;
let getGlobalPropertyDecoratorType: () => ObjectType;
let getGlobalMethodDecoratorType: () => ObjectType;
let getGlobalTypedPropertyDescriptorType: () => ObjectType;
let getGlobalPromiseType: () => ObjectType;
let tryGetGlobalPromiseType: () => ObjectType;
let getGlobalPromiseLikeType: () => ObjectType;
Expand All @@ -145,14 +146,15 @@ namespace ts {
let emitParam = false;
let emitAwaiter = false;
let emitGenerator = false;

let resolutionTargets: Object[] = [];
let resolutionResults: boolean[] = [];

let mergedSymbols: Symbol[] = [];
let symbolLinks: SymbolLinks[] = [];
let nodeLinks: NodeLinks[] = [];
let potentialThisCollisions: Node[] = [];
let awaitedTypeStack: number[] = [];

let diagnostics = createDiagnosticCollection();

Expand Down Expand Up @@ -8896,7 +8898,7 @@ namespace ts {
}
}

checkFunctionExpressionBodies(node.body);
checkFunctionAndClassExpressionBodies(node.body);
}
}
}
Expand Down Expand Up @@ -10517,8 +10519,6 @@ namespace ts {
return getTypeAtPosition(signature, 0);
}

let awaitedTypeStack: number[] = [];

/**
* Gets the "awaited type" of a type.
* @param type The type to await.
Expand Down Expand Up @@ -13993,6 +13993,7 @@ namespace ts {
getGlobalPropertyDecoratorType = memoize(() => getGlobalType("PropertyDecorator"));
getGlobalMethodDecoratorType = memoize(() => getGlobalType("MethodDecorator"));
getGlobalParameterDecoratorType = memoize(() => getGlobalType("ParameterDecorator"));
getGlobalTypedPropertyDescriptorType = memoize(() => getGlobalType("TypedPropertyDescriptor", /*arity*/ 1));
getGlobalPromiseType = memoize(() => getGlobalType("Promise", /*arity*/ 1));
tryGetGlobalPromiseType = memoize(() => getGlobalSymbol("Promise", SymbolFlags.Type, /*diagnostic*/ undefined) && getGlobalPromiseType());
getGlobalPromiseLikeType = memoize(() => getGlobalType("PromiseLike", /*arity*/ 1));
Expand Down
21 changes: 21 additions & 0 deletions src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ namespace ts {
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." },
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'." },
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'." },
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." },
Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression: { code: 1239, category: DiagnosticCategory.Error, key: "Unable to resolve signature of parameter decorator when called as an expression." },
Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression: { code: 1240, category: DiagnosticCategory.Error, key: "Unable to resolve signature of property decorator when called as an expression." },
Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression: { code: 1241, category: DiagnosticCategory.Error, key: "Unable to resolve signature of method decorator when called as an expression." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
Expand Down Expand Up @@ -386,11 +392,26 @@ namespace ts {
Cannot_find_namespace_0: { code: 2503, category: DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." },
No_best_common_type_exists_among_yield_expressions: { code: 2504, category: DiagnosticCategory.Error, key: "No best common type exists among yield expressions." },
A_generator_cannot_have_a_void_type_annotation: { code: 2505, category: DiagnosticCategory.Error, key: "A generator cannot have a 'void' type annotation." },
_0_is_referenced_directly_or_indirectly_in_its_own_base_expression: { code: 2506, category: DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own base expression." },
Type_0_is_not_a_constructor_function_type: { code: 2507, category: DiagnosticCategory.Error, key: "Type '{0}' is not a constructor function type." },
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." },
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." },
Base_constructors_must_all_have_the_same_return_type: { code: 2510, category: DiagnosticCategory.Error, key: "Base constructors must all have the same return type." },
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." },
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." },
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." },
yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." },
await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." },
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." },
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." },
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." },
Property_0_in_type_1_is_not_assignable_to_type_2: { code: 2603, category: DiagnosticCategory.Error, key: "Property '{0}' in type '{1}' is not assignable to type '{2}'" },
JSX_element_type_0_does_not_have_any_construct_or_call_signatures: { code: 2604, category: DiagnosticCategory.Error, key: "JSX element type '{0}' does not have any construct or call signatures." },
JSX_element_type_0_is_not_a_constructor_function_for_JSX_elements: { code: 2605, category: DiagnosticCategory.Error, key: "JSX element type '{0}' is not a constructor function for JSX elements." },
Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property: { code: 2606, category: DiagnosticCategory.Error, key: "Property '{0}' of JSX spread attribute is not assignable to target property." },
JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: { code: 2607, category: DiagnosticCategory.Error, key: "JSX element class does not support attributes because it does not have a '{0}' property" },
The_global_type_JSX_0_may_not_have_more_than_one_property: { code: 2608, category: DiagnosticCategory.Error, key: "The global type 'JSX.{0}' may not have more than one property" },
Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
Expand Down
87 changes: 87 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,31 @@
"code": 1311
},

"The return type of a property decorator function must be either 'void' or 'any'.": {
"category": "Error",
"code": 1236
},
"The return type of a parameter decorator function must be either 'void' or 'any'.": {
"category": "Error",
"code": 1237
},
"Unable to resolve signature of class decorator when called as an expression.": {
"category": "Error",
"code": 1238
},
"Unable to resolve signature of parameter decorator when called as an expression.": {
"category": "Error",
"code": 1239
},
"Unable to resolve signature of property decorator when called as an expression.": {
"category": "Error",
"code": 1240
},
"Unable to resolve signature of method decorator when called as an expression.": {
"category": "Error",
"code": 1241
},

"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300
Expand Down Expand Up @@ -1534,6 +1559,27 @@
< F438 /td> "category": "Error",
"code": 2505
},
"'{0}' is referenced directly or indirectly in its own base expression.": {
"category": "Error",
"code": 2506
},
"Type '{0}' is not a constructor function type.": {
"category": "Error",
"code": 2507
},
"No base constructor has the specified number of type arguments.": {
"category": "Error",
"code": 2508
},
"Base constructor return type '{0}' is not a class or interface type.": {
"category": "Error",
"code": 2509
},
"Base constructors must all have the same return type.": {
"category": "Error",
"code": 2510
},

"Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": {
"category": "Error",
"code": 2520
Expand All @@ -1555,6 +1601,47 @@
"code": 2524
},

"JSX element attributes type '{0}' must be an object type.": {
"category": "Error",
"code": 2600
},
"The return type of a JSX element constructor must return an object type.": {
"category": "Error",
"code": 2601
},
"JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist.": {
"category": "Error",
"code": 2602
},
"Property '{0}' in type '{1}' is not assignable to type '{2}'": {
"category": "Error",
"code": 2603
},
"JSX element type '{0}' does not have any construct or call signatures.": {
"category": "Error",
"code": 2604
},
"JSX element type '{0}' is not a constructor function for JSX elements.": {
"category": "Error",
"code": 2605
},
"Property '{0}' of JSX spread attribute is not assignable to target property.": {
"category": "Error",
"code": 2606
},
"JSX element class does not support attributes because it does not have a '{0}' property": {
"category": "Error",
"code": 2607
},
"The global type 'JSX.{0}' may not have more than one property": {
"category": "Error",
"code": 2608
},
"Cannot emit namespaced JSX elements in React": {
"category": "Error",
"code": 2650
},

"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000
Expand Down
11 changes: 10 additions & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,16 @@ namespace ts {
}
}
}


export function getContainingClass(node: Node): ClassLikeDeclaration {
while (true) {
node = node.parent;
if (!node || isClassLike(node)) {
return <ClassLikeDeclaration>node;
}
}
}

export function getThisContainer(node: Node, includeArrowFunctions: boolean): Node {
while (true) {
node = node.parent;
Expand Down
20 changes: 10 additions & 10 deletions tests/baselines/reference/APISample_linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,26 @@ function delint(sourceFile) {
delintNode(sourceFile);
function delintNode(node) {
switch (node.kind) {
case 192 /* ForStatement */:
case 193 /* ForInStatement */:
case 191 /* WhileStatement */:
case 190 /* DoStatement */:
if (node.statement.kind !== 185 /* Block */) {
case 194 /* ForStatement */:
case 195 /* ForInStatement */:
case 193 /* WhileStatement */:
case 192 /* DoStatement */:
if (node.statement.kind !== 187 /* Block */) {
report(node, "A looping statement's contents should be wrapped in a block body.");
}
break;
case 189 /* IfStatement */:
case 191 /* IfStatement */:
var ifStatement = node;
if (ifStatement.thenStatement.kind !== 185 /* Block */) {
if (ifStatement.thenStatement.kind !== 187 /* Block */) {
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
}
if (ifStatement.elseStatement &&
ifStatement.elseStatement.kind !== 185 /* Block */ &&
ifStatement.elseStatement.kind !== 189 /* IfStatement */) {
ifStatement.elseStatement.kind !== 187 /* Block */ &&
ifStatement.elseStatement.kind !== 191 /* IfStatement */) {
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
}
break;
case 175 /* BinaryExpression */:
case 176 /* BinaryExpression */:
var op = node.operatorToken.kind;
if (op === 29 /* EqualsEqualsToken */ || op == 30 /* ExclamationEqualsToken */) {
report(node, "Use '===' and '!=='.");
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/asyncArrowFunction1_es6.symbols
Original file line number 5E6E Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

var foo = async (): Promise<void> => {
>foo : Symbol(foo, Decl(asyncArrowFunction1_es6.ts, 1, 3))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4772, 1), Decl(lib.d.ts, 4858, 11))

};
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.
0