diff --git a/bin/lib.core.d.ts b/bin/lib.core.d.ts index a8b5fdbcf7cea..db3122ea564b0 100644 --- a/bin/lib.core.d.ts +++ b/bin/lib.core.d.ts @@ -258,7 +258,7 @@ interface Function { } interface FunctionConstructor { - /** + /** * Creates a new function. * @param args A list of arguments the function accepts. */ @@ -1164,3 +1164,11 @@ interface ArrayConstructor { } declare var Array: ArrayConstructor; + +interface IPromise { + then(onfulfilled: (value: T) => TResult | IPromise, onrejected: (reason: any) => TResult | IPromise): IPromise; +} + +interface IPromiseConstructor { + new (init: (resolve: (value: T | IPromise) => void, reject: (reason: any) => void) => void): IPromise; +} diff --git a/bin/lib.core.es6.d.ts b/bin/lib.core.es6.d.ts index d5898b35a715a..178c72a74f074 100644 --- a/bin/lib.core.es6.d.ts +++ b/bin/lib.core.es6.d.ts @@ -258,7 +258,7 @@ interface Function { } interface FunctionConstructor { - /** + /** * Creates a new function. * @param args A list of arguments the function accepts. */ @@ -1164,6 +1164,14 @@ interface ArrayConstructor { } declare var Array: ArrayConstructor; + +interface IPromise { + then(onfulfilled: (value: T) => TResult | IPromise, onrejected: (reason: any) => TResult | IPromise): IPromise; +} + +interface IPromiseConstructor { + new (init: (resolve: (value: T | IPromise) => void, reject: (reason: any) => void) => void): IPromise; +} declare type PropertyKey = string | number | Symbol; interface Symbol { diff --git a/bin/lib.d.ts b/bin/lib.d.ts index 02c45824aa84b..439370440c776 100644 --- a/bin/lib.d.ts +++ b/bin/lib.d.ts @@ -258,7 +258,7 @@ interface Function { } interface FunctionConstructor { - /** + /** * Creates a new function. * @param args A list of arguments the function accepts. */ @@ -1165,6 +1165,14 @@ interface ArrayConstructor { declare var Array: ArrayConstructor; +interface IPromise { + then(onfulfilled: (value: T) => TResult | IPromise, onrejected: (reason: any) => TResult | IPromise): IPromise; +} + +interface IPromiseConstructor { + new (init: (resolve: (value: T | IPromise) => void, reject: (reason: any) => void) => void): IPromise; +} + ///////////////////////////// /// IE10 ECMAScript Extensions ///////////////////////////// diff --git a/bin/lib.es6.d.ts b/bin/lib.es6.d.ts index a66c28662fdcd..99445e51114b5 100644 --- a/bin/lib.es6.d.ts +++ b/bin/lib.es6.d.ts @@ -258,7 +258,7 @@ interface Function { } interface FunctionConstructor { - /** + /** * Creates a new function. * @param args A list of arguments the function accepts. */ @@ -1164,6 +1164,14 @@ interface ArrayConstructor { } declare var Array: ArrayConstructor; + +interface IPromise { + then(onfulfilled: (value: T) => TResult | IPromise, onrejected: (reason: any) => TResult | IPromise): IPromise; +} + +interface IPromiseConstructor { + new (init: (resolve: (value: T | IPromise) => void, reject: (reason: any) => void) => void): IPromise; +} declare type PropertyKey = string | number | Symbol; interface Symbol { diff --git a/bin/tsc.js b/bin/tsc.js index 7a5c75155f429..c1968b6638918 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -15,6 +15,44 @@ and limitations under the License. var ts; (function (ts) { + (function (OpCode) { + OpCode[OpCode["Nop"] = 0] = "Nop"; + OpCode[OpCode["Statement"] = 1] = "Statement"; + OpCode[OpCode["Assign"] = 2] = "Assign"; + OpCode[OpCode["Break"] = 3] = "Break"; + OpCode[OpCode["BreakWhenTrue"] = 4] = "BreakWhenTrue"; + OpCode[OpCode["BreakWhenFalse"] = 5] = "BreakWhenFalse"; + OpCode[OpCode["Yield"] = 6] = "Yield"; + OpCode[OpCode["Return"] = 7] = "Return"; + OpCode[OpCode["Throw"] = 8] = "Throw"; + OpCode[OpCode["Endfinally"] = 9] = "Endfinally"; + })(ts.OpCode || (ts.OpCode = {})); + var OpCode = ts.OpCode; + (function (BlockAction) { + BlockAction[BlockAction["Open"] = 0] = "Open"; + BlockAction[BlockAction["Close"] = 1] = "Close"; + })(ts.BlockAction || (ts.BlockAction = {})); + var BlockAction = ts.BlockAction; + (function (BlockKind) { + BlockKind[BlockKind["Exception"] = 0] = "Exception"; + BlockKind[BlockKind["ScriptBreak"] = 1] = "ScriptBreak"; + BlockKind[BlockKind["Break"] = 2] = "Break"; + BlockKind[BlockKind["ScriptContinue"] = 3] = "ScriptContinue"; + BlockKind[BlockKind["Continue"] = 4] = "Continue"; + BlockKind[BlockKind["With"] = 5] = "With"; + })(ts.BlockKind || (ts.BlockKind = {})); + var BlockKind = ts.BlockKind; + (function (ExceptionBlockState) { + ExceptionBlockState[ExceptionBlockState["Try"] = 0] = "Try"; + ExceptionBlockState[ExceptionBlockState["Catch"] = 1] = "Catch"; + ExceptionBlockState[ExceptionBlockState["Finally"] = 2] = "Finally"; + ExceptionBlockState[ExceptionBlockState["Done"] = 3] = "Done"; + })(ts.ExceptionBlockState || (ts.ExceptionBlockState = {})); + var ExceptionBlockState = ts.ExceptionBlockState; + (function (FunctionBuilderFlags) { + FunctionBuilderFlags[FunctionBuilderFlags["HasProtectedRegions"] = 0x1] = "HasProtectedRegions"; + })(ts.FunctionBuilderFlags || (ts.FunctionBuilderFlags = {})); + var FunctionBuilderFlags = ts.FunctionBuilderFlags; (function (ExitStatus) { ExitStatus[ExitStatus["Success"] = 0] = "Success"; ExitStatus[ExitStatus["DiagnosticsPresent_OutputsSkipped"] = 1] = "DiagnosticsPresent_OutputsSkipped"; @@ -99,6 +137,49 @@ var ts; return result; } ts.map = map; + function flatMap(array, f) { + if (array) { + var result = []; + for (var i = 0, len = array.length; i < len; i++) { + var part = f(array[i]); + if (part) { + result.push.apply(result, part); + } + } + } + return result; + } + ts.flatMap = flatMap; + function foldLeft(array, f, initial) { + if (array) { + var count = array.length; + if (count > 0) { + var pos = 0; + var result = arguments.length <= 2 ? array[pos++] : initial; + while (pos < count) { + result = f(result, array[pos++]); + } + return result; + } + } + return initial; + } + ts.foldLeft = foldLeft; + function foldRight(array, f, initial) { + if (array) { + var count = array.length; + if (count > 0) { + var pos = count - 1; + var result = arguments.length <= 2 ? array[pos--] : initial; + while (pos >= 0) { + result = f(result, array[pos--]); + } + return result; + } + } + return initial; + } + ts.foldRight = foldRight; function concatenate(array1, array2) { if (!array2 || !array2.length) return array1; @@ -902,8 +983,12 @@ var ts; Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: 1, key: "Statements are not allowed in ambient contexts." }, A_declare_modifier_cannot_be_used_in_an_already_ambient_context: { code: 1038, category: 1, key: "A 'declare' modifier cannot be used in an already ambient context." }, Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: 1, key: "Initializers are not allowed in ambient contexts." }, + _0_modifier_cannot_be_used_in_an_ambient_context: { code: 1040, category: 1, key: "'{0}' modifier cannot be used in an ambient context." }, + _0_modifier_cannot_be_used_with_a_class_declaration: { code: 1041, category: 1, key: "'{0}' modifier cannot be used with a class declaration." }, + _0_modifier_cannot_be_used_here: { code: 1042, category: 1, key: "'{0}' modifier cannot be used here." }, + _0_modifier_cannot_appear_on_a_data_property: { code: 1043, category: 1, key: "'{0}' modifier cannot appear on a data property." }, _0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: 1, key: "'{0}' modifier cannot appear on a module element." }, - A_declare_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: 1, key: "A 'declare' modifier cannot be used with an interface declaration." }, + _0_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: 1, key: "'{0}' modifier cannot be used with an interface declaration." }, A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file: { code: 1046, category: 1, key: "A 'declare' modifier is required for a top level declaration in a .d.ts file." }, A_rest_parameter_cannot_be_optional: { code: 1047, category: 1, key: "A rest parameter cannot be optional." }, A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: 1, key: "A rest parameter cannot have an initializer." }, @@ -913,11 +998,13 @@ var ts; A_set_accessor_cannot_have_rest_parameter: { code: 1053, category: 1, key: "A 'set' accessor cannot have rest parameter." }, A_get_accessor_cannot_have_parameters: { code: 1054, category: 1, key: "A 'get' accessor cannot have parameters." }, Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1056, category: 1, key: "Accessors are only available when targeting ECMAScript 5 and higher." }, + An_async_function_or_method_must_have_a_valid_awaitable_return_type: { code: 1057, category: 1, key: "An async function or method must have a valid awaitable return type." }, + Type_for_await_does_not_have_a_valid_callable_then_member: { code: 1058, category: 1, key: "Type for 'await' does not have a valid callable 'then' member." }, Enum_member_must_have_initializer: { code: 1061, category: 1, key: "Enum member must have initializer." }, An_export_assignment_cannot_be_used_in_an_internal_module: { code: 1063, category: 1, key: "An export assignment cannot be used in an internal module." }, Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: 1, key: "Ambient enum elements can only have integer literal initializers." }, Unexpected_token_A_constructor_method_accessor_or_property_was_expected: { code: 1068, category: 1, key: "Unexpected token. A constructor, method, accessor, or property was expected." }, - A_declare_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: 1, key: "A 'declare' modifier cannot be used with an import declaration." }, + _0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: 1, key: "'{0}' modifier cannot be used with an import declaration." }, Invalid_reference_directive_syntax: { code: 1084, category: 1, key: "Invalid 'reference' directive syntax." }, Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: 1, key: "Octal literals are not available when targeting ECMAScript 5 and higher." }, An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: 1, key: "An accessor cannot be declared in an ambient context." }, @@ -989,7 +1076,7 @@ var ts; Unterminated_template_literal: { code: 1160, category: 1, key: "Unterminated template literal." }, Unterminated_regular_expression_literal: { code: 1161, category: 1, key: "Unterminated regular expression literal." }, An_object_member_cannot_be_declared_optional: { code: 1162, category: 1, key: "An object member cannot be declared optional." }, - yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: 1, key: "'yield' expression must be contained_within a generator declaration." }, + yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: 1, key: "'yield' expression must be contained within a generator declaration." }, Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: 1, key: "Computed property names are not allowed in enums." }, Computed_property_names_are_not_allowed_in_an_ambient_context: { code: 1165, category: 1, key: "Computed property names are not allowed in an ambient context." }, Computed_property_names_are_not_allowed_in_class_property_declarations: { code: 1166, category: 1, key: "Computed property names are not allowed in class property declarations." }, @@ -1011,10 +1098,22 @@ var ts; A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: 1, key: "A destructuring declaration must have an initializer." }, Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: 1, key: "Destructuring declarations are not allowed in ambient contexts." }, An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: 1, key: "An implementation cannot be declared in ambient contexts." }, - Modifiers_cannot_appear_here: { code: 1184, category: 1, key: "Modifiers cannot appear here." }, - Merge_conflict_marker_encountered: { code: 1185, category: 1, key: "Merge conflict marker encountered." }, - A_rest_element_cannot_have_an_initializer: { code: 1186, category: 1, key: "A rest element cannot have an initializer." }, - A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: 1, key: "A parameter property may not be a binding pattern." }, + Modifiers_cannot_appear_here: { code: 1185, category: 1, key: "Modifiers cannot appear here." }, + Merge_conflict_marker_encountered: { code: 1186, category: 1, key: "Merge conflict marker encountered." }, + A_rest_element_cannot_have_an_initializer: { code: 1187, category: 1, key: "A rest element cannot have an initializer." }, + A_parameter_property_may_not_be_a_binding_pattern: { code: 1188, category: 1, key: "A parameter property may not be a binding pattern." }, + with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: 1, key: "'with' statements are not allowed in an async function block." }, + _0_modifier_cannot_be_used_with_a_generator: { code: 1301, category: 1, key: "'{0}' modifier cannot be used with a generator." }, + _0_modifier_cannot_be_used_with_a_module_declaration: { code: 1302, category: 1, key: "'{0}' modifier cannot be used with a module declaration." }, + _0_modifier_cannot_be_used_with_an_enum_declaration: { code: 1303, category: 1, key: "'{0}' modifier cannot be used with an enum declaration." }, + _0_modifier_cannot_be_used_with_an_export_assignment_declaration: { code: 1304, category: 1, key: "'{0}' modifier cannot be used with an export assignment declaration." }, + _0_modifier_cannot_be_used_on_a_variable_statement: { code: 1305, category: 1, key: "'{0}' modifier cannot be used on a variable statement." }, + _0_modifier_cannot_be_used_with_a_type_declaration: { code: 1306, category: 1, key: "'{0}' modifier cannot be used with a type declaration." }, + _0_modifier_cannot_be_used_with_a_parameter_declaration: { code: 1307, category: 1, key: "'{0}' modifier cannot be used with a parameter declaration." }, + await_expression_must_be_contained_within_an_async_function: { code: 1308, category: 1, key: "'await' expression must be contained within an async function." }, + _0_modifier_cannot_be_used_on_an_object_literal_element: { code: 1309, category: 1, key: "'{0}' modifier cannot be used on an object literal element." }, + _0_expression_is_not_allowed_in_an_initializer: { code: 1310, category: 1, key: "'{0}' expression is not allowed in an initializer." }, + Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: 1, key: "Async functions are only available when targeting ECMAScript 6 and higher." }, Duplicate_identifier_0: { code: 2300, category: 1, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: 1, 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: 1, key: "Static members cannot reference class type parameters." }, @@ -1170,7 +1269,11 @@ var ts; A_computed_property_name_must_be_of_type_string_number_or_any: { code: 2464, category: 1, key: "A computed property name must be of type 'string', 'number', or 'any'." }, this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: 1, key: "'this' cannot be referenced in a computed property name." }, super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: 1, key: "'super' cannot be referenced in a computed property name." }, - A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2466, category: 1, key: "A computed property name cannot reference a type parameter from its containing type." }, + A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2467, category: 1, key: "A computed property name cannot reference a type parameter from its containing type." }, + Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2500, category: 1, 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: 2501, category: 1, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." }, + Duplicate_identifier_arguments_Compiler_uses_variable_declaration_arguments_to_capture_arguments_reference: { code: 2502, category: 1, key: "Duplicate identifier '_arguments'. Compiler uses variable declaration '_arguments' to capture 'arguments' reference." }, + Expression_resolves_to_variable_declaration_arguments_that_compiler_uses_to_capture_arguments_reference: { code: 2503, category: 1, key: "Expression resolves to variable declaration '_arguments' that compiler uses to capture 'arguments' reference." }, Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher: { code: 2468, category: 1, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1, 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: 1, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, @@ -1249,6 +1352,7 @@ var ts; const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: { code: 4087, category: 1, key: "'const' enum member initializer was evaluated to disallowed value 'NaN'." }, Property_0_does_not_exist_on_const_enum_1: { code: 4088, category: 1, key: "Property '{0}' does not exist on 'const' enum '{1}'." }, let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations: { code: 4089, category: 1, key: "'let' is not allowed to be used as a name in 'let' or 'const' declarations." }, + Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1: { code: 4090, category: 1, key: "Cannot initialize outer scoped variable '{0}' in the same scope as block scoped declaration '{1}'." }, The_current_host_does_not_support_the_0_option: { code: 5001, category: 1, key: "The current host does not support the '{0}' option." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: 1, key: "Cannot find the common subdirectory path for the input files." }, Cannot_read_file_0_Colon_1: { code: 5012, category: 1, key: "Cannot read file '{0}': {1}" }, @@ -1304,6 +1408,8 @@ var ts; File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: 1, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: 2, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: 2, key: "Do not emit declarations for code that has an '@internal' annotation." }, + Emit_async_functions_when_ECMAScript_target_version_is_lower_than_ES6: { code: 6057, category: 2, key: "Emit async functions when ECMAScript target version is lower than 'ES6'." }, + Do_not_emit_runtime_helper_functions_e_g_extends_awaiter_Assumes_manual_reference_to_tslib_js: { code: 6058, category: 2, key: "Do not emit runtime helper functions (e.g. '__extends', '__awaiter'). Assumes manual reference to tslib.js." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: 1, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: 1, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: 1, key: "Member '{0}' implicitly has an '{1}' type." }, @@ -1386,6 +1492,8 @@ var ts; "while": 99, "with": 100, "yield": 109, + "async": 121, + "await": 122, "{": 14, "}": 15, "(": 16, @@ -1555,6 +1663,8 @@ var ts; } ts.isOctalDigit = isOctalDigit; function skipTrivia(text, pos, stopAfterLineBreak) { + if (pos < 0) + return pos; while (true) { var ch = text.charCodeAt(pos); switch (ch) { @@ -2480,13 +2590,10 @@ var ts; writeParameter: writeText, writeSymbol: writeText, writeLine: function () { return str += " "; }, - increaseIndent: function () { - }, - decreaseIndent: function () { - }, + increaseIndent: function () { }, + decreaseIndent: function () { }, clear: function () { return str = ""; }, - trackSymbol: function () { - } + trackSymbol: function () { } }; } return stringWriters.pop(); @@ -2503,20 +2610,38 @@ var ts; ts.getFullWidth = getFullWidth; function containsParseError(node) { aggregateChildData(node); - return (node.parserContextFlags & 32) !== 0; + return (node.parserContextFlags & 128) !== 0; } ts.containsParseError = containsParseError; + function isAwaitOrYield(node) { + return node && (node.kind === 163 || node.kind === 169); + } + ts.isAwaitOrYield = isAwaitOrYield; + function hasAwaitOrYield(node) { + if (!node) { + return false; + } + aggregateChildData(node); + return (node.parserContextFlags & 256) !== 0; + } + ts.hasAwaitOrYield = hasAwaitOrYield; function aggregateChildData(node) { - if (!(node.parserContextFlags & 64)) { + if (!(node.parserContextFlags & 512)) { var thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & 16) !== 0) || ts.forEachChild(node, containsParseError); if (thisNodeOrAnySubNodesHasError) { - node.parserContextFlags |= 32; + node.parserContextFlags |= 128; + } + if (!isAnyFunction(node)) { + var thisNodeOrAnySubNodesHasAwaitOrYield = isAwaitOrYield(node) || ts.forEachChild(node, hasAwaitOrYield); + if (thisNodeOrAnySubNodesHasAwaitOrYield) { + node.parserContextFlags |= 256; + } } - node.parserContextFlags |= 64; + node.parserContextFlags |= 512; } } function getSourceFileOfNode(node) { - while (node && node.kind !== 207) { + while (node && node.kind !== 211) { node = node.parent; } return node; @@ -2536,13 +2661,25 @@ var ts; if (!node) { return true; } - return node.pos === node.end && node.kind !== 1; + return node.pos === node.end && node.kind !== 1 && node.pos >= 0; } ts.nodeIsMissing = nodeIsMissing; + function nodeIsGenerated(node) { + return node && node.pos === node.end && node.kind !== 1 && node.pos < 0; + } + ts.nodeIsGenerated = nodeIsGenerated; + function nodeIsMissingOrGenerated(node) { + return nodeIsMissing(node) || nodeIsGenerated(node); + } + ts.nodeIsMissingOrGenerated = nodeIsMissingOrGenerated; function nodeIsPresent(node) { - return !nodeIsMissing(node); + return !nodeIsMissingOrGenerated(node); } ts.nodeIsPresent = nodeIsPresent; + function nodeIsPresentOrGenerated(node) { + return !nodeIsMissing(node); + } + ts.nodeIsPresentOrGenerated = nodeIsPresentOrGenerated; function getTokenPosOfNode(node, sourceFile) { if (nodeIsMissing(node)) { return node.pos; @@ -2607,13 +2744,13 @@ var ts; function getErrorSpanForNode(node) { var errorSpan; switch (node.kind) { - case 188: - case 146: - case 191: case 192: + case 148: case 195: - case 194: - case 206: + case 196: + case 199: + case 198: + case 210: errorSpan = node.name; break; } @@ -2629,11 +2766,11 @@ var ts; } ts.isDeclarationFile = isDeclarationFile; function isConstEnumDeclaration(node) { - return node.kind === 194 && isConst(node); + return node.kind === 198 && isConst(node); } ts.isConstEnumDeclaration = isConstEnumDeclaration; function walkUpBindingElementsAndPatterns(node) { - while (node && (node.kind === 146 || isBindingPattern(node))) { + while (node && (node.kind === 148 || isBindingPattern(node))) { node = node.parent; } return node; @@ -2641,14 +2778,14 @@ var ts; function getCombinedNodeFlags(node) { node = walkUpBindingElementsAndPatterns(node); var flags = node.flags; - if (node.kind === 188) { + if (node.kind === 192) { node = node.parent; } - if (node && node.kind === 189) { + if (node && node.kind === 193) { flags |= node.flags; node = node.parent; } - if (node && node.kind === 171) { + if (node && node.kind === 175) { flags |= node.flags; } return flags; @@ -2663,12 +2800,12 @@ var ts; } ts.isLet = isLet; function isPrologueDirective(node) { - return node.kind === 173 && node.expression.kind === 8; + return node.kind === 177 && node.expression.kind === 8; } ts.isPrologueDirective = isPrologueDirective; function getLeadingCommentRangesOfNode(node, sourceFileOfNode) { sourceFileOfNode = sourceFileOfNode || getSourceFileOfNode(node); - if (node.kind === 124 || node.kind === 123) { + if (node.kind === 126 || node.kind === 125) { return ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)); } else { @@ -2688,21 +2825,21 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 181: + case 185: return visitor(node); - case 170: case 174: - case 175: - case 176: - case 177: case 178: + case 179: + case 180: + case 181: case 182: - case 183: - case 200: - case 201: - case 184: case 186: - case 203: + case 187: + case 204: + case 205: + case 188: + case 190: + case 207: return ts.forEachChild(node, traverse); } } @@ -2711,22 +2848,22 @@ var ts; function isAnyFunction(node) { if (node) { switch (node.kind) { - case 129: - case 156: - case 190: - case 157: - case 128: - case 127: - case 130: case 131: + case 158: + case 194: + case 159: + case 130: + case 129: case 132: case 133: case 134: + case 135: case 136: - case 137: - case 156: - case 157: - case 190: + case 138: + case 139: + case 158: + case 159: + case 194: return true; } } @@ -2734,13 +2871,27 @@ var ts; } ts.isAnyFunction = isAnyFunction; function isFunctionBlock(node) { - return node && node.kind === 170 && isAnyFunction(node.parent); + return node && node.kind === 174 && isAnyFunction(node.parent); } ts.isFunctionBlock = isFunctionBlock; function isObjectLiteralMethod(node) { - return node && node.kind === 128 && node.parent.kind === 148; + return node && node.kind === 130 && node.parent.kind === 150; } ts.isObjectLiteralMethod = isObjectLiteralMethod; + function isObjectLiteralElement(node) { + if (node) { + switch (node.kind) { + case 208: + case 209: + case 130: + case 132: + case 133: + return true; + } + } + return false; + } + ts.isObjectLiteralElement = isObjectLiteralElement; function getContainingFunction(node) { while (true) { node = node.parent; @@ -2750,6 +2901,18 @@ var ts; } } ts.getContainingFunction = getContainingFunction; + function getContainingParameter(node) { + while (true) { + node = node.parent; + if (!node || isAnyFunction(node)) { + break; + } + if (node.kind === 126) { + return node; + } + } + } + ts.getContainingParameter = getContainingParameter; function getThisContainer(node, includeArrowFunctions) { while (true) { node = node.parent; @@ -2757,28 +2920,28 @@ var ts; return undefined; } switch (node.kind) { - case 122: - if (node.parent.parent.kind === 191) { + case 124: + if (node.parent.parent.kind === 195) { return node; } node = node.parent; break; - case 157: + case 159: if (!includeArrowFunctions) { continue; } - case 190: - case 156: - case 195: - case 126: - case 125: + case 194: + case 158: + case 199: case 128: case 127: - case 129: case 130: + case 129: case 131: - case 194: - case 207: + case 132: + case 133: + case 198: + case 211: return node; } } @@ -2790,32 +2953,32 @@ var ts; if (!node) return node; switch (node.kind) { - case 122: - if (node.parent.parent.kind === 191) { + case 124: + if (node.parent.parent.kind === 195) { return node; } node = node.parent; break; - case 190: - case 156: - case 157: + case 194: + case 158: + case 159: if (!includeFunctions) { continue; } - case 126: - case 125: case 128: case 127: - case 129: case 130: + case 129: case 131: + case 132: + case 133: return node; } } } ts.getSuperContainer = getSuperContainer; function getInvokedExpression(node) { - if (node.kind === 153) { + if (node.kind === 155) { return node.tag; } return node.expression; @@ -2829,8 +2992,6 @@ var ts; case 94: case 79: case 9: - case 147: - case 148: case 149: case 150: case 151: @@ -2840,61 +3001,64 @@ var ts; case 155: case 156: case 157: - case 160: case 158: case 159: - case 161: case 162: + case 160: + case 161: case 163: case 164: - case 167: case 165: - case 10: + case 166: + case 167: + case 171: case 168: + case 10: + case 172: return true; - case 121: - while (node.parent.kind === 121) { + case 123: + while (node.parent.kind === 123) { node = node.parent; } - return node.parent.kind === 138; + return node.parent.kind === 140; case 64: - if (node.parent.kind === 138) { + if (node.parent.kind === 140) { return true; } case 7: case 8: var parent = node.parent; switch (parent.kind) { - case 188: - case 124: + case 192: case 126: - case 125: - case 206: - case 204: - case 146: + case 128: + case 127: + case 210: + case 208: + case 148: return parent.initializer === node; - case 173: - case 174: - case 175: - case 176: - case 181: - case 182: - case 183: - case 200: + case 177: + case 178: + case 179: + case 180: case 185: - case 183: + case 186: + case 187: + case 204: + case 189: + case 187: return parent.expression === node; - case 177: + case 181: var forStatement = parent; - return (forStatement.initializer === node && forStatement.initializer.kind !== 189) || forStatement.condition === node || forStatement.iterator === node; - case 178: + return (forStatement.initializer === node && forStatement.initializer.kind !== 193) || forStatement.condition === node || forStatement.iterator === node; + case 182: var forInStatement = parent; - return (forInStatement.initializer === node && forInStatement.initializer.kind !== 189) || forInStatement.expression === node; - case 154: + return (forInStatement.initializer === node && forInStatement.initializer.kind !== 193) || forInStatement.expression === node; + case 156: return node === parent.expression; - case 169: + case 173: return node === parent.expression; - case 122: + case 124: return node === parent.expression; default: if (isExpression(parent)) { @@ -2905,13 +3069,93 @@ var ts; return false; } ts.isExpression = isExpression; + function isUnaryExpression(node) { + switch (node.kind) { + case 156: + case 160: + case 161: + case 162: + case 163: + case 164: + case 165: + return true; + default: + return ts.isLeftHandSideExpression(node); + } + } + ts.isUnaryExpression = isUnaryExpression; + function isLabeledOrIterationOrSwitchStatement(node) { + switch (node.kind) { + case 179: + case 180: + case 181: + case 182: + case 187: + case 188: + return true; + } + return false; + } + ts.isLabeledOrIterationOrSwitchStatement = isLabeledOrIterationOrSwitchStatement; + function isLogicalBinary(node) { + switch (node.operator) { + case 48: + case 49: + return true; + } + return false; + } + ts.isLogicalBinary = isLogicalBinary; + function isAssignment(node) { + switch (node.operator) { + case 52: + case 53: + case 54: + case 55: + case 56: + case 57: + case 58: + case 59: + case 60: + case 61: + case 62: + case 63: + return true; + } + return false; + } + ts.isAssignment = isAssignment; + function isDestructuringAssignment(node) { + if (node.operator === 52) { + var left = node.left; + while (left.kind === 157) { + left = left.expression; + } + switch (left.kind) { + case 150: + case 149: + return true; + } + } + return false; + } + ts.isDestructuringAssignment = isDestructuringAssignment; + function isAnyAccessor(node) { + switch (node.kind) { + case 132: + case 133: + return true; + } + return false; + } + ts.isAnyAccessor = isAnyAccessor; function isInstantiatedModule(node, preserveConstEnums) { var moduleState = ts.getModuleInstanceState(node); return moduleState === 1 || (preserveConstEnums && moduleState === 2); } ts.isInstantiatedModule = isInstantiatedModule; function isExternalModuleImportDeclaration(node) { - return node.kind === 197 && node.moduleReference.kind === 199; + return node.kind === 201 && node.moduleReference.kind === 203; } ts.isExternalModuleImportDeclaration = isExternalModuleImportDeclaration; function getExternalModuleImportDeclarationExpression(node) { @@ -2920,26 +3164,26 @@ var ts; } ts.getExternalModuleImportDeclarationExpression = getExternalModuleImportDeclarationExpression; function isInternalModuleImportDeclaration(node) { - return node.kind === 197 && node.moduleReference.kind !== 199; + return node.kind === 201 && node.moduleReference.kind !== 203; } ts.isInternalModuleImportDeclaration = isInternalModuleImportDeclaration; function hasDotDotDotToken(node) { - return node && node.kind === 124 && node.dotDotDotToken !== undefined; + return node && node.kind === 126 && node.dotDotDotToken !== undefined; } ts.hasDotDotDotToken = hasDotDotDotToken; function hasQuestionToken(node) { if (node) { switch (node.kind) { - case 124: + case 126: + return node.questionToken !== undefined; + case 130: + case 129: return node.questionToken !== undefined; + case 209: + case 208: case 128: case 127: return node.questionToken !== undefined; - case 205: - case 204: - case 126: - case 125: - return node.questionToken !== undefined; } } return false; @@ -2961,10 +3205,18 @@ var ts; return 10 <= kind && kind <= 13; } ts.isTemplateLiteralKind = isTemplateLiteralKind; + function isTemplateLiteralOrTemplateExpression(node) { + return node.kind === 168 || isTemplateLiteralKind(node.kind); + } + ts.isTemplateLiteralOrTemplateExpression = isTemplateLiteralOrTemplateExpression; function isBindingPattern(node) { - return node.kind === 145 || node.kind === 144; + return node.kind === 147 || node.kind === 146; } ts.isBindingPattern = isBindingPattern; + function isIdentifierOrBindingPattern(node) { + return node.kind === 64 || isBindingPattern(node); + } + ts.isIdentifierOrBindingPattern = isIdentifierOrBindingPattern; function isInAmbientContext(node) { while (node) { if (node.flags & (2 | 1024)) { @@ -2977,27 +3229,27 @@ var ts; ts.isInAmbientContext = isInAmbientContext; function isDeclaration(node) { switch (node.kind) { - case 123: - case 124: - case 188: - case 146: - case 126: case 125: - case 204: - case 205: - case 206: + case 126: + case 192: + case 148: case 128: case 127: - case 190: + case 208: + case 209: + case 210: case 130: - case 131: case 129: - case 191: - case 192: - case 193: case 194: + case 132: + case 133: + case 131: case 195: + case 196: case 197: + case 198: + case 199: + case 201: return true; } return false; @@ -3005,39 +3257,53 @@ var ts; ts.isDeclaration = isDeclaration; function isStatement(n) { switch (n.kind) { - case 180: + case 184: + case 183: + case 191: case 179: - case 187: - case 175: - case 173: - case 172: - case 178: case 177: - case 174: - case 184: + case 176: + case 182: case 181: - case 183: + case 178: + case 188: + case 185: + case 187: case 93: + case 189: + case 190: + case 175: + case 180: case 186: - case 171: - case 176: - case 182: - case 198: + case 202: return true; default: return false; } } ts.isStatement = isStatement; + function needsParenthesisForPropertyAccess(expression) { + if (expression.parent) { + switch (expression.parent.kind) { + case 177: + case 189: + case 185: + case 157: + return false; + } + } + return !ts.isLeftHandSideExpression(expression); + } + ts.needsParenthesisForPropertyAccess = needsParenthesisForPropertyAccess; function isDeclarationOrFunctionExpressionOrCatchVariableName(name) { if (name.kind !== 64 && name.kind !== 8 && name.kind !== 7) { return false; } var parent = name.parent; - if (isDeclaration(parent) || parent.kind === 156) { + if (isDeclaration(parent) || parent.kind === 158) { return parent.name === name; } - if (parent.kind === 203) { + if (parent.kind === 207) { return parent.name === name; } return false; @@ -3079,16 +3345,16 @@ var ts; ts.tryResolveScriptReference = tryResolveScriptReference; function getAncestor(node, kind) { switch (kind) { - case 191: + case 195: while (node) { switch (node.kind) { - case 191: - return node; - case 194: - case 192: - case 193: case 195: + return node; + case 198: + case 196: case 197: + case 199: + case 201: return undefined; default: node = node.parent; @@ -3143,13 +3409,17 @@ var ts; } ts.getFileReferenceFromReferencePath = getFileReferenceFromReferencePath; function isKeyword(token) { - return 65 <= token && token <= 120; + return 65 <= token && token <= 122; } ts.isKeyword = isKeyword; function isTrivia(token) { return 2 <= token && token <= 6; } ts.isTrivia = isTrivia; + function isAsyncFunction(node) { + return (node.flags & 16384) !== 0; + } + ts.isAsyncFunction = isAsyncFunction; function isModifier(token) { switch (token) { case 107: @@ -3159,6 +3429,7 @@ var ts; case 77: case 113: case 69: + case 121: return true; } return false; @@ -3338,10 +3609,31 @@ var ts; } } ts.createDiagnosticCollection = createDiagnosticCollection; + function reportUnexpectedNode(node) { + var nodeKind = node ? getSyntaxKind(node.kind) : "Unknown"; + ts.Debug.fail("Unexpected node: " + nodeKind); + } + ts.reportUnexpectedNode = reportUnexpectedNode; + function reportUnexpectedNodeAfterVisit(visited, node) { + var visitedKind = visited ? getSyntaxKind(visited.kind) : "Unknown"; + var nodeKind = node ? getSyntaxKind(node.kind) : "Unknown"; + ts.Debug.fail("Unexpected node after visit: " + visitedKind + ", source: " + nodeKind); + } + ts.reportUnexpectedNodeAfterVisit = reportUnexpectedNodeAfterVisit; + function getSyntaxKind(kind) { + var nodeKind; + if (typeof ts.SyntaxKind === "object") { + nodeKind = ts.SyntaxKind[kind]; + } + else { + nodeKind = "SyntaxKind[" + String(kind) + "]"; + } + return nodeKind; + } })(ts || (ts = {})); var ts; (function (ts) { - var nodeConstructors = new Array(209); + var nodeConstructors = new Array(213); ts.parseTime = 0; function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); @@ -3378,152 +3670,154 @@ var ts; var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode; var cbNodes = cbNodeArray || cbNode; switch (node.kind) { - case 121: - return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 123: + return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); + case 125: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); - case 124: case 126: - case 125: - case 204: - case 205: - case 188: - case 146: + case 128: + case 127: + case 208: + case 209: + case 192: + case 148: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.dotDotDotToken) || visitNode(cbNode, node.name) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type) || visitNode(cbNode, node.initializer); - case 136: - case 137: - case 132: - case 133: + case 138: + case 139: case 134: + case 135: + case 136: return visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); - case 128: - case 127: - case 129: case 130: + case 129: case 131: - case 156: - case 190: - case 157: + case 132: + case 133: + case 158: + case 194: + case 159: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.name) || visitNode(cbNode, node.questionToken) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type) || visitNode(cbNode, node.body); - case 135: + case 137: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); - case 138: - return visitNode(cbNode, node.exprName); - case 139: - return visitNodes(cbNodes, node.members); case 140: - return visitNode(cbNode, node.elementType); + return visitNode(cbNode, node.exprName); case 141: - return visitNodes(cbNodes, node.elementTypes); + return visitNodes(cbNodes, node.members); case 142: - return visitNodes(cbNodes, node.types); + return visitNode(cbNode, node.elementType); case 143: - return visitNode(cbNode, node.type); + return visitNodes(cbNodes, node.elementTypes); case 144: + return visitNodes(cbNodes, node.types); case 145: - return visitNodes(cbNodes, node.elements); + return visitNode(cbNode, node.type); + case 146: case 147: return visitNodes(cbNodes, node.elements); - case 148: - return visitNodes(cbNodes, node.properties); case 149: - return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); + return visitNodes(cbNodes, node.elements); case 150: - return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); + return visitNodes(cbNodes, node.properties); case 151: + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 152: - return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 153: - return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 154: - return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); + return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 155: - return visitNode(cbNode, node.expression); - case 158: - return visitNode(cbNode, node.expression); - case 159: + return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); + case 156: + return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); + case 157: return visitNode(cbNode, node.expression); case 160: return visitNode(cbNode, node.expression); case 161: - return visitNode(cbNode, node.operand); - case 166: - return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); + return visitNode(cbNode, node.expression); case 162: + return visitNode(cbNode, node.expression); + case 164: return visitNode(cbNode, node.operand); + case 169: + return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 163: + return visitNode(cbNode, node.expression); + case 165: + return visitNode(cbNode, node.operand); + case 166: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); - case 164: - return visitNode(cbNode, node.condition) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.whenFalse); case 167: + return visitNode(cbNode, node.condition) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.whenFalse); + case 171: return visitNode(cbNode, node.expression); - case 170: - case 196: + case 174: + case 200: return visitNodes(cbNodes, node.statements); - case 207: + case 211: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); - case 171: + case 175: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); - case 189: + case 193: return visitNodes(cbNodes, node.declarations); - case 173: + case 177: return visitNode(cbNode, node.expression); - case 174: + case 178: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); - case 175: + case 179: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); - case 176: + case 180: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 177: + case 181: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.iterator) || visitNode(cbNode, node.statement); - case 178: + case 182: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 179: - case 180: + case 183: + case 184: return visitNode(cbNode, node.label); - case 181: + case 185: return visitNode(cbNode, node.expression); - case 182: + case 186: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 183: + case 187: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.clauses); - case 200: + case 204: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); - case 201: + case 205: return visitNodes(cbNodes, node.statements); - case 184: + case 188: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); - case 185: + case 189: return visitNode(cbNode, node.expression); - case 186: + case 190: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); - case 203: + case 207: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type) || visitNode(cbNode, node.block); - case 191: + case 195: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); - case 192: + case 196: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); - case 193: + case 197: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.type); - case 194: + case 198: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); - case 206: + case 210: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); - case 195: + case 199: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); - case 197: + case 201: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); - case 198: + case 202: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportName); - case 165: + case 168: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); - case 169: + case 173: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); - case 122: + case 124: return visitNode(cbNode, node.expression); - case 202: + case 206: return visitNodes(cbNodes, node.types); - case 199: + case 203: return visitNode(cbNode, node.expression); } } @@ -3562,6 +3856,7 @@ var ts; case 77: return 1; case 113: return 2; case 69: return 4096; + case 121: return 16384; } return 0; } @@ -3874,7 +4169,7 @@ var ts; var identifierCount = 0; var nodeCount = 0; var token; - var sourceFile = createNode(207, 0); + var sourceFile = createNode(211, 0); sourceFile.pos = 0; sourceFile.end = sourceText.length; sourceFile.text = sourceText; @@ -3920,6 +4215,12 @@ var ts; function setGeneratorParameterContext(val) { setContextFlag(val, 8); } + function setAwaitContext(val) { + setContextFlag(val, 64); + } + function setAsyncParameterContext(val) { + setContextFlag(val, 32); + } function allowInAnd(func) { if (contextFlags & 2) { setDisallowInContext(false); @@ -3938,21 +4239,16 @@ var ts; setDisallowInContext(false); return result; } - function doInYieldContext(func) { - if (contextFlags & 4) { - return func(); - } - setYieldContext(true); + function doOutsideOfYieldOrAwaitOrParameterContext(func) { + var saveContextFlags = contextFlags & 108; + contextFlags &= ~saveContextFlags; var result = func(); - setYieldContext(false); + contextFlags |= saveContextFlags; return result; } - function doOutsideOfYieldContext(func) { - if (contextFlags & 4) { - setYieldContext(false); - var result = func(); - setYieldContext(true); - return result; + function doOutsideOfYieldOrAwaitOrParameterContextWhenInParameter(func) { + if (contextFlags & (32 | 8)) { + return doOutsideOfYieldOrAwaitOrParameterContext(func); } return func(); } @@ -3968,6 +4264,12 @@ var ts; function inDisallowInContext() { return (contextFlags & 2) !== 0; } + function inAwaitContext() { + return (contextFlags & 64) !== 0; + } + function inAsyncParameterContext() { + return (contextFlags & 32) !== 0; + } function parseErrorAtCurrentToken(message, arg0) { var start = scanner.getTokenPos(); var length = scanner.getTextPos() - start; @@ -4032,6 +4334,9 @@ var ts; if (token === 109 && inYieldContext()) { return false; } + if (token === 122 && inAwaitContext()) { + return false; + } return inStrictModeContext() ? token > 109 : token > 100; } function parseExpected(kind, diagnosticMessage) { @@ -4144,37 +4449,45 @@ var ts; return parseIdentifierName(); } function parseComputedPropertyName() { - var node = createNode(122); + var node = createNode(124); parseExpected(18); - var yieldContext = inYieldContext(); - if (inGeneratorParameterContext()) { - setYieldContext(false); - } - node.expression = allowInAnd(parseExpression); - if (inGeneratorParameterContext()) { - setYieldContext(yieldContext); - } + node.expression = doOutsideOfYieldOrAwaitOrParameterContextWhenInParameter(parseExpression); parseExpected(19); return finishNode(node); } - function parseContextualModifier(t) { - return token === t && tryParse(nextTokenCanFollowModifier); + function allowInAndParseExpression() { + return allowInAnd(parseExpression); + } + function parseContextualModifier(t, isArrowFunction) { + return token === t && tryParse(isArrowFunction ? nextTokenCanFollowModifierForArrowFunction : nextTokenCanFollowModifier); + } + function nextTokenCanFollowModifierForArrowFunction() { + return nextTokenCanFollowModifier(true); } - function nextTokenCanFollowModifier() { + function nextTokenCanFollowModifier(isArrowFunction) { nextToken(); - return canFollowModifier(); + return canFollowModifier(isArrowFunction); } - function parseAnyContextualModifier() { - return ts.isModifier(token) && tryParse(nextTokenCanFollowContextualModifier); + function parseAnyContextualModifier(isArrowFunction) { + return ts.isModifier(token) && tryParse(isArrowFunction ? nextTokenCanFollowContextualModifierForArrowFunction : nextTokenCanFollowContextualModifier); } - function nextTokenCanFollowContextualModifier() { + function nextTokenCanFollowContextualModifierForArrowFunction() { + return nextTokenCanFollowContextualModifier(true); + } + function nextTokenCanFollowContextualModifier(isArrowFunction) { if (token === 69) { return nextToken() === 76; } nextToken(); - return canFollowModifier(); + return canFollowModifier(isArrowFunction); } - function canFollowModifier() { + function canFollowModifier(isArrowFunction) { + if (isArrowFunction) { + if (scanner.hasPrecedingLineBreak()) { + return false; + } + return token === 16 || token === 24; + } return token === 18 || token === 14 || token === 35 || isLiteralPropertyName(); } function isListElement(parsingContext, inErrorRecovery) { @@ -4204,9 +4517,9 @@ var ts; case 8: return isIdentifier() && !isNotHeritageClauseTypeName(); case 9: - return isIdentifierOrPattern(); + return isIdentifierOrBindingPattern(); case 11: - return token === 23 || token === 21 || isIdentifierOrPattern(); + return token === 23 || token === 21 || isIdentifierOrBindingPattern(); case 16: return isIdentifier(); case 12: @@ -4346,7 +4659,7 @@ var ts; if (ts.containsParseError(node)) { return undefined; } - var nodeContextFlags = node.parserContextFlags & 31; + var nodeContextFlags = node.parserContextFlags & 127; if (nodeContextFlags !== contextFlags) { return undefined; } @@ -4392,12 +4705,12 @@ var ts; function isReusableModuleElement(node) { if (node) { switch (node.kind) { - case 197: - case 198: - case 191: - case 192: + case 201: + case 202: case 195: - case 194: + case 196: + case 199: + case 198: return true; } return isReusableStatement(node); @@ -4407,12 +4720,12 @@ var ts; function isReusableClassMember(node) { if (node) { switch (node.kind) { - case 129: - case 134: - case 128: - case 130: case 131: - case 126: + case 136: + case 130: + case 132: + case 133: + case 128: return true; } } @@ -4421,8 +4734,8 @@ var ts; function isReusableSwitchClause(node) { if (node) { switch (node.kind) { - case 200: - case 201: + case 204: + case 205: return true; } } @@ -4431,55 +4744,55 @@ var ts; function isReusableStatement(node) { if (node) { switch (node.kind) { - case 190: - case 171: - case 170: + case 194: + case 175: case 174: - case 173: - case 185: - case 181: - case 183: - case 180: - case 179: case 178: case 177: - case 176: + case 189: + case 185: + case 187: + case 184: + case 183: case 182: - case 172: + case 181: + case 180: case 186: - case 184: - case 175: - case 187: + case 176: + case 190: + case 188: + case 179: + case 191: return true; } } return false; } function isReusableEnumMember(node) { - return node.kind === 206; + return node.kind === 210; } function isReusableTypeMember(node) { if (node) { switch (node.kind) { - case 133: + case 135: + case 129: + case 136: case 127: case 134: - case 125: - case 132: return true; } } return false; } function isReusableVariableDeclaration(node) { - if (node.kind !== 188) { + if (node.kind !== 192) { return false; } var variableDeclarator = node; return variableDeclarator.initializer === undefined; } function isReusableParameter(node) { - if (node.kind !== 124) { + if (node.kind !== 126) { return false; } var parameter = node; @@ -4548,7 +4861,7 @@ var ts; function parseEntityName(allowReservedWords, diagnosticMessage) { var entity = parseIdentifier(diagnosticMessage); while (parseOptional(20)) { - var node = createNode(121, entity.pos); + var node = createNode(123, entity.pos); node.left = entity; node.right = parseRightSideOfDot(allowReservedWords); entity = finishNode(node); @@ -4570,7 +4883,7 @@ var ts; return finishNode(node); } function parseTemplateExpression() { - var template = createNode(165); + var template = createNode(168); template.head = parseLiteralNode(); ts.Debug.assert(template.head.kind === 11, "Template head has wrong token kind"); var templateSpans = []; @@ -4583,7 +4896,7 @@ var ts; return finishNode(template); } function parseTemplateSpan() { - var span = createNode(169); + var span = createNode(173); span.expression = allowInAnd(parseExpression); var literal; if (token === 15) { @@ -4612,7 +4925,7 @@ var ts; return node; } function parseTypeReference() { - var node = createNode(135); + var node = createNode(137); node.typeName = parseEntityName(false, ts.Diagnostics.Type_expected); if (!scanner.hasPrecedingLineBreak() && token === 24) { node.typeArguments = parseBracketedList(17, parseType, 24, 25); @@ -4620,13 +4933,13 @@ var ts; return finishNode(node); } function parseTypeQuery() { - var node = createNode(138); + var node = createNode(140); parseExpected(96); node.exprName = parseEntityName(true); return finishNode(node); } function parseTypeParameter() { - var node = createNode(123); + var node = createNode(125); node.name = parseIdentifier(); if (parseOptional(78)) { if (isStartOfType() || !isStartOfExpression()) { @@ -4650,7 +4963,7 @@ var ts; return undefined; } function isStartOfParameter() { - return token === 21 || isIdentifierOrPattern() || ts.isModifier(token); + return token === 21 || isIdentifierOrBindingPattern() || ts.isModifier(token); } function setModifiers(node, modifiers) { if (modifiers) { @@ -4659,25 +4972,22 @@ var ts; } } function parseParameter() { - var node = createNode(124); + var node = createNode(126); setModifiers(node, parseModifiers()); node.dotDotDotToken = parseOptionalToken(21); - node.name = inGeneratorParameterContext() ? doInYieldContext(parseIdentifierOrPattern) : parseIdentifierOrPattern(); + node.name = parseIdentifierOrBindingPattern(true); if (ts.getFullWidth(node.name) === 0 && node.flags === 0 && ts.isModifier(token)) { nextToken(); } node.questionToken = parseOptionalToken(50); node.type = parseParameterType(); - node.initializer = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseParameterInitializer) : parseParameterInitializer(); + node.initializer = parseBindingElementInitializer(true); return finishNode(node); } - function parseParameterInitializer() { - return parseInitializer(true); - } - function fillSignature(returnToken, yieldAndGeneratorParameterContext, requireCompleteParameterList, signature) { + function fillSignature(returnToken, yieldAndGeneratorParameterContext, awaitAndAsyncParameterContext, requireCompleteParameterList, signature) { var returnTokenRequired = returnToken === 32; signature.typeParameters = parseTypeParameters(); - signature.parameters = parseParameterList(yieldAndGeneratorParameterContext, requireCompleteParameterList); + signature.parameters = parseParameterList(yieldAndGeneratorParameterContext, awaitAndAsyncParameterContext, requireCompleteParameterList); if (returnTokenRequired) { parseExpected(returnToken); signature.type = parseType(); @@ -4686,15 +4996,27 @@ var ts; signature.type = parseType(); } } - function parseParameterList(yieldAndGeneratorParameterContext, requireCompleteParameterList) { + function parseParameterList(yieldAndGeneratorParameterContext, awaitAndAsyncParameterContext, requireCompleteParameterList) { if (parseExpected(16)) { - var savedYieldContext = inYieldContext(); - var savedGeneratorParameterContext = inGeneratorParameterContext(); - setYieldContext(yieldAndGeneratorParameterContext); - setGeneratorParameterContext(yieldAndGeneratorParameterContext); + if (yieldAndGeneratorParameterContext || awaitAndAsyncParameterContext) { + var saveContextFlags = contextFlags & 108; + if (yieldAndGeneratorParameterContext) { + contextFlags |= 4 | 8; + } + else { + contextFlags &= ~8; + } + if (awaitAndAsyncParameterContext) { + contextFlags |= 64 | 32; + } + else { + contextFlags &= ~32; + } + } var result = parseDelimitedList(15, parseParameter); - setYieldContext(savedYieldContext); - setGeneratorParameterContext(savedGeneratorParameterContext); + if (yieldAndGeneratorParameterContext || awaitAndAsyncParameterContext) { + contextFlags = (contextFlags & ~108) | saveContextFlags; + } if (!parseExpected(17) && requireCompleteParameterList) { return undefined; } @@ -4702,6 +5024,9 @@ var ts; } return requireCompleteParameterList ? undefined : createMissingList(); } + function parseDelimitedParameterList() { + return parseDelimitedList(15, parseParameter); + } function parseTypeMemberSemicolon() { if (parseSemicolon()) { return; @@ -4710,10 +5035,10 @@ var ts; } function parseSignatureMember(kind) { var node = createNode(kind); - if (kind === 133) { + if (kind === 135) { parseExpected(87); } - fillSignature(51, false, false, node); + fillSignature(51, false, false, false, node); parseTypeMemberSemicolon(); return finishNode(node); } @@ -4751,7 +5076,7 @@ var ts; } function parseIndexSignatureDeclaration(modifiers) { var fullStart = modifiers ? modifiers.pos : scanner.getStartPos(); - var node = createNode(134, fullStart); + var node = createNode(136, fullStart); setModifiers(node, modifiers); node.parameters = parseBracketedList(15, parseParameter, 18, 19); node.type = parseTypeAnnotation(); @@ -4763,15 +5088,15 @@ var ts; var name = parsePropertyName(); var questionToken = parseOptionalToken(50); if (token === 16 || token === 24) { - var method = createNode(127, fullStart); + var method = createNode(129, fullStart); method.name = name; method.questionToken = questionToken; - fillSignature(51, false, false, method); + fillSignature(51, false, false, false, method); parseTypeMemberSemicolon(); return finishNode(method); } else { - var property = createNode(125, fullStart); + var property = createNode(127, fullStart); property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); @@ -4809,12 +5134,12 @@ var ts; switch (token) { case 16: case 24: - return parseSignatureMember(132); + return parseSignatureMember(134); case 18: return isIndexSignature() ? parseIndexSignatureDeclaration(undefined) : parsePropertyOrMethodSignature(); case 87: if (lookAhead(isStartOfConstructSignature)) { - return parseSignatureMember(133); + return parseSignatureMember(135); } case 8: case 7: @@ -4840,7 +5165,7 @@ var ts; return token === 16 || token === 24; } function parseTypeLiteral() { - var node = createNode(139); + var node = createNode(141); node.members = parseObjectTypeMembers(); return finishNode(node); } @@ -4856,12 +5181,12 @@ var ts; return members; } function parseTupleType() { - var node = createNode(141); + var node = createNode(143); node.elementTypes = parseBracketedList(18, parseType, 18, 19); return finishNode(node); } function parseParenthesizedType() { - var node = createNode(143); + var node = createNode(145); parseExpected(16); node.type = parseType(); parseExpected(17); @@ -4869,10 +5194,10 @@ var ts; } function parseFunctionOrConstructorType(kind) { var node = createNode(kind); - if (kind === 137) { + if (kind === 139) { parseExpected(87); } - fillSignature(32, false, false, node); + fillSignature(32, false, false, false, node); return finishNode(node); } function parseKeywordAndNoDot() { @@ -4928,7 +5253,7 @@ var ts; var type = parseNonArrayType(); while (!scanner.hasPrecedingLineBreak() && parseOptional(18)) { parseExpected(19); - var node = createNode(140, type.pos); + var node = createNode(142, type.pos); node.elementType = type; type = finishNode(node); } @@ -4943,7 +5268,7 @@ var ts; types.push(parseArrayTypeOrHigher()); } types.end = getNodeEnd(); - var node = createNode(142, type.pos); + var node = createNode(144, type.pos); node.types = types; type = finishNode(node); } @@ -4975,21 +5300,14 @@ var ts; return false; } function parseType() { - var savedYieldContext = inYieldContext(); - var savedGeneratorParameterContext = inGeneratorParameterContext(); - setYieldContext(false); - setGeneratorParameterContext(false); - var result = parseTypeWorker(); - setYieldContext(savedYieldContext); - setGeneratorParameterContext(savedGeneratorParameterContext); - return result; + return doOutsideOfYieldOrAwaitOrParameterContext(parseTypeWorker); } function parseTypeWorker() { if (isStartOfFunctionType()) { - return parseFunctionOrConstructorType(136); + return parseFunctionOrConstructorType(138); } if (token === 87) { - return parseFunctionOrConstructorType(137); + return parseFunctionOrConstructorType(139); } return parseUnionTypeOrHigher(); } @@ -5025,6 +5343,7 @@ var ts; case 39: case 24: case 64: + case 122: case 109: return true; default: @@ -5044,6 +5363,15 @@ var ts; } return expr; } + function parseBindingElementInitializer(inParameter) { + return doOutsideOfYieldOrAwaitOrParameterContextWhenInParameter(inParameter ? parseParameterInitializer : parseNonParameterInitializer); + } + function parseParameterInitializer() { + return parseInitializer(true); + } + function parseNonParameterInitializer() { + return parseInitializer(false); + } function parseInitializer(inParameter) { if (token !== 52) { if (scanner.hasPrecedingLineBreak() || (inParameter && token === 14) || !isStartOfExpression()) { @@ -5089,7 +5417,7 @@ var ts; return !scanner.hasPrecedingLineBreak() && isIdentifier(); } function parseYieldExpression() { - var node = createNode(166); + var node = createNode(169); nextToken(); if (!scanner.hasPrecedingLineBreak() && (token === 35 || isStartOfExpression())) { node.asteriskToken = parseOptionalToken(35); @@ -5102,15 +5430,15 @@ var ts; } function parseSimpleArrowFunctionExpression(identifier) { ts.Debug.assert(token === 32, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); - var node = createNode(157, identifier.pos); - var parameter = createNode(124, identifier.pos); + var node = createNode(159, identifier.pos); + var parameter = createNode(126, identifier.pos); parameter.name = identifier; finishNode(parameter); node.parameters = [parameter]; node.parameters.pos = parameter.pos; node.parameters.end = parameter.end; parseExpected(32); - node.body = parseArrowFunctionExpressionBody(); + node.body = parseArrowFunctionExpressionBody(false); return finishNode(node); } function tryParseParenthesizedArrowFunctionExpression() { @@ -5123,7 +5451,7 @@ var ts; return undefined; } if (parseExpected(32) || token === 14) { - arrowFunction.body = parseArrowFunctionExpressionBody(); + arrowFunction.body = parseArrowFunctionExpressionBody(!!(arrowFunction.flags & 16384)); } else { arrowFunction.body = parseIdentifier(); @@ -5131,7 +5459,7 @@ var ts; return finishNode(arrowFunction); } function isParenthesizedArrowFunctionExpression() { - if (token === 16 || token === 24) { + if (token === 16 || token === 24 || token === 121) { return lookAhead(isParenthesizedArrowFunctionExpressionWorker); } if (token === 32) { @@ -5140,6 +5468,9 @@ var ts; return 0; } function isParenthesizedArrowFunctionExpressionWorker() { + if (token === 121 && !parseContextualModifier(121, true)) { + return 0; + } var first = token; var second = nextToken(); if (first === 16) { @@ -5177,8 +5508,10 @@ var ts; return parseParenthesizedArrowFunctionExpressionHead(false); } function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity) { - var node = createNode(157); - fillSignature(51, false, !allowAmbiguity, node); + var node = createNode(159); + setModifiers(node, parseModifiers(true)); + var isAsync = !!(node.flags & 16384); + fillSignature(51, false, isAsync, !allowAmbiguity, node); if (!node.parameters) { return undefined; } @@ -5187,20 +5520,24 @@ var ts; } return node; } - function parseArrowFunctionExpressionBody() { + function parseArrowFunctionExpressionBody(isAsync) { if (token === 14) { - return parseFunctionBlock(false, false); + return parseFunctionBlock(false, isAsync, false); } if (isStartOfStatement(true) && !isStartOfExpressionStatement() && token !== 82) { - return parseFunctionBlock(false, true); + return parseFunctionBlock(false, isAsync, true); } - return parseAssignmentExpressionOrHigher(); + var savedAwaitContext = inAwaitContext(); + setAwaitContext(isAsync); + var result = parseAssignmentExpressionOrHigher(); + setAwaitContext(savedAwaitContext); + return result; } function parseConditionalExpressionRest(leftOperand) { if (!parseOptional(50)) { return leftOperand; } - var node = createNode(164, leftOperand.pos); + var node = createNode(167, leftOperand.pos); node.condition = leftOperand; node.whenTrue = allowInAnd(parseAssignmentExpressionOrHigher); parseExpected(51); @@ -5272,38 +5609,56 @@ var ts; return -1; } function makeBinaryExpression(left, operator, right) { - var node = createNode(163, left.pos); + var node = createNode(166, left.pos); node.left = left; node.operator = operator; node.right = right; return finishNode(node); } function parsePrefixUnaryExpression() { - var node = createNode(161); + var node = createNode(164); node.operator = token; nextToken(); node.operand = parseUnaryExpressionOrHigher(); return finishNode(node); } function parseDeleteExpression() { - var node = createNode(158); + var node = createNode(160); nextToken(); node.expression = parseUnaryExpressionOrHigher(); return finishNode(node); } function parseTypeOfExpression() { - var node = createNode(159); + var node = createNode(161); nextToken(); node.expression = parseUnaryExpressionOrHigher(); return finishNode(node); } function parseVoidExpression() { - var node = createNode(160); + var node = createNode(162); + nextToken(); + node.expression = parseUnaryExpressionOrHigher(); + return finishNode(node); + } + function isAwaitExpression() { + if (token === 122) { + if (inAwaitContext()) { + return true; + } + return lookAhead(nextTokenIsIdentifierOnSameLine); + } + return false; + } + function parseAwaitExpression() { + var node = createNode(163); nextToken(); node.expression = parseUnaryExpressionOrHigher(); return finishNode(node); } function parseUnaryExpressionOrHigher() { + if (isAwaitExpression()) { + return parseAwaitExpression(); + } switch (token) { case 33: case 34: @@ -5328,7 +5683,7 @@ var ts; var expression = parseLeftHandSideExpressionOrHigher(); ts.Debug.assert(isLeftHandSideExpression(expression)); if ((token === 38 || token === 39) && !scanner.hasPrecedingLineBreak()) { - var node = createNode(162, expression.pos); + var node = createNode(165, expression.pos); node.operand = expression; node.operator = token; nextToken(); @@ -5349,14 +5704,14 @@ var ts; if (token === 16 || token === 20) { return expression; } - var node = createNode(149, expression.pos); + var node = createNode(151, expression.pos); node.expression = expression; parseExpected(20, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); node.name = parseRightSideOfDot(true); return finishNode(node); } function parseTypeAssertion() { - var node = createNode(154); + var node = createNode(156); parseExpected(24); node.type = parseType(); parseExpected(25); @@ -5367,14 +5722,14 @@ var ts; while (true) { var dotOrBracketStart = scanner.getTokenPos(); if (parseOptional(20)) { - var propertyAccess = createNode(149, expression.pos); + var propertyAccess = createNode(151, expression.pos); propertyAccess.expression = expression; propertyAccess.name = parseRightSideOfDot(true); expression = finishNode(propertyAccess); continue; } if (parseOptional(18)) { - var indexedAccess = createNode(150, expression.pos); + var indexedAccess = createNode(152, expression.pos); indexedAccess.expression = expression; if (token !== 19) { indexedAccess.argumentExpression = allowInAnd(parseExpression); @@ -5388,7 +5743,7 @@ var ts; continue; } if (token === 10 || token === 11) { - var tagExpression = createNode(153, expression.pos); + var tagExpression = createNode(155, expression.pos); tagExpression.tag = expression; tagExpression.template = token === 10 ? parseLiteralNode() : parseTemplateExpression(); expression = finishNode(tagExpression); @@ -5405,7 +5760,7 @@ var ts; if (!typeArguments) { return expression; } - var callExpr = createNode(151, expression.pos); + var callExpr = createNode(153, expression.pos); callExpr.expression = expression; callExpr.typeArguments = typeArguments; callExpr.arguments = parseArgumentList(); @@ -5413,7 +5768,7 @@ var ts; continue; } else if (token === 16) { - var callExpr = createNode(151, expression.pos); + var callExpr = createNode(153, expression.pos); callExpr.expression = expression; callExpr.arguments = parseArgumentList(); expression = finishNode(callExpr); @@ -5465,6 +5820,7 @@ var ts; } } function parsePrimaryExpression() { + var modifiers; switch (token) { case 7: case 8: @@ -5482,6 +5838,11 @@ var ts; return parseArrayLiteralExpression(); case 14: return parseObjectLiteralExpression(); + case 121: + if (!lookAhead(nextTokenIsFunctionKeywordOnSameLine)) { + break; + } + return parseFunctionExpression(); case 82: return parseFunctionExpression(); case 87: @@ -5498,26 +5859,26 @@ var ts; return parseIdentifier(ts.Diagnostics.Expression_expected); } function parseParenthesizedExpression() { - var node = createNode(155); + var node = createNode(157); parseExpected(16); node.expression = allowInAnd(parseExpression); parseExpected(17); return finishNode(node); } function parseSpreadElement() { - var node = createNode(167); + var node = createNode(171); parseExpected(21); node.expression = parseAssignmentExpressionOrHigher(); return finishNode(node); } function parseArgumentOrArrayLiteralElement() { - return token === 21 ? parseSpreadElement() : token === 23 ? createNode(168) : parseAssignmentExpressionOrHigher(); + return token === 21 ? parseSpreadElement() : token === 23 ? createNode(172) : parseAssignmentExpressionOrHigher(); } function parseArgumentExpression() { return allowInAnd(parseArgumentOrArrayLiteralElement); } function parseArrayLiteralExpression() { - var node = createNode(147); + var node = createNode(149); parseExpected(18); if (scanner.hasPrecedingLineBreak()) node.flags |= 256; @@ -5527,10 +5888,10 @@ var ts; } function tryParseAccessorDeclaration(fullStart, modifiers) { if (parseContextualModifier(114)) { - return parseAccessorDeclaration(130, fullStart, modifiers); + return parseAccessorDeclaration(132, fullStart, modifiers); } else if (parseContextualModifier(118)) { - return parseAccessorDeclaration(131, fullStart, modifiers); + return parseAccessorDeclaration(133, fullStart, modifiers); } return undefined; } @@ -5550,13 +5911,13 @@ var ts; return parseMethodDeclaration(fullStart, modifiers, asteriskToken, propertyName, questionToken); } if ((token === 23 || token === 15) && tokenIsIdentifier) { - var shorthandDeclaration = createNode(205, fullStart); + var shorthandDeclaration = createNode(209, fullStart); shorthandDeclaration.name = propertyName; shorthandDeclaration.questionToken = questionToken; return finishNode(shorthandDeclaration); } else { - var propertyAssignment = createNode(204, fullStart); + var propertyAssignment = createNode(208, fullStart); propertyAssignment.name = propertyName; propertyAssignment.questionToken = questionToken; parseExpected(51); @@ -5565,7 +5926,7 @@ var ts; } } function parseObjectLiteralExpression() { - var node = createNode(148); + var node = createNode(150); parseExpected(14); if (scanner.hasPrecedingLineBreak()) { node.flags |= 256; @@ -5575,19 +5936,35 @@ var ts; return finishNode(node); } function parseFunctionExpression() { - var node = createNode(156); + var node = createNode(158); + setModifiers(node, parseModifiers()); parseExpected(82); + var isAsync = !!(node.flags & 16384); node.asteriskToken = parseOptionalToken(35); - node.name = node.asteriskToken ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier(); - fillSignature(51, !!node.asteriskToken, false, node); - node.body = parseFunctionBlock(!!node.asteriskToken, false); + if (node.asteriskToken) { + var savedYieldContext = inYieldContext(); + setYieldContext(true); + } + if (isAsync) { + var savedAwaitContext = inAwaitContext(); + setAwaitContext(true); + } + node.name = parseOptionalIdentifier(); + if (node.asteriskToken) { + setYieldContext(savedYieldContext); + } + if (isAsync) { + setAwaitContext(savedAwaitContext); + } + fillSignature(51, !!node.asteriskToken, isAsync, false, node); + node.body = parseFunctionBlock(!!node.asteriskToken, isAsync, false); return finishNode(node); } function parseOptionalIdentifier() { return isIdentifier() ? parseIdentifier() : undefined; } function parseNewExpression() { - var node = createNode(152); + var node = createNode(154); parseExpected(87); node.expression = parseMemberExpressionOrHigher(); node.typeArguments = tryParse(parseTypeArgumentsInExpression); @@ -5597,7 +5974,7 @@ var ts; return finishNode(node); } function parseBlock(ignoreMissingOpenBrace, checkForStrictMode, diagnosticMessage) { - var node = createNode(170); + var node = createNode(174); if (parseExpected(14, diagnosticMessage) || ignoreMissingOpenBrace) { node.statements = parseList(2, checkForStrictMode, parseStatement); parseExpected(15); @@ -5607,20 +5984,23 @@ var ts; } return finishNode(node); } - function parseFunctionBlock(allowYield, ignoreMissingOpenBrace, diagnosticMessage) { + function parseFunctionBlock(allowYield, allowAwait, ignoreMissingOpenBrace, diagnosticMessage) { var savedYieldContext = inYieldContext(); setYieldContext(allowYield); + var savedAwaitContext = inAwaitContext(); + setAwaitContext(allowAwait); var block = parseBlock(ignoreMissingOpenBrace, true, diagnosticMessage); setYieldContext(savedYieldContext); + setAwaitContext(savedAwaitContext); return block; } function parseEmptyStatement() { - var node = createNode(172); + var node = createNode(176); parseExpected(22); return finishNode(node); } function parseIfStatement() { - var node = createNode(174); + var node = createNode(178); parseExpected(83); parseExpected(16); node.expression = allowInAnd(parseExpression); @@ -5630,7 +6010,7 @@ var ts; return finishNode(node); } function parseDoStatement() { - var node = createNode(175); + var node = createNode(179); parseExpected(74); node.statement = parseStatement(); parseExpected(99); @@ -5641,7 +6021,7 @@ var ts; return finishNode(node); } function parseWhileStatement() { - var node = createNode(176); + var node = createNode(180); parseExpected(99); parseExpected(16); node.expression = allowInAnd(parseExpression); @@ -5664,14 +6044,14 @@ var ts; } var forOrForInStatement; if (parseOptional(85)) { - var forInStatement = createNode(178, pos); + var forInStatement = createNode(182, pos); forInStatement.initializer = initializer; forInStatement.expression = allowInAnd(parseExpression); parseExpected(17); forOrForInStatement = forInStatement; } else { - var forStatement = createNode(177, pos); + var forStatement = createNode(181, pos); forStatement.initializer = initializer; parseExpected(22); if (token !== 22 && token !== 17) { @@ -5689,7 +6069,7 @@ var ts; } function parseBreakOrContinueStatement(kind) { var node = createNode(kind); - parseExpected(kind === 180 ? 65 : 70); + parseExpected(kind === 184 ? 65 : 70); if (!canParseSemicolon()) { node.label = parseIdentifier(); } @@ -5697,7 +6077,7 @@ var ts; return finishNode(node); } function parseReturnStatement() { - var node = createNode(181); + var node = createNode(185); parseExpected(89); if (!canParseSemicolon()) { node.expression = allowInAnd(parseExpression); @@ -5706,7 +6086,7 @@ var ts; return finishNode(node); } function parseWithStatement() { - var node = createNode(182); + var node = createNode(186); parseExpected(100); parseExpected(16); node.expression = allowInAnd(parseExpression); @@ -5715,7 +6095,7 @@ var ts; return finishNode(node); } function parseCaseClause() { - var node = createNode(200); + var node = createNode(204); parseExpected(66); node.expression = allowInAnd(parseExpression); parseExpected(51); @@ -5723,7 +6103,7 @@ var ts; return finishNode(node); } function parseDefaultClause() { - var node = createNode(201); + var node = createNode(205); parseExpected(72); parseExpected(51); node.statements = parseList(4, false, parseStatement); @@ -5733,7 +6113,7 @@ var ts; return token === 66 ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement() { - var node = createNode(183); + var node = createNode(187); parseExpected(91); parseExpected(16); node.expression = allowInAnd(parseExpression); @@ -5744,14 +6124,14 @@ var ts; return finishNode(node); } function parseThrowStatement() { - var node = createNode(185); + var node = createNode(189); parseExpected(93); node.expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression); parseSemicolon(); return finishNode(node); } function parseTryStatement() { - var node = createNode(186); + var node = createNode(190); parseExpected(95); node.tryBlock = parseBlock(false, false); node.catchClause = token === 67 ? parseCatchClause() : undefined; @@ -5762,7 +6142,7 @@ var ts; return finishNode(node); } function parseCatchClause() { - var result = createNode(203); + var result = createNode(207); parseExpected(67); parseExpected(16); result.name = parseIdentifier(); @@ -5772,7 +6152,7 @@ var ts; return finishNode(result); } function parseDebuggerStatement() { - var node = createNode(187); + var node = createNode(191); parseExpected(71); parseSemicolon(); return finishNode(node); @@ -5781,13 +6161,13 @@ var ts; var fullStart = scanner.getStartPos(); var expression = allowInAnd(parseExpression); if (expression.kind === 64 && parseOptional(51)) { - var labeledStatement = createNode(184, fullStart); + var labeledStatement = createNode(188, fullStart); labeledStatement.label = expression; labeledStatement.statement = parseStatement(); return finishNode(labeledStatement); } else { - var expressionStatement = createNode(173, fullStart); + var expressionStatement = createNode(177, fullStart); expressionStatement.expression = expression; parseSemicolon(); return finishNode(expressionStatement); @@ -5825,6 +6205,11 @@ var ts; case 69: var isConstEnum = lookAhead(nextTokenIsEnumKeyword); return !isConstEnum; + case 121: + if (lookAhead(nextTokenIsFunctionKeywordOnSameLine)) { + return true; + } + return isStartOfExpression(); case 102: case 68: case 115: @@ -5872,9 +6257,9 @@ var ts; case 81: return parseForOrForInStatement(); case 70: - return parseBreakOrContinueStatement(179); + return parseBreakOrContinueStatement(183); case 65: - return parseBreakOrContinueStatement(180); + return parseBreakOrContinueStatement(184); case 89: return parseReturnStatement(); case 100: @@ -5925,25 +6310,25 @@ var ts; } return undefined; } - function parseFunctionBlockOrSemicolon(isGenerator, diagnosticMessage) { + function parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage) { if (token !== 14 && canParseSemicolon()) { parseSemicolon(); return; } - return parseFunctionBlock(isGenerator, false, diagnosticMessage); + return parseFunctionBlock(isGenerator, isAsync, false, diagnosticMessage); } function parseArrayBindingElement() { if (token === 23) { - return createNode(168); + return createNode(172); } - var node = createNode(146); + var node = createNode(148); node.dotDotDotToken = parseOptionalToken(21); - node.name = parseIdentifierOrPattern(); - node.initializer = parseInitializer(false); + node.name = parseIdentifierOrBindingPattern(true); + node.initializer = parseBindingElementInitializer(false); return finishNode(node); } function parseObjectBindingElement() { - var node = createNode(146); + var node = createNode(148); var id = parsePropertyName(); if (id.kind === 64 && token !== 51) { node.name = id; @@ -5951,29 +6336,32 @@ var ts; else { parseExpected(51); node.propertyName = id; - node.name = parseIdentifierOrPattern(); + node.name = parseIdentifierOrBindingPattern(true); } - node.initializer = parseInitializer(false); + node.initializer = parseBindingElementInitializer(false); return finishNode(node); } function parseObjectBindingPattern() { - var node = createNode(144); + var node = createNode(146); parseExpected(14); node.elements = parseDelimitedList(10, parseObjectBindingElement); parseExpected(15); return finishNode(node); } function parseArrayBindingPattern() { - var node = createNode(145); + var node = createNode(147); parseExpected(18); node.elements = parseDelimitedList(11, parseArrayBindingElement); parseExpected(19); return finishNode(node); } - function isIdentifierOrPattern() { - return token === 14 || token === 18 || isIdentifier(); + function isIdentifierOrBindingPattern() { + return isBindingPattern() || isIdentifier(); } - function parseIdentifierOrPattern() { + function isBindingPattern() { + return token === 18 || token === 14; + } + function parseIdentifierOrBindingPattern(inBindingElement) { if (token === 18) { return parseArrayBindingPattern(); } @@ -5983,14 +6371,14 @@ var ts; return parseIdentifier(); } function parseVariableDeclaration() { - var node = createNode(188); - node.name = parseIdentifierOrPattern(); + var node = createNode(192); + node.name = parseIdentifierOrBindingPattern(false); node.type = parseTypeAnnotation(); node.initializer = parseInitializer(false); return finishNode(node); } function parseVariableDeclarationList(disallowIn) { - var node = createNode(189); + var node = createNode(193); switch (token) { case 97: break; @@ -6011,38 +6399,40 @@ var ts; return finishNode(node); } function parseVariableStatement(fullStart, modifiers) { - var node = createNode(171, fullStart); + var node = createNode(175, fullStart); setModifiers(node, modifiers); node.declarationList = parseVariableDeclarationList(false); parseSemicolon(); return finishNode(node); } function parseFunctionDeclaration(fullStart, modifiers) { - var node = createNode(190, fullStart); + var node = createNode(194, fullStart); setModifiers(node, modifiers); parseExpected(82); node.asteriskToken = parseOptionalToken(35); node.name = parseIdentifier(); - fillSignature(51, !!node.asteriskToken, false, node); - node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, ts.Diagnostics.or_expected); + var isAsync = (node.flags & 16384) !== 0; + fillSignature(51, !!node.asteriskToken, isAsync, false, node); + node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, isAsync, ts.Diagnostics.or_expected); return finishNode(node); } function parseConstructorDeclaration(pos, modifiers) { - var node = createNode(129, pos); + var node = createNode(131, pos); setModifiers(node, modifiers); parseExpected(112); - fillSignature(51, false, false, node); - node.body = parseFunctionBlockOrSemicolon(false, ts.Diagnostics.or_expected); + fillSignature(51, false, false, false, node); + node.body = parseFunctionBlockOrSemicolon(false, false, ts.Diagnostics.or_expected); return finishNode(node); } function parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, diagnosticMessage) { - var method = createNode(128, fullStart); + var method = createNode(130, fullStart); setModifiers(method, modifiers); method.asteriskToken = asteriskToken; method.name = name; method.questionToken = questionToken; - fillSignature(51, !!asteriskToken, false, method); - method.body = parseFunctionBlockOrSemicolon(!!asteriskToken, diagnosticMessage); + var isAsync = !!(method.flags & 16384); + fillSignature(51, !!asteriskToken, isAsync, false, method); + method.body = parseFunctionBlockOrSemicolon(!!asteriskToken, isAsync, diagnosticMessage); return finishNode(method); } function parsePropertyOrMethodDeclaration(fullStart, modifiers) { @@ -6053,7 +6443,7 @@ var ts; return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected); } else { - var property = createNode(126, fullStart); + var property = createNode(128, fullStart); setModifiers(property, modifiers); property.name = name; property.questionToken = questionToken; @@ -6063,15 +6453,13 @@ var ts; return finishNode(property); } } - function parseNonParameterInitializer() { - return parseInitializer(false); - } function parseAccessorDeclaration(kind, fullStart, modifiers) { var node = createNode(kind, fullStart); setModifiers(node, modifiers); node.name = parsePropertyName(); - fillSignature(51, false, false, node); - node.body = parseFunctionBlockOrSemicolon(false); + var isAsync = (node.flags & 16384) !== 0; + fillSignature(51, false, isAsync, false, node); + node.body = parseFunctionBlockOrSemicolon(false, isAsync); return finishNode(node); } function isClassMemberStart() { @@ -6107,13 +6495,13 @@ var ts; } return false; } - function parseModifiers() { + function parseModifiers(isArrowFunction) { var flags = 0; var modifiers; while (true) { var modifierStart = scanner.getStartPos(); var modifierKind = token; - if (!parseAnyContextualModifier()) { + if (!parseAnyContextualModifier(isArrowFunction)) { break; } if (!modifiers) { @@ -6148,14 +6536,14 @@ var ts; ts.Debug.fail("Should not have attempted to parse class member declaration."); } function parseClassDeclaration(fullStart, modifiers) { - var node = createNode(191, fullStart); + var node = createNode(195, fullStart); setModifiers(node, modifiers); parseExpected(68); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(true); if (parseExpected(14)) { - node.members = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseClassMembers) : parseClassMembers(); + node.members = doOutsideOfYieldOrAwaitOrParameterContextWhenInParameter(parseClassMembers); parseExpected(15); } else { @@ -6165,7 +6553,10 @@ var ts; } function parseHeritageClauses(isClassHeritageClause) { if (isHeritageClause()) { - return isClassHeritageClause && inGeneratorParameterContext() ? doOutsideOfYieldContext(parseHeritageClausesWorker) : parseHeritageClausesWorker(); + if (isClassHeritageClause) { + return doOutsideOfYieldOrAwaitOrParameterContextWhenInParameter(parseHeritageClausesWorker); + } + return parseHeritageClausesWorker(); } return undefined; } @@ -6174,7 +6565,7 @@ var ts; } function parseHeritageClause() { if (token === 78 || token === 101) { - var node = createNode(202); + var node = createNode(206); node.token = token; nextToken(); node.types = parseDelimitedList(8, parseTypeReference); @@ -6189,7 +6580,7 @@ var ts; return parseList(6, false, parseClassElement); } function parseInterfaceDeclaration(fullStart, modifiers) { - var node = createNode(192, fullStart); + var node = createNode(196, fullStart); setModifiers(node, modifiers); parseExpected(102); node.name = parseIdentifier(); @@ -6199,7 +6590,7 @@ var ts; return finishNode(node); } function parseTypeAliasDeclaration(fullStart, modifiers) { - var node = createNode(193, fullStart); + var node = createNode(197, fullStart); setModifiers(node, modifiers); parseExpected(120); node.name = parseIdentifier(); @@ -6209,13 +6600,13 @@ var ts; return finishNode(node); } function parseEnumMember() { - var node = createNode(206, scanner.getStartPos()); + var node = createNode(210, scanner.getStartPos()); node.name = parsePropertyName(); node.initializer = allowInAnd(parseNonParameterInitializer); return finishNode(node); } function parseEnumDeclaration(fullStart, modifiers) { - var node = createNode(194, fullStart); + var node = createNode(198, fullStart); setModifiers(node, modifiers); parseExpected(76); node.name = parseIdentifier(); @@ -6229,7 +6620,7 @@ var ts; return finishNode(node); } function parseModuleBlock() { - var node = createNode(196, scanner.getStartPos()); + var node = createNode(200, scanner.getStartPos()); if (parseExpected(14)) { node.statements = parseList(1, false, parseModuleElement); parseExpected(15); @@ -6240,7 +6631,7 @@ var ts; return finishNode(node); } function parseInternalModuleTail(fullStart, modifiers, flags) { - var node = createNode(195, fullStart); + var node = createNode(199, fullStart); setModifiers(node, modifiers); node.flags |= flags; node.name = parseIdentifier(); @@ -6248,7 +6639,7 @@ var ts; return finishNode(node); } function parseAmbientExternalModuleDeclaration(fullStart, modifiers) { - var node = createNode(195, fullStart); + var node = createNode(199, fullStart); setModifiers(node, modifiers); node.name = parseLiteralNode(true); node.body = parseModuleBlock(); @@ -6265,7 +6656,7 @@ var ts; return nextToken() === 16; } function parseImportDeclaration(fullStart, modifiers) { - var node = createNode(197, fullStart); + var node = createNode(201, fullStart); setModifiers(node, modifiers); parseExpected(84); node.name = parseIdentifier(); @@ -6278,7 +6669,7 @@ var ts; return isExternalModuleReference() ? parseExternalModuleReference() : parseEntityName(false); } function parseExternalModuleReference() { - var node = createNode(199); + var node = createNode(203); parseExpected(116); parseExpected(16); node.expression = parseExpression(); @@ -6289,7 +6680,7 @@ var ts; return finishNode(node); } function parseExportAssignmentTail(fullStart, modifiers) { - var node = createNode(198, fullStart); + var node = createNode(202, fullStart); setModifiers(node, modifiers); node.exportName = parseIdentifier(); parseSemicolon(); @@ -6322,6 +6713,8 @@ var ts; case 106: case 108: return lookAhead(nextTokenIsDeclarationStart); + case 121: + return lookAhead(nextTokenIsDeclarationStartOnSameLine); } } function isIdentifierOrKeyword() { @@ -6343,6 +6736,14 @@ var ts; nextToken(); return isDeclarationStart(); } + function nextTokenIsDeclarationStartOnSameLine() { + nextToken(); + return !scanner.hasPrecedingLineBreak() && isDeclarationStart(); + } + function nextTokenIsFunctionKeywordOnSameLine() { + nextToken(); + return !scanner.hasPrecedingLineBreak() && token === 82; + } function parseDeclaration() { var fullStart = getNodePos(); var modifiers = parseModifiers(); @@ -6442,27 +6843,27 @@ var ts; sourceFile.amdModuleName = amdModuleName; } function setExternalModuleIndicator(sourceFile) { - sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { return node.flags & 1 || node.kind === 197 && node.moduleReference.kind === 199 || node.kind === 198 ? node : undefined; }); + sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { return node.flags & 1 || node.kind === 201 && node.moduleReference.kind === 203 || node.kind === 202 ? node : undefined; }); } } function isLeftHandSideExpression(expr) { if (expr) { switch (expr.kind) { - case 149: - case 150: - case 152: case 151: + case 152: + case 154: case 153: - case 147: case 155: - case 148: - case 156: + case 149: + case 157: + case 150: + case 158: case 64: case 9: case 7: case 8: case 10: - case 165: + case 168: case 79: case 88: case 92: @@ -6483,16 +6884,16 @@ var ts; (function (ts) { ts.bindTime = 0; function getModuleInstanceState(node) { - if (node.kind === 192 || node.kind === 193) { + if (node.kind === 196 || node.kind === 197) { return 0; } else if (ts.isConstEnumDeclaration(node)) { return 2; } - else if (node.kind === 197 && !(node.flags & 1)) { + else if (node.kind === 201 && !(node.flags & 1)) { return 0; } - else if (node.kind === 196) { + else if (node.kind === 200) { var state = 0; ts.forEachChild(node, function (n) { switch (getModuleInstanceState(n)) { @@ -6508,7 +6909,7 @@ var ts; }); return state; } - else if (node.kind === 195) { + else if (node.kind === 199) { return getModuleInstanceState(node.body); } else { @@ -6517,7 +6918,7 @@ var ts; } ts.getModuleInstanceState = getModuleInstanceState; function hasDynamicName(declaration) { - return declaration.name && declaration.name.kind === 122; + return declaration.name && declaration.name.kind === 124; } ts.hasDynamicName = hasDynamicName; function bindSourceFile(file) { @@ -6558,22 +6959,22 @@ var ts; } function getDeclarationName(node) { if (node.name) { - if (node.kind === 195 && node.name.kind === 8) { + if (node.kind === 199 && node.name.kind === 8) { return '"' + node.name.text + '"'; } ts.Debug.assert(!hasDynamicName(node)); return node.name.text; } switch (node.kind) { - case 137: - case 129: + case 139: + case 131: return "__constructor"; - case 136: - case 132: + case 138: + case 134: return "__call"; - case 133: + case 135: return "__new"; - case 134: + case 136: return "__index"; } } @@ -6602,7 +7003,7 @@ var ts; } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; - if (node.kind === 191 && symbol.exports) { + if (node.kind === 195 && symbol.exports) { var prototypeSymbol = createSymbol(4 | 134217728, "prototype"); if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { if (node.name) { @@ -6634,7 +7035,7 @@ var ts; if (symbolKind & 1536) { exportKind |= 4194304; } - if (ts.getCombinedNodeFlags(node) & 1 || (node.kind !== 197 && isAmbientContext(container))) { + if (ts.getCombinedNodeFlags(node) & 1 || (node.kind !== 201 && isAmbientContext(container))) { if (exportKind) { var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); @@ -6673,40 +7074,40 @@ var ts; } function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) { switch (container.kind) { - case 195: + case 199: declareModuleMember(node, symbolKind, symbolExcludes); break; - case 207: + case 211: if (ts.isExternalModule(container)) { declareModuleMember(node, symbolKind, symbolExcludes); break; } - case 136: - case 137: - case 132: - case 133: + case 138: + case 139: case 134: - case 128: - case 127: - case 129: + case 135: + case 136: case 130: + case 129: case 131: - case 190: - case 156: - case 157: + case 132: + case 133: + case 194: + case 158: + case 159: declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); break; - case 191: + case 195: if (node.flags & 128) { declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } - case 139: - case 148: - case 192: + case 141: + case 150: + case 196: declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes); break; - case 194: + case 198: declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } @@ -6739,7 +7140,7 @@ var ts; var typeLiteralSymbol = createSymbol(2048, "__type"); addDeclarationToSymbol(typeLiteralSymbol, node, 2048); typeLiteralSymbol.members = {}; - typeLiteralSymbol.members[node.kind === 136 ? "__call" : "__new"] = symbol; + typeLiteralSymbol.members[node.kind === 138 ? "__call" : "__new"] = symbol; } function bindAnonymousDeclaration(node, symbolKind, name, isBlockScopeContainer) { var symbol = createSymbol(symbolKind, name); @@ -6758,10 +7159,10 @@ var ts; } function bindBlockScopedVariableDeclaration(node) { switch (blockScopeContainer.kind) { - case 195: + case 199: declareModuleMember(node, 2, 107455); break; - case 207: + case 211: if (ts.isExternalModule(container)) { declareModuleMember(node, 2, 107455); break; @@ -6780,14 +7181,14 @@ var ts; function bind(node) { node.parent = parent; switch (node.kind) { - case 123: + case 125: bindDeclaration(node, 262144, 530912, false); break; - case 124: + case 126: bindParameter(node); break; - case 188: - case 146: + case 192: + case 148: if (ts.isBindingPattern(node.name)) { bindChildren(node, 0, false); } @@ -6798,65 +7199,65 @@ var ts; bindDeclaration(node, 1, 107454, false); } break; - case 126: - case 125: + case 128: + case 127: bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455, false); break; - case 204: - case 205: + case 208: + case 209: bindPropertyOrMethodOrAccessor(node, 4, 107455, false); break; - case 206: + case 210: bindPropertyOrMethodOrAccessor(node, 8, 107455, false); break; - case 132: - case 133: case 134: + case 135: + case 136: bindDeclaration(node, 131072, 0, false); break; - case 128: - case 127: + case 130: + case 129: bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263, true); break; - case 190: + case 194: bindDeclaration(node, 16, 106927, true); break; - case 129: + case 131: bindDeclaration(node, 16384, 0, true); break; - case 130: + case 132: bindPropertyOrMethodOrAccessor(node, 32768, 41919, true); break; - case 131: + case 133: bindPropertyOrMethodOrAccessor(node, 65536, 74687, true); break; - case 136: - case 137: + case 138: + case 139: bindFunctionOrConstructorType(node); break; - case 139: + case 141: bindAnonymousDeclaration(node, 2048, "__type", false); break; - case 148: + case 150: bindAnonymousDeclaration(node, 4096, "__object", false); break; - case 156: - case 157: + case 158: + case 159: bindAnonymousDeclaration(node, 16, "__function", true); break; - case 203: + case 207: bindCatchVariableDeclaration(node); break; - case 191: + case 195: bindDeclaration(node, 32, 899583, false); break; - case 192: + case 196: bindDeclaration(node, 64, 792992, false); break; - case 193: + case 197: bindDeclaration(node, 524288, 793056, false); break; - case 194: + case 198: if (ts.isConst(node)) { bindDeclaration(node, 128, 899967, false); } @@ -6864,22 +7265,24 @@ var ts; bindDeclaration(node, 256, 899327, false); } break; - case 195: + case 199: bindModuleDeclaration(node); break; - case 197: + case 201: bindDeclaration(node, 8388608, 8388608, false); break; - case 207: + case 211: if (ts.isExternalModule(node)) { bindAnonymousDeclaration(node, 512, '"' + ts.removeFileExtension(node.fileName) + '"', true); break; } - case 170: - case 203: - case 177: - case 178: - case 183: + case 174: + bindChildren(node, 0, !ts.isAnyFunction(node.parent)); + break; + case 207: + case 181: + case 182: + case 187: bindChildren(node, 0, true); break; default: @@ -6896,7 +7299,7 @@ var ts; else { bindDeclaration(node, 1, 107455, false); } - if (node.flags & 112 && node.parent.kind === 129 && node.parent.parent.kind === 191) { + if (node.flags & 112 && node.parent.kind === 131 && node.parent.parent.kind === 195) { var classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); } @@ -6975,6 +7378,7 @@ var ts; var nullType = createIntrinsicType(64 | 262144, "null"); var unknownType = createIntrinsicType(1, "unknown"); var resolvingType = createIntrinsicType(1, "__resolving__"); + var thenableType; var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); var anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); var noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -6983,6 +7387,7 @@ var ts; var unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false); var globals = {}; var globalArraySymbol; + var globalPromiseSymbol; var globalObjectType; var globalFunctionType; var globalArrayType; @@ -6991,15 +7396,22 @@ var ts; var globalBooleanType; var globalRegExpType; var globalTemplateStringsArrayType; + var globalPromiseType; + var globalPromiseLikeInterfaceType; + var globalPromiseConstructorLikeInterfaceType; var anyArrayType; var tupleTypes = {}; var unionTypes = {}; var stringLiteralTypes = {}; var emitExtends = false; + var emitAwaiter = false; + var emitGenerator = false; var mergedSymbols = []; var symbolLinks = []; var nodeLinks = []; var potentialThisCollisions = []; + var potentialArgumentsCollisions = []; + var symbolNameOverrides; var diagnostics = ts.createDiagnosticCollection(); var primitiveTypeInfo = { "string": { @@ -7153,10 +7565,10 @@ var ts; return nodeLinks[node.id] || (nodeLinks[node.id] = {}); } function getSourceFile(node) { - return ts.getAncestor(node, 207); + return ts.getAncestor(node, 211); } function isGlobalSourceFile(node) { - return node.kind === 207 && !ts.isExternalModule(node); + return node.kind === 211 && !ts.isExternalModule(node); } function getSymbol(symbols, name, meaning) { if (meaning && ts.hasProperty(symbols, name)) { @@ -7197,22 +7609,22 @@ var ts; } } switch (location.kind) { - case 207: + case 211: if (!ts.isExternalModule(location)) break; - case 195: + case 199: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8914931)) { break loop; } break; - case 194: + case 198: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8)) { break loop; } break; - case 126: - case 125: - if (location.parent.kind === 191 && !(location.flags & 128)) { + case 128: + case 127: + if (location.parent.kind === 195 && !(location.flags & 128)) { var ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { if (getSymbol(ctor.locals, name, meaning & 107455)) { @@ -7221,8 +7633,8 @@ var ts; } } break; - case 191: - case 192: + case 195: + case 196: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056)) { if (lastLocation && lastLocation.flags & 128) { error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters); @@ -7231,28 +7643,28 @@ var ts; break loop; } break; - case 122: + case 124: var grandparent = location.parent.parent; - if (grandparent.kind === 191 || grandparent.kind === 192) { + if (grandparent.kind === 195 || grandparent.kind === 196) { if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; - case 128: - case 127: - case 129: case 130: + case 129: case 131: - case 190: - case 157: + case 132: + case 133: + case 194: + case 159: if (name === "arguments") { result = argumentsSymbol; break loop; } break; - case 156: + case 158: if (name === "arguments") { result = argumentsSymbol; break loop; @@ -7263,7 +7675,7 @@ var ts; break loop; } break; - case 203: + case 207: var id = location.name; if (name === id.text) { result = location.symbol; @@ -7304,13 +7716,13 @@ var ts; var links = getSymbolLinks(symbol); if (!links.target) { links.target = resolvingSymbol; - var node = ts.getDeclarationOfKind(symbol, 197); - if (node.moduleReference.kind === 199) { + var node = ts.getDeclarationOfKind(symbol, 201); + if (node.moduleReference.kind === 203) { if (node.moduleReference.expression.kind !== 8) { grammarErrorOnNode(node.moduleReference.expression, ts.Diagnostics.String_literal_expected); } } - var target = node.moduleReference.kind === 199 ? resolveExternalModuleName(node, ts.getExternalModuleImportDeclarationExpression(node)) : getSymbolOfPartOfRightHandSideOfImport(node.moduleReference, node); + var target = node.moduleReference.kind === 203 ? resolveExternalModuleName(node, ts.getExternalModuleImportDeclarationExpression(node)) : getSymbolOfPartOfRightHandSideOfImport(node.moduleReference, node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; } @@ -7325,17 +7737,17 @@ var ts; } function getSymbolOfPartOfRightHandSideOfImport(entityName, importDeclaration) { if (!importDeclaration) { - importDeclaration = ts.getAncestor(entityName, 197); + importDeclaration = ts.getAncestor(entityName, 201); ts.Debug.assert(importDeclaration !== undefined); } if (entityName.kind === 64 && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { entityName = entityName.parent; } - if (entityName.kind === 64 || entityName.parent.kind === 121) { + if (entityName.kind === 64 || entityName.parent.kind === 123) { return resolveEntityName(importDeclaration, entityName, 1536); } else { - ts.Debug.assert(entityName.parent.kind === 197); + ts.Debug.assert(entityName.parent.kind === 201); return resolveEntityName(importDeclaration, entityName, 107455 | 793056 | 1536); } } @@ -7352,7 +7764,7 @@ var ts; return; } } - else if (name.kind === 121) { + else if (name.kind === 123) { var namespace = resolveEntityName(location, name.left, 1536); if (!namespace || namespace === unknownSymbol || ts.getFullWidth(name.right) === 0) return; @@ -7444,9 +7856,9 @@ var ts; var seenExportedMember = false; var result = []; ts.forEach(symbol.declarations, function (declaration) { - var block = (declaration.kind === 207 ? declaration : declaration.body); + var block = (declaration.kind === 211 ? declaration : declaration.body); ts.forEach(block.statements, function (node) { - if (node.kind === 198) { + if (node.kind === 202) { result.push(node); } else { @@ -7488,7 +7900,7 @@ var ts; var members = node.members; for (var i = 0; i < members.length; i++) { var member = members[i]; - if (member.kind === 129 && ts.nodeIsPresent(member.body)) { + if (member.kind === 131 && ts.nodeIsPresent(member.body)) { return member; } } @@ -7550,17 +7962,17 @@ var ts; } } switch (location.kind) { - case 207: + case 211: if (!ts.isExternalModule(location)) { break; } - case 195: + case 199: if (result = callback(getSymbolOfNode(location).exports)) { return result; } break; - case 191: - case 192: + case 195: + case 196: if (result = callback(getSymbolOfNode(location).members)) { return result; } @@ -7673,7 +8085,7 @@ var ts; } } function hasExternalModuleSymbol(declaration) { - return (declaration.kind === 195 && declaration.name.kind === 8) || (declaration.kind === 207 && ts.isExternalModule(declaration)); + return (declaration.kind === 199 && declaration.name.kind === 8) || (declaration.kind === 211 && ts.isExternalModule(declaration)); } function hasVisibleDeclarations(symbol) { var aliasesToMakeVisible; @@ -7683,7 +8095,7 @@ var ts; return { accessibility: 0, aliasesToMakeVisible: aliasesToMakeVisible }; function getIsDeclarationVisible(declaration) { if (!isDeclarationVisible(declaration)) { - if (declaration.kind === 197 && !(declaration.flags & 1) && isDeclarationVisible(declaration.parent)) { + if (declaration.kind === 201 && !(declaration.flags & 1) && isDeclarationVisible(declaration.parent)) { getNodeLinks(declaration).isVisible = true; if (aliasesToMakeVisible) { if (!ts.contains(aliasesToMakeVisible, declaration)) { @@ -7702,10 +8114,10 @@ var ts; } function isEntityNameVisible(entityName, enclosingDeclaration) { var meaning; - if (entityName.parent.kind === 138) { + if (entityName.parent.kind === 140) { meaning = 107455 | 1048576; } - else if (entityName.kind === 121 || entityName.parent.kind === 197) { + else if (entityName.kind === 123 || entityName.parent.kind === 201) { meaning = 1536; } else { @@ -7749,10 +8161,10 @@ var ts; function getTypeAliasForTypeLiteral(type) { if (type.symbol && type.symbol.flags & 2048) { var node = type.symbol.declarations[0].parent; - while (node.kind === 143) { + while (node.kind === 145) { node = node.parent; } - if (node.kind === 193) { + if (node.kind === 197) { return getSymbolOfNode(node); } } @@ -7917,7 +8329,7 @@ var ts; function shouldWriteTypeOfFunctionSymbol() { if (type.symbol) { var isStaticMethodSymbol = !!(type.symbol.flags & 8192 && ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 207 || declaration.parent.kind === 196; })); + var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 211 || declaration.parent.kind === 200; })); if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { return !!(flags & 2) || (typeStack && ts.contains(typeStack, type)); } @@ -8144,12 +8556,12 @@ var ts; function isDeclarationVisible(node) { function getContainingExternalModule(node) { for (; node; node = node.parent) { - if (node.kind === 195) { + if (node.kind === 199) { if (node.name.kind === 8) { return node; } } - else if (node.kind === 207) { + else if (node.kind === 211) { return ts.isExternalModule(node) ? node : undefined; } } @@ -8191,46 +8603,46 @@ var ts; } function determineIfDeclarationIsVisible() { switch (node.kind) { - case 188: - case 146: - case 195: - case 191: case 192: - case 193: - case 190: - case 194: + case 148: + case 199: + case 195: + case 196: case 197: + case 194: + case 198: + case 201: var parent = getDeclarationContainer(node); - if (!(ts.getCombinedNodeFlags(node) & 1) && !(node.kind !== 197 && parent.kind !== 207 && ts.isInAmbientContext(parent))) { + if (!(ts.getCombinedNodeFlags(node) & 1) && !(node.kind !== 201 && parent.kind !== 211 && ts.isInAmbientContext(parent))) { return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); } return isDeclarationVisible(parent); - case 126: - case 125: - case 130: - case 131: case 128: case 127: + case 132: + case 133: + case 130: + case 129: if (node.flags & (32 | 64)) { return false; } - case 129: - case 133: - case 132: + case 131: + case 135: case 134: - case 124: - case 196: case 136: - case 137: + case 126: + case 200: + case 138: case 139: - case 135: - case 140: case 141: + case 137: case 142: case 143: + case 144: + case 145: return isDeclarationVisible(node.parent); - case 123: - case 207: + case 125: + case 211: return true; default: ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind); @@ -8245,14 +8657,14 @@ var ts; } } function getRootDeclaration(node) { - while (node.kind === 146) { + while (node.kind === 148) { node = node.parent.parent; } return node; } function getDeclarationContainer(node) { node = getRootDeclaration(node); - return node.kind === 188 ? node.parent.parent.parent : node.parent; + return node.kind === 192 ? node.parent.parent.parent : node.parent; } function getTypeOfPrototypeProperty(prototype) { var classType = getDeclaredTypeOfSymbol(prototype.parent); @@ -8274,7 +8686,7 @@ var ts; } return parentType; } - if (pattern.kind === 144) { + if (pattern.kind === 146) { var name = declaration.propertyName || declaration.name; var type = getTypeOfPropertyOfType(parentType, name.text) || isNumericLiteralName(name.text) && getIndexTypeOfType(parentType, 1) || getIndexTypeOfType(parentType, 0); if (!type) { @@ -8302,7 +8714,7 @@ var ts; return type; } function getTypeForVariableLikeDeclaration(declaration) { - if (declaration.parent.parent.kind === 178) { + if (declaration.parent.parent.kind === 182) { return anyType; } if (ts.isBindingPattern(declaration.parent)) { @@ -8311,10 +8723,10 @@ var ts; if (declaration.type) { return getTypeFromTypeNode(declaration.type); } - if (declaration.kind === 124) { + if (declaration.kind === 126) { var func = declaration.parent; - if (func.kind === 131 && !ts.hasDynamicName(func)) { - var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 130); + if (func.kind === 133 && !ts.hasDynamicName(func)) { + var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 132); if (getter) { return getReturnTypeOfSignature(getSignatureFromDeclaration(getter)); } @@ -8327,7 +8739,7 @@ var ts; if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } - if (declaration.kind === 205) { + if (declaration.kind === 209) { return checkIdentifier(declaration.name); } return undefined; @@ -8356,7 +8768,7 @@ var ts; var hasSpreadElement = false; var elementTypes = []; ts.forEach(pattern.elements, function (e) { - elementTypes.push(e.kind === 168 || e.dotDotDotToken ? anyType : getTypeFromBindingElement(e)); + elementTypes.push(e.kind === 172 || e.dotDotDotToken ? anyType : getTypeFromBindingElement(e)); if (e.dotDotDotToken) { hasSpreadElement = true; } @@ -8364,7 +8776,7 @@ var ts; return !elementTypes.length ? anyArrayType : hasSpreadElement ? createArrayType(getUnionType(elementTypes)) : createTupleType(elementTypes); } function getTypeFromBindingPattern(pattern) { - return pattern.kind === 144 ? getTypeFromObjectBindingPattern(pattern) : getTypeFromArrayBindingPattern(pattern); + return pattern.kind === 146 ? getTypeFromObjectBindingPattern(pattern) : getTypeFromArrayBindingPattern(pattern); } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { var type = getTypeForVariableLikeDeclaration(declaration); @@ -8372,7 +8784,7 @@ var ts; if (reportErrors) { reportErrorsFromWidening(declaration, type); } - return declaration.kind !== 204 ? getWidenedType(type) : type; + return declaration.kind !== 208 ? getWidenedType(type) : type; } if (ts.isBindingPattern(declaration.name)) { return getTypeFromBindingPattern(declaration.name); @@ -8380,7 +8792,7 @@ var ts; type = declaration.dotDotDotToken ? anyArrayType : anyType; if (reportErrors && compilerOptions.noImplicitAny) { var root = getRootDeclaration(declaration); - if (!isPrivateWithinAmbient(root) && !(root.kind === 124 && isPrivateWithinAmbient(root.parent))) { + if (!isPrivateWithinAmbient(root) && !(root.kind === 126 && isPrivateWithinAmbient(root.parent))) { reportImplicitAnyError(declaration, type); } } @@ -8393,7 +8805,7 @@ var ts; return links.type = getTypeOfPrototypeProperty(symbol); } var declaration = symbol.valueDeclaration; - if (declaration.kind === 203) { + if (declaration.kind === 207) { return links.type = anyType; } links.type = resolvingType; @@ -8416,7 +8828,7 @@ var ts; } function getAnnotatedAccessorType(accessor) { if (accessor) { - if (accessor.kind === 130) { + if (accessor.kind === 132) { return accessor.type && getTypeFromTypeNode(accessor.type); } else { @@ -8435,8 +8847,8 @@ var ts; links = links || getSymbolLinks(symbol); if (!links.type) { links.type = resolvingType; - var getter = ts.getDeclarationOfKind(symbol, 130); - var setter = ts.getDeclarationOfKind(symbol, 131); + var getter = ts.getDeclarationOfKind(symbol, 132); + var setter = ts.getDeclarationOfKind(symbol, 133); var type; var getterReturnType = getAnnotatedAccessorType(getter); if (getterReturnType) { @@ -8466,7 +8878,7 @@ var ts; else if (links.type === resolvingType) { links.type = anyType; if (compilerOptions.noImplicitAny) { - var getter = ts.getDeclarationOfKind(symbol, 130); + var getter = ts.getDeclarationOfKind(symbol, 132); error(getter, ts.Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol)); } } @@ -8533,7 +8945,7 @@ var ts; function getTypeParametersOfClassOrInterface(symbol) { var result; ts.forEach(symbol.declarations, function (node) { - if (node.kind === 192 || node.kind === 191) { + if (node.kind === 196 || node.kind === 195) { var declaration = node; if (declaration.typeParameters && declaration.typeParameters.length) { ts.forEach(declaration.typeParameters, function (node) { @@ -8564,7 +8976,7 @@ var ts; type.typeArguments = type.typeParameters; } type.baseTypes = []; - var declaration = ts.getDeclarationOfKind(symbol, 191); + var declaration = ts.getDeclarationOfKind(symbol, 195); var baseTypeNode = ts.getClassBaseTypeNode(declaration); if (baseTypeNode) { var baseType = getTypeFromTypeReferenceNode(baseTypeNode); @@ -8605,7 +9017,7 @@ var ts; } type.baseTypes = []; ts.forEach(symbol.declarations, function (declaration) { - if (declaration.kind === 192 && ts.getInterfaceBaseTypeNodes(declaration)) { + if (declaration.kind === 196 && ts.getInterfaceBaseTypeNodes(declaration)) { ts.forEach(ts.getInterfaceBaseTypeNodes(declaration), function (node) { var baseType = getTypeFromTypeReferenceNode(node); if (baseType !== unknownType) { @@ -8636,7 +9048,7 @@ var ts; var links = getSymbolLinks(symbol); if (!links.declaredType) { links.declaredType = resolvingType; - var declaration = ts.getDeclarationOfKind(symbol, 193); + var declaration = ts.getDeclarationOfKind(symbol, 197); var type = getTypeFromTypeNode(declaration.type); if (links.declaredType === resolvingType) { links.declaredType = type; @@ -8644,7 +9056,7 @@ var ts; } else if (links.declaredType === resolvingType) { links.declaredType = unknownType; - var declaration = ts.getDeclarationOfKind(symbol, 193); + var declaration = ts.getDeclarationOfKind(symbol, 197); error(declaration.name, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol)); } return links.declaredType; @@ -8663,7 +9075,7 @@ var ts; if (!links.declaredType) { var type = createType(512); type.symbol = symbol; - if (!ts.getDeclarationOfKind(symbol, 123).constraint) { + if (!ts.getDeclarationOfKind(symbol, 125).constraint) { type.constraint = noConstraintType; } links.declaredType = type; @@ -9066,7 +9478,7 @@ var ts; function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { - var classType = declaration.kind === 129 ? getDeclaredTypeOfClass(declaration.parent.symbol) : undefined; + var classType = declaration.kind === 131 ? getDeclaredTypeOfClass(declaration.parent.symbol) : undefined; var typeParameters = classType ? classType.typeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; var hasStringLiterals = false; @@ -9094,8 +9506,8 @@ var ts; returnType = getTypeFromTypeNode(declaration.type); } else { - if (declaration.kind === 130 && !ts.hasDynamicName(declaration)) { - var setter = ts.getDeclarationOfKind(declaration.symbol, 131); + if (declaration.kind === 132 && !ts.hasDynamicName(declaration)) { + var setter = ts.getDeclarationOfKind(declaration.symbol, 133); returnType = getAnnotatedAccessorType(setter); } if (!returnType && ts.nodeIsMissing(declaration.body)) { @@ -9113,19 +9525,19 @@ var ts; for (var i = 0, len = symbol.declarations.length; i < len; i++) { var node = symbol.declarations[i]; switch (node.kind) { - case 136: - case 137: - case 190: - case 128: - case 127: + case 138: + case 139: + case 194: + case 130: case 129: + case 131: + case 134: + case 135: + case 136: case 132: case 133: - case 134: - case 130: - case 131: - case 156: - case 157: + case 158: + case 159: if (i > 0 && node.body) { var previous = symbol.declarations[i - 1]; if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) { @@ -9194,7 +9606,7 @@ var ts; } function getOrCreateTypeFromSignature(signature) { if (!signature.isolatedSignatureType) { - var isConstructor = signature.declaration.kind === 129 || signature.declaration.kind === 133; + var isConstructor = signature.declaration.kind === 131 || signature.declaration.kind === 135; var type = createObjectType(32768 | 65536); type.members = emptySymbols; type.properties = emptyArray; @@ -9235,7 +9647,7 @@ var ts; type.constraint = targetConstraint ? instantiateType(targetConstraint, type.mapper) : noConstraintType; } else { - type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 123).constraint); + type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 125).constraint); } } return type.constraint === noConstraintType ? undefined : type.constraint; @@ -9283,13 +9695,13 @@ var ts; while (!ts.forEach(typeParameterSymbol.declarations, function (d) { return d.parent === currentNode.parent; })) { currentNode = currentNode.parent; } - links.isIllegalTypeReferenceInConstraint = currentNode.kind === 123; + links.isIllegalTypeReferenceInConstraint = currentNode.kind === 125; return links.isIllegalTypeReferenceInConstraint; } function checkTypeParameterHasIllegalReferencesInConstraint(typeParameter) { var typeParameterSymbol; function check(n) { - if (n.kind === 135 && n.typeName.kind === 64) { + if (n.kind === 137 && n.typeName.kind === 64) { var links = getNodeLinks(n); if (links.isIllegalTypeReferenceInConstraint === undefined) { var symbol = resolveName(typeParameter, n.typeName.text, 793056, undefined, undefined); @@ -9354,9 +9766,9 @@ var ts; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; switch (declaration.kind) { - case 191: - case 192: - case 194: + case 195: + case 196: + case 198: return declaration; } } @@ -9532,24 +9944,24 @@ var ts; return voidType; case 8: return getTypeFromStringLiteral(node); - case 135: + case 137: return getTypeFromTypeReferenceNode(node); - case 138: - return getTypeFromTypeQueryNode(node); case 140: + return getTypeFromTypeQueryNode(node); + case 142: return getTypeFromArrayTypeNode(node); - case 141: + case 143: return getTypeFromTupleTypeNode(node); - case 142: + case 144: return getTypeFromUnionTypeNode(node); - case 143: + case 145: return getTypeFromTypeNode(node.type); - case 136: - case 137: + case 138: case 139: + case 141: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); case 64: - case 121: + case 123: var symbol = getSymbolInfo(node); return symbol && getDeclaredTypeOfSymbol(symbol); default: @@ -9693,25 +10105,25 @@ var ts; return type; } function isContextSensitive(node) { - ts.Debug.assert(node.kind !== 128 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 130 || ts.isObjectLiteralMethod(node)); switch (node.kind) { - case 156: - case 157: + case 158: + case 159: return isContextSensitiveFunctionLikeDeclaration(node); - case 148: + case 150: return ts.forEach(node.properties, isContextSensitive); - case 147: + case 149: return ts.forEach(node.elements, isContextSensitive); - case 164: + case 167: return isContextSensitive(node.whenTrue) || isContextSensitive(node.whenFalse); - case 163: + case 166: return node.operator === 49 && (isContextSensitive(node.left) || isContextSensitive(node.right)); - case 204: + case 208: return isContextSensitive(node.initializer); - case 128: - case 127: + case 130: + case 129: return isContextSensitiveFunctionLikeDeclaration(node); - case 155: + case 157: return isContextSensitive(node.expression); } return false; @@ -10464,20 +10876,20 @@ var ts; function reportImplicitAnyError(declaration, type) { var typeAsString = typeToString(getWidenedType(type)); switch (declaration.kind) { - case 126: - case 125: + case 128: + case 127: var diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type; break; - case 124: + case 126: var diagnostic = declaration.dotDotDotToken ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Parameter_0_implicitly_has_an_1_type; break; - case 190: - case 128: - case 127: + case 194: case 130: - case 131: - case 156: - case 157: + case 129: + case 132: + case 133: + case 158: + case 159: if (!declaration.name) { error(declaration, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString); return; @@ -10705,10 +11117,10 @@ var ts; function isInTypeQuery(node) { while (node) { switch (node.kind) { - case 138: + case 140: return true; case 64: - case 121: + case 123: node = node.parent; continue; default: @@ -10747,7 +11159,7 @@ var ts; function isAssignedInBinaryExpression(node) { if (node.operator >= 52 && node.operator <= 63) { var n = node.left; - while (n.kind === 155) { + while (n.kind === 157) { n = n.expression; } if (n.kind === 64 && getResolvedSymbol(n) === symbol) { @@ -10764,45 +11176,47 @@ var ts; } function isAssignedIn(node) { switch (node.kind) { - case 163: + case 166: return isAssignedInBinaryExpression(node); - case 188: - case 146: + case 192: + case 148: return isAssignedInVariableDeclaration(node); - case 144: - case 145: + case 146: case 147: - case 148: case 149: case 150: case 151: case 152: + case 153: case 154: - case 155: - case 161: - case 158: - case 159: + case 156: + case 157: + case 164: case 160: + case 163: + case 161: case 162: - case 164: + case 165: + case 169: case 167: - case 170: case 171: - case 173: case 174: case 175: - case 176: case 177: case 178: + case 179: + case 180: case 181: case 182: - case 183: - case 200: - case 201: - case 184: case 185: case 186: - case 203: + case 187: + case 204: + case 205: + case 188: + case 189: + case 190: + case 207: return ts.forEachChild(node, isAssignedIn); } return false; @@ -10839,17 +11253,17 @@ var ts; node = node.parent; var narrowedType = type; switch (node.kind) { - case 174: + case 178: if (child !== node.expression) { narrowedType = narrowType(type, node.expression, child === node.thenStatement); } break; - case 164: + case 167: if (child !== node.condition) { narrowedType = narrowType(type, node.condition, child === node.whenTrue); } break; - case 163: + case 166: if (child === node.right) { if (node.operator === 48) { narrowedType = narrowType(type, node.left, true); @@ -10859,14 +11273,14 @@ var ts; } } break; - case 207: - case 195: - case 190: - case 128: - case 127: + case 211: + case 199: + case 194: case 130: - case 131: case 129: + case 132: + case 133: + case 131: break loop; } if (narrowedType !== type) { @@ -10879,7 +11293,7 @@ var ts; } return type; function narrowTypeByEquality(type, expr, assumeTrue) { - if (expr.left.kind !== 159 || expr.right.kind !== 8) { + if (expr.left.kind !== 161 || expr.right.kind !== 8) { return type; } var left = expr.left; @@ -10952,9 +11366,9 @@ var ts; } function narrowType(type, expr, assumeTrue) { switch (expr.kind) { - case 155: + case 157: return narrowType(type, expr.expression, assumeTrue); - case 163: + case 166: var operator = expr.operator; if (operator === 30 || operator === 31) { return narrowTypeByEquality(type, expr, assumeTrue); @@ -10969,7 +11383,7 @@ var ts; return narrowTypeByInstanceof(type, expr, assumeTrue); } break; - case 161: + case 164: if (expr.operator === 46) { return narrowType(type, expr.operand, !assumeTrue); } @@ -10985,19 +11399,34 @@ var ts; nodeLinks.importOnRightSide = undefined; getSymbolLinks(rightSide).referenced = true; ts.Debug.assert((rightSide.flags & 8388608) !== 0); - nodeLinks = getNodeLinks(ts.getDeclarationOfKind(rightSide, 197)); + nodeLinks = getNodeLinks(ts.getDeclarationOfKind(rightSide, 201)); } } + function renameSymbol(symbol, name) { + if (!symbolNameOverrides) { + symbolNameOverrides = []; + } + symbolNameOverrides[symbol.id] = name; + } + function getRenamedIdentifier(name) { + if (symbolNameOverrides) { + var links = getNodeLinks(name); + if (links.resolvedSymbol) { + return symbolNameOverrides[links.resolvedSymbol.id]; + } + } + return undefined; + } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); - if (symbol === argumentsSymbol && ts.getContainingFunction(node).kind === 157) { + if (symbol === argumentsSymbol && ts.getContainingFunction(node).kind === 159) { error(node, ts.Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression); } if (symbol.flags & 8388608) { var symbolLinks = getSymbolLinks(symbol); if (!symbolLinks.referenced) { var importOrExportAssignment = getLeftSideOfImportOrExportAssignment(node); - if (!importOrExportAssignment || (importOrExportAssignment.flags & 1) || (importOrExportAssignment.kind === 198)) { + if (!importOrExportAssignment || (importOrExportAssignment.flags & 1) || (importOrExportAssignment.kind === 202)) { symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); } else { @@ -11007,17 +11436,24 @@ var ts; } } if (symbolLinks.referenced) { - markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 197)); + markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 201)); } } + if (isLexicalArguments(node)) { + var container = ts.getContainingFunction(node); + captureLexicalArguments(node, container); + } checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); + checkCollisionWithCapturedArgumentsVariable(node, node); + checkCollisionWithAwaiterVariablesInGeneratedCode(node, node); + checkCollisionWithGeneratorVariablesInGeneratedCode(node, node); return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } function captureLexicalThis(node, container) { - var classNode = container.parent && container.parent.kind === 191 ? container.parent : undefined; + var classNode = container.parent && container.parent.kind === 195 ? container.parent : undefined; getNodeLinks(node).flags |= 2; - if (container.kind === 126 || container.kind === 129) { + if (container.kind === 128 || container.kind === 131) { getNodeLinks(classNode).flags |= 4; } else { @@ -11027,53 +11463,68 @@ var ts; function checkThisExpression(node) { var container = ts.getThisContainer(node, true); var needToCaptureLexicalThis = false; - if (container.kind === 157) { + if (container.kind === 159) { container = ts.getThisContainer(container, false); needToCaptureLexicalThis = (languageVersion < 2); } + if (node.parserContextFlags & 64) { + needToCaptureLexicalThis = true; + } switch (container.kind) { - case 195: + case 199: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_body); break; - case 194: + case 198: error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location); break; - case 129: + case 131: if (isInConstructorArgumentInitializer(node, container)) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_constructor_arguments); } break; - case 126: - case 125: + case 128: + case 127: if (container.flags & 128) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); } break; - case 122: + case 124: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_computed_property_name); break; } if (needToCaptureLexicalThis) { captureLexicalThis(node, container); } - var classNode = container.parent && container.parent.kind === 191 ? container.parent : undefined; + var classNode = container.parent && container.parent.kind === 195 ? container.parent : undefined; if (classNode) { var symbol = getSymbolOfNode(classNode); return container.flags & 128 ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); } return anyType; } - function isInConstructorArgumentInitializer(node, constructorDecl) { - for (var n = node; n && n !== constructorDecl; n = n.parent) { - if (n.kind === 124) { - return true; - } + function isLexicalArguments(node) { + if (node.text === "arguments" && node.parserContextFlags & 64) { + return true; + } + return false; + } + function captureLexicalArguments(node, container) { + if (node.parent.kind !== 126) { + getNodeLinks(node).flags |= 8; + } + getNodeLinks(container).flags |= 16; + } + function isInConstructorArgumentInitializer(node, constructorDecl) { + for (var n = node; n && n !== constructorDecl; n = n.parent) { + if (n.kind === 126) { + return true; + } } return false; } function checkSuperExpression(node) { - var isCallExpression = node.parent.kind === 151 && node.parent.expression === node; - var enclosingClass = ts.getAncestor(node, 191); + var isCallExpression = node.parent.kind === 153 && node.parent.expression === node; + var enclosingClass = ts.getAncestor(node, 195); var baseClass; if (enclosingClass && ts.getClassBaseTypeNode(enclosingClass)) { var classType = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClass)); @@ -11087,34 +11538,34 @@ var ts; if (container) { var canUseSuperExpression = false; if (isCallExpression) { - canUseSuperExpression = container.kind === 129; + canUseSuperExpression = container.kind === 131; } else { var needToCaptureLexicalThis = false; - while (container && container.kind === 157) { + while (container && container.kind === 159) { container = ts.getSuperContainer(container, true); needToCaptureLexicalThis = true; } - if (container && container.parent && container.parent.kind === 191) { + if (container && container.parent && container.parent.kind === 195) { if (container.flags & 128) { - canUseSuperExpression = container.kind === 128 || container.kind === 127 || container.kind === 130 || container.kind === 131; + canUseSuperExpression = container.kind === 130 || container.kind === 129 || container.kind === 132 || container.kind === 133; } else { - canUseSuperExpression = container.kind === 128 || container.kind === 127 || container.kind === 130 || container.kind === 131 || container.kind === 126 || container.kind === 125 || container.kind === 129; + canUseSuperExpression = container.kind === 130 || container.kind === 129 || container.kind === 132 || container.kind === 133 || container.kind === 128 || container.kind === 127 || container.kind === 131; } } } if (canUseSuperExpression) { var returnType; if ((container.flags & 128) || isCallExpression) { - getNodeLinks(node).flags |= 32; + getNodeLinks(node).flags |= 128; returnType = getTypeOfSymbol(baseClass.symbol); } else { - getNodeLinks(node).flags |= 16; + getNodeLinks(node).flags |= 64; returnType = baseClass; } - if (container.kind === 129 && isInConstructorArgumentInitializer(node, container)) { + if (container.kind === 131 && isInConstructorArgumentInitializer(node, container)) { error(node, ts.Diagnostics.super_cannot_be_referenced_in_constructor_arguments); returnType = unknownType; } @@ -11124,7 +11575,7 @@ var ts; return returnType; } } - if (container.kind === 122) { + if (container.kind === 124) { error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); } else if (isCallExpression) { @@ -11161,7 +11612,7 @@ var ts; if (declaration.type) { return getTypeFromTypeNode(declaration.type); } - if (declaration.kind === 124) { + if (declaration.kind === 126) { var type = getContextuallyTypedParameterType(declaration); if (type) { return type; @@ -11176,7 +11627,7 @@ var ts; function getContextualTypeForReturnExpression(node) { var func = ts.getContainingFunction(node); if (func) { - if (func.type || func.kind === 129 || func.kind === 130 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(func.symbol, 131))) { + if (func.type || func.kind === 131 || func.kind === 132 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(func.symbol, 133))) { return getReturnTypeOfSignature(getSignatureFromDeclaration(func)); } var signature = getContextualSignatureForFunctionLikeDeclaration(func); @@ -11196,7 +11647,7 @@ var ts; return undefined; } function getContextualTypeForSubstitutionExpression(template, substitutionExpression) { - if (template.parent.kind === 153) { + if (template.parent.kind === 155) { return getContextualTypeForArgument(template.parent, substitutionExpression); } return undefined; @@ -11300,32 +11751,32 @@ var ts; } var parent = node.parent; switch (parent.kind) { - case 188: - case 124: + case 192: case 126: - case 125: - case 146: + case 128: + case 127: + case 148: return getContextualTypeForInitializerExpression(node); - case 157: - case 181: + case 159: + case 185: return getContextualTypeForReturnExpression(node); - case 151: - case 152: - return getContextualTypeForArgument(parent, node); + case 153: case 154: + return getContextualTypeForArgument(parent, node); + case 156: return getTypeFromTypeNode(parent.type); - case 163: + case 166: return getContextualTypeForBinaryOperand(node); - case 204: + case 208: return getContextualTypeForObjectLiteralElement(parent); - case 147: + case 149: return getContextualTypeForElementExpression(node); - case 164: + case 167: return getContextualTypeForConditionalOperand(node); - case 169: - ts.Debug.assert(parent.parent.kind === 165); + case 173: + ts.Debug.assert(parent.parent.kind === 168); return getContextualTypeForSubstitutionExpression(parent.parent, node); - case 155: + case 157: return getContextualType(parent); } return undefined; @@ -11340,13 +11791,13 @@ var ts; } } function isFunctionExpressionOrArrowFunction(node) { - return node.kind === 156 || node.kind === 157; + return node.kind === 158 || node.kind === 159; } function getContextualSignatureForFunctionLikeDeclaration(node) { return isFunctionExpressionOrArrowFunction(node) ? getContextualSignature(node) : undefined; } function getContextualSignature(node) { - ts.Debug.assert(node.kind !== 128 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 130 || ts.isObjectLiteralMethod(node)); var type = ts.isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getContextualType(node); if (!type) { return undefined; @@ -11386,13 +11837,13 @@ var ts; } function isAssignmentTarget(node) { var parent = node.parent; - if (parent.kind === 163 && parent.operator === 52 && parent.left === node) { + if (parent.kind === 166 && parent.operator === 52 && parent.left === node) { return true; } - if (parent.kind === 204) { + if (parent.kind === 208) { return isAssignmentTarget(parent.parent); } - if (parent.kind === 147) { + if (parent.kind === 149) { return isAssignmentTarget(parent); } return false; @@ -11414,7 +11865,7 @@ var ts; var elementTypes = []; ts.forEach(elements, function (e) { var type = checkExpression(e, contextualMapper); - if (e.kind === 167) { + if (e.kind === 171) { elementTypes.push(getIndexTypeOfType(type, 1) || anyType); hasSpreadElement = true; } @@ -11431,7 +11882,7 @@ var ts; return createArrayType(getUnionType(elementTypes)); } function isNumericName(name) { - return name.kind === 122 ? isNumericComputedName(name) : isNumericLiteralName(name.text); + return name.kind === 124 ? isNumericComputedName(name) : isNumericLiteralName(name.text); } function isNumericComputedName(name) { return isTypeOfKind(checkComputedPropertyName(name), 1 | 132); @@ -11458,16 +11909,16 @@ var ts; for (var i = 0; i < node.properties.length; i++) { var memberDecl = node.properties[i]; var member = memberDecl.symbol; - if (memberDecl.kind === 204 || memberDecl.kind === 205 || ts.isObjectLiteralMethod(memberDecl)) { - if (memberDecl.kind === 204) { + if (memberDecl.kind === 208 || memberDecl.kind === 209 || ts.isObjectLiteralMethod(memberDecl)) { + if (memberDecl.kind === 208) { var type = checkPropertyAssignment(memberDecl, contextualMapper); } - else if (memberDecl.kind === 128) { + else if (memberDecl.kind === 130) { var type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { - ts.Debug.assert(memberDecl.kind === 205); - var type = memberDecl.name.kind === 122 ? unknownType : checkExpression(memberDecl.name, contextualMapper); + ts.Debug.assert(memberDecl.kind === 209); + var type = memberDecl.name.kind === 124 ? unknownType : checkExpression(memberDecl.name, contextualMapper); } typeFlags |= type.flags; var prop = createSymbol(4 | 67108864 | member.flags, member.name); @@ -11481,7 +11932,7 @@ var ts; member = prop; } else { - ts.Debug.assert(memberDecl.kind === 130 || memberDecl.kind === 131); + ts.Debug.assert(memberDecl.kind === 132 || memberDecl.kind === 133); checkAccessorDeclaration(memberDecl); } if (!ts.hasDynamicName(memberDecl)) { @@ -11514,7 +11965,7 @@ var ts; } } function getDeclarationKindFromSymbol(s) { - return s.valueDeclaration ? s.valueDeclaration.kind : 126; + return s.valueDeclaration ? s.valueDeclaration.kind : 128; } function getDeclarationFlagsFromSymbol(s) { return s.valueDeclaration ? ts.getCombinedNodeFlags(s.valueDeclaration) : s.flags & 134217728 ? 16 | 128 : 0; @@ -11524,7 +11975,7 @@ var ts; if (!(flags & (32 | 64))) { return; } - var enclosingClassDeclaration = ts.getAncestor(node, 191); + var enclosingClassDeclaration = ts.getAncestor(node, 195); var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; var declaringClass = getDeclaredTypeOfSymbol(prop.parent); if (flags & 32) { @@ -11571,7 +12022,7 @@ var ts; } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & 32) { - if (left.kind === 90 && getDeclarationKindFromSymbol(prop) !== 128) { + if (left.kind === 90 && getDeclarationKindFromSymbol(prop) !== 130) { error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); } else { @@ -11583,12 +12034,12 @@ var ts; return anyType; } function isValidPropertyAccess(node, propertyName) { - var left = node.kind === 149 ? node.expression : node.left; + var left = node.kind === 151 ? node.expression : node.left; var type = checkExpressionOrQualifiedName(left); if (type !== unknownType && type !== anyType) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & 32) { - if (left.kind === 90 && getDeclarationKindFromSymbol(prop) !== 128) { + if (left.kind === 90 && getDeclarationKindFromSymbol(prop) !== 130) { return false; } else { @@ -11603,7 +12054,7 @@ var ts; function checkIndexedAccess(node) { if (!node.argumentExpression) { var sourceFile = getSourceFile(node); - if (node.parent.kind === 152 && node.parent.expression === node) { + if (node.parent.kind === 154 && node.parent.expression === node) { var start = ts.skipTrivia(sourceFile.text, node.expression.end); var end = node.end; grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); @@ -11658,7 +12109,7 @@ var ts; return unknownType; } function resolveUntypedCall(node) { - if (node.kind === 153) { + if (node.kind === 155) { checkExpression(node.template); } else { @@ -11711,7 +12162,7 @@ var ts; } function getSpreadArgumentIndex(args) { for (var i = 0; i < args.length; i++) { - if (args[i].kind === 167) { + if (args[i].kind === 171) { return i; } } @@ -11721,11 +12172,11 @@ var ts; var adjustedArgCount; var typeArguments; var callIsIncomplete; - if (node.kind === 153) { + if (node.kind === 155) { var tagExpression = node; adjustedArgCount = args.length; typeArguments = undefined; - if (tagExpression.template.kind === 165) { + if (tagExpression.template.kind === 168) { var templateExpression = tagExpression.template; var lastSpan = ts.lastOrUndefined(templateExpression.templateSpans); ts.Debug.assert(lastSpan !== undefined); @@ -11740,7 +12191,7 @@ var ts; else { var callExpression = node; if (!callExpression.arguments) { - ts.Debug.assert(callExpression.kind === 152); + ts.Debug.assert(callExpression.kind === 154); return signature.minArgumentCount === 0; } adjustedArgCount = callExpression.arguments.hasTrailingComma ? args.length + 1 : args.length; @@ -11783,9 +12234,9 @@ var ts; var inferenceMapper = createInferenceMapper(context); for (var i = 0; i < args.length; i++) { var arg = args[i]; - if (arg.kind !== 168) { - var paramType = getTypeAtPosition(signature, arg.kind === 167 ? -1 : i); - if (i === 0 && args[i].parent.kind === 153) { + if (arg.kind !== 172) { + var paramType = getTypeAtPosition(signature, arg.kind === 171 ? -1 : i); + if (i === 0 && args[i].parent.kind === 155) { var argType = globalTemplateStringsArrayType; } else { @@ -11799,7 +12250,7 @@ var ts; for (var i = 0; i < args.length; i++) { if (excludeArgument[i] === false) { var arg = args[i]; - var paramType = getTypeAtPosition(signature, arg.kind === 167 ? -1 : i); + var paramType = getTypeAtPosition(signature, arg.kind === 171 ? -1 : i); inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType); } } @@ -11832,9 +12283,9 @@ var ts; function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) { for (var i = 0; i < args.length; i++) { var arg = args[i]; - if (arg.kind !== 168) { - var paramType = getTypeAtPosition(signature, arg.kind === 167 ? -1 : i); - var argType = i === 0 && node.kind === 153 ? globalTemplateStringsArrayType : arg.kind === 8 && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); + if (arg.kind !== 172) { + var paramType = getTypeAtPosition(signature, arg.kind === 171 ? -1 : i); + var argType = i === 0 && node.kind === 155 ? globalTemplateStringsArrayType : arg.kind === 8 && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); if (!checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1)) { return false; } @@ -11844,10 +12295,10 @@ var ts; } function getEffectiveCallArguments(node) { var args; - if (node.kind === 153) { + if (node.kind === 155) { var template = node.template; args = [template]; - if (template.kind === 165) { + if (template.kind === 168) { ts.forEach(template.templateSpans, function (span) { args.push(span.expression); }); @@ -11860,7 +12311,7 @@ var ts; } function getEffectiveTypeArguments(callExpression) { if (callExpression.expression.kind === 90) { - var containingClass = ts.getAncestor(callExpression, 191); + var containingClass = ts.getAncestor(callExpression, 195); var baseClassTypeNode = containingClass && ts.getClassBaseTypeNode(containingClass); return baseClassTypeNode && baseClassTypeNode.typeArguments; } @@ -11869,7 +12320,7 @@ var ts; } } function resolveCall(node, signatures, candidatesOutArray) { - var isTaggedTemplate = node.kind === 153; + var isTaggedTemplate = node.kind === 155; var typeArguments; if (!isTaggedTemplate) { typeArguments = getEffectiveTypeArguments(node); @@ -12075,13 +12526,13 @@ var ts; var links = getNodeLinks(node); if (!links.resolvedSignature || candidatesOutArray) { links.resolvedSignature = anySignature; - if (node.kind === 151) { + if (node.kind === 153) { links.resolvedSignature = resolveCallExpression(node, candidatesOutArray); } - else if (node.kind === 152) { + else if (node.kind === 154) { links.resolvedSignature = resolveNewExpression(node, candidatesOutArray); } - else if (node.kind === 153) { + else if (node.kind === 155) { links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray); } else { @@ -12096,9 +12547,9 @@ var ts; if (node.expression.kind === 90) { return voidType; } - if (node.kind === 152) { + if (node.kind === 154) { var declaration = signature.declaration; - if (declaration && declaration.kind !== 129 && declaration.kind !== 133 && declaration.kind !== 137) { + if (declaration && declaration.kind !== 131 && declaration.kind !== 135 && declaration.kind !== 139) { if (compilerOptions.noImplicitAny) { error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type); } @@ -12143,18 +12594,28 @@ var ts; links.type = instantiateType(getTypeOfSymbol(context.parameters[context.parameters.length - 1]), mapper); } } + function createPromiseType(promisedType, location) { + if (globalPromiseSymbol) { + promisedType = getAwaitedType(promisedType); + var promiseType = globalPromiseType || getDeclaredTypeOfSymbol(globalPromiseSymbol); + return promiseType !== emptyObjectType ? createTypeReference(promiseType, [promisedType]) : emptyObjectType; + } + error(location, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); + return unknownType; + } function getReturnTypeFromBody(func, contextualMapper) { var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func); if (!func.body) { return unknownType; } - if (func.body.kind !== 170) { - var type = checkExpressionCached(func.body, contextualMapper); + var isAsync = ts.isAsyncFunction(func); + if (func.body.kind !== 174) { + var type = checkExpressionCached(func.body, contextualMapper, isAsync); } else { - var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); + var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync); if (types.length === 0) { - return voidType; + return isAsync ? createPromiseType(voidType, func) : voidType; } var type = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!type) { @@ -12165,14 +12626,15 @@ var ts; if (!contextualSignature) { reportErrorsFromWidening(func, type); } - return getWidenedType(type); + type = getWidenedType(type); + return isAsync ? createPromiseType(type, func) : type; } - function checkAndAggregateReturnExpressionTypes(body, contextualMapper) { + function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync) { var aggregatedTypes = []; ts.forEachReturnStatement(body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { - var type = checkExpressionCached(expr, contextualMapper); + var type = checkExpressionCached(expr, contextualMapper, isAsync); if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } @@ -12186,7 +12648,7 @@ var ts; }); } function bodyContainsSingleThrowStatement(body) { - return (body.statements.length === 1) && (body.statements[0].kind === 185); + return (body.statements.length === 1) && (body.statements[0].kind === 189); } function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) { if (!produceDiagnostics) { @@ -12195,7 +12657,7 @@ var ts; if (returnType === voidType || returnType === anyType) { return; } - if (ts.nodeIsMissing(func.body) || func.body.kind !== 170) { + if (ts.nodeIsMissing(func.body) || func.body.kind !== 174) { return; } var bodyBlock = func.body; @@ -12208,20 +12670,24 @@ var ts; error(func.type, ts.Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement); } function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { - ts.Debug.assert(node.kind !== 128 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 130 || ts.isObjectLiteralMethod(node)); var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); - if (!hasGrammarError && node.kind === 156) { + if (!hasGrammarError && node.kind === 158) { checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); } if (contextualMapper === identityMapper && isContextSensitive(node)) { return anyFunctionType; } + var isAsync = ts.isAsyncFunction(node); + if (isAsync) { + emitAwaiter = true; + } var links = getNodeLinks(node); var type = getTypeOfSymbol(node.symbol); - if (!(links.flags & 64)) { + if (!(links.flags & 256)) { var contextualSignature = getContextualSignature(node); - if (!(links.flags & 64)) { - links.flags |= 64; + if (!(links.flags & 256)) { + links.flags |= 256; if (contextualSignature) { var signature = getSignaturesOfType(type, 0)[0]; if (isContextSensitive(node)) { @@ -12238,25 +12704,32 @@ var ts; checkSignatureDeclaration(node); } } - if (produceDiagnostics && node.kind !== 128 && node.kind !== 127) { + if (produceDiagnostics && node.kind !== 130 && node.kind !== 129) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollisionWithCapturedArgumentsVariable(node, node.name); } return type; } function checkFunctionExpressionOrObjectLiteralMethodBody(node) { - ts.Debug.assert(node.kind !== 128 || ts.isObjectLiteralMethod(node)); - if (node.type) { - checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); + ts.Debug.assert(node.kind !== 130 || ts.isObjectLiteralMethod(node)); + var isAsync = ts.isAsyncFunction(node); + var returnType = node.type ? getTypeFromTypeNode(node.type) : undefined; + var promisedType; + if (returnType && isAsync) { + promisedType = checkAsyncFunctionReturnType(node, returnType); + } + if (returnType) { + checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, isAsync ? promisedType : returnType); } if (node.body) { - if (node.body.kind === 170) { + if (node.body.kind === 174) { checkSourceElement(node.body); } else { var exprType = checkExpression(node.body); - if (node.type) { - checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined); + if (returnType) { + checkTypeAssignableTo(isAsync ? getAwaitedType(exprType) : exprType, isAsync ? promisedType : returnType, node.body); } checkFunctionExpressionBodies(node.body); } @@ -12279,12 +12752,12 @@ var ts; case 64: var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 3) !== 0; - case 149: + case 151: var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || (symbol.flags & ~8) !== 0; - case 150: + case 152: return true; - case 155: + case 157: return isReferenceOrErrorExpression(n.expression); default: return false; @@ -12293,10 +12766,10 @@ var ts; function isConstVariableReference(n) { switch (n.kind) { case 64: - case 149: + case 151: var symbol = findSymbol(n); return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 4096) !== 0; - case 150: + case 152: var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8) { @@ -12305,7 +12778,7 @@ var ts; return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 4096) !== 0; } return false; - case 155: + case 157: return isConstVariableReference(n.expression); default: return false; @@ -12336,6 +12809,19 @@ var ts; var operandType = checkExpression(node.expression); return undefinedType; } + function checkAwaitExpression(node) { + if (!(node.parserContextFlags & 64)) { + var parameter = ts.getContainingParameter(node); + if (parameter && parameter.parserContextFlags & 64) { + grammarErrorAfterFirstToken(node, ts.Diagnostics._0_expression_is_not_allowed_in_an_initializer, "await"); + } + else { + grammarErrorOnFirstToken(node, ts.Diagnostics.await_expression_must_be_contained_within_an_async_function); + } + } + var operandType = checkExpression(node.expression); + return getAwaitedType(operandType); + } function checkPrefixUnaryExpression(node) { if ((node.operator === 38 || node.operator === 39)) { checkGrammarEvalOrArgumentsInStrictMode(node, node.operand); @@ -12410,7 +12896,7 @@ var ts; var properties = node.properties; for (var i = 0; i < properties.length; i++) { var p = properties[i]; - if (p.kind === 204 || p.kind === 205) { + if (p.kind === 208 || p.kind === 209) { var name = p.name; var type = sourceType.flags & 1 ? sourceType : getTypeOfPropertyOfType(sourceType, name.text) || isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, 1) || getIndexTypeOfType(sourceType, 0); if (type) { @@ -12434,8 +12920,8 @@ var ts; var elements = node.elements; for (var i = 0; i < elements.length; i++) { var e = elements[i]; - if (e.kind !== 168) { - if (e.kind !== 167) { + if (e.kind !== 172) { + if (e.kind !== 171) { var propName = "" + i; var type = sourceType.flags & 1 ? sourceType : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : getIndexTypeOfType(sourceType, 1); if (type) { @@ -12458,14 +12944,14 @@ var ts; return sourceType; } function checkDestructuringAssignment(target, sourceType, contextualMapper) { - if (target.kind === 163 && target.operator === 52) { + if (target.kind === 166 && target.operator === 52) { checkBinaryExpression(target, contextualMapper); target = target.left; } - if (target.kind === 148) { + if (target.kind === 150) { return checkObjectLiteralAssignment(target, sourceType, contextualMapper); } - if (target.kind === 147) { + if (target.kind === 149) { return checkArrayLiteralAssignment(target, sourceType, contextualMapper); } return checkReferenceAssignment(target, sourceType, contextualMapper); @@ -12482,7 +12968,7 @@ var ts; checkGrammarEvalOrArgumentsInStrictMode(node, node.left); } var operator = node.operator; - if (operator === 52 && (node.left.kind === 148 || node.left.kind === 147)) { + if (operator === 52 && (node.left.kind === 150 || node.left.kind === 149)) { return checkDestructuringAssignment(node.left, checkExpression(node.right, contextualMapper), contextualMapper); } var leftType = checkExpression(node.left, contextualMapper); @@ -12603,7 +13089,13 @@ var ts; } function checkYieldExpression(node) { if (!(node.parserContextFlags & 4)) { - grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); + var parameter = ts.getContainingParameter(node); + if (parameter && (parameter.parserContextFlags & 4)) { + grammarErrorAfterFirstToken(node, ts.Diagnostics._0_expression_is_not_allowed_in_an_initializer, "yield"); + } + else { + grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); + } } else { grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported); @@ -12628,11 +13120,17 @@ var ts; node.contextualType = saveContextualType; return result; } - function checkExpressionCached(node, contextualMapper) { + function checkExpressionCached(node, contextualMapper, resolveAwaitedType) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = checkExpression(node, contextualMapper); } + if (resolveAwaitedType) { + if (!links.resolvedAwaitedType) { + links.resolvedAwaitedType = getAwaitedType(links.resolvedType); + } + return links.resolvedAwaitedType; + } return links.resolvedType; } function checkPropertyAssignment(node, contextualMapper) { @@ -12669,7 +13167,7 @@ var ts; } function checkExpressionOrQualifiedName(node, contextualMapper) { var type; - if (node.kind == 121) { + if (node.kind == 123) { type = checkQualifiedName(node); } else { @@ -12677,7 +13175,7 @@ var ts; type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } if (isConstEnumObjectType(type)) { - var ok = (node.parent.kind === 149 && node.parent.expression === node) || (node.parent.kind === 150 && node.parent.expression === node) || ((node.kind === 64 || node.kind === 121) && isInRightSideOfImportOrExportAssignment(node)); + var ok = (node.parent.kind === 151 && node.parent.expression === node) || (node.parent.kind === 152 && node.parent.expression === node) || ((node.kind === 64 || node.kind === 123) && isInRightSideOfImportOrExportAssignment(node)); if (!ok) { error(node, ts.Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment); } @@ -12703,52 +13201,54 @@ var ts; return booleanType; case 7: return checkNumericLiteral(node); - case 165: + case 168: return checkTemplateExpression(node); case 8: case 10: return stringType; case 9: return globalRegExpType; - case 147: - return checkArrayLiteral(node, contextualMapper); - case 148: - return checkObjectLiteral(node, contextualMapper); case 149: - return checkPropertyAccessExpression(node); + return checkArrayLiteral(node, contextualMapper); case 150: - return checkIndexedAccess(node); + return checkObjectLiteral(node, contextualMapper); case 151: + return checkPropertyAccessExpression(node); case 152: - return checkCallExpression(node); + return checkIndexedAccess(node); case 153: - return checkTaggedTemplateExpression(node); case 154: - return checkTypeAssertion(node); + return checkCallExpression(node); case 155: - return checkExpression(node.expression, contextualMapper); + return checkTaggedTemplateExpression(node); case 156: + return checkTypeAssertion(node); case 157: - return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); + return checkExpression(node.expression, contextualMapper); + case 158: case 159: + return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); + case 161: return checkTypeOfExpression(node); - case 158: - return checkDeleteExpression(node); case 160: + return checkDeleteExpression(node); + case 162: return checkVoidExpression(node); - case 161: + case 163: + return checkAwaitExpression(node); + case 164: return checkPrefixUnaryExpression(node); - case 162: + case 165: return checkPostfixUnaryExpression(node); - case 163: + case 166: return checkBinaryExpression(node, contextualMapper); - case 164: - return checkConditionalExpression(node, contextualMapper); case 167: + return checkConditionalExpression(node, contextualMapper); + case 171: return checkSpreadElementExpression(node, contextualMapper); - case 168: + case 172: return undefinedType; - case 166: + case 169: checkYieldExpression(node); return unknownType; } @@ -12770,7 +13270,7 @@ var ts; var func = ts.getContainingFunction(node); if (node.flags & 112) { func = ts.getContainingFunction(node); - if (!(func.kind === 129 && ts.nodeIsPresent(func.body))) { + if (!(func.kind === 131 && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } @@ -12784,10 +13284,10 @@ var ts; } } function checkSignatureDeclaration(node) { - if (node.kind === 134) { + if (node.kind === 136) { checkGrammarIndexSignature(node); } - else if (node.kind === 136 || node.kind === 190 || node.kind === 137 || node.kind === 132 || node.kind === 129 || node.kind === 133) { + else if (node.kind === 138 || node.kind === 194 || node.kind === 139 || node.kind === 134 || node.kind === 131 || node.kind === 135) { checkGrammarFunctionLikeDeclaration(node); } checkTypeParameters(node.typeParameters); @@ -12796,22 +13296,40 @@ var ts; checkSourceElement(node.type); } if (produceDiagnostics) { + checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name); + checkCollisionWithGeneratorVariablesInGeneratedCode(node, node.name); checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { - case 133: + case 135: error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; - case 132: + case 134: error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; } } + if (ts.isAsyncFunction(node)) { + var promiseConstructor = getPromiseConstructor(node); + if (promiseConstructor) { + var promiseIdentifier = getFirstIdentifier(promiseConstructor); + var promiseName = promiseIdentifier.text; + var typeSymbol = resolveName(node, promiseName, 793056 | 1536, undefined, undefined); + var valueSymbol = resolveName(node, promiseName, 107455, undefined, undefined); + if (typeSymbol !== valueSymbol) { + var valueLinks = getNodeLinks(valueSymbol.valueDeclaration); + if (!(valueLinks.flags & 512)) { + valueLinks.flags |= 512; + error(valueSymbol.valueDeclaration, ts.Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, promiseName, ts.getTextOfNode(promiseConstructor)); + } + } + } + } } checkSpecializedSignatureDeclaration(node); } function checkTypeForDuplicateIndexSignatures(node) { - if (node.kind === 192) { + if (node.kind === 196) { var nodeSymbol = getSymbolOfNode(node); if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) { return; @@ -12870,17 +13388,17 @@ var ts; return; } function isSuperCallExpression(n) { - return n.kind === 151 && n.expression.kind === 90; + return n.kind === 153 && n.expression.kind === 90; } function containsSuperCall(n) { if (isSuperCallExpression(n)) { return true; } switch (n.kind) { - case 156: - case 190: - case 157: - case 148: return false; + case 158: + case 194: + case 159: + case 150: return false; default: return ts.forEachChild(n, containsSuperCall); } } @@ -12888,19 +13406,19 @@ var ts; if (n.kind === 92) { error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location); } - else if (n.kind !== 156 && n.kind !== 190) { + else if (n.kind !== 158 && n.kind !== 194) { ts.forEachChild(n, markThisReferencesAsErrors); } } function isInstancePropertyWithInitializer(n) { - return n.kind === 126 && !(n.flags & 128) && !!n.initializer; + return n.kind === 128 && !(n.flags & 128) && !!n.initializer; } if (ts.getClassBaseTypeNode(node.parent)) { if (containsSuperCall(node.body)) { var superCallShouldBeFirst = ts.forEach(node.parent.members, isInstancePropertyWithInitializer) || ts.forEach(node.parameters, function (p) { return p.flags & (16 | 32 | 64); }); if (superCallShouldBeFirst) { var statements = node.body.statements; - if (!statements.length || statements[0].kind !== 173 || !isSuperCallExpression(statements[0].expression)) { + if (!statements.length || statements[0].kind !== 177 || !isSuperCallExpression(statements[0].expression)) { error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); } else { @@ -12915,14 +13433,14 @@ var ts; } function checkAccessorDeclaration(node) { if (produceDiagnostics) { - checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); - if (node.kind === 130) { + checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); + if (node.kind === 132) { if (!ts.isInAmbientContext(node) && ts.nodeIsPresent(node.body) && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement); } } if (!ts.hasDynamicName(node)) { - var otherKind = node.kind === 130 ? 131 : 130; + var otherKind = node.kind === 132 ? 133 : 132; var otherAccessor = ts.getDeclarationOfKind(node.symbol, otherKind); if (otherAccessor) { if (((node.flags & 112) !== (otherAccessor.flags & 112))) { @@ -12996,9 +13514,9 @@ var ts; return; } var signaturesToCheck; - if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 192) { - ts.Debug.assert(signatureDeclarationNode.kind === 132 || signatureDeclarationNode.kind === 133); - var signatureKind = signatureDeclarationNode.kind === 132 ? 0 : 1; + if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 196) { + ts.Debug.assert(signatureDeclarationNode.kind === 134 || signatureDeclarationNode.kind === 135); + var signatureKind = signatureDeclarationNode.kind === 134 ? 0 : 1; var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent); var containingType = getDeclaredTypeOfSymbol(containingSymbol); signaturesToCheck = getSignaturesOfType(containingType, signatureKind); @@ -13016,7 +13534,7 @@ var ts; } function getEffectiveDeclarationFlags(n, flagsToCheck) { var flags = ts.getCombinedNodeFlags(n); - if (n.parent.kind !== 192 && ts.isInAmbientContext(n)) { + if (n.parent.kind !== 196 && ts.isInAmbientContext(n)) { if (!(flags & 2)) { flags |= 1; } @@ -13089,7 +13607,7 @@ var ts; if (subsequentNode.kind === node.kind) { var errorNode = subsequentNode.name || subsequentNode; if (node.name && subsequentNode.name && node.name.text === subsequentNode.name.text) { - ts.Debug.assert(node.kind === 128 || node.kind === 127); + ts.Debug.assert(node.kind === 130 || node.kind === 129); ts.Debug.assert((node.flags & 128) !== (subsequentNode.flags & 128)); var diagnostic = node.flags & 128 ? ts.Diagnostics.Function_overload_must_be_static : ts.Diagnostics.Function_overload_must_not_be_static; error(errorNode, diagnostic); @@ -13115,11 +13633,11 @@ var ts; for (var i = 0; i < declarations.length; i++) { var node = declarations[i]; var inAmbientContext = ts.isInAmbientContext(node); - var inAmbientContextOrInterface = node.parent.kind === 192 || node.parent.kind === 139 || inAmbientContext; + var inAmbientContextOrInterface = node.parent.kind === 196 || node.parent.kind === 141 || inAmbientContext; if (inAmbientContextOrInterface) { previousDeclaration = undefined; } - if (node.kind === 190 || node.kind === 128 || node.kind === 127 || node.kind === 129) { + if (node.kind === 194 || node.kind === 130 || node.kind === 129 || node.kind === 131) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; @@ -13216,14 +13734,14 @@ var ts; } function getDeclarationSpaces(d) { switch (d.kind) { - case 192: + case 196: return 2097152; - case 195: + case 199: return d.name.kind === 8 || ts.getModuleInstanceState(d) !== 0 ? 4194304 | 1048576 : 4194304; - case 191: - case 194: + case 195: + case 198: return 2097152 | 1048576; - case 197: + case 201: var result = 0; var target = resolveImport(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { @@ -13235,11 +13753,92 @@ var ts; } } } + function getPromisedType(type) { + if (!globalPromiseLikeInterfaceType || !(type.flags & 48128)) { + return undefined; + } + if (isTypeAssignableTo(type, globalPromiseLikeInterfaceType)) { + var awaitedTypes = []; + var thenProp = getPropertyOfType(type, "then"); + var thenType = getTypeOfSymbol(thenProp); + var thenSignatures = getSignaturesOfType(thenType, 0); + var thenSignatureCount = thenSignatures.length; + for (var i = 0; i < thenSignatureCount; i++) { + var thenSignature = getErasedSignature(thenSignatures[i]); + var onfulfilledParameterType = getTypeAtPosition(thenSignature, 0); + var onfulfilledParameterSignatures = getSignaturesOfType(onfulfilledParameterType, 0); + var onfulfilledParameterSignaturesCount = onfulfilledParameterSignatures.length; + for (var j = 0; j < onfulfilledParameterSignaturesCount; j++) { + var onfulfilledParameterSignature = onfulfilledParameterSignatures[i]; + var valueParameterType = getTypeAtPosition(onfulfilledParameterSignature, 0); + if (valueParameterType !== type) { + awaitedTypes.push(valueParameterType); + } + } + } + return getUnionType(awaitedTypes); + } + return undefined; + } + function getAwaitedType(type) { + if (!globalPromiseLikeInterfaceType || !(type.flags & 48128)) { + return type; + } + var promisedType = getPromisedType(type); + if (promisedType) { + if (promisedType === type) { + return emptyObjectType; + } + var seen; + while (true) { + var nestedPromisedType = getPromisedType(promisedType); + if (!nestedPromisedType) { + return promisedType; + } + if (!seen) { + seen = []; + seen[type.id] = true; + seen[promisedType.id] = true; + } + else if (seen[nestedPromisedType.id]) { + return emptyObjectType; + } + seen[nestedPromisedType.id] = true; + promisedType = nestedPromisedType; + } + return promisedType; + } + if (isTypeAssignableTo(type, thenableType)) { + error(null, ts.Diagnostics.Type_for_await_does_not_have_a_valid_callable_then_member); + return emptyObjectType; + } + return type; + } + function checkAsyncFunctionReturnType(node, returnType) { + if (!returnType) { + returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } + var declaredType = returnType.symbol ? getTypeOfSymbol(returnType.symbol) : emptyObjectType; + if (isTypeAssignableTo(declaredType, globalPromiseConstructorLikeInterfaceType)) { + var promisedType = getPromisedType(returnType); + if (promisedType) { + var promiseConstructor = getPromiseConstructor(node); + if (promiseConstructor) { + emitAwaiter = true; + checkExpressionOrQualifiedName(promiseConstructor); + return getAwaitedType(promisedType); + } + } + } + error(node, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); + return emptyObjectType; + } function checkFunctionDeclaration(node) { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollisionWithCapturedArgumentsVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); } } @@ -13262,19 +13861,25 @@ var ts; } } checkSourceElement(node.body); - if (node.type && !isAccessor(node.kind)) { - checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); + if (node.type && !ts.isAnyAccessor(node)) { + if (ts.isAsyncFunction(node)) { + var promisedType = checkAsyncFunctionReturnType(node, getTypeFromTypeNode(node.type)); + checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, promisedType); + } + else { + checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); + } } if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) { reportImplicitAnyError(node, anyType); } } function checkBlock(node) { - if (node.kind === 170) { + if (node.kind === 174) { checkGrammarForStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); - if (ts.isFunctionBlock(node) || node.kind === 196) { + if (ts.isFunctionBlock(node) || node.kind === 200) { checkFunctionExpressionBodies(node); } } @@ -13292,14 +13897,14 @@ var ts; if (!(identifier && identifier.text === name)) { return false; } - if (node.kind === 126 || node.kind === 125 || node.kind === 128 || node.kind === 127 || node.kind === 130 || node.kind === 131) { + if (node.kind === 128 || node.kind === 127 || node.kind === 130 || node.kind === 129 || node.kind === 132 || node.kind === 133) { return false; } if (ts.isInAmbientContext(node)) { return false; } var root = getRootDeclaration(node); - if (root.kind === 124 && ts.nodeIsMissing(root.parent.body)) { + if (root.kind === 126 && ts.nodeIsMissing(root.parent.body)) { return false; } return true; @@ -13309,6 +13914,11 @@ var ts; potentialThisCollisions.push(node); } } + function checkCollisionWithCapturedArgumentsVariable(node, name) { + if (needCollisionCheckForIdentifier(node, name, "_arguments")) { + potentialArgumentsCollisions.push(node); + } + } function checkIfThisIsCapturedInEnclosingScope(node) { var current = node; while (current) { @@ -13325,11 +13935,27 @@ var ts; current = current.parent; } } + function checkIfArgumentsIsCapturedInEnclosingScope(node) { + var current = node; + while (current) { + if (getNodeCheckFlags(current) & 16) { + var isDeclaration = node.kind !== 64; + if (isDeclaration) { + error(node.name, ts.Diagnostics.Duplicate_identifier_arguments_Compiler_uses_variable_declaration_arguments_to_capture_arguments_reference); + } + else { + error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_arguments_that_compiler_uses_to_capture_arguments_reference); + } + return; + } + current = current.parent; + } + } function checkCollisionWithCapturedSuperVariable(node, name) { if (!needCollisionCheckForIdentifier(node, name, "_super")) { return; } - var enclosingClass = ts.getAncestor(node, 191); + var enclosingClass = ts.getAncestor(node, 195); if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) { return; } @@ -13347,35 +13973,88 @@ var ts; if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { return; } - if (node.kind === 195 && ts.getModuleInstanceState(node) !== 1) { + if (node.kind === 199 && ts.getModuleInstanceState(node) !== 1) { return; } var parent = getDeclarationContainer(node); - if (parent.kind === 207 && ts.isExternalModule(parent)) { + if (parent.kind === 211 && ts.isExternalModule(parent)) { error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module, ts.declarationNameToString(name), ts.declarationNameToString(name)); } } - function checkCollisionWithConstDeclarations(node) { + function checkVarDeclaredNamesNotShadowed(node) { if (node.initializer && (ts.getCombinedNodeFlags(node) & 6144) === 0) { var symbol = getSymbolOfNode(node); if (symbol.flags & 1) { var localDeclarationSymbol = resolveName(node, node.name.text, 3, undefined, undefined); if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & 2) { - if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 4096) { - error(node, ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0, symbolToString(localDeclarationSymbol)); + if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 6144) { + var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 193); + var container = varDeclList.parent.kind === 175 && varDeclList.parent.parent; + var namesShareScope = container && (container.kind === 174 && ts.isAnyFunction(container.parent) || (container.kind === 200 && container.kind === 199) || container.kind === 211); + if (!namesShareScope) { + var name = symbolToString(localDeclarationSymbol); + error(ts.getErrorSpanForNode(node), ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name); + } } } } } } + function getPromiseConstructor(node) { + if (node.type && node.type.kind === 137) { + var typeReference = node.type; + return typeReference.typeName; + } + if (globalPromiseSymbol && globalPromiseSymbol === resolveName(node, "Promise", 107455, undefined, undefined)) { + return globalPromiseSymbol.valueDeclaration.name; + } + } + function checkCollisionWithAwaiterVariablesInGeneratedCode(node, name) { + if (!name || name.kind !== 64 || isTypeNode(name)) { + return; + } + var identifier = name; + if (identifier.text === "__awaiter") { + var isDeclaration = node.kind !== 64; + if (isDeclaration) { + error(node, ts.Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, identifier.text, identifier.text); + } + else { + error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions, identifier.text); + } + } + var container = ts.getContainingFunction(name); + if (container && container.flags & 16384 && node.kind !== 64) { + var promiseConstructor = getPromiseConstructor(container); + if (promiseConstructor && promiseConstructor.kind === 64 && promiseConstructor.text === identifier.text) { + error(node, ts.Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, identifier.text, ts.getTextOfNode(promiseConstructor)); + } + } + } + function checkCollisionWithGeneratorVariablesInGeneratedCode(node, name) { + if (!name || name.kind !== 64 || compilerOptions.target > 1 || isTypeNode(name)) { + return; + } + var identifier = name; + if (identifier.text !== "__generator") { + return; + } + var isDeclaration = node.kind !== 64; + if (isDeclaration) { + error(node, ts.Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, identifier.text, identifier.text); + } + else { + error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions, identifier.text); + } + } function isParameterDeclaration(node) { - while (node.kind === 146) { + while (node.kind === 148) { node = node.parent.parent; } - return node.kind === 124; + return node.kind === 126; } function checkParameterInitializer(node) { - if (getRootDeclaration(node).kind === 124) { + if (getRootDeclaration(node).kind === 126) { var func = ts.getContainingFunction(node); visit(node.initializer); } @@ -13383,7 +14062,7 @@ var ts; if (n.kind === 64) { var referencedSymbol = getNodeLinks(n).resolvedSymbol; if (referencedSymbol && referencedSymbol !== unknownSymbol && getSymbol(func.locals, referencedSymbol.name, 107455) === referencedSymbol) { - if (referencedSymbol.valueDeclaration.kind === 124) { + if (referencedSymbol.valueDeclaration.kind === 126) { if (referencedSymbol.valueDeclaration === node) { error(n, ts.Diagnostics.Parameter_0_cannot_be_referenced_in_its_initializer, ts.declarationNameToString(node.name)); return; @@ -13412,7 +14091,7 @@ var ts; if (ts.isBindingPattern(node.name)) { ts.forEach(node.name.elements, checkSourceElement); } - if (node.initializer && getRootDeclaration(node).kind === 124 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { + if (node.initializer && getRootDeclaration(node).kind === 126 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); return; } @@ -13440,13 +14119,20 @@ var ts; checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined); } } - if (node.kind !== 126 && node.kind !== 125) { + if (node.kind !== 128 && node.kind !== 127) { checkExportsOnMergedDeclarations(node); - checkCollisionWithConstDeclarations(node); + if (node.kind === 192 || node.kind === 148) { + checkVarDeclaredNamesNotShadowed(node); + } checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollisionWithCapturedArgumentsVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); } + if (!ts.isBindingPattern(node.name) && isLexicalArguments(node.name)) { + var container = ts.getContainingFunction(node); + captureLexicalArguments(node.name, container); + } } function checkVariableDeclaration(node) { checkGrammarVariableDeclaration(node); @@ -13463,17 +14149,20 @@ var ts; function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) { if (node.modifiers) { if (inBlockOrObjectLiteralExpression(node)) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + if (node.modifiers.flags & ~16384) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } } } } function inBlockOrObjectLiteralExpression(node) { while (node) { - if (node.kind === 170 || node.kind === 148) { + if (node.kind === 174 || node.kind === 150) { return true; } node = node.parent; } + return false; } function checkExpressionStatement(node) { checkGrammarForStatementInAmbientContext(node); @@ -13497,12 +14186,12 @@ var ts; } function checkForStatement(node) { if (!checkGrammarForStatementInAmbientContext(node)) { - if (node.initializer && node.initializer.kind == 189) { + if (node.initializer && node.initializer.kind == 193) { checkGrammarVariableDeclarationList(node.initializer); } } if (node.initializer) { - if (node.initializer.kind === 189) { + if (node.initializer.kind === 193) { ts.forEach(node.initializer.declarations, checkVariableDeclaration); } else { @@ -13517,7 +14206,7 @@ var ts; } function checkForInStatement(node) { if (!checkGrammarForStatementInAmbientContext(node)) { - if (node.initializer.kind === 189) { + if (node.initializer.kind === 193) { var variableList = node.initializer; if (!checkGrammarVariableDeclarationList(variableList)) { if (variableList.declarations.length > 1) { @@ -13526,7 +14215,7 @@ var ts; } } } - if (node.initializer.kind === 189) { + if (node.initializer.kind === 193) { var variableDeclarationList = node.initializer; if (variableDeclarationList.declarations.length >= 1) { var decl = variableDeclarationList.declarations[0]; @@ -13556,7 +14245,7 @@ var ts; checkGrammarForStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node); } function isGetAccessorWithAnnotatatedSetAccessor(node) { - return !!(node.kind === 130 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 131))); + return !!(node.kind === 132 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 133))); } function checkReturnStatement(node) { if (!checkGrammarForStatementInAmbientContext(node)) { @@ -13570,15 +14259,18 @@ var ts; if (func) { var returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func)); var exprType = checkExpressionCached(node.expression); - if (func.kind === 131) { + if (func.kind === 133) { error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value); } else { - if (func.kind === 129) { + if (func.kind === 131) { if (!isTypeAssignableTo(exprType, returnType)) { error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } } + else if (func.type && !ts.isAnyAccessor(func) && ts.isAsyncFunction(func)) { + checkTypeAssignableTo(getAwaitedType(exprType), getPromisedType(returnType), node.expression, undefined); + } else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) { checkTypeAssignableTo(exprType, returnType, node.expression, undefined); } @@ -13601,7 +14293,7 @@ var ts; var hasDuplicateDefaultClause = false; var expressionType = checkExpression(node.expression); ts.forEach(node.clauses, function (clause) { - if (clause.kind === 201 && !hasDuplicateDefaultClause) { + if (clause.kind === 205 && !hasDuplicateDefaultClause) { if (firstDefaultClause === undefined) { firstDefaultClause = clause; } @@ -13613,7 +14305,7 @@ var ts; hasDuplicateDefaultClause = true; } } - if (produceDiagnostics && clause.kind === 200) { + if (produceDiagnostics && clause.kind === 204) { var caseClause = clause; var caseType = checkExpression(caseClause.expression); if (!isTypeAssignableTo(expressionType, caseType)) { @@ -13630,7 +14322,7 @@ var ts; if (ts.isAnyFunction(current)) { break; } - if (current.kind === 184 && current.label.text === node.label.text) { + if (current.kind === 188 && current.label.text === node.label.text) { var sourceFile = ts.getSourceFileOfNode(node); grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label)); break; @@ -13677,7 +14369,7 @@ var ts; checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, 0); checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, 1); }); - if (type.flags & 1024 && type.symbol.valueDeclaration.kind === 191) { + if (type.flags & 1024 && type.symbol.valueDeclaration.kind === 195) { var classDeclaration = type.symbol.valueDeclaration; for (var i = 0; i < classDeclaration.members.length; i++) { var member = classDeclaration.members[i]; @@ -13708,7 +14400,7 @@ var ts; return; } var errorNode; - if (prop.valueDeclaration.name.kind === 122 || prop.parent === containingType.symbol) { + if (prop.valueDeclaration.name.kind === 124 || prop.parent === containingType.symbol) { errorNode = prop.valueDeclaration; } else if (indexDeclaration) { @@ -13755,6 +14447,8 @@ var ts; checkTypeParameters(node.typeParameters); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name); + checkCollisionWithGeneratorVariablesInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); @@ -13847,9 +14541,6 @@ var ts; } } } - function isAccessor(kind) { - return kind === 130 || kind === 131; - } function areTypeParametersIdentical(list1, list2) { if (!list1 && !list2) { return true; @@ -13915,7 +14606,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 192); + var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 196); if (symbol.declarations.length > 1) { if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) { error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters); @@ -13944,14 +14635,14 @@ var ts; } function computeEnumMemberValues(node) { var nodeLinks = getNodeLinks(node); - if (!(nodeLinks.flags & 128)) { + if (!(nodeLinks.flags & 1024)) { var enumSymbol = getSymbolOfNode(node); var enumType = getDeclaredTypeOfSymbol(enumSymbol); var autoValue = 0; var ambient = ts.isInAmbientContext(node); var enumIsConst = ts.isConst(node); ts.forEach(node.members, function (member) { - if (member.name.kind !== 122 && isNumericLiteralName(member.name.text)) { + if (member.name.kind !== 124 && isNumericLiteralName(member.name.text)) { error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name); } var initializer = member.initializer; @@ -13981,13 +14672,13 @@ var ts; getNodeLinks(member).enumMemberValue = autoValue++; } }); - nodeLinks.flags |= 128; + nodeLinks.flags |= 1024; } function getConstantValueForEnumMemberInitializer(initializer, enumIsConst) { return evalConstant(initializer); function evalConstant(e) { switch (e.kind) { - case 161: + case 164: var value = evalConstant(e.operand); if (value === undefined) { return undefined; @@ -13998,7 +14689,7 @@ var ts; case 47: return enumIsConst ? ~value : undefined; } return undefined; - case 163: + case 166: if (!enumIsConst) { return undefined; } @@ -14026,11 +14717,11 @@ var ts; return undefined; case 7: return +e.text; - case 155: + case 157: return enumIsConst ? evalConstant(e.expression) : undefined; case 64: - case 150: - case 149: + case 152: + case 151: if (!enumIsConst) { return undefined; } @@ -14043,7 +14734,7 @@ var ts; propertyName = e.text; } else { - if (e.kind === 150) { + if (e.kind === 152) { if (e.argumentExpression === undefined || e.argumentExpression.kind !== 8) { return undefined; } @@ -14085,6 +14776,8 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name); + checkCollisionWithGeneratorVariablesInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); computeEnumMemberValues(node); var enumSymbol = getSymbolOfNode(node); @@ -14100,7 +14793,7 @@ var ts; } var seenEnumMissingInitialInitializer = false; ts.forEach(enumSymbol.declarations, function (declaration) { - if (declaration.kind !== 194) { + if (declaration.kind !== 198) { return false; } var enumDeclaration = declaration; @@ -14123,7 +14816,7 @@ var ts; var declarations = symbol.declarations; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; - if ((declaration.kind === 191 || (declaration.kind === 190 && ts.nodeIsPresent(declaration.body))) && !ts.isInAmbientContext(declaration)) { + if ((declaration.kind === 195 || (declaration.kind === 194 && ts.nodeIsPresent(declaration.body))) && !ts.isInAmbientContext(declaration)) { return declaration; } } @@ -14135,11 +14828,11 @@ var ts; if (!ts.isInAmbientContext(node) && node.name.kind === 8) { grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); } - else if (node.name.kind === 64 && node.body.kind === 196) { + else if (node.name.kind === 64 && node.body.kind === 200) { var statements = node.body.statements; for (var i = 0, n = statements.length; i < n; i++) { var statement = statements[i]; - if (statement.kind === 198) { + if (statement.kind === 202) { grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); } else if (ts.isExternalModuleImportDeclaration(statement)) { @@ -14150,6 +14843,8 @@ var ts; } checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name); + checkCollisionWithGeneratorVariablesInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); if (symbol.flags & 512 && symbol.declarations.length > 1 && !ts.isInAmbientContext(node) && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums)) { @@ -14175,7 +14870,7 @@ var ts; checkSourceElement(node.body); } function getFirstIdentifier(node) { - while (node.kind === 121) { + while (node.kind === 123) { node = node.left; } return node; @@ -14184,6 +14879,8 @@ var ts; checkGrammarModifiers(node); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name); + checkCollisionWithGeneratorVariablesInGeneratedCode(node, node.name); var symbol = getSymbolOfNode(node); var target; if (ts.isInternalModuleImportDeclaration(node)) { @@ -14204,10 +14901,10 @@ var ts; } } else { - if (node.parent.kind === 207) { + if (node.parent.kind === 211) { target = resolveImport(symbol); } - else if (node.parent.kind === 196 && node.parent.parent.name.kind === 8) { + else if (node.parent.kind === 200 && node.parent.parent.name.kind === 8) { if (ts.getExternalModuleImportDeclarationExpression(node).kind === 8) { if (isExternalModuleNameRelative(ts.getExternalModuleImportDeclarationExpression(node).text)) { error(node, ts.Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name); @@ -14233,11 +14930,11 @@ var ts; } } function checkExportAssignment(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + if (!checkGrammarModifiers(node) && (node.flags & 16627)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); } var container = node.parent; - if (container.kind !== 207) { + if (container.kind !== 211) { container = container.parent; } checkTypeOfExportAssignmentSymbol(getSymbolOfNode(container)); @@ -14246,176 +14943,178 @@ var ts; if (!node) return; switch (node.kind) { - case 123: + case 125: return checkTypeParameter(node); - case 124: - return checkParameter(node); case 126: - case 125: + return checkParameter(node); + case 128: + case 127: return checkPropertyDeclaration(node); - case 136: - case 137: - case 132: - case 133: - return checkSignatureDeclaration(node); + case 138: + case 139: case 134: + case 135: + return checkSignatureDeclaration(node); + case 136: return checkSignatureDeclaration(node); - case 128: - case 127: - return checkMethodDeclaration(node); - case 129: - return checkConstructorDeclaration(node); case 130: + case 129: + return checkMethodDeclaration(node); case 131: + return checkConstructorDeclaration(node); + case 132: + case 133: return checkAccessorDeclaration(node); - case 135: + case 137: return checkTypeReference(node); - case 138: + case 140: return checkTypeQuery(node); - case 139: + case 141: return checkTypeLiteral(node); - case 140: + case 142: return checkArrayType(node); - case 141: + case 143: return checkTupleType(node); - case 142: + case 144: return checkUnionType(node); - case 143: + case 145: return checkSourceElement(node.type); - case 190: + case 194: return checkFunctionDeclaration(node); - case 170: - case 196: - return checkBlock(node); - case 171: + case 174: + case 200: + return checkBlock(node); + case 175: return checkVariableStatement(node); - case 173: + case 177: return checkExpressionStatement(node); - case 174: + case 178: return checkIfStatement(node); - case 175: + case 179: return checkDoStatement(node); - case 176: + case 180: return checkWhileStatement(node); - case 177: + case 181: return checkForStatement(node); - case 178: + case 182: return checkForInStatement(node); - case 179: - case 180: + case 183: + case 184: return checkBreakOrContinueStatement(node); - case 181: + case 185: return checkReturnStatement(node); - case 182: + case 186: return checkWithStatement(node); - case 183: + case 187: return checkSwitchStatement(node); - case 184: + case 188: return checkLabeledStatement(node); - case 185: + case 189: return checkThrowStatement(node); - case 186: + case 190: return checkTryStatement(node); - case 188: + case 192: return checkVariableDeclaration(node); - case 146: + case 148: return checkBindingElement(node); - case 191: + case 195: return checkClassDeclaration(node); - case 192: + case 196: return checkInterfaceDeclaration(node); - case 193: + case 197: return checkTypeAliasDeclaration(node); - case 194: + case 198: return checkEnumDeclaration(node); - case 195: + case 199: return checkModuleDeclaration(node); - case 197: + case 201: return checkImportDeclaration(node); - case 198: + case 202: return checkExportAssignment(node); - case 172: + case 176: checkGrammarForStatementInAmbientContext(node); return; - case 187: + case 191: checkGrammarForStatementInAmbientContext(node); return; } } function checkFunctionExpressionBodies(node) { switch (node.kind) { - case 156: - case 157: + case 158: + case 159: ts.forEach(node.parameters, checkFunctionExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; - case 128: - case 127: + case 130: + case 129: ts.forEach(node.parameters, checkFunctionExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); } break; - case 129: - case 130: case 131: - case 190: + case 132: + case 133: + case 194: ts.forEach(node.parameters, checkFunctionExpressionBodies); break; - case 182: + case 186: checkFunctionExpressionBodies(node.expression); break; - case 124: case 126: - case 125: - case 144: - case 145: + case 128: + case 127: case 146: case 147: case 148: - case 204: case 149: case 150: + case 208: case 151: case 152: case 153: - case 165: - case 169: case 154: case 155: - case 159: - case 160: - case 158: + case 168: + case 173: + case 156: + case 157: case 161: case 162: case 163: + case 160: case 164: + case 165: + case 166: case 167: - case 170: - case 196: case 171: - case 173: + case 169: case 174: + case 200: case 175: - case 176: case 177: case 178: case 179: case 180: case 181: + case 182: case 183: - case 200: - case 201: case 184: case 185: - case 186: - case 203: + case 187: + case 204: + case 205: case 188: case 189: - case 191: - case 194: - case 206: + case 190: case 207: + case 192: + case 193: + case 195: + case 198: + case 210: + case 211: ts.forEachChild(node, checkFunctionExpressionBodies); break; } @@ -14431,21 +15130,32 @@ var ts; checkGrammarSourceFile(node); emitExtends = false; potentialThisCollisions.length = 0; + potentialArgumentsCollisions.length = 0; ts.forEach(node.statements, checkSourceElement); checkFunctionExpressionBodies(node); if (ts.isExternalModule(node)) { var symbol = getExportAssignmentSymbol(node.symbol); if (symbol && symbol.flags & 8388608) { getSymbolLinks(symbol).referenced = true; - markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 197)); + markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 201)); } } if (potentialThisCollisions.length) { ts.forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope); potentialThisCollisions.length = 0; } + if (potentialArgumentsCollisions.length) { + ts.forEach(potentialArgumentsCollisions, checkIfArgumentsIsCapturedInEnclosingScope); + potentialArgumentsCollisions.length = 0; + } if (emitExtends) { - links.flags |= 8; + links.flags |= 32; + } + if (emitAwaiter) { + links.flags |= 2048; + } + if (emitGenerator || (emitAwaiter && languageVersion < 2)) { + links.flags |= 4096; } links.flags |= 1; } @@ -14471,7 +15181,7 @@ var ts; function isInsideWithStatementBody(node) { if (node) { while (node.parent) { - if (node.parent.kind === 182 && node.parent.statement === node) { + if (node.parent.kind === 186 && node.parent.statement === node) { return true; } node = node.parent; @@ -14507,27 +15217,27 @@ var ts; copySymbols(location.locals, meaning); } switch (location.kind) { - case 207: + case 211: if (!ts.isExternalModule(location)) break; - case 195: + case 199: copySymbols(getSymbolOfNode(location).exports, meaning & 8914931); break; - case 194: + case 198: copySymbols(getSymbolOfNode(location).exports, meaning & 8); break; - case 191: - case 192: + case 195: + case 196: if (!(memberFlags & 128)) { copySymbols(getSymbolOfNode(location).members, meaning & 793056); } break; - case 156: + case 158: if (location.name) { copySymbol(location.symbol, meaning); } break; - case 203: + case 207: if (location.name.text) { copySymbol(location.symbol, meaning); } @@ -14544,22 +15254,22 @@ var ts; } function isTypeDeclaration(node) { switch (node.kind) { - case 123: - case 191: - case 192: - case 193: - case 194: + case 125: + case 195: + case 196: + case 197: + case 198: return true; } } function isTypeReferenceIdentifier(entityName) { var node = entityName; - while (node.parent && node.parent.kind === 121) + while (node.parent && node.parent.kind === 123) node = node.parent; - return node.parent && node.parent.kind === 135; + return node.parent && node.parent.kind === 137; } function isTypeNode(node) { - if (135 <= node.kind && node.kind <= 143) { + if (137 <= node.kind && node.kind <= 145) { return true; } switch (node.kind) { @@ -14569,62 +15279,62 @@ var ts; case 111: return true; case 98: - return node.parent.kind !== 160; + return node.parent.kind !== 162; case 8: - return node.parent.kind === 124; + return node.parent.kind === 126; case 64: - if (node.parent.kind === 121 && node.parent.right === node) { + if (node.parent.kind === 123 && node.parent.right === node) { node = node.parent; } - case 121: - ts.Debug.assert(node.kind === 64 || node.kind === 121, "'node' was expected to be a qualified name or identifier in 'isTypeNode'."); + case 123: + ts.Debug.assert(node.kind === 64 || node.kind === 123, "'node' was expected to be a qualified name or identifier in 'isTypeNode'."); var parent = node.parent; - if (parent.kind === 138) { + if (parent.kind === 140) { return false; } - if (135 <= parent.kind && parent.kind <= 143) { + if (137 <= parent.kind && parent.kind <= 145) { return true; } switch (parent.kind) { - case 123: - return node === parent.constraint; - case 126: case 125: - case 124: - case 188: - return node === parent.type; - case 190: - case 156: - case 157: - case 129: + return node === parent.constraint; case 128: case 127: - case 130: - case 131: + case 126: + case 192: return node === parent.type; + case 194: + case 158: + case 159: + case 131: + case 130: + case 129: case 132: case 133: + return node === parent.type; case 134: + case 135: + case 136: return node === parent.type; - case 154: + case 156: return node === parent.type; - case 151: - case 152: - return parent.typeArguments && ts.indexOf(parent.typeArguments, node) >= 0; case 153: + case 154: + return parent.typeArguments && ts.indexOf(parent.typeArguments, node) >= 0; + case 155: return false; } } return false; } function getLeftSideOfImportOrExportAssignment(nodeOnRightSide) { - while (nodeOnRightSide.parent.kind === 121) { + while (nodeOnRightSide.parent.kind === 123) { nodeOnRightSide = nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === 197) { + if (nodeOnRightSide.parent.kind === 201) { return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === 198) { + if (nodeOnRightSide.parent.kind === 202) { return nodeOnRightSide.parent.exportName === nodeOnRightSide && nodeOnRightSide.parent; } return undefined; @@ -14633,16 +15343,16 @@ var ts; return getLeftSideOfImportOrExportAssignment(node) !== undefined; } function isRightSideOfQualifiedNameOrPropertyAccess(node) { - return (node.parent.kind === 121 && node.parent.right === node) || (node.parent.kind === 149 && node.parent.name === node); + return (node.parent.kind === 123 && node.parent.right === node) || (node.parent.kind === 151 && node.parent.name === node); } function getSymbolOfEntityNameOrPropertyAccessExpression(entityName) { if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { return getSymbolOfNode(entityName.parent); } - if (entityName.parent.kind === 198) { + if (entityName.parent.kind === 202) { return resolveEntityName(entityName.parent.parent, entityName, 107455 | 793056 | 1536 | 8388608); } - if (entityName.kind !== 149) { + if (entityName.kind !== 151) { if (isInRightSideOfImportOrExportAssignment(entityName)) { return getSymbolOfPartOfRightHandSideOfImport(entityName); } @@ -14658,14 +15368,14 @@ var ts; var meaning = 107455 | 8388608; return resolveEntityName(entityName, entityName, meaning); } - else if (entityName.kind === 149) { + else if (entityName.kind === 151) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkPropertyAccessExpression(entityName); } return getNodeLinks(entityName).resolvedSymbol; } - else if (entityName.kind === 121) { + else if (entityName.kind === 123) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkQualifiedName(entityName); @@ -14674,7 +15384,7 @@ var ts; } } else if (isTypeReferenceIdentifier(entityName)) { - var meaning = entityName.parent.kind === 135 ? 793056 : 1536; + var meaning = entityName.parent.kind === 137 ? 793056 : 1536; meaning |= 8388608; return resolveEntityName(entityName, entityName, meaning); } @@ -14688,12 +15398,12 @@ var ts; return getSymbolOfNode(node.parent); } if (node.kind === 64 && isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 198 ? getSymbolOfEntityNameOrPropertyAccessExpression(node) : getSymbolOfPartOfRightHandSideOfImport(node); + return node.parent.kind === 202 ? getSymbolOfEntityNameOrPropertyAccessExpression(node) : getSymbolOfPartOfRightHandSideOfImport(node); } switch (node.kind) { case 64: - case 149: - case 121: + case 151: + case 123: return getSymbolOfEntityNameOrPropertyAccessExpression(node); case 92: case 90: @@ -14701,7 +15411,7 @@ var ts; return type.symbol; case 112: var constructorDeclaration = node.parent; - if (constructorDeclaration && constructorDeclaration.kind === 129) { + if (constructorDeclaration && constructorDeclaration.kind === 131) { return constructorDeclaration.parent.symbol; } return undefined; @@ -14712,7 +15422,7 @@ var ts; return moduleType ? moduleType.symbol : undefined; } case 7: - if (node.parent.kind == 150 && node.parent.argumentExpression === node) { + if (node.parent.kind == 152 && node.parent.argumentExpression === node) { var objectType = checkExpression(node.parent.expression); if (objectType === unknownType) return undefined; @@ -14726,7 +15436,7 @@ var ts; return undefined; } function getShorthandAssignmentValueSymbol(location) { - if (location && location.kind === 205) { + if (location && location.kind === 209) { return resolveEntityName(location, location.name, 107455); } return undefined; @@ -14800,7 +15510,7 @@ var ts; return [symbol]; } function isExternalModuleSymbol(symbol) { - return symbol.flags & 512 && symbol.declarations.length === 1 && symbol.declarations[0].kind === 207; + return symbol.flags & 512 && symbol.declarations.length === 1 && symbol.declarations[0].kind === 211; } function isNodeDescendentOf(node, ancestor) { while (node) { @@ -14818,7 +15528,7 @@ var ts; return false; } if (symbolWithRelevantName.flags & 8388608) { - var importDeclarationWithRelevantName = ts.getDeclarationOfKind(symbolWithRelevantName, 197); + var importDeclarationWithRelevantName = ts.getDeclarationOfKind(symbolWithRelevantName, 201); if (isReferencedImportDeclaration(importDeclarationWithRelevantName)) { return false; } @@ -14842,7 +15552,7 @@ var ts; function getLocalNameForSymbol(symbol, location) { var node = location; while (node) { - if ((node.kind === 195 || node.kind === 194) && getSymbolOfNode(node) === symbol) { + if ((node.kind === 199 || node.kind === 198) && getSymbolOfNode(node) === symbol) { return getLocalNameOfContainer(node); } node = node.parent; @@ -14866,7 +15576,7 @@ var ts; return symbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol) ? symbolToString(symbol) : undefined; } function isTopLevelValueImportWithEntityName(node) { - if (node.parent.kind !== 207 || !ts.isInternalModuleImportDeclaration(node)) { + if (node.parent.kind !== 211 || !ts.isInternalModuleImportDeclaration(node)) { return false; } return isImportResolvedToValue(getSymbolOfNode(node)); @@ -14904,14 +15614,14 @@ var ts; return getNodeLinks(node).enumMemberValue; } function getConstantValue(node) { - if (node.kind === 206) { + if (node.kind === 210) { return getEnumMemberValue(node); } var symbol = getNodeLinks(node).resolvedSymbol; if (symbol && (symbol.flags & 8)) { var declaration = symbol.valueDeclaration; var constantValue; - if (declaration.kind === 206) { + if (declaration.kind === 210) { return getEnumMemberValue(declaration); } } @@ -14944,7 +15654,10 @@ var ts; isSymbolAccessible: isSymbolAccessible, isEntityNameVisible: isEntityNameVisible, getConstantValue: getConstantValue, - isUnknownIdentifier: isUnknownIdentifier + isUnknownIdentifier: isUnknownIdentifier, + renameSymbol: renameSymbol, + getRenamedIdentifier: getRenamedIdentifier, + getPromiseConstructor: getPromiseConstructor }; } function initializeTypeChecker() { @@ -14969,28 +15682,47 @@ var ts; globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); globalTemplateStringsArrayType = languageVersion >= 2 ? getGlobalType("TemplateStringsArray") : unknownType; + var iPromiseType = getTypeOfGlobalSymbol(getGlobalSymbol("IPromise"), 1); + if (iPromiseType !== emptyObjectType) { + globalPromiseLikeInterfaceType = createTypeReference(iPromiseType, [anyType]); + } + globalPromiseConstructorLikeInterfaceType = getGlobalType("IPromiseConstructor"); + if (compilerOptions.target >= 2) { + globalPromiseSymbol = getGlobalSymbol("Promise"); + } + else { + globalPromiseSymbol = resolveName(undefined, "Promise", 793056, undefined, undefined); + } + if (globalPromiseSymbol) { + globalPromiseType = getTypeOfGlobalSymbol(globalPromiseSymbol, 1); + } + var thenPropertySymbol = createSymbol(67108864 | 4, "then"); + getSymbolLinks(thenPropertySymbol).type = globalFunctionType; + thenableType = createObjectType(48128); + thenableType.properties = [thenPropertySymbol]; + thenableType.members = createSymbolTable(thenableType.properties); anyArrayType = createArrayType(anyType); } function checkGrammarModifiers(node) { switch (node.kind) { - case 130: + case 132: + case 133: case 131: - case 129: - case 126: - case 125: case 128: case 127: - case 134: - case 191: - case 192: + case 130: + case 129: + case 136: case 195: - case 194: + case 196: + case 199: case 198: - case 171: - case 190: - case 193: + case 202: + case 175: + case 194: case 197: - case 124: + case 201: + case 126: break; default: return false; @@ -14998,7 +15730,7 @@ var ts; if (!node.modifiers) { return; } - var lastStatic, lastPrivate, lastProtected, lastDeclare; + var lastStatic, lastPrivate, lastProtected, lastDeclare, lastAsync; var flags = 0; for (var i = 0, n = node.modifiers.length; i < n; i++) { var modifier = node.modifiers[i]; @@ -15024,7 +15756,10 @@ var ts; else if (flags & 128) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); } - else if (node.parent.kind === 196 || node.parent.kind === 207) { + else if (flags & 16384) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "async"); + } + else if (node.parent.kind === 200 || node.parent.kind === 211) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); } flags |= ts.modifierToFlag(modifier.kind); @@ -15033,10 +15768,13 @@ var ts; if (flags & 128) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } - else if (node.parent.kind === 196 || node.parent.kind === 207) { + else if (flags & 16384) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "static", "async"); + } + else if (node.parent.kind === 200 || node.parent.kind === 211) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); } - else if (node.kind === 124) { + else if (node.kind === 126) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); } flags |= 128; @@ -15049,10 +15787,13 @@ var ts; else if (flags & 2) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare"); } - else if (node.parent.kind === 191) { + else if (flags & 16384) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "async"); + } + else if (node.parent.kind === 195) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); } - else if (node.kind === 124) { + else if (node.kind === 126) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); } flags |= 1; @@ -15061,21 +15802,37 @@ var ts; if (flags & 2) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); } - else if (node.parent.kind === 191) { + else if (flags & 16384) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); + } + else if (node.parent.kind === 195) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); } - else if (node.kind === 124) { + else if (node.kind === 126) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); } - else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 196) { + else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 200) { return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); } flags |= 2; lastDeclare = modifier; break; + case 121: + if (flags & 16384) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async"); + } + else if (flags & 2 || ts.isInAmbientContext(node.parent)) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); + } + else if (node.kind === 126) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "async"); + } + flags |= 16384; + lastAsync = modifier; + break; } } - if (node.kind === 129) { + if (node.kind === 131) { if (flags & 128) { return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); } @@ -15085,16 +15842,42 @@ var ts; else if (flags & 32) { return grammarErrorOnNode(lastPrivate, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); } + else if (flags & 16384) { + return grammarErrorOnNode(lastAsync, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async"); + } + return; + } + else if (node.kind === 201 && flags & 2) { + return grammarErrorOnNode(lastDeclare, ts.Diagnostics._0_modifier_cannot_be_used_with_an_import_declaration, "declare"); } - else if (node.kind === 197 && flags & 2) { - return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); + else if (node.kind === 196 && flags & 2) { + return grammarErrorOnNode(lastDeclare, ts.Diagnostics._0_modifier_cannot_be_used_with_an_interface_declaration, "declare"); } - else if (node.kind === 192 && flags & 2) { - return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); + else if (node.kind === 126 && (flags & 112) && ts.isBindingPattern(node.name)) { + return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } - else if (node.kind === 124 && (flags & 112) && ts.isBindingPattern(node.name)) { + else if (node.kind === 126 && (flags & 112) && ts.isBindingPattern(node.name)) { return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } + if (flags & 16384) { + return checkGrammarAsyncModifier(node, lastAsync); + } + } + function checkGrammarAsyncModifier(node, asyncModifier) { + if (languageVersion < 2 && !compilerOptions.asyncFunctions) { + return grammarErrorOnNode(asyncModifier, ts.Diagnostics.Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + switch (node.kind) { + case 130: + case 194: + case 158: + case 159: + if (!node.asteriskToken) { + return false; + } + break; + } + return grammarErrorOnNode(asyncModifier, ts.Diagnostics._0_modifier_cannot_be_used_here, "async"); } function checkGrammarForDisallowedTrailingComma(list) { if (list && list.hasTrailingComma) { @@ -15163,7 +15946,7 @@ var ts; else if (parameter.dotDotDotToken) { return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter); } - else if (parameter.flags & 243) { + else if (parameter.flags & 16627) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); } else if (parameter.questionToken) { @@ -15183,7 +15966,7 @@ var ts; } } function checkGrammarForIndexSignatureModifier(node) { - if (node.flags & 243) { + if (node.flags & 16627) { grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members); } } @@ -15206,7 +15989,7 @@ var ts; var sourceFile = ts.getSourceFileOfNode(node); for (var i = 0, n = arguments.length; i < n; i++) { var arg = arguments[i]; - if (arg.kind === 168) { + if (arg.kind === 172) { return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected); } } @@ -15278,14 +16061,14 @@ var ts; return false; } function checkGrammarComputedPropertyName(node) { - if (node.kind !== 122) { + if (node.kind !== 124) { return false; } var computedPropertyName = node; if (languageVersion < 2) { return grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); } - else if (computedPropertyName.expression.kind === 163 && computedPropertyName.expression.operator === 23) { + else if (computedPropertyName.expression.kind === 166 && computedPropertyName.expression.operator === 23) { return grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); } } @@ -15312,25 +16095,25 @@ var ts; for (var i = 0, n = node.properties.length; i < n; i++) { var prop = node.properties[i]; var name = prop.name; - if (prop.kind === 168 || name.kind === 122) { + if (prop.kind === 172 || name.kind === 124) { checkGrammarComputedPropertyName(name); continue; } var currentKind; - if (prop.kind === 204 || prop.kind === 205) { + if (prop.kind === 208 || prop.kind === 209) { checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); if (name.kind === 7) { checkGrammarNumbericLiteral(name); } currentKind = Property; } - else if (prop.kind === 128) { + else if (prop.kind === 130) { currentKind = Property; } - else if (prop.kind === 130) { + else if (prop.kind === 132) { currentKind = GetAccessor; } - else if (prop.kind === 131) { + else if (prop.kind === 133) { currentKind = SetAccesor; } else { @@ -15374,10 +16157,10 @@ var ts; else if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); } - else if (kind === 130 && accessor.parameters.length) { + else if (kind === 132 && accessor.parameters.length) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters); } - else if (kind === 131) { + else if (kind === 133) { if (accessor.type) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); } @@ -15389,7 +16172,7 @@ var ts; if (parameter.dotDotDotToken) { return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter); } - else if (parameter.flags & 243) { + else if (parameter.flags & 16627) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } else if (parameter.questionToken) { @@ -15402,7 +16185,7 @@ var ts; } } function checkGrammarForDisallowedComputedProperty(node, message) { - if (node.kind === 122) { + if (node.kind === 124) { return grammarErrorOnNode(node, message); } } @@ -15410,7 +16193,7 @@ var ts; if (checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { return true; } - if (node.parent.kind === 148) { + if (node.parent.kind === 150) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -15418,7 +16201,7 @@ var ts; return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } } - if (node.parent.kind === 191) { + if (node.parent.kind === 195) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -15429,21 +16212,21 @@ var ts; return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_method_overloads); } } - else if (node.parent.kind === 192) { + else if (node.parent.kind === 196) { return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_interfaces); } - else if (node.parent.kind === 139) { + else if (node.parent.kind === 141) { return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_type_literals); } } function isIterationStatement(node, lookInLabeledStatements) { switch (node.kind) { - case 177: - case 178: - case 175: - case 176: + case 181: + case 182: + case 179: + case 180: return true; - case 184: + case 188: return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements); } return false; @@ -15455,17 +16238,17 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } switch (current.kind) { - case 184: + case 188: if (node.label && current.label.text === node.label.text) { - var isMisplacedContinueLabel = node.kind === 179 && !isIterationStatement(current.statement, true); + var isMisplacedContinueLabel = node.kind === 183 && !isIterationStatement(current.statement, true); if (isMisplacedContinueLabel) { return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); } return false; } break; - case 183: - if (node.kind === 180 && !node.label) { + case 187: + if (node.kind === 184 && !node.label) { return false; } break; @@ -15478,11 +16261,11 @@ var ts; current = current.parent; } if (node.label) { - var message = node.kind === 180 ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; + var message = node.kind === 184 ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); } else { - var message = node.kind === 180 ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; + var message = node.kind === 184 ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); } } @@ -15552,14 +16335,14 @@ var ts; } function allowLetAndConstDeclarations(parent) { switch (parent.kind) { - case 174: - case 175: - case 176: - case 182: - case 177: case 178: + case 179: + case 180: + case 186: + case 181: + case 182: return false; - case 184: + case 188: return allowLetAndConstDeclarations(parent.parent); } return true; @@ -15575,7 +16358,7 @@ var ts; } } function isIntegerLiteral(expression) { - if (expression.kind === 161) { + if (expression.kind === 164) { var unaryExpression = expression; if (unaryExpression.operator === 33 || unaryExpression.operator === 34) { expression = unaryExpression.operand; @@ -15594,7 +16377,7 @@ var ts; var inAmbientContext = ts.isInAmbientContext(enumDecl); for (var i = 0, n = enumDecl.members.length; i < n; i++) { var node = enumDecl.members[i]; - if (node.name.kind === 122) { + if (node.name.kind === 124) { hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); } else if (inAmbientContext) { @@ -15662,17 +16445,17 @@ var ts; } } function checkGrammarProperty(node) { - if (node.parent.kind === 191) { + if (node.parent.kind === 195) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) || checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_class_property_declarations)) { return true; } } - else if (node.parent.kind === 192) { + else if (node.parent.kind === 196) { if (checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_interfaces)) { return true; } } - else if (node.parent.kind === 139) { + else if (node.parent.kind === 141) { if (checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_type_literals)) { return true; } @@ -15682,7 +16465,7 @@ var ts; } } function checkGrammarTopLevelElementForRequiredDeclareModifier(node) { - if (node.kind === 192 || node.kind === 197 || node.kind === 198 || (node.flags & 2)) { + if (node.kind === 196 || node.kind === 201 || node.kind === 202 || (node.flags & 2)) { return false; } return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); @@ -15690,7 +16473,7 @@ var ts; function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) { for (var i = 0, n = file.statements.length; i < n; i++) { var decl = file.statements[i]; - if (ts.isDeclaration(decl) || decl.kind === 171) { + if (ts.isDeclaration(decl) || decl.kind === 175) { if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) { return true; } @@ -15702,14 +16485,14 @@ var ts; } function checkGrammarForStatementInAmbientContext(node) { if (ts.isInAmbientContext(node)) { - if (isAccessor(node.parent.kind)) { + if (ts.isAnyAccessor(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = true; } var links = getNodeLinks(node); if (!links.hasReportedStatementInAmbientContext && ts.isAnyFunction(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); } - if (node.parent.kind === 170 || node.parent.kind === 196 || node.parent.kind === 207) { + if (node.parent.kind === 174 || node.parent.kind === 200 || node.parent.kind === 211) { var links = getNodeLinks(node.parent); if (!links.hasReportedStatementInAmbientContext) { return links.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts); @@ -15745,19 +16528,3233 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { - var indentStrings = ["", " "]; - function getIndentString(level) { - if (indentStrings[level] === undefined) { - indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; + var Factory; + (function (Factory) { + function createStringLiteral(text, location, flags) { + var node = Factory.beginNode(8); + node.text = text; + return Factory.finishNode(node, location, flags); + } + Factory.createStringLiteral = createStringLiteral; + function createNumericLiteral(value, location, flags) { + var node = Factory.beginNode(7); + node.text = String(value); + return Factory.finishNode(node, location, flags); + } + Factory.createNumericLiteral = createNumericLiteral; + function createIdentifier(text, location, flags) { + var node = Factory.beginNode(64); + node.text = text; + return Factory.finishNode(node, location, flags); + } + Factory.createIdentifier = createIdentifier; + function createQualifiedName(left, right, location, flags) { + var node = Factory.beginNode(123); + node.left = left; + node.right = right; + return Factory.finishNode(node, location, flags); } - return indentStrings[level]; - } - ts.getIndentString = getIndentString; - function getIndentSize() { - return indentStrings[1].length; - } - function shouldEmitToOwnFile(sourceFile, compilerOptions) { - if (!ts.isDeclarationFile(sourceFile)) { + Factory.createQualifiedName = createQualifiedName; + function updateQualifiedName(node, left, right) { + if (node.left !== left || node.right !== right) { + return createQualifiedName(left, right, node, node.flags); + } + return node; + } + Factory.updateQualifiedName = updateQualifiedName; + function createComputedPropertyName(expression, location, flags) { + var node = Factory.beginNode(124); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createComputedPropertyName = createComputedPropertyName; + function updateComputedPropertyName(node, expression) { + if (node.expression !== expression) { + return createComputedPropertyName(expression, node, node.flags); + } + return node; + } + Factory.updateComputedPropertyName = updateComputedPropertyName; + function createTypeParameter(name, constraint, expression, location, flags) { + var node = Factory.beginNode(125); + node.name = name; + node.constraint = constraint; + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createTypeParameter = createTypeParameter; + function updateTypeParameter(node, name, constraint) { + if (node.name !== name || node.constraint !== constraint) { + return createTypeParameter(name, constraint, node.expression, node, node.flags); + } + return node; + } + Factory.updateTypeParameter = updateTypeParameter; + function createParameterDeclaration(name, initializer, type, modifiers, dotDotDotToken, questionToken, location, flags) { + var node = Factory.beginNode(126); + node.name = name; + node.initializer = initializer; + node.type = type; + node.modifiers = modifiers; + node.dotDotDotToken = dotDotDotToken; + node.questionToken = questionToken; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createParameterDeclaration = createParameterDeclaration; + function updateParameterDeclaration(node, name, initializer, type) { + if (node.name !== name || node.initializer !== initializer || node.type !== type) { + return createParameterDeclaration(name, initializer, type, node.modifiers, node.dotDotDotToken, node.questionToken, node, node.flags); + } + return node; + } + Factory.updateParameterDeclaration = updateParameterDeclaration; + function createPropertySignature(name, type, questionToken, location, flags) { + var node = Factory.beginNode(127); + node.name = name; + node.type = type; + node.questionToken = questionToken; + return Factory.finishNode(node, location, flags); + } + Factory.createPropertySignature = createPropertySignature; + function updatePropertySignature(node, name, type) { + if (node.name !== name || node.type !== type) { + return createPropertySignature(name, type, node.questionToken, node, node.flags); + } + return node; + } + Factory.updatePropertySignature = updatePropertySignature; + function createPropertyDeclaration(name, initializer, type, questionToken, location, flags) { + var node = Factory.beginNode(128); + node.name = name; + node.initializer = initializer; + node.type = type; + node.questionToken = questionToken; + return Factory.finishNode(node, location, flags); + } + Factory.createPropertyDeclaration = createPropertyDeclaration; + function updatePropertyDeclaration(node, name, initializer, type) { + if (node.name !== name || node.initializer !== initializer || node.type !== type) { + return createPropertyDeclaration(name, initializer, type, node.questionToken, node, node.flags); + } + return node; + } + Factory.updatePropertyDeclaration = updatePropertyDeclaration; + function createMethodSignature(name, parameters, typeParameters, type, modifiers, asteriskToken, questionToken, location, flags) { + var node = Factory.beginNode(129); + node.name = name; + node.parameters = Factory.createNodeArray(parameters); + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + node.asteriskToken = asteriskToken; + node.questionToken = questionToken; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createMethodSignature = createMethodSignature; + function updateMethodSignature(node, name, parameters) { + if (node.name !== name || node.parameters !== parameters) { + return createMethodSignature(name, parameters, node.typeParameters, node.type, node.modifiers, node.asteriskToken, node.questionToken, node, node.flags); + } + return node; + } + Factory.updateMethodSignature = updateMethodSignature; + function createMethodDeclaration(name, parameters, body, typeParameters, type, modifiers, asteriskToken, location, flags) { + var node = Factory.beginNode(130); + node.name = name; + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + node.asteriskToken = asteriskToken; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createMethodDeclaration = createMethodDeclaration; + function updateMethodDeclaration(node, name, parameters, body) { + if (node.name !== name || node.parameters !== parameters || node.body !== body) { + return createMethodDeclaration(name, parameters, body, node.typeParameters, node.type, node.modifiers, node.asteriskToken, node, node.flags); + } + return node; + } + Factory.updateMethodDeclaration = updateMethodDeclaration; + function createConstructor(parameters, body, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(131); + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createConstructor = createConstructor; + function updateConstructor(node, parameters, body) { + if (node.parameters !== parameters || node.body !== body) { + return createConstructor(parameters, body, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateConstructor = updateConstructor; + function createGetAccessor(name, parameters, body, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(132); + node.name = name; + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createGetAccessor = createGetAccessor; + function updateGetAccessor(node, name, parameters, body) { + if (node.name !== name || node.parameters !== parameters || node.body !== body) { + return createGetAccessor(name, parameters, body, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateGetAccessor = updateGetAccessor; + function createSetAccessor(name, parameters, body, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(133); + node.name = name; + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createSetAccessor = createSetAccessor; + function updateSetAccessor(node, name, parameters, body) { + if (node.name !== name || node.parameters !== parameters || node.body !== body) { + return createSetAccessor(name, parameters, body, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateSetAccessor = updateSetAccessor; + function createCallSignature(parameters, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(134); + node.parameters = Factory.createNodeArray(parameters); + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createCallSignature = createCallSignature; + function updateCallSignature(node, parameters) { + if (node.parameters !== parameters) { + return createCallSignature(parameters, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateCallSignature = updateCallSignature; + function createConstructSignature(parameters, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(135); + node.parameters = Factory.createNodeArray(parameters); + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createConstructSignature = createConstructSignature; + function updateConstructSignature(node, parameters) { + if (node.parameters !== parameters) { + return createConstructSignature(parameters, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateConstructSignature = updateConstructSignature; + function createIndexSignature(parameters, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(136); + node.parameters = Factory.createNodeArray(parameters); + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createIndexSignature = createIndexSignature; + function updateIndexSignature(node, parameters) { + if (node.parameters !== parameters) { + return createIndexSignature(parameters, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateIndexSignature = updateIndexSignature; + function createObjectBindingPattern(elements, location, flags) { + var node = Factory.beginNode(146); + node.elements = Factory.createNodeArray(elements); + return Factory.finishNode(node, location, flags); + } + Factory.createObjectBindingPattern = createObjectBindingPattern; + function updateObjectBindingPattern(node, elements) { + if (node.elements !== elements) { + return createObjectBindingPattern(elements, node, node.flags); + } + return node; + } + Factory.updateObjectBindingPattern = updateObjectBindingPattern; + function createArrayBindingPattern(elements, location, flags) { + var node = Factory.beginNode(147); + node.elements = Factory.createNodeArray(elements); + return Factory.finishNode(node, location, flags); + } + Factory.createArrayBindingPattern = createArrayBindingPattern; + function updateArrayBindingPattern(node, elements) { + if (node.elements !== elements) { + return createArrayBindingPattern(elements, node, node.flags); + } + return node; + } + Factory.updateArrayBindingPattern = updateArrayBindingPattern; + function createBindingElement(name, propertyName, initializer, location, flags) { + var node = Factory.beginNode(148); + node.name = name; + node.propertyName = propertyName; + node.initializer = initializer; + return Factory.finishNode(node, location, flags); + } + Factory.createBindingElement = createBindingElement; + function updateBindingElement(node, name, propertyName, initializer) { + if (node.name !== name || node.propertyName !== propertyName || node.initializer !== initializer) { + return createBindingElement(name, propertyName, initializer, node, node.flags); + } + return node; + } + Factory.updateBindingElement = updateBindingElement; + function createArrayLiteralExpression(elements, location, flags) { + var node = Factory.beginNode(149); + node.elements = Factory.createNodeArray(elements); + return Factory.finishNode(node, location, flags); + } + Factory.createArrayLiteralExpression = createArrayLiteralExpression; + function updateArrayLiteralExpression(node, elements) { + if (node.elements !== elements) { + return createArrayLiteralExpression(elements, node, node.flags); + } + return node; + } + Factory.updateArrayLiteralExpression = updateArrayLiteralExpression; + function createObjectLiteralExpression(properties, location, flags) { + var node = Factory.beginNode(150); + node.properties = Factory.createNodeArray(properties); + return Factory.finishNode(node, location, flags); + } + Factory.createObjectLiteralExpression = createObjectLiteralExpression; + function updateObjectLiteralExpression(node, properties) { + if (node.properties !== properties) { + return createObjectLiteralExpression(properties, node, node.flags); + } + return node; + } + Factory.updateObjectLiteralExpression = updateObjectLiteralExpression; + function createPropertyAccessExpression(expression, name, location, flags) { + var node = Factory.beginNode(151); + node.expression = expression; + node.name = name; + return Factory.finishNode(node, location, flags); + } + Factory.createPropertyAccessExpression = createPropertyAccessExpression; + function updatePropertyAccessExpression(node, expression, name) { + if (node.expression !== expression || node.name !== name) { + return createPropertyAccessExpression(expression, name, node, node.flags); + } + return node; + } + Factory.updatePropertyAccessExpression = updatePropertyAccessExpression; + function createElementAccessExpression(expression, argumentExpression, location, flags) { + var node = Factory.beginNode(152); + node.expression = expression; + node.argumentExpression = argumentExpression; + return Factory.finishNode(node, location, flags); + } + Factory.createElementAccessExpression = createElementAccessExpression; + function updateElementAccessExpression(node, expression, argumentExpression) { + if (node.expression !== expression || node.argumentExpression !== argumentExpression) { + return createElementAccessExpression(expression, argumentExpression, node, node.flags); + } + return node; + } + Factory.updateElementAccessExpression = updateElementAccessExpression; + function createCallExpression(expression, arguments, location, flags) { + var node = Factory.beginNode(153); + node.expression = expression; + node.arguments = Factory.createNodeArray(arguments); + return Factory.finishNode(node, location, flags); + } + Factory.createCallExpression = createCallExpression; + function updateCallExpression(node, expression, arguments) { + if (node.expression !== expression || node.arguments !== arguments) { + return createCallExpression(expression, arguments, node, node.flags); + } + return node; + } + Factory.updateCallExpression = updateCallExpression; + function createNewExpression(expression, arguments, location, flags) { + var node = Factory.beginNode(154); + node.expression = expression; + node.arguments = Factory.createNodeArray(arguments); + return Factory.finishNode(node, location, flags); + } + Factory.createNewExpression = createNewExpression; + function updateNewExpression(node, expression, arguments) { + if (node.expression !== expression || node.arguments !== arguments) { + return createNewExpression(expression, arguments, node, node.flags); + } + return node; + } + Factory.updateNewExpression = updateNewExpression; + function createTaggedTemplateExpression(tag, template, location, flags) { + var node = Factory.beginNode(155); + node.tag = tag; + node.template = template; + return Factory.finishNode(node, location, flags); + } + Factory.createTaggedTemplateExpression = createTaggedTemplateExpression; + function updateTaggedTemplateExpression(node, tag, template) { + if (node.tag !== tag || node.template !== template) { + return createTaggedTemplateExpression(tag, template, node, node.flags); + } + return node; + } + Factory.updateTaggedTemplateExpression = updateTaggedTemplateExpression; + function createTypeAssertion(type, expression, location, flags) { + var node = Factory.beginNode(156); + node.type = type; + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createTypeAssertion = createTypeAssertion; + function updateTypeAssertion(node, expression) { + if (node.expression !== expression) { + return createTypeAssertion(node.type, expression, node, node.flags); + } + return node; + } + Factory.updateTypeAssertion = updateTypeAssertion; + function createParenthesizedExpression(expression, location, flags) { + var node = Factory.beginNode(157); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createParenthesizedExpression = createParenthesizedExpression; + function updateParenthesizedExpression(node, expression) { + if (node.expression !== expression) { + return createParenthesizedExpression(expression, node, node.flags); + } + return node; + } + Factory.updateParenthesizedExpression = updateParenthesizedExpression; + function createFunctionExpression(name, parameters, body, typeParameters, type, modifiers, asteriskToken, location, flags) { + var node = Factory.beginNode(158); + node.name = name; + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + node.asteriskToken = asteriskToken; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createFunctionExpression = createFunctionExpression; + function updateFunctionExpression(node, name, parameters, body) { + if (node.name !== name || node.parameters !== parameters || node.body !== body) { + return createFunctionExpression(name, parameters, body, node.typeParameters, node.type, node.modifiers, node.asteriskToken, node, node.flags); + } + return node; + } + Factory.updateFunctionExpression = updateFunctionExpression; + function createArrowFunction(parameters, body, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(159); + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createArrowFunction = createArrowFunction; + function updateArrowFunction(node, parameters, body) { + if (node.parameters !== parameters || node.body !== body) { + return createArrowFunction(parameters, body, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateArrowFunction = updateArrowFunction; + function createDeleteExpression(expression, location, flags) { + var node = Factory.beginNode(160); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createDeleteExpression = createDeleteExpression; + function updateDeleteExpression(node, expression) { + if (node.expression !== expression) { + return createDeleteExpression(expression, node, node.flags); + } + return node; + } + Factory.updateDeleteExpression = updateDeleteExpression; + function createTypeOfExpression(expression, location, flags) { + var node = Factory.beginNode(161); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createTypeOfExpression = createTypeOfExpression; + function updateTypeOfExpression(node, expression) { + if (node.expression !== expression) { + return createTypeOfExpression(expression, node, node.flags); + } + return node; + } + Factory.updateTypeOfExpression = updateTypeOfExpression; + function createVoidExpression(expression, location, flags) { + var node = Factory.beginNode(162); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createVoidExpression = createVoidExpression; + function updateVoidExpression(node, expression) { + if (node.expression !== expression) { + return createVoidExpression(expression, node, node.flags); + } + return node; + } + Factory.updateVoidExpression = updateVoidExpression; + function createAwaitExpression(expression, location, flags) { + var node = Factory.beginNode(163); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createAwaitExpression = createAwaitExpression; + function updateAwaitExpression(node, expression) { + if (node.expression !== expression) { + return createAwaitExpression(expression, node, node.flags); + } + return node; + } + Factory.updateAwaitExpression = updateAwaitExpression; + function createPrefixUnaryExpression(operator, operand, location, flags) { + var node = Factory.beginNode(164); + node.operator = operator; + node.operand = operand; + return Factory.finishNode(node, location, flags); + } + Factory.createPrefixUnaryExpression = createPrefixUnaryExpression; + function updatePrefixUnaryExpression(node, operand) { + if (node.operand !== operand) { + return createPrefixUnaryExpression(node.operator, operand, node, node.flags); + } + return node; + } + Factory.updatePrefixUnaryExpression = updatePrefixUnaryExpression; + function createPostfixUnaryExpression(operator, operand, location, flags) { + var node = Factory.beginNode(165); + node.operator = operator; + node.operand = operand; + return Factory.finishNode(node, location, flags); + } + Factory.createPostfixUnaryExpression = createPostfixUnaryExpression; + function updatePostfixUnaryExpression(node, operand) { + if (node.operand !== operand) { + return createPostfixUnaryExpression(node.operator, operand, node, node.flags); + } + return node; + } + Factory.updatePostfixUnaryExpression = updatePostfixUnaryExpression; + function createBinaryExpression(operator, left, right, location, flags) { + var node = Factory.beginNode(166); + node.operator = operator; + node.left = left; + node.right = right; + return Factory.finishNode(node, location, flags); + } + Factory.createBinaryExpression = createBinaryExpression; + function updateBinaryExpression(node, left, right) { + if (node.left !== left || node.right !== right) { + return createBinaryExpression(node.operator, left, right, node, node.flags); + } + return node; + } + Factory.updateBinaryExpression = updateBinaryExpression; + function createConditionalExpression(condition, whenTrue, whenFalse, location, flags) { + var node = Factory.beginNode(167); + node.condition = condition; + node.whenTrue = whenTrue; + node.whenFalse = whenFalse; + return Factory.finishNode(node, location, flags); + } + Factory.createConditionalExpression = createConditionalExpression; + function updateConditionalExpression(node, condition, whenTrue, whenFalse) { + if (node.condition !== condition || node.whenTrue !== whenTrue || node.whenFalse !== whenFalse) { + return createConditionalExpression(condition, whenTrue, whenFalse, node, node.flags); + } + return node; + } + Factory.updateConditionalExpression = updateConditionalExpression; + function createTemplateExpression(head, templateSpans, location, flags) { + var node = Factory.beginNode(168); + node.head = head; + node.templateSpans = Factory.createNodeArray(templateSpans); + return Factory.finishNode(node, location, flags); + } + Factory.createTemplateExpression = createTemplateExpression; + function updateTemplateExpression(node, head, templateSpans) { + if (node.head !== head || node.templateSpans !== templateSpans) { + return createTemplateExpression(head, templateSpans, node, node.flags); + } + return node; + } + Factory.updateTemplateExpression = updateTemplateExpression; + function createYieldExpression(expression, asteriskToken, location, flags) { + var node = Factory.beginNode(169); + node.expression = expression; + node.asteriskToken = asteriskToken; + return Factory.finishNode(node, location, flags); + } + Factory.createYieldExpression = createYieldExpression; + function updateYieldExpression(node, expression) { + if (node.expression !== expression) { + return createYieldExpression(expression, node.asteriskToken, node, node.flags); + } + return node; + } + Factory.updateYieldExpression = updateYieldExpression; + function createGeneratedLabel(label, labelNumbers, location, flags) { + var node = Factory.beginNode(170); + node.label = label; + node.labelNumbers = labelNumbers; + return Factory.finishNode(node, location, flags); + } + Factory.createGeneratedLabel = createGeneratedLabel; + function createSpreadElementExpression(expression, location, flags) { + var node = Factory.beginNode(171); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createSpreadElementExpression = createSpreadElementExpression; + function updateSpreadElementExpression(node, expression) { + if (node.expression !== expression) { + return createSpreadElementExpression(expression, node, node.flags); + } + return node; + } + Factory.updateSpreadElementExpression = updateSpreadElementExpression; + function createOmittedExpression(location, flags) { + var node = Factory.beginNode(172); + return Factory.finishNode(node, location, flags); + } + Factory.createOmittedExpression = createOmittedExpression; + function createTemplateSpan(expression, literal, location, flags) { + var node = Factory.beginNode(173); + node.expression = expression; + node.literal = literal; + return Factory.finishNode(node, location, flags); + } + Factory.createTemplateSpan = createTemplateSpan; + function updateTemplateSpan(node, expression, literal) { + if (node.expression !== expression || node.literal !== literal) { + return createTemplateSpan(expression, literal, node, node.flags); + } + return node; + } + Factory.updateTemplateSpan = updateTemplateSpan; + function createBlock(statements, location, flags) { + var node = Factory.beginNode(174); + node.statements = Factory.createNodeArray(statements); + return Factory.finishNode(node, location, flags); + } + Factory.createBlock = createBlock; + function updateBlock(node, statements) { + if (node.statements !== statements) { + return createBlock(statements, node, node.flags); + } + return node; + } + Factory.updateBlock = updateBlock; + function createVariableStatement(declarationList, location, flags) { + var node = Factory.beginNode(175); + node.declarationList = declarationList; + return Factory.finishNode(node, location, flags); + } + Factory.createVariableStatement = createVariableStatement; + function updateVariableStatement(node, declarationList) { + if (node.declarationList !== declarationList) { + return createVariableStatement(declarationList, node, node.flags); + } + return node; + } + Factory.updateVariableStatement = updateVariableStatement; + function createEmptyStatement(location, flags) { + var node = Factory.beginNode(176); + return Factory.finishNode(node, location, flags); + } + Factory.createEmptyStatement = createEmptyStatement; + function createExpressionStatement(expression, location, flags) { + var node = Factory.beginNode(177); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createExpressionStatement = createExpressionStatement; + function updateExpressionStatement(node, expression) { + if (node.expression !== expression) { + return createExpressionStatement(expression, node, node.flags); + } + return node; + } + Factory.updateExpressionStatement = updateExpressionStatement; + function createIfStatement(expression, thenStatement, elseStatement, location, flags) { + var node = Factory.beginNode(178); + node.expression = expression; + node.thenStatement = thenStatement; + node.elseStatement = elseStatement; + return Factory.finishNode(node, location, flags); + } + Factory.createIfStatement = createIfStatement; + function updateIfStatement(node, expression, thenStatement, elseStatement) { + if (node.expression !== expression || node.thenStatement !== thenStatement || node.elseStatement !== elseStatement) { + return createIfStatement(expression, thenStatement, elseStatement, node, node.flags); + } + return node; + } + Factory.updateIfStatement = updateIfStatement; + function createDoStatement(statement, expression, location, flags) { + var node = Factory.beginNode(179); + node.statement = statement; + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createDoStatement = createDoStatement; + function updateDoStatement(node, statement, expression) { + if (node.statement !== statement || node.expression !== expression) { + return createDoStatement(statement, expression, node, node.flags); + } + return node; + } + Factory.updateDoStatement = updateDoStatement; + function createWhileStatement(expression, statement, location, flags) { + var node = Factory.beginNode(180); + node.expression = expression; + node.statement = statement; + return Factory.finishNode(node, location, flags); + } + Factory.createWhileStatement = createWhileStatement; + function updateWhileStatement(node, expression, statement) { + if (node.expression !== expression || node.statement !== statement) { + return createWhileStatement(expression, statement, node, node.flags); + } + return node; + } + Factory.updateWhileStatement = updateWhileStatement; + function createForStatement(initializer, condition, iterator, statement, location, flags) { + var node = Factory.beginNode(181); + node.initializer = initializer; + node.condition = condition; + node.iterator = iterator; + node.statement = statement; + return Factory.finishNode(node, location, flags); + } + Factory.createForStatement = createForStatement; + function updateForStatement(node, initializer, condition, iterator, statement) { + if (node.initializer !== initializer || node.condition !== condition || node.iterator !== iterator || node.statement !== statement) { + return createForStatement(initializer, condition, iterator, statement, node, node.flags); + } + return node; + } + Factory.updateForStatement = updateForStatement; + function createForInStatement(initializer, expression, statement, location, flags) { + var node = Factory.beginNode(182); + node.initializer = initializer; + node.expression = expression; + node.statement = statement; + return Factory.finishNode(node, location, flags); + } + Factory.createForInStatement = createForInStatement; + function updateForInStatement(node, initializer, expression, statement) { + if (node.initializer !== initializer || node.expression !== expression || node.statement !== statement) { + return createForInStatement(initializer, expression, statement, node, node.flags); + } + return node; + } + Factory.updateForInStatement = updateForInStatement; + function createContinueStatement(label, location, flags) { + var node = Factory.beginNode(183); + node.label = label; + return Factory.finishNode(node, location, flags); + } + Factory.createContinueStatement = createContinueStatement; + function updateContinueStatement(node, label) { + if (node.label !== label) { + return createContinueStatement(label, node, node.flags); + } + return node; + } + Factory.updateContinueStatement = updateContinueStatement; + function createBreakStatement(label, location, flags) { + var node = Factory.beginNode(184); + node.label = label; + return Factory.finishNode(node, location, flags); + } + Factory.createBreakStatement = createBreakStatement; + function updateBreakStatement(node, label) { + if (node.label !== label) { + return createBreakStatement(label, node, node.flags); + } + return node; + } + Factory.updateBreakStatement = updateBreakStatement; + function createReturnStatement(expression, location, flags) { + var node = Factory.beginNode(185); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createReturnStatement = createReturnStatement; + function updateReturnStatement(node, expression) { + if (node.expression !== expression) { + return createReturnStatement(expression, node, node.flags); + } + return node; + } + Factory.updateReturnStatement = updateReturnStatement; + function createWithStatement(expression, statement, location, flags) { + var node = Factory.beginNode(186); + node.expression = expression; + node.statement = statement; + return Factory.finishNode(node, location, flags); + } + Factory.createWithStatement = createWithStatement; + function updateWithStatement(node, expression, statement) { + if (node.expression !== expression || node.statement !== statement) { + return createWithStatement(expression, statement, node, node.flags); + } + return node; + } + Factory.updateWithStatement = updateWithStatement; + function createSwitchStatement(expression, clauses, location, flags) { + var node = Factory.beginNode(187); + node.expression = expression; + node.clauses = Factory.createNodeArray(clauses); + return Factory.finishNode(node, location, flags); + } + Factory.createSwitchStatement = createSwitchStatement; + function updateSwitchStatement(node, expression, clauses) { + if (node.expression !== expression || node.clauses !== clauses) { + return createSwitchStatement(expression, clauses, node, node.flags); + } + return node; + } + Factory.updateSwitchStatement = updateSwitchStatement; + function createLabeledStatement(label, statement, location, flags) { + var node = Factory.beginNode(188); + node.label = label; + node.statement = statement; + return Factory.finishNode(node, location, flags); + } + Factory.createLabeledStatement = createLabeledStatement; + function updateLabeledStatement(node, label, statement) { + if (node.label !== label || node.statement !== statement) { + return createLabeledStatement(label, statement, node, node.flags); + } + return node; + } + Factory.updateLabeledStatement = updateLabeledStatement; + function createThrowStatement(expression, location, flags) { + var node = Factory.beginNode(189); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createThrowStatement = createThrowStatement; + function updateThrowStatement(node, expression) { + if (node.expression !== expression) { + return createThrowStatement(expression, node, node.flags); + } + return node; + } + Factory.updateThrowStatement = updateThrowStatement; + function createTryStatement(tryBlock, catchClause, finallyBlock, location, flags) { + var node = Factory.beginNode(190); + node.tryBlock = tryBlock; + node.catchClause = catchClause; + node.finallyBlock = finallyBlock; + return Factory.finishNode(node, location, flags); + } + Factory.createTryStatement = createTryStatement; + function updateTryStatement(node, tryBlock, catchClause, finallyBlock) { + if (node.tryBlock !== tryBlock || node.catchClause !== catchClause || node.finallyBlock !== finallyBlock) { + return createTryStatement(tryBlock, catchClause, finallyBlock, node, node.flags); + } + return node; + } + Factory.updateTryStatement = updateTryStatement; + function createDebuggerStatement(location, flags) { + var node = Factory.beginNode(191); + return Factory.finishNode(node, location, flags); + } + Factory.createDebuggerStatement = createDebuggerStatement; + function createVariableDeclaration(name, initializer, location, flags) { + var node = Factory.beginNode(192); + node.name = name; + node.initializer = initializer; + return Factory.finishNode(node, location, flags); + } + Factory.createVariableDeclaration = createVariableDeclaration; + function updateVariableDeclaration(node, name, initializer) { + if (node.name !== name || node.initializer !== initializer) { + return createVariableDeclaration(name, initializer, node, node.flags); + } + return node; + } + Factory.updateVariableDeclaration = updateVariableDeclaration; + function createVariableDeclarationList(declarations, location, flags) { + var node = Factory.beginNode(193); + node.declarations = Factory.createNodeArray(declarations); + return Factory.finishNode(node, location, flags); + } + Factory.createVariableDeclarationList = createVariableDeclarationList; + function updateVariableDeclarationList(node, declarations) { + if (node.declarations !== declarations) { + return createVariableDeclarationList(declarations, node, node.flags); + } + return node; + } + Factory.updateVariableDeclarationList = updateVariableDeclarationList; + function createFunctionDeclaration(name, parameters, body, typeParameters, type, modifiers, asteriskToken, location, flags) { + var node = Factory.beginNode(194); + node.name = name; + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + node.asteriskToken = asteriskToken; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createFunctionDeclaration = createFunctionDeclaration; + function updateFunctionDeclaration(node, name, parameters, body) { + if (node.name !== name || node.parameters !== parameters || node.body !== body) { + return createFunctionDeclaration(name, parameters, body, node.typeParameters, node.type, node.modifiers, node.asteriskToken, node, node.flags); + } + return node; + } + Factory.updateFunctionDeclaration = updateFunctionDeclaration; + function createCaseClause(expression, statements, location, flags) { + var node = Factory.beginNode(204); + node.expression = expression; + node.statements = Factory.createNodeArray(statements); + return Factory.finishNode(node, location, flags); + } + Factory.createCaseClause = createCaseClause; + function updateCaseClause(node, expression, statements) { + if (node.expression !== expression || node.statements !== statements) { + return createCaseClause(expression, statements, node, node.flags); + } + return node; + } + Factory.updateCaseClause = updateCaseClause; + function createDefaultClause(statements, location, flags) { + var node = Factory.beginNode(205); + node.statements = Factory.createNodeArray(statements); + return Factory.finishNode(node, location, flags); + } + Factory.createDefaultClause = createDefaultClause; + function updateDefaultClause(node, statements) { + if (node.statements !== statements) { + return createDefaultClause(statements, node, node.flags); + } + return node; + } + Factory.updateDefaultClause = updateDefaultClause; + function createCatchClause(name, block, location, flags) { + var node = Factory.beginNode(207); + node.name = name; + node.block = block; + return Factory.finishNode(node, location, flags); + } + Factory.createCatchClause = createCatchClause; + function updateCatchClause(node, name, block) { + if (node.name !== name || node.block !== block) { + return createCatchClause(name, block, node, node.flags); + } + return node; + } + Factory.updateCatchClause = updateCatchClause; + function createPropertyAssignment(name, initializer, location, flags) { + var node = Factory.beginNode(208); + node.name = name; + node.initializer = initializer; + return Factory.finishNode(node, location, flags); + } + Factory.createPropertyAssignment = createPropertyAssignment; + function updatePropertyAssignment(node, name, initializer) { + if (node.name !== name || node.initializer !== initializer) { + return createPropertyAssignment(name, initializer, node, node.flags); + } + return node; + } + Factory.updatePropertyAssignment = updatePropertyAssignment; + function createShorthandPropertyAssignment(name, location, flags) { + var node = Factory.beginNode(209); + node.name = name; + return Factory.finishNode(node, location, flags); + } + Factory.createShorthandPropertyAssignment = createShorthandPropertyAssignment; + function updateShorthandPropertyAssignment(node, name) { + if (node.name !== name) { + return createShorthandPropertyAssignment(name, node, node.flags); + } + return node; + } + Factory.updateShorthandPropertyAssignment = updateShorthandPropertyAssignment; + })(Factory = ts.Factory || (ts.Factory = {})); + var Visitor; + (function (Visitor) { + function fallback(node, cbNode, state) { + if (!cbNode || !node) { + return node; + } + return accept(node, cbNode, state); + } + Visitor.fallback = fallback; + function accept(node, cbNode, state) { + switch (node.kind) { + case 123: + return Factory.updateQualifiedName(node, Visitor.visit(node.left, cbNode, state), Visitor.visit(node.right, cbNode, state)); + case 124: + return Factory.updateComputedPropertyName(node, Visitor.visit(node.expression, cbNode, state)); + case 125: + return Factory.updateTypeParameter(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.constraint, cbNode, state)); + case 126: + return Factory.updateParameterDeclaration(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.initializer, cbNode, state), Visitor.visit(node.type, cbNode, state)); + case 127: + return Factory.updatePropertySignature(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.type, cbNode, state)); + case 128: + return Factory.updatePropertyDeclaration(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.initializer, cbNode, state), Visitor.visit(node.type, cbNode, state)); + case 129: + return Factory.updateMethodSignature(node, Visitor.visit(node.name, cbNode, state), Visitor.visitNodes(node.parameters, cbNode, state)); + case 130: + return Factory.updateMethodDeclaration(node, Visitor.visit(node.name, cbNode, state), Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 131: + return Factory.updateConstructor(node, Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 132: + return Factory.updateGetAccessor(node, Visitor.visit(node.name, cbNode, state), Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 133: + return Factory.updateSetAccessor(node, Visitor.visit(node.name, cbNode, state), Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 134: + return Factory.updateCallSignature(node, Visitor.visitNodes(node.parameters, cbNode, state)); + case 135: + return Factory.updateConstructSignature(node, Visitor.visitNodes(node.parameters, cbNode, state)); + case 136: + return Factory.updateIndexSignature(node, Visitor.visitNodes(node.parameters, cbNode, state)); + case 146: + return Factory.updateObjectBindingPattern(node, Visitor.visitNodes(node.elements, cbNode, state)); + case 147: + return Factory.updateArrayBindingPattern(node, Visitor.visitNodes(node.elements, cbNode, state)); + case 148: + return Factory.updateBindingElement(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.propertyName, cbNode, state), Visitor.visit(node.initializer, cbNode, state)); + case 149: + return Factory.updateArrayLiteralExpression(node, Visitor.visitNodes(node.elements, cbNode, state)); + case 150: + return Factory.updateObjectLiteralExpression(node, Visitor.visitNodes(node.properties, cbNode, state)); + case 151: + return Factory.updatePropertyAccessExpression(node, Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.name, cbNode, state)); + case 152: + return Factory.updateElementAccessExpression(node, Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.argumentExpression, cbNode, state)); + case 153: + return Factory.updateCallExpression(node, Visitor.visit(node.expression, cbNode, state), Visitor.visitNodes(node.arguments, cbNode, state)); + case 154: + return Factory.updateNewExpression(node, Visitor.visit(node.expression, cbNode, state), Visitor.visitNodes(node.arguments, cbNode, state)); + case 155: + return Factory.updateTaggedTemplateExpression(node, Visitor.visit(node.tag, cbNode, state), Visitor.visit(node.template, cbNode, state)); + case 156: + return Factory.updateTypeAssertion(node, Visitor.visit(node.expression, cbNode, state)); + case 157: + return Factory.updateParenthesizedExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 158: + return Factory.updateFunctionExpression(node, Visitor.visit(node.name, cbNode, state), Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 159: + return Factory.updateArrowFunction(node, Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 160: + return Factory.updateDeleteExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 161: + return Factory.updateTypeOfExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 162: + return Factory.updateVoidExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 163: + return Factory.updateAwaitExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 164: + return Factory.updatePrefixUnaryExpression(node, Visitor.visit(node.operand, cbNode, state)); + case 165: + return Factory.updatePostfixUnaryExpression(node, Visitor.visit(node.operand, cbNode, state)); + case 166: + return Factory.updateBinaryExpression(node, Visitor.visit(node.left, cbNode, state), Visitor.visit(node.right, cbNode, state)); + case 167: + return Factory.updateConditionalExpression(node, Visitor.visit(node.condition, cbNode, state), Visitor.visit(node.whenTrue, cbNode, state), Visitor.visit(node.whenFalse, cbNode, state)); + case 168: + return Factory.updateTemplateExpression(node, Visitor.visit(node.head, cbNode, state), Visitor.visitNodes(node.templateSpans, cbNode, state)); + case 169: + return Factory.updateYieldExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 171: + return Factory.updateSpreadElementExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 173: + return Factory.updateTemplateSpan(node, Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.literal, cbNode, state)); + case 174: + return Factory.updateBlock(node, Visitor.visitNodes(node.statements, cbNode, state)); + case 175: + return Factory.updateVariableStatement(node, Visitor.visit(node.declarationList, cbNode, state)); + case 177: + return Factory.updateExpressionStatement(node, Visitor.visit(node.expression, cbNode, state)); + case 178: + return Factory.updateIfStatement(node, Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.thenStatement, cbNode, state), Visitor.visit(node.elseStatement, cbNode, state)); + case 179: + return Factory.updateDoStatement(node, Visitor.visit(node.statement, cbNode, state), Visitor.visit(node.expression, cbNode, state)); + case 180: + return Factory.updateWhileStatement(node, Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.statement, cbNode, state)); + case 181: + return Factory.updateForStatement(node, Visitor.visit(node.initializer, cbNode, state), Visitor.visit(node.condition, cbNode, state), Visitor.visit(node.iterator, cbNode, state), Visitor.visit(node.statement, cbNode, state)); + case 182: + return Factory.updateForInStatement(node, Visitor.visit(node.initializer, cbNode, state), Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.statement, cbNode, state)); + case 183: + return Factory.updateContinueStatement(node, Visitor.visit(node.label, cbNode, state)); + case 184: + return Factory.updateBreakStatement(node, Visitor.visit(node.label, cbNode, state)); + case 185: + return Factory.updateReturnStatement(node, Visitor.visit(node.expression, cbNode, state)); + case 186: + return Factory.updateWithStatement(node, Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.statement, cbNode, state)); + case 187: + return Factory.updateSwitchStatement(node, Visitor.visit(node.expression, cbNode, state), Visitor.visitNodes(node.clauses, cbNode, state)); + case 188: + return Factory.updateLabeledStatement(node, Visitor.visit(node.label, cbNode, state), Visitor.visit(node.statement, cbNode, state)); + case 189: + return Factory.updateThrowStatement(node, Visitor.visit(node.expression, cbNode, state)); + case 190: + return Factory.updateTryStatement(node, Visitor.visit(node.tryBlock, cbNode, state), Visitor.visit(node.catchClause, cbNode, state), Visitor.visit(node.finallyBlock, cbNode, state)); + case 192: + return Factory.updateVariableDeclaration(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.initializer, cbNode, state)); + case 193: + return Factory.updateVariableDeclarationList(node, Visitor.visitNodes(node.declarations, cbNode, state)); + case 194: + return Factory.updateFunctionDeclaration(node, Visitor.visit(node.name, cbNode, state), Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 204: + return Factory.updateCaseClause(node, Visitor.visit(node.expression, cbNode, state), Visitor.visitNodes(node.statements, cbNode, state)); + case 205: + return Factory.updateDefaultClause(node, Visitor.visitNodes(node.statements, cbNode, state)); + case 207: + return Factory.updateCatchClause(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.block, cbNode, state)); + case 208: + return Factory.updatePropertyAssignment(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.initializer, cbNode, state)); + case 209: + return Factory.updateShorthandPropertyAssignment(node, Visitor.visit(node.name, cbNode, state)); + default: + return node; + } + } + })(Visitor = ts.Visitor || (ts.Visitor = {})); +})(ts || (ts = {})); +var ts; +(function (ts) { + var Factory; + (function (Factory) { + function createNodeArray(elements, location) { + if (elements === void 0) { elements = []; } + var nodeArray = elements; + if (location) { + nodeArray.pos = location.pos; + nodeArray.end = location.end; + } + else if (!("pos" in nodeArray && "end" in nodeArray)) { + nodeArray.pos = -1; + nodeArray.end = -1; + } + return nodeArray; + } + Factory.createNodeArray = createNodeArray; + function createVoidZero(location, flags) { + return Factory.createVoidExpression(Factory.createNumericLiteral(0, location, flags), location, flags); + } + Factory.createVoidZero = createVoidZero; + function makeLeftHandSideExpression(expression) { + if (ts.isLeftHandSideExpression(expression)) { + return expression; + } + return Factory.createParenthesizedExpression(expression); + } + Factory.makeLeftHandSideExpression = makeLeftHandSideExpression; + function createPropertyOrElementAccessExpression(expression, propName) { + if (propName.kind !== 64) { + return Factory.createElementAccessExpression(expression, propName); + } + return Factory.createPropertyAccessExpression(expression, propName); + } + Factory.createPropertyOrElementAccessExpression = createPropertyOrElementAccessExpression; + function updateFunctionLikeDeclaration(node, name, body, parameters) { + switch (node.kind) { + case 194: + return Factory.updateFunctionDeclaration(node, name, parameters, body); + case 130: + return Factory.updateMethodDeclaration(node, name, parameters, body); + case 132: + return Factory.updateGetAccessor(node, name, parameters, body); + case 158: + return Factory.updateFunctionExpression(node, name, parameters, body); + case 159: + return Factory.updateArrowFunction(node, parameters, body); + } + return node; + } + Factory.updateFunctionLikeDeclaration = updateFunctionLikeDeclaration; + function getExpressionForEntityName(name) { + if (!name) { + return finishNode(beginNode(88)); + } + if (name.kind === 64) { + return Factory.createIdentifier(name.text); + } + else { + return Factory.createPropertyAccessExpression(getExpressionForEntityName(name.left), Factory.createIdentifier(name.right.text)); + } + } + Factory.getExpressionForEntityName = getExpressionForEntityName; + function createTokenNode(token, location, flags) { + return finishNode(beginNode(token), location, flags); + } + Factory.createTokenNode = createTokenNode; + function beginNode(kind) { + var ctor = ts.getNodeConstructor(kind); + var node = (new ctor()); + return node; + } + Factory.beginNode = beginNode; + function finishNode(node, location, flags, modifiers) { + if (location) { + node.pos = location.pos; + node.end = location.end; + } + else { + node.pos = -1; + node.end = -1; + } + if (flags) { + node.flags = flags; + } + if (modifiers) { + node.modifiers = modifiers; + node.flags |= node.modifiers.flags; + } + ts.forEachChild(node, function (child) { return childAdded(node, child); }); + return node; + } + Factory.finishNode = finishNode; + function childAdded(parent, child) { + if (child && !child.parent) { + child.parent = parent; + } + } + })(Factory = ts.Factory || (ts.Factory = {})); + var Visitor; + (function (Visitor) { + function visit(node, cbNode, state) { + if (!cbNode || !node) { + return node; + } + return cbNode(node, state); + } + Visitor.visit = visit; + function visitNodes(nodes, cbNode, state, shouldCacheNode, cacheNode, removeMissingNodes) { + if (!nodes || !cbNode) { + return nodes; + } + var updatedNodes; + var updatedOffset = 0; + var cacheOffset = 0; + for (var i = 0; i < nodes.length; i++) { + var updatedIndex = i - updatedOffset; + var node = nodes[i]; + if (shouldCacheNode && shouldCacheNode(node, state)) { + if (!updatedNodes) { + updatedNodes = nodes.slice(0, i); + } + if (cacheNode) { + while (cacheOffset < updatedIndex) { + updatedNodes[cacheOffset] = cacheNode(updatedNodes[cacheOffset], state); + cacheOffset++; + } + } + cacheOffset = updatedIndex; + } + var updatedNode = visit(node, cbNode, state); + if ((updatedNodes || updatedNode !== node || (!updatedNode && removeMissingNodes))) { + if (!updatedNodes) { + updatedNodes = nodes.slice(0, i); + } + if (!updatedNode && removeMissingNodes) { + updatedOffset++; + } + else { + updatedNodes[i - updatedOffset] = updatedNode; + } + } + } + if (updatedNodes) { + return Factory.createNodeArray(updatedNodes, nodes); + } + return nodes; + } + Visitor.visitNodes = visitNodes; + })(Visitor = ts.Visitor || (ts.Visitor = {})); +})(ts || (ts = {})); +var ts; +(function (ts) { + var Locals; + (function (Locals) { + function create(resolver, context, globals) { + return { resolver: resolver, context: context, globals: globals, tempCount: 0 }; + } + Locals.create = create; + function copy(source, target) { + if (!source || target === source) { + return target; + } + target.context = source.context; + target.globals = source.globals; + target.resolver = source.resolver; + target.tempCount = source.tempCount; + target.variables = source.variables; + return target; + } + Locals.copy = copy; + function createUniqueIdentifier(locals, name, globallyUnique) { + while (true) { + if (name && locals.resolver.isUnknownIdentifier(locals.context, name)) { + break; + } + name = "_" + (locals.tempCount < 25 ? String.fromCharCode(locals.tempCount + (locals.tempCount < 8 ? 0 : 1) + 97) : locals.tempCount - 25); + locals.tempCount++; + } + if (globallyUnique) { + locals.globals[name] = true; + } + return ts.Factory.createIdentifier(name); + } + Locals.createUniqueIdentifier = createUniqueIdentifier; + function recordVariable(locals, name) { + if (!locals.variables) { + locals.variables = []; + } + locals.variables.push(name); + } + Locals.recordVariable = recordVariable; + function ensureIdentifier(locals, expression, writeAssignment, state) { + if (expression.kind !== 64) { + var local = createUniqueIdentifier(locals); + writeAssignment(local, expression, state); + return local; + } + return expression; + } + Locals.ensureIdentifier = ensureIdentifier; + function getValueOrDefault(locals, value, defaultValue, writeAssignment, state) { + value = ensureIdentifier(locals, value, writeAssignment, state); + var equalityExpression = ts.Factory.createBinaryExpression(30, value, ts.Factory.createVoidZero()); + var conditionalExpression = ts.Factory.createConditionalExpression(equalityExpression, defaultValue, value); + return conditionalExpression; + } + Locals.getValueOrDefault = getValueOrDefault; + })(Locals = ts.Locals || (ts.Locals = {})); + var GeneratorFunctionBuilder; + (function (GeneratorFunctionBuilder) { + function create(locals) { + return { + locals: locals, + flags: 0, + nextLabelId: 1 + }; + } + GeneratorFunctionBuilder.create = create; + function declareLocal(builder, name, globallyUnique) { + var local = Locals.createUniqueIdentifier(builder.locals, name, globallyUnique); + Locals.recordVariable(builder.locals, local); + return local; + } + GeneratorFunctionBuilder.declareLocal = declareLocal; + function writeLocation(builder, location) { + builder.pendingLocation = location; + } + GeneratorFunctionBuilder.writeLocation = writeLocation; + function readLocation(builder) { + var location = builder.pendingLocation; + builder.pendingLocation = undefined; + return location; + } + function addParameter(builder, name, flags) { + if (!builder.parameters) { + builder.parameters = []; + } + builder.parameters.push(ts.Factory.createParameterDeclaration(name, undefined, undefined, undefined, undefined, undefined, readLocation(builder), flags)); + } + GeneratorFunctionBuilder.addParameter = addParameter; + function addVariable(builder, name, flags) { + Locals.recordVariable(builder.locals, name); + } + GeneratorFunctionBuilder.addVariable = addVariable; + function addFunction(builder, func) { + if (!builder.functions) { + builder.functions = []; + } + builder.functions.push(func); + } + GeneratorFunctionBuilder.addFunction = addFunction; + function defineLabel(builder) { + if (!builder.labels) { + builder.labels = []; + } + var label = builder.nextLabelId++; + builder.labels[label] = -1; + return label; + } + GeneratorFunctionBuilder.defineLabel = defineLabel; + function markLabel(builder, label) { + ts.Debug.assert(!!builder.labels, "No labels were defined."); + builder.labels[label] = builder.operations ? builder.operations.length : 0; + } + GeneratorFunctionBuilder.markLabel = markLabel; + function beginWithBlock(builder, expression) { + var startLabel = defineLabel(builder); + var endLabel = defineLabel(builder); + markLabel(builder, startLabel); + beginBlock(builder, { + kind: 5, + expression: expression, + startLabel: startLabel, + endLabel: endLabel + }); + } + GeneratorFunctionBuilder.beginWithBlock = beginWithBlock; + function endWithBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 5); + var withBlock = endBlock(builder); + markLabel(builder, withBlock.endLabel); + } + GeneratorFunctionBuilder.endWithBlock = endWithBlock; + function beginExceptionBlock(builder) { + var startLabel = defineLabel(builder); + var endLabel = defineLabel(builder); + markLabel(builder, startLabel); + beginBlock(builder, { + kind: 0, + state: 0, + startLabel: startLabel, + endLabel: endLabel + }); + emit(builder, 0); + builder.flags |= 1; + return endLabel; + } + GeneratorFunctionBuilder.beginExceptionBlock = beginExceptionBlock; + function beginCatchBlock(builder, variable) { + ts.Debug.assert(peekBlockKind(builder) === 0); + var exception = peekBlock(builder); + ts.Debug.assert(exception.state < 1); + var endLabel = exception.endLabel; + emit(builder, 3, endLabel); + var catchLabel = defineLabel(builder); + markLabel(builder, catchLabel); + exception.state = 1; + exception.catchVariable = variable; + exception.catchLabel = catchLabel; + var state = getState(builder); + var errorProperty = ts.Factory.createPropertyAccessExpression(state, ts.Factory.createIdentifier("error")); + var assignExpression = ts.Factory.createBinaryExpression(52, variable, errorProperty); + emit(builder, 1, assignExpression); + emit(builder, 0); + } + GeneratorFunctionBuilder.beginCatchBlock = beginCatchBlock; + function beginFinallyBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 0); + var exception = peekBlock(builder); + ts.Debug.assert(exception.state < 2); + var state = exception.state; + var endLabel = exception.endLabel; + emit(builder, 3, endLabel); + var finallyLabel = defineLabel(builder); + markLabel(builder, finallyLabel); + exception.state = 2; + exception.finallyLabel = finallyLabel; + } + GeneratorFunctionBuilder.beginFinallyBlock = beginFinallyBlock; + function endExceptionBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 0); + var exception = endBlock(builder); + var state = exception.state; + if (state < 2) { + emit(builder, 3, exception.endLabel); + } + else { + emit(builder, 9); + } + markLabel(builder, exception.endLabel); + exception.state = 3; + } + GeneratorFunctionBuilder.endExceptionBlock = endExceptionBlock; + function beginScriptContinueBlock(builder, labelText) { + beginBlock(builder, { + kind: 3, + labelText: labelText, + breakLabel: -1, + continueLabel: -1 + }); + } + GeneratorFunctionBuilder.beginScriptContinueBlock = beginScriptContinueBlock; + function endScriptContinueBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 3); + endBlock(builder); + } + GeneratorFunctionBuilder.endScriptContinueBlock = endScriptContinueBlock; + function beginScriptBreakBlock(builder, labelText, requireLabel) { + beginBlock(builder, { + kind: 1, + labelText: labelText, + breakLabel: -1, + requireLabel: requireLabel + }); + } + GeneratorFunctionBuilder.beginScriptBreakBlock = beginScriptBreakBlock; + function endScriptBreakBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 1); + endBlock(builder); + } + GeneratorFunctionBuilder.endScriptBreakBlock = endScriptBreakBlock; + function beginContinueBlock(builder, continueLabel, labelText) { + var breakLabel = defineLabel(builder); + beginBlock(builder, { + kind: 4, + labelText: labelText, + breakLabel: breakLabel, + continueLabel: continueLabel + }); + return breakLabel; + } + GeneratorFunctionBuilder.beginContinueBlock = beginContinueBlock; + function endContinueBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 4); + var block = endBlock(builder); + var breakLabel = block.breakLabel; + if (breakLabel > 0) { + markLabel(builder, breakLabel); + } + } + GeneratorFunctionBuilder.endContinueBlock = endContinueBlock; + function beginBreakBlock(builder, labelText, requireLabel) { + var breakLabel = defineLabel(builder); + beginBlock(builder, { + kind: 2, + labelText: labelText, + breakLabel: breakLabel, + requireLabel: requireLabel + }); + return breakLabel; + } + GeneratorFunctionBuilder.beginBreakBlock = beginBreakBlock; + function endBreakBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 2); + var block = endBlock(builder); + var breakLabel = block.breakLabel; + if (breakLabel > 0) { + markLabel(builder, breakLabel); + } + } + GeneratorFunctionBuilder.endBreakBlock = endBreakBlock; + function beginBlock(builder, block) { + if (!builder.blocks) { + builder.blocks = []; + builder.blockActions = []; + builder.blockOffsets = []; + builder.blockStack = []; + } + var index = builder.blockActions.length; + builder.blockActions[index] = 0; + builder.blockOffsets[index] = builder.operations ? builder.operations.length : 0; + builder.blocks[index] = block; + builder.blockStack.push(block); + return index; + } + function endBlock(builder) { + ts.Debug.assert(!!builder.blocks, "beginBlock was never called."); + var block = builder.blockStack.pop(); + var index = builder.blockActions.length; + builder.blockActions[index] = 1; + builder.blockOffsets[index] = builder.operations ? builder.operations.length : 0; + builder.blocks[index] = block; + return block; + } + function peekBlock(builder, back) { + if (back === void 0) { back = 0; } + if (builder.blocks) { + return builder.blockStack[builder.blockStack.length - (1 + back)]; + } + } + function peekBlockKind(builder, back) { + if (back === void 0) { back = 0; } + var block = peekBlock(builder, back); + return block && block.kind; + } + function findBreakTarget(builder, labelText) { + if (builder.blocks) { + for (var i = builder.blockStack.length - 1; i >= 0; i--) { + var block = builder.blockStack[i]; + if (supportsBreak(builder, block)) { + var breakBlock = block; + if ((!labelText && !breakBlock.requireLabel) || breakBlock.labelText && breakBlock.labelText.indexOf(labelText) !== -1) { + return breakBlock.breakLabel; + } + } + } + } + return 0; + } + GeneratorFunctionBuilder.findBreakTarget = findBreakTarget; + function findContinueTarget(builder, labelText) { + if (builder.blocks) { + for (var i = builder.blockStack.length - 1; i >= 0; i--) { + var block = builder.blockStack[i]; + if (supportsContinue(builder, block)) { + var continueBreakBlock = block; + if (!labelText || continueBreakBlock.labelText && continueBreakBlock.labelText.indexOf(labelText) !== -1) { + return continueBreakBlock.continueLabel; + } + } + } + } + } + GeneratorFunctionBuilder.findContinueTarget = findContinueTarget; + function supportsBreak(builder, block) { + switch (block.kind) { + case 1: + case 3: + case 2: + case 4: + return true; + } + return false; + } + function supportsContinue(builder, block) { + switch (block.kind) { + case 3: + case 4: + return true; + } + return false; + } + function emit(builder, code) { + var args = []; + for (var _i = 2; _i < arguments.length; _i++) { + args[_i - 2] = arguments[_i]; + } + switch (code) { + case 3: + case 5: + case 4: + case 0: + case 2: + case 1: + case 7: + case 8: + case 9: + case 6: + break; + default: + reportUnexpectedOpCode(code); + return; + } + var location = readLocation(builder); + if (code === 1) { + var node = args[0]; + if (!node) { + return; + } + } + if (!builder.operations) { + builder.operations = []; + builder.operationArguments = []; + builder.operationLocations = []; + } + if (!builder.labels) { + markLabel(builder, defineLabel(builder)); + } + var operationIndex = builder.operations.length; + builder.operations[operationIndex] = code; + builder.operationArguments[operationIndex] = args; + builder.operationLocations[operationIndex] = location; + } + GeneratorFunctionBuilder.emit = emit; + function createLabel(builder, label) { + if (label > 0) { + if (!builder.labelNumbers) { + builder.labelNumbers = []; + } + return ts.Factory.createGeneratedLabel(label, builder.labelNumbers); + } + return ts.Factory.createOmittedExpression(); + } + function createInlineBreak(builder, label) { + ts.Debug.assert(label > 0, "Invalid label: " + label); + var instruction = ts.Factory.createNumericLiteral('3 /*break*/'); + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction, createLabel(builder, label)]); + return ts.Factory.createReturnStatement(returnExpression, readLocation(builder)); + } + GeneratorFunctionBuilder.createInlineBreak = createInlineBreak; + function createInlineReturn(builder, expression) { + var instruction = ts.Factory.createNumericLiteral('3 /*return*/'); + if (expression) { + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction, expression]); + } + else { + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction]); + } + return ts.Factory.createReturnStatement(returnExpression, readLocation(builder)); + } + GeneratorFunctionBuilder.createInlineReturn = createInlineReturn; + function createResume(builder) { + var state = getState(builder); + return ts.Factory.createPropertyAccessExpression(state, ts.Factory.createIdentifier("sent")); + } + GeneratorFunctionBuilder.createResume = createResume; + function getState(builder) { + if (!builder.state) { + builder.state = Locals.createUniqueIdentifier(builder.locals, "_state"); + } + return builder.state; + } + function buildFunction(builder, kind, name, location, flags, modifiers) { + var statements = []; + statements = buildHoistedFunctionDeclarations(builder, statements); + var generatorStatements = buildStatements(builder); + var generatorFunctionBody = ts.Factory.createBlock(generatorStatements); + var generatorFunction = ts.Factory.createFunctionExpression(undefined, [ts.Factory.createParameterDeclaration(getState(builder))], generatorFunctionBody); + var generatorExpression = ts.Factory.createCallExpression(ts.Factory.createIdentifier("__generator"), [generatorFunction]); + var returnStatement = ts.Factory.createReturnStatement(generatorExpression); + statements.push(returnStatement); + var body = ts.Factory.createBlock(ts.Factory.createNodeArray(statements)); + var node; + switch (kind) { + case 194: + return ts.Factory.createFunctionDeclaration(name, builder.parameters, body, undefined, undefined, modifiers, undefined, location, flags); + case 130: + return ts.Factory.createMethodDeclaration(name, builder.parameters, body, undefined, undefined, modifiers, undefined, location, flags); + case 132: + return ts.Factory.createGetAccessor(name, builder.parameters, body, undefined, undefined, modifiers, location, flags); + case 158: + return ts.Factory.createFunctionExpression(name, builder.parameters, body, undefined, undefined, modifiers, undefined, location, flags); + case 159: + return ts.Factory.createArrowFunction(builder.parameters, body, undefined, undefined, modifiers, location, flags); + default: + ts.reportUnexpectedNode(node); + return node; + } + } + GeneratorFunctionBuilder.buildFunction = buildFunction; + function buildHoistedFunctionDeclarations(builder, statements) { + if (builder.functions) { + statements = statements.concat(builder.functions); + } + return statements; + } + function buildStatements(builder) { + var operations = builder.operations, operationArguments = builder.operationArguments, operationLocations = builder.operationLocations; + var statementBuilder = { + builder: builder, + operationIndex: 0, + blockIndex: 0, + labelNumber: 0 + }; + if (builder.flags & 1) { + initializeProtectedRegions(statementBuilder); + } + if (operations) { + for (statementBuilder.operationIndex = 0; statementBuilder.operationIndex < operations.length; statementBuilder.operationIndex++) { + writeOperation(statementBuilder, operations[statementBuilder.operationIndex], operationArguments[statementBuilder.operationIndex], operationLocations[statementBuilder.operationIndex]); + } + } + flushFinalLabel(statementBuilder); + if (statementBuilder.clauses) { + var state = getState(builder); + var labelExpression = ts.Factory.createPropertyAccessExpression(state, ts.Factory.createIdentifier("label")); + var switchStatement = ts.Factory.createSwitchStatement(labelExpression, statementBuilder.clauses); + return [switchStatement]; + } + if (statementBuilder.statements) { + return statementBuilder.statements; + } + return []; + } + function initializeProtectedRegions(statementBuilder) { + var trysProperty = ts.Factory.createPropertyAccessExpression(getState(statementBuilder.builder), ts.Factory.createIdentifier("trys")); + var trysArray = ts.Factory.createArrayLiteralExpression([]); + var assignTrys = ts.Factory.createBinaryExpression(52, trysProperty, trysArray); + writeStatement(statementBuilder, assignTrys); + flushLabel(statementBuilder); + } + function flushLabel(statementBuilder) { + if (!statementBuilder.statements) { + return; + } + appendLabel(statementBuilder, !statementBuilder.lastOperationWasAbrupt); + statementBuilder.lastOperationWasAbrupt = false; + statementBuilder.lastOperationWasCompletion = false; + statementBuilder.labelNumber++; + } + function flushFinalLabel(statementBuilder) { + if (!statementBuilder.lastOperationWasCompletion) { + tryEnterLabel(statementBuilder); + writeReturn(statementBuilder); + } + if (statementBuilder.statements && statementBuilder.clauses) { + appendLabel(statementBuilder, false); + } + } + function appendLabel(statementBuilder, markLabelEnd) { + var builder = statementBuilder.builder, statements = statementBuilder.statements, withBlockStack = statementBuilder.withBlockStack, currentExceptionBlock = statementBuilder.currentExceptionBlock, labelNumber = statementBuilder.labelNumber; + if (!statementBuilder.clauses) { + statementBuilder.clauses = []; + } + if (statements) { + if (withBlockStack) { + for (var i = withBlockStack.length - 1; i >= 0; i--) { + var withBlock = withBlockStack[i]; + statements = [ts.Factory.createWithStatement(withBlock.expression, ts.Factory.createBlock(statements))]; + } + } + if (currentExceptionBlock) { + var startLabel = currentExceptionBlock.startLabel, catchLabel = currentExceptionBlock.catchLabel, finallyLabel = currentExceptionBlock.finallyLabel, endLabel = currentExceptionBlock.endLabel; + var labelsArray = ts.Factory.createArrayLiteralExpression([ + createLabel(builder, startLabel), + createLabel(builder, catchLabel), + createLabel(builder, finallyLabel), + createLabel(builder, endLabel) + ]); + var trysProperty = ts.Factory.createPropertyAccessExpression(getState(builder), ts.Factory.createIdentifier("trys")); + var pushMethod = ts.Factory.createPropertyAccessExpression(trysProperty, ts.Factory.createIdentifier("push")); + var callExpression = ts.Factory.createCallExpression(pushMethod, [labelsArray]); + statements.unshift(ts.Factory.createExpressionStatement(callExpression)); + statementBuilder.currentExceptionBlock = undefined; + } + if (markLabelEnd) { + var nextLabelNumberExpression = ts.Factory.createNumericLiteral(labelNumber + 1); + var labelProperty = ts.Factory.createPropertyAccessExpression(getState(builder), ts.Factory.createIdentifier("label")); + var labelAssign = ts.Factory.createBinaryExpression(52, labelProperty, nextLabelNumberExpression); + statements.push(ts.Factory.createExpressionStatement(labelAssign)); + } + } + var labelNumberExpression = ts.Factory.createNumericLiteral(labelNumber); + var clause = ts.Factory.createCaseClause(labelNumberExpression, statements || []); + statementBuilder.clauses.push(clause); + statementBuilder.statements = undefined; + } + function tryEnterLabel(statementBuilder) { + var operationIndex = statementBuilder.operationIndex, builder = statementBuilder.builder, labels = builder.labels; + if (!labels) { + return; + } + var isLabel = false; + for (var label = 0; label < labels.length; label++) { + if (labels[label] === operationIndex) { + flushLabel(statementBuilder); + if (!builder.labelNumbers) { + builder.labelNumbers = []; + } + builder.labelNumbers[label] = statementBuilder.labelNumber; + } + } + } + function tryEnterOrLeaveBlock(statementBuilder) { + var operationIndex = statementBuilder.operationIndex, _a = statementBuilder.builder, blocks = _a.blocks, blockActions = _a.blockActions, blockOffsets = _a.blockOffsets; + if (blocks) { + for (; statementBuilder.blockIndex < blockActions.length && blockOffsets[statementBuilder.blockIndex] <= operationIndex; statementBuilder.blockIndex++) { + statementBuilder.blockIndex = statementBuilder.blockIndex; + var block = blocks[statementBuilder.blockIndex]; + var blockAction = blockActions[statementBuilder.blockIndex]; + if (blockAction === 0 && block.kind === 0) { + var exceptionBlock = block; + if (!statementBuilder.exceptionBlockStack) { + statementBuilder.exceptionBlockStack = []; + } + if (!statementBuilder.statements) { + statementBuilder.statements = []; + } + statementBuilder.exceptionBlockStack.push(statementBuilder.currentExceptionBlock); + statementBuilder.currentExceptionBlock = exceptionBlock; + } + else if (blockAction === 1 && block.kind === 0) { + statementBuilder.currentExceptionBlock = statementBuilder.exceptionBlockStack.pop(); + } + else if (blockAction === 0 && block.kind === 5) { + var withBlock = block; + if (!statementBuilder.withBlockStack) { + statementBuilder.withBlockStack = []; + } + statementBuilder.withBlockStack.push(withBlock); + } + else if (blockAction === 1 && block.kind === 5) { + statementBuilder.withBlockStack.pop(); + } + } + } + } + function writeOperation(statementBuilder, operation, operationArguments, operationLocation) { + tryEnterLabel(statementBuilder); + tryEnterOrLeaveBlock(statementBuilder); + if (statementBuilder.lastOperationWasAbrupt) { + return; + } + statementBuilder.lastOperationWasAbrupt = false; + statementBuilder.lastOperationWasCompletion = false; + switch (operation) { + case 0: return; + case 1: return writeStatement(statementBuilder, operationArguments[0]); + case 2: return writeAssign(statementBuilder, operationArguments[0], operationArguments[1], operationLocation); + case 3: return writeBreak(statementBuilder, operationArguments[0], operationLocation); + case 4: return writeBreakWhenTrue(statementBuilder, operationArguments[0], operationArguments[1], operationLocation); + case 5: return writeBreakWhenFalse(statementBuilder, operationArguments[0], operationArguments[1], operationLocation); + case 6: return writeYield(statementBuilder, operationArguments[0], operationLocation); + case 7: return writeReturn(statementBuilder, operationArguments[0], operationLocation); + case 8: return writeThrow(statementBuilder, operationArguments[0], operationLocation); + case 9: return writeEndfinally(statementBuilder); + } + } + function writeStatement(statementBuilder, node) { + if (ts.isExpression(node)) { + node = ts.Factory.createExpressionStatement(node); + } + if (!statementBuilder.statements) { + statementBuilder.statements = []; + } + statementBuilder.statements.push(node); + } + function writeAssign(statementBuilder, left, right, operationLocation) { + var assignExpression = ts.Factory.createBinaryExpression(52, left, right, operationLocation); + writeStatement(statementBuilder, assignExpression); + } + function writeThrow(statementBuilder, expression, operationLocation) { + statementBuilder.lastOperationWasAbrupt = true; + statementBuilder.lastOperationWasCompletion = true; + var throwStatement = ts.Factory.createThrowStatement(expression, operationLocation); + writeStatement(statementBuilder, throwStatement); + } + function writeReturn(statementBuilder, expression, operationLocation) { + statementBuilder.lastOperationWasAbrupt = true; + statementBuilder.lastOperationWasCompletion = true; + var elements = [ts.Factory.createNumericLiteral('2 /*return*/')]; + if (expression) { + elements.push(expression); + } + var returnExpression = ts.Factory.createArrayLiteralExpression(elements); + var returnStatement = ts.Factory.createReturnStatement(returnExpression, operationLocation); + writeStatement(statementBuilder, returnStatement); + } + function writeBreak(statementBuilder, label, operationLocation) { + statementBuilder.lastOperationWasAbrupt = true; + var instruction = ts.Factory.createNumericLiteral('3 /*break*/'); + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction, createLabel(statementBuilder.builder, label)]); + var returnStatement = ts.Factory.createReturnStatement(returnExpression, operationLocation); + writeStatement(statementBuilder, returnStatement); + } + function writeBreakWhenTrue(statementBuilder, label, condition, operationLocation) { + var instruction = ts.Factory.createNumericLiteral('3 /*break*/'); + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction, createLabel(statementBuilder.builder, label)]); + var returnStatement = ts.Factory.createReturnStatement(returnExpression, operationLocation); + var ifStatement = ts.Factory.createIfStatement(condition, returnStatement); + writeStatement(statementBuilder, ifStatement); + } + function writeBreakWhenFalse(statementBuilder, label, condition, operationLocation) { + var instruction = ts.Factory.createNumericLiteral('3 /*break*/'); + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction, createLabel(statementBuilder.builder, label)]); + var returnStatement = ts.Factory.createReturnStatement(returnExpression, operationLocation); + var parenExpression = ts.Factory.createParenthesizedExpression(condition); + var notExpression = ts.Factory.createPrefixUnaryExpression(46, parenExpression); + var ifStatement = ts.Factory.createIfStatement(notExpression, returnStatement); + writeStatement(statementBuilder, ifStatement); + } + function writeYield(statementBuilder, expression, operationLocation) { + statementBuilder.lastOperationWasAbrupt = true; + var elements = [ts.Factory.createNumericLiteral('4 /*yield*/')]; + if (expression) { + elements.push(expression); + } + var returnExpression = ts.Factory.createArrayLiteralExpression(elements); + var returnStatement = ts.Factory.createReturnStatement(returnExpression, operationLocation); + writeStatement(statementBuilder, returnStatement); + } + function writeEndfinally(statementBuilder) { + statementBuilder.lastOperationWasAbrupt = true; + var instruction = ts.Factory.createNumericLiteral('5 /*endfinally*/'); + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction]); + var returnStatement = ts.Factory.createReturnStatement(returnExpression); + writeStatement(statementBuilder, returnStatement); + } + function reportUnexpectedOpCode(code) { + var text; + if (typeof ts.OpCode === "object") { + text = ts.OpCode[code]; + } + else { + text = String(code); + } + ts.Debug.fail("Unexpected OpCode: " + text); + } + })(GeneratorFunctionBuilder = ts.GeneratorFunctionBuilder || (ts.GeneratorFunctionBuilder = {})); +})(ts || (ts = {})); +var ts; +(function (ts) { + var BindingElementRewriter; + (function (BindingElementRewriter) { + function rewrite(root, locals, value) { + var isDeclaration = root.kind === 192 && !(ts.getCombinedNodeFlags(root) & 1) || root.kind === 126; + var state = { + isDeclaration: isDeclaration, + root: root, + locals: locals, + value: value + }; + ts.Visitor.visit(root, visitNode, state); + return state.variableDeclarations; + } + BindingElementRewriter.rewrite = rewrite; + function visitNode(node, state) { + switch (node.kind) { + case 126: + case 192: + case 148: + return visitBindingElement(node, state); + case 146: + return visitObjectBindingPattern(node, state); + case 147: + return visitArrayBindingPattern(node, state); + case 64: + return visitIdentifier(node, state); + default: + return node; + } + } + function visitBindingElement(node, state) { + var value = state.value, locals = state.locals, saveValue = value; + if (node.initializer) { + value = value ? ts.Locals.getValueOrDefault(locals, value, node.initializer, writeDeclaration, state) : node.initializer; + } + else if (!value) { + value = ts.Factory.createVoidZero(); + } + state.value = value; + ts.Visitor.visit(node.name, visitNode, state); + state.value = saveValue; + return node; + } + function visitObjectBindingPattern(node, state) { + var value = state.value, locals = state.locals, saveValue = value; + var elements = node.elements; + if (elements.length !== 1) { + value = ts.Locals.ensureIdentifier(locals, value, writeDeclaration, state); + } + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + var propName = element.propertyName || element.name; + state.value = ts.Factory.createPropertyOrElementAccessExpression(ts.Factory.makeLeftHandSideExpression(value), propName); + ts.Visitor.visit(element, visitNode, state); + } + state.value = saveValue; + return node; + } + function visitArrayBindingPattern(node, state) { + var value = state.value, locals = state.locals, saveValue = value; + var elements = node.elements; + if (elements.length !== 1) { + value = ts.Locals.ensureIdentifier(locals, value, writeDeclaration, state); + } + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + if (element.kind !== 172) { + if (!element.dotDotDotToken) { + state.value = ts.Factory.createElementAccessExpression(ts.Factory.makeLeftHandSideExpression(value), ts.Factory.createNumericLiteral(i)); + ts.Visitor.visit(element, visitNode, state); + } + else if (i === elements.length - 1) { + value = ts.Locals.ensureIdentifier(locals, value, writeDeclaration, state); + var name = element.name; + var sliceExpression = ts.Factory.createPropertyAccessExpression(ts.Factory.makeLeftHandSideExpression(value), ts.Factory.createIdentifier("slice")); + var callExpression = ts.Factory.createCallExpression(sliceExpression, [ts.Factory.createNumericLiteral(i)]); + writeAssignment(name, callExpression, state); + } + } + } + state.value = saveValue; + return node; + } + function visitIdentifier(node, state) { + var value = state.value; + writeAssignment(node, value, state); + return node; + } + function writeDeclaration(left, right, state) { + var isDeclaration = state.isDeclaration, locals = state.locals; + if (!isDeclaration) { + ts.Locals.recordVariable(locals, left); + } + writeAssignment(left, right, state); + } + function writeAssignment(left, right, state) { + var _a = state.variableDeclarations, variableDeclarations = _a === void 0 ? [] : _a, root = state.root; + var variableDeclaration = ts.Factory.createVariableDeclaration(left, right); + if (root.kind === 192 && left.parent && (left.parent.kind === 192 || left.parent.kind === 148)) { + if (ts.getCombinedNodeFlags(left.parent) & 1) { + variableDeclaration.parent = state.root.parent; + variableDeclaration.flags |= 1; + } + } + variableDeclarations.push(variableDeclaration); + state.variableDeclarations = variableDeclarations; + } + })(BindingElementRewriter = ts.BindingElementRewriter || (ts.BindingElementRewriter = {})); + var DestructuringAssignmentRewriter; + (function (DestructuringAssignmentRewriter) { + function rewrite(root, locals) { + var value = root.right; + var state = { + root: root, + locals: locals, + value: value + }; + var target = getLeftHandSideOfDestructuringAssignment(root); + if (root.parent.kind !== 177) { + value = ts.Locals.ensureIdentifier(locals, value, writeDeclaration, state); + } + state.value = value; + ts.Visitor.visit(target, visitNode, state); + var mergedAssignments = state.mergedAssignments; + if (root.parent.kind !== 177) { + mergedAssignments = ts.Factory.createBinaryExpression(23, mergedAssignments, value); + } + return mergedAssignments; + } + DestructuringAssignmentRewriter.rewrite = rewrite; + function getLeftHandSideOfDestructuringAssignment(node) { + if (node.operator === 52) { + var left = node.left; + while (left.kind === 157) { + left = left.expression; + } + switch (left.kind) { + case 150: + case 149: + return left; + } + } + } + function visitNode(node, state) { + switch (node.kind) { + case 166: + return visitBinaryExpression(node, state); + case 150: + return visitObjectLiteralExpression(node, state); + case 149: + return visitArrayLiteralExpression(node, state); + } + var value = state.value; + writeAssignment(node, value, state); + return node; + } + function visitClassElement(node, state) { + switch (node.kind) { + case 208: + case 209: + return visitPropertyAssignment(node, state); + default: + return node; + } + } + function visitBinaryExpression(node, state) { + var value = state.value, locals = state.locals, saveValue = value; + if (node.operator === 52) { + value = ts.Locals.getValueOrDefault(locals, value, node.right, writeDeclaration, state); + state.value = value; + ts.Visitor.visit(node.left, visitNode, state); + } + state.value = saveValue; + return node; + } + function visitObjectLiteralExpression(node, state) { + var value = state.value, locals = state.locals, saveValue = value; + var properties = node.properties; + if (properties.length !== 1) { + value = ts.Locals.ensureIdentifier(locals, value, writeDeclaration, state); + } + state.value = value; + ts.Visitor.visitNodes(properties, visitClassElement, state); + state.value = saveValue; + return node; + } + function visitPropertyAssignment(node, state) { + var value = state.value, saveValue = value; + var propName = node.name; + state.value = ts.Factory.createPropertyOrElementAccessExpression(ts.Factory.makeLeftHandSideExpression(value), propName); + ts.Visitor.visit(node.initializer || propName, visitNode, state); + state.value = saveValue; + return node; + } + function visitArrayLiteralExpression(node, state) { + var value = state.value, locals = state.locals, saveValue = value; + var elements = node.elements; + if (elements.length !== 1) { + value = ts.Locals.ensureIdentifier(state.locals, value, writeDeclaration, state); + } + for (var i = 0; i < elements.length; i++) { + var e = elements[i]; + if (e.kind !== 172) { + if (e.kind !== 171) { + state.value = ts.Factory.createElementAccessExpression(ts.Factory.makeLeftHandSideExpression(value), ts.Factory.createNumericLiteral(i)); + ts.Visitor.visit(e, visitNode, state); + } + else if (i === elements.length - 1) { + value = ts.Locals.ensureIdentifier(state.locals, value, writeDeclaration, state); + var sliceExpression = ts.Factory.createPropertyAccessExpression(ts.Factory.makeLeftHandSideExpression(value), ts.Factory.createIdentifier("slice")); + var callExpression = ts.Factory.createCallExpression(sliceExpression, [ts.Factory.createNumericLiteral(i)]); + writeAssignment(e.expression, callExpression, state); + } + } + } + state.value = saveValue; + return node; + } + function visitIdentifier(node, state) { + var value = state.value; + writeAssignment(node, value, state); + return node; + } + function writeDeclaration(left, right, state) { + var locals = state.locals; + ts.Locals.recordVariable(locals, left); + writeAssignment(left, right, state); + } + function writeAssignment(left, right, state) { + var mergedAssignments = state.mergedAssignments; + var assignmentExpression = ts.Factory.createBinaryExpression(52, left, right); + if (mergedAssignments) { + mergedAssignments = ts.Factory.createBinaryExpression(23, mergedAssignments, assignmentExpression); + } + else { + mergedAssignments = assignmentExpression; + } + state.mergedAssignments = mergedAssignments; + } + })(DestructuringAssignmentRewriter = ts.DestructuringAssignmentRewriter || (ts.DestructuringAssignmentRewriter = {})); + var SpreadElementRewriter; + (function (SpreadElementRewriter) { + function rewrite(elements) { + var segments; + var length = elements.length; + var start = 0; + for (var i = 0; i < length; i++) { + var element = elements[i]; + if (element.kind === 171) { + if (!segments) { + segments = []; + } + if (i > start) { + segments.push(ts.Factory.createArrayLiteralExpression(elements.slice(start, i))); + } + segments.push(element.expression); + start = i + 1; + } + } + if (!segments) { + return undefined; + } + if (start < length) { + segments.push(ts.Factory.createArrayLiteralExpression(elements.slice(start, length))); + } + if (segments.length === 1) { + return ts.Factory.makeLeftHandSideExpression(segments[0]); + } + var head = ts.Factory.makeLeftHandSideExpression(segments.shift()); + var concatExpression = ts.Factory.createPropertyAccessExpression(head, ts.Factory.createIdentifier("concat")); + var callExpression = ts.Factory.createCallExpression(concatExpression, segments); + return callExpression; + } + SpreadElementRewriter.rewrite = rewrite; + })(SpreadElementRewriter = ts.SpreadElementRewriter || (ts.SpreadElementRewriter = {})); + var AsyncFunctionRewriter; + (function (AsyncFunctionRewriter) { + function rewrite(node, promiseConstructor, locals, compilerOptions) { + var resolve = ts.Locals.createUniqueIdentifier(locals, "_resolve"); + var generatorFunctionBody = ts.Factory.createBlock(rewriteBody(node.body)); + var generatorFunction = ts.Factory.createFunctionExpression(undefined, [], generatorFunctionBody); + generatorFunction.asteriskToken = ts.Factory.createTokenNode(35); + var bodyStatements = []; + var generator = createGenerator(generatorFunctionBody, bodyStatements, locals, compilerOptions); + var awaiterCallExpression = ts.Factory.createCallExpression(ts.Factory.createIdentifier("__awaiter"), [generator]); + var resolveCallExpression = ts.Factory.createCallExpression(resolve, [awaiterCallExpression]); + var resolveCallStatement = ts.Factory.createExpressionStatement(resolveCallExpression); + var initFunctionBody = ts.Factory.createBlock([resolveCallStatement]); + var initFunctionExpression = ts.Factory.createFunctionExpression(undefined, [ts.Factory.createParameterDeclaration(resolve)], initFunctionBody); + var newPromiseExpression = ts.Factory.createNewExpression(ts.Factory.getExpressionForEntityName(promiseConstructor), [initFunctionExpression]); + var bodyReturnStatement = ts.Factory.createReturnStatement(newPromiseExpression); + bodyStatements.push(bodyReturnStatement); + var block = ts.Factory.createBlock(bodyStatements); + var func = ts.Factory.updateFunctionLikeDeclaration(node, node.name, block, node.parameters); + func.id = node.id; + func.parent = node.parent; + return func; + } + AsyncFunctionRewriter.rewrite = rewrite; + function rewriteBody(body) { + if (body.kind === 174) { + return ts.Visitor.visitNodes(body.statements, visitNode); + } + else { + return ts.Factory.createNodeArray([ + ts.Factory.createReturnStatement(ts.Visitor.visit(body, visitNode)) + ]); + } + } + function createGenerator(body, statements, locals, compilerOptions) { + var generatorFunction = ts.Factory.createFunctionExpression(undefined, [], body); + generatorFunction.asteriskToken = ts.Factory.createTokenNode(35); + if (compilerOptions.target < 2) { + generatorFunction = GeneratorFunctionRewriter.rewrite(generatorFunction, locals); + body = generatorFunction.body; + var generator; + for (var i = 0; i < body.statements.length; i++) { + var statement = body.statements[i]; + if (statement.kind === 194 || statement.kind === 175) { + statements.push(statement); + } + else if (statement.kind === 185) { + generator = statement.expression; + } + } + return generator; + } + else { + return ts.Factory.createCallExpression(generatorFunction, []); + } + } + function visitNode(node) { + switch (node.kind) { + case 163: + return visitAwaitExpression(node); + case 177: + return visitExpressionStatement(node); + case 159: + case 158: + case 194: + case 132: + case 133: + case 130: + return node; + default: + return ts.Visitor.fallback(node, visitNode); + } + } + function visitAwaitExpression(node) { + var expression = ts.Visitor.visit(node.expression, visitNode); + var yieldExpression = ts.Factory.createYieldExpression(expression, undefined, node); + return ts.Factory.makeLeftHandSideExpression(yieldExpression); + } + function visitExpressionStatement(node) { + var expression = ts.Visitor.visit(node.expression, visitNode); + if (ts.nodeIsGenerated(expression) && expression.kind === 157) { + expression = expression.expression; + } + return ts.Factory.updateExpressionStatement(node, expression); + } + })(AsyncFunctionRewriter = ts.AsyncFunctionRewriter || (ts.AsyncFunctionRewriter = {})); + var GeneratorFunctionRewriter; + (function (GeneratorFunctionRewriter) { + function rewrite(node, locals) { + var builder = ts.GeneratorFunctionBuilder.create(locals); + var state = { + locals: locals, + builder: builder + }; + if (node.parameters) { + for (var i = 0; i < node.parameters.length; i++) { + var parameter = node.parameters[i]; + rewriteParameterDeclaration(parameter, state); + } + } + if (node.body.kind === 174) { + rewriteBlock(node.body, state); + } + else { + ts.GeneratorFunctionBuilder.emit(builder, 7, ts.Visitor.visit(node.body, visitNode, state)); + } + var func = ts.GeneratorFunctionBuilder.buildFunction(builder, node.kind, node.name, node, node.flags, node.modifiers); + func.id = node.id; + func.parent = node.parent; + return func; + } + GeneratorFunctionRewriter.rewrite = rewrite; + function visitNode(node, state) { + switch (node.kind) { + case 166: return visitBinaryExpression(node, state); + case 167: return visitConditionalExpression(node, state); + case 169: return visitYieldExpression(node, state); + case 149: return visitArrayLiteralExpression(node, state); + case 150: return visitObjectLiteralExpression(node, state); + case 152: return visitElementAccessExpression(node, state); + case 153: return visitCallExpression(node, state); + case 154: return visitNewExpression(node, state); + case 155: return visitTaggedTemplateExpression(node, state); + case 168: return visitTemplateExpression(node, state); + case 157: return visitParenthesizedExpression(node, state); + case 175: return visitVariableStatement(node, state); + case 177: return visitExpressionStatement(node, state); + case 178: return visitIfStatement(node, state); + case 179: return visitDoStatement(node, state); + case 180: return visitWhileStatement(node, state); + case 181: return visitForStatement(node, state); + case 182: return visitForInStatement(node, state); + case 183: return visitContinueStatement(node, state); + case 184: return visitBreakStatement(node, state); + case 185: return visitReturnStatement(node, state); + case 186: return visitWithStatement(node, state); + case 187: return visitSwitchStatement(node, state); + case 188: return visitLabeledStatement(node, state); + case 190: return visitTryStatement(node, state); + case 194: return visitFunctionDeclaration(node, state); + case 158: + case 159: + case 132: + case 133: + case 130: + return node; + default: + return ts.Visitor.fallback(node, visitNode, state); + } + } + function visitBinaryExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + return rewriteBinaryExpression(node, state); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitConditionalExpression(node, state) { + if (ts.hasAwaitOrYield(node.whenTrue) || ts.hasAwaitOrYield(node.whenFalse)) { + return rewriteConditionalExpression(node, state); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitYieldExpression(node, state) { + return rewriteYieldExpression(node, state); + } + function visitArrayLiteralExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + var rewritten = SpreadElementRewriter.rewrite(node.elements); + if (rewritten) { + return ts.Visitor.visit(rewritten, visitNode, state); + } + return ts.Factory.updateArrayLiteralExpression(node, ts.Visitor.visitNodes(node.elements, visitNode, state, ts.hasAwaitOrYield, cacheExpression)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitObjectLiteralExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + return ts.Factory.updateObjectLiteralExpression(node, ts.Visitor.visitNodes(node.properties, visitNode, state, ts.hasAwaitOrYield, cacheObjectLiteralElement)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitElementAccessExpression(node, state) { + if (ts.hasAwaitOrYield(node.argumentExpression)) { + var object = cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state); + return ts.Factory.updateElementAccessExpression(node, object, ts.Visitor.visit(node.argumentExpression, visitNode, state)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitCallExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + var binding = rewriteLeftHandSideOfCallExpression(node.expression, state); + var arguments = ts.Visitor.visitNodes(node.arguments, visitNode, state, ts.hasAwaitOrYield, cacheExpression); + var target = binding.target; + var thisArg = binding.thisArg; + if (thisArg) { + var callArguments = ts.Factory.createNodeArray([thisArg].concat(arguments), node.arguments); + var callProperty = ts.Factory.createPropertyAccessExpression(target, ts.Factory.createIdentifier("call")); + return ts.Factory.updateCallExpression(node, callProperty, callArguments); + } + else { + return ts.Factory.updateCallExpression(node, target, arguments); + } + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitNewExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + return ts.Factory.updateNewExpression(node, cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state), ts.Visitor.visitNodes(node.arguments, visitNode, state, ts.hasAwaitOrYield, cacheExpression)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitTaggedTemplateExpression(node, state) { + if (ts.hasAwaitOrYield(node.template)) { + return ts.Factory.updateTaggedTemplateExpression(node, cacheExpression(ts.Visitor.visit(node.tag, visitNode, state), state), ts.Visitor.visit(node.template, visitNode, state)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitTemplateExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + return ts.Factory.updateTemplateExpression(node, node.head, ts.Visitor.visitNodes(node.templateSpans, visitNode, state, ts.hasAwaitOrYield, cacheTemplateSpan)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitParenthesizedExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + return rewriteParenthesizedExpression(node, state); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitFunctionDeclaration(node, state) { + ts.GeneratorFunctionBuilder.addFunction(state.builder, node); + return; + } + function visitVariableStatement(node, state) { + var assignment = rewriteVariableDeclarationList(node.declarationList, state); + if (assignment) { + return ts.Factory.createExpressionStatement(assignment); + } + return; + } + function visitVariableDeclarationListOrExpression(node, state) { + if (node.kind === 193) { + return rewriteVariableDeclarationList(node, state); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitExpressionStatement(node, state) { + if (ts.hasAwaitOrYield(node.expression)) { + rewriteExpressionStatement(node, state); + return; + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitIfStatement(node, state) { + if (ts.hasAwaitOrYield(node.thenStatement) || ts.hasAwaitOrYield(node.elseStatement)) { + rewriteIfStatement(node, state); + return; + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitDoStatement(node, state) { + if (ts.hasAwaitOrYield(node)) { + rewriteDoStatement(node, state); + return; + } + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginScriptContinueBlock(state.builder, getLabelNames(node)); + node = ts.Visitor.fallback(node, visitNode, state); + ts.GeneratorFunctionBuilder.endScriptContinueBlock(builder); + return node; + } + function visitWhileStatement(node, state) { + if (ts.hasAwaitOrYield(node)) { + rewriteWhileStatement(node, state); + return; + } + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginScriptContinueBlock(builder, getLabelNames(node)); + node = ts.Visitor.fallback(node, visitNode, state); + ts.GeneratorFunctionBuilder.endScriptContinueBlock(builder); + return node; + } + function visitForStatement(node, state) { + if (ts.hasAwaitOrYield(node.condition) || ts.hasAwaitOrYield(node.iterator) || ts.hasAwaitOrYield(node.statement)) { + rewriteForStatement(node, state); + return; + } + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginScriptContinueBlock(builder, getLabelNames(node)); + node = ts.Factory.updateForStatement(node, ts.Visitor.visit(node.initializer, visitVariableDeclarationListOrExpression, state), ts.Visitor.visit(node.condition, visitNode, state), ts.Visitor.visit(node.iterator, visitNode, state), ts.Visitor.visit(node.statement, visitNode, state)); + ts.GeneratorFunctionBuilder.endScriptContinueBlock(builder); + return node; + } + function visitForInStatement(node, state) { + if (ts.hasAwaitOrYield(node.statement)) { + rewriteForInStatement(node, state); + return; + } + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginScriptContinueBlock(builder, getLabelNames(node)); + node = ts.Factory.updateForInStatement(node, ts.Visitor.visit(node.initializer, visitVariableDeclarationListOrExpression, state), ts.Visitor.visit(node.expression, visitNode, state), ts.Visitor.visit(node.statement, visitNode, state)); + ts.GeneratorFunctionBuilder.endScriptContinueBlock(builder); + return node; + } + function visitBreakStatement(node, state) { + var label = ts.GeneratorFunctionBuilder.findBreakTarget(state.builder, node.label && node.label.text); + if (label > 0) { + ts.GeneratorFunctionBuilder.writeLocation(state.builder, node); + return ts.GeneratorFunctionBuilder.createInlineBreak(state.builder, label); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitContinueStatement(node, state) { + var label = ts.GeneratorFunctionBuilder.findContinueTarget(state.builder, node.label && node.label.text); + if (label > 0) { + ts.GeneratorFunctionBuilder.writeLocation(state.builder, node); + return ts.GeneratorFunctionBuilder.createInlineBreak(state.builder, label); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitReturnStatement(node, state) { + var expression = ts.Visitor.visit(node.expression, visitNode, state); + ts.GeneratorFunctionBuilder.writeLocation(state.builder, node); + return ts.GeneratorFunctionBuilder.createInlineReturn(state.builder, expression); + } + function visitSwitchStatement(node, state) { + if (ts.forEach(node.clauses, ts.hasAwaitOrYield)) { + rewriteSwitchStatement(node, state); + return; + } + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginScriptBreakBlock(builder, getLabelNames(node), false); + node = ts.Visitor.fallback(node, visitNode, state); + ts.GeneratorFunctionBuilder.endScriptBreakBlock(builder); + return node; + } + function visitWithStatement(node, state) { + if (ts.hasAwaitOrYield(node.statement)) { + rewriteWithStatement(node, state); + return; + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitLabeledStatement(node, state) { + if (ts.hasAwaitOrYield(node.statement)) { + rewriteLabeledStatement(node, state); + return; + } + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginScriptBreakBlock(builder, getLabelNames(node), true); + node = ts.Visitor.fallback(node, visitNode, state); + ts.GeneratorFunctionBuilder.endScriptBreakBlock(builder); + return node; + } + function visitTryStatement(node, state) { + if (ts.hasAwaitOrYield(node)) { + rewriteTryStatement(node, state); + return; + } + return ts.Visitor.fallback(node, visitNode, state); + } + function cacheExpression(node, state) { + var local = ts.GeneratorFunctionBuilder.declareLocal(state.builder); + var assignExpression = ts.Factory.createBinaryExpression(52, local, node); + ts.GeneratorFunctionBuilder.emit(state.builder, 1, ts.Factory.createExpressionStatement(assignExpression)); + return local; + } + function cacheObjectLiteralElement(node, state) { + switch (node.kind) { + case 208: + return cachePropertyAssignment(node, state); + case 209: + return cacheShorthandPropertyAssignment(node, state); + default: + return node; + } + } + function cachePropertyAssignment(node, state) { + return ts.Factory.updatePropertyAssignment(node, node.name, cacheExpression(node.initializer, state)); + } + function cacheShorthandPropertyAssignment(node, state) { + return ts.Factory.createPropertyAssignment(ts.Factory.createIdentifier(node.name.text), cacheExpression(node.name, state)); + } + function cacheTemplateSpan(node, state) { + return ts.Factory.updateTemplateSpan(node, cacheExpression(node.expression, state), node.literal); + } + function rewriteBinaryExpression(node, state) { + if (ts.isLogicalBinary(node)) { + if (ts.hasAwaitOrYield(node.right)) { + return rewriteLogicalBinaryExpression(node, state); + } + } + else if (ts.isDestructuringAssignment(node)) { + return rewriteDestructuringAssignment(node, state); + } + else if (ts.isAssignment(node)) { + if (ts.hasAwaitOrYield(node.right)) { + return rewriteAssignmentExpression(node, state); + } + } + else if (node.operator === 23) { + return rewriteCommaExpression(node, state); + } + else if (ts.hasAwaitOrYield(node.right)) { + return ts.Factory.updateBinaryExpression(node, cacheExpression(ts.Visitor.visit(node.left, visitNode, state), state), ts.Visitor.visit(node.right, visitNode, state)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function rewriteLogicalBinaryExpression(node, state) { + var builder = state.builder; + var resumeLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var resultLocal = ts.GeneratorFunctionBuilder.declareLocal(builder); + var code = node.operator === 48 ? 5 : 4; + ts.GeneratorFunctionBuilder.writeLocation(builder, node.left); + ts.GeneratorFunctionBuilder.emit(builder, 2, resultLocal, ts.Visitor.visit(node.left, visitNode, state)); + ts.GeneratorFunctionBuilder.emit(builder, code, resumeLabel, resultLocal); + ts.GeneratorFunctionBuilder.writeLocation(builder, node.right); + ts.GeneratorFunctionBuilder.emit(builder, 2, resultLocal, ts.Visitor.visit(node.right, visitNode, state)); + ts.GeneratorFunctionBuilder.markLabel(builder, resumeLabel); + return resultLocal; + } + function rewriteCommaExpression(node, state) { + var builder = state.builder; + var expressions = flattenCommaExpression(node); + var merged; + for (var i = 0; i < expressions.length; i++) { + var expression = expressions[i]; + if (ts.hasAwaitOrYield(expression) && merged) { + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(merged)); + merged = undefined; + } + var visited = ts.Visitor.visit(expression, visitNode, state); + if (merged) { + merged = ts.Factory.createBinaryExpression(23, merged, visited); + } + else { + merged = visited; + } + } + return merged; + } + function rewriteDestructuringAssignment(node, state) { + var destructured = DestructuringAssignmentRewriter.rewrite(node, state.locals); + var rewritten = visitBinaryExpression(destructured, state); + if (ts.needsParenthesisForPropertyAccess(node)) { + return ts.Factory.makeLeftHandSideExpression(rewritten); + } + return rewritten; + } + function rewriteAssignmentExpression(node, state) { + return ts.Factory.updateBinaryExpression(node, rewriteLeftHandSideOfAssignmentExpression(node.left, state), ts.Visitor.visit(node.right, visitNode, state)); + } + function rewriteLeftHandSideOfAssignmentExpression(node, state) { + switch (node.kind) { + case 152: + return rewriteLeftHandSideElementAccessExpressionOfAssignmentExpression(node, state); + case 151: + return rewriteLeftHandSidePropertyAccessExpressionOfAssignmentExpression(node, state); + default: + return ts.Visitor.fallback(node, visitNode, state); + } + } + function rewriteLeftHandSideElementAccessExpressionOfAssignmentExpression(node, state) { + return ts.Factory.updateElementAccessExpression(node, cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state), cacheExpression(ts.Visitor.visit(node.argumentExpression, visitNode, state), state)); + } + function rewriteLeftHandSidePropertyAccessExpressionOfAssignmentExpression(node, state) { + return ts.Factory.updatePropertyAccessExpression(node, cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state), node.name); + } + function rewriteLeftHandSideOfCallExpression(node, state) { + switch (node.kind) { + case 151: + return rewriteLeftHandSidePropertyAccessExpressionOfCallExpression(node, state); + case 152: + return rewriteLeftHandSideElementAccessExpressionOfCallExpression(node, state); + default: + return { target: cacheExpression(ts.Visitor.visit(node, visitNode, state), state) }; + } + } + function rewriteLeftHandSideElementAccessExpressionOfCallExpression(node, state) { + var builder = state.builder; + var thisArg = cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state); + var target = ts.GeneratorFunctionBuilder.declareLocal(builder); + var index = ts.Visitor.visit(node.argumentExpression, visitNode, state); + var indexedAccess = ts.Factory.createElementAccessExpression(thisArg, index, node); + var assignExpression = ts.Factory.createBinaryExpression(52, target, indexedAccess); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(assignExpression)); + return { target: target, thisArg: thisArg }; + } + function rewriteLeftHandSidePropertyAccessExpressionOfCallExpression(node, state) { + var builder = state.builder; + var thisArg = cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state); + var target = ts.GeneratorFunctionBuilder.declareLocal(builder); + var property = ts.Factory.createIdentifier(node.name.text); + var propertyAccess = ts.Factory.createPropertyAccessExpression(thisArg, property, node); + var assignExpression = ts.Factory.createBinaryExpression(52, target, propertyAccess); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(assignExpression)); + return { target: target, thisArg: thisArg }; + } + function rewriteVariableDeclarationList(node, state) { + var declarations = node.declarations; + return rewriteVariableDeclarations(node, declarations, state); + } + function rewriteVariableDeclarations(parent, declarations, state) { + var builder = state.builder; + var mergedAssignment; + for (var i = 0; i < declarations.length; i++) { + var node = declarations[i]; + if (ts.hasAwaitOrYield(node)) { + if (mergedAssignment) { + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(mergedAssignment)); + mergedAssignment = undefined; + } + } + var rewritten = rewriteVariableDeclaration(node, state); + if (rewritten) { + if (mergedAssignment) { + mergedAssignment = ts.Factory.createBinaryExpression(23, mergedAssignment, rewritten); + } + else { + mergedAssignment = rewritten; + } + } + } + if (parent.kind === 193 && parent.parent.kind === 182) { + if (mergedAssignment) { + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(mergedAssignment)); + mergedAssignment = undefined; + } + var declaration = declarations[0]; + return declaration.name; + } + return mergedAssignment; + } + function rewriteVariableDeclaration(node, state) { + var builder = state.builder; + if (ts.isBindingPattern(node.name)) { + var declarations = BindingElementRewriter.rewrite(node, state.locals); + var result = rewriteVariableDeclarations(node, declarations, state); + rewriteExpression(result, state); + return; + } + ts.GeneratorFunctionBuilder.addVariable(builder, ts.Factory.createIdentifier(node.name.text)); + var initializer = ts.Visitor.visit(node.initializer, visitNode, state); + if (initializer) { + return ts.Factory.createBinaryExpression(52, node.name, initializer, node); + } + } + function rewriteConditionalExpression(node, state) { + var builder = state.builder; + var whenFalseLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var resumeLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var resultLocal = ts.GeneratorFunctionBuilder.declareLocal(builder); + ts.GeneratorFunctionBuilder.emit(builder, 5, whenFalseLabel, ts.Visitor.visit(node.condition, visitNode, state)); + ts.GeneratorFunctionBuilder.writeLocation(builder, node.whenTrue); + ts.GeneratorFunctionBuilder.emit(builder, 2, resultLocal, ts.Visitor.visit(node.whenTrue, visitNode, state)); + ts.GeneratorFunctionBuilder.emit(builder, 3, resumeLabel); + ts.GeneratorFunctionBuilder.markLabel(builder, whenFalseLabel); + ts.GeneratorFunctionBuilder.writeLocation(builder, node.whenFalse); + ts.GeneratorFunctionBuilder.emit(builder, 2, resultLocal, ts.Visitor.visit(node.whenFalse, visitNode, state)); + ts.GeneratorFunctionBuilder.markLabel(builder, resumeLabel); + return resultLocal; + } + function rewriteYieldExpression(node, state) { + var builder = state.builder; + var expression = ts.Visitor.visit(node.expression, visitNode, state); + var resumeLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.Debug.assert(!node.asteriskToken, "yield* not supported"); + ts.GeneratorFunctionBuilder.emit(builder, 6, expression); + ts.GeneratorFunctionBuilder.markLabel(builder, resumeLabel); + return ts.GeneratorFunctionBuilder.createResume(builder); + } + function rewriteParenthesizedExpression(node, state) { + var expression = ts.Visitor.visit(node.expression, visitNode, state); + return ts.Factory.makeLeftHandSideExpression(expression); + } + function rewriteExpressionStatement(node, state) { + var builder = state.builder; + var expression = ts.Visitor.visit(node.expression, visitNode, state); + if (!ts.isAwaitOrYield(node.expression)) { + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 1, expression); + } + } + function rewriteIfStatement(node, state) { + var builder = state.builder; + var resumeLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + if (node.elseStatement) { + var elseLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + } + ts.GeneratorFunctionBuilder.emit(builder, 5, elseLabel || resumeLabel, ts.Visitor.visit(node.expression, visitNode, state)); + rewriteBlockOrStatement(node.thenStatement, state); + if (node.elseStatement) { + ts.GeneratorFunctionBuilder.emit(builder, 3, resumeLabel); + ts.GeneratorFunctionBuilder.markLabel(builder, elseLabel); + rewriteBlockOrStatement(node.elseStatement, state); + } + ts.GeneratorFunctionBuilder.markLabel(builder, resumeLabel); + } + function rewriteDoStatement(node, state) { + var builder = state.builder; + var bodyLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var conditionLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var endLabel = ts.GeneratorFunctionBuilder.beginContinueBlock(builder, conditionLabel, getLabelNames(node)); + ts.GeneratorFunctionBuilder.markLabel(builder, bodyLabel); + rewriteBlockOrStatement(node.statement, state); + ts.GeneratorFunctionBuilder.markLabel(builder, conditionLabel); + ts.GeneratorFunctionBuilder.emit(builder, 4, bodyLabel, ts.Visitor.visit(node.expression, visitNode, state)); + ts.GeneratorFunctionBuilder.endContinueBlock(builder); + } + function rewriteWhileStatement(node, state) { + var builder = state.builder; + var conditionLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var bodyLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var endLabel = ts.GeneratorFunctionBuilder.beginContinueBlock(builder, conditionLabel, getLabelNames(node)); + ts.GeneratorFunctionBuilder.markLabel(builder, conditionLabel); + ts.GeneratorFunctionBuilder.emit(builder, 5, endLabel, ts.Visitor.visit(node.expression, visitNode, state)); + rewriteBlockOrStatement(node.statement, state); + ts.GeneratorFunctionBuilder.emit(builder, 3, conditionLabel); + ts.GeneratorFunctionBuilder.endContinueBlock(builder); + } + function rewriteForStatement(node, state) { + var builder = state.builder; + var conditionLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var iteratorLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var endLabel = ts.GeneratorFunctionBuilder.beginContinueBlock(builder, iteratorLabel, getLabelNames(node)); + if (node.initializer) { + var initializer = visitVariableDeclarationListOrExpression(node.initializer, state); + ts.GeneratorFunctionBuilder.writeLocation(builder, node.initializer); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(initializer)); + } + ts.GeneratorFunctionBuilder.markLabel(builder, conditionLabel); + if (node.condition) { + ts.GeneratorFunctionBuilder.emit(builder, 5, endLabel, ts.Visitor.visit(node.condition, visitNode, state)); + } + rewriteBlockOrStatement(node.statement, state); + ts.GeneratorFunctionBuilder.markLabel(builder, iteratorLabel); + if (node.iterator) { + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(ts.Visitor.visit(node.iterator, visitNode, state))); + } + ts.GeneratorFunctionBuilder.emit(builder, 3, conditionLabel); + ts.GeneratorFunctionBuilder.endContinueBlock(builder); + } + function rewriteForInStatement(node, state) { + var builder = state.builder; + var variable = visitVariableDeclarationListOrExpression(node.initializer, state); + while (variable.kind === 166) { + variable = variable.left; + } + var keysLocal = ts.GeneratorFunctionBuilder.declareLocal(builder); + var tempLocal = ts.GeneratorFunctionBuilder.declareLocal(builder); + var conditionLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var iteratorLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var endLabel = ts.GeneratorFunctionBuilder.beginContinueBlock(builder, iteratorLabel, getLabelNames(node)); + var initializeKeysExpression = ts.Factory.createBinaryExpression(52, keysLocal, ts.Factory.createArrayLiteralExpression([])); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(initializeKeysExpression)); + var keysLengthExpression = ts.Factory.createPropertyAccessExpression(keysLocal, ts.Factory.createIdentifier("length")); + var keysPushExpression = ts.Factory.createElementAccessExpression(keysLocal, keysLengthExpression); + var assignKeyExpression = ts.Factory.createBinaryExpression(52, keysPushExpression, tempLocal); + var assignKeyStatement = ts.Factory.createExpressionStatement(assignKeyExpression); + var expression = cacheExpression(ts.Factory.makeLeftHandSideExpression(ts.Visitor.visit(node.expression, visitNode, state)), state); + var forTempInExpressionStatement = ts.Factory.createForInStatement(tempLocal, expression, assignKeyStatement); + ts.GeneratorFunctionBuilder.emit(builder, 1, forTempInExpressionStatement); + var initializeTempExpression = ts.Factory.createBinaryExpression(52, tempLocal, ts.Factory.createNumericLiteral(0)); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(initializeTempExpression)); + var conditionExpression = ts.Factory.createBinaryExpression(24, tempLocal, keysLengthExpression); + ts.GeneratorFunctionBuilder.markLabel(builder, conditionLabel); + ts.GeneratorFunctionBuilder.emit(builder, 5, endLabel, conditionExpression); + var readKeyExpression = ts.Factory.createElementAccessExpression(keysLocal, tempLocal); + var hasKeyExpression = ts.Factory.createBinaryExpression(85, readKeyExpression, expression); + ts.GeneratorFunctionBuilder.emit(builder, 5, iteratorLabel, hasKeyExpression); + var assignVariableExpression = ts.Factory.createBinaryExpression(52, variable, readKeyExpression); + ts.GeneratorFunctionBuilder.writeLocation(builder, node.initializer); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(assignVariableExpression, variable)); + rewriteBlockOrStatement(node.statement, state); + ts.GeneratorFunctionBuilder.markLabel(builder, iteratorLabel); + var incrementTempExpression = ts.Factory.createPostfixUnaryExpression(38, tempLocal); + ts.GeneratorFunctionBuilder.writeLocation(builder, node.initializer); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(incrementTempExpression, variable)); + ts.GeneratorFunctionBuilder.emit(builder, 3, conditionLabel); + ts.GeneratorFunctionBuilder.endContinueBlock(builder); + } + function rewriteSwitchStatement(node, state) { + var builder = state.builder; + var defaultClauseIndex = -1; + var endLabel = ts.GeneratorFunctionBuilder.beginBreakBlock(builder, getLabelNames(node), false); + var clauseHasStatements = []; + var clauseLabelMap = []; + var clauseLabels = [endLabel]; + for (var clauseIndex = node.clauses.length - 1; clauseIndex >= 0; clauseIndex--) { + var clause = node.clauses[clauseIndex]; + if (clause.kind === 205) { + if (defaultClauseIndex === -1) { + defaultClauseIndex = clauseIndex; + } + } + clauseHasStatements[clauseIndex] = !!(clause.statements && clause.statements.length); + if (clauseHasStatements[clauseIndex]) { + clauseLabelMap[clauseIndex] = clauseLabels.length; + clauseLabels.push(ts.GeneratorFunctionBuilder.defineLabel(builder)); + } + else { + clauseLabelMap[clauseIndex] = clauseLabels.length - 1; + } + } + var expression = cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state); + var lastClauseOffset = 0; + for (var clauseIndex = 0; clauseIndex < node.clauses.length; clauseIndex++) { + var clause = node.clauses[clauseIndex]; + if (clause.kind === 204) { + var caseClause = clause; + if (ts.hasAwaitOrYield(caseClause.expression)) { + emitPartialSwitchStatement(); + lastClauseOffset = clauseIndex; + } + } + } + emitPartialSwitchStatement(); + if (defaultClauseIndex > -1) { + var defaultClauseLabel = clauseLabels[clauseLabelMap[defaultClauseIndex]]; + ts.GeneratorFunctionBuilder.writeLocation(builder, node.clauses[defaultClauseIndex]); + ts.GeneratorFunctionBuilder.emit(builder, 3, defaultClauseLabel); + } + else { + ts.GeneratorFunctionBuilder.emit(builder, 3, endLabel); + } + for (var clauseIndex = 0; clauseIndex < node.clauses.length; clauseIndex++) { + if (!clauseHasStatements[clauseIndex]) { + continue; + } + var clause = node.clauses[clauseIndex]; + var clauseLabel = clauseLabels[clauseLabelMap[clauseIndex]]; + ts.GeneratorFunctionBuilder.markLabel(builder, clauseLabel); + rewriteStatements(clause.statements, state); + } + ts.GeneratorFunctionBuilder.endBreakBlock(builder); + function emitPartialSwitchStatement() { + var clauses = []; + if (lastClauseOffset < clauseIndex) { + var clause = node.clauses[lastClauseOffset]; + if (clause.kind === 204) { + var caseClause = clause; + if (ts.hasAwaitOrYield(caseClause.expression)) { + var clauseExpression = ts.Visitor.visit(caseClause.expression, visitNode, state); + var clauseLabel = clauseLabels[clauseLabelMap[lastClauseOffset]]; + ts.GeneratorFunctionBuilder.writeLocation(builder, caseClause.expression); + var breakStatement = ts.GeneratorFunctionBuilder.createInlineBreak(builder, clauseLabel); + clauses.push(ts.Factory.createCaseClause(clauseExpression, [breakStatement])); + lastClauseOffset++; + } + } + } + while (lastClauseOffset < clauseIndex) { + var clause = node.clauses[lastClauseOffset]; + var clauseLabel = clauseLabels[clauseLabelMap[lastClauseOffset]]; + if (clause.kind === 204) { + var caseClause = clause; + ts.GeneratorFunctionBuilder.writeLocation(builder, caseClause.expression); + var inlineBreak = ts.GeneratorFunctionBuilder.createInlineBreak(builder, clauseLabel); + clauses.push(ts.Factory.createCaseClause(ts.Visitor.visit(caseClause.expression, visitNode, state), [inlineBreak])); + } + lastClauseOffset++; + } + if (clauses.length) { + var switchStatement = ts.Factory.createSwitchStatement(expression, clauses, node); + ts.GeneratorFunctionBuilder.emit(builder, 1, switchStatement); + } + } + } + function rewriteWithStatement(node, state) { + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginWithBlock(builder, cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state)); + rewriteBlockOrStatement(node.statement, state); + ts.GeneratorFunctionBuilder.endWithBlock(builder); + } + function rewriteLabeledStatement(node, state) { + var builder = state.builder; + if (!ts.isLabeledOrIterationOrSwitchStatement(node.statement)) { + ts.GeneratorFunctionBuilder.beginBreakBlock(builder, getLabelNames(node), true); + } + rewriteBlockOrStatement(node.statement, state); + if (!ts.isLabeledOrIterationOrSwitchStatement(node.statement)) { + ts.GeneratorFunctionBuilder.endBreakBlock(builder); + } + } + function rewriteTryStatement(node, state) { + var builder = state.builder; + var endLabel = ts.GeneratorFunctionBuilder.beginExceptionBlock(builder); + rewriteBlock(node.tryBlock, state); + if (node.catchClause) { + var variable = ts.GeneratorFunctionBuilder.declareLocal(builder, undefined, true); + if (node.catchClause.symbol) { + state.locals.resolver.renameSymbol(node.catchClause.symbol, variable.text); + } + ts.GeneratorFunctionBuilder.beginCatchBlock(builder, variable); + rewriteBlock(node.catchClause.block, state); + } + if (node.finallyBlock) { + ts.GeneratorFunctionBuilder.beginFinallyBlock(builder); + rewriteBlock(node.finallyBlock, state); + } + ts.GeneratorFunctionBuilder.endExceptionBlock(builder); + } + function rewriteReturnStatement(node, state) { + var builder = state.builder; + var expression = ts.Visitor.visit(node.expression, visitNode, state); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 7, expression); + } + function rewriteThrowStatement(node, state) { + var builder = state.builder; + var expression = ts.Visitor.visit(node.expression, visitNode, state); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 8, expression); + } + function rewriteBreakStatement(node, state) { + var builder = state.builder; + var label = ts.GeneratorFunctionBuilder.findBreakTarget(builder, node.label && node.label.text); + ts.Debug.assert(label > 0, "Expected break statement to point to a label."); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 3, label); + } + function rewriteContinueStatement(node, state) { + var builder = state.builder; + var label = ts.GeneratorFunctionBuilder.findContinueTarget(builder, node.label && node.label.text); + ts.Debug.assert(label > 0, "Expected continue statement to point to a label."); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 3, label); + } + function rewriteStatements(statements, state) { + for (var i = 0; i < statements.length; i++) { + var statement = statements[i]; + rewriteStatement(statement, state); + } + } + function rewriteBlockOrStatement(node, state) { + if (!node) { + return; + } + switch (node.kind) { + case 174: + return rewriteBlock(node, state); + default: + return rewriteStatement(node, state); + } + } + function rewriteBlock(node, state) { + if (!node) { + return; + } + rewriteStatements(node.statements, state); + } + function rewriteStatement(node, state) { + var builder = state.builder; + if (!node) { + return; + } + switch (node.kind) { + case 174: + if (!ts.hasAwaitOrYield(node)) { + break; + } + return rewriteBlock(node, state); + case 189: + return rewriteThrowStatement(node, state); + case 185: + return rewriteReturnStatement(node, state); + case 184: + return rewriteBreakStatement(node, state); + case 183: + return rewriteContinueStatement(node, state); + } + var visited = ts.Visitor.visit(node, visitNode, state); + if (visited) { + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 1, visited); + } + } + function rewriteExpression(node, state) { + var builder = state.builder; + if (!node) { + return; + } + var visited = ts.Visitor.visit(node, visitNode, state); + if (visited) { + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 1, visited); + } + } + function rewriteParameterDeclaration(node, state) { + var builder = state.builder; + var parameterName; + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + if (ts.isBindingPattern(node.name)) { + parameterName = ts.Locals.createUniqueIdentifier(state.locals); + } + else { + parameterName = node.name; + } + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.addParameter(builder, parameterName, node.flags); + if (ts.isBindingPattern(node.name)) { + var declarations = BindingElementRewriter.rewrite(node, state.locals, parameterName); + var expression = rewriteVariableDeclarations(node, declarations, state); + if (expression) { + ts.GeneratorFunctionBuilder.emit(builder, 1, expression); + } + } + else if (node.initializer) { + var equalityExpression = ts.Factory.createBinaryExpression(30, parameterName, ts.Factory.createVoidZero()); + var assignmentExpression = ts.Factory.createBinaryExpression(52, parameterName, node.initializer); + var expressionStatement = ts.Factory.createExpressionStatement(assignmentExpression); + var ifStatement = ts.Factory.createIfStatement(equalityExpression, expressionStatement); + rewriteStatement(ifStatement, state); + } + } + function flattenCommaExpression(node) { + var expressions = []; + function visitExpression(node) { + if (node.kind === 166 && node.operator === 23) { + visitExpression(node.left); + visitExpression(node.right); + } + else { + expressions.push(node); + } + } + visitExpression(node); + return expressions; + } + function getLabelNames(node) { + var labeledStatement; + switch (node.kind) { + case 188: + labeledStatement = node; + break; + case 187: + case 179: + case 180: + case 181: + case 182: + if (node.parent.kind === 188) { + labeledStatement = node.parent; + break; + } + default: + return; + } + var labels = []; + while (true) { + labels.push(labeledStatement.label.text); + if (labeledStatement.parent.kind === 188) { + labeledStatement = labeledStatement.parent; + } + else { + break; + } + } + return labels; + } + })(GeneratorFunctionRewriter = ts.GeneratorFunctionRewriter || (ts.GeneratorFunctionRewriter = {})); +})(ts || (ts = {})); +var ts; +(function (ts) { + var indentStrings = ["", " "]; + function getIndentString(level) { + if (indentStrings[level] === undefined) { + indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; + } + return indentStrings[level]; + } + ts.getIndentString = getIndentString; + function getIndentSize() { + return indentStrings[1].length; + } + function shouldEmitToOwnFile(sourceFile, compilerOptions) { + if (!ts.isDeclarationFile(sourceFile)) { if ((ts.isExternalModule(sourceFile) || !compilerOptions.out) && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { return true; } @@ -15830,6 +19827,9 @@ var ts; }; } function getLineOfLocalPosition(currentSourceFile, pos) { + if (pos < 0) { + return -1; + } return ts.getLineAndCharacterOfPosition(currentSourceFile, pos).line; } function emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments) { @@ -15917,7 +19917,7 @@ var ts; } function getFirstConstructorWithBody(node) { return ts.forEach(node.members, function (member) { - if (member.kind === 129 && ts.nodeIsPresent(member.body)) { + if (member.kind === 131 && ts.nodeIsPresent(member.body)) { return member; } }); @@ -15926,12 +19926,12 @@ var ts; var firstAccessor; var getAccessor; var setAccessor; - if (accessor.name.kind === 122) { + if (accessor.name.kind === 124) { firstAccessor = accessor; - if (accessor.kind === 130) { + if (accessor.kind === 132) { getAccessor = accessor; } - else if (accessor.kind === 131) { + else if (accessor.kind === 133) { setAccessor = accessor; } else { @@ -15940,14 +19940,14 @@ var ts; } else { ts.forEach(node.members, function (member) { - if ((member.kind === 130 || member.kind === 131) && member.name.text === accessor.name.text && (member.flags & 128) === (accessor.flags & 128)) { + if ((member.kind === 132 || member.kind === 133) && member.name.text === accessor.name.text && (member.flags & 128) === (accessor.flags & 128)) { if (!firstAccessor) { firstAccessor = member; } - if (member.kind === 130 && !getAccessor) { + if (member.kind === 132 && !getAccessor) { getAccessor = member; } - if (member.kind === 131 && !setAccessor) { + if (member.kind === 133 && !setAccessor) { setAccessor = member; } } @@ -15992,8 +19992,7 @@ var ts; var enclosingDeclaration; var currentSourceFile; var reportedDeclarationError = false; - var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { - } : writeJsDocComments; + var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { } : writeJsDocComments; var emit = compilerOptions.stripInternal ? stripInternal : emitNode; var aliasDeclarationEmitInfo = []; var referencePathsOutput = ""; @@ -16165,32 +20164,32 @@ var ts; case 98: case 8: return writeTextOfNode(currentSourceFile, type); - case 135: + case 137: return emitTypeReference(type); - case 138: - return emitTypeQuery(type); case 140: + return emitTypeQuery(type); + case 142: return emitArrayType(type); - case 141: + case 143: return emitTupleType(type); - case 142: + case 144: return emitUnionType(type); - case 143: + case 145: return emitParenType(type); - case 136: - case 137: - return emitSignatureDeclarationWithJsDocComments(type); + case 138: case 139: + return emitSignatureDeclarationWithJsDocComments(type); + case 141: return emitTypeLiteral(type); case 64: return emitEntityName(type); - case 121: + case 123: return emitEntityName(type); default: ts.Debug.fail("Unknown type annotation: " + type.kind); } function emitEntityName(entityName) { - var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 197 ? entityName.parent : enclosingDeclaration); + var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 201 ? entityName.parent : enclosingDeclaration); handleSymbolAccessibilityError(visibilityResult); writeEntityName(entityName); function writeEntityName(entityName) { @@ -16261,7 +20260,7 @@ var ts; if (node.flags & 1) { write("export "); } - if (node.kind !== 192) { + if (node.kind !== 196) { write("declare "); } } @@ -16321,7 +20320,7 @@ var ts; emitModuleElementDeclarationFlags(node); write("module "); writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== 196) { + while (node.body.kind !== 200) { node = node.body; write("."); writeTextOfNode(currentSourceFile, node.name); @@ -16387,7 +20386,7 @@ var ts; writeLine(); } function isPrivateMethodTypeParameter(node) { - return node.parent.kind === 128 && (node.parent.flags & 32); + return node.parent.kind === 130 && (node.parent.flags & 32); } function emitTypeParameters(typeParameters) { function emitTypeParameter(node) { @@ -16397,8 +20396,8 @@ var ts; writeTextOfNode(currentSourceFile, node.name); if (node.constraint && !isPrivateMethodTypeParameter(node)) { write(" extends "); - if (node.parent.kind === 136 || node.parent.kind === 137 || (node.parent.parent && node.parent.parent.kind === 139)) { - ts.Debug.assert(node.parent.kind === 128 || node.parent.kind === 127 || node.parent.kind === 136 || node.parent.kind === 137 || node.parent.kind === 132 || node.parent.kind === 133); + if (node.parent.kind === 138 || node.parent.kind === 139 || (node.parent.parent && node.parent.parent.kind === 141)) { + ts.Debug.assert(node.parent.kind === 130 || node.parent.kind === 129 || node.parent.kind === 138 || node.parent.kind === 139 || node.parent.kind === 134 || node.parent.kind === 135); emitType(node.constraint); } else { @@ -16408,31 +20407,31 @@ var ts; function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.parent.kind) { - case 191: + case 195: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; break; - case 192: + case 196: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; break; - case 133: + case 135: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 132: + case 134: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 128: - case 127: + case 130: + case 129: if (node.parent.flags & 128) { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 191) { + else if (node.parent.parent.kind === 195) { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 190: + case 194: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -16460,7 +20459,7 @@ var ts; emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.parent.parent.kind === 191) { + if (node.parent.parent.kind === 195) { diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; } else { @@ -16539,12 +20538,12 @@ var ts; writeLine(); } function emitVariableDeclaration(node) { - if (node.kind !== 188 || resolver.isDeclarationVisible(node)) { + if (node.kind !== 192 || resolver.isDeclarationVisible(node)) { writeTextOfNode(currentSourceFile, node.name); - if ((node.kind === 126 || node.kind === 125) && ts.hasQuestionToken(node)) { + if ((node.kind === 128 || node.kind === 127) && ts.hasQuestionToken(node)) { write("?"); } - if ((node.kind === 126 || node.kind === 125) && node.parent.kind === 139) { + if ((node.kind === 128 || node.kind === 127) && node.parent.kind === 141) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.flags & 32)) { @@ -16553,14 +20552,14 @@ var ts; } function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.kind === 188) { + if (node.kind === 192) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } - else if (node.kind === 126 || node.kind === 125) { + else if (node.kind === 128 || node.kind === 127) { if (node.flags & 128) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.kind === 191) { + else if (node.parent.kind === 195) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { @@ -16613,7 +20612,7 @@ var ts; var accessorWithTypeAnnotation = node; var type = getTypeAnnotationFromAccessor(node); if (!type) { - var anotherAccessor = node.kind === 130 ? accessors.setAccessor : accessors.getAccessor; + var anotherAccessor = node.kind === 132 ? accessors.setAccessor : accessors.getAccessor; type = getTypeAnnotationFromAccessor(anotherAccessor); if (type) { accessorWithTypeAnnotation = anotherAccessor; @@ -16626,12 +20625,12 @@ var ts; } function getTypeAnnotationFromAccessor(accessor) { if (accessor) { - return accessor.kind === 130 ? accessor.type : accessor.parameters.length > 0 ? accessor.parameters[0].type : undefined; + return accessor.kind === 132 ? accessor.type : accessor.parameters.length > 0 ? accessor.parameters[0].type : undefined; } } function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (accessorWithTypeAnnotation.kind === 131) { + if (accessorWithTypeAnnotation.kind === 133) { if (accessorWithTypeAnnotation.parent.flags & 128) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; } @@ -16663,19 +20662,19 @@ var ts; if (ts.hasDynamicName(node)) { return; } - if ((node.kind !== 190 || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { + if ((node.kind !== 194 || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); - if (node.kind === 190) { + if (node.kind === 194) { emitModuleElementDeclarationFlags(node); } - else if (node.kind === 128) { + else if (node.kind === 130) { emitClassMemberDeclarationFlags(node); } - if (node.kind === 190) { + if (node.kind === 194) { write("function "); writeTextOfNode(currentSourceFile, node.name); } - else if (node.kind === 129) { + else if (node.kind === 131) { write("constructor"); } else { @@ -16692,11 +20691,11 @@ var ts; emitSignatureDeclaration(node); } function emitSignatureDeclaration(node) { - if (node.kind === 133 || node.kind === 137) { + if (node.kind === 135 || node.kind === 139) { write("new "); } emitTypeParameters(node.typeParameters); - if (node.kind === 134) { + if (node.kind === 136) { write("["); } else { @@ -16705,20 +20704,20 @@ var ts; var prevEnclosingDeclaration = enclosingDeclaration; enclosingDeclaration = node; emitCommaList(node.parameters, emitParameterDeclaration); - if (node.kind === 134) { + if (node.kind === 136) { write("]"); } else { write(")"); } - var isFunctionTypeOrConstructorType = node.kind === 136 || node.kind === 137; - if (isFunctionTypeOrConstructorType || node.parent.kind === 139) { + var isFunctionTypeOrConstructorType = node.kind === 138 || node.kind === 139; + if (isFunctionTypeOrConstructorType || node.parent.kind === 141) { if (node.type) { write(isFunctionTypeOrConstructorType ? " => " : ": "); emitType(node.type); } } - else if (node.kind !== 129 && !(node.flags & 32)) { + else if (node.kind !== 131 && !(node.flags & 32)) { writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); } enclosingDeclaration = prevEnclosingDeclaration; @@ -16729,28 +20728,28 @@ var ts; function getReturnTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.kind) { - case 133: + case 135: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 132: + case 134: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 134: + case 136: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 128: - case 127: + case 130: + case 129: if (node.flags & 128) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } - else if (node.parent.kind === 191) { + else if (node.parent.kind === 195) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; - case 190: + case 194: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; break; default: @@ -16778,7 +20777,7 @@ var ts; write("?"); } decreaseIndent(); - if (node.parent.kind === 136 || node.parent.kind === 137 || node.parent.parent.kind === 139) { + if (node.parent.kind === 138 || node.parent.kind === 139 || node.parent.parent.kind === 141) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.parent.flags & 32)) { @@ -16787,28 +20786,28 @@ var ts; function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.parent.kind) { - case 129: + case 131: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; break; - case 133: + case 135: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 132: + case 134: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 128: - case 127: + case 130: + case 129: if (node.parent.flags & 128) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 191) { + else if (node.parent.parent.kind === 195) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 190: + case 194: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -16823,40 +20822,40 @@ var ts; } function emitNode(node) { switch (node.kind) { + case 131: + case 194: + case 130: case 129: - case 190: - case 128: - case 127: return emitFunctionDeclaration(node); - case 133: - case 132: + case 135: case 134: + case 136: return emitSignatureDeclarationWithJsDocComments(node); - case 130: - case 131: + case 132: + case 133: return emitAccessorDeclaration(node); - case 171: + case 175: return emitVariableStatement(node); - case 126: - case 125: + case 128: + case 127: return emitPropertyDeclaration(node); - case 192: + case 196: return emitInterfaceDeclaration(node); - case 191: + case 195: return emitClassDeclaration(node); - case 193: + case 197: return emitTypeAliasDeclaration(node); - case 206: + case 210: return emitEnumMemberDeclaration(node); - case 194: + case 198: return emitEnumDeclaration(node); - case 195: + case 199: return emitModuleDeclaration(node); - case 197: + case 201: return emitImportDeclaration(node); - case 198: + case 202: return emitExportAssignment(node); - case 207: + case 211: return emitSourceFile(node); } } @@ -16914,32 +20913,26 @@ var ts; var decreaseIndent = writer.decreaseIndent; var currentSourceFile; var extendsEmitted = false; - var tempCount = 0; - var tempVariables; + var awaiterEmitted = false; + var generatorEmitted = false; + var localsScope; + var locals; + var globals; var tempParameters; var writeEmittedFiles = writeJavaScriptFile; - var emitLeadingComments = compilerOptions.removeComments ? function (node) { - } : emitLeadingDeclarationComments; - var emitTrailingComments = compilerOptions.removeComments ? function (node) { - } : emitTrailingDeclarationComments; - var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { - } : emitLeadingCommentsOfLocalPosition; + var emitLeadingComments = compilerOptions.removeComments ? function (node) { } : emitLeadingDeclarationComments; + var emitTrailingComments = compilerOptions.removeComments ? function (node) { } : emitTrailingDeclarationComments; + var emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos) { } : emitLeadingCommentsOfLocalPosition; var detachedCommentsInfo; - var emitDetachedComments = compilerOptions.removeComments ? function (node) { - } : emitDetachedCommentsAtPosition; - var emitPinnedOrTripleSlashComments = compilerOptions.removeComments ? function (node) { - } : emitPinnedOrTripleSlashCommentsOfNode; + var emitDetachedComments = compilerOptions.removeComments ? function (node) { } : emitDetachedCommentsAtPosition; + var emitPinnedOrTripleSlashComments = compilerOptions.removeComments ? function (node) { } : emitPinnedOrTripleSlashCommentsOfNode; var writeComment = writeCommentRange; var emit = emitNode; - var emitStart = function (node) { - }; - var emitEnd = function (node) { - }; + var emitStart = function (node) { }; + var emitEnd = function (node) { }; var emitToken = emitTokenText; - var scopeEmitStart = function (scopeDeclaration, scopeName) { - }; - var scopeEmitEnd = function () { - }; + var scopeEmitStart = function (scopeDeclaration, scopeName) { }; + var scopeEmitEnd = function () { }; var sourceMapData; if (compilerOptions.sourceMap) { initializeEmitterWithSourceMaps(); @@ -17047,17 +21040,28 @@ var ts; } } function recordEmitNodeStartSpan(node) { + if (ts.nodeIsMissingOrGenerated(node)) { + return; + } recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); } function recordEmitNodeEndSpan(node) { + if (ts.nodeIsMissingOrGenerated(node)) { + return; + } recordSourceMapSpan(node.end); } function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { - var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); - recordSourceMapSpan(tokenStartPos); + if (startPos >= 0) { + var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); + recordSourceMapSpan(tokenStartPos); + } var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); - recordSourceMapSpan(tokenEndPos); - return tokenEndPos; + if (startPos >= 0) { + recordSourceMapSpan(tokenEndPos); + return tokenEndPos; + } + return -1; } function recordNewSourceFileStart(node) { var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir; @@ -17075,7 +21079,7 @@ var ts; var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { var name = node.name; - if (!name || name.kind !== 122) { + if (!name || name.kind !== 124) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -17092,10 +21096,10 @@ var ts; if (scopeName) { recordScopeNameStart(scopeName); } - else if (node.kind === 190 || node.kind === 156 || node.kind === 128 || node.kind === 127 || node.kind === 130 || node.kind === 131 || node.kind === 195 || node.kind === 191 || node.kind === 194) { + else if (node.kind === 194 || node.kind === 158 || node.kind === 130 || node.kind === 129 || node.kind === 132 || node.kind === 133 || node.kind === 199 || node.kind === 195 || node.kind === 198) { if (node.name) { var name = node.name; - scopeName = name.kind === 122 ? ts.getTextOfNode(name) : node.name.text; + scopeName = name.kind === 124 ? ts.getTextOfNode(name) : node.name.text; } recordScopeNameStart(scopeName); } @@ -17175,7 +21179,7 @@ var ts; } function emitNodeWithMap(node) { if (node) { - if (node.kind != 207) { + if (node.kind != 211) { recordEmitNodeStartSpan(node); emitNode(node); recordEmitNodeEndSpan(node); @@ -17198,27 +21202,16 @@ var ts; function writeJavaScriptFile(emitOutput, writeByteOrderMark) { writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); } - function createTempVariable(location, forLoopVariable) { - var name = forLoopVariable ? "_i" : undefined; - while (true) { - if (name && resolver.isUnknownIdentifier(location, name)) { - break; - } - name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + 97) : tempCount - 25); - tempCount++; + function ensureLocals() { + if (!globals) { + globals = {}; } - var result = ts.createNode(64); - result.text = name; - return result; - } - function recordTempDeclaration(name) { - if (!tempVariables) { - tempVariables = []; + if (!locals) { + locals = ts.Locals.create(resolver, localsScope, globals); } - tempVariables.push(name); } function emitTempDeclarations(newLine) { - if (tempVariables) { + if (locals && locals.variables) { if (newLine) { writeLine(); } @@ -17226,7 +21219,7 @@ var ts; write(" "); } write("var "); - emitCommaList(tempVariables); + emitCommaList(locals.variables); write(";"); } } @@ -17315,7 +21308,7 @@ var ts; return false; } function emitLiteral(node) { - var text = languageVersion < 2 && ts.isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; + var text = languageVersion < 2 && ts.isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent && node.pos >= 0 ? ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; if (compilerOptions.sourceMap && (node.kind === 8 || ts.isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } @@ -17345,7 +21338,7 @@ var ts; } for (var i = 0; i < node.templateSpans.length; i++) { var templateSpan = node.templateSpans[i]; - var needsParens = templateSpan.expression.kind !== 155 && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; + var needsParens = templateSpan.expression.kind !== 157 && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; if (i > 0 || headEmitted) { write(" + "); } @@ -17364,11 +21357,11 @@ var ts; } function templateNeedsParens(template, parent) { switch (parent.kind) { - case 151: - case 152: - return parent.expression === template; case 153: + case 154: + return parent.expression === template; case 155: + case 157: return false; default: return comparePrecedenceToBinaryPlus(parent) !== -1; @@ -17376,7 +21369,7 @@ var ts; } function comparePrecedenceToBinaryPlus(expression) { switch (expression.kind) { - case 163: + case 166: switch (expression.operator) { case 35: case 36: @@ -17388,7 +21381,7 @@ var ts; default: return -1; } - case 164: + case 167: return -1; default: return 1; @@ -17403,7 +21396,7 @@ var ts; if (node.kind === 8) { emitLiteral(node); } - else if (node.kind === 122) { + else if (node.kind === 124) { emit(node.expression); } else { @@ -17420,33 +21413,33 @@ var ts; function isNotExpressionIdentifier(node) { var parent = node.parent; switch (parent.kind) { - case 124: - case 188: - case 146: case 126: - case 125: - case 204: - case 205: - case 206: + case 192: + case 148: case 128: case 127: - case 190: + case 208: + case 209: + case 210: case 130: - case 131: - case 156: - case 191: - case 192: + case 129: case 194: + case 132: + case 133: + case 158: case 195: - case 197: - return parent.name === node; - case 180: - case 179: + case 196: case 198: - return false; + case 199: + case 201: + return parent.name === node; case 184: + case 183: + case 202: + return false; + case 188: return node.parent.label === node; - case 203: + case 207: return node.parent.name === node; } } @@ -17456,17 +21449,40 @@ var ts; write(prefix); write("."); } - writeTextOfNode(currentSourceFile, node); + if (resolver.getNodeCheckFlags(node) & 8) { + write("_arguments"); + } + else { + var generatedName = resolver.getRenamedIdentifier(node); + if (generatedName) { + write(generatedName); + } + else if (!node.parent || ts.nodeIsMissingOrGenerated(node)) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + } } function emitIdentifier(node) { - if (!node.parent) { - write(node.text); - } - else if (!isNotExpressionIdentifier(node)) { - emitExpressionIdentifier(node); + if (resolver.getNodeCheckFlags(node) & 8) { + write("_arguments"); } else { - writeTextOfNode(currentSourceFile, node); + var generatedName = resolver.getRenamedIdentifier(node); + if (generatedName) { + write(generatedName); + } + else if (!node.parent || ts.nodeIsMissingOrGenerated(node)) { + write(node.text); + } + else if (!isNotExpressionIdentifier(node)) { + emitExpressionIdentifier(node); + } + else { + writeTextOfNode(currentSourceFile, node); + } } } function emitThis(node) { @@ -17479,10 +21495,10 @@ var ts; } function emitSuper(node) { var flags = resolver.getNodeCheckFlags(node); - if (flags & 16) { + if (flags & 64) { write("_super.prototype"); } - else if (flags & 32) { + else if (flags & 128) { write("_super"); } else { @@ -17521,64 +21537,22 @@ var ts; write("..."); emit(node.expression); } - function needsParenthesisForPropertyAccess(node) { - switch (node.kind) { - case 64: - case 147: - case 149: - case 150: - case 151: - case 155: - return false; - } - return true; - } - function emitListWithSpread(elements, multiLine, trailingComma) { - var pos = 0; - var group = 0; - var length = elements.length; - while (pos < length) { - if (group === 1) { - write(".concat("); - } - else if (group > 1) { - write(", "); - } - var e = elements[pos]; - if (e.kind === 167) { - e = e.expression; - emitParenthesized(e, group === 0 && needsParenthesisForPropertyAccess(e)); - pos++; - } - else { - var i = pos; - while (i < length && elements[i].kind !== 167) { - i++; - } - write("["); - emitList(elements, pos, i - pos, multiLine, trailingComma && i === length); - write("]"); - pos = i; - } - group++; - } - if (group > 1) { - write(")"); - } - } function emitArrayLiteral(node) { var elements = node.elements; - if (elements.length === 0) { + var length = elements.length; + if (length === 0) { write("[]"); + return; } - else if (languageVersion >= 2) { - write("["); - emitList(elements, 0, elements.length, (node.flags & 256) !== 0, elements.hasTrailingComma); - write("]"); - } - else { - emitListWithSpread(elements, (node.flags & 256) !== 0, elements.hasTrailingComma); + if (languageVersion < 2) { + var rewritten = ts.SpreadElementRewriter.rewrite(node.elements); + if (rewritten) { + return emit(rewritten); + } } + write("["); + emitList(elements, 0, elements.length, (node.flags & 256) !== 0, elements.hasTrailingComma); + write("]"); } function emitObjectLiteral(node) { write("{"); @@ -17601,6 +21575,9 @@ var ts; write("]"); } function emitMethod(node) { + if (languageVersion >= 2) { + emit(node.asteriskToken); + } emit(node.name); if (languageVersion < 2) { write(": function "); @@ -17624,7 +21601,7 @@ var ts; if (constantValue !== undefined) { write(constantValue.toString()); if (!compilerOptions.removeComments) { - var propertyName = node.kind === 149 ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); + var propertyName = node.kind === 151 ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); write(" /* " + propertyName + " */"); } return true; @@ -17654,10 +21631,10 @@ var ts; write("]"); } function hasSpreadElement(elements) { - return ts.forEach(elements, function (e) { return e.kind === 167; }); + return ts.forEach(elements, function (e) { return e.kind === 171; }); } function skipParentheses(node) { - while (node.kind === 155 || node.kind === 154) { + while (node.kind === 157 || node.kind === 156) { node = node.expression; } return node; @@ -17667,8 +21644,9 @@ var ts; emit(node); return node; } - var temp = createTempVariable(node); - recordTempDeclaration(temp); + ensureLocals(); + var temp = ts.Locals.createUniqueIdentifier(locals); + ts.Locals.recordVariable(locals, temp); write("("); emit(temp); write(" = "); @@ -17679,12 +21657,12 @@ var ts; function emitCallWithSpread(node) { var target; var expr = skipParentheses(node.expression); - if (expr.kind === 149) { + if (expr.kind === 151) { target = emitCallTarget(expr.expression); write("."); emit(expr.name); } - else if (expr.kind === 150) { + else if (expr.kind === 152) { target = emitCallTarget(expr.expression); write("["); emit(expr.argumentExpression); @@ -17710,7 +21688,8 @@ var ts; write("void 0"); } write(", "); - emitListWithSpread(node.arguments, false, false); + var rewritten = ts.SpreadElementRewriter.rewrite(node.arguments); + emit(rewritten); write(")"); } function emitCallExpression(node) { @@ -17725,7 +21704,7 @@ var ts; } else { emit(node.expression); - superCall = node.expression.kind === 149 && node.expression.expression.kind === 90; + superCall = node.expression.kind === 151 && node.expression.expression.kind === 90; } if (superCall) { write(".call("); @@ -17757,12 +21736,12 @@ var ts; emit(node.template); } function emitParenExpression(node) { - if (node.expression.kind === 154) { + if (node.expression.kind === 156) { var operand = node.expression.expression; - while (operand.kind == 154) { + while (operand.kind == 156) { operand = operand.expression; } - if (operand.kind !== 161 && operand.kind !== 160 && operand.kind !== 159 && operand.kind !== 158 && operand.kind !== 162 && operand.kind !== 152 && !(operand.kind === 151 && node.parent.kind === 152) && !(operand.kind === 156 && node.parent.kind === 151)) { + if (operand.kind !== 164 && operand.kind !== 162 && operand.kind !== 161 && operand.kind !== 160 && operand.kind !== 165 && operand.kind !== 154 && !(operand.kind === 153 && node.parent.kind === 154) && !(operand.kind === 158 && node.parent.kind === 153)) { emit(operand); return; } @@ -17781,6 +21760,19 @@ var ts; write(" "); emit(node.expression); } + function emitAwaitExpression(node) { + write(ts.tokenToString(122)); + write(" "); + emit(node.expression); + } + function emitYieldExpression(node) { + write(ts.tokenToString(109)); + emit(node.asteriskToken); + if (node.expression) { + write(" "); + emit(node.expression); + } + } function emitTypeOfExpression(node) { write(ts.tokenToString(96)); write(" "); @@ -17788,7 +21780,7 @@ var ts; } function emitPrefixUnaryExpression(node) { write(ts.tokenToString(node.operator)); - if (node.operand.kind === 161) { + if (node.operand.kind === 164) { var operand = node.operand; if (node.operator === 33 && (operand.operator === 33 || operand.operator === 38)) { write(" "); @@ -17804,17 +21796,16 @@ var ts; write(ts.tokenToString(node.operator)); } function emitBinaryExpression(node) { - if (languageVersion < 2 && node.operator === 52 && (node.left.kind === 148 || node.left.kind === 147)) { - emitDestructuring(node); + if (languageVersion < 2 && node.operator === 52 && (node.left.kind === 150 || node.left.kind === 149)) { + ensureLocals(); + node = ts.DestructuringAssignmentRewriter.rewrite(node, locals); } - else { - emit(node.left); - if (node.operator !== 23) - write(" "); - write(ts.tokenToString(node.operator)); + emit(node.left); + if (node.operator !== 23) write(" "); - emit(node.right); - } + write(ts.tokenToString(node.operator)); + write(" "); + emit(node.right); } function emitConditionalExpression(node) { emit(node.condition); @@ -17823,8 +21814,11 @@ var ts; write(" : "); emit(node.whenFalse); } + function emitGeneratedLabel(node) { + write(String(node.labelNumbers[node.label])); + } function isSingleLineBlock(node) { - if (node && node.kind === 170) { + if (node && node.kind === 174) { var block = node; return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block); } @@ -17839,12 +21833,12 @@ var ts; emitToken(14, node.pos); increaseIndent(); scopeEmitStart(node.parent); - if (node.kind === 196) { - ts.Debug.assert(node.parent.kind === 195); + if (node.kind === 200) { + ts.Debug.assert(node.parent.kind === 199); emitCaptureThisForNodeIfNecessary(node.parent); } emitLines(node.statements); - if (node.kind === 196) { + if (node.kind === 200) { emitTempDeclarations(true); } decreaseIndent(); @@ -17853,7 +21847,7 @@ var ts; scopeEmitEnd(); } function emitEmbeddedStatement(node) { - if (node.kind === 170) { + if (node.kind === 174) { write(" "); emit(node); } @@ -17865,7 +21859,7 @@ var ts; } } function emitExpressionStatement(node) { - emitParenthesized(node.expression, node.expression.kind === 157); + emitParenthesized(node.expression, node.expression.kind === 159); write(";"); } function emitIfStatement(node) { @@ -17878,7 +21872,7 @@ var ts; if (node.elseStatement) { writeLine(); emitToken(75, node.thenStatement.end); - if (node.elseStatement.kind === 174) { + if (node.elseStatement.kind === 178) { write(" "); emit(node.elseStatement); } @@ -17890,7 +21884,7 @@ var ts; function emitDoStatement(node) { write("do"); emitEmbeddedStatement(node.statement); - if (node.statement.kind === 170) { + if (node.statement.kind === 174) { write(" "); } else { @@ -17910,7 +21904,7 @@ var ts; var endPos = emitToken(81, node.pos); write(" "); endPos = emitToken(16, endPos); - if (node.initializer && node.initializer.kind === 189) { + if (node.initializer && node.initializer.kind === 193) { var variableDeclarationList = node.initializer; var declarations = variableDeclarationList.declarations; if (declarations[0] && ts.isLet(declarations[0])) { @@ -17939,7 +21933,7 @@ var ts; var endPos = emitToken(81, node.pos); write(" "); endPos = emitToken(16, endPos); - if (node.initializer.kind === 189) { + if (node.initializer.kind === 193) { var variableDeclarationList = node.initializer; if (variableDeclarationList.declarations.length >= 1) { var decl = variableDeclarationList.declarations[0]; @@ -17962,7 +21956,7 @@ var ts; emitEmbeddedStatement(node.statement); } function emitBreakOrContinueStatement(node) { - emitToken(node.kind === 180 ? 65 : 70, node.pos); + emitToken(node.kind === 184 ? 65 : 70, node.pos); emitOptional(" ", node.label); write(";"); } @@ -17998,7 +21992,7 @@ var ts; return getLineOfLocalPosition(currentSourceFile, node1.end) === getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); } function emitCaseOrDefaultClause(node) { - if (node.kind === 200) { + if (node.kind === 204) { write("case "); emit(node.expression); write(":"); @@ -18053,7 +22047,7 @@ var ts; function getContainingModule(node) { do { node = node.parent; - } while (node && node.kind !== 195); + } while (node && node.kind !== 199); return node; } function emitModuleMemberName(node) { @@ -18066,196 +22060,11 @@ var ts; emitNode(node.name); emitEnd(node.name); } - function emitDestructuring(root, value) { - var emitCount = 0; - var isDeclaration = (root.kind === 188 && !(ts.getCombinedNodeFlags(root) & 1)) || root.kind === 124; - if (root.kind === 163) { - emitAssignmentExpression(root); - } - else { - emitBindingElement(root, value); - } - function emitAssignment(name, value) { - if (emitCount++) { - write(", "); - } - if (name.parent && (name.parent.kind === 188 || name.parent.kind === 146)) { - emitModuleMemberName(name.parent); - } - else { - emit(name); - } - write(" = "); - emit(value); - } - function ensureIdentifier(expr) { - if (expr.kind !== 64) { - var identifier = createTempVariable(root); - if (!isDeclaration) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - expr = identifier; - } - return expr; - } - function createVoidZero() { - var zero = ts.createNode(7); - zero.text = "0"; - var result = ts.createNode(160); - result.expression = zero; - return result; - } - function createDefaultValueCheck(value, defaultValue) { - value = ensureIdentifier(value); - var equals = ts.createNode(163); - equals.left = value; - equals.operator = 30; - equals.right = createVoidZero(); - var cond = ts.createNode(164); - cond.condition = equals; - cond.whenTrue = defaultValue; - cond.whenFalse = value; - return cond; - } - function createNumericLiteral(value) { - var node = ts.createNode(7); - node.text = "" + value; - return node; - } - function parenthesizeForAccess(expr) { - if (expr.kind === 64 || expr.kind === 149 || expr.kind === 150) { - return expr; - } - var node = ts.createNode(155); - node.expression = expr; - return node; - } - function createPropertyAccess(object, propName) { - if (propName.kind !== 64) { - return createElementAccess(object, propName); - } - var node = ts.createNode(149); - node.expression = parenthesizeForAccess(object); - node.name = propName; - return node; - } - function createElementAccess(object, index) { - var node = ts.createNode(150); - node.expression = parenthesizeForAccess(object); - node.argumentExpression = index; - return node; - } - function emitObjectLiteralAssignment(target, value) { - var properties = target.properties; - if (properties.length !== 1) { - value = ensureIdentifier(value); - } - for (var i = 0; i < properties.length; i++) { - var p = properties[i]; - if (p.kind === 204 || p.kind === 205) { - var propName = (p.name); - emitDestructuringAssignment(p.initializer || propName, createPropertyAccess(value, propName)); - } - } - } - function emitArrayLiteralAssignment(target, value) { - var elements = target.elements; - if (elements.length !== 1) { - value = ensureIdentifier(value); - } - for (var i = 0; i < elements.length; i++) { - var e = elements[i]; - if (e.kind !== 168) { - if (e.kind !== 167) { - emitDestructuringAssignment(e, createElementAccess(value, createNumericLiteral(i))); - } - else { - if (i === elements.length - 1) { - value = ensureIdentifier(value); - emitAssignment(e.expression, value); - write(".slice(" + i + ")"); - } - } - } - } - } - function emitDestructuringAssignment(target, value) { - if (target.kind === 163 && target.operator === 52) { - value = createDefaultValueCheck(value, target.right); - target = target.left; - } - if (target.kind === 148) { - emitObjectLiteralAssignment(target, value); - } - else if (target.kind === 147) { - emitArrayLiteralAssignment(target, value); - } - else { - emitAssignment(target, value); - } - } - function emitAssignmentExpression(root) { - var target = root.left; - var value = root.right; - if (root.parent.kind === 173) { - emitDestructuringAssignment(target, value); - } - else { - if (root.parent.kind !== 155) { - write("("); - } - value = ensureIdentifier(value); - emitDestructuringAssignment(target, value); - write(", "); - emit(value); - if (root.parent.kind !== 155) { - write(")"); - } - } - } - function emitBindingElement(target, value) { - if (target.initializer) { - value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; - } - else if (!value) { - value = createVoidZero(); - } - if (ts.isBindingPattern(target.name)) { - var pattern = target.name; - var elements = pattern.elements; - if (elements.length !== 1) { - value = ensureIdentifier(value); - } - for (var i = 0; i < elements.length; i++) { - var element = elements[i]; - if (pattern.kind === 144) { - var propName = element.propertyName || element.name; - emitBindingElement(element, createPropertyAccess(value, propName)); - } - else if (element.kind !== 168) { - if (!element.dotDotDotToken) { - emitBindingElement(element, createElementAccess(value, createNumericLiteral(i))); - } - else { - if (i === elements.length - 1) { - value = ensureIdentifier(value); - emitAssignment(element.name, value); - write(".slice(" + i + ")"); - } - } - } - } - } - else { - emitAssignment(target.name, value); - } - } - } function emitVariableDeclaration(node) { if (ts.isBindingPattern(node.name)) { if (languageVersion < 2) { - emitDestructuring(node); + ensureLocals(); + emitCommaList(ts.BindingElementRewriter.rewrite(node, locals)); } else { emit(node.name); @@ -18285,7 +22094,8 @@ var ts; function emitParameter(node) { if (languageVersion < 2) { if (ts.isBindingPattern(node.name)) { - var name = createTempVariable(node); + ensureLocals(); + var name = ts.Locals.createUniqueIdentifier(locals); if (!tempParameters) { tempParameters = []; } @@ -18311,7 +22121,7 @@ var ts; if (ts.isBindingPattern(p.name)) { writeLine(); write("var "); - emitDestructuring(p, tempParameters[tempIndex]); + emitCommaList(ts.BindingElementRewriter.rewrite(p, locals, tempParameters[tempIndex])); write(";"); tempIndex++; } @@ -18335,9 +22145,10 @@ var ts; } function emitRestParameter(node) { if (languageVersion < 2 && ts.hasRestParameters(node)) { + ensureLocals(); var restIndex = node.parameters.length - 1; var restParam = node.parameters[restIndex]; - var tempName = createTempVariable(node, true).text; + var tempName = ts.Locals.createUniqueIdentifier(locals, "_i").text; writeLine(); emitLeadingComments(restParam); emitStart(restParam); @@ -18372,28 +22183,30 @@ var ts; } } function emitAccessor(node) { - write(node.kind === 130 ? "get " : "set "); + write(node.kind === 132 ? "get " : "set "); emit(node.name); emitSignatureAndBody(node); } function shouldEmitAsArrowFunction(node) { - return node.kind === 157 && languageVersion >= 2; + return node.kind === 159 && languageVersion >= 2; } function emitFunctionDeclaration(node) { if (ts.nodeIsMissing(node.body)) { return emitPinnedOrTripleSlashComments(node); } - if (node.kind !== 128 && node.kind !== 127) { + if (node.kind !== 130 && node.kind !== 129) { emitLeadingComments(node); } if (!shouldEmitAsArrowFunction(node)) { - write("function "); + write("function"); + emit(node.asteriskToken); + write(" "); } - if (node.kind === 190 || (node.kind === 156 && node.name)) { + if (node.kind === 194 || (node.kind === 158 && node.name)) { emit(node.name); } emitSignatureAndBody(node); - if (node.kind !== 128 && node.kind !== 127) { + if (node.kind !== 130 && node.kind !== 129) { emitTrailingComments(node); } } @@ -18405,6 +22218,14 @@ var ts; emitEnd(node); } } + function emitCaptureArgumentsForNodeIfNecessary(node) { + if (resolver.getNodeCheckFlags(node) & 16) { + writeLine(); + emitStart(node); + write("var _arguments = arguments;"); + emitEnd(node); + } + } function emitSignatureParameters(node) { increaseIndent(); write("("); @@ -18424,12 +22245,18 @@ var ts; emitSignatureParameters(node); } function emitSignatureAndBody(node) { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; + var saveLocals = locals; + var saveLocalsScope = localsScope; var saveTempParameters = tempParameters; - tempCount = 0; - tempVariables = undefined; + localsScope = node.body; + locals = undefined; tempParameters = undefined; + if (!ts.isAnyAccessor(node)) { + if (node.flags & 16384) { + ensureLocals(); + node = ts.AsyncFunctionRewriter.rewrite(node, resolver.getPromiseConstructor(node), locals, compilerOptions); + } + } if (shouldEmitAsArrowFunction(node)) { emitSignatureParametersForArrow(node); write(" =>"); @@ -18449,16 +22276,17 @@ var ts; } else { increaseIndent(); - emitDetachedComments(node.body.kind === 170 ? node.body.statements : node.body); + emitDetachedComments(node.body.kind === 174 ? node.body.statements : node.body); var startIndex = 0; - if (node.body.kind === 170) { + if (node.body.kind === 174) { startIndex = emitDirectivePrologues(node.body.statements, true); } var outPos = writer.getTextPos(); emitCaptureThisForNodeIfNecessary(node); + emitCaptureArgumentsForNodeIfNecessary(node); emitDefaultValueAssignments(node); emitRestParameter(node); - if (node.body.kind !== 170 && outPos === writer.getTextPos()) { + if (node.body.kind !== 174 && outPos === writer.getTextPos()) { decreaseIndent(); write(" "); emitStart(node.body); @@ -18473,7 +22301,7 @@ var ts; emitEnd(node.body); } else { - if (node.body.kind === 170) { + if (node.body.kind === 174) { emitLinesStartingAt(node.body.statements, startIndex); } else { @@ -18486,7 +22314,7 @@ var ts; } emitTempDeclarations(true); writeLine(); - if (node.body.kind === 170) { + if (node.body.kind === 174) { emitLeadingCommentsOfPosition(node.body.statements.end); decreaseIndent(); emitToken(15, node.body.statements.end); @@ -18510,16 +22338,16 @@ var ts; emitEnd(node); write(";"); } - tempCount = saveTempCount; - tempVariables = saveTempVariables; tempParameters = saveTempParameters; + locals = saveLocals; + localsScope = saveLocalsScope; } function findInitialSuperCall(ctor) { if (ctor.body) { var statement = ctor.body.statements[0]; - if (statement && statement.kind === 173) { + if (statement && statement.kind === 177) { var expr = statement.expression; - if (expr && expr.kind === 151) { + if (expr && expr.kind === 153) { var func = expr.expression; if (func && func.kind === 90) { return statement; @@ -18550,7 +22378,7 @@ var ts; emitNode(memberName); write("]"); } - else if (memberName.kind === 122) { + else if (memberName.kind === 124) { emitComputedPropertyName(memberName); } else { @@ -18560,7 +22388,7 @@ var ts; } function emitMemberAssignments(node, staticFlag) { ts.forEach(node.members, function (member) { - if (member.kind === 126 && (member.flags & 128) === staticFlag && member.initializer) { + if (member.kind === 128 && (member.flags & 128) === staticFlag && member.initializer) { writeLine(); emitLeadingComments(member); emitStart(member); @@ -18583,7 +22411,7 @@ var ts; } function emitMemberFunctions(node) { ts.forEach(node.members, function (member) { - if (member.kind === 128 || node.kind === 127) { + if (member.kind === 130 || node.kind === 129) { if (!member.body) { return emitPinnedOrTripleSlashComments(member); } @@ -18605,7 +22433,7 @@ var ts; write(";"); emitTrailingComments(member); } - else if (member.kind === 130 || member.kind === 131) { + else if (member.kind === 132 || member.kind === 133) { var accessors = getAllAccessorDeclarations(node, member); if (member === accessors.firstAccessor) { writeLine(); @@ -18706,14 +22534,14 @@ var ts; write(";"); } function emitConstructorOfClass() { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; + var saveLocals = locals; + var saveLocalsScope = localsScope; var saveTempParameters = tempParameters; - tempCount = 0; - tempVariables = undefined; + locals = undefined; + localsScope = node; tempParameters = undefined; ts.forEach(node.members, function (member) { - if (member.kind === 129 && !member.body) { + if (member.kind === 131 && !member.body) { emitPinnedOrTripleSlashComments(member); } }); @@ -18733,6 +22561,7 @@ var ts; } emitCaptureThisForNodeIfNecessary(node); if (ctor) { + localsScope = ctor.body; emitDefaultValueAssignments(ctor); emitRestParameter(ctor); if (baseTypeNode) { @@ -18743,6 +22572,7 @@ var ts; } } emitParameterPropertyAssignments(ctor); + localsScope = node; } else { if (baseTypeNode) { @@ -18771,9 +22601,9 @@ var ts; if (ctor) { emitTrailingComments(ctor); } - tempCount = saveTempCount; - tempVariables = saveTempVariables; tempParameters = saveTempParameters; + locals = saveLocals; + localsScope = saveLocalsScope; } } function emitInterfaceDeclaration(node) { @@ -18856,7 +22686,7 @@ var ts; } } function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { - if (moduleDeclaration.body.kind === 195) { + if (moduleDeclaration.body.kind === 199) { var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); return recursiveInnerModule || moduleDeclaration.body; } @@ -18881,20 +22711,21 @@ var ts; write(resolver.getLocalNameOfContainer(node)); emitEnd(node.name); write(") "); - if (node.body.kind === 196) { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - tempCount = 0; - tempVariables = undefined; + if (node.body.kind === 200) { + var saveLocals = locals; + var saveLocalsScope = localsScope; + locals = undefined; + localsScope = node.body; emit(node.body); - tempCount = saveTempCount; - tempVariables = saveTempVariables; + locals = saveLocals; + localsScope = saveLocalsScope; } else { write("{"); increaseIndent(); scopeEmitStart(node); emitCaptureThisForNodeIfNecessary(node); + emitCaptureArgumentsForNodeIfNecessary(node); writeLine(); emit(node.body); decreaseIndent(); @@ -18920,7 +22751,7 @@ var ts; emitImportDeclaration = !ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportWithEntityName(node); } if (emitImportDeclaration) { - if (ts.isExternalModuleImportDeclaration(node) && node.parent.kind === 207 && compilerOptions.module === 2) { + if (ts.isExternalModuleImportDeclaration(node) && node.parent.kind === 211 && compilerOptions.module === 2) { if (node.flags & 1) { writeLine(); emitLeadingComments(node); @@ -18969,7 +22800,7 @@ var ts; } function getFirstExportAssignment(sourceFile) { return ts.forEach(sourceFile.statements, function (node) { - if (node.kind === 198) { + if (node.kind === 202) { return node; } }); @@ -19066,30 +22897,270 @@ var ts; return i; } } - return statements.length; - } - function emitSourceFile(node) { - currentSourceFile = node; - writeLine(); - emitDetachedComments(node); - var startIndex = emitDirectivePrologues(node.statements, false); - if (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8) { - writeLine(); - write("var __extends = this.__extends || function (d, b) {"); - increaseIndent(); - writeLine(); - write("for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];"); - writeLine(); - write("function __() { this.constructor = d; }"); - writeLine(); - write("__.prototype = b.prototype;"); - writeLine(); - write("d.prototype = new __();"); - decreaseIndent(); - writeLine(); - write("};"); - extendsEmitted = true; - } + return statements.length; + } + function emitSourceFile(node) { + currentSourceFile = node; + globals = undefined; + localsScope = node; + locals = undefined; + writeLine(); + emitDetachedComments(node); + var startIndex = emitDirectivePrologues(node.statements, false); + if (!compilerOptions.noHelpers) { + if (!extendsEmitted && resolver.getNodeCheckFlags(node) & 32) { + writeLine(); + write("var __extends = this.__extends || function (d, b) {"); + increaseIndent(); + writeLine(); + write("for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];"); + writeLine(); + write("function __() { this.constructor = d; }"); + writeLine(); + write("__.prototype = b.prototype;"); + writeLine(); + write("d.prototype = new __();"); + decreaseIndent(); + writeLine(); + write("};"); + extendsEmitted = true; + } + if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & 2048) { + writeLine(); + write("var __awaiter = this.__awaiter || function (gen) {"); + increaseIndent(); + writeLine(); + write("function step(result) {"); + increaseIndent(); + writeLine(); + write("while (true) {"); + increaseIndent(); + writeLine(); + write("var done = result.done, value = result.value, then;"); + writeLine(); + write("if (done) return value;"); + writeLine(); + write("if (value && typeof (then = value.then) === \"function\")"); + increaseIndent(); + writeLine(); + write("return then.call(value,"); + increaseIndent(); + writeLine(); + write("function(value) { return step(gen.next(value)) },"); + writeLine(); + write("function(reason) { return step(gen[\"throw\"](reason)) });"); + decreaseIndent(); + decreaseIndent(); + writeLine(); + write("result = gen.next(value);"); + decreaseIndent(); + writeLine(); + write("}"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("return step(gen.next());"); + decreaseIndent(); + writeLine(); + write("};"); + awaiterEmitted = true; + } + if (!generatorEmitted && resolver.getNodeCheckFlags(node) & 4096) { + writeLine(); + write("var __generator = this.__generator || function (body) {"); + increaseIndent(); + writeLine(); + write("var done, finallyStack, executing, state;"); + writeLine(); + write("function step(opcode, arg) {"); + increaseIndent(); + writeLine(); + write("var trys, region, tryLabel, catchLabel, finallyLabel, endLabel;"); + writeLine(); + write("if (executing) throw new TypeError(\"Generator is already executing.\");"); + writeLine(); + write("state = state || { label: 0 };"); + writeLine(); + write("while (true) {"); + increaseIndent(); + writeLine(); + write("executing = false;"); + writeLine(); + write("if (!done) {"); + increaseIndent(); + writeLine(); + write("trys = state.trys;"); + writeLine(); + write("region = trys && trys[trys.length - 1];"); + writeLine(); + write("if (region) {"); + increaseIndent(); + writeLine(); + write("tryLabel = region[0];"); + writeLine(); + write("catchLabel = region[1];"); + writeLine(); + write("finallyLabel = region[2];"); + writeLine(); + write("endLabel = region[3];"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("else if (opcode === 1 || opcode === 2) {"); + increaseIndent(); + writeLine(); + write("done = true;"); + decreaseIndent(); + writeLine(); + write("}"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("if (done) {"); + increaseIndent(); + writeLine(); + write("finallyStack = void 0;"); + writeLine(); + write("switch (opcode) {"); + increaseIndent(); + writeLine(); + write("case 0 /*next*/: return { value: void 0, done: true };"); + writeLine(); + write("case 1 /*throw*/: throw arg;"); + writeLine(); + write("case 2 /*return*/: return { value: arg, done: true };"); + decreaseIndent(); + writeLine(); + write("}"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("switch (opcode) {"); + increaseIndent(); + writeLine(); + write("case 0 /*next*/:"); + increaseIndent(); + writeLine(); + write("state.sent = arg;"); + writeLine(); + write("break;"); + decreaseIndent(); + writeLine(); + write("case 4 /*yield*/:"); + increaseIndent(); + writeLine(); + write("state.label++;"); + writeLine(); + write("return { value: arg, done: false };"); + decreaseIndent(); + writeLine(); + write("case 5 /*endfinally*/:"); + increaseIndent(); + writeLine(); + write("arg = finallyStack.pop(), opcode = finallyStack.pop();"); + writeLine(); + write("trys.pop();"); + writeLine(); + write("continue;"); + decreaseIndent(); + writeLine(); + write("default:"); + increaseIndent(); + writeLine(); + write("if (opcode === 3 /*break*/ && (!region || (arg > tryLabel && arg < endLabel))) {"); + increaseIndent(); + writeLine(); + write("state.label = arg;"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("else if (opcode === 1 /*throw*/ && state.label < catchLabel) {"); + increaseIndent(); + writeLine(); + write("state.error = arg;"); + writeLine(); + write("state.label = catchLabel;"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("else if (state.label < finallyLabel) {"); + increaseIndent(); + writeLine(); + write("finallyStack = finallyStack || [];"); + writeLine(); + write("finallyStack.push(opcode, arg);"); + writeLine(); + write("state.label = finallyLabel;"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("else {"); + increaseIndent(); + writeLine(); + write("if (finallyLabel) finallyStack.pop(), finallyStack.pop();"); + writeLine(); + write("trys.pop();"); + writeLine(); + write("continue;"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("break;"); + decreaseIndent(); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("executing = true;"); + writeLine(); + write("try {"); + increaseIndent(); + writeLine(); + write("var operation = body(state);"); + writeLine(); + write("opcode = operation[0], arg = operation[1];"); + decreaseIndent(); + writeLine(); + write("} catch (e) {"); + increaseIndent(); + writeLine(); + write("opcode = 1 /*throw*/, arg = e;"); + writeLine(); + decreaseIndent(); + write("}"); + decreaseIndent(); + writeLine(); + write("}"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("return {"); + increaseIndent(); + writeLine(); + write("next: function (v) { return step(0 /*next*/, v); },"); + writeLine(); + write("\"throw\": function (v) { return step(1 /*throw*/, v); },"); + writeLine(); + write("\"return\": function (v) { return step(2 /*return*/, v); },"); + decreaseIndent(); + writeLine(); + write("};"); + decreaseIndent(); + writeLine(); + write("};"); + writeLine(); + generatorEmitted = true; + } + } if (ts.isExternalModule(node)) { if (compilerOptions.module === 2) { emitAMDModule(node, startIndex); @@ -19123,15 +23194,15 @@ var ts; } function shouldEmitLeadingAndTrailingComments(node) { switch (node.kind) { - case 192: - case 190: + case 196: + case 194: + case 201: case 197: - case 193: - case 198: + case 202: return false; - case 195: + case 199: return shouldEmitModuleDeclaration(node); - case 194: + case 198: return shouldEmitEnumDeclaration(node); } return true; @@ -19140,13 +23211,13 @@ var ts; switch (node.kind) { case 64: return emitIdentifier(node); - case 124: + case 126: return emitParameter(node); - case 128: - case 127: - return emitMethod(node); case 130: - case 131: + case 129: + return emitMethod(node); + case 132: + case 133: return emitAccessor(node); case 92: return emitThis(node); @@ -19158,6 +23229,8 @@ var ts; return write("true"); case 79: return write("false"); + case 35: + return write("*"); case 7: case 8: case 9: @@ -19166,120 +23239,126 @@ var ts; case 12: case 13: return emitLiteral(node); - case 165: + case 168: return emitTemplateExpression(node); - case 169: + case 173: return emitTemplateSpan(node); - case 121: + case 123: return emitQualifiedName(node); - case 144: + case 146: return emitObjectBindingPattern(node); - case 145: + case 147: return emitArrayBindingPattern(node); - case 146: + case 148: return emitBindingElement(node); - case 147: + case 149: return emitArrayLiteral(node); - case 148: + case 150: return emitObjectLiteral(node); - case 204: + case 208: return emitPropertyAssignment(node); - case 205: + case 209: return emitShorthandPropertyAssignment(node); - case 122: + case 124: return emitComputedPropertyName(node); - case 149: - return emitPropertyAccess(node); - case 150: - return emitIndexedAccess(node); case 151: - return emitCallExpression(node); + return emitPropertyAccess(node); case 152: - return emitNewExpression(node); + return emitIndexedAccess(node); case 153: - return emitTaggedTemplateExpression(node); + return emitCallExpression(node); case 154: - return emit(node.expression); + return emitNewExpression(node); case 155: - return emitParenExpression(node); - case 190: + return emitTaggedTemplateExpression(node); case 156: + return emit(node.expression); case 157: - return emitFunctionDeclaration(node); + return emitParenExpression(node); + case 194: case 158: - return emitDeleteExpression(node); case 159: - return emitTypeOfExpression(node); + return emitFunctionDeclaration(node); case 160: - return emitVoidExpression(node); + return emitDeleteExpression(node); case 161: - return emitPrefixUnaryExpression(node); + return emitTypeOfExpression(node); case 162: - return emitPostfixUnaryExpression(node); + return emitVoidExpression(node); case 163: - return emitBinaryExpression(node); + return emitAwaitExpression(node); + case 169: + return emitYieldExpression(node); case 164: - return emitConditionalExpression(node); + return emitPrefixUnaryExpression(node); + case 165: + return emitPostfixUnaryExpression(node); + case 166: + return emitBinaryExpression(node); case 167: + return emitConditionalExpression(node); + case 170: + return emitGeneratedLabel(node); + case 171: return emitSpreadElementExpression(node); - case 168: + case 172: return; - case 170: - case 196: + case 174: + case 200: return emitBlock(node); - case 171: + case 175: return emitVariableStatement(node); - case 172: + case 176: return write(";"); - case 173: + case 177: return emitExpressionStatement(node); - case 174: + case 178: return emitIfStatement(node); - case 175: + case 179: return emitDoStatement(node); - case 176: + case 180: return emitWhileStatement(node); - case 177: + case 181: return emitForStatement(node); - case 178: + case 182: return emitForInStatement(node); - case 179: - case 180: + case 183: + case 184: return emitBreakOrContinueStatement(node); - case 181: + case 185: return emitReturnStatement(node); - case 182: + case 186: return emitWithStatement(node); - case 183: + case 187: return emitSwitchStatement(node); - case 200: - case 201: + case 204: + case 205: return emitCaseOrDefaultClause(node); - case 184: + case 188: return emitLabelledStatement(node); - case 185: + case 189: return emitThrowStatement(node); - case 186: + case 190: return emitTryStatement(node); - case 203: + case 207: return emitCatchClause(node); - case 187: + case 191: return emitDebuggerStatement(node); - case 188: + case 192: return emitVariableDeclaration(node); - case 191: + case 195: return emitClassDeclaration(node); - case 192: + case 196: return emitInterfaceDeclaration(node); - case 194: + case 198: return emitEnumDeclaration(node); - case 206: + case 210: return emitEnumMember(node); - case 195: + case 199: return emitModuleDeclaration(node); - case 197: + case 201: return emitImportDeclaration(node); - case 207: + case 211: return emitSourceFile(node); } } @@ -19298,7 +23377,7 @@ var ts; } function getLeadingCommentsToEmit(node) { if (node.parent) { - if (node.parent.kind === 207 || node.pos !== node.parent.pos) { + if (node.pos >= 0 && (node.parent.kind === 211 || node.pos !== node.parent.pos)) { var leadingComments; if (hasDetachedComments(node.pos)) { leadingComments = getLeadingCommentsWithoutDetachedComments(); @@ -19317,13 +23396,16 @@ var ts; } function emitTrailingDeclarationComments(node) { if (node.parent) { - if (node.parent.kind === 207 || node.end !== node.parent.end) { + if (node.pos >= 0 && (node.parent.kind === 211 || node.end !== node.parent.end)) { var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); } } } function emitLeadingCommentsOfLocalPosition(pos) { + if (pos < 0) { + return; + } var leadingComments; if (hasDetachedComments(pos)) { leadingComments = getLeadingCommentsWithoutDetachedComments(); @@ -19335,6 +23417,9 @@ var ts; emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); } function emitDetachedCommentsAtPosition(node) { + if (node.pos === node.end) { + return; + } var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); if (leadingComments) { var detachedComments = []; @@ -19712,7 +23797,7 @@ var ts; } } } - else if (node.kind === 195 && node.name.kind === 8 && (node.flags & 2 || ts.isDeclarationFile(file))) { + else if (node.kind === 199 && node.name.kind === 8 && (node.flags & 2 || ts.isDeclarationFile(file))) { ts.forEachChild(node.body, function (node) { if (ts.isExternalModuleImportDeclaration(node) && ts.getExternalModuleImportDeclarationExpression(node).kind === 8) { var nameLiteral = ts.getExternalModuleImportDeclarationExpression(node); @@ -19876,6 +23961,12 @@ var ts; name: "noResolve", type: "boolean" }, + { + name: "noHelpers", + type: "boolean", + description: ts.Diagnostics.Do_not_emit_runtime_helper_functions_e_g_extends_awaiter_Assumes_manual_reference_to_tslib_js, + experimental: true + }, { name: "out", type: "string", @@ -19938,6 +24029,12 @@ var ts; paramType: ts.Diagnostics.VERSION, error: ts.Diagnostics.Argument_for_target_option_must_be_es3_es5_or_es6 }, + { + name: "asyncFunctions", + type: "boolean", + experimental: true, + description: ts.Diagnostics.Emit_async_functions_when_ECMAScript_target_version_is_lower_than_ES6 + }, { name: "version", shortName: "v", @@ -20390,7 +24487,7 @@ var ts; var start = new Date().getTime(); var program = ts.createProgram(fileNames, compilerOptions, compilerHost); var exitStatus = compileProgram(); - var end = start - new Date().getTime(); + var end = new Date().getTime() - start; if (compilerOptions.listFiles) { ts.forEach(program.getSourceFiles(), function (file) { ts.sys.write(file.fileName + ts.sys.newLine); @@ -20411,7 +24508,7 @@ var ts; reportTimeStatistic("Bind time", ts.bindTime); reportTimeStatistic("Check time", ts.checkTime); reportTimeStatistic("Emit time", ts.emitTime); - reportTimeStatistic("Total time", start - end); + reportTimeStatistic("Total time", end); } return { program: program, exitStatus: exitStatus }; function compileProgram() { diff --git a/bin/tslib.d.ts b/bin/tslib.d.ts new file mode 100644 index 0000000000000..d60573fa4d50e --- /dev/null +++ b/bin/tslib.d.ts @@ -0,0 +1,18 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +export function __extends(b: any, d: any): void; +export function __awaiter(generator: any): any; +export function __generator(body: any): any; \ No newline at end of file diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 7c97542d8afc5..443461a48abea 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -143,109 +143,113 @@ declare module "typescript" { SetKeyword = 118, StringKeyword = 119, TypeKeyword = 120, - QualifiedName = 121, - ComputedPropertyName = 122, - TypeParameter = 123, - Parameter = 124, - PropertySignature = 125, - PropertyDeclaration = 126, - MethodSignature = 127, - MethodDeclaration = 128, - Constructor = 129, - GetAccessor = 130, - SetAccessor = 131, - CallSignature = 132, - ConstructSignature = 133, - IndexSignature = 134, - TypeReference = 135, - FunctionType = 136, - ConstructorType = 137, - TypeQuery = 138, - TypeLiteral = 139, - ArrayType = 140, - TupleType = 141, - UnionType = 142, - ParenthesizedType = 143, - ObjectBindingPattern = 144, - ArrayBindingPattern = 145, - BindingElement = 146, - ArrayLiteralExpression = 147, - ObjectLiteralExpression = 148, - PropertyAccessExpression = 149, - ElementAccessExpression = 150, - CallExpression = 151, - NewExpression = 152, - TaggedTemplateExpression = 153, - TypeAssertionExpression = 154, - ParenthesizedExpression = 155, - FunctionExpression = 156, - ArrowFunction = 157, - DeleteExpression = 158, - TypeOfExpression = 159, - VoidExpression = 160, - PrefixUnaryExpression = 161, - PostfixUnaryExpression = 162, - BinaryExpression = 163, - ConditionalExpression = 164, - TemplateExpression = 165, - YieldExpression = 166, - SpreadElementExpression = 167, - OmittedExpression = 168, - TemplateSpan = 169, - Block = 170, - VariableStatement = 171, - EmptyStatement = 172, - ExpressionStatement = 173, - IfStatement = 174, - DoStatement = 175, - WhileStatement = 176, - ForStatement = 177, - ForInStatement = 178, - ContinueStatement = 179, - BreakStatement = 180, - ReturnStatement = 181, - WithStatement = 182, - SwitchStatement = 183, - LabeledStatement = 184, - ThrowStatement = 185, - TryStatement = 186, - DebuggerStatement = 187, - VariableDeclaration = 188, - VariableDeclarationList = 189, - FunctionDeclaration = 190, - ClassDeclaration = 191, - InterfaceDeclaration = 192, - TypeAliasDeclaration = 193, - EnumDeclaration = 194, - ModuleDeclaration = 195, - ModuleBlock = 196, - ImportDeclaration = 197, - ExportAssignment = 198, - ExternalModuleReference = 199, - CaseClause = 200, - DefaultClause = 201, - HeritageClause = 202, - CatchClause = 203, - PropertyAssignment = 204, - ShorthandPropertyAssignment = 205, - EnumMember = 206, - SourceFile = 207, - SyntaxList = 208, - Count = 209, + AsyncKeyword = 121, + AwaitKeyword = 122, + QualifiedName = 123, + ComputedPropertyName = 124, + TypeParameter = 125, + Parameter = 126, + PropertySignature = 127, + PropertyDeclaration = 128, + MethodSignature = 129, + MethodDeclaration = 130, + Constructor = 131, + GetAccessor = 132, + SetAccessor = 133, + CallSignature = 134, + ConstructSignature = 135, + IndexSignature = 136, + TypeReference = 137, + FunctionType = 138, + ConstructorType = 139, + TypeQuery = 140, + TypeLiteral = 141, + ArrayType = 142, + TupleType = 143, + UnionType = 144, + ParenthesizedType = 145, + ObjectBindingPattern = 146, + ArrayBindingPattern = 147, + BindingElement = 148, + ArrayLiteralExpression = 149, + ObjectLiteralExpression = 150, + PropertyAccessExpression = 151, + ElementAccessExpression = 152, + CallExpression = 153, + NewExpression = 154, + TaggedTemplateExpression = 155, + TypeAssertionExpression = 156, + ParenthesizedExpression = 157, + FunctionExpression = 158, + ArrowFunction = 159, + DeleteExpression = 160, + TypeOfExpression = 161, + VoidExpression = 162, + AwaitExpression = 163, + PrefixUnaryExpression = 164, + PostfixUnaryExpression = 165, + BinaryExpression = 166, + ConditionalExpression = 167, + TemplateExpression = 168, + YieldExpression = 169, + GeneratedLabel = 170, + SpreadElementExpression = 171, + OmittedExpression = 172, + TemplateSpan = 173, + Block = 174, + VariableStatement = 175, + EmptyStatement = 176, + ExpressionStatement = 177, + IfStatement = 178, + DoStatement = 179, + WhileStatement = 180, + ForStatement = 181, + ForInStatement = 182, + ContinueStatement = 183, + BreakStatement = 184, + ReturnStatement = 185, + WithStatement = 186, + SwitchStatement = 187, + LabeledStatement = 188, + ThrowStatement = 189, + TryStatement = 190, + DebuggerStatement = 191, + VariableDeclaration = 192, + VariableDeclarationList = 193, + FunctionDeclaration = 194, + ClassDeclaration = 195, + InterfaceDeclaration = 196, + TypeAliasDeclaration = 197, + EnumDeclaration = 198, + ModuleDeclaration = 199, + ModuleBlock = 200, + ImportDeclaration = 201, + ExportAssignment = 202, + ExternalModuleReference = 203, + CaseClause = 204, + DefaultClause = 205, + HeritageClause = 206, + CatchClause = 207, + PropertyAssignment = 208, + ShorthandPropertyAssignment = 209, + EnumMember = 210, + SourceFile = 211, + SyntaxList = 212, + Count = 213, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, LastReservedWord = 100, FirstKeyword = 65, - LastKeyword = 120, + LastKeyword = 122, FirstFutureReservedWord = 101, LastFutureReservedWord = 109, - FirstTypeNode = 135, - LastTypeNode = 143, + FirstTypeNode = 137, + LastTypeNode = 145, FirstPunctuation = 14, LastPunctuation = 63, FirstToken = 0, - LastToken = 120, + LastToken = 122, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -254,7 +258,7 @@ declare module "typescript" { LastTemplateToken = 13, FirstBinaryOperator = 24, LastBinaryOperator = 63, - FirstNode = 121, + FirstNode = 123, } const enum NodeFlags { Export = 1, @@ -269,19 +273,25 @@ declare module "typescript" { Let = 2048, Const = 4096, OctalLiteral = 8192, - Modifier = 243, + Async = 16384, + Modifier = 16627, AccessibilityModifier = 112, BlockScoped = 6144, } const enum ParserContextFlags { + None = 0, StrictMode = 1, DisallowIn = 2, Yield = 4, GeneratorParameter = 8, ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + AsyncParameter = 32, + Await = 64, + ParserGeneratedFlags = 127, + ContextParameterFlags = 108, + ThisNodeOrAnySubNodesHasError = 128, + ThisNodeOrAnySubNodesHasAwaitOrYield = 256, + HasAggregatedChildData = 512, } const enum RelationComparisonResult { Succeeded = 1, @@ -481,6 +491,9 @@ declare module "typescript" { interface VoidExpression extends UnaryExpression { expression: UnaryExpression; } + interface AwaitExpression extends UnaryExpression { + expression: UnaryExpression; + } interface YieldExpression extends Expression { asteriskToken?: Node; expression: Expression; @@ -675,6 +688,10 @@ declare module "typescript" { interface ExportAssignment extends Statement, ModuleElement { exportName: Identifier; } + interface GeneratedLabel extends Expression { + label: Label; + labelNumbers?: number[]; + } interface FileReference extends TextRange { fileName: string; } @@ -725,13 +742,96 @@ declare module "typescript" { getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; } + enum OpCode { + Nop = 0, + Statement = 1, + Assign = 2, + Break = 3, + BreakWhenTrue = 4, + BreakWhenFalse = 5, + Yield = 6, + Return = 7, + Throw = 8, + Endfinally = 9, + } + type Label = number; + interface Locals { + resolver: EmitResolver; + context: Node; + tempCount: number; + globals?: Map; + variables?: Identifier[]; + } + enum BlockAction { + Open = 0, + Close = 1, + } + enum BlockKind { + Exception = 0, + ScriptBreak = 1, + Break = 2, + ScriptContinue = 3, + Continue = 4, + With = 5, + } + enum ExceptionBlockState { + Try = 0, + Catch = 1, + Finally = 2, + Done = 3, + } + interface BlockScope { + kind: BlockKind; + } + interface ExceptionBlock extends BlockScope { + state: ExceptionBlockState; + startLabel: Label; + catchVariable?: Identifier; + catchLabel?: Label; + finallyLabel?: Label; + endLabel: Label; + } + interface BreakBlock extends BlockScope { + breakLabel: Label; + labelText?: string[]; + requireLabel?: boolean; + } + interface ContinueBlock extends BreakBlock { + continueLabel: Label; + } + interface WithBlock extends BlockScope { + expression: Identifier; + startLabel: Label; + endLabel: Label; + } + enum FunctionBuilderFlags { + HasProtectedRegions = 1, + } + interface GeneratorFunctionBuilder { + locals: Locals; + flags: FunctionBuilderFlags; + pendingLocation?: TextRange; + parameters?: ParameterDeclaration[]; + functions?: FunctionDeclaration[]; + blocks?: BlockScope[]; + blockStack?: BlockScope[]; + blockActions?: BlockAction[]; + blockOffsets?: number[]; + nextLabelId: number; + labelNumbers?: number[]; + labels?: number[]; + operations?: OpCode[]; + operationArguments?: any[][]; + operationLocations?: TextRange[]; + state?: Identifier; + } interface SourceMapSpan { emittedLine: number; emittedColumn: number; - sourceLine: number; - sourceColumn: number; + sourceLine?: number; + sourceColumn?: number; nameIndex?: number; - sourceIndex: number; + sourceIndex?: number; } interface SourceMapData { sourceMapFilePath: string; @@ -857,6 +957,9 @@ declare module "typescript" { isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + renameSymbol(symbol: Symbol, name: string): void; + getRenamedIdentifier(name: Identifier): string; + getPromiseConstructor(node: SignatureDeclaration): EntityName; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -954,14 +1057,20 @@ declare module "typescript" { TypeChecked = 1, LexicalThis = 2, CaptureThis = 4, - EmitExtends = 8, - SuperInstance = 16, - SuperStatic = 32, - ContextChecked = 64, - EnumValuesComputed = 128, + LexicalArguments = 8, + CaptureArguments = 16, + EmitExtends = 32, + SuperInstance = 64, + SuperStatic = 128, + ContextChecked = 256, + PromiseCollision = 512, + EnumValuesComputed = 1024, + EmitAwaiter = 2048, + EmitGenerator = 4096, } interface NodeLinks { resolvedType?: Type; + resolvedAwaitedType?: Type; resolvedSignature?: Signature; resolvedSymbol?: Symbol; flags?: NodeCheckFlags; @@ -1129,6 +1238,7 @@ declare module "typescript" { noImplicitAny?: boolean; noLib?: boolean; noLibCheck?: boolean; + noHelpers?: boolean; noResolve?: boolean; out?: string; outDir?: string; @@ -1142,6 +1252,7 @@ declare module "typescript" { version?: boolean; watch?: boolean; stripInternal?: boolean; + asyncFunctions?: boolean; [option: string]: string | number | boolean; } const enum ModuleKind { @@ -1373,7 +1484,7 @@ declare module "typescript" { function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; function isEvalOrArgumentsIdentifier(node: Node): boolean; function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile; - function isLeftHandSideExpression(expr: Expression): boolean; + function isLeftHandSideExpression(expr: Node): boolean; function isAssignmentOperator(token: SyntaxKind): boolean; } declare module "typescript" { @@ -1704,6 +1815,9 @@ declare module "typescript" { InMultiLineCommentTrivia = 1, InSingleQuoteStringLiteral = 2, InDoubleQuoteStringLiteral = 3, + InTemplateHeadOrNoSubstitutionTemplate = 4, + InTemplateMiddleOrTail = 5, + InTemplateSubstitutionPosition = 6, } enum TokenClass { Punctuation = 0, @@ -1725,7 +1839,26 @@ declare module "typescript" { classification: TokenClass; } interface Classifier { - getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult; + /** + * Gives lexical classifications of tokens on a line without any syntactic context. + * For instance, a token consisting of the text 'string' can be either an identifier + * named 'string' or the keyword 'string', however, because this classifier is not aware, + * it relies on certain heuristics to give acceptable results. For classifications where + * speed trumps accuracy, this function is preferable; however, for true accuracy, the + * syntactic classifier is ideal. In fact, in certain editing scenarios, combining the + * lexical, syntactic, and semantic classifiers may issue the best user experience. + * + * @param text The text of a line to classify. + * @param lexState The state of the lexical classifier at the end of the previous line. + * @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier. + * If there is no syntactic classifier (syntacticClassifierAbsent=true), + * certain heuristics may be used in its place; however, if there is a + * syntactic classifier (syntacticClassifierAbsent=false), certain + * classifications which may be incorrectly categorized will be given + * back as Identifiers in order to allow the syntactic classifier to + * subsume the classification. + */ + getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult; } /** * The document registry represents a store of SourceFile objects that can be shared between diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index 38a7d43c861a4..8592cd7ba992f 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -143,109 +143,113 @@ declare module ts { SetKeyword = 118, StringKeyword = 119, TypeKeyword = 120, - QualifiedName = 121, - ComputedPropertyName = 122, - TypeParameter = 123, - Parameter = 124, - PropertySignature = 125, - PropertyDeclaration = 126, - MethodSignature = 127, - MethodDeclaration = 128, - Constructor = 129, - GetAccessor = 130, - SetAccessor = 131, - CallSignature = 132, - ConstructSignature = 133, - IndexSignature = 134, - TypeReference = 135, - FunctionType = 136, - ConstructorType = 137, - TypeQuery = 138, - TypeLiteral = 139, - ArrayType = 140, - TupleType = 141, - UnionType = 142, - ParenthesizedType = 143, - ObjectBindingPattern = 144, - ArrayBindingPattern = 145, - BindingElement = 146, - ArrayLiteralExpression = 147, - ObjectLiteralExpression = 148, - PropertyAccessExpression = 149, - ElementAccessExpression = 150, - CallExpression = 151, - NewExpression = 152, - TaggedTemplateExpression = 153, - TypeAssertionExpression = 154, - ParenthesizedExpression = 155, - FunctionExpression = 156, - ArrowFunction = 157, - DeleteExpression = 158, - TypeOfExpression = 159, - VoidExpression = 160, - PrefixUnaryExpression = 161, - PostfixUnaryExpression = 162, - BinaryExpression = 163, - ConditionalExpression = 164, - TemplateExpression = 165, - YieldExpression = 166, - SpreadElementExpression = 167, - OmittedExpression = 168, - TemplateSpan = 169, - Block = 170, - VariableStatement = 171, - EmptyStatement = 172, - ExpressionStatement = 173, - IfStatement = 174, - DoStatement = 175, - WhileStatement = 176, - ForStatement = 177, - ForInStatement = 178, - ContinueStatement = 179, - BreakStatement = 180, - ReturnStatement = 181, - WithStatement = 182, - SwitchStatement = 183, - LabeledStatement = 184, - ThrowStatement = 185, - TryStatement = 186, - DebuggerStatement = 187, - VariableDeclaration = 188, - VariableDeclarationList = 189, - FunctionDeclaration = 190, - ClassDeclaration = 191, - InterfaceDeclaration = 192, - TypeAliasDeclaration = 193, - EnumDeclaration = 194, - ModuleDeclaration = 195, - ModuleBlock = 196, - ImportDeclaration = 197, - ExportAssignment = 198, - ExternalModuleReference = 199, - CaseClause = 200, - DefaultClause = 201, - HeritageClause = 202, - CatchClause = 203, - PropertyAssignment = 204, - ShorthandPropertyAssignment = 205, - EnumMember = 206, - SourceFile = 207, - SyntaxList = 208, - Count = 209, + AsyncKeyword = 121, + AwaitKeyword = 122, + QualifiedName = 123, + ComputedPropertyName = 124, + TypeParameter = 125, + Parameter = 126, + PropertySignature = 127, + PropertyDeclaration = 128, + MethodSignature = 129, + MethodDeclaration = 130, + Constructor = 131, + GetAccessor = 132, + SetAccessor = 133, + CallSignature = 134, + ConstructSignature = 135, + IndexSignature = 136, + TypeReference = 137, + FunctionType = 138, + ConstructorType = 139, + TypeQuery = 140, + TypeLiteral = 141, + ArrayType = 142, + TupleType = 143, + UnionType = 144, + ParenthesizedType = 145, + ObjectBindingPattern = 146, + ArrayBindingPattern = 147, + BindingElement = 148, + ArrayLiteralExpression = 149, + ObjectLiteralExpression = 150, + PropertyAccessExpression = 151, + ElementAccessExpression = 152, + CallExpression = 153, + NewExpression = 154, + TaggedTemplateExpression = 155, + TypeAssertionExpression = 156, + ParenthesizedExpression = 157, + FunctionExpression = 158, + ArrowFunction = 159, + DeleteExpression = 160, + TypeOfExpression = 161, + VoidExpression = 162, + AwaitExpression = 163, + PrefixUnaryExpression = 164, + PostfixUnaryExpression = 165, + BinaryExpression = 166, + ConditionalExpression = 167, + TemplateExpression = 168, + YieldExpression = 169, + GeneratedLabel = 170, + SpreadElementExpression = 171, + OmittedExpression = 172, + TemplateSpan = 173, + Block = 174, + VariableStatement = 175, + EmptyStatement = 176, + ExpressionStatement = 177, + IfStatement = 178, + DoStatement = 179, + WhileStatement = 180, + ForStatement = 181, + ForInStatement = 182, + ContinueStatement = 183, + BreakStatement = 184, + ReturnStatement = 185, + WithStatement = 186, + SwitchStatement = 187, + LabeledStatement = 188, + ThrowStatement = 189, + TryStatement = 190, + DebuggerStatement = 191, + VariableDeclaration = 192, + VariableDeclarationList = 193, + FunctionDeclaration = 194, + ClassDeclaration = 195, + InterfaceDeclaration = 196, + TypeAliasDeclaration = 197, + EnumDeclaration = 198, + ModuleDeclaration = 199, + ModuleBlock = 200, + ImportDeclaration = 201, + ExportAssignment = 202, + ExternalModuleReference = 203, + CaseClause = 204, + DefaultClause = 205, + HeritageClause = 206, + CatchClause = 207, + PropertyAssignment = 208, + ShorthandPropertyAssignment = 209, + EnumMember = 210, + SourceFile = 211, + SyntaxList = 212, + Count = 213, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, LastReservedWord = 100, FirstKeyword = 65, - LastKeyword = 120, + LastKeyword = 122, FirstFutureReservedWord = 101, LastFutureReservedWord = 109, - FirstTypeNode = 135, - LastTypeNode = 143, + FirstTypeNode = 137, + LastTypeNode = 145, FirstPunctuation = 14, LastPunctuation = 63, FirstToken = 0, - LastToken = 120, + LastToken = 122, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -254,7 +258,7 @@ declare module ts { LastTemplateToken = 13, FirstBinaryOperator = 24, LastBinaryOperator = 63, - FirstNode = 121, + FirstNode = 123, } const enum NodeFlags { Export = 1, @@ -269,19 +273,25 @@ declare module ts { Let = 2048, Const = 4096, OctalLiteral = 8192, - Modifier = 243, + Async = 16384, + Modifier = 16627, AccessibilityModifier = 112, BlockScoped = 6144, } const enum ParserContextFlags { + None = 0, StrictMode = 1, DisallowIn = 2, Yield = 4, GeneratorParameter = 8, ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + AsyncParameter = 32, + Await = 64, + ParserGeneratedFlags = 127, + ContextParameterFlags = 108, + ThisNodeOrAnySubNodesHasError = 128, + ThisNodeOrAnySubNodesHasAwaitOrYield = 256, + HasAggregatedChildData = 512, } const enum RelationComparisonResult { Succeeded = 1, @@ -481,6 +491,9 @@ declare module ts { interface VoidExpression extends UnaryExpression { expression: UnaryExpression; } + interface AwaitExpression extends UnaryExpression { + expression: UnaryExpression; + } interface YieldExpression extends Expression { asteriskToken?: Node; expression: Expression; @@ -675,6 +688,10 @@ declare module ts { interface ExportAssignment extends Statement, ModuleElement { exportName: Identifier; } + interface GeneratedLabel extends Expression { + label: Label; + labelNumbers?: number[]; + } interface FileReference extends TextRange { fileName: string; } @@ -725,13 +742,96 @@ declare module ts { getTypeChecker(): TypeChecker; getCommonSourceDirectory(): string; } + enum OpCode { + Nop = 0, + Statement = 1, + Assign = 2, + Break = 3, + BreakWhenTrue = 4, + BreakWhenFalse = 5, + Yield = 6, + Return = 7, + Throw = 8, + Endfinally = 9, + } + type Label = number; + interface Locals { + resolver: EmitResolver; + context: Node; + tempCount: number; + globals?: Map; + variables?: Identifier[]; + } + enum BlockAction { + Open = 0, + Close = 1, + } + enum BlockKind { + Exception = 0, + ScriptBreak = 1, + Break = 2, + ScriptContinue = 3, + Continue = 4, + With = 5, + } + enum ExceptionBlockState { + Try = 0, + Catch = 1, + Finally = 2, + Done = 3, + } + interface BlockScope { + kind: BlockKind; + } + interface ExceptionBlock extends BlockScope { + state: ExceptionBlockState; + startLabel: Label; + catchVariable?: Identifier; + catchLabel?: Label; + finallyLabel?: Label; + endLabel: Label; + } + interface BreakBlock extends BlockScope { + breakLabel: Label; + labelText?: string[]; + requireLabel?: boolean; + } + interface ContinueBlock extends BreakBlock { + continueLabel: Label; + } + interface WithBlock extends BlockScope { + expression: Identifier; + startLabel: Label; + endLabel: Label; + } + enum FunctionBuilderFlags { + HasProtectedRegions = 1, + } + interface GeneratorFunctionBuilder { + locals: Locals; + flags: FunctionBuilderFlags; + pendingLocation?: TextRange; + parameters?: ParameterDeclaration[]; + functions?: FunctionDeclaration[]; + blocks?: BlockScope[]; + blockStack?: BlockScope[]; + blockActions?: BlockAction[]; + blockOffsets?: number[]; + nextLabelId: number; + labelNumbers?: number[]; + labels?: number[]; + operations?: OpCode[]; + operationArguments?: any[][]; + operationLocations?: TextRange[]; + state?: Identifier; + } interface SourceMapSpan { emittedLine: number; emittedColumn: number; - sourceLine: number; - sourceColumn: number; + sourceLine?: number; + sourceColumn?: number; nameIndex?: number; - sourceIndex: number; + sourceIndex?: number; } interface SourceMapData { sourceMapFilePath: string; @@ -857,6 +957,9 @@ declare module ts { isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + renameSymbol(symbol: Symbol, name: string): void; + getRenamedIdentifier(name: Identifier): string; + getPromiseConstructor(node: SignatureDeclaration): EntityName; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -954,14 +1057,20 @@ declare module ts { TypeChecked = 1, LexicalThis = 2, CaptureThis = 4, - EmitExtends = 8, - SuperInstance = 16, - SuperStatic = 32, - ContextChecked = 64, - EnumValuesComputed = 128, + LexicalArguments = 8, + CaptureArguments = 16, + EmitExtends = 32, + SuperInstance = 64, + SuperStatic = 128, + ContextChecked = 256, + PromiseCollision = 512, + EnumValuesComputed = 1024, + EmitAwaiter = 2048, + EmitGenerator = 4096, } interface NodeLinks { resolvedType?: Type; + resolvedAwaitedType?: Type; resolvedSignature?: Signature; resolvedSymbol?: Symbol; flags?: NodeCheckFlags; @@ -1129,6 +1238,7 @@ declare module ts { noImplicitAny?: boolean; noLib?: boolean; noLibCheck?: boolean; + noHelpers?: boolean; noResolve?: boolean; out?: string; outDir?: string; @@ -1142,6 +1252,7 @@ declare module ts { version?: boolean; watch?: boolean; stripInternal?: boolean; + asyncFunctions?: boolean; [option: string]: string | number | boolean; } const enum ModuleKind { @@ -1373,7 +1484,7 @@ declare module ts { function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; function isEvalOrArgumentsIdentifier(node: Node): boolean; function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile; - function isLeftHandSideExpression(expr: Expression): boolean; + function isLeftHandSideExpression(expr: Node): boolean; function isAssignmentOperator(token: SyntaxKind): boolean; } declare module ts { @@ -1704,6 +1815,9 @@ declare module ts { InMultiLineCommentTrivia = 1, InSingleQuoteStringLiteral = 2, InDoubleQuoteStringLiteral = 3, + InTemplateHeadOrNoSubstitutionTemplate = 4, + InTemplateMiddleOrTail = 5, + InTemplateSubstitutionPosition = 6, } enum TokenClass { Punctuation = 0, @@ -1725,7 +1839,26 @@ declare module ts { classification: TokenClass; } interface Classifier { - getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics?: boolean): ClassificationResult; + /** + * Gives lexical classifications of tokens on a line without any syntactic context. + * For instance, a token consisting of the text 'string' can be either an identifier + * named 'string' or the keyword 'string', however, because this classifier is not aware, + * it relies on certain heuristics to give acceptable results. For classifications where + * speed trumps accuracy, this function is preferable; however, for true accuracy, the + * syntactic classifier is ideal. In fact, in certain editing scenarios, combining the + * lexical, syntactic, and semantic classifiers may issue the best user experience. + * + * @param text The text of a line to classify. + * @param lexState The state of the lexical classifier at the end of the previous line. + * @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier. + * If there is no syntactic classifier (syntacticClassifierAbsent=true), + * certain heuristics may be used in its place; however, if there is a + * syntactic classifier (syntacticClassifierAbsent=false), certain + * classifications which may be incorrectly categorized will be given + * back as Identifiers in order to allow the syntactic classifier to + * subsume the classification. + */ + getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult; } /** * The document registry represents a store of SourceFile objects that can be shared between diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 6b06fcc1cd9b0..cdcbaa1d84fc8 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -137,109 +137,113 @@ var ts; SyntaxKind[SyntaxKind["SetKeyword"] = 118] = "SetKeyword"; SyntaxKind[SyntaxKind["StringKeyword"] = 119] = "StringKeyword"; SyntaxKind[SyntaxKind["TypeKeyword"] = 120] = "TypeKeyword"; - SyntaxKind[SyntaxKind["QualifiedName"] = 121] = "QualifiedName"; - SyntaxKind[SyntaxKind["ComputedPropertyName"] = 122] = "ComputedPropertyName"; - SyntaxKind[SyntaxKind["TypeParameter"] = 123] = "TypeParameter"; - SyntaxKind[SyntaxKind["Parameter"] = 124] = "Parameter"; - SyntaxKind[SyntaxKind["PropertySignature"] = 125] = "PropertySignature"; - SyntaxKind[SyntaxKind["PropertyDeclaration"] = 126] = "PropertyDeclaration"; - SyntaxKind[SyntaxKind["MethodSignature"] = 127] = "MethodSignature"; - SyntaxKind[SyntaxKind["MethodDeclaration"] = 128] = "MethodDeclaration"; - SyntaxKind[SyntaxKind["Constructor"] = 129] = "Constructor"; - SyntaxKind[SyntaxKind["GetAccessor"] = 130] = "GetAccessor"; - SyntaxKind[SyntaxKind["SetAccessor"] = 131] = "SetAccessor"; - SyntaxKind[SyntaxKind["CallSignature"] = 132] = "CallSignature"; - SyntaxKind[SyntaxKind["ConstructSignature"] = 133] = "ConstructSignature"; - SyntaxKind[SyntaxKind["IndexSignature"] = 134] = "IndexSignature"; - SyntaxKind[SyntaxKind["TypeReference"] = 135] = "TypeReference"; - SyntaxKind[SyntaxKind["FunctionType"] = 136] = "FunctionType"; - SyntaxKind[SyntaxKind["ConstructorType"] = 137] = "ConstructorType"; - SyntaxKind[SyntaxKind["TypeQuery"] = 138] = "TypeQuery"; - SyntaxKind[SyntaxKind["TypeLiteral"] = 139] = "TypeLiteral"; - SyntaxKind[SyntaxKind["ArrayType"] = 140] = "ArrayType"; - SyntaxKind[SyntaxKind["TupleType"] = 141] = "TupleType"; - SyntaxKind[SyntaxKind["UnionType"] = 142] = "UnionType"; - SyntaxKind[SyntaxKind["ParenthesizedType"] = 143] = "ParenthesizedType"; - SyntaxKind[SyntaxKind["ObjectBindingPattern"] = 144] = "ObjectBindingPattern"; - SyntaxKind[SyntaxKind["ArrayBindingPattern"] = 145] = "ArrayBindingPattern"; - SyntaxKind[SyntaxKind["BindingElement"] = 146] = "BindingElement"; - SyntaxKind[SyntaxKind["ArrayLiteralExpression"] = 147] = "ArrayLiteralExpression"; - SyntaxKind[SyntaxKind["ObjectLiteralExpression"] = 148] = "ObjectLiteralExpression"; - SyntaxKind[SyntaxKind["PropertyAccessExpression"] = 149] = "PropertyAccessExpression"; - SyntaxKind[SyntaxKind["ElementAccessExpression"] = 150] = "ElementAccessExpression"; - SyntaxKind[SyntaxKind["CallExpression"] = 151] = "CallExpression"; - SyntaxKind[SyntaxKind["NewExpression"] = 152] = "NewExpression"; - SyntaxKind[SyntaxKind["TaggedTemplateExpression"] = 153] = "TaggedTemplateExpression"; - SyntaxKind[SyntaxKind["TypeAssertionExpression"] = 154] = "TypeAssertionExpression"; - SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 155] = "ParenthesizedExpression"; - SyntaxKind[SyntaxKind["FunctionExpression"] = 156] = "FunctionExpression"; - SyntaxKind[SyntaxKind["ArrowFunction"] = 157] = "ArrowFunction"; - SyntaxKind[SyntaxKind["DeleteExpression"] = 158] = "DeleteExpression"; - SyntaxKind[SyntaxKind["TypeOfExpression"] = 159] = "TypeOfExpression"; - SyntaxKind[SyntaxKind["VoidExpression"] = 160] = "VoidExpression"; - SyntaxKind[SyntaxKind["PrefixUnaryExpression"] = 161] = "PrefixUnaryExpression"; - SyntaxKind[SyntaxKind["PostfixUnaryExpression"] = 162] = "PostfixUnaryExpression"; - SyntaxKind[SyntaxKind["BinaryExpression"] = 163] = "BinaryExpression"; - SyntaxKind[SyntaxKind["ConditionalExpression"] = 164] = "ConditionalExpression"; - SyntaxKind[SyntaxKind["TemplateExpression"] = 165] = "TemplateExpression"; - SyntaxKind[SyntaxKind["YieldExpression"] = 166] = "YieldExpression"; - SyntaxKind[SyntaxKind["SpreadElementExpression"] = 167] = "SpreadElementExpression"; - SyntaxKind[SyntaxKind["OmittedExpression"] = 168] = "OmittedExpression"; - SyntaxKind[SyntaxKind["TemplateSpan"] = 169] = "TemplateSpan"; - SyntaxKind[SyntaxKind["Block"] = 170] = "Block"; - SyntaxKind[SyntaxKind["VariableStatement"] = 171] = "VariableStatement"; - SyntaxKind[SyntaxKind["EmptyStatement"] = 172] = "EmptyStatement"; - SyntaxKind[SyntaxKind["ExpressionStatement"] = 173] = "ExpressionStatement"; - SyntaxKind[SyntaxKind["IfStatement"] = 174] = "IfStatement"; - SyntaxKind[SyntaxKind["DoStatement"] = 175] = "DoStatement"; - SyntaxKind[SyntaxKind["WhileStatement"] = 176] = "WhileStatement"; - SyntaxKind[SyntaxKind["ForStatement"] = 177] = "ForStatement"; - SyntaxKind[SyntaxKind["ForInStatement"] = 178] = "ForInStatement"; - SyntaxKind[SyntaxKind["ContinueStatement"] = 179] = "ContinueStatement"; - SyntaxKind[SyntaxKind["BreakStatement"] = 180] = "BreakStatement"; - SyntaxKind[SyntaxKind["ReturnStatement"] = 181] = "ReturnStatement"; - SyntaxKind[SyntaxKind["WithStatement"] = 182] = "WithStatement"; - SyntaxKind[SyntaxKind["SwitchStatement"] = 183] = "SwitchStatement"; - SyntaxKind[SyntaxKind["LabeledStatement"] = 184] = "LabeledStatement"; - SyntaxKind[SyntaxKind["ThrowStatement"] = 185] = "ThrowStatement"; - SyntaxKind[SyntaxKind["TryStatement"] = 186] = "TryStatement"; - SyntaxKind[SyntaxKind["DebuggerStatement"] = 187] = "DebuggerStatement"; - SyntaxKind[SyntaxKind["VariableDeclaration"] = 188] = "VariableDeclaration"; - SyntaxKind[SyntaxKind["VariableDeclarationList"] = 189] = "VariableDeclarationList"; - SyntaxKind[SyntaxKind["FunctionDeclaration"] = 190] = "FunctionDeclaration"; - SyntaxKind[SyntaxKind["ClassDeclaration"] = 191] = "ClassDeclaration"; - SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 192] = "InterfaceDeclaration"; - SyntaxKind[SyntaxKind["TypeAliasDeclaration"] = 193] = "TypeAliasDeclaration"; - SyntaxKind[SyntaxKind["EnumDeclaration"] = 194] = "EnumDeclaration"; - SyntaxKind[SyntaxKind["ModuleDeclaration"] = 195] = "ModuleDeclaration"; - SyntaxKind[SyntaxKind["ModuleBlock"] = 196] = "ModuleBlock"; - SyntaxKind[SyntaxKind["ImportDeclaration"] = 197] = "ImportDeclaration"; - SyntaxKind[SyntaxKind["ExportAssignment"] = 198] = "ExportAssignment"; - SyntaxKind[SyntaxKind["ExternalModuleReference"] = 199] = "ExternalModuleReference"; - SyntaxKind[SyntaxKind["CaseClause"] = 200] = "CaseClause"; - SyntaxKind[SyntaxKind["DefaultClause"] = 201] = "DefaultClause"; - SyntaxKind[SyntaxKind["HeritageClause"] = 202] = "HeritageClause"; - SyntaxKind[SyntaxKind["CatchClause"] = 203] = "CatchClause"; - SyntaxKind[SyntaxKind["PropertyAssignment"] = 204] = "PropertyAssignment"; - SyntaxKind[SyntaxKind["ShorthandPropertyAssignment"] = 205] = "ShorthandPropertyAssignment"; - SyntaxKind[SyntaxKind["EnumMember"] = 206] = "EnumMember"; - SyntaxKind[SyntaxKind["SourceFile"] = 207] = "SourceFile"; - SyntaxKind[SyntaxKind["SyntaxList"] = 208] = "SyntaxList"; - SyntaxKind[SyntaxKind["Count"] = 209] = "Count"; + SyntaxKind[SyntaxKind["AsyncKeyword"] = 121] = "AsyncKeyword"; + SyntaxKind[SyntaxKind["AwaitKeyword"] = 122] = "AwaitKeyword"; + SyntaxKind[SyntaxKind["QualifiedName"] = 123] = "QualifiedName"; + SyntaxKind[SyntaxKind["ComputedPropertyName"] = 124] = "ComputedPropertyName"; + SyntaxKind[SyntaxKind["TypeParameter"] = 125] = "TypeParameter"; + SyntaxKind[SyntaxKind["Parameter"] = 126] = "Parameter"; + SyntaxKind[SyntaxKind["PropertySignature"] = 127] = "PropertySignature"; + SyntaxKind[SyntaxKind["PropertyDeclaration"] = 128] = "PropertyDeclaration"; + SyntaxKind[SyntaxKind["MethodSignature"] = 129] = "MethodSignature"; + SyntaxKind[SyntaxKind["MethodDeclaration"] = 130] = "MethodDeclaration"; + SyntaxKind[SyntaxKind["Constructor"] = 131] = "Constructor"; + SyntaxKind[SyntaxKind["GetAccessor"] = 132] = "GetAccessor"; + SyntaxKind[SyntaxKind["SetAccessor"] = 133] = "SetAccessor"; + SyntaxKind[SyntaxKind["CallSignature"] = 134] = "CallSignature"; + SyntaxKind[SyntaxKind["ConstructSignature"] = 135] = "ConstructSignature"; + SyntaxKind[SyntaxKind["IndexSignature"] = 136] = "IndexSignature"; + SyntaxKind[SyntaxKind["TypeReference"] = 137] = "TypeReference"; + SyntaxKind[SyntaxKind["FunctionType"] = 138] = "FunctionType"; + SyntaxKind[SyntaxKind["ConstructorType"] = 139] = "ConstructorType"; + SyntaxKind[SyntaxKind["TypeQuery"] = 140] = "TypeQuery"; + SyntaxKind[SyntaxKind["TypeLiteral"] = 141] = "TypeLiteral"; + SyntaxKind[SyntaxKind["ArrayType"] = 142] = "ArrayType"; + SyntaxKind[SyntaxKind["TupleType"] = 143] = "TupleType"; + SyntaxKind[SyntaxKind["UnionType"] = 144] = "UnionType"; + SyntaxKind[SyntaxKind["ParenthesizedType"] = 145] = "ParenthesizedType"; + SyntaxKind[SyntaxKind["ObjectBindingPattern"] = 146] = "ObjectBindingPattern"; + SyntaxKind[SyntaxKind["ArrayBindingPattern"] = 147] = "ArrayBindingPattern"; + SyntaxKind[SyntaxKind["BindingElement"] = 148] = "BindingElement"; + SyntaxKind[SyntaxKind["ArrayLiteralExpression"] = 149] = "ArrayLiteralExpression"; + SyntaxKind[SyntaxKind["ObjectLiteralExpression"] = 150] = "ObjectLiteralExpression"; + SyntaxKind[SyntaxKind["PropertyAccessExpression"] = 151] = "PropertyAccessExpression"; + SyntaxKind[SyntaxKind["ElementAccessExpression"] = 152] = "ElementAccessExpression"; + SyntaxKind[SyntaxKind["CallExpression"] = 153] = "CallExpression"; + SyntaxKind[SyntaxKind["NewExpression"] = 154] = "NewExpression"; + SyntaxKind[SyntaxKind["TaggedTemplateExpression"] = 155] = "TaggedTemplateExpression"; + SyntaxKind[SyntaxKind["TypeAssertionExpression"] = 156] = "TypeAssertionExpression"; + SyntaxKind[SyntaxKind["ParenthesizedExpression"] = 157] = "ParenthesizedExpression"; + SyntaxKind[SyntaxKind["FunctionExpression"] = 158] = "FunctionExpression"; + SyntaxKind[SyntaxKind["ArrowFunction"] = 159] = "ArrowFunction"; + SyntaxKind[SyntaxKind["DeleteExpression"] = 160] = "DeleteExpression"; + SyntaxKind[SyntaxKind["TypeOfExpression"] = 161] = "TypeOfExpression"; + SyntaxKind[SyntaxKind["VoidExpression"] = 162] = "VoidExpression"; + SyntaxKind[SyntaxKind["AwaitExpression"] = 163] = "AwaitExpression"; + SyntaxKind[SyntaxKind["PrefixUnaryExpression"] = 164] = "PrefixUnaryExpression"; + SyntaxKind[SyntaxKind["PostfixUnaryExpression"] = 165] = "PostfixUnaryExpression"; + SyntaxKind[SyntaxKind["BinaryExpression"] = 166] = "BinaryExpression"; + SyntaxKind[SyntaxKind["ConditionalExpression"] = 167] = "ConditionalExpression"; + SyntaxKind[SyntaxKind["TemplateExpression"] = 168] = "TemplateExpression"; + SyntaxKind[SyntaxKind["YieldExpression"] = 169] = "YieldExpression"; + SyntaxKind[SyntaxKind["GeneratedLabel"] = 170] = "GeneratedLabel"; + SyntaxKind[SyntaxKind["SpreadElementExpression"] = 171] = "SpreadElementExpression"; + SyntaxKind[SyntaxKind["OmittedExpression"] = 172] = "OmittedExpression"; + SyntaxKind[SyntaxKind["TemplateSpan"] = 173] = "TemplateSpan"; + SyntaxKind[SyntaxKind["Block"] = 174] = "Block"; + SyntaxKind[SyntaxKind["VariableStatement"] = 175] = "VariableStatement"; + SyntaxKind[SyntaxKind["EmptyStatement"] = 176] = "EmptyStatement"; + SyntaxKind[SyntaxKind["ExpressionStatement"] = 177] = "ExpressionStatement"; + SyntaxKind[SyntaxKind["IfStatement"] = 178] = "IfStatement"; + SyntaxKind[SyntaxKind["DoStatement"] = 179] = "DoStatement"; + SyntaxKind[SyntaxKind["WhileStatement"] = 180] = "WhileStatement"; + SyntaxKind[SyntaxKind["ForStatement"] = 181] = "ForStatement"; + SyntaxKind[SyntaxKind["ForInStatement"] = 182] = "ForInStatement"; + SyntaxKind[SyntaxKind["ContinueStatement"] = 183] = "ContinueStatement"; + SyntaxKind[SyntaxKind["BreakStatement"] = 184] = "BreakStatement"; + SyntaxKind[SyntaxKind["ReturnStatement"] = 185] = "ReturnStatement"; + SyntaxKind[SyntaxKind["WithStatement"] = 186] = "WithStatement"; + SyntaxKind[SyntaxKind["SwitchStatement"] = 187] = "SwitchStatement"; + SyntaxKind[SyntaxKind["LabeledStatement"] = 188] = "LabeledStatement"; + SyntaxKind[SyntaxKind["ThrowStatement"] = 189] = "ThrowStatement"; + SyntaxKind[SyntaxKind["TryStatement"] = 190] = "TryStatement"; + SyntaxKind[SyntaxKind["DebuggerStatement"] = 191] = "DebuggerStatement"; + SyntaxKind[SyntaxKind["VariableDeclaration"] = 192] = "VariableDeclaration"; + SyntaxKind[SyntaxKind["VariableDeclarationList"] = 193] = "VariableDeclarationList"; + SyntaxKind[SyntaxKind["FunctionDeclaration"] = 194] = "FunctionDeclaration"; + SyntaxKind[SyntaxKind["ClassDeclaration"] = 195] = "ClassDeclaration"; + SyntaxKind[SyntaxKind["InterfaceDeclaration"] = 196] = "InterfaceDeclaration"; + SyntaxKind[SyntaxKind["TypeAliasDeclaration"] = 197] = "TypeAliasDeclaration"; + SyntaxKind[SyntaxKind["EnumDeclaration"] = 198] = "EnumDeclaration"; + SyntaxKind[SyntaxKind["ModuleDeclaration"] = 199] = "ModuleDeclaration"; + SyntaxKind[SyntaxKind["ModuleBlock"] = 200] = "ModuleBlock"; + SyntaxKind[SyntaxKind["ImportDeclaration"] = 201] = "ImportDeclaration"; + SyntaxKind[SyntaxKind["ExportAssignment"] = 202] = "ExportAssignment"; + SyntaxKind[SyntaxKind["ExternalModuleReference"] = 203] = "ExternalModuleReference"; + SyntaxKind[SyntaxKind["CaseClause"] = 204] = "CaseClause"; + SyntaxKind[SyntaxKind["DefaultClause"] = 205] = "DefaultClause"; + SyntaxKind[SyntaxKind["HeritageClause"] = 206] = "HeritageClause"; + SyntaxKind[SyntaxKind["CatchClause"] = 207] = "CatchClause"; + SyntaxKind[SyntaxKind["PropertyAssignment"] = 208] = "PropertyAssignment"; + SyntaxKind[SyntaxKind["ShorthandPropertyAssignment"] = 209] = "ShorthandPropertyAssignment"; + SyntaxKind[SyntaxKind["EnumMember"] = 210] = "EnumMember"; + SyntaxKind[SyntaxKind["SourceFile"] = 211] = "SourceFile"; + SyntaxKind[SyntaxKind["SyntaxList"] = 212] = "SyntaxList"; + SyntaxKind[SyntaxKind["Count"] = 213] = "Count"; SyntaxKind[SyntaxKind["FirstAssignment"] = 52] = "FirstAssignment"; SyntaxKind[SyntaxKind["LastAssignment"] = 63] = "LastAssignment"; SyntaxKind[SyntaxKind["FirstReservedWord"] = 65] = "FirstReservedWord"; SyntaxKind[SyntaxKind["LastReservedWord"] = 100] = "LastReservedWord"; SyntaxKind[SyntaxKind["FirstKeyword"] = 65] = "FirstKeyword"; - SyntaxKind[SyntaxKind["LastKeyword"] = 120] = "LastKeyword"; + SyntaxKind[SyntaxKind["LastKeyword"] = 122] = "LastKeyword"; SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 101] = "FirstFutureReservedWord"; SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 109] = "LastFutureReservedWord"; - SyntaxKind[SyntaxKind["FirstTypeNode"] = 135] = "FirstTypeNode"; - SyntaxKind[SyntaxKind["LastTypeNode"] = 143] = "LastTypeNode"; + SyntaxKind[SyntaxKind["FirstTypeNode"] = 137] = "FirstTypeNode"; + SyntaxKind[SyntaxKind["LastTypeNode"] = 145] = "LastTypeNode"; SyntaxKind[SyntaxKind["FirstPunctuation"] = 14] = "FirstPunctuation"; SyntaxKind[SyntaxKind["LastPunctuation"] = 63] = "LastPunctuation"; SyntaxKind[SyntaxKind["FirstToken"] = 0] = "FirstToken"; - SyntaxKind[SyntaxKind["LastToken"] = 120] = "LastToken"; + SyntaxKind[SyntaxKind["LastToken"] = 122] = "LastToken"; SyntaxKind[SyntaxKind["FirstTriviaToken"] = 2] = "FirstTriviaToken"; SyntaxKind[SyntaxKind["LastTriviaToken"] = 6] = "LastTriviaToken"; SyntaxKind[SyntaxKind["FirstLiteralToken"] = 7] = "FirstLiteralToken"; @@ -248,7 +252,7 @@ var ts; SyntaxKind[SyntaxKind["LastTemplateToken"] = 13] = "LastTemplateToken"; SyntaxKind[SyntaxKind["FirstBinaryOperator"] = 24] = "FirstBinaryOperator"; SyntaxKind[SyntaxKind["LastBinaryOperator"] = 63] = "LastBinaryOperator"; - SyntaxKind[SyntaxKind["FirstNode"] = 121] = "FirstNode"; + SyntaxKind[SyntaxKind["FirstNode"] = 123] = "FirstNode"; })(ts.SyntaxKind || (ts.SyntaxKind = {})); var SyntaxKind = ts.SyntaxKind; (function (NodeFlags) { @@ -264,20 +268,26 @@ var ts; NodeFlags[NodeFlags["Let"] = 2048] = "Let"; NodeFlags[NodeFlags["Const"] = 4096] = "Const"; NodeFlags[NodeFlags["OctalLiteral"] = 8192] = "OctalLiteral"; - NodeFlags[NodeFlags["Modifier"] = 243] = "Modifier"; + NodeFlags[NodeFlags["Async"] = 16384] = "Async"; + NodeFlags[NodeFlags["Modifier"] = 16627] = "Modifier"; NodeFlags[NodeFlags["AccessibilityModifier"] = 112] = "AccessibilityModifier"; NodeFlags[NodeFlags["BlockScoped"] = 6144] = "BlockScoped"; })(ts.NodeFlags || (ts.NodeFlags = {})); var NodeFlags = ts.NodeFlags; (function (ParserContextFlags) { + ParserContextFlags[ParserContextFlags["None"] = 0] = "None"; ParserContextFlags[ParserContextFlags["StrictMode"] = 1] = "StrictMode"; ParserContextFlags[ParserContextFlags["DisallowIn"] = 2] = "DisallowIn"; ParserContextFlags[ParserContextFlags["Yield"] = 4] = "Yield"; ParserContextFlags[ParserContextFlags["GeneratorParameter"] = 8] = "GeneratorParameter"; ParserContextFlags[ParserContextFlags["ThisNodeHasError"] = 16] = "ThisNodeHasError"; - ParserContextFlags[ParserContextFlags["ParserGeneratedFlags"] = 31] = "ParserGeneratedFlags"; - ParserContextFlags[ParserContextFlags["ThisNodeOrAnySubNodesHasError"] = 32] = "ThisNodeOrAnySubNodesHasError"; - ParserContextFlags[ParserContextFlags["HasAggregatedChildData"] = 64] = "HasAggregatedChildData"; + ParserContextFlags[ParserContextFlags["AsyncParameter"] = 32] = "AsyncParameter"; + ParserContextFlags[ParserContextFlags["Await"] = 64] = "Await"; + ParserContextFlags[ParserContextFlags["ParserGeneratedFlags"] = 127] = "ParserGeneratedFlags"; + ParserContextFlags[ParserContextFlags["ContextParameterFlags"] = 108] = "ContextParameterFlags"; + ParserContextFlags[ParserContextFlags["ThisNodeOrAnySubNodesHasError"] = 128] = "ThisNodeOrAnySubNodesHasError"; + ParserContextFlags[ParserContextFlags["ThisNodeOrAnySubNodesHasAwaitOrYield"] = 256] = "ThisNodeOrAnySubNodesHasAwaitOrYield"; + ParserContextFlags[ParserContextFlags["HasAggregatedChildData"] = 512] = "HasAggregatedChildData"; })(ts.ParserContextFlags || (ts.ParserContextFlags = {})); var ParserContextFlags = ts.ParserContextFlags; (function (RelationComparisonResult) { @@ -286,6 +296,44 @@ var ts; RelationComparisonResult[RelationComparisonResult["FailedAndReported"] = 3] = "FailedAndReported"; })(ts.RelationComparisonResult || (ts.RelationComparisonResult = {})); var RelationComparisonResult = ts.RelationComparisonResult; + (function (OpCode) { + OpCode[OpCode["Nop"] = 0] = "Nop"; + OpCode[OpCode["Statement"] = 1] = "Statement"; + OpCode[OpCode["Assign"] = 2] = "Assign"; + OpCode[OpCode["Break"] = 3] = "Break"; + OpCode[OpCode["BreakWhenTrue"] = 4] = "BreakWhenTrue"; + OpCode[OpCode["BreakWhenFalse"] = 5] = "BreakWhenFalse"; + OpCode[OpCode["Yield"] = 6] = "Yield"; + OpCode[OpCode["Return"] = 7] = "Return"; + OpCode[OpCode["Throw"] = 8] = "Throw"; + OpCode[OpCode["Endfinally"] = 9] = "Endfinally"; + })(ts.OpCode || (ts.OpCode = {})); + var OpCode = ts.OpCode; + (function (BlockAction) { + BlockAction[BlockAction["Open"] = 0] = "Open"; + BlockAction[BlockAction["Close"] = 1] = "Close"; + })(ts.BlockAction || (ts.BlockAction = {})); + var BlockAction = ts.BlockAction; + (function (BlockKind) { + BlockKind[BlockKind["Exception"] = 0] = "Exception"; + BlockKind[BlockKind["ScriptBreak"] = 1] = "ScriptBreak"; + BlockKind[BlockKind["Break"] = 2] = "Break"; + BlockKind[BlockKind["ScriptContinue"] = 3] = "ScriptContinue"; + BlockKind[BlockKind["Continue"] = 4] = "Continue"; + BlockKind[BlockKind["With"] = 5] = "With"; + })(ts.BlockKind || (ts.BlockKind = {})); + var BlockKind = ts.BlockKind; + (function (ExceptionBlockState) { + ExceptionBlockState[ExceptionBlockState["Try"] = 0] = "Try"; + ExceptionBlockState[ExceptionBlockState["Catch"] = 1] = "Catch"; + ExceptionBlockState[ExceptionBlockState["Finally"] = 2] = "Finally"; + ExceptionBlockState[ExceptionBlockState["Done"] = 3] = "Done"; + })(ts.ExceptionBlockState || (ts.ExceptionBlockState = {})); + var ExceptionBlockState = ts.ExceptionBlockState; + (function (FunctionBuilderFlags) { + FunctionBuilderFlags[FunctionBuilderFlags["HasProtectedRegions"] = 0x1] = "HasProtectedRegions"; + })(ts.FunctionBuilderFlags || (ts.FunctionBuilderFlags = {})); + var FunctionBuilderFlags = ts.FunctionBuilderFlags; (function (ExitStatus) { ExitStatus[ExitStatus["Success"] = 0] = "Success"; ExitStatus[ExitStatus["DiagnosticsPresent_OutputsSkipped"] = 1] = "DiagnosticsPresent_OutputsSkipped"; @@ -386,11 +434,16 @@ var ts; NodeCheckFlags[NodeCheckFlags["TypeChecked"] = 1] = "TypeChecked"; NodeCheckFlags[NodeCheckFlags["LexicalThis"] = 2] = "LexicalThis"; NodeCheckFlags[NodeCheckFlags["CaptureThis"] = 4] = "CaptureThis"; - NodeCheckFlags[NodeCheckFlags["EmitExtends"] = 8] = "EmitExtends"; - NodeCheckFlags[NodeCheckFlags["SuperInstance"] = 16] = "SuperInstance"; - NodeCheckFlags[NodeCheckFlags["SuperStatic"] = 32] = "SuperStatic"; - NodeCheckFlags[NodeCheckFlags["ContextChecked"] = 64] = "ContextChecked"; - NodeCheckFlags[NodeCheckFlags["EnumValuesComputed"] = 128] = "EnumValuesComputed"; + NodeCheckFlags[NodeCheckFlags["LexicalArguments"] = 8] = "LexicalArguments"; + NodeCheckFlags[NodeCheckFlags["CaptureArguments"] = 16] = "CaptureArguments"; + NodeCheckFlags[NodeCheckFlags["EmitExtends"] = 32] = "EmitExtends"; + NodeCheckFlags[NodeCheckFlags["SuperInstance"] = 64] = "SuperInstance"; + NodeCheckFlags[NodeCheckFlags["SuperStatic"] = 128] = "SuperStatic"; + NodeCheckFlags[NodeCheckFlags["ContextChecked"] = 256] = "ContextChecked"; + NodeCheckFlags[NodeCheckFlags["PromiseCollision"] = 512] = "PromiseCollision"; + NodeCheckFlags[NodeCheckFlags["EnumValuesComputed"] = 1024] = "EnumValuesComputed"; + NodeCheckFlags[NodeCheckFlags["EmitAwaiter"] = 2048] = "EmitAwaiter"; + NodeCheckFlags[NodeCheckFlags["EmitGenerator"] = 4096] = "EmitGenerator"; })(ts.NodeCheckFlags || (ts.NodeCheckFlags = {})); var NodeCheckFlags = ts.NodeCheckFlags; (function (TypeFlags) { @@ -661,6 +714,49 @@ var ts; return result; } ts.map = map; + function flatMap(array, f) { + if (array) { + var result = []; + for (var i = 0, len = array.length; i < len; i++) { + var part = f(array[i]); + if (part) { + result.push.apply(result, part); + } + } + } + return result; + } + ts.flatMap = flatMap; + function foldLeft(array, f, initial) { + if (array) { + var count = array.length; + if (count > 0) { + var pos = 0; + var result = arguments.length <= 2 ? array[pos++] : initial; + while (pos < count) { + result = f(result, array[pos++]); + } + return result; + } + } + return initial; + } + ts.foldLeft = foldLeft; + function foldRight(array, f, initial) { + if (array) { + var count = array.length; + if (count > 0) { + var pos = count - 1; + var result = arguments.length <= 2 ? array[pos--] : initial; + while (pos >= 0) { + result = f(result, array[pos--]); + } + return result; + } + } + return initial; + } + ts.foldRight = foldRight; function concatenate(array1, array2) { if (!array2 || !array2.length) return array1; @@ -1471,8 +1567,12 @@ var ts; Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: 1, key: "Statements are not allowed in ambient contexts." }, A_declare_modifier_cannot_be_used_in_an_already_ambient_context: { code: 1038, category: 1, key: "A 'declare' modifier cannot be used in an already ambient context." }, Initializers_are_not_allowed_in_ambient_contexts: { code: 1039, category: 1, key: "Initializers are not allowed in ambient contexts." }, + _0_modifier_cannot_be_used_in_an_ambient_context: { code: 1040, category: 1, key: "'{0}' modifier cannot be used in an ambient context." }, + _0_modifier_cannot_be_used_with_a_class_declaration: { code: 1041, category: 1, key: "'{0}' modifier cannot be used with a class declaration." }, + _0_modifier_cannot_be_used_here: { code: 1042, category: 1, key: "'{0}' modifier cannot be used here." }, + _0_modifier_cannot_appear_on_a_data_property: { code: 1043, category: 1, key: "'{0}' modifier cannot appear on a data property." }, _0_modifier_cannot_appear_on_a_module_element: { code: 1044, category: 1, key: "'{0}' modifier cannot appear on a module element." }, - A_declare_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: 1, key: "A 'declare' modifier cannot be used with an interface declaration." }, + _0_modifier_cannot_be_used_with_an_interface_declaration: { code: 1045, category: 1, key: "'{0}' modifier cannot be used with an interface declaration." }, A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file: { code: 1046, category: 1, key: "A 'declare' modifier is required for a top level declaration in a .d.ts file." }, A_rest_parameter_cannot_be_optional: { code: 1047, category: 1, key: "A rest parameter cannot be optional." }, A_rest_parameter_cannot_have_an_initializer: { code: 1048, category: 1, key: "A rest parameter cannot have an initializer." }, @@ -1482,11 +1582,13 @@ var ts; A_set_accessor_cannot_have_rest_parameter: { code: 1053, category: 1, key: "A 'set' accessor cannot have rest parameter." }, A_get_accessor_cannot_have_parameters: { code: 1054, category: 1, key: "A 'get' accessor cannot have parameters." }, Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1056, category: 1, key: "Accessors are only available when targeting ECMAScript 5 and higher." }, + An_async_function_or_method_must_have_a_valid_awaitable_return_type: { code: 1057, category: 1, key: "An async function or method must have a valid awaitable return type." }, + Type_for_await_does_not_have_a_valid_callable_then_member: { code: 1058, category: 1, key: "Type for 'await' does not have a valid callable 'then' member." }, Enum_member_must_have_initializer: { code: 1061, category: 1, key: "Enum member must have initializer." }, An_export_assignment_cannot_be_used_in_an_internal_module: { code: 1063, category: 1, key: "An export assignment cannot be used in an internal module." }, Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: 1, key: "Ambient enum elements can only have integer literal initializers." }, Unexpected_token_A_constructor_method_accessor_or_property_was_expected: { code: 1068, category: 1, key: "Unexpected token. A constructor, method, accessor, or property was expected." }, - A_declare_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: 1, key: "A 'declare' modifier cannot be used with an import declaration." }, + _0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: 1, key: "'{0}' modifier cannot be used with an import declaration." }, Invalid_reference_directive_syntax: { code: 1084, category: 1, key: "Invalid 'reference' directive syntax." }, Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: 1, key: "Octal literals are not available when targeting ECMAScript 5 and higher." }, An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: 1, key: "An accessor cannot be declared in an ambient context." }, @@ -1558,7 +1660,7 @@ var ts; Unterminated_template_literal: { code: 1160, category: 1, key: "Unterminated template literal." }, Unterminated_regular_expression_literal: { code: 1161, category: 1, key: "Unterminated regular expression literal." }, An_object_member_cannot_be_declared_optional: { code: 1162, category: 1, key: "An object member cannot be declared optional." }, - yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: 1, key: "'yield' expression must be contained_within a generator declaration." }, + yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: 1, key: "'yield' expression must be contained within a generator declaration." }, Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: 1, key: "Computed property names are not allowed in enums." }, Computed_property_names_are_not_allowed_in_an_ambient_context: { code: 1165, category: 1, key: "Computed property names are not allowed in an ambient context." }, Computed_property_names_are_not_allowed_in_class_property_declarations: { code: 1166, category: 1, key: "Computed property names are not allowed in class property declarations." }, @@ -1580,10 +1682,22 @@ var ts; A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: 1, key: "A destructuring declaration must have an initializer." }, Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: 1, key: "Destructuring declarations are not allowed in ambient contexts." }, An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: 1, key: "An implementation cannot be declared in ambient contexts." }, - Modifiers_cannot_appear_here: { code: 1184, category: 1, key: "Modifiers cannot appear here." }, - Merge_conflict_marker_encountered: { code: 1185, category: 1, key: "Merge conflict marker encountered." }, - A_rest_element_cannot_have_an_initializer: { code: 1186, category: 1, key: "A rest element cannot have an initializer." }, - A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: 1, key: "A parameter property may not be a binding pattern." }, + Modifiers_cannot_appear_here: { code: 1185, category: 1, key: "Modifiers cannot appear here." }, + Merge_conflict_marker_encountered: { code: 1186, category: 1, key: "Merge conflict marker encountered." }, + A_rest_element_cannot_have_an_initializer: { code: 1187, category: 1, key: "A rest element cannot have an initializer." }, + A_parameter_property_may_not_be_a_binding_pattern: { code: 1188, category: 1, key: "A parameter property may not be a binding pattern." }, + with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: 1, key: "'with' statements are not allowed in an async function block." }, + _0_modifier_cannot_be_used_with_a_generator: { code: 1301, category: 1, key: "'{0}' modifier cannot be used with a generator." }, + _0_modifier_cannot_be_used_with_a_module_declaration: { code: 1302, category: 1, key: "'{0}' modifier cannot be used with a module declaration." }, + _0_modifier_cannot_be_used_with_an_enum_declaration: { code: 1303, category: 1, key: "'{0}' modifier cannot be used with an enum declaration." }, + _0_modifier_cannot_be_used_with_an_export_assignment_declaration: { code: 1304, category: 1, key: "'{0}' modifier cannot be used with an export assignment declaration." }, + _0_modifier_cannot_be_used_on_a_variable_statement: { code: 1305, category: 1, key: "'{0}' modifier cannot be used on a variable statement." }, + _0_modifier_cannot_be_used_with_a_type_declaration: { code: 1306, category: 1, key: "'{0}' modifier cannot be used with a type declaration." }, + _0_modifier_cannot_be_used_with_a_parameter_declaration: { code: 1307, category: 1, key: "'{0}' modifier cannot be used with a parameter declaration." }, + await_expression_must_be_contained_within_an_async_function: { code: 1308, category: 1, key: "'await' expression must be contained within an async function." }, + _0_modifier_cannot_be_used_on_an_object_literal_element: { code: 1309, category: 1, key: "'{0}' modifier cannot be used on an object literal element." }, + _0_expression_is_not_allowed_in_an_initializer: { code: 1310, category: 1, key: "'{0}' expression is not allowed in an initializer." }, + Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: 1, key: "Async functions are only available when targeting ECMAScript 6 and higher." }, Duplicate_identifier_0: { code: 2300, category: 1, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: 1, 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: 1, key: "Static members cannot reference class type parameters." }, @@ -1739,7 +1853,11 @@ var ts; A_computed_property_name_must_be_of_type_string_number_or_any: { code: 2464, category: 1, key: "A computed property name must be of type 'string', 'number', or 'any'." }, this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: 1, key: "'this' cannot be referenced in a computed property name." }, super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: 1, key: "'super' cannot be referenced in a computed property name." }, - A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2466, category: 1, key: "A computed property name cannot reference a type parameter from its containing type." }, + A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2467, category: 1, key: "A computed property name cannot reference a type parameter from its containing type." }, + Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2500, category: 1, 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: 2501, category: 1, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." }, + Duplicate_identifier_arguments_Compiler_uses_variable_declaration_arguments_to_capture_arguments_reference: { code: 2502, category: 1, key: "Duplicate identifier '_arguments'. Compiler uses variable declaration '_arguments' to capture 'arguments' reference." }, + Expression_resolves_to_variable_declaration_arguments_that_compiler_uses_to_capture_arguments_reference: { code: 2503, category: 1, key: "Expression resolves to variable declaration '_arguments' that compiler uses to capture 'arguments' reference." }, Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher: { code: 2468, category: 1, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1, 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: 1, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, @@ -1818,6 +1936,7 @@ var ts; const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: { code: 4087, category: 1, key: "'const' enum member initializer was evaluated to disallowed value 'NaN'." }, Property_0_does_not_exist_on_const_enum_1: { code: 4088, category: 1, key: "Property '{0}' does not exist on 'const' enum '{1}'." }, let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations: { code: 4089, category: 1, key: "'let' is not allowed to be used as a name in 'let' or 'const' declarations." }, + Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1: { code: 4090, category: 1, key: "Cannot initialize outer scoped variable '{0}' in the same scope as block scoped declaration '{1}'." }, The_current_host_does_not_support_the_0_option: { code: 5001, category: 1, key: "The current host does not support the '{0}' option." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: 1, key: "Cannot find the common subdirectory path for the input files." }, Cannot_read_file_0_Colon_1: { code: 5012, category: 1, key: "Cannot read file '{0}': {1}" }, @@ -1873,6 +1992,8 @@ var ts; File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: 1, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: 2, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: 2, key: "Do not emit declarations for code that has an '@internal' annotation." }, + Emit_async_functions_when_ECMAScript_target_version_is_lower_than_ES6: { code: 6057, category: 2, key: "Emit async functions when ECMAScript target version is lower than 'ES6'." }, + Do_not_emit_runtime_helper_functions_e_g_extends_awaiter_Assumes_manual_reference_to_tslib_js: { code: 6058, category: 2, key: "Do not emit runtime helper functions (e.g. '__extends', '__awaiter'). Assumes manual reference to tslib.js." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: 1, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: 1, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: 1, key: "Member '{0}' implicitly has an '{1}' type." }, @@ -1955,6 +2076,8 @@ var ts; "while": 99, "with": 100, "yield": 109, + "async": 121, + "await": 122, "{": 14, "}": 15, "(": 16, @@ -2124,6 +2247,8 @@ var ts; } ts.isOctalDigit = isOctalDigit; function skipTrivia(text, pos, stopAfterLineBreak) { + if (pos < 0) + return pos; while (true) { var ch = text.charCodeAt(pos); switch (ch) { @@ -3069,20 +3194,38 @@ var ts; ts.getFullWidth = getFullWidth; function containsParseError(node) { aggregateChildData(node); - return (node.parserContextFlags & 32) !== 0; + return (node.parserContextFlags & 128) !== 0; } ts.containsParseError = containsParseError; + function isAwaitOrYield(node) { + return node && (node.kind === 163 || node.kind === 169); + } + ts.isAwaitOrYield = isAwaitOrYield; + function hasAwaitOrYield(node) { + if (!node) { + return false; + } + aggregateChildData(node); + return (node.parserContextFlags & 256) !== 0; + } + ts.hasAwaitOrYield = hasAwaitOrYield; function aggregateChildData(node) { - if (!(node.parserContextFlags & 64)) { + if (!(node.parserContextFlags & 512)) { var thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & 16) !== 0) || ts.forEachChild(node, containsParseError); if (thisNodeOrAnySubNodesHasError) { - node.parserContextFlags |= 32; + node.parserContextFlags |= 128; } - node.parserContextFlags |= 64; + if (!isAnyFunction(node)) { + var thisNodeOrAnySubNodesHasAwaitOrYield = isAwaitOrYield(node) || ts.forEachChild(node, hasAwaitOrYield); + if (thisNodeOrAnySubNodesHasAwaitOrYield) { + node.parserContextFlags |= 256; + } + } + node.parserContextFlags |= 512; } } function getSourceFileOfNode(node) { - while (node && node.kind !== 207) { + while (node && node.kind !== 211) { node = node.parent; } return node; @@ -3102,13 +3245,25 @@ var ts; if (!node) { return true; } - return node.pos === node.end && node.kind !== 1; + return node.pos === node.end && node.kind !== 1 && node.pos >= 0; } ts.nodeIsMissing = nodeIsMissing; + function nodeIsGenerated(node) { + return node && node.pos === node.end && node.kind !== 1 && node.pos < 0; + } + ts.nodeIsGenerated = nodeIsGenerated; + function nodeIsMissingOrGenerated(node) { + return nodeIsMissing(node) || nodeIsGenerated(node); + } + ts.nodeIsMissingOrGenerated = nodeIsMissingOrGenerated; function nodeIsPresent(node) { - return !nodeIsMissing(node); + return !nodeIsMissingOrGenerated(node); } ts.nodeIsPresent = nodeIsPresent; + function nodeIsPresentOrGenerated(node) { + return !nodeIsMissing(node); + } + ts.nodeIsPresentOrGenerated = nodeIsPresentOrGenerated; function getTokenPosOfNode(node, sourceFile) { if (nodeIsMissing(node)) { return node.pos; @@ -3173,13 +3328,13 @@ var ts; function getErrorSpanForNode(node) { var errorSpan; switch (node.kind) { - case 188: - case 146: - case 191: case 192: + case 148: case 195: - case 194: - case 206: + case 196: + case 199: + case 198: + case 210: errorSpan = node.name; break; } @@ -3195,11 +3350,11 @@ var ts; } ts.isDeclarationFile = isDeclarationFile; function isConstEnumDeclaration(node) { - return node.kind === 194 && isConst(node); + return node.kind === 198 && isConst(node); } ts.isConstEnumDeclaration = isConstEnumDeclaration; function walkUpBindingElementsAndPatterns(node) { - while (node && (node.kind === 146 || isBindingPattern(node))) { + while (node && (node.kind === 148 || isBindingPattern(node))) { node = node.parent; } return node; @@ -3207,14 +3362,14 @@ var ts; function getCombinedNodeFlags(node) { node = walkUpBindingElementsAndPatterns(node); var flags = node.flags; - if (node.kind === 188) { + if (node.kind === 192) { node = node.parent; } - if (node && node.kind === 189) { + if (node && node.kind === 193) { flags |= node.flags; node = node.parent; } - if (node && node.kind === 171) { + if (node && node.kind === 175) { flags |= node.flags; } return flags; @@ -3229,12 +3384,12 @@ var ts; } ts.isLet = isLet; function isPrologueDirective(node) { - return node.kind === 173 && node.expression.kind === 8; + return node.kind === 177 && node.expression.kind === 8; } ts.isPrologueDirective = isPrologueDirective; function getLeadingCommentRangesOfNode(node, sourceFileOfNode) { sourceFileOfNode = sourceFileOfNode || getSourceFileOfNode(node); - if (node.kind === 124 || node.kind === 123) { + if (node.kind === 126 || node.kind === 125) { return ts.concatenate(ts.getTrailingCommentRanges(sourceFileOfNode.text, node.pos), ts.getLeadingCommentRanges(sourceFileOfNode.text, node.pos)); } else { @@ -3254,21 +3409,21 @@ var ts; return traverse(body); function traverse(node) { switch (node.kind) { - case 181: + case 185: return visitor(node); - case 170: case 174: - case 175: - case 176: - case 177: case 178: + case 179: + case 180: + case 181: case 182: - case 183: - case 200: - case 201: - case 184: case 186: - case 203: + case 187: + case 204: + case 205: + case 188: + case 190: + case 207: return ts.forEachChild(node, traverse); } } @@ -3277,22 +3432,22 @@ var ts; function isAnyFunction(node) { if (node) { switch (node.kind) { - case 129: - case 156: - case 190: - case 157: - case 128: - case 127: - case 130: case 131: + case 158: + case 194: + case 159: + case 130: + case 129: case 132: case 133: case 134: + case 135: case 136: - case 137: - case 156: - case 157: - case 190: + case 138: + case 139: + case 158: + case 159: + case 194: return true; } } @@ -3300,13 +3455,27 @@ var ts; } ts.isAnyFunction = isAnyFunction; function isFunctionBlock(node) { - return node && node.kind === 170 && isAnyFunction(node.parent); + return node && node.kind === 174 && isAnyFunction(node.parent); } ts.isFunctionBlock = isFunctionBlock; function isObjectLiteralMethod(node) { - return node && node.kind === 128 && node.parent.kind === 148; + return node && node.kind === 130 && node.parent.kind === 150; } ts.isObjectLiteralMethod = isObjectLiteralMethod; + function isObjectLiteralElement(node) { + if (node) { + switch (node.kind) { + case 208: + case 209: + case 130: + case 132: + case 133: + return true; + } + } + return false; + } + ts.isObjectLiteralElement = isObjectLiteralElement; function getContainingFunction(node) { while (true) { node = node.parent; @@ -3316,6 +3485,18 @@ var ts; } } ts.getContainingFunction = getContainingFunction; + function getContainingParameter(node) { + while (true) { + node = node.parent; + if (!node || isAnyFunction(node)) { + break; + } + if (node.kind === 126) { + return node; + } + } + } + ts.getContainingParameter = getContainingParameter; function getThisContainer(node, includeArrowFunctions) { while (true) { node = node.parent; @@ -3323,28 +3504,28 @@ var ts; return undefined; } switch (node.kind) { - case 122: - if (node.parent.parent.kind === 191) { + case 124: + if (node.parent.parent.kind === 195) { return node; } node = node.parent; break; - case 157: + case 159: if (!includeArrowFunctions) { continue; } - case 190: - case 156: - case 195: - case 126: - case 125: + case 194: + case 158: + case 199: case 128: case 127: - case 129: case 130: + case 129: case 131: - case 194: - case 207: + case 132: + case 133: + case 198: + case 211: return node; } } @@ -3356,32 +3537,32 @@ var ts; if (!node) return node; switch (node.kind) { - case 122: - if (node.parent.parent.kind === 191) { + case 124: + if (node.parent.parent.kind === 195) { return node; } node = node.parent; break; - case 190: - case 156: - case 157: + case 194: + case 158: + case 159: if (!includeFunctions) { continue; } - case 126: - case 125: case 128: case 127: - case 129: case 130: + case 129: case 131: + case 132: + case 133: return node; } } } ts.getSuperContainer = getSuperContainer; function getInvokedExpression(node) { - if (node.kind === 153) { + if (node.kind === 155) { return node.tag; } return node.expression; @@ -3395,8 +3576,6 @@ var ts; case 94: case 79: case 9: - case 147: - case 148: case 149: case 150: case 151: @@ -3406,61 +3585,64 @@ var ts; case 155: case 156: case 157: - case 160: case 158: case 159: - case 161: case 162: + case 160: + case 161: case 163: case 164: - case 167: case 165: - case 10: + case 166: + case 167: + case 171: case 168: + case 10: + case 172: return true; - case 121: - while (node.parent.kind === 121) { + case 123: + while (node.parent.kind === 123) { node = node.parent; } - return node.parent.kind === 138; + return node.parent.kind === 140; case 64: - if (node.parent.kind === 138) { + if (node.parent.kind === 140) { return true; } case 7: case 8: var parent = node.parent; switch (parent.kind) { - case 188: - case 124: + case 192: case 126: - case 125: - case 206: - case 204: - case 146: + case 128: + case 127: + case 210: + case 208: + case 148: return parent.initializer === node; - case 173: - case 174: - case 175: - case 176: - case 181: - case 182: - case 183: - case 200: + case 177: + case 178: + case 179: + case 180: case 185: - case 183: + case 186: + case 187: + case 204: + case 189: + case 187: return parent.expression === node; - case 177: + case 181: var forStatement = parent; - return (forStatement.initializer === node && forStatement.initializer.kind !== 189) || forStatement.condition === node || forStatement.iterator === node; - case 178: + return (forStatement.initializer === node && forStatement.initializer.kind !== 193) || forStatement.condition === node || forStatement.iterator === node; + case 182: var forInStatement = parent; - return (forInStatement.initializer === node && forInStatement.initializer.kind !== 189) || forInStatement.expression === node; - case 154: + return (forInStatement.initializer === node && forInStatement.initializer.kind !== 193) || forInStatement.expression === node; + case 156: return node === parent.expression; - case 169: + case 173: return node === parent.expression; - case 122: + case 124: return node === parent.expression; default: if (isExpression(parent)) { @@ -3471,13 +3653,93 @@ var ts; return false; } ts.isExpression = isExpression; + function isUnaryExpression(node) { + switch (node.kind) { + case 156: + case 160: + case 161: + case 162: + case 163: + case 164: + case 165: + return true; + default: + return ts.isLeftHandSideExpression(node); + } + } + ts.isUnaryExpression = isUnaryExpression; + function isLabeledOrIterationOrSwitchStatement(node) { + switch (node.kind) { + case 179: + case 180: + case 181: + case 182: + case 187: + case 188: + return true; + } + return false; + } + ts.isLabeledOrIterationOrSwitchStatement = isLabeledOrIterationOrSwitchStatement; + function isLogicalBinary(node) { + switch (node.operator) { + case 48: + case 49: + return true; + } + return false; + } + ts.isLogicalBinary = isLogicalBinary; + function isAssignment(node) { + switch (node.operator) { + case 52: + case 53: + case 54: + case 55: + case 56: + case 57: + case 58: + case 59: + case 60: + case 61: + case 62: + case 63: + return true; + } + return false; + } + ts.isAssignment = isAssignment; + function isDestructuringAssignment(node) { + if (node.operator === 52) { + var left = node.left; + while (left.kind === 157) { + left = left.expression; + } + switch (left.kind) { + case 150: + case 149: + return true; + } + } + return false; + } + ts.isDestructuringAssignment = isDestructuringAssignment; + function isAnyAccessor(node) { + switch (node.kind) { + case 132: + case 133: + return true; + } + return false; + } + ts.isAnyAccessor = isAnyAccessor; function isInstantiatedModule(node, preserveConstEnums) { var moduleState = ts.getModuleInstanceState(node); return moduleState === 1 || (preserveConstEnums && moduleState === 2); } ts.isInstantiatedModule = isInstantiatedModule; function isExternalModuleImportDeclaration(node) { - return node.kind === 197 && node.moduleReference.kind === 199; + return node.kind === 201 && node.moduleReference.kind === 203; } ts.isExternalModuleImportDeclaration = isExternalModuleImportDeclaration; function getExternalModuleImportDeclarationExpression(node) { @@ -3486,26 +3748,26 @@ var ts; } ts.getExternalModuleImportDeclarationExpression = getExternalModuleImportDeclarationExpression; function isInternalModuleImportDeclaration(node) { - return node.kind === 197 && node.moduleReference.kind !== 199; + return node.kind === 201 && node.moduleReference.kind !== 203; } ts.isInternalModuleImportDeclaration = isInternalModuleImportDeclaration; function hasDotDotDotToken(node) { - return node && node.kind === 124 && node.dotDotDotToken !== undefined; + return node && node.kind === 126 && node.dotDotDotToken !== undefined; } ts.hasDotDotDotToken = hasDotDotDotToken; function hasQuestionToken(node) { if (node) { switch (node.kind) { - case 124: + case 126: + return node.questionToken !== undefined; + case 130: + case 129: return node.questionToken !== undefined; + case 209: + case 208: case 128: case 127: return node.questionToken !== undefined; - case 205: - case 204: - case 126: - case 125: - return node.questionToken !== undefined; } } return false; @@ -3527,10 +3789,18 @@ var ts; return 10 <= kind && kind <= 13; } ts.isTemplateLiteralKind = isTemplateLiteralKind; + function isTemplateLiteralOrTemplateExpression(node) { + return node.kind === 168 || isTemplateLiteralKind(node.kind); + } + ts.isTemplateLiteralOrTemplateExpression = isTemplateLiteralOrTemplateExpression; function isBindingPattern(node) { - return node.kind === 145 || node.kind === 144; + return node.kind === 147 || node.kind === 146; } ts.isBindingPattern = isBindingPattern; + function isIdentifierOrBindingPattern(node) { + return node.kind === 64 || isBindingPattern(node); + } + ts.isIdentifierOrBindingPattern = isIdentifierOrBindingPattern; function isInAmbientContext(node) { while (node) { if (node.flags & (2 | 1024)) { @@ -3543,27 +3813,27 @@ var ts; ts.isInAmbientContext = isInAmbientContext; function isDeclaration(node) { switch (node.kind) { - case 123: - case 124: - case 188: - case 146: - case 126: case 125: - case 204: - case 205: - case 206: + case 126: + case 192: + case 148: case 128: case 127: - case 190: + case 208: + case 209: + case 210: case 130: - case 131: case 129: - case 191: - case 192: - case 193: case 194: + case 132: + case 133: + case 131: case 195: + case 196: case 197: + case 198: + case 199: + case 201: return true; } return false; @@ -3571,39 +3841,53 @@ var ts; ts.isDeclaration = isDeclaration; function isStatement(n) { switch (n.kind) { - case 180: + case 184: + case 183: + case 191: case 179: - case 187: - case 175: - case 173: - case 172: - case 178: case 177: - case 174: - case 184: + case 176: + case 182: case 181: - case 183: + case 178: + case 188: + case 185: + case 187: case 93: + case 189: + case 190: + case 175: + case 180: case 186: - case 171: - case 176: - case 182: - case 198: + case 202: return true; default: return false; } } ts.isStatement = isStatement; + function needsParenthesisForPropertyAccess(expression) { + if (expression.parent) { + switch (expression.parent.kind) { + case 177: + case 189: + case 185: + case 157: + return false; + } + } + return !ts.isLeftHandSideExpression(expression); + } + ts.needsParenthesisForPropertyAccess = needsParenthesisForPropertyAccess; function isDeclarationOrFunctionExpressionOrCatchVariableName(name) { if (name.kind !== 64 && name.kind !== 8 && name.kind !== 7) { return false; } var parent = name.parent; - if (isDeclaration(parent) || parent.kind === 156) { + if (isDeclaration(parent) || parent.kind === 158) { return parent.name === name; } - if (parent.kind === 203) { + if (parent.kind === 207) { return parent.name === name; } return false; @@ -3645,16 +3929,16 @@ var ts; ts.tryResolveScriptReference = tryResolveScriptReference; function getAncestor(node, kind) { switch (kind) { - case 191: + case 195: while (node) { switch (node.kind) { - case 191: - return node; - case 194: - case 192: - case 193: case 195: + return node; + case 198: + case 196: case 197: + case 199: + case 201: return undefined; default: node = node.parent; @@ -3709,13 +3993,17 @@ var ts; } ts.getFileReferenceFromReferencePath = getFileReferenceFromReferencePath; function isKeyword(token) { - return 65 <= token && token <= 120; + return 65 <= token && token <= 122; } ts.isKeyword = isKeyword; function isTrivia(token) { return 2 <= token && token <= 6; } ts.isTrivia = isTrivia; + function isAsyncFunction(node) { + return (node.flags & 16384) !== 0; + } + ts.isAsyncFunction = isAsyncFunction; function isModifier(token) { switch (token) { case 107: @@ -3725,6 +4013,7 @@ var ts; case 77: case 113: case 69: + case 121: return true; } return false; @@ -3904,10 +4193,31 @@ var ts; } } ts.createDiagnosticCollection = createDiagnosticCollection; + function reportUnexpectedNode(node) { + var nodeKind = node ? getSyntaxKind(node.kind) : "Unknown"; + ts.Debug.fail("Unexpected node: " + nodeKind); + } + ts.reportUnexpectedNode = reportUnexpectedNode; + function reportUnexpectedNodeAfterVisit(visited, node) { + var visitedKind = visited ? getSyntaxKind(visited.kind) : "Unknown"; + var nodeKind = node ? getSyntaxKind(node.kind) : "Unknown"; + ts.Debug.fail("Unexpected node after visit: " + visitedKind + ", source: " + nodeKind); + } + ts.reportUnexpectedNodeAfterVisit = reportUnexpectedNodeAfterVisit; + function getSyntaxKind(kind) { + var nodeKind; + if (typeof ts.SyntaxKind === "object") { + nodeKind = ts.SyntaxKind[kind]; + } + else { + nodeKind = "SyntaxKind[" + String(kind) + "]"; + } + return nodeKind; + } })(ts || (ts = {})); var ts; (function (ts) { - var nodeConstructors = new Array(209); + var nodeConstructors = new Array(213); ts.parseTime = 0; function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); @@ -3944,152 +4254,154 @@ var ts; var visitNodes = cbNodeArray ? visitNodeArray : visitEachNode; var cbNodes = cbNodeArray || cbNode; switch (node.kind) { - case 121: - return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); case 123: + return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); + case 125: return visitNode(cbNode, node.name) || visitNode(cbNode, node.constraint) || visitNode(cbNode, node.expression); - case 124: case 126: - case 125: - case 204: - case 205: - case 188: - case 146: + case 128: + case 127: + case 208: + case 209: + case 192: + case 148: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.propertyName) || visitNode(cbNode, node.dotDotDotToken) || visitNode(cbNode, node.name) || visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.type) || visitNode(cbNode, node.initializer); - case 136: - case 137: - case 132: - case 133: + case 138: + case 139: case 134: + case 135: + case 136: return visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type); - case 128: - case 127: - case 129: case 130: + case 129: case 131: - case 156: - case 190: - case 157: + case 132: + case 133: + case 158: + case 194: + case 159: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.name) || visitNode(cbNode, node.questionToken) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.parameters) || visitNode(cbNode, node.type) || visitNode(cbNode, node.body); - case 135: + case 137: return visitNode(cbNode, node.typeName) || visitNodes(cbNodes, node.typeArguments); - case 138: - return visitNode(cbNode, node.exprName); - case 139: - return visitNodes(cbNodes, node.members); case 140: - return visitNode(cbNode, node.elementType); + return visitNode(cbNode, node.exprName); case 141: - return visitNodes(cbNodes, node.elementTypes); + return visitNodes(cbNodes, node.members); case 142: - return visitNodes(cbNodes, node.types); + return visitNode(cbNode, node.elementType); case 143: - return visitNode(cbNode, node.type); + return visitNodes(cbNodes, node.elementTypes); case 144: + return visitNodes(cbNodes, node.types); case 145: - return visitNodes(cbNodes, node.elements); + return visitNode(cbNode, node.type); + case 146: case 147: return visitNodes(cbNodes, node.elements); - case 148: - return visitNodes(cbNodes, node.properties); case 149: - return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); + return visitNodes(cbNodes, node.elements); case 150: - return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); + return visitNodes(cbNodes, node.properties); case 151: + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.name); case 152: - return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); + return visitNode(cbNode, node.expression) || visitNode(cbNode, node.argumentExpression); case 153: - return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); case 154: - return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); + return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.typeArguments) || visitNodes(cbNodes, node.arguments); case 155: - return visitNode(cbNode, node.expression); - case 158: - return visitNode(cbNode, node.expression); - case 159: + return visitNode(cbNode, node.tag) || visitNode(cbNode, node.template); + case 156: + return visitNode(cbNode, node.type) || visitNode(cbNode, node.expression); + case 157: return visitNode(cbNode, node.expression); case 160: return visitNode(cbNode, node.expression); case 161: - return visitNode(cbNode, node.operand); - case 166: - return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); + return visitNode(cbNode, node.expression); case 162: + return visitNode(cbNode, node.expression); + case 164: return visitNode(cbNode, node.operand); + case 169: + return visitNode(cbNode, node.asteriskToken) || visitNode(cbNode, node.expression); case 163: + return visitNode(cbNode, node.expression); + case 165: + return visitNode(cbNode, node.operand); + case 166: return visitNode(cbNode, node.left) || visitNode(cbNode, node.right); - case 164: - return visitNode(cbNode, node.condition) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.whenFalse); case 167: + return visitNode(cbNode, node.condition) || visitNode(cbNode, node.whenTrue) || visitNode(cbNode, node.whenFalse); + case 171: return visitNode(cbNode, node.expression); - case 170: - case 196: + case 174: + case 200: return visitNodes(cbNodes, node.statements); - case 207: + case 211: return visitNodes(cbNodes, node.statements) || visitNode(cbNode, node.endOfFileToken); - case 171: + case 175: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.declarationList); - case 189: + case 193: return visitNodes(cbNodes, node.declarations); - case 173: + case 177: return visitNode(cbNode, node.expression); - case 174: + case 178: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.thenStatement) || visitNode(cbNode, node.elseStatement); - case 175: + case 179: return visitNode(cbNode, node.statement) || visitNode(cbNode, node.expression); - case 176: + case 180: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 177: + case 181: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.condition) || visitNode(cbNode, node.iterator) || visitNode(cbNode, node.statement); - case 178: + case 182: return visitNode(cbNode, node.initializer) || visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 179: - case 180: + case 183: + case 184: return visitNode(cbNode, node.label); - case 181: + case 185: return visitNode(cbNode, node.expression); - case 182: + case 186: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.statement); - case 183: + case 187: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.clauses); - case 200: + case 204: return visitNode(cbNode, node.expression) || visitNodes(cbNodes, node.statements); - case 201: + case 205: return visitNodes(cbNodes, node.statements); - case 184: + case 188: return visitNode(cbNode, node.label) || visitNode(cbNode, node.statement); - case 185: + case 189: return visitNode(cbNode, node.expression); - case 186: + case 190: return visitNode(cbNode, node.tryBlock) || visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); - case 203: + case 207: return visitNode(cbNode, node.name) || visitNode(cbNode, node.type) || visitNode(cbNode, node.block); - case 191: + case 195: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); - case 192: + case 196: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.typeParameters) || visitNodes(cbNodes, node.heritageClauses) || visitNodes(cbNodes, node.members); - case 193: + case 197: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.type); - case 194: + case 198: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNodes(cbNodes, node.members); - case 206: + case 210: return visitNode(cbNode, node.name) || visitNode(cbNode, node.initializer); - case 195: + case 199: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.body); - case 197: + case 201: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.name) || visitNode(cbNode, node.moduleReference); - case 198: + case 202: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, node.exportName); - case 165: + case 168: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); - case 169: + case 173: return visitNode(cbNode, node.expression) || visitNode(cbNode, node.literal); - case 122: + case 124: return visitNode(cbNode, node.expression); - case 202: + case 206: return visitNodes(cbNodes, node.types); - case 199: + case 203: return visitNode(cbNode, node.expression); } } @@ -4158,6 +4470,7 @@ var ts; case 77: return 1; case 113: return 2; case 69: return 4096; + case 121: return 16384; } return 0; } @@ -4474,7 +4787,7 @@ var ts; var identifierCount = 0; var nodeCount = 0; var token; - var sourceFile = createNode(207, 0); + var sourceFile = createNode(211, 0); sourceFile.pos = 0; sourceFile.end = sourceText.length; sourceFile.text = sourceText; @@ -4520,6 +4833,12 @@ var ts; function setGeneratorParameterContext(val) { setContextFlag(val, 8); } + function setAwaitContext(val) { + setContextFlag(val, 64); + } + function setAsyncParameterContext(val) { + setContextFlag(val, 32); + } function allowInAnd(func) { if (contextFlags & 2) { setDisallowInContext(false); @@ -4538,21 +4857,16 @@ var ts; setDisallowInContext(false); return result; } - function doInYieldContext(func) { - if (contextFlags & 4) { - return func(); - } - setYieldContext(true); + function doOutsideOfYieldOrAwaitOrParameterContext(func) { + var saveContextFlags = contextFlags & 108; + contextFlags &= ~saveContextFlags; var result = func(); - setYieldContext(false); + contextFlags |= saveContextFlags; return result; } - function doOutsideOfYieldContext(func) { - if (contextFlags & 4) { - setYieldContext(false); - var result = func(); - setYieldContext(true); - return result; + function doOutsideOfYieldOrAwaitOrParameterContextWhenInParameter(func) { + if (contextFlags & (32 | 8)) { + return doOutsideOfYieldOrAwaitOrParameterContext(func); } return func(); } @@ -4568,6 +4882,12 @@ var ts; function inDisallowInContext() { return (contextFlags & 2) !== 0; } + function inAwaitContext() { + return (contextFlags & 64) !== 0; + } + function inAsyncParameterContext() { + return (contextFlags & 32) !== 0; + } function parseErrorAtCurrentToken(message, arg0) { var start = scanner.getTokenPos(); var length = scanner.getTextPos() - start; @@ -4632,6 +4952,9 @@ var ts; if (token === 109 && inYieldContext()) { return false; } + if (token === 122 && inAwaitContext()) { + return false; + } return inStrictModeContext() ? token > 109 : token > 100; } function parseExpected(kind, diagnosticMessage) { @@ -4744,37 +5067,45 @@ var ts; return parseIdentifierName(); } function parseComputedPropertyName() { - var node = createNode(122); + var node = createNode(124); parseExpected(18); - var yieldContext = inYieldContext(); - if (inGeneratorParameterContext()) { - setYieldContext(false); - } - node.expression = allowInAnd(parseExpression); - if (inGeneratorParameterContext()) { - setYieldContext(yieldContext); - } + node.expression = doOutsideOfYieldOrAwaitOrParameterContextWhenInParameter(parseExpression); parseExpected(19); return finishNode(node); } - function parseContextualModifier(t) { - return token === t && tryParse(nextTokenCanFollowModifier); + function allowInAndParseExpression() { + return allowInAnd(parseExpression); + } + function parseContextualModifier(t, isArrowFunction) { + return token === t && tryParse(isArrowFunction ? nextTokenCanFollowModifierForArrowFunction : nextTokenCanFollowModifier); } - function nextTokenCanFollowModifier() { + function nextTokenCanFollowModifierForArrowFunction() { + return nextTokenCanFollowModifier(true); + } + function nextTokenCanFollowModifier(isArrowFunction) { nextToken(); - return canFollowModifier(); + return canFollowModifier(isArrowFunction); + } + function parseAnyContextualModifier(isArrowFunction) { + return ts.isModifier(token) && tryParse(isArrowFunction ? nextTokenCanFollowContextualModifierForArrowFunction : nextTokenCanFollowContextualModifier); } - function parseAnyContextualModifier() { - return ts.isModifier(token) && tryParse(nextTokenCanFollowContextualModifier); + function nextTokenCanFollowContextualModifierForArrowFunction() { + return nextTokenCanFollowContextualModifier(true); } - function nextTokenCanFollowContextualModifier() { + function nextTokenCanFollowContextualModifier(isArrowFunction) { if (token === 69) { return nextToken() === 76; } nextToken(); - return canFollowModifier(); + return canFollowModifier(isArrowFunction); } - function canFollowModifier() { + function canFollowModifier(isArrowFunction) { + if (isArrowFunction) { + if (scanner.hasPrecedingLineBreak()) { + return false; + } + return token === 16 || token === 24; + } return token === 18 || token === 14 || token === 35 || isLiteralPropertyName(); } function isListElement(parsingContext, inErrorRecovery) { @@ -4804,9 +5135,9 @@ var ts; case 8: return isIdentifier() && !isNotHeritageClauseTypeName(); case 9: - return isIdentifierOrPattern(); + return isIdentifierOrBindingPattern(); case 11: - return token === 23 || token === 21 || isIdentifierOrPattern(); + return token === 23 || token === 21 || isIdentifierOrBindingPattern(); case 16: return isIdentifier(); case 12: @@ -4946,7 +5277,7 @@ var ts; if (ts.containsParseError(node)) { return undefined; } - var nodeContextFlags = node.parserContextFlags & 31; + var nodeContextFlags = node.parserContextFlags & 127; if (nodeContextFlags !== contextFlags) { return undefined; } @@ -4992,12 +5323,12 @@ var ts; function isReusableModuleElement(node) { if (node) { switch (node.kind) { - case 197: - case 198: - case 191: - case 192: + case 201: + case 202: case 195: - case 194: + case 196: + case 199: + case 198: return true; } return isReusableStatement(node); @@ -5007,12 +5338,12 @@ var ts; function isReusableClassMember(node) { if (node) { switch (node.kind) { - case 129: - case 134: - case 128: - case 130: case 131: - case 126: + case 136: + case 130: + case 132: + case 133: + case 128: return true; } } @@ -5021,8 +5352,8 @@ var ts; function isReusableSwitchClause(node) { if (node) { switch (node.kind) { - case 200: - case 201: + case 204: + case 205: return true; } } @@ -5031,55 +5362,55 @@ var ts; function isReusableStatement(node) { if (node) { switch (node.kind) { - case 190: - case 171: - case 170: + case 194: + case 175: case 174: - case 173: - case 185: - case 181: - case 183: - case 180: - case 179: case 178: case 177: - case 176: + case 189: + case 185: + case 187: + case 184: + case 183: case 182: - case 172: + case 181: + case 180: case 186: - case 184: - case 175: - case 187: + case 176: + case 190: + case 188: + case 179: + case 191: return true; } } return false; } function isReusableEnumMember(node) { - return node.kind === 206; + return node.kind === 210; } function isReusableTypeMember(node) { if (node) { switch (node.kind) { - case 133: + case 135: + case 129: + case 136: case 127: case 134: - case 125: - case 132: return true; } } return false; } function isReusableVariableDeclaration(node) { - if (node.kind !== 188) { + if (node.kind !== 192) { return false; } var variableDeclarator = node; return variableDeclarator.initializer === undefined; } function isReusableParameter(node) { - if (node.kind !== 124) { + if (node.kind !== 126) { return false; } var parameter = node; @@ -5148,7 +5479,7 @@ var ts; function parseEntityName(allowReservedWords, diagnosticMessage) { var entity = parseIdentifier(diagnosticMessage); while (parseOptional(20)) { - var node = createNode(121, entity.pos); + var node = createNode(123, entity.pos); node.left = entity; node.right = parseRightSideOfDot(allowReservedWords); entity = finishNode(node); @@ -5170,7 +5501,7 @@ var ts; return finishNode(node); } function parseTemplateExpression() { - var template = createNode(165); + var template = createNode(168); template.head = parseLiteralNode(); ts.Debug.assert(template.head.kind === 11, "Template head has wrong token kind"); var templateSpans = []; @@ -5183,7 +5514,7 @@ var ts; return finishNode(template); } function parseTemplateSpan() { - var span = createNode(169); + var span = createNode(173); span.expression = allowInAnd(parseExpression); var literal; if (token === 15) { @@ -5212,7 +5543,7 @@ var ts; return node; } function parseTypeReference() { - var node = createNode(135); + var node = createNode(137); node.typeName = parseEntityName(false, ts.Diagnostics.Type_expected); if (!scanner.hasPrecedingLineBreak() && token === 24) { node.typeArguments = parseBracketedList(17, parseType, 24, 25); @@ -5220,13 +5551,13 @@ var ts; return finishNode(node); } function parseTypeQuery() { - var node = createNode(138); + var node = createNode(140); parseExpected(96); node.exprName = parseEntityName(true); return finishNode(node); } function parseTypeParameter() { - var node = createNode(123); + var node = createNode(125); node.name = parseIdentifier(); if (parseOptional(78)) { if (isStartOfType() || !isStartOfExpression()) { @@ -5250,7 +5581,7 @@ var ts; return undefined; } function isStartOfParameter() { - return token === 21 || isIdentifierOrPattern() || ts.isModifier(token); + return token === 21 || isIdentifierOrBindingPattern() || ts.isModifier(token); } function setModifiers(node, modifiers) { if (modifiers) { @@ -5259,25 +5590,22 @@ var ts; } } function parseParameter() { - var node = createNode(124); + var node = createNode(126); setModifiers(node, parseModifiers()); node.dotDotDotToken = parseOptionalToken(21); - node.name = inGeneratorParameterContext() ? doInYieldContext(parseIdentifierOrPattern) : parseIdentifierOrPattern(); + node.name = parseIdentifierOrBindingPattern(true); if (ts.getFullWidth(node.name) === 0 && node.flags === 0 && ts.isModifier(token)) { nextToken(); } node.questionToken = parseOptionalToken(50); node.type = parseParameterType(); - node.initializer = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseParameterInitializer) : parseParameterInitializer(); + node.initializer = parseBindingElementInitializer(true); return finishNode(node); } - function parseParameterInitializer() { - return parseInitializer(true); - } - function fillSignature(returnToken, yieldAndGeneratorParameterContext, requireCompleteParameterList, signature) { + function fillSignature(returnToken, yieldAndGeneratorParameterContext, awaitAndAsyncParameterContext, requireCompleteParameterList, signature) { var returnTokenRequired = returnToken === 32; signature.typeParameters = parseTypeParameters(); - signature.parameters = parseParameterList(yieldAndGeneratorParameterContext, requireCompleteParameterList); + signature.parameters = parseParameterList(yieldAndGeneratorParameterContext, awaitAndAsyncParameterContext, requireCompleteParameterList); if (returnTokenRequired) { parseExpected(returnToken); signature.type = parseType(); @@ -5286,15 +5614,27 @@ var ts; signature.type = parseType(); } } - function parseParameterList(yieldAndGeneratorParameterContext, requireCompleteParameterList) { + function parseParameterList(yieldAndGeneratorParameterContext, awaitAndAsyncParameterContext, requireCompleteParameterList) { if (parseExpected(16)) { - var savedYieldContext = inYieldContext(); - var savedGeneratorParameterContext = inGeneratorParameterContext(); - setYieldContext(yieldAndGeneratorParameterContext); - setGeneratorParameterContext(yieldAndGeneratorParameterContext); + if (yieldAndGeneratorParameterContext || awaitAndAsyncParameterContext) { + var saveContextFlags = contextFlags & 108; + if (yieldAndGeneratorParameterContext) { + contextFlags |= 4 | 8; + } + else { + contextFlags &= ~8; + } + if (awaitAndAsyncParameterContext) { + contextFlags |= 64 | 32; + } + else { + contextFlags &= ~32; + } + } var result = parseDelimitedList(15, parseParameter); - setYieldContext(savedYieldContext); - setGeneratorParameterContext(savedGeneratorParameterContext); + if (yieldAndGeneratorParameterContext || awaitAndAsyncParameterContext) { + contextFlags = (contextFlags & ~108) | saveContextFlags; + } if (!parseExpected(17) && requireCompleteParameterList) { return undefined; } @@ -5302,6 +5642,9 @@ var ts; } return requireCompleteParameterList ? undefined : createMissingList(); } + function parseDelimitedParameterList() { + return parseDelimitedList(15, parseParameter); + } function parseTypeMemberSemicolon() { if (parseSemicolon()) { return; @@ -5310,10 +5653,10 @@ var ts; } function parseSignatureMember(kind) { var node = createNode(kind); - if (kind === 133) { + if (kind === 135) { parseExpected(87); } - fillSignature(51, false, false, node); + fillSignature(51, false, false, false, node); parseTypeMemberSemicolon(); return finishNode(node); } @@ -5351,7 +5694,7 @@ var ts; } function parseIndexSignatureDeclaration(modifiers) { var fullStart = modifiers ? modifiers.pos : scanner.getStartPos(); - var node = createNode(134, fullStart); + var node = createNode(136, fullStart); setModifiers(node, modifiers); node.parameters = parseBracketedList(15, parseParameter, 18, 19); node.type = parseTypeAnnotation(); @@ -5363,15 +5706,15 @@ var ts; var name = parsePropertyName(); var questionToken = parseOptionalToken(50); if (token === 16 || token === 24) { - var method = createNode(127, fullStart); + var method = createNode(129, fullStart); method.name = name; method.questionToken = questionToken; - fillSignature(51, false, false, method); + fillSignature(51, false, false, false, method); parseTypeMemberSemicolon(); return finishNode(method); } else { - var property = createNode(125, fullStart); + var property = createNode(127, fullStart); property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); @@ -5409,12 +5752,12 @@ var ts; switch (token) { case 16: case 24: - return parseSignatureMember(132); + return parseSignatureMember(134); case 18: return isIndexSignature() ? parseIndexSignatureDeclaration(undefined) : parsePropertyOrMethodSignature(); case 87: if (lookAhead(isStartOfConstructSignature)) { - return parseSignatureMember(133); + return parseSignatureMember(135); } case 8: case 7: @@ -5440,7 +5783,7 @@ var ts; return token === 16 || token === 24; } function parseTypeLiteral() { - var node = createNode(139); + var node = createNode(141); node.members = parseObjectTypeMembers(); return finishNode(node); } @@ -5456,12 +5799,12 @@ var ts; return members; } function parseTupleType() { - var node = createNode(141); + var node = createNode(143); node.elementTypes = parseBracketedList(18, parseType, 18, 19); return finishNode(node); } function parseParenthesizedType() { - var node = createNode(143); + var node = createNode(145); parseExpected(16); node.type = parseType(); parseExpected(17); @@ -5469,10 +5812,10 @@ var ts; } function parseFunctionOrConstructorType(kind) { var node = createNode(kind); - if (kind === 137) { + if (kind === 139) { parseExpected(87); } - fillSignature(32, false, false, node); + fillSignature(32, false, false, false, node); return finishNode(node); } function parseKeywordAndNoDot() { @@ -5528,7 +5871,7 @@ var ts; var type = parseNonArrayType(); while (!scanner.hasPrecedingLineBreak() && parseOptional(18)) { parseExpected(19); - var node = createNode(140, type.pos); + var node = createNode(142, type.pos); node.elementType = type; type = finishNode(node); } @@ -5543,7 +5886,7 @@ var ts; types.push(parseArrayTypeOrHigher()); } types.end = getNodeEnd(); - var node = createNode(142, type.pos); + var node = createNode(144, type.pos); node.types = types; type = finishNode(node); } @@ -5575,21 +5918,14 @@ var ts; return false; } function parseType() { - var savedYieldContext = inYieldContext(); - var savedGeneratorParameterContext = inGeneratorParameterContext(); - setYieldContext(false); - setGeneratorParameterContext(false); - var result = parseTypeWorker(); - setYieldContext(savedYieldContext); - setGeneratorParameterContext(savedGeneratorParameterContext); - return result; + return doOutsideOfYieldOrAwaitOrParameterContext(parseTypeWorker); } function parseTypeWorker() { if (isStartOfFunctionType()) { - return parseFunctionOrConstructorType(136); + return parseFunctionOrConstructorType(138); } if (token === 87) { - return parseFunctionOrConstructorType(137); + return parseFunctionOrConstructorType(139); } return parseUnionTypeOrHigher(); } @@ -5625,6 +5961,7 @@ var ts; case 39: case 24: case 64: + case 122: case 109: return true; default: @@ -5644,6 +5981,15 @@ var ts; } return expr; } + function parseBindingElementInitializer(inParameter) { + return doOutsideOfYieldOrAwaitOrParameterContextWhenInParameter(inParameter ? parseParameterInitializer : parseNonParameterInitializer); + } + function parseParameterInitializer() { + return parseInitializer(true); + } + function parseNonParameterInitializer() { + return parseInitializer(false); + } function parseInitializer(inParameter) { if (token !== 52) { if (scanner.hasPrecedingLineBreak() || (inParameter && token === 14) || !isStartOfExpression()) { @@ -5689,7 +6035,7 @@ var ts; return !scanner.hasPrecedingLineBreak() && isIdentifier(); } function parseYieldExpression() { - var node = createNode(166); + var node = createNode(169); nextToken(); if (!scanner.hasPrecedingLineBreak() && (token === 35 || isStartOfExpression())) { node.asteriskToken = parseOptionalToken(35); @@ -5702,15 +6048,15 @@ var ts; } function parseSimpleArrowFunctionExpression(identifier) { ts.Debug.assert(token === 32, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); - var node = createNode(157, identifier.pos); - var parameter = createNode(124, identifier.pos); + var node = createNode(159, identifier.pos); + var parameter = createNode(126, identifier.pos); parameter.name = identifier; finishNode(parameter); node.parameters = [parameter]; node.parameters.pos = parameter.pos; node.parameters.end = parameter.end; parseExpected(32); - node.body = parseArrowFunctionExpressionBody(); + node.body = parseArrowFunctionExpressionBody(false); return finishNode(node); } function tryParseParenthesizedArrowFunctionExpression() { @@ -5723,7 +6069,7 @@ var ts; return undefined; } if (parseExpected(32) || token === 14) { - arrowFunction.body = parseArrowFunctionExpressionBody(); + arrowFunction.body = parseArrowFunctionExpressionBody(!!(arrowFunction.flags & 16384)); } else { arrowFunction.body = parseIdentifier(); @@ -5731,7 +6077,7 @@ var ts; return finishNode(arrowFunction); } function isParenthesizedArrowFunctionExpression() { - if (token === 16 || token === 24) { + if (token === 16 || token === 24 || token === 121) { return lookAhead(isParenthesizedArrowFunctionExpressionWorker); } if (token === 32) { @@ -5740,6 +6086,9 @@ var ts; return 0; } function isParenthesizedArrowFunctionExpressionWorker() { + if (token === 121 && !parseContextualModifier(121, true)) { + return 0; + } var first = token; var second = nextToken(); if (first === 16) { @@ -5777,8 +6126,10 @@ var ts; return parseParenthesizedArrowFunctionExpressionHead(false); } function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity) { - var node = createNode(157); - fillSignature(51, false, !allowAmbiguity, node); + var node = createNode(159); + setModifiers(node, parseModifiers(true)); + var isAsync = !!(node.flags & 16384); + fillSignature(51, false, isAsync, !allowAmbiguity, node); if (!node.parameters) { return undefined; } @@ -5787,20 +6138,24 @@ var ts; } return node; } - function parseArrowFunctionExpressionBody() { + function parseArrowFunctionExpressionBody(isAsync) { if (token === 14) { - return parseFunctionBlock(false, false); + return parseFunctionBlock(false, isAsync, false); } if (isStartOfStatement(true) && !isStartOfExpressionStatement() && token !== 82) { - return parseFunctionBlock(false, true); + return parseFunctionBlock(false, isAsync, true); } - return parseAssignmentExpressionOrHigher(); + var savedAwaitContext = inAwaitContext(); + setAwaitContext(isAsync); + var result = parseAssignmentExpressionOrHigher(); + setAwaitContext(savedAwaitContext); + return result; } function parseConditionalExpressionRest(leftOperand) { if (!parseOptional(50)) { return leftOperand; } - var node = createNode(164, leftOperand.pos); + var node = createNode(167, leftOperand.pos); node.condition = leftOperand; node.whenTrue = allowInAnd(parseAssignmentExpressionOrHigher); parseExpected(51); @@ -5872,38 +6227,56 @@ var ts; return -1; } function makeBinaryExpression(left, operator, right) { - var node = createNode(163, left.pos); + var node = createNode(166, left.pos); node.left = left; node.operator = operator; node.right = right; return finishNode(node); } function parsePrefixUnaryExpression() { - var node = createNode(161); + var node = createNode(164); node.operator = token; nextToken(); node.operand = parseUnaryExpressionOrHigher(); return finishNode(node); } function parseDeleteExpression() { - var node = createNode(158); + var node = createNode(160); nextToken(); node.expression = parseUnaryExpressionOrHigher(); return finishNode(node); } function parseTypeOfExpression() { - var node = createNode(159); + var node = createNode(161); nextToken(); node.expression = parseUnaryExpressionOrHigher(); return finishNode(node); } function parseVoidExpression() { - var node = createNode(160); + var node = createNode(162); + nextToken(); + node.expression = parseUnaryExpressionOrHigher(); + return finishNode(node); + } + function isAwaitExpression() { + if (token === 122) { + if (inAwaitContext()) { + return true; + } + return lookAhead(nextTokenIsIdentifierOnSameLine); + } + return false; + } + function parseAwaitExpression() { + var node = createNode(163); nextToken(); node.expression = parseUnaryExpressionOrHigher(); return finishNode(node); } function parseUnaryExpressionOrHigher() { + if (isAwaitExpression()) { + return parseAwaitExpression(); + } switch (token) { case 33: case 34: @@ -5928,7 +6301,7 @@ var ts; var expression = parseLeftHandSideExpressionOrHigher(); ts.Debug.assert(isLeftHandSideExpression(expression)); if ((token === 38 || token === 39) && !scanner.hasPrecedingLineBreak()) { - var node = createNode(162, expression.pos); + var node = createNode(165, expression.pos); node.operand = expression; node.operator = token; nextToken(); @@ -5949,14 +6322,14 @@ var ts; if (token === 16 || token === 20) { return expression; } - var node = createNode(149, expression.pos); + var node = createNode(151, expression.pos); node.expression = expression; parseExpected(20, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); node.name = parseRightSideOfDot(true); return finishNode(node); } function parseTypeAssertion() { - var node = createNode(154); + var node = createNode(156); parseExpected(24); node.type = parseType(); parseExpected(25); @@ -5967,14 +6340,14 @@ var ts; while (true) { var dotOrBracketStart = scanner.getTokenPos(); if (parseOptional(20)) { - var propertyAccess = createNode(149, expression.pos); + var propertyAccess = createNode(151, expression.pos); propertyAccess.expression = expression; propertyAccess.name = parseRightSideOfDot(true); expression = finishNode(propertyAccess); continue; } if (parseOptional(18)) { - var indexedAccess = createNode(150, expression.pos); + var indexedAccess = createNode(152, expression.pos); indexedAccess.expression = expression; if (token !== 19) { indexedAccess.argumentExpression = allowInAnd(parseExpression); @@ -5988,7 +6361,7 @@ var ts; continue; } if (token === 10 || token === 11) { - var tagExpression = createNode(153, expression.pos); + var tagExpression = createNode(155, expression.pos); tagExpression.tag = expression; tagExpression.template = token === 10 ? parseLiteralNode() : parseTemplateExpression(); expression = finishNode(tagExpression); @@ -6005,7 +6378,7 @@ var ts; if (!typeArguments) { return expression; } - var callExpr = createNode(151, expression.pos); + var callExpr = createNode(153, expression.pos); callExpr.expression = expression; callExpr.typeArguments = typeArguments; callExpr.arguments = parseArgumentList(); @@ -6013,7 +6386,7 @@ var ts; continue; } else if (token === 16) { - var callExpr = createNode(151, expression.pos); + var callExpr = createNode(153, expression.pos); callExpr.expression = expression; callExpr.arguments = parseArgumentList(); expression = finishNode(callExpr); @@ -6065,6 +6438,7 @@ var ts; } } function parsePrimaryExpression() { + var modifiers; switch (token) { case 7: case 8: @@ -6082,6 +6456,11 @@ var ts; return parseArrayLiteralExpression(); case 14: return parseObjectLiteralExpression(); + case 121: + if (!lookAhead(nextTokenIsFunctionKeywordOnSameLine)) { + break; + } + return parseFunctionExpression(); case 82: return parseFunctionExpression(); case 87: @@ -6098,26 +6477,26 @@ var ts; return parseIdentifier(ts.Diagnostics.Expression_expected); } function parseParenthesizedExpression() { - var node = createNode(155); + var node = createNode(157); parseExpected(16); node.expression = allowInAnd(parseExpression); parseExpected(17); return finishNode(node); } function parseSpreadElement() { - var node = createNode(167); + var node = createNode(171); parseExpected(21); node.expression = parseAssignmentExpressionOrHigher(); return finishNode(node); } function parseArgumentOrArrayLiteralElement() { - return token === 21 ? parseSpreadElement() : token === 23 ? createNode(168) : parseAssignmentExpressionOrHigher(); + return token === 21 ? parseSpreadElement() : token === 23 ? createNode(172) : parseAssignmentExpressionOrHigher(); } function parseArgumentExpression() { return allowInAnd(parseArgumentOrArrayLiteralElement); } function parseArrayLiteralExpression() { - var node = createNode(147); + var node = createNode(149); parseExpected(18); if (scanner.hasPrecedingLineBreak()) node.flags |= 256; @@ -6127,10 +6506,10 @@ var ts; } function tryParseAccessorDeclaration(fullStart, modifiers) { if (parseContextualModifier(114)) { - return parseAccessorDeclaration(130, fullStart, modifiers); + return parseAccessorDeclaration(132, fullStart, modifiers); } else if (parseContextualModifier(118)) { - return parseAccessorDeclaration(131, fullStart, modifiers); + return parseAccessorDeclaration(133, fullStart, modifiers); } return undefined; } @@ -6150,13 +6529,13 @@ var ts; return parseMethodDeclaration(fullStart, modifiers, asteriskToken, propertyName, questionToken); } if ((token === 23 || token === 15) && tokenIsIdentifier) { - var shorthandDeclaration = createNode(205, fullStart); + var shorthandDeclaration = createNode(209, fullStart); shorthandDeclaration.name = propertyName; shorthandDeclaration.questionToken = questionToken; return finishNode(shorthandDeclaration); } else { - var propertyAssignment = createNode(204, fullStart); + var propertyAssignment = createNode(208, fullStart); propertyAssignment.name = propertyName; propertyAssignment.questionToken = questionToken; parseExpected(51); @@ -6165,7 +6544,7 @@ var ts; } } function parseObjectLiteralExpression() { - var node = createNode(148); + var node = createNode(150); parseExpected(14); if (scanner.hasPrecedingLineBreak()) { node.flags |= 256; @@ -6175,19 +6554,35 @@ var ts; return finishNode(node); } function parseFunctionExpression() { - var node = createNode(156); + var node = createNode(158); + setModifiers(node, parseModifiers()); parseExpected(82); + var isAsync = !!(node.flags & 16384); node.asteriskToken = parseOptionalToken(35); - node.name = node.asteriskToken ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier(); - fillSignature(51, !!node.asteriskToken, false, node); - node.body = parseFunctionBlock(!!node.asteriskToken, false); + if (node.asteriskToken) { + var savedYieldContext = inYieldContext(); + setYieldContext(true); + } + if (isAsync) { + var savedAwaitContext = inAwaitContext(); + setAwaitContext(true); + } + node.name = parseOptionalIdentifier(); + if (node.asteriskToken) { + setYieldContext(savedYieldContext); + } + if (isAsync) { + setAwaitContext(savedAwaitContext); + } + fillSignature(51, !!node.asteriskToken, isAsync, false, node); + node.body = parseFunctionBlock(!!node.asteriskToken, isAsync, false); return finishNode(node); } function parseOptionalIdentifier() { return isIdentifier() ? parseIdentifier() : undefined; } function parseNewExpression() { - var node = createNode(152); + var node = createNode(154); parseExpected(87); node.expression = parseMemberExpressionOrHigher(); node.typeArguments = tryParse(parseTypeArgumentsInExpression); @@ -6197,7 +6592,7 @@ var ts; return finishNode(node); } function parseBlock(ignoreMissingOpenBrace, checkForStrictMode, diagnosticMessage) { - var node = createNode(170); + var node = createNode(174); if (parseExpected(14, diagnosticMessage) || ignoreMissingOpenBrace) { node.statements = parseList(2, checkForStrictMode, parseStatement); parseExpected(15); @@ -6207,20 +6602,23 @@ var ts; } return finishNode(node); } - function parseFunctionBlock(allowYield, ignoreMissingOpenBrace, diagnosticMessage) { + function parseFunctionBlock(allowYield, allowAwait, ignoreMissingOpenBrace, diagnosticMessage) { var savedYieldContext = inYieldContext(); setYieldContext(allowYield); + var savedAwaitContext = inAwaitContext(); + setAwaitContext(allowAwait); var block = parseBlock(ignoreMissingOpenBrace, true, diagnosticMessage); setYieldContext(savedYieldContext); + setAwaitContext(savedAwaitContext); return block; } function parseEmptyStatement() { - var node = createNode(172); + var node = createNode(176); parseExpected(22); return finishNode(node); } function parseIfStatement() { - var node = createNode(174); + var node = createNode(178); parseExpected(83); parseExpected(16); node.expression = allowInAnd(parseExpression); @@ -6230,7 +6628,7 @@ var ts; return finishNode(node); } function parseDoStatement() { - var node = createNode(175); + var node = createNode(179); parseExpected(74); node.statement = parseStatement(); parseExpected(99); @@ -6241,7 +6639,7 @@ var ts; return finishNode(node); } function parseWhileStatement() { - var node = createNode(176); + var node = createNode(180); parseExpected(99); parseExpected(16); node.expression = allowInAnd(parseExpression); @@ -6264,14 +6662,14 @@ var ts; } var forOrForInStatement; if (parseOptional(85)) { - var forInStatement = createNode(178, pos); + var forInStatement = createNode(182, pos); forInStatement.initializer = initializer; forInStatement.expression = allowInAnd(parseExpression); parseExpected(17); forOrForInStatement = forInStatement; } else { - var forStatement = createNode(177, pos); + var forStatement = createNode(181, pos); forStatement.initializer = initializer; parseExpected(22); if (token !== 22 && token !== 17) { @@ -6289,7 +6687,7 @@ var ts; } function parseBreakOrContinueStatement(kind) { var node = createNode(kind); - parseExpected(kind === 180 ? 65 : 70); + parseExpected(kind === 184 ? 65 : 70); if (!canParseSemicolon()) { node.label = parseIdentifier(); } @@ -6297,7 +6695,7 @@ var ts; return finishNode(node); } function parseReturnStatement() { - var node = createNode(181); + var node = createNode(185); parseExpected(89); if (!canParseSemicolon()) { node.expression = allowInAnd(parseExpression); @@ -6306,7 +6704,7 @@ var ts; return finishNode(node); } function parseWithStatement() { - var node = createNode(182); + var node = createNode(186); parseExpected(100); parseExpected(16); node.expression = allowInAnd(parseExpression); @@ -6315,7 +6713,7 @@ var ts; return finishNode(node); } function parseCaseClause() { - var node = createNode(200); + var node = createNode(204); parseExpected(66); node.expression = allowInAnd(parseExpression); parseExpected(51); @@ -6323,7 +6721,7 @@ var ts; return finishNode(node); } function parseDefaultClause() { - var node = createNode(201); + var node = createNode(205); parseExpected(72); parseExpected(51); node.statements = parseList(4, false, parseStatement); @@ -6333,7 +6731,7 @@ var ts; return token === 66 ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement() { - var node = createNode(183); + var node = createNode(187); parseExpected(91); parseExpected(16); node.expression = allowInAnd(parseExpression); @@ -6344,14 +6742,14 @@ var ts; return finishNode(node); } function parseThrowStatement() { - var node = createNode(185); + var node = createNode(189); parseExpected(93); node.expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression); parseSemicolon(); return finishNode(node); } function parseTryStatement() { - var node = createNode(186); + var node = createNode(190); parseExpected(95); node.tryBlock = parseBlock(false, false); node.catchClause = token === 67 ? parseCatchClause() : undefined; @@ -6362,7 +6760,7 @@ var ts; return finishNode(node); } function parseCatchClause() { - var result = createNode(203); + var result = createNode(207); parseExpected(67); parseExpected(16); result.name = parseIdentifier(); @@ -6372,7 +6770,7 @@ var ts; return finishNode(result); } function parseDebuggerStatement() { - var node = createNode(187); + var node = createNode(191); parseExpected(71); parseSemicolon(); return finishNode(node); @@ -6381,13 +6779,13 @@ var ts; var fullStart = scanner.getStartPos(); var expression = allowInAnd(parseExpression); if (expression.kind === 64 && parseOptional(51)) { - var labeledStatement = createNode(184, fullStart); + var labeledStatement = createNode(188, fullStart); labeledStatement.label = expression; labeledStatement.statement = parseStatement(); return finishNode(labeledStatement); } else { - var expressionStatement = createNode(173, fullStart); + var expressionStatement = createNode(177, fullStart); expressionStatement.expression = expression; parseSemicolon(); return finishNode(expressionStatement); @@ -6425,6 +6823,11 @@ var ts; case 69: var isConstEnum = lookAhead(nextTokenIsEnumKeyword); return !isConstEnum; + case 121: + if (lookAhead(nextTokenIsFunctionKeywordOnSameLine)) { + return true; + } + return isStartOfExpression(); case 102: case 68: case 115: @@ -6472,9 +6875,9 @@ var ts; case 81: return parseForOrForInStatement(); case 70: - return parseBreakOrContinueStatement(179); + return parseBreakOrContinueStatement(183); case 65: - return parseBreakOrContinueStatement(180); + return parseBreakOrContinueStatement(184); case 89: return parseReturnStatement(); case 100: @@ -6525,25 +6928,25 @@ var ts; } return undefined; } - function parseFunctionBlockOrSemicolon(isGenerator, diagnosticMessage) { + function parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage) { if (token !== 14 && canParseSemicolon()) { parseSemicolon(); return; } - return parseFunctionBlock(isGenerator, false, diagnosticMessage); + return parseFunctionBlock(isGenerator, isAsync, false, diagnosticMessage); } function parseArrayBindingElement() { if (token === 23) { - return createNode(168); + return createNode(172); } - var node = createNode(146); + var node = createNode(148); node.dotDotDotToken = parseOptionalToken(21); - node.name = parseIdentifierOrPattern(); - node.initializer = parseInitializer(false); + node.name = parseIdentifierOrBindingPattern(true); + node.initializer = parseBindingElementInitializer(false); return finishNode(node); } function parseObjectBindingElement() { - var node = createNode(146); + var node = createNode(148); var id = parsePropertyName(); if (id.kind === 64 && token !== 51) { node.name = id; @@ -6551,29 +6954,32 @@ var ts; else { parseExpected(51); node.propertyName = id; - node.name = parseIdentifierOrPattern(); + node.name = parseIdentifierOrBindingPattern(true); } - node.initializer = parseInitializer(false); + node.initializer = parseBindingElementInitializer(false); return finishNode(node); } function parseObjectBindingPattern() { - var node = createNode(144); + var node = createNode(146); parseExpected(14); node.elements = parseDelimitedList(10, parseObjectBindingElement); parseExpected(15); return finishNode(node); } function parseArrayBindingPattern() { - var node = createNode(145); + var node = createNode(147); parseExpected(18); node.elements = parseDelimitedList(11, parseArrayBindingElement); parseExpected(19); return finishNode(node); } - function isIdentifierOrPattern() { - return token === 14 || token === 18 || isIdentifier(); + function isIdentifierOrBindingPattern() { + return isBindingPattern() || isIdentifier(); + } + function isBindingPattern() { + return token === 18 || token === 14; } - function parseIdentifierOrPattern() { + function parseIdentifierOrBindingPattern(inBindingElement) { if (token === 18) { return parseArrayBindingPattern(); } @@ -6583,14 +6989,14 @@ var ts; return parseIdentifier(); } function parseVariableDeclaration() { - var node = createNode(188); - node.name = parseIdentifierOrPattern(); + var node = createNode(192); + node.name = parseIdentifierOrBindingPattern(false); node.type = parseTypeAnnotation(); node.initializer = parseInitializer(false); return finishNode(node); } function parseVariableDeclarationList(disallowIn) { - var node = createNode(189); + var node = createNode(193); switch (token) { case 97: break; @@ -6611,38 +7017,40 @@ var ts; return finishNode(node); } function parseVariableStatement(fullStart, modifiers) { - var node = createNode(171, fullStart); + var node = createNode(175, fullStart); setModifiers(node, modifiers); node.declarationList = parseVariableDeclarationList(false); parseSemicolon(); return finishNode(node); } function parseFunctionDeclaration(fullStart, modifiers) { - var node = createNode(190, fullStart); + var node = createNode(194, fullStart); setModifiers(node, modifiers); parseExpected(82); node.asteriskToken = parseOptionalToken(35); node.name = parseIdentifier(); - fillSignature(51, !!node.asteriskToken, false, node); - node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, ts.Diagnostics.or_expected); + var isAsync = (node.flags & 16384) !== 0; + fillSignature(51, !!node.asteriskToken, isAsync, false, node); + node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, isAsync, ts.Diagnostics.or_expected); return finishNode(node); } function parseConstructorDeclaration(pos, modifiers) { - var node = createNode(129, pos); + var node = createNode(131, pos); setModifiers(node, modifiers); parseExpected(112); - fillSignature(51, false, false, node); - node.body = parseFunctionBlockOrSemicolon(false, ts.Diagnostics.or_expected); + fillSignature(51, false, false, false, node); + node.body = parseFunctionBlockOrSemicolon(false, false, ts.Diagnostics.or_expected); return finishNode(node); } function parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, diagnosticMessage) { - var method = createNode(128, fullStart); + var method = createNode(130, fullStart); setModifiers(method, modifiers); method.asteriskToken = asteriskToken; method.name = name; method.questionToken = questionToken; - fillSignature(51, !!asteriskToken, false, method); - method.body = parseFunctionBlockOrSemicolon(!!asteriskToken, diagnosticMessage); + var isAsync = !!(method.flags & 16384); + fillSignature(51, !!asteriskToken, isAsync, false, method); + method.body = parseFunctionBlockOrSemicolon(!!asteriskToken, isAsync, diagnosticMessage); return finishNode(method); } function parsePropertyOrMethodDeclaration(fullStart, modifiers) { @@ -6653,7 +7061,7 @@ var ts; return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, ts.Diagnostics.or_expected); } else { - var property = createNode(126, fullStart); + var property = createNode(128, fullStart); setModifiers(property, modifiers); property.name = name; property.questionToken = questionToken; @@ -6663,15 +7071,13 @@ var ts; return finishNode(property); } } - function parseNonParameterInitializer() { - return parseInitializer(false); - } function parseAccessorDeclaration(kind, fullStart, modifiers) { var node = createNode(kind, fullStart); setModifiers(node, modifiers); node.name = parsePropertyName(); - fillSignature(51, false, false, node); - node.body = parseFunctionBlockOrSemicolon(false); + var isAsync = (node.flags & 16384) !== 0; + fillSignature(51, false, isAsync, false, node); + node.body = parseFunctionBlockOrSemicolon(false, isAsync); return finishNode(node); } function isClassMemberStart() { @@ -6707,13 +7113,13 @@ var ts; } return false; } - function parseModifiers() { + function parseModifiers(isArrowFunction) { var flags = 0; var modifiers; while (true) { var modifierStart = scanner.getStartPos(); var modifierKind = token; - if (!parseAnyContextualModifier()) { + if (!parseAnyContextualModifier(isArrowFunction)) { break; } if (!modifiers) { @@ -6748,14 +7154,14 @@ var ts; ts.Debug.fail("Should not have attempted to parse class member declaration."); } function parseClassDeclaration(fullStart, modifiers) { - var node = createNode(191, fullStart); + var node = createNode(195, fullStart); setModifiers(node, modifiers); parseExpected(68); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(true); if (parseExpected(14)) { - node.members = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseClassMembers) : parseClassMembers(); + node.members = doOutsideOfYieldOrAwaitOrParameterContextWhenInParameter(parseClassMembers); parseExpected(15); } else { @@ -6765,7 +7171,10 @@ var ts; } function parseHeritageClauses(isClassHeritageClause) { if (isHeritageClause()) { - return isClassHeritageClause && inGeneratorParameterContext() ? doOutsideOfYieldContext(parseHeritageClausesWorker) : parseHeritageClausesWorker(); + if (isClassHeritageClause) { + return doOutsideOfYieldOrAwaitOrParameterContextWhenInParameter(parseHeritageClausesWorker); + } + return parseHeritageClausesWorker(); } return undefined; } @@ -6774,7 +7183,7 @@ var ts; } function parseHeritageClause() { if (token === 78 || token === 101) { - var node = createNode(202); + var node = createNode(206); node.token = token; nextToken(); node.types = parseDelimitedList(8, parseTypeReference); @@ -6789,7 +7198,7 @@ var ts; return parseList(6, false, parseClassElement); } function parseInterfaceDeclaration(fullStart, modifiers) { - var node = createNode(192, fullStart); + var node = createNode(196, fullStart); setModifiers(node, modifiers); parseExpected(102); node.name = parseIdentifier(); @@ -6799,7 +7208,7 @@ var ts; return finishNode(node); } function parseTypeAliasDeclaration(fullStart, modifiers) { - var node = createNode(193, fullStart); + var node = createNode(197, fullStart); setModifiers(node, modifiers); parseExpected(120); node.name = parseIdentifier(); @@ -6809,13 +7218,13 @@ var ts; return finishNode(node); } function parseEnumMember() { - var node = createNode(206, scanner.getStartPos()); + var node = createNode(210, scanner.getStartPos()); node.name = parsePropertyName(); node.initializer = allowInAnd(parseNonParameterInitializer); return finishNode(node); } function parseEnumDeclaration(fullStart, modifiers) { - var node = createNode(194, fullStart); + var node = createNode(198, fullStart); setModifiers(node, modifiers); parseExpected(76); node.name = parseIdentifier(); @@ -6829,7 +7238,7 @@ var ts; return finishNode(node); } function parseModuleBlock() { - var node = createNode(196, scanner.getStartPos()); + var node = createNode(200, scanner.getStartPos()); if (parseExpected(14)) { node.statements = parseList(1, false, parseModuleElement); parseExpected(15); @@ -6840,7 +7249,7 @@ var ts; return finishNode(node); } function parseInternalModuleTail(fullStart, modifiers, flags) { - var node = createNode(195, fullStart); + var node = createNode(199, fullStart); setModifiers(node, modifiers); node.flags |= flags; node.name = parseIdentifier(); @@ -6848,7 +7257,7 @@ var ts; return finishNode(node); } function parseAmbientExternalModuleDeclaration(fullStart, modifiers) { - var node = createNode(195, fullStart); + var node = createNode(199, fullStart); setModifiers(node, modifiers); node.name = parseLiteralNode(true); node.body = parseModuleBlock(); @@ -6865,7 +7274,7 @@ var ts; return nextToken() === 16; } function parseImportDeclaration(fullStart, modifiers) { - var node = createNode(197, fullStart); + var node = createNode(201, fullStart); setModifiers(node, modifiers); parseExpected(84); node.name = parseIdentifier(); @@ -6878,7 +7287,7 @@ var ts; return isExternalModuleReference() ? parseExternalModuleReference() : parseEntityName(false); } function parseExternalModuleReference() { - var node = createNode(199); + var node = createNode(203); parseExpected(116); parseExpected(16); node.expression = parseExpression(); @@ -6889,7 +7298,7 @@ var ts; return finishNode(node); } function parseExportAssignmentTail(fullStart, modifiers) { - var node = createNode(198, fullStart); + var node = createNode(202, fullStart); setModifiers(node, modifiers); node.exportName = parseIdentifier(); parseSemicolon(); @@ -6922,6 +7331,8 @@ var ts; case 106: case 108: return lookAhead(nextTokenIsDeclarationStart); + case 121: + return lookAhead(nextTokenIsDeclarationStartOnSameLine); } } function isIdentifierOrKeyword() { @@ -6943,6 +7354,14 @@ var ts; nextToken(); return isDeclarationStart(); } + function nextTokenIsDeclarationStartOnSameLine() { + nextToken(); + return !scanner.hasPrecedingLineBreak() && isDeclarationStart(); + } + function nextTokenIsFunctionKeywordOnSameLine() { + nextToken(); + return !scanner.hasPrecedingLineBreak() && token === 82; + } function parseDeclaration() { var fullStart = getNodePos(); var modifiers = parseModifiers(); @@ -7042,27 +7461,27 @@ var ts; sourceFile.amdModuleName = amdModuleName; } function setExternalModuleIndicator(sourceFile) { - sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { return node.flags & 1 || node.kind === 197 && node.moduleReference.kind === 199 || node.kind === 198 ? node : undefined; }); + sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { return node.flags & 1 || node.kind === 201 && node.moduleReference.kind === 203 || node.kind === 202 ? node : undefined; }); } } function isLeftHandSideExpression(expr) { if (expr) { switch (expr.kind) { - case 149: - case 150: - case 152: case 151: + case 152: + case 154: case 153: - case 147: case 155: - case 148: - case 156: + case 149: + case 157: + case 150: + case 158: case 64: case 9: case 7: case 8: case 10: - case 165: + case 168: case 79: case 88: case 92: @@ -7089,16 +7508,16 @@ var ts; })(ts.ModuleInstanceState || (ts.ModuleInstanceState = {})); var ModuleInstanceState = ts.ModuleInstanceState; function getModuleInstanceState(node) { - if (node.kind === 192 || node.kind === 193) { + if (node.kind === 196 || node.kind === 197) { return 0; } else if (ts.isConstEnumDeclaration(node)) { return 2; } - else if (node.kind === 197 && !(node.flags & 1)) { + else if (node.kind === 201 && !(node.flags & 1)) { return 0; } - else if (node.kind === 196) { + else if (node.kind === 200) { var state = 0; ts.forEachChild(node, function (n) { switch (getModuleInstanceState(n)) { @@ -7114,7 +7533,7 @@ var ts; }); return state; } - else if (node.kind === 195) { + else if (node.kind === 199) { return getModuleInstanceState(node.body); } else { @@ -7123,7 +7542,7 @@ var ts; } ts.getModuleInstanceState = getModuleInstanceState; function hasDynamicName(declaration) { - return declaration.name && declaration.name.kind === 122; + return declaration.name && declaration.name.kind === 124; } ts.hasDynamicName = hasDynamicName; function bindSourceFile(file) { @@ -7164,22 +7583,22 @@ var ts; } function getDeclarationName(node) { if (node.name) { - if (node.kind === 195 && node.name.kind === 8) { + if (node.kind === 199 && node.name.kind === 8) { return '"' + node.name.text + '"'; } ts.Debug.assert(!hasDynamicName(node)); return node.name.text; } switch (node.kind) { - case 137: - case 129: + case 139: + case 131: return "__constructor"; - case 136: - case 132: + case 138: + case 134: return "__call"; - case 133: + case 135: return "__new"; - case 134: + case 136: return "__index"; } } @@ -7208,7 +7627,7 @@ var ts; } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; - if (node.kind === 191 && symbol.exports) { + if (node.kind === 195 && symbol.exports) { var prototypeSymbol = createSymbol(4 | 134217728, "prototype"); if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { if (node.name) { @@ -7240,7 +7659,7 @@ var ts; if (symbolKind & 1536) { exportKind |= 4194304; } - if (ts.getCombinedNodeFlags(node) & 1 || (node.kind !== 197 && isAmbientContext(container))) { + if (ts.getCombinedNodeFlags(node) & 1 || (node.kind !== 201 && isAmbientContext(container))) { if (exportKind) { var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); @@ -7279,40 +7698,40 @@ var ts; } function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) { switch (container.kind) { - case 195: + case 199: declareModuleMember(node, symbolKind, symbolExcludes); break; - case 207: + case 211: if (ts.isExternalModule(container)) { declareModuleMember(node, symbolKind, symbolExcludes); break; } - case 136: - case 137: - case 132: - case 133: + case 138: + case 139: case 134: - case 128: - case 127: - case 129: + case 135: + case 136: case 130: + case 129: case 131: - case 190: - case 156: - case 157: + case 132: + case 133: + case 194: + case 158: + case 159: declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); break; - case 191: + case 195: if (node.flags & 128) { declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } - case 139: - case 148: - case 192: + case 141: + case 150: + case 196: declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes); break; - case 194: + case 198: declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); break; } @@ -7345,7 +7764,7 @@ var ts; var typeLiteralSymbol = createSymbol(2048, "__type"); addDeclarationToSymbol(typeLiteralSymbol, node, 2048); typeLiteralSymbol.members = {}; - typeLiteralSymbol.members[node.kind === 136 ? "__call" : "__new"] = symbol; + typeLiteralSymbol.members[node.kind === 138 ? "__call" : "__new"] = symbol; } function bindAnonymousDeclaration(node, symbolKind, name, isBlockScopeContainer) { var symbol = createSymbol(symbolKind, name); @@ -7364,10 +7783,10 @@ var ts; } function bindBlockScopedVariableDeclaration(node) { switch (blockScopeContainer.kind) { - case 195: + case 199: declareModuleMember(node, 2, 107455); break; - case 207: + case 211: if (ts.isExternalModule(container)) { declareModuleMember(node, 2, 107455); break; @@ -7386,14 +7805,14 @@ var ts; function bind(node) { node.parent = parent; switch (node.kind) { - case 123: + case 125: bindDeclaration(node, 262144, 530912, false); break; - case 124: + case 126: bindParameter(node); break; - case 188: - case 146: + case 192: + case 148: if (ts.isBindingPattern(node.name)) { bindChildren(node, 0, false); } @@ -7404,65 +7823,65 @@ var ts; bindDeclaration(node, 1, 107454, false); } break; - case 126: - case 125: + case 128: + case 127: bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455, false); break; - case 204: - case 205: + case 208: + case 209: bindPropertyOrMethodOrAccessor(node, 4, 107455, false); break; - case 206: + case 210: bindPropertyOrMethodOrAccessor(node, 8, 107455, false); break; - case 132: - case 133: case 134: + case 135: + case 136: bindDeclaration(node, 131072, 0, false); break; - case 128: - case 127: + case 130: + case 129: bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263, true); break; - case 190: + case 194: bindDeclaration(node, 16, 106927, true); break; - case 129: + case 131: bindDeclaration(node, 16384, 0, true); break; - case 130: + case 132: bindPropertyOrMethodOrAccessor(node, 32768, 41919, true); break; - case 131: + case 133: bindPropertyOrMethodOrAccessor(node, 65536, 74687, true); break; - case 136: - case 137: + case 138: + case 139: bindFunctionOrConstructorType(node); break; - case 139: + case 141: bindAnonymousDeclaration(node, 2048, "__type", false); break; - case 148: + case 150: bindAnonymousDeclaration(node, 4096, "__object", false); break; - case 156: - case 157: + case 158: + case 159: bindAnonymousDeclaration(node, 16, "__function", true); break; - case 203: + case 207: bindCatchVariableDeclaration(node); break; - case 191: + case 195: bindDeclaration(node, 32, 899583, false); break; - case 192: + case 196: bindDeclaration(node, 64, 792992, false); break; - case 193: + case 197: bindDeclaration(node, 524288, 793056, false); break; - case 194: + case 198: if (ts.isConst(node)) { bindDeclaration(node, 128, 899967, false); } @@ -7470,22 +7889,24 @@ var ts; bindDeclaration(node, 256, 899327, false); } break; - case 195: + case 199: bindModuleDeclaration(node); break; - case 197: + case 201: bindDeclaration(node, 8388608, 8388608, false); break; - case 207: + case 211: if (ts.isExternalModule(node)) { bindAnonymousDeclaration(node, 512, '"' + ts.removeFileExtension(node.fileName) + '"', true); break; } - case 170: - case 203: - case 177: - case 178: - case 183: + case 174: + bindChildren(node, 0, !ts.isAnyFunction(node.parent)); + break; + case 207: + case 181: + case 182: + case 187: bindChildren(node, 0, true); break; default: @@ -7502,7 +7923,7 @@ var ts; else { bindDeclaration(node, 1, 107455, false); } - if (node.flags & 112 && node.parent.kind === 129 && node.parent.parent.kind === 191) { + if (node.flags & 112 && node.parent.kind === 131 && node.parent.parent.kind === 195) { var classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); } @@ -7581,6 +8002,7 @@ var ts; var nullType = createIntrinsicType(64 | 262144, "null"); var unknownType = createIntrinsicType(1, "unknown"); var resolvingType = createIntrinsicType(1, "__resolving__"); + var thenableType; var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); var anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); var noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -7589,6 +8011,7 @@ var ts; var unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false); var globals = {}; var globalArraySymbol; + var globalPromiseSymbol; var globalObjectType; var globalFunctionType; var globalArrayType; @@ -7597,15 +8020,22 @@ var ts; var globalBooleanType; var globalRegExpType; var globalTemplateStringsArrayType; + var globalPromiseType; + var globalPromiseLikeInterfaceType; + var globalPromiseConstructorLikeInterfaceType; var anyArrayType; var tupleTypes = {}; var unionTypes = {}; var stringLiteralTypes = {}; var emitExtends = false; + var emitAwaiter = false; + var emitGenerator = false; var mergedSymbols = []; var symbolLinks = []; var nodeLinks = []; var potentialThisCollisions = []; + var potentialArgumentsCollisions = []; + var symbolNameOverrides; var diagnostics = ts.createDiagnosticCollection(); var primitiveTypeInfo = { "string": { @@ -7759,10 +8189,10 @@ var ts; return nodeLinks[node.id] || (nodeLinks[node.id] = {}); } function getSourceFile(node) { - return ts.getAncestor(node, 207); + return ts.getAncestor(node, 211); } function isGlobalSourceFile(node) { - return node.kind === 207 && !ts.isExternalModule(node); + return node.kind === 211 && !ts.isExternalModule(node); } function getSymbol(symbols, name, meaning) { if (meaning && ts.hasProperty(symbols, name)) { @@ -7803,22 +8233,22 @@ var ts; } } switch (location.kind) { - case 207: + case 211: if (!ts.isExternalModule(location)) break; - case 195: + case 199: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8914931)) { break loop; } break; - case 194: + case 198: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8)) { break loop; } break; - case 126: - case 125: - if (location.parent.kind === 191 && !(location.flags & 128)) { + case 128: + case 127: + if (location.parent.kind === 195 && !(location.flags & 128)) { var ctor = findConstructorDeclaration(location.parent); if (ctor && ctor.locals) { if (getSymbol(ctor.locals, name, meaning & 107455)) { @@ -7827,8 +8257,8 @@ var ts; } } break; - case 191: - case 192: + case 195: + case 196: if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 793056)) { if (lastLocation && lastLocation.flags & 128) { error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters); @@ -7837,28 +8267,28 @@ var ts; break loop; } break; - case 122: + case 124: var grandparent = location.parent.parent; - if (grandparent.kind === 191 || grandparent.kind === 192) { + if (grandparent.kind === 195 || grandparent.kind === 196) { if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056)) { error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); return undefined; } } break; - case 128: - case 127: - case 129: case 130: + case 129: case 131: - case 190: - case 157: + case 132: + case 133: + case 194: + case 159: if (name === "arguments") { result = argumentsSymbol; break loop; } break; - case 156: + case 158: if (name === "arguments") { result = argumentsSymbol; break loop; @@ -7869,7 +8299,7 @@ var ts; break loop; } break; - case 203: + case 207: var id = location.name; if (name === id.text) { result = location.symbol; @@ -7910,13 +8340,13 @@ var ts; var links = getSymbolLinks(symbol); if (!links.target) { links.target = resolvingSymbol; - var node = ts.getDeclarationOfKind(symbol, 197); - if (node.moduleReference.kind === 199) { + var node = ts.getDeclarationOfKind(symbol, 201); + if (node.moduleReference.kind === 203) { if (node.moduleReference.expression.kind !== 8) { grammarErrorOnNode(node.moduleReference.expression, ts.Diagnostics.String_literal_expected); } } - var target = node.moduleReference.kind === 199 ? resolveExternalModuleName(node, ts.getExternalModuleImportDeclarationExpression(node)) : getSymbolOfPartOfRightHandSideOfImport(node.moduleReference, node); + var target = node.moduleReference.kind === 203 ? resolveExternalModuleName(node, ts.getExternalModuleImportDeclarationExpression(node)) : getSymbolOfPartOfRightHandSideOfImport(node.moduleReference, node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; } @@ -7931,17 +8361,17 @@ var ts; } function getSymbolOfPartOfRightHandSideOfImport(entityName, importDeclaration) { if (!importDeclaration) { - importDeclaration = ts.getAncestor(entityName, 197); + importDeclaration = ts.getAncestor(entityName, 201); ts.Debug.assert(importDeclaration !== undefined); } if (entityName.kind === 64 && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { entityName = entityName.parent; } - if (entityName.kind === 64 || entityName.parent.kind === 121) { + if (entityName.kind === 64 || entityName.parent.kind === 123) { return resolveEntityName(importDeclaration, entityName, 1536); } else { - ts.Debug.assert(entityName.parent.kind === 197); + ts.Debug.assert(entityName.parent.kind === 201); return resolveEntityName(importDeclaration, entityName, 107455 | 793056 | 1536); } } @@ -7958,7 +8388,7 @@ var ts; return; } } - else if (name.kind === 121) { + else if (name.kind === 123) { var namespace = resolveEntityName(location, name.left, 1536); if (!namespace || namespace === unknownSymbol || ts.getFullWidth(name.right) === 0) return; @@ -8050,9 +8480,9 @@ var ts; var seenExportedMember = false; var result = []; ts.forEach(symbol.declarations, function (declaration) { - var block = (declaration.kind === 207 ? declaration : declaration.body); + var block = (declaration.kind === 211 ? declaration : declaration.body); ts.forEach(block.statements, function (node) { - if (node.kind === 198) { + if (node.kind === 202) { result.push(node); } else { @@ -8094,7 +8524,7 @@ var ts; var members = node.members; for (var i = 0; i < members.length; i++) { var member = members[i]; - if (member.kind === 129 && ts.nodeIsPresent(member.body)) { + if (member.kind === 131 && ts.nodeIsPresent(member.body)) { return member; } } @@ -8156,17 +8586,17 @@ var ts; } } switch (location.kind) { - case 207: + case 211: if (!ts.isExternalModule(location)) { break; } - case 195: + case 199: if (result = callback(getSymbolOfNode(location).exports)) { return result; } break; - case 191: - case 192: + case 195: + case 196: if (result = callback(getSymbolOfNode(location).members)) { return result; } @@ -8279,7 +8709,7 @@ var ts; } } function hasExternalModuleSymbol(declaration) { - return (declaration.kind === 195 && declaration.name.kind === 8) || (declaration.kind === 207 && ts.isExternalModule(declaration)); + return (declaration.kind === 199 && declaration.name.kind === 8) || (declaration.kind === 211 && ts.isExternalModule(declaration)); } function hasVisibleDeclarations(symbol) { var aliasesToMakeVisible; @@ -8289,7 +8719,7 @@ var ts; return { accessibility: 0, aliasesToMakeVisible: aliasesToMakeVisible }; function getIsDeclarationVisible(declaration) { if (!isDeclarationVisible(declaration)) { - if (declaration.kind === 197 && !(declaration.flags & 1) && isDeclarationVisible(declaration.parent)) { + if (declaration.kind === 201 && !(declaration.flags & 1) && isDeclarationVisible(declaration.parent)) { getNodeLinks(declaration).isVisible = true; if (aliasesToMakeVisible) { if (!ts.contains(aliasesToMakeVisible, declaration)) { @@ -8308,10 +8738,10 @@ var ts; } function isEntityNameVisible(entityName, enclosingDeclaration) { var meaning; - if (entityName.parent.kind === 138) { + if (entityName.parent.kind === 140) { meaning = 107455 | 1048576; } - else if (entityName.kind === 121 || entityName.parent.kind === 197) { + else if (entityName.kind === 123 || entityName.parent.kind === 201) { meaning = 1536; } else { @@ -8355,10 +8785,10 @@ var ts; function getTypeAliasForTypeLiteral(type) { if (type.symbol && type.symbol.flags & 2048) { var node = type.symbol.declarations[0].parent; - while (node.kind === 143) { + while (node.kind === 145) { node = node.parent; } - if (node.kind === 193) { + if (node.kind === 197) { return getSymbolOfNode(node); } } @@ -8523,7 +8953,7 @@ var ts; function shouldWriteTypeOfFunctionSymbol() { if (type.symbol) { var isStaticMethodSymbol = !!(type.symbol.flags & 8192 && ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128; })); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 207 || declaration.parent.kind === 196; })); + var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 211 || declaration.parent.kind === 200; })); if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { return !!(flags & 2) || (typeStack && ts.contains(typeStack, type)); } @@ -8750,12 +9180,12 @@ var ts; function isDeclarationVisible(node) { function getContainingExternalModule(node) { for (; node; node = node.parent) { - if (node.kind === 195) { + if (node.kind === 199) { if (node.name.kind === 8) { return node; } } - else if (node.kind === 207) { + else if (node.kind === 211) { return ts.isExternalModule(node) ? node : undefined; } } @@ -8797,46 +9227,46 @@ var ts; } function determineIfDeclarationIsVisible() { switch (node.kind) { - case 188: - case 146: - case 195: - case 191: case 192: - case 193: - case 190: - case 194: + case 148: + case 199: + case 195: + case 196: case 197: + case 194: + case 198: + case 201: var parent = getDeclarationContainer(node); - if (!(ts.getCombinedNodeFlags(node) & 1) && !(node.kind !== 197 && parent.kind !== 207 && ts.isInAmbientContext(parent))) { + if (!(ts.getCombinedNodeFlags(node) & 1) && !(node.kind !== 201 && parent.kind !== 211 && ts.isInAmbientContext(parent))) { return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); } return isDeclarationVisible(parent); - case 126: - case 125: - case 130: - case 131: case 128: case 127: + case 132: + case 133: + case 130: + case 129: if (node.flags & (32 | 64)) { return false; } - case 129: - case 133: - case 132: + case 131: + case 135: case 134: - case 124: - case 196: case 136: - case 137: + case 126: + case 200: + case 138: case 139: - case 135: - case 140: case 141: + case 137: case 142: case 143: + case 144: + case 145: return isDeclarationVisible(node.parent); - case 123: - case 207: + case 125: + case 211: return true; default: ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind); @@ -8851,14 +9281,14 @@ var ts; } } function getRootDeclaration(node) { - while (node.kind === 146) { + while (node.kind === 148) { node = node.parent.parent; } return node; } function getDeclarationContainer(node) { node = getRootDeclaration(node); - return node.kind === 188 ? node.parent.parent.parent : node.parent; + return node.kind === 192 ? node.parent.parent.parent : node.parent; } function getTypeOfPrototypeProperty(prototype) { var classType = getDeclaredTypeOfSymbol(prototype.parent); @@ -8880,7 +9310,7 @@ var ts; } return parentType; } - if (pattern.kind === 144) { + if (pattern.kind === 146) { var name = declaration.propertyName || declaration.name; var type = getTypeOfPropertyOfType(parentType, name.text) || isNumericLiteralName(name.text) && getIndexTypeOfType(parentType, 1) || getIndexTypeOfType(parentType, 0); if (!type) { @@ -8908,7 +9338,7 @@ var ts; return type; } function getTypeForVariableLikeDeclaration(declaration) { - if (declaration.parent.parent.kind === 178) { + if (declaration.parent.parent.kind === 182) { return anyType; } if (ts.isBindingPattern(declaration.parent)) { @@ -8917,10 +9347,10 @@ var ts; if (declaration.type) { return getTypeFromTypeNode(declaration.type); } - if (declaration.kind === 124) { + if (declaration.kind === 126) { var func = declaration.parent; - if (func.kind === 131 && !ts.hasDynamicName(func)) { - var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 130); + if (func.kind === 133 && !ts.hasDynamicName(func)) { + var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 132); if (getter) { return getReturnTypeOfSignature(getSignatureFromDeclaration(getter)); } @@ -8933,7 +9363,7 @@ var ts; if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } - if (declaration.kind === 205) { + if (declaration.kind === 209) { return checkIdentifier(declaration.name); } return undefined; @@ -8962,7 +9392,7 @@ var ts; var hasSpreadElement = false; var elementTypes = []; ts.forEach(pattern.elements, function (e) { - elementTypes.push(e.kind === 168 || e.dotDotDotToken ? anyType : getTypeFromBindingElement(e)); + elementTypes.push(e.kind === 172 || e.dotDotDotToken ? anyType : getTypeFromBindingElement(e)); if (e.dotDotDotToken) { hasSpreadElement = true; } @@ -8970,7 +9400,7 @@ var ts; return !elementTypes.length ? anyArrayType : hasSpreadElement ? createArrayType(getUnionType(elementTypes)) : createTupleType(elementTypes); } function getTypeFromBindingPattern(pattern) { - return pattern.kind === 144 ? getTypeFromObjectBindingPattern(pattern) : getTypeFromArrayBindingPattern(pattern); + return pattern.kind === 146 ? getTypeFromObjectBindingPattern(pattern) : getTypeFromArrayBindingPattern(pattern); } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { var type = getTypeForVariableLikeDeclaration(declaration); @@ -8978,7 +9408,7 @@ var ts; if (reportErrors) { reportErrorsFromWidening(declaration, type); } - return declaration.kind !== 204 ? getWidenedType(type) : type; + return declaration.kind !== 208 ? getWidenedType(type) : type; } if (ts.isBindingPattern(declaration.name)) { return getTypeFromBindingPattern(declaration.name); @@ -8986,7 +9416,7 @@ var ts; type = declaration.dotDotDotToken ? anyArrayType : anyType; if (reportErrors && compilerOptions.noImplicitAny) { var root = getRootDeclaration(declaration); - if (!isPrivateWithinAmbient(root) && !(root.kind === 124 && isPrivateWithinAmbient(root.parent))) { + if (!isPrivateWithinAmbient(root) && !(root.kind === 126 && isPrivateWithinAmbient(root.parent))) { reportImplicitAnyError(declaration, type); } } @@ -8999,7 +9429,7 @@ var ts; return links.type = getTypeOfPrototypeProperty(symbol); } var declaration = symbol.valueDeclaration; - if (declaration.kind === 203) { + if (declaration.kind === 207) { return links.type = anyType; } links.type = resolvingType; @@ -9022,7 +9452,7 @@ var ts; } function getAnnotatedAccessorType(accessor) { if (accessor) { - if (accessor.kind === 130) { + if (accessor.kind === 132) { return accessor.type && getTypeFromTypeNode(accessor.type); } else { @@ -9041,8 +9471,8 @@ var ts; links = links || getSymbolLinks(symbol); if (!links.type) { links.type = resolvingType; - var getter = ts.getDeclarationOfKind(symbol, 130); - var setter = ts.getDeclarationOfKind(symbol, 131); + var getter = ts.getDeclarationOfKind(symbol, 132); + var setter = ts.getDeclarationOfKind(symbol, 133); var type; var getterReturnType = getAnnotatedAccessorType(getter); if (getterReturnType) { @@ -9072,7 +9502,7 @@ var ts; else if (links.type === resolvingType) { links.type = anyType; if (compilerOptions.noImplicitAny) { - var getter = ts.getDeclarationOfKind(symbol, 130); + var getter = ts.getDeclarationOfKind(symbol, 132); error(getter, ts.Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol)); } } @@ -9139,7 +9569,7 @@ var ts; function getTypeParametersOfClassOrInterface(symbol) { var result; ts.forEach(symbol.declarations, function (node) { - if (node.kind === 192 || node.kind === 191) { + if (node.kind === 196 || node.kind === 195) { var declaration = node; if (declaration.typeParameters && declaration.typeParameters.length) { ts.forEach(declaration.typeParameters, function (node) { @@ -9170,7 +9600,7 @@ var ts; type.typeArguments = type.typeParameters; } type.baseTypes = []; - var declaration = ts.getDeclarationOfKind(symbol, 191); + var declaration = ts.getDeclarationOfKind(symbol, 195); var baseTypeNode = ts.getClassBaseTypeNode(declaration); if (baseTypeNode) { var baseType = getTypeFromTypeReferenceNode(baseTypeNode); @@ -9211,7 +9641,7 @@ var ts; } type.baseTypes = []; ts.forEach(symbol.declarations, function (declaration) { - if (declaration.kind === 192 && ts.getInterfaceBaseTypeNodes(declaration)) { + if (declaration.kind === 196 && ts.getInterfaceBaseTypeNodes(declaration)) { ts.forEach(ts.getInterfaceBaseTypeNodes(declaration), function (node) { var baseType = getTypeFromTypeReferenceNode(node); if (baseType !== unknownType) { @@ -9242,7 +9672,7 @@ var ts; var links = getSymbolLinks(symbol); if (!links.declaredType) { links.declaredType = resolvingType; - var declaration = ts.getDeclarationOfKind(symbol, 193); + var declaration = ts.getDeclarationOfKind(symbol, 197); var type = getTypeFromTypeNode(declaration.type); if (links.declaredType === resolvingType) { links.declaredType = type; @@ -9250,7 +9680,7 @@ var ts; } else if (links.declaredType === resolvingType) { links.declaredType = unknownType; - var declaration = ts.getDeclarationOfKind(symbol, 193); + var declaration = ts.getDeclarationOfKind(symbol, 197); error(declaration.name, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol)); } return links.declaredType; @@ -9269,7 +9699,7 @@ var ts; if (!links.declaredType) { var type = createType(512); type.symbol = symbol; - if (!ts.getDeclarationOfKind(symbol, 123).constraint) { + if (!ts.getDeclarationOfKind(symbol, 125).constraint) { type.constraint = noConstraintType; } links.declaredType = type; @@ -9672,7 +10102,7 @@ var ts; function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { - var classType = declaration.kind === 129 ? getDeclaredTypeOfClass(declaration.parent.symbol) : undefined; + var classType = declaration.kind === 131 ? getDeclaredTypeOfClass(declaration.parent.symbol) : undefined; var typeParameters = classType ? classType.typeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; var hasStringLiterals = false; @@ -9700,8 +10130,8 @@ var ts; returnType = getTypeFromTypeNode(declaration.type); } else { - if (declaration.kind === 130 && !ts.hasDynamicName(declaration)) { - var setter = ts.getDeclarationOfKind(declaration.symbol, 131); + if (declaration.kind === 132 && !ts.hasDynamicName(declaration)) { + var setter = ts.getDeclarationOfKind(declaration.symbol, 133); returnType = getAnnotatedAccessorType(setter); } if (!returnType && ts.nodeIsMissing(declaration.body)) { @@ -9719,19 +10149,19 @@ var ts; for (var i = 0, len = symbol.declarations.length; i < len; i++) { var node = symbol.declarations[i]; switch (node.kind) { - case 136: - case 137: - case 190: - case 128: - case 127: + case 138: + case 139: + case 194: + case 130: case 129: + case 131: + case 134: + case 135: + case 136: case 132: case 133: - case 134: - case 130: - case 131: - case 156: - case 157: + case 158: + case 159: if (i > 0 && node.body) { var previous = symbol.declarations[i - 1]; if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) { @@ -9800,7 +10230,7 @@ var ts; } function getOrCreateTypeFromSignature(signature) { if (!signature.isolatedSignatureType) { - var isConstructor = signature.declaration.kind === 129 || signature.declaration.kind === 133; + var isConstructor = signature.declaration.kind === 131 || signature.declaration.kind === 135; var type = createObjectType(32768 | 65536); type.members = emptySymbols; type.properties = emptyArray; @@ -9841,7 +10271,7 @@ var ts; type.constraint = targetConstraint ? instantiateType(targetConstraint, type.mapper) : noConstraintType; } else { - type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 123).constraint); + type.constraint = getTypeFromTypeNode(ts.getDeclarationOfKind(type.symbol, 125).constraint); } } return type.constraint === noConstraintType ? undefined : type.constraint; @@ -9889,13 +10319,13 @@ var ts; while (!ts.forEach(typeParameterSymbol.declarations, function (d) { return d.parent === currentNode.parent; })) { currentNode = currentNode.parent; } - links.isIllegalTypeReferenceInConstraint = currentNode.kind === 123; + links.isIllegalTypeReferenceInConstraint = currentNode.kind === 125; return links.isIllegalTypeReferenceInConstraint; } function checkTypeParameterHasIllegalReferencesInConstraint(typeParameter) { var typeParameterSymbol; function check(n) { - if (n.kind === 135 && n.typeName.kind === 64) { + if (n.kind === 137 && n.typeName.kind === 64) { var links = getNodeLinks(n); if (links.isIllegalTypeReferenceInConstraint === undefined) { var symbol = resolveName(typeParameter, n.typeName.text, 793056, undefined, undefined); @@ -9960,9 +10390,9 @@ var ts; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; switch (declaration.kind) { - case 191: - case 192: - case 194: + case 195: + case 196: + case 198: return declaration; } } @@ -10138,24 +10568,24 @@ var ts; return voidType; case 8: return getTypeFromStringLiteral(node); - case 135: + case 137: return getTypeFromTypeReferenceNode(node); - case 138: - return getTypeFromTypeQueryNode(node); case 140: + return getTypeFromTypeQueryNode(node); + case 142: return getTypeFromArrayTypeNode(node); - case 141: + case 143: return getTypeFromTupleTypeNode(node); - case 142: + case 144: return getTypeFromUnionTypeNode(node); - case 143: + case 145: return getTypeFromTypeNode(node.type); - case 136: - case 137: + case 138: case 139: + case 141: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); case 64: - case 121: + case 123: var symbol = getSymbolInfo(node); return symbol && getDeclaredTypeOfSymbol(symbol); default: @@ -10299,25 +10729,25 @@ var ts; return type; } function isContextSensitive(node) { - ts.Debug.assert(node.kind !== 128 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 130 || ts.isObjectLiteralMethod(node)); switch (node.kind) { - case 156: - case 157: + case 158: + case 159: return isContextSensitiveFunctionLikeDeclaration(node); - case 148: + case 150: return ts.forEach(node.properties, isContextSensitive); - case 147: + case 149: return ts.forEach(node.elements, isContextSensitive); - case 164: + case 167: return isContextSensitive(node.whenTrue) || isContextSensitive(node.whenFalse); - case 163: + case 166: return node.operator === 49 && (isContextSensitive(node.left) || isContextSensitive(node.right)); - case 204: + case 208: return isContextSensitive(node.initializer); - case 128: - case 127: + case 130: + case 129: return isContextSensitiveFunctionLikeDeclaration(node); - case 155: + case 157: return isContextSensitive(node.expression); } return false; @@ -11070,20 +11500,20 @@ var ts; function reportImplicitAnyError(declaration, type) { var typeAsString = typeToString(getWidenedType(type)); switch (declaration.kind) { - case 126: - case 125: + case 128: + case 127: var diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type; break; - case 124: + case 126: var diagnostic = declaration.dotDotDotToken ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Parameter_0_implicitly_has_an_1_type; break; - case 190: - case 128: - case 127: + case 194: case 130: - case 131: - case 156: - case 157: + case 129: + case 132: + case 133: + case 158: + case 159: if (!declaration.name) { error(declaration, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString); return; @@ -11311,10 +11741,10 @@ var ts; function isInTypeQuery(node) { while (node) { switch (node.kind) { - case 138: + case 140: return true; case 64: - case 121: + case 123: node = node.parent; continue; default: @@ -11353,7 +11783,7 @@ var ts; function isAssignedInBinaryExpression(node) { if (node.operator >= 52 && node.operator <= 63) { var n = node.left; - while (n.kind === 155) { + while (n.kind === 157) { n = n.expression; } if (n.kind === 64 && getResolvedSymbol(n) === symbol) { @@ -11370,45 +11800,47 @@ var ts; } function isAssignedIn(node) { switch (node.kind) { - case 163: + case 166: return isAssignedInBinaryExpression(node); - case 188: - case 146: + case 192: + case 148: return isAssignedInVariableDeclaration(node); - case 144: - case 145: + case 146: case 147: - case 148: case 149: case 150: case 151: case 152: + case 153: case 154: - case 155: - case 161: - case 158: - case 159: + case 156: + case 157: + case 164: case 160: + case 163: + case 161: case 162: - case 164: + case 165: + case 169: case 167: - case 170: case 171: - case 173: case 174: case 175: - case 176: case 177: case 178: + case 179: + case 180: case 181: case 182: - case 183: - case 200: - case 201: - case 184: case 185: case 186: - case 203: + case 187: + case 204: + case 205: + case 188: + case 189: + case 190: + case 207: return ts.forEachChild(node, isAssignedIn); } return false; @@ -11445,17 +11877,17 @@ var ts; node = node.parent; var narrowedType = type; switch (node.kind) { - case 174: + case 178: if (child !== node.expression) { narrowedType = narrowType(type, node.expression, child === node.thenStatement); } break; - case 164: + case 167: if (child !== node.condition) { narrowedType = narrowType(type, node.condition, child === node.whenTrue); } break; - case 163: + case 166: if (child === node.right) { if (node.operator === 48) { narrowedType = narrowType(type, node.left, true); @@ -11465,14 +11897,14 @@ var ts; } } break; - case 207: - case 195: - case 190: - case 128: - case 127: + case 211: + case 199: + case 194: case 130: - case 131: case 129: + case 132: + case 133: + case 131: break loop; } if (narrowedType !== type) { @@ -11485,7 +11917,7 @@ var ts; } return type; function narrowTypeByEquality(type, expr, assumeTrue) { - if (expr.left.kind !== 159 || expr.right.kind !== 8) { + if (expr.left.kind !== 161 || expr.right.kind !== 8) { return type; } var left = expr.left; @@ -11558,9 +11990,9 @@ var ts; } function narrowType(type, expr, assumeTrue) { switch (expr.kind) { - case 155: + case 157: return narrowType(type, expr.expression, assumeTrue); - case 163: + case 166: var operator = expr.operator; if (operator === 30 || operator === 31) { return narrowTypeByEquality(type, expr, assumeTrue); @@ -11575,7 +12007,7 @@ var ts; return narrowTypeByInstanceof(type, expr, assumeTrue); } break; - case 161: + case 164: if (expr.operator === 46) { return narrowType(type, expr.operand, !assumeTrue); } @@ -11591,19 +12023,34 @@ var ts; nodeLinks.importOnRightSide = undefined; getSymbolLinks(rightSide).referenced = true; ts.Debug.assert((rightSide.flags & 8388608) !== 0); - nodeLinks = getNodeLinks(ts.getDeclarationOfKind(rightSide, 197)); + nodeLinks = getNodeLinks(ts.getDeclarationOfKind(rightSide, 201)); } } + function renameSymbol(symbol, name) { + if (!symbolNameOverrides) { + symbolNameOverrides = []; + } + symbolNameOverrides[symbol.id] = name; + } + function getRenamedIdentifier(name) { + if (symbolNameOverrides) { + var links = getNodeLinks(name); + if (links.resolvedSymbol) { + return symbolNameOverrides[links.resolvedSymbol.id]; + } + } + return undefined; + } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); - if (symbol === argumentsSymbol && ts.getContainingFunction(node).kind === 157) { + if (symbol === argumentsSymbol && ts.getContainingFunction(node).kind === 159) { error(node, ts.Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression); } if (symbol.flags & 8388608) { var symbolLinks = getSymbolLinks(symbol); if (!symbolLinks.referenced) { var importOrExportAssignment = getLeftSideOfImportOrExportAssignment(node); - if (!importOrExportAssignment || (importOrExportAssignment.flags & 1) || (importOrExportAssignment.kind === 198)) { + if (!importOrExportAssignment || (importOrExportAssignment.flags & 1) || (importOrExportAssignment.kind === 202)) { symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); } else { @@ -11613,17 +12060,24 @@ var ts; } } if (symbolLinks.referenced) { - markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 197)); + markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 201)); } } + if (isLexicalArguments(node)) { + var container = ts.getContainingFunction(node); + captureLexicalArguments(node, container); + } checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); + checkCollisionWithCapturedArgumentsVariable(node, node); + checkCollisionWithAwaiterVariablesInGeneratedCode(node, node); + checkCollisionWithGeneratorVariablesInGeneratedCode(node, node); return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } function captureLexicalThis(node, container) { - var classNode = container.parent && container.parent.kind === 191 ? container.parent : undefined; + var classNode = container.parent && container.parent.kind === 195 ? container.parent : undefined; getNodeLinks(node).flags |= 2; - if (container.kind === 126 || container.kind === 129) { + if (container.kind === 128 || container.kind === 131) { getNodeLinks(classNode).flags |= 4; } else { @@ -11633,53 +12087,68 @@ var ts; function checkThisExpression(node) { var container = ts.getThisContainer(node, true); var needToCaptureLexicalThis = false; - if (container.kind === 157) { + if (container.kind === 159) { container = ts.getThisContainer(container, false); needToCaptureLexicalThis = (languageVersion < 2); } + if (node.parserContextFlags & 64) { + needToCaptureLexicalThis = true; + } switch (container.kind) { - case 195: + case 199: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_body); break; - case 194: + case 198: error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location); break; - case 129: + case 131: if (isInConstructorArgumentInitializer(node, container)) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_constructor_arguments); } break; - case 126: - case 125: - if (container.flags & 128) { + case 128: + case 127: + if (container.flags & 128) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); } break; - case 122: + case 124: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_computed_property_name); break; } if (needToCaptureLexicalThis) { captureLexicalThis(node, container); } - var classNode = container.parent && container.parent.kind === 191 ? container.parent : undefined; + var classNode = container.parent && container.parent.kind === 195 ? container.parent : undefined; if (classNode) { var symbol = getSymbolOfNode(classNode); return container.flags & 128 ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol); } return anyType; } + function isLexicalArguments(node) { + if (node.text === "arguments" && node.parserContextFlags & 64) { + return true; + } + return false; + } + function captureLexicalArguments(node, container) { + if (node.parent.kind !== 126) { + getNodeLinks(node).flags |= 8; + } + getNodeLinks(container).flags |= 16; + } function isInConstructorArgumentInitializer(node, constructorDecl) { for (var n = node; n && n !== constructorDecl; n = n.parent) { - if (n.kind === 124) { + if (n.kind === 126) { return true; } } return false; } function checkSuperExpression(node) { - var isCallExpression = node.parent.kind === 151 && node.parent.expression === node; - var enclosingClass = ts.getAncestor(node, 191); + var isCallExpression = node.parent.kind === 153 && node.parent.expression === node; + var enclosingClass = ts.getAncestor(node, 195); var baseClass; if (enclosingClass && ts.getClassBaseTypeNode(enclosingClass)) { var classType = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClass)); @@ -11693,34 +12162,34 @@ var ts; if (container) { var canUseSuperExpression = false; if (isCallExpression) { - canUseSuperExpression = container.kind === 129; + canUseSuperExpression = container.kind === 131; } else { var needToCaptureLexicalThis = false; - while (container && container.kind === 157) { + while (container && container.kind === 159) { container = ts.getSuperContainer(container, true); needToCaptureLexicalThis = true; } - if (container && container.parent && container.parent.kind === 191) { + if (container && container.parent && container.parent.kind === 195) { if (container.flags & 128) { - canUseSuperExpression = container.kind === 128 || container.kind === 127 || container.kind === 130 || container.kind === 131; + canUseSuperExpression = container.kind === 130 || container.kind === 129 || container.kind === 132 || container.kind === 133; } else { - canUseSuperExpression = container.kind === 128 || container.kind === 127 || container.kind === 130 || container.kind === 131 || container.kind === 126 || container.kind === 125 || container.kind === 129; + canUseSuperExpression = container.kind === 130 || container.kind === 129 || container.kind === 132 || container.kind === 133 || container.kind === 128 || container.kind === 127 || container.kind === 131; } } } if (canUseSuperExpression) { var returnType; if ((container.flags & 128) || isCallExpression) { - getNodeLinks(node).flags |= 32; + getNodeLinks(node).flags |= 128; returnType = getTypeOfSymbol(baseClass.symbol); } else { - getNodeLinks(node).flags |= 16; + getNodeLinks(node).flags |= 64; returnType = baseClass; } - if (container.kind === 129 && isInConstructorArgumentInitializer(node, container)) { + if (container.kind === 131 && isInConstructorArgumentInitializer(node, container)) { error(node, ts.Diagnostics.super_cannot_be_referenced_in_constructor_arguments); returnType = unknownType; } @@ -11730,7 +12199,7 @@ var ts; return returnType; } } - if (container.kind === 122) { + if (container.kind === 124) { error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); } else if (isCallExpression) { @@ -11767,7 +12236,7 @@ var ts; if (declaration.type) { return getTypeFromTypeNode(declaration.type); } - if (declaration.kind === 124) { + if (declaration.kind === 126) { var type = getContextuallyTypedParameterType(declaration); if (type) { return type; @@ -11782,7 +12251,7 @@ var ts; function getContextualTypeForReturnExpression(node) { var func = ts.getContainingFunction(node); if (func) { - if (func.type || func.kind === 129 || func.kind === 130 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(func.symbol, 131))) { + if (func.type || func.kind === 131 || func.kind === 132 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(func.symbol, 133))) { return getReturnTypeOfSignature(getSignatureFromDeclaration(func)); } var signature = getContextualSignatureForFunctionLikeDeclaration(func); @@ -11802,7 +12271,7 @@ var ts; return undefined; } function getContextualTypeForSubstitutionExpression(template, substitutionExpression) { - if (template.parent.kind === 153) { + if (template.parent.kind === 155) { return getContextualTypeForArgument(template.parent, substitutionExpression); } return undefined; @@ -11906,32 +12375,32 @@ var ts; } var parent = node.parent; switch (parent.kind) { - case 188: - case 124: + case 192: case 126: - case 125: - case 146: + case 128: + case 127: + case 148: return getContextualTypeForInitializerExpression(node); - case 157: - case 181: + case 159: + case 185: return getContextualTypeForReturnExpression(node); - case 151: - case 152: - return getContextualTypeForArgument(parent, node); + case 153: case 154: + return getContextualTypeForArgument(parent, node); + case 156: return getTypeFromTypeNode(parent.type); - case 163: + case 166: return getContextualTypeForBinaryOperand(node); - case 204: + case 208: return getContextualTypeForObjectLiteralElement(parent); - case 147: + case 149: return getContextualTypeForElementExpression(node); - case 164: + case 167: return getContextualTypeForConditionalOperand(node); - case 169: - ts.Debug.assert(parent.parent.kind === 165); + case 173: + ts.Debug.assert(parent.parent.kind === 168); return getContextualTypeForSubstitutionExpression(parent.parent, node); - case 155: + case 157: return getContextualType(parent); } return undefined; @@ -11946,13 +12415,13 @@ var ts; } } function isFunctionExpressionOrArrowFunction(node) { - return node.kind === 156 || node.kind === 157; + return node.kind === 158 || node.kind === 159; } function getContextualSignatureForFunctionLikeDeclaration(node) { return isFunctionExpressionOrArrowFunction(node) ? getContextualSignature(node) : undefined; } function getContextualSignature(node) { - ts.Debug.assert(node.kind !== 128 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 130 || ts.isObjectLiteralMethod(node)); var type = ts.isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getContextualType(node); if (!type) { return undefined; @@ -11992,13 +12461,13 @@ var ts; } function isAssignmentTarget(node) { var parent = node.parent; - if (parent.kind === 163 && parent.operator === 52 && parent.left === node) { + if (parent.kind === 166 && parent.operator === 52 && parent.left === node) { return true; } - if (parent.kind === 204) { + if (parent.kind === 208) { return isAssignmentTarget(parent.parent); } - if (parent.kind === 147) { + if (parent.kind === 149) { return isAssignmentTarget(parent); } return false; @@ -12020,7 +12489,7 @@ var ts; var elementTypes = []; ts.forEach(elements, function (e) { var type = checkExpression(e, contextualMapper); - if (e.kind === 167) { + if (e.kind === 171) { elementTypes.push(getIndexTypeOfType(type, 1) || anyType); hasSpreadElement = true; } @@ -12037,7 +12506,7 @@ var ts; return createArrayType(getUnionType(elementTypes)); } function isNumericName(name) { - return name.kind === 122 ? isNumericComputedName(name) : isNumericLiteralName(name.text); + return name.kind === 124 ? isNumericComputedName(name) : isNumericLiteralName(name.text); } function isNumericComputedName(name) { return isTypeOfKind(checkComputedPropertyName(name), 1 | 132); @@ -12064,16 +12533,16 @@ var ts; for (var i = 0; i < node.properties.length; i++) { var memberDecl = node.properties[i]; var member = memberDecl.symbol; - if (memberDecl.kind === 204 || memberDecl.kind === 205 || ts.isObjectLiteralMethod(memberDecl)) { - if (memberDecl.kind === 204) { + if (memberDecl.kind === 208 || memberDecl.kind === 209 || ts.isObjectLiteralMethod(memberDecl)) { + if (memberDecl.kind === 208) { var type = checkPropertyAssignment(memberDecl, contextualMapper); } - else if (memberDecl.kind === 128) { + else if (memberDecl.kind === 130) { var type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { - ts.Debug.assert(memberDecl.kind === 205); - var type = memberDecl.name.kind === 122 ? unknownType : checkExpression(memberDecl.name, contextualMapper); + ts.Debug.assert(memberDecl.kind === 209); + var type = memberDecl.name.kind === 124 ? unknownType : checkExpression(memberDecl.name, contextualMapper); } typeFlags |= type.flags; var prop = createSymbol(4 | 67108864 | member.flags, member.name); @@ -12087,7 +12556,7 @@ var ts; member = prop; } else { - ts.Debug.assert(memberDecl.kind === 130 || memberDecl.kind === 131); + ts.Debug.assert(memberDecl.kind === 132 || memberDecl.kind === 133); checkAccessorDeclaration(memberDecl); } if (!ts.hasDynamicName(memberDecl)) { @@ -12120,7 +12589,7 @@ var ts; } } function getDeclarationKindFromSymbol(s) { - return s.valueDeclaration ? s.valueDeclaration.kind : 126; + return s.valueDeclaration ? s.valueDeclaration.kind : 128; } function getDeclarationFlagsFromSymbol(s) { return s.valueDeclaration ? ts.getCombinedNodeFlags(s.valueDeclaration) : s.flags & 134217728 ? 16 | 128 : 0; @@ -12130,7 +12599,7 @@ var ts; if (!(flags & (32 | 64))) { return; } - var enclosingClassDeclaration = ts.getAncestor(node, 191); + var enclosingClassDeclaration = ts.getAncestor(node, 195); var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; var declaringClass = getDeclaredTypeOfSymbol(prop.parent); if (flags & 32) { @@ -12177,7 +12646,7 @@ var ts; } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & 32) { - if (left.kind === 90 && getDeclarationKindFromSymbol(prop) !== 128) { + if (left.kind === 90 && getDeclarationKindFromSymbol(prop) !== 130) { error(right, ts.Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); } else { @@ -12189,12 +12658,12 @@ var ts; return anyType; } function isValidPropertyAccess(node, propertyName) { - var left = node.kind === 149 ? node.expression : node.left; + var left = node.kind === 151 ? node.expression : node.left; var type = checkExpressionOrQualifiedName(left); if (type !== unknownType && type !== anyType) { var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & 32) { - if (left.kind === 90 && getDeclarationKindFromSymbol(prop) !== 128) { + if (left.kind === 90 && getDeclarationKindFromSymbol(prop) !== 130) { return false; } else { @@ -12209,7 +12678,7 @@ var ts; function checkIndexedAccess(node) { if (!node.argumentExpression) { var sourceFile = getSourceFile(node); - if (node.parent.kind === 152 && node.parent.expression === node) { + if (node.parent.kind === 154 && node.parent.expression === node) { var start = ts.skipTrivia(sourceFile.text, node.expression.end); var end = node.end; grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead); @@ -12264,7 +12733,7 @@ var ts; return unknownType; } function resolveUntypedCall(node) { - if (node.kind === 153) { + if (node.kind === 155) { checkExpression(node.template); } else { @@ -12317,7 +12786,7 @@ var ts; } function getSpreadArgumentIndex(args) { for (var i = 0; i < args.length; i++) { - if (args[i].kind === 167) { + if (args[i].kind === 171) { return i; } } @@ -12327,11 +12796,11 @@ var ts; var adjustedArgCount; var typeArguments; var callIsIncomplete; - if (node.kind === 153) { + if (node.kind === 155) { var tagExpression = node; adjustedArgCount = args.length; typeArguments = undefined; - if (tagExpression.template.kind === 165) { + if (tagExpression.template.kind === 168) { var templateExpression = tagExpression.template; var lastSpan = ts.lastOrUndefined(templateExpression.templateSpans); ts.Debug.assert(lastSpan !== undefined); @@ -12346,7 +12815,7 @@ var ts; else { var callExpression = node; if (!callExpression.arguments) { - ts.Debug.assert(callExpression.kind === 152); + ts.Debug.assert(callExpression.kind === 154); return signature.minArgumentCount === 0; } adjustedArgCount = callExpression.arguments.hasTrailingComma ? args.length + 1 : args.length; @@ -12389,9 +12858,9 @@ var ts; var inferenceMapper = createInferenceMapper(context); for (var i = 0; i < args.length; i++) { var arg = args[i]; - if (arg.kind !== 168) { - var paramType = getTypeAtPosition(signature, arg.kind === 167 ? -1 : i); - if (i === 0 && args[i].parent.kind === 153) { + if (arg.kind !== 172) { + var paramType = getTypeAtPosition(signature, arg.kind === 171 ? -1 : i); + if (i === 0 && args[i].parent.kind === 155) { var argType = globalTemplateStringsArrayType; } else { @@ -12405,7 +12874,7 @@ var ts; for (var i = 0; i < args.length; i++) { if (excludeArgument[i] === false) { var arg = args[i]; - var paramType = getTypeAtPosition(signature, arg.kind === 167 ? -1 : i); + var paramType = getTypeAtPosition(signature, arg.kind === 171 ? -1 : i); inferTypes(context, checkExpressionWithContextualType(arg, paramType, inferenceMapper), paramType); } } @@ -12438,9 +12907,9 @@ var ts; function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) { for (var i = 0; i < args.length; i++) { var arg = args[i]; - if (arg.kind !== 168) { - var paramType = getTypeAtPosition(signature, arg.kind === 167 ? -1 : i); - var argType = i === 0 && node.kind === 153 ? globalTemplateStringsArrayType : arg.kind === 8 && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); + if (arg.kind !== 172) { + var paramType = getTypeAtPosition(signature, arg.kind === 171 ? -1 : i); + var argType = i === 0 && node.kind === 155 ? globalTemplateStringsArrayType : arg.kind === 8 && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); if (!checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined, ts.Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1)) { return false; } @@ -12450,10 +12919,10 @@ var ts; } function getEffectiveCallArguments(node) { var args; - if (node.kind === 153) { + if (node.kind === 155) { var template = node.template; args = [template]; - if (template.kind === 165) { + if (template.kind === 168) { ts.forEach(template.templateSpans, function (span) { args.push(span.expression); }); @@ -12466,7 +12935,7 @@ var ts; } function getEffectiveTypeArguments(callExpression) { if (callExpression.expression.kind === 90) { - var containingClass = ts.getAncestor(callExpression, 191); + var containingClass = ts.getAncestor(callExpression, 195); var baseClassTypeNode = containingClass && ts.getClassBaseTypeNode(containingClass); return baseClassTypeNode && baseClassTypeNode.typeArguments; } @@ -12475,7 +12944,7 @@ var ts; } } function resolveCall(node, signatures, candidatesOutArray) { - var isTaggedTemplate = node.kind === 153; + var isTaggedTemplate = node.kind === 155; var typeArguments; if (!isTaggedTemplate) { typeArguments = getEffectiveTypeArguments(node); @@ -12681,13 +13150,13 @@ var ts; var links = getNodeLinks(node); if (!links.resolvedSignature || candidatesOutArray) { links.resolvedSignature = anySignature; - if (node.kind === 151) { + if (node.kind === 153) { links.resolvedSignature = resolveCallExpression(node, candidatesOutArray); } - else if (node.kind === 152) { + else if (node.kind === 154) { links.resolvedSignature = resolveNewExpression(node, candidatesOutArray); } - else if (node.kind === 153) { + else if (node.kind === 155) { links.resolvedSignature = resolveTaggedTemplateExpression(node, candidatesOutArray); } else { @@ -12702,9 +13171,9 @@ var ts; if (node.expression.kind === 90) { return voidType; } - if (node.kind === 152) { + if (node.kind === 154) { var declaration = signature.declaration; - if (declaration && declaration.kind !== 129 && declaration.kind !== 133 && declaration.kind !== 137) { + if (declaration && declaration.kind !== 131 && declaration.kind !== 135 && declaration.kind !== 139) { if (compilerOptions.noImplicitAny) { error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type); } @@ -12749,18 +13218,28 @@ var ts; links.type = instantiateType(getTypeOfSymbol(context.parameters[context.parameters.length - 1]), mapper); } } + function createPromiseType(promisedType, location) { + if (globalPromiseSymbol) { + promisedType = getAwaitedType(promisedType); + var promiseType = globalPromiseType || getDeclaredTypeOfSymbol(globalPromiseSymbol); + return promiseType !== emptyObjectType ? createTypeReference(promiseType, [promisedType]) : emptyObjectType; + } + error(location, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); + return unknownType; + } function getReturnTypeFromBody(func, contextualMapper) { var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func); if (!func.body) { return unknownType; } - if (func.body.kind !== 170) { - var type = checkExpressionCached(func.body, contextualMapper); + var isAsync = ts.isAsyncFunction(func); + if (func.body.kind !== 174) { + var type = checkExpressionCached(func.body, contextualMapper, isAsync); } else { - var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); + var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync); if (types.length === 0) { - return voidType; + return isAsync ? createPromiseType(voidType, func) : voidType; } var type = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!type) { @@ -12771,14 +13250,15 @@ var ts; if (!contextualSignature) { reportErrorsFromWidening(func, type); } - return getWidenedType(type); + type = getWidenedType(type); + return isAsync ? createPromiseType(type, func) : type; } - function checkAndAggregateReturnExpressionTypes(body, contextualMapper) { + function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync) { var aggregatedTypes = []; ts.forEachReturnStatement(body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { - var type = checkExpressionCached(expr, contextualMapper); + var type = checkExpressionCached(expr, contextualMapper, isAsync); if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } @@ -12792,7 +13272,7 @@ var ts; }); } function bodyContainsSingleThrowStatement(body) { - return (body.statements.length === 1) && (body.statements[0].kind === 185); + return (body.statements.length === 1) && (body.statements[0].kind === 189); } function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) { if (!produceDiagnostics) { @@ -12801,7 +13281,7 @@ var ts; if (returnType === voidType || returnType === anyType) { return; } - if (ts.nodeIsMissing(func.body) || func.body.kind !== 170) { + if (ts.nodeIsMissing(func.body) || func.body.kind !== 174) { return; } var bodyBlock = func.body; @@ -12814,20 +13294,24 @@ var ts; error(func.type, ts.Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement); } function checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper) { - ts.Debug.assert(node.kind !== 128 || ts.isObjectLiteralMethod(node)); + ts.Debug.assert(node.kind !== 130 || ts.isObjectLiteralMethod(node)); var hasGrammarError = checkGrammarFunctionLikeDeclaration(node); - if (!hasGrammarError && node.kind === 156) { + if (!hasGrammarError && node.kind === 158) { checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); } if (contextualMapper === identityMapper && isContextSensitive(node)) { return anyFunctionType; } + var isAsync = ts.isAsyncFunction(node); + if (isAsync) { + emitAwaiter = true; + } var links = getNodeLinks(node); var type = getTypeOfSymbol(node.symbol); - if (!(links.flags & 64)) { + if (!(links.flags & 256)) { var contextualSignature = getContextualSignature(node); - if (!(links.flags & 64)) { - links.flags |= 64; + if (!(links.flags & 256)) { + links.flags |= 256; if (contextualSignature) { var signature = getSignaturesOfType(type, 0)[0]; if (isContextSensitive(node)) { @@ -12844,25 +13328,32 @@ var ts; checkSignatureDeclaration(node); } } - if (produceDiagnostics && node.kind !== 128 && node.kind !== 127) { + if (produceDiagnostics && node.kind !== 130 && node.kind !== 129) { checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollisionWithCapturedArgumentsVariable(node, node.name); } return type; } function checkFunctionExpressionOrObjectLiteralMethodBody(node) { - ts.Debug.assert(node.kind !== 128 || ts.isObjectLiteralMethod(node)); - if (node.type) { - checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); + ts.Debug.assert(node.kind !== 130 || ts.isObjectLiteralMethod(node)); + var isAsync = ts.isAsyncFunction(node); + var returnType = node.type ? getTypeFromTypeNode(node.type) : undefined; + var promisedType; + if (returnType && isAsync) { + promisedType = checkAsyncFunctionReturnType(node, returnType); + } + if (returnType) { + checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, isAsync ? promisedType : returnType); } if (node.body) { - if (node.body.kind === 170) { + if (node.body.kind === 174) { checkSourceElement(node.body); } else { var exprType = checkExpression(node.body); - if (node.type) { - checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, undefined); + if (returnType) { + checkTypeAssignableTo(isAsync ? getAwaitedType(exprType) : exprType, isAsync ? promisedType : returnType, node.body); } checkFunctionExpressionBodies(node.body); } @@ -12885,12 +13376,12 @@ var ts; case 64: var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & 3) !== 0; - case 149: + case 151: var symbol = findSymbol(n); return !symbol || symbol === unknownSymbol || (symbol.flags & ~8) !== 0; - case 150: + case 152: return true; - case 155: + case 157: return isReferenceOrErrorExpression(n.expression); default: return false; @@ -12899,10 +13390,10 @@ var ts; function isConstVariableReference(n) { switch (n.kind) { case 64: - case 149: + case 151: var symbol = findSymbol(n); return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 4096) !== 0; - case 150: + case 152: var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8) { @@ -12911,7 +13402,7 @@ var ts; return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 4096) !== 0; } return false; - case 155: + case 157: return isConstVariableReference(n.expression); default: return false; @@ -12942,6 +13433,19 @@ var ts; var operandType = checkExpression(node.expression); return undefinedType; } + function checkAwaitExpression(node) { + if (!(node.parserContextFlags & 64)) { + var parameter = ts.getContainingParameter(node); + if (parameter && parameter.parserContextFlags & 64) { + grammarErrorAfterFirstToken(node, ts.Diagnostics._0_expression_is_not_allowed_in_an_initializer, "await"); + } + else { + grammarErrorOnFirstToken(node, ts.Diagnostics.await_expression_must_be_contained_within_an_async_function); + } + } + var operandType = checkExpression(node.expression); + return getAwaitedType(operandType); + } function checkPrefixUnaryExpression(node) { if ((node.operator === 38 || node.operator === 39)) { checkGrammarEvalOrArgumentsInStrictMode(node, node.operand); @@ -13016,7 +13520,7 @@ var ts; var properties = node.properties; for (var i = 0; i < properties.length; i++) { var p = properties[i]; - if (p.kind === 204 || p.kind === 205) { + if (p.kind === 208 || p.kind === 209) { var name = p.name; var type = sourceType.flags & 1 ? sourceType : getTypeOfPropertyOfType(sourceType, name.text) || isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, 1) || getIndexTypeOfType(sourceType, 0); if (type) { @@ -13040,8 +13544,8 @@ var ts; var elements = node.elements; for (var i = 0; i < elements.length; i++) { var e = elements[i]; - if (e.kind !== 168) { - if (e.kind !== 167) { + if (e.kind !== 172) { + if (e.kind !== 171) { var propName = "" + i; var type = sourceType.flags & 1 ? sourceType : isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : getIndexTypeOfType(sourceType, 1); if (type) { @@ -13064,14 +13568,14 @@ var ts; return sourceType; } function checkDestructuringAssignment(target, sourceType, contextualMapper) { - if (target.kind === 163 && target.operator === 52) { + if (target.kind === 166 && target.operator === 52) { checkBinaryExpression(target, contextualMapper); target = target.left; } - if (target.kind === 148) { + if (target.kind === 150) { return checkObjectLiteralAssignment(target, sourceType, contextualMapper); } - if (target.kind === 147) { + if (target.kind === 149) { return checkArrayLiteralAssignment(target, sourceType, contextualMapper); } return checkReferenceAssignment(target, sourceType, contextualMapper); @@ -13088,7 +13592,7 @@ var ts; checkGrammarEvalOrArgumentsInStrictMode(node, node.left); } var operator = node.operator; - if (operator === 52 && (node.left.kind === 148 || node.left.kind === 147)) { + if (operator === 52 && (node.left.kind === 150 || node.left.kind === 149)) { return checkDestructuringAssignment(node.left, checkExpression(node.right, contextualMapper), contextualMapper); } var leftType = checkExpression(node.left, contextualMapper); @@ -13209,7 +13713,13 @@ var ts; } function checkYieldExpression(node) { if (!(node.parserContextFlags & 4)) { - grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); + var parameter = ts.getContainingParameter(node); + if (parameter && (parameter.parserContextFlags & 4)) { + grammarErrorAfterFirstToken(node, ts.Diagnostics._0_expression_is_not_allowed_in_an_initializer, "yield"); + } + else { + grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); + } } else { grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported); @@ -13234,11 +13744,17 @@ var ts; node.contextualType = saveContextualType; return result; } - function checkExpressionCached(node, contextualMapper) { + function checkExpressionCached(node, contextualMapper, resolveAwaitedType) { var links = getNodeLinks(node); if (!links.resolvedType) { links.resolvedType = checkExpression(node, contextualMapper); } + if (resolveAwaitedType) { + if (!links.resolvedAwaitedType) { + links.resolvedAwaitedType = getAwaitedType(links.resolvedType); + } + return links.resolvedAwaitedType; + } return links.resolvedType; } function checkPropertyAssignment(node, contextualMapper) { @@ -13275,7 +13791,7 @@ var ts; } function checkExpressionOrQualifiedName(node, contextualMapper) { var type; - if (node.kind == 121) { + if (node.kind == 123) { type = checkQualifiedName(node); } else { @@ -13283,7 +13799,7 @@ var ts; type = instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } if (isConstEnumObjectType(type)) { - var ok = (node.parent.kind === 149 && node.parent.expression === node) || (node.parent.kind === 150 && node.parent.expression === node) || ((node.kind === 64 || node.kind === 121) && isInRightSideOfImportOrExportAssignment(node)); + var ok = (node.parent.kind === 151 && node.parent.expression === node) || (node.parent.kind === 152 && node.parent.expression === node) || ((node.kind === 64 || node.kind === 123) && isInRightSideOfImportOrExportAssignment(node)); if (!ok) { error(node, ts.Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment); } @@ -13309,52 +13825,54 @@ var ts; return booleanType; case 7: return checkNumericLiteral(node); - case 165: + case 168: return checkTemplateExpression(node); case 8: case 10: return stringType; case 9: return globalRegExpType; - case 147: - return checkArrayLiteral(node, contextualMapper); - case 148: - return checkObjectLiteral(node, contextualMapper); case 149: - return checkPropertyAccessExpression(node); + return checkArrayLiteral(node, contextualMapper); case 150: - return checkIndexedAccess(node); + return checkObjectLiteral(node, contextualMapper); case 151: + return checkPropertyAccessExpression(node); case 152: - return checkCallExpression(node); + return checkIndexedAccess(node); case 153: - return checkTaggedTemplateExpression(node); case 154: - return checkTypeAssertion(node); + return checkCallExpression(node); case 155: - return checkExpression(node.expression, contextualMapper); + return checkTaggedTemplateExpression(node); case 156: + return checkTypeAssertion(node); case 157: - return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); + return checkExpression(node.expression, contextualMapper); + case 158: case 159: + return checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); + case 161: return checkTypeOfExpression(node); - case 158: - return checkDeleteExpression(node); case 160: + return checkDeleteExpression(node); + case 162: return checkVoidExpression(node); - case 161: + case 163: + return checkAwaitExpression(node); + case 164: return checkPrefixUnaryExpression(node); - case 162: + case 165: return checkPostfixUnaryExpression(node); - case 163: + case 166: return checkBinaryExpression(node, contextualMapper); - case 164: - return checkConditionalExpression(node, contextualMapper); case 167: + return checkConditionalExpression(node, contextualMapper); + case 171: return checkSpreadElementExpression(node, contextualMapper); - case 168: + case 172: return undefinedType; - case 166: + case 169: checkYieldExpression(node); return unknownType; } @@ -13376,7 +13894,7 @@ var ts; var func = ts.getContainingFunction(node); if (node.flags & 112) { func = ts.getContainingFunction(node); - if (!(func.kind === 129 && ts.nodeIsPresent(func.body))) { + if (!(func.kind === 131 && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } @@ -13390,10 +13908,10 @@ var ts; } } function checkSignatureDeclaration(node) { - if (node.kind === 134) { + if (node.kind === 136) { checkGrammarIndexSignature(node); } - else if (node.kind === 136 || node.kind === 190 || node.kind === 137 || node.kind === 132 || node.kind === 129 || node.kind === 133) { + else if (node.kind === 138 || node.kind === 194 || node.kind === 139 || node.kind === 134 || node.kind === 131 || node.kind === 135) { checkGrammarFunctionLikeDeclaration(node); } checkTypeParameters(node.typeParameters); @@ -13402,22 +13920,40 @@ var ts; checkSourceElement(node.type); } if (produceDiagnostics) { + checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name); + checkCollisionWithGeneratorVariablesInGeneratedCode(node, node.name); checkCollisionWithArgumentsInGeneratedCode(node); if (compilerOptions.noImplicitAny && !node.type) { switch (node.kind) { - case 133: + case 135: error(node, ts.Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; - case 132: + case 134: error(node, ts.Diagnostics.Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); break; } } + if (ts.isAsyncFunction(node)) { + var promiseConstructor = getPromiseConstructor(node); + if (promiseConstructor) { + var promiseIdentifier = getFirstIdentifier(promiseConstructor); + var promiseName = promiseIdentifier.text; + var typeSymbol = resolveName(node, promiseName, 793056 | 1536, undefined, undefined); + var valueSymbol = resolveName(node, promiseName, 107455, undefined, undefined); + if (typeSymbol !== valueSymbol) { + var valueLinks = getNodeLinks(valueSymbol.valueDeclaration); + if (!(valueLinks.flags & 512)) { + valueLinks.flags |= 512; + error(valueSymbol.valueDeclaration, ts.Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, promiseName, ts.getTextOfNode(promiseConstructor)); + } + } + } + } } checkSpecializedSignatureDeclaration(node); } function checkTypeForDuplicateIndexSignatures(node) { - if (node.kind === 192) { + if (node.kind === 196) { var nodeSymbol = getSymbolOfNode(node); if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) { return; @@ -13476,17 +14012,17 @@ var ts; return; } function isSuperCallExpression(n) { - return n.kind === 151 && n.expression.kind === 90; + return n.kind === 153 && n.expression.kind === 90; } function containsSuperCall(n) { if (isSuperCallExpression(n)) { return true; } switch (n.kind) { - case 156: - case 190: - case 157: - case 148: return false; + case 158: + case 194: + case 159: + case 150: return false; default: return ts.forEachChild(n, containsSuperCall); } } @@ -13494,19 +14030,19 @@ var ts; if (n.kind === 92) { error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location); } - else if (n.kind !== 156 && n.kind !== 190) { + else if (n.kind !== 158 && n.kind !== 194) { ts.forEachChild(n, markThisReferencesAsErrors); } } function isInstancePropertyWithInitializer(n) { - return n.kind === 126 && !(n.flags & 128) && !!n.initializer; + return n.kind === 128 && !(n.flags & 128) && !!n.initializer; } if (ts.getClassBaseTypeNode(node.parent)) { if (containsSuperCall(node.body)) { var superCallShouldBeFirst = ts.forEach(node.parent.members, isInstancePropertyWithInitializer) || ts.forEach(node.parameters, function (p) { return p.flags & (16 | 32 | 64); }); if (superCallShouldBeFirst) { var statements = node.body.statements; - if (!statements.length || statements[0].kind !== 173 || !isSuperCallExpression(statements[0].expression)) { + if (!statements.length || statements[0].kind !== 177 || !isSuperCallExpression(statements[0].expression)) { error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); } else { @@ -13521,14 +14057,14 @@ var ts; } function checkAccessorDeclaration(node) { if (produceDiagnostics) { - checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); - if (node.kind === 130) { + checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); + if (node.kind === 132) { if (!ts.isInAmbientContext(node) && ts.nodeIsPresent(node.body) && !(bodyContainsAReturnStatement(node.body) || bodyContainsSingleThrowStatement(node.body))) { error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement); } } if (!ts.hasDynamicName(node)) { - var otherKind = node.kind === 130 ? 131 : 130; + var otherKind = node.kind === 132 ? 133 : 132; var otherAccessor = ts.getDeclarationOfKind(node.symbol, otherKind); if (otherAccessor) { if (((node.flags & 112) !== (otherAccessor.flags & 112))) { @@ -13602,9 +14138,9 @@ var ts; return; } var signaturesToCheck; - if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 192) { - ts.Debug.assert(signatureDeclarationNode.kind === 132 || signatureDeclarationNode.kind === 133); - var signatureKind = signatureDeclarationNode.kind === 132 ? 0 : 1; + if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 196) { + ts.Debug.assert(signatureDeclarationNode.kind === 134 || signatureDeclarationNode.kind === 135); + var signatureKind = signatureDeclarationNode.kind === 134 ? 0 : 1; var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent); var containingType = getDeclaredTypeOfSymbol(containingSymbol); signaturesToCheck = getSignaturesOfType(containingType, signatureKind); @@ -13622,7 +14158,7 @@ var ts; } function getEffectiveDeclarationFlags(n, flagsToCheck) { var flags = ts.getCombinedNodeFlags(n); - if (n.parent.kind !== 192 && ts.isInAmbientContext(n)) { + if (n.parent.kind !== 196 && ts.isInAmbientContext(n)) { if (!(flags & 2)) { flags |= 1; } @@ -13695,7 +14231,7 @@ var ts; if (subsequentNode.kind === node.kind) { var errorNode = subsequentNode.name || subsequentNode; if (node.name && subsequentNode.name && node.name.text === subsequentNode.name.text) { - ts.Debug.assert(node.kind === 128 || node.kind === 127); + ts.Debug.assert(node.kind === 130 || node.kind === 129); ts.Debug.assert((node.flags & 128) !== (subsequentNode.flags & 128)); var diagnostic = node.flags & 128 ? ts.Diagnostics.Function_overload_must_be_static : ts.Diagnostics.Function_overload_must_not_be_static; error(errorNode, diagnostic); @@ -13721,11 +14257,11 @@ var ts; for (var i = 0; i < declarations.length; i++) { var node = declarations[i]; var inAmbientContext = ts.isInAmbientContext(node); - var inAmbientContextOrInterface = node.parent.kind === 192 || node.parent.kind === 139 || inAmbientContext; + var inAmbientContextOrInterface = node.parent.kind === 196 || node.parent.kind === 141 || inAmbientContext; if (inAmbientContextOrInterface) { previousDeclaration = undefined; } - if (node.kind === 190 || node.kind === 128 || node.kind === 127 || node.kind === 129) { + if (node.kind === 194 || node.kind === 130 || node.kind === 129 || node.kind === 131) { var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck); someNodeFlags |= currentNodeFlags; allNodeFlags &= currentNodeFlags; @@ -13822,14 +14358,14 @@ var ts; } function getDeclarationSpaces(d) { switch (d.kind) { - case 192: + case 196: return 2097152; - case 195: + case 199: return d.name.kind === 8 || ts.getModuleInstanceState(d) !== 0 ? 4194304 | 1048576 : 4194304; - case 191: - case 194: + case 195: + case 198: return 2097152 | 1048576; - case 197: + case 201: var result = 0; var target = resolveImport(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { @@ -13841,11 +14377,92 @@ var ts; } } } + function getPromisedType(type) { + if (!globalPromiseLikeInterfaceType || !(type.flags & 48128)) { + return undefined; + } + if (isTypeAssignableTo(type, globalPromiseLikeInterfaceType)) { + var awaitedTypes = []; + var thenProp = getPropertyOfType(type, "then"); + var thenType = getTypeOfSymbol(thenProp); + var thenSignatures = getSignaturesOfType(thenType, 0); + var thenSignatureCount = thenSignatures.length; + for (var i = 0; i < thenSignatureCount; i++) { + var thenSignature = getErasedSignature(thenSignatures[i]); + var onfulfilledParameterType = getTypeAtPosition(thenSignature, 0); + var onfulfilledParameterSignatures = getSignaturesOfType(onfulfilledParameterType, 0); + var onfulfilledParameterSignaturesCount = onfulfilledParameterSignatures.length; + for (var j = 0; j < onfulfilledParameterSignaturesCount; j++) { + var onfulfilledParameterSignature = onfulfilledParameterSignatures[i]; + var valueParameterType = getTypeAtPosition(onfulfilledParameterSignature, 0); + if (valueParameterType !== type) { + awaitedTypes.push(valueParameterType); + } + } + } + return getUnionType(awaitedTypes); + } + return undefined; + } + function getAwaitedType(type) { + if (!globalPromiseLikeInterfaceType || !(type.flags & 48128)) { + return type; + } + var promisedType = getPromisedType(type); + if (promisedType) { + if (promisedType === type) { + return emptyObjectType; + } + var seen; + while (true) { + var nestedPromisedType = getPromisedType(promisedType); + if (!nestedPromisedType) { + return promisedType; + } + if (!seen) { + seen = []; + seen[type.id] = true; + seen[promisedType.id] = true; + } + else if (seen[nestedPromisedType.id]) { + return emptyObjectType; + } + seen[nestedPromisedType.id] = true; + promisedType = nestedPromisedType; + } + return promisedType; + } + if (isTypeAssignableTo(type, thenableType)) { + error(null, ts.Diagnostics.Type_for_await_does_not_have_a_valid_callable_then_member); + return emptyObjectType; + } + return type; + } + function checkAsyncFunctionReturnType(node, returnType) { + if (!returnType) { + returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } + var declaredType = returnType.symbol ? getTypeOfSymbol(returnType.symbol) : emptyObjectType; + if (isTypeAssignableTo(declaredType, globalPromiseConstructorLikeInterfaceType)) { + var promisedType = getPromisedType(returnType); + if (promisedType) { + var promiseConstructor = getPromiseConstructor(node); + if (promiseConstructor) { + emitAwaiter = true; + checkExpressionOrQualifiedName(promiseConstructor); + return getAwaitedType(promisedType); + } + } + } + error(node, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); + return emptyObjectType; + } function checkFunctionDeclaration(node) { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollisionWithCapturedArgumentsVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); } } @@ -13868,19 +14485,25 @@ var ts; } } checkSourceElement(node.body); - if (node.type && !isAccessor(node.kind)) { - checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); + if (node.type && !ts.isAnyAccessor(node)) { + if (ts.isAsyncFunction(node)) { + var promisedType = checkAsyncFunctionReturnType(node, getTypeFromTypeNode(node.type)); + checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, promisedType); + } + else { + checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); + } } if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) { reportImplicitAnyError(node, anyType); } } function checkBlock(node) { - if (node.kind === 170) { + if (node.kind === 174) { checkGrammarForStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); - if (ts.isFunctionBlock(node) || node.kind === 196) { + if (ts.isFunctionBlock(node) || node.kind === 200) { checkFunctionExpressionBodies(node); } } @@ -13898,14 +14521,14 @@ var ts; if (!(identifier && identifier.text === name)) { return false; } - if (node.kind === 126 || node.kind === 125 || node.kind === 128 || node.kind === 127 || node.kind === 130 || node.kind === 131) { + if (node.kind === 128 || node.kind === 127 || node.kind === 130 || node.kind === 129 || node.kind === 132 || node.kind === 133) { return false; } if (ts.isInAmbientContext(node)) { return false; } var root = getRootDeclaration(node); - if (root.kind === 124 && ts.nodeIsMissing(root.parent.body)) { + if (root.kind === 126 && ts.nodeIsMissing(root.parent.body)) { return false; } return true; @@ -13915,6 +14538,11 @@ var ts; potentialThisCollisions.push(node); } } + function checkCollisionWithCapturedArgumentsVariable(node, name) { + if (needCollisionCheckForIdentifier(node, name, "_arguments")) { + potentialArgumentsCollisions.push(node); + } + } function checkIfThisIsCapturedInEnclosingScope(node) { var current = node; while (current) { @@ -13931,11 +14559,27 @@ var ts; current = current.parent; } } + function checkIfArgumentsIsCapturedInEnclosingScope(node) { + var current = node; + while (current) { + if (getNodeCheckFlags(current) & 16) { + var isDeclaration = node.kind !== 64; + if (isDeclaration) { + error(node.name, ts.Diagnostics.Duplicate_identifier_arguments_Compiler_uses_variable_declaration_arguments_to_capture_arguments_reference); + } + else { + error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_arguments_that_compiler_uses_to_capture_arguments_reference); + } + return; + } + current = current.parent; + } + } function checkCollisionWithCapturedSuperVariable(node, name) { if (!needCollisionCheckForIdentifier(node, name, "_super")) { return; } - var enclosingClass = ts.getAncestor(node, 191); + var enclosingClass = ts.getAncestor(node, 195); if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) { return; } @@ -13953,35 +14597,88 @@ var ts; if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { return; } - if (node.kind === 195 && ts.getModuleInstanceState(node) !== 1) { + if (node.kind === 199 && ts.getModuleInstanceState(node) !== 1) { return; } var parent = getDeclarationContainer(node); - if (parent.kind === 207 && ts.isExternalModule(parent)) { + if (parent.kind === 211 && ts.isExternalModule(parent)) { error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module, ts.declarationNameToString(name), ts.declarationNameToString(name)); } } - function checkCollisionWithConstDeclarations(node) { + function checkVarDeclaredNamesNotShadowed(node) { if (node.initializer && (ts.getCombinedNodeFlags(node) & 6144) === 0) { var symbol = getSymbolOfNode(node); if (symbol.flags & 1) { var localDeclarationSymbol = resolveName(node, node.name.text, 3, undefined, undefined); if (localDeclarationSymbol && localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & 2) { - if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 4096) { - error(node, ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0, symbolToString(localDeclarationSymbol)); + if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 6144) { + var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 193); + var container = varDeclList.parent.kind === 175 && varDeclList.parent.parent; + var namesShareScope = container && (container.kind === 174 && ts.isAnyFunction(container.parent) || (container.kind === 200 && container.kind === 199) || container.kind === 211); + if (!namesShareScope) { + var name = symbolToString(localDeclarationSymbol); + error(ts.getErrorSpanForNode(node), ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name); + } } } } } } + function getPromiseConstructor(node) { + if (node.type && node.type.kind === 137) { + var typeReference = node.type; + return typeReference.typeName; + } + if (globalPromiseSymbol && globalPromiseSymbol === resolveName(node, "Promise", 107455, undefined, undefined)) { + return globalPromiseSymbol.valueDeclaration.name; + } + } + function checkCollisionWithAwaiterVariablesInGeneratedCode(node, name) { + if (!name || name.kind !== 64 || isTypeNode(name)) { + return; + } + var identifier = name; + if (identifier.text === "__awaiter") { + var isDeclaration = node.kind !== 64; + if (isDeclaration) { + error(node, ts.Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, identifier.text, identifier.text); + } + else { + error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions, identifier.text); + } + } + var container = ts.getContainingFunction(name); + if (container && container.flags & 16384 && node.kind !== 64) { + var promiseConstructor = getPromiseConstructor(container); + if (promiseConstructor && promiseConstructor.kind === 64 && promiseConstructor.text === identifier.text) { + error(node, ts.Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, identifier.text, ts.getTextOfNode(promiseConstructor)); + } + } + } + function checkCollisionWithGeneratorVariablesInGeneratedCode(node, name) { + if (!name || name.kind !== 64 || compilerOptions.target > 1 || isTypeNode(name)) { + return; + } + var identifier = name; + if (identifier.text !== "__generator") { + return; + } + var isDeclaration = node.kind !== 64; + if (isDeclaration) { + error(node, ts.Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, identifier.text, identifier.text); + } + else { + error(node, ts.Diagnostics.Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions, identifier.text); + } + } function isParameterDeclaration(node) { - while (node.kind === 146) { + while (node.kind === 148) { node = node.parent.parent; } - return node.kind === 124; + return node.kind === 126; } function checkParameterInitializer(node) { - if (getRootDeclaration(node).kind === 124) { + if (getRootDeclaration(node).kind === 126) { var func = ts.getContainingFunction(node); visit(node.initializer); } @@ -13989,7 +14686,7 @@ var ts; if (n.kind === 64) { var referencedSymbol = getNodeLinks(n).resolvedSymbol; if (referencedSymbol && referencedSymbol !== unknownSymbol && getSymbol(func.locals, referencedSymbol.name, 107455) === referencedSymbol) { - if (referencedSymbol.valueDeclaration.kind === 124) { + if (referencedSymbol.valueDeclaration.kind === 126) { if (referencedSymbol.valueDeclaration === node) { error(n, ts.Diagnostics.Parameter_0_cannot_be_referenced_in_its_initializer, ts.declarationNameToString(node.name)); return; @@ -14018,7 +14715,7 @@ var ts; if (ts.isBindingPattern(node.name)) { ts.forEach(node.name.elements, checkSourceElement); } - if (node.initializer && getRootDeclaration(node).kind === 124 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { + if (node.initializer && getRootDeclaration(node).kind === 126 && ts.nodeIsMissing(ts.getContainingFunction(node).body)) { error(node, ts.Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); return; } @@ -14046,13 +14743,20 @@ var ts; checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined); } } - if (node.kind !== 126 && node.kind !== 125) { + if (node.kind !== 128 && node.kind !== 127) { checkExportsOnMergedDeclarations(node); - checkCollisionWithConstDeclarations(node); + if (node.kind === 192 || node.kind === 148) { + checkVarDeclaredNamesNotShadowed(node); + } checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); + checkCollisionWithCapturedArgumentsVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); } + if (!ts.isBindingPattern(node.name) && isLexicalArguments(node.name)) { + var container = ts.getContainingFunction(node); + captureLexicalArguments(node.name, container); + } } function checkVariableDeclaration(node) { checkGrammarVariableDeclaration(node); @@ -14069,17 +14773,20 @@ var ts; function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) { if (node.modifiers) { if (inBlockOrObjectLiteralExpression(node)) { - return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + if (node.modifiers.flags & ~16384) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } } } } function inBlockOrObjectLiteralExpression(node) { while (node) { - if (node.kind === 170 || node.kind === 148) { + if (node.kind === 174 || node.kind === 150) { return true; } node = node.parent; } + return false; } function checkExpressionStatement(node) { checkGrammarForStatementInAmbientContext(node); @@ -14103,12 +14810,12 @@ var ts; } function checkForStatement(node) { if (!checkGrammarForStatementInAmbientContext(node)) { - if (node.initializer && node.initializer.kind == 189) { + if (node.initializer && node.initializer.kind == 193) { checkGrammarVariableDeclarationList(node.initializer); } } if (node.initializer) { - if (node.initializer.kind === 189) { + if (node.initializer.kind === 193) { ts.forEach(node.initializer.declarations, checkVariableDeclaration); } else { @@ -14123,7 +14830,7 @@ var ts; } function checkForInStatement(node) { if (!checkGrammarForStatementInAmbientContext(node)) { - if (node.initializer.kind === 189) { + if (node.initializer.kind === 193) { var variableList = node.initializer; if (!checkGrammarVariableDeclarationList(variableList)) { if (variableList.declarations.length > 1) { @@ -14132,7 +14839,7 @@ var ts; } } } - if (node.initializer.kind === 189) { + if (node.initializer.kind === 193) { var variableDeclarationList = node.initializer; if (variableDeclarationList.declarations.length >= 1) { var decl = variableDeclarationList.declarations[0]; @@ -14162,7 +14869,7 @@ var ts; checkGrammarForStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node); } function isGetAccessorWithAnnotatatedSetAccessor(node) { - return !!(node.kind === 130 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 131))); + return !!(node.kind === 132 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 133))); } function checkReturnStatement(node) { if (!checkGrammarForStatementInAmbientContext(node)) { @@ -14176,15 +14883,18 @@ var ts; if (func) { var returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func)); var exprType = checkExpressionCached(node.expression); - if (func.kind === 131) { + if (func.kind === 133) { error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value); } else { - if (func.kind === 129) { + if (func.kind === 131) { if (!isTypeAssignableTo(exprType, returnType)) { error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } } + else if (func.type && !ts.isAnyAccessor(func) && ts.isAsyncFunction(func)) { + checkTypeAssignableTo(getAwaitedType(exprType), getPromisedType(returnType), node.expression, undefined); + } else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) { checkTypeAssignableTo(exprType, returnType, node.expression, undefined); } @@ -14207,7 +14917,7 @@ var ts; var hasDuplicateDefaultClause = false; var expressionType = checkExpression(node.expression); ts.forEach(node.clauses, function (clause) { - if (clause.kind === 201 && !hasDuplicateDefaultClause) { + if (clause.kind === 205 && !hasDuplicateDefaultClause) { if (firstDefaultClause === undefined) { firstDefaultClause = clause; } @@ -14219,7 +14929,7 @@ var ts; hasDuplicateDefaultClause = true; } } - if (produceDiagnostics && clause.kind === 200) { + if (produceDiagnostics && clause.kind === 204) { var caseClause = clause; var caseType = checkExpression(caseClause.expression); if (!isTypeAssignableTo(expressionType, caseType)) { @@ -14236,7 +14946,7 @@ var ts; if (ts.isAnyFunction(current)) { break; } - if (current.kind === 184 && current.label.text === node.label.text) { + if (current.kind === 188 && current.label.text === node.label.text) { var sourceFile = ts.getSourceFileOfNode(node); grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label)); break; @@ -14283,7 +14993,7 @@ var ts; checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, 0); checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, 1); }); - if (type.flags & 1024 && type.symbol.valueDeclaration.kind === 191) { + if (type.flags & 1024 && type.symbol.valueDeclaration.kind === 195) { var classDeclaration = type.symbol.valueDeclaration; for (var i = 0; i < classDeclaration.members.length; i++) { var member = classDeclaration.members[i]; @@ -14314,7 +15024,7 @@ var ts; return; } var errorNode; - if (prop.valueDeclaration.name.kind === 122 || prop.parent === containingType.symbol) { + if (prop.valueDeclaration.name.kind === 124 || prop.parent === containingType.symbol) { errorNode = prop.valueDeclaration; } else if (indexDeclaration) { @@ -14361,6 +15071,8 @@ var ts; checkTypeParameters(node.typeParameters); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name); + checkCollisionWithGeneratorVariablesInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); @@ -14453,9 +15165,6 @@ var ts; } } } - function isAccessor(kind) { - return kind === 130 || kind === 131; - } function areTypeParametersIdentical(list1, list2) { if (!list1 && !list2) { return true; @@ -14521,7 +15230,7 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); - var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 192); + var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 196); if (symbol.declarations.length > 1) { if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) { error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters); @@ -14550,14 +15259,14 @@ var ts; } function computeEnumMemberValues(node) { var nodeLinks = getNodeLinks(node); - if (!(nodeLinks.flags & 128)) { + if (!(nodeLinks.flags & 1024)) { var enumSymbol = getSymbolOfNode(node); var enumType = getDeclaredTypeOfSymbol(enumSymbol); var autoValue = 0; var ambient = ts.isInAmbientContext(node); var enumIsConst = ts.isConst(node); ts.forEach(node.members, function (member) { - if (member.name.kind !== 122 && isNumericLiteralName(member.name.text)) { + if (member.name.kind !== 124 && isNumericLiteralName(member.name.text)) { error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name); } var initializer = member.initializer; @@ -14587,13 +15296,13 @@ var ts; getNodeLinks(member).enumMemberValue = autoValue++; } }); - nodeLinks.flags |= 128; + nodeLinks.flags |= 1024; } function getConstantValueForEnumMemberInitializer(initializer, enumIsConst) { return evalConstant(initializer); function evalConstant(e) { switch (e.kind) { - case 161: + case 164: var value = evalConstant(e.operand); if (value === undefined) { return undefined; @@ -14604,7 +15313,7 @@ var ts; case 47: return enumIsConst ? ~value : undefined; } return undefined; - case 163: + case 166: if (!enumIsConst) { return undefined; } @@ -14632,11 +15341,11 @@ var ts; return undefined; case 7: return +e.text; - case 155: + case 157: return enumIsConst ? evalConstant(e.expression) : undefined; case 64: - case 150: - case 149: + case 152: + case 151: if (!enumIsConst) { return undefined; } @@ -14649,7 +15358,7 @@ var ts; propertyName = e.text; } else { - if (e.kind === 150) { + if (e.kind === 152) { if (e.argumentExpression === undefined || e.argumentExpression.kind !== 8) { return undefined; } @@ -14691,6 +15400,8 @@ var ts; checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name); + checkCollisionWithGeneratorVariablesInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); computeEnumMemberValues(node); var enumSymbol = getSymbolOfNode(node); @@ -14706,7 +15417,7 @@ var ts; } var seenEnumMissingInitialInitializer = false; ts.forEach(enumSymbol.declarations, function (declaration) { - if (declaration.kind !== 194) { + if (declaration.kind !== 198) { return false; } var enumDeclaration = declaration; @@ -14729,7 +15440,7 @@ var ts; var declarations = symbol.declarations; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; - if ((declaration.kind === 191 || (declaration.kind === 190 && ts.nodeIsPresent(declaration.body))) && !ts.isInAmbientContext(declaration)) { + if ((declaration.kind === 195 || (declaration.kind === 194 && ts.nodeIsPresent(declaration.body))) && !ts.isInAmbientContext(declaration)) { return declaration; } } @@ -14741,11 +15452,11 @@ var ts; if (!ts.isInAmbientContext(node) && node.name.kind === 8) { grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names); } - else if (node.name.kind === 64 && node.body.kind === 196) { + else if (node.name.kind === 64 && node.body.kind === 200) { var statements = node.body.statements; for (var i = 0, n = statements.length; i < n; i++) { var statement = statements[i]; - if (statement.kind === 198) { + if (statement.kind === 202) { grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); } else if (ts.isExternalModuleImportDeclaration(statement)) { @@ -14756,6 +15467,8 @@ var ts; } checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name); + checkCollisionWithGeneratorVariablesInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); if (symbol.flags & 512 && symbol.declarations.length > 1 && !ts.isInAmbientContext(node) && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums)) { @@ -14781,7 +15494,7 @@ var ts; checkSourceElement(node.body); } function getFirstIdentifier(node) { - while (node.kind === 121) { + while (node.kind === 123) { node = node.left; } return node; @@ -14790,6 +15503,8 @@ var ts; checkGrammarModifiers(node); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + checkCollisionWithAwaiterVariablesInGeneratedCode(node, node.name); + checkCollisionWithGeneratorVariablesInGeneratedCode(node, node.name); var symbol = getSymbolOfNode(node); var target; if (ts.isInternalModuleImportDeclaration(node)) { @@ -14810,10 +15525,10 @@ var ts; } } else { - if (node.parent.kind === 207) { + if (node.parent.kind === 211) { target = resolveImport(symbol); } - else if (node.parent.kind === 196 && node.parent.parent.name.kind === 8) { + else if (node.parent.kind === 200 && node.parent.parent.name.kind === 8) { if (ts.getExternalModuleImportDeclarationExpression(node).kind === 8) { if (isExternalModuleNameRelative(ts.getExternalModuleImportDeclarationExpression(node).text)) { error(node, ts.Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name); @@ -14839,11 +15554,11 @@ var ts; } } function checkExportAssignment(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + if (!checkGrammarModifiers(node) && (node.flags & 16627)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); } var container = node.parent; - if (container.kind !== 207) { + if (container.kind !== 211) { container = container.parent; } checkTypeOfExportAssignmentSymbol(getSymbolOfNode(container)); @@ -14852,176 +15567,178 @@ var ts; if (!node) return; switch (node.kind) { - case 123: + case 125: return checkTypeParameter(node); - case 124: - return checkParameter(node); case 126: - case 125: + return checkParameter(node); + case 128: + case 127: return checkPropertyDeclaration(node); - case 136: - case 137: - case 132: - case 133: - return checkSignatureDeclaration(node); + case 138: + case 139: case 134: + case 135: + return checkSignatureDeclaration(node); + case 136: return checkSignatureDeclaration(node); - case 128: - case 127: - return checkMethodDeclaration(node); - case 129: - return checkConstructorDeclaration(node); case 130: + case 129: + return checkMethodDeclaration(node); case 131: + return checkConstructorDeclaration(node); + case 132: + case 133: return checkAccessorDeclaration(node); - case 135: + case 137: return checkTypeReference(node); - case 138: + case 140: return checkTypeQuery(node); - case 139: + case 141: return checkTypeLiteral(node); - case 140: + case 142: return checkArrayType(node); - case 141: + case 143: return checkTupleType(node); - case 142: + case 144: return checkUnionType(node); - case 143: + case 145: return checkSourceElement(node.type); - case 190: + case 194: return checkFunctionDeclaration(node); - case 170: - case 196: + case 174: + case 200: return checkBlock(node); - case 171: + case 175: return checkVariableStatement(node); - case 173: + case 177: return checkExpressionStatement(node); - case 174: + case 178: return checkIfStatement(node); - case 175: + case 179: return checkDoStatement(node); - case 176: + case 180: return checkWhileStatement(node); - case 177: + case 181: return checkForStatement(node); - case 178: + case 182: return checkForInStatement(node); - case 179: - case 180: + case 183: + case 184: return checkBreakOrContinueStatement(node); - case 181: + case 185: return checkReturnStatement(node); - case 182: + case 186: return checkWithStatement(node); - case 183: + case 187: return checkSwitchStatement(node); - case 184: + case 188: return checkLabeledStatement(node); - case 185: + case 189: return checkThrowStatement(node); - case 186: + case 190: return checkTryStatement(node); - case 188: + case 192: return checkVariableDeclaration(node); - case 146: + case 148: return checkBindingElement(node); - case 191: + case 195: return checkClassDeclaration(node); - case 192: + case 196: return checkInterfaceDeclaration(node); - case 193: + case 197: return checkTypeAliasDeclaration(node); - case 194: + case 198: return checkEnumDeclaration(node); - case 195: + case 199: return checkModuleDeclaration(node); - case 197: + case 201: return checkImportDeclaration(node); - case 198: + case 202: return checkExportAssignment(node); - case 172: + case 176: checkGrammarForStatementInAmbientContext(node); return; - case 187: + case 191: checkGrammarForStatementInAmbientContext(node); return; } } function checkFunctionExpressionBodies(node) { switch (node.kind) { - case 156: - case 157: + case 158: + case 159: ts.forEach(node.parameters, checkFunctionExpressionBodies); checkFunctionExpressionOrObjectLiteralMethodBody(node); break; - case 128: - case 127: + case 130: + case 129: ts.forEach(node.parameters, checkFunctionExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); } break; - case 129: - case 130: case 131: - case 190: + case 132: + case 133: + case 194: ts.forEach(node.parameters, checkFunctionExpressionBodies); break; - case 182: + case 186: checkFunctionExpressionBodies(node.expression); break; - case 124: case 126: - case 125: - case 144: - case 145: + case 128: + case 127: case 146: case 147: case 148: - case 204: case 149: case 150: + case 208: case 151: case 152: case 153: - case 165: - case 169: case 154: case 155: - case 159: - case 160: - case 158: + case 168: + case 173: + case 156: + case 157: case 161: case 162: case 163: + case 160: case 164: + case 165: + case 166: case 167: - case 170: - case 196: case 171: - case 173: + case 169: case 174: + case 200: case 175: - case 176: case 177: case 178: case 179: case 180: case 181: + case 182: case 183: - case 200: - case 201: case 184: case 185: - case 186: - case 203: + case 187: + case 204: + case 205: case 188: case 189: - case 191: - case 194: - case 206: + case 190: case 207: + case 192: + case 193: + case 195: + case 198: + case 210: + case 211: ts.forEachChild(node, checkFunctionExpressionBodies); break; } @@ -15037,21 +15754,32 @@ var ts; checkGrammarSourceFile(node); emitExtends = false; potentialThisCollisions.length = 0; + potentialArgumentsCollisions.length = 0; ts.forEach(node.statements, checkSourceElement); checkFunctionExpressionBodies(node); if (ts.isExternalModule(node)) { var symbol = getExportAssignmentSymbol(node.symbol); if (symbol && symbol.flags & 8388608) { getSymbolLinks(symbol).referenced = true; - markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 197)); + markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 201)); } } if (potentialThisCollisions.length) { ts.forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope); potentialThisCollisions.length = 0; } + if (potentialArgumentsCollisions.length) { + ts.forEach(potentialArgumentsCollisions, checkIfArgumentsIsCapturedInEnclosingScope); + potentialArgumentsCollisions.length = 0; + } if (emitExtends) { - links.flags |= 8; + links.flags |= 32; + } + if (emitAwaiter) { + links.flags |= 2048; + } + if (emitGenerator || (emitAwaiter && languageVersion < 2)) { + links.flags |= 4096; } links.flags |= 1; } @@ -15077,7 +15805,7 @@ var ts; function isInsideWithStatementBody(node) { if (node) { while (node.parent) { - if (node.parent.kind === 182 && node.parent.statement === node) { + if (node.parent.kind === 186 && node.parent.statement === node) { return true; } node = node.parent; @@ -15113,27 +15841,27 @@ var ts; copySymbols(location.locals, meaning); } switch (location.kind) { - case 207: + case 211: if (!ts.isExternalModule(location)) break; - case 195: + case 199: copySymbols(getSymbolOfNode(location).exports, meaning & 8914931); break; - case 194: + case 198: copySymbols(getSymbolOfNode(location).exports, meaning & 8); break; - case 191: - case 192: + case 195: + case 196: if (!(memberFlags & 128)) { copySymbols(getSymbolOfNode(location).members, meaning & 793056); } break; - case 156: + case 158: if (location.name) { copySymbol(location.symbol, meaning); } break; - case 203: + case 207: if (location.name.text) { copySymbol(location.symbol, meaning); } @@ -15150,22 +15878,22 @@ var ts; } function isTypeDeclaration(node) { switch (node.kind) { - case 123: - case 191: - case 192: - case 193: - case 194: + case 125: + case 195: + case 196: + case 197: + case 198: return true; } } function isTypeReferenceIdentifier(entityName) { var node = entityName; - while (node.parent && node.parent.kind === 121) + while (node.parent && node.parent.kind === 123) node = node.parent; - return node.parent && node.parent.kind === 135; + return node.parent && node.parent.kind === 137; } function isTypeNode(node) { - if (135 <= node.kind && node.kind <= 143) { + if (137 <= node.kind && node.kind <= 145) { return true; } switch (node.kind) { @@ -15175,62 +15903,62 @@ var ts; case 111: return true; case 98: - return node.parent.kind !== 160; + return node.parent.kind !== 162; case 8: - return node.parent.kind === 124; + return node.parent.kind === 126; case 64: - if (node.parent.kind === 121 && node.parent.right === node) { + if (node.parent.kind === 123 && node.parent.right === node) { node = node.parent; } - case 121: - ts.Debug.assert(node.kind === 64 || node.kind === 121, "'node' was expected to be a qualified name or identifier in 'isTypeNode'."); + case 123: + ts.Debug.assert(node.kind === 64 || node.kind === 123, "'node' was expected to be a qualified name or identifier in 'isTypeNode'."); var parent = node.parent; - if (parent.kind === 138) { + if (parent.kind === 140) { return false; } - if (135 <= parent.kind && parent.kind <= 143) { + if (137 <= parent.kind && parent.kind <= 145) { return true; } switch (parent.kind) { - case 123: - return node === parent.constraint; - case 126: case 125: - case 124: - case 188: - return node === parent.type; - case 190: - case 156: - case 157: - case 129: + return node === parent.constraint; case 128: case 127: - case 130: - case 131: + case 126: + case 192: return node === parent.type; + case 194: + case 158: + case 159: + case 131: + case 130: + case 129: case 132: case 133: + return node === parent.type; case 134: + case 135: + case 136: return node === parent.type; - case 154: + case 156: return node === parent.type; - case 151: - case 152: - return parent.typeArguments && ts.indexOf(parent.typeArguments, node) >= 0; case 153: + case 154: + return parent.typeArguments && ts.indexOf(parent.typeArguments, node) >= 0; + case 155: return false; } } return false; } function getLeftSideOfImportOrExportAssignment(nodeOnRightSide) { - while (nodeOnRightSide.parent.kind === 121) { + while (nodeOnRightSide.parent.kind === 123) { nodeOnRightSide = nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === 197) { + if (nodeOnRightSide.parent.kind === 201) { return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === 198) { + if (nodeOnRightSide.parent.kind === 202) { return nodeOnRightSide.parent.exportName === nodeOnRightSide && nodeOnRightSide.parent; } return undefined; @@ -15239,16 +15967,16 @@ var ts; return getLeftSideOfImportOrExportAssignment(node) !== undefined; } function isRightSideOfQualifiedNameOrPropertyAccess(node) { - return (node.parent.kind === 121 && node.parent.right === node) || (node.parent.kind === 149 && node.parent.name === node); + return (node.parent.kind === 123 && node.parent.right === node) || (node.parent.kind === 151 && node.parent.name === node); } function getSymbolOfEntityNameOrPropertyAccessExpression(entityName) { if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { return getSymbolOfNode(entityName.parent); } - if (entityName.parent.kind === 198) { + if (entityName.parent.kind === 202) { return resolveEntityName(entityName.parent.parent, entityName, 107455 | 793056 | 1536 | 8388608); } - if (entityName.kind !== 149) { + if (entityName.kind !== 151) { if (isInRightSideOfImportOrExportAssignment(entityName)) { return getSymbolOfPartOfRightHandSideOfImport(entityName); } @@ -15264,14 +15992,14 @@ var ts; var meaning = 107455 | 8388608; return resolveEntityName(entityName, entityName, meaning); } - else if (entityName.kind === 149) { + else if (entityName.kind === 151) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkPropertyAccessExpression(entityName); } return getNodeLinks(entityName).resolvedSymbol; } - else if (entityName.kind === 121) { + else if (entityName.kind === 123) { var symbol = getNodeLinks(entityName).resolvedSymbol; if (!symbol) { checkQualifiedName(entityName); @@ -15280,7 +16008,7 @@ var ts; } } else if (isTypeReferenceIdentifier(entityName)) { - var meaning = entityName.parent.kind === 135 ? 793056 : 1536; + var meaning = entityName.parent.kind === 137 ? 793056 : 1536; meaning |= 8388608; return resolveEntityName(entityName, entityName, meaning); } @@ -15294,12 +16022,12 @@ var ts; return getSymbolOfNode(node.parent); } if (node.kind === 64 && isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 198 ? getSymbolOfEntityNameOrPropertyAccessExpression(node) : getSymbolOfPartOfRightHandSideOfImport(node); + return node.parent.kind === 202 ? getSymbolOfEntityNameOrPropertyAccessExpression(node) : getSymbolOfPartOfRightHandSideOfImport(node); } switch (node.kind) { case 64: - case 149: - case 121: + case 151: + case 123: return getSymbolOfEntityNameOrPropertyAccessExpression(node); case 92: case 90: @@ -15307,7 +16035,7 @@ var ts; return type.symbol; case 112: var constructorDeclaration = node.parent; - if (constructorDeclaration && constructorDeclaration.kind === 129) { + if (constructorDeclaration && constructorDeclaration.kind === 131) { return constructorDeclaration.parent.symbol; } return undefined; @@ -15318,7 +16046,7 @@ var ts; return moduleType ? moduleType.symbol : undefined; } case 7: - if (node.parent.kind == 150 && node.parent.argumentExpression === node) { + if (node.parent.kind == 152 && node.parent.argumentExpression === node) { var objectType = checkExpression(node.parent.expression); if (objectType === unknownType) return undefined; @@ -15332,7 +16060,7 @@ var ts; return undefined; } function getShorthandAssignmentValueSymbol(location) { - if (location && location.kind === 205) { + if (location && location.kind === 209) { return resolveEntityName(location, location.name, 107455); } return undefined; @@ -15406,7 +16134,7 @@ var ts; return [symbol]; } function isExternalModuleSymbol(symbol) { - return symbol.flags & 512 && symbol.declarations.length === 1 && symbol.declarations[0].kind === 207; + return symbol.flags & 512 && symbol.declarations.length === 1 && symbol.declarations[0].kind === 211; } function isNodeDescendentOf(node, ancestor) { while (node) { @@ -15424,7 +16152,7 @@ var ts; return false; } if (symbolWithRelevantName.flags & 8388608) { - var importDeclarationWithRelevantName = ts.getDeclarationOfKind(symbolWithRelevantName, 197); + var importDeclarationWithRelevantName = ts.getDeclarationOfKind(symbolWithRelevantName, 201); if (isReferencedImportDeclaration(importDeclarationWithRelevantName)) { return false; } @@ -15448,7 +16176,7 @@ var ts; function getLocalNameForSymbol(symbol, location) { var node = location; while (node) { - if ((node.kind === 195 || node.kind === 194) && getSymbolOfNode(node) === symbol) { + if ((node.kind === 199 || node.kind === 198) && getSymbolOfNode(node) === symbol) { return getLocalNameOfContainer(node); } node = node.parent; @@ -15472,7 +16200,7 @@ var ts; return symbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol) ? symbolToString(symbol) : undefined; } function isTopLevelValueImportWithEntityName(node) { - if (node.parent.kind !== 207 || !ts.isInternalModuleImportDeclaration(node)) { + if (node.parent.kind !== 211 || !ts.isInternalModuleImportDeclaration(node)) { return false; } return isImportResolvedToValue(getSymbolOfNode(node)); @@ -15510,14 +16238,14 @@ var ts; return getNodeLinks(node).enumMemberValue; } function getConstantValue(node) { - if (node.kind === 206) { + if (node.kind === 210) { return getEnumMemberValue(node); } var symbol = getNodeLinks(node).resolvedSymbol; if (symbol && (symbol.flags & 8)) { var declaration = symbol.valueDeclaration; var constantValue; - if (declaration.kind === 206) { + if (declaration.kind === 210) { return getEnumMemberValue(declaration); } } @@ -15550,7 +16278,10 @@ var ts; isSymbolAccessible: isSymbolAccessible, isEntityNameVisible: isEntityNameVisible, getConstantValue: getConstantValue, - isUnknownIdentifier: isUnknownIdentifier + isUnknownIdentifier: isUnknownIdentifier, + renameSymbol: renameSymbol, + getRenamedIdentifier: getRenamedIdentifier, + getPromiseConstructor: getPromiseConstructor }; } function initializeTypeChecker() { @@ -15575,28 +16306,47 @@ var ts; globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); globalTemplateStringsArrayType = languageVersion >= 2 ? getGlobalType("TemplateStringsArray") : unknownType; + var iPromiseType = getTypeOfGlobalSymbol(getGlobalSymbol("IPromise"), 1); + if (iPromiseType !== emptyObjectType) { + globalPromiseLikeInterfaceType = createTypeReference(iPromiseType, [anyType]); + } + globalPromiseConstructorLikeInterfaceType = getGlobalType("IPromiseConstructor"); + if (compilerOptions.target >= 2) { + globalPromiseSymbol = getGlobalSymbol("Promise"); + } + else { + globalPromiseSymbol = resolveName(undefined, "Promise", 793056, undefined, undefined); + } + if (globalPromiseSymbol) { + globalPromiseType = getTypeOfGlobalSymbol(globalPromiseSymbol, 1); + } + var thenPropertySymbol = createSymbol(67108864 | 4, "then"); + getSymbolLinks(thenPropertySymbol).type = globalFunctionType; + thenableType = createObjectType(48128); + thenableType.properties = [thenPropertySymbol]; + thenableType.members = createSymbolTable(thenableType.properties); anyArrayType = createArrayType(anyType); } function checkGrammarModifiers(node) { switch (node.kind) { - case 130: + case 132: + case 133: case 131: - case 129: - case 126: - case 125: case 128: case 127: - case 134: - case 191: - case 192: + case 130: + case 129: + case 136: case 195: - case 194: + case 196: + case 199: case 198: - case 171: - case 190: - case 193: + case 202: + case 175: + case 194: case 197: - case 124: + case 201: + case 126: break; default: return false; @@ -15604,7 +16354,7 @@ var ts; if (!node.modifiers) { return; } - var lastStatic, lastPrivate, lastProtected, lastDeclare; + var lastStatic, lastPrivate, lastProtected, lastDeclare, lastAsync; var flags = 0; for (var i = 0, n = node.modifiers.length; i < n; i++) { var modifier = node.modifiers[i]; @@ -15630,7 +16380,10 @@ var ts; else if (flags & 128) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); } - else if (node.parent.kind === 196 || node.parent.kind === 207) { + else if (flags & 16384) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "async"); + } + else if (node.parent.kind === 200 || node.parent.kind === 211) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text); } flags |= ts.modifierToFlag(modifier.kind); @@ -15639,10 +16392,13 @@ var ts; if (flags & 128) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } - else if (node.parent.kind === 196 || node.parent.kind === 207) { + else if (flags & 16384) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "static", "async"); + } + else if (node.parent.kind === 200 || node.parent.kind === 211) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static"); } - else if (node.kind === 124) { + else if (node.kind === 126) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static"); } flags |= 128; @@ -15655,10 +16411,13 @@ var ts; else if (flags & 2) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare"); } - else if (node.parent.kind === 191) { + else if (flags & 16384) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "async"); + } + else if (node.parent.kind === 195) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export"); } - else if (node.kind === 124) { + else if (node.kind === 126) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export"); } flags |= 1; @@ -15667,21 +16426,37 @@ var ts; if (flags & 2) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); } - else if (node.parent.kind === 191) { + else if (flags & 16384) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); + } + else if (node.parent.kind === 195) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare"); } - else if (node.kind === 124) { + else if (node.kind === 126) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare"); } - else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 196) { + else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 200) { return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); } flags |= 2; lastDeclare = modifier; break; + case 121: + if (flags & 16384) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async"); + } + else if (flags & 2 || ts.isInAmbientContext(node.parent)) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); + } + else if (node.kind === 126) { + return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "async"); + } + flags |= 16384; + lastAsync = modifier; + break; } } - if (node.kind === 129) { + if (node.kind === 131) { if (flags & 128) { return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static"); } @@ -15691,16 +16466,42 @@ var ts; else if (flags & 32) { return grammarErrorOnNode(lastPrivate, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); } + else if (flags & 16384) { + return grammarErrorOnNode(lastAsync, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async"); + } + return; + } + else if (node.kind === 201 && flags & 2) { + return grammarErrorOnNode(lastDeclare, ts.Diagnostics._0_modifier_cannot_be_used_with_an_import_declaration, "declare"); } - else if (node.kind === 197 && flags & 2) { - return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); + else if (node.kind === 196 && flags & 2) { + return grammarErrorOnNode(lastDeclare, ts.Diagnostics._0_modifier_cannot_be_used_with_an_interface_declaration, "declare"); } - else if (node.kind === 192 && flags & 2) { - return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); + else if (node.kind === 126 && (flags & 112) && ts.isBindingPattern(node.name)) { + return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } - else if (node.kind === 124 && (flags & 112) && ts.isBindingPattern(node.name)) { + else if (node.kind === 126 && (flags & 112) && ts.isBindingPattern(node.name)) { return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } + if (flags & 16384) { + return checkGrammarAsyncModifier(node, lastAsync); + } + } + function checkGrammarAsyncModifier(node, asyncModifier) { + if (languageVersion < 2 && !compilerOptions.asyncFunctions) { + return grammarErrorOnNode(asyncModifier, ts.Diagnostics.Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher); + } + switch (node.kind) { + case 130: + case 194: + case 158: + case 159: + if (!node.asteriskToken) { + return false; + } + break; + } + return grammarErrorOnNode(asyncModifier, ts.Diagnostics._0_modifier_cannot_be_used_here, "async"); } function checkGrammarForDisallowedTrailingComma(list) { if (list && list.hasTrailingComma) { @@ -15769,7 +16570,7 @@ var ts; else if (parameter.dotDotDotToken) { return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter); } - else if (parameter.flags & 243) { + else if (parameter.flags & 16627) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); } else if (parameter.questionToken) { @@ -15789,7 +16590,7 @@ var ts; } } function checkGrammarForIndexSignatureModifier(node) { - if (node.flags & 243) { + if (node.flags & 16627) { grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members); } } @@ -15812,7 +16613,7 @@ var ts; var sourceFile = ts.getSourceFileOfNode(node); for (var i = 0, n = arguments.length; i < n; i++) { var arg = arguments[i]; - if (arg.kind === 168) { + if (arg.kind === 172) { return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected); } } @@ -15884,14 +16685,14 @@ var ts; return false; } function checkGrammarComputedPropertyName(node) { - if (node.kind !== 122) { + if (node.kind !== 124) { return false; } var computedPropertyName = node; if (languageVersion < 2) { return grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); } - else if (computedPropertyName.expression.kind === 163 && computedPropertyName.expression.operator === 23) { + else if (computedPropertyName.expression.kind === 166 && computedPropertyName.expression.operator === 23) { return grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); } } @@ -15918,25 +16719,25 @@ var ts; for (var i = 0, n = node.properties.length; i < n; i++) { var prop = node.properties[i]; var name = prop.name; - if (prop.kind === 168 || name.kind === 122) { + if (prop.kind === 172 || name.kind === 124) { checkGrammarComputedPropertyName(name); continue; } var currentKind; - if (prop.kind === 204 || prop.kind === 205) { + if (prop.kind === 208 || prop.kind === 209) { checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); if (name.kind === 7) { checkGrammarNumbericLiteral(name); } currentKind = Property; } - else if (prop.kind === 128) { + else if (prop.kind === 130) { currentKind = Property; } - else if (prop.kind === 130) { + else if (prop.kind === 132) { currentKind = GetAccessor; } - else if (prop.kind === 131) { + else if (prop.kind === 133) { currentKind = SetAccesor; } else { @@ -15980,10 +16781,10 @@ var ts; else if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); } - else if (kind === 130 && accessor.parameters.length) { + else if (kind === 132 && accessor.parameters.length) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters); } - else if (kind === 131) { + else if (kind === 133) { if (accessor.type) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation); } @@ -15995,7 +16796,7 @@ var ts; if (parameter.dotDotDotToken) { return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter); } - else if (parameter.flags & 243) { + else if (parameter.flags & 16627) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } else if (parameter.questionToken) { @@ -16008,7 +16809,7 @@ var ts; } } function checkGrammarForDisallowedComputedProperty(node, message) { - if (node.kind === 122) { + if (node.kind === 124) { return grammarErrorOnNode(node, message); } } @@ -16016,7 +16817,7 @@ var ts; if (checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { return true; } - if (node.parent.kind === 148) { + if (node.parent.kind === 150) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -16024,7 +16825,7 @@ var ts; return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } } - if (node.parent.kind === 191) { + if (node.parent.kind === 195) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) { return true; } @@ -16035,21 +16836,21 @@ var ts; return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_method_overloads); } } - else if (node.parent.kind === 192) { + else if (node.parent.kind === 196) { return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_interfaces); } - else if (node.parent.kind === 139) { + else if (node.parent.kind === 141) { return checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_type_literals); } } function isIterationStatement(node, lookInLabeledStatements) { switch (node.kind) { - case 177: - case 178: - case 175: - case 176: + case 181: + case 182: + case 179: + case 180: return true; - case 184: + case 188: return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements); } return false; @@ -16061,17 +16862,17 @@ var ts; return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } switch (current.kind) { - case 184: + case 188: if (node.label && current.label.text === node.label.text) { - var isMisplacedContinueLabel = node.kind === 179 && !isIterationStatement(current.statement, true); + var isMisplacedContinueLabel = node.kind === 183 && !isIterationStatement(current.statement, true); if (isMisplacedContinueLabel) { return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement); } return false; } break; - case 183: - if (node.kind === 180 && !node.label) { + case 187: + if (node.kind === 184 && !node.label) { return false; } break; @@ -16084,11 +16885,11 @@ var ts; current = current.parent; } if (node.label) { - var message = node.kind === 180 ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; + var message = node.kind === 184 ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); } else { - var message = node.kind === 180 ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; + var message = node.kind === 184 ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; return grammarErrorOnNode(node, message); } } @@ -16158,14 +16959,14 @@ var ts; } function allowLetAndConstDeclarations(parent) { switch (parent.kind) { - case 174: - case 175: - case 176: - case 182: - case 177: case 178: + case 179: + case 180: + case 186: + case 181: + case 182: return false; - case 184: + case 188: return allowLetAndConstDeclarations(parent.parent); } return true; @@ -16181,7 +16982,7 @@ var ts; } } function isIntegerLiteral(expression) { - if (expression.kind === 161) { + if (expression.kind === 164) { var unaryExpression = expression; if (unaryExpression.operator === 33 || unaryExpression.operator === 34) { expression = unaryExpression.operand; @@ -16200,7 +17001,7 @@ var ts; var inAmbientContext = ts.isInAmbientContext(enumDecl); for (var i = 0, n = enumDecl.members.length; i < n; i++) { var node = enumDecl.members[i]; - if (node.name.kind === 122) { + if (node.name.kind === 124) { hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums); } else if (inAmbientContext) { @@ -16268,17 +17069,17 @@ var ts; } } function checkGrammarProperty(node) { - if (node.parent.kind === 191) { + if (node.parent.kind === 195) { if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) || checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_class_property_declarations)) { return true; } } - else if (node.parent.kind === 192) { + else if (node.parent.kind === 196) { if (checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_interfaces)) { return true; } } - else if (node.parent.kind === 139) { + else if (node.parent.kind === 141) { if (checkGrammarForDisallowedComputedProperty(node.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_type_literals)) { return true; } @@ -16288,7 +17089,7 @@ var ts; } } function checkGrammarTopLevelElementForRequiredDeclareModifier(node) { - if (node.kind === 192 || node.kind === 197 || node.kind === 198 || (node.flags & 2)) { + if (node.kind === 196 || node.kind === 201 || node.kind === 202 || (node.flags & 2)) { return false; } return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file); @@ -16296,7 +17097,7 @@ var ts; function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) { for (var i = 0, n = file.statements.length; i < n; i++) { var decl = file.statements[i]; - if (ts.isDeclaration(decl) || decl.kind === 171) { + if (ts.isDeclaration(decl) || decl.kind === 175) { if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) { return true; } @@ -16308,14 +17109,14 @@ var ts; } function checkGrammarForStatementInAmbientContext(node) { if (ts.isInAmbientContext(node)) { - if (isAccessor(node.parent.kind)) { + if (ts.isAnyAccessor(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = true; } var links = getNodeLinks(node); if (!links.hasReportedStatementInAmbientContext && ts.isAnyFunction(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); } - if (node.parent.kind === 170 || node.parent.kind === 196 || node.parent.kind === 207) { + if (node.parent.kind === 174 || node.parent.kind === 200 || node.parent.kind === 211) { var links = getNodeLinks(node.parent); if (!links.hasReportedStatementInAmbientContext) { return links.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts); @@ -16351,13 +17152,3227 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { - var indentStrings = ["", " "]; - function getIndentString(level) { - if (indentStrings[level] === undefined) { - indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; + var Factory; + (function (Factory) { + function createStringLiteral(text, location, flags) { + var node = Factory.beginNode(8); + node.text = text; + return Factory.finishNode(node, location, flags); + } + Factory.createStringLiteral = createStringLiteral; + function createNumericLiteral(value, location, flags) { + var node = Factory.beginNode(7); + node.text = String(value); + return Factory.finishNode(node, location, flags); + } + Factory.createNumericLiteral = createNumericLiteral; + function createIdentifier(text, location, flags) { + var node = Factory.beginNode(64); + node.text = text; + return Factory.finishNode(node, location, flags); + } + Factory.createIdentifier = createIdentifier; + function createQualifiedName(left, right, location, flags) { + var node = Factory.beginNode(123); + node.left = left; + node.right = right; + return Factory.finishNode(node, location, flags); } - return indentStrings[level]; - } + Factory.createQualifiedName = createQualifiedName; + function updateQualifiedName(node, left, right) { + if (node.left !== left || node.right !== right) { + return createQualifiedName(left, right, node, node.flags); + } + return node; + } + Factory.updateQualifiedName = updateQualifiedName; + function createComputedPropertyName(expression, location, flags) { + var node = Factory.beginNode(124); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createComputedPropertyName = createComputedPropertyName; + function updateComputedPropertyName(node, expression) { + if (node.expression !== expression) { + return createComputedPropertyName(expression, node, node.flags); + } + return node; + } + Factory.updateComputedPropertyName = updateComputedPropertyName; + function createTypeParameter(name, constraint, expression, location, flags) { + var node = Factory.beginNode(125); + node.name = name; + node.constraint = constraint; + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createTypeParameter = createTypeParameter; + function updateTypeParameter(node, name, constraint) { + if (node.name !== name || node.constraint !== constraint) { + return createTypeParameter(name, constraint, node.expression, node, node.flags); + } + return node; + } + Factory.updateTypeParameter = updateTypeParameter; + function createParameterDeclaration(name, initializer, type, modifiers, dotDotDotToken, questionToken, location, flags) { + var node = Factory.beginNode(126); + node.name = name; + node.initializer = initializer; + node.type = type; + node.modifiers = modifiers; + node.dotDotDotToken = dotDotDotToken; + node.questionToken = questionToken; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createParameterDeclaration = createParameterDeclaration; + function updateParameterDeclaration(node, name, initializer, type) { + if (node.name !== name || node.initializer !== initializer || node.type !== type) { + return createParameterDeclaration(name, initializer, type, node.modifiers, node.dotDotDotToken, node.questionToken, node, node.flags); + } + return node; + } + Factory.updateParameterDeclaration = updateParameterDeclaration; + function createPropertySignature(name, type, questionToken, location, flags) { + var node = Factory.beginNode(127); + node.name = name; + node.type = type; + node.questionToken = questionToken; + return Factory.finishNode(node, location, flags); + } + Factory.createPropertySignature = createPropertySignature; + function updatePropertySignature(node, name, type) { + if (node.name !== name || node.type !== type) { + return createPropertySignature(name, type, node.questionToken, node, node.flags); + } + return node; + } + Factory.updatePropertySignature = updatePropertySignature; + function createPropertyDeclaration(name, initializer, type, questionToken, location, flags) { + var node = Factory.beginNode(128); + node.name = name; + node.initializer = initializer; + node.type = type; + node.questionToken = questionToken; + return Factory.finishNode(node, location, flags); + } + Factory.createPropertyDeclaration = createPropertyDeclaration; + function updatePropertyDeclaration(node, name, initializer, type) { + if (node.name !== name || node.initializer !== initializer || node.type !== type) { + return createPropertyDeclaration(name, initializer, type, node.questionToken, node, node.flags); + } + return node; + } + Factory.updatePropertyDeclaration = updatePropertyDeclaration; + function createMethodSignature(name, parameters, typeParameters, type, modifiers, asteriskToken, questionToken, location, flags) { + var node = Factory.beginNode(129); + node.name = name; + node.parameters = Factory.createNodeArray(parameters); + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + node.asteriskToken = asteriskToken; + node.questionToken = questionToken; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createMethodSignature = createMethodSignature; + function updateMethodSignature(node, name, parameters) { + if (node.name !== name || node.parameters !== parameters) { + return createMethodSignature(name, parameters, node.typeParameters, node.type, node.modifiers, node.asteriskToken, node.questionToken, node, node.flags); + } + return node; + } + Factory.updateMethodSignature = updateMethodSignature; + function createMethodDeclaration(name, parameters, body, typeParameters, type, modifiers, asteriskToken, location, flags) { + var node = Factory.beginNode(130); + node.name = name; + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + node.asteriskToken = asteriskToken; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createMethodDeclaration = createMethodDeclaration; + function updateMethodDeclaration(node, name, parameters, body) { + if (node.name !== name || node.parameters !== parameters || node.body !== body) { + return createMethodDeclaration(name, parameters, body, node.typeParameters, node.type, node.modifiers, node.asteriskToken, node, node.flags); + } + return node; + } + Factory.updateMethodDeclaration = updateMethodDeclaration; + function createConstructor(parameters, body, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(131); + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createConstructor = createConstructor; + function updateConstructor(node, parameters, body) { + if (node.parameters !== parameters || node.body !== body) { + return createConstructor(parameters, body, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateConstructor = updateConstructor; + function createGetAccessor(name, parameters, body, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(132); + node.name = name; + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createGetAccessor = createGetAccessor; + function updateGetAccessor(node, name, parameters, body) { + if (node.name !== name || node.parameters !== parameters || node.body !== body) { + return createGetAccessor(name, parameters, body, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateGetAccessor = updateGetAccessor; + function createSetAccessor(name, parameters, body, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(133); + node.name = name; + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createSetAccessor = createSetAccessor; + function updateSetAccessor(node, name, parameters, body) { + if (node.name !== name || node.parameters !== parameters || node.body !== body) { + return createSetAccessor(name, parameters, body, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateSetAccessor = updateSetAccessor; + function createCallSignature(parameters, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(134); + node.parameters = Factory.createNodeArray(parameters); + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createCallSignature = createCallSignature; + function updateCallSignature(node, parameters) { + if (node.parameters !== parameters) { + return createCallSignature(parameters, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateCallSignature = updateCallSignature; + function createConstructSignature(parameters, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(135); + node.parameters = Factory.createNodeArray(parameters); + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createConstructSignature = createConstructSignature; + function updateConstructSignature(node, parameters) { + if (node.parameters !== parameters) { + return createConstructSignature(parameters, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateConstructSignature = updateConstructSignature; + function createIndexSignature(parameters, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(136); + node.parameters = Factory.createNodeArray(parameters); + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createIndexSignature = createIndexSignature; + function updateIndexSignature(node, parameters) { + if (node.parameters !== parameters) { + return createIndexSignature(parameters, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateIndexSignature = updateIndexSignature; + function createObjectBindingPattern(elements, location, flags) { + var node = Factory.beginNode(146); + node.elements = Factory.createNodeArray(elements); + return Factory.finishNode(node, location, flags); + } + Factory.createObjectBindingPattern = createObjectBindingPattern; + function updateObjectBindingPattern(node, elements) { + if (node.elements !== elements) { + return createObjectBindingPattern(elements, node, node.flags); + } + return node; + } + Factory.updateObjectBindingPattern = updateObjectBindingPattern; + function createArrayBindingPattern(elements, location, flags) { + var node = Factory.beginNode(147); + node.elements = Factory.createNodeArray(elements); + return Factory.finishNode(node, location, flags); + } + Factory.createArrayBindingPattern = createArrayBindingPattern; + function updateArrayBindingPattern(node, elements) { + if (node.elements !== elements) { + return createArrayBindingPattern(elements, node, node.flags); + } + return node; + } + Factory.updateArrayBindingPattern = updateArrayBindingPattern; + function createBindingElement(name, propertyName, initializer, location, flags) { + var node = Factory.beginNode(148); + node.name = name; + node.propertyName = propertyName; + node.initializer = initializer; + return Factory.finishNode(node, location, flags); + } + Factory.createBindingElement = createBindingElement; + function updateBindingElement(node, name, propertyName, initializer) { + if (node.name !== name || node.propertyName !== propertyName || node.initializer !== initializer) { + return createBindingElement(name, propertyName, initializer, node, node.flags); + } + return node; + } + Factory.updateBindingElement = updateBindingElement; + function createArrayLiteralExpression(elements, location, flags) { + var node = Factory.beginNode(149); + node.elements = Factory.createNodeArray(elements); + return Factory.finishNode(node, location, flags); + } + Factory.createArrayLiteralExpression = createArrayLiteralExpression; + function updateArrayLiteralExpression(node, elements) { + if (node.elements !== elements) { + return createArrayLiteralExpression(elements, node, node.flags); + } + return node; + } + Factory.updateArrayLiteralExpression = updateArrayLiteralExpression; + function createObjectLiteralExpression(properties, location, flags) { + var node = Factory.beginNode(150); + node.properties = Factory.createNodeArray(properties); + return Factory.finishNode(node, location, flags); + } + Factory.createObjectLiteralExpression = createObjectLiteralExpression; + function updateObjectLiteralExpression(node, properties) { + if (node.properties !== properties) { + return createObjectLiteralExpression(properties, node, node.flags); + } + return node; + } + Factory.updateObjectLiteralExpression = updateObjectLiteralExpression; + function createPropertyAccessExpression(expression, name, location, flags) { + var node = Factory.beginNode(151); + node.expression = expression; + node.name = name; + return Factory.finishNode(node, location, flags); + } + Factory.createPropertyAccessExpression = createPropertyAccessExpression; + function updatePropertyAccessExpression(node, expression, name) { + if (node.expression !== expression || node.name !== name) { + return createPropertyAccessExpression(expression, name, node, node.flags); + } + return node; + } + Factory.updatePropertyAccessExpression = updatePropertyAccessExpression; + function createElementAccessExpression(expression, argumentExpression, location, flags) { + var node = Factory.beginNode(152); + node.expression = expression; + node.argumentExpression = argumentExpression; + return Factory.finishNode(node, location, flags); + } + Factory.createElementAccessExpression = createElementAccessExpression; + function updateElementAccessExpression(node, expression, argumentExpression) { + if (node.expression !== expression || node.argumentExpression !== argumentExpression) { + return createElementAccessExpression(expression, argumentExpression, node, node.flags); + } + return node; + } + Factory.updateElementAccessExpression = updateElementAccessExpression; + function createCallExpression(expression, arguments, location, flags) { + var node = Factory.beginNode(153); + node.expression = expression; + node.arguments = Factory.createNodeArray(arguments); + return Factory.finishNode(node, location, flags); + } + Factory.createCallExpression = createCallExpression; + function updateCallExpression(node, expression, arguments) { + if (node.expression !== expression || node.arguments !== arguments) { + return createCallExpression(expression, arguments, node, node.flags); + } + return node; + } + Factory.updateCallExpression = updateCallExpression; + function createNewExpression(expression, arguments, location, flags) { + var node = Factory.beginNode(154); + node.expression = expression; + node.arguments = Factory.createNodeArray(arguments); + return Factory.finishNode(node, location, flags); + } + Factory.createNewExpression = createNewExpression; + function updateNewExpression(node, expression, arguments) { + if (node.expression !== expression || node.arguments !== arguments) { + return createNewExpression(expression, arguments, node, node.flags); + } + return node; + } + Factory.updateNewExpression = updateNewExpression; + function createTaggedTemplateExpression(tag, template, location, flags) { + var node = Factory.beginNode(155); + node.tag = tag; + node.template = template; + return Factory.finishNode(node, location, flags); + } + Factory.createTaggedTemplateExpression = createTaggedTemplateExpression; + function updateTaggedTemplateExpression(node, tag, template) { + if (node.tag !== tag || node.template !== template) { + return createTaggedTemplateExpression(tag, template, node, node.flags); + } + return node; + } + Factory.updateTaggedTemplateExpression = updateTaggedTemplateExpression; + function createTypeAssertion(type, expression, location, flags) { + var node = Factory.beginNode(156); + node.type = type; + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createTypeAssertion = createTypeAssertion; + function updateTypeAssertion(node, expression) { + if (node.expression !== expression) { + return createTypeAssertion(node.type, expression, node, node.flags); + } + return node; + } + Factory.updateTypeAssertion = updateTypeAssertion; + function createParenthesizedExpression(expression, location, flags) { + var node = Factory.beginNode(157); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createParenthesizedExpression = createParenthesizedExpression; + function updateParenthesizedExpression(node, expression) { + if (node.expression !== expression) { + return createParenthesizedExpression(expression, node, node.flags); + } + return node; + } + Factory.updateParenthesizedExpression = updateParenthesizedExpression; + function createFunctionExpression(name, parameters, body, typeParameters, type, modifiers, asteriskToken, location, flags) { + var node = Factory.beginNode(158); + node.name = name; + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + node.asteriskToken = asteriskToken; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createFunctionExpression = createFunctionExpression; + function updateFunctionExpression(node, name, parameters, body) { + if (node.name !== name || node.parameters !== parameters || node.body !== body) { + return createFunctionExpression(name, parameters, body, node.typeParameters, node.type, node.modifiers, node.asteriskToken, node, node.flags); + } + return node; + } + Factory.updateFunctionExpression = updateFunctionExpression; + function createArrowFunction(parameters, body, typeParameters, type, modifiers, location, flags) { + var node = Factory.beginNode(159); + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createArrowFunction = createArrowFunction; + function updateArrowFunction(node, parameters, body) { + if (node.parameters !== parameters || node.body !== body) { + return createArrowFunction(parameters, body, node.typeParameters, node.type, node.modifiers, node, node.flags); + } + return node; + } + Factory.updateArrowFunction = updateArrowFunction; + function createDeleteExpression(expression, location, flags) { + var node = Factory.beginNode(160); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createDeleteExpression = createDeleteExpression; + function updateDeleteExpression(node, expression) { + if (node.expression !== expression) { + return createDeleteExpression(expression, node, node.flags); + } + return node; + } + Factory.updateDeleteExpression = updateDeleteExpression; + function createTypeOfExpression(expression, location, flags) { + var node = Factory.beginNode(161); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createTypeOfExpression = createTypeOfExpression; + function updateTypeOfExpression(node, expression) { + if (node.expression !== expression) { + return createTypeOfExpression(expression, node, node.flags); + } + return node; + } + Factory.updateTypeOfExpression = updateTypeOfExpression; + function createVoidExpression(expression, location, flags) { + var node = Factory.beginNode(162); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createVoidExpression = createVoidExpression; + function updateVoidExpression(node, expression) { + if (node.expression !== expression) { + return createVoidExpression(expression, node, node.flags); + } + return node; + } + Factory.updateVoidExpression = updateVoidExpression; + function createAwaitExpression(expression, location, flags) { + var node = Factory.beginNode(163); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createAwaitExpression = createAwaitExpression; + function updateAwaitExpression(node, expression) { + if (node.expression !== expression) { + return createAwaitExpression(expression, node, node.flags); + } + return node; + } + Factory.updateAwaitExpression = updateAwaitExpression; + function createPrefixUnaryExpression(operator, operand, location, flags) { + var node = Factory.beginNode(164); + node.operator = operator; + node.operand = operand; + return Factory.finishNode(node, location, flags); + } + Factory.createPrefixUnaryExpression = createPrefixUnaryExpression; + function updatePrefixUnaryExpression(node, operand) { + if (node.operand !== operand) { + return createPrefixUnaryExpression(node.operator, operand, node, node.flags); + } + return node; + } + Factory.updatePrefixUnaryExpression = updatePrefixUnaryExpression; + function createPostfixUnaryExpression(operator, operand, location, flags) { + var node = Factory.beginNode(165); + node.operator = operator; + node.operand = operand; + return Factory.finishNode(node, location, flags); + } + Factory.createPostfixUnaryExpression = createPostfixUnaryExpression; + function updatePostfixUnaryExpression(node, operand) { + if (node.operand !== operand) { + return createPostfixUnaryExpression(node.operator, operand, node, node.flags); + } + return node; + } + Factory.updatePostfixUnaryExpression = updatePostfixUnaryExpression; + function createBinaryExpression(operator, left, right, location, flags) { + var node = Factory.beginNode(166); + node.operator = operator; + node.left = left; + node.right = right; + return Factory.finishNode(node, location, flags); + } + Factory.createBinaryExpression = createBinaryExpression; + function updateBinaryExpression(node, left, right) { + if (node.left !== left || node.right !== right) { + return createBinaryExpression(node.operator, left, right, node, node.flags); + } + return node; + } + Factory.updateBinaryExpression = updateBinaryExpression; + function createConditionalExpression(condition, whenTrue, whenFalse, location, flags) { + var node = Factory.beginNode(167); + node.condition = condition; + node.whenTrue = whenTrue; + node.whenFalse = whenFalse; + return Factory.finishNode(node, location, flags); + } + Factory.createConditionalExpression = createConditionalExpression; + function updateConditionalExpression(node, condition, whenTrue, whenFalse) { + if (node.condition !== condition || node.whenTrue !== whenTrue || node.whenFalse !== whenFalse) { + return createConditionalExpression(condition, whenTrue, whenFalse, node, node.flags); + } + return node; + } + Factory.updateConditionalExpression = updateConditionalExpression; + function createTemplateExpression(head, templateSpans, location, flags) { + var node = Factory.beginNode(168); + node.head = head; + node.templateSpans = Factory.createNodeArray(templateSpans); + return Factory.finishNode(node, location, flags); + } + Factory.createTemplateExpression = createTemplateExpression; + function updateTemplateExpression(node, head, templateSpans) { + if (node.head !== head || node.templateSpans !== templateSpans) { + return createTemplateExpression(head, templateSpans, node, node.flags); + } + return node; + } + Factory.updateTemplateExpression = updateTemplateExpression; + function createYieldExpression(expression, asteriskToken, location, flags) { + var node = Factory.beginNode(169); + node.expression = expression; + node.asteriskToken = asteriskToken; + return Factory.finishNode(node, location, flags); + } + Factory.createYieldExpression = createYieldExpression; + function updateYieldExpression(node, expression) { + if (node.expression !== expression) { + return createYieldExpression(expression, node.asteriskToken, node, node.flags); + } + return node; + } + Factory.updateYieldExpression = updateYieldExpression; + function createGeneratedLabel(label, labelNumbers, location, flags) { + var node = Factory.beginNode(170); + node.label = label; + node.labelNumbers = labelNumbers; + return Factory.finishNode(node, location, flags); + } + Factory.createGeneratedLabel = createGeneratedLabel; + function createSpreadElementExpression(expression, location, flags) { + var node = Factory.beginNode(171); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createSpreadElementExpression = createSpreadElementExpression; + function updateSpreadElementExpression(node, expression) { + if (node.expression !== expression) { + return createSpreadElementExpression(expression, node, node.flags); + } + return node; + } + Factory.updateSpreadElementExpression = updateSpreadElementExpression; + function createOmittedExpression(location, flags) { + var node = Factory.beginNode(172); + return Factory.finishNode(node, location, flags); + } + Factory.createOmittedExpression = createOmittedExpression; + function createTemplateSpan(expression, literal, location, flags) { + var node = Factory.beginNode(173); + node.expression = expression; + node.literal = literal; + return Factory.finishNode(node, location, flags); + } + Factory.createTemplateSpan = createTemplateSpan; + function updateTemplateSpan(node, expression, literal) { + if (node.expression !== expression || node.literal !== literal) { + return createTemplateSpan(expression, literal, node, node.flags); + } + return node; + } + Factory.updateTemplateSpan = updateTemplateSpan; + function createBlock(statements, location, flags) { + var node = Factory.beginNode(174); + node.statements = Factory.createNodeArray(statements); + return Factory.finishNode(node, location, flags); + } + Factory.createBlock = createBlock; + function updateBlock(node, statements) { + if (node.statements !== statements) { + return createBlock(statements, node, node.flags); + } + return node; + } + Factory.updateBlock = updateBlock; + function createVariableStatement(declarationList, location, flags) { + var node = Factory.beginNode(175); + node.declarationList = declarationList; + return Factory.finishNode(node, location, flags); + } + Factory.createVariableStatement = createVariableStatement; + function updateVariableStatement(node, declarationList) { + if (node.declarationList !== declarationList) { + return createVariableStatement(declarationList, node, node.flags); + } + return node; + } + Factory.updateVariableStatement = updateVariableStatement; + function createEmptyStatement(location, flags) { + var node = Factory.beginNode(176); + return Factory.finishNode(node, location, flags); + } + Factory.createEmptyStatement = createEmptyStatement; + function createExpressionStatement(expression, location, flags) { + var node = Factory.beginNode(177); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createExpressionStatement = createExpressionStatement; + function updateExpressionStatement(node, expression) { + if (node.expression !== expression) { + return createExpressionStatement(expression, node, node.flags); + } + return node; + } + Factory.updateExpressionStatement = updateExpressionStatement; + function createIfStatement(expression, thenStatement, elseStatement, location, flags) { + var node = Factory.beginNode(178); + node.expression = expression; + node.thenStatement = thenStatement; + node.elseStatement = elseStatement; + return Factory.finishNode(node, location, flags); + } + Factory.createIfStatement = createIfStatement; + function updateIfStatement(node, expression, thenStatement, elseStatement) { + if (node.expression !== expression || node.thenStatement !== thenStatement || node.elseStatement !== elseStatement) { + return createIfStatement(expression, thenStatement, elseStatement, node, node.flags); + } + return node; + } + Factory.updateIfStatement = updateIfStatement; + function createDoStatement(statement, expression, location, flags) { + var node = Factory.beginNode(179); + node.statement = statement; + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createDoStatement = createDoStatement; + function updateDoStatement(node, statement, expression) { + if (node.statement !== statement || node.expression !== expression) { + return createDoStatement(statement, expression, node, node.flags); + } + return node; + } + Factory.updateDoStatement = updateDoStatement; + function createWhileStatement(expression, statement, location, flags) { + var node = Factory.beginNode(180); + node.expression = expression; + node.statement = statement; + return Factory.finishNode(node, location, flags); + } + Factory.createWhileStatement = createWhileStatement; + function updateWhileStatement(node, expression, statement) { + if (node.expression !== expression || node.statement !== statement) { + return createWhileStatement(expression, statement, node, node.flags); + } + return node; + } + Factory.updateWhileStatement = updateWhileStatement; + function createForStatement(initializer, condition, iterator, statement, location, flags) { + var node = Factory.beginNode(181); + node.initializer = initializer; + node.condition = condition; + node.iterator = iterator; + node.statement = statement; + return Factory.finishNode(node, location, flags); + } + Factory.createForStatement = createForStatement; + function updateForStatement(node, initializer, condition, iterator, statement) { + if (node.initializer !== initializer || node.condition !== condition || node.iterator !== iterator || node.statement !== statement) { + return createForStatement(initializer, condition, iterator, statement, node, node.flags); + } + return node; + } + Factory.updateForStatement = updateForStatement; + function createForInStatement(initializer, expression, statement, location, flags) { + var node = Factory.beginNode(182); + node.initializer = initializer; + node.expression = expression; + node.statement = statement; + return Factory.finishNode(node, location, flags); + } + Factory.createForInStatement = createForInStatement; + function updateForInStatement(node, initializer, expression, statement) { + if (node.initializer !== initializer || node.expression !== expression || node.statement !== statement) { + return createForInStatement(initializer, expression, statement, node, node.flags); + } + return node; + } + Factory.updateForInStatement = updateForInStatement; + function createContinueStatement(label, location, flags) { + var node = Factory.beginNode(183); + node.label = label; + return Factory.finishNode(node, location, flags); + } + Factory.createContinueStatement = createContinueStatement; + function updateContinueStatement(node, label) { + if (node.label !== label) { + return createContinueStatement(label, node, node.flags); + } + return node; + } + Factory.updateContinueStatement = updateContinueStatement; + function createBreakStatement(label, location, flags) { + var node = Factory.beginNode(184); + node.label = label; + return Factory.finishNode(node, location, flags); + } + Factory.createBreakStatement = createBreakStatement; + function updateBreakStatement(node, label) { + if (node.label !== label) { + return createBreakStatement(label, node, node.flags); + } + return node; + } + Factory.updateBreakStatement = updateBreakStatement; + function createReturnStatement(expression, location, flags) { + var node = Factory.beginNode(185); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createReturnStatement = createReturnStatement; + function updateReturnStatement(node, expression) { + if (node.expression !== expression) { + return createReturnStatement(expression, node, node.flags); + } + return node; + } + Factory.updateReturnStatement = updateReturnStatement; + function createWithStatement(expression, statement, location, flags) { + var node = Factory.beginNode(186); + node.expression = expression; + node.statement = statement; + return Factory.finishNode(node, location, flags); + } + Factory.createWithStatement = createWithStatement; + function updateWithStatement(node, expression, statement) { + if (node.expression !== expression || node.statement !== statement) { + return createWithStatement(expression, statement, node, node.flags); + } + return node; + } + Factory.updateWithStatement = updateWithStatement; + function createSwitchStatement(expression, clauses, location, flags) { + var node = Factory.beginNode(187); + node.expression = expression; + node.clauses = Factory.createNodeArray(clauses); + return Factory.finishNode(node, location, flags); + } + Factory.createSwitchStatement = createSwitchStatement; + function updateSwitchStatement(node, expression, clauses) { + if (node.expression !== expression || node.clauses !== clauses) { + return createSwitchStatement(expression, clauses, node, node.flags); + } + return node; + } + Factory.updateSwitchStatement = updateSwitchStatement; + function createLabeledStatement(label, statement, location, flags) { + var node = Factory.beginNode(188); + node.label = label; + node.statement = statement; + return Factory.finishNode(node, location, flags); + } + Factory.createLabeledStatement = createLabeledStatement; + function updateLabeledStatement(node, label, statement) { + if (node.label !== label || node.statement !== statement) { + return createLabeledStatement(label, statement, node, node.flags); + } + return node; + } + Factory.updateLabeledStatement = updateLabeledStatement; + function createThrowStatement(expression, location, flags) { + var node = Factory.beginNode(189); + node.expression = expression; + return Factory.finishNode(node, location, flags); + } + Factory.createThrowStatement = createThrowStatement; + function updateThrowStatement(node, expression) { + if (node.expression !== expression) { + return createThrowStatement(expression, node, node.flags); + } + return node; + } + Factory.updateThrowStatement = updateThrowStatement; + function createTryStatement(tryBlock, catchClause, finallyBlock, location, flags) { + var node = Factory.beginNode(190); + node.tryBlock = tryBlock; + node.catchClause = catchClause; + node.finallyBlock = finallyBlock; + return Factory.finishNode(node, location, flags); + } + Factory.createTryStatement = createTryStatement; + function updateTryStatement(node, tryBlock, catchClause, finallyBlock) { + if (node.tryBlock !== tryBlock || node.catchClause !== catchClause || node.finallyBlock !== finallyBlock) { + return createTryStatement(tryBlock, catchClause, finallyBlock, node, node.flags); + } + return node; + } + Factory.updateTryStatement = updateTryStatement; + function createDebuggerStatement(location, flags) { + var node = Factory.beginNode(191); + return Factory.finishNode(node, location, flags); + } + Factory.createDebuggerStatement = createDebuggerStatement; + function createVariableDeclaration(name, initializer, location, flags) { + var node = Factory.beginNode(192); + node.name = name; + node.initializer = initializer; + return Factory.finishNode(node, location, flags); + } + Factory.createVariableDeclaration = createVariableDeclaration; + function updateVariableDeclaration(node, name, initializer) { + if (node.name !== name || node.initializer !== initializer) { + return createVariableDeclaration(name, initializer, node, node.flags); + } + return node; + } + Factory.updateVariableDeclaration = updateVariableDeclaration; + function createVariableDeclarationList(declarations, location, flags) { + var node = Factory.beginNode(193); + node.declarations = Factory.createNodeArray(declarations); + return Factory.finishNode(node, location, flags); + } + Factory.createVariableDeclarationList = createVariableDeclarationList; + function updateVariableDeclarationList(node, declarations) { + if (node.declarations !== declarations) { + return createVariableDeclarationList(declarations, node, node.flags); + } + return node; + } + Factory.updateVariableDeclarationList = updateVariableDeclarationList; + function createFunctionDeclaration(name, parameters, body, typeParameters, type, modifiers, asteriskToken, location, flags) { + var node = Factory.beginNode(194); + node.name = name; + node.parameters = Factory.createNodeArray(parameters); + node.body = body; + node.typeParameters = Factory.createNodeArray(typeParameters); + node.type = type; + node.modifiers = modifiers; + node.asteriskToken = asteriskToken; + return Factory.finishNode(node, location, flags, modifiers); + } + Factory.createFunctionDeclaration = createFunctionDeclaration; + function updateFunctionDeclaration(node, name, parameters, body) { + if (node.name !== name || node.parameters !== parameters || node.body !== body) { + return createFunctionDeclaration(name, parameters, body, node.typeParameters, node.type, node.modifiers, node.asteriskToken, node, node.flags); + } + return node; + } + Factory.updateFunctionDeclaration = updateFunctionDeclaration; + function createCaseClause(expression, statements, location, flags) { + var node = Factory.beginNode(204); + node.expression = expression; + node.statements = Factory.createNodeArray(statements); + return Factory.finishNode(node, location, flags); + } + Factory.createCaseClause = createCaseClause; + function updateCaseClause(node, expression, statements) { + if (node.expression !== expression || node.statements !== statements) { + return createCaseClause(expression, statements, node, node.flags); + } + return node; + } + Factory.updateCaseClause = updateCaseClause; + function createDefaultClause(statements, location, flags) { + var node = Factory.beginNode(205); + node.statements = Factory.createNodeArray(statements); + return Factory.finishNode(node, location, flags); + } + Factory.createDefaultClause = createDefaultClause; + function updateDefaultClause(node, statements) { + if (node.statements !== statements) { + return createDefaultClause(statements, node, node.flags); + } + return node; + } + Factory.updateDefaultClause = updateDefaultClause; + function createCatchClause(name, block, location, flags) { + var node = Factory.beginNode(207); + node.name = name; + node.block = block; + return Factory.finishNode(node, location, flags); + } + Factory.createCatchClause = createCatchClause; + function updateCatchClause(node, name, block) { + if (node.name !== name || node.block !== block) { + return createCatchClause(name, block, node, node.flags); + } + return node; + } + Factory.updateCatchClause = updateCatchClause; + function createPropertyAssignment(name, initializer, location, flags) { + var node = Factory.beginNode(208); + node.name = name; + node.initializer = initializer; + return Factory.finishNode(node, location, flags); + } + Factory.createPropertyAssignment = createPropertyAssignment; + function updatePropertyAssignment(node, name, initializer) { + if (node.name !== name || node.initializer !== initializer) { + return createPropertyAssignment(name, initializer, node, node.flags); + } + return node; + } + Factory.updatePropertyAssignment = updatePropertyAssignment; + function createShorthandPropertyAssignment(name, location, flags) { + var node = Factory.beginNode(209); + node.name = name; + return Factory.finishNode(node, location, flags); + } + Factory.createShorthandPropertyAssignment = createShorthandPropertyAssignment; + function updateShorthandPropertyAssignment(node, name) { + if (node.name !== name) { + return createShorthandPropertyAssignment(name, node, node.flags); + } + return node; + } + Factory.updateShorthandPropertyAssignment = updateShorthandPropertyAssignment; + })(Factory = ts.Factory || (ts.Factory = {})); + var Visitor; + (function (Visitor) { + function fallback(node, cbNode, state) { + if (!cbNode || !node) { + return node; + } + return accept(node, cbNode, state); + } + Visitor.fallback = fallback; + function accept(node, cbNode, state) { + switch (node.kind) { + case 123: + return Factory.updateQualifiedName(node, Visitor.visit(node.left, cbNode, state), Visitor.visit(node.right, cbNode, state)); + case 124: + return Factory.updateComputedPropertyName(node, Visitor.visit(node.expression, cbNode, state)); + case 125: + return Factory.updateTypeParameter(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.constraint, cbNode, state)); + case 126: + return Factory.updateParameterDeclaration(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.initializer, cbNode, state), Visitor.visit(node.type, cbNode, state)); + case 127: + return Factory.updatePropertySignature(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.type, cbNode, state)); + case 128: + return Factory.updatePropertyDeclaration(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.initializer, cbNode, state), Visitor.visit(node.type, cbNode, state)); + case 129: + return Factory.updateMethodSignature(node, Visitor.visit(node.name, cbNode, state), Visitor.visitNodes(node.parameters, cbNode, state)); + case 130: + return Factory.updateMethodDeclaration(node, Visitor.visit(node.name, cbNode, state), Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 131: + return Factory.updateConstructor(node, Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 132: + return Factory.updateGetAccessor(node, Visitor.visit(node.name, cbNode, state), Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 133: + return Factory.updateSetAccessor(node, Visitor.visit(node.name, cbNode, state), Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 134: + return Factory.updateCallSignature(node, Visitor.visitNodes(node.parameters, cbNode, state)); + case 135: + return Factory.updateConstructSignature(node, Visitor.visitNodes(node.parameters, cbNode, state)); + case 136: + return Factory.updateIndexSignature(node, Visitor.visitNodes(node.parameters, cbNode, state)); + case 146: + return Factory.updateObjectBindingPattern(node, Visitor.visitNodes(node.elements, cbNode, state)); + case 147: + return Factory.updateArrayBindingPattern(node, Visitor.visitNodes(node.elements, cbNode, state)); + case 148: + return Factory.updateBindingElement(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.propertyName, cbNode, state), Visitor.visit(node.initializer, cbNode, state)); + case 149: + return Factory.updateArrayLiteralExpression(node, Visitor.visitNodes(node.elements, cbNode, state)); + case 150: + return Factory.updateObjectLiteralExpression(node, Visitor.visitNodes(node.properties, cbNode, state)); + case 151: + return Factory.updatePropertyAccessExpression(node, Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.name, cbNode, state)); + case 152: + return Factory.updateElementAccessExpression(node, Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.argumentExpression, cbNode, state)); + case 153: + return Factory.updateCallExpression(node, Visitor.visit(node.expression, cbNode, state), Visitor.visitNodes(node.arguments, cbNode, state)); + case 154: + return Factory.updateNewExpression(node, Visitor.visit(node.expression, cbNode, state), Visitor.visitNodes(node.arguments, cbNode, state)); + case 155: + return Factory.updateTaggedTemplateExpression(node, Visitor.visit(node.tag, cbNode, state), Visitor.visit(node.template, cbNode, state)); + case 156: + return Factory.updateTypeAssertion(node, Visitor.visit(node.expression, cbNode, state)); + case 157: + return Factory.updateParenthesizedExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 158: + return Factory.updateFunctionExpression(node, Visitor.visit(node.name, cbNode, state), Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 159: + return Factory.updateArrowFunction(node, Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 160: + return Factory.updateDeleteExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 161: + return Factory.updateTypeOfExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 162: + return Factory.updateVoidExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 163: + return Factory.updateAwaitExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 164: + return Factory.updatePrefixUnaryExpression(node, Visitor.visit(node.operand, cbNode, state)); + case 165: + return Factory.updatePostfixUnaryExpression(node, Visitor.visit(node.operand, cbNode, state)); + case 166: + return Factory.updateBinaryExpression(node, Visitor.visit(node.left, cbNode, state), Visitor.visit(node.right, cbNode, state)); + case 167: + return Factory.updateConditionalExpression(node, Visitor.visit(node.condition, cbNode, state), Visitor.visit(node.whenTrue, cbNode, state), Visitor.visit(node.whenFalse, cbNode, state)); + case 168: + return Factory.updateTemplateExpression(node, Visitor.visit(node.head, cbNode, state), Visitor.visitNodes(node.templateSpans, cbNode, state)); + case 169: + return Factory.updateYieldExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 171: + return Factory.updateSpreadElementExpression(node, Visitor.visit(node.expression, cbNode, state)); + case 173: + return Factory.updateTemplateSpan(node, Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.literal, cbNode, state)); + case 174: + return Factory.updateBlock(node, Visitor.visitNodes(node.statements, cbNode, state)); + case 175: + return Factory.updateVariableStatement(node, Visitor.visit(node.declarationList, cbNode, state)); + case 177: + return Factory.updateExpressionStatement(node, Visitor.visit(node.expression, cbNode, state)); + case 178: + return Factory.updateIfStatement(node, Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.thenStatement, cbNode, state), Visitor.visit(node.elseStatement, cbNode, state)); + case 179: + return Factory.updateDoStatement(node, Visitor.visit(node.statement, cbNode, state), Visitor.visit(node.expression, cbNode, state)); + case 180: + return Factory.updateWhileStatement(node, Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.statement, cbNode, state)); + case 181: + return Factory.updateForStatement(node, Visitor.visit(node.initializer, cbNode, state), Visitor.visit(node.condition, cbNode, state), Visitor.visit(node.iterator, cbNode, state), Visitor.visit(node.statement, cbNode, state)); + case 182: + return Factory.updateForInStatement(node, Visitor.visit(node.initializer, cbNode, state), Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.statement, cbNode, state)); + case 183: + return Factory.updateContinueStatement(node, Visitor.visit(node.label, cbNode, state)); + case 184: + return Factory.updateBreakStatement(node, Visitor.visit(node.label, cbNode, state)); + case 185: + return Factory.updateReturnStatement(node, Visitor.visit(node.expression, cbNode, state)); + case 186: + return Factory.updateWithStatement(node, Visitor.visit(node.expression, cbNode, state), Visitor.visit(node.statement, cbNode, state)); + case 187: + return Factory.updateSwitchStatement(node, Visitor.visit(node.expression, cbNode, state), Visitor.visitNodes(node.clauses, cbNode, state)); + case 188: + return Factory.updateLabeledStatement(node, Visitor.visit(node.label, cbNode, state), Visitor.visit(node.statement, cbNode, state)); + case 189: + return Factory.updateThrowStatement(node, Visitor.visit(node.expression, cbNode, state)); + case 190: + return Factory.updateTryStatement(node, Visitor.visit(node.tryBlock, cbNode, state), Visitor.visit(node.catchClause, cbNode, state), Visitor.visit(node.finallyBlock, cbNode, state)); + case 192: + return Factory.updateVariableDeclaration(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.initializer, cbNode, state)); + case 193: + return Factory.updateVariableDeclarationList(node, Visitor.visitNodes(node.declarations, cbNode, state)); + case 194: + return Factory.updateFunctionDeclaration(node, Visitor.visit(node.name, cbNode, state), Visitor.visitNodes(node.parameters, cbNode, state), Visitor.visit(node.body, cbNode, state)); + case 204: + return Factory.updateCaseClause(node, Visitor.visit(node.expression, cbNode, state), Visitor.visitNodes(node.statements, cbNode, state)); + case 205: + return Factory.updateDefaultClause(node, Visitor.visitNodes(node.statements, cbNode, state)); + case 207: + return Factory.updateCatchClause(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.block, cbNode, state)); + case 208: + return Factory.updatePropertyAssignment(node, Visitor.visit(node.name, cbNode, state), Visitor.visit(node.initializer, cbNode, state)); + case 209: + return Factory.updateShorthandPropertyAssignment(node, Visitor.visit(node.name, cbNode, state)); + default: + return node; + } + } + })(Visitor = ts.Visitor || (ts.Visitor = {})); +})(ts || (ts = {})); +var ts; +(function (ts) { + var Factory; + (function (Factory) { + function createNodeArray(elements, location) { + if (elements === void 0) { elements = []; } + var nodeArray = elements; + if (location) { + nodeArray.pos = location.pos; + nodeArray.end = location.end; + } + else if (!("pos" in nodeArray && "end" in nodeArray)) { + nodeArray.pos = -1; + nodeArray.end = -1; + } + return nodeArray; + } + Factory.createNodeArray = createNodeArray; + function createVoidZero(location, flags) { + return Factory.createVoidExpression(Factory.createNumericLiteral(0, location, flags), location, flags); + } + Factory.createVoidZero = createVoidZero; + function makeLeftHandSideExpression(expression) { + if (ts.isLeftHandSideExpression(expression)) { + return expression; + } + return Factory.createParenthesizedExpression(expression); + } + Factory.makeLeftHandSideExpression = makeLeftHandSideExpression; + function createPropertyOrElementAccessExpression(expression, propName) { + if (propName.kind !== 64) { + return Factory.createElementAccessExpression(expression, propName); + } + return Factory.createPropertyAccessExpression(expression, propName); + } + Factory.createPropertyOrElementAccessExpression = createPropertyOrElementAccessExpression; + function updateFunctionLikeDeclaration(node, name, body, parameters) { + switch (node.kind) { + case 194: + return Factory.updateFunctionDeclaration(node, name, parameters, body); + case 130: + return Factory.updateMethodDeclaration(node, name, parameters, body); + case 132: + return Factory.updateGetAccessor(node, name, parameters, body); + case 158: + return Factory.updateFunctionExpression(node, name, parameters, body); + case 159: + return Factory.updateArrowFunction(node, parameters, body); + } + return node; + } + Factory.updateFunctionLikeDeclaration = updateFunctionLikeDeclaration; + function getExpressionForEntityName(name) { + if (!name) { + return finishNode(beginNode(88)); + } + if (name.kind === 64) { + return Factory.createIdentifier(name.text); + } + else { + return Factory.createPropertyAccessExpression(getExpressionForEntityName(name.left), Factory.createIdentifier(name.right.text)); + } + } + Factory.getExpressionForEntityName = getExpressionForEntityName; + function createTokenNode(token, location, flags) { + return finishNode(beginNode(token), location, flags); + } + Factory.createTokenNode = createTokenNode; + function beginNode(kind) { + var ctor = ts.getNodeConstructor(kind); + var node = (new ctor()); + return node; + } + Factory.beginNode = beginNode; + function finishNode(node, location, flags, modifiers) { + if (location) { + node.pos = location.pos; + node.end = location.end; + } + else { + node.pos = -1; + node.end = -1; + } + if (flags) { + node.flags = flags; + } + if (modifiers) { + node.modifiers = modifiers; + node.flags |= node.modifiers.flags; + } + ts.forEachChild(node, function (child) { return childAdded(node, child); }); + return node; + } + Factory.finishNode = finishNode; + function childAdded(parent, child) { + if (child && !child.parent) { + child.parent = parent; + } + } + })(Factory = ts.Factory || (ts.Factory = {})); + var Visitor; + (function (Visitor) { + function visit(node, cbNode, state) { + if (!cbNode || !node) { + return node; + } + return cbNode(node, state); + } + Visitor.visit = visit; + function visitNodes(nodes, cbNode, state, shouldCacheNode, cacheNode, removeMissingNodes) { + if (!nodes || !cbNode) { + return nodes; + } + var updatedNodes; + var updatedOffset = 0; + var cacheOffset = 0; + for (var i = 0; i < nodes.length; i++) { + var updatedIndex = i - updatedOffset; + var node = nodes[i]; + if (shouldCacheNode && shouldCacheNode(node, state)) { + if (!updatedNodes) { + updatedNodes = nodes.slice(0, i); + } + if (cacheNode) { + while (cacheOffset < updatedIndex) { + updatedNodes[cacheOffset] = cacheNode(updatedNodes[cacheOffset], state); + cacheOffset++; + } + } + cacheOffset = updatedIndex; + } + var updatedNode = visit(node, cbNode, state); + if ((updatedNodes || updatedNode !== node || (!updatedNode && removeMissingNodes))) { + if (!updatedNodes) { + updatedNodes = nodes.slice(0, i); + } + if (!updatedNode && removeMissingNodes) { + updatedOffset++; + } + else { + updatedNodes[i - updatedOffset] = updatedNode; + } + } + } + if (updatedNodes) { + return Factory.createNodeArray(updatedNodes, nodes); + } + return nodes; + } + Visitor.visitNodes = visitNodes; + })(Visitor = ts.Visitor || (ts.Visitor = {})); +})(ts || (ts = {})); +var ts; +(function (ts) { + var Locals; + (function (Locals) { + function create(resolver, context, globals) { + return { resolver: resolver, context: context, globals: globals, tempCount: 0 }; + } + Locals.create = create; + function copy(source, target) { + if (!source || target === source) { + return target; + } + target.context = source.context; + target.globals = source.globals; + target.resolver = source.resolver; + target.tempCount = source.tempCount; + target.variables = source.variables; + return target; + } + Locals.copy = copy; + function createUniqueIdentifier(locals, name, globallyUnique) { + while (true) { + if (name && locals.resolver.isUnknownIdentifier(locals.context, name)) { + break; + } + name = "_" + (locals.tempCount < 25 ? String.fromCharCode(locals.tempCount + (locals.tempCount < 8 ? 0 : 1) + 97) : locals.tempCount - 25); + locals.tempCount++; + } + if (globallyUnique) { + locals.globals[name] = true; + } + return ts.Factory.createIdentifier(name); + } + Locals.createUniqueIdentifier = createUniqueIdentifier; + function recordVariable(locals, name) { + if (!locals.variables) { + locals.variables = []; + } + locals.variables.push(name); + } + Locals.recordVariable = recordVariable; + function ensureIdentifier(locals, expression, writeAssignment, state) { + if (expression.kind !== 64) { + var local = createUniqueIdentifier(locals); + writeAssignment(local, expression, state); + return local; + } + return expression; + } + Locals.ensureIdentifier = ensureIdentifier; + function getValueOrDefault(locals, value, defaultValue, writeAssignment, state) { + value = ensureIdentifier(locals, value, writeAssignment, state); + var equalityExpression = ts.Factory.createBinaryExpression(30, value, ts.Factory.createVoidZero()); + var conditionalExpression = ts.Factory.createConditionalExpression(equalityExpression, defaultValue, value); + return conditionalExpression; + } + Locals.getValueOrDefault = getValueOrDefault; + })(Locals = ts.Locals || (ts.Locals = {})); + var GeneratorFunctionBuilder; + (function (GeneratorFunctionBuilder) { + function create(locals) { + return { + locals: locals, + flags: 0, + nextLabelId: 1 + }; + } + GeneratorFunctionBuilder.create = create; + function declareLocal(builder, name, globallyUnique) { + var local = Locals.createUniqueIdentifier(builder.locals, name, globallyUnique); + Locals.recordVariable(builder.locals, local); + return local; + } + GeneratorFunctionBuilder.declareLocal = declareLocal; + function writeLocation(builder, location) { + builder.pendingLocation = location; + } + GeneratorFunctionBuilder.writeLocation = writeLocation; + function readLocation(builder) { + var location = builder.pendingLocation; + builder.pendingLocation = undefined; + return location; + } + function addParameter(builder, name, flags) { + if (!builder.parameters) { + builder.parameters = []; + } + builder.parameters.push(ts.Factory.createParameterDeclaration(name, undefined, undefined, undefined, undefined, undefined, readLocation(builder), flags)); + } + GeneratorFunctionBuilder.addParameter = addParameter; + function addVariable(builder, name, flags) { + Locals.recordVariable(builder.locals, name); + } + GeneratorFunctionBuilder.addVariable = addVariable; + function addFunction(builder, func) { + if (!builder.functions) { + builder.functions = []; + } + builder.functions.push(func); + } + GeneratorFunctionBuilder.addFunction = addFunction; + function defineLabel(builder) { + if (!builder.labels) { + builder.labels = []; + } + var label = builder.nextLabelId++; + builder.labels[label] = -1; + return label; + } + GeneratorFunctionBuilder.defineLabel = defineLabel; + function markLabel(builder, label) { + ts.Debug.assert(!!builder.labels, "No labels were defined."); + builder.labels[label] = builder.operations ? builder.operations.length : 0; + } + GeneratorFunctionBuilder.markLabel = markLabel; + function beginWithBlock(builder, expression) { + var startLabel = defineLabel(builder); + var endLabel = defineLabel(builder); + markLabel(builder, startLabel); + beginBlock(builder, { + kind: 5, + expression: expression, + startLabel: startLabel, + endLabel: endLabel + }); + } + GeneratorFunctionBuilder.beginWithBlock = beginWithBlock; + function endWithBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 5); + var withBlock = endBlock(builder); + markLabel(builder, withBlock.endLabel); + } + GeneratorFunctionBuilder.endWithBlock = endWithBlock; + function beginExceptionBlock(builder) { + var startLabel = defineLabel(builder); + var endLabel = defineLabel(builder); + markLabel(builder, startLabel); + beginBlock(builder, { + kind: 0, + state: 0, + startLabel: startLabel, + endLabel: endLabel + }); + emit(builder, 0); + builder.flags |= 1; + return endLabel; + } + GeneratorFunctionBuilder.beginExceptionBlock = beginExceptionBlock; + function beginCatchBlock(builder, variable) { + ts.Debug.assert(peekBlockKind(builder) === 0); + var exception = peekBlock(builder); + ts.Debug.assert(exception.state < 1); + var endLabel = exception.endLabel; + emit(builder, 3, endLabel); + var catchLabel = defineLabel(builder); + markLabel(builder, catchLabel); + exception.state = 1; + exception.catchVariable = variable; + exception.catchLabel = catchLabel; + var state = getState(builder); + var errorProperty = ts.Factory.createPropertyAccessExpression(state, ts.Factory.createIdentifier("error")); + var assignExpression = ts.Factory.createBinaryExpression(52, variable, errorProperty); + emit(builder, 1, assignExpression); + emit(builder, 0); + } + GeneratorFunctionBuilder.beginCatchBlock = beginCatchBlock; + function beginFinallyBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 0); + var exception = peekBlock(builder); + ts.Debug.assert(exception.state < 2); + var state = exception.state; + var endLabel = exception.endLabel; + emit(builder, 3, endLabel); + var finallyLabel = defineLabel(builder); + markLabel(builder, finallyLabel); + exception.state = 2; + exception.finallyLabel = finallyLabel; + } + GeneratorFunctionBuilder.beginFinallyBlock = beginFinallyBlock; + function endExceptionBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 0); + var exception = endBlock(builder); + var state = exception.state; + if (state < 2) { + emit(builder, 3, exception.endLabel); + } + else { + emit(builder, 9); + } + markLabel(builder, exception.endLabel); + exception.state = 3; + } + GeneratorFunctionBuilder.endExceptionBlock = endExceptionBlock; + function beginScriptContinueBlock(builder, labelText) { + beginBlock(builder, { + kind: 3, + labelText: labelText, + breakLabel: -1, + continueLabel: -1 + }); + } + GeneratorFunctionBuilder.beginScriptContinueBlock = beginScriptContinueBlock; + function endScriptContinueBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 3); + endBlock(builder); + } + GeneratorFunctionBuilder.endScriptContinueBlock = endScriptContinueBlock; + function beginScriptBreakBlock(builder, labelText, requireLabel) { + beginBlock(builder, { + kind: 1, + labelText: labelText, + breakLabel: -1, + requireLabel: requireLabel + }); + } + GeneratorFunctionBuilder.beginScriptBreakBlock = beginScriptBreakBlock; + function endScriptBreakBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 1); + endBlock(builder); + } + GeneratorFunctionBuilder.endScriptBreakBlock = endScriptBreakBlock; + function beginContinueBlock(builder, continueLabel, labelText) { + var breakLabel = defineLabel(builder); + beginBlock(builder, { + kind: 4, + labelText: labelText, + breakLabel: breakLabel, + continueLabel: continueLabel + }); + return breakLabel; + } + GeneratorFunctionBuilder.beginContinueBlock = beginContinueBlock; + function endContinueBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 4); + var block = endBlock(builder); + var breakLabel = block.breakLabel; + if (breakLabel > 0) { + markLabel(builder, breakLabel); + } + } + GeneratorFunctionBuilder.endContinueBlock = endContinueBlock; + function beginBreakBlock(builder, labelText, requireLabel) { + var breakLabel = defineLabel(builder); + beginBlock(builder, { + kind: 2, + labelText: labelText, + breakLabel: breakLabel, + requireLabel: requireLabel + }); + return breakLabel; + } + GeneratorFunctionBuilder.beginBreakBlock = beginBreakBlock; + function endBreakBlock(builder) { + ts.Debug.assert(peekBlockKind(builder) === 2); + var block = endBlock(builder); + var breakLabel = block.breakLabel; + if (breakLabel > 0) { + markLabel(builder, breakLabel); + } + } + GeneratorFunctionBuilder.endBreakBlock = endBreakBlock; + function beginBlock(builder, block) { + if (!builder.blocks) { + builder.blocks = []; + builder.blockActions = []; + builder.blockOffsets = []; + builder.blockStack = []; + } + var index = builder.blockActions.length; + builder.blockActions[index] = 0; + builder.blockOffsets[index] = builder.operations ? builder.operations.length : 0; + builder.blocks[index] = block; + builder.blockStack.push(block); + return index; + } + function endBlock(builder) { + ts.Debug.assert(!!builder.blocks, "beginBlock was never called."); + var block = builder.blockStack.pop(); + var index = builder.blockActions.length; + builder.blockActions[index] = 1; + builder.blockOffsets[index] = builder.operations ? builder.operations.length : 0; + builder.blocks[index] = block; + return block; + } + function peekBlock(builder, back) { + if (back === void 0) { back = 0; } + if (builder.blocks) { + return builder.blockStack[builder.blockStack.length - (1 + back)]; + } + } + function peekBlockKind(builder, back) { + if (back === void 0) { back = 0; } + var block = peekBlock(builder, back); + return block && block.kind; + } + function findBreakTarget(builder, labelText) { + if (builder.blocks) { + for (var i = builder.blockStack.length - 1; i >= 0; i--) { + var block = builder.blockStack[i]; + if (supportsBreak(builder, block)) { + var breakBlock = block; + if ((!labelText && !breakBlock.requireLabel) || breakBlock.labelText && breakBlock.labelText.indexOf(labelText) !== -1) { + return breakBlock.breakLabel; + } + } + } + } + return 0; + } + GeneratorFunctionBuilder.findBreakTarget = findBreakTarget; + function findContinueTarget(builder, labelText) { + if (builder.blocks) { + for (var i = builder.blockStack.length - 1; i >= 0; i--) { + var block = builder.blockStack[i]; + if (supportsContinue(builder, block)) { + var continueBreakBlock = block; + if (!labelText || continueBreakBlock.labelText && continueBreakBlock.labelText.indexOf(labelText) !== -1) { + return continueBreakBlock.continueLabel; + } + } + } + } + } + GeneratorFunctionBuilder.findContinueTarget = findContinueTarget; + function supportsBreak(builder, block) { + switch (block.kind) { + case 1: + case 3: + case 2: + case 4: + return true; + } + return false; + } + function supportsContinue(builder, block) { + switch (block.kind) { + case 3: + case 4: + return true; + } + return false; + } + function emit(builder, code) { + var args = []; + for (var _i = 2; _i < arguments.length; _i++) { + args[_i - 2] = arguments[_i]; + } + switch (code) { + case 3: + case 5: + case 4: + case 0: + case 2: + case 1: + case 7: + case 8: + case 9: + case 6: + break; + default: + reportUnexpectedOpCode(code); + return; + } + var location = readLocation(builder); + if (code === 1) { + var node = args[0]; + if (!node) { + return; + } + } + if (!builder.operations) { + builder.operations = []; + builder.operationArguments = []; + builder.operationLocations = []; + } + if (!builder.labels) { + markLabel(builder, defineLabel(builder)); + } + var operationIndex = builder.operations.length; + builder.operations[operationIndex] = code; + builder.operationArguments[operationIndex] = args; + builder.operationLocations[operationIndex] = location; + } + GeneratorFunctionBuilder.emit = emit; + function createLabel(builder, label) { + if (label > 0) { + if (!builder.labelNumbers) { + builder.labelNumbers = []; + } + return ts.Factory.createGeneratedLabel(label, builder.labelNumbers); + } + return ts.Factory.createOmittedExpression(); + } + function createInlineBreak(builder, label) { + ts.Debug.assert(label > 0, "Invalid label: " + label); + var instruction = ts.Factory.createNumericLiteral('3 /*break*/'); + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction, createLabel(builder, label)]); + return ts.Factory.createReturnStatement(returnExpression, readLocation(builder)); + } + GeneratorFunctionBuilder.createInlineBreak = createInlineBreak; + function createInlineReturn(builder, expression) { + var instruction = ts.Factory.createNumericLiteral('3 /*return*/'); + if (expression) { + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction, expression]); + } + else { + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction]); + } + return ts.Factory.createReturnStatement(returnExpression, readLocation(builder)); + } + GeneratorFunctionBuilder.createInlineReturn = createInlineReturn; + function createResume(builder) { + var state = getState(builder); + return ts.Factory.createPropertyAccessExpression(state, ts.Factory.createIdentifier("sent")); + } + GeneratorFunctionBuilder.createResume = createResume; + function getState(builder) { + if (!builder.state) { + builder.state = Locals.createUniqueIdentifier(builder.locals, "_state"); + } + return builder.state; + } + function buildFunction(builder, kind, name, location, flags, modifiers) { + var statements = []; + statements = buildHoistedFunctionDeclarations(builder, statements); + var generatorStatements = buildStatements(builder); + var generatorFunctionBody = ts.Factory.createBlock(generatorStatements); + var generatorFunction = ts.Factory.createFunctionExpression(undefined, [ts.Factory.createParameterDeclaration(getState(builder))], generatorFunctionBody); + var generatorExpression = ts.Factory.createCallExpression(ts.Factory.createIdentifier("__generator"), [generatorFunction]); + var returnStatement = ts.Factory.createReturnStatement(generatorExpression); + statements.push(returnStatement); + var body = ts.Factory.createBlock(ts.Factory.createNodeArray(statements)); + var node; + switch (kind) { + case 194: + return ts.Factory.createFunctionDeclaration(name, builder.parameters, body, undefined, undefined, modifiers, undefined, location, flags); + case 130: + return ts.Factory.createMethodDeclaration(name, builder.parameters, body, undefined, undefined, modifiers, undefined, location, flags); + case 132: + return ts.Factory.createGetAccessor(name, builder.parameters, body, undefined, undefined, modifiers, location, flags); + case 158: + return ts.Factory.createFunctionExpression(name, builder.parameters, body, undefined, undefined, modifiers, undefined, location, flags); + case 159: + return ts.Factory.createArrowFunction(builder.parameters, body, undefined, undefined, modifiers, location, flags); + default: + ts.reportUnexpectedNode(node); + return node; + } + } + GeneratorFunctionBuilder.buildFunction = buildFunction; + function buildHoistedFunctionDeclarations(builder, statements) { + if (builder.functions) { + statements = statements.concat(builder.functions); + } + return statements; + } + function buildStatements(builder) { + var operations = builder.operations, operationArguments = builder.operationArguments, operationLocations = builder.operationLocations; + var statementBuilder = { + builder: builder, + operationIndex: 0, + blockIndex: 0, + labelNumber: 0 + }; + if (builder.flags & 1) { + initializeProtectedRegions(statementBuilder); + } + if (operations) { + for (statementBuilder.operationIndex = 0; statementBuilder.operationIndex < operations.length; statementBuilder.operationIndex++) { + writeOperation(statementBuilder, operations[statementBuilder.operationIndex], operationArguments[statementBuilder.operationIndex], operationLocations[statementBuilder.operationIndex]); + } + } + flushFinalLabel(statementBuilder); + if (statementBuilder.clauses) { + var state = getState(builder); + var labelExpression = ts.Factory.createPropertyAccessExpression(state, ts.Factory.createIdentifier("label")); + var switchStatement = ts.Factory.createSwitchStatement(labelExpression, statementBuilder.clauses); + return [switchStatement]; + } + if (statementBuilder.statements) { + return statementBuilder.statements; + } + return []; + } + function initializeProtectedRegions(statementBuilder) { + var trysProperty = ts.Factory.createPropertyAccessExpression(getState(statementBuilder.builder), ts.Factory.createIdentifier("trys")); + var trysArray = ts.Factory.createArrayLiteralExpression([]); + var assignTrys = ts.Factory.createBinaryExpression(52, trysProperty, trysArray); + writeStatement(statementBuilder, assignTrys); + flushLabel(statementBuilder); + } + function flushLabel(statementBuilder) { + if (!statementBuilder.statements) { + return; + } + appendLabel(statementBuilder, !statementBuilder.lastOperationWasAbrupt); + statementBuilder.lastOperationWasAbrupt = false; + statementBuilder.lastOperationWasCompletion = false; + statementBuilder.labelNumber++; + } + function flushFinalLabel(statementBuilder) { + if (!statementBuilder.lastOperationWasCompletion) { + tryEnterLabel(statementBuilder); + writeReturn(statementBuilder); + } + if (statementBuilder.statements && statementBuilder.clauses) { + appendLabel(statementBuilder, false); + } + } + function appendLabel(statementBuilder, markLabelEnd) { + var builder = statementBuilder.builder, statements = statementBuilder.statements, withBlockStack = statementBuilder.withBlockStack, currentExceptionBlock = statementBuilder.currentExceptionBlock, labelNumber = statementBuilder.labelNumber; + if (!statementBuilder.clauses) { + statementBuilder.clauses = []; + } + if (statements) { + if (withBlockStack) { + for (var i = withBlockStack.length - 1; i >= 0; i--) { + var withBlock = withBlockStack[i]; + statements = [ts.Factory.createWithStatement(withBlock.expression, ts.Factory.createBlock(statements))]; + } + } + if (currentExceptionBlock) { + var startLabel = currentExceptionBlock.startLabel, catchLabel = currentExceptionBlock.catchLabel, finallyLabel = currentExceptionBlock.finallyLabel, endLabel = currentExceptionBlock.endLabel; + var labelsArray = ts.Factory.createArrayLiteralExpression([ + createLabel(builder, startLabel), + createLabel(builder, catchLabel), + createLabel(builder, finallyLabel), + createLabel(builder, endLabel) + ]); + var trysProperty = ts.Factory.createPropertyAccessExpression(getState(builder), ts.Factory.createIdentifier("trys")); + var pushMethod = ts.Factory.createPropertyAccessExpression(trysProperty, ts.Factory.createIdentifier("push")); + var callExpression = ts.Factory.createCallExpression(pushMethod, [labelsArray]); + statements.unshift(ts.Factory.createExpressionStatement(callExpression)); + statementBuilder.currentExceptionBlock = undefined; + } + if (markLabelEnd) { + var nextLabelNumberExpression = ts.Factory.createNumericLiteral(labelNumber + 1); + var labelProperty = ts.Factory.createPropertyAccessExpression(getState(builder), ts.Factory.createIdentifier("label")); + var labelAssign = ts.Factory.createBinaryExpression(52, labelProperty, nextLabelNumberExpression); + statements.push(ts.Factory.createExpressionStatement(labelAssign)); + } + } + var labelNumberExpression = ts.Factory.createNumericLiteral(labelNumber); + var clause = ts.Factory.createCaseClause(labelNumberExpression, statements || []); + statementBuilder.clauses.push(clause); + statementBuilder.statements = undefined; + } + function tryEnterLabel(statementBuilder) { + var operationIndex = statementBuilder.operationIndex, builder = statementBuilder.builder, labels = builder.labels; + if (!labels) { + return; + } + var isLabel = false; + for (var label = 0; label < labels.length; label++) { + if (labels[label] === operationIndex) { + flushLabel(statementBuilder); + if (!builder.labelNumbers) { + builder.labelNumbers = []; + } + builder.labelNumbers[label] = statementBuilder.labelNumber; + } + } + } + function tryEnterOrLeaveBlock(statementBuilder) { + var operationIndex = statementBuilder.operationIndex, _a = statementBuilder.builder, blocks = _a.blocks, blockActions = _a.blockActions, blockOffsets = _a.blockOffsets; + if (blocks) { + for (; statementBuilder.blockIndex < blockActions.length && blockOffsets[statementBuilder.blockIndex] <= operationIndex; statementBuilder.blockIndex++) { + statementBuilder.blockIndex = statementBuilder.blockIndex; + var block = blocks[statementBuilder.blockIndex]; + var blockAction = blockActions[statementBuilder.blockIndex]; + if (blockAction === 0 && block.kind === 0) { + var exceptionBlock = block; + if (!statementBuilder.exceptionBlockStack) { + statementBuilder.exceptionBlockStack = []; + } + if (!statementBuilder.statements) { + statementBuilder.statements = []; + } + statementBuilder.exceptionBlockStack.push(statementBuilder.currentExceptionBlock); + statementBuilder.currentExceptionBlock = exceptionBlock; + } + else if (blockAction === 1 && block.kind === 0) { + statementBuilder.currentExceptionBlock = statementBuilder.exceptionBlockStack.pop(); + } + else if (blockAction === 0 && block.kind === 5) { + var withBlock = block; + if (!statementBuilder.withBlockStack) { + statementBuilder.withBlockStack = []; + } + statementBuilder.withBlockStack.push(withBlock); + } + else if (blockAction === 1 && block.kind === 5) { + statementBuilder.withBlockStack.pop(); + } + } + } + } + function writeOperation(statementBuilder, operation, operationArguments, operationLocation) { + tryEnterLabel(statementBuilder); + tryEnterOrLeaveBlock(statementBuilder); + if (statementBuilder.lastOperationWasAbrupt) { + return; + } + statementBuilder.lastOperationWasAbrupt = false; + statementBuilder.lastOperationWasCompletion = false; + switch (operation) { + case 0: return; + case 1: return writeStatement(statementBuilder, operationArguments[0]); + case 2: return writeAssign(statementBuilder, operationArguments[0], operationArguments[1], operationLocation); + case 3: return writeBreak(statementBuilder, operationArguments[0], operationLocation); + case 4: return writeBreakWhenTrue(statementBuilder, operationArguments[0], operationArguments[1], operationLocation); + case 5: return writeBreakWhenFalse(statementBuilder, operationArguments[0], operationArguments[1], operationLocation); + case 6: return writeYield(statementBuilder, operationArguments[0], operationLocation); + case 7: return writeReturn(statementBuilder, operationArguments[0], operationLocation); + case 8: return writeThrow(statementBuilder, operationArguments[0], operationLocation); + case 9: return writeEndfinally(statementBuilder); + } + } + function writeStatement(statementBuilder, node) { + if (ts.isExpression(node)) { + node = ts.Factory.createExpressionStatement(node); + } + if (!statementBuilder.statements) { + statementBuilder.statements = []; + } + statementBuilder.statements.push(node); + } + function writeAssign(statementBuilder, left, right, operationLocation) { + var assignExpression = ts.Factory.createBinaryExpression(52, left, right, operationLocation); + writeStatement(statementBuilder, assignExpression); + } + function writeThrow(statementBuilder, expression, operationLocation) { + statementBuilder.lastOperationWasAbrupt = true; + statementBuilder.lastOperationWasCompletion = true; + var throwStatement = ts.Factory.createThrowStatement(expression, operationLocation); + writeStatement(statementBuilder, throwStatement); + } + function writeReturn(statementBuilder, expression, operationLocation) { + statementBuilder.lastOperationWasAbrupt = true; + statementBuilder.lastOperationWasCompletion = true; + var elements = [ts.Factory.createNumericLiteral('2 /*return*/')]; + if (expression) { + elements.push(expression); + } + var returnExpression = ts.Factory.createArrayLiteralExpression(elements); + var returnStatement = ts.Factory.createReturnStatement(returnExpression, operationLocation); + writeStatement(statementBuilder, returnStatement); + } + function writeBreak(statementBuilder, label, operationLocation) { + statementBuilder.lastOperationWasAbrupt = true; + var instruction = ts.Factory.createNumericLiteral('3 /*break*/'); + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction, createLabel(statementBuilder.builder, label)]); + var returnStatement = ts.Factory.createReturnStatement(returnExpression, operationLocation); + writeStatement(statementBuilder, returnStatement); + } + function writeBreakWhenTrue(statementBuilder, label, condition, operationLocation) { + var instruction = ts.Factory.createNumericLiteral('3 /*break*/'); + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction, createLabel(statementBuilder.builder, label)]); + var returnStatement = ts.Factory.createReturnStatement(returnExpression, operationLocation); + var ifStatement = ts.Factory.createIfStatement(condition, returnStatement); + writeStatement(statementBuilder, ifStatement); + } + function writeBreakWhenFalse(statementBuilder, label, condition, operationLocation) { + var instruction = ts.Factory.createNumericLiteral('3 /*break*/'); + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction, createLabel(statementBuilder.builder, label)]); + var returnStatement = ts.Factory.createReturnStatement(returnExpression, operationLocation); + var parenExpression = ts.Factory.createParenthesizedExpression(condition); + var notExpression = ts.Factory.createPrefixUnaryExpression(46, parenExpression); + var ifStatement = ts.Factory.createIfStatement(notExpression, returnStatement); + writeStatement(statementBuilder, ifStatement); + } + function writeYield(statementBuilder, expression, operationLocation) { + statementBuilder.lastOperationWasAbrupt = true; + var elements = [ts.Factory.createNumericLiteral('4 /*yield*/')]; + if (expression) { + elements.push(expression); + } + var returnExpression = ts.Factory.createArrayLiteralExpression(elements); + var returnStatement = ts.Factory.createReturnStatement(returnExpression, operationLocation); + writeStatement(statementBuilder, returnStatement); + } + function writeEndfinally(statementBuilder) { + statementBuilder.lastOperationWasAbrupt = true; + var instruction = ts.Factory.createNumericLiteral('5 /*endfinally*/'); + var returnExpression = ts.Factory.createArrayLiteralExpression([instruction]); + var returnStatement = ts.Factory.createReturnStatement(returnExpression); + writeStatement(statementBuilder, returnStatement); + } + function reportUnexpectedOpCode(code) { + var text; + if (typeof ts.OpCode === "object") { + text = ts.OpCode[code]; + } + else { + text = String(code); + } + ts.Debug.fail("Unexpected OpCode: " + text); + } + })(GeneratorFunctionBuilder = ts.GeneratorFunctionBuilder || (ts.GeneratorFunctionBuilder = {})); +})(ts || (ts = {})); +var ts; +(function (ts) { + var BindingElementRewriter; + (function (BindingElementRewriter) { + function rewrite(root, locals, value) { + var isDeclaration = root.kind === 192 && !(ts.getCombinedNodeFlags(root) & 1) || root.kind === 126; + var state = { + isDeclaration: isDeclaration, + root: root, + locals: locals, + value: value + }; + ts.Visitor.visit(root, visitNode, state); + return state.variableDeclarations; + } + BindingElementRewriter.rewrite = rewrite; + function visitNode(node, state) { + switch (node.kind) { + case 126: + case 192: + case 148: + return visitBindingElement(node, state); + case 146: + return visitObjectBindingPattern(node, state); + case 147: + return visitArrayBindingPattern(node, state); + case 64: + return visitIdentifier(node, state); + default: + return node; + } + } + function visitBindingElement(node, state) { + var value = state.value, locals = state.locals, saveValue = value; + if (node.initializer) { + value = value ? ts.Locals.getValueOrDefault(locals, value, node.initializer, writeDeclaration, state) : node.initializer; + } + else if (!value) { + value = ts.Factory.createVoidZero(); + } + state.value = value; + ts.Visitor.visit(node.name, visitNode, state); + state.value = saveValue; + return node; + } + function visitObjectBindingPattern(node, state) { + var value = state.value, locals = state.locals, saveValue = value; + var elements = node.elements; + if (elements.length !== 1) { + value = ts.Locals.ensureIdentifier(locals, value, writeDeclaration, state); + } + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + var propName = element.propertyName || element.name; + state.value = ts.Factory.createPropertyOrElementAccessExpression(ts.Factory.makeLeftHandSideExpression(value), propName); + ts.Visitor.visit(element, visitNode, state); + } + state.value = saveValue; + return node; + } + function visitArrayBindingPattern(node, state) { + var value = state.value, locals = state.locals, saveValue = value; + var elements = node.elements; + if (elements.length !== 1) { + value = ts.Locals.ensureIdentifier(locals, value, writeDeclaration, state); + } + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + if (element.kind !== 172) { + if (!element.dotDotDotToken) { + state.value = ts.Factory.createElementAccessExpression(ts.Factory.makeLeftHandSideExpression(value), ts.Factory.createNumericLiteral(i)); + ts.Visitor.visit(element, visitNode, state); + } + else if (i === elements.length - 1) { + value = ts.Locals.ensureIdentifier(locals, value, writeDeclaration, state); + var name = element.name; + var sliceExpression = ts.Factory.createPropertyAccessExpression(ts.Factory.makeLeftHandSideExpression(value), ts.Factory.createIdentifier("slice")); + var callExpression = ts.Factory.createCallExpression(sliceExpression, [ts.Factory.createNumericLiteral(i)]); + writeAssignment(name, callExpression, state); + } + } + } + state.value = saveValue; + return node; + } + function visitIdentifier(node, state) { + var value = state.value; + writeAssignment(node, value, state); + return node; + } + function writeDeclaration(left, right, state) { + var isDeclaration = state.isDeclaration, locals = state.locals; + if (!isDeclaration) { + ts.Locals.recordVariable(locals, left); + } + writeAssignment(left, right, state); + } + function writeAssignment(left, right, state) { + var _a = state.variableDeclarations, variableDeclarations = _a === void 0 ? [] : _a, root = state.root; + var variableDeclaration = ts.Factory.createVariableDeclaration(left, right); + if (root.kind === 192 && left.parent && (left.parent.kind === 192 || left.parent.kind === 148)) { + if (ts.getCombinedNodeFlags(left.parent) & 1) { + variableDeclaration.parent = state.root.parent; + variableDeclaration.flags |= 1; + } + } + variableDeclarations.push(variableDeclaration); + state.variableDeclarations = variableDeclarations; + } + })(BindingElementRewriter = ts.BindingElementRewriter || (ts.BindingElementRewriter = {})); + var DestructuringAssignmentRewriter; + (function (DestructuringAssignmentRewriter) { + function rewrite(root, locals) { + var value = root.right; + var state = { + root: root, + locals: locals, + value: value + }; + var target = getLeftHandSideOfDestructuringAssignment(root); + if (root.parent.kind !== 177) { + value = ts.Locals.ensureIdentifier(locals, value, writeDeclaration, state); + } + state.value = value; + ts.Visitor.visit(target, visitNode, state); + var mergedAssignments = state.mergedAssignments; + if (root.parent.kind !== 177) { + mergedAssignments = ts.Factory.createBinaryExpression(23, mergedAssignments, value); + } + return mergedAssignments; + } + DestructuringAssignmentRewriter.rewrite = rewrite; + function getLeftHandSideOfDestructuringAssignment(node) { + if (node.operator === 52) { + var left = node.left; + while (left.kind === 157) { + left = left.expression; + } + switch (left.kind) { + case 150: + case 149: + return left; + } + } + } + function visitNode(node, state) { + switch (node.kind) { + case 166: + return visitBinaryExpression(node, state); + case 150: + return visitObjectLiteralExpression(node, state); + case 149: + return visitArrayLiteralExpression(node, state); + } + var value = state.value; + writeAssignment(node, value, state); + return node; + } + function visitClassElement(node, state) { + switch (node.kind) { + case 208: + case 209: + return visitPropertyAssignment(node, state); + default: + return node; + } + } + function visitBinaryExpression(node, state) { + var value = state.value, locals = state.locals, saveValue = value; + if (node.operator === 52) { + value = ts.Locals.getValueOrDefault(locals, value, node.right, writeDeclaration, state); + state.value = value; + ts.Visitor.visit(node.left, visitNode, state); + } + state.value = saveValue; + return node; + } + function visitObjectLiteralExpression(node, state) { + var value = state.value, locals = state.locals, saveValue = value; + var properties = node.properties; + if (properties.length !== 1) { + value = ts.Locals.ensureIdentifier(locals, value, writeDeclaration, state); + } + state.value = value; + ts.Visitor.visitNodes(properties, visitClassElement, state); + state.value = saveValue; + return node; + } + function visitPropertyAssignment(node, state) { + var value = state.value, saveValue = value; + var propName = node.name; + state.value = ts.Factory.createPropertyOrElementAccessExpression(ts.Factory.makeLeftHandSideExpression(value), propName); + ts.Visitor.visit(node.initializer || propName, visitNode, state); + state.value = saveValue; + return node; + } + function visitArrayLiteralExpression(node, state) { + var value = state.value, locals = state.locals, saveValue = value; + var elements = node.elements; + if (elements.length !== 1) { + value = ts.Locals.ensureIdentifier(state.locals, value, writeDeclaration, state); + } + for (var i = 0; i < elements.length; i++) { + var e = elements[i]; + if (e.kind !== 172) { + if (e.kind !== 171) { + state.value = ts.Factory.createElementAccessExpression(ts.Factory.makeLeftHandSideExpression(value), ts.Factory.createNumericLiteral(i)); + ts.Visitor.visit(e, visitNode, state); + } + else if (i === elements.length - 1) { + value = ts.Locals.ensureIdentifier(state.locals, value, writeDeclaration, state); + var sliceExpression = ts.Factory.createPropertyAccessExpression(ts.Factory.makeLeftHandSideExpression(value), ts.Factory.createIdentifier("slice")); + var callExpression = ts.Factory.createCallExpression(sliceExpression, [ts.Factory.createNumericLiteral(i)]); + writeAssignment(e.expression, callExpression, state); + } + } + } + state.value = saveValue; + return node; + } + function visitIdentifier(node, state) { + var value = state.value; + writeAssignment(node, value, state); + return node; + } + function writeDeclaration(left, right, state) { + var locals = state.locals; + ts.Locals.recordVariable(locals, left); + writeAssignment(left, right, state); + } + function writeAssignment(left, right, state) { + var mergedAssignments = state.mergedAssignments; + var assignmentExpression = ts.Factory.createBinaryExpression(52, left, right); + if (mergedAssignments) { + mergedAssignments = ts.Factory.createBinaryExpression(23, mergedAssignments, assignmentExpression); + } + else { + mergedAssignments = assignmentExpression; + } + state.mergedAssignments = mergedAssignments; + } + })(DestructuringAssignmentRewriter = ts.DestructuringAssignmentRewriter || (ts.DestructuringAssignmentRewriter = {})); + var SpreadElementRewriter; + (function (SpreadElementRewriter) { + function rewrite(elements) { + var segments; + var length = elements.length; + var start = 0; + for (var i = 0; i < length; i++) { + var element = elements[i]; + if (element.kind === 171) { + if (!segments) { + segments = []; + } + if (i > start) { + segments.push(ts.Factory.createArrayLiteralExpression(elements.slice(start, i))); + } + segments.push(element.expression); + start = i + 1; + } + } + if (!segments) { + return undefined; + } + if (start < length) { + segments.push(ts.Factory.createArrayLiteralExpression(elements.slice(start, length))); + } + if (segments.length === 1) { + return ts.Factory.makeLeftHandSideExpression(segments[0]); + } + var head = ts.Factory.makeLeftHandSideExpression(segments.shift()); + var concatExpression = ts.Factory.createPropertyAccessExpression(head, ts.Factory.createIdentifier("concat")); + var callExpression = ts.Factory.createCallExpression(concatExpression, segments); + return callExpression; + } + SpreadElementRewriter.rewrite = rewrite; + })(SpreadElementRewriter = ts.SpreadElementRewriter || (ts.SpreadElementRewriter = {})); + var AsyncFunctionRewriter; + (function (AsyncFunctionRewriter) { + function rewrite(node, promiseConstructor, locals, compilerOptions) { + var resolve = ts.Locals.createUniqueIdentifier(locals, "_resolve"); + var generatorFunctionBody = ts.Factory.createBlock(rewriteBody(node.body)); + var generatorFunction = ts.Factory.createFunctionExpression(undefined, [], generatorFunctionBody); + generatorFunction.asteriskToken = ts.Factory.createTokenNode(35); + var bodyStatements = []; + var generator = createGenerator(generatorFunctionBody, bodyStatements, locals, compilerOptions); + var awaiterCallExpression = ts.Factory.createCallExpression(ts.Factory.createIdentifier("__awaiter"), [generator]); + var resolveCallExpression = ts.Factory.createCallExpression(resolve, [awaiterCallExpression]); + var resolveCallStatement = ts.Factory.createExpressionStatement(resolveCallExpression); + var initFunctionBody = ts.Factory.createBlock([resolveCallStatement]); + var initFunctionExpression = ts.Factory.createFunctionExpression(undefined, [ts.Factory.createParameterDeclaration(resolve)], initFunctionBody); + var newPromiseExpression = ts.Factory.createNewExpression(ts.Factory.getExpressionForEntityName(promiseConstructor), [initFunctionExpression]); + var bodyReturnStatement = ts.Factory.createReturnStatement(newPromiseExpression); + bodyStatements.push(bodyReturnStatement); + var block = ts.Factory.createBlock(bodyStatements); + var func = ts.Factory.updateFunctionLikeDeclaration(node, node.name, block, node.parameters); + func.id = node.id; + func.parent = node.parent; + return func; + } + AsyncFunctionRewriter.rewrite = rewrite; + function rewriteBody(body) { + if (body.kind === 174) { + return ts.Visitor.visitNodes(body.statements, visitNode); + } + else { + return ts.Factory.createNodeArray([ + ts.Factory.createReturnStatement(ts.Visitor.visit(body, visitNode)) + ]); + } + } + function createGenerator(body, statements, locals, compilerOptions) { + var generatorFunction = ts.Factory.createFunctionExpression(undefined, [], body); + generatorFunction.asteriskToken = ts.Factory.createTokenNode(35); + if (compilerOptions.target < 2) { + generatorFunction = GeneratorFunctionRewriter.rewrite(generatorFunction, locals); + body = generatorFunction.body; + var generator; + for (var i = 0; i < body.statements.length; i++) { + var statement = body.statements[i]; + if (statement.kind === 194 || statement.kind === 175) { + statements.push(statement); + } + else if (statement.kind === 185) { + generator = statement.expression; + } + } + return generator; + } + else { + return ts.Factory.createCallExpression(generatorFunction, []); + } + } + function visitNode(node) { + switch (node.kind) { + case 163: + return visitAwaitExpression(node); + case 177: + return visitExpressionStatement(node); + case 159: + case 158: + case 194: + case 132: + case 133: + case 130: + return node; + default: + return ts.Visitor.fallback(node, visitNode); + } + } + function visitAwaitExpression(node) { + var expression = ts.Visitor.visit(node.expression, visitNode); + var yieldExpression = ts.Factory.createYieldExpression(expression, undefined, node); + return ts.Factory.makeLeftHandSideExpression(yieldExpression); + } + function visitExpressionStatement(node) { + var expression = ts.Visitor.visit(node.expression, visitNode); + if (ts.nodeIsGenerated(expression) && expression.kind === 157) { + expression = expression.expression; + } + return ts.Factory.updateExpressionStatement(node, expression); + } + })(AsyncFunctionRewriter = ts.AsyncFunctionRewriter || (ts.AsyncFunctionRewriter = {})); + var GeneratorFunctionRewriter; + (function (GeneratorFunctionRewriter) { + function rewrite(node, locals) { + var builder = ts.GeneratorFunctionBuilder.create(locals); + var state = { + locals: locals, + builder: builder + }; + if (node.parameters) { + for (var i = 0; i < node.parameters.length; i++) { + var parameter = node.parameters[i]; + rewriteParameterDeclaration(parameter, state); + } + } + if (node.body.kind === 174) { + rewriteBlock(node.body, state); + } + else { + ts.GeneratorFunctionBuilder.emit(builder, 7, ts.Visitor.visit(node.body, visitNode, state)); + } + var func = ts.GeneratorFunctionBuilder.buildFunction(builder, node.kind, node.name, node, node.flags, node.modifiers); + func.id = node.id; + func.parent = node.parent; + return func; + } + GeneratorFunctionRewriter.rewrite = rewrite; + function visitNode(node, state) { + switch (node.kind) { + case 166: return visitBinaryExpression(node, state); + case 167: return visitConditionalExpression(node, state); + case 169: return visitYieldExpression(node, state); + case 149: return visitArrayLiteralExpression(node, state); + case 150: return visitObjectLiteralExpression(node, state); + case 152: return visitElementAccessExpression(node, state); + case 153: return visitCallExpression(node, state); + case 154: return visitNewExpression(node, state); + case 155: return visitTaggedTemplateExpression(node, state); + case 168: return visitTemplateExpression(node, state); + case 157: return visitParenthesizedExpression(node, state); + case 175: return visitVariableStatement(node, state); + case 177: return visitExpressionStatement(node, state); + case 178: return visitIfStatement(node, state); + case 179: return visitDoStatement(node, state); + case 180: return visitWhileStatement(node, state); + case 181: return visitForStatement(node, state); + case 182: return visitForInStatement(node, state); + case 183: return visitContinueStatement(node, state); + case 184: return visitBreakStatement(node, state); + case 185: return visitReturnStatement(node, state); + case 186: return visitWithStatement(node, state); + case 187: return visitSwitchStatement(node, state); + case 188: return visitLabeledStatement(node, state); + case 190: return visitTryStatement(node, state); + case 194: return visitFunctionDeclaration(node, state); + case 158: + case 159: + case 132: + case 133: + case 130: + return node; + default: + return ts.Visitor.fallback(node, visitNode, state); + } + } + function visitBinaryExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + return rewriteBinaryExpression(node, state); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitConditionalExpression(node, state) { + if (ts.hasAwaitOrYield(node.whenTrue) || ts.hasAwaitOrYield(node.whenFalse)) { + return rewriteConditionalExpression(node, state); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitYieldExpression(node, state) { + return rewriteYieldExpression(node, state); + } + function visitArrayLiteralExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + var rewritten = SpreadElementRewriter.rewrite(node.elements); + if (rewritten) { + return ts.Visitor.visit(rewritten, visitNode, state); + } + return ts.Factory.updateArrayLiteralExpression(node, ts.Visitor.visitNodes(node.elements, visitNode, state, ts.hasAwaitOrYield, cacheExpression)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitObjectLiteralExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + return ts.Factory.updateObjectLiteralExpression(node, ts.Visitor.visitNodes(node.properties, visitNode, state, ts.hasAwaitOrYield, cacheObjectLiteralElement)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitElementAccessExpression(node, state) { + if (ts.hasAwaitOrYield(node.argumentExpression)) { + var object = cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state); + return ts.Factory.updateElementAccessExpression(node, object, ts.Visitor.visit(node.argumentExpression, visitNode, state)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitCallExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + var binding = rewriteLeftHandSideOfCallExpression(node.expression, state); + var arguments = ts.Visitor.visitNodes(node.arguments, visitNode, state, ts.hasAwaitOrYield, cacheExpression); + var target = binding.target; + var thisArg = binding.thisArg; + if (thisArg) { + var callArguments = ts.Factory.createNodeArray([thisArg].concat(arguments), node.arguments); + var callProperty = ts.Factory.createPropertyAccessExpression(target, ts.Factory.createIdentifier("call")); + return ts.Factory.updateCallExpression(node, callProperty, callArguments); + } + else { + return ts.Factory.updateCallExpression(node, target, arguments); + } + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitNewExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + return ts.Factory.updateNewExpression(node, cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state), ts.Visitor.visitNodes(node.arguments, visitNode, state, ts.hasAwaitOrYield, cacheExpression)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitTaggedTemplateExpression(node, state) { + if (ts.hasAwaitOrYield(node.template)) { + return ts.Factory.updateTaggedTemplateExpression(node, cacheExpression(ts.Visitor.visit(node.tag, visitNode, state), state), ts.Visitor.visit(node.template, visitNode, state)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitTemplateExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + return ts.Factory.updateTemplateExpression(node, node.head, ts.Visitor.visitNodes(node.templateSpans, visitNode, state, ts.hasAwaitOrYield, cacheTemplateSpan)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitParenthesizedExpression(node, state) { + if (ts.hasAwaitOrYield(node)) { + return rewriteParenthesizedExpression(node, state); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitFunctionDeclaration(node, state) { + ts.GeneratorFunctionBuilder.addFunction(state.builder, node); + return; + } + function visitVariableStatement(node, state) { + var assignment = rewriteVariableDeclarationList(node.declarationList, state); + if (assignment) { + return ts.Factory.createExpressionStatement(assignment); + } + return; + } + function visitVariableDeclarationListOrExpression(node, state) { + if (node.kind === 193) { + return rewriteVariableDeclarationList(node, state); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitExpressionStatement(node, state) { + if (ts.hasAwaitOrYield(node.expression)) { + rewriteExpressionStatement(node, state); + return; + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitIfStatement(node, state) { + if (ts.hasAwaitOrYield(node.thenStatement) || ts.hasAwaitOrYield(node.elseStatement)) { + rewriteIfStatement(node, state); + return; + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitDoStatement(node, state) { + if (ts.hasAwaitOrYield(node)) { + rewriteDoStatement(node, state); + return; + } + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginScriptContinueBlock(state.builder, getLabelNames(node)); + node = ts.Visitor.fallback(node, visitNode, state); + ts.GeneratorFunctionBuilder.endScriptContinueBlock(builder); + return node; + } + function visitWhileStatement(node, state) { + if (ts.hasAwaitOrYield(node)) { + rewriteWhileStatement(node, state); + return; + } + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginScriptContinueBlock(builder, getLabelNames(node)); + node = ts.Visitor.fallback(node, visitNode, state); + ts.GeneratorFunctionBuilder.endScriptContinueBlock(builder); + return node; + } + function visitForStatement(node, state) { + if (ts.hasAwaitOrYield(node.condition) || ts.hasAwaitOrYield(node.iterator) || ts.hasAwaitOrYield(node.statement)) { + rewriteForStatement(node, state); + return; + } + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginScriptContinueBlock(builder, getLabelNames(node)); + node = ts.Factory.updateForStatement(node, ts.Visitor.visit(node.initializer, visitVariableDeclarationListOrExpression, state), ts.Visitor.visit(node.condition, visitNode, state), ts.Visitor.visit(node.iterator, visitNode, state), ts.Visitor.visit(node.statement, visitNode, state)); + ts.GeneratorFunctionBuilder.endScriptContinueBlock(builder); + return node; + } + function visitForInStatement(node, state) { + if (ts.hasAwaitOrYield(node.statement)) { + rewriteForInStatement(node, state); + return; + } + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginScriptContinueBlock(builder, getLabelNames(node)); + node = ts.Factory.updateForInStatement(node, ts.Visitor.visit(node.initializer, visitVariableDeclarationListOrExpression, state), ts.Visitor.visit(node.expression, visitNode, state), ts.Visitor.visit(node.statement, visitNode, state)); + ts.GeneratorFunctionBuilder.endScriptContinueBlock(builder); + return node; + } + function visitBreakStatement(node, state) { + var label = ts.GeneratorFunctionBuilder.findBreakTarget(state.builder, node.label && node.label.text); + if (label > 0) { + ts.GeneratorFunctionBuilder.writeLocation(state.builder, node); + return ts.GeneratorFunctionBuilder.createInlineBreak(state.builder, label); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitContinueStatement(node, state) { + var label = ts.GeneratorFunctionBuilder.findContinueTarget(state.builder, node.label && node.label.text); + if (label > 0) { + ts.GeneratorFunctionBuilder.writeLocation(state.builder, node); + return ts.GeneratorFunctionBuilder.createInlineBreak(state.builder, label); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitReturnStatement(node, state) { + var expression = ts.Visitor.visit(node.expression, visitNode, state); + ts.GeneratorFunctionBuilder.writeLocation(state.builder, node); + return ts.GeneratorFunctionBuilder.createInlineReturn(state.builder, expression); + } + function visitSwitchStatement(node, state) { + if (ts.forEach(node.clauses, ts.hasAwaitOrYield)) { + rewriteSwitchStatement(node, state); + return; + } + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginScriptBreakBlock(builder, getLabelNames(node), false); + node = ts.Visitor.fallback(node, visitNode, state); + ts.GeneratorFunctionBuilder.endScriptBreakBlock(builder); + return node; + } + function visitWithStatement(node, state) { + if (ts.hasAwaitOrYield(node.statement)) { + rewriteWithStatement(node, state); + return; + } + return ts.Visitor.fallback(node, visitNode, state); + } + function visitLabeledStatement(node, state) { + if (ts.hasAwaitOrYield(node.statement)) { + rewriteLabeledStatement(node, state); + return; + } + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginScriptBreakBlock(builder, getLabelNames(node), true); + node = ts.Visitor.fallback(node, visitNode, state); + ts.GeneratorFunctionBuilder.endScriptBreakBlock(builder); + return node; + } + function visitTryStatement(node, state) { + if (ts.hasAwaitOrYield(node)) { + rewriteTryStatement(node, state); + return; + } + return ts.Visitor.fallback(node, visitNode, state); + } + function cacheExpression(node, state) { + var local = ts.GeneratorFunctionBuilder.declareLocal(state.builder); + var assignExpression = ts.Factory.createBinaryExpression(52, local, node); + ts.GeneratorFunctionBuilder.emit(state.builder, 1, ts.Factory.createExpressionStatement(assignExpression)); + return local; + } + function cacheObjectLiteralElement(node, state) { + switch (node.kind) { + case 208: + return cachePropertyAssignment(node, state); + case 209: + return cacheShorthandPropertyAssignment(node, state); + default: + return node; + } + } + function cachePropertyAssignment(node, state) { + return ts.Factory.updatePropertyAssignment(node, node.name, cacheExpression(node.initializer, state)); + } + function cacheShorthandPropertyAssignment(node, state) { + return ts.Factory.createPropertyAssignment(ts.Factory.createIdentifier(node.name.text), cacheExpression(node.name, state)); + } + function cacheTemplateSpan(node, state) { + return ts.Factory.updateTemplateSpan(node, cacheExpression(node.expression, state), node.literal); + } + function rewriteBinaryExpression(node, state) { + if (ts.isLogicalBinary(node)) { + if (ts.hasAwaitOrYield(node.right)) { + return rewriteLogicalBinaryExpression(node, state); + } + } + else if (ts.isDestructuringAssignment(node)) { + return rewriteDestructuringAssignment(node, state); + } + else if (ts.isAssignment(node)) { + if (ts.hasAwaitOrYield(node.right)) { + return rewriteAssignmentExpression(node, state); + } + } + else if (node.operator === 23) { + return rewriteCommaExpression(node, state); + } + else if (ts.hasAwaitOrYield(node.right)) { + return ts.Factory.updateBinaryExpression(node, cacheExpression(ts.Visitor.visit(node.left, visitNode, state), state), ts.Visitor.visit(node.right, visitNode, state)); + } + return ts.Visitor.fallback(node, visitNode, state); + } + function rewriteLogicalBinaryExpression(node, state) { + var builder = state.builder; + var resumeLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var resultLocal = ts.GeneratorFunctionBuilder.declareLocal(builder); + var code = node.operator === 48 ? 5 : 4; + ts.GeneratorFunctionBuilder.writeLocation(builder, node.left); + ts.GeneratorFunctionBuilder.emit(builder, 2, resultLocal, ts.Visitor.visit(node.left, visitNode, state)); + ts.GeneratorFunctionBuilder.emit(builder, code, resumeLabel, resultLocal); + ts.GeneratorFunctionBuilder.writeLocation(builder, node.right); + ts.GeneratorFunctionBuilder.emit(builder, 2, resultLocal, ts.Visitor.visit(node.right, visitNode, state)); + ts.GeneratorFunctionBuilder.markLabel(builder, resumeLabel); + return resultLocal; + } + function rewriteCommaExpression(node, state) { + var builder = state.builder; + var expressions = flattenCommaExpression(node); + var merged; + for (var i = 0; i < expressions.length; i++) { + var expression = expressions[i]; + if (ts.hasAwaitOrYield(expression) && merged) { + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(merged)); + merged = undefined; + } + var visited = ts.Visitor.visit(expression, visitNode, state); + if (merged) { + merged = ts.Factory.createBinaryExpression(23, merged, visited); + } + else { + merged = visited; + } + } + return merged; + } + function rewriteDestructuringAssignment(node, state) { + var destructured = DestructuringAssignmentRewriter.rewrite(node, state.locals); + var rewritten = visitBinaryExpression(destructured, state); + if (ts.needsParenthesisForPropertyAccess(node)) { + return ts.Factory.makeLeftHandSideExpression(rewritten); + } + return rewritten; + } + function rewriteAssignmentExpression(node, state) { + return ts.Factory.updateBinaryExpression(node, rewriteLeftHandSideOfAssignmentExpression(node.left, state), ts.Visitor.visit(node.right, visitNode, state)); + } + function rewriteLeftHandSideOfAssignmentExpression(node, state) { + switch (node.kind) { + case 152: + return rewriteLeftHandSideElementAccessExpressionOfAssignmentExpression(node, state); + case 151: + return rewriteLeftHandSidePropertyAccessExpressionOfAssignmentExpression(node, state); + default: + return ts.Visitor.fallback(node, visitNode, state); + } + } + function rewriteLeftHandSideElementAccessExpressionOfAssignmentExpression(node, state) { + return ts.Factory.updateElementAccessExpression(node, cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state), cacheExpression(ts.Visitor.visit(node.argumentExpression, visitNode, state), state)); + } + function rewriteLeftHandSidePropertyAccessExpressionOfAssignmentExpression(node, state) { + return ts.Factory.updatePropertyAccessExpression(node, cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state), node.name); + } + function rewriteLeftHandSideOfCallExpression(node, state) { + switch (node.kind) { + case 151: + return rewriteLeftHandSidePropertyAccessExpressionOfCallExpression(node, state); + case 152: + return rewriteLeftHandSideElementAccessExpressionOfCallExpression(node, state); + default: + return { target: cacheExpression(ts.Visitor.visit(node, visitNode, state), state) }; + } + } + function rewriteLeftHandSideElementAccessExpressionOfCallExpression(node, state) { + var builder = state.builder; + var thisArg = cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state); + var target = ts.GeneratorFunctionBuilder.declareLocal(builder); + var index = ts.Visitor.visit(node.argumentExpression, visitNode, state); + var indexedAccess = ts.Factory.createElementAccessExpression(thisArg, index, node); + var assignExpression = ts.Factory.createBinaryExpression(52, target, indexedAccess); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(assignExpression)); + return { target: target, thisArg: thisArg }; + } + function rewriteLeftHandSidePropertyAccessExpressionOfCallExpression(node, state) { + var builder = state.builder; + var thisArg = cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state); + var target = ts.GeneratorFunctionBuilder.declareLocal(builder); + var property = ts.Factory.createIdentifier(node.name.text); + var propertyAccess = ts.Factory.createPropertyAccessExpression(thisArg, property, node); + var assignExpression = ts.Factory.createBinaryExpression(52, target, propertyAccess); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(assignExpression)); + return { target: target, thisArg: thisArg }; + } + function rewriteVariableDeclarationList(node, state) { + var declarations = node.declarations; + return rewriteVariableDeclarations(node, declarations, state); + } + function rewriteVariableDeclarations(parent, declarations, state) { + var builder = state.builder; + var mergedAssignment; + for (var i = 0; i < declarations.length; i++) { + var node = declarations[i]; + if (ts.hasAwaitOrYield(node)) { + if (mergedAssignment) { + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(mergedAssignment)); + mergedAssignment = undefined; + } + } + var rewritten = rewriteVariableDeclaration(node, state); + if (rewritten) { + if (mergedAssignment) { + mergedAssignment = ts.Factory.createBinaryExpression(23, mergedAssignment, rewritten); + } + else { + mergedAssignment = rewritten; + } + } + } + if (parent.kind === 193 && parent.parent.kind === 182) { + if (mergedAssignment) { + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(mergedAssignment)); + mergedAssignment = undefined; + } + var declaration = declarations[0]; + return declaration.name; + } + return mergedAssignment; + } + function rewriteVariableDeclaration(node, state) { + var builder = state.builder; + if (ts.isBindingPattern(node.name)) { + var declarations = BindingElementRewriter.rewrite(node, state.locals); + var result = rewriteVariableDeclarations(node, declarations, state); + rewriteExpression(result, state); + return; + } + ts.GeneratorFunctionBuilder.addVariable(builder, ts.Factory.createIdentifier(node.name.text)); + var initializer = ts.Visitor.visit(node.initializer, visitNode, state); + if (initializer) { + return ts.Factory.createBinaryExpression(52, node.name, initializer, node); + } + } + function rewriteConditionalExpression(node, state) { + var builder = state.builder; + var whenFalseLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var resumeLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var resultLocal = ts.GeneratorFunctionBuilder.declareLocal(builder); + ts.GeneratorFunctionBuilder.emit(builder, 5, whenFalseLabel, ts.Visitor.visit(node.condition, visitNode, state)); + ts.GeneratorFunctionBuilder.writeLocation(builder, node.whenTrue); + ts.GeneratorFunctionBuilder.emit(builder, 2, resultLocal, ts.Visitor.visit(node.whenTrue, visitNode, state)); + ts.GeneratorFunctionBuilder.emit(builder, 3, resumeLabel); + ts.GeneratorFunctionBuilder.markLabel(builder, whenFalseLabel); + ts.GeneratorFunctionBuilder.writeLocation(builder, node.whenFalse); + ts.GeneratorFunctionBuilder.emit(builder, 2, resultLocal, ts.Visitor.visit(node.whenFalse, visitNode, state)); + ts.GeneratorFunctionBuilder.markLabel(builder, resumeLabel); + return resultLocal; + } + function rewriteYieldExpression(node, state) { + var builder = state.builder; + var expression = ts.Visitor.visit(node.expression, visitNode, state); + var resumeLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.Debug.assert(!node.asteriskToken, "yield* not supported"); + ts.GeneratorFunctionBuilder.emit(builder, 6, expression); + ts.GeneratorFunctionBuilder.markLabel(builder, resumeLabel); + return ts.GeneratorFunctionBuilder.createResume(builder); + } + function rewriteParenthesizedExpression(node, state) { + var expression = ts.Visitor.visit(node.expression, visitNode, state); + return ts.Factory.makeLeftHandSideExpression(expression); + } + function rewriteExpressionStatement(node, state) { + var builder = state.builder; + var expression = ts.Visitor.visit(node.expression, visitNode, state); + if (!ts.isAwaitOrYield(node.expression)) { + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 1, expression); + } + } + function rewriteIfStatement(node, state) { + var builder = state.builder; + var resumeLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + if (node.elseStatement) { + var elseLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + } + ts.GeneratorFunctionBuilder.emit(builder, 5, elseLabel || resumeLabel, ts.Visitor.visit(node.expression, visitNode, state)); + rewriteBlockOrStatement(node.thenStatement, state); + if (node.elseStatement) { + ts.GeneratorFunctionBuilder.emit(builder, 3, resumeLabel); + ts.GeneratorFunctionBuilder.markLabel(builder, elseLabel); + rewriteBlockOrStatement(node.elseStatement, state); + } + ts.GeneratorFunctionBuilder.markLabel(builder, resumeLabel); + } + function rewriteDoStatement(node, state) { + var builder = state.builder; + var bodyLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var conditionLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var endLabel = ts.GeneratorFunctionBuilder.beginContinueBlock(builder, conditionLabel, getLabelNames(node)); + ts.GeneratorFunctionBuilder.markLabel(builder, bodyLabel); + rewriteBlockOrStatement(node.statement, state); + ts.GeneratorFunctionBuilder.markLabel(builder, conditionLabel); + ts.GeneratorFunctionBuilder.emit(builder, 4, bodyLabel, ts.Visitor.visit(node.expression, visitNode, state)); + ts.GeneratorFunctionBuilder.endContinueBlock(builder); + } + function rewriteWhileStatement(node, state) { + var builder = state.builder; + var conditionLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var bodyLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var endLabel = ts.GeneratorFunctionBuilder.beginContinueBlock(builder, conditionLabel, getLabelNames(node)); + ts.GeneratorFunctionBuilder.markLabel(builder, conditionLabel); + ts.GeneratorFunctionBuilder.emit(builder, 5, endLabel, ts.Visitor.visit(node.expression, visitNode, state)); + rewriteBlockOrStatement(node.statement, state); + ts.GeneratorFunctionBuilder.emit(builder, 3, conditionLabel); + ts.GeneratorFunctionBuilder.endContinueBlock(builder); + } + function rewriteForStatement(node, state) { + var builder = state.builder; + var conditionLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var iteratorLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var endLabel = ts.GeneratorFunctionBuilder.beginContinueBlock(builder, iteratorLabel, getLabelNames(node)); + if (node.initializer) { + var initializer = visitVariableDeclarationListOrExpression(node.initializer, state); + ts.GeneratorFunctionBuilder.writeLocation(builder, node.initializer); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(initializer)); + } + ts.GeneratorFunctionBuilder.markLabel(builder, conditionLabel); + if (node.condition) { + ts.GeneratorFunctionBuilder.emit(builder, 5, endLabel, ts.Visitor.visit(node.condition, visitNode, state)); + } + rewriteBlockOrStatement(node.statement, state); + ts.GeneratorFunctionBuilder.markLabel(builder, iteratorLabel); + if (node.iterator) { + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(ts.Visitor.visit(node.iterator, visitNode, state))); + } + ts.GeneratorFunctionBuilder.emit(builder, 3, conditionLabel); + ts.GeneratorFunctionBuilder.endContinueBlock(builder); + } + function rewriteForInStatement(node, state) { + var builder = state.builder; + var variable = visitVariableDeclarationListOrExpression(node.initializer, state); + while (variable.kind === 166) { + variable = variable.left; + } + var keysLocal = ts.GeneratorFunctionBuilder.declareLocal(builder); + var tempLocal = ts.GeneratorFunctionBuilder.declareLocal(builder); + var conditionLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var iteratorLabel = ts.GeneratorFunctionBuilder.defineLabel(builder); + var endLabel = ts.GeneratorFunctionBuilder.beginContinueBlock(builder, iteratorLabel, getLabelNames(node)); + var initializeKeysExpression = ts.Factory.createBinaryExpression(52, keysLocal, ts.Factory.createArrayLiteralExpression([])); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(initializeKeysExpression)); + var keysLengthExpression = ts.Factory.createPropertyAccessExpression(keysLocal, ts.Factory.createIdentifier("length")); + var keysPushExpression = ts.Factory.createElementAccessExpression(keysLocal, keysLengthExpression); + var assignKeyExpression = ts.Factory.createBinaryExpression(52, keysPushExpression, tempLocal); + var assignKeyStatement = ts.Factory.createExpressionStatement(assignKeyExpression); + var expression = cacheExpression(ts.Factory.makeLeftHandSideExpression(ts.Visitor.visit(node.expression, visitNode, state)), state); + var forTempInExpressionStatement = ts.Factory.createForInStatement(tempLocal, expression, assignKeyStatement); + ts.GeneratorFunctionBuilder.emit(builder, 1, forTempInExpressionStatement); + var initializeTempExpression = ts.Factory.createBinaryExpression(52, tempLocal, ts.Factory.createNumericLiteral(0)); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(initializeTempExpression)); + var conditionExpression = ts.Factory.createBinaryExpression(24, tempLocal, keysLengthExpression); + ts.GeneratorFunctionBuilder.markLabel(builder, conditionLabel); + ts.GeneratorFunctionBuilder.emit(builder, 5, endLabel, conditionExpression); + var readKeyExpression = ts.Factory.createElementAccessExpression(keysLocal, tempLocal); + var hasKeyExpression = ts.Factory.createBinaryExpression(85, readKeyExpression, expression); + ts.GeneratorFunctionBuilder.emit(builder, 5, iteratorLabel, hasKeyExpression); + var assignVariableExpression = ts.Factory.createBinaryExpression(52, variable, readKeyExpression); + ts.GeneratorFunctionBuilder.writeLocation(builder, node.initializer); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(assignVariableExpression, variable)); + rewriteBlockOrStatement(node.statement, state); + ts.GeneratorFunctionBuilder.markLabel(builder, iteratorLabel); + var incrementTempExpression = ts.Factory.createPostfixUnaryExpression(38, tempLocal); + ts.GeneratorFunctionBuilder.writeLocation(builder, node.initializer); + ts.GeneratorFunctionBuilder.emit(builder, 1, ts.Factory.createExpressionStatement(incrementTempExpression, variable)); + ts.GeneratorFunctionBuilder.emit(builder, 3, conditionLabel); + ts.GeneratorFunctionBuilder.endContinueBlock(builder); + } + function rewriteSwitchStatement(node, state) { + var builder = state.builder; + var defaultClauseIndex = -1; + var endLabel = ts.GeneratorFunctionBuilder.beginBreakBlock(builder, getLabelNames(node), false); + var clauseHasStatements = []; + var clauseLabelMap = []; + var clauseLabels = [endLabel]; + for (var clauseIndex = node.clauses.length - 1; clauseIndex >= 0; clauseIndex--) { + var clause = node.clauses[clauseIndex]; + if (clause.kind === 205) { + if (defaultClauseIndex === -1) { + defaultClauseIndex = clauseIndex; + } + } + clauseHasStatements[clauseIndex] = !!(clause.statements && clause.statements.length); + if (clauseHasStatements[clauseIndex]) { + clauseLabelMap[clauseIndex] = clauseLabels.length; + clauseLabels.push(ts.GeneratorFunctionBuilder.defineLabel(builder)); + } + else { + clauseLabelMap[clauseIndex] = clauseLabels.length - 1; + } + } + var expression = cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state); + var lastClauseOffset = 0; + for (var clauseIndex = 0; clauseIndex < node.clauses.length; clauseIndex++) { + var clause = node.clauses[clauseIndex]; + if (clause.kind === 204) { + var caseClause = clause; + if (ts.hasAwaitOrYield(caseClause.expression)) { + emitPartialSwitchStatement(); + lastClauseOffset = clauseIndex; + } + } + } + emitPartialSwitchStatement(); + if (defaultClauseIndex > -1) { + var defaultClauseLabel = clauseLabels[clauseLabelMap[defaultClauseIndex]]; + ts.GeneratorFunctionBuilder.writeLocation(builder, node.clauses[defaultClauseIndex]); + ts.GeneratorFunctionBuilder.emit(builder, 3, defaultClauseLabel); + } + else { + ts.GeneratorFunctionBuilder.emit(builder, 3, endLabel); + } + for (var clauseIndex = 0; clauseIndex < node.clauses.length; clauseIndex++) { + if (!clauseHasStatements[clauseIndex]) { + continue; + } + var clause = node.clauses[clauseIndex]; + var clauseLabel = clauseLabels[clauseLabelMap[clauseIndex]]; + ts.GeneratorFunctionBuilder.markLabel(builder, clauseLabel); + rewriteStatements(clause.statements, state); + } + ts.GeneratorFunctionBuilder.endBreakBlock(builder); + function emitPartialSwitchStatement() { + var clauses = []; + if (lastClauseOffset < clauseIndex) { + var clause = node.clauses[lastClauseOffset]; + if (clause.kind === 204) { + var caseClause = clause; + if (ts.hasAwaitOrYield(caseClause.expression)) { + var clauseExpression = ts.Visitor.visit(caseClause.expression, visitNode, state); + var clauseLabel = clauseLabels[clauseLabelMap[lastClauseOffset]]; + ts.GeneratorFunctionBuilder.writeLocation(builder, caseClause.expression); + var breakStatement = ts.GeneratorFunctionBuilder.createInlineBreak(builder, clauseLabel); + clauses.push(ts.Factory.createCaseClause(clauseExpression, [breakStatement])); + lastClauseOffset++; + } + } + } + while (lastClauseOffset < clauseIndex) { + var clause = node.clauses[lastClauseOffset]; + var clauseLabel = clauseLabels[clauseLabelMap[lastClauseOffset]]; + if (clause.kind === 204) { + var caseClause = clause; + ts.GeneratorFunctionBuilder.writeLocation(builder, caseClause.expression); + var inlineBreak = ts.GeneratorFunctionBuilder.createInlineBreak(builder, clauseLabel); + clauses.push(ts.Factory.createCaseClause(ts.Visitor.visit(caseClause.expression, visitNode, state), [inlineBreak])); + } + lastClauseOffset++; + } + if (clauses.length) { + var switchStatement = ts.Factory.createSwitchStatement(expression, clauses, node); + ts.GeneratorFunctionBuilder.emit(builder, 1, switchStatement); + } + } + } + function rewriteWithStatement(node, state) { + var builder = state.builder; + ts.GeneratorFunctionBuilder.beginWithBlock(builder, cacheExpression(ts.Visitor.visit(node.expression, visitNode, state), state)); + rewriteBlockOrStatement(node.statement, state); + ts.GeneratorFunctionBuilder.endWithBlock(builder); + } + function rewriteLabeledStatement(node, state) { + var builder = state.builder; + if (!ts.isLabeledOrIterationOrSwitchStatement(node.statement)) { + ts.GeneratorFunctionBuilder.beginBreakBlock(builder, getLabelNames(node), true); + } + rewriteBlockOrStatement(node.statement, state); + if (!ts.isLabeledOrIterationOrSwitchStatement(node.statement)) { + ts.GeneratorFunctionBuilder.endBreakBlock(builder); + } + } + function rewriteTryStatement(node, state) { + var builder = state.builder; + var endLabel = ts.GeneratorFunctionBuilder.beginExceptionBlock(builder); + rewriteBlock(node.tryBlock, state); + if (node.catchClause) { + var variable = ts.GeneratorFunctionBuilder.declareLocal(builder, undefined, true); + if (node.catchClause.symbol) { + state.locals.resolver.renameSymbol(node.catchClause.symbol, variable.text); + } + ts.GeneratorFunctionBuilder.beginCatchBlock(builder, variable); + rewriteBlock(node.catchClause.block, state); + } + if (node.finallyBlock) { + ts.GeneratorFunctionBuilder.beginFinallyBlock(builder); + rewriteBlock(node.finallyBlock, state); + } + ts.GeneratorFunctionBuilder.endExceptionBlock(builder); + } + function rewriteReturnStatement(node, state) { + var builder = state.builder; + var expression = ts.Visitor.visit(node.expression, visitNode, state); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 7, expression); + } + function rewriteThrowStatement(node, state) { + var builder = state.builder; + var expression = ts.Visitor.visit(node.expression, visitNode, state); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 8, expression); + } + function rewriteBreakStatement(node, state) { + var builder = state.builder; + var label = ts.GeneratorFunctionBuilder.findBreakTarget(builder, node.label && node.label.text); + ts.Debug.assert(label > 0, "Expected break statement to point to a label."); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 3, label); + } + function rewriteContinueStatement(node, state) { + var builder = state.builder; + var label = ts.GeneratorFunctionBuilder.findContinueTarget(builder, node.label && node.label.text); + ts.Debug.assert(label > 0, "Expected continue statement to point to a label."); + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 3, label); + } + function rewriteStatements(statements, state) { + for (var i = 0; i < statements.length; i++) { + var statement = statements[i]; + rewriteStatement(statement, state); + } + } + function rewriteBlockOrStatement(node, state) { + if (!node) { + return; + } + switch (node.kind) { + case 174: + return rewriteBlock(node, state); + default: + return rewriteStatement(node, state); + } + } + function rewriteBlock(node, state) { + if (!node) { + return; + } + rewriteStatements(node.statements, state); + } + function rewriteStatement(node, state) { + var builder = state.builder; + if (!node) { + return; + } + switch (node.kind) { + case 174: + if (!ts.hasAwaitOrYield(node)) { + break; + } + return rewriteBlock(node, state); + case 189: + return rewriteThrowStatement(node, state); + case 185: + return rewriteReturnStatement(node, state); + case 184: + return rewriteBreakStatement(node, state); + case 183: + return rewriteContinueStatement(node, state); + } + var visited = ts.Visitor.visit(node, visitNode, state); + if (visited) { + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 1, visited); + } + } + function rewriteExpression(node, state) { + var builder = state.builder; + if (!node) { + return; + } + var visited = ts.Visitor.visit(node, visitNode, state); + if (visited) { + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.emit(builder, 1, visited); + } + } + function rewriteParameterDeclaration(node, state) { + var builder = state.builder; + var parameterName; + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + if (ts.isBindingPattern(node.name)) { + parameterName = ts.Locals.createUniqueIdentifier(state.locals); + } + else { + parameterName = node.name; + } + ts.GeneratorFunctionBuilder.writeLocation(builder, node); + ts.GeneratorFunctionBuilder.addParameter(builder, parameterName, node.flags); + if (ts.isBindingPattern(node.name)) { + var declarations = BindingElementRewriter.rewrite(node, state.locals, parameterName); + var expression = rewriteVariableDeclarations(node, declarations, state); + if (expression) { + ts.GeneratorFunctionBuilder.emit(builder, 1, expression); + } + } + else if (node.initializer) { + var equalityExpression = ts.Factory.createBinaryExpression(30, parameterName, ts.Factory.createVoidZero()); + var assignmentExpression = ts.Factory.createBinaryExpression(52, parameterName, node.initializer); + var expressionStatement = ts.Factory.createExpressionStatement(assignmentExpression); + var ifStatement = ts.Factory.createIfStatement(equalityExpression, expressionStatement); + rewriteStatement(ifStatement, state); + } + } + function flattenCommaExpression(node) { + var expressions = []; + function visitExpression(node) { + if (node.kind === 166 && node.operator === 23) { + visitExpression(node.left); + visitExpression(node.right); + } + else { + expressions.push(node); + } + } + visitExpression(node); + return expressions; + } + function getLabelNames(node) { + var labeledStatement; + switch (node.kind) { + case 188: + labeledStatement = node; + break; + case 187: + case 179: + case 180: + case 181: + case 182: + if (node.parent.kind === 188) { + labeledStatement = node.parent; + break; + } + default: + return; + } + var labels = []; + while (true) { + labels.push(labeledStatement.label.text); + if (labeledStatement.parent.kind === 188) { + labeledStatement = labeledStatement.parent; + } + else { + break; + } + } + return labels; + } + })(GeneratorFunctionRewriter = ts.GeneratorFunctionRewriter || (ts.GeneratorFunctionRewriter = {})); +})(ts || (ts = {})); +var ts; +(function (ts) { + var indentStrings = ["", " "]; + function getIndentString(level) { + if (indentStrings[level] === undefined) { + indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; + } + return indentStrings[level]; + } ts.getIndentString = getIndentString; function getIndentSize() { return indentStrings[1].length; @@ -16436,6 +20451,9 @@ var ts; }; } function getLineOfLocalPosition(currentSourceFile, pos) { + if (pos < 0) { + return -1; + } return ts.getLineAndCharacterOfPosition(currentSourceFile, pos).line; } function emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments) { @@ -16523,7 +20541,7 @@ var ts; } function getFirstConstructorWithBody(node) { return ts.forEach(node.members, function (member) { - if (member.kind === 129 && ts.nodeIsPresent(member.body)) { + if (member.kind === 131 && ts.nodeIsPresent(member.body)) { return member; } }); @@ -16532,12 +20550,12 @@ var ts; var firstAccessor; var getAccessor; var setAccessor; - if (accessor.name.kind === 122) { + if (accessor.name.kind === 124) { firstAccessor = accessor; - if (accessor.kind === 130) { + if (accessor.kind === 132) { getAccessor = accessor; } - else if (accessor.kind === 131) { + else if (accessor.kind === 133) { setAccessor = accessor; } else { @@ -16546,14 +20564,14 @@ var ts; } else { ts.forEach(node.members, function (member) { - if ((member.kind === 130 || member.kind === 131) && member.name.text === accessor.name.text && (member.flags & 128) === (accessor.flags & 128)) { + if ((member.kind === 132 || member.kind === 133) && member.name.text === accessor.name.text && (member.flags & 128) === (accessor.flags & 128)) { if (!firstAccessor) { firstAccessor = member; } - if (member.kind === 130 && !getAccessor) { + if (member.kind === 132 && !getAccessor) { getAccessor = member; } - if (member.kind === 131 && !setAccessor) { + if (member.kind === 133 && !setAccessor) { setAccessor = member; } } @@ -16770,32 +20788,32 @@ var ts; case 98: case 8: return writeTextOfNode(currentSourceFile, type); - case 135: + case 137: return emitTypeReference(type); - case 138: - return emitTypeQuery(type); case 140: + return emitTypeQuery(type); + case 142: return emitArrayType(type); - case 141: + case 143: return emitTupleType(type); - case 142: + case 144: return emitUnionType(type); - case 143: + case 145: return emitParenType(type); - case 136: - case 137: - return emitSignatureDeclarationWithJsDocComments(type); + case 138: case 139: + return emitSignatureDeclarationWithJsDocComments(type); + case 141: return emitTypeLiteral(type); case 64: return emitEntityName(type); - case 121: + case 123: return emitEntityName(type); default: ts.Debug.fail("Unknown type annotation: " + type.kind); } function emitEntityName(entityName) { - var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 197 ? entityName.parent : enclosingDeclaration); + var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 201 ? entityName.parent : enclosingDeclaration); handleSymbolAccessibilityError(visibilityResult); writeEntityName(entityName); function writeEntityName(entityName) { @@ -16866,7 +20884,7 @@ var ts; if (node.flags & 1) { write("export "); } - if (node.kind !== 192) { + if (node.kind !== 196) { write("declare "); } } @@ -16926,7 +20944,7 @@ var ts; emitModuleElementDeclarationFlags(node); write("module "); writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== 196) { + while (node.body.kind !== 200) { node = node.body; write("."); writeTextOfNode(currentSourceFile, node.name); @@ -16992,7 +21010,7 @@ var ts; writeLine(); } function isPrivateMethodTypeParameter(node) { - return node.parent.kind === 128 && (node.parent.flags & 32); + return node.parent.kind === 130 && (node.parent.flags & 32); } function emitTypeParameters(typeParameters) { function emitTypeParameter(node) { @@ -17002,8 +21020,8 @@ var ts; writeTextOfNode(currentSourceFile, node.name); if (node.constraint && !isPrivateMethodTypeParameter(node)) { write(" extends "); - if (node.parent.kind === 136 || node.parent.kind === 137 || (node.parent.parent && node.parent.parent.kind === 139)) { - ts.Debug.assert(node.parent.kind === 128 || node.parent.kind === 127 || node.parent.kind === 136 || node.parent.kind === 137 || node.parent.kind === 132 || node.parent.kind === 133); + if (node.parent.kind === 138 || node.parent.kind === 139 || (node.parent.parent && node.parent.parent.kind === 141)) { + ts.Debug.assert(node.parent.kind === 130 || node.parent.kind === 129 || node.parent.kind === 138 || node.parent.kind === 139 || node.parent.kind === 134 || node.parent.kind === 135); emitType(node.constraint); } else { @@ -17013,31 +21031,31 @@ var ts; function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.parent.kind) { - case 191: + case 195: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; break; - case 192: + case 196: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; break; - case 133: + case 135: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 132: + case 134: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 128: - case 127: + case 130: + case 129: if (node.parent.flags & 128) { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 191) { + else if (node.parent.parent.kind === 195) { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 190: + case 194: diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -17065,7 +21083,7 @@ var ts; emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.parent.parent.kind === 191) { + if (node.parent.parent.kind === 195) { diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; } else { @@ -17144,12 +21162,12 @@ var ts; writeLine(); } function emitVariableDeclaration(node) { - if (node.kind !== 188 || resolver.isDeclarationVisible(node)) { + if (node.kind !== 192 || resolver.isDeclarationVisible(node)) { writeTextOfNode(currentSourceFile, node.name); - if ((node.kind === 126 || node.kind === 125) && ts.hasQuestionToken(node)) { + if ((node.kind === 128 || node.kind === 127) && ts.hasQuestionToken(node)) { write("?"); } - if ((node.kind === 126 || node.kind === 125) && node.parent.kind === 139) { + if ((node.kind === 128 || node.kind === 127) && node.parent.kind === 141) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.flags & 32)) { @@ -17158,14 +21176,14 @@ var ts; } function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (node.kind === 188) { + if (node.kind === 192) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } - else if (node.kind === 126 || node.kind === 125) { + else if (node.kind === 128 || node.kind === 127) { if (node.flags & 128) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.kind === 191) { + else if (node.parent.kind === 195) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { @@ -17218,7 +21236,7 @@ var ts; var accessorWithTypeAnnotation = node; var type = getTypeAnnotationFromAccessor(node); if (!type) { - var anotherAccessor = node.kind === 130 ? accessors.setAccessor : accessors.getAccessor; + var anotherAccessor = node.kind === 132 ? accessors.setAccessor : accessors.getAccessor; type = getTypeAnnotationFromAccessor(anotherAccessor); if (type) { accessorWithTypeAnnotation = anotherAccessor; @@ -17231,12 +21249,12 @@ var ts; } function getTypeAnnotationFromAccessor(accessor) { if (accessor) { - return accessor.kind === 130 ? accessor.type : accessor.parameters.length > 0 ? accessor.parameters[0].type : undefined; + return accessor.kind === 132 ? accessor.type : accessor.parameters.length > 0 ? accessor.parameters[0].type : undefined; } } function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; - if (accessorWithTypeAnnotation.kind === 131) { + if (accessorWithTypeAnnotation.kind === 133) { if (accessorWithTypeAnnotation.parent.flags & 128) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; } @@ -17268,19 +21286,19 @@ var ts; if (ts.hasDynamicName(node)) { return; } - if ((node.kind !== 190 || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { + if ((node.kind !== 194 || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); - if (node.kind === 190) { + if (node.kind === 194) { emitModuleElementDeclarationFlags(node); } - else if (node.kind === 128) { + else if (node.kind === 130) { emitClassMemberDeclarationFlags(node); } - if (node.kind === 190) { + if (node.kind === 194) { write("function "); writeTextOfNode(currentSourceFile, node.name); } - else if (node.kind === 129) { + else if (node.kind === 131) { write("constructor"); } else { @@ -17297,11 +21315,11 @@ var ts; emitSignatureDeclaration(node); } function emitSignatureDeclaration(node) { - if (node.kind === 133 || node.kind === 137) { + if (node.kind === 135 || node.kind === 139) { write("new "); } emitTypeParameters(node.typeParameters); - if (node.kind === 134) { + if (node.kind === 136) { write("["); } else { @@ -17310,20 +21328,20 @@ var ts; var prevEnclosingDeclaration = enclosingDeclaration; enclosingDeclaration = node; emitCommaList(node.parameters, emitParameterDeclaration); - if (node.kind === 134) { + if (node.kind === 136) { write("]"); } else { write(")"); } - var isFunctionTypeOrConstructorType = node.kind === 136 || node.kind === 137; - if (isFunctionTypeOrConstructorType || node.parent.kind === 139) { + var isFunctionTypeOrConstructorType = node.kind === 138 || node.kind === 139; + if (isFunctionTypeOrConstructorType || node.parent.kind === 141) { if (node.type) { write(isFunctionTypeOrConstructorType ? " => " : ": "); emitType(node.type); } } - else if (node.kind !== 129 && !(node.flags & 32)) { + else if (node.kind !== 131 && !(node.flags & 32)) { writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); } enclosingDeclaration = prevEnclosingDeclaration; @@ -17334,28 +21352,28 @@ var ts; function getReturnTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.kind) { - case 133: + case 135: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 132: + case 134: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 134: + case 136: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; break; - case 128: - case 127: + case 130: + case 129: if (node.flags & 128) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } - else if (node.parent.kind === 191) { + else if (node.parent.kind === 195) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; - case 190: + case 194: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; break; default: @@ -17383,7 +21401,7 @@ var ts; write("?"); } decreaseIndent(); - if (node.parent.kind === 136 || node.parent.kind === 137 || node.parent.parent.kind === 139) { + if (node.parent.kind === 138 || node.parent.kind === 139 || node.parent.parent.kind === 141) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } else if (!(node.parent.flags & 32)) { @@ -17392,28 +21410,28 @@ var ts; function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; switch (node.parent.kind) { - case 129: + case 131: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; break; - case 133: + case 135: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 132: + case 134: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; - case 128: - case 127: + case 130: + case 129: if (node.parent.flags & 128) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } - else if (node.parent.parent.kind === 191) { + else if (node.parent.parent.kind === 195) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; - case 190: + case 194: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -17428,40 +21446,40 @@ var ts; } function emitNode(node) { switch (node.kind) { + case 131: + case 194: + case 130: case 129: - case 190: - case 128: - case 127: return emitFunctionDeclaration(node); - case 133: - case 132: + case 135: case 134: + case 136: return emitSignatureDeclarationWithJsDocComments(node); - case 130: - case 131: + case 132: + case 133: return emitAccessorDeclaration(node); - case 171: + case 175: return emitVariableStatement(node); - case 126: - case 125: + case 128: + case 127: return emitPropertyDeclaration(node); - case 192: + case 196: return emitInterfaceDeclaration(node); - case 191: + case 195: return emitClassDeclaration(node); - case 193: + case 197: return emitTypeAliasDeclaration(node); - case 206: + case 210: return emitEnumMemberDeclaration(node); - case 194: + case 198: return emitEnumDeclaration(node); - case 195: + case 199: return emitModuleDeclaration(node); - case 197: + case 201: return emitImportDeclaration(node); - case 198: + case 202: return emitExportAssignment(node); - case 207: + case 211: return emitSourceFile(node); } } @@ -17519,8 +21537,11 @@ var ts; var decreaseIndent = writer.decreaseIndent; var currentSourceFile; var extendsEmitted = false; - var tempCount = 0; - var tempVariables; + var awaiterEmitted = false; + var generatorEmitted = false; + var localsScope; + var locals; + var globals; var tempParameters; var writeEmittedFiles = writeJavaScriptFile; var emitLeadingComments = compilerOptions.removeComments ? function (node) { } : emitLeadingDeclarationComments; @@ -17643,17 +21664,28 @@ var ts; } } function recordEmitNodeStartSpan(node) { + if (ts.nodeIsMissingOrGenerated(node)) { + return; + } recordSourceMapSpan(ts.skipTrivia(currentSourceFile.text, node.pos)); } function recordEmitNodeEndSpan(node) { + if (ts.nodeIsMissingOrGenerated(node)) { + return; + } recordSourceMapSpan(node.end); } function writeTextWithSpanRecord(tokenKind, startPos, emitFn) { - var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); - recordSourceMapSpan(tokenStartPos); + if (startPos >= 0) { + var tokenStartPos = ts.skipTrivia(currentSourceFile.text, startPos); + recordSourceMapSpan(tokenStartPos); + } var tokenEndPos = emitTokenText(tokenKind, tokenStartPos, emitFn); - recordSourceMapSpan(tokenEndPos); - return tokenEndPos; + if (startPos >= 0) { + recordSourceMapSpan(tokenEndPos); + return tokenEndPos; + } + return -1; } function recordNewSourceFileStart(node) { var sourcesDirectoryPath = compilerOptions.sourceRoot ? host.getCommonSourceDirectory() : sourceMapDir; @@ -17671,7 +21703,7 @@ var ts; var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { var name = node.name; - if (!name || name.kind !== 122) { + if (!name || name.kind !== 124) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -17688,10 +21720,10 @@ var ts; if (scopeName) { recordScopeNameStart(scopeName); } - else if (node.kind === 190 || node.kind === 156 || node.kind === 128 || node.kind === 127 || node.kind === 130 || node.kind === 131 || node.kind === 195 || node.kind === 191 || node.kind === 194) { + else if (node.kind === 194 || node.kind === 158 || node.kind === 130 || node.kind === 129 || node.kind === 132 || node.kind === 133 || node.kind === 199 || node.kind === 195 || node.kind === 198) { if (node.name) { var name = node.name; - scopeName = name.kind === 122 ? ts.getTextOfNode(name) : node.name.text; + scopeName = name.kind === 124 ? ts.getTextOfNode(name) : node.name.text; } recordScopeNameStart(scopeName); } @@ -17771,7 +21803,7 @@ var ts; } function emitNodeWithMap(node) { if (node) { - if (node.kind != 207) { + if (node.kind != 211) { recordEmitNodeStartSpan(node); emitNode(node); recordEmitNodeEndSpan(node); @@ -17794,27 +21826,16 @@ var ts; function writeJavaScriptFile(emitOutput, writeByteOrderMark) { writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); } - function createTempVariable(location, forLoopVariable) { - var name = forLoopVariable ? "_i" : undefined; - while (true) { - if (name && resolver.isUnknownIdentifier(location, name)) { - break; - } - name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + 97) : tempCount - 25); - tempCount++; + function ensureLocals() { + if (!globals) { + globals = {}; } - var result = ts.createNode(64); - result.text = name; - return result; - } - function recordTempDeclaration(name) { - if (!tempVariables) { - tempVariables = []; + if (!locals) { + locals = ts.Locals.create(resolver, localsScope, globals); } - tempVariables.push(name); } function emitTempDeclarations(newLine) { - if (tempVariables) { + if (locals && locals.variables) { if (newLine) { writeLine(); } @@ -17822,7 +21843,7 @@ var ts; write(" "); } write("var "); - emitCommaList(tempVariables); + emitCommaList(locals.variables); write(";"); } } @@ -17911,7 +21932,7 @@ var ts; return false; } function emitLiteral(node) { - var text = languageVersion < 2 && ts.isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; + var text = languageVersion < 2 && ts.isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent && node.pos >= 0 ? ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; if (compilerOptions.sourceMap && (node.kind === 8 || ts.isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } @@ -17941,7 +21962,7 @@ var ts; } for (var i = 0; i < node.templateSpans.length; i++) { var templateSpan = node.templateSpans[i]; - var needsParens = templateSpan.expression.kind !== 155 && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; + var needsParens = templateSpan.expression.kind !== 157 && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; if (i > 0 || headEmitted) { write(" + "); } @@ -17960,11 +21981,11 @@ var ts; } function templateNeedsParens(template, parent) { switch (parent.kind) { - case 151: - case 152: - return parent.expression === template; case 153: + case 154: + return parent.expression === template; case 155: + case 157: return false; default: return comparePrecedenceToBinaryPlus(parent) !== -1; @@ -17972,7 +21993,7 @@ var ts; } function comparePrecedenceToBinaryPlus(expression) { switch (expression.kind) { - case 163: + case 166: switch (expression.operator) { case 35: case 36: @@ -17984,7 +22005,7 @@ var ts; default: return -1; } - case 164: + case 167: return -1; default: return 1; @@ -17999,7 +22020,7 @@ var ts; if (node.kind === 8) { emitLiteral(node); } - else if (node.kind === 122) { + else if (node.kind === 124) { emit(node.expression); } else { @@ -18016,33 +22037,33 @@ var ts; function isNotExpressionIdentifier(node) { var parent = node.parent; switch (parent.kind) { - case 124: - case 188: - case 146: case 126: - case 125: - case 204: - case 205: - case 206: + case 192: + case 148: case 128: case 127: - case 190: + case 208: + case 209: + case 210: case 130: - case 131: - case 156: - case 191: - case 192: + case 129: case 194: + case 132: + case 133: + case 158: case 195: - case 197: - return parent.name === node; - case 180: - case 179: + case 196: case 198: - return false; + case 199: + case 201: + return parent.name === node; case 184: + case 183: + case 202: + return false; + case 188: return node.parent.label === node; - case 203: + case 207: return node.parent.name === node; } } @@ -18052,17 +22073,40 @@ var ts; write(prefix); write("."); } - writeTextOfNode(currentSourceFile, node); + if (resolver.getNodeCheckFlags(node) & 8) { + write("_arguments"); + } + else { + var generatedName = resolver.getRenamedIdentifier(node); + if (generatedName) { + write(generatedName); + } + else if (!node.parent || ts.nodeIsMissingOrGenerated(node)) { + write(node.text); + } + else { + writeTextOfNode(currentSourceFile, node); + } + } } function emitIdentifier(node) { - if (!node.parent) { - write(node.text); - } - else if (!isNotExpressionIdentifier(node)) { - emitExpressionIdentifier(node); + if (resolver.getNodeCheckFlags(node) & 8) { + write("_arguments"); } else { - writeTextOfNode(currentSourceFile, node); + var generatedName = resolver.getRenamedIdentifier(node); + if (generatedName) { + write(generatedName); + } + else if (!node.parent || ts.nodeIsMissingOrGenerated(node)) { + write(node.text); + } + else if (!isNotExpressionIdentifier(node)) { + emitExpressionIdentifier(node); + } + else { + writeTextOfNode(currentSourceFile, node); + } } } function emitThis(node) { @@ -18075,10 +22119,10 @@ var ts; } function emitSuper(node) { var flags = resolver.getNodeCheckFlags(node); - if (flags & 16) { + if (flags & 64) { write("_super.prototype"); } - else if (flags & 32) { + else if (flags & 128) { write("_super"); } else { @@ -18117,64 +22161,22 @@ var ts; write("..."); emit(node.expression); } - function needsParenthesisForPropertyAccess(node) { - switch (node.kind) { - case 64: - case 147: - case 149: - case 150: - case 151: - case 155: - return false; - } - return true; - } - function emitListWithSpread(elements, multiLine, trailingComma) { - var pos = 0; - var group = 0; - var length = elements.length; - while (pos < length) { - if (group === 1) { - write(".concat("); - } - else if (group > 1) { - write(", "); - } - var e = elements[pos]; - if (e.kind === 167) { - e = e.expression; - emitParenthesized(e, group === 0 && needsParenthesisForPropertyAccess(e)); - pos++; - } - else { - var i = pos; - while (i < length && elements[i].kind !== 167) { - i++; - } - write("["); - emitList(elements, pos, i - pos, multiLine, trailingComma && i === length); - write("]"); - pos = i; - } - group++; - } - if (group > 1) { - write(")"); - } - } function emitArrayLiteral(node) { var elements = node.elements; - if (elements.length === 0) { + var length = elements.length; + if (length === 0) { write("[]"); + return; } - else if (languageVersion >= 2) { - write("["); - emitList(elements, 0, elements.length, (node.flags & 256) !== 0, elements.hasTrailingComma); - write("]"); - } - else { - emitListWithSpread(elements, (node.flags & 256) !== 0, elements.hasTrailingComma); + if (languageVersion < 2) { + var rewritten = ts.SpreadElementRewriter.rewrite(node.elements); + if (rewritten) { + return emit(rewritten); + } } + write("["); + emitList(elements, 0, elements.length, (node.flags & 256) !== 0, elements.hasTrailingComma); + write("]"); } function emitObjectLiteral(node) { write("{"); @@ -18197,6 +22199,9 @@ var ts; write("]"); } function emitMethod(node) { + if (languageVersion >= 2) { + emit(node.asteriskToken); + } emit(node.name); if (languageVersion < 2) { write(": function "); @@ -18220,7 +22225,7 @@ var ts; if (constantValue !== undefined) { write(constantValue.toString()); if (!compilerOptions.removeComments) { - var propertyName = node.kind === 149 ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); + var propertyName = node.kind === 151 ? ts.declarationNameToString(node.name) : ts.getTextOfNode(node.argumentExpression); write(" /* " + propertyName + " */"); } return true; @@ -18250,10 +22255,10 @@ var ts; write("]"); } function hasSpreadElement(elements) { - return ts.forEach(elements, function (e) { return e.kind === 167; }); + return ts.forEach(elements, function (e) { return e.kind === 171; }); } function skipParentheses(node) { - while (node.kind === 155 || node.kind === 154) { + while (node.kind === 157 || node.kind === 156) { node = node.expression; } return node; @@ -18263,8 +22268,9 @@ var ts; emit(node); return node; } - var temp = createTempVariable(node); - recordTempDeclaration(temp); + ensureLocals(); + var temp = ts.Locals.createUniqueIdentifier(locals); + ts.Locals.recordVariable(locals, temp); write("("); emit(temp); write(" = "); @@ -18275,12 +22281,12 @@ var ts; function emitCallWithSpread(node) { var target; var expr = skipParentheses(node.expression); - if (expr.kind === 149) { + if (expr.kind === 151) { target = emitCallTarget(expr.expression); write("."); emit(expr.name); } - else if (expr.kind === 150) { + else if (expr.kind === 152) { target = emitCallTarget(expr.expression); write("["); emit(expr.argumentExpression); @@ -18306,7 +22312,8 @@ var ts; write("void 0"); } write(", "); - emitListWithSpread(node.arguments, false, false); + var rewritten = ts.SpreadElementRewriter.rewrite(node.arguments); + emit(rewritten); write(")"); } function emitCallExpression(node) { @@ -18321,7 +22328,7 @@ var ts; } else { emit(node.expression); - superCall = node.expression.kind === 149 && node.expression.expression.kind === 90; + superCall = node.expression.kind === 151 && node.expression.expression.kind === 90; } if (superCall) { write(".call("); @@ -18353,12 +22360,12 @@ var ts; emit(node.template); } function emitParenExpression(node) { - if (node.expression.kind === 154) { + if (node.expression.kind === 156) { var operand = node.expression.expression; - while (operand.kind == 154) { + while (operand.kind == 156) { operand = operand.expression; } - if (operand.kind !== 161 && operand.kind !== 160 && operand.kind !== 159 && operand.kind !== 158 && operand.kind !== 162 && operand.kind !== 152 && !(operand.kind === 151 && node.parent.kind === 152) && !(operand.kind === 156 && node.parent.kind === 151)) { + if (operand.kind !== 164 && operand.kind !== 162 && operand.kind !== 161 && operand.kind !== 160 && operand.kind !== 165 && operand.kind !== 154 && !(operand.kind === 153 && node.parent.kind === 154) && !(operand.kind === 158 && node.parent.kind === 153)) { emit(operand); return; } @@ -18377,6 +22384,19 @@ var ts; write(" "); emit(node.expression); } + function emitAwaitExpression(node) { + write(ts.tokenToString(122)); + write(" "); + emit(node.expression); + } + function emitYieldExpression(node) { + write(ts.tokenToString(109)); + emit(node.asteriskToken); + if (node.expression) { + write(" "); + emit(node.expression); + } + } function emitTypeOfExpression(node) { write(ts.tokenToString(96)); write(" "); @@ -18384,7 +22404,7 @@ var ts; } function emitPrefixUnaryExpression(node) { write(ts.tokenToString(node.operator)); - if (node.operand.kind === 161) { + if (node.operand.kind === 164) { var operand = node.operand; if (node.operator === 33 && (operand.operator === 33 || operand.operator === 38)) { write(" "); @@ -18400,17 +22420,16 @@ var ts; write(ts.tokenToString(node.operator)); } function emitBinaryExpression(node) { - if (languageVersion < 2 && node.operator === 52 && (node.left.kind === 148 || node.left.kind === 147)) { - emitDestructuring(node); + if (languageVersion < 2 && node.operator === 52 && (node.left.kind === 150 || node.left.kind === 149)) { + ensureLocals(); + node = ts.DestructuringAssignmentRewriter.rewrite(node, locals); } - else { - emit(node.left); - if (node.operator !== 23) - write(" "); - write(ts.tokenToString(node.operator)); + emit(node.left); + if (node.operator !== 23) write(" "); - emit(node.right); - } + write(ts.tokenToString(node.operator)); + write(" "); + emit(node.right); } function emitConditionalExpression(node) { emit(node.condition); @@ -18419,8 +22438,11 @@ var ts; write(" : "); emit(node.whenFalse); } + function emitGeneratedLabel(node) { + write(String(node.labelNumbers[node.label])); + } function isSingleLineBlock(node) { - if (node && node.kind === 170) { + if (node && node.kind === 174) { var block = node; return block.statements.length === 0 && nodeEndIsOnSameLineAsNodeStart(block, block); } @@ -18435,12 +22457,12 @@ var ts; emitToken(14, node.pos); increaseIndent(); scopeEmitStart(node.parent); - if (node.kind === 196) { - ts.Debug.assert(node.parent.kind === 195); + if (node.kind === 200) { + ts.Debug.assert(node.parent.kind === 199); emitCaptureThisForNodeIfNecessary(node.parent); } emitLines(node.statements); - if (node.kind === 196) { + if (node.kind === 200) { emitTempDeclarations(true); } decreaseIndent(); @@ -18449,7 +22471,7 @@ var ts; scopeEmitEnd(); } function emitEmbeddedStatement(node) { - if (node.kind === 170) { + if (node.kind === 174) { write(" "); emit(node); } @@ -18461,7 +22483,7 @@ var ts; } } function emitExpressionStatement(node) { - emitParenthesized(node.expression, node.expression.kind === 157); + emitParenthesized(node.expression, node.expression.kind === 159); write(";"); } function emitIfStatement(node) { @@ -18474,7 +22496,7 @@ var ts; if (node.elseStatement) { writeLine(); emitToken(75, node.thenStatement.end); - if (node.elseStatement.kind === 174) { + if (node.elseStatement.kind === 178) { write(" "); emit(node.elseStatement); } @@ -18486,7 +22508,7 @@ var ts; function emitDoStatement(node) { write("do"); emitEmbeddedStatement(node.statement); - if (node.statement.kind === 170) { + if (node.statement.kind === 174) { write(" "); } else { @@ -18506,7 +22528,7 @@ var ts; var endPos = emitToken(81, node.pos); write(" "); endPos = emitToken(16, endPos); - if (node.initializer && node.initializer.kind === 189) { + if (node.initializer && node.initializer.kind === 193) { var variableDeclarationList = node.initializer; var declarations = variableDeclarationList.declarations; if (declarations[0] && ts.isLet(declarations[0])) { @@ -18535,7 +22557,7 @@ var ts; var endPos = emitToken(81, node.pos); write(" "); endPos = emitToken(16, endPos); - if (node.initializer.kind === 189) { + if (node.initializer.kind === 193) { var variableDeclarationList = node.initializer; if (variableDeclarationList.declarations.length >= 1) { var decl = variableDeclarationList.declarations[0]; @@ -18558,7 +22580,7 @@ var ts; emitEmbeddedStatement(node.statement); } function emitBreakOrContinueStatement(node) { - emitToken(node.kind === 180 ? 65 : 70, node.pos); + emitToken(node.kind === 184 ? 65 : 70, node.pos); emitOptional(" ", node.label); write(";"); } @@ -18594,7 +22616,7 @@ var ts; return getLineOfLocalPosition(currentSourceFile, node1.end) === getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos)); } function emitCaseOrDefaultClause(node) { - if (node.kind === 200) { + if (node.kind === 204) { write("case "); emit(node.expression); write(":"); @@ -18649,7 +22671,7 @@ var ts; function getContainingModule(node) { do { node = node.parent; - } while (node && node.kind !== 195); + } while (node && node.kind !== 199); return node; } function emitModuleMemberName(node) { @@ -18662,196 +22684,11 @@ var ts; emitNode(node.name); emitEnd(node.name); } - function emitDestructuring(root, value) { - var emitCount = 0; - var isDeclaration = (root.kind === 188 && !(ts.getCombinedNodeFlags(root) & 1)) || root.kind === 124; - if (root.kind === 163) { - emitAssignmentExpression(root); - } - else { - emitBindingElement(root, value); - } - function emitAssignment(name, value) { - if (emitCount++) { - write(", "); - } - if (name.parent && (name.parent.kind === 188 || name.parent.kind === 146)) { - emitModuleMemberName(name.parent); - } - else { - emit(name); - } - write(" = "); - emit(value); - } - function ensureIdentifier(expr) { - if (expr.kind !== 64) { - var identifier = createTempVariable(root); - if (!isDeclaration) { - recordTempDeclaration(identifier); - } - emitAssignment(identifier, expr); - expr = identifier; - } - return expr; - } - function createVoidZero() { - var zero = ts.createNode(7); - zero.text = "0"; - var result = ts.createNode(160); - result.expression = zero; - return result; - } - function createDefaultValueCheck(value, defaultValue) { - value = ensureIdentifier(value); - var equals = ts.createNode(163); - equals.left = value; - equals.operator = 30; - equals.right = createVoidZero(); - var cond = ts.createNode(164); - cond.condition = equals; - cond.whenTrue = defaultValue; - cond.whenFalse = value; - return cond; - } - function createNumericLiteral(value) { - var node = ts.createNode(7); - node.text = "" + value; - return node; - } - function parenthesizeForAccess(expr) { - if (expr.kind === 64 || expr.kind === 149 || expr.kind === 150) { - return expr; - } - var node = ts.createNode(155); - node.expression = expr; - return node; - } - function createPropertyAccess(object, propName) { - if (propName.kind !== 64) { - return createElementAccess(object, propName); - } - var node = ts.createNode(149); - node.expression = parenthesizeForAccess(object); - node.name = propName; - return node; - } - function createElementAccess(object, index) { - var node = ts.createNode(150); - node.expression = parenthesizeForAccess(object); - node.argumentExpression = index; - return node; - } - function emitObjectLiteralAssignment(target, value) { - var properties = target.properties; - if (properties.length !== 1) { - value = ensureIdentifier(value); - } - for (var i = 0; i < properties.length; i++) { - var p = properties[i]; - if (p.kind === 204 || p.kind === 205) { - var propName = (p.name); - emitDestructuringAssignment(p.initializer || propName, createPropertyAccess(value, propName)); - } - } - } - function emitArrayLiteralAssignment(target, value) { - var elements = target.elements; - if (elements.length !== 1) { - value = ensureIdentifier(value); - } - for (var i = 0; i < elements.length; i++) { - var e = elements[i]; - if (e.kind !== 168) { - if (e.kind !== 167) { - emitDestructuringAssignment(e, createElementAccess(value, createNumericLiteral(i))); - } - else { - if (i === elements.length - 1) { - value = ensureIdentifier(value); - emitAssignment(e.expression, value); - write(".slice(" + i + ")"); - } - } - } - } - } - function emitDestructuringAssignment(target, value) { - if (target.kind === 163 && target.operator === 52) { - value = createDefaultValueCheck(value, target.right); - target = target.left; - } - if (target.kind === 148) { - emitObjectLiteralAssignment(target, value); - } - else if (target.kind === 147) { - emitArrayLiteralAssignment(target, value); - } - else { - emitAssignment(target, value); - } - } - function emitAssignmentExpression(root) { - var target = root.left; - var value = root.right; - if (root.parent.kind === 173) { - emitDestructuringAssignment(target, value); - } - else { - if (root.parent.kind !== 155) { - write("("); - } - value = ensureIdentifier(value); - emitDestructuringAssignment(target, value); - write(", "); - emit(value); - if (root.parent.kind !== 155) { - write(")"); - } - } - } - function emitBindingElement(target, value) { - if (target.initializer) { - value = value ? createDefaultValueCheck(value, target.initializer) : target.initializer; - } - else if (!value) { - value = createVoidZero(); - } - if (ts.isBindingPattern(target.name)) { - var pattern = target.name; - var elements = pattern.elements; - if (elements.length !== 1) { - value = ensureIdentifier(value); - } - for (var i = 0; i < elements.length; i++) { - var element = elements[i]; - if (pattern.kind === 144) { - var propName = element.propertyName || element.name; - emitBindingElement(element, createPropertyAccess(value, propName)); - } - else if (element.kind !== 168) { - if (!element.dotDotDotToken) { - emitBindingElement(element, createElementAccess(value, createNumericLiteral(i))); - } - else { - if (i === elements.length - 1) { - value = ensureIdentifier(value); - emitAssignment(element.name, value); - write(".slice(" + i + ")"); - } - } - } - } - } - else { - emitAssignment(target.name, value); - } - } - } function emitVariableDeclaration(node) { if (ts.isBindingPattern(node.name)) { if (languageVersion < 2) { - emitDestructuring(node); + ensureLocals(); + emitCommaList(ts.BindingElementRewriter.rewrite(node, locals)); } else { emit(node.name); @@ -18881,7 +22718,8 @@ var ts; function emitParameter(node) { if (languageVersion < 2) { if (ts.isBindingPattern(node.name)) { - var name = createTempVariable(node); + ensureLocals(); + var name = ts.Locals.createUniqueIdentifier(locals); if (!tempParameters) { tempParameters = []; } @@ -18907,7 +22745,7 @@ var ts; if (ts.isBindingPattern(p.name)) { writeLine(); write("var "); - emitDestructuring(p, tempParameters[tempIndex]); + emitCommaList(ts.BindingElementRewriter.rewrite(p, locals, tempParameters[tempIndex])); write(";"); tempIndex++; } @@ -18931,9 +22769,10 @@ var ts; } function emitRestParameter(node) { if (languageVersion < 2 && ts.hasRestParameters(node)) { + ensureLocals(); var restIndex = node.parameters.length - 1; var restParam = node.parameters[restIndex]; - var tempName = createTempVariable(node, true).text; + var tempName = ts.Locals.createUniqueIdentifier(locals, "_i").text; writeLine(); emitLeadingComments(restParam); emitStart(restParam); @@ -18968,28 +22807,30 @@ var ts; } } function emitAccessor(node) { - write(node.kind === 130 ? "get " : "set "); + write(node.kind === 132 ? "get " : "set "); emit(node.name); emitSignatureAndBody(node); } function shouldEmitAsArrowFunction(node) { - return node.kind === 157 && languageVersion >= 2; + return node.kind === 159 && languageVersion >= 2; } function emitFunctionDeclaration(node) { if (ts.nodeIsMissing(node.body)) { return emitPinnedOrTripleSlashComments(node); } - if (node.kind !== 128 && node.kind !== 127) { + if (node.kind !== 130 && node.kind !== 129) { emitLeadingComments(node); } if (!shouldEmitAsArrowFunction(node)) { - write("function "); + write("function"); + emit(node.asteriskToken); + write(" "); } - if (node.kind === 190 || (node.kind === 156 && node.name)) { + if (node.kind === 194 || (node.kind === 158 && node.name)) { emit(node.name); } emitSignatureAndBody(node); - if (node.kind !== 128 && node.kind !== 127) { + if (node.kind !== 130 && node.kind !== 129) { emitTrailingComments(node); } } @@ -19001,6 +22842,14 @@ var ts; emitEnd(node); } } + function emitCaptureArgumentsForNodeIfNecessary(node) { + if (resolver.getNodeCheckFlags(node) & 16) { + writeLine(); + emitStart(node); + write("var _arguments = arguments;"); + emitEnd(node); + } + } function emitSignatureParameters(node) { increaseIndent(); write("("); @@ -19020,12 +22869,18 @@ var ts; emitSignatureParameters(node); } function emitSignatureAndBody(node) { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; + var saveLocals = locals; + var saveLocalsScope = localsScope; var saveTempParameters = tempParameters; - tempCount = 0; - tempVariables = undefined; + localsScope = node.body; + locals = undefined; tempParameters = undefined; + if (!ts.isAnyAccessor(node)) { + if (node.flags & 16384) { + ensureLocals(); + node = ts.AsyncFunctionRewriter.rewrite(node, resolver.getPromiseConstructor(node), locals, compilerOptions); + } + } if (shouldEmitAsArrowFunction(node)) { emitSignatureParametersForArrow(node); write(" =>"); @@ -19045,16 +22900,17 @@ var ts; } else { increaseIndent(); - emitDetachedComments(node.body.kind === 170 ? node.body.statements : node.body); + emitDetachedComments(node.body.kind === 174 ? node.body.statements : node.body); var startIndex = 0; - if (node.body.kind === 170) { + if (node.body.kind === 174) { startIndex = emitDirectivePrologues(node.body.statements, true); } var outPos = writer.getTextPos(); emitCaptureThisForNodeIfNecessary(node); + emitCaptureArgumentsForNodeIfNecessary(node); emitDefaultValueAssignments(node); emitRestParameter(node); - if (node.body.kind !== 170 && outPos === writer.getTextPos()) { + if (node.body.kind !== 174 && outPos === writer.getTextPos()) { decreaseIndent(); write(" "); emitStart(node.body); @@ -19069,7 +22925,7 @@ var ts; emitEnd(node.body); } else { - if (node.body.kind === 170) { + if (node.body.kind === 174) { emitLinesStartingAt(node.body.statements, startIndex); } else { @@ -19082,7 +22938,7 @@ var ts; } emitTempDeclarations(true); writeLine(); - if (node.body.kind === 170) { + if (node.body.kind === 174) { emitLeadingCommentsOfPosition(node.body.statements.end); decreaseIndent(); emitToken(15, node.body.statements.end); @@ -19106,16 +22962,16 @@ var ts; emitEnd(node); write(";"); } - tempCount = saveTempCount; - tempVariables = saveTempVariables; tempParameters = saveTempParameters; + locals = saveLocals; + localsScope = saveLocalsScope; } function findInitialSuperCall(ctor) { if (ctor.body) { var statement = ctor.body.statements[0]; - if (statement && statement.kind === 173) { + if (statement && statement.kind === 177) { var expr = statement.expression; - if (expr && expr.kind === 151) { + if (expr && expr.kind === 153) { var func = expr.expression; if (func && func.kind === 90) { return statement; @@ -19146,7 +23002,7 @@ var ts; emitNode(memberName); write("]"); } - else if (memberName.kind === 122) { + else if (memberName.kind === 124) { emitComputedPropertyName(memberName); } else { @@ -19156,7 +23012,7 @@ var ts; } function emitMemberAssignments(node, staticFlag) { ts.forEach(node.members, function (member) { - if (member.kind === 126 && (member.flags & 128) === staticFlag && member.initializer) { + if (member.kind === 128 && (member.flags & 128) === staticFlag && member.initializer) { writeLine(); emitLeadingComments(member); emitStart(member); @@ -19179,7 +23035,7 @@ var ts; } function emitMemberFunctions(node) { ts.forEach(node.members, function (member) { - if (member.kind === 128 || node.kind === 127) { + if (member.kind === 130 || node.kind === 129) { if (!member.body) { return emitPinnedOrTripleSlashComments(member); } @@ -19201,7 +23057,7 @@ var ts; write(";"); emitTrailingComments(member); } - else if (member.kind === 130 || member.kind === 131) { + else if (member.kind === 132 || member.kind === 133) { var accessors = getAllAccessorDeclarations(node, member); if (member === accessors.firstAccessor) { writeLine(); @@ -19302,14 +23158,14 @@ var ts; write(";"); } function emitConstructorOfClass() { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; + var saveLocals = locals; + var saveLocalsScope = localsScope; var saveTempParameters = tempParameters; - tempCount = 0; - tempVariables = undefined; + locals = undefined; + localsScope = node; tempParameters = undefined; ts.forEach(node.members, function (member) { - if (member.kind === 129 && !member.body) { + if (member.kind === 131 && !member.body) { emitPinnedOrTripleSlashComments(member); } }); @@ -19329,6 +23185,7 @@ var ts; } emitCaptureThisForNodeIfNecessary(node); if (ctor) { + localsScope = ctor.body; emitDefaultValueAssignments(ctor); emitRestParameter(ctor); if (baseTypeNode) { @@ -19339,6 +23196,7 @@ var ts; } } emitParameterPropertyAssignments(ctor); + localsScope = node; } else { if (baseTypeNode) { @@ -19367,9 +23225,9 @@ var ts; if (ctor) { emitTrailingComments(ctor); } - tempCount = saveTempCount; - tempVariables = saveTempVariables; tempParameters = saveTempParameters; + locals = saveLocals; + localsScope = saveLocalsScope; } } function emitInterfaceDeclaration(node) { @@ -19452,7 +23310,7 @@ var ts; } } function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { - if (moduleDeclaration.body.kind === 195) { + if (moduleDeclaration.body.kind === 199) { var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body); return recursiveInnerModule || moduleDeclaration.body; } @@ -19477,20 +23335,21 @@ var ts; write(resolver.getLocalNameOfContainer(node)); emitEnd(node.name); write(") "); - if (node.body.kind === 196) { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - tempCount = 0; - tempVariables = undefined; + if (node.body.kind === 200) { + var saveLocals = locals; + var saveLocalsScope = localsScope; + locals = undefined; + localsScope = node.body; emit(node.body); - tempCount = saveTempCount; - tempVariables = saveTempVariables; + locals = saveLocals; + localsScope = saveLocalsScope; } else { write("{"); increaseIndent(); scopeEmitStart(node); emitCaptureThisForNodeIfNecessary(node); + emitCaptureArgumentsForNodeIfNecessary(node); writeLine(); emit(node.body); decreaseIndent(); @@ -19516,7 +23375,7 @@ var ts; emitImportDeclaration = !ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportWithEntityName(node); } if (emitImportDeclaration) { - if (ts.isExternalModuleImportDeclaration(node) && node.parent.kind === 207 && compilerOptions.module === 2) { + if (ts.isExternalModuleImportDeclaration(node) && node.parent.kind === 211 && compilerOptions.module === 2) { if (node.flags & 1) { writeLine(); emitLeadingComments(node); @@ -19565,7 +23424,7 @@ var ts; } function getFirstExportAssignment(sourceFile) { return ts.forEach(sourceFile.statements, function (node) { - if (node.kind === 198) { + if (node.kind === 202) { return node; } }); @@ -19666,25 +23525,265 @@ var ts; } function emitSourceFile(node) { currentSourceFile = node; + globals = undefined; + localsScope = node; + locals = undefined; writeLine(); emitDetachedComments(node); var startIndex = emitDirectivePrologues(node.statements, false); - if (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8) { - writeLine(); - write("var __extends = this.__extends || function (d, b) {"); - increaseIndent(); - writeLine(); - write("for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];"); - writeLine(); - write("function __() { this.constructor = d; }"); - writeLine(); - write("__.prototype = b.prototype;"); - writeLine(); - write("d.prototype = new __();"); - decreaseIndent(); - writeLine(); - write("};"); - extendsEmitted = true; + if (!compilerOptions.noHelpers) { + if (!extendsEmitted && resolver.getNodeCheckFlags(node) & 32) { + writeLine(); + write("var __extends = this.__extends || function (d, b) {"); + increaseIndent(); + writeLine(); + write("for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];"); + writeLine(); + write("function __() { this.constructor = d; }"); + writeLine(); + write("__.prototype = b.prototype;"); + writeLine(); + write("d.prototype = new __();"); + decreaseIndent(); + writeLine(); + write("};"); + extendsEmitted = true; + } + if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & 2048) { + writeLine(); + write("var __awaiter = this.__awaiter || function (gen) {"); + increaseIndent(); + writeLine(); + write("function step(result) {"); + increaseIndent(); + writeLine(); + write("while (true) {"); + increaseIndent(); + writeLine(); + write("var done = result.done, value = result.value, then;"); + writeLine(); + write("if (done) return value;"); + writeLine(); + write("if (value && typeof (then = value.then) === \"function\")"); + increaseIndent(); + writeLine(); + write("return then.call(value,"); + increaseIndent(); + writeLine(); + write("function(value) { return step(gen.next(value)) },"); + writeLine(); + write("function(reason) { return step(gen[\"throw\"](reason)) });"); + decreaseIndent(); + decreaseIndent(); + writeLine(); + write("result = gen.next(value);"); + decreaseIndent(); + writeLine(); + write("}"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("return step(gen.next());"); + decreaseIndent(); + writeLine(); + write("};"); + awaiterEmitted = true; + } + if (!generatorEmitted && resolver.getNodeCheckFlags(node) & 4096) { + writeLine(); + write("var __generator = this.__generator || function (body) {"); + increaseIndent(); + writeLine(); + write("var done, finallyStack, executing, state;"); + writeLine(); + write("function step(opcode, arg) {"); + increaseIndent(); + writeLine(); + write("var trys, region, tryLabel, catchLabel, finallyLabel, endLabel;"); + writeLine(); + write("if (executing) throw new TypeError(\"Generator is already executing.\");"); + writeLine(); + write("state = state || { label: 0 };"); + writeLine(); + write("while (true) {"); + increaseIndent(); + writeLine(); + write("executing = false;"); + writeLine(); + write("if (!done) {"); + increaseIndent(); + writeLine(); + write("trys = state.trys;"); + writeLine(); + write("region = trys && trys[trys.length - 1];"); + writeLine(); + write("if (region) {"); + increaseIndent(); + writeLine(); + write("tryLabel = region[0];"); + writeLine(); + write("catchLabel = region[1];"); + writeLine(); + write("finallyLabel = region[2];"); + writeLine(); + write("endLabel = region[3];"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("else if (opcode === 1 || opcode === 2) {"); + increaseIndent(); + writeLine(); + write("done = true;"); + decreaseIndent(); + writeLine(); + write("}"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("if (done) {"); + increaseIndent(); + writeLine(); + write("finallyStack = void 0;"); + writeLine(); + write("switch (opcode) {"); + increaseIndent(); + writeLine(); + write("case 0 /*next*/: return { value: void 0, done: true };"); + writeLine(); + write("case 1 /*throw*/: throw arg;"); + writeLine(); + write("case 2 /*return*/: return { value: arg, done: true };"); + decreaseIndent(); + writeLine(); + write("}"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("switch (opcode) {"); + increaseIndent(); + writeLine(); + write("case 0 /*next*/:"); + increaseIndent(); + writeLine(); + write("state.sent = arg;"); + writeLine(); + write("break;"); + decreaseIndent(); + writeLine(); + write("case 4 /*yield*/:"); + increaseIndent(); + writeLine(); + write("state.label++;"); + writeLine(); + write("return { value: arg, done: false };"); + decreaseIndent(); + writeLine(); + write("case 5 /*endfinally*/:"); + increaseIndent(); + writeLine(); + write("arg = finallyStack.pop(), opcode = finallyStack.pop();"); + writeLine(); + write("trys.pop();"); + writeLine(); + write("continue;"); + decreaseIndent(); + writeLine(); + write("default:"); + increaseIndent(); + writeLine(); + write("if (opcode === 3 /*break*/ && (!region || (arg > tryLabel && arg < endLabel))) {"); + increaseIndent(); + writeLine(); + write("state.label = arg;"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("else if (opcode === 1 /*throw*/ && state.label < catchLabel) {"); + increaseIndent(); + writeLine(); + write("state.error = arg;"); + writeLine(); + write("state.label = catchLabel;"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("else if (state.label < finallyLabel) {"); + increaseIndent(); + writeLine(); + write("finallyStack = finallyStack || [];"); + writeLine(); + write("finallyStack.push(opcode, arg);"); + writeLine(); + write("state.label = finallyLabel;"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("else {"); + increaseIndent(); + writeLine(); + write("if (finallyLabel) finallyStack.pop(), finallyStack.pop();"); + writeLine(); + write("trys.pop();"); + writeLine(); + write("continue;"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("break;"); + decreaseIndent(); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("executing = true;"); + writeLine(); + write("try {"); + increaseIndent(); + writeLine(); + write("var operation = body(state);"); + writeLine(); + write("opcode = operation[0], arg = operation[1];"); + decreaseIndent(); + writeLine(); + write("} catch (e) {"); + increaseIndent(); + writeLine(); + write("opcode = 1 /*throw*/, arg = e;"); + writeLine(); + decreaseIndent(); + write("}"); + decreaseIndent(); + writeLine(); + write("}"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + write("return {"); + increaseIndent(); + writeLine(); + write("next: function (v) { return step(0 /*next*/, v); },"); + writeLine(); + write("\"throw\": function (v) { return step(1 /*throw*/, v); },"); + writeLine(); + write("\"return\": function (v) { return step(2 /*return*/, v); },"); + decreaseIndent(); + writeLine(); + write("};"); + decreaseIndent(); + writeLine(); + write("};"); + writeLine(); + generatorEmitted = true; + } } if (ts.isExternalModule(node)) { if (compilerOptions.module === 2) { @@ -19719,15 +23818,15 @@ var ts; } function shouldEmitLeadingAndTrailingComments(node) { switch (node.kind) { - case 192: - case 190: + case 196: + case 194: + case 201: case 197: - case 193: - case 198: + case 202: return false; - case 195: + case 199: return shouldEmitModuleDeclaration(node); - case 194: + case 198: return shouldEmitEnumDeclaration(node); } return true; @@ -19736,13 +23835,13 @@ var ts; switch (node.kind) { case 64: return emitIdentifier(node); - case 124: + case 126: return emitParameter(node); - case 128: - case 127: - return emitMethod(node); case 130: - case 131: + case 129: + return emitMethod(node); + case 132: + case 133: return emitAccessor(node); case 92: return emitThis(node); @@ -19754,6 +23853,8 @@ var ts; return write("true"); case 79: return write("false"); + case 35: + return write("*"); case 7: case 8: case 9: @@ -19762,120 +23863,126 @@ var ts; case 12: case 13: return emitLiteral(node); - case 165: + case 168: return emitTemplateExpression(node); - case 169: + case 173: return emitTemplateSpan(node); - case 121: + case 123: return emitQualifiedName(node); - case 144: + case 146: return emitObjectBindingPattern(node); - case 145: + case 147: return emitArrayBindingPattern(node); - case 146: + case 148: return emitBindingElement(node); - case 147: + case 149: return emitArrayLiteral(node); - case 148: + case 150: return emitObjectLiteral(node); - case 204: + case 208: return emitPropertyAssignment(node); - case 205: + case 209: return emitShorthandPropertyAssignment(node); - case 122: + case 124: return emitComputedPropertyName(node); - case 149: - return emitPropertyAccess(node); - case 150: - return emitIndexedAccess(node); case 151: - return emitCallExpression(node); + return emitPropertyAccess(node); case 152: - return emitNewExpression(node); + return emitIndexedAccess(node); case 153: - return emitTaggedTemplateExpression(node); + return emitCallExpression(node); case 154: - return emit(node.expression); + return emitNewExpression(node); case 155: - return emitParenExpression(node); - case 190: + return emitTaggedTemplateExpression(node); case 156: + return emit(node.expression); case 157: - return emitFunctionDeclaration(node); + return emitParenExpression(node); + case 194: case 158: - return emitDeleteExpression(node); case 159: - return emitTypeOfExpression(node); + return emitFunctionDeclaration(node); case 160: - return emitVoidExpression(node); + return emitDeleteExpression(node); case 161: - return emitPrefixUnaryExpression(node); + return emitTypeOfExpression(node); case 162: - return emitPostfixUnaryExpression(node); + return emitVoidExpression(node); case 163: - return emitBinaryExpression(node); + return emitAwaitExpression(node); + case 169: + return emitYieldExpression(node); case 164: - return emitConditionalExpression(node); + return emitPrefixUnaryExpression(node); + case 165: + return emitPostfixUnaryExpression(node); + case 166: + return emitBinaryExpression(node); case 167: + return emitConditionalExpression(node); + case 170: + return emitGeneratedLabel(node); + case 171: return emitSpreadElementExpression(node); - case 168: + case 172: return; - case 170: - case 196: + case 174: + case 200: return emitBlock(node); - case 171: + case 175: return emitVariableStatement(node); - case 172: + case 176: return write(";"); - case 173: + case 177: return emitExpressionStatement(node); - case 174: + case 178: return emitIfStatement(node); - case 175: + case 179: return emitDoStatement(node); - case 176: + case 180: return emitWhileStatement(node); - case 177: + case 181: return emitForStatement(node); - case 178: + case 182: return emitForInStatement(node); - case 179: - case 180: + case 183: + case 184: return emitBreakOrContinueStatement(node); - case 181: + case 185: return emitReturnStatement(node); - case 182: + case 186: return emitWithStatement(node); - case 183: + case 187: return emitSwitchStatement(node); - case 200: - case 201: + case 204: + case 205: return emitCaseOrDefaultClause(node); - case 184: + case 188: return emitLabelledStatement(node); - case 185: + case 189: return emitThrowStatement(node); - case 186: + case 190: return emitTryStatement(node); - case 203: + case 207: return emitCatchClause(node); - case 187: + case 191: return emitDebuggerStatement(node); - case 188: + case 192: return emitVariableDeclaration(node); - case 191: + case 195: return emitClassDeclaration(node); - case 192: + case 196: return emitInterfaceDeclaration(node); - case 194: + case 198: return emitEnumDeclaration(node); - case 206: + case 210: return emitEnumMember(node); - case 195: + case 199: return emitModuleDeclaration(node); - case 197: + case 201: return emitImportDeclaration(node); - case 207: + case 211: return emitSourceFile(node); } } @@ -19894,7 +24001,7 @@ var ts; } function getLeadingCommentsToEmit(node) { if (node.parent) { - if (node.parent.kind === 207 || node.pos !== node.parent.pos) { + if (node.pos >= 0 && (node.parent.kind === 211 || node.pos !== node.parent.pos)) { var leadingComments; if (hasDetachedComments(node.pos)) { leadingComments = getLeadingCommentsWithoutDetachedComments(); @@ -19913,13 +24020,16 @@ var ts; } function emitTrailingDeclarationComments(node) { if (node.parent) { - if (node.parent.kind === 207 || node.end !== node.parent.end) { + if (node.pos >= 0 && (node.parent.kind === 211 || node.end !== node.parent.end)) { var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); } } } function emitLeadingCommentsOfLocalPosition(pos) { + if (pos < 0) { + return; + } var leadingComments; if (hasDetachedComments(pos)) { leadingComments = getLeadingCommentsWithoutDetachedComments(); @@ -19931,6 +24041,9 @@ var ts; emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); } function emitDetachedCommentsAtPosition(node) { + if (node.pos === node.end) { + return; + } var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos); if (leadingComments) { var detachedComments = []; @@ -20308,7 +24421,7 @@ var ts; } } } - else if (node.kind === 195 && node.name.kind === 8 && (node.flags & 2 || ts.isDeclarationFile(file))) { + else if (node.kind === 199 && node.name.kind === 8 && (node.flags & 2 || ts.isDeclarationFile(file))) { ts.forEachChild(node.body, function (node) { if (ts.isExternalModuleImportDeclaration(node) && ts.getExternalModuleImportDeclarationExpression(node).kind === 8) { var nameLiteral = ts.getExternalModuleImportDeclarationExpression(node); @@ -20472,6 +24585,12 @@ var ts; name: "noResolve", type: "boolean" }, + { + name: "noHelpers", + type: "boolean", + description: ts.Diagnostics.Do_not_emit_runtime_helper_functions_e_g_extends_awaiter_Assumes_manual_reference_to_tslib_js, + experimental: true + }, { name: "out", type: "string", @@ -20534,6 +24653,12 @@ var ts; paramType: ts.Diagnostics.VERSION, error: ts.Diagnostics.Argument_for_target_option_must_be_es3_es5_or_es6 }, + { + name: "asyncFunctions", + type: "boolean", + experimental: true, + description: ts.Diagnostics.Emit_async_functions_when_ECMAScript_target_version_is_lower_than_ES6 + }, { name: "version", shortName: "v", @@ -20746,10 +24871,10 @@ var ts; } function autoCollapse(node) { switch (node.kind) { + case 200: + case 195: case 196: - case 191: - case 192: - case 194: + case 198: return false; } return true; @@ -20761,16 +24886,16 @@ var ts; return; } switch (n.kind) { - case 170: + case 174: if (!ts.isFunctionBlock(n)) { var parent = n.parent; var openBrace = ts.findChildOfKind(n, 14, sourceFile); var closeBrace = ts.findChildOfKind(n, 15, sourceFile); - if (parent.kind === 175 || parent.kind === 178 || parent.kind === 177 || parent.kind === 174 || parent.kind === 176 || parent.kind === 182 || parent.kind === 203) { + if (parent.kind === 179 || parent.kind === 182 || parent.kind === 181 || parent.kind === 178 || parent.kind === 180 || parent.kind === 186 || parent.kind === 207) { addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); break; } - if (parent.kind === 186) { + if (parent.kind === 190) { var tryStatement = parent; if (tryStatement.tryBlock === n) { addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); @@ -20793,21 +24918,21 @@ var ts; }); break; } - case 196: + case 200: var openBrace = ts.findChildOfKind(n, 14, sourceFile); var closeBrace = ts.findChildOfKind(n, 15, sourceFile); addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n)); break; - case 191: - case 192: - case 194: - case 148: - case 183: + case 195: + case 196: + case 198: + case 150: + case 187: var openBrace = ts.findChildOfKind(n, 14, sourceFile); var closeBrace = ts.findChildOfKind(n, 15, sourceFile); addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n)); break; - case 147: + case 149: var openBracket = ts.findChildOfKind(n, 18, sourceFile); var closeBracket = ts.findChildOfKind(n, 19, sourceFile); addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n)); @@ -20835,14 +24960,14 @@ var ts; var current = node.parent; while (current) { switch (current.kind) { - case 195: + case 199: do { current = current.parent; - } while (current.kind === 195); - case 191: + } while (current.kind === 199); + case 195: + case 198: + case 196: case 194: - case 192: - case 190: indent++; } current = current.parent; @@ -20853,24 +24978,24 @@ var ts; var childNodes = []; function visit(node) { switch (node.kind) { - case 171: + case 175: ts.forEach(node.declarationList.declarations, visit); break; - case 144: - case 145: + case 146: + case 147: ts.forEach(node.elements, visit); break; - case 146: - case 188: + case 148: + case 192: if (ts.isBindingPattern(node.name)) { visit(node.name); break; } - case 191: - case 194: - case 192: case 195: - case 190: + case 198: + case 196: + case 199: + case 194: childNodes.push(node); } } @@ -20904,17 +25029,17 @@ var ts; for (var i = 0, n = nodes.length; i < n; i++) { var node = nodes[i]; switch (node.kind) { - case 191: - case 194: - case 192: + case 195: + case 198: + case 196: topLevelNodes.push(node); break; - case 195: + case 199: var moduleDeclaration = node; topLevelNodes.push(node); addTopLevelNodes(getInnermostModule(moduleDeclaration).body.statements, topLevelNodes); break; - case 190: + case 194: var functionDeclaration = node; if (isTopLevelFunctionDeclaration(functionDeclaration)) { topLevelNodes.push(node); @@ -20925,9 +25050,9 @@ var ts; } } function isTopLevelFunctionDeclaration(functionDeclaration) { - if (functionDeclaration.kind === 190) { - if (functionDeclaration.body && functionDeclaration.body.kind === 170) { - if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 190 && !isEmpty(s.name.text); })) { + if (functionDeclaration.kind === 194) { + if (functionDeclaration.body && functionDeclaration.body.kind === 174) { + if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 194 && !isEmpty(s.name.text); })) { return true; } if (!ts.isFunctionBlock(functionDeclaration.parent)) { @@ -20980,42 +25105,42 @@ var ts; } function createChildItem(node) { switch (node.kind) { - case 124: + case 126: if (ts.isBindingPattern(node.name)) { break; } - if ((node.flags & 243) === 0) { + if ((node.flags & 16627) === 0) { return undefined; } return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); - case 128: - case 127: - return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberFunctionElement); case 130: + case 129: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberFunctionElement); + case 132: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberGetAccessorElement); - case 131: + case 133: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); - case 134: + case 136: return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); - case 206: + case 210: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); - case 132: + case 134: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); - case 133: + case 135: return createItem(node, "new()", ts.ScriptElementKind.constructSignatureElement); - case 126: - case 125: + case 128: + case 127: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); - case 190: + case 194: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.functionElement); - case 188: - case 146: + case 192: + case 148: var variableDeclarationNode; var name; - if (node.kind === 146) { + if (node.kind === 148) { name = node.name; variableDeclarationNode = node; - while (variableDeclarationNode && variableDeclarationNode.kind !== 188) { + while (variableDeclarationNode && variableDeclarationNode.kind !== 192) { variableDeclarationNode = variableDeclarationNode.parent; } ts.Debug.assert(variableDeclarationNode !== undefined); @@ -21034,7 +25159,7 @@ var ts; else { return createItem(node, getTextOfNode(name), ts.ScriptElementKind.variableElement); } - case 129: + case 131: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); } return undefined; @@ -21064,17 +25189,17 @@ var ts; } function createTopLevelItem(node) { switch (node.kind) { - case 207: + case 211: return createSourceFileItem(node); - case 191: + case 195: return createClassItem(node); - case 194: + case 198: return createEnumItem(node); - case 192: + case 196: return createIterfaceItem(node); - case 195: + case 199: return createModuleItem(node); - case 190: + case 194: return createFunctionItem(node); } return undefined; @@ -21084,7 +25209,7 @@ var ts; } var result = []; result.push(moduleDeclaration.name.text); - while (moduleDeclaration.body && moduleDeclaration.body.kind === 195) { + while (moduleDeclaration.body && moduleDeclaration.body.kind === 199) { moduleDeclaration = moduleDeclaration.body; result.push(moduleDeclaration.name.text); } @@ -21096,7 +25221,7 @@ var ts; return getNavigationBarItem(moduleName, ts.ScriptElementKind.moduleElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); } function createFunctionItem(node) { - if (node.name && node.body && node.body.kind === 170) { + if (node.name && node.body && node.body.kind === 174) { var childItems = getItemsWorker(sortNodes(node.body.statements), createChildItem); return getNavigationBarItem(node.name.text, ts.ScriptElementKind.functionElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node)); } @@ -21115,7 +25240,7 @@ var ts; var childItems; if (node.members) { var constructor = ts.forEach(node.members, function (member) { - return member.kind === 129 && member; + return member.kind === 131 && member; }); var nodes = removeComputedProperties(node); if (constructor) { @@ -21135,16 +25260,16 @@ var ts; } } function removeComputedProperties(node) { - return ts.filter(node.members, function (member) { return member.name === undefined || member.name.kind !== 122; }); + return ts.filter(node.members, function (member) { return member.name === undefined || member.name.kind !== 124; }); } function getInnermostModule(node) { - while (node.body.kind === 195) { + while (node.body.kind === 199) { node = node.body; } return node; } function getNodeSpan(node) { - return node.kind === 207 ? ts.createTextSpanFromBounds(node.getFullStart(), node.getEnd()) : ts.createTextSpanFromBounds(node.getStart(), node.getEnd()); + return node.kind === 211 ? ts.createTextSpanFromBounds(node.getFullStart(), node.getEnd()) : ts.createTextSpanFromBounds(node.getStart(), node.getEnd()); } function getTextOfNode(node) { return ts.getTextOfNodeFromSourceText(sourceFile.text, node); @@ -21183,7 +25308,7 @@ var ts; } return createSignatureHelpItems(candidates, resolvedSignature, argumentInfo); function getImmediatelyContainingArgumentInfo(node) { - if (node.parent.kind === 151 || node.parent.kind === 152) { + if (node.parent.kind === 153 || node.parent.kind === 154) { var callExpression = node.parent; if (node.kind === 24 || node.kind === 16) { var list = getChildListThatStartsWithOpenerToken(callExpression, node, sourceFile); @@ -21211,24 +25336,24 @@ var ts; }; } } - else if (node.kind === 10 && node.parent.kind === 153) { + else if (node.kind === 10 && node.parent.kind === 155) { if (ts.isInsideTemplateLiteral(node, position)) { return getArgumentListInfoForTemplate(node.parent, 0); } } - else if (node.kind === 11 && node.parent.parent.kind === 153) { + else if (node.kind === 11 && node.parent.parent.kind === 155) { var templateExpression = node.parent; var tagExpression = templateExpression.parent; - ts.Debug.assert(templateExpression.kind === 165); + ts.Debug.assert(templateExpression.kind === 168); var argumentIndex = ts.isInsideTemplateLiteral(node, position) ? 0 : 1; return getArgumentListInfoForTemplate(tagExpression, argumentIndex); } - else if (node.parent.kind === 169 && node.parent.parent.parent.kind === 153) { + else if (node.parent.kind === 173 && node.parent.parent.parent.kind === 155) { var templateSpan = node.parent; var templateExpression = templateSpan.parent; var tagExpression = templateExpression.parent; - ts.Debug.assert(templateExpression.kind === 165); - if (node.kind === 13 && position >= node.getEnd() && !node.isUnterminated) { + ts.Debug.assert(templateExpression.kind === 168); + if (node.kind === 13 && !ts.isInsideTemplateLiteral(node, position)) { return undefined; } var spanIndex = templateExpression.templateSpans.indexOf(templateSpan); @@ -21269,7 +25394,7 @@ var ts; var template = taggedTemplate.template; var applicableSpanStart = template.getStart(); var applicableSpanEnd = template.getEnd(); - if (template.kind === 165) { + if (template.kind === 168) { var lastSpan = ts.lastOrUndefined(template.templateSpans); if (lastSpan.literal.getFullWidth() === 0) { applicableSpanEnd = ts.skipTrivia(sourceFile.text, applicableSpanEnd, false); @@ -21278,7 +25403,7 @@ var ts; return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart); } function getContainingArgumentInfo(node) { - for (var n = node; n.kind !== 207; n = n.parent) { + for (var n = node; n.kind !== 211; n = n.parent) { if (ts.isFunctionBlock(n)) { return undefined; } @@ -21463,7 +25588,7 @@ var ts; ts.findChildOfKind = findChildOfKind; function findContainingList(node) { var syntaxList = ts.forEach(node.parent.getChildren(), function (c) { - if (c.kind === 208 && c.pos <= node.pos && c.end >= node.end) { + if (c.kind === 212 && c.pos <= node.pos && c.end >= node.end) { return c; } }); @@ -21567,7 +25692,7 @@ var ts; } } } - ts.Debug.assert(startNode !== undefined || n.kind === 207); + ts.Debug.assert(startNode !== undefined || n.kind === 211); if (children.length) { var candidate = findRightmostChildNodeWithTokens(children, children.length); return candidate && findRightmostToken(candidate); @@ -21604,17 +25729,17 @@ var ts; } ts.getNodeModifiers = getNodeModifiers; function getTypeArgumentOrTypeParameterList(node) { - if (node.kind === 135 || node.kind === 151) { + if (node.kind === 137 || node.kind === 153) { return node.typeArguments; } - if (ts.isAnyFunction(node) || node.kind === 191 || node.kind === 192) { + if (ts.isAnyFunction(node) || node.kind === 195 || node.kind === 196) { return node.typeParameters; } return undefined; } ts.getTypeArgumentOrTypeParameterList = getTypeArgumentOrTypeParameterList; function isToken(n) { - return n.kind >= 0 && n.kind <= 120; + return n.kind >= 0 && n.kind <= 122; } ts.isToken = isToken; function isWord(kind) { @@ -21655,7 +25780,7 @@ var ts; var ts; (function (ts) { function isFirstDeclarationOfSymbolParameter(symbol) { - return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === 124; + return symbol.declarations && symbol.declarations.length > 0 && symbol.declarations[0].kind === 126; } ts.isFirstDeclarationOfSymbolParameter = isFirstDeclarationOfSymbolParameter; var displayPartWriter = getDisplayPartWriter(); @@ -21887,7 +26012,7 @@ var ts; savedPos = scanner.getStartPos(); } function shouldRescanGreaterThanToken(container) { - if (container.kind !== 163) { + if (container.kind !== 166) { return false; } switch (container.operator) { @@ -22385,24 +26510,24 @@ var ts; throw new Error("Unknown rule"); }; Rules.IsForContext = function (context) { - return context.contextNode.kind === 177; + return context.contextNode.kind === 181; }; Rules.IsNotForContext = function (context) { return !Rules.IsForContext(context); }; Rules.IsBinaryOpContext = function (context) { switch (context.contextNode.kind) { - case 163: - case 164: + case 166: + case 167: return true; - case 197: - case 188: - case 124: - case 206: + case 201: + case 192: case 126: - case 125: + case 210: + case 128: + case 127: return context.currentTokenSpan.kind === 52 || context.nextTokenSpan.kind === 52; - case 178: + case 182: return context.currentTokenSpan.kind === 85 || context.nextTokenSpan.kind === 85; } return false; @@ -22433,26 +26558,26 @@ var ts; return true; } switch (node.kind) { - case 170: - case 183: - case 148: - case 196: + case 174: + case 187: + case 150: + case 200: return true; } return false; }; Rules.IsFunctionDeclContext = function (context) { switch (context.contextNode.kind) { - case 190: - case 128: - case 127: + case 194: case 130: - case 131: - case 132: - case 156: case 129: - case 157: - case 192: + case 132: + case 133: + case 134: + case 158: + case 131: + case 159: + case 196: return true; } return false; @@ -22462,52 +26587,52 @@ var ts; }; Rules.NodeIsTypeScriptDeclWithBlockContext = function (node) { switch (node.kind) { - case 191: - case 192: - case 194: - case 139: case 195: + case 196: + case 198: + case 141: + case 199: return true; } return false; }; Rules.IsAfterCodeBlockContext = function (context) { switch (context.currentTokenParent.kind) { - case 191: case 195: - case 194: - case 170: - case 203: - case 196: - case 183: + case 199: + case 198: + case 174: + case 207: + case 200: + case 187: return true; } return false; }; Rules.IsControlDeclContext = function (context) { switch (context.contextNode.kind) { - case 174: - case 183: - case 177: case 178: - case 176: - case 186: - case 175: + case 187: + case 181: case 182: - case 203: + case 180: + case 190: + case 179: + case 186: + case 207: return true; default: return false; } }; Rules.IsObjectContext = function (context) { - return context.contextNode.kind === 148; + return context.contextNode.kind === 150; }; Rules.IsFunctionCallContext = function (context) { - return context.contextNode.kind === 151; + return context.contextNode.kind === 153; }; Rules.IsNewContext = function (context) { - return context.contextNode.kind === 152; + return context.contextNode.kind === 154; }; Rules.IsFunctionCallOrNewContext = function (context) { return Rules.IsFunctionCallContext(context) || Rules.IsNewContext(context); @@ -22522,28 +26647,28 @@ var ts; return context.formattingRequestKind != 2; }; Rules.IsModuleDeclContext = function (context) { - return context.contextNode.kind === 195; + return context.contextNode.kind === 199; }; Rules.IsObjectTypeContext = function (context) { - return context.contextNode.kind === 139; + return context.contextNode.kind === 141; }; Rules.IsTypeArgumentOrParameter = function (token, parent) { if (token.kind !== 24 && token.kind !== 25) { return false; } switch (parent.kind) { + case 137: + case 195: + case 196: + case 194: + case 158: + case 159: + case 130: + case 129: + case 134: case 135: - case 191: - case 192: - case 190: - case 156: - case 157: - case 128: - case 127: - case 132: - case 133: - case 151: - case 152: + case 153: + case 154: return true; default: return false; @@ -22553,7 +26678,7 @@ var ts; return Rules.IsTypeArgumentOrParameter(context.currentTokenSpan, context.currentTokenParent) || Rules.IsTypeArgumentOrParameter(context.nextTokenSpan, context.nextTokenParent); }; Rules.IsVoidOpContext = function (context) { - return context.currentTokenSpan.kind === 98 && context.currentTokenParent.kind === 160; + return context.currentTokenSpan.kind === 98 && context.currentTokenParent.kind === 162; }; return Rules; })(); @@ -22575,7 +26700,7 @@ var ts; return result; }; RulesMap.prototype.Initialize = function (rules) { - this.mapRowLength = 120 + 1; + this.mapRowLength = 122 + 1; this.map = new Array(this.mapRowLength * this.mapRowLength); var rulesBucketConstructionStateList = new Array(this.map.length); this.FillRules(rules, rulesBucketConstructionStateList); @@ -22743,7 +26868,7 @@ var ts; } TokenAllAccess.prototype.GetTokens = function () { var result = []; - for (var token = 0; token <= 120; token++) { + for (var token = 0; token <= 122; token++) { result.push(token); } return result; @@ -22785,7 +26910,7 @@ var ts; }; TokenRange.Any = TokenRange.AllTokens(); TokenRange.AnyIncludingMultilineComments = TokenRange.FromTokens(TokenRange.Any.GetTokens().concat([3])); - TokenRange.Keywords = TokenRange.FromRange(65, 120); + TokenRange.Keywords = TokenRange.FromRange(65, 122); TokenRange.BinaryOperators = TokenRange.FromRange(24, 63); TokenRange.BinaryKeywordOperators = TokenRange.FromTokens([85, 86]); TokenRange.UnaryPrefixOperators = TokenRange.FromTokens([38, 39, 47, 46]); @@ -22955,17 +27080,17 @@ var ts; } function isListElement(parent, node) { switch (parent.kind) { - case 191: - case 192: - return ts.rangeContainsRange(parent.members, node); case 195: - var body = parent.body; - return body && body.kind === 170 && ts.rangeContainsRange(body.statements, node); - case 207: - case 170: case 196: + return ts.rangeContainsRange(parent.members, node); + case 199: + var body = parent.body; + return body && body.kind === 174 && ts.rangeContainsRange(body.statements, node); + case 211: + case 174: + case 200: return ts.rangeContainsRange(parent.statements, node); - case 203: + case 207: return ts.rangeContainsRange(parent.block.statements, node); } return false; @@ -23081,7 +27206,7 @@ var ts; var indentation = inheritedIndentation; if (indentation === -1) { if (isSomeBlock(node.kind)) { - if (isSomeBlock(parent.kind) || parent.kind === 207 || parent.kind === 200 || parent.kind === 201) { + if (isSomeBlock(parent.kind) || parent.kind === 211 || parent.kind === 204 || parent.kind === 205) { indentation = parentDynamicIndentation.getIndentation() + parentDynamicIndentation.getDelta(); } else { @@ -23481,20 +27606,20 @@ var ts; } function isSomeBlock(kind) { switch (kind) { - case 170: - case 196: + case 174: + case 200: return true; } return false; } function getOpenTokenForList(node, list) { switch (node.kind) { + case 131: + case 194: + case 158: + case 130: case 129: - case 190: - case 156: - case 128: - case 127: - case 157: + case 159: if (node.typeParameters === list) { return 24; } @@ -23502,8 +27627,8 @@ var ts; return 16; } break; - case 151: - case 152: + case 153: + case 154: if (node.typeArguments === list) { return 24; } @@ -23511,7 +27636,7 @@ var ts; return 16; } break; - case 135: + case 137: if (node.typeArguments === list) { return 24; } @@ -23591,7 +27716,7 @@ var ts; return 0; } var lineAtPosition = sourceFile.getLineAndCharacterFromPosition(position).line; - if (precedingToken.kind === 23 && precedingToken.parent.kind !== 163) { + if (precedingToken.kind === 23 && precedingToken.parent.kind !== 166) { var actualIndentation = getActualIndentationForListItemBeforeComma(precedingToken, sourceFile, options); if (actualIndentation !== -1) { return actualIndentation; @@ -23675,7 +27800,7 @@ var ts; return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options); } function getActualIndentationForNode(current, parent, currentLineAndChar, parentAndChildShareLine, sourceFile, options) { - var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && (parent.kind === 207 || !parentAndChildShareLine); + var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && (parent.kind === 211 || !parentAndChildShareLine); if (!useActualIndentation) { return -1; } @@ -23702,7 +27827,7 @@ var ts; return candidate.end > position || !isCompletedNode(candidate, sourceFile); } function childStartsOnTheSameLineWithElseInIfStatement(parent, child, childStartLine, sourceFile) { - if (parent.kind === 174 && parent.elseStatement === child) { + if (parent.kind === 178 && parent.elseStatement === child) { var elseKeyword = ts.findChildOfKind(parent, 75, sourceFile); ts.Debug.assert(elseKeyword !== undefined); var elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line; @@ -23714,22 +27839,22 @@ var ts; function getContainingList(node, sourceFile) { if (node.parent) { switch (node.parent.kind) { - case 135: + case 137: if (node.parent.typeArguments && ts.rangeContainsStartEnd(node.parent.typeArguments, node.getStart(sourceFile), node.getEnd())) { return node.parent.typeArguments; } break; - case 148: + case 150: return node.parent.properties; - case 147: + case 149: return node.parent.elements; - case 190: - case 156: - case 157: - case 128: - case 127: - case 132: - case 133: + case 194: + case 158: + case 159: + case 130: + case 129: + case 134: + case 135: var start = node.getStart(sourceFile); if (node.parent.typeParameters && ts.rangeContainsStartEnd(node.parent.typeParameters, start, node.getEnd())) { return node.parent.typeParameters; @@ -23738,8 +27863,8 @@ var ts; return node.parent.parameters; } break; - case 152: - case 151: + case 154: + case 153: var start = node.getStart(sourceFile); if (node.parent.typeArguments && ts.rangeContainsStartEnd(node.parent.typeArguments, start, node.getEnd())) { return node.parent.typeArguments; @@ -23799,25 +27924,25 @@ var ts; SmartIndenter.findFirstNonWhitespaceColumn = findFirstNonWhitespaceColumn; function nodeContentIsAlwaysIndented(kind) { switch (kind) { - case 191: - case 192: - case 194: - case 147: - case 170: + case 195: case 196: - case 148: - case 139: - case 183: - case 201: - case 200: - case 155: - case 151: - case 152: - case 171: - case 188: case 198: - case 181: - case 164: + case 149: + case 174: + case 200: + case 150: + case 141: + case 187: + case 205: + case 204: + case 157: + case 153: + case 154: + case 175: + case 192: + case 202: + case 185: + case 167: return true; } return false; @@ -23827,20 +27952,20 @@ var ts; return true; } switch (parent) { - case 175: - case 176: + case 179: + case 180: + case 182: + case 181: case 178: - case 177: - case 174: - case 190: - case 156: - case 128: - case 127: - case 157: - case 129: + case 194: + case 158: case 130: + case 129: + case 159: case 131: - return child !== 170; + case 132: + case 133: + return child !== 174; default: return false; } @@ -23864,44 +27989,44 @@ var ts; return false; } switch (n.kind) { - case 191: - case 192: - case 194: - case 148: - case 170: + case 195: case 196: - case 183: + case 198: + case 150: + case 174: + case 200: + case 187: return nodeEndsWith(n, 15, sourceFile); - case 203: + case 207: return isCompletedNode(n.block, sourceFile); - case 155: - case 132: - case 151: - case 133: - return nodeEndsWith(n, 17, sourceFile); - case 190: - case 156: - case 128: - case 127: case 157: + case 134: + case 153: + case 135: + return nodeEndsWith(n, 17, sourceFile); + case 194: + case 158: + case 130: + case 129: + case 159: return !n.body || isCompletedNode(n.body, sourceFile); - case 195: + case 199: return n.body && isCompletedNode(n.body, sourceFile); - case 174: + case 178: if (n.elseStatement) { return isCompletedNode(n.elseStatement, sourceFile); } return isCompletedNode(n.thenStatement, sourceFile); - case 173: + case 177: return isCompletedNode(n.expression, sourceFile); - case 147: + case 149: return nodeEndsWith(n, 19, sourceFile); - case 200: - case 201: + case 204: + case 205: return false; - case 176: + case 180: return isCompletedNode(n.statement, sourceFile); - case 175: + case 179: var hasWhileKeyword = ts.findChildOfKind(n, 99, sourceFile); if (hasWhileKeyword) { return nodeEndsWith(n, 17, sourceFile); @@ -23997,7 +28122,7 @@ var ts; return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(208, nodes.pos, nodes.end, 512, this); + var list = createNode(212, nodes.pos, nodes.end, 512, this); list._children = []; var pos = nodes.pos; for (var i = 0, len = nodes.length; i < len; i++) { @@ -24015,7 +28140,7 @@ var ts; }; NodeObject.prototype.createChildren = function (sourceFile) { var _this = this; - if (this.kind >= 121) { + if (this.kind >= 123) { scanner.setText((sourceFile || this.getSourceFile()).text); var children = []; var pos = this.pos; @@ -24060,7 +28185,7 @@ var ts; var children = this.getChildren(); for (var i = 0; i < children.length; i++) { var child = children[i]; - if (child.kind < 121) { + if (child.kind < 123) { return child; } return child.getFirstToken(sourceFile); @@ -24070,7 +28195,7 @@ var ts; var children = this.getChildren(sourceFile); for (var i = children.length - 1; i >= 0; i--) { var child = children[i]; - if (child.kind < 121) { + if (child.kind < 123) { return child; } return child.getLastToken(sourceFile); @@ -24116,7 +28241,7 @@ var ts; ts.forEach(declarations, function (declaration, indexOfDeclaration) { if (ts.indexOf(declarations, declaration) === indexOfDeclaration) { var sourceFileOfDeclaration = ts.getSourceFileOfNode(declaration); - if (canUseParsedParamTagComments && declaration.kind === 124) { + if (canUseParsedParamTagComments && declaration.kind === 126) { ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), function (jsDocCommentTextRange) { var cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedParamJsDocComment) { @@ -24124,13 +28249,13 @@ var ts; } }); } - if (declaration.kind === 195 && declaration.body.kind === 195) { + if (declaration.kind === 199 && declaration.body.kind === 199) { return; } - while (declaration.kind === 195 && declaration.parent.kind === 195) { + while (declaration.kind === 199 && declaration.parent.kind === 199) { declaration = declaration.parent; } - ts.forEach(getJsDocCommentTextRange(declaration.kind === 188 ? declaration.parent.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { + ts.forEach(getJsDocCommentTextRange(declaration.kind === 192 ? declaration.parent.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedJsDocComment) { jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment); @@ -24411,9 +28536,9 @@ var ts; var namedDeclarations = []; ts.forEachChild(sourceFile, function visit(node) { switch (node.kind) { - case 190: - case 128: - case 127: + case 194: + case 130: + case 129: var functionDeclaration = node; if (functionDeclaration.name && functionDeclaration.name.getFullWidth() > 0) { var lastDeclaration = namedDeclarations.length > 0 ? namedDeclarations[namedDeclarations.length - 1] : undefined; @@ -24428,44 +28553,44 @@ var ts; ts.forEachChild(node, visit); } break; - case 191: - case 192: - case 193: - case 194: case 195: + case 196: case 197: - case 130: - case 131: - case 139: + case 198: + case 199: + case 201: + case 132: + case 133: + case 141: if (node.name) { namedDeclarations.push(node); } - case 129: - case 171: - case 189: - case 144: - case 145: - case 196: + case 131: + case 175: + case 193: + case 146: + case 147: + case 200: ts.forEachChild(node, visit); break; - case 170: + case 174: if (ts.isFunctionBlock(node)) { ts.forEachChild(node, visit); } break; - case 124: + case 126: if (!(node.flags & 112)) { break; } - case 188: - case 146: + case 192: + case 148: if (ts.isBindingPattern(node.name)) { ts.forEachChild(node.name, visit); break; } - case 206: - case 126: - case 125: + case 210: + case 128: + case 127: namedDeclarations.push(node); break; } @@ -24518,6 +28643,9 @@ var ts; EndOfLineState[EndOfLineState["InMultiLineCommentTrivia"] = 1] = "InMultiLineCommentTrivia"; EndOfLineState[EndOfLineState["InSingleQuoteStringLiteral"] = 2] = "InSingleQuoteStringLiteral"; EndOfLineState[EndOfLineState["InDoubleQuoteStringLiteral"] = 3] = "InDoubleQuoteStringLiteral"; + EndOfLineState[EndOfLineState["InTemplateHeadOrNoSubstitutionTemplate"] = 4] = "InTemplateHeadOrNoSubstitutionTemplate"; + EndOfLineState[EndOfLineState["InTemplateMiddleOrTail"] = 5] = "InTemplateMiddleOrTail"; + EndOfLineState[EndOfLineState["InTemplateSubstitutionPosition"] = 6] = "InTemplateSubstitutionPosition"; })(ts.EndOfLineState || (ts.EndOfLineState = {})); var EndOfLineState = ts.EndOfLineState; (function (TokenClass) { @@ -24618,14 +28746,14 @@ var ts; return false; } return ts.forEach(symbol.declarations, function (declaration) { - if (declaration.kind === 156) { + if (declaration.kind === 158) { return true; } - if (declaration.kind !== 188 && declaration.kind !== 190) { + if (declaration.kind !== 192 && declaration.kind !== 194) { return false; } for (var parent = declaration.parent; !ts.isFunctionBlock(parent); parent = parent.parent) { - if (parent.kind === 207 || parent.kind === 196) { + if (parent.kind === 211 || parent.kind === 200) { return false; } } @@ -24930,7 +29058,7 @@ var ts; ts.preProcessFile = preProcessFile; function getTargetLabel(referenceNode, labelName) { while (referenceNode) { - if (referenceNode.kind === 184 && referenceNode.label.text === labelName) { + if (referenceNode.kind === 188 && referenceNode.label.text === labelName) { return referenceNode.label; } referenceNode = referenceNode.parent; @@ -24938,13 +29066,13 @@ var ts; return undefined; } function isJumpStatementTarget(node) { - return node.kind === 64 && (node.parent.kind === 180 || node.parent.kind === 179) && node.parent.label === node; + return node.kind === 64 && (node.parent.kind === 184 || node.parent.kind === 183) && node.parent.label === node; } function isLabelOfLabeledStatement(node) { - return node.kind === 64 && node.parent.kind === 184 && node.parent.label === node; + return node.kind === 64 && node.parent.kind === 188 && node.parent.label === node; } function isLabeledBy(node, labelName) { - for (var owner = node.parent; owner.kind === 184; owner = owner.parent) { + for (var owner = node.parent; owner.kind === 188; owner = owner.parent) { if (owner.label.text === labelName) { return true; } @@ -24955,46 +29083,46 @@ var ts; return isLabelOfLabeledStatement(node) || isJumpStatementTarget(node); } function isRightSideOfQualifiedName(node) { - return node.parent.kind === 121 && node.parent.right === node; + return node.parent.kind === 123 && node.parent.right === node; } function isRightSideOfPropertyAccess(node) { - return node && node.parent && node.parent.kind === 149 && node.parent.name === node; + return node && node.parent && node.parent.kind === 151 && node.parent.name === node; } function isCallExpressionTarget(node) { if (isRightSideOfPropertyAccess(node)) { node = node.parent; } - return node && node.parent && node.parent.kind === 151 && node.parent.expression === node; + return node && node.parent && node.parent.kind === 153 && node.parent.expression === node; } function isNewExpressionTarget(node) { if (isRightSideOfPropertyAccess(node)) { node = node.parent; } - return node && node.parent && node.parent.kind === 152 && node.parent.expression === node; + return node && node.parent && node.parent.kind === 154 && node.parent.expression === node; } function isNameOfModuleDeclaration(node) { - return node.parent.kind === 195 && node.parent.name === node; + return node.parent.kind === 199 && node.parent.name === node; } function isNameOfFunctionDeclaration(node) { return node.kind === 64 && ts.isAnyFunction(node.parent) && node.parent.name === node; } function isNameOfPropertyAssignment(node) { - return (node.kind === 64 || node.kind === 8 || node.kind === 7) && (node.parent.kind === 204 || node.parent.kind === 205) && node.parent.name === node; + return (node.kind === 64 || node.kind === 8 || node.kind === 7) && (node.parent.kind === 208 || node.parent.kind === 209) && node.parent.name === node; } function isLiteralNameOfPropertyDeclarationOrIndexAccess(node) { if (node.kind === 8 || node.kind === 7) { switch (node.parent.kind) { - case 126: - case 125: - case 204: - case 206: case 128: case 127: + case 208: + case 210: case 130: - case 131: - case 195: + case 129: + case 132: + case 133: + case 199: return node.parent.name === node; - case 150: + case 152: return node.parent.argumentExpression === node; } } @@ -25043,7 +29171,7 @@ var ts; BreakContinueSearchType[BreakContinueSearchType["All"] = 3] = "All"; })(BreakContinueSearchType || (BreakContinueSearchType = {})); var keywordCompletions = []; - for (var i = 65; i <= 120; i++) { + for (var i = 65; i <= 122; i++) { keywordCompletions.push({ name: ts.tokenToString(i), kind: ScriptElementKind.keyword, @@ -25246,11 +29374,11 @@ var ts; } var node; var isRightOfDot; - if (previousToken && previousToken.kind === 20 && previousToken.parent.kind === 149) { + if (previousToken && previousToken.kind === 20 && previousToken.parent.kind === 151) { node = previousToken.parent.expression; isRightOfDot = true; } - else if (previousToken && previousToken.kind === 20 && previousToken.parent.kind === 121) { + else if (previousToken && previousToken.kind === 20 && previousToken.parent.kind === 123) { node = previousToken.parent.left; isRightOfDot = true; } @@ -25272,7 +29400,7 @@ var ts; var symbols = []; var isMemberCompletion = true; var isNewIdentifierLocation = false; - if (node.kind === 64 || node.kind === 121 || node.kind === 149) { + if (node.kind === 64 || node.kind === 123 || node.kind === 151) { var symbol = typeInfoResolver.getSymbolAtLocation(node); if (symbol && symbol.flags & 8388608) { symbol = typeInfoResolver.getAliasedSymbol(symbol); @@ -25353,27 +29481,27 @@ var ts; var containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { case 23: - return containingNodeKind === 151 || containingNodeKind === 129 || containingNodeKind === 152 || containingNodeKind === 147 || containingNodeKind === 163; + return containingNodeKind === 153 || containingNodeKind === 131 || containingNodeKind === 154 || containingNodeKind === 149 || containingNodeKind === 166; case 16: - return containingNodeKind === 151 || containingNodeKind === 129 || containingNodeKind === 152 || containingNodeKind === 155; + return containingNodeKind === 153 || containingNodeKind === 131 || containingNodeKind === 154 || containingNodeKind === 157; case 18: - return containingNodeKind === 147; + return containingNodeKind === 149; case 115: return true; case 20: - return containingNodeKind === 195; + return containingNodeKind === 199; case 14: - return containingNodeKind === 191; + return containingNodeKind === 195; case 52: - return containingNodeKind === 188 || containingNodeKind === 163; + return containingNodeKind === 192 || containingNodeKind === 166; case 11: - return containingNodeKind === 165; + return containingNodeKind === 168; case 12: - return containingNodeKind === 169; + return containingNodeKind === 173; case 107: case 105: case 106: - return containingNodeKind === 126; + return containingNodeKind === 128; } switch (previousToken.getText()) { case "public": @@ -25403,7 +29531,7 @@ var ts; switch (previousToken.kind) { case 14: case 23: - if (parent && parent.kind === 148) { + if (parent && parent.kind === 150) { return parent; } break; @@ -25413,16 +29541,16 @@ var ts; } function isFunction(kind) { switch (kind) { - case 156: - case 157: - case 190: - case 128: - case 127: + case 158: + case 159: + case 194: case 130: - case 131: + case 129: case 132: case 133: case 134: + case 135: + case 136: return true; } return false; @@ -25432,27 +29560,27 @@ var ts; var containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { case 23: - return containingNodeKind === 188 || containingNodeKind === 189 || containingNodeKind === 171 || containingNodeKind === 194 || isFunction(containingNodeKind) || containingNodeKind === 191 || containingNodeKind === 190 || containingNodeKind === 192 || containingNodeKind === 145 || containingNodeKind === 144; + return containingNodeKind === 192 || containingNodeKind === 193 || containingNodeKind === 175 || containingNodeKind === 198 || isFunction(containingNodeKind) || containingNodeKind === 195 || containingNodeKind === 194 || containingNodeKind === 196 || containingNodeKind === 147 || containingNodeKind === 146; case 20: - return containingNodeKind === 145; + return containingNodeKind === 147; case 18: - return containingNodeKind === 145; + return containingNodeKind === 147; case 16: - return containingNodeKind === 203 || isFunction(containingNodeKind); + return containingNodeKind === 207 || isFunction(containingNodeKind); case 14: - return containingNodeKind === 194 || containingNodeKind === 192 || containingNodeKind === 139 || containingNodeKind === 144; + return containingNodeKind === 198 || containingNodeKind === 196 || containingNodeKind === 141 || containingNodeKind === 146; case 22: - return containingNodeKind === 125 && (previousToken.parent.parent.kind === 192 || previousToken.parent.parent.kind === 139); + return containingNodeKind === 127 && (previousToken.parent.parent.kind === 196 || previousToken.parent.parent.kind === 141); case 24: - return containingNodeKind === 191 || containingNodeKind === 190 || containingNodeKind === 192 || isFunction(containingNodeKind); + return containingNodeKind === 195 || containingNodeKind === 194 || containingNodeKind === 196 || isFunction(containingNodeKind); case 108: - return containingNodeKind === 126; + return containingNodeKind === 128; case 21: - return containingNodeKind === 124 || containingNodeKind === 129 || (previousToken.parent.parent.kind === 145); + return containingNodeKind === 126 || containingNodeKind === 131 || (previousToken.parent.parent.kind === 147); case 107: case 105: case 106: - return containingNodeKind === 124; + return containingNodeKind === 126; case 68: case 76: case 102: @@ -25494,7 +29622,7 @@ var ts; } var existingMemberNames = {}; ts.forEach(existingMembers, function (m) { - if (m.kind !== 204 && m.kind !== 205) { + if (m.kind !== 208 && m.kind !== 209) { return; } if (m.getStart() <= position && position <= m.getEnd()) { @@ -25549,17 +29677,17 @@ var ts; return undefined; } switch (node.kind) { - case 207: - case 128: - case 127: - case 190: - case 156: + case 211: case 130: - case 131: - case 191: - case 192: + case 129: case 194: + case 158: + case 132: + case 133: case 195: + case 196: + case 198: + case 199: return node; } } @@ -25658,29 +29786,29 @@ var ts; } function getNodeKind(node) { switch (node.kind) { - case 195: return ScriptElementKind.moduleElement; - case 191: return ScriptElementKind.classElement; - case 192: return ScriptElementKind.interfaceElement; - case 193: return ScriptElementKind.typeElement; - case 194: return ScriptElementKind.enumElement; - case 188: + case 199: return ScriptElementKind.moduleElement; + case 195: return ScriptElementKind.classElement; + case 196: return ScriptElementKind.interfaceElement; + case 197: return ScriptElementKind.typeElement; + case 198: return ScriptElementKind.enumElement; + case 192: return ts.isConst(node) ? ScriptElementKind.constElement : ts.isLet(node) ? ScriptElementKind.letElement : ScriptElementKind.variableElement; - case 190: return ScriptElementKind.functionElement; - case 130: return ScriptElementKind.memberGetAccessorElement; - case 131: return ScriptElementKind.memberSetAccessorElement; + case 194: return ScriptElementKind.functionElement; + case 132: return ScriptElementKind.memberGetAccessorElement; + case 133: return ScriptElementKind.memberSetAccessorElement; + case 130: + case 129: + return ScriptElementKind.memberFunctionElement; case 128: case 127: - return ScriptElementKind.memberFunctionElement; - case 126: - case 125: return ScriptElementKind.memberVariableElement; - case 134: return ScriptElementKind.indexSignatureElement; - case 133: return ScriptElementKind.constructSignatureElement; - case 132: return ScriptElementKind.callSignatureElement; - case 129: return ScriptElementKind.constructorImplementationElement; - case 123: return ScriptElementKind.typeParameterElement; - case 206: return ScriptElementKind.variableElement; - case 124: return (node.flags & 112) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; + case 136: return ScriptElementKind.indexSignatureElement; + case 135: return ScriptElementKind.constructSignatureElement; + case 134: return ScriptElementKind.callSignatureElement; + case 131: return ScriptElementKind.constructorImplementationElement; + case 125: return ScriptElementKind.typeParameterElement; + case 210: return ScriptElementKind.variableElement; + case 126: return (node.flags & 112) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; } return ScriptElementKind.unknown; } @@ -25700,14 +29828,14 @@ var ts; } var type = typeResolver.getTypeOfSymbolAtLocation(symbol, location); if (type) { - if (location.parent && location.parent.kind === 149) { + if (location.parent && location.parent.kind === 151) { var right = location.parent.name; if (right === location || (right && right.getFullWidth() === 0)) { location = location.parent; } } var callExpression; - if (location.kind === 151 || location.kind === 152) { + if (location.kind === 153 || location.kind === 154) { callExpression = location; } else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) { @@ -25719,7 +29847,7 @@ var ts; if (!signature && candidateSignatures.length) { signature = candidateSignatures[0]; } - var useConstructSignatures = callExpression.kind === 152 || callExpression.expression.kind === 90; + var useConstructSignatures = callExpression.kind === 154 || callExpression.expression.kind === 90; var allSignatures = useConstructSignatures ? type.getConstructSignatures() : type.getCallSignatures(); if (!ts.contains(allSignatures, signature.target || signature)) { signature = allSignatures.length ? allSignatures[0] : undefined; @@ -25768,22 +29896,22 @@ var ts; hasAddedSymbolInfo = true; } } - else if ((isNameOfFunctionDeclaration(location) && !(symbol.flags & 98304)) || (location.kind === 112 && location.parent.kind === 129)) { + else if ((isNameOfFunctionDeclaration(location) && !(symbol.flags & 98304)) || (location.kind === 112 && location.parent.kind === 131)) { var signature; var functionDeclaration = location.parent; - var allSignatures = functionDeclaration.kind === 129 ? type.getConstructSignatures() : type.getCallSignatures(); + var allSignatures = functionDeclaration.kind === 131 ? type.getConstructSignatures() : type.getCallSignatures(); if (!typeResolver.isImplementationOfOverload(functionDeclaration)) { signature = typeResolver.getSignatureFromDeclaration(functionDeclaration); } else { signature = allSignatures[0]; } - if (functionDeclaration.kind === 129) { + if (functionDeclaration.kind === 131) { symbolKind = ScriptElementKind.constructorImplementationElement; addPrefixForAnyFunctionOrVar(type.symbol, symbolKind); } else { - addPrefixForAnyFunctionOrVar(functionDeclaration.kind === 132 && !(type.symbol.flags & 2048 || type.symbol.flags & 4096) ? type.symbol : symbol, symbolKind); + addPrefixForAnyFunctionOrVar(functionDeclaration.kind === 134 && !(type.symbol.flags & 2048 || type.symbol.flags & 4096) ? type.symbol : symbol, symbolKind); } addSignatureDisplayParts(signature, allSignatures); hasAddedSymbolInfo = true; @@ -25844,13 +29972,13 @@ var ts; writeTypeParametersOfSymbol(symbol.parent, enclosingDeclaration); } else { - var signatureDeclaration = ts.getDeclarationOfKind(symbol, 123).parent; + var signatureDeclaration = ts.getDeclarationOfKind(symbol, 125).parent; var signature = typeResolver.getSignatureFromDeclaration(signatureDeclaration); - if (signatureDeclaration.kind === 133) { + if (signatureDeclaration.kind === 135) { displayParts.push(ts.keywordPart(87)); displayParts.push(ts.spacePart()); } - else if (signatureDeclaration.kind !== 132 && signatureDeclaration.name) { + else if (signatureDeclaration.kind !== 134 && signatureDeclaration.name) { addFullSymbolName(signatureDeclaration.symbol); } displayParts.push.apply(displayParts, ts.signatureToDisplayParts(typeResolver, signature, sourceFile, 32)); @@ -25859,7 +29987,7 @@ var ts; if (symbolFlags & 8) { addPrefixForAnyFunctionOrVar(symbol, "enum member"); var declaration = symbol.declarations[0]; - if (declaration.kind === 206) { + if (declaration.kind === 210) { var constantValue = typeResolver.getConstantValue(declaration); if (constantValue !== undefined) { displayParts.push(ts.spacePart()); @@ -25875,7 +30003,7 @@ var ts; displayParts.push(ts.spacePart()); addFullSymbolName(symbol); ts.forEach(symbol.declarations, function (declaration) { - if (declaration.kind === 197) { + if (declaration.kind === 201) { var importDeclaration = declaration; if (ts.isExternalModuleImportDeclaration(importDeclaration)) { displayParts.push(ts.spacePart()); @@ -25981,8 +30109,8 @@ var ts; if (!symbol) { switch (node.kind) { case 64: - case 149: - case 121: + case 151: + case 123: case 92: case 90: var type = typeInfoResolver.getTypeAtLocation(node); @@ -26040,7 +30168,7 @@ var ts; return undefined; } var result = []; - if (node.parent.kind === 205) { + if (node.parent.kind === 209) { var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); var shorthandDeclarations = shorthandSymbol.getDeclarations(); var shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver, node); @@ -26076,7 +30204,7 @@ var ts; var declarations = []; var definition; ts.forEach(signatureDeclarations, function (d) { - if ((selectConstructors && d.kind === 129) || (!selectConstructors && (d.kind === 190 || d.kind === 128 || d.kind === 127))) { + if ((selectConstructors && d.kind === 131) || (!selectConstructors && (d.kind === 194 || d.kind === 130 || d.kind === 129))) { declarations.push(d); if (d.body) definition = d; @@ -26096,7 +30224,7 @@ var ts; if (isNewExpressionTarget(location) || location.kind === 112) { if (symbol.flags & 32) { var classDeclaration = symbol.getDeclarations()[0]; - ts.Debug.assert(classDeclaration && classDeclaration.kind === 191); + ts.Debug.assert(classDeclaration && classDeclaration.kind === 195); return tryAddSignature(classDeclaration.members, true, symbolKind, symbolName, containerName, result); } } @@ -26123,78 +30251,78 @@ var ts; switch (node.kind) { case 83: case 75: - if (hasKind(node.parent, 174)) { + if (hasKind(node.parent, 178)) { return getIfElseOccurrences(node.parent); } break; case 89: - if (hasKind(node.parent, 181)) { + if (hasKind(node.parent, 185)) { return getReturnOccurrences(node.parent); } break; case 93: - if (hasKind(node.parent, 185)) { + if (hasKind(node.parent, 189)) { return getThrowOccurrences(node.parent); } break; case 67: - if (hasKind(parent(parent(node)), 186)) { + if (hasKind(parent(parent(node)), 190)) { return getTryCatchFinallyOccurrences(node.parent.parent); } break; case 95: case 80: - if (hasKind(parent(node), 186)) { + if (hasKind(parent(node), 190)) { return getTryCatchFinallyOccurrences(node.parent); } break; case 91: - if (hasKind(node.parent, 183)) { + if (hasKind(node.parent, 187)) { return getSwitchCaseDefaultOccurrences(node.parent); } break; case 66: case 72: - if (hasKind(parent(parent(node)), 183)) { + if (hasKind(parent(parent(node)), 187)) { return getSwitchCaseDefaultOccurrences(node.parent.parent); } break; case 65: case 70: - if (hasKind(node.parent, 180) || hasKind(node.parent, 179)) { + if (hasKind(node.parent, 184) || hasKind(node.parent, 183)) { return getBreakOrContinueStatementOccurences(node.parent); } break; case 81: - if (hasKind(node.parent, 177) || hasKind(node.parent, 178)) { + if (hasKind(node.parent, 181) || hasKind(node.parent, 182)) { return getLoopBreakContinueOccurrences(node.parent); } break; case 99: case 74: - if (hasKind(node.parent, 176) || hasKind(node.parent, 175)) { + if (hasKind(node.parent, 180) || hasKind(node.parent, 179)) { return getLoopBreakContinueOccurrences(node.parent); } break; case 112: - if (hasKind(node.parent, 129)) { + if (hasKind(node.parent, 131)) { return getConstructorOccurrences(node.parent); } break; case 114: case 118: - if (hasKind(node.parent, 130) || hasKind(node.parent, 131)) { + if (hasKind(node.parent, 132) || hasKind(node.parent, 133)) { return getGetAndSetOccurrences(node.parent); } default: - if (ts.isModifier(node.kind) && node.parent && (ts.isDeclaration(node.parent) || node.parent.kind === 171)) { + if (ts.isModifier(node.kind) && node.parent && (ts.isDeclaration(node.parent) || node.parent.kind === 175)) { return getModifierOccurrences(node.kind, node.parent); } } return undefined; function getIfElseOccurrences(ifStatement) { var keywords = []; - while (hasKind(ifStatement.parent, 174) && ifStatement.parent.elseStatement === ifStatement) { + while (hasKind(ifStatement.parent, 178) && ifStatement.parent.elseStatement === ifStatement) { ifStatement = ifStatement.parent; } while (ifStatement) { @@ -26205,7 +30333,7 @@ var ts; break; } } - if (!hasKind(ifStatement.elseStatement, 174)) { + if (!hasKind(ifStatement.elseStatement, 178)) { break; } ifStatement = ifStatement.elseStatement; @@ -26238,7 +30366,7 @@ var ts; } function getReturnOccurrences(returnStatement) { var func = ts.getContainingFunction(returnStatement); - if (!(func && hasKind(func.body, 170))) { + if (!(func && hasKind(func.body, 174))) { return undefined; } var keywords = []; @@ -26271,10 +30399,10 @@ var ts; aggregate(node); return statementAccumulator; function aggregate(node) { - if (node.kind === 185) { + if (node.kind === 189) { statementAccumulator.push(node); } - else if (node.kind === 186) { + else if (node.kind === 190) { var tryStatement = node; if (tryStatement.catchClause) { aggregate(tryStatement.catchClause); @@ -26296,10 +30424,10 @@ var ts; var child = throwStatement; while (child.parent) { var parent = child.parent; - if (ts.isFunctionBlock(parent) || parent.kind === 207) { + if (ts.isFunctionBlock(parent) || parent.kind === 211) { return parent; } - if (parent.kind === 186) { + if (parent.kind === 190) { var tryStatement = parent; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; @@ -26324,7 +30452,7 @@ var ts; function getLoopBreakContinueOccurrences(loopNode) { var keywords = []; if (pushKeywordIf(keywords, loopNode.getFirstToken(), 81, 99, 74)) { - if (loopNode.kind === 175) { + if (loopNode.kind === 179) { var loopTokens = loopNode.getChildren(); for (var i = loopTokens.length - 1; i >= 0; i--) { if (pushKeywordIf(keywords, loopTokens[i], 99)) { @@ -26359,12 +30487,12 @@ var ts; var owner = getBreakOrContinueOwner(breakOrContinueStatement); if (owner) { switch (owner.kind) { - case 177: - case 178: - case 175: - case 176: + case 181: + case 182: + case 179: + case 180: return getLoopBreakContinueOccurrences(owner); - case 183: + case 187: return getSwitchCaseDefaultOccurrences(owner); } } @@ -26375,7 +30503,7 @@ var ts; aggregate(node); return statementAccumulator; function aggregate(node) { - if (node.kind === 180 || node.kind === 179) { + if (node.kind === 184 || node.kind === 183) { statementAccumulator.push(node); } else if (!ts.isAnyFunction(node)) { @@ -26391,14 +30519,14 @@ var ts; function getBreakOrContinueOwner(statement) { for (var node = statement.parent; node; node = node.parent) { switch (node.kind) { - case 183: - if (statement.kind === 179) { + case 187: + if (statement.kind === 183) { continue; } - case 177: - case 178: - case 176: - case 175: + case 181: + case 182: + case 180: + case 179: if (!statement.label || isLabeledBy(node, statement.label.text)) { return node; } @@ -26424,8 +30552,8 @@ var ts; } function getGetAndSetOccurrences(accessorDeclaration) { var keywords = []; - tryPushAccessorKeyword(accessorDeclaration.symbol, 130); - tryPushAccessorKeyword(accessorDeclaration.symbol, 131); + tryPushAccessorKeyword(accessorDeclaration.symbol, 132); + tryPushAccessorKeyword(accessorDeclaration.symbol, 133); return ts.map(keywords, getReferenceEntryFromNode); function tryPushAccessorKeyword(accessorSymbol, accessorKind) { var accessor = ts.getDeclarationOfKind(accessorSymbol, accessorKind); @@ -26437,17 +30565,17 @@ var ts; function getModifierOccurrences(modifier, declaration) { var container = declaration.parent; if (declaration.flags & 112) { - if (!(container.kind === 191 || (declaration.kind === 124 && hasKind(container, 129)))) { + if (!(container.kind === 195 || (declaration.kind === 126 && hasKind(container, 131)))) { return undefined; } } else if (declaration.flags & 128) { - if (container.kind !== 191) { + if (container.kind !== 195) { return undefined; } } else if (declaration.flags & (1 | 2)) { - if (!(container.kind === 196 || container.kind === 207)) { + if (!(container.kind === 200 || container.kind === 211)) { return undefined; } } @@ -26458,18 +30586,18 @@ var ts; var modifierFlag = getFlagFromModifier(modifier); var nodes; switch (container.kind) { - case 196: - case 207: + case 200: + case 211: nodes = container.statements; break; - case 129: + case 131: nodes = container.parameters.concat(container.parent.members); break; - case 191: + case 195: nodes = container.members; if (modifierFlag & 112) { var constructor = ts.forEach(container.members, function (member) { - return member.kind === 129 && member; + return member.kind === 131 && member; }); if (constructor) { nodes = nodes.concat(constructor.parameters); @@ -26619,7 +30747,7 @@ var ts; return stripQuotes(name); } function getInternedName(symbol, declarations) { - var functionExpression = ts.forEach(declarations, function (d) { return d.kind === 156 ? d : undefined; }); + var functionExpression = ts.forEach(declarations, function (d) { return d.kind === 158 ? d : undefined; }); if (functionExpression && functionExpression.name) { var name = functionExpression.name.text; } @@ -26640,7 +30768,7 @@ var ts; if (symbol.getFlags() && (4 | 8192)) { var privateDeclaration = ts.forEach(symbol.getDeclarations(), function (d) { return (d.flags & 32) ? d : undefined; }); if (privateDeclaration) { - return ts.getAncestor(privateDeclaration, 191); + return ts.getAncestor(privateDeclaration, 195); } } if (symbol.parent || (symbol.getFlags() & 268435456)) { @@ -26657,7 +30785,7 @@ var ts; if (scope && scope !== container) { return undefined; } - if (container.kind === 207 && !ts.isExternalModule(container)) { + if (container.kind === 211 && !ts.isExternalModule(container)) { return undefined; } scope = container; @@ -26784,13 +30912,13 @@ var ts; } var staticFlag = 128; switch (searchSpaceNode.kind) { - case 126: - case 125: case 128: case 127: - case 129: case 130: + case 129: case 131: + case 132: + case 133: staticFlag &= searchSpaceNode.flags; searchSpaceNode = searchSpaceNode.parent; break; @@ -26817,31 +30945,31 @@ var ts; var searchSpaceNode = ts.getThisContainer(thisOrSuperKeyword, false); var staticFlag = 128; switch (searchSpaceNode.kind) { - case 128: - case 127: + case 130: + case 129: if (ts.isObjectLiteralMethod(searchSpaceNode)) { break; } - case 126: - case 125: - case 129: - case 130: + case 128: + case 127: case 131: + case 132: + case 133: staticFlag &= searchSpaceNode.flags; searchSpaceNode = searchSpaceNode.parent; break; - case 207: + case 211: if (ts.isExternalModule(searchSpaceNode)) { return undefined; } - case 190: - case 156: + case 194: + case 158: break; default: return undefined; } var result = []; - if (searchSpaceNode.kind === 207) { + if (searchSpaceNode.kind === 211) { ts.forEach(sourceFiles, function (sourceFile) { var possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "this", sourceFile.getStart(), sourceFile.getEnd()); getThisReferencesInFile(sourceFile, sourceFile, possiblePositions, result); @@ -26862,25 +30990,25 @@ var ts; } var container = ts.getThisContainer(node, false); switch (searchSpaceNode.kind) { - case 156: - case 190: + case 158: + case 194: if (searchSpaceNode.symbol === container.symbol) { result.push(getReferenceEntryFromNode(node)); } break; - case 128: - case 127: + case 130: + case 129: if (ts.isObjectLiteralMethod(searchSpaceNode) && searchSpaceNode.symbol === container.symbol) { result.push(getReferenceEntryFromNode(node)); } break; - case 191: + case 195: if (container.parent && searchSpaceNode.symbol === container.parent.symbol && (container.flags & 128) === staticFlag) { result.push(getReferenceEntryFromNode(node)); } break; - case 207: - if (container.kind === 207 && !ts.isExternalModule(container)) { + case 211: + if (container.kind === 211 && !ts.isExternalModule(container)) { result.push(getReferenceEntryFromNode(node)); } break; @@ -26912,11 +31040,11 @@ var ts; function getPropertySymbolsFromBaseTypes(symbol, propertyName, result) { if (symbol && symbol.flags & (32 | 64)) { ts.forEach(symbol.getDeclarations(), function (declaration) { - if (declaration.kind === 191) { + if (declaration.kind === 195) { getPropertySymbolFromTypeReference(ts.getClassBaseTypeNode(declaration)); ts.forEach(ts.getClassImplementedTypeNodes(declaration), getPropertySymbolFromTypeReference); } - else if (declaration.kind === 192) { + else if (declaration.kind === 196) { ts.forEach(ts.getInterfaceBaseTypeNodes(declaration), getPropertySymbolFromTypeReference); } }); @@ -27022,10 +31150,10 @@ var ts; } var parent = node.parent; if (parent) { - if (parent.kind === 162 || parent.kind === 161) { + if (parent.kind === 165 || parent.kind === 164) { return true; } - else if (parent.kind === 163 && parent.left === node) { + else if (parent.kind === 166 && parent.left === node) { var operator = parent.operator; return 52 <= operator && operator <= 63; } @@ -27115,33 +31243,33 @@ var ts; } function getMeaningFromDeclaration(node) { switch (node.kind) { - case 124: - case 188: - case 146: case 126: - case 125: - case 204: - case 205: - case 206: + case 192: + case 148: case 128: case 127: - case 129: + case 208: + case 209: + case 210: case 130: + case 129: case 131: - case 190: - case 156: - case 157: - case 203: + case 132: + case 133: + case 194: + case 158: + case 159: + case 207: return 1; - case 123: - case 192: - case 193: - case 139: + case 125: + case 196: + case 197: + case 141: return 2; - case 191: - case 194: - return 1 | 2; case 195: + case 198: + return 1 | 2; + case 199: if (node.name.kind === 8) { return 4 | 1; } @@ -27151,9 +31279,9 @@ var ts; else { return 4; } - case 197: + case 201: return 1 | 2 | 4; - case 207: + case 211: return 4 | 1; } ts.Debug.fail("Unknown declaration type"); @@ -27162,33 +31290,33 @@ var ts; if (isRightSideOfQualifiedName(node)) { node = node.parent; } - return node.parent.kind === 135; + return node.parent.kind === 137; } function isNamespaceReference(node) { var root = node; var isLastClause = true; - if (root.parent.kind === 121) { - while (root.parent && root.parent.kind === 121) + if (root.parent.kind === 123) { + while (root.parent && root.parent.kind === 123) root = root.parent; isLastClause = root.right === node; } - return root.parent.kind === 135 && !isLastClause; + return root.parent.kind === 137 && !isLastClause; } function isInRightSideOfImport(node) { - while (node.parent.kind === 121) { + while (node.parent.kind === 123) { node = node.parent; } return ts.isInternalModuleImportDeclaration(node.parent) && node.parent.moduleReference === node; } function getMeaningFromRightHandSideOfImport(node) { ts.Debug.assert(node.kind === 64); - if (node.parent.kind === 121 && node.parent.right === node && node.parent.parent.kind === 197) { + if (node.parent.kind === 123 && node.parent.right === node && node.parent.parent.kind === 201) { return 1 | 2 | 4; } return 4; } function getMeaningFromLocation(node) { - if (node.parent.kind === 198) { + if (node.parent.kind === 202) { return 1 | 2 | 4; } else if (isInRightSideOfImport(node)) { @@ -27225,8 +31353,8 @@ var ts; return; } switch (node.kind) { - case 149: - case 121: + case 151: + case 123: case 8: case 79: case 94: @@ -27244,7 +31372,7 @@ var ts; nodeForStartPos = nodeForStartPos.parent; } else if (isNameOfModuleDeclaration(nodeForStartPos)) { - if (nodeForStartPos.parent.parent.kind === 195 && nodeForStartPos.parent.parent.body === nodeForStartPos.parent) { + if (nodeForStartPos.parent.parent.kind === 199 && nodeForStartPos.parent.parent.body === nodeForStartPos.parent) { nodeForStartPos = nodeForStartPos.parent.parent.name; } else { @@ -27299,7 +31427,7 @@ var ts; return undefined; function hasValueSideModule(symbol) { return ts.forEach(symbol.declarations, function (declaration) { - return declaration.kind === 195 && ts.getModuleInstanceState(declaration) == 1; + return declaration.kind === 199 && ts.getModuleInstanceState(declaration) == 1; }); } } @@ -27418,11 +31546,11 @@ var ts; if (ts.isPunctuation(tokenKind)) { if (token) { if (tokenKind === 52) { - if (token.parent.kind === 188 || token.parent.kind === 126 || token.parent.kind === 124) { + if (token.parent.kind === 192 || token.parent.kind === 128 || token.parent.kind === 126) { return ClassificationTypeNames.operator; } } - if (token.parent.kind === 163 || token.parent.kind === 161 || token.parent.kind === 162 || token.parent.kind === 164) { + if (token.parent.kind === 166 || token.parent.kind === 164 || token.parent.kind === 165 || token.parent.kind === 167) { return ClassificationTypeNames.operator; } } @@ -27443,27 +31571,27 @@ var ts; else if (tokenKind === 64) { if (token) { switch (token.parent.kind) { - case 191: + case 195: if (token.parent.name === token) { return ClassificationTypeNames.className; } return; - case 123: + case 125: if (token.parent.name === token) { return ClassificationTypeNames.typeParameterName; } return; - case 192: + case 196: if (token.parent.name === token) { return ClassificationTypeNames.interfaceName; } return; - case 194: + case 198: if (token.parent.name === token) { return ClassificationTypeNames.enumName; } return; - case 195: + case 199: if (token.parent.name === token) { return ClassificationTypeNames.moduleName; } @@ -27722,6 +31850,7 @@ var ts; noRegexTable[15] = true; noRegexTable[94] = true; noRegexTable[79] = true; + var templateStack = []; function isAccessibilityModifier(kind) { switch (kind) { case 107: @@ -27740,10 +31869,13 @@ var ts; } return true; } - function getClassificationsForLine(text, lexState, classifyKeywordsInGenerics) { + function getClassificationsForLine(text, lexState, syntacticClassifierAbsent) { var offset = 0; var token = 0; var lastNonTriviaToken = 0; + while (templateStack.length > 0) { + templateStack.pop(); + } switch (lexState) { case 3: text = '"\\\n' + text; @@ -27757,6 +31889,16 @@ var ts; text = "/*\n" + text; offset = 3; break; + case 4: + text = "`\n" + text; + offset = 2; + break; + case 5: + text = "}\n" + text; + offset = 2; + case 6: + templateStack.push(11); + break; } scanner.setText(text); var result = { @@ -27785,10 +31927,36 @@ var ts; angleBracketStack--; } else if (token === 110 || token === 119 || token === 117 || token === 111) { - if (angleBracketStack > 0 && !classifyKeywordsInGenerics) { + if (angleBracketStack > 0 && !syntacticClassifierAbsent) { token = 64; } } + else if (token === 11) { + templateStack.push(token); + } + else if (token === 14) { + if (templateStack.length > 0) { + templateStack.push(token); + } + } + else if (token === 15) { + if (templateStack.length > 0) { + var lastTemplateStackToken = ts.lastOrUndefined(templateStack); + if (lastTemplateStackToken === 11) { + token = scanner.reScanTemplateToken(); + if (token === 13) { + templateStack.pop(); + } + else { + ts.Debug.assert(token === 12, "Should have been a template middle. Was " + token); + } + } + else { + ts.Debug.assert(lastTemplateStackToken === 14, "Should have been an open brace. Was: " + token); + templateStack.pop(); + } + } + } lastNonTriviaToken = token; } processToken(); @@ -27818,6 +31986,22 @@ var ts; result.finalLexState = 1; } } + else if (ts.isTemplateLiteralKind(token)) { + if (scanner.isUnterminated()) { + if (token === 13) { + result.finalLexState = 5; + } + else if (token === 10) { + result.finalLexState = 4; + } + else { + ts.Debug.fail("Only 'NoSubstitutionTemplateLiteral's and 'TemplateTail's can be unterminated; got SyntaxKind #" + token); + } + } + } + else if (templateStack.length > 0 && ts.lastOrUndefined(templateStack) === 11) { + result.finalLexState = 6; + } } } function addResult(length, classification) { @@ -27885,7 +32069,7 @@ var ts; } } function isKeyword(token) { - return token >= 65 && token <= 120; + return token >= 65 && token <= 122; } function classFromKind(token) { if (isKeyword(token)) { @@ -27912,6 +32096,9 @@ var ts; return 4; case 64: default: + if (ts.isTemplateLiteralKind(token)) { + return 7; + } return 5; } } @@ -27930,7 +32117,7 @@ var ts; getNodeConstructor: function (kind) { function Node() { } - var proto = kind === 207 ? new SourceFileObject() : new NodeObject(); + var proto = kind === 211 ? new SourceFileObject() : new NodeObject(); proto.kind = kind; proto.pos = 0; proto.end = 0; @@ -27984,93 +32171,93 @@ var ts; function spanInNode(node) { if (node) { if (ts.isExpression(node)) { - if (node.parent.kind === 175) { + if (node.parent.kind === 179) { return spanInPreviousNode(node); } - if (node.parent.kind === 177) { + if (node.parent.kind === 181) { return textSpan(node); } - if (node.parent.kind === 163 && node.parent.operator === 23) { + if (node.parent.kind === 166 && node.parent.operator === 23) { return textSpan(node); } - if (node.parent.kind == 157 && node.parent.body == node) { + if (node.parent.kind == 159 && node.parent.body == node) { return textSpan(node); } } switch (node.kind) { - case 171: + case 175: return spanInVariableDeclaration(node.declarationList.declarations[0]); - case 188: - case 126: - case 125: - return spanInVariableDeclaration(node); - case 124: - return spanInParameterDeclaration(node); - case 190: + case 192: case 128: case 127: + return spanInVariableDeclaration(node); + case 126: + return spanInParameterDeclaration(node); + case 194: case 130: - case 131: case 129: - case 156: - case 157: + case 132: + case 133: + case 131: + case 158: + case 159: return spanInFunctionDeclaration(node); - case 170: + case 174: if (ts.isFunctionBlock(node)) { return spanInFunctionBlock(node); } - case 196: + case 200: return spanInBlock(node); - case 203: + case 207: return spanInBlock(node.block); - case 173: + case 177: return textSpan(node.expression); - case 181: + case 185: return textSpan(node.getChildAt(0), node.expression); - case 176: + case 180: return textSpan(node, ts.findNextToken(node.expression, node)); - case 175: + case 179: return spanInNode(node.statement); - case 187: + case 191: return textSpan(node.getChildAt(0)); - case 174: + case 178: return textSpan(node, ts.findNextToken(node.expression, node)); - case 184: + case 188: return spanInNode(node.statement); - case 180: - case 179: + case 184: + case 183: return textSpan(node.getChildAt(0), node.label); - case 177: + case 181: return spanInForStatement(node); - case 178: + case 182: return textSpan(node, ts.findNextToken(node.expression, node)); - case 183: + case 187: return textSpan(node, ts.findNextToken(node.expression, node)); - case 200: - case 201: + case 204: + case 205: return spanInNode(node.statements[0]); - case 186: + case 190: return spanInBlock(node.tryBlock); - case 185: + case 189: return textSpan(node, node.expression); - case 198: + case 202: return textSpan(node, node.exportName); - case 197: + case 201: return textSpan(node, node.moduleReference); - case 195: + case 199: if (ts.getModuleInstanceState(node) !== 1) { return undefined; } - case 191: - case 194: - case 206: - case 151: - case 152: + case 195: + case 198: + case 210: + case 153: + case 154: return textSpan(node); - case 182: + case 186: return spanInNode(node.statement); - case 192: - case 193: + case 196: + case 197: return undefined; case 22: case 1: @@ -28097,10 +32284,10 @@ var ts; case 80: return spanInNextNode(node); default: - if (node.parent.kind === 204 && node.parent.name === node) { + if (node.parent.kind === 208 && node.parent.name === node) { return spanInNode(node.parent.initializer); } - if (node.parent.kind === 154 && node.parent.type === node) { + if (node.parent.kind === 156 && node.parent.type === node) { return spanInNode(node.parent.expression); } if (ts.isAnyFunction(node.parent) && node.parent.type === node) { @@ -28110,11 +32297,11 @@ var ts; } } function spanInVariableDeclaration(variableDeclaration) { - if (variableDeclaration.parent.parent.kind === 178) { + if (variableDeclaration.parent.parent.kind === 182) { return spanInNode(variableDeclaration.parent.parent); } - var isParentVariableStatement = variableDeclaration.parent.parent.kind === 171; - var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === 177 && ts.contains(variableDeclaration.parent.parent.initializer.declarations, variableDeclaration); + var isParentVariableStatement = variableDeclaration.parent.parent.kind === 175; + var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === 181 && ts.contains(variableDeclaration.parent.parent.initializer.declarations, variableDeclaration); var declarations = isParentVariableStatement ? variableDeclaration.parent.parent.declarationList.declarations : isDeclarationOfForStatement ? variableDeclaration.parent.parent.initializer.declarations : undefined; if (variableDeclaration.initializer || (variableDeclaration.flags & 1)) { if (declarations && declarations[0] === variableDeclaration) { @@ -28154,7 +32341,7 @@ var ts; } } function canFunctionHaveSpanInWholeDeclaration(functionDeclaration) { - return !!(functionDeclaration.flags & 1) || (functionDeclaration.parent.kind === 191 && functionDeclaration.kind !== 129); + return !!(functionDeclaration.flags & 1) || (functionDeclaration.parent.kind === 195 && functionDeclaration.kind !== 131); } function spanInFunctionDeclaration(functionDeclaration) { if (!functionDeclaration.body) { @@ -28174,22 +32361,22 @@ var ts; } function spanInBlock(block) { switch (block.parent.kind) { - case 195: + case 199: if (ts.getModuleInstanceState(block.parent) !== 1) { return undefined; } - case 176: - case 174: + case 180: case 178: + case 182: return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]); - case 177: + case 181: return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(block.pos, sourceFile, block.parent), block.statements[0]); } return spanInNode(block.statements[0]); } function spanInForStatement(forStatement) { if (forStatement.initializer) { - if (forStatement.initializer.kind === 189) { + if (forStatement.initializer.kind === 193) { var variableDeclarationList = forStatement.initializer; if (variableDeclarationList.declarations.length > 0) { return spanInNode(variableDeclarationList.declarations[0]); @@ -28208,34 +32395,34 @@ var ts; } function spanInOpenBraceToken(node) { switch (node.parent.kind) { - case 194: + case 198: var enumDeclaration = node.parent; return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile)); - case 191: + case 195: var classDeclaration = node.parent; return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile)); - case 183: + case 187: return spanInNodeIfStartsOnSameLine(node.parent, node.parent.clauses[0]); } return spanInNode(node.parent); } function spanInCloseBraceToken(node) { switch (node.parent.kind) { - case 196: + case 200: if (ts.getModuleInstanceState(node.parent.parent) !== 1) { return undefined; } - case 194: - case 191: + case 198: + case 195: return textSpan(node); - case 170: + case 174: if (ts.isFunctionBlock(node.parent)) { return textSpan(node); } - case 203: + case 207: return spanInNode(node.parent.statements[node.parent.statements.length - 1]); ; - case 183: + case 187: var switchStatement = node.parent; var lastClause = switchStatement.clauses[switchStatement.clauses.length - 1]; if (lastClause) { @@ -28247,24 +32434,24 @@ var ts; } } function spanInOpenParenToken(node) { - if (node.parent.kind === 175) { + if (node.parent.kind === 179) { return spanInPreviousNode(node); } return spanInNode(node.parent); } function spanInCloseParenToken(node) { switch (node.parent.kind) { - case 156: - case 190: - case 157: - case 128: - case 127: + case 158: + case 194: + case 159: case 130: - case 131: case 129: - case 176: - case 175: - case 177: + case 132: + case 133: + case 131: + case 180: + case 179: + case 181: return spanInPreviousNode(node); default: return spanInNode(node.parent); @@ -28272,19 +32459,19 @@ var ts; return spanInNode(node.parent); } function spanInColonToken(node) { - if (ts.isAnyFunction(node.parent) || node.parent.kind === 204) { + if (ts.isAnyFunction(node.parent) || node.parent.kind === 208) { return spanInPreviousNode(node); } return spanInNode(node.parent); } function spanInGreaterThanOrLessThanToken(node) { - if (node.parent.kind === 154) { + if (node.parent.kind === 156) { return spanInNode(node.parent.expression); } return spanInNode(node.parent); } function spanInWhileKeyword(node) { - if (node.parent.kind === 175) { + if (node.parent.kind === 179) { return textSpan(node, ts.findNextToken(node.parent.expression, node.parent)); } return spanInNode(node.parent); diff --git a/bin/typescriptServices_internal.d.ts b/bin/typescriptServices_internal.d.ts index c6ba4f561f009..335d6e2920f61 100644 --- a/bin/typescriptServices_internal.d.ts +++ b/bin/typescriptServices_internal.d.ts @@ -32,6 +32,11 @@ declare module ts { function countWhere(array: T[], predicate: (x: T) => boolean): number; function filter(array: T[], f: (x: T) => boolean): T[]; function map(array: T[], f: (x: T) => U): U[]; + function flatMap(array: T[], f: (x: T) => U[]): U[]; + function foldLeft(array: T[], f: (a: T, x: T) => T): T; + function foldLeft(array: T[], f: (a: U, x: T) => U, initial: U): U; + function foldRight(array: T[], f: (a: T, x: T) => T): T; + function foldRight(array: T[], f: (a: U, x: T) => U, initial: U): U; function concatenate(array1: T[], array2: T[]): T[]; function deduplicate(array: T[]): T[]; function sum(array: any[], prop: string): number; @@ -158,11 +163,16 @@ declare module ts { function releaseStringWriter(writer: StringSymbolWriter): void; function getFullWidth(node: Node): number; function containsParseError(node: Node): boolean; + function isAwaitOrYield(node: Node): boolean; + function hasAwaitOrYield(node: Node): boolean; function getSourceFileOfNode(node: Node): SourceFile; function nodePosToString(node: Node): string; function getStartPosOfNode(node: Node): number; function nodeIsMissing(node: Node): boolean; + function nodeIsGenerated(node: Node): boolean; + function nodeIsMissingOrGenerated(node: Node): boolean; function nodeIsPresent(node: Node): boolean; + function nodeIsPresentOrGenerated(node: Node): boolean; function getTokenPosOfNode(node: Node, sourceFile?: SourceFile): number; function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node): string; function getTextOfNodeFromSourceText(sourceText: string, node: Node): string; @@ -187,11 +197,19 @@ declare module ts { function isAnyFunction(node: Node): boolean; function isFunctionBlock(node: Node): boolean; function isObjectLiteralMethod(node: Node): boolean; + function isObjectLiteralElement(node: Node): boolean; function getContainingFunction(node: Node): FunctionLikeDeclaration; + function getContainingParameter(node: Node): ParameterDeclaration; function getThisContainer(node: Node, includeArrowFunctions: boolean): Node; function getSuperContainer(node: Node, includeFunctions: boolean): Node; function getInvokedExpression(node: CallLikeExpression): Expression; function isExpression(node: Node): boolean; + function isUnaryExpression(node: Node): boolean; + function isLabeledOrIterationOrSwitchStatement(node: Node): boolean; + function isLogicalBinary(node: BinaryExpression): boolean; + function isAssignment(node: BinaryExpression): boolean; + function isDestructuringAssignment(node: BinaryExpression): boolean; + function isAnyAccessor(node: Node): boolean; function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean): boolean; function isExternalModuleImportDeclaration(node: Node): boolean; function getExternalModuleImportDeclarationExpression(node: Node): Expression; @@ -202,10 +220,13 @@ declare module ts { function isLiteralKind(kind: SyntaxKind): boolean; function isTextualLiteralKind(kind: SyntaxKind): boolean; function isTemplateLiteralKind(kind: SyntaxKind): boolean; + function isTemplateLiteralOrTemplateExpression(node: Node): boolean; function isBindingPattern(node: Node): boolean; + function isIdentifierOrBindingPattern(node: Node): boolean; function isInAmbientContext(node: Node): boolean; function isDeclaration(node: Node): boolean; function isStatement(n: Node): boolean; + function needsParenthesisForPropertyAccess(expression: Expression): boolean; function isDeclarationOrFunctionExpressionOrCatchVariableName(name: Node): boolean; function getClassBaseTypeNode(node: ClassDeclaration): TypeReferenceNode; function getClassImplementedTypeNodes(node: ClassDeclaration): NodeArray; @@ -216,6 +237,7 @@ declare module ts { function getFileReferenceFromReferencePath(comment: string, commentRange: CommentRange): ReferencePathMatchResult; function isKeyword(token: SyntaxKind): boolean; function isTrivia(token: SyntaxKind): boolean; + function isAsyncFunction(node: SignatureDeclaration): boolean; function isModifier(token: SyntaxKind): boolean; function textSpanEnd(span: TextSpan): number; function textSpanIsEmpty(span: TextSpan): boolean; @@ -242,6 +264,8 @@ declare module ts { * Vn. */ function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; + function reportUnexpectedNode(node: Node): void; + function reportUnexpectedNodeAfterVisit(visited: Node, node: Node): void; } declare module ts { var optionDeclarations: CommandLineOption[]; diff --git a/bin/typescript_internal.d.ts b/bin/typescript_internal.d.ts index b7def7258d9c1..ff60faa86f8ee 100644 --- a/bin/typescript_internal.d.ts +++ b/bin/typescript_internal.d.ts @@ -32,6 +32,11 @@ declare module "typescript" { function countWhere(array: T[], predicate: (x: T) => boolean): number; function filter(array: T[], f: (x: T) => boolean): T[]; function map(array: T[], f: (x: T) => U): U[]; + function flatMap(array: T[], f: (x: T) => U[]): U[]; + function foldLeft(array: T[], f: (a: T, x: T) => T): T; + function foldLeft(array: T[], f: (a: U, x: T) => U, initial: U): U; + function foldRight(array: T[], f: (a: T, x: T) => T): T; + function foldRight(array: T[], f: (a: U, x: T) => U, initial: U): U; function concatenate(array1: T[], array2: T[]): T[]; function deduplicate(array: T[]): T[]; function sum(array: any[], prop: string): number; @@ -158,11 +163,16 @@ declare module "typescript" { function releaseStringWriter(writer: StringSymbolWriter): void; function getFullWidth(node: Node): number; function containsParseError(node: Node): boolean; + function isAwaitOrYield(node: Node): boolean; + function hasAwaitOrYield(node: Node): boolean; function getSourceFileOfNode(node: Node): SourceFile; function nodePosToString(node: Node): string; function getStartPosOfNode(node: Node): number; function nodeIsMissing(node: Node): boolean; + function nodeIsGenerated(node: Node): boolean; + function nodeIsMissingOrGenerated(node: Node): boolean; function nodeIsPresent(node: Node): boolean; + function nodeIsPresentOrGenerated(node: Node): boolean; function getTokenPosOfNode(node: Node, sourceFile?: SourceFile): number; function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node): string; function getTextOfNodeFromSourceText(sourceText: string, node: Node): string; @@ -187,11 +197,19 @@ declare module "typescript" { function isAnyFunction(node: Node): boolean; function isFunctionBlock(node: Node): boolean; function isObjectLiteralMethod(node: Node): boolean; + function isObjectLiteralElement(node: Node): boolean; function getContainingFunction(node: Node): FunctionLikeDeclaration; + function getContainingParameter(node: Node): ParameterDeclaration; function getThisContainer(node: Node, includeArrowFunctions: boolean): Node; function getSuperContainer(node: Node, includeFunctions: boolean): Node; function getInvokedExpression(node: CallLikeExpression): Expression; function isExpression(node: Node): boolean; + function isUnaryExpression(node: Node): boolean; + function isLabeledOrIterationOrSwitchStatement(node: Node): boolean; + function isLogicalBinary(node: BinaryExpression): boolean; + function isAssignment(node: BinaryExpression): boolean; + function isDestructuringAssignment(node: BinaryExpression): boolean; + function isAnyAccessor(node: Node): boolean; function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean): boolean; function isExternalModuleImportDeclaration(node: Node): boolean; function getExternalModuleImportDeclarationExpression(node: Node): Expression; @@ -202,10 +220,13 @@ declare module "typescript" { function isLiteralKind(kind: SyntaxKind): boolean; function isTextualLiteralKind(kind: SyntaxKind): boolean; function isTemplateLiteralKind(kind: SyntaxKind): boolean; + function isTemplateLiteralOrTemplateExpression(node: Node): boolean; function isBindingPattern(node: Node): boolean; + function isIdentifierOrBindingPattern(node: Node): boolean; function isInAmbientContext(node: Node): boolean; function isDeclaration(node: Node): boolean; function isStatement(n: Node): boolean; + function needsParenthesisForPropertyAccess(expression: Expression): boolean; function isDeclarationOrFunctionExpressionOrCatchVariableName(name: Node): boolean; function getClassBaseTypeNode(node: ClassDeclaration): TypeReferenceNode; function getClassImplementedTypeNodes(node: ClassDeclaration): NodeArray; @@ -216,6 +237,7 @@ declare module "typescript" { function getFileReferenceFromReferencePath(comment: string, commentRange: CommentRange): ReferencePathMatchResult; function isKeyword(token: SyntaxKind): boolean; function isTrivia(token: SyntaxKind): boolean; + function isAsyncFunction(node: SignatureDeclaration): boolean; function isModifier(token: SyntaxKind): boolean; function textSpanEnd(span: TextSpan): number; function textSpanIsEmpty(span: TextSpan): boolean; @@ -242,6 +264,8 @@ declare module "typescript" { * Vn. */ function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; + function reportUnexpectedNode(node: Node): void; + function reportUnexpectedNodeAfterVisit(visited: Node, node: Node): void; } declare module "typescript" { var optionDeclarations: CommandLineOption[];