From 04d373ab9b72f33335867073f28b00d90ab189df Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 7 Mar 2015 13:59:18 -0800 Subject: [PATCH] Update LKG --- bin/tsc.js | 2234 +++++++++++------ bin/tsserver.js | 3447 +++++++++++++++++--------- bin/typescript.d.ts | 129 +- bin/typescript.js | 3420 ++++++++++++++++--------- bin/typescriptServices.d.ts | 129 +- bin/typescriptServices.js | 3420 ++++++++++++++++--------- bin/typescriptServices_internal.d.ts | 31 +- bin/typescript_internal.d.ts | 31 +- 8 files changed, 8436 insertions(+), 4405 deletions(-) diff --git a/bin/tsc.js b/bin/tsc.js index 48eeb47befc..573d07360c9 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -396,7 +396,9 @@ var ts; normalized.pop(); } else { - normalized.push(part); + if (part) { + normalized.push(part); + } } } } @@ -539,7 +541,7 @@ var ts; } ts.removeFileExtension = removeFileExtension; var backslashOrDoubleQuote = /[\"\\]/g; - var escapedCharsRegExp = /[\0-\19\t\v\f\b\0\r\n\u2028\u2029\u0085]/g; + var escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g; var escapedCharsMap = { "\0": "\\0", "\t": "\\t", @@ -554,20 +556,6 @@ var ts; "\u2029": "\\u2029", "\u0085": "\\u0085" }; - function escapeString(s) { - s = backslashOrDoubleQuote.test(s) ? s.replace(backslashOrDoubleQuote, getReplacement) : s; - s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s; - return s; - function getReplacement(c) { - return escapedCharsMap[c] || unicodeEscape(c); - } - function unicodeEscape(c) { - var hexCharCode = c.charCodeAt(0).toString(16); - var paddedHexCode = ("0000" + hexCharCode).slice(-4); - return "\\u" + paddedHexCode; - } - } - ts.escapeString = escapeString; function getDefaultLibFileName(options) { return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts"; } @@ -880,7 +868,6 @@ var ts; Trailing_comma_not_allowed: { code: 1009, category: 1, key: "Trailing comma not allowed." }, Asterisk_Slash_expected: { code: 1010, category: 1, key: "'*/' expected." }, Unexpected_token: { code: 1012, category: 1, key: "Unexpected token." }, - Catch_clause_parameter_cannot_have_a_type_annotation: { code: 1013, category: 1, key: "Catch clause parameter cannot have a type annotation." }, A_rest_parameter_must_be_last_in_a_parameter_list: { code: 1014, category: 1, key: "A rest parameter must be last in a parameter list." }, Parameter_cannot_have_question_mark_and_initializer: { code: 1015, category: 1, key: "Parameter cannot have question mark and initializer." }, A_required_parameter_cannot_follow_an_optional_parameter: { code: 1016, category: 1, key: "A required parameter cannot follow an optional parameter." }, @@ -988,7 +975,6 @@ var ts; const_declarations_must_be_initialized: { code: 1155, category: 1, key: "'const' declarations must be initialized" }, const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: 1, key: "'const' declarations can only be declared inside a block." }, let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: 1, key: "'let' declarations can only be declared inside a block." }, - Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: 1, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." }, 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." }, @@ -1025,6 +1011,11 @@ var ts; External_module_0_has_no_default_export_or_export_assignment: { code: 1192, category: 1, key: "External module '{0}' has no default export or export assignment." }, An_export_declaration_cannot_have_modifiers: { code: 1193, category: 1, key: "An export declaration cannot have modifiers." }, Export_declarations_are_not_permitted_in_an_internal_module: { code: 1194, category: 1, key: "Export declarations are not permitted in an internal module." }, + Catch_clause_variable_name_must_be_an_identifier: { code: 1195, category: 1, key: "Catch clause variable name must be an identifier." }, + Catch_clause_variable_cannot_have_a_type_annotation: { code: 1196, category: 1, key: "Catch clause variable cannot have a type annotation." }, + Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: 1, key: "Catch clause variable cannot have an initializer." }, + An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: 1, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, + Unterminated_Unicode_escape_sequence: { code: 1199, category: 1, key: "Unterminated Unicode escape sequence." }, 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." }, @@ -1198,6 +1189,14 @@ var ts; for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 2482, category: 1, key: "'for...of' statements are only available when targeting ECMAScript 6 or higher." }, The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation: { code: 2483, category: 1, key: "The left-hand side of a 'for...of' statement cannot use a type annotation." }, Export_declaration_conflicts_with_exported_declaration_of_0: { code: 2484, category: 1, key: "Export declaration conflicts with exported declaration of '{0}'" }, + The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant: { code: 2485, category: 1, key: "The left-hand side of a 'for...of' statement cannot be a previously defined constant." }, + The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant: { code: 2486, category: 1, key: "The left-hand side of a 'for...in' statement cannot be a previously defined constant." }, + Invalid_left_hand_side_in_for_of_statement: { code: 2487, category: 1, key: "Invalid left-hand side in 'for...of' statement." }, + The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator: { code: 2488, category: 1, key: "The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator." }, + The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method: { code: 2489, category: 1, key: "The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method." }, + The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property: { code: 2490, category: 1, key: "The type returned by the 'next()' method of an iterator must have a 'value' property." }, + The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern: { code: 2491, category: 1, key: "The left-hand side of a 'for...in' statement cannot be a destructuring pattern." }, + Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: 1, key: "Cannot redeclare identifier '{0}' in catch clause" }, 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}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: 1, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1267,6 +1266,7 @@ var ts; Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: 1, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: 1, key: "Parameter '{0}' of exported function has or is using private name '{1}'." }, Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: 1, key: "Exported type alias '{0}' has or is using private name '{1}'." }, + Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: 1, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." }, 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}" }, @@ -1342,25 +1342,24 @@ var ts; You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: 1, key: "You cannot rename elements that are defined in the standard TypeScript library." }, yield_expressions_are_not_currently_supported: { code: 9000, category: 1, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: 1, key: "Generators are not currently supported." }, - The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: 1, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, - for_of_statements_are_not_currently_supported: { code: 9003, category: 1, key: "'for...of' statements are not currently supported." } + The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: 1, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." } }; })(ts || (ts = {})); var ts; (function (ts) { var textToToken = { - "any": 112, + "any": 111, "as": 101, - "boolean": 113, + "boolean": 112, "break": 65, "case": 66, "catch": 67, "class": 68, "continue": 70, "const": 69, - "constructor": 114, + "constructor": 113, "debugger": 71, - "declare": 115, + "declare": 114, "default": 72, "delete": 73, "do": 74, @@ -1371,43 +1370,43 @@ var ts; "false": 79, "finally": 80, "for": 81, - "from": 102, + "from": 123, "function": 82, - "get": 116, + "get": 115, "if": 83, - "implements": 103, + "implements": 102, "import": 84, "in": 85, "instanceof": 86, - "interface": 104, - "let": 105, - "module": 117, + "interface": 103, + "let": 104, + "module": 116, "new": 87, "null": 88, - "number": 119, - "package": 106, - "private": 107, - "protected": 108, - "public": 109, - "require": 118, + "number": 118, + "package": 105, + "private": 106, + "protected": 107, + "public": 108, + "require": 117, "return": 89, - "set": 120, - "static": 110, - "string": 121, + "set": 119, + "static": 109, + "string": 120, "super": 90, "switch": 91, - "symbol": 122, + "symbol": 121, "this": 92, "throw": 93, "true": 94, "try": 95, - "type": 123, + "type": 122, "typeof": 96, "var": 97, "void": 98, "while": 99, "with": 100, - "yield": 111, + "yield": 110, "of": 124, "{": 14, "}": 15, @@ -1780,6 +1779,7 @@ var ts; var token; var tokenValue; var precedingLineBreak; + var hasExtendedUnicodeEscape; var tokenIsUnterminated; function error(message, length) { if (onError) { @@ -1829,10 +1829,16 @@ var ts; } return +(text.substring(start, pos)); } - function scanHexDigits(count, mustMatchCount) { + function scanExactNumberOfHexDigits(count) { + return scanHexDigits(count, false); + } + function scanMinimumNumberOfHexDigits(count) { + return scanHexDigits(count, true); + } + function scanHexDigits(minCount, scanAsManyAsPossible) { var digits = 0; var value = 0; - while (digits < count || !mustMatchCount) { + while (digits < minCount || scanAsManyAsPossible) { var ch = text.charCodeAt(pos); if (ch >= 48 && ch <= 57) { value = value * 16 + ch - 48; @@ -1849,7 +1855,7 @@ var ts; pos++; digits++; } - if (digits < count) { + if (digits < minCount) { value = -1; } return value; @@ -1962,16 +1968,15 @@ var ts; return "\'"; case 34: return "\""; - case 120: case 117: - var ch = scanHexDigits(ch === 120 ? 2 : 4, true); - if (ch >= 0) { - return String.fromCharCode(ch); - } - else { - error(ts.Diagnostics.Hexadecimal_digit_expected); - return ""; + if (pos < len && text.charCodeAt(pos) === 123) { + hasExtendedUnicodeEscape = true; + pos++; + return scanExtendedUnicodeEscape(); } + return scanHexadecimalEscape(4); + case 120: + return scanHexadecimalEscape(2); case 13: if (pos < len && text.charCodeAt(pos) === 10) { pos++; @@ -1984,11 +1989,57 @@ var ts; return String.fromCharCode(ch); } } + function scanHexadecimalEscape(numDigits) { + var escapedValue = scanExactNumberOfHexDigits(numDigits); + if (escapedValue >= 0) { + return String.fromCharCode(escapedValue); + } + else { + error(ts.Diagnostics.Hexadecimal_digit_expected); + return ""; + } + } + function scanExtendedUnicodeEscape() { + var escapedValue = scanMinimumNumberOfHexDigits(1); + var isInvalidExtendedEscape = false; + if (escapedValue < 0) { + error(ts.Diagnostics.Hexadecimal_digit_expected); + isInvalidExtendedEscape = true; + } + else if (escapedValue > 0x10FFFF) { + error(ts.Diagnostics.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive); + isInvalidExtendedEscape = true; + } + if (pos >= len) { + error(ts.Diagnostics.Unexpected_end_of_text); + isInvalidExtendedEscape = true; + } + else if (text.charCodeAt(pos) == 125) { + pos++; + } + else { + error(ts.Diagnostics.Unterminated_Unicode_escape_sequence); + isInvalidExtendedEscape = true; + } + if (isInvalidExtendedEscape) { + return ""; + } + return utf16EncodeAsString(escapedValue); + } + function utf16EncodeAsString(codePoint) { + ts.Debug.assert(0x0 <= codePoint && codePoint <= 0x10FFFF); + if (codePoint <= 65535) { + return String.fromCharCode(codePoint); + } + var codeUnit1 = Math.floor((codePoint - 65536) / 1024) + 0xD800; + var codeUnit2 = ((codePoint - 65536) % 1024) + 0xDC00; + return String.fromCharCode(codeUnit1, codeUnit2); + } function peekUnicodeEscape() { if (pos + 5 < len && text.charCodeAt(pos + 1) === 117) { var start = pos; pos += 2; - var value = scanHexDigits(4, true); + var value = scanExactNumberOfHexDigits(4); pos = start; return value; } @@ -2050,6 +2101,7 @@ var ts; } function scan() { startPos = pos; + hasExtendedUnicodeEscape = false; precedingLineBreak = false; tokenIsUnterminated = false; while (true) { @@ -2201,7 +2253,7 @@ var ts; case 48: if (pos + 2 < len && (text.charCodeAt(pos + 1) === 88 || text.charCodeAt(pos + 1) === 120)) { pos += 2; - var value = scanHexDigits(1, false); + var value = scanMinimumNumberOfHexDigits(1); if (value < 0) { error(ts.Diagnostics.Hexadecimal_digit_expected); value = 0; @@ -2471,6 +2523,7 @@ var ts; getTokenPos: function () { return tokenPos; }, getTokenText: function () { return text.substring(tokenPos, pos); }, getTokenValue: function () { return tokenValue; }, + hasExtendedUnicodeEscape: function () { return hasExtendedUnicodeEscape; }, hasPrecedingLineBreak: function () { return precedingLineBreak; }, isIdentifier: function () { return token === 64 || token > 100; }, isReservedWord: function () { return token >= 65 && token <= 100; }, @@ -2619,35 +2672,51 @@ var ts; return ts.getBaseFileName(moduleName).replace(/\W/g, "_"); } ts.makeIdentifierFromModuleName = makeIdentifierFromModuleName; + function isBlockOrCatchScoped(declaration) { + return (getCombinedNodeFlags(declaration) & 12288) !== 0 || + isCatchClauseVariableDeclaration(declaration); + } + ts.isBlockOrCatchScoped = isBlockOrCatchScoped; + function isCatchClauseVariableDeclaration(declaration) { + return declaration && + declaration.kind === 193 && + declaration.parent && + declaration.parent.kind === 216; + } + ts.isCatchClauseVariableDeclaration = isCatchClauseVariableDeclaration; function declarationNameToString(name) { return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name); } ts.declarationNameToString = declarationNameToString; function createDiagnosticForNode(node, message, arg0, arg1, arg2) { - node = getErrorSpanForNode(node); - var file = getSourceFileOfNode(node); - var start = getTokenPosOfNode(node, file); - var length = node.end - start; - return ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2); + var sourceFile = getSourceFileOfNode(node); + var span = getErrorSpanForNode(sourceFile, node); + return ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2); } ts.createDiagnosticForNode = createDiagnosticForNode; function createDiagnosticForNodeFromMessageChain(node, messageChain) { - node = getErrorSpanForNode(node); - var file = getSourceFileOfNode(node); - var start = ts.skipTrivia(file.text, node.pos); - var length = node.end - start; + var sourceFile = getSourceFileOfNode(node); + var span = getErrorSpanForNode(sourceFile, node); return { - file: file, - start: start, - length: length, + file: sourceFile, + start: span.start, + length: span.length, code: messageChain.code, category: messageChain.category, messageText: messageChain.next ? messageChain : messageChain.messageText }; } ts.createDiagnosticForNodeFromMessageChain = createDiagnosticForNodeFromMessageChain; - function getErrorSpanForNode(node) { - var errorSpan; + function getSpanOfTokenAtPosition(sourceFile, pos) { + var scanner = ts.createScanner(sourceFile.languageVersion, true, sourceFile.text); + scanner.setTextPos(pos); + scanner.scan(); + var start = scanner.getTokenPos(); + return createTextSpanFromBounds(start, scanner.getTextPos()); + } + ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; + function getErrorSpanForNode(sourceFile, node) { + var errorNode = node; switch (node.kind) { case 193: case 150: @@ -2656,10 +2725,16 @@ var ts; case 200: case 199: case 219: - errorSpan = node.name; + case 195: + case 160: + errorNode = node.name; break; } - return errorSpan && errorSpan.pos < errorSpan.end ? errorSpan : node; + if (errorNode === undefined) { + return getSpanOfTokenAtPosition(sourceFile, node.pos); + } + var pos = nodeIsMissing(errorNode) ? errorNode.pos : ts.skipTrivia(sourceFile.text, errorNode.pos); + return createTextSpanFromBounds(pos, errorNode.end); } ts.getErrorSpanForNode = getErrorSpanForNode; function isExternalModule(file) { @@ -2667,7 +2742,7 @@ var ts; } ts.isExternalModule = isExternalModule; function isDeclarationFile(file) { - return (file.flags & 1024) !== 0; + return (file.flags & 2048) !== 0; } ts.isDeclarationFile = isDeclarationFile; function isConstEnumDeclaration(node) { @@ -2697,11 +2772,11 @@ var ts; } ts.getCombinedNodeFlags = getCombinedNodeFlags; function isConst(node) { - return !!(getCombinedNodeFlags(node) & 4096); + return !!(getCombinedNodeFlags(node) & 8192); } ts.isConst = isConst; function isLet(node) { - return !!(getCombinedNodeFlags(node) & 2048); + return !!(getCombinedNodeFlags(node) & 4096); } ts.isLet = isLet; function isPrologueDirective(node) { @@ -2753,7 +2828,24 @@ var ts; } } ts.forEachReturnStatement = forEachReturnStatement; - function isAnyFunction(node) { + function isVariableLike(node) { + if (node) { + switch (node.kind) { + case 150: + case 219: + case 128: + case 217: + case 130: + case 129: + case 218: + case 193: + return true; + } + } + return false; + } + ts.isVariableLike = isVariableLike; + function isFunctionLike(node) { if (node) { switch (node.kind) { case 133: @@ -2777,9 +2869,9 @@ var ts; } return false; } - ts.isAnyFunction = isAnyFunction; + ts.isFunctionLike = isFunctionLike; function isFunctionBlock(node) { - return node && node.kind === 174 && isAnyFunction(node.parent); + return node && node.kind === 174 && isFunctionLike(node.parent); } ts.isFunctionBlock = isFunctionBlock; function isObjectLiteralMethod(node) { @@ -2789,7 +2881,7 @@ var ts; function getContainingFunction(node) { while (true) { node = node.parent; - if (!node || isAnyFunction(node)) { + if (!node || isFunctionLike(node)) { return node; } } @@ -3027,12 +3119,12 @@ var ts; } ts.isTemplateLiteralKind = isTemplateLiteralKind; function isBindingPattern(node) { - return node.kind === 149 || node.kind === 148; + return !!node && (node.kind === 149 || node.kind === 148); } ts.isBindingPattern = isBindingPattern; function isInAmbientContext(node) { while (node) { - if (node.flags & (2 | 1024)) { + if (node.flags & (2 | 2048)) { return true; } node = node.parent; @@ -3042,31 +3134,33 @@ var ts; ts.isInAmbientContext = isInAmbientContext; function isDeclaration(node) { switch (node.kind) { - case 127: - case 128: - case 193: + case 161: case 150: - case 130: - case 129: - case 217: - case 218: + case 196: + case 133: + case 199: case 219: + case 211: + case 195: + case 160: + case 134: + case 204: + case 202: + case 207: + case 197: case 132: case 131: - case 195: - case 134: - case 135: - case 133: - case 196: - case 197: - case 198: - case 199: case 200: - case 202: - case 204: - case 207: case 205: - case 211: + case 128: + case 217: + case 130: + case 129: + case 135: + case 218: + case 198: + case 127: + case 193: return true; } return false; @@ -3099,27 +3193,29 @@ var ts; } } ts.isStatement = isStatement; - function isDeclarationOrFunctionExpressionOrCatchVariableName(name) { + function isDeclarationName(name) { if (name.kind !== 64 && name.kind !== 8 && name.kind !== 7) { return false; } var parent = name.parent; - if (isDeclaration(parent) || parent.kind === 160) { - return parent.name === name; + if (parent.kind === 207 || parent.kind === 211) { + if (parent.propertyName) { + return true; + } } - if (parent.kind === 216) { + if (isDeclaration(parent)) { return parent.name === name; } return false; } - ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName; + ts.isDeclarationName = isDeclarationName; function getClassBaseTypeNode(node) { var heritageClause = getHeritageClause(node.heritageClauses, 78); return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined; } ts.getClassBaseTypeNode = getClassBaseTypeNode; function getClassImplementedTypeNodes(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 103); + var heritageClause = getHeritageClause(node.heritageClauses, 102); return heritageClause ? heritageClause.types : undefined; } ts.getClassImplementedTypeNodes = getClassImplementedTypeNodes; @@ -3233,13 +3329,14 @@ var ts; ts.isESSymbolIdentifier = isESSymbolIdentifier; function isModifier(token) { switch (token) { - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: case 77: - case 115: + case 114: case 69: + case 72: return true; } return false; @@ -3354,6 +3451,42 @@ var ts; return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); } ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; + function nodeStartsNewLexicalEnvironment(n) { + return isFunctionLike(n) || n.kind === 200 || n.kind === 220; + } + ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment; + function nodeIsSynthesized(node) { + return node.pos === -1 && node.end === -1; + } + ts.nodeIsSynthesized = nodeIsSynthesized; + function createSynthesizedNode(kind, startsOnNewLine) { + var node = ts.createNode(kind); + node.pos = -1; + node.end = -1; + node.startsOnNewLine = startsOnNewLine; + return node; + } + ts.createSynthesizedNode = createSynthesizedNode; + function generateUniqueName(baseName, isExistingName) { + if (baseName.charCodeAt(0) !== 95) { + var baseName = "_" + baseName; + if (!isExistingName(baseName)) { + return baseName; + } + } + if (baseName.charCodeAt(baseName.length - 1) !== 95) { + baseName += "_"; + } + var i = 1; + while (true) { + var name = baseName + i; + if (!isExistingName(name)) { + return name; + } + i++; + } + } + ts.generateUniqueName = generateUniqueName; function createDiagnosticCollection() { var nonFileDiagnostics = []; var fileDiagnostics = {}; @@ -3419,6 +3552,39 @@ var ts; } } ts.createDiagnosticCollection = createDiagnosticCollection; + var escapedCharsRegExp = /[\\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g; + var escapedCharsMap = { + "\0": "\\0", + "\t": "\\t", + "\v": "\\v", + "\f": "\\f", + "\b": "\\b", + "\r": "\\r", + "\n": "\\n", + "\\": "\\\\", + "\"": "\\\"", + "\u2028": "\\u2028", + "\u2029": "\\u2029", + "\u0085": "\\u0085" + }; + function escapeString(s) { + s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s; + return s; + function getReplacement(c) { + return escapedCharsMap[c] || get16BitUnicodeEscapeSequence(c.charCodeAt(0)); + } + } + ts.escapeString = escapeString; + function get16BitUnicodeEscapeSequence(charCode) { + var hexCharCode = charCode.toString(16).toUpperCase(); + var paddedHexCode = ("0000" + hexCharCode).slice(-4); + return "\\u" + paddedHexCode; + } + var nonAsciiCharacters = /[^\u0000-\u007F]/g; + function escapeNonAsciiCharacters(s) { + return nonAsciiCharacters.test(s) ? s.replace(nonAsciiCharacters, function (c) { return get16BitUnicodeEscapeSequence(c.charCodeAt(0)); }) : s; + } + ts.escapeNonAsciiCharacters = escapeNonAsciiCharacters; })(ts || (ts = {})); var ts; (function (ts) { @@ -3529,6 +3695,7 @@ var ts; return visitNodes(cbNodes, node.properties); case 153: return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.dotToken) || visitNode(cbNode, node.name); case 154: return visitNode(cbNode, node.expression) || @@ -3565,7 +3732,9 @@ var ts; visitNode(cbNode, node.right); case 168: return visitNode(cbNode, node.condition) || + visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || + visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 171: return visitNode(cbNode, node.expression); @@ -3631,8 +3800,7 @@ var ts; visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 216: - return visitNode(cbNode, node.name) || - visitNode(cbNode, node.type) || + return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 196: return visitNodes(cbNodes, node.modifiers) || @@ -3687,7 +3855,7 @@ var ts; visitNode(cbNode, node.name); case 208: return visitNodes(cbNodes, node.modifiers) || - visitNode(cbNode, node.exportName); + visitNode(cbNode, node.expression); case 169: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 173: @@ -3729,13 +3897,14 @@ var ts; ; function modifierToFlag(token) { switch (token) { - case 110: return 128; - case 109: return 16; - case 108: return 64; - case 107: return 32; + case 109: return 128; + case 108: return 16; + case 107: return 64; + case 106: return 32; case 77: return 1; - case 115: return 2; - case 69: return 4096; + case 114: return 2; + case 69: return 8192; + case 72: return 256; } return 0; } @@ -4057,7 +4226,7 @@ var ts; sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = ts.normalizePath(fileName); - sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 1024 : 0; + sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 2048 : 0; var contextFlags = 0; var parseErrorBeforeNextFinishedNode = false; var scanner = ts.createScanner(languageVersion, true, sourceText, scanError); @@ -4204,10 +4373,10 @@ var ts; if (token === 64) { return true; } - if (token === 111 && inYieldContext()) { + if (token === 110 && inYieldContext()) { return false; } - return inStrictModeContext() ? token > 111 : token > 100; + return inStrictModeContext() ? token > 110 : token > 100; } function parseExpected(kind, diagnosticMessage) { if (token === kind) { @@ -4231,12 +4400,14 @@ var ts; } function parseOptionalToken(t) { if (token === t) { - var node = createNode(t); - nextToken(); - return finishNode(node); + return parseTokenNode(); } return undefined; } + function parseExpectedToken(t, reportAtCurrentPosition, diagnosticMessage, arg0) { + return parseOptionalToken(t) || + createMissingNode(t, reportAtCurrentPosition, diagnosticMessage, arg0); + } function parseTokenNode() { var node = createNode(token); nextToken(); @@ -4355,14 +4526,24 @@ var ts; } if (token === 77) { nextToken(); + if (token === 72) { + return lookAhead(nextTokenIsClassOrFunction); + } return token !== 35 && token !== 14 && canFollowModifier(); } + if (token === 72) { + return nextTokenIsClassOrFunction(); + } nextToken(); return canFollowModifier(); } function canFollowModifier() { return token === 18 || token === 14 || token === 35 || isLiteralPropertyName(); } + function nextTokenIsClassOrFunction() { + nextToken(); + return token === 68 || token === 82; + } function isListElement(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); if (node) { @@ -4415,7 +4596,7 @@ var ts; return isIdentifier(); } function isNotHeritageClauseTypeName() { - if (token === 103 || + if (token === 102 || token === 78) { return lookAhead(nextTokenIsIdentifier); } @@ -4439,11 +4620,11 @@ var ts; case 4: return token === 15 || token === 66 || token === 72; case 8: - return token === 14 || token === 78 || token === 103; + return token === 14 || token === 78 || token === 102; case 9: return isVariableDeclaratorListTerminator(); case 16: - return token === 25 || token === 16 || token === 14 || token === 78 || token === 103; + return token === 25 || token === 16 || token === 14 || token === 78 || token === 102; case 12: return token === 17 || token === 22; case 14: @@ -4779,7 +4960,7 @@ var ts; literal = parseLiteralNode(); } else { - literal = createMissingNode(13, false, ts.Diagnostics._0_expected, ts.tokenToString(15)); + literal = parseExpectedToken(13, false, ts.Diagnostics._0_expected, ts.tokenToString(15)); } span.literal = literal; return finishNode(span); @@ -4788,6 +4969,9 @@ var ts; var node = createNode(token); var text = scanner.getTokenValue(); node.text = internName ? internIdentifier(text) : text; + if (scanner.hasExtendedUnicodeEscape()) { + node.hasExtendedUnicodeEscape = true; + } if (scanner.isUnterminated()) { node.isUnterminated = true; } @@ -4795,7 +4979,7 @@ var ts; nextToken(); finishNode(node); if (node.kind === 7 && sourceText.charCodeAt(tokenPos) === 48 && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { - node.flags |= 8192; + node.flags |= 16384; } return node; } @@ -5073,11 +5257,11 @@ var ts; } function parseNonArrayType() { switch (token) { + case 111: + case 120: + case 118: case 112: case 121: - case 119: - case 113: - case 122: var node = tryParse(parseKeywordAndNoDot); return node || parseTypeReference(); case 98: @@ -5096,11 +5280,11 @@ var ts; } function isStartOfType() { switch (token) { + case 111: + case 120: + case 118: case 112: case 121: - case 119: - case 113: - case 122: case 98: case 96: case 14: @@ -5221,7 +5405,7 @@ var ts; case 39: case 24: case 64: - case 111: + case 110: return true; default: if (isBinaryOperator()) { @@ -5268,7 +5452,7 @@ var ts; return parseConditionalExpressionRest(expr); } function isYieldExpression() { - if (token === 111) { + if (token === 110) { if (inYieldContext()) { return true; } @@ -5393,13 +5577,15 @@ var ts; return parseAssignmentExpressionOrHigher(); } function parseConditionalExpressionRest(leftOperand) { - if (!parseOptional(50)) { + var questionToken = parseOptionalToken(50); + if (!questionToken) { return leftOperand; } var node = createNode(168, leftOperand.pos); node.condition = leftOperand; + node.questionToken = questionToken; node.whenTrue = allowInAnd(parseAssignmentExpressionOrHigher); - parseExpected(51); + node.colonToken = parseExpectedToken(51, false, ts.Diagnostics._0_expected, ts.tokenToString(51)); node.whenFalse = parseAssignmentExpressionOrHigher(); return finishNode(node); } @@ -5548,7 +5734,7 @@ var ts; } var node = createNode(153, expression.pos); node.expression = expression; - parseExpected(20, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); + node.dotToken = parseExpectedToken(20, false, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); node.name = parseRightSideOfDot(true); return finishNode(node); } @@ -5562,10 +5748,11 @@ var ts; } function parseMemberExpressionRest(expression) { while (true) { - var dotOrBracketStart = scanner.getTokenPos(); - if (parseOptional(20)) { + var dotToken = parseOptionalToken(20); + if (dotToken) { var propertyAccess = createNode(153, expression.pos); propertyAccess.expression = expression; + propertyAccess.dotToken = dotToken; propertyAccess.name = parseRightSideOfDot(true); expression = finishNode(propertyAccess); continue; @@ -5717,16 +5904,16 @@ var ts; var node = createNode(151); parseExpected(18); if (scanner.hasPrecedingLineBreak()) - node.flags |= 256; + node.flags |= 512; node.elements = parseDelimitedList(14, parseArgumentOrArrayLiteralElement); parseExpected(19); return finishNode(node); } function tryParseAccessorDeclaration(fullStart, modifiers) { - if (parseContextualModifier(116)) { + if (parseContextualModifier(115)) { return parseAccessorDeclaration(134, fullStart, modifiers); } - else if (parseContextualModifier(120)) { + else if (parseContextualModifier(119)) { return parseAccessorDeclaration(135, fullStart, modifiers); } return undefined; @@ -5765,7 +5952,7 @@ var ts; var node = createNode(152); parseExpected(14); if (scanner.hasPrecedingLineBreak()) { - node.flags |= 256; + node.flags |= 512; } node.properties = parseDelimitedList(13, parseObjectLiteralElement, true); parseExpected(15); @@ -5852,7 +6039,7 @@ var ts; parseExpected(16); var initializer = undefined; if (token !== 22) { - if (token === 97 || token === 105 || token === 69) { + if (token === 97 || token === 104 || token === 69) { initializer = parseVariableDeclarationList(true); } else { @@ -5968,9 +6155,9 @@ var ts; function parseCatchClause() { var result = createNode(216); parseExpected(67); - parseExpected(16); - result.name = parseIdentifier(); - result.type = parseTypeAnnotation(); + if (parseExpected(16)) { + result.variableDeclaration = parseVariableDeclaration(); + } parseExpected(17); result.block = parseBlock(false, false); return finishNode(result); @@ -6009,7 +6196,7 @@ var ts; return !inErrorRecovery; case 14: case 97: - case 105: + case 104: case 82: case 83: case 74: @@ -6029,18 +6216,18 @@ var ts; case 69: var isConstEnum = lookAhead(nextTokenIsEnumKeyword); return !isConstEnum; - case 104: + case 103: case 68: - case 117: + case 116: case 76: - case 123: + case 122: if (isDeclarationStart()) { return false; } - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { return false; } @@ -6093,7 +6280,7 @@ var ts; return parseTryStatement(); case 71: return parseDebuggerStatement(); - case 105: + case 104: if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), undefined); } @@ -6117,7 +6304,7 @@ var ts; return undefined; } return parseVariableStatement(start, modifiers); - case 105: + case 104: if (!isLetDeclaration()) { return undefined; } @@ -6200,11 +6387,11 @@ var ts; switch (token) { case 97: break; - case 105: - node.flags |= 2048; + case 104: + node.flags |= 4096; break; case 69: - node.flags |= 4096; + node.flags |= 8192; break; default: ts.Debug.fail(); @@ -6236,7 +6423,7 @@ var ts; setModifiers(node, modifiers); parseExpected(82); node.asteriskToken = parseOptionalToken(35); - node.name = parseIdentifier(); + node.name = node.flags & 256 ? parseOptionalIdentifier() : parseIdentifier(); fillSignature(51, !!node.asteriskToken, false, node); node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, ts.Diagnostics.or_expected); return finishNode(node); @@ -6244,7 +6431,7 @@ var ts; function parseConstructorDeclaration(pos, modifiers) { var node = createNode(133, pos); setModifiers(node, modifiers); - parseExpected(114); + parseExpected(113); fillSignature(51, false, false, node); node.body = parseFunctionBlockOrSemicolon(false, ts.Diagnostics.or_expected); return finishNode(node); @@ -6305,7 +6492,7 @@ var ts; return true; } if (idToken !== undefined) { - if (!ts.isKeyword(idToken) || idToken === 120 || idToken === 116) { + if (!ts.isKeyword(idToken) || idToken === 119 || idToken === 115) { return true; } switch (token) { @@ -6350,7 +6537,7 @@ var ts; if (accessor) { return accessor; } - if (token === 114) { + if (token === 113) { return parseConstructorDeclaration(fullStart, modifiers); } if (isIndexSignature()) { @@ -6369,7 +6556,7 @@ var ts; var node = createNode(196, fullStart); setModifiers(node, modifiers); parseExpected(68); - node.name = parseIdentifier(); + node.name = node.flags & 256 ? parseOptionalIdentifier() : parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(true); if (parseExpected(14)) { @@ -6391,7 +6578,7 @@ var ts; return parseList(19, false, parseHeritageClause); } function parseHeritageClause() { - if (token === 78 || token === 103) { + if (token === 78 || token === 102) { var node = createNode(215); node.token = token; nextToken(); @@ -6401,7 +6588,7 @@ var ts; return undefined; } function isHeritageClause() { - return token === 78 || token === 103; + return token === 78 || token === 102; } function parseClassMembers() { return parseList(6, false, parseClassElement); @@ -6409,7 +6596,7 @@ var ts; function parseInterfaceDeclaration(fullStart, modifiers) { var node = createNode(197, fullStart); setModifiers(node, modifiers); - parseExpected(104); + parseExpected(103); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(false); @@ -6419,7 +6606,7 @@ var ts; function parseTypeAliasDeclaration(fullStart, modifiers) { var node = createNode(198, fullStart); setModifiers(node, modifiers); - parseExpected(123); + parseExpected(122); node.name = parseIdentifier(); parseExpected(52); node.type = parseType(); @@ -6473,11 +6660,11 @@ var ts; return finishNode(node); } function parseModuleDeclaration(fullStart, modifiers) { - parseExpected(117); + parseExpected(116); return token === 8 ? parseAmbientExternalModuleDeclaration(fullStart, modifiers) : parseInternalModuleTail(fullStart, modifiers, modifiers ? modifiers.flags : 0); } function isExternalModuleReference() { - return token === 118 && + return token === 117 && lookAhead(nextTokenIsOpenParen); } function nextTokenIsOpenParen() { @@ -6486,7 +6673,7 @@ var ts; function nextTokenIsCommaOrFromKeyword() { nextToken(); return token === 23 || - token === 102; + token === 123; } function parseImportDeclarationOrImportEqualsDeclaration(fullStart, modifiers) { parseExpected(84); @@ -6494,7 +6681,7 @@ var ts; var identifier; if (isIdentifier()) { identifier = parseIdentifier(); - if (token !== 23 && token !== 102) { + if (token !== 23 && token !== 123) { var importEqualsDeclaration = createNode(202, fullStart); setModifiers(importEqualsDeclaration, modifiers); importEqualsDeclaration.name = identifier; @@ -6510,7 +6697,7 @@ var ts; token === 35 || token === 14) { importDeclaration.importClause = parseImportClause(identifier, afterImportPos); - parseExpected(102); + parseExpected(123); } importDeclaration.moduleSpecifier = parseModuleSpecifier(); parseSemicolon(); @@ -6532,7 +6719,7 @@ var ts; } function parseExternalModuleReference() { var node = createNode(212); - parseExpected(118); + parseExpected(117); parseExpected(16); node.expression = parseModuleSpecifier(); parseExpected(17); @@ -6590,22 +6777,28 @@ var ts; var node = createNode(209, fullStart); setModifiers(node, modifiers); if (parseOptional(35)) { - parseExpected(102); + parseExpected(123); node.moduleSpecifier = parseModuleSpecifier(); } else { node.exportClause = parseNamedImportsOrExports(210); - if (parseOptional(102)) { + if (parseOptional(123)) { node.moduleSpecifier = parseModuleSpecifier(); } } parseSemicolon(); return finishNode(node); } - function parseExportAssignmentTail(fullStart, modifiers) { + function parseExportAssignment(fullStart, modifiers) { var node = createNode(208, fullStart); setModifiers(node, modifiers); - node.exportName = parseIdentifier(); + if (parseOptional(52)) { + node.isExportEquals = true; + } + else { + parseExpected(72); + } + node.expression = parseAssignmentExpressionOrHigher(); parseSemicolon(); return finishNode(node); } @@ -6618,24 +6811,24 @@ var ts; case 69: case 82: return true; - case 105: + case 104: return isLetDeclaration(); case 68: - case 104: + case 103: case 76: - case 123: + case 122: return lookAhead(nextTokenIsIdentifierOrKeyword); case 84: return lookAhead(nextTokenCanFollowImportKeyword); - case 117: + case 116: return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); case 77: return lookAhead(nextTokenCanFollowExportKeyword); - case 115: - case 109: - case 107: + case 114: case 108: - case 110: + case 106: + case 107: + case 109: return lookAhead(nextTokenIsDeclarationStart); } } @@ -6658,7 +6851,7 @@ var ts; function nextTokenCanFollowExportKeyword() { nextToken(); return token === 52 || token === 35 || - token === 14 || isDeclarationStart(); + token === 14 || token === 72 || isDeclarationStart(); } function nextTokenIsDeclarationStart() { nextToken(); @@ -6672,8 +6865,8 @@ var ts; var modifiers = parseModifiers(); if (token === 77) { nextToken(); - if (parseOptional(52)) { - return parseExportAssignmentTail(fullStart, modifiers); + if (token === 72 || token === 52) { + return parseExportAssignment(fullStart, modifiers); } if (token === 35 || token === 14) { return parseExportDeclaration(fullStart, modifiers); @@ -6681,20 +6874,20 @@ var ts; } switch (token) { case 97: - case 105: + case 104: case 69: return parseVariableStatement(fullStart, modifiers); case 82: return parseFunctionDeclaration(fullStart, modifiers); case 68: return parseClassDeclaration(fullStart, modifiers); - case 104: + case 103: return parseInterfaceDeclaration(fullStart, modifiers); - case 123: + case 122: return parseTypeAliasDeclaration(fullStart, modifiers); case 76: return parseEnumDeclaration(fullStart, modifiers); - case 117: + case 116: return parseModuleDeclaration(fullStart, modifiers); case 84: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, modifiers); @@ -6860,7 +7053,8 @@ var ts; var Symbol = ts.objectAllocator.getSymbolConstructor(); if (!file.locals) { file.locals = {}; - container = blockScopeContainer = file; + container = file; + setBlockScopeContainer(file, false); bind(file); file.symbolCount = symbolCount; } @@ -6868,6 +7062,12 @@ var ts; symbolCount++; return new Symbol(flags, name); } + function setBlockScopeContainer(node, cleanLocals) { + blockScopeContainer = node; + if (cleanLocals) { + blockScopeContainer.locals = undefined; + } + } function addDeclarationToSymbol(symbol, node, symbolKind) { symbol.flags |= symbolKind; if (!symbol.declarations) @@ -6904,6 +7104,13 @@ var ts; return "__new"; case 138: return "__index"; + case 209: + return "__export"; + case 208: + return "default"; + case 195: + case 196: + return node.flags & 256 ? "default" : undefined; } } function getDisplayName(node) { @@ -6911,7 +7118,7 @@ var ts; } function declareSymbol(symbols, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); - var name = getDeclarationName(node); + var name = node.flags & 256 && parent ? "default" : getDeclarationName(node); if (name !== undefined) { var symbol = ts.hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); if (symbol.flags & excludes) { @@ -6920,9 +7127,9 @@ var ts; } var message = symbol.flags & 2 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; ts.forEach(symbol.declarations, function (declaration) { - file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name, message, getDisplayName(declaration))); + file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); }); - file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name, message, getDisplayName(node))); + file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message, getDisplayName(node))); symbol = createSymbol(0, name); } } @@ -6992,7 +7199,7 @@ var ts; lastContainer = container; } if (isBlockScopeContainer) { - blockScopeContainer = node; + setBlockScopeContainer(node, (symbolKind & 255504) === 0 && node.kind !== 220); } ts.forEachChild(node, bind); container = saveContainer; @@ -7060,12 +7267,6 @@ var ts; } } } - function bindExportDeclaration(node) { - if (!node.exportClause) { - (container.exportStars || (container.exportStars = [])).push(node); - } - bindChildren(node, 0, false); - } function bindFunctionOrConstructorType(node) { var symbol = createSymbol(131072, getDeclarationName(node)); addDeclarationToSymbol(symbol, node, 131072); @@ -7081,14 +7282,7 @@ var ts; bindChildren(node, symbolKind, isBlockScopeContainer); } function bindCatchVariableDeclaration(node) { - var symbol = createSymbol(1, node.name.text || "__missing"); - addDeclarationToSymbol(symbol, node, 1); - var saveParent = parent; - var savedBlockScopeContainer = blockScopeContainer; - parent = blockScopeContainer = node; - ts.forEachChild(node, bind); - parent = saveParent; - blockScopeContainer = savedBlockScopeContainer; + bindChildren(node, 0, true); } function bindBlockScopedVariableDeclaration(node) { switch (blockScopeContainer.kind) { @@ -7125,7 +7319,7 @@ var ts; if (ts.isBindingPattern(node.name)) { bindChildren(node, 0, false); } - else if (ts.getCombinedNodeFlags(node) & 6144) { + else if (ts.isBlockOrCatchScoped(node)) { bindBlockScopedVariableDeclaration(node); } else { @@ -7207,9 +7401,6 @@ var ts; case 211: bindDeclaration(node, 8388608, 8388608, false); break; - case 209: - bindExportDeclaration(node); - break; case 204: if (node.name) { bindDeclaration(node, 8388608, 8388608, false); @@ -7218,13 +7409,28 @@ var ts; bindChildren(node, 0, false); } break; + case 209: + if (!node.exportClause) { + declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0); + } + bindChildren(node, 0, false); + break; + case 208: + if (node.expression.kind === 64) { + declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 8388608); + } + else { + declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455); + } + bindChildren(node, 0, false); + break; case 220: if (ts.isExternalModule(node)) { bindAnonymousDeclaration(node, 512, '"' + ts.removeFileExtension(node.fileName) + '"', true); break; } case 174: - bindChildren(node, 0, !ts.isAnyFunction(node.parent)); + bindChildren(node, 0, !ts.isFunctionLike(node.parent)); break; case 216: case 181: @@ -7312,8 +7518,9 @@ var ts; isValidPropertyAccess: isValidPropertyAccess, getSignatureFromDeclaration: getSignatureFromDeclaration, isImplementationOfOverload: isImplementationOfOverload, - getAliasedSymbol: resolveImport, - getEmitResolver: getEmitResolver + getAliasedSymbol: resolveAlias, + getEmitResolver: getEmitResolver, + getExportsOfExternalModule: getExportsOfExternalModule }; var undefinedSymbol = createSymbol(4 | 67108864, "undefined"); var argumentsSymbol = createSymbol(4 | 67108864, "arguments"); @@ -7347,6 +7554,7 @@ var ts; var globalRegExpType; var globalTemplateStringsArrayType; var globalESSymbolType; + var globalIterableType; var anyArrayType; var tupleTypes = {}; var unionTypes = {}; @@ -7500,13 +7708,6 @@ var ts; } } } - function extendSymbolTable(target, source) { - for (var id in source) { - if (!ts.hasProperty(target, id)) { - target[id] = source[id]; - } - } - } function getSymbolLinks(symbol) { if (symbol.flags & 67108864) return symbol; @@ -7533,7 +7734,7 @@ var ts; return symbol; } if (symbol.flags & 8388608) { - var target = resolveImport(symbol); + var target = resolveAlias(symbol); if (target === unknownSymbol || target.flags & meaning) { return symbol; } @@ -7569,7 +7770,7 @@ var ts; break; case 200: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8914931)) { - if (!(result.flags & 8388608 && getDeclarationOfImportSymbol(result).kind === 211)) { + if (!(result.flags & 8388608 && getDeclarationOfAliasSymbol(result).kind === 211)) { break loop; } result = undefined; @@ -7633,13 +7834,6 @@ var ts; break loop; } break; - case 216: - var id = location.name; - if (name === id.text) { - result = location.symbol; - break loop; - } - break; } lastLocation = location; location = location.parent; @@ -7660,7 +7854,7 @@ var ts; return undefined; } if (result.flags & 2) { - var declaration = ts.forEach(result.declarations, function (d) { return ts.getCombinedNodeFlags(d) & 6144 ? d : undefined; }); + var declaration = ts.forEach(result.declarations, function (d) { return ts.isBlockOrCatchScoped(d) ? d : undefined; }); ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); if (!isDefinedBefore(declaration, errorLocation)) { error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name)); @@ -7669,15 +7863,16 @@ var ts; } return result; } - function isImportSymbolDeclaration(node) { + function isAliasSymbolDeclaration(node) { return node.kind === 202 || node.kind === 204 && !!node.name || node.kind === 205 || node.kind === 207 || - node.kind === 211; + node.kind === 211 || + node.kind === 208; } - function getDeclarationOfImportSymbol(symbol) { - return ts.forEach(symbol.declarations, function (d) { return isImportSymbolDeclaration(d) ? d : undefined; }); + function getDeclarationOfAliasSymbol(symbol) { + return ts.forEach(symbol.declarations, function (d) { return isAliasSymbolDeclaration(d) ? d : undefined; }); } function getTargetOfImportEqualsDeclaration(node) { if (node.moduleReference.kind === 212) { @@ -7710,7 +7905,7 @@ var ts; error(name, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name)); return; } - return symbol.flags & (107455 | 793056 | 1536) ? symbol : resolveImport(symbol); + return symbol.flags & (107455 | 793056 | 1536) ? symbol : resolveAlias(symbol); } } } @@ -7718,7 +7913,10 @@ var ts; return getExternalModuleMember(node.parent.parent.parent, node); } function getTargetOfExportSpecifier(node) { - return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : resolveEntityName(node, node.propertyName || node.name, 107455 | 793056 | 1536); + return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : resolveEntityName(node.propertyName || node.name, 107455 | 793056 | 1536); + } + function getTargetOfExportAssignment(node) { + return resolveEntityName(node.expression, 107455 | 793056 | 1536); } function getTargetOfImportDeclaration(node) { switch (node.kind) { @@ -7732,14 +7930,16 @@ var ts; return getTargetOfImportSpecifier(node); case 211: return getTargetOfExportSpecifier(node); + case 208: + return getTargetOfExportAssignment(node); } } - function resolveImport(symbol) { - ts.Debug.assert((symbol.flags & 8388608) !== 0, "Should only get Imports here."); + function resolveAlias(symbol) { + ts.Debug.assert((symbol.flags & 8388608) !== 0, "Should only get Alias here."); var links = getSymbolLinks(symbol); if (!links.target) { links.target = resolvingSymbol; - var node = getDeclarationOfImportSymbol(symbol); + var node = getDeclarationOfAliasSymbol(symbol); var target = getTargetOfImportDeclaration(node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; @@ -7753,6 +7953,29 @@ var ts; } return links.target; } + function markExportAsReferenced(node) { + var symbol = getSymbolOfNode(node); + var target = resolveAlias(symbol); + if (target && target !== unknownSymbol && target.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(target)) { + markAliasSymbolAsReferenced(symbol); + } + } + function markAliasSymbolAsReferenced(symbol) { + var links = getSymbolLinks(symbol); + if (!links.referenced) { + links.referenced = true; + var node = getDeclarationOfAliasSymbol(symbol); + if (node.kind === 208) { + checkExpressionCached(node.expression); + } + else if (node.kind === 211) { + checkExpressionCached(node.propertyName || node.name); + } + else if (ts.isInternalModuleImportEqualsDeclaration(node)) { + checkExpressionCached(node.moduleReference); + } + } + } function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) { if (!importDeclaration) { importDeclaration = ts.getAncestor(entityName, 202); @@ -7762,38 +7985,40 @@ var ts; entityName = entityName.parent; } if (entityName.kind === 64 || entityName.parent.kind === 125) { - return resolveEntityName(importDeclaration, entityName, 1536); + return resolveEntityName(entityName, 1536); } else { ts.Debug.assert(entityName.parent.kind === 202); - return resolveEntityName(importDeclaration, entityName, 107455 | 793056 | 1536); + return resolveEntityName(entityName, 107455 | 793056 | 1536); } } function getFullyQualifiedName(symbol) { return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol); } - function resolveEntityName(location, name, meaning) { + function resolveEntityName(name, meaning) { if (ts.getFullWidth(name) === 0) { return undefined; } if (name.kind === 64) { - var symbol = resolveName(location, name.text, meaning, ts.Diagnostics.Cannot_find_name_0, name); + var symbol = resolveName(name, name.text, meaning, ts.Diagnostics.Cannot_find_name_0, name); if (!symbol) { - return; + return undefined; } } else if (name.kind === 125) { - var namespace = resolveEntityName(location, name.left, 1536); - if (!namespace || namespace === unknownSymbol || ts.getFullWidth(name.right) === 0) - return; - var symbol = getSymbol(getExportsOfSymbol(namespace), name.right.text, meaning); + var namespace = resolveEntityName(name.left, 1536); + if (!namespace || namespace === unknownSymbol || ts.getFullWidth(name.right) === 0) { + return undefined; + } + var right = name.right; + var symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { - error(location, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(name.right)); - return; + error(right, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(right)); + return undefined; } } ts.Debug.assert((symbol.flags & 16777216) === 0, "Should never get an instantiated symbol here."); - return symbol.flags & meaning ? symbol : resolveImport(symbol); + return symbol.flags & meaning ? symbol : resolveAlias(symbol); } function isExternalModuleNameRelative(moduleName) { return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; @@ -7833,6 +8058,9 @@ var ts; } error(moduleReferenceLiteral, ts.Diagnostics.Cannot_find_external_module_0, moduleName); } + function getExportAssignmentSymbol(moduleSymbol) { + return moduleSymbol.exports["default"]; + } function getResolvedExportAssignmentSymbol(moduleSymbol) { var symbol = getExportAssignmentSymbol(moduleSymbol); if (symbol) { @@ -7840,82 +8068,52 @@ var ts; return symbol; } if (symbol.flags & 8388608) { - return resolveImport(symbol); + return resolveAlias(symbol); } } } - function getExportAssignmentSymbol(symbol) { - checkTypeOfExportAssignmentSymbol(symbol); - return getSymbolLinks(symbol).exportAssignmentSymbol; - } - function checkTypeOfExportAssignmentSymbol(containerSymbol) { - var symbolLinks = getSymbolLinks(containerSymbol); - if (!symbolLinks.exportAssignmentChecked) { - var exportInformation = collectExportInformationForSourceFileOrModule(containerSymbol); - if (exportInformation.exportAssignments.length) { - if (exportInformation.exportAssignments.length > 1) { - ts.forEach(exportInformation.exportAssignments, function (node) { return error(node, ts.Diagnostics.A_module_cannot_have_more_than_one_export_assignment); }); - } - var node = exportInformation.exportAssignments[0]; - if (exportInformation.hasExportedMember) { - error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); - } - if (node.exportName.text) { - var meaning = 107455 | 793056 | 1536; - var exportSymbol = resolveName(node, node.exportName.text, meaning, ts.Diagnostics.Cannot_find_name_0, node.exportName); - } - symbolLinks.exportAssignmentSymbol = exportSymbol || unknownSymbol; - } - symbolLinks.exportAssignmentChecked = true; - } - } - function collectExportInformationForSourceFileOrModule(symbol) { - var seenExportedMember = false; - var result = []; - ts.forEach(symbol.declarations, function (declaration) { - var block = (declaration.kind === 220 ? declaration : declaration.body); - ts.forEach(block.statements, function (node) { - if (node.kind === 208) { - result.push(node); - } - else { - seenExportedMember = seenExportedMember || (node.flags & 1) !== 0; - } - }); - }); - return { - hasExportedMember: seenExportedMember, - exportAssignments: result - }; - } function getExportsOfSymbol(symbol) { return symbol.flags & 1536 ? getExportsOfModule(symbol) : symbol.exports; } - function getExportsOfModule(symbol) { - var links = getSymbolLinks(symbol); - return links.resolvedExports || (links.resolvedExports = getExportsForModule(symbol)); + function getExportsOfModule(moduleSymbol) { + var links = getSymbolLinks(moduleSymbol); + return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol)); } - function getExportsForModule(symbol) { + function extendExportSymbols(target, source) { + for (var id in source) { + if (id !== "default" && !ts.hasProperty(target, id)) { + target[id] = source[id]; + } + } + } + function getExportsForModule(moduleSymbol) { + if (compilerOptions.target < 2) { + var defaultSymbol = getExportAssignmentSymbol(moduleSymbol); + if (defaultSymbol) { + return { + "default": defaultSymbol + }; + } + } var result; var visitedSymbols = []; - visit(symbol); - return result; + visit(moduleSymbol); + return result || moduleSymbol.exports; function visit(symbol) { if (!ts.contains(visitedSymbols, symbol)) { visitedSymbols.push(symbol); - if (!result) { - result = symbol.exports; - } - else { - extendSymbolTable(result, symbol.exports); - } - ts.forEach(symbol.declarations, function (node) { - if (node.kind === 220 || node.kind === 200) { - ts.forEach(node.exportStars, function (exportStar) { - visit(resolveExternalModuleName(exportStar, exportStar.moduleSpecifier)); - }); + if (symbol !== moduleSymbol) { + if (!result) { + result = cloneSymbolTable(moduleSymbol.exports); } - }); + extendExportSymbols(result, symbol.exports); + } + var exportStars = symbol.exports["__export"]; + if (exportStars) { + ts.forEach(exportStars.declarations, function (node) { + visit(resolveExternalModuleName(node, node.moduleSpecifier)); + }); + } } } } @@ -7940,7 +8138,7 @@ var ts; return true; } if (symbol.flags & 8388608) { - return (resolveImport(symbol).flags & 107455) !== 0; + return (resolveAlias(symbol).flags & 107455) !== 0; } return false; } @@ -8057,8 +8255,8 @@ var ts; if (symbolFromSymbolTable.flags & 8388608) { if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, ts.isExternalModuleImportEqualsDeclaration)) { - var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); - if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { + var resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable); + if (isAccessible(symbolFromSymbolTable, resolveAlias(symbolFromSymbolTable))) { return [symbolFromSymbolTable]; } var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; @@ -8083,7 +8281,7 @@ var ts; if (symbolFromSymbolTable === symbol) { return true; } - symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608) ? resolveImport(symbolFromSymbolTable) : symbolFromSymbolTable; + symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; if (symbolFromSymbolTable.flags & meaning) { qualify = true; return true; @@ -8374,7 +8572,7 @@ var ts; buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); } else { - writeKeyword(writer, 112); + writeKeyword(writer, 111); } } else { @@ -8465,7 +8663,7 @@ var ts; writer.writeParameter(getIndexerParameterName(resolved, 0, "x")); writePunctuation(writer, 51); writeSpace(writer); - writeKeyword(writer, 121); + writeKeyword(writer, 120); writePunctuation(writer, 19); writePunctuation(writer, 51); writeSpace(writer); @@ -8478,7 +8676,7 @@ var ts; writer.writeParameter(getIndexerParameterName(resolved, 1, "x")); writePunctuation(writer, 51); writeSpace(writer); - writeKeyword(writer, 119); + writeKeyword(writer, 118); writePunctuation(writer, 19); writePunctuation(writer, 51); writeSpace(writer); @@ -8643,7 +8841,7 @@ var ts; return true; } if (symbolOfNode.flags & 8388608) { - return isSymbolUsedInExportAssignment(resolveImport(symbolOfNode)); + return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode)); } } function isSymbolUsedInExportAssignment(symbol) { @@ -8651,7 +8849,7 @@ var ts; return true; } if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & 8388608)) { - resolvedExportSymbol = resolvedExportSymbol || resolveImport(exportAssignmentSymbol); + resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol); if (resolvedExportSymbol === symbol) { return true; } @@ -8785,6 +8983,9 @@ var ts; if (declaration.parent.parent.kind === 182) { return anyType; } + if (declaration.parent.parent.kind === 183) { + return getTypeForVariableDeclarationInForOfStatement(declaration.parent.parent); + } if (ts.isBindingPattern(declaration.parent)) { return getTypeForBindingElement(declaration); } @@ -8873,9 +9074,12 @@ var ts; return links.type = getTypeOfPrototypeProperty(symbol); } var declaration = symbol.valueDeclaration; - if (declaration.kind === 216) { + if (declaration.parent.kind === 216) { return links.type = anyType; } + if (declaration.kind === 208) { + return links.type = checkExpression(declaration.expression); + } links.type = resolvingType; var type = getWidenedTypeForVariableLikeDeclaration(declaration, true); if (links.type === resolvingType) { @@ -8965,10 +9169,10 @@ var ts; } return links.type; } - function getTypeOfImport(symbol) { + function getTypeOfAlias(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { - links.type = getTypeOfSymbol(resolveImport(symbol)); + links.type = getTypeOfSymbol(resolveAlias(symbol)); } return links.type; } @@ -8996,7 +9200,7 @@ var ts; return getTypeOfAccessors(symbol); } if (symbol.flags & 8388608) { - return getTypeOfImport(symbol); + return getTypeOfAlias(symbol); } return unknownType; } @@ -9150,10 +9354,10 @@ var ts; } return links.declaredType; } - function getDeclaredTypeOfImport(symbol) { + function getDeclaredTypeOfAlias(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { - links.declaredType = getDeclaredTypeOfSymbol(resolveImport(symbol)); + links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol)); } return links.declaredType; } @@ -9175,7 +9379,7 @@ var ts; return getDeclaredTypeOfTypeParameter(symbol); } if (symbol.flags & 8388608) { - return getDeclaredTypeOfImport(symbol); + return getDeclaredTypeOfAlias(symbol); } return unknownType; } @@ -9546,6 +9750,16 @@ var ts; }); return result; } + function getExportsOfExternalModule(node) { + if (!node.moduleSpecifier) { + return emptyArray; + } + var module = resolveExternalModuleName(node, node.moduleSpecifier); + if (!module || !module.exports) { + return emptyArray; + } + return ts.mapToArray(getExportsOfModule(module)); + } function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { @@ -9691,7 +9905,7 @@ var ts; return symbol.members["__index"]; } function getIndexDeclarationOfSymbol(symbol, kind) { - var syntaxKind = kind === 1 ? 119 : 121; + var syntaxKind = kind === 1 ? 118 : 120; var indexSymbol = getIndexSymbol(symbol); if (indexSymbol) { var len = indexSymbol.declarations.length; @@ -9794,7 +10008,7 @@ var ts; function getTypeFromTypeReferenceNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { - var symbol = resolveEntityName(node, node.typeName, 793056); + var symbol = resolveEntityName(node.typeName, 793056); if (symbol) { var type; if ((symbol.flags & 262144) && isTypeParameterReferenceIllegalInConstraint(node, symbol)) { @@ -9867,8 +10081,9 @@ var ts; function getGlobalSymbol(name, meaning, diagnostic) { return resolveName(undefined, name, meaning, diagnostic, name); } - function getGlobalType(name) { - return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), 0); + function getGlobalType(name, arity) { + if (arity === void 0) { arity = 0; } + return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity); } function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); @@ -10012,15 +10227,15 @@ var ts; } function getTypeFromTypeNode(node) { switch (node.kind) { - case 112: + case 111: return anyType; - case 121: + case 120: return stringType; - case 119: + case 118: return numberType; - case 113: + case 112: return booleanType; - case 122: + case 121: return esSymbolType; case 98: return voidType; @@ -10201,7 +10416,7 @@ var ts; isContextSensitive(node.whenFalse); case 167: return node.operatorToken.kind === 49 && - (isContextSensitive(node.left) || isContextSensitive(node.right)); + (isContextSensitive(node.left) || isContextSensitive(node.right)); case 217: return isContextSensitive(node.initializer); case 132: @@ -11481,46 +11696,56 @@ var ts; return type; } } - function markLinkedImportsAsReferenced(node) { - if (node) { - var nodeLinks = getNodeLinks(node); - while (nodeLinks.importOnRightSide) { - var rightSide = nodeLinks.importOnRightSide; - nodeLinks.importOnRightSide = undefined; - getSymbolLinks(rightSide).referenced = true; - ts.Debug.assert((rightSide.flags & 8388608) !== 0); - nodeLinks = getNodeLinks(ts.getDeclarationOfKind(rightSide, 202)); - } - } - } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); if (symbol === argumentsSymbol && ts.getContainingFunction(node).kind === 161) { 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 = getLeftSideOfImportEqualsOrExportAssignment(node); - if (!importOrExportAssignment || - (importOrExportAssignment.flags & 1) || - (importOrExportAssignment.kind === 208)) { - symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); - } - else { - var nodeLinks = getNodeLinks(importOrExportAssignment); - ts.Debug.assert(!nodeLinks.importOnRightSide); - nodeLinks.importOnRightSide = symbol; - } - } - if (symbolLinks.referenced) { - markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 202)); - } + if (symbol.flags & 8388608 && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { + markAliasSymbolAsReferenced(symbol); } checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); + checkBlockScopedBindingCapturedInLoop(node, symbol); return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } + function isInsideFunction(node, threshold) { + var current = node; + while (current && current !== threshold) { + if (ts.isFunctionLike(current)) { + return true; + } + current = current.parent; + } + return false; + } + function checkBlockScopedBindingCapturedInLoop(node, symbol) { + if (languageVersion >= 2 || + (symbol.flags & 2) === 0 || + symbol.valueDeclaration.parent.kind === 216) { + return; + } + var container = symbol.valueDeclaration; + while (container.kind !== 194) { + container = container.parent; + } + container = container.parent; + if (container.kind === 175) { + container = container.parent; + } + var inFunction = isInsideFunction(node.parent, container); + var current = container; + while (current && !ts.nodeStartsNewLexicalEnvironment(current)) { + if (isIterationStatement(current, false)) { + if (inFunction) { + grammarErrorOnFirstToken(current, ts.Diagnostics.Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher, ts.declarationNameToString(node)); + } + getNodeLinks(symbol.valueDeclaration).flags |= 256; + break; + } + current = current.parent; + } + } function captureLexicalThis(node, container) { var classNode = container.parent && container.parent.kind === 196 ? container.parent : undefined; getNodeLinks(node).flags |= 2; @@ -11803,7 +12028,7 @@ var ts; var type = getContextualType(arrayLiteral); if (type) { var index = ts.indexOf(arrayLiteral.elements, node); - return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1); + return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1) || (languageVersion >= 2 ? checkIteratedType(type, undefined) : undefined); } return undefined; } @@ -12680,9 +12905,6 @@ var ts; return getReturnTypeOfSignature(signature); } function checkTaggedTemplateExpression(node) { - if (languageVersion < 2) { - grammarErrorOnFirstToken(node.template, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); - } return getReturnTypeOfSignature(getResolvedSignature(node)); } function checkTypeAssertion(node) { @@ -12841,7 +13063,7 @@ var ts; } return true; } - function checkReferenceExpression(n, invalidReferenceMessage, constantVarianleMessage) { + function checkReferenceExpression(n, invalidReferenceMessage, constantVariableMessage) { function findSymbol(n) { var symbol = getNodeLinks(n).resolvedSymbol; return symbol && getExportSymbolOfValueSymbolIfExported(symbol); @@ -12867,14 +13089,14 @@ var ts; case 64: case 153: var symbol = findSymbol(n); - return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 4096) !== 0; + return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 8192) !== 0; case 154: var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8) { var name = index.text; var prop = getPropertyOfType(getTypeOfSymbol(symbol), name); - return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 4096) !== 0; + return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192) !== 0; } return false; case 159: @@ -12888,7 +13110,7 @@ var ts; return false; } if (isConstVariableReference(n)) { - error(n, constantVarianleMessage); + error(n, constantVariableMessage); return false; } return true; @@ -13439,7 +13661,7 @@ var ts; var declaration = indexSymbol.declarations[i]; if (declaration.parameters.length === 1 && declaration.parameters[0].type) { switch (declaration.parameters[0].type.kind) { - case 121: + case 120: if (!seenStringIndexer) { seenStringIndexer = true; } @@ -13447,7 +13669,7 @@ var ts; error(declaration, ts.Diagnostics.Duplicate_string_index_signature); } break; - case 119: + case 118: if (!seenNumericIndexer) { seenNumericIndexer = true; } @@ -13842,7 +14064,7 @@ var ts; return 2097152 | 1048576; case 202: var result = 0; - var target = resolveImport(getSymbolOfNode(d)); + var target = resolveAlias(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); }); return result; default: @@ -13853,9 +14075,9 @@ var ts; function checkFunctionDeclaration(node) { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || - checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || - checkGrammarFunctionName(node.name) || - checkGrammarForGenerator(node); + checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || + checkGrammarFunctionName(node.name) || + checkGrammarForGenerator(node); checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -13863,7 +14085,7 @@ var ts; } function checkFunctionLikeDeclaration(node) { checkSignatureDeclaration(node); - if (node.name.kind === 126) { + if (node.name && node.name.kind === 126) { checkComputedPropertyName(node.name); } if (!ts.hasDynamicName(node)) { @@ -13979,24 +14201,24 @@ var ts; } } function checkVarDeclaredNamesNotShadowed(node) { - if (node.initializer && (ts.getCombinedNodeFlags(node) & 6144) === 0) { + if (node.initializer && (ts.getCombinedNodeFlags(node) & 12288) === 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) & 6144) { + if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 12288) { var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 194); var container = varDeclList.parent.kind === 175 && varDeclList.parent.parent; var namesShareScope = container && - (container.kind === 174 && ts.isAnyFunction(container.parent) || - (container.kind === 201 && container.kind === 200) || + (container.kind === 174 && ts.isFunctionLike(container.parent) || + (container.kind === 201 && container.kind === 200) || container.kind === 220); 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); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name); } } } @@ -14152,33 +14374,125 @@ var ts; checkSourceElement(node.statement); } function checkForOfStatement(node) { - checkGrammarForOfStatement(node); + if (languageVersion < 2) { + grammarErrorOnFirstToken(node, ts.Diagnostics.for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher); + return; + } + checkGrammarForInOrForOfStatement(node); + if (node.initializer.kind === 194) { + checkForInOrForOfVariableDeclaration(node); + } + else { + var varExpr = node.initializer; + var rightType = checkExpression(node.expression); + var iteratedType = checkIteratedType(rightType, node.expression); + if (varExpr.kind === 151 || varExpr.kind === 152) { + checkDestructuringAssignment(varExpr, iteratedType || unknownType); + } + else { + var leftType = checkExpression(varExpr); + checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_of_statement, ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant); + if (iteratedType) { + checkTypeAssignableTo(iteratedType, leftType, varExpr, undefined); + } + } + } + checkSourceElement(node.statement); } function checkForInStatement(node) { checkGrammarForInOrForOfStatement(node); if (node.initializer.kind === 194) { - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length >= 1) { - var decl = variableDeclarationList.declarations[0]; - checkVariableDeclaration(decl); + var variable = node.initializer.declarations[0]; + if (variable && ts.isBindingPattern(variable.name)) { + error(variable.name, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } + checkForInOrForOfVariableDeclaration(node); } else { var varExpr = node.initializer; - var exprType = checkExpression(varExpr); - if (!allConstituentTypesHaveKind(exprType, 1 | 258)) { + var leftType = checkExpression(varExpr); + if (varExpr.kind === 151 || varExpr.kind === 152) { + error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); + } + else if (!allConstituentTypesHaveKind(leftType, 1 | 258)) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { - checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant); } } - var exprType = checkExpression(node.expression); - if (!allConstituentTypesHaveKind(exprType, 1 | 48128 | 512)) { + var rightType = checkExpression(node.expression); + if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); } + function checkForInOrForOfVariableDeclaration(iterationStatement) { + var variableDeclarationList = iterationStatement.initializer; + if (variableDeclarationList.declarations.length >= 1) { + var decl = variableDeclarationList.declarations[0]; + checkVariableDeclaration(decl); + } + } + function getTypeForVariableDeclarationInForOfStatement(forOfStatement) { + if (languageVersion < 2) { + return anyType; + } + var expressionType = getTypeOfExpression(forOfStatement.expression); + return checkIteratedType(expressionType, forOfStatement.expression) || anyType; + } + function checkIteratedType(iterable, expressionForError) { + ts.Debug.assert(languageVersion >= 2); + var iteratedType = getIteratedType(iterable, expressionForError); + if (expressionForError && iteratedType) { + var completeIterableType = globalIterableType !== emptyObjectType ? createTypeReference(globalIterableType, [iteratedType]) : emptyObjectType; + checkTypeAssignableTo(iterable, completeIterableType, expressionForError); + } + return iteratedType; + function getIteratedType(iterable, expressionForError) { + if (allConstituentTypesHaveKind(iterable, 1)) { + return undefined; + } + var iteratorFunction = getTypeOfPropertyOfType(iterable, ts.getPropertyNameForKnownSymbolName("iterator")); + if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, 1)) { + return undefined; + } + var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray; + if (iteratorFunctionSignatures.length === 0) { + if (expressionForError) { + error(expressionForError, ts.Diagnostics.The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + } + return undefined; + } + var iterator = getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)); + if (allConstituentTypesHaveKind(iterator, 1)) { + return undefined; + } + var iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next"); + if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, 1)) { + return undefined; + } + var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray; + if (iteratorNextFunctionSignatures.length === 0) { + if (expressionForError) { + error(expressionForError, ts.Diagnostics.The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method); + } + return undefined; + } + var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); + if (allConstituentTypesHaveKind(iteratorNextResult, 1)) { + return undefined; + } + var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); + if (!iteratorNextValue) { + if (expressionForError) { + error(expressionForError, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); + } + return undefined; + } + return iteratorNextValue; + } + } function checkBreakOrContinueStatement(node) { checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node); } @@ -14254,7 +14568,7 @@ var ts; if (!checkGrammarStatementInAmbientContext(node)) { var current = node.parent; while (current) { - if (ts.isAnyFunction(current)) { + if (ts.isFunctionLike(current)) { break; } if (current.kind === 189 && current.label.text === node.label.text) { @@ -14282,16 +14596,33 @@ var ts; checkBlock(node.tryBlock); var catchClause = node.catchClause; if (catchClause) { - if (catchClause.type) { - var sourceFile = ts.getSourceFileOfNode(node); - var colonStart = ts.skipTrivia(sourceFile.text, catchClause.name.end); - grammarErrorAtPos(sourceFile, colonStart, ":".length, ts.Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); + if (catchClause.variableDeclaration) { + if (catchClause.variableDeclaration.name.kind !== 64) { + grammarErrorOnFirstToken(catchClause.variableDeclaration.name, ts.Diagnostics.Catch_clause_variable_name_must_be_an_identifier); + } + else if (catchClause.variableDeclaration.type) { + grammarErrorOnFirstToken(catchClause.variableDeclaration.type, ts.Diagnostics.Catch_clause_variable_cannot_have_a_type_annotation); + } + else if (catchClause.variableDeclaration.initializer) { + grammarErrorOnFirstToken(catchClause.variableDeclaration.initializer, ts.Diagnostics.Catch_clause_variable_cannot_have_an_initializer); + } + else { + var identifierName = catchClause.variableDeclaration.name.text; + var locals = catchClause.block.locals; + if (locals && ts.hasProperty(locals, identifierName)) { + var localSymbol = locals[identifierName]; + if (localSymbol && (localSymbol.flags & 2) !== 0) { + grammarErrorOnNode(localSymbol.valueDeclaration, ts.Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName); + } + } + checkGrammarEvalOrArgumentsInStrictMode(node, catchClause.variableDeclaration.name); + } } - checkGrammarEvalOrArgumentsInStrictMode(node, catchClause.name); checkBlock(catchClause.block); } - if (node.finallyBlock) + if (node.finallyBlock) { checkBlock(node.finallyBlock); + } } function checkIndexConstraints(type) { var declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, 1); @@ -14379,10 +14710,12 @@ var ts; } function checkClassDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); - checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); + if (node.name) { + checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); + checkCollisionWithCapturedThisVariable(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + } checkTypeParameters(node.typeParameters); - checkCollisionWithCapturedThisVariable(node, node.name); - checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); @@ -14395,10 +14728,10 @@ var ts; if (type.baseTypes.length) { if (produceDiagnostics) { var baseType = type.baseTypes[0]; - checkTypeAssignableTo(type, baseType, node.name, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); + checkTypeAssignableTo(type, baseType, node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); var staticBaseType = getTypeOfSymbol(baseType.symbol); - checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); - if (baseType.symbol !== resolveEntityName(node, baseTypeNode.typeName, 107455)) { + checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); + if (baseType.symbol !== resolveEntityName(baseTypeNode.typeName, 107455)) { error(baseTypeNode, ts.Diagnostics.Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_0, typeToString(baseType)); } checkKindsOfPropertyMemberOverrides(type, baseType); @@ -14414,7 +14747,7 @@ var ts; if (t !== unknownType) { var declaredType = (t.flags & 4096) ? t.target : t; if (declaredType.flags & (1024 | 2048)) { - checkTypeAssignableTo(type, t, node.name, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); + checkTypeAssignableTo(type, t, node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); } else { error(typeRefNode, ts.Diagnostics.A_class_may_only_implement_another_class_or_interface); @@ -14762,15 +15095,6 @@ 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 === 201) { - var statements = node.body.statements; - for (var i = 0, n = statements.length; i < n; i++) { - var statement = statements[i]; - if (statement.kind === 208) { - grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); - } - } - } } checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); @@ -14821,9 +15145,9 @@ var ts; } return true; } - function checkImportSymbol(node) { + function checkAliasSymbol(node) { var symbol = getSymbolOfNode(node); - var target = resolveImport(symbol); + var target = resolveAlias(symbol); if (target !== unknownSymbol) { var excludedMeanings = (symbol.flags & 107455 ? 107455 : 0) | (symbol.flags & 793056 ? 793056 : 0) | @@ -14837,10 +15161,10 @@ var ts; function checkImportBinding(node) { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); - checkImportSymbol(node); + checkAliasSymbol(node); } function checkImportDeclaration(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + if (!checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -14862,50 +15186,107 @@ var ts; } function checkImportEqualsDeclaration(node) { checkGrammarModifiers(node); - if (ts.isInternalModuleImportEqualsDeclaration(node)) { + if (ts.isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); - var symbol = getSymbolOfNode(node); - var target = resolveImport(symbol); - if (target !== unknownSymbol) { - if (target.flags & 107455) { - var moduleName = getFirstIdentifier(node.moduleReference); - if (resolveEntityName(node, moduleName, 107455 | 1536).flags & 1536) { - checkExpressionOrQualifiedName(node.moduleReference); - } - else { - error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName)); - } - } - if (target.flags & 793056) { - checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); - } + if (node.flags & 1) { + markExportAsReferenced(node); } - } - else { - if (checkExternalImportOrExportDeclaration(node)) { - checkImportBinding(node); + if (ts.isInternalModuleImportEqualsDeclaration(node)) { + var target = resolveAlias(getSymbolOfNode(node)); + if (target !== unknownSymbol) { + if (target.flags & 107455) { + var moduleName = getFirstIdentifier(node.moduleReference); + if (!(resolveEntityName(moduleName, 107455 | 1536).flags & 1536)) { + error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName)); + } + } + if (target.flags & 793056) { + checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); + } + } } } } function checkExportDeclaration(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + if (!checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_declaration_cannot_have_modifiers); } if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) { if (node.exportClause) { - ts.forEach(node.exportClause.elements, checkImportSymbol); + ts.forEach(node.exportClause.elements, checkExportSpecifier); } } } + function checkExportSpecifier(node) { + checkAliasSymbol(node); + if (!node.parent.parent.moduleSpecifier) { + markExportAsReferenced(node); + } + } function checkExportAssignment(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + var container = node.parent.kind === 220 ? node.parent : node.parent.parent; + if (container.kind === 200 && container.name.kind === 64) { + error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); + return; + } + if (!checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); } - var container = node.parent; - if (container.kind !== 220) { - container = container.parent; + if (node.expression.kind === 64) { + markExportAsReferenced(node); + } + else { + checkExpressionCached(node.expression); + } + checkExternalModuleExports(container); + } + function getModuleStatements(node) { + if (node.kind === 220) { + return node.statements; + } + if (node.kind === 200 && node.body.kind === 201) { + return node.body.statements; + } + return emptyArray; + } + function hasExportedMembers(moduleSymbol) { + var declarations = moduleSymbol.declarations; + for (var i = 0; i < declarations.length; i++) { + var statements = getModuleStatements(declarations[i]); + for (var j = 0; j < statements.length; j++) { + var node = statements[j]; + if (node.kind === 209) { + var exportClause = node.exportClause; + if (!exportClause) { + return true; + } + var specifiers = exportClause.elements; + for (var k = 0; k < specifiers.length; k++) { + var specifier = specifiers[k]; + if (!(specifier.propertyName && specifier.name && specifier.name.text === "default")) { + return true; + } + } + } + else if (node.kind !== 208 && node.flags & 1 && !(node.flags & 256)) { + return true; + } + } + } + } + function checkExternalModuleExports(node) { + var moduleSymbol = getSymbolOfNode(node); + var links = getSymbolLinks(moduleSymbol); + if (!links.exportsChecked) { + var defaultSymbol = getExportAssignmentSymbol(moduleSymbol); + if (defaultSymbol) { + if (hasExportedMembers(moduleSymbol)) { + var declaration = getDeclarationOfAliasSymbol(defaultSymbol) || defaultSymbol.valueDeclaration; + error(declaration, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); + } + } + links.exportsChecked = true; } - checkTypeOfExportAssignmentSymbol(getSymbolOfNode(container)); } function checkSourceElement(node) { if (!node) @@ -15087,6 +15468,7 @@ var ts; case 196: case 199: case 219: + case 208: case 220: ts.forEachChild(node, checkFunctionExpressionBodies); break; @@ -15106,11 +15488,7 @@ var ts; 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, 202)); - } + checkExternalModuleExports(node); } if (potentialThisCollisions.length) { ts.forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope); @@ -15199,11 +15577,6 @@ var ts; copySymbol(location.symbol, meaning); } break; - case 216: - if (location.name.text) { - copySymbol(location.symbol, meaning); - } - break; } memberFlags = location.flags; location = location.parent; @@ -15237,11 +15610,11 @@ var ts; return true; } switch (node.kind) { + case 111: + case 118: + case 120: case 112: - case 119: case 121: - case 113: - case 122: return true; case 98: return node.parent.kind !== 164; @@ -15300,7 +15673,7 @@ var ts; return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent; } if (nodeOnRightSide.parent.kind === 208) { - return nodeOnRightSide.parent.exportName === nodeOnRightSide && nodeOnRightSide.parent; + return nodeOnRightSide.parent.expression === nodeOnRightSide && nodeOnRightSide.parent; } return undefined; } @@ -15312,11 +15685,11 @@ var ts; (node.parent.kind === 153 && node.parent.name === node); } function getSymbolOfEntityNameOrPropertyAccessExpression(entityName) { - if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { + if (ts.isDeclarationName(entityName)) { return getSymbolOfNode(entityName.parent); } if (entityName.parent.kind === 208) { - return resolveEntityName(entityName.parent.parent, entityName, 107455 | 793056 | 1536 | 8388608); + return resolveEntityName(entityName, 107455 | 793056 | 1536 | 8388608); } if (entityName.kind !== 153) { if (isInRightSideOfImportOrExportAssignment(entityName)) { @@ -15332,7 +15705,7 @@ var ts; } if (entityName.kind === 64) { var meaning = 107455 | 8388608; - return resolveEntityName(entityName, entityName, meaning); + return resolveEntityName(entityName, meaning); } else if (entityName.kind === 153) { var symbol = getNodeLinks(entityName).resolvedSymbol; @@ -15352,7 +15725,7 @@ var ts; else if (isTypeReferenceIdentifier(entityName)) { var meaning = entityName.parent.kind === 139 ? 793056 : 1536; meaning |= 8388608; - return resolveEntityName(entityName, entityName, meaning); + return resolveEntityName(entityName, meaning); } return undefined; } @@ -15360,7 +15733,7 @@ var ts; if (isInsideWithStatementBody(node)) { return undefined; } - if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (ts.isDeclarationName(node)) { return getSymbolOfNode(node.parent); } if (node.kind === 64 && isInRightSideOfImportOrExportAssignment(node)) { @@ -15375,18 +15748,19 @@ var ts; case 90: var type = checkExpression(node); return type.symbol; - case 114: + case 113: var constructorDeclaration = node.parent; if (constructorDeclaration && constructorDeclaration.kind === 133) { return constructorDeclaration.parent.symbol; } return undefined; case 8: - if (ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) && - ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) { - var importSymbol = getSymbolOfNode(node.parent.parent); - var moduleType = getTypeOfSymbol(importSymbol); - return moduleType ? moduleType.symbol : undefined; + var moduleName; + if ((ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) && + ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) || + ((node.parent.kind === 203 || node.parent.kind === 209) && + node.parent.moduleSpecifier === node)) { + return resolveExternalModuleName(node, node); } case 7: if (node.parent.kind == 154 && node.parent.argumentExpression === node) { @@ -15404,7 +15778,7 @@ var ts; } function getShorthandAssignmentValueSymbol(location) { if (location && location.kind === 218) { - return resolveEntityName(location, location.name, 107455); + return resolveEntityName(location.name, 107455); } return undefined; } @@ -15430,7 +15804,7 @@ var ts; var symbol = getSymbolOfNode(node); return getTypeOfSymbol(symbol); } - if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (ts.isDeclarationName(node)) { var symbol = getSymbolInfo(node); return symbol && getTypeOfSymbol(symbol); } @@ -15507,6 +15881,10 @@ var ts; return generatedNames; function generateNames(node) { switch (node.kind) { + case 195: + case 196: + generateNameForFunctionOrClassDeclaration(node); + break; case 200: generateNameForModuleOrEnum(node); generateNames(node.body); @@ -15520,6 +15898,9 @@ var ts; case 209: generateNameForExportDeclaration(node); break; + case 208: + generateNameForExportAssignment(node); + break; case 220: case 201: ts.forEach(node.statements, generateNames); @@ -15530,27 +15911,17 @@ var ts; return ts.hasProperty(globals, name) || ts.hasProperty(sourceFile.identifiers, name) || ts.hasProperty(generatedNames, name); } function makeUniqueName(baseName) { - if (baseName.charCodeAt(0) !== 95) { - var baseName = "_" + baseName; - if (!isExistingName(baseName)) { - return generatedNames[baseName] = baseName; - } - } - if (baseName.charCodeAt(baseName.length - 1) !== 95) { - baseName += "_"; - } - var i = 1; - while (true) { - name = baseName + i; - if (!isExistingName(name)) { - return generatedNames[name] = name; - } - i++; - } + var name = ts.generateUniqueName(baseName, isExistingName); + return generatedNames[name] = name; } function assignGeneratedName(node, name) { getNodeLinks(node).generatedName = ts.unescapeIdentifier(name); } + function generateNameForFunctionOrClassDeclaration(node) { + if (!node.name) { + assignGeneratedName(node, makeUniqueName("default")); + } + } function generateNameForModuleOrEnum(node) { if (node.name.kind === 64) { var name = node.name.text; @@ -15572,6 +15943,11 @@ var ts; generateNameForImportOrExportDeclaration(node); } } + function generateNameForExportAssignment(node) { + if (node.expression.kind !== 64) { + assignGeneratedName(node, makeUniqueName("default")); + } + } } function getGeneratedNameForNode(node) { var links = getNodeLinks(node); @@ -15586,8 +15962,8 @@ var ts; function getLocalNameForImportDeclaration(node) { return getGeneratedNameForNode(node); } - function getImportNameSubstitution(symbol) { - var declaration = getDeclarationOfImportSymbol(symbol); + function getAliasNameSubstitution(symbol) { + var declaration = getDeclarationOfAliasSymbol(symbol); if (declaration && declaration.kind === 207) { var moduleName = getGeneratedNameForNode(declaration.parent.parent.parent); var propertyName = declaration.propertyName || declaration.name; @@ -15618,38 +15994,35 @@ var ts; return getExportNameSubstitution(exportSymbol, node.parent); } if (symbol.flags & 8388608) { - return getImportNameSubstitution(symbol); + return getAliasNameSubstitution(symbol); } } } - function getExportAssignmentName(node) { - var symbol = getExportAssignmentSymbol(getSymbolOfNode(node)); - return symbol && symbol !== unknownSymbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol) ? symbolToString(symbol) : undefined; + function hasExportDefaultValue(node) { + var symbol = getResolvedExportAssignmentSymbol(getSymbolOfNode(node)); + return symbol && symbol !== unknownSymbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol); } function isTopLevelValueImportEqualsWithEntityName(node) { if (node.parent.kind !== 220 || !ts.isInternalModuleImportEqualsDeclaration(node)) { return false; } - return isImportResolvedToValue(getSymbolOfNode(node)); + return isAliasResolvedToValue(getSymbolOfNode(node)); } - function isImportResolvedToValue(symbol) { - var target = resolveImport(symbol); + function isAliasResolvedToValue(symbol) { + var target = resolveAlias(symbol); return target !== unknownSymbol && target.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(target); } function isConstEnumOrConstEnumOnlyModule(s) { return isConstEnumSymbol(s) || s.constEnumOnlyModule; } - function isReferencedImportDeclaration(node) { - if (isImportSymbolDeclaration(node)) { + function isReferencedAliasDeclaration(node) { + if (isAliasSymbolDeclaration(node)) { var symbol = getSymbolOfNode(node); if (getSymbolLinks(symbol).referenced) { return true; } - if (node.kind === 202 && node.flags & 1 && isImportResolvedToValue(symbol)) { - return true; - } } - return ts.forEachChild(node, isReferencedImportDeclaration); + return ts.forEachChild(node, isReferencedAliasDeclaration); } function isImplementationOfOverload(node) { if (ts.nodeIsPresent(node.body)) { @@ -15694,12 +16067,36 @@ var ts; return !resolveName(location, name, 107455, undefined, undefined) && !ts.hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name); } + function getBlockScopedVariableId(n) { + ts.Debug.assert(!ts.nodeIsSynthesized(n)); + if (n.parent.kind === 153 && + n.parent.name === n) { + return undefined; + } + if (n.parent.kind === 150 && + n.parent.propertyName === n) { + return undefined; + } + var declarationSymbol = (n.parent.kind === 193 && n.parent.name === n) || + n.parent.kind === 150 ? getSymbolOfNode(n.parent) : undefined; + var symbol = declarationSymbol || + getNodeLinks(n).resolvedSymbol || + resolveName(n, n.text, 2 | 8388608, undefined, undefined); + var isLetOrConst = symbol && + (symbol.flags & 2) && + symbol.valueDeclaration.parent.kind !== 216; + if (isLetOrConst) { + getSymbolLinks(symbol); + return symbol.id; + } + return undefined; + } function createResolver() { return { getGeneratedNameForNode: getGeneratedNameForNode, getExpressionNameSubstitution: getExpressionNameSubstitution, - getExportAssignmentName: getExportAssignmentName, - isReferencedImportDeclaration: isReferencedImportDeclaration, + hasExportDefaultValue: hasExportDefaultValue, + isReferencedAliasDeclaration: isReferencedAliasDeclaration, getNodeCheckFlags: getNodeCheckFlags, isTopLevelValueImportEqualsWithEntityName: isTopLevelValueImportEqualsWithEntityName, isDeclarationVisible: isDeclarationVisible, @@ -15709,7 +16106,8 @@ var ts; isSymbolAccessible: isSymbolAccessible, isEntityNameVisible: isEntityNameVisible, getConstantValue: getConstantValue, - isUnknownIdentifier: isUnknownIdentifier + isUnknownIdentifier: isUnknownIdentifier, + getBlockScopedVariableId: getBlockScopedVariableId }; } function initializeTypeChecker() { @@ -15737,6 +16135,7 @@ var ts; globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray"); globalESSymbolType = getGlobalType("Symbol"); globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"); + globalIterableType = getGlobalType("Iterable", 1); } else { globalTemplateStringsArrayType = unknownType; @@ -15779,14 +16178,14 @@ var ts; for (var i = 0, n = node.modifiers.length; i < n; i++) { var modifier = node.modifiers[i]; switch (modifier.kind) { - case 109: case 108: case 107: + case 106: var text; - if (modifier.kind === 109) { + if (modifier.kind === 108) { text = "public"; } - else if (modifier.kind === 108) { + else if (modifier.kind === 107) { text = "protected"; lastProtected = modifier; } @@ -15805,7 +16204,7 @@ var ts; } flags |= ts.modifierToFlag(modifier.kind); break; - case 110: + case 109: if (flags & 128) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } @@ -15833,7 +16232,7 @@ var ts; } flags |= 1; break; - case 115: + case 114: if (flags & 2) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); } @@ -15939,7 +16338,7 @@ var ts; if (parameter.dotDotDotToken) { return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter); } - if (parameter.flags & 243) { + if (parameter.flags & 499) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); } if (parameter.questionToken) { @@ -15951,7 +16350,7 @@ var ts; if (!parameter.type) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); } - if (parameter.type.kind !== 121 && parameter.type.kind !== 119) { + if (parameter.type.kind !== 120 && parameter.type.kind !== 118) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); } if (!node.type) { @@ -15959,7 +16358,7 @@ var ts; } } function checkGrammarForIndexSignatureModifier(node) { - if (node.flags & 243) { + if (node.flags & 499) { grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members); } } @@ -16024,7 +16423,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103); + ts.Debug.assert(heritageClause.token === 102); if (seenImplementsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); } @@ -16047,7 +16446,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103); + ts.Debug.assert(heritageClause.token === 102); return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); } checkGrammarHeritageClause(heritageClause); @@ -16160,13 +16559,6 @@ var ts; } return false; } - function checkGrammarForOfStatement(forOfStatement) { - return grammarErrorOnFirstToken(forOfStatement, ts.Diagnostics.for_of_statements_are_not_currently_supported); - if (languageVersion < 2) { - return grammarErrorOnFirstToken(forOfStatement, ts.Diagnostics.for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher); - } - return checkGrammarForInOrForOfStatement(forOfStatement); - } function checkGrammarAccessor(accessor) { var kind = accessor.kind; if (languageVersion < 1) { @@ -16196,7 +16588,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 & 499) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } else if (parameter.questionToken) { @@ -16261,7 +16653,7 @@ var ts; function checkGrammarBreakOrContinueStatement(node) { var current = node; while (current) { - if (ts.isAnyFunction(current)) { + if (ts.isFunctionLike(current)) { return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } switch (current.kind) { @@ -16309,16 +16701,17 @@ var ts; return checkGrammarEvalOrArgumentsInStrictMode(node, node.name); } function checkGrammarVariableDeclaration(node) { - if (ts.isInAmbientContext(node)) { - if (ts.isBindingPattern(node.name)) { - return grammarErrorOnNode(node, ts.Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); + if (node.parent.parent.kind !== 182 && node.parent.parent.kind !== 183) { + if (ts.isInAmbientContext(node)) { + if (ts.isBindingPattern(node.name)) { + return grammarErrorOnNode(node, ts.Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); + } + if (node.initializer) { + var equalsTokenLength = "=".length; + return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, equalsTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } } - if (node.initializer) { - return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - 1, 1, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); - } - } - else { - if (!node.initializer) { + else if (!node.initializer) { if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) { return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer); } @@ -16352,14 +16745,6 @@ var ts; if (!declarationList.declarations.length) { return grammarErrorAtPos(ts.getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); } - if (languageVersion < 2) { - if (ts.isLet(declarationList)) { - return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (ts.isConst(declarationList)) { - return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - } } function allowLetAndConstDeclarations(parent) { switch (parent.kind) { @@ -16399,7 +16784,7 @@ var ts; return false; } function checkGrammarEnumDeclaration(enumDecl) { - var enumIsConst = (enumDecl.flags & 4096) !== 0; + var enumIsConst = (enumDecl.flags & 8192) !== 0; var hasError = false; if (!enumIsConst) { var inConstantEnumMemberSection = true; @@ -16427,18 +16812,11 @@ var ts; function hasParseDiagnostics(sourceFile) { return sourceFile.parseDiagnostics.length > 0; } - function scanToken(scanner, pos) { - scanner.setTextPos(pos); - scanner.scan(); - var start = scanner.getTokenPos(); - return start; - } function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = ts.createScanner(languageVersion, true, sourceFile.text); - var start = scanToken(scanner, node.pos); - diagnostics.add(ts.createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2)); + var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos); + diagnostics.add(ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2)); return true; } } @@ -16451,16 +16829,17 @@ var ts; function grammarErrorOnNode(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var span = ts.getErrorSpanForNode(node); - var start = span.end > span.pos ? ts.skipTrivia(sourceFile.text, span.pos) : span.pos; - diagnostics.add(ts.createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2)); + diagnostics.add(ts.createDiagnosticForNode(node, message, arg0, arg1, arg2)); return true; } } - function checkGrammarEvalOrArgumentsInStrictMode(contextNode, identifier) { - if (contextNode && (contextNode.parserContextFlags & 1) && ts.isEvalOrArgumentsIdentifier(identifier)) { - var name = ts.declarationNameToString(identifier); - return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, name); + function checkGrammarEvalOrArgumentsInStrictMode(contextNode, name) { + if (name && name.kind === 64) { + var identifier = name; + if (contextNode && (contextNode.parserContextFlags & 1) && ts.isEvalOrArgumentsIdentifier(identifier)) { + var nameText = ts.declarationNameToString(identifier); + return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); + } } } function checkGrammarConstructorTypeParameters(node) { @@ -16524,7 +16903,7 @@ var ts; return getNodeLinks(node).hasReportedStatementInAmbientContext = true; } var links = getNodeLinks(node); - if (!links.hasReportedStatementInAmbientContext && ts.isAnyFunction(node.parent)) { + if (!links.hasReportedStatementInAmbientContext && ts.isFunctionLike(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); } if (node.parent.kind === 174 || node.parent.kind === 201 || node.parent.kind === 220) { @@ -16538,7 +16917,7 @@ var ts; } } function checkGrammarNumbericLiteral(node) { - if (node.flags & 8192) { + if (node.flags & 16384) { if (node.parserContextFlags & 1) { return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); } @@ -16550,9 +16929,8 @@ var ts; function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = ts.createScanner(languageVersion, true, sourceFile.text); - scanToken(scanner, node.pos); - diagnostics.add(ts.createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2)); + var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos); + diagnostics.add(ts.createFileDiagnostic(sourceFile, ts.textSpanEnd(span), 0, message, arg0, arg1, arg2)); return true; } } @@ -16824,7 +17202,7 @@ var ts; var addedGlobalFileReference = false; ts.forEach(root.referencedFiles, function (fileReference) { var referencedFile = ts.tryResolveScriptReference(host, root, fileReference); - if (referencedFile && ((referencedFile.flags & 1024) || + if (referencedFile && ((referencedFile.flags & 2048) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) { writeReferencePath(referencedFile); @@ -16983,11 +17361,11 @@ var ts; } function emitType(type) { switch (type.kind) { + case 111: + case 120: + case 118: case 112: case 121: - case 119: - case 113: - case 122: case 98: case 8: return writeTextOfNode(currentSourceFile, type); @@ -17077,8 +17455,8 @@ var ts; emitLines(node.statements); } function emitExportAssignment(node) { - write("export = "); - writeTextOfNode(currentSourceFile, node.exportName); + write(node.isExportEquals ? "export = " : "export default "); + writeTextOfNode(currentSourceFile, node.expression); write(";"); writeLine(); } @@ -17697,7 +18075,7 @@ var ts; } } function writeReferencePath(referencedFile) { - var declFileName = referencedFile.flags & 1024 ? referencedFile.fileName : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; + var declFileName = referencedFile.flags & 2048 ? referencedFile.fileName : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, host.getCurrentDirectory(), host.getCanonicalFileName, false); referencePathsOutput += "/// " + newLine; } @@ -17749,12 +18127,16 @@ var ts; var increaseIndent = writer.increaseIndent; var decreaseIndent = writer.decreaseIndent; var currentSourceFile; + var lastFrame; + var currentScopeNames; + var generatedBlockScopeNames; var extendsEmitted = false; var tempCount = 0; var tempVariables; var tempParameters; var externalImports; var exportSpecifiers; + var exportDefault; var writeEmittedFiles = writeJavaScriptFile; var emitLeadingComments = compilerOptions.removeComments ? function (node) { } : emitLeadingDeclarationComments; var emitTrailingComments = compilerOptions.removeComments ? function (node) { } : emitTrailingDeclarationComments; @@ -17786,6 +18168,53 @@ var ts; writeLine(); writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); return; + function enterNameScope() { + var names = currentScopeNames; + currentScopeNames = undefined; + if (names) { + lastFrame = { names: names, previous: lastFrame }; + return true; + } + return false; + } + function exitNameScope(popFrame) { + if (popFrame) { + currentScopeNames = lastFrame.names; + lastFrame = lastFrame.previous; + } + else { + currentScopeNames = undefined; + } + } + function generateUniqueNameForLocation(location, baseName) { + var name; + if (!isExistingName(location, baseName)) { + name = baseName; + } + else { + name = ts.generateUniqueName(baseName, function (n) { return isExistingName(location, n); }); + } + if (!currentScopeNames) { + currentScopeNames = {}; + } + return currentScopeNames[name] = name; + } + function isExistingName(location, name) { + if (!resolver.isUnknownIdentifier(location, name)) { + return true; + } + if (currentScopeNames && ts.hasProperty(currentScopeNames, name)) { + return true; + } + var frame = lastFrame; + while (frame) { + if (ts.hasProperty(frame.names, name)) { + return true; + } + frame = frame.previous; + } + return false; + } function initializeEmitterWithSourceMaps() { var sourceMapDir; var sourceMapSourceIndex = -1; @@ -18045,13 +18474,13 @@ var ts; function createTempVariable(location, forLoopVariable) { var name = forLoopVariable ? "_i" : undefined; while (true) { - if (name && resolver.isUnknownIdentifier(location, name)) { + if (name && !isExistingName(location, name)) { break; } name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + 97) : tempCount - 25); tempCount++; } - var result = ts.createNode(64); + var result = ts.createSynthesizedNode(64); result.text = name; return result; } @@ -18095,7 +18524,7 @@ var ts; emit(node); } } - function emitParenthesized(node, parenthesized) { + function emitParenthesizedIf(node, parenthesized) { if (parenthesized) { write("("); } @@ -18182,30 +18611,100 @@ var ts; emit(nodes[i]); } } - function isBinaryOrOctalIntegerLiteral(text) { - if (text.length <= 0) { - return false; - } - if (text.charCodeAt(1) === 66 || text.charCodeAt(1) === 98 || - text.charCodeAt(1) === 79 || text.charCodeAt(1) === 111) { - return true; + function isBinaryOrOctalIntegerLiteral(node, text) { + if (node.kind === 7 && text.length > 1) { + switch (text.charCodeAt(1)) { + case 98: + case 66: + case 111: + case 79: + return true; + } } 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 = getLiteralText(node); if (compilerOptions.sourceMap && (node.kind === 8 || ts.isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } - else if (languageVersion < 2 && node.kind === 7 && isBinaryOrOctalIntegerLiteral(text)) { + else if (languageVersion < 2 && isBinaryOrOctalIntegerLiteral(node, text)) { write(node.text); } else { write(text); } } - function getTemplateLiteralAsStringLiteral(node) { - return '"' + ts.escapeString(node.text) + '"'; + function getLiteralText(node) { + if (languageVersion < 2 && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { + return getQuotedEscapedLiteralText('"', node.text, '"'); + } + if (node.parent) { + return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + } + switch (node.kind) { + case 8: + return getQuotedEscapedLiteralText('"', node.text, '"'); + case 10: + return getQuotedEscapedLiteralText('`', node.text, '`'); + case 11: + return getQuotedEscapedLiteralText('`', node.text, '${'); + case 12: + return getQuotedEscapedLiteralText('}', node.text, '${'); + case 13: + return getQuotedEscapedLiteralText('}', node.text, '`'); + case 7: + return node.text; + } + ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for."); + } + function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) { + return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote; + } + function emitDownlevelRawTemplateLiteral(node) { + var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + var isLast = node.kind === 10 || node.kind === 13; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + text = text.replace(/\r\n?/g, "\n"); + text = ts.escapeString(text); + write('"' + text + '"'); + } + function emitDownlevelTaggedTemplateArray(node, literalEmitter) { + write("["); + if (node.template.kind === 10) { + literalEmitter(node.template); + } + else { + literalEmitter(node.template.head); + ts.forEach(node.template.templateSpans, function (child) { + write(", "); + literalEmitter(child.literal); + }); + } + write("]"); + } + function emitDownlevelTaggedTemplate(node) { + var tempVariable = createAndRecordTempVariable(node); + write("("); + emit(tempVariable); + write(" = "); + emitDownlevelTaggedTemplateArray(node, emit); + write(", "); + emit(tempVariable); + write(".raw = "); + emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); + write(", "); + emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); + write("("); + emit(tempVariable); + if (node.template.kind === 169) { + ts.forEach(node.template.templateSpans, function (templateSpan) { + write(", "); + var needsParens = templateSpan.expression.kind === 167 && templateSpan.expression.operatorToken.kind === 23; + emitParenthesizedIf(templateSpan.expression, needsParens); + }); + } + write("))"); } function emitTemplateExpression(node) { if (languageVersion >= 2) { @@ -18227,7 +18726,7 @@ var ts; if (i > 0 || headEmitted) { write(" + "); } - emitParenthesized(templateSpan.expression, needsParens); + emitParenthesizedIf(templateSpan.expression, needsParens); if (templateSpan.literal.text.length !== 0) { write(" + "); emitLiteral(templateSpan.literal); @@ -18325,8 +18824,6 @@ var ts; return false; case 189: return node.parent.label === node; - case 216: - return node.parent.name === node; } } function emitExpressionIdentifier(node) { @@ -18338,7 +18835,18 @@ var ts; writeTextOfNode(currentSourceFile, node); } } + function getBlockScopedVariableId(node) { + return !ts.nodeIsSynthesized(node) && resolver.getBlockScopedVariableId(node); + } function emitIdentifier(node) { + var variableId = getBlockScopedVariableId(node); + if (variableId !== undefined && generatedBlockScopeNames) { + var text = generatedBlockScopeNames[variableId]; + if (text) { + write(text); + return; + } + } if (!node.parent) { write(node.text); } @@ -18401,7 +18909,7 @@ var ts; write("..."); emit(node.expression); } - function needsParenthesisForPropertyAccess(node) { + function needsParenthesisForPropertyAccessOrInvocation(node) { switch (node.kind) { case 64: case 151: @@ -18427,7 +18935,7 @@ var ts; var e = elements[pos]; if (e.kind === 171) { e = e.expression; - emitParenthesized(e, group === 0 && needsParenthesisForPropertyAccess(e)); + emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; } else { @@ -18466,24 +18974,18 @@ var ts; write("]"); } else { - emitListWithSpread(elements, (node.flags & 256) !== 0, elements.hasTrailingComma); + emitListWithSpread(elements, (node.flags & 512) !== 0, elements.hasTrailingComma); } } - function createSynthesizedNode(kind) { - var node = ts.createNode(kind); - node.pos = -1; - node.end = -1; - return node; - } function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) { var parenthesizedObjectLiteral = createDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex); return emit(parenthesizedObjectLiteral); } function createDownlevelObjectLiteralWithComputedProperties(originalObjectLiteral, firstComputedPropertyIndex) { var tempVar = createAndRecordTempVariable(originalObjectLiteral); - var initialObjectLiteral = createSynthesizedNode(152); + var initialObjectLiteral = ts.createSynthesizedNode(152); initialObjectLiteral.properties = originalObjectLiteral.properties.slice(0, firstComputedPropertyIndex); - initialObjectLiteral.flags |= 256; + initialObjectLiteral.flags |= 512; var propertyPatches = createBinaryExpression(tempVar, 52, initialObjectLiteral); ts.forEach(originalObjectLiteral.properties, function (property) { var patchedProperty = tryCreatePatchingPropertyAssignment(originalObjectLiteral, tempVar, property); @@ -18491,7 +18993,7 @@ var ts; propertyPatches = createBinaryExpression(propertyPatches, 23, patchedProperty); } }); - propertyPatches = createBinaryExpression(propertyPatches, 23, tempVar); + propertyPatches = createBinaryExpression(propertyPatches, 23, createIdentifier(tempVar.text, true)); var result = createParenthesizedExpression(propertyPatches); return result; } @@ -18502,7 +19004,7 @@ var ts; function tryCreatePatchingPropertyAssignment(objectLiteral, tempVar, property) { var leftHandSide = createMemberAccessForPropertyName(tempVar, property.name); var maybeRightHandSide = tryGetRightHandSideOfPatchingPropertyAssignment(objectLiteral, property); - return maybeRightHandSide && createBinaryExpression(leftHandSide, 52, maybeRightHandSide); + return maybeRightHandSide && createBinaryExpression(leftHandSide, 52, maybeRightHandSide, true); } function tryGetRightHandSideOfPatchingPropertyAssignment(objectLiteral, property) { switch (property.kind) { @@ -18518,7 +19020,7 @@ var ts; if (firstAccessor !== property) { return undefined; } - var propertyDescriptor = createSynthesizedNode(152); + var propertyDescriptor = ts.createSynthesizedNode(152); var descriptorProperties = []; if (getAccessor) { var getProperty = createPropertyAssignment(createIdentifier("get"), createFunctionExpression(getAccessor.parameters, getAccessor.body)); @@ -18528,7 +19030,7 @@ var ts; var setProperty = createPropertyAssignment(createIdentifier("set"), createFunctionExpression(setAccessor.parameters, setAccessor.body)); descriptorProperties.push(setProperty); } - var trueExpr = createSynthesizedNode(94); + var trueExpr = ts.createSynthesizedNode(94); var enumerableTrue = createPropertyAssignment(createIdentifier("enumerable"), trueExpr); descriptorProperties.push(enumerableTrue); var configurableTrue = createPropertyAssignment(createIdentifier("configurable"), trueExpr); @@ -18541,7 +19043,7 @@ var ts; } } function createParenthesizedExpression(expression) { - var result = createSynthesizedNode(159); + var result = ts.createSynthesizedNode(159); result.expression = expression; return result; } @@ -18555,9 +19057,9 @@ var ts; result.end = -1; return result; } - function createBinaryExpression(left, operator, right) { - var result = createSynthesizedNode(167); - result.operatorToken = createSynthesizedNode(operator); + function createBinaryExpression(left, operator, right, startsOnNewLine) { + var result = ts.createSynthesizedNode(167, startsOnNewLine); + result.operatorToken = ts.createSynthesizedNode(operator); result.left = left; result.right = right; return result; @@ -18577,36 +19079,37 @@ var ts; } } function createPropertyAssignment(name, initializer) { - var result = createSynthesizedNode(217); + var result = ts.createSynthesizedNode(217); result.name = name; result.initializer = initializer; return result; } function createFunctionExpression(parameters, body) { - var result = createSynthesizedNode(160); + var result = ts.createSynthesizedNode(160); result.parameters = parameters; result.body = body; return result; } function createPropertyAccessExpression(expression, name) { - var result = createSynthesizedNode(153); + var result = ts.createSynthesizedNode(153); result.expression = expression; + result.dotToken = ts.createSynthesizedNode(20); result.name = name; return result; } function createElementAccessExpression(expression, argumentExpression) { - var result = createSynthesizedNode(154); + var result = ts.createSynthesizedNode(154); result.expression = expression; result.argumentExpression = argumentExpression; return result; } - function createIdentifier(name) { - var result = createSynthesizedNode(64); + function createIdentifier(name, startsOnNewLine) { + var result = ts.createSynthesizedNode(64, startsOnNewLine); result.text = name; return result; } function createCallExpression(invokedExpression, arguments) { - var result = createSynthesizedNode(155); + var result = ts.createSynthesizedNode(155); result.expression = invokedExpression; result.arguments = arguments; return result; @@ -18671,13 +19174,29 @@ var ts; } return false; } + function indentIfOnDifferentLines(parent, node1, node2) { + var isSynthesized = ts.nodeIsSynthesized(parent); + var realNodesAreOnDifferentLines = !isSynthesized && !nodeEndIsOnSameLineAsNodeStart(node1, node2); + var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2); + if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) { + increaseIndent(); + writeLine(); + return true; + } + return false; + } function emitPropertyAccess(node) { if (tryEmitConstantValue(node)) { return; } emit(node.expression); + var indented = indentIfOnDifferentLines(node, node.expression, node.dotToken); write("."); + indented = indented || indentIfOnDifferentLines(node, node.dotToken, node.name); emit(node.name); + if (indented) { + decreaseIndent(); + } } function emitQualifiedName(node) { emit(node.left); @@ -18791,26 +19310,33 @@ var ts; } } function emitTaggedTemplateExpression(node) { - emit(node.tag); - write(" "); - emit(node.template); + if (compilerOptions.target >= 2) { + emit(node.tag); + write(" "); + emit(node.template); + } + else { + emitDownlevelTaggedTemplate(node); + } } function emitParenExpression(node) { - if (node.expression.kind === 158) { - var operand = node.expression.expression; - while (operand.kind == 158) { - operand = operand.expression; - } - if (operand.kind !== 165 && - operand.kind !== 164 && - operand.kind !== 163 && - operand.kind !== 162 && - operand.kind !== 166 && - operand.kind !== 156 && - !(operand.kind === 155 && node.parent.kind === 156) && - !(operand.kind === 160 && node.parent.kind === 155)) { - emit(operand); - return; + if (!node.parent || node.parent.kind !== 161) { + if (node.expression.kind === 158) { + var operand = node.expression.expression; + while (operand.kind == 158) { + operand = operand.expression; + } + if (operand.kind !== 165 && + operand.kind !== 164 && + operand.kind !== 163 && + operand.kind !== 162 && + operand.kind !== 166 && + operand.kind !== 156 && + !(operand.kind === 155 && node.parent.kind === 156) && + !(operand.kind === 160 && node.parent.kind === 155)) { + emit(operand); + return; + } } } write("("); @@ -18856,48 +19382,58 @@ var ts; } else { emit(node.left); - if (node.operatorToken.kind !== 23) { + var indented1 = indentIfOnDifferentLines(node, node.left, node.operatorToken); + if (!indented1 && node.operatorToken.kind !== 23) { write(" "); } write(ts.tokenToString(node.operatorToken.kind)); - var operatorEnd = ts.getLineAndCharacterOfPosition(currentSourceFile, node.operatorToken.end); - var rightStart = ts.getLineAndCharacterOfPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.right.pos)); - var onDifferentLine = operatorEnd.line !== rightStart.line; - if (onDifferentLine) { - var exprStart = ts.getLineAndCharacterOfPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); - var firstCharOfExpr = getFirstNonWhitespaceCharacterIndexOnLine(exprStart.line); - var shouldIndent = rightStart.character > firstCharOfExpr; - if (shouldIndent) { - increaseIndent(); - } - writeLine(); + if (!indented1) { + var indented2 = indentIfOnDifferentLines(node, node.operatorToken, node.right); } - else { + if (!indented2) { write(" "); } emit(node.right); - if (shouldIndent) { + if (indented1 || indented2) { decreaseIndent(); } } } - function getFirstNonWhitespaceCharacterIndexOnLine(line) { - var lineStart = ts.getLineStarts(currentSourceFile)[line]; - var text = currentSourceFile.text; - for (var i = lineStart; i < text.length; i++) { - var ch = text.charCodeAt(i); - if (!ts.isWhiteSpace(text.charCodeAt(i)) || ts.isLineBreak(ch)) { - break; - } - } - return i - lineStart; + function synthesizedNodeStartsOnNewLine(node) { + return ts.nodeIsSynthesized(node) && node.startsOnNewLine; } function emitConditionalExpression(node) { emit(node.condition); - write(" ? "); + var indent1 = indentIfOnDifferentLines(node, node.condition, node.questionToken); + if (!indent1) { + write(" "); + } + write("?"); + if (!indent1) { + var indent2 = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue); + } + if (!indent2) { + write(" "); + } emit(node.whenTrue); - write(" : "); + if (indent1 || indent2) { + decreaseIndent(); + } + var indent3 = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken); + if (!indent3) { + write(" "); + } + write(":"); + if (!indent3) { + var indent4 = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse); + } + if (!indent4) { + write(" "); + } emit(node.whenFalse); + if (indent3 || indent4) { + decreaseIndent(); + } } function isSingleLineEmptyBlock(node) { if (node && node.kind === 174) { @@ -18941,7 +19477,7 @@ var ts; } } function emitExpressionStatement(node) { - emitParenthesized(node.expression, node.expression.kind === 161); + emitParenthesizedIf(node.expression, node.expression.kind === 161); write(";"); } function emitIfStatement(node) { @@ -18982,6 +19518,30 @@ var ts; write(")"); emitEmbeddedStatement(node.statement); } + function emitStartOfVariableDeclarationList(decl, startPos) { + var tokenKind = 97; + if (decl && languageVersion >= 2) { + if (ts.isLet(decl)) { + tokenKind = 104; + } + else if (ts.isConst(decl)) { + tokenKind = 69; + } + } + if (startPos !== undefined) { + emitToken(tokenKind, startPos); + } + else { + switch (tokenKind) { + case 97: + return write("var "); + case 104: + return write("let "); + case 69: + return write("const "); + } + } + } function emitForStatement(node) { var endPos = emitToken(81, node.pos); write(" "); @@ -18989,17 +19549,9 @@ var ts; if (node.initializer && node.initializer.kind === 194) { var variableDeclarationList = node.initializer; var declarations = variableDeclarationList.declarations; - if (declarations[0] && ts.isLet(declarations[0])) { - emitToken(105, endPos); - } - else if (declarations[0] && ts.isConst(declarations[0])) { - emitToken(69, endPos); - } - else { - emitToken(97, endPos); - } + emitStartOfVariableDeclarationList(declarations[0], endPos); write(" "); - emitCommaList(variableDeclarationList.declarations); + emitCommaList(declarations); } else if (node.initializer) { emit(node.initializer); @@ -19019,12 +19571,7 @@ var ts; var variableDeclarationList = node.initializer; if (variableDeclarationList.declarations.length >= 1) { var decl = variableDeclarationList.declarations[0]; - if (ts.isLet(decl)) { - emitToken(105, endPos); - } - else { - emitToken(97, endPos); - } + emitStartOfVariableDeclarationList(decl, endPos); write(" "); emit(decl); } @@ -19123,8 +19670,8 @@ var ts; var endPos = emitToken(67, node.pos); write(" "); emitToken(16, endPos); - emit(node.name); - emitToken(17, node.name.end); + emit(node.variableDeclaration); + emitToken(17, node.variableDeclaration ? node.variableDeclaration.end : endPos); write(" "); emitBlock(node.block); } @@ -19156,8 +19703,15 @@ var ts; emitNode(node.name); emitEnd(node.name); } + function createVoidZero() { + var zero = ts.createSynthesizedNode(7); + zero.text = "0"; + var result = ts.createSynthesizedNode(164); + result.expression = zero; + return result; + } function emitExportMemberAssignments(name) { - if (exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { + if (!exportDefault && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { ts.forEach(exportSpecifiers[name.text], function (specifier) { writeLine(); emitStart(specifier.name); @@ -19184,6 +19738,7 @@ var ts; if (emitCount++) { write(", "); } + renameNonTopLevelLetAndConst(name); if (name.parent && (name.parent.kind === 193 || name.parent.kind === 150)) { emitModuleMemberName(name.parent); } @@ -19204,27 +19759,25 @@ var ts; } return expr; } - function createVoidZero() { - var zero = ts.createNode(7); - zero.text = "0"; - var result = ts.createNode(164); - result.expression = zero; - return result; - } function createDefaultValueCheck(value, defaultValue) { value = ensureIdentifier(value); - var equals = ts.createNode(167); + var equals = ts.createSynthesizedNode(167); equals.left = value; - equals.operatorToken = ts.createNode(30); + equals.operatorToken = ts.createSynthesizedNode(30); equals.right = createVoidZero(); - var cond = ts.createNode(168); - cond.condition = equals; - cond.whenTrue = defaultValue; - cond.whenFalse = value; + return createConditionalExpression(equals, defaultValue, value); + } + function createConditionalExpression(condition, whenTrue, whenFalse) { + var cond = ts.createSynthesizedNode(168); + cond.condition = condition; + cond.questionToken = ts.createSynthesizedNode(50); + cond.whenTrue = whenTrue; + cond.colonToken = ts.createSynthesizedNode(51); + cond.whenFalse = whenFalse; return cond; } function createNumericLiteral(value) { - var node = ts.createNode(7); + var node = ts.createSynthesizedNode(7); node.text = "" + value; return node; } @@ -19232,7 +19785,7 @@ var ts; if (expr.kind === 64 || expr.kind === 153 || expr.kind === 154) { return expr; } - var node = ts.createNode(159); + var node = ts.createSynthesizedNode(159); node.expression = expr; return node; } @@ -19240,13 +19793,10 @@ var ts; if (propName.kind !== 64) { return createElementAccess(object, propName); } - var node = ts.createNode(153); - node.expression = parenthesizeForAccess(object); - node.name = propName; - return node; + return createPropertyAccessExpression(parenthesizeForAccess(object), propName); } function createElementAccess(object, index) { - var node = ts.createNode(154); + var node = ts.createSynthesizedNode(154); node.expression = parenthesizeForAccess(object); node.argumentExpression = index; return node; @@ -19368,8 +19918,19 @@ var ts; } } else { + var isLet = renameNonTopLevelLetAndConst(node.name); emitModuleMemberName(node); - emitOptional(" = ", node.initializer); + var initializer = node.initializer; + if (!initializer && languageVersion < 2) { + var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 256) && + (getCombinedFlagsForIdentifier(node.name) & 4096); + if (isUninitializedLet && + node.parent.parent.kind !== 182 && + node.parent.parent.kind !== 183) { + initializer = createVoidZero(); + } + } + emitOptional(" = ", initializer); } } function emitExportVariableAssignments(node) { @@ -19381,17 +19942,62 @@ var ts; ts.forEach(name.elements, emitExportVariableAssignments); } } + function getEnclosingBlockScopeContainer(node) { + var current = node; + while (current) { + if (ts.isFunctionLike(current)) { + return current; + } + switch (current.kind) { + case 220: + case 91: + case 216: + case 200: + case 181: + case 182: + case 183: + return current; + case 174: + if (!ts.isFunctionLike(current.parent)) { + return current; + } + } + current = current.parent; + } + } + function getCombinedFlagsForIdentifier(node) { + if (!node.parent || (node.parent.kind !== 193 && node.parent.kind !== 150)) { + return 0; + } + return ts.getCombinedNodeFlags(node.parent); + } + function renameNonTopLevelLetAndConst(node) { + if (languageVersion >= 2 || + ts.nodeIsSynthesized(node) || + node.kind !== 64 || + (node.parent.kind !== 193 && node.parent.kind !== 150)) { + return; + } + var combinedFlags = getCombinedFlagsForIdentifier(node); + if (((combinedFlags & 12288) === 0) || combinedFlags & 1) { + return; + } + var list = ts.getAncestor(node, 194); + if (list.parent.kind === 175 && list.parent.parent.kind === 220) { + return; + } + var blockScopeContainer = getEnclosingBlockScopeContainer(node); + var parent = blockScopeContainer.kind === 220 ? blockScopeContainer : blockScopeContainer.parent; + var generatedName = generateUniqueNameForLocation(parent, node.text); + var variableId = resolver.getBlockScopedVariableId(node); + if (!generatedBlockScopeNames) { + generatedBlockScopeNames = []; + } + generatedBlockScopeNames[variableId] = generatedName; + } function emitVariableStatement(node) { if (!(node.flags & 1)) { - if (ts.isLet(node.declarationList)) { - write("let "); - } - else if (ts.isConst(node.declarationList)) { - write("const "); - } - else { - write("var "); - } + emitStartOfVariableDeclarationList(node.declarationList); } emitCommaList(node.declarationList.declarations); write(";"); @@ -19496,6 +20102,14 @@ var ts; function shouldEmitAsArrowFunction(node) { return node.kind === 161 && languageVersion >= 2; } + function emitDeclarationName(node) { + if (node.name) { + emitNode(node.name); + } + else { + write(resolver.getGeneratedNameForNode(node)); + } + } function emitFunctionDeclaration(node) { if (ts.nodeIsMissing(node.body)) { return emitPinnedOrTripleSlashComments(node); @@ -19507,10 +20121,10 @@ var ts; write("function "); } if (node.kind === 195 || (node.kind === 160 && node.name)) { - emit(node.name); + emitDeclarationName(node); } emitSignatureAndBody(node); - if (languageVersion < 2 && node.kind === 195 && node.parent === currentSourceFile) { + if (languageVersion < 2 && node.kind === 195 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } if (node.kind !== 132 && node.kind !== 131) { @@ -19550,6 +20164,7 @@ var ts; tempCount = 0; tempVariables = undefined; tempParameters = undefined; + var popFrame = enterNameScope(); if (shouldEmitAsArrowFunction(node)) { emitSignatureParametersForArrow(node); write(" =>"); @@ -19566,15 +20181,16 @@ var ts; else { emitExpressionFunctionBody(node, node.body); } - if (node.flags & 1) { + if (node.flags & 1 && !(node.flags & 256)) { writeLine(); emitStart(node); emitModuleMemberName(node); write(" = "); - emit(node.name); + emitDeclarationName(node); emitEnd(node); write(";"); } + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; @@ -19590,7 +20206,11 @@ var ts; return; } write(" "); - emit(body); + var current = body; + while (current.kind === 158) { + current = current.expression; + } + emitParenthesizedIf(body, current.kind === 152); } function emitDownLevelExpressionFunctionBody(node, body) { write(" {"); @@ -19629,45 +20249,15 @@ var ts; scopeEmitEnd(); } function emitBlockFunctionBody(node, body) { - if (body.statements.length === 0 && !anyParameterHasBindingPatternOrInitializer(node)) { - emitFunctionBodyWithNoStatements(node, body); - } - else { - emitFunctionBodyWithStatements(node, body); - } - } - function anyParameterHasBindingPatternOrInitializer(func) { - return ts.forEach(func.parameters, hasBindingPatternOrInitializer); - } - function hasBindingPatternOrInitializer(parameter) { - return parameter.initializer || ts.isBindingPattern(parameter.name); - } - function emitFunctionBodyWithNoStatements(node, body) { - var singleLine = isSingleLineEmptyBlock(node.body); - write(" {"); - if (singleLine) { - write(" "); - } - else { - increaseIndent(); - writeLine(); - } - emitLeadingCommentsOfPosition(body.statements.end); - if (!singleLine) { - decreaseIndent(); - } - emitToken(15, body.statements.end); - } - function emitFunctionBodyWithStatements(node, body) { write(" {"); scopeEmitStart(node); - var outPos = writer.getTextPos(); + var initialTextPos = writer.getTextPos(); increaseIndent(); emitDetachedComments(body.statements); var startIndex = emitDirectivePrologues(body.statements, true); emitFunctionBodyPreamble(node); decreaseIndent(); - var preambleEmitted = writer.getTextPos() !== outPos; + var preambleEmitted = writer.getTextPos() !== initialTextPos; if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) { for (var i = 0, n = body.statements.length; i < n; i++) { write(" "); @@ -19740,7 +20330,7 @@ var ts; emitStart(member); emitStart(member.name); if (staticFlag) { - emitNode(node.name); + emitDeclarationName(node); } else { write("this"); @@ -19765,7 +20355,7 @@ var ts; emitLeadingComments(member); emitStart(member); emitStart(member.name); - emitNode(node.name); + emitDeclarationName(node); if (!(member.flags & 128)) { write(".prototype"); } @@ -19786,7 +20376,7 @@ var ts; emitStart(member); write("Object.defineProperty("); emitStart(member.name); - emitNode(node.name); + emitDeclarationName(node); if (!(member.flags & 128)) { write(".prototype"); } @@ -19831,7 +20421,7 @@ var ts; } function emitClassDeclaration(node) { write("var "); - emit(node.name); + emitDeclarationName(node); write(" = (function ("); var baseTypeNode = ts.getClassBaseTypeNode(node); if (baseTypeNode) { @@ -19844,7 +20434,7 @@ var ts; writeLine(); emitStart(baseTypeNode); write("__extends("); - emit(node.name); + emitDeclarationName(node); write(", _super);"); emitEnd(baseTypeNode); } @@ -19853,11 +20443,10 @@ var ts; emitMemberFunctions(node); emitMemberAssignments(node, 128); writeLine(); - function emitClassReturnStatement() { + emitToken(15, node.members.end, function () { write("return "); - emitNode(node.name); - } - emitToken(15, node.members.end, emitClassReturnStatement); + emitDeclarationName(node); + }); write(";"); decreaseIndent(); writeLine(); @@ -19870,16 +20459,16 @@ var ts; } write(");"); emitEnd(node); - if (node.flags & 1) { + if (node.flags & 1 && !(node.flags & 256)) { writeLine(); emitStart(node); emitModuleMemberName(node); write(" = "); - emit(node.name); + emitDeclarationName(node); emitEnd(node); write(";"); } - if (languageVersion < 2 && node.parent === currentSourceFile) { + if (languageVersion < 2 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } function emitConstructorOfClass() { @@ -19889,6 +20478,7 @@ var ts; tempCount = 0; tempVariables = undefined; tempParameters = undefined; + var popFrame = enterNameScope(); ts.forEach(node.members, function (member) { if (member.kind === 133 && !member.body) { emitPinnedOrTripleSlashComments(member); @@ -19900,7 +20490,7 @@ var ts; } emitStart(ctor || node); write("function "); - emit(node.name); + emitDeclarationName(node); emitSignatureParameters(ctor); write(" {"); scopeEmitStart(node, "constructor"); @@ -19948,6 +20538,7 @@ var ts; if (ctor) { emitTrailingComments(ctor); } + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; @@ -20066,7 +20657,9 @@ var ts; var saveTempVariables = tempVariables; tempCount = 0; tempVariables = undefined; + var popFrame = enterNameScope(); emit(node.body); + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; } @@ -20155,7 +20748,7 @@ var ts; emitImportDeclaration(node); return; } - if (resolver.isReferencedImportDeclaration(node) || + if (resolver.isReferencedAliasDeclaration(node) || (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { emitLeadingComments(node); emitStart(node); @@ -20251,17 +20844,29 @@ var ts; function createExternalModuleInfo(sourceFile) { externalImports = []; exportSpecifiers = {}; + exportDefault = undefined; ts.forEach(sourceFile.statements, function (node) { if (node.kind === 209 && !node.moduleSpecifier) { ts.forEach(node.exportClause.elements, function (specifier) { + if (specifier.name.text === "default") { + exportDefault = exportDefault || specifier; + } var name = (specifier.propertyName || specifier.name).text; (exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier); }); } + else if (node.kind === 208) { + exportDefault = exportDefault || node; + } + else if (node.kind === 195 || node.kind === 196) { + if (node.flags & 1 && node.flags & 256) { + exportDefault = exportDefault || node; + } + } else { var info = createExternalImportInfo(node); if (info) { - if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedImportDeclaration(node)) { + if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedAliasDeclaration(node)) { externalImports.push(info); } } @@ -20342,18 +20947,7 @@ var ts; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(true); - var exportName = resolver.getExportAssignmentName(node); - if (exportName) { - writeLine(); - var exportAssignment = getFirstExportAssignment(node); - emitStart(exportAssignment); - write("return "); - emitStart(exportAssignment.exportName); - write(exportName); - emitEnd(exportAssignment.exportName); - write(";"); - emitEnd(exportAssignment); - } + emitExportDefault(node, true); decreaseIndent(); writeLine(); write("});"); @@ -20362,17 +20956,24 @@ var ts; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(true); - var exportName = resolver.getExportAssignmentName(node); - if (exportName) { + emitExportDefault(node, false); + } + function emitExportDefault(sourceFile, emitAsReturn) { + if (exportDefault && resolver.hasExportDefaultValue(sourceFile)) { writeLine(); - var exportAssignment = getFirstExportAssignment(node); - emitStart(exportAssignment); - write("module.exports = "); - emitStart(exportAssignment.exportName); - write(exportName); - emitEnd(exportAssignment.exportName); + emitStart(exportDefault); + write(emitAsReturn ? "return " : "module.exports = "); + if (exportDefault.kind === 208) { + emit(exportDefault.expression); + } + else if (exportDefault.kind === 211) { + emit(exportDefault.propertyName); + } + else { + emitDeclarationName(exportDefault); + } write(";"); - emitEnd(exportAssignment); + emitEnd(exportDefault); } } function emitDirectivePrologues(statements, startWithNewLine) { @@ -20423,6 +21024,7 @@ var ts; else { externalImports = undefined; exportSpecifiers = undefined; + exportDefault = undefined; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(true); @@ -20742,6 +21344,7 @@ var ts; var ts; (function (ts) { ts.emitTime = 0; + ts.ioReadTime = 0; function createCompilerHost(options) { var currentDirectory; var existingDirectories = {}; @@ -20751,7 +21354,9 @@ var ts; var unsupportedFileEncodingErrorCode = -2147024809; function getSourceFile(fileName, languageVersion, onError) { try { + var start = new Date().getTime(); var text = ts.sys.readFile(fileName, options.charset); + ts.ioReadTime += new Date().getTime() - start; } catch (e) { if (onError) { @@ -20888,8 +21493,9 @@ var ts; if (options.noEmitOnError && getPreEmitDiagnostics(this).length > 0) { return { diagnostics: [], sourceMaps: undefined, emitSkipped: true }; } + var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); var start = new Date().getTime(); - var emitResult = ts.emitFiles(getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile), getEmitHost(writeFileCallback), sourceFile); + var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile); ts.emitTime += new Date().getTime() - start; return emitResult; } @@ -21078,20 +21684,18 @@ var ts; } return; } - var firstExternalModule = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); - if (firstExternalModule && !options.module) { - var externalModuleErrorSpan = ts.getErrorSpanForNode(firstExternalModule.externalModuleIndicator); - var errorStart = ts.skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos); - var errorLength = externalModuleErrorSpan.end - errorStart; - diagnostics.add(ts.createFileDiagnostic(firstExternalModule, errorStart, errorLength, ts.Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); + if (firstExternalModuleSourceFile && !options.module) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + diagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); } if (options.outDir || options.sourceRoot || (options.mapRoot && - (!options.out || firstExternalModule !== undefined))) { + (!options.out || firstExternalModuleSourceFile !== undefined))) { var commonPathComponents; ts.forEach(files, function (sourceFile) { - if (!(sourceFile.flags & 1024) && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { + if (!(sourceFile.flags & 2048) && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, host.getCurrentDirectory()); sourcePathComponents.pop(); if (commonPathComponents) { @@ -21668,7 +22272,7 @@ var ts; compilerHost.getSourceFile = getSourceFile; } var compileResult = compile(rootFileNames, compilerOptions, compilerHost); - if (!commandLine.options.watch) { + if (!compilerOptions.watch) { return ts.sys.exit(compileResult.exitStatus); } setCachedProgram(compileResult.program); @@ -21682,7 +22286,7 @@ var ts; } } var sourceFile = hostGetSourceFile(fileName, languageVersion, onError); - if (sourceFile && commandLine.options.watch) { + if (sourceFile && compilerOptions.watch) { sourceFile.fileWatcher = ts.sys.watchFile(sourceFile.fileName, function () { return sourceFileChanged(sourceFile); }); } return sourceFile; @@ -21723,14 +22327,17 @@ var ts; } ts.executeCommandLine = executeCommandLine; function compile(fileNames, compilerOptions, compilerHost) { + ts.ioReadTime = 0; ts.parseTime = 0; ts.bindTime = 0; ts.checkTime = 0; ts.emitTime = 0; var start = new Date().getTime(); var program = ts.createProgram(fileNames, compilerOptions, compilerHost); + var programTime = new Date().getTime() - start; var exitStatus = compileProgram(); var end = new Date().getTime() - start; + var compileTime = end - programTime; if (compilerOptions.listFiles) { ts.forEach(program.getSourceFiles(), function (file) { ts.sys.write(file.fileName + ts.sys.newLine); @@ -21747,10 +22354,13 @@ var ts; if (memoryUsed >= 0) { reportStatisticalValue("Memory used", Math.round(memoryUsed / 1000) + "K"); } - reportTimeStatistic("Parse time", ts.parseTime); + reportTimeStatistic("Parse time", programTime); reportTimeStatistic("Bind time", ts.bindTime); reportTimeStatistic("Check time", ts.checkTime); reportTimeStatistic("Emit time", ts.emitTime); + reportTimeStatistic("Parse time w/o IO", ts.parseTime); + reportTimeStatistic("IO read", ts.ioReadTime); + reportTimeStatistic("Compile time", compileTime); reportTimeStatistic("Total time", end); } return { program: program, exitStatus: exitStatus }; diff --git a/bin/tsserver.js b/bin/tsserver.js index fa69f8cf5fa..3c4c266cb70 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -248,7 +248,9 @@ var ts; } ts.localizedDiagnosticMessages = undefined; function getLocaleSpecificMessage(message) { - return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message] ? ts.localizedDiagnosticMessages[message] : message; + return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message] + ? ts.localizedDiagnosticMessages[message] + : message; } ts.getLocaleSpecificMessage = getLocaleSpecificMessage; function createFileDiagnostic(file, start, length, message) { @@ -396,7 +398,9 @@ var ts; normalized.pop(); } else { - normalized.push(part); + if (part) { + normalized.push(part); + } } } } @@ -539,7 +543,7 @@ var ts; } ts.removeFileExtension = removeFileExtension; var backslashOrDoubleQuote = /[\"\\]/g; - var escapedCharsRegExp = /[\0-\19\t\v\f\b\0\r\n\u2028\u2029\u0085]/g; + var escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g; var escapedCharsMap = { "\0": "\\0", "\t": "\\t", @@ -554,20 +558,6 @@ var ts; "\u2029": "\\u2029", "\u0085": "\\u0085" }; - function escapeString(s) { - s = backslashOrDoubleQuote.test(s) ? s.replace(backslashOrDoubleQuote, getReplacement) : s; - s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s; - return s; - function getReplacement(c) { - return escapedCharsMap[c] || unicodeEscape(c); - } - function unicodeEscape(c) { - var hexCharCode = c.charCodeAt(0).toString(16); - var paddedHexCode = ("0000" + hexCharCode).slice(-4); - return "\\u" + paddedHexCode; - } - } - ts.escapeString = escapeString; function getDefaultLibFileName(options) { return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts"; } @@ -880,7 +870,6 @@ var ts; Trailing_comma_not_allowed: { code: 1009, category: 1, key: "Trailing comma not allowed." }, Asterisk_Slash_expected: { code: 1010, category: 1, key: "'*/' expected." }, Unexpected_token: { code: 1012, category: 1, key: "Unexpected token." }, - Catch_clause_parameter_cannot_have_a_type_annotation: { code: 1013, category: 1, key: "Catch clause parameter cannot have a type annotation." }, A_rest_parameter_must_be_last_in_a_parameter_list: { code: 1014, category: 1, key: "A rest parameter must be last in a parameter list." }, Parameter_cannot_have_question_mark_and_initializer: { code: 1015, category: 1, key: "Parameter cannot have question mark and initializer." }, A_required_parameter_cannot_follow_an_optional_parameter: { code: 1016, category: 1, key: "A required parameter cannot follow an optional parameter." }, @@ -988,7 +977,6 @@ var ts; const_declarations_must_be_initialized: { code: 1155, category: 1, key: "'const' declarations must be initialized" }, const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: 1, key: "'const' declarations can only be declared inside a block." }, let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: 1, key: "'let' declarations can only be declared inside a block." }, - Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: 1, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." }, 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." }, @@ -1025,6 +1013,11 @@ var ts; External_module_0_has_no_default_export_or_export_assignment: { code: 1192, category: 1, key: "External module '{0}' has no default export or export assignment." }, An_export_declaration_cannot_have_modifiers: { code: 1193, category: 1, key: "An export declaration cannot have modifiers." }, Export_declarations_are_not_permitted_in_an_internal_module: { code: 1194, category: 1, key: "Export declarations are not permitted in an internal module." }, + Catch_clause_variable_name_must_be_an_identifier: { code: 1195, category: 1, key: "Catch clause variable name must be an identifier." }, + Catch_clause_variable_cannot_have_a_type_annotation: { code: 1196, category: 1, key: "Catch clause variable cannot have a type annotation." }, + Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: 1, key: "Catch clause variable cannot have an initializer." }, + An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: 1, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, + Unterminated_Unicode_escape_sequence: { code: 1199, category: 1, key: "Unterminated Unicode escape sequence." }, 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." }, @@ -1198,6 +1191,14 @@ var ts; for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 2482, category: 1, key: "'for...of' statements are only available when targeting ECMAScript 6 or higher." }, The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation: { code: 2483, category: 1, key: "The left-hand side of a 'for...of' statement cannot use a type annotation." }, Export_declaration_conflicts_with_exported_declaration_of_0: { code: 2484, category: 1, key: "Export declaration conflicts with exported declaration of '{0}'" }, + The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant: { code: 2485, category: 1, key: "The left-hand side of a 'for...of' statement cannot be a previously defined constant." }, + The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant: { code: 2486, category: 1, key: "The left-hand side of a 'for...in' statement cannot be a previously defined constant." }, + Invalid_left_hand_side_in_for_of_statement: { code: 2487, category: 1, key: "Invalid left-hand side in 'for...of' statement." }, + The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator: { code: 2488, category: 1, key: "The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator." }, + The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method: { code: 2489, category: 1, key: "The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method." }, + The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property: { code: 2490, category: 1, key: "The type returned by the 'next()' method of an iterator must have a 'value' property." }, + The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern: { code: 2491, category: 1, key: "The left-hand side of a 'for...in' statement cannot be a destructuring pattern." }, + Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: 1, key: "Cannot redeclare identifier '{0}' in catch clause" }, 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}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: 1, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1267,6 +1268,7 @@ var ts; Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: 1, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: 1, key: "Parameter '{0}' of exported function has or is using private name '{1}'." }, Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: 1, key: "Exported type alias '{0}' has or is using private name '{1}'." }, + Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: 1, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." }, 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}" }, @@ -1342,25 +1344,24 @@ var ts; You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: 1, key: "You cannot rename elements that are defined in the standard TypeScript library." }, yield_expressions_are_not_currently_supported: { code: 9000, category: 1, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: 1, key: "Generators are not currently supported." }, - The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: 1, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, - for_of_statements_are_not_currently_supported: { code: 9003, category: 1, key: "'for...of' statements are not currently supported." } + The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: 1, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." } }; })(ts || (ts = {})); var ts; (function (ts) { var textToToken = { - "any": 112, + "any": 111, "as": 101, - "boolean": 113, + "boolean": 112, "break": 65, "case": 66, "catch": 67, "class": 68, "continue": 70, "const": 69, - "constructor": 114, + "constructor": 113, "debugger": 71, - "declare": 115, + "declare": 114, "default": 72, "delete": 73, "do": 74, @@ -1371,43 +1372,43 @@ var ts; "false": 79, "finally": 80, "for": 81, - "from": 102, + "from": 123, "function": 82, - "get": 116, + "get": 115, "if": 83, - "implements": 103, + "implements": 102, "import": 84, "in": 85, "instanceof": 86, - "interface": 104, - "let": 105, - "module": 117, + "interface": 103, + "let": 104, + "module": 116, "new": 87, "null": 88, - "number": 119, - "package": 106, - "private": 107, - "protected": 108, - "public": 109, - "require": 118, + "number": 118, + "package": 105, + "private": 106, + "protected": 107, + "public": 108, + "require": 117, "return": 89, - "set": 120, - "static": 110, - "string": 121, + "set": 119, + "static": 109, + "string": 120, "super": 90, "switch": 91, - "symbol": 122, + "symbol": 121, "this": 92, "throw": 93, "true": 94, "try": 95, - "type": 123, + "type": 122, "typeof": 96, "var": 97, "void": 98, "while": 99, "with": 100, - "yield": 111, + "yield": 110, "of": 124, "{": 14, "}": 15, @@ -1487,11 +1488,15 @@ var ts; return false; } function isUnicodeIdentifierStart(code, languageVersion) { - return languageVersion >= 1 ? lookupInUnicodeMap(code, unicodeES5IdentifierStart) : lookupInUnicodeMap(code, unicodeES3IdentifierStart); + return languageVersion >= 1 ? + lookupInUnicodeMap(code, unicodeES5IdentifierStart) : + lookupInUnicodeMap(code, unicodeES3IdentifierStart); } ts.isUnicodeIdentifierStart = isUnicodeIdentifierStart; function isUnicodeIdentifierPart(code, languageVersion) { - return languageVersion >= 1 ? lookupInUnicodeMap(code, unicodeES5IdentifierPart) : lookupInUnicodeMap(code, unicodeES3IdentifierPart); + return languageVersion >= 1 ? + lookupInUnicodeMap(code, unicodeES5IdentifierPart) : + lookupInUnicodeMap(code, unicodeES3IdentifierPart); } function makeReverseMap(source) { var result = []; @@ -1780,6 +1785,7 @@ var ts; var token; var tokenValue; var precedingLineBreak; + var hasExtendedUnicodeEscape; var tokenIsUnterminated; function error(message, length) { if (onError) { @@ -1829,10 +1835,16 @@ var ts; } return +(text.substring(start, pos)); } - function scanHexDigits(count, mustMatchCount) { + function scanExactNumberOfHexDigits(count) { + return scanHexDigits(count, false); + } + function scanMinimumNumberOfHexDigits(count) { + return scanHexDigits(count, true); + } + function scanHexDigits(minCount, scanAsManyAsPossible) { var digits = 0; var value = 0; - while (digits < count || !mustMatchCount) { + while (digits < minCount || scanAsManyAsPossible) { var ch = text.charCodeAt(pos); if (ch >= 48 && ch <= 57) { value = value * 16 + ch - 48; @@ -1849,7 +1861,7 @@ var ts; pos++; digits++; } - if (digits < count) { + if (digits < minCount) { value = -1; } return value; @@ -1962,16 +1974,15 @@ var ts; return "\'"; case 34: return "\""; - case 120: case 117: - var ch = scanHexDigits(ch === 120 ? 2 : 4, true); - if (ch >= 0) { - return String.fromCharCode(ch); - } - else { - error(ts.Diagnostics.Hexadecimal_digit_expected); - return ""; + if (pos < len && text.charCodeAt(pos) === 123) { + hasExtendedUnicodeEscape = true; + pos++; + return scanExtendedUnicodeEscape(); } + return scanHexadecimalEscape(4); + case 120: + return scanHexadecimalEscape(2); case 13: if (pos < len && text.charCodeAt(pos) === 10) { pos++; @@ -1984,11 +1995,57 @@ var ts; return String.fromCharCode(ch); } } + function scanHexadecimalEscape(numDigits) { + var escapedValue = scanExactNumberOfHexDigits(numDigits); + if (escapedValue >= 0) { + return String.fromCharCode(escapedValue); + } + else { + error(ts.Diagnostics.Hexadecimal_digit_expected); + return ""; + } + } + function scanExtendedUnicodeEscape() { + var escapedValue = scanMinimumNumberOfHexDigits(1); + var isInvalidExtendedEscape = false; + if (escapedValue < 0) { + error(ts.Diagnostics.Hexadecimal_digit_expected); + isInvalidExtendedEscape = true; + } + else if (escapedValue > 0x10FFFF) { + error(ts.Diagnostics.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive); + isInvalidExtendedEscape = true; + } + if (pos >= len) { + error(ts.Diagnostics.Unexpected_end_of_text); + isInvalidExtendedEscape = true; + } + else if (text.charCodeAt(pos) == 125) { + pos++; + } + else { + error(ts.Diagnostics.Unterminated_Unicode_escape_sequence); + isInvalidExtendedEscape = true; + } + if (isInvalidExtendedEscape) { + return ""; + } + return utf16EncodeAsString(escapedValue); + } + function utf16EncodeAsString(codePoint) { + ts.Debug.assert(0x0 <= codePoint && codePoint <= 0x10FFFF); + if (codePoint <= 65535) { + return String.fromCharCode(codePoint); + } + var codeUnit1 = Math.floor((codePoint - 65536) / 1024) + 0xD800; + var codeUnit2 = ((codePoint - 65536) % 1024) + 0xDC00; + return String.fromCharCode(codeUnit1, codeUnit2); + } function peekUnicodeEscape() { if (pos + 5 < len && text.charCodeAt(pos + 1) === 117) { var start = pos; pos += 2; - var value = scanHexDigits(4, true); + var value = scanExactNumberOfHexDigits(4); pos = start; return value; } @@ -2050,6 +2107,7 @@ var ts; } function scan() { startPos = pos; + hasExtendedUnicodeEscape = false; precedingLineBreak = false; tokenIsUnterminated = false; while (true) { @@ -2201,7 +2259,7 @@ var ts; case 48: if (pos + 2 < len && (text.charCodeAt(pos + 1) === 88 || text.charCodeAt(pos + 1) === 120)) { pos += 2; - var value = scanHexDigits(1, false); + var value = scanMinimumNumberOfHexDigits(1); if (value < 0) { error(ts.Diagnostics.Hexadecimal_digit_expected); value = 0; @@ -2471,6 +2529,7 @@ var ts; getTokenPos: function () { return tokenPos; }, getTokenText: function () { return text.substring(tokenPos, pos); }, getTokenValue: function () { return tokenValue; }, + hasExtendedUnicodeEscape: function () { return hasExtendedUnicodeEscape; }, hasPrecedingLineBreak: function () { return precedingLineBreak; }, isIdentifier: function () { return token === 64 || token > 100; }, isReservedWord: function () { return token >= 65 && token <= 100; }, @@ -2957,35 +3016,51 @@ var ts; return ts.getBaseFileName(moduleName).replace(/\W/g, "_"); } ts.makeIdentifierFromModuleName = makeIdentifierFromModuleName; + function isBlockOrCatchScoped(declaration) { + return (getCombinedNodeFlags(declaration) & 12288) !== 0 || + isCatchClauseVariableDeclaration(declaration); + } + ts.isBlockOrCatchScoped = isBlockOrCatchScoped; + function isCatchClauseVariableDeclaration(declaration) { + return declaration && + declaration.kind === 193 && + declaration.parent && + declaration.parent.kind === 216; + } + ts.isCatchClauseVariableDeclaration = isCatchClauseVariableDeclaration; function declarationNameToString(name) { return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name); } ts.declarationNameToString = declarationNameToString; function createDiagnosticForNode(node, message, arg0, arg1, arg2) { - node = getErrorSpanForNode(node); - var file = getSourceFileOfNode(node); - var start = getTokenPosOfNode(node, file); - var length = node.end - start; - return ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2); + var sourceFile = getSourceFileOfNode(node); + var span = getErrorSpanForNode(sourceFile, node); + return ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2); } ts.createDiagnosticForNode = createDiagnosticForNode; function createDiagnosticForNodeFromMessageChain(node, messageChain) { - node = getErrorSpanForNode(node); - var file = getSourceFileOfNode(node); - var start = ts.skipTrivia(file.text, node.pos); - var length = node.end - start; + var sourceFile = getSourceFileOfNode(node); + var span = getErrorSpanForNode(sourceFile, node); return { - file: file, - start: start, - length: length, + file: sourceFile, + start: span.start, + length: span.length, code: messageChain.code, category: messageChain.category, messageText: messageChain.next ? messageChain : messageChain.messageText }; } ts.createDiagnosticForNodeFromMessageChain = createDiagnosticForNodeFromMessageChain; - function getErrorSpanForNode(node) { - var errorSpan; + function getSpanOfTokenAtPosition(sourceFile, pos) { + var scanner = ts.createScanner(sourceFile.languageVersion, true, sourceFile.text); + scanner.setTextPos(pos); + scanner.scan(); + var start = scanner.getTokenPos(); + return createTextSpanFromBounds(start, scanner.getTextPos()); + } + ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; + function getErrorSpanForNode(sourceFile, node) { + var errorNode = node; switch (node.kind) { case 193: case 150: @@ -2994,10 +3069,18 @@ var ts; case 200: case 199: case 219: - errorSpan = node.name; + case 195: + case 160: + errorNode = node.name; break; } - return errorSpan && errorSpan.pos < errorSpan.end ? errorSpan : node; + if (errorNode === undefined) { + return getSpanOfTokenAtPosition(sourceFile, node.pos); + } + var pos = nodeIsMissing(errorNode) + ? errorNode.pos + : ts.skipTrivia(sourceFile.text, errorNode.pos); + return createTextSpanFromBounds(pos, errorNode.end); } ts.getErrorSpanForNode = getErrorSpanForNode; function isExternalModule(file) { @@ -3005,7 +3088,7 @@ var ts; } ts.isExternalModule = isExternalModule; function isDeclarationFile(file) { - return (file.flags & 1024) !== 0; + return (file.flags & 2048) !== 0; } ts.isDeclarationFile = isDeclarationFile; function isConstEnumDeclaration(node) { @@ -3035,11 +3118,11 @@ var ts; } ts.getCombinedNodeFlags = getCombinedNodeFlags; function isConst(node) { - return !!(getCombinedNodeFlags(node) & 4096); + return !!(getCombinedNodeFlags(node) & 8192); } ts.isConst = isConst; function isLet(node) { - return !!(getCombinedNodeFlags(node) & 2048); + return !!(getCombinedNodeFlags(node) & 4096); } ts.isLet = isLet; function isPrologueDirective(node) { @@ -3091,7 +3174,24 @@ var ts; } } ts.forEachReturnStatement = forEachReturnStatement; - function isAnyFunction(node) { + function isVariableLike(node) { + if (node) { + switch (node.kind) { + case 150: + case 219: + case 128: + case 217: + case 130: + case 129: + case 218: + case 193: + return true; + } + } + return false; + } + ts.isVariableLike = isVariableLike; + function isFunctionLike(node) { if (node) { switch (node.kind) { case 133: @@ -3115,9 +3215,9 @@ var ts; } return false; } - ts.isAnyFunction = isAnyFunction; + ts.isFunctionLike = isFunctionLike; function isFunctionBlock(node) { - return node && node.kind === 174 && isAnyFunction(node.parent); + return node && node.kind === 174 && isFunctionLike(node.parent); } ts.isFunctionBlock = isFunctionBlock; function isObjectLiteralMethod(node) { @@ -3127,7 +3227,7 @@ var ts; function getContainingFunction(node) { while (true) { node = node.parent; - if (!node || isAnyFunction(node)) { + if (!node || isFunctionLike(node)) { return node; } } @@ -3365,12 +3465,12 @@ var ts; } ts.isTemplateLiteralKind = isTemplateLiteralKind; function isBindingPattern(node) { - return node.kind === 149 || node.kind === 148; + return !!node && (node.kind === 149 || node.kind === 148); } ts.isBindingPattern = isBindingPattern; function isInAmbientContext(node) { while (node) { - if (node.flags & (2 | 1024)) { + if (node.flags & (2 | 2048)) { return true; } node = node.parent; @@ -3380,31 +3480,33 @@ var ts; ts.isInAmbientContext = isInAmbientContext; function isDeclaration(node) { switch (node.kind) { - case 127: - case 128: - case 193: + case 161: case 150: - case 130: - case 129: - case 217: - case 218: + case 196: + case 133: + case 199: case 219: + case 211: + case 195: + case 160: + case 134: + case 204: + case 202: + case 207: + case 197: case 132: case 131: - case 195: - case 134: - case 135: - case 133: - case 196: - case 197: - case 198: - case 199: case 200: - case 202: - case 204: - case 207: case 205: - case 211: + case 128: + case 217: + case 130: + case 129: + case 135: + case 218: + case 198: + case 127: + case 193: return true; } return false; @@ -3437,27 +3539,29 @@ var ts; } } ts.isStatement = isStatement; - function isDeclarationOrFunctionExpressionOrCatchVariableName(name) { + function isDeclarationName(name) { if (name.kind !== 64 && name.kind !== 8 && name.kind !== 7) { return false; } var parent = name.parent; - if (isDeclaration(parent) || parent.kind === 160) { - return parent.name === name; + if (parent.kind === 207 || parent.kind === 211) { + if (parent.propertyName) { + return true; + } } - if (parent.kind === 216) { + if (isDeclaration(parent)) { return parent.name === name; } return false; } - ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName; + ts.isDeclarationName = isDeclarationName; function getClassBaseTypeNode(node) { var heritageClause = getHeritageClause(node.heritageClauses, 78); return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined; } ts.getClassBaseTypeNode = getClassBaseTypeNode; function getClassImplementedTypeNodes(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 103); + var heritageClause = getHeritageClause(node.heritageClauses, 102); return heritageClause ? heritageClause.types : undefined; } ts.getClassImplementedTypeNodes = getClassImplementedTypeNodes; @@ -3571,13 +3675,14 @@ var ts; ts.isESSymbolIdentifier = isESSymbolIdentifier; function isModifier(token) { switch (token) { - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: case 77: - case 115: + case 114: case 69: + case 72: return true; } return false; @@ -3692,6 +3797,42 @@ var ts; return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); } ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; + function nodeStartsNewLexicalEnvironment(n) { + return isFunctionLike(n) || n.kind === 200 || n.kind === 220; + } + ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment; + function nodeIsSynthesized(node) { + return node.pos === -1 && node.end === -1; + } + ts.nodeIsSynthesized = nodeIsSynthesized; + function createSynthesizedNode(kind, startsOnNewLine) { + var node = ts.createNode(kind); + node.pos = -1; + node.end = -1; + node.startsOnNewLine = startsOnNewLine; + return node; + } + ts.createSynthesizedNode = createSynthesizedNode; + function generateUniqueName(baseName, isExistingName) { + if (baseName.charCodeAt(0) !== 95) { + var baseName = "_" + baseName; + if (!isExistingName(baseName)) { + return baseName; + } + } + if (baseName.charCodeAt(baseName.length - 1) !== 95) { + baseName += "_"; + } + var i = 1; + while (true) { + var name = baseName + i; + if (!isExistingName(name)) { + return name; + } + i++; + } + } + ts.generateUniqueName = generateUniqueName; function createDiagnosticCollection() { var nonFileDiagnostics = []; var fileDiagnostics = {}; @@ -3757,6 +3898,41 @@ var ts; } } ts.createDiagnosticCollection = createDiagnosticCollection; + var escapedCharsRegExp = /[\\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g; + var escapedCharsMap = { + "\0": "\\0", + "\t": "\\t", + "\v": "\\v", + "\f": "\\f", + "\b": "\\b", + "\r": "\\r", + "\n": "\\n", + "\\": "\\\\", + "\"": "\\\"", + "\u2028": "\\u2028", + "\u2029": "\\u2029", + "\u0085": "\\u0085" + }; + function escapeString(s) { + s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s; + return s; + function getReplacement(c) { + return escapedCharsMap[c] || get16BitUnicodeEscapeSequence(c.charCodeAt(0)); + } + } + ts.escapeString = escapeString; + function get16BitUnicodeEscapeSequence(charCode) { + var hexCharCode = charCode.toString(16).toUpperCase(); + var paddedHexCode = ("0000" + hexCharCode).slice(-4); + return "\\u" + paddedHexCode; + } + var nonAsciiCharacters = /[^\u0000-\u007F]/g; + function escapeNonAsciiCharacters(s) { + return nonAsciiCharacters.test(s) ? + s.replace(nonAsciiCharacters, function (c) { return get16BitUnicodeEscapeSequence(c.charCodeAt(0)); }) : + s; + } + ts.escapeNonAsciiCharacters = escapeNonAsciiCharacters; })(ts || (ts = {})); var ts; (function (ts) { @@ -3867,6 +4043,7 @@ var ts; return visitNodes(cbNodes, node.properties); case 153: return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.dotToken) || visitNode(cbNode, node.name); case 154: return visitNode(cbNode, node.expression) || @@ -3903,7 +4080,9 @@ var ts; visitNode(cbNode, node.right); case 168: return visitNode(cbNode, node.condition) || + visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || + visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 171: return visitNode(cbNode, node.expression); @@ -3969,8 +4148,7 @@ var ts; visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 216: - return visitNode(cbNode, node.name) || - visitNode(cbNode, node.type) || + return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 196: return visitNodes(cbNodes, node.modifiers) || @@ -4025,7 +4203,7 @@ var ts; visitNode(cbNode, node.name); case 208: return visitNodes(cbNodes, node.modifiers) || - visitNode(cbNode, node.exportName); + visitNode(cbNode, node.expression); case 169: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 173: @@ -4067,13 +4245,14 @@ var ts; ; function modifierToFlag(token) { switch (token) { - case 110: return 128; - case 109: return 16; - case 108: return 64; - case 107: return 32; + case 109: return 128; + case 108: return 16; + case 107: return 64; + case 106: return 32; case 77: return 1; - case 115: return 2; - case 69: return 4096; + case 114: return 2; + case 69: return 8192; + case 72: return 256; } return 0; } @@ -4395,7 +4574,7 @@ var ts; sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = ts.normalizePath(fileName); - sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 1024 : 0; + sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 2048 : 0; var contextFlags = 0; var parseErrorBeforeNextFinishedNode = false; var scanner = ts.createScanner(languageVersion, true, sourceText, scanError); @@ -4523,7 +4702,9 @@ var ts; var saveParseDiagnosticsLength = sourceFile.parseDiagnostics.length; var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; var saveContextFlags = contextFlags; - var result = isLookAhead ? scanner.lookAhead(callback) : scanner.tryScan(callback); + var result = isLookAhead + ? scanner.lookAhead(callback) + : scanner.tryScan(callback); ts.Debug.assert(saveContextFlags === contextFlags); if (!result || isLookAhead) { token = saveToken; @@ -4542,10 +4723,10 @@ var ts; if (token === 64) { return true; } - if (token === 111 && inYieldContext()) { + if (token === 110 && inYieldContext()) { return false; } - return inStrictModeContext() ? token > 111 : token > 100; + return inStrictModeContext() ? token > 110 : token > 100; } function parseExpected(kind, diagnosticMessage) { if (token === kind) { @@ -4569,12 +4750,14 @@ var ts; } function parseOptionalToken(t) { if (token === t) { - var node = createNode(t); - nextToken(); - return finishNode(node); + return parseTokenNode(); } return undefined; } + function parseExpectedToken(t, reportAtCurrentPosition, diagnosticMessage, arg0) { + return parseOptionalToken(t) || + createMissingNode(t, reportAtCurrentPosition, diagnosticMessage, arg0); + } function parseTokenNode() { var node = createNode(token); nextToken(); @@ -4693,13 +4876,26 @@ var ts; } if (token === 77) { nextToken(); + if (token === 72) { + return lookAhead(nextTokenIsClassOrFunction); + } return token !== 35 && token !== 14 && canFollowModifier(); } + if (token === 72) { + return nextTokenIsClassOrFunction(); + } nextToken(); return canFollowModifier(); } function canFollowModifier() { - return token === 18 || token === 14 || token === 35 || isLiteralPropertyName(); + return token === 18 + || token === 14 + || token === 35 + || isLiteralPropertyName(); + } + function nextTokenIsClassOrFunction() { + nextToken(); + return token === 68 || token === 82; } function isListElement(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); @@ -4753,7 +4949,7 @@ var ts; return isIdentifier(); } function isNotHeritageClauseTypeName() { - if (token === 103 || + if (token === 102 || token === 78) { return lookAhead(nextTokenIsIdentifier); } @@ -4777,11 +4973,11 @@ var ts; case 4: return token === 15 || token === 66 || token === 72; case 8: - return token === 14 || token === 78 || token === 103; + return token === 14 || token === 78 || token === 102; case 9: return isVariableDeclaratorListTerminator(); case 16: - return token === 25 || token === 16 || token === 14 || token === 78 || token === 103; + return token === 25 || token === 16 || token === 14 || token === 78 || token === 102; case 12: return token === 17 || token === 22; case 14: @@ -5117,7 +5313,7 @@ var ts; literal = parseLiteralNode(); } else { - literal = createMissingNode(13, false, ts.Diagnostics._0_expected, ts.tokenToString(15)); + literal = parseExpectedToken(13, false, ts.Diagnostics._0_expected, ts.tokenToString(15)); } span.literal = literal; return finishNode(span); @@ -5126,14 +5322,19 @@ var ts; var node = createNode(token); var text = scanner.getTokenValue(); node.text = internName ? internIdentifier(text) : text; + if (scanner.hasExtendedUnicodeEscape()) { + node.hasExtendedUnicodeEscape = true; + } if (scanner.isUnterminated()) { node.isUnterminated = true; } var tokenPos = scanner.getTokenPos(); nextToken(); finishNode(node); - if (node.kind === 7 && sourceText.charCodeAt(tokenPos) === 48 && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { - node.flags |= 8192; + if (node.kind === 7 + && sourceText.charCodeAt(tokenPos) === 48 + && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { + node.flags |= 16384; } return node; } @@ -5171,7 +5372,9 @@ var ts; } function parseParameterType() { if (parseOptional(51)) { - return token === 8 ? parseLiteralNode(true) : parseType(); + return token === 8 + ? parseLiteralNode(true) + : parseType(); } return undefined; } @@ -5341,7 +5544,9 @@ var ts; case 24: return parseSignatureMember(136); case 18: - return isIndexSignature() ? parseIndexSignatureDeclaration(undefined) : parsePropertyOrMethodSignature(); + return isIndexSignature() + ? parseIndexSignatureDeclaration(undefined) + : parsePropertyOrMethodSignature(); case 87: if (lookAhead(isStartOfConstructSignature)) { return parseSignatureMember(137); @@ -5363,7 +5568,9 @@ var ts; } function parseIndexSignatureWithModifiers() { var modifiers = parseModifiers(); - return isIndexSignature() ? parseIndexSignatureDeclaration(modifiers) : undefined; + return isIndexSignature() + ? parseIndexSignatureDeclaration(modifiers) + : undefined; } function isStartOfConstructSignature() { nextToken(); @@ -5411,11 +5618,11 @@ var ts; } function parseNonArrayType() { switch (token) { + case 111: + case 120: + case 118: case 112: case 121: - case 119: - case 113: - case 122: var node = tryParse(parseKeywordAndNoDot); return node || parseTypeReference(); case 98: @@ -5434,11 +5641,11 @@ var ts; } function isStartOfType() { switch (token) { + case 111: + case 120: + case 118: case 112: case 121: - case 119: - case 113: - case 122: case 98: case 96: case 14: @@ -5559,7 +5766,7 @@ var ts; case 39: case 24: case 64: - case 111: + case 110: return true; default: if (isBinaryOperator()) { @@ -5606,7 +5813,7 @@ var ts; return parseConditionalExpressionRest(expr); } function isYieldExpression() { - if (token === 111) { + if (token === 110) { if (inYieldContext()) { return true; } @@ -5652,7 +5859,9 @@ var ts; if (triState === 0) { return undefined; } - var arrowFunction = triState === 1 ? parseParenthesizedArrowFunctionExpressionHead(true) : tryParse(parsePossibleParenthesizedArrowFunctionExpressionHead); + var arrowFunction = triState === 1 + ? parseParenthesizedArrowFunctionExpressionHead(true) + : tryParse(parsePossibleParenthesizedArrowFunctionExpressionHead); if (!arrowFunction) { return undefined; } @@ -5731,13 +5940,15 @@ var ts; return parseAssignmentExpressionOrHigher(); } function parseConditionalExpressionRest(leftOperand) { - if (!parseOptional(50)) { + var questionToken = parseOptionalToken(50); + if (!questionToken) { return leftOperand; } var node = createNode(168, leftOperand.pos); node.condition = leftOperand; + node.questionToken = questionToken; node.whenTrue = allowInAnd(parseAssignmentExpressionOrHigher); - parseExpected(51); + node.colonToken = parseExpectedToken(51, false, ts.Diagnostics._0_expected, ts.tokenToString(51)); node.whenFalse = parseAssignmentExpressionOrHigher(); return finishNode(node); } @@ -5872,7 +6083,9 @@ var ts; return expression; } function parseLeftHandSideExpressionOrHigher() { - var expression = token === 90 ? parseSuperExpression() : parseMemberExpressionOrHigher(); + var expression = token === 90 + ? parseSuperExpression() + : parseMemberExpressionOrHigher(); return parseCallExpressionRest(expression); } function parseMemberExpressionOrHigher() { @@ -5886,7 +6099,7 @@ var ts; } var node = createNode(153, expression.pos); node.expression = expression; - parseExpected(20, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); + node.dotToken = parseExpectedToken(20, false, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); node.name = parseRightSideOfDot(true); return finishNode(node); } @@ -5900,10 +6113,11 @@ var ts; } function parseMemberExpressionRest(expression) { while (true) { - var dotOrBracketStart = scanner.getTokenPos(); - if (parseOptional(20)) { + var dotToken = parseOptionalToken(20); + if (dotToken) { var propertyAccess = createNode(153, expression.pos); propertyAccess.expression = expression; + propertyAccess.dotToken = dotToken; propertyAccess.name = parseRightSideOfDot(true); expression = finishNode(propertyAccess); continue; @@ -5925,7 +6139,9 @@ var ts; if (token === 10 || token === 11) { var tagExpression = createNode(157, expression.pos); tagExpression.tag = expression; - tagExpression.template = token === 10 ? parseLiteralNode() : parseTemplateExpression(); + tagExpression.template = token === 10 + ? parseLiteralNode() + : parseTemplateExpression(); expression = finishNode(tagExpression); continue; } @@ -5971,7 +6187,9 @@ var ts; if (!parseExpected(25)) { return undefined; } - return typeArguments && canFollowTypeArgumentsInExpression() ? typeArguments : undefined; + return typeArguments && canFollowTypeArgumentsInExpression() + ? typeArguments + : undefined; } function canFollowTypeArgumentsInExpression() { switch (token) { @@ -6046,7 +6264,9 @@ var ts; return finishNode(node); } function parseArgumentOrArrayLiteralElement() { - return token === 21 ? parseSpreadElement() : token === 23 ? createNode(172) : parseAssignmentExpressionOrHigher(); + return token === 21 ? parseSpreadElement() : + token === 23 ? createNode(172) : + parseAssignmentExpressionOrHigher(); } function parseArgumentExpression() { return allowInAnd(parseArgumentOrArrayLiteralElement); @@ -6055,16 +6275,16 @@ var ts; var node = createNode(151); parseExpected(18); if (scanner.hasPrecedingLineBreak()) - node.flags |= 256; + node.flags |= 512; node.elements = parseDelimitedList(14, parseArgumentOrArrayLiteralElement); parseExpected(19); return finishNode(node); } function tryParseAccessorDeclaration(fullStart, modifiers) { - if (parseContextualModifier(116)) { + if (parseContextualModifier(115)) { return parseAccessorDeclaration(134, fullStart, modifiers); } - else if (parseContextualModifier(120)) { + else if (parseContextualModifier(119)) { return parseAccessorDeclaration(135, fullStart, modifiers); } return undefined; @@ -6103,7 +6323,7 @@ var ts; var node = createNode(152); parseExpected(14); if (scanner.hasPrecedingLineBreak()) { - node.flags |= 256; + node.flags |= 512; } node.properties = parseDelimitedList(13, parseObjectLiteralElement, true); parseExpected(15); @@ -6190,7 +6410,7 @@ var ts; parseExpected(16); var initializer = undefined; if (token !== 22) { - if (token === 97 || token === 105 || token === 69) { + if (token === 97 || token === 104 || token === 69) { initializer = parseVariableDeclarationList(true); } else { @@ -6306,9 +6526,9 @@ var ts; function parseCatchClause() { var result = createNode(216); parseExpected(67); - parseExpected(16); - result.name = parseIdentifier(); - result.type = parseTypeAnnotation(); + if (parseExpected(16)) { + result.variableDeclaration = parseVariableDeclaration(); + } parseExpected(17); result.block = parseBlock(false, false); return finishNode(result); @@ -6347,7 +6567,7 @@ var ts; return !inErrorRecovery; case 14: case 97: - case 105: + case 104: case 82: case 83: case 74: @@ -6367,18 +6587,18 @@ var ts; case 69: var isConstEnum = lookAhead(nextTokenIsEnumKeyword); return !isConstEnum; - case 104: + case 103: case 68: - case 117: + case 116: case 76: - case 123: + case 122: if (isDeclarationStart()) { return false; } - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { return false; } @@ -6431,7 +6651,7 @@ var ts; return parseTryStatement(); case 71: return parseDebuggerStatement(); - case 105: + case 104: if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), undefined); } @@ -6455,7 +6675,7 @@ var ts; return undefined; } return parseVariableStatement(start, modifiers); - case 105: + case 104: if (!isLetDeclaration()) { return undefined; } @@ -6538,11 +6758,11 @@ var ts; switch (token) { case 97: break; - case 105: - node.flags |= 2048; + case 104: + node.flags |= 4096; break; case 69: - node.flags |= 4096; + node.flags |= 8192; break; default: ts.Debug.fail(); @@ -6574,7 +6794,7 @@ var ts; setModifiers(node, modifiers); parseExpected(82); node.asteriskToken = parseOptionalToken(35); - node.name = parseIdentifier(); + node.name = node.flags & 256 ? parseOptionalIdentifier() : parseIdentifier(); fillSignature(51, !!node.asteriskToken, false, node); node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, ts.Diagnostics.or_expected); return finishNode(node); @@ -6582,7 +6802,7 @@ var ts; function parseConstructorDeclaration(pos, modifiers) { var node = createNode(133, pos); setModifiers(node, modifiers); - parseExpected(114); + parseExpected(113); fillSignature(51, false, false, node); node.body = parseFunctionBlockOrSemicolon(false, ts.Diagnostics.or_expected); return finishNode(node); @@ -6643,7 +6863,7 @@ var ts; return true; } if (idToken !== undefined) { - if (!ts.isKeyword(idToken) || idToken === 120 || idToken === 116) { + if (!ts.isKeyword(idToken) || idToken === 119 || idToken === 115) { return true; } switch (token) { @@ -6688,7 +6908,7 @@ var ts; if (accessor) { return accessor; } - if (token === 114) { + if (token === 113) { return parseConstructorDeclaration(fullStart, modifiers); } if (isIndexSignature()) { @@ -6707,11 +6927,13 @@ var ts; var node = createNode(196, fullStart); setModifiers(node, modifiers); parseExpected(68); - node.name = parseIdentifier(); + node.name = node.flags & 256 ? parseOptionalIdentifier() : parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(true); if (parseExpected(14)) { - node.members = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseClassMembers) : parseClassMembers(); + node.members = inGeneratorParameterContext() + ? doOutsideOfYieldContext(parseClassMembers) + : parseClassMembers(); parseExpected(15); } else { @@ -6721,7 +6943,9 @@ var ts; } function parseHeritageClauses(isClassHeritageClause) { if (isHeritageClause()) { - return isClassHeritageClause && inGeneratorParameterContext() ? doOutsideOfYieldContext(parseHeritageClausesWorker) : parseHeritageClausesWorker(); + return isClassHeritageClause && inGeneratorParameterContext() + ? doOutsideOfYieldContext(parseHeritageClausesWorker) + : parseHeritageClausesWorker(); } return undefined; } @@ -6729,7 +6953,7 @@ var ts; return parseList(19, false, parseHeritageClause); } function parseHeritageClause() { - if (token === 78 || token === 103) { + if (token === 78 || token === 102) { var node = createNode(215); node.token = token; nextToken(); @@ -6739,7 +6963,7 @@ var ts; return undefined; } function isHeritageClause() { - return token === 78 || token === 103; + return token === 78 || token === 102; } function parseClassMembers() { return parseList(6, false, parseClassElement); @@ -6747,7 +6971,7 @@ var ts; function parseInterfaceDeclaration(fullStart, modifiers) { var node = createNode(197, fullStart); setModifiers(node, modifiers); - parseExpected(104); + parseExpected(103); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(false); @@ -6757,7 +6981,7 @@ var ts; function parseTypeAliasDeclaration(fullStart, modifiers) { var node = createNode(198, fullStart); setModifiers(node, modifiers); - parseExpected(123); + parseExpected(122); node.name = parseIdentifier(); parseExpected(52); node.type = parseType(); @@ -6800,7 +7024,9 @@ var ts; setModifiers(node, modifiers); node.flags |= flags; node.name = parseIdentifier(); - node.body = parseOptional(20) ? parseInternalModuleTail(getNodePos(), undefined, 1) : parseModuleBlock(); + node.body = parseOptional(20) + ? parseInternalModuleTail(getNodePos(), undefined, 1) + : parseModuleBlock(); return finishNode(node); } function parseAmbientExternalModuleDeclaration(fullStart, modifiers) { @@ -6811,11 +7037,13 @@ var ts; return finishNode(node); } function parseModuleDeclaration(fullStart, modifiers) { - parseExpected(117); - return token === 8 ? parseAmbientExternalModuleDeclaration(fullStart, modifiers) : parseInternalModuleTail(fullStart, modifiers, modifiers ? modifiers.flags : 0); + parseExpected(116); + return token === 8 + ? parseAmbientExternalModuleDeclaration(fullStart, modifiers) + : parseInternalModuleTail(fullStart, modifiers, modifiers ? modifiers.flags : 0); } function isExternalModuleReference() { - return token === 118 && + return token === 117 && lookAhead(nextTokenIsOpenParen); } function nextTokenIsOpenParen() { @@ -6824,7 +7052,7 @@ var ts; function nextTokenIsCommaOrFromKeyword() { nextToken(); return token === 23 || - token === 102; + token === 123; } function parseImportDeclarationOrImportEqualsDeclaration(fullStart, modifiers) { parseExpected(84); @@ -6832,7 +7060,7 @@ var ts; var identifier; if (isIdentifier()) { identifier = parseIdentifier(); - if (token !== 23 && token !== 102) { + if (token !== 23 && token !== 123) { var importEqualsDeclaration = createNode(202, fullStart); setModifiers(importEqualsDeclaration, modifiers); importEqualsDeclaration.name = identifier; @@ -6848,7 +7076,7 @@ var ts; token === 35 || token === 14) { importDeclaration.importClause = parseImportClause(identifier, afterImportPos); - parseExpected(102); + parseExpected(123); } importDeclaration.moduleSpecifier = parseModuleSpecifier(); parseSemicolon(); @@ -6866,11 +7094,13 @@ var ts; return finishNode(importClause); } function parseModuleReference() { - return isExternalModuleReference() ? parseExternalModuleReference() : parseEntityName(false); + return isExternalModuleReference() + ? parseExternalModuleReference() + : parseEntityName(false); } function parseExternalModuleReference() { var node = createNode(212); - parseExpected(118); + parseExpected(117); parseExpected(16); node.expression = parseModuleSpecifier(); parseExpected(17); @@ -6928,22 +7158,28 @@ var ts; var node = createNode(209, fullStart); setModifiers(node, modifiers); if (parseOptional(35)) { - parseExpected(102); + parseExpected(123); node.moduleSpecifier = parseModuleSpecifier(); } else { node.exportClause = parseNamedImportsOrExports(210); - if (parseOptional(102)) { + if (parseOptional(123)) { node.moduleSpecifier = parseModuleSpecifier(); } } parseSemicolon(); return finishNode(node); } - function parseExportAssignmentTail(fullStart, modifiers) { + function parseExportAssignment(fullStart, modifiers) { var node = createNode(208, fullStart); setModifiers(node, modifiers); - node.exportName = parseIdentifier(); + if (parseOptional(52)) { + node.isExportEquals = true; + } + else { + parseExpected(72); + } + node.expression = parseAssignmentExpressionOrHigher(); parseSemicolon(); return finishNode(node); } @@ -6956,24 +7192,24 @@ var ts; case 69: case 82: return true; - case 105: + case 104: return isLetDeclaration(); case 68: - case 104: + case 103: case 76: - case 123: + case 122: return lookAhead(nextTokenIsIdentifierOrKeyword); case 84: return lookAhead(nextTokenCanFollowImportKeyword); - case 117: + case 116: return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); case 77: return lookAhead(nextTokenCanFollowExportKeyword); - case 115: - case 109: - case 107: + case 114: case 108: - case 110: + case 106: + case 107: + case 109: return lookAhead(nextTokenIsDeclarationStart); } } @@ -6996,7 +7232,7 @@ var ts; function nextTokenCanFollowExportKeyword() { nextToken(); return token === 52 || token === 35 || - token === 14 || isDeclarationStart(); + token === 14 || token === 72 || isDeclarationStart(); } function nextTokenIsDeclarationStart() { nextToken(); @@ -7010,8 +7246,8 @@ var ts; var modifiers = parseModifiers(); if (token === 77) { nextToken(); - if (parseOptional(52)) { - return parseExportAssignmentTail(fullStart, modifiers); + if (token === 72 || token === 52) { + return parseExportAssignment(fullStart, modifiers); } if (token === 35 || token === 14) { return parseExportDeclaration(fullStart, modifiers); @@ -7019,20 +7255,20 @@ var ts; } switch (token) { case 97: - case 105: + case 104: case 69: return parseVariableStatement(fullStart, modifiers); case 82: return parseFunctionDeclaration(fullStart, modifiers); case 68: return parseClassDeclaration(fullStart, modifiers); - case 104: + case 103: return parseInterfaceDeclaration(fullStart, modifiers); - case 123: + case 122: return parseTypeAliasDeclaration(fullStart, modifiers); case 76: return parseEnumDeclaration(fullStart, modifiers); - case 117: + case 116: return parseModuleDeclaration(fullStart, modifiers); case 84: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, modifiers); @@ -7050,7 +7286,9 @@ var ts; return parseSourceElementOrModuleElement(); } function parseSourceElementOrModuleElement() { - return isDeclarationStart() ? parseDeclaration() : parseStatement(); + return isDeclarationStart() + ? parseDeclaration() + : parseStatement(); } function processReferenceComments(sourceFile) { var triviaScanner = ts.createScanner(sourceFile.languageVersion, false, sourceText); @@ -7108,7 +7346,13 @@ var ts; } function setExternalModuleIndicator(sourceFile) { sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { - return node.flags & 1 || node.kind === 202 && node.moduleReference.kind === 212 || node.kind === 203 || node.kind === 208 || node.kind === 209 ? node : undefined; + return node.flags & 1 + || node.kind === 202 && node.moduleReference.kind === 212 + || node.kind === 203 + || node.kind === 208 + || node.kind === 209 + ? node + : undefined; }); } } @@ -7198,7 +7442,8 @@ var ts; var Symbol = ts.objectAllocator.getSymbolConstructor(); if (!file.locals) { file.locals = {}; - container = blockScopeContainer = file; + container = file; + setBlockScopeContainer(file, false); bind(file); file.symbolCount = symbolCount; } @@ -7206,6 +7451,12 @@ var ts; symbolCount++; return new Symbol(flags, name); } + function setBlockScopeContainer(node, cleanLocals) { + blockScopeContainer = node; + if (cleanLocals) { + blockScopeContainer.locals = undefined; + } + } function addDeclarationToSymbol(symbol, node, symbolKind) { symbol.flags |= symbolKind; if (!symbol.declarations) @@ -7242,6 +7493,13 @@ var ts; return "__new"; case 138: return "__index"; + case 209: + return "__export"; + case 208: + return "default"; + case 195: + case 196: + return node.flags & 256 ? "default" : undefined; } } function getDisplayName(node) { @@ -7249,18 +7507,20 @@ var ts; } function declareSymbol(symbols, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); - var name = getDeclarationName(node); + var name = node.flags & 256 && parent ? "default" : getDeclarationName(node); if (name !== undefined) { var symbol = ts.hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); if (symbol.flags & excludes) { if (node.name) { node.name.parent = node; } - var message = symbol.flags & 2 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + var message = symbol.flags & 2 + ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 + : ts.Diagnostics.Duplicate_identifier_0; ts.forEach(symbol.declarations, function (declaration) { - file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name, message, getDisplayName(declaration))); + file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); }); - file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name, message, getDisplayName(node))); + file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message, getDisplayName(node))); symbol = createSymbol(0, name); } } @@ -7330,7 +7590,7 @@ var ts; lastContainer = container; } if (isBlockScopeContainer) { - blockScopeContainer = node; + setBlockScopeContainer(node, (symbolKind & 255504) === 0 && node.kind !== 220); } ts.forEachChild(node, bind); container = saveContainer; @@ -7398,12 +7658,6 @@ var ts; } } } - function bindExportDeclaration(node) { - if (!node.exportClause) { - (container.exportStars || (container.exportStars = [])).push(node); - } - bindChildren(node, 0, false); - } function bindFunctionOrConstructorType(node) { var symbol = createSymbol(131072, getDeclarationName(node)); addDeclarationToSymbol(symbol, node, 131072); @@ -7419,14 +7673,7 @@ var ts; bindChildren(node, symbolKind, isBlockScopeContainer); } function bindCatchVariableDeclaration(node) { - var symbol = createSymbol(1, node.name.text || "__missing"); - addDeclarationToSymbol(symbol, node, 1); - var saveParent = parent; - var savedBlockScopeContainer = blockScopeContainer; - parent = blockScopeContainer = node; - ts.forEachChild(node, bind); - parent = saveParent; - blockScopeContainer = savedBlockScopeContainer; + bindChildren(node, 0, true); } function bindBlockScopedVariableDeclaration(node) { switch (blockScopeContainer.kind) { @@ -7463,7 +7710,7 @@ var ts; if (ts.isBindingPattern(node.name)) { bindChildren(node, 0, false); } - else if (ts.getCombinedNodeFlags(node) & 6144) { + else if (ts.isBlockOrCatchScoped(node)) { bindBlockScopedVariableDeclaration(node); } else { @@ -7545,9 +7792,6 @@ var ts; case 211: bindDeclaration(node, 8388608, 8388608, false); break; - case 209: - bindExportDeclaration(node); - break; case 204: if (node.name) { bindDeclaration(node, 8388608, 8388608, false); @@ -7556,13 +7800,28 @@ var ts; bindChildren(node, 0, false); } break; + case 209: + if (!node.exportClause) { + declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0); + } + bindChildren(node, 0, false); + break; + case 208: + if (node.expression.kind === 64) { + declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 8388608); + } + else { + declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455); + } + bindChildren(node, 0, false); + break; case 220: if (ts.isExternalModule(node)) { bindAnonymousDeclaration(node, 512, '"' + ts.removeFileExtension(node.fileName) + '"', true); break; } case 174: - bindChildren(node, 0, !ts.isAnyFunction(node.parent)); + bindChildren(node, 0, !ts.isFunctionLike(node.parent)); break; case 216: case 181: @@ -7650,8 +7909,9 @@ var ts; isValidPropertyAccess: isValidPropertyAccess, getSignatureFromDeclaration: getSignatureFromDeclaration, isImplementationOfOverload: isImplementationOfOverload, - getAliasedSymbol: resolveImport, - getEmitResolver: getEmitResolver + getAliasedSymbol: resolveAlias, + getEmitResolver: getEmitResolver, + getExportsOfExternalModule: getExportsOfExternalModule }; var undefinedSymbol = createSymbol(4 | 67108864, "undefined"); var argumentsSymbol = createSymbol(4 | 67108864, "arguments"); @@ -7685,6 +7945,7 @@ var ts; var globalRegExpType; var globalTemplateStringsArrayType; var globalESSymbolType; + var globalIterableType; var anyArrayType; var tupleTypes = {}; var unionTypes = {}; @@ -7718,7 +7979,9 @@ var ts; return emitResolver; } function error(location, message, arg0, arg1, arg2) { - var diagnostic = location ? ts.createDiagnosticForNode(location, message, arg0, arg1, arg2) : ts.createCompilerDiagnostic(message, arg0, arg1, arg2); + var diagnostic = location + ? ts.createDiagnosticForNode(location, message, arg0, arg1, arg2) + : ts.createCompilerDiagnostic(message, arg0, arg1, arg2); diagnostics.add(diagnostic); } function createSymbol(flags, name) { @@ -7804,7 +8067,8 @@ var ts; recordMergedSymbol(target, source); } else { - var message = target.flags & 2 || source.flags & 2 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + var message = target.flags & 2 || source.flags & 2 + ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; ts.forEach(source.declarations, function (node) { error(node.name ? node.name : node, message, symbolToString(source)); }); @@ -7838,13 +8102,6 @@ var ts; } } } - function extendSymbolTable(target, source) { - for (var id in source) { - if (!ts.hasProperty(target, id)) { - target[id] = source[id]; - } - } - } function getSymbolLinks(symbol) { if (symbol.flags & 67108864) return symbol; @@ -7871,7 +8128,7 @@ var ts; return symbol; } if (symbol.flags & 8388608) { - var target = resolveImport(symbol); + var target = resolveAlias(symbol); if (target === unknownSymbol || target.flags & meaning) { return symbol; } @@ -7907,7 +8164,7 @@ var ts; break; case 200: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8914931)) { - if (!(result.flags & 8388608 && getDeclarationOfImportSymbol(result).kind === 211)) { + if (!(result.flags & 8388608 && getDeclarationOfAliasSymbol(result).kind === 211)) { break loop; } result = undefined; @@ -7971,13 +8228,6 @@ var ts; break loop; } break; - case 216: - var id = location.name; - if (name === id.text) { - result = location.symbol; - break loop; - } - break; } lastLocation = location; location = location.parent; @@ -7998,7 +8248,7 @@ var ts; return undefined; } if (result.flags & 2) { - var declaration = ts.forEach(result.declarations, function (d) { return ts.getCombinedNodeFlags(d) & 6144 ? d : undefined; }); + var declaration = ts.forEach(result.declarations, function (d) { return ts.isBlockOrCatchScoped(d) ? d : undefined; }); ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); if (!isDefinedBefore(declaration, errorLocation)) { error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name)); @@ -8007,15 +8257,16 @@ var ts; } return result; } - function isImportSymbolDeclaration(node) { + function isAliasSymbolDeclaration(node) { return node.kind === 202 || node.kind === 204 && !!node.name || node.kind === 205 || node.kind === 207 || - node.kind === 211; + node.kind === 211 || + node.kind === 208; } - function getDeclarationOfImportSymbol(symbol) { - return ts.forEach(symbol.declarations, function (d) { return isImportSymbolDeclaration(d) ? d : undefined; }); + function getDeclarationOfAliasSymbol(symbol) { + return ts.forEach(symbol.declarations, function (d) { return isAliasSymbolDeclaration(d) ? d : undefined; }); } function getTargetOfImportEqualsDeclaration(node) { if (node.moduleReference.kind === 212) { @@ -8048,7 +8299,7 @@ var ts; error(name, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name)); return; } - return symbol.flags & (107455 | 793056 | 1536) ? symbol : resolveImport(symbol); + return symbol.flags & (107455 | 793056 | 1536) ? symbol : resolveAlias(symbol); } } } @@ -8056,7 +8307,12 @@ var ts; return getExternalModuleMember(node.parent.parent.parent, node); } function getTargetOfExportSpecifier(node) { - return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : resolveEntityName(node, node.propertyName || node.name, 107455 | 793056 | 1536); + return node.parent.parent.moduleSpecifier ? + getExternalModuleMember(node.parent.parent, node) : + resolveEntityName(node.propertyName || node.name, 107455 | 793056 | 1536); + } + function getTargetOfExportAssignment(node) { + return resolveEntityName(node.expression, 107455 | 793056 | 1536); } function getTargetOfImportDeclaration(node) { switch (node.kind) { @@ -8070,14 +8326,16 @@ var ts; return getTargetOfImportSpecifier(node); case 211: return getTargetOfExportSpecifier(node); + case 208: + return getTargetOfExportAssignment(node); } } - function resolveImport(symbol) { - ts.Debug.assert((symbol.flags & 8388608) !== 0, "Should only get Imports here."); + function resolveAlias(symbol) { + ts.Debug.assert((symbol.flags & 8388608) !== 0, "Should only get Alias here."); var links = getSymbolLinks(symbol); if (!links.target) { links.target = resolvingSymbol; - var node = getDeclarationOfImportSymbol(symbol); + var node = getDeclarationOfAliasSymbol(symbol); var target = getTargetOfImportDeclaration(node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; @@ -8091,6 +8349,29 @@ var ts; } return links.target; } + function markExportAsReferenced(node) { + var symbol = getSymbolOfNode(node); + var target = resolveAlias(symbol); + if (target && target !== unknownSymbol && target.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(target)) { + markAliasSymbolAsReferenced(symbol); + } + } + function markAliasSymbolAsReferenced(symbol) { + var links = getSymbolLinks(symbol); + if (!links.referenced) { + links.referenced = true; + var node = getDeclarationOfAliasSymbol(symbol); + if (node.kind === 208) { + checkExpressionCached(node.expression); + } + else if (node.kind === 211) { + checkExpressionCached(node.propertyName || node.name); + } + else if (ts.isInternalModuleImportEqualsDeclaration(node)) { + checkExpressionCached(node.moduleReference); + } + } + } function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) { if (!importDeclaration) { importDeclaration = ts.getAncestor(entityName, 202); @@ -8100,38 +8381,40 @@ var ts; entityName = entityName.parent; } if (entityName.kind === 64 || entityName.parent.kind === 125) { - return resolveEntityName(importDeclaration, entityName, 1536); + return resolveEntityName(entityName, 1536); } else { ts.Debug.assert(entityName.parent.kind === 202); - return resolveEntityName(importDeclaration, entityName, 107455 | 793056 | 1536); + return resolveEntityName(entityName, 107455 | 793056 | 1536); } } function getFullyQualifiedName(symbol) { return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol); } - function resolveEntityName(location, name, meaning) { + function resolveEntityName(name, meaning) { if (ts.getFullWidth(name) === 0) { return undefined; } if (name.kind === 64) { - var symbol = resolveName(location, name.text, meaning, ts.Diagnostics.Cannot_find_name_0, name); + var symbol = resolveName(name, name.text, meaning, ts.Diagnostics.Cannot_find_name_0, name); if (!symbol) { - return; + return undefined; } } else if (name.kind === 125) { - var namespace = resolveEntityName(location, name.left, 1536); - if (!namespace || namespace === unknownSymbol || ts.getFullWidth(name.right) === 0) - return; - var symbol = getSymbol(getExportsOfSymbol(namespace), name.right.text, meaning); + var namespace = resolveEntityName(name.left, 1536); + if (!namespace || namespace === unknownSymbol || ts.getFullWidth(name.right) === 0) { + return undefined; + } + var right = name.right; + var symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { - error(location, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(name.right)); - return; + error(right, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(right)); + return undefined; } } ts.Debug.assert((symbol.flags & 16777216) === 0, "Should never get an instantiated symbol here."); - return symbol.flags & meaning ? symbol : resolveImport(symbol); + return symbol.flags & meaning ? symbol : resolveAlias(symbol); } function isExternalModuleNameRelative(moduleName) { return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; @@ -8171,6 +8454,9 @@ var ts; } error(moduleReferenceLiteral, ts.Diagnostics.Cannot_find_external_module_0, moduleName); } + function getExportAssignmentSymbol(moduleSymbol) { + return moduleSymbol.exports["default"]; + } function getResolvedExportAssignmentSymbol(moduleSymbol) { var symbol = getExportAssignmentSymbol(moduleSymbol); if (symbol) { @@ -8178,82 +8464,52 @@ var ts; return symbol; } if (symbol.flags & 8388608) { - return resolveImport(symbol); + return resolveAlias(symbol); } } } - function getExportAssignmentSymbol(symbol) { - checkTypeOfExportAssignmentSymbol(symbol); - return getSymbolLinks(symbol).exportAssignmentSymbol; - } - function checkTypeOfExportAssignmentSymbol(containerSymbol) { - var symbolLinks = getSymbolLinks(containerSymbol); - if (!symbolLinks.exportAssignmentChecked) { - var exportInformation = collectExportInformationForSourceFileOrModule(containerSymbol); - if (exportInformation.exportAssignments.length) { - if (exportInformation.exportAssignments.length > 1) { - ts.forEach(exportInformation.exportAssignments, function (node) { return error(node, ts.Diagnostics.A_module_cannot_have_more_than_one_export_assignment); }); - } - var node = exportInformation.exportAssignments[0]; - if (exportInformation.hasExportedMember) { - error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); - } - if (node.exportName.text) { - var meaning = 107455 | 793056 | 1536; - var exportSymbol = resolveName(node, node.exportName.text, meaning, ts.Diagnostics.Cannot_find_name_0, node.exportName); - } - symbolLinks.exportAssignmentSymbol = exportSymbol || unknownSymbol; - } - symbolLinks.exportAssignmentChecked = true; - } - } - function collectExportInformationForSourceFileOrModule(symbol) { - var seenExportedMember = false; - var result = []; - ts.forEach(symbol.declarations, function (declaration) { - var block = (declaration.kind === 220 ? declaration : declaration.body); - ts.forEach(block.statements, function (node) { - if (node.kind === 208) { - result.push(node); - } - else { - seenExportedMember = seenExportedMember || (node.flags & 1) !== 0; - } - }); - }); - return { - hasExportedMember: seenExportedMember, - exportAssignments: result - }; - } function getExportsOfSymbol(symbol) { return symbol.flags & 1536 ? getExportsOfModule(symbol) : symbol.exports; } - function getExportsOfModule(symbol) { - var links = getSymbolLinks(symbol); - return links.resolvedExports || (links.resolvedExports = getExportsForModule(symbol)); + function getExportsOfModule(moduleSymbol) { + var links = getSymbolLinks(moduleSymbol); + return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol)); } - function getExportsForModule(symbol) { + function extendExportSymbols(target, source) { + for (var id in source) { + if (id !== "default" && !ts.hasProperty(target, id)) { + target[id] = source[id]; + } + } + } + function getExportsForModule(moduleSymbol) { + if (compilerOptions.target < 2) { + var defaultSymbol = getExportAssignmentSymbol(moduleSymbol); + if (defaultSymbol) { + return { + "default": defaultSymbol + }; + } + } var result; var visitedSymbols = []; - visit(symbol); - return result; + visit(moduleSymbol); + return result || moduleSymbol.exports; function visit(symbol) { if (!ts.contains(visitedSymbols, symbol)) { visitedSymbols.push(symbol); - if (!result) { - result = symbol.exports; - } - else { - extendSymbolTable(result, symbol.exports); - } - ts.forEach(symbol.declarations, function (node) { - if (node.kind === 220 || node.kind === 200) { - ts.forEach(node.exportStars, function (exportStar) { - visit(resolveExternalModuleName(exportStar, exportStar.moduleSpecifier)); - }); + if (symbol !== moduleSymbol) { + if (!result) { + result = cloneSymbolTable(moduleSymbol.exports); } - }); + extendExportSymbols(result, symbol.exports); + } + var exportStars = symbol.exports["__export"]; + if (exportStars) { + ts.forEach(exportStars.declarations, function (node) { + visit(resolveExternalModuleName(node, node.moduleSpecifier)); + }); + } } } } @@ -8268,7 +8524,9 @@ var ts; return getMergedSymbol(symbol.parent); } function getExportSymbolOfValueSymbolIfExported(symbol) { - return symbol && (symbol.flags & 1048576) !== 0 ? getMergedSymbol(symbol.exportSymbol) : symbol; + return symbol && (symbol.flags & 1048576) !== 0 + ? getMergedSymbol(symbol.exportSymbol) + : symbol; } function symbolIsValue(symbol) { if (symbol.flags & 16777216) { @@ -8278,7 +8536,7 @@ var ts; return true; } if (symbol.flags & 8388608) { - return (resolveImport(symbol).flags & 107455) !== 0; + return (resolveAlias(symbol).flags & 107455) !== 0; } return false; } @@ -8395,8 +8653,8 @@ var ts; if (symbolFromSymbolTable.flags & 8388608) { if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, ts.isExternalModuleImportEqualsDeclaration)) { - var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); - if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { + var resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable); + if (isAccessible(symbolFromSymbolTable, resolveAlias(symbolFromSymbolTable))) { return [symbolFromSymbolTable]; } var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; @@ -8421,7 +8679,7 @@ var ts; if (symbolFromSymbolTable === symbol) { return true; } - symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608) ? resolveImport(symbolFromSymbolTable) : symbolFromSymbolTable; + symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; if (symbolFromSymbolTable.flags & meaning) { qualify = true; return true; @@ -8712,7 +8970,7 @@ var ts; buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); } else { - writeKeyword(writer, 112); + writeKeyword(writer, 111); } } else { @@ -8803,7 +9061,7 @@ var ts; writer.writeParameter(getIndexerParameterName(resolved, 0, "x")); writePunctuation(writer, 51); writeSpace(writer); - writeKeyword(writer, 121); + writeKeyword(writer, 120); writePunctuation(writer, 19); writePunctuation(writer, 51); writeSpace(writer); @@ -8816,7 +9074,7 @@ var ts; writer.writeParameter(getIndexerParameterName(resolved, 1, "x")); writePunctuation(writer, 51); writeSpace(writer); - writeKeyword(writer, 119); + writeKeyword(writer, 118); writePunctuation(writer, 19); writePunctuation(writer, 51); writeSpace(writer); @@ -8981,7 +9239,7 @@ var ts; return true; } if (symbolOfNode.flags & 8388608) { - return isSymbolUsedInExportAssignment(resolveImport(symbolOfNode)); + return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode)); } } function isSymbolUsedInExportAssignment(symbol) { @@ -8989,7 +9247,7 @@ var ts; return true; } if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & 8388608)) { - resolvedExportSymbol = resolvedExportSymbol || resolveImport(exportAssignmentSymbol); + resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol); if (resolvedExportSymbol === symbol) { return true; } @@ -9123,6 +9381,9 @@ var ts; if (declaration.parent.parent.kind === 182) { return anyType; } + if (declaration.parent.parent.kind === 183) { + return getTypeForVariableDeclarationInForOfStatement(declaration.parent.parent); + } if (ts.isBindingPattern(declaration.parent)) { return getTypeForBindingElement(declaration); } @@ -9182,7 +9443,9 @@ var ts; return !elementTypes.length ? anyArrayType : hasSpreadElement ? createArrayType(getUnionType(elementTypes)) : createTupleType(elementTypes); } function getTypeFromBindingPattern(pattern) { - return pattern.kind === 148 ? getTypeFromObjectBindingPattern(pattern) : getTypeFromArrayBindingPattern(pattern); + return pattern.kind === 148 + ? getTypeFromObjectBindingPattern(pattern) + : getTypeFromArrayBindingPattern(pattern); } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { var type = getTypeForVariableLikeDeclaration(declaration); @@ -9211,9 +9474,12 @@ var ts; return links.type = getTypeOfPrototypeProperty(symbol); } var declaration = symbol.valueDeclaration; - if (declaration.kind === 216) { + if (declaration.parent.kind === 216) { return links.type = anyType; } + if (declaration.kind === 208) { + return links.type = checkExpression(declaration.expression); + } links.type = resolvingType; var type = getWidenedTypeForVariableLikeDeclaration(declaration, true); if (links.type === resolvingType) { @@ -9223,7 +9489,9 @@ var ts; else if (links.type === resolvingType) { links.type = anyType; if (compilerOptions.noImplicitAny) { - var diagnostic = symbol.valueDeclaration.type ? ts.Diagnostics._0_implicitly_has_type_any_because_it_is_referenced_directly_or_indirectly_in_its_own_type_annotation : ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer; + var diagnostic = symbol.valueDeclaration.type ? + ts.Diagnostics._0_implicitly_has_type_any_because_it_is_referenced_directly_or_indirectly_in_its_own_type_annotation : + ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer; error(symbol.valueDeclaration, diagnostic, symbolToString(symbol)); } } @@ -9303,10 +9571,10 @@ var ts; } return links.type; } - function getTypeOfImport(symbol) { + function getTypeOfAlias(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { - links.type = getTypeOfSymbol(resolveImport(symbol)); + links.type = getTypeOfSymbol(resolveAlias(symbol)); } return links.type; } @@ -9334,7 +9602,7 @@ var ts; return getTypeOfAccessors(symbol); } if (symbol.flags & 8388608) { - return getTypeOfImport(symbol); + return getTypeOfAlias(symbol); } return unknownType; } @@ -9488,10 +9756,10 @@ var ts; } return links.declaredType; } - function getDeclaredTypeOfImport(symbol) { + function getDeclaredTypeOfAlias(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { - links.declaredType = getDeclaredTypeOfSymbol(resolveImport(symbol)); + links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol)); } return links.declaredType; } @@ -9513,7 +9781,7 @@ var ts; return getDeclaredTypeOfTypeParameter(symbol); } if (symbol.flags & 8388608) { - return getDeclaredTypeOfImport(symbol); + return getDeclaredTypeOfAlias(symbol); } return unknownType; } @@ -9603,7 +9871,8 @@ var ts; var baseType = classType.baseTypes[0]; var baseSignatures = getSignaturesOfType(getTypeOfSymbol(baseType.symbol), 1); return ts.map(baseSignatures, function (baseSignature) { - var signature = baseType.flags & 4096 ? getSignatureInstantiation(baseSignature, baseType.typeArguments) : cloneSignature(baseSignature); + var signature = baseType.flags & 4096 ? + getSignatureInstantiation(baseSignature, baseType.typeArguments) : cloneSignature(baseSignature); signature.typeParameters = classType.typeParameters; signature.resolvedReturnType = classType; return signature; @@ -9884,11 +10153,22 @@ var ts; }); return result; } + function getExportsOfExternalModule(node) { + if (!node.moduleSpecifier) { + return emptyArray; + } + var module = resolveExternalModuleName(node, node.moduleSpecifier); + if (!module || !module.exports) { + return emptyArray; + } + return ts.mapToArray(getExportsOfModule(module)); + } function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { var classType = declaration.kind === 133 ? getDeclaredTypeOfClass(declaration.parent.symbol) : undefined; - var typeParameters = classType ? classType.typeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; + var typeParameters = classType ? classType.typeParameters : + declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; var hasStringLiterals = false; var minArgumentCount = -1; @@ -10029,7 +10309,7 @@ var ts; return symbol.members["__index"]; } function getIndexDeclarationOfSymbol(symbol, kind) { - var syntaxKind = kind === 1 ? 119 : 121; + var syntaxKind = kind === 1 ? 118 : 120; var indexSymbol = getIndexSymbol(symbol); if (indexSymbol) { var len = indexSymbol.declarations.length; @@ -10047,7 +10327,9 @@ var ts; } function getIndexTypeOfSymbol(symbol, kind) { var declaration = getIndexDeclarationOfSymbol(symbol, kind); - return declaration ? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType : undefined; + return declaration + ? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType + : undefined; } function getConstraintOfTypeParameter(type) { if (!type.constraint) { @@ -10132,7 +10414,7 @@ var ts; function getTypeFromTypeReferenceNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { - var symbol = resolveEntityName(node, node.typeName, 793056); + var symbol = resolveEntityName(node.typeName, 793056); if (symbol) { var type; if ((symbol.flags & 262144) && isTypeParameterReferenceIllegalInConstraint(node, symbol)) { @@ -10205,8 +10487,9 @@ var ts; function getGlobalSymbol(name, meaning, diagnostic) { return resolveName(undefined, name, meaning, diagnostic, name); } - function getGlobalType(name) { - return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), 0); + function getGlobalType(name, arity) { + if (arity === void 0) { arity = 0; } + return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity); } function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); @@ -10350,15 +10633,15 @@ var ts; } function getTypeFromTypeNode(node) { switch (node.kind) { - case 112: + case 111: return anyType; - case 121: + case 120: return stringType; - case 119: + case 118: return numberType; - case 113: + case 112: return booleanType; - case 122: + case 121: return esSymbolType; case 98: return voidType; @@ -10510,7 +10793,8 @@ var ts; return mapper(type); } if (type.flags & 32768) { - return type.symbol && type.symbol.flags & (16 | 8192 | 2048 | 4096) ? instantiateAnonymousType(type, mapper) : type; + return type.symbol && type.symbol.flags & (16 | 8192 | 2048 | 4096) ? + instantiateAnonymousType(type, mapper) : type; } if (type.flags & 4096) { return createTypeReference(type.target, instantiateList(type.typeArguments, mapper, instantiateType)); @@ -10539,7 +10823,7 @@ var ts; isContextSensitive(node.whenFalse); case 167: return node.operatorToken.kind === 49 && - (isContextSensitive(node.left) || isContextSensitive(node.right)); + (isContextSensitive(node.left) || isContextSensitive(node.right)); case 217: return isContextSensitive(node.initializer); case 132: @@ -11309,7 +11593,9 @@ var ts; var diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type; break; case 128: - var diagnostic = declaration.dotDotDotToken ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Parameter_0_implicitly_has_an_1_type; + 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 195: case 132: @@ -11410,7 +11696,9 @@ var ts; for (var i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { var inferences = context.inferences[i]; - var candidates = inferiority ? inferences.secondary || (inferences.secondary = []) : inferences.primary || (inferences.primary = []); + var candidates = inferiority ? + inferences.secondary || (inferences.secondary = []) : + inferences.primary || (inferences.primary = []); if (!ts.contains(candidates, source)) candidates.push(source); break; @@ -11819,46 +12107,56 @@ var ts; return type; } } - function markLinkedImportsAsReferenced(node) { - if (node) { - var nodeLinks = getNodeLinks(node); - while (nodeLinks.importOnRightSide) { - var rightSide = nodeLinks.importOnRightSide; - nodeLinks.importOnRightSide = undefined; - getSymbolLinks(rightSide).referenced = true; - ts.Debug.assert((rightSide.flags & 8388608) !== 0); - nodeLinks = getNodeLinks(ts.getDeclarationOfKind(rightSide, 202)); - } - } - } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); if (symbol === argumentsSymbol && ts.getContainingFunction(node).kind === 161) { 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 = getLeftSideOfImportEqualsOrExportAssignment(node); - if (!importOrExportAssignment || - (importOrExportAssignment.flags & 1) || - (importOrExportAssignment.kind === 208)) { - symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); - } - else { - var nodeLinks = getNodeLinks(importOrExportAssignment); - ts.Debug.assert(!nodeLinks.importOnRightSide); - nodeLinks.importOnRightSide = symbol; - } - } - if (symbolLinks.referenced) { - markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 202)); - } + if (symbol.flags & 8388608 && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { + markAliasSymbolAsReferenced(symbol); } checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); + checkBlockScopedBindingCapturedInLoop(node, symbol); return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } + function isInsideFunction(node, threshold) { + var current = node; + while (current && current !== threshold) { + if (ts.isFunctionLike(current)) { + return true; + } + current = current.parent; + } + return false; + } + function checkBlockScopedBindingCapturedInLoop(node, symbol) { + if (languageVersion >= 2 || + (symbol.flags & 2) === 0 || + symbol.valueDeclaration.parent.kind === 216) { + return; + } + var container = symbol.valueDeclaration; + while (container.kind !== 194) { + container = container.parent; + } + container = container.parent; + if (container.kind === 175) { + container = container.parent; + } + var inFunction = isInsideFunction(node.parent, container); + var current = container; + while (current && !ts.nodeStartsNewLexicalEnvironment(current)) { + if (isIterationStatement(current, false)) { + if (inFunction) { + grammarErrorOnFirstToken(current, ts.Diagnostics.Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher, ts.declarationNameToString(node)); + } + getNodeLinks(symbol.valueDeclaration).flags |= 256; + break; + } + current = current.parent; + } + } function captureLexicalThis(node, container) { var classNode = container.parent && container.parent.kind === 196 ? container.parent : undefined; getNodeLinks(node).flags |= 2; @@ -11944,19 +12242,19 @@ var ts; if (container.flags & 128) { canUseSuperExpression = container.kind === 132 || - container.kind === 131 || - container.kind === 134 || - container.kind === 135; + container.kind === 131 || + container.kind === 134 || + container.kind === 135; } else { canUseSuperExpression = container.kind === 132 || - container.kind === 131 || - container.kind === 134 || - container.kind === 135 || - container.kind === 130 || - container.kind === 129 || - container.kind === 133; + container.kind === 131 || + container.kind === 134 || + container.kind === 135 || + container.kind === 130 || + container.kind === 129 || + container.kind === 133; } } } @@ -12141,7 +12439,9 @@ var ts; var type = getContextualType(arrayLiteral); if (type) { var index = ts.indexOf(arrayLiteral.elements, node); - return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1); + return getTypeOfPropertyOfContextualType(type, "" + index) + || getIndexTypeOfContextualType(type, 1) + || (languageVersion >= 2 ? checkIteratedType(type, undefined) : undefined); } return undefined; } @@ -12205,7 +12505,9 @@ var ts; } function getContextualSignature(node) { ts.Debug.assert(node.kind !== 132 || ts.isObjectLiteralMethod(node)); - var type = ts.isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getContextualType(node); + var type = ts.isObjectLiteralMethod(node) + ? getContextualTypeForObjectLiteralMethod(node) + : getContextualType(node); if (!type) { return undefined; } @@ -12331,7 +12633,9 @@ var ts; } else { ts.Debug.assert(memberDecl.kind === 218); - var type = memberDecl.name.kind === 126 ? unknownType : checkExpression(memberDecl.name, contextualMapper); + var type = memberDecl.name.kind === 126 + ? unknownType + : checkExpression(memberDecl.name, contextualMapper); } typeFlags |= type.flags; var prop = createSymbol(4 | 67108864 | member.flags, member.name); @@ -12447,7 +12751,9 @@ var ts; return anyType; } function isValidPropertyAccess(node, propertyName) { - var left = node.kind === 153 ? node.expression : node.left; + var left = node.kind === 153 + ? node.expression + : node.left; var type = checkExpressionOrQualifiedName(left); if (type !== unknownType && type !== anyType) { var prop = getPropertyOfType(getWidenedType(type), propertyName); @@ -12741,7 +13047,9 @@ var ts; var arg = args[i]; if (arg.kind !== 172) { var paramType = getTypeAtPosition(signature, arg.kind === 171 ? -1 : i); - var argType = i === 0 && node.kind === 157 ? globalTemplateStringsArrayType : arg.kind === 8 && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); + var argType = i === 0 && node.kind === 157 ? 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; } @@ -13018,9 +13326,6 @@ var ts; return getReturnTypeOfSignature(signature); } function checkTaggedTemplateExpression(node) { - if (languageVersion < 2) { - grammarErrorOnFirstToken(node.template, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); - } return getReturnTypeOfSignature(getResolvedSignature(node)); } function checkTypeAssertion(node) { @@ -13036,9 +13341,13 @@ var ts; } function getTypeAtPosition(signature, pos) { if (pos >= 0) { - return signature.hasRestParameter ? pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) : pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType; + return signature.hasRestParameter ? + pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) : + pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType; } - return signature.hasRestParameter ? getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]) : anyArrayType; + return signature.hasRestParameter ? + getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]) : + anyArrayType; } function assignContextualParameterTypes(signature, context, mapper) { var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0); @@ -13179,7 +13488,7 @@ var ts; } return true; } - function checkReferenceExpression(n, invalidReferenceMessage, constantVarianleMessage) { + function checkReferenceExpression(n, invalidReferenceMessage, constantVariableMessage) { function findSymbol(n) { var symbol = getNodeLinks(n).resolvedSymbol; return symbol && getExportSymbolOfValueSymbolIfExported(symbol); @@ -13205,14 +13514,14 @@ var ts; case 64: case 153: var symbol = findSymbol(n); - return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 4096) !== 0; + return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 8192) !== 0; case 154: var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8) { var name = index.text; var prop = getPropertyOfType(getTypeOfSymbol(symbol), name); - return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 4096) !== 0; + return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192) !== 0; } return false; case 159: @@ -13226,7 +13535,7 @@ var ts; return false; } if (isConstVariableReference(n)) { - error(n, constantVarianleMessage); + error(n, constantVariableMessage); return false; } return true; @@ -13340,9 +13649,10 @@ var ts; var p = properties[i]; if (p.kind === 217 || p.kind === 218) { var name = p.name; - var type = sourceType.flags & 1 ? sourceType : getTypeOfPropertyOfType(sourceType, name.text) || - isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, 1) || - getIndexTypeOfType(sourceType, 0); + var type = sourceType.flags & 1 ? sourceType : + getTypeOfPropertyOfType(sourceType, name.text) || + isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, 1) || + getIndexTypeOfType(sourceType, 0); if (type) { checkDestructuringAssignment(p.initializer || name, type); } @@ -13367,7 +13677,9 @@ var ts; 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); + var type = sourceType.flags & 1 ? sourceType : + isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : + getIndexTypeOfType(sourceType, 1); if (type) { checkDestructuringAssignment(e, type, contextualMapper); } @@ -13515,7 +13827,9 @@ var ts; return rightType; } function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576) ? node.left : someConstituentTypeHasKind(rightType, 1048576) ? node.right : undefined; + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576) ? node.left : + someConstituentTypeHasKind(rightType, 1048576) ? node.right : + undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); return false; @@ -13626,8 +13940,8 @@ var ts; } if (isConstEnumObjectType(type)) { var ok = (node.parent.kind === 153 && node.parent.expression === node) || - (node.parent.kind === 154 && node.parent.expression === node) || - ((node.kind === 64 || node.kind === 125) && isInRightSideOfImportOrExportAssignment(node)); + (node.parent.kind === 154 && node.parent.expression === node) || + ((node.kind === 64 || node.kind === 125) && 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); } @@ -13777,7 +14091,7 @@ var ts; var declaration = indexSymbol.declarations[i]; if (declaration.parameters.length === 1 && declaration.parameters[0].type) { switch (declaration.parameters[0].type.kind) { - case 121: + case 120: if (!seenStringIndexer) { seenStringIndexer = true; } @@ -13785,7 +14099,7 @@ var ts; error(declaration, ts.Diagnostics.Duplicate_string_index_signature); } break; - case 119: + case 118: if (!seenNumericIndexer) { seenNumericIndexer = true; } @@ -13852,7 +14166,7 @@ var ts; 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); }); + 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 !== 177 || !isSuperCallExpression(statements[0].expression)) { @@ -14174,13 +14488,15 @@ var ts; case 197: return 2097152; case 200: - return d.name.kind === 8 || ts.getModuleInstanceState(d) !== 0 ? 4194304 | 1048576 : 4194304; + return d.name.kind === 8 || ts.getModuleInstanceState(d) !== 0 + ? 4194304 | 1048576 + : 4194304; case 196: case 199: return 2097152 | 1048576; case 202: var result = 0; - var target = resolveImport(getSymbolOfNode(d)); + var target = resolveAlias(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); }); return result; default: @@ -14201,7 +14517,7 @@ var ts; } function checkFunctionLikeDeclaration(node) { checkSignatureDeclaration(node); - if (node.name.kind === 126) { + if (node.name && node.name.kind === 126) { checkComputedPropertyName(node.name); } if (!ts.hasDynamicName(node)) { @@ -14317,24 +14633,24 @@ var ts; } } function checkVarDeclaredNamesNotShadowed(node) { - if (node.initializer && (ts.getCombinedNodeFlags(node) & 6144) === 0) { + if (node.initializer && (ts.getCombinedNodeFlags(node) & 12288) === 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) & 6144) { + if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 12288) { var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 194); var container = varDeclList.parent.kind === 175 && - varDeclList.parent.parent; + varDeclList.parent.parent; var namesShareScope = container && - (container.kind === 174 && ts.isAnyFunction(container.parent) || - (container.kind === 201 && container.kind === 200) || - container.kind === 220); + (container.kind === 174 && ts.isFunctionLike(container.parent) || + (container.kind === 201 && container.kind === 200) || + container.kind === 220); 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); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name); } } } @@ -14490,33 +14806,127 @@ var ts; checkSourceElement(node.statement); } function checkForOfStatement(node) { - checkGrammarForOfStatement(node); + if (languageVersion < 2) { + grammarErrorOnFirstToken(node, ts.Diagnostics.for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher); + return; + } + checkGrammarForInOrForOfStatement(node); + if (node.initializer.kind === 194) { + checkForInOrForOfVariableDeclaration(node); + } + else { + var varExpr = node.initializer; + var rightType = checkExpression(node.expression); + var iteratedType = checkIteratedType(rightType, node.expression); + if (varExpr.kind === 151 || varExpr.kind === 152) { + checkDestructuringAssignment(varExpr, iteratedType || unknownType); + } + else { + var leftType = checkExpression(varExpr); + checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_of_statement, ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant); + if (iteratedType) { + checkTypeAssignableTo(iteratedType, leftType, varExpr, undefined); + } + } + } + checkSourceElement(node.statement); } function checkForInStatement(node) { checkGrammarForInOrForOfStatement(node); if (node.initializer.kind === 194) { - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length >= 1) { - var decl = variableDeclarationList.declarations[0]; - checkVariableDeclaration(decl); + var variable = node.initializer.declarations[0]; + if (variable && ts.isBindingPattern(variable.name)) { + error(variable.name, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } + checkForInOrForOfVariableDeclaration(node); } else { var varExpr = node.initializer; - var exprType = checkExpression(varExpr); - if (!allConstituentTypesHaveKind(exprType, 1 | 258)) { + var leftType = checkExpression(varExpr); + if (varExpr.kind === 151 || varExpr.kind === 152) { + error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); + } + else if (!allConstituentTypesHaveKind(leftType, 1 | 258)) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { - checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant); } } - var exprType = checkExpression(node.expression); - if (!allConstituentTypesHaveKind(exprType, 1 | 48128 | 512)) { + var rightType = checkExpression(node.expression); + if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); } + function checkForInOrForOfVariableDeclaration(iterationStatement) { + var variableDeclarationList = iterationStatement.initializer; + if (variableDeclarationList.declarations.length >= 1) { + var decl = variableDeclarationList.declarations[0]; + checkVariableDeclaration(decl); + } + } + function getTypeForVariableDeclarationInForOfStatement(forOfStatement) { + if (languageVersion < 2) { + return anyType; + } + var expressionType = getTypeOfExpression(forOfStatement.expression); + return checkIteratedType(expressionType, forOfStatement.expression) || anyType; + } + function checkIteratedType(iterable, expressionForError) { + ts.Debug.assert(languageVersion >= 2); + var iteratedType = getIteratedType(iterable, expressionForError); + if (expressionForError && iteratedType) { + var completeIterableType = globalIterableType !== emptyObjectType + ? createTypeReference(globalIterableType, [iteratedType]) + : emptyObjectType; + checkTypeAssignableTo(iterable, completeIterableType, expressionForError); + } + return iteratedType; + function getIteratedType(iterable, expressionForError) { + if (allConstituentTypesHaveKind(iterable, 1)) { + return undefined; + } + var iteratorFunction = getTypeOfPropertyOfType(iterable, ts.getPropertyNameForKnownSymbolName("iterator")); + if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, 1)) { + return undefined; + } + var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray; + if (iteratorFunctionSignatures.length === 0) { + if (expressionForError) { + error(expressionForError, ts.Diagnostics.The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + } + return undefined; + } + var iterator = getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)); + if (allConstituentTypesHaveKind(iterator, 1)) { + return undefined; + } + var iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next"); + if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, 1)) { + return undefined; + } + var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray; + if (iteratorNextFunctionSignatures.length === 0) { + if (expressionForError) { + error(expressionForError, ts.Diagnostics.The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method); + } + return undefined; + } + var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); + if (allConstituentTypesHaveKind(iteratorNextResult, 1)) { + return undefined; + } + var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); + if (!iteratorNextValue) { + if (expressionForError) { + error(expressionForError, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); + } + return undefined; + } + return iteratorNextValue; + } + } function checkBreakOrContinueStatement(node) { checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node); } @@ -14592,7 +15002,7 @@ var ts; if (!checkGrammarStatementInAmbientContext(node)) { var current = node.parent; while (current) { - if (ts.isAnyFunction(current)) { + if (ts.isFunctionLike(current)) { break; } if (current.kind === 189 && current.label.text === node.label.text) { @@ -14620,16 +15030,33 @@ var ts; checkBlock(node.tryBlock); var catchClause = node.catchClause; if (catchClause) { - if (catchClause.type) { - var sourceFile = ts.getSourceFileOfNode(node); - var colonStart = ts.skipTrivia(sourceFile.text, catchClause.name.end); - grammarErrorAtPos(sourceFile, colonStart, ":".length, ts.Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); + if (catchClause.variableDeclaration) { + if (catchClause.variableDeclaration.name.kind !== 64) { + grammarErrorOnFirstToken(catchClause.variableDeclaration.name, ts.Diagnostics.Catch_clause_variable_name_must_be_an_identifier); + } + else if (catchClause.variableDeclaration.type) { + grammarErrorOnFirstToken(catchClause.variableDeclaration.type, ts.Diagnostics.Catch_clause_variable_cannot_have_a_type_annotation); + } + else if (catchClause.variableDeclaration.initializer) { + grammarErrorOnFirstToken(catchClause.variableDeclaration.initializer, ts.Diagnostics.Catch_clause_variable_cannot_have_an_initializer); + } + else { + var identifierName = catchClause.variableDeclaration.name.text; + var locals = catchClause.block.locals; + if (locals && ts.hasProperty(locals, identifierName)) { + var localSymbol = locals[identifierName]; + if (localSymbol && (localSymbol.flags & 2) !== 0) { + grammarErrorOnNode(localSymbol.valueDeclaration, ts.Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName); + } + } + checkGrammarEvalOrArgumentsInStrictMode(node, catchClause.variableDeclaration.name); + } } - checkGrammarEvalOrArgumentsInStrictMode(node, catchClause.name); checkBlock(catchClause.block); } - if (node.finallyBlock) + if (node.finallyBlock) { checkBlock(node.finallyBlock); + } } function checkIndexConstraints(type) { var declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, 1); @@ -14684,7 +15111,9 @@ var ts; errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0]; } if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { - var errorMessage = indexKind === 0 ? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 : ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; + var errorMessage = indexKind === 0 + ? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 + : ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType)); } } @@ -14717,10 +15146,12 @@ var ts; } function checkClassDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); - checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); + if (node.name) { + checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); + checkCollisionWithCapturedThisVariable(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + } checkTypeParameters(node.typeParameters); - checkCollisionWithCapturedThisVariable(node, node.name); - checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); @@ -14733,10 +15164,10 @@ var ts; if (type.baseTypes.length) { if (produceDiagnostics) { var baseType = type.baseTypes[0]; - checkTypeAssignableTo(type, baseType, node.name, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); + checkTypeAssignableTo(type, baseType, node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); var staticBaseType = getTypeOfSymbol(baseType.symbol); - checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); - if (baseType.symbol !== resolveEntityName(node, baseTypeNode.typeName, 107455)) { + checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); + if (baseType.symbol !== resolveEntityName(baseTypeNode.typeName, 107455)) { error(baseTypeNode, ts.Diagnostics.Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_0, typeToString(baseType)); } checkKindsOfPropertyMemberOverrides(type, baseType); @@ -14752,7 +15183,7 @@ var ts; if (t !== unknownType) { var declaredType = (t.flags & 4096) ? t.target : t; if (declaredType.flags & (1024 | 2048)) { - checkTypeAssignableTo(type, t, node.name, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); + checkTypeAssignableTo(type, t, node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); } else { error(typeRefNode, ts.Diagnostics.A_class_may_only_implement_another_class_or_interface); @@ -15100,21 +15531,15 @@ 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 === 201) { - var statements = node.body.statements; - for (var i = 0, n = statements.length; i < n; i++) { - var statement = statements[i]; - if (statement.kind === 208) { - grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); - } - } - } } checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(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)) { + if (symbol.flags & 512 + && symbol.declarations.length > 1 + && !ts.isInAmbientContext(node) + && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums)) { var classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (classOrFunc) { if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(classOrFunc)) { @@ -15150,7 +15575,9 @@ var ts; } var inAmbientExternalModule = node.parent.kind === 201 && node.parent.parent.name.kind === 8; if (node.parent.kind !== 220 && !inAmbientExternalModule) { - error(moduleName, node.kind === 209 ? ts.Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module : ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + error(moduleName, node.kind === 209 ? + ts.Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module : + ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); return false; } if (inAmbientExternalModule && isExternalModuleNameRelative(moduleName.text)) { @@ -15159,15 +15586,17 @@ var ts; } return true; } - function checkImportSymbol(node) { + function checkAliasSymbol(node) { var symbol = getSymbolOfNode(node); - var target = resolveImport(symbol); + var target = resolveAlias(symbol); if (target !== unknownSymbol) { var excludedMeanings = (symbol.flags & 107455 ? 107455 : 0) | - (symbol.flags & 793056 ? 793056 : 0) | - (symbol.flags & 1536 ? 1536 : 0); + (symbol.flags & 793056 ? 793056 : 0) | + (symbol.flags & 1536 ? 1536 : 0); if (target.flags & excludedMeanings) { - var message = node.kind === 211 ? ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; + var message = node.kind === 211 ? + ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : + ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; error(node, message, symbolToString(symbol)); } } @@ -15175,10 +15604,10 @@ var ts; function checkImportBinding(node) { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); - checkImportSymbol(node); + checkAliasSymbol(node); } function checkImportDeclaration(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + if (!checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -15200,50 +15629,107 @@ var ts; } function checkImportEqualsDeclaration(node) { checkGrammarModifiers(node); - if (ts.isInternalModuleImportEqualsDeclaration(node)) { + if (ts.isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); - var symbol = getSymbolOfNode(node); - var target = resolveImport(symbol); - if (target !== unknownSymbol) { - if (target.flags & 107455) { - var moduleName = getFirstIdentifier(node.moduleReference); - if (resolveEntityName(node, moduleName, 107455 | 1536).flags & 1536) { - checkExpressionOrQualifiedName(node.moduleReference); - } - else { - error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName)); - } - } - if (target.flags & 793056) { - checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); - } + if (node.flags & 1) { + markExportAsReferenced(node); } - } - else { - if (checkExternalImportOrExportDeclaration(node)) { - checkImportBinding(node); + if (ts.isInternalModuleImportEqualsDeclaration(node)) { + var target = resolveAlias(getSymbolOfNode(node)); + if (target !== unknownSymbol) { + if (target.flags & 107455) { + var moduleName = getFirstIdentifier(node.moduleReference); + if (!(resolveEntityName(moduleName, 107455 | 1536).flags & 1536)) { + error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName)); + } + } + if (target.flags & 793056) { + checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); + } + } } } } function checkExportDeclaration(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + if (!checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_declaration_cannot_have_modifiers); } if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) { if (node.exportClause) { - ts.forEach(node.exportClause.elements, checkImportSymbol); + ts.forEach(node.exportClause.elements, checkExportSpecifier); } } } + function checkExportSpecifier(node) { + checkAliasSymbol(node); + if (!node.parent.parent.moduleSpecifier) { + markExportAsReferenced(node); + } + } function checkExportAssignment(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + var container = node.parent.kind === 220 ? node.parent : node.parent.parent; + if (container.kind === 200 && container.name.kind === 64) { + error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); + return; + } + if (!checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); } - var container = node.parent; - if (container.kind !== 220) { - container = container.parent; + if (node.expression.kind === 64) { + markExportAsReferenced(node); + } + else { + checkExpressionCached(node.expression); + } + checkExternalModuleExports(container); + } + function getModuleStatements(node) { + if (node.kind === 220) { + return node.statements; + } + if (node.kind === 200 && node.body.kind === 201) { + return node.body.statements; + } + return emptyArray; + } + function hasExportedMembers(moduleSymbol) { + var declarations = moduleSymbol.declarations; + for (var i = 0; i < declarations.length; i++) { + var statements = getModuleStatements(declarations[i]); + for (var j = 0; j < statements.length; j++) { + var node = statements[j]; + if (node.kind === 209) { + var exportClause = node.exportClause; + if (!exportClause) { + return true; + } + var specifiers = exportClause.elements; + for (var k = 0; k < specifiers.length; k++) { + var specifier = specifiers[k]; + if (!(specifier.propertyName && specifier.name && specifier.name.text === "default")) { + return true; + } + } + } + else if (node.kind !== 208 && node.flags & 1 && !(node.flags & 256)) { + return true; + } + } + } + } + function checkExternalModuleExports(node) { + var moduleSymbol = getSymbolOfNode(node); + var links = getSymbolLinks(moduleSymbol); + if (!links.exportsChecked) { + var defaultSymbol = getExportAssignmentSymbol(moduleSymbol); + if (defaultSymbol) { + if (hasExportedMembers(moduleSymbol)) { + var declaration = getDeclarationOfAliasSymbol(defaultSymbol) || defaultSymbol.valueDeclaration; + error(declaration, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); + } + } + links.exportsChecked = true; } - checkTypeOfExportAssignmentSymbol(getSymbolOfNode(container)); } function checkSourceElement(node) { if (!node) @@ -15425,6 +15911,7 @@ var ts; case 196: case 199: case 219: + case 208: case 220: ts.forEachChild(node, checkFunctionExpressionBodies); break; @@ -15444,11 +15931,7 @@ var ts; 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, 202)); - } + checkExternalModuleExports(node); } if (potentialThisCollisions.length) { ts.forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope); @@ -15537,11 +16020,6 @@ var ts; copySymbol(location.symbol, meaning); } break; - case 216: - if (location.name.text) { - copySymbol(location.symbol, meaning); - } - break; } memberFlags = location.flags; location = location.parent; @@ -15575,11 +16053,11 @@ var ts; return true; } switch (node.kind) { + case 111: + case 118: + case 120: case 112: - case 119: case 121: - case 113: - case 122: return true; case 98: return node.parent.kind !== 164; @@ -15638,7 +16116,7 @@ var ts; return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent; } if (nodeOnRightSide.parent.kind === 208) { - return nodeOnRightSide.parent.exportName === nodeOnRightSide && nodeOnRightSide.parent; + return nodeOnRightSide.parent.expression === nodeOnRightSide && nodeOnRightSide.parent; } return undefined; } @@ -15650,11 +16128,11 @@ var ts; (node.parent.kind === 153 && node.parent.name === node); } function getSymbolOfEntityNameOrPropertyAccessExpression(entityName) { - if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { + if (ts.isDeclarationName(entityName)) { return getSymbolOfNode(entityName.parent); } if (entityName.parent.kind === 208) { - return resolveEntityName(entityName.parent.parent, entityName, 107455 | 793056 | 1536 | 8388608); + return resolveEntityName(entityName, 107455 | 793056 | 1536 | 8388608); } if (entityName.kind !== 153) { if (isInRightSideOfImportOrExportAssignment(entityName)) { @@ -15670,7 +16148,7 @@ var ts; } if (entityName.kind === 64) { var meaning = 107455 | 8388608; - return resolveEntityName(entityName, entityName, meaning); + return resolveEntityName(entityName, meaning); } else if (entityName.kind === 153) { var symbol = getNodeLinks(entityName).resolvedSymbol; @@ -15690,7 +16168,7 @@ var ts; else if (isTypeReferenceIdentifier(entityName)) { var meaning = entityName.parent.kind === 139 ? 793056 : 1536; meaning |= 8388608; - return resolveEntityName(entityName, entityName, meaning); + return resolveEntityName(entityName, meaning); } return undefined; } @@ -15698,11 +16176,13 @@ var ts; if (isInsideWithStatementBody(node)) { return undefined; } - if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (ts.isDeclarationName(node)) { return getSymbolOfNode(node.parent); } if (node.kind === 64 && isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 208 ? getSymbolOfEntityNameOrPropertyAccessExpression(node) : getSymbolOfPartOfRightHandSideOfImportEquals(node); + return node.parent.kind === 208 + ? getSymbolOfEntityNameOrPropertyAccessExpression(node) + : getSymbolOfPartOfRightHandSideOfImportEquals(node); } switch (node.kind) { case 64: @@ -15713,18 +16193,19 @@ var ts; case 90: var type = checkExpression(node); return type.symbol; - case 114: + case 113: var constructorDeclaration = node.parent; if (constructorDeclaration && constructorDeclaration.kind === 133) { return constructorDeclaration.parent.symbol; } return undefined; case 8: - if (ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) && - ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) { - var importSymbol = getSymbolOfNode(node.parent.parent); - var moduleType = getTypeOfSymbol(importSymbol); - return moduleType ? moduleType.symbol : undefined; + var moduleName; + if ((ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) && + ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) || + ((node.parent.kind === 203 || node.parent.kind === 209) && + node.parent.moduleSpecifier === node)) { + return resolveExternalModuleName(node, node); } case 7: if (node.parent.kind == 154 && node.parent.argumentExpression === node) { @@ -15742,7 +16223,7 @@ var ts; } function getShorthandAssignmentValueSymbol(location) { if (location && location.kind === 218) { - return resolveEntityName(location, location.name, 107455); + return resolveEntityName(location.name, 107455); } return undefined; } @@ -15768,7 +16249,7 @@ var ts; var symbol = getSymbolOfNode(node); return getTypeOfSymbol(symbol); } - if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (ts.isDeclarationName(node)) { var symbol = getSymbolInfo(node); return symbol && getTypeOfSymbol(symbol); } @@ -15845,6 +16326,10 @@ var ts; return generatedNames; function generateNames(node) { switch (node.kind) { + case 195: + case 196: + generateNameForFunctionOrClassDeclaration(node); + break; case 200: generateNameForModuleOrEnum(node); generateNames(node.body); @@ -15858,6 +16343,9 @@ var ts; case 209: generateNameForExportDeclaration(node); break; + case 208: + generateNameForExportAssignment(node); + break; case 220: case 201: ts.forEach(node.statements, generateNames); @@ -15868,27 +16356,17 @@ var ts; return ts.hasProperty(globals, name) || ts.hasProperty(sourceFile.identifiers, name) || ts.hasProperty(generatedNames, name); } function makeUniqueName(baseName) { - if (baseName.charCodeAt(0) !== 95) { - var baseName = "_" + baseName; - if (!isExistingName(baseName)) { - return generatedNames[baseName] = baseName; - } - } - if (baseName.charCodeAt(baseName.length - 1) !== 95) { - baseName += "_"; - } - var i = 1; - while (true) { - name = baseName + i; - if (!isExistingName(name)) { - return generatedNames[name] = name; - } - i++; - } + var name = ts.generateUniqueName(baseName, isExistingName); + return generatedNames[name] = name; } function assignGeneratedName(node, name) { getNodeLinks(node).generatedName = ts.unescapeIdentifier(name); } + function generateNameForFunctionOrClassDeclaration(node) { + if (!node.name) { + assignGeneratedName(node, makeUniqueName("default")); + } + } function generateNameForModuleOrEnum(node) { if (node.name.kind === 64) { var name = node.name.text; @@ -15897,7 +16375,8 @@ var ts; } function generateNameForImportOrExportDeclaration(node) { var expr = ts.getExternalModuleName(node); - var baseName = expr.kind === 8 ? ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; + var baseName = expr.kind === 8 ? + ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; assignGeneratedName(node, makeUniqueName(baseName)); } function generateNameForImportDeclaration(node) { @@ -15910,6 +16389,11 @@ var ts; generateNameForImportOrExportDeclaration(node); } } + function generateNameForExportAssignment(node) { + if (node.expression.kind !== 64) { + assignGeneratedName(node, makeUniqueName("default")); + } + } } function getGeneratedNameForNode(node) { var links = getNodeLinks(node); @@ -15924,8 +16408,8 @@ var ts; function getLocalNameForImportDeclaration(node) { return getGeneratedNameForNode(node); } - function getImportNameSubstitution(symbol) { - var declaration = getDeclarationOfImportSymbol(symbol); + function getAliasNameSubstitution(symbol) { + var declaration = getDeclarationOfAliasSymbol(symbol); if (declaration && declaration.kind === 207) { var moduleName = getGeneratedNameForNode(declaration.parent.parent.parent); var propertyName = declaration.propertyName || declaration.name; @@ -15956,38 +16440,35 @@ var ts; return getExportNameSubstitution(exportSymbol, node.parent); } if (symbol.flags & 8388608) { - return getImportNameSubstitution(symbol); + return getAliasNameSubstitution(symbol); } } } - function getExportAssignmentName(node) { - var symbol = getExportAssignmentSymbol(getSymbolOfNode(node)); - return symbol && symbol !== unknownSymbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol) ? symbolToString(symbol) : undefined; + function hasExportDefaultValue(node) { + var symbol = getResolvedExportAssignmentSymbol(getSymbolOfNode(node)); + return symbol && symbol !== unknownSymbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol); } function isTopLevelValueImportEqualsWithEntityName(node) { if (node.parent.kind !== 220 || !ts.isInternalModuleImportEqualsDeclaration(node)) { return false; } - return isImportResolvedToValue(getSymbolOfNode(node)); + return isAliasResolvedToValue(getSymbolOfNode(node)); } - function isImportResolvedToValue(symbol) { - var target = resolveImport(symbol); + function isAliasResolvedToValue(symbol) { + var target = resolveAlias(symbol); return target !== unknownSymbol && target.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(target); } function isConstEnumOrConstEnumOnlyModule(s) { return isConstEnumSymbol(s) || s.constEnumOnlyModule; } - function isReferencedImportDeclaration(node) { - if (isImportSymbolDeclaration(node)) { + function isReferencedAliasDeclaration(node) { + if (isAliasSymbolDeclaration(node)) { var symbol = getSymbolOfNode(node); if (getSymbolLinks(symbol).referenced) { return true; } - if (node.kind === 202 && node.flags & 1 && isImportResolvedToValue(symbol)) { - return true; - } } - return ts.forEachChild(node, isReferencedImportDeclaration); + return ts.forEachChild(node, isReferencedAliasDeclaration); } function isImplementationOfOverload(node) { if (ts.nodeIsPresent(node.body)) { @@ -16021,7 +16502,9 @@ var ts; } function writeTypeOfDeclaration(declaration, enclosingDeclaration, flags, writer) { var symbol = getSymbolOfNode(declaration); - var type = symbol && !(symbol.flags & (2048 | 131072)) ? getTypeOfSymbol(symbol) : unknownType; + var type = symbol && !(symbol.flags & (2048 | 131072)) + ? getTypeOfSymbol(symbol) + : unknownType; getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } function writeReturnTypeOfSignatureDeclaration(signatureDeclaration, enclosingDeclaration, flags, writer) { @@ -16032,12 +16515,38 @@ var ts; return !resolveName(location, name, 107455, undefined, undefined) && !ts.hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name); } + function getBlockScopedVariableId(n) { + ts.Debug.assert(!ts.nodeIsSynthesized(n)); + if (n.parent.kind === 153 && + n.parent.name === n) { + return undefined; + } + if (n.parent.kind === 150 && + n.parent.propertyName === n) { + return undefined; + } + var declarationSymbol = (n.parent.kind === 193 && n.parent.name === n) || + n.parent.kind === 150 + ? getSymbolOfNode(n.parent) + : undefined; + var symbol = declarationSymbol || + getNodeLinks(n).resolvedSymbol || + resolveName(n, n.text, 2 | 8388608, undefined, undefined); + var isLetOrConst = symbol && + (symbol.flags & 2) && + symbol.valueDeclaration.parent.kind !== 216; + if (isLetOrConst) { + getSymbolLinks(symbol); + return symbol.id; + } + return undefined; + } function createResolver() { return { getGeneratedNameForNode: getGeneratedNameForNode, getExpressionNameSubstitution: getExpressionNameSubstitution, - getExportAssignmentName: getExportAssignmentName, - isReferencedImportDeclaration: isReferencedImportDeclaration, + hasExportDefaultValue: hasExportDefaultValue, + isReferencedAliasDeclaration: isReferencedAliasDeclaration, getNodeCheckFlags: getNodeCheckFlags, isTopLevelValueImportEqualsWithEntityName: isTopLevelValueImportEqualsWithEntityName, isDeclarationVisible: isDeclarationVisible, @@ -16047,7 +16556,8 @@ var ts; isSymbolAccessible: isSymbolAccessible, isEntityNameVisible: isEntityNameVisible, getConstantValue: getConstantValue, - isUnknownIdentifier: isUnknownIdentifier + isUnknownIdentifier: isUnknownIdentifier, + getBlockScopedVariableId: getBlockScopedVariableId }; } function initializeTypeChecker() { @@ -16075,6 +16585,7 @@ var ts; globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray"); globalESSymbolType = getGlobalType("Symbol"); globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"); + globalIterableType = getGlobalType("Iterable", 1); } else { globalTemplateStringsArrayType = unknownType; @@ -16117,14 +16628,14 @@ var ts; for (var i = 0, n = node.modifiers.length; i < n; i++) { var modifier = node.modifiers[i]; switch (modifier.kind) { - case 109: case 108: case 107: + case 106: var text; - if (modifier.kind === 109) { + if (modifier.kind === 108) { text = "public"; } - else if (modifier.kind === 108) { + else if (modifier.kind === 107) { text = "protected"; lastProtected = modifier; } @@ -16143,7 +16654,7 @@ var ts; } flags |= ts.modifierToFlag(modifier.kind); break; - case 110: + case 109: if (flags & 128) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } @@ -16171,7 +16682,7 @@ var ts; } flags |= 1; break; - case 115: + case 114: if (flags & 2) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); } @@ -16277,7 +16788,7 @@ var ts; if (parameter.dotDotDotToken) { return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter); } - if (parameter.flags & 243) { + if (parameter.flags & 499) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); } if (parameter.questionToken) { @@ -16289,7 +16800,7 @@ var ts; if (!parameter.type) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); } - if (parameter.type.kind !== 121 && parameter.type.kind !== 119) { + if (parameter.type.kind !== 120 && parameter.type.kind !== 118) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); } if (!node.type) { @@ -16297,7 +16808,7 @@ var ts; } } function checkGrammarForIndexSignatureModifier(node) { - if (node.flags & 243) { + if (node.flags & 499) { grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members); } } @@ -16362,7 +16873,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103); + ts.Debug.assert(heritageClause.token === 102); if (seenImplementsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); } @@ -16385,7 +16896,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103); + ts.Debug.assert(heritageClause.token === 102); return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); } checkGrammarHeritageClause(heritageClause); @@ -16482,29 +16993,28 @@ var ts; var variableList = forInOrOfStatement.initializer; if (!checkGrammarVariableDeclarationList(variableList)) { if (variableList.declarations.length > 1) { - var diagnostic = forInOrOfStatement.kind === 182 ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement; + var diagnostic = forInOrOfStatement.kind === 182 + ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement + : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement; return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic); } var firstDeclaration = variableList.declarations[0]; if (firstDeclaration.initializer) { - var diagnostic = forInOrOfStatement.kind === 182 ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer; + var diagnostic = forInOrOfStatement.kind === 182 + ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer + : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer; return grammarErrorOnNode(firstDeclaration.name, diagnostic); } if (firstDeclaration.type) { - var diagnostic = forInOrOfStatement.kind === 182 ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation; + var diagnostic = forInOrOfStatement.kind === 182 + ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation + : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation; return grammarErrorOnNode(firstDeclaration, diagnostic); } } } return false; } - function checkGrammarForOfStatement(forOfStatement) { - return grammarErrorOnFirstToken(forOfStatement, ts.Diagnostics.for_of_statements_are_not_currently_supported); - if (languageVersion < 2) { - return grammarErrorOnFirstToken(forOfStatement, ts.Diagnostics.for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher); - } - return checkGrammarForInOrForOfStatement(forOfStatement); - } function checkGrammarAccessor(accessor) { var kind = accessor.kind; if (languageVersion < 1) { @@ -16534,7 +17044,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 & 499) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } else if (parameter.questionToken) { @@ -16599,13 +17109,14 @@ var ts; function checkGrammarBreakOrContinueStatement(node) { var current = node; while (current) { - if (ts.isAnyFunction(current)) { + if (ts.isFunctionLike(current)) { return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } switch (current.kind) { case 189: if (node.label && current.label.text === node.label.text) { - var isMisplacedContinueLabel = node.kind === 184 && !isIterationStatement(current.statement, true); + var isMisplacedContinueLabel = node.kind === 184 + && !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); } @@ -16626,11 +17137,15 @@ var ts; current = current.parent; } if (node.label) { - var message = node.kind === 185 ? 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 === 185 + ? 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 === 185 ? 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 === 185 + ? 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); } } @@ -16647,16 +17162,17 @@ var ts; return checkGrammarEvalOrArgumentsInStrictMode(node, node.name); } function checkGrammarVariableDeclaration(node) { - if (ts.isInAmbientContext(node)) { - if (ts.isBindingPattern(node.name)) { - return grammarErrorOnNode(node, ts.Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); + if (node.parent.parent.kind !== 182 && node.parent.parent.kind !== 183) { + if (ts.isInAmbientContext(node)) { + if (ts.isBindingPattern(node.name)) { + return grammarErrorOnNode(node, ts.Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); + } + if (node.initializer) { + var equalsTokenLength = "=".length; + return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, equalsTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } } - if (node.initializer) { - return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - 1, 1, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); - } - } - else { - if (!node.initializer) { + else if (!node.initializer) { if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) { return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer); } @@ -16690,14 +17206,6 @@ var ts; if (!declarationList.declarations.length) { return grammarErrorAtPos(ts.getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); } - if (languageVersion < 2) { - if (ts.isLet(declarationList)) { - return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (ts.isConst(declarationList)) { - return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - } } function allowLetAndConstDeclarations(parent) { switch (parent.kind) { @@ -16737,7 +17245,7 @@ var ts; return false; } function checkGrammarEnumDeclaration(enumDecl) { - var enumIsConst = (enumDecl.flags & 4096) !== 0; + var enumIsConst = (enumDecl.flags & 8192) !== 0; var hasError = false; if (!enumIsConst) { var inConstantEnumMemberSection = true; @@ -16765,18 +17273,11 @@ var ts; function hasParseDiagnostics(sourceFile) { return sourceFile.parseDiagnostics.length > 0; } - function scanToken(scanner, pos) { - scanner.setTextPos(pos); - scanner.scan(); - var start = scanner.getTokenPos(); - return start; - } function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = ts.createScanner(languageVersion, true, sourceFile.text); - var start = scanToken(scanner, node.pos); - diagnostics.add(ts.createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2)); + var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos); + diagnostics.add(ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2)); return true; } } @@ -16789,16 +17290,17 @@ var ts; function grammarErrorOnNode(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var span = ts.getErrorSpanForNode(node); - var start = span.end > span.pos ? ts.skipTrivia(sourceFile.text, span.pos) : span.pos; - diagnostics.add(ts.createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2)); + diagnostics.add(ts.createDiagnosticForNode(node, message, arg0, arg1, arg2)); return true; } } - function checkGrammarEvalOrArgumentsInStrictMode(contextNode, identifier) { - if (contextNode && (contextNode.parserContextFlags & 1) && ts.isEvalOrArgumentsIdentifier(identifier)) { - var name = ts.declarationNameToString(identifier); - return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, name); + function checkGrammarEvalOrArgumentsInStrictMode(contextNode, name) { + if (name && name.kind === 64) { + var identifier = name; + if (contextNode && (contextNode.parserContextFlags & 1) && ts.isEvalOrArgumentsIdentifier(identifier)) { + var nameText = ts.declarationNameToString(identifier); + return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); + } } } function checkGrammarConstructorTypeParameters(node) { @@ -16862,7 +17364,7 @@ var ts; return getNodeLinks(node).hasReportedStatementInAmbientContext = true; } var links = getNodeLinks(node); - if (!links.hasReportedStatementInAmbientContext && ts.isAnyFunction(node.parent)) { + if (!links.hasReportedStatementInAmbientContext && ts.isFunctionLike(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); } if (node.parent.kind === 174 || node.parent.kind === 201 || node.parent.kind === 220) { @@ -16876,7 +17378,7 @@ var ts; } } function checkGrammarNumbericLiteral(node) { - if (node.flags & 8192) { + if (node.flags & 16384) { if (node.parserContextFlags & 1) { return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); } @@ -16888,9 +17390,8 @@ var ts; function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = ts.createScanner(languageVersion, true, sourceFile.text); - scanToken(scanner, node.pos); - diagnostics.add(ts.createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2)); + var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos); + diagnostics.add(ts.createFileDiagnostic(sourceFile, ts.textSpanEnd(span), 0, message, arg0, arg1, arg2)); return true; } } @@ -17019,7 +17520,9 @@ var ts; var lineCount = ts.getLineStarts(currentSourceFile).length; var firstCommentLineIndent; for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - var nextLineStart = (currentLine + 1) === lineCount ? currentSourceFile.text.length + 1 : ts.getStartPositionOfLine(currentLine + 1, currentSourceFile); + var nextLineStart = (currentLine + 1) === lineCount + ? currentSourceFile.text.length + 1 + : ts.getStartPositionOfLine(currentLine + 1, currentSourceFile); if (pos !== comment.pos) { if (firstCommentLineIndent === undefined) { firstCommentLineIndent = calculateIndent(ts.getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos); @@ -17097,7 +17600,8 @@ var ts; } else { ts.forEach(declarations, function (member) { - if ((member.kind === 134 || member.kind === 135) && (member.flags & 128) === (accessor.flags & 128)) { + if ((member.kind === 134 || member.kind === 135) + && (member.flags & 128) === (accessor.flags & 128)) { var memberName = ts.getPropertyNameForPropertyNameNode(member.name); var accessorName = ts.getPropertyNameForPropertyNameNode(accessor.name); if (memberName === accessorName) { @@ -17162,7 +17666,7 @@ var ts; var addedGlobalFileReference = false; ts.forEach(root.referencedFiles, function (fileReference) { var referencedFile = ts.tryResolveScriptReference(host, root, fileReference); - if (referencedFile && ((referencedFile.flags & 1024) || + if (referencedFile && ((referencedFile.flags & 2048) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) { writeReferencePath(referencedFile); @@ -17321,11 +17825,11 @@ var ts; } function emitType(type) { switch (type.kind) { + case 111: + case 120: + case 118: case 112: case 121: - case 119: - case 113: - case 122: case 98: case 8: return writeTextOfNode(currentSourceFile, type); @@ -17415,8 +17919,8 @@ var ts; emitLines(node.statements); } function emitExportAssignment(node) { - write("export = "); - writeTextOfNode(currentSourceFile, node.exportName); + write(node.isExportEquals ? "export = " : "export default "); + writeTextOfNode(currentSourceFile, node.expression); write(";"); writeLine(); } @@ -17632,7 +18136,9 @@ var ts; function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; if (node.parent.parent.kind === 196) { - 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; + 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 { diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; @@ -17725,17 +18231,31 @@ var ts; function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; if (node.kind === 193) { - 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; + 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 === 130 || node.kind === 129) { 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; + 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 === 196) { - 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; + 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 { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; } } return diagnosticMessage !== undefined ? { @@ -17797,17 +18317,25 @@ var ts; } function getTypeAnnotationFromAccessor(accessor) { if (accessor) { - return accessor.kind === 134 ? accessor.type : accessor.parameters.length > 0 ? accessor.parameters[0].type : undefined; + return accessor.kind === 134 + ? accessor.type + : accessor.parameters.length > 0 + ? accessor.parameters[0].type + : undefined; } } function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; if (accessorWithTypeAnnotation.kind === 135) { 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; + 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; } else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; } return { diagnosticMessage: diagnosticMessage, @@ -17817,10 +18345,18 @@ var ts; } else { if (accessorWithTypeAnnotation.flags & 128) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === 2 ? + ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; } else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === 2 ? + ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; } return { diagnosticMessage: diagnosticMessage, @@ -17902,28 +18438,48 @@ var ts; var diagnosticMessage; switch (node.kind) { case 137: - 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; + 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 136: - 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; + 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 138: - 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; + 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 132: case 131: 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; + 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 === 196) { - 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; + 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; + 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 195: - 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; + 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: ts.Debug.fail("This is unknown kind for signature: " + node.kind); @@ -17962,28 +18518,50 @@ var ts; var diagnosticMessage; switch (node.parent.kind) { case 133: - 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; + 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 137: - 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; + 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 136: - 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; + 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 132: case 131: 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; + 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 === 196) { - 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; + 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; + 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 195: - 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; + 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: ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind); @@ -18035,7 +18613,11 @@ var ts; } } function writeReferencePath(referencedFile) { - var declFileName = referencedFile.flags & 1024 ? referencedFile.fileName : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; + var declFileName = referencedFile.flags & 2048 + ? referencedFile.fileName + : shouldEmitToOwnFile(referencedFile, compilerOptions) + ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") + : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, host.getCurrentDirectory(), host.getCanonicalFileName, false); referencePathsOutput += "/// " + newLine; } @@ -18087,12 +18669,16 @@ var ts; var increaseIndent = writer.increaseIndent; var decreaseIndent = writer.decreaseIndent; var currentSourceFile; + var lastFrame; + var currentScopeNames; + var generatedBlockScopeNames; var extendsEmitted = false; var tempCount = 0; var tempVariables; var tempParameters; var externalImports; var exportSpecifiers; + var exportDefault; var writeEmittedFiles = writeJavaScriptFile; var emitLeadingComments = compilerOptions.removeComments ? function (node) { } : emitLeadingDeclarationComments; var emitTrailingComments = compilerOptions.removeComments ? function (node) { } : emitTrailingDeclarationComments; @@ -18124,6 +18710,53 @@ var ts; writeLine(); writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); return; + function enterNameScope() { + var names = currentScopeNames; + currentScopeNames = undefined; + if (names) { + lastFrame = { names: names, previous: lastFrame }; + return true; + } + return false; + } + function exitNameScope(popFrame) { + if (popFrame) { + currentScopeNames = lastFrame.names; + lastFrame = lastFrame.previous; + } + else { + currentScopeNames = undefined; + } + } + function generateUniqueNameForLocation(location, baseName) { + var name; + if (!isExistingName(location, baseName)) { + name = baseName; + } + else { + name = ts.generateUniqueName(baseName, function (n) { return isExistingName(location, n); }); + } + if (!currentScopeNames) { + currentScopeNames = {}; + } + return currentScopeNames[name] = name; + } + function isExistingName(location, name) { + if (!resolver.isUnknownIdentifier(location, name)) { + return true; + } + if (currentScopeNames && ts.hasProperty(currentScopeNames, name)) { + return true; + } + var frame = lastFrame; + while (frame) { + if (ts.hasProperty(frame.names, name)) { + return true; + } + frame = frame.previous; + } + return false; + } function initializeEmitterWithSourceMaps() { var sourceMapDir; var sourceMapSourceIndex = -1; @@ -18277,7 +18910,9 @@ var ts; node.kind === 199) { if (node.name) { var name = node.name; - scopeName = name.kind === 126 ? ts.getTextOfNode(name) : node.name.text; + scopeName = name.kind === 126 + ? ts.getTextOfNode(name) + : node.name.text; } recordScopeNameStart(scopeName); } @@ -18383,13 +19018,13 @@ var ts; function createTempVariable(location, forLoopVariable) { var name = forLoopVariable ? "_i" : undefined; while (true) { - if (name && resolver.isUnknownIdentifier(location, name)) { + if (name && !isExistingName(location, name)) { break; } name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + 97) : tempCount - 25); tempCount++; } - var result = ts.createNode(64); + var result = ts.createSynthesizedNode(64); result.text = name; return result; } @@ -18433,7 +19068,7 @@ var ts; emit(node); } } - function emitParenthesized(node, parenthesized) { + function emitParenthesizedIf(node, parenthesized) { if (parenthesized) { write("("); } @@ -18520,37 +19155,109 @@ var ts; emit(nodes[i]); } } - function isBinaryOrOctalIntegerLiteral(text) { - if (text.length <= 0) { - return false; - } - if (text.charCodeAt(1) === 66 || text.charCodeAt(1) === 98 || - text.charCodeAt(1) === 79 || text.charCodeAt(1) === 111) { - return true; + function isBinaryOrOctalIntegerLiteral(node, text) { + if (node.kind === 7 && text.length > 1) { + switch (text.charCodeAt(1)) { + case 98: + case 66: + case 111: + case 79: + return true; + } } 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 = getLiteralText(node); if (compilerOptions.sourceMap && (node.kind === 8 || ts.isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } - else if (languageVersion < 2 && node.kind === 7 && isBinaryOrOctalIntegerLiteral(text)) { + else if (languageVersion < 2 && isBinaryOrOctalIntegerLiteral(node, text)) { write(node.text); } else { write(text); } } - function getTemplateLiteralAsStringLiteral(node) { - return '"' + ts.escapeString(node.text) + '"'; + function getLiteralText(node) { + if (languageVersion < 2 && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { + return getQuotedEscapedLiteralText('"', node.text, '"'); + } + if (node.parent) { + return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + } + switch (node.kind) { + case 8: + return getQuotedEscapedLiteralText('"', node.text, '"'); + case 10: + return getQuotedEscapedLiteralText('`', node.text, '`'); + case 11: + return getQuotedEscapedLiteralText('`', node.text, '${'); + case 12: + return getQuotedEscapedLiteralText('}', node.text, '${'); + case 13: + return getQuotedEscapedLiteralText('}', node.text, '`'); + case 7: + return node.text; + } + ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for."); + } + function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) { + return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote; + } + function emitDownlevelRawTemplateLiteral(node) { + var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + var isLast = node.kind === 10 || node.kind === 13; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + text = text.replace(/\r\n?/g, "\n"); + text = ts.escapeString(text); + write('"' + text + '"'); + } + function emitDownlevelTaggedTemplateArray(node, literalEmitter) { + write("["); + if (node.template.kind === 10) { + literalEmitter(node.template); + } + else { + literalEmitter(node.template.head); + ts.forEach(node.template.templateSpans, function (child) { + write(", "); + literalEmitter(child.literal); + }); + } + write("]"); + } + function emitDownlevelTaggedTemplate(node) { + var tempVariable = createAndRecordTempVariable(node); + write("("); + emit(tempVariable); + write(" = "); + emitDownlevelTaggedTemplateArray(node, emit); + write(", "); + emit(tempVariable); + write(".raw = "); + emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); + write(", "); + emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); + write("("); + emit(tempVariable); + if (node.template.kind === 169) { + ts.forEach(node.template.templateSpans, function (templateSpan) { + write(", "); + var needsParens = templateSpan.expression.kind === 167 + && templateSpan.expression.operatorToken.kind === 23; + emitParenthesizedIf(templateSpan.expression, needsParens); + }); + } + write("))"); } function emitTemplateExpression(node) { if (languageVersion >= 2) { ts.forEachChild(node, emit); return; } - var emitOuterParens = ts.isExpression(node.parent) && templateNeedsParens(node, node.parent); + var emitOuterParens = ts.isExpression(node.parent) + && templateNeedsParens(node, node.parent); if (emitOuterParens) { write("("); } @@ -18561,11 +19268,12 @@ var ts; } for (var i = 0; i < node.templateSpans.length; i++) { var templateSpan = node.templateSpans[i]; - var needsParens = templateSpan.expression.kind !== 159 && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; + var needsParens = templateSpan.expression.kind !== 159 + && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; if (i > 0 || headEmitted) { write(" + "); } - emitParenthesized(templateSpan.expression, needsParens); + emitParenthesizedIf(templateSpan.expression, needsParens); if (templateSpan.literal.text.length !== 0) { write(" + "); emitLiteral(templateSpan.literal); @@ -18663,8 +19371,6 @@ var ts; return false; case 189: return node.parent.label === node; - case 216: - return node.parent.name === node; } } function emitExpressionIdentifier(node) { @@ -18676,7 +19382,18 @@ var ts; writeTextOfNode(currentSourceFile, node); } } + function getBlockScopedVariableId(node) { + return !ts.nodeIsSynthesized(node) && resolver.getBlockScopedVariableId(node); + } function emitIdentifier(node) { + var variableId = getBlockScopedVariableId(node); + if (variableId !== undefined && generatedBlockScopeNames) { + var text = generatedBlockScopeNames[variableId]; + if (text) { + write(text); + return; + } + } if (!node.parent) { write(node.text); } @@ -18739,7 +19456,7 @@ var ts; write("..."); emit(node.expression); } - function needsParenthesisForPropertyAccess(node) { + function needsParenthesisForPropertyAccessOrInvocation(node) { switch (node.kind) { case 64: case 151: @@ -18765,7 +19482,7 @@ var ts; var e = elements[pos]; if (e.kind === 171) { e = e.expression; - emitParenthesized(e, group === 0 && needsParenthesisForPropertyAccess(e)); + emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; } else { @@ -18804,24 +19521,18 @@ var ts; write("]"); } else { - emitListWithSpread(elements, (node.flags & 256) !== 0, elements.hasTrailingComma); + emitListWithSpread(elements, (node.flags & 512) !== 0, elements.hasTrailingComma); } } - function createSynthesizedNode(kind) { - var node = ts.createNode(kind); - node.pos = -1; - node.end = -1; - return node; - } function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) { var parenthesizedObjectLiteral = createDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex); return emit(parenthesizedObjectLiteral); } function createDownlevelObjectLiteralWithComputedProperties(originalObjectLiteral, firstComputedPropertyIndex) { var tempVar = createAndRecordTempVariable(originalObjectLiteral); - var initialObjectLiteral = createSynthesizedNode(152); + var initialObjectLiteral = ts.createSynthesizedNode(152); initialObjectLiteral.properties = originalObjectLiteral.properties.slice(0, firstComputedPropertyIndex); - initialObjectLiteral.flags |= 256; + initialObjectLiteral.flags |= 512; var propertyPatches = createBinaryExpression(tempVar, 52, initialObjectLiteral); ts.forEach(originalObjectLiteral.properties, function (property) { var patchedProperty = tryCreatePatchingPropertyAssignment(originalObjectLiteral, tempVar, property); @@ -18829,7 +19540,7 @@ var ts; propertyPatches = createBinaryExpression(propertyPatches, 23, patchedProperty); } }); - propertyPatches = createBinaryExpression(propertyPatches, 23, tempVar); + propertyPatches = createBinaryExpression(propertyPatches, 23, createIdentifier(tempVar.text, true)); var result = createParenthesizedExpression(propertyPatches); return result; } @@ -18840,7 +19551,7 @@ var ts; function tryCreatePatchingPropertyAssignment(objectLiteral, tempVar, property) { var leftHandSide = createMemberAccessForPropertyName(tempVar, property.name); var maybeRightHandSide = tryGetRightHandSideOfPatchingPropertyAssignment(objectLiteral, property); - return maybeRightHandSide && createBinaryExpression(leftHandSide, 52, maybeRightHandSide); + return maybeRightHandSide && createBinaryExpression(leftHandSide, 52, maybeRightHandSide, true); } function tryGetRightHandSideOfPatchingPropertyAssignment(objectLiteral, property) { switch (property.kind) { @@ -18856,7 +19567,7 @@ var ts; if (firstAccessor !== property) { return undefined; } - var propertyDescriptor = createSynthesizedNode(152); + var propertyDescriptor = ts.createSynthesizedNode(152); var descriptorProperties = []; if (getAccessor) { var getProperty = createPropertyAssignment(createIdentifier("get"), createFunctionExpression(getAccessor.parameters, getAccessor.body)); @@ -18866,7 +19577,7 @@ var ts; var setProperty = createPropertyAssignment(createIdentifier("set"), createFunctionExpression(setAccessor.parameters, setAccessor.body)); descriptorProperties.push(setProperty); } - var trueExpr = createSynthesizedNode(94); + var trueExpr = ts.createSynthesizedNode(94); var enumerableTrue = createPropertyAssignment(createIdentifier("enumerable"), trueExpr); descriptorProperties.push(enumerableTrue); var configurableTrue = createPropertyAssignment(createIdentifier("configurable"), trueExpr); @@ -18879,7 +19590,7 @@ var ts; } } function createParenthesizedExpression(expression) { - var result = createSynthesizedNode(159); + var result = ts.createSynthesizedNode(159); result.expression = expression; return result; } @@ -18893,9 +19604,9 @@ var ts; result.end = -1; return result; } - function createBinaryExpression(left, operator, right) { - var result = createSynthesizedNode(167); - result.operatorToken = createSynthesizedNode(operator); + function createBinaryExpression(left, operator, right, startsOnNewLine) { + var result = ts.createSynthesizedNode(167, startsOnNewLine); + result.operatorToken = ts.createSynthesizedNode(operator); result.left = left; result.right = right; return result; @@ -18915,36 +19626,37 @@ var ts; } } function createPropertyAssignment(name, initializer) { - var result = createSynthesizedNode(217); + var result = ts.createSynthesizedNode(217); result.name = name; result.initializer = initializer; return result; } function createFunctionExpression(parameters, body) { - var result = createSynthesizedNode(160); + var result = ts.createSynthesizedNode(160); result.parameters = parameters; result.body = body; return result; } function createPropertyAccessExpression(expression, name) { - var result = createSynthesizedNode(153); + var result = ts.createSynthesizedNode(153); result.expression = expression; + result.dotToken = ts.createSynthesizedNode(20); result.name = name; return result; } function createElementAccessExpression(expression, argumentExpression) { - var result = createSynthesizedNode(154); + var result = ts.createSynthesizedNode(154); result.expression = expression; result.argumentExpression = argumentExpression; return result; } - function createIdentifier(name) { - var result = createSynthesizedNode(64); + function createIdentifier(name, startsOnNewLine) { + var result = ts.createSynthesizedNode(64, startsOnNewLine); result.text = name; return result; } function createCallExpression(invokedExpression, arguments) { - var result = createSynthesizedNode(155); + var result = ts.createSynthesizedNode(155); result.expression = invokedExpression; result.arguments = arguments; return result; @@ -19009,13 +19721,29 @@ var ts; } return false; } + function indentIfOnDifferentLines(parent, node1, node2) { + var isSynthesized = ts.nodeIsSynthesized(parent); + var realNodesAreOnDifferentLines = !isSynthesized && !nodeEndIsOnSameLineAsNodeStart(node1, node2); + var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2); + if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) { + increaseIndent(); + writeLine(); + return true; + } + return false; + } function emitPropertyAccess(node) { if (tryEmitConstantValue(node)) { return; } emit(node.expression); + var indented = indentIfOnDifferentLines(node, node.expression, node.dotToken); write("."); + indented = indented || indentIfOnDifferentLines(node, node.dotToken, node.name); emit(node.name); + if (indented) { + decreaseIndent(); + } } function emitQualifiedName(node) { emit(node.left); @@ -19129,26 +19857,33 @@ var ts; } } function emitTaggedTemplateExpression(node) { - emit(node.tag); - write(" "); - emit(node.template); + if (compilerOptions.target >= 2) { + emit(node.tag); + write(" "); + emit(node.template); + } + else { + emitDownlevelTaggedTemplate(node); + } } function emitParenExpression(node) { - if (node.expression.kind === 158) { - var operand = node.expression.expression; - while (operand.kind == 158) { - operand = operand.expression; - } - if (operand.kind !== 165 && - operand.kind !== 164 && - operand.kind !== 163 && - operand.kind !== 162 && - operand.kind !== 166 && - operand.kind !== 156 && - !(operand.kind === 155 && node.parent.kind === 156) && - !(operand.kind === 160 && node.parent.kind === 155)) { - emit(operand); - return; + if (!node.parent || node.parent.kind !== 161) { + if (node.expression.kind === 158) { + var operand = node.expression.expression; + while (operand.kind == 158) { + operand = operand.expression; + } + if (operand.kind !== 165 && + operand.kind !== 164 && + operand.kind !== 163 && + operand.kind !== 162 && + operand.kind !== 166 && + operand.kind !== 156 && + !(operand.kind === 155 && node.parent.kind === 156) && + !(operand.kind === 160 && node.parent.kind === 155)) { + emit(operand); + return; + } } } write("("); @@ -19194,48 +19929,58 @@ var ts; } else { emit(node.left); - if (node.operatorToken.kind !== 23) { + var indented1 = indentIfOnDifferentLines(node, node.left, node.operatorToken); + if (!indented1 && node.operatorToken.kind !== 23) { write(" "); } write(ts.tokenToString(node.operatorToken.kind)); - var operatorEnd = ts.getLineAndCharacterOfPosition(currentSourceFile, node.operatorToken.end); - var rightStart = ts.getLineAndCharacterOfPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.right.pos)); - var onDifferentLine = operatorEnd.line !== rightStart.line; - if (onDifferentLine) { - var exprStart = ts.getLineAndCharacterOfPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); - var firstCharOfExpr = getFirstNonWhitespaceCharacterIndexOnLine(exprStart.line); - var shouldIndent = rightStart.character > firstCharOfExpr; - if (shouldIndent) { - increaseIndent(); - } - writeLine(); + if (!indented1) { + var indented2 = indentIfOnDifferentLines(node, node.operatorToken, node.right); } - else { + if (!indented2) { write(" "); } emit(node.right); - if (shouldIndent) { + if (indented1 || indented2) { decreaseIndent(); } } } - function getFirstNonWhitespaceCharacterIndexOnLine(line) { - var lineStart = ts.getLineStarts(currentSourceFile)[line]; - var text = currentSourceFile.text; - for (var i = lineStart; i < text.length; i++) { - var ch = text.charCodeAt(i); - if (!ts.isWhiteSpace(text.charCodeAt(i)) || ts.isLineBreak(ch)) { - break; - } - } - return i - lineStart; + function synthesizedNodeStartsOnNewLine(node) { + return ts.nodeIsSynthesized(node) && node.startsOnNewLine; } function emitConditionalExpression(node) { emit(node.condition); - write(" ? "); + var indent1 = indentIfOnDifferentLines(node, node.condition, node.questionToken); + if (!indent1) { + write(" "); + } + write("?"); + if (!indent1) { + var indent2 = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue); + } + if (!indent2) { + write(" "); + } emit(node.whenTrue); - write(" : "); + if (indent1 || indent2) { + decreaseIndent(); + } + var indent3 = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken); + if (!indent3) { + write(" "); + } + write(":"); + if (!indent3) { + var indent4 = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse); + } + if (!indent4) { + write(" "); + } emit(node.whenFalse); + if (indent3 || indent4) { + decreaseIndent(); + } } function isSingleLineEmptyBlock(node) { if (node && node.kind === 174) { @@ -19279,7 +20024,7 @@ var ts; } } function emitExpressionStatement(node) { - emitParenthesized(node.expression, node.expression.kind === 161); + emitParenthesizedIf(node.expression, node.expression.kind === 161); write(";"); } function emitIfStatement(node) { @@ -19320,6 +20065,30 @@ var ts; write(")"); emitEmbeddedStatement(node.statement); } + function emitStartOfVariableDeclarationList(decl, startPos) { + var tokenKind = 97; + if (decl && languageVersion >= 2) { + if (ts.isLet(decl)) { + tokenKind = 104; + } + else if (ts.isConst(decl)) { + tokenKind = 69; + } + } + if (startPos !== undefined) { + emitToken(tokenKind, startPos); + } + else { + switch (tokenKind) { + case 97: + return write("var "); + case 104: + return write("let "); + case 69: + return write("const "); + } + } + } function emitForStatement(node) { var endPos = emitToken(81, node.pos); write(" "); @@ -19327,17 +20096,9 @@ var ts; if (node.initializer && node.initializer.kind === 194) { var variableDeclarationList = node.initializer; var declarations = variableDeclarationList.declarations; - if (declarations[0] && ts.isLet(declarations[0])) { - emitToken(105, endPos); - } - else if (declarations[0] && ts.isConst(declarations[0])) { - emitToken(69, endPos); - } - else { - emitToken(97, endPos); - } + emitStartOfVariableDeclarationList(declarations[0], endPos); write(" "); - emitCommaList(variableDeclarationList.declarations); + emitCommaList(declarations); } else if (node.initializer) { emit(node.initializer); @@ -19357,12 +20118,7 @@ var ts; var variableDeclarationList = node.initializer; if (variableDeclarationList.declarations.length >= 1) { var decl = variableDeclarationList.declarations[0]; - if (ts.isLet(decl)) { - emitToken(105, endPos); - } - else { - emitToken(97, endPos); - } + emitStartOfVariableDeclarationList(decl, endPos); write(" "); emit(decl); } @@ -19461,8 +20217,8 @@ var ts; var endPos = emitToken(67, node.pos); write(" "); emitToken(16, endPos); - emit(node.name); - emitToken(17, node.name.end); + emit(node.variableDeclaration); + emitToken(17, node.variableDeclaration ? node.variableDeclaration.end : endPos); write(" "); emitBlock(node.block); } @@ -19494,8 +20250,15 @@ var ts; emitNode(node.name); emitEnd(node.name); } + function createVoidZero() { + var zero = ts.createSynthesizedNode(7); + zero.text = "0"; + var result = ts.createSynthesizedNode(164); + result.expression = zero; + return result; + } function emitExportMemberAssignments(name) { - if (exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { + if (!exportDefault && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { ts.forEach(exportSpecifiers[name.text], function (specifier) { writeLine(); emitStart(specifier.name); @@ -19522,6 +20285,7 @@ var ts; if (emitCount++) { write(", "); } + renameNonTopLevelLetAndConst(name); if (name.parent && (name.parent.kind === 193 || name.parent.kind === 150)) { emitModuleMemberName(name.parent); } @@ -19542,27 +20306,25 @@ var ts; } return expr; } - function createVoidZero() { - var zero = ts.createNode(7); - zero.text = "0"; - var result = ts.createNode(164); - result.expression = zero; - return result; - } function createDefaultValueCheck(value, defaultValue) { value = ensureIdentifier(value); - var equals = ts.createNode(167); + var equals = ts.createSynthesizedNode(167); equals.left = value; - equals.operatorToken = ts.createNode(30); + equals.operatorToken = ts.createSynthesizedNode(30); equals.right = createVoidZero(); - var cond = ts.createNode(168); - cond.condition = equals; - cond.whenTrue = defaultValue; - cond.whenFalse = value; + return createConditionalExpression(equals, defaultValue, value); + } + function createConditionalExpression(condition, whenTrue, whenFalse) { + var cond = ts.createSynthesizedNode(168); + cond.condition = condition; + cond.questionToken = ts.createSynthesizedNode(50); + cond.whenTrue = whenTrue; + cond.colonToken = ts.createSynthesizedNode(51); + cond.whenFalse = whenFalse; return cond; } function createNumericLiteral(value) { - var node = ts.createNode(7); + var node = ts.createSynthesizedNode(7); node.text = "" + value; return node; } @@ -19570,7 +20332,7 @@ var ts; if (expr.kind === 64 || expr.kind === 153 || expr.kind === 154) { return expr; } - var node = ts.createNode(159); + var node = ts.createSynthesizedNode(159); node.expression = expr; return node; } @@ -19578,13 +20340,10 @@ var ts; if (propName.kind !== 64) { return createElementAccess(object, propName); } - var node = ts.createNode(153); - node.expression = parenthesizeForAccess(object); - node.name = propName; - return node; + return createPropertyAccessExpression(parenthesizeForAccess(object), propName); } function createElementAccess(object, index) { - var node = ts.createNode(154); + var node = ts.createSynthesizedNode(154); node.expression = parenthesizeForAccess(object); node.argumentExpression = index; return node; @@ -19706,8 +20465,19 @@ var ts; } } else { + var isLet = renameNonTopLevelLetAndConst(node.name); emitModuleMemberName(node); - emitOptional(" = ", node.initializer); + var initializer = node.initializer; + if (!initializer && languageVersion < 2) { + var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 256) && + (getCombinedFlagsForIdentifier(node.name) & 4096); + if (isUninitializedLet && + node.parent.parent.kind !== 182 && + node.parent.parent.kind !== 183) { + initializer = createVoidZero(); + } + } + emitOptional(" = ", initializer); } } function emitExportVariableAssignments(node) { @@ -19719,17 +20489,64 @@ var ts; ts.forEach(name.elements, emitExportVariableAssignments); } } + function getEnclosingBlockScopeContainer(node) { + var current = node; + while (current) { + if (ts.isFunctionLike(current)) { + return current; + } + switch (current.kind) { + case 220: + case 91: + case 216: + case 200: + case 181: + case 182: + case 183: + return current; + case 174: + if (!ts.isFunctionLike(current.parent)) { + return current; + } + } + current = current.parent; + } + } + function getCombinedFlagsForIdentifier(node) { + if (!node.parent || (node.parent.kind !== 193 && node.parent.kind !== 150)) { + return 0; + } + return ts.getCombinedNodeFlags(node.parent); + } + function renameNonTopLevelLetAndConst(node) { + if (languageVersion >= 2 || + ts.nodeIsSynthesized(node) || + node.kind !== 64 || + (node.parent.kind !== 193 && node.parent.kind !== 150)) { + return; + } + var combinedFlags = getCombinedFlagsForIdentifier(node); + if (((combinedFlags & 12288) === 0) || combinedFlags & 1) { + return; + } + var list = ts.getAncestor(node, 194); + if (list.parent.kind === 175 && list.parent.parent.kind === 220) { + return; + } + var blockScopeContainer = getEnclosingBlockScopeContainer(node); + var parent = blockScopeContainer.kind === 220 + ? blockScopeContainer + : blockScopeContainer.parent; + var generatedName = generateUniqueNameForLocation(parent, node.text); + var variableId = resolver.getBlockScopedVariableId(node); + if (!generatedBlockScopeNames) { + generatedBlockScopeNames = []; + } + generatedBlockScopeNames[variableId] = generatedName; + } function emitVariableStatement(node) { if (!(node.flags & 1)) { - if (ts.isLet(node.declarationList)) { - write("let "); - } - else if (ts.isConst(node.declarationList)) { - write("const "); - } - else { - write("var "); - } + emitStartOfVariableDeclarationList(node.declarationList); } emitCommaList(node.declarationList.declarations); write(";"); @@ -19834,6 +20651,14 @@ var ts; function shouldEmitAsArrowFunction(node) { return node.kind === 161 && languageVersion >= 2; } + function emitDeclarationName(node) { + if (node.name) { + emitNode(node.name); + } + else { + write(resolver.getGeneratedNameForNode(node)); + } + } function emitFunctionDeclaration(node) { if (ts.nodeIsMissing(node.body)) { return emitPinnedOrTripleSlashComments(node); @@ -19845,10 +20670,10 @@ var ts; write("function "); } if (node.kind === 195 || (node.kind === 160 && node.name)) { - emit(node.name); + emitDeclarationName(node); } emitSignatureAndBody(node); - if (languageVersion < 2 && node.kind === 195 && node.parent === currentSourceFile) { + if (languageVersion < 2 && node.kind === 195 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } if (node.kind !== 132 && node.kind !== 131) { @@ -19888,6 +20713,7 @@ var ts; tempCount = 0; tempVariables = undefined; tempParameters = undefined; + var popFrame = enterNameScope(); if (shouldEmitAsArrowFunction(node)) { emitSignatureParametersForArrow(node); write(" =>"); @@ -19904,15 +20730,16 @@ var ts; else { emitExpressionFunctionBody(node, node.body); } - if (node.flags & 1) { + if (node.flags & 1 && !(node.flags & 256)) { writeLine(); emitStart(node); emitModuleMemberName(node); write(" = "); - emit(node.name); + emitDeclarationName(node); emitEnd(node); write(";"); } + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; @@ -19928,7 +20755,11 @@ var ts; return; } write(" "); - emit(body); + var current = body; + while (current.kind === 158) { + current = current.expression; + } + emitParenthesizedIf(body, current.kind === 152); } function emitDownLevelExpressionFunctionBody(node, body) { write(" {"); @@ -19967,45 +20798,15 @@ var ts; scopeEmitEnd(); } function emitBlockFunctionBody(node, body) { - if (body.statements.length === 0 && !anyParameterHasBindingPatternOrInitializer(node)) { - emitFunctionBodyWithNoStatements(node, body); - } - else { - emitFunctionBodyWithStatements(node, body); - } - } - function anyParameterHasBindingPatternOrInitializer(func) { - return ts.forEach(func.parameters, hasBindingPatternOrInitializer); - } - function hasBindingPatternOrInitializer(parameter) { - return parameter.initializer || ts.isBindingPattern(parameter.name); - } - function emitFunctionBodyWithNoStatements(node, body) { - var singleLine = isSingleLineEmptyBlock(node.body); - write(" {"); - if (singleLine) { - write(" "); - } - else { - increaseIndent(); - writeLine(); - } - emitLeadingCommentsOfPosition(body.statements.end); - if (!singleLine) { - decreaseIndent(); - } - emitToken(15, body.statements.end); - } - function emitFunctionBodyWithStatements(node, body) { write(" {"); scopeEmitStart(node); - var outPos = writer.getTextPos(); + var initialTextPos = writer.getTextPos(); increaseIndent(); emitDetachedComments(body.statements); var startIndex = emitDirectivePrologues(body.statements, true); emitFunctionBodyPreamble(node); decreaseIndent(); - var preambleEmitted = writer.getTextPos() !== outPos; + var preambleEmitted = writer.getTextPos() !== initialTextPos; if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) { for (var i = 0, n = body.statements.length; i < n; i++) { write(" "); @@ -20078,7 +20879,7 @@ var ts; emitStart(member); emitStart(member.name); if (staticFlag) { - emitNode(node.name); + emitDeclarationName(node); } else { write("this"); @@ -20103,7 +20904,7 @@ var ts; emitLeadingComments(member); emitStart(member); emitStart(member.name); - emitNode(node.name); + emitDeclarationName(node); if (!(member.flags & 128)) { write(".prototype"); } @@ -20124,7 +20925,7 @@ var ts; emitStart(member); write("Object.defineProperty("); emitStart(member.name); - emitNode(node.name); + emitDeclarationName(node); if (!(member.flags & 128)) { write(".prototype"); } @@ -20169,7 +20970,7 @@ var ts; } function emitClassDeclaration(node) { write("var "); - emit(node.name); + emitDeclarationName(node); write(" = (function ("); var baseTypeNode = ts.getClassBaseTypeNode(node); if (baseTypeNode) { @@ -20182,7 +20983,7 @@ var ts; writeLine(); emitStart(baseTypeNode); write("__extends("); - emit(node.name); + emitDeclarationName(node); write(", _super);"); emitEnd(baseTypeNode); } @@ -20191,11 +20992,10 @@ var ts; emitMemberFunctions(node); emitMemberAssignments(node, 128); writeLine(); - function emitClassReturnStatement() { + emitToken(15, node.members.end, function () { write("return "); - emitNode(node.name); - } - emitToken(15, node.members.end, emitClassReturnStatement); + emitDeclarationName(node); + }); write(";"); decreaseIndent(); writeLine(); @@ -20208,16 +21008,16 @@ var ts; } write(");"); emitEnd(node); - if (node.flags & 1) { + if (node.flags & 1 && !(node.flags & 256)) { writeLine(); emitStart(node); emitModuleMemberName(node); write(" = "); - emit(node.name); + emitDeclarationName(node); emitEnd(node); write(";"); } - if (languageVersion < 2 && node.parent === currentSourceFile) { + if (languageVersion < 2 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } function emitConstructorOfClass() { @@ -20227,6 +21027,7 @@ var ts; tempCount = 0; tempVariables = undefined; tempParameters = undefined; + var popFrame = enterNameScope(); ts.forEach(node.members, function (member) { if (member.kind === 133 && !member.body) { emitPinnedOrTripleSlashComments(member); @@ -20238,7 +21039,7 @@ var ts; } emitStart(ctor || node); write("function "); - emit(node.name); + emitDeclarationName(node); emitSignatureParameters(ctor); write(" {"); scopeEmitStart(node, "constructor"); @@ -20286,6 +21087,7 @@ var ts; if (ctor) { emitTrailingComments(ctor); } + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; @@ -20404,7 +21206,9 @@ var ts; var saveTempVariables = tempVariables; tempCount = 0; tempVariables = undefined; + var popFrame = enterNameScope(); emit(node.body); + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; } @@ -20493,7 +21297,7 @@ var ts; emitImportDeclaration(node); return; } - if (resolver.isReferencedImportDeclaration(node) || + if (resolver.isReferencedAliasDeclaration(node) || (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { emitLeadingComments(node); emitStart(node); @@ -20589,17 +21393,29 @@ var ts; function createExternalModuleInfo(sourceFile) { externalImports = []; exportSpecifiers = {}; + exportDefault = undefined; ts.forEach(sourceFile.statements, function (node) { if (node.kind === 209 && !node.moduleSpecifier) { ts.forEach(node.exportClause.elements, function (specifier) { + if (specifier.name.text === "default") { + exportDefault = exportDefault || specifier; + } var name = (specifier.propertyName || specifier.name).text; (exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier); }); } + else if (node.kind === 208) { + exportDefault = exportDefault || node; + } + else if (node.kind === 195 || node.kind === 196) { + if (node.flags & 1 && node.flags & 256) { + exportDefault = exportDefault || node; + } + } else { var info = createExternalImportInfo(node); if (info) { - if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedImportDeclaration(node)) { + if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedAliasDeclaration(node)) { externalImports.push(info); } } @@ -20680,18 +21496,7 @@ var ts; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(true); - var exportName = resolver.getExportAssignmentName(node); - if (exportName) { - writeLine(); - var exportAssignment = getFirstExportAssignment(node); - emitStart(exportAssignment); - write("return "); - emitStart(exportAssignment.exportName); - write(exportName); - emitEnd(exportAssignment.exportName); - write(";"); - emitEnd(exportAssignment); - } + emitExportDefault(node, true); decreaseIndent(); writeLine(); write("});"); @@ -20700,17 +21505,24 @@ var ts; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(true); - var exportName = resolver.getExportAssignmentName(node); - if (exportName) { + emitExportDefault(node, false); + } + function emitExportDefault(sourceFile, emitAsReturn) { + if (exportDefault && resolver.hasExportDefaultValue(sourceFile)) { writeLine(); - var exportAssignment = getFirstExportAssignment(node); - emitStart(exportAssignment); - write("module.exports = "); - emitStart(exportAssignment.exportName); - write(exportName); - emitEnd(exportAssignment.exportName); + emitStart(exportDefault); + write(emitAsReturn ? "return " : "module.exports = "); + if (exportDefault.kind === 208) { + emit(exportDefault.expression); + } + else if (exportDefault.kind === 211) { + emit(exportDefault.propertyName); + } + else { + emitDeclarationName(exportDefault); + } write(";"); - emitEnd(exportAssignment); + emitEnd(exportDefault); } } function emitDirectivePrologues(statements, startWithNewLine) { @@ -20761,6 +21573,7 @@ var ts; else { externalImports = undefined; exportSpecifiers = undefined; + exportDefault = undefined; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(true); @@ -21080,6 +21893,7 @@ var ts; var ts; (function (ts) { ts.emitTime = 0; + ts.ioReadTime = 0; function createCompilerHost(options) { var currentDirectory; var existingDirectories = {}; @@ -21089,11 +21903,15 @@ var ts; var unsupportedFileEncodingErrorCode = -2147024809; function getSourceFile(fileName, languageVersion, onError) { try { + var start = new Date().getTime(); var text = ts.sys.readFile(fileName, options.charset); + ts.ioReadTime += new Date().getTime() - start; } catch (e) { if (onError) { - onError(e.number === unsupportedFileEncodingErrorCode ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText : e.message); + onError(e.number === unsupportedFileEncodingErrorCode + ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText + : e.message); } text = ""; } @@ -21226,8 +22044,9 @@ var ts; if (options.noEmitOnError && getPreEmitDiagnostics(this).length > 0) { return { diagnostics: [], sourceMaps: undefined, emitSkipped: true }; } + var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); var start = new Date().getTime(); - var emitResult = ts.emitFiles(getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile), getEmitHost(writeFileCallback), sourceFile); + var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile); ts.emitTime += new Date().getTime() - start; return emitResult; } @@ -21416,20 +22235,19 @@ var ts; } return; } - var firstExternalModule = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); - if (firstExternalModule && !options.module) { - var externalModuleErrorSpan = ts.getErrorSpanForNode(firstExternalModule.externalModuleIndicator); - var errorStart = ts.skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos); - var errorLength = externalModuleErrorSpan.end - errorStart; - diagnostics.add(ts.createFileDiagnostic(firstExternalModule, errorStart, errorLength, ts.Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); + if (firstExternalModuleSourceFile && !options.module) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + diagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); } if (options.outDir || options.sourceRoot || (options.mapRoot && - (!options.out || firstExternalModule !== undefined))) { + (!options.out || firstExternalModuleSourceFile !== undefined))) { var commonPathComponents; ts.forEach(files, function (sourceFile) { - if (!(sourceFile.flags & 1024) && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { + if (!(sourceFile.flags & 2048) + && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, host.getCurrentDirectory()); sourcePathComponents.pop(); if (commonPathComponents) { @@ -21474,7 +22292,7 @@ var ts; var BreakpointResolver; (function (BreakpointResolver) { function spanInSourceFileAtLocation(sourceFile, position) { - if (sourceFile.flags & 1024) { + if (sourceFile.flags & 2048) { return undefined; } var tokenAtLocation = ts.getTokenAtPosition(sourceFile, position); @@ -21578,9 +22396,13 @@ var ts; case 190: return textSpan(node, node.expression); case 208: - return textSpan(node, node.exportName); + return textSpan(node, node.expression); case 202: return textSpan(node, node.moduleReference); + case 203: + return textSpan(node, node.moduleSpecifier); + case 209: + return textSpan(node, node.moduleSpecifier); case 200: if (ts.getModuleInstanceState(node) !== 1) { return undefined; @@ -21627,7 +22449,7 @@ var ts; if (node.parent.kind === 158 && node.parent.type === node) { return spanInNode(node.parent.expression); } - if (ts.isAnyFunction(node.parent) && node.parent.type === node) { + if (ts.isFunctionLike(node.parent) && node.parent.type === node) { return spanInPreviousNode(node); } return spanInNode(node.parent); @@ -21640,7 +22462,11 @@ var ts; } 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; + 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) { if (isParentVariableStatement) { @@ -21800,7 +22626,7 @@ var ts; return spanInNode(node.parent); } function spanInColonToken(node) { - if (ts.isAnyFunction(node.parent) || node.parent.kind === 217) { + if (ts.isFunctionLike(node.parent) || node.parent.kind === 217) { return spanInPreviousNode(node); } return spanInNode(node.parent); @@ -22111,6 +22937,27 @@ var ts; case 149: ts.forEach(node.elements, visit); break; + case 209: + if (node.exportClause) { + ts.forEach(node.exportClause.elements, visit); + } + break; + case 203: + var importClause = node.importClause; + if (importClause) { + if (importClause.name) { + childNodes.push(importClause); + } + if (importClause.namedBindings) { + if (importClause.namedBindings.kind === 205) { + childNodes.push(importClause.namedBindings); + } + else { + ts.forEach(importClause.namedBindings.elements, visit); + } + } + } + break; case 150: case 193: if (ts.isBindingPattern(node.name)) { @@ -22122,7 +22969,11 @@ var ts; case 197: case 200: case 195: + case 202: + case 207: + case 211: childNodes.push(node); + break; } } ts.forEach(nodes, visit); @@ -22235,7 +23086,7 @@ var ts; if (ts.isBindingPattern(node.name)) { break; } - if ((node.flags & 243) === 0) { + if ((node.flags & 499) === 0) { return undefined; } return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); @@ -22287,6 +23138,12 @@ var ts; } case 133: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); + case 211: + case 207: + case 202: + case 204: + case 205: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.alias); } return undefined; function createItem(node, name, scriptElementKind) { @@ -22359,10 +23216,15 @@ var ts; return undefined; } hasGlobalNode = true; - var rootName = ts.isExternalModule(node) ? "\"" + ts.escapeString(ts.getBaseFileName(ts.removeFileExtension(ts.normalizePath(node.fileName)))) + "\"" : ""; + var rootName = ts.isExternalModule(node) + ? "\"" + ts.escapeString(ts.getBaseFileName(ts.removeFileExtension(ts.normalizePath(node.fileName)))) + "\"" + : ""; return getNavigationBarItem(rootName, ts.ScriptElementKind.moduleElement, ts.ScriptElementKindModifier.none, [getNodeSpan(node)], childItems); } function createClassItem(node) { + if (!node.name) { + return undefined; + } var childItems; if (node.members) { var constructor = ts.forEach(node.members, function (member) { @@ -22398,7 +23260,9 @@ var ts; return node; } function getNodeSpan(node) { - return node.kind === 220 ? ts.createTextSpanFromBounds(node.getFullStart(), node.getEnd()) : ts.createTextSpanFromBounds(node.getStart(), node.getEnd()); + return node.kind === 220 + ? ts.createTextSpanFromBounds(node.getFullStart(), node.getEnd()) + : ts.createTextSpanFromBounds(node.getStart(), node.getEnd()); } function getTextOfNode(node) { return ts.getTextOfNodeFromSourceText(sourceFile.text, node); @@ -22852,7 +23716,9 @@ var ts; function transitionFromLowerToUpper(identifier, word, index) { var lastIsUpper = isUpperCaseLetter(identifier.charCodeAt(index - 1)); var currentIsUpper = isUpperCaseLetter(identifier.charCodeAt(index)); - var transition = word ? (currentIsUpper && !lastIsUpper) : currentIsUpper; + var transition = word + ? (currentIsUpper && !lastIsUpper) + : currentIsUpper; return transition; } })(ts || (ts = {})); @@ -22900,12 +23766,14 @@ var ts; var list = listItemInfo.list; var isTypeArgList = callExpression.typeArguments && callExpression.typeArguments.pos === list.pos; var argumentIndex = (listItemInfo.listItemIndex + 1) >> 1; + var argumentCount = getCommaBasedArgCount(list); + ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex); return { kind: isTypeArgList ? 0 : 1, invocation: callExpression, argumentsSpan: getApplicableSpanForArguments(list), argumentIndex: argumentIndex, - argumentCount: getCommaBasedArgCount(list) + argumentCount: argumentCount }; } } @@ -22936,7 +23804,9 @@ var ts; return undefined; } function getCommaBasedArgCount(argumentsList) { - return argumentsList.getChildCount() === 0 ? 0 : 1 + ts.countWhere(argumentsList.getChildren(), function (arg) { return arg.kind === 23; }); + return argumentsList.getChildCount() === 0 + ? 0 + : 1 + ts.countWhere(argumentsList.getChildren(), function (arg) { return arg.kind === 23; }); } function getArgumentIndexForTemplatePiece(spanIndex, node) { ts.Debug.assert(position >= node.getStart(), "Assumed 'position' could not occur before node."); @@ -22949,7 +23819,10 @@ var ts; return spanIndex + 1; } function getArgumentListInfoForTemplate(tagExpression, argumentIndex) { - var argumentCount = tagExpression.template.kind === 10 ? 1 : tagExpression.template.templateSpans.length + 1; + var argumentCount = tagExpression.template.kind === 10 + ? 1 + : tagExpression.template.templateSpans.length + 1; + ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex); return { kind: 2, invocation: tagExpression, @@ -23064,6 +23937,7 @@ var ts; if (selectedItemIndex < 0) { selectedItemIndex = selectBestInvalidOverloadIndex(candidates, argumentCount); } + ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex); return { items: items, applicableSpan: applicableSpan, @@ -23233,7 +24107,7 @@ var ts; for (var i = 0, len = children.length; i < len; ++i) { var child = children[i]; var shouldDiveInChildNode = (child.pos <= previousToken.pos && child.end > previousToken.end) || - (child.pos === previousToken.end); + (child.pos === previousToken.end); if (shouldDiveInChildNode && nodeHasTokens(child)) { return find(child); } @@ -23311,7 +24185,7 @@ var ts; if (node.kind === 139 || node.kind === 155) { return node.typeArguments; } - if (ts.isAnyFunction(node) || node.kind === 196 || node.kind === 197) { + if (ts.isFunctionLike(node) || node.kind === 196 || node.kind === 197) { return node.typeParameters; } return undefined; @@ -23336,7 +24210,8 @@ var ts; } ts.isPunctuation = isPunctuation; function isInsideTemplateLiteral(node, position) { - return ts.isTemplateLiteralKind(node.kind) && (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd()); + return ts.isTemplateLiteralKind(node.kind) + && (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd()); } ts.isInsideTemplateLiteral = isInsideTemplateLiteral; function compareDataObjects(dst, src) { @@ -23610,7 +24485,13 @@ var ts; token: undefined }; } - var expectedScanAction = shouldRescanGreaterThanToken(n) ? 1 : shouldRescanSlashToken(n) ? 2 : shouldRescanTemplateToken(n) ? 3 : 0; + var expectedScanAction = shouldRescanGreaterThanToken(n) + ? 1 + : shouldRescanSlashToken(n) + ? 2 + : shouldRescanTemplateToken(n) + ? 3 + : 0; if (lastTokenInfo && expectedScanAction === lastScanAction) { return fixTokenKind(lastTokenInfo, n); } @@ -23923,7 +24804,7 @@ var ts; this.SpaceAfterSubtractWhenFollowedByPredecrement = new formatting.Rule(formatting.RuleDescriptor.create1(34, 39), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.NoSpaceBeforeComma = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 23), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceAfterCertainKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([97, 93, 87, 73, 89, 96]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([105, 69]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2)); + this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([104, 69]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8)); this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(82, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionDeclContext), 8)); @@ -23931,13 +24812,13 @@ var ts; this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(89, 22), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceBetweenStatements = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([17, 74, 75, 66]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotForContext), 2)); this.SpaceAfterTryFinally = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([95, 80]), 14), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([116, 120]), 64), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); + this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([115, 119]), 64), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); this.SpaceBeforeBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.BinaryKeywordOperators), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); - this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(114, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([117, 118]), 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([68, 115, 76, 77, 78, 116, 103, 84, 104, 117, 107, 109, 120, 110]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([78, 103])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(113, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([116, 117]), 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([68, 114, 76, 77, 78, 115, 102, 84, 103, 116, 106, 108, 119, 109]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([78, 102])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(8, 14), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2)); this.SpaceAfterArrow = new formatting.Rule(formatting.RuleDescriptor.create3(32, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.NoSpaceAfterEllipsis = new formatting.Rule(formatting.RuleDescriptor.create1(21, 64), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); @@ -23949,52 +24830,52 @@ var ts; this.NoSpaceAfterCloseAngularBracket = new formatting.Rule(formatting.RuleDescriptor.create3(25, formatting.Shared.TokenRange.FromTokens([16, 18, 25, 23])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsTypeArgumentOrParameterContext), 8)); this.NoSpaceBetweenEmptyInterfaceBraceBrackets = new formatting.Rule(formatting.RuleDescriptor.create1(14, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsObjectTypeContext), 8)); this.HighPriorityCommonRules = - [ - this.IgnoreBeforeComment, this.IgnoreAfterLineComment, - this.NoSpaceBeforeColon, this.SpaceAfterColon, this.NoSpaceBeforeQuestionMark, this.SpaceAfterQuestionMarkInConditionalOperator, - this.NoSpaceAfterQuestionMark, - this.NoSpaceBeforeDot, this.NoSpaceAfterDot, - this.NoSpaceAfterUnaryPrefixOperator, - this.NoSpaceAfterUnaryPreincrementOperator, this.NoSpaceAfterUnaryPredecrementOperator, - this.NoSpaceBeforeUnaryPostincrementOperator, this.NoSpaceBeforeUnaryPostdecrementOperator, - this.SpaceAfterPostincrementWhenFollowedByAdd, - this.SpaceAfterAddWhenFollowedByUnaryPlus, this.SpaceAfterAddWhenFollowedByPreincrement, - this.SpaceAfterPostdecrementWhenFollowedBySubtract, - this.SpaceAfterSubtractWhenFollowedByUnaryMinus, this.SpaceAfterSubtractWhenFollowedByPredecrement, - this.NoSpaceAfterCloseBrace, - this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext, - this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets, - this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember, - this.NoSpaceBetweenReturnAndSemicolon, - this.SpaceAfterCertainKeywords, - this.SpaceAfterLetConstInVariableDeclaration, - this.NoSpaceBeforeOpenParenInFuncCall, - this.SpaceBeforeBinaryKeywordOperator, this.SpaceAfterBinaryKeywordOperator, - this.SpaceAfterVoidOperator, - this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, - this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, - this.SpaceAfterModuleName, - this.SpaceAfterArrow, - this.NoSpaceAfterEllipsis, - this.NoSpaceAfterOptionalParameters, - this.NoSpaceBetweenEmptyInterfaceBraceBrackets, - this.NoSpaceBeforeOpenAngularBracket, - this.NoSpaceBetweenCloseParenAndAngularBracket, - this.NoSpaceAfterOpenAngularBracket, - this.NoSpaceBeforeCloseAngularBracket, - this.NoSpaceAfterCloseAngularBracket - ]; + [ + this.IgnoreBeforeComment, this.IgnoreAfterLineComment, + this.NoSpaceBeforeColon, this.SpaceAfterColon, this.NoSpaceBeforeQuestionMark, this.SpaceAfterQuestionMarkInConditionalOperator, + this.NoSpaceAfterQuestionMark, + this.NoSpaceBeforeDot, this.NoSpaceAfterDot, + this.NoSpaceAfterUnaryPrefixOperator, + this.NoSpaceAfterUnaryPreincrementOperator, this.NoSpaceAfterUnaryPredecrementOperator, + this.NoSpaceBeforeUnaryPostincrementOperator, this.NoSpaceBeforeUnaryPostdecrementOperator, + this.SpaceAfterPostincrementWhenFollowedByAdd, + this.SpaceAfterAddWhenFollowedByUnaryPlus, this.SpaceAfterAddWhenFollowedByPreincrement, + this.SpaceAfterPostdecrementWhenFollowedBySubtract, + this.SpaceAfterSubtractWhenFollowedByUnaryMinus, this.SpaceAfterSubtractWhenFollowedByPredecrement, + this.NoSpaceAfterCloseBrace, + this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext, + this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets, + this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember, + this.NoSpaceBetweenReturnAndSemicolon, + this.SpaceAfterCertainKeywords, + this.SpaceAfterLetConstInVariableDeclaration, + this.NoSpaceBeforeOpenParenInFuncCall, + this.SpaceBeforeBinaryKeywordOperator, this.SpaceAfterBinaryKeywordOperator, + this.SpaceAfterVoidOperator, + this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, + this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, + this.SpaceAfterModuleName, + this.SpaceAfterArrow, + this.NoSpaceAfterEllipsis, + this.NoSpaceAfterOptionalParameters, + this.NoSpaceBetweenEmptyInterfaceBraceBrackets, + this.NoSpaceBeforeOpenAngularBracket, + this.NoSpaceBetweenCloseParenAndAngularBracket, + this.NoSpaceAfterOpenAngularBracket, + this.NoSpaceBeforeCloseAngularBracket, + this.NoSpaceAfterCloseAngularBracket + ]; this.LowPriorityCommonRules = - [ - this.NoSpaceBeforeSemicolon, - this.SpaceBeforeOpenBraceInControl, this.SpaceBeforeOpenBraceInFunction, this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock, - this.NoSpaceBeforeComma, - this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterOpenBracket, - this.NoSpaceBeforeCloseBracket, this.NoSpaceAfterCloseBracket, - this.SpaceAfterSemicolon, - this.NoSpaceBeforeOpenParenInFuncDecl, - this.SpaceBetweenStatements, this.SpaceAfterTryFinally - ]; + [ + this.NoSpaceBeforeSemicolon, + this.SpaceBeforeOpenBraceInControl, this.SpaceBeforeOpenBraceInFunction, this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock, + this.NoSpaceBeforeComma, + this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterOpenBracket, + this.NoSpaceBeforeCloseBracket, this.NoSpaceAfterCloseBracket, + this.SpaceAfterSemicolon, + this.NoSpaceBeforeOpenParenInFuncDecl, + this.SpaceBetweenStatements, this.SpaceAfterTryFinally + ]; this.SpaceAfterComma = new formatting.Rule(formatting.RuleDescriptor.create3(23, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.NoSpaceAfterComma = new formatting.Rule(formatting.RuleDescriptor.create3(23, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceBeforeBinaryOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.BinaryOperators), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); @@ -24322,13 +25203,19 @@ var ts; RulesBucket.prototype.AddRule = function (rule, specificTokens, constructionState, rulesBucketIndex) { var position; if (rule.Operation.Action == 1) { - position = specificTokens ? 0 : RulesPosition.IgnoreRulesAny; + position = specificTokens ? + 0 : + RulesPosition.IgnoreRulesAny; } else if (!rule.Operation.Context.IsAny()) { - position = specificTokens ? RulesPosition.ContextRulesSpecific : RulesPosition.ContextRulesAny; + position = specificTokens ? + RulesPosition.ContextRulesSpecific : + RulesPosition.ContextRulesAny; } else { - position = specificTokens ? RulesPosition.NoContextRulesSpecific : RulesPosition.NoContextRulesAny; + position = specificTokens ? + RulesPosition.NoContextRulesSpecific : + RulesPosition.NoContextRulesAny; } var state = constructionState[rulesBucketIndex]; if (state === undefined) { @@ -24450,7 +25337,7 @@ var ts; TokenRange.UnaryPredecrementExpressions = TokenRange.FromTokens([64, 16, 92, 87]); TokenRange.UnaryPostdecrementExpressions = TokenRange.FromTokens([64, 17, 19, 87]); TokenRange.Comments = TokenRange.FromTokens([2, 3]); - TokenRange.TypeNames = TokenRange.FromTokens([64, 119, 121, 113, 122, 98, 112]); + TokenRange.TypeNames = TokenRange.FromTokens([64, 118, 120, 112, 121, 98, 111]); return TokenRange; })(); Shared.TokenRange = TokenRange; @@ -24643,7 +25530,9 @@ var ts; if (!errors.length) { return rangeHasNoErrors; } - var sorted = errors.filter(function (d) { return ts.rangeOverlapsWithStartEnd(originalRange, d.start, d.start + d.length); }).sort(function (e1, e2) { return e1.start - e2.start; }); + var sorted = errors + .filter(function (d) { return ts.rangeOverlapsWithStartEnd(originalRange, d.start, d.start + d.length); }) + .sort(function (e1, e2) { return e1.start - e2.start; }); if (!sorted.length) { return rangeHasNoErrors; } @@ -25013,8 +25902,8 @@ var ts; } } trimTrailingWhitespaces = - (rule.Operation.Action & (4 | 2)) && - rule.Flag !== 1; + (rule.Operation.Action & (4 | 2)) && + rule.Flag !== 1; } else { trimTrailingWhitespaces = true; @@ -25069,7 +25958,9 @@ var ts; var delta = indentation - nonWhitespaceColumnInFirstPart.column; for (var i = startIndex, len = parts.length; i < len; ++i, ++startLine) { var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile); - var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart : formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options); + var nonWhitespaceCharacterAndColumn = i === 0 + ? nonWhitespaceColumnInFirstPart + : formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options); var newIndentation = nonWhitespaceCharacterAndColumn.column + delta; if (newIndentation > 0) { var indentationString = getIndentationString(newIndentation, options); @@ -25249,11 +26140,11 @@ var ts; return 0; } var precedingTokenIsLiteral = precedingToken.kind === 8 || - precedingToken.kind === 9 || - precedingToken.kind === 10 || - precedingToken.kind === 11 || - precedingToken.kind === 12 || - precedingToken.kind === 13; + precedingToken.kind === 9 || + precedingToken.kind === 10 || + precedingToken.kind === 11 || + precedingToken.kind === 12 || + precedingToken.kind === 13; if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { return 0; } @@ -25314,7 +26205,7 @@ var ts; } parentStart = getParentStart(parent, current, sourceFile); var parentAndChildShareLine = parentStart.line === currentStart.line || - childStartsOnTheSameLineWithElseInIfStatement(parent, current, currentStart.line, sourceFile); + childStartsOnTheSameLineWithElseInIfStatement(parent, current, currentStart.line, sourceFile); if (useActualIndentation) { var actualIndentation = getActualIndentationForNode(current, parent, currentStart, parentAndChildShareLine, sourceFile, options); if (actualIndentation !== -1) { @@ -25339,12 +26230,16 @@ var ts; } function getActualIndentationForListItemBeforeComma(commaToken, sourceFile, options) { var commaItemInfo = ts.findListItemInfo(commaToken); - ts.Debug.assert(commaItemInfo && commaItemInfo.listItemIndex > 0); - return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options); + if (commaItemInfo && commaItemInfo.listItemIndex > 0) { + return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options); + } + else { + return -1; + } } function getActualIndentationForNode(current, parent, currentLineAndChar, parentAndChildShareLine, sourceFile, options) { var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && - (parent.kind === 220 || !parentAndChildShareLine); + (parent.kind === 220 || !parentAndChildShareLine); if (!useActualIndentation) { return -1; } @@ -25671,13 +26566,13 @@ var ts; while (pos < end) { var token = scanner.scan(); var textPos = scanner.getTextPos(); - nodes.push(createNode(token, pos, textPos, 512, this)); + nodes.push(createNode(token, pos, textPos, 1024, this)); pos = textPos; } return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(221, nodes.pos, nodes.end, 512, this); + var list = createNode(221, nodes.pos, nodes.end, 1024, this); list._children = []; var pos = nodes.pos; for (var i = 0, len = nodes.length; i < len; i++) { @@ -26099,7 +26994,9 @@ var ts; case 131: var functionDeclaration = node; if (functionDeclaration.name && functionDeclaration.name.getFullWidth() > 0) { - var lastDeclaration = namedDeclarations.length > 0 ? namedDeclarations[namedDeclarations.length - 1] : undefined; + var lastDeclaration = namedDeclarations.length > 0 ? + namedDeclarations[namedDeclarations.length - 1] : + undefined; if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) { if (functionDeclaration.body && !lastDeclaration.body) { namedDeclarations[namedDeclarations.length - 1] = functionDeclaration; @@ -26117,6 +27014,11 @@ var ts; case 199: case 200: case 202: + case 211: + case 207: + case 202: + case 204: + case 205: case 134: case 135: case 143: @@ -26151,6 +27053,27 @@ var ts; case 129: namedDeclarations.push(node); break; + case 209: + if (node.exportClause) { + ts.forEach(node.exportClause.elements, visit); + } + break; + case 203: + var importClause = node.importClause; + if (importClause) { + if (importClause.name) { + namedDeclarations.push(importClause); + } + if (importClause.namedBindings) { + if (importClause.namedBindings.kind === 205) { + namedDeclarations.push(importClause.namedBindings); + } + else { + ts.forEach(importClause.namedBindings.elements, visit); + } + } + } + break; } }); this.namedDeclarations = namedDeclarations; @@ -26455,7 +27378,7 @@ var ts; var entry = entries[i]; sourceFiles.push({ name: i, - refCount: entry.refCount, + refCount: entry.languageServiceRefCount, references: entry.owners.slice(0) }); } @@ -26468,34 +27391,40 @@ var ts; return JSON.stringify(bucketInfoArray, null, 2); } function acquireDocument(fileName, compilationSettings, scriptSnapshot, version) { + return acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, true); + } + function updateDocument(fileName, compilationSettings, scriptSnapshot, version) { + return acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, false); + } + function acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, acquiring) { var bucket = getBucketForCompilationSettings(compilationSettings, true); var entry = ts.lookUp(bucket, fileName); if (!entry) { + ts.Debug.assert(acquiring, "How could we be trying to update a document that the registry doesn't have?"); var sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, compilationSettings.target, version, false); bucket[fileName] = entry = { sourceFile: sourceFile, - refCount: 0, + languageServiceRefCount: 0, owners: [] }; } - entry.refCount++; - return entry.sourceFile; - } - function updateDocument(sourceFile, fileName, compilationSettings, scriptSnapshot, version, textChangeRange) { - var bucket = getBucketForCompilationSettings(compilationSettings, false); - ts.Debug.assert(bucket !== undefined); - var entry = ts.lookUp(bucket, fileName); - ts.Debug.assert(entry !== undefined); - entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, textChangeRange); + else { + if (entry.sourceFile.version !== version) { + entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot)); + } + } + if (acquiring) { + entry.languageServiceRefCount++; + } return entry.sourceFile; } function releaseDocument(fileName, compilationSettings) { var bucket = getBucketForCompilationSettings(compilationSettings, false); ts.Debug.assert(bucket !== undefined); var entry = ts.lookUp(bucket, fileName); - entry.refCount--; - ts.Debug.assert(entry.refCount >= 0); - if (entry.refCount === 0) { + entry.languageServiceRefCount--; + ts.Debug.assert(entry.languageServiceRefCount >= 0); + if (entry.languageServiceRefCount === 0) { delete bucket[fileName]; } } @@ -26526,31 +27455,111 @@ var ts; } }); } + function recordModuleName() { + var importPath = scanner.getTokenValue(); + var pos = scanner.getTokenPos(); + importedFiles.push({ + fileName: importPath, + pos: pos, + end: pos + importPath.length + }); + } function processImport() { scanner.setText(sourceText); var token = scanner.scan(); while (token !== 1) { if (token === 84) { token = scanner.scan(); - if (token === 64) { - token = scanner.scan(); - if (token === 52) { + if (token === 8) { + recordModuleName(); + continue; + } + else { + if (token === 64) { token = scanner.scan(); - if (token === 118) { + if (token === 123) { token = scanner.scan(); - if (token === 16) { + if (token === 8) { + recordModuleName(); + continue; + } + } + else if (token === 52) { + token = scanner.scan(); + if (token === 117) { token = scanner.scan(); - if (token === 8) { - var importPath = scanner.getTokenValue(); - var pos = scanner.getTokenPos(); - importedFiles.push({ - fileName: importPath, - pos: pos, - end: pos + importPath.length - }); + if (token === 16) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + continue; + } } } } + else if (token === 23) { + token = scanner.scan(); + } + else { + continue; + } + } + if (token === 14) { + token = scanner.scan(); + while (token !== 15) { + token = scanner.scan(); + } + if (token === 15) { + token = scanner.scan(); + if (token === 123) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + } + } + } + } + else if (token === 35) { + token = scanner.scan(); + if (token === 101) { + token = scanner.scan(); + if (token === 64) { + token = scanner.scan(); + if (token === 123) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + } + } + } + } + } + } + } + else if (token === 77) { + token = scanner.scan(); + if (token === 14) { + token = scanner.scan(); + while (token !== 15) { + token = scanner.scan(); + } + if (token === 15) { + token = scanner.scan(); + if (token === 123) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + } + } + } + } + else if (token === 35) { + token = scanner.scan(); + if (token === 123) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + } } } } @@ -26618,7 +27627,7 @@ var ts; } function isNameOfFunctionDeclaration(node) { return node.kind === 64 && - ts.isAnyFunction(node.parent) && node.parent.name === node; + ts.isFunctionLike(node.parent) && node.parent.name === node; } function isNameOfPropertyAssignment(node) { return (node.kind === 64 || node.kind === 8 || node.kind === 7) && @@ -26713,7 +27722,11 @@ var ts; case 198: return ScriptElementKind.typeElement; case 199: return ScriptElementKind.enumElement; case 193: - return ts.isConst(node) ? ScriptElementKind.constElement : ts.isLet(node) ? ScriptElementKind.letElement : ScriptElementKind.variableElement; + return ts.isConst(node) + ? ScriptElementKind.constElement + : ts.isLet(node) + ? ScriptElementKind.letElement + : ScriptElementKind.variableElement; case 195: return ScriptElementKind.functionElement; case 134: return ScriptElementKind.memberGetAccessorElement; case 135: return ScriptElementKind.memberSetAccessorElement; @@ -26730,6 +27743,12 @@ var ts; case 127: return ScriptElementKind.typeParameterElement; case 219: return ScriptElementKind.variableElement; case 128: return (node.flags & 112) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; + case 202: + case 207: + case 204: + case 211: + case 205: + return ScriptElementKind.alias; } return ScriptElementKind.unknown; } @@ -26807,11 +27826,7 @@ var ts; if (!changesInCompilationSettingsAffectSyntax) { var oldSourceFile = program && program.getSourceFile(fileName); if (oldSourceFile) { - if (sourceFileUpToDate(oldSourceFile)) { - return oldSourceFile; - } - var textChangeRange = hostFileInformation.scriptSnapshot.getChangeRange(oldSourceFile.scriptSnapshot); - return documentRegistry.updateDocument(oldSourceFile, fileName, newSettings, hostFileInformation.scriptSnapshot, hostFileInformation.version, textChangeRange); + return documentRegistry.updateDocument(fileName, newSettings, hostFileInformation.scriptSnapshot, hostFileInformation.version); } } return documentRegistry.acquireDocument(fileName, newSettings, hostFileInformation.scriptSnapshot, hostFileInformation.version); @@ -26846,7 +27861,9 @@ var ts; } function dispose() { if (program) { - ts.forEach(program.getSourceFiles(), function (f) { documentRegistry.releaseDocument(f.fileName, program.getCompilerOptions()); }); + ts.forEach(program.getSourceFiles(), function (f) { + return documentRegistry.releaseDocument(f.fileName, program.getCompilerOptions()); + }); } } function getSyntacticDiagnostics(fileName) { @@ -26991,6 +28008,17 @@ var ts; getCompletionEntriesFromSymbols(filteredMembers, activeCompletionSession); } } + else if (ts.getAncestor(previousToken, 204)) { + isMemberCompletion = true; + isNewIdentifierLocation = true; + if (showCompletionsInImportsClause(previousToken)) { + var importDeclaration = ts.getAncestor(previousToken, 203); + ts.Debug.assert(importDeclaration !== undefined); + var exports = typeInfoResolver.getExportsOfExternalModule(importDeclaration); + var filteredExports = filterModuleExports(exports, importDeclaration); + getCompletionEntriesFromSymbols(filteredExports, activeCompletionSession); + } + } else { isMemberCompletion = false; isNewIdentifierLocation = isNewIdentifierDefinitionLocation(previousToken); @@ -27031,31 +28059,47 @@ var ts; log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; } + function showCompletionsInImportsClause(node) { + if (node) { + if (node.kind === 14 || node.kind === 23) { + return node.parent.kind === 206; + } + } + return false; + } function isNewIdentifierDefinitionLocation(previousToken) { if (previousToken) { var containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { case 23: - return containingNodeKind === 155 || containingNodeKind === 133 || containingNodeKind === 156 || containingNodeKind === 151 || containingNodeKind === 167; + return containingNodeKind === 155 + || containingNodeKind === 133 + || containingNodeKind === 156 + || containingNodeKind === 151 + || containingNodeKind === 167; case 16: - return containingNodeKind === 155 || containingNodeKind === 133 || containingNodeKind === 156 || containingNodeKind === 159; + return containingNodeKind === 155 + || containingNodeKind === 133 + || containingNodeKind === 156 + || containingNodeKind === 159; case 18: return containingNodeKind === 151; - case 117: + case 116: return true; case 20: return containingNodeKind === 200; case 14: return containingNodeKind === 196; case 52: - return containingNodeKind === 193 || containingNodeKind === 167; + return containingNodeKind === 193 + || containingNodeKind === 167; case 11: return containingNodeKind === 169; case 12: return containingNodeKind === 173; - case 109: - case 107: case 108: + case 106: + case 107: return containingNodeKind === 130; } switch (previousToken.getText()) { @@ -27068,7 +28112,9 @@ var ts; return false; } function isInStringOrRegularExpressionOrTemplateLiteral(previousToken) { - if (previousToken.kind === 8 || previousToken.kind === 9 || ts.isTemplateLiteralKind(previousToken.kind)) { + if (previousToken.kind === 8 + || previousToken.kind === 9 + || ts.isTemplateLiteralKind(previousToken.kind)) { var start = previousToken.getStart(); var end = previousToken.getEnd(); if (start < position && position < end) { @@ -27146,27 +28192,27 @@ var ts; containingNodeKind === 195 || containingNodeKind === 197 || isFunction(containingNodeKind); - case 110: + case 109: return containingNodeKind === 130; case 21: return containingNodeKind === 128 || containingNodeKind === 133 || (previousToken.parent.parent.kind === 149); - case 109: - case 107: case 108: + case 106: + case 107: return containingNodeKind === 128; case 68: case 76: - case 104: + case 103: case 82: case 97: - case 116: - case 120: + case 115: + case 119: case 84: - case 105: + case 104: case 69: - case 111: + case 110: return true; } switch (previousToken.getText()) { @@ -27191,6 +28237,23 @@ var ts; } return false; } + function filterModuleExports(exports, importDeclaration) { + var exisingImports = {}; + if (!importDeclaration.importClause) { + return exports; + } + if (importDeclaration.importClause.namedBindings && + importDeclaration.importClause.namedBindings.kind === 206) { + ts.forEach(importDeclaration.importClause.namedBindings.elements, function (el) { + var name = el.propertyName || el.name; + exisingImports[name.text] = true; + }); + } + if (ts.isEmpty(exisingImports)) { + return exports; + } + return ts.filter(exports, function (e) { return !ts.lookUp(exisingImports, e.name); }); + } function filterContextualMembersList(contextualMemberSymbols, existingMembers) { if (!existingMembers || existingMembers.length === 0) { return contextualMemberSymbols; @@ -27337,7 +28400,9 @@ var ts; return ScriptElementKind.unknown; } function getSymbolModifiers(symbol) { - return symbol && symbol.declarations && symbol.declarations.length > 0 ? ts.getNodeModifiers(symbol.declarations[0]) : ScriptElementKindModifier.none; + return symbol && symbol.declarations && symbol.declarations.length > 0 + ? ts.getNodeModifiers(symbol.declarations[0]) + : ScriptElementKindModifier.none; } function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, enclosingDeclaration, typeResolver, location, semanticMeaning) { if (semanticMeaning === void 0) { semanticMeaning = getMeaningFromLocation(location); } @@ -27421,7 +28486,7 @@ var ts; } } else if ((isNameOfFunctionDeclaration(location) && !(symbol.flags & 98304)) || - (location.kind === 114 && location.parent.kind === 133)) { + (location.kind === 113 && location.parent.kind === 133)) { var signature; var functionDeclaration = location.parent; var allSignatures = functionDeclaration.kind === 133 ? type.getConstructSignatures() : type.getCallSignatures(); @@ -27452,14 +28517,14 @@ var ts; } if ((symbolFlags & 64) && (semanticMeaning & 2)) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(104)); + displayParts.push(ts.keywordPart(103)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); } if (symbolFlags & 524288) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(123)); + displayParts.push(ts.keywordPart(122)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); displayParts.push(ts.spacePart()); @@ -27479,7 +28544,7 @@ var ts; } if (symbolFlags & 1536) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(117)); + displayParts.push(ts.keywordPart(116)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); } @@ -27535,7 +28600,7 @@ var ts; displayParts.push(ts.spacePart()); displayParts.push(ts.operatorPart(52)); displayParts.push(ts.spacePart()); - displayParts.push(ts.keywordPart(118)); + displayParts.push(ts.keywordPart(117)); displayParts.push(ts.punctuationPart(16)); displayParts.push(ts.displayPart(ts.getTextOfNode(ts.getExternalModuleImportEqualsDeclarationExpression(importEqualsDeclaration)), 8)); displayParts.push(ts.punctuationPart(17)); @@ -27698,6 +28763,12 @@ var ts; if (!symbol) { return undefined; } + if (symbol.flags & 8388608) { + var declaration = symbol.declarations[0]; + if (node.kind === 64 && node.parent === declaration) { + symbol = typeInfoResolver.getAliasedSymbol(symbol); + } + } var result = []; if (node.parent.kind === 218) { var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); @@ -27754,7 +28825,7 @@ var ts; return false; } function tryAddConstructSignature(symbol, location, symbolKind, symbolName, containerName, result) { - if (isNewExpressionTarget(location) || location.kind === 114) { + if (isNewExpressionTarget(location) || location.kind === 113) { if (symbol.flags & 32) { var classDeclaration = symbol.getDeclarations()[0]; ts.Debug.assert(classDeclaration && classDeclaration.kind === 196); @@ -27839,13 +28910,13 @@ var ts; return getLoopBreakContinueOccurrences(node.parent); } break; - case 114: + case 113: if (hasKind(node.parent, 133)) { return getConstructorOccurrences(node.parent); } break; - case 116: - case 120: + case 115: + case 119: if (hasKind(node.parent, 134) || hasKind(node.parent, 135)) { return getGetAndSetOccurrences(node.parent); } @@ -27950,7 +29021,7 @@ var ts; aggregate(tryStatement.finallyBlock); } } - else if (!ts.isAnyFunction(node)) { + else if (!ts.isFunctionLike(node)) { ts.forEachChild(node, aggregate); } } @@ -28043,7 +29114,7 @@ var ts; if (node.kind === 185 || node.kind === 184) { statementAccumulator.push(node); } - else if (!ts.isAnyFunction(node)) { + else if (!ts.isFunctionLike(node)) { ts.forEachChild(node, aggregate); } } @@ -28070,7 +29141,7 @@ var ts; } break; default: - if (ts.isAnyFunction(node)) { + if (ts.isFunctionLike(node)) { return undefined; } break; @@ -28083,7 +29154,7 @@ var ts; var keywords = []; ts.forEach(declarations, function (declaration) { ts.forEach(declaration.getChildren(), function (token) { - return pushKeywordIf(keywords, token, 114); + return pushKeywordIf(keywords, token, 113); }); }); return ts.map(keywords, getReferenceEntryFromNode); @@ -28096,7 +29167,7 @@ var ts; function tryPushAccessorKeyword(accessorSymbol, accessorKind) { var accessor = ts.getDeclarationOfKind(accessorSymbol, accessorKind); if (accessor) { - ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 116, 120); }); + ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 115, 119); }); } } } @@ -28154,17 +29225,17 @@ var ts; return ts.map(keywords, getReferenceEntryFromNode); function getFlagFromModifier(modifier) { switch (modifier) { - case 109: - return 16; - case 107: - return 32; case 108: + return 16; + case 106: + return 32; + case 107: return 64; - case 110: + case 109: return 128; case 77: return 1; - case 115: + case 114: return 2; default: ts.Debug.fail(); @@ -28210,24 +29281,6 @@ var ts; ts.Debug.assert(node.kind === 64 || node.kind === 7 || node.kind === 8); return getReferencesForNode(node, program.getSourceFiles(), false, findInStrings, findInComments); } - function initializeNameTable(sourceFile) { - var nameTable = {}; - walk(sourceFile); - sourceFile.nameTable = nameTable; - function walk(node) { - switch (node.kind) { - case 64: - nameTable[node.text] = node.text; - break; - case 8: - case 7: - nameTable[node.text] = node.text; - break; - default: - ts.forEachChild(node, walk); - } - } - } function getReferencesForNode(node, sourceFiles, searchOnlyInCurrentFile, findInStrings, findInComments) { if (isLabelName(node)) { if (isJumpStatementTarget(node)) { @@ -28254,7 +29307,7 @@ var ts; } var result; var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); - var declaredName = getDeclaredName(symbol); + var declaredName = getDeclaredName(symbol, node); var scope = getSymbolScope(symbol); if (scope) { result = []; @@ -28267,14 +29320,11 @@ var ts; getReferencesInNode(sourceFiles[0], symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); } else { - var internedName = getInternedName(symbol, declarations); + var internedName = getInternedName(symbol, node, declarations); ts.forEach(sourceFiles, function (sourceFile) { cancellationToken.throwIfCancellationRequested(); - if (!sourceFile.nameTable) { - initializeNameTable(sourceFile); - } - ts.Debug.assert(sourceFile.nameTable !== undefined); - if (ts.lookUp(sourceFile.nameTable, internedName)) { + var nameTable = getNameTable(sourceFile); + if (ts.lookUp(nameTable, internedName)) { result = result || []; getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); } @@ -28282,11 +29332,31 @@ var ts; } } return result; - function getDeclaredName(symbol) { + function isImportOrExportSpecifierName(location) { + return location.parent && + (location.parent.kind === 207 || location.parent.kind === 211) && + location.parent.propertyName === location; + } + function isImportOrExportSpecifierImportSymbol(symbol) { + return (symbol.flags & 8388608) && ts.forEach(symbol.declarations, function (declaration) { + return declaration.kind === 207 || declaration.kind === 211; + }); + } + function getDeclaredName(symbol, location) { + var functionExpression = ts.forEach(symbol.declarations, function (d) { return d.kind === 160 ? d : undefined; }); + if (functionExpression && functionExpression.name) { + var name = functionExpression.name.text; + } + if (isImportOrExportSpecifierName(location)) { + return location.getText(); + } var name = typeInfoResolver.symbolToString(symbol); return stripQuotes(name); } - function getInternedName(symbol, declarations) { + function getInternedName(symbol, location, declarations) { + if (isImportOrExportSpecifierName(location)) { + return location.getText(); + } var functionExpression = ts.forEach(declarations, function (d) { return d.kind === 160 ? d : undefined; }); if (functionExpression && functionExpression.name) { var name = functionExpression.name.text; @@ -28305,13 +29375,16 @@ var ts; return name; } function getSymbolScope(symbol) { - if (symbol.getFlags() && (4 | 8192)) { + if (symbol.flags & (4 | 8192)) { var privateDeclaration = ts.forEach(symbol.getDeclarations(), function (d) { return (d.flags & 32) ? d : undefined; }); if (privateDeclaration) { return ts.getAncestor(privateDeclaration, 196); } } - if (symbol.parent || (symbol.getFlags() & 268435456)) { + if (symbol.flags & 8388608) { + return undefined; + } + if (symbol.parent || (symbol.flags & 268435456)) { return undefined; } var scope = undefined; @@ -28562,6 +29635,9 @@ var ts; } function populateSearchSymbolSet(symbol, location) { var result = [symbol]; + if (isImportOrExportSpecifierImportSymbol(symbol)) { + result.push(typeInfoResolver.getAliasedSymbol(symbol)); + } if (isNameOfPropertyAssignment(location)) { ts.forEach(getPropertySymbolsFromContextualType(location), function (contextualSymbol) { result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol)); @@ -28611,6 +29687,10 @@ var ts; if (searchSymbols.indexOf(referenceSymbol) >= 0) { return true; } + if (isImportOrExportSpecifierImportSymbol(referenceSymbol) && + searchSymbols.indexOf(typeInfoResolver.getAliasedSymbol(referenceSymbol)) >= 0) { + return true; + } if (isNameOfPropertyAssignment(referenceLocation)) { return ts.forEach(getPropertySymbolsFromContextualType(referenceLocation), function (contextualSymbol) { return ts.forEach(typeInfoResolver.getRootSymbols(contextualSymbol), function (s) { return searchSymbols.indexOf(s) >= 0; }); @@ -28689,7 +29769,7 @@ var ts; }; } function isWriteAccess(node) { - if (node.kind === 64 && ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (node.kind === 64 && ts.isDeclarationName(node)) { return true; } var parent = node.parent; @@ -28766,11 +29846,17 @@ var ts; else { return 4; } + case 206: + case 207: case 202: + case 203: + case 208: + case 209: return 1 | 2 | 4; case 220: return 4 | 1; } + return 1 | 2 | 4; ts.Debug.fail("Unknown declaration type"); } function isTypeReference(node) { @@ -28811,7 +29897,7 @@ var ts; else if (isInRightSideOfImport(node)) { return getMeaningFromRightHandSideOfImportEquals(node); } - else if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + else if (ts.isDeclarationName(node)) { return getMeaningFromDeclaration(node.parent); } else if (isTypeReference(node)) { @@ -29320,6 +30406,41 @@ var ts; }; } ts.createLanguageService = createLanguageService; + function getNameTable(sourceFile) { + if (!sourceFile.nameTable) { + initializeNameTable(sourceFile); + } + return sourceFile.nameTable; + } + ts.getNameTable = getNameTable; + function initializeNameTable(sourceFile) { + var nameTable = {}; + walk(sourceFile); + sourceFile.nameTable = nameTable; + function walk(node) { + switch (node.kind) { + case 64: + nameTable[node.text] = node.text; + break; + case 8: + case 7: + if (ts.isDeclarationName(node) || + node.parent.kind === 212 || + isArgumentOfElementAccessExpression(node)) { + nameTable[node.text] = node.text; + } + break; + default: + ts.forEachChild(node, walk); + } + } + } + function isArgumentOfElementAccessExpression(node) { + return node && + node.parent && + node.parent.kind === 154 && + node.parent.argumentExpression === node; + } function createClassifier() { var scanner = ts.createScanner(2, false); var noRegexTable = []; @@ -29338,19 +30459,19 @@ var ts; var templateStack = []; function isAccessibilityModifier(kind) { switch (kind) { - case 109: - case 107: case 108: + case 106: + case 107: return true; } return false; } function canFollow(keyword1, keyword2) { if (isAccessibilityModifier(keyword1)) { - if (keyword2 === 116 || - keyword2 === 120 || - keyword2 === 114 || - keyword2 === 110) { + if (keyword2 === 115 || + keyword2 === 119 || + keyword2 === 113 || + keyword2 === 109) { return true; } return false; @@ -29415,11 +30536,11 @@ var ts; else if (token === 25 && angleBracketStack > 0) { angleBracketStack--; } - else if (token === 112 || - token === 121 || - token === 119 || - token === 113 || - token === 122) { + else if (token === 111 || + token === 120 || + token === 118 || + token === 112 || + token === 121) { if (angleBracketStack > 0 && !syntacticClassifierAbsent) { token = 64; } @@ -29470,7 +30591,9 @@ var ts; } if (numBackslashes & 1) { var quoteChar = tokenText.charCodeAt(0); - result.finalLexState = quoteChar === 34 ? 3 : 2; + result.finalLexState = quoteChar === 34 + ? 3 + : 2; } } } @@ -29704,13 +30827,7 @@ var ts; return this.compilationSettings; }; LSHost.prototype.getScriptFileNames = function () { - var filenames = []; - for (var filename in this.filenameToScript) { - if (this.filenameToScript[filename] && this.filenameToScript[filename].isOpen) { - filenames.push(filename); - } - } - return filenames; + return this.roots.map(function (root) { return root.fileName; }); }; LSHost.prototype.getScriptVersion = function (filename) { return this.getScriptInfo(filename).svc.latestVersion().toString(); @@ -29979,7 +31096,7 @@ var ts; var r = this.openFileRoots[i]; if (info.defaultProject.getSourceFile(r)) { this.inferredProjects = - copyListRemovingItem(r.defaultProject, this.inferredProjects); + copyListRemovingItem(r.defaultProject, this.inferredProjects); this.openFilesReferenced.push(r); r.defaultProject = info.defaultProject; } @@ -30044,15 +31161,20 @@ var ts; ProjectService.prototype.updateProjectStructure = function () { this.log("updating project structure from ...", "Info"); this.printProjects(); + var openFilesReferenced = []; + var unattachedOpenFiles = []; for (var i = 0, len = this.openFilesReferenced.length; i < len; i++) { - var refdFile = this.openFilesReferenced[i]; - refdFile.defaultProject.updateGraph(); - var sourceFile = refdFile.defaultProject.getSourceFile(refdFile); - if (!sourceFile) { - this.openFilesReferenced = copyListRemovingItem(refdFile, this.openFilesReferenced); - this.addOpenFile(refdFile); + var referencedFile = this.openFilesReferenced[i]; + referencedFile.defaultProject.updateGraph(); + var sourceFile = referencedFile.defaultProject.getSourceFile(referencedFile); + if (sourceFile) { + openFilesReferenced.push(referencedFile); + } + else { + unattachedOpenFiles.push(referencedFile); } } + this.openFilesReferenced = openFilesReferenced; var openFileRoots = []; for (var i = 0, len = this.openFileRoots.length; i < len; i++) { var rootFile = this.openFileRoots[i]; @@ -30068,6 +31190,9 @@ var ts; } } this.openFileRoots = openFileRoots; + for (var i = 0, len = unattachedOpenFiles.length; i < len; i++) { + this.addOpenFile(unattachedOpenFiles[i]); + } this.printProjects(); }; ProjectService.prototype.getScriptInfo = function (filename) { @@ -30562,6 +31687,7 @@ var ts; ScriptVersionCache.changeLengthThreshold = 256; return ScriptVersionCache; })(); + server.ScriptVersionCache = ScriptVersionCache; var LineIndexSnapshot = (function () { function LineIndexSnapshot(version, cache) { this.version = version; @@ -30643,7 +31769,7 @@ var ts; }; LineIndex.prototype.getText = function (rangeStart, rangeLength) { var accum = ""; - if (rangeLength > 0) { + if ((rangeLength > 0) && (rangeStart < this.root.charCount())) { this.walk(rangeStart, rangeLength, { goSubtree: true, done: false, @@ -30686,7 +31812,19 @@ var ts; var checkText = editFlat(this.getText(0, this.root.charCount()), pos, deleteLength, newText); } var walker = new EditWalker(); - if (deleteLength > 0) { + if (pos >= this.root.charCount()) { + pos = this.root.charCount() - 1; + var endString = this.getText(pos, 1); + if (newText) { + newText = endString + newText; + } + else { + newText = endString; + } + deleteLength = 0; + walker.suppressTrailingText = true; + } + else if (deleteLength > 0) { var e = pos + deleteLength; var lineInfo = this.charOffsetToLineNumberAndPos(e); if ((lineInfo && (lineInfo.col == 0))) { @@ -30699,20 +31837,10 @@ var ts; } } } - else if (pos >= this.root.charCount()) { - var endString = this.getText(pos - 1, 1); - if (newText) { - newText = endString + newText; - } - else { - newText = endString; - } - pos = pos - 1; - deleteLength = 0; - walker.suppressTrailingText = true; + if (pos < this.root.charCount()) { + this.root.walk(pos, deleteLength, walker); + walker.insertLines(newText); } - this.root.walk(pos, deleteLength, walker); - walker.insertLines(newText); if (this.checkEdits) { var updatedText = this.getText(0, this.root.charCount()); ts.Debug.assert(checkText == updatedText, "buffer edit mismatch"); @@ -30770,6 +31898,7 @@ var ts; }; return LineIndex; })(); + server.LineIndex = LineIndex; var LineNode = (function () { function LineNode() { this.totalChars = 0; @@ -31214,17 +32343,27 @@ var ts; this.response(body, commandName, requestSequence, errorMessage); }; Session.prototype.semanticCheck = function (file, project) { - var diags = project.compilerService.languageService.getSemanticDiagnostics(file); - if (diags) { - var bakedDiags = diags.map(function (diag) { return formatDiag(file, project, diag); }); - this.event({ file: file, diagnostics: bakedDiags }, "semanticDiag"); + try { + var diags = project.compilerService.languageService.getSemanticDiagnostics(file); + if (diags) { + var bakedDiags = diags.map(function (diag) { return formatDiag(file, project, diag); }); + this.event({ file: file, diagnostics: bakedDiags }, "semanticDiag"); + } + } + catch (err) { + this.logError(err, "semantic check"); } }; Session.prototype.syntacticCheck = function (file, project) { - var diags = project.compilerService.languageService.getSyntacticDiagnostics(file); - if (diags) { - var bakedDiags = diags.map(function (diag) { return formatDiag(file, project, diag); }); - this.event({ file: file, diagnostics: bakedDiags }, "syntaxDiag"); + try { + var diags = project.compilerService.languageService.getSyntacticDiagnostics(file); + if (diags) { + var bakedDiags = diags.map(function (diag) { return formatDiag(file, project, diag); }); + this.event({ file: file, diagnostics: bakedDiags }, "syntaxDiag"); + } + } + catch (err) { + this.logError(err, "syntactic check"); } }; Session.prototype.errorCheck = function (file, project) { @@ -31317,11 +32456,11 @@ var ts; if (!renameLocations) { return undefined; } - var bakedRenameLocs = renameLocations.map(function (location) { return { + var bakedRenameLocs = renameLocations.map(function (location) { return ({ file: location.fileName, start: compilerService.host.positionToLineCol(location.fileName, location.textSpan.start), end: compilerService.host.positionToLineCol(location.fileName, ts.textSpanEnd(location.textSpan)) - }; }).sort(function (a, b) { + }); }).sort(function (a, b) { if (a.file < b.file) { return -1; } @@ -31530,6 +32669,7 @@ var ts; } }; Session.prototype.change = function (line, col, endLine, endCol, insertString, fileName) { + var _this = this; var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (project) { @@ -31540,6 +32680,7 @@ var ts; compilerService.host.editScript(file, start, end, insertString); this.changeSeq++; } + this.updateProjectStructure(this.changeSeq, function (n) { return n == _this.changeSeq; }); } }; Session.prototype.reload = function (fileName, tempFileName, reqSeq) { @@ -31938,6 +33079,10 @@ var ts; close: function () { return watchedFileSet.removeFile(watchedFile); } }; }; - new IOSession(ts.sys, logger).listen(); + var ioSession = new IOSession(ts.sys, logger); + process.on('uncaughtException', function (err) { + ioSession.logError(err, "unknown"); + }); + ioSession.listen(); })(server = ts.server || (ts.server = {})); })(ts || (ts = {})); diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 8da331c74e1..3de69b45409 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -124,28 +124,28 @@ declare module "typescript" { WhileKeyword = 99, WithKeyword = 100, AsKeyword = 101, - FromKeyword = 102, - ImplementsKeyword = 103, - InterfaceKeyword = 104, - LetKeyword = 105, - PackageKeyword = 106, - PrivateKeyword = 107, - ProtectedKeyword = 108, - PublicKeyword = 109, - StaticKeyword = 110, - YieldKeyword = 111, - AnyKeyword = 112, - BooleanKeyword = 113, - ConstructorKeyword = 114, - DeclareKeyword = 115, - GetKeyword = 116, - ModuleKeyword = 117, - RequireKeyword = 118, - NumberKeyword = 119, - SetKeyword = 120, - StringKeyword = 121, - SymbolKeyword = 122, - TypeKeyword = 123, + ImplementsKeyword = 102, + InterfaceKeyword = 103, + LetKeyword = 104, + PackageKeyword = 105, + PrivateKeyword = 106, + ProtectedKeyword = 107, + PublicKeyword = 108, + StaticKeyword = 109, + YieldKeyword = 110, + AnyKeyword = 111, + BooleanKeyword = 112, + ConstructorKeyword = 113, + DeclareKeyword = 114, + GetKeyword = 115, + ModuleKeyword = 116, + RequireKeyword = 117, + NumberKeyword = 118, + SetKeyword = 119, + StringKeyword = 120, + SymbolKeyword = 121, + TypeKeyword = 122, + FromKeyword = 123, OfKeyword = 124, QualifiedName = 125, ComputedPropertyName = 126, @@ -251,8 +251,8 @@ declare module "typescript" { LastReservedWord = 100, FirstKeyword = 65, LastKeyword = 124, - FirstFutureReservedWord = 103, - LastFutureReservedWord = 111, + FirstFutureReservedWord = 102, + LastFutureReservedWord = 110, FirstTypeNode = 139, LastTypeNode = 147, FirstPunctuation = 14, @@ -276,15 +276,16 @@ declare module "typescript" { Private = 32, Protected = 64, Static = 128, - MultiLine = 256, - Synthetic = 512, - DeclarationFile = 1024, - Let = 2048, - Const = 4096, - OctalLiteral = 8192, - Modifier = 243, + Default = 256, + MultiLine = 512, + Synthetic = 1024, + DeclarationFile = 2048, + Let = 4096, + Const = 8192, + OctalLiteral = 16384, + Modifier = 499, AccessibilityModifier = 112, - BlockScoped = 6144, + BlockScoped = 12288, } const enum ParserContextFlags { StrictMode = 1, @@ -412,7 +413,7 @@ declare module "typescript" { body?: Block | Expression; } interface FunctionDeclaration extends FunctionLikeDeclaration, Statement { - name: Identifier; + name?: Identifier; body?: Block; } interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { @@ -505,7 +506,9 @@ declare module "typescript" { } interface ConditionalExpression extends Expression { condition: Expression; + questionToken: Node; whenTrue: Expression; + colonToken: Node; whenFalse: Expression; } interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclaration { @@ -515,6 +518,7 @@ declare module "typescript" { interface LiteralExpression extends PrimaryExpression { text: string; isUnterminated?: boolean; + hasExtendedUnicodeEscape?: boolean; } interface StringLiteralExpression extends LiteralExpression { _stringLiteralExpressionBrand: any; @@ -541,6 +545,7 @@ declare module "typescript" { } interface PropertyAccessExpression extends MemberExpression { expression: LeftHandSideExpression; + dotToken: Node; name: Identifier; } interface ElementAccessExpression extends MemberExpression { @@ -636,16 +641,15 @@ declare module "typescript" { catchClause?: CatchClause; finallyBlock?: Block; } - interface CatchClause extends Declaration { - name: Identifier; - type?: TypeNode; + interface CatchClause extends Node { + variableDeclaration: VariableDeclaration; block: Block; } interface ModuleElement extends Node { _moduleElementBrand: any; } interface ClassDeclaration extends Declaration, ModuleElement { - name: Identifier; + name?: Identifier; typeParameters?: NodeArray; heritageClauses?: NodeArray; members: NodeArray; @@ -675,10 +679,7 @@ declare module "typescript" { name: Identifier; members: NodeArray; } - interface ExportContainer { - exportStars?: ExportDeclaration[]; - } - interface ModuleDeclaration extends Declaration, ModuleElement, ExportContainer { + interface ModuleDeclaration extends Declaration, ModuleElement { name: Identifier | LiteralExpression; body: ModuleBlock | ModuleDeclaration; } @@ -703,7 +704,7 @@ declare module "typescript" { interface NamespaceImport extends Declaration { name: Identifier; } - interface ExportDeclaration extends Statement, ModuleElement { + interface ExportDeclaration extends Declaration, ModuleElement { exportClause?: NamedExports; moduleSpecifier?: Expression; } @@ -718,8 +719,9 @@ declare module "typescript" { } type ImportSpecifier = ImportOrExportSpecifier; type ExportSpecifier = ImportOrExportSpecifier; - interface ExportAssignment extends Statement, ModuleElement { - exportName: Identifier; + interface ExportAssignment extends Declaration, ModuleElement { + isExportEquals?: boolean; + expression: Expression; } interface FileReference extends TextRange { fileName: string; @@ -727,7 +729,7 @@ declare module "typescript" { interface CommentRange extends TextRange { hasTrailingNewLine?: boolean; } - interface SourceFile extends Declaration, ExportContainer { + interface SourceFile extends Declaration { statements: NodeArray; endOfFileToken: Node; fileName: string; @@ -832,6 +834,7 @@ declare module "typescript" { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean; getAliasedSymbol(symbol: Symbol): Symbol; + getExportsOfExternalModule(node: ImportDeclaration): Symbol[]; } interface SymbolDisplayBuilder { buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; @@ -889,10 +892,10 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; + getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - getExportAssignmentName(node: SourceFile): string; - isReferencedImportDeclaration(node: Node): boolean; + hasExportDefaultValue(node: SourceFile): boolean; + isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; @@ -903,6 +906,7 @@ declare module "typescript" { isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -928,13 +932,14 @@ declare module "typescript" { ExportValue = 1048576, ExportType = 2097152, ExportNamespace = 4194304, - Import = 8388608, + Alias = 8388608, Instantiated = 16777216, Merged = 33554432, Transient = 67108864, Prototype = 134217728, UnionProperty = 268435456, Optional = 536870912, + ExportStar = 1073741824, Enum = 384, Variable = 3, Value = 107455, @@ -959,7 +964,7 @@ declare module "typescript" { SetAccessorExcludes = 74687, TypeParameterExcludes = 530912, TypeAliasExcludes = 793056, - ImportExcludes = 8388608, + AliasExcludes = 8388608, ModuleMember = 8914931, ExportHasLocal = 944, HasLocals = 255504, @@ -988,10 +993,9 @@ declare module "typescript" { declaredType?: Type; mapper?: TypeMapper; referenced?: boolean; - exportAssignmentChecked?: boolean; - exportAssignmentSymbol?: Symbol; unionType?: UnionType; resolvedExports?: SymbolTable; + exportsChecked?: boolean; } interface TransientSymbol extends Symbol, SymbolLinks { } @@ -1007,6 +1011,7 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, + BlockScopedBindingInLoop = 256, } interface NodeLinks { resolvedType?: Type; @@ -1383,6 +1388,7 @@ declare module "typescript" { getTokenPos(): number; getTokenText(): string; getTokenValue(): string; + hasExtendedUnicodeEscape(): boolean; hasPrecedingLineBreak(): boolean; isIdentifier(): boolean; isReservedWord(): boolean; @@ -1479,9 +1485,6 @@ declare module "typescript" { getDocumentationComment(): SymbolDisplayPart[]; } interface SourceFile { - version: string; - scriptSnapshot: IScriptSnapshot; - nameTable: Map; getNamedDeclarations(): Declaration[]; getLineAndCharacterOfPosition(pos: number): LineAndCharacter; getLineStarts(): number[]; @@ -1835,25 +1838,17 @@ declare module "typescript" { acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile; /** * Request an updated version of an already existing SourceFile with a given fileName - * and compilationSettings. The update will intern call updateLanguageServiceSourceFile + * and compilationSettings. The update will in-turn call updateLanguageServiceSourceFile * to get an updated SourceFile. * - * Note: It is not allowed to call update on a SourceFile that was not acquired from this - * registry originally. - * - * @param sourceFile The original sourceFile object to update * @param fileName The name of the file requested * @param compilationSettings Some compilation settings like target affects the * shape of a the resulting SourceFile. This allows the DocumentRegistry to store * multiple copies of the same file for different compilation settings. - * @parm scriptSnapshot Text of the file. Only used if the file was not found - * in the registry and a new one was created. - * @parm version Current version of the file. Only used if the file was not found - * in the registry and a new one was created. - * @parm textChangeRange Change ranges since the last snapshot. Only used if the file - * was not found in the registry and a new one was created. + * @param scriptSnapshot Text of the file. + * @param version Current version of the file. */ - updateDocument(sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile; + updateDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile; /** * Informs the DocumentRegistry that a file is not needed any longer. * diff --git a/bin/typescript.js b/bin/typescript.js index 4ee694a8f19..f3c487b2079 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -118,28 +118,28 @@ var ts; SyntaxKind[SyntaxKind["WhileKeyword"] = 99] = "WhileKeyword"; SyntaxKind[SyntaxKind["WithKeyword"] = 100] = "WithKeyword"; SyntaxKind[SyntaxKind["AsKeyword"] = 101] = "AsKeyword"; - SyntaxKind[SyntaxKind["FromKeyword"] = 102] = "FromKeyword"; - SyntaxKind[SyntaxKind["ImplementsKeyword"] = 103] = "ImplementsKeyword"; - SyntaxKind[SyntaxKind["InterfaceKeyword"] = 104] = "InterfaceKeyword"; - SyntaxKind[SyntaxKind["LetKeyword"] = 105] = "LetKeyword"; - SyntaxKind[SyntaxKind["PackageKeyword"] = 106] = "PackageKeyword"; - SyntaxKind[SyntaxKind["PrivateKeyword"] = 107] = "PrivateKeyword"; - SyntaxKind[SyntaxKind["ProtectedKeyword"] = 108] = "ProtectedKeyword"; - SyntaxKind[SyntaxKind["PublicKeyword"] = 109] = "PublicKeyword"; - SyntaxKind[SyntaxKind["StaticKeyword"] = 110] = "StaticKeyword"; - SyntaxKind[SyntaxKind["YieldKeyword"] = 111] = "YieldKeyword"; - SyntaxKind[SyntaxKind["AnyKeyword"] = 112] = "AnyKeyword"; - SyntaxKind[SyntaxKind["BooleanKeyword"] = 113] = "BooleanKeyword"; - SyntaxKind[SyntaxKind["ConstructorKeyword"] = 114] = "ConstructorKeyword"; - SyntaxKind[SyntaxKind["DeclareKeyword"] = 115] = "DeclareKeyword"; - SyntaxKind[SyntaxKind["GetKeyword"] = 116] = "GetKeyword"; - SyntaxKind[SyntaxKind["ModuleKeyword"] = 117] = "ModuleKeyword"; - SyntaxKind[SyntaxKind["RequireKeyword"] = 118] = "RequireKeyword"; - SyntaxKind[SyntaxKind["NumberKeyword"] = 119] = "NumberKeyword"; - SyntaxKind[SyntaxKind["SetKeyword"] = 120] = "SetKeyword"; - SyntaxKind[SyntaxKind["StringKeyword"] = 121] = "StringKeyword"; - SyntaxKind[SyntaxKind["SymbolKeyword"] = 122] = "SymbolKeyword"; - SyntaxKind[SyntaxKind["TypeKeyword"] = 123] = "TypeKeyword"; + SyntaxKind[SyntaxKind["ImplementsKeyword"] = 102] = "ImplementsKeyword"; + SyntaxKind[SyntaxKind["InterfaceKeyword"] = 103] = "InterfaceKeyword"; + SyntaxKind[SyntaxKind["LetKeyword"] = 104] = "LetKeyword"; + SyntaxKind[SyntaxKind["PackageKeyword"] = 105] = "PackageKeyword"; + SyntaxKind[SyntaxKind["PrivateKeyword"] = 106] = "PrivateKeyword"; + SyntaxKind[SyntaxKind["ProtectedKeyword"] = 107] = "ProtectedKeyword"; + SyntaxKind[SyntaxKind["PublicKeyword"] = 108] = "PublicKeyword"; + SyntaxKind[SyntaxKind["StaticKeyword"] = 109] = "StaticKeyword"; + SyntaxKind[SyntaxKind["YieldKeyword"] = 110] = "YieldKeyword"; + SyntaxKind[SyntaxKind["AnyKeyword"] = 111] = "AnyKeyword"; + SyntaxKind[SyntaxKind["BooleanKeyword"] = 112] = "BooleanKeyword"; + SyntaxKind[SyntaxKind["ConstructorKeyword"] = 113] = "ConstructorKeyword"; + SyntaxKind[SyntaxKind["DeclareKeyword"] = 114] = "DeclareKeyword"; + SyntaxKind[SyntaxKind["GetKeyword"] = 115] = "GetKeyword"; + SyntaxKind[SyntaxKind["ModuleKeyword"] = 116] = "ModuleKeyword"; + SyntaxKind[SyntaxKind["RequireKeyword"] = 117] = "RequireKeyword"; + SyntaxKind[SyntaxKind["NumberKeyword"] = 118] = "NumberKeyword"; + SyntaxKind[SyntaxKind["SetKeyword"] = 119] = "SetKeyword"; + SyntaxKind[SyntaxKind["StringKeyword"] = 120] = "StringKeyword"; + SyntaxKind[SyntaxKind["SymbolKeyword"] = 121] = "SymbolKeyword"; + SyntaxKind[SyntaxKind["TypeKeyword"] = 122] = "TypeKeyword"; + SyntaxKind[SyntaxKind["FromKeyword"] = 123] = "FromKeyword"; SyntaxKind[SyntaxKind["OfKeyword"] = 124] = "OfKeyword"; SyntaxKind[SyntaxKind["QualifiedName"] = 125] = "QualifiedName"; SyntaxKind[SyntaxKind["ComputedPropertyName"] = 126] = "ComputedPropertyName"; @@ -245,8 +245,8 @@ var ts; SyntaxKind[SyntaxKind["LastReservedWord"] = 100] = "LastReservedWord"; SyntaxKind[SyntaxKind["FirstKeyword"] = 65] = "FirstKeyword"; SyntaxKind[SyntaxKind["LastKeyword"] = 124] = "LastKeyword"; - SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 103] = "FirstFutureReservedWord"; - SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 111] = "LastFutureReservedWord"; + SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 102] = "FirstFutureReservedWord"; + SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 110] = "LastFutureReservedWord"; SyntaxKind[SyntaxKind["FirstTypeNode"] = 139] = "FirstTypeNode"; SyntaxKind[SyntaxKind["LastTypeNode"] = 147] = "LastTypeNode"; SyntaxKind[SyntaxKind["FirstPunctuation"] = 14] = "FirstPunctuation"; @@ -271,15 +271,16 @@ var ts; NodeFlags[NodeFlags["Private"] = 32] = "Private"; NodeFlags[NodeFlags["Protected"] = 64] = "Protected"; NodeFlags[NodeFlags["Static"] = 128] = "Static"; - NodeFlags[NodeFlags["MultiLine"] = 256] = "MultiLine"; - NodeFlags[NodeFlags["Synthetic"] = 512] = "Synthetic"; - NodeFlags[NodeFlags["DeclarationFile"] = 1024] = "DeclarationFile"; - NodeFlags[NodeFlags["Let"] = 2048] = "Let"; - NodeFlags[NodeFlags["Const"] = 4096] = "Const"; - NodeFlags[NodeFlags["OctalLiteral"] = 8192] = "OctalLiteral"; - NodeFlags[NodeFlags["Modifier"] = 243] = "Modifier"; + NodeFlags[NodeFlags["Default"] = 256] = "Default"; + NodeFlags[NodeFlags["MultiLine"] = 512] = "MultiLine"; + NodeFlags[NodeFlags["Synthetic"] = 1024] = "Synthetic"; + NodeFlags[NodeFlags["DeclarationFile"] = 2048] = "DeclarationFile"; + NodeFlags[NodeFlags["Let"] = 4096] = "Let"; + NodeFlags[NodeFlags["Const"] = 8192] = "Const"; + NodeFlags[NodeFlags["OctalLiteral"] = 16384] = "OctalLiteral"; + NodeFlags[NodeFlags["Modifier"] = 499] = "Modifier"; NodeFlags[NodeFlags["AccessibilityModifier"] = 112] = "AccessibilityModifier"; - NodeFlags[NodeFlags["BlockScoped"] = 6144] = "BlockScoped"; + NodeFlags[NodeFlags["BlockScoped"] = 12288] = "BlockScoped"; })(ts.NodeFlags || (ts.NodeFlags = {})); var NodeFlags = ts.NodeFlags; (function (ParserContextFlags) { @@ -353,13 +354,14 @@ var ts; SymbolFlags[SymbolFlags["ExportValue"] = 1048576] = "ExportValue"; SymbolFlags[SymbolFlags["ExportType"] = 2097152] = "ExportType"; SymbolFlags[SymbolFlags["ExportNamespace"] = 4194304] = "ExportNamespace"; - SymbolFlags[SymbolFlags["Import"] = 8388608] = "Import"; + SymbolFlags[SymbolFlags["Alias"] = 8388608] = "Alias"; SymbolFlags[SymbolFlags["Instantiated"] = 16777216] = "Instantiated"; SymbolFlags[SymbolFlags["Merged"] = 33554432] = "Merged"; SymbolFlags[SymbolFlags["Transient"] = 67108864] = "Transient"; SymbolFlags[SymbolFlags["Prototype"] = 134217728] = "Prototype"; SymbolFlags[SymbolFlags["UnionProperty"] = 268435456] = "UnionProperty"; SymbolFlags[SymbolFlags["Optional"] = 536870912] = "Optional"; + SymbolFlags[SymbolFlags["ExportStar"] = 1073741824] = "ExportStar"; SymbolFlags[SymbolFlags["Enum"] = 384] = "Enum"; SymbolFlags[SymbolFlags["Variable"] = 3] = "Variable"; SymbolFlags[SymbolFlags["Value"] = 107455] = "Value"; @@ -384,7 +386,7 @@ var ts; SymbolFlags[SymbolFlags["SetAccessorExcludes"] = 74687] = "SetAccessorExcludes"; SymbolFlags[SymbolFlags["TypeParameterExcludes"] = 530912] = "TypeParameterExcludes"; SymbolFlags[SymbolFlags["TypeAliasExcludes"] = 793056] = "TypeAliasExcludes"; - SymbolFlags[SymbolFlags["ImportExcludes"] = 8388608] = "ImportExcludes"; + SymbolFlags[SymbolFlags["AliasExcludes"] = 8388608] = "AliasExcludes"; SymbolFlags[SymbolFlags["ModuleMember"] = 8914931] = "ModuleMember"; SymbolFlags[SymbolFlags["ExportHasLocal"] = 944] = "ExportHasLocal"; SymbolFlags[SymbolFlags["HasLocals"] = 255504] = "HasLocals"; @@ -404,6 +406,7 @@ var ts; NodeCheckFlags[NodeCheckFlags["SuperStatic"] = 32] = "SuperStatic"; NodeCheckFlags[NodeCheckFlags["ContextChecked"] = 64] = "ContextChecked"; NodeCheckFlags[NodeCheckFlags["EnumValuesComputed"] = 128] = "EnumValuesComputed"; + NodeCheckFlags[NodeCheckFlags["BlockScopedBindingInLoop"] = 256] = "BlockScopedBindingInLoop"; })(ts.NodeCheckFlags || (ts.NodeCheckFlags = {})); var NodeCheckFlags = ts.NodeCheckFlags; (function (TypeFlags) { @@ -825,7 +828,9 @@ var ts; } ts.localizedDiagnosticMessages = undefined; function getLocaleSpecificMessage(message) { - return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message] ? ts.localizedDiagnosticMessages[message] : message; + return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message] + ? ts.localizedDiagnosticMessages[message] + : message; } ts.getLocaleSpecificMessage = getLocaleSpecificMessage; function createFileDiagnostic(file, start, length, message) { @@ -973,7 +978,9 @@ var ts; normalized.pop(); } else { - normalized.push(part); + if (part) { + normalized.push(part); + } } } } @@ -1116,7 +1123,7 @@ var ts; } ts.removeFileExtension = removeFileExtension; var backslashOrDoubleQuote = /[\"\\]/g; - var escapedCharsRegExp = /[\0-\19\t\v\f\b\0\r\n\u2028\u2029\u0085]/g; + var escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g; var escapedCharsMap = { "\0": "\\0", "\t": "\\t", @@ -1131,20 +1138,6 @@ var ts; "\u2029": "\\u2029", "\u0085": "\\u0085" }; - function escapeString(s) { - s = backslashOrDoubleQuote.test(s) ? s.replace(backslashOrDoubleQuote, getReplacement) : s; - s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s; - return s; - function getReplacement(c) { - return escapedCharsMap[c] || unicodeEscape(c); - } - function unicodeEscape(c) { - var hexCharCode = c.charCodeAt(0).toString(16); - var paddedHexCode = ("0000" + hexCharCode).slice(-4); - return "\\u" + paddedHexCode; - } - } - ts.escapeString = escapeString; function getDefaultLibFileName(options) { return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts"; } @@ -1464,7 +1457,6 @@ var ts; Trailing_comma_not_allowed: { code: 1009, category: 1, key: "Trailing comma not allowed." }, Asterisk_Slash_expected: { code: 1010, category: 1, key: "'*/' expected." }, Unexpected_token: { code: 1012, category: 1, key: "Unexpected token." }, - Catch_clause_parameter_cannot_have_a_type_annotation: { code: 1013, category: 1, key: "Catch clause parameter cannot have a type annotation." }, A_rest_parameter_must_be_last_in_a_parameter_list: { code: 1014, category: 1, key: "A rest parameter must be last in a parameter list." }, Parameter_cannot_have_question_mark_and_initializer: { code: 1015, category: 1, key: "Parameter cannot have question mark and initializer." }, A_required_parameter_cannot_follow_an_optional_parameter: { code: 1016, category: 1, key: "A required parameter cannot follow an optional parameter." }, @@ -1572,7 +1564,6 @@ var ts; const_declarations_must_be_initialized: { code: 1155, category: 1, key: "'const' declarations must be initialized" }, const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: 1, key: "'const' declarations can only be declared inside a block." }, let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: 1, key: "'let' declarations can only be declared inside a block." }, - Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: 1, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." }, 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." }, @@ -1609,6 +1600,11 @@ var ts; External_module_0_has_no_default_export_or_export_assignment: { code: 1192, category: 1, key: "External module '{0}' has no default export or export assignment." }, An_export_declaration_cannot_have_modifiers: { code: 1193, category: 1, key: "An export declaration cannot have modifiers." }, Export_declarations_are_not_permitted_in_an_internal_module: { code: 1194, category: 1, key: "Export declarations are not permitted in an internal module." }, + Catch_clause_variable_name_must_be_an_identifier: { code: 1195, category: 1, key: "Catch clause variable name must be an identifier." }, + Catch_clause_variable_cannot_have_a_type_annotation: { code: 1196, category: 1, key: "Catch clause variable cannot have a type annotation." }, + Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: 1, key: "Catch clause variable cannot have an initializer." }, + An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: 1, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, + Unterminated_Unicode_escape_sequence: { code: 1199, category: 1, key: "Unterminated Unicode escape sequence." }, 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." }, @@ -1782,6 +1778,14 @@ var ts; for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 2482, category: 1, key: "'for...of' statements are only available when targeting ECMAScript 6 or higher." }, The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation: { code: 2483, category: 1, key: "The left-hand side of a 'for...of' statement cannot use a type annotation." }, Export_declaration_conflicts_with_exported_declaration_of_0: { code: 2484, category: 1, key: "Export declaration conflicts with exported declaration of '{0}'" }, + The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant: { code: 2485, category: 1, key: "The left-hand side of a 'for...of' statement cannot be a previously defined constant." }, + The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant: { code: 2486, category: 1, key: "The left-hand side of a 'for...in' statement cannot be a previously defined constant." }, + Invalid_left_hand_side_in_for_of_statement: { code: 2487, category: 1, key: "Invalid left-hand side in 'for...of' statement." }, + The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator: { code: 2488, category: 1, key: "The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator." }, + The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method: { code: 2489, category: 1, key: "The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method." }, + The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property: { code: 2490, category: 1, key: "The type returned by the 'next()' method of an iterator must have a 'value' property." }, + The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern: { code: 2491, category: 1, key: "The left-hand side of a 'for...in' statement cannot be a destructuring pattern." }, + Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: 1, key: "Cannot redeclare identifier '{0}' in catch clause" }, 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}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: 1, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1851,6 +1855,7 @@ var ts; Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: 1, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: 1, key: "Parameter '{0}' of exported function has or is using private name '{1}'." }, Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: 1, key: "Exported type alias '{0}' has or is using private name '{1}'." }, + Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: 1, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." }, 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}" }, @@ -1926,25 +1931,24 @@ var ts; You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: 1, key: "You cannot rename elements that are defined in the standard TypeScript library." }, yield_expressions_are_not_currently_supported: { code: 9000, category: 1, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: 1, key: "Generators are not currently supported." }, - The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: 1, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, - for_of_statements_are_not_currently_supported: { code: 9003, category: 1, key: "'for...of' statements are not currently supported." } + The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: 1, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." } }; })(ts || (ts = {})); var ts; (function (ts) { var textToToken = { - "any": 112, + "any": 111, "as": 101, - "boolean": 113, + "boolean": 112, "break": 65, "case": 66, "catch": 67, "class": 68, "continue": 70, "const": 69, - "constructor": 114, + "constructor": 113, "debugger": 71, - "declare": 115, + "declare": 114, "default": 72, "delete": 73, "do": 74, @@ -1955,43 +1959,43 @@ var ts; "false": 79, "finally": 80, "for": 81, - "from": 102, + "from": 123, "function": 82, - "get": 116, + "get": 115, "if": 83, - "implements": 103, + "implements": 102, "import": 84, "in": 85, "instanceof": 86, - "interface": 104, - "let": 105, - "module": 117, + "interface": 103, + "let": 104, + "module": 116, "new": 87, "null": 88, - "number": 119, - "package": 106, - "private": 107, - "protected": 108, - "public": 109, - "require": 118, + "number": 118, + "package": 105, + "private": 106, + "protected": 107, + "public": 108, + "require": 117, "return": 89, - "set": 120, - "static": 110, - "string": 121, + "set": 119, + "static": 109, + "string": 120, "super": 90, "switch": 91, - "symbol": 122, + "symbol": 121, "this": 92, "throw": 93, "true": 94, "try": 95, - "type": 123, + "type": 122, "typeof": 96, "var": 97, "void": 98, "while": 99, "with": 100, - "yield": 111, + "yield": 110, "of": 124, "{": 14, "}": 15, @@ -2071,11 +2075,15 @@ var ts; return false; } function isUnicodeIdentifierStart(code, languageVersion) { - return languageVersion >= 1 ? lookupInUnicodeMap(code, unicodeES5IdentifierStart) : lookupInUnicodeMap(code, unicodeES3IdentifierStart); + return languageVersion >= 1 ? + lookupInUnicodeMap(code, unicodeES5IdentifierStart) : + lookupInUnicodeMap(code, unicodeES3IdentifierStart); } ts.isUnicodeIdentifierStart = isUnicodeIdentifierStart; function isUnicodeIdentifierPart(code, languageVersion) { - return languageVersion >= 1 ? lookupInUnicodeMap(code, unicodeES5IdentifierPart) : lookupInUnicodeMap(code, unicodeES3IdentifierPart); + return languageVersion >= 1 ? + lookupInUnicodeMap(code, unicodeES5IdentifierPart) : + lookupInUnicodeMap(code, unicodeES3IdentifierPart); } function makeReverseMap(source) { var result = []; @@ -2364,6 +2372,7 @@ var ts; var token; var tokenValue; var precedingLineBreak; + var hasExtendedUnicodeEscape; var tokenIsUnterminated; function error(message, length) { if (onError) { @@ -2413,10 +2422,16 @@ var ts; } return +(text.substring(start, pos)); } - function scanHexDigits(count, mustMatchCount) { + function scanExactNumberOfHexDigits(count) { + return scanHexDigits(count, false); + } + function scanMinimumNumberOfHexDigits(count) { + return scanHexDigits(count, true); + } + function scanHexDigits(minCount, scanAsManyAsPossible) { var digits = 0; var value = 0; - while (digits < count || !mustMatchCount) { + while (digits < minCount || scanAsManyAsPossible) { var ch = text.charCodeAt(pos); if (ch >= 48 && ch <= 57) { value = value * 16 + ch - 48; @@ -2433,7 +2448,7 @@ var ts; pos++; digits++; } - if (digits < count) { + if (digits < minCount) { value = -1; } return value; @@ -2546,16 +2561,15 @@ var ts; return "\'"; case 34: return "\""; - case 120: case 117: - var ch = scanHexDigits(ch === 120 ? 2 : 4, true); - if (ch >= 0) { - return String.fromCharCode(ch); - } - else { - error(ts.Diagnostics.Hexadecimal_digit_expected); - return ""; + if (pos < len && text.charCodeAt(pos) === 123) { + hasExtendedUnicodeEscape = true; + pos++; + return scanExtendedUnicodeEscape(); } + return scanHexadecimalEscape(4); + case 120: + return scanHexadecimalEscape(2); case 13: if (pos < len && text.charCodeAt(pos) === 10) { pos++; @@ -2568,11 +2582,57 @@ var ts; return String.fromCharCode(ch); } } + function scanHexadecimalEscape(numDigits) { + var escapedValue = scanExactNumberOfHexDigits(numDigits); + if (escapedValue >= 0) { + return String.fromCharCode(escapedValue); + } + else { + error(ts.Diagnostics.Hexadecimal_digit_expected); + return ""; + } + } + function scanExtendedUnicodeEscape() { + var escapedValue = scanMinimumNumberOfHexDigits(1); + var isInvalidExtendedEscape = false; + if (escapedValue < 0) { + error(ts.Diagnostics.Hexadecimal_digit_expected); + isInvalidExtendedEscape = true; + } + else if (escapedValue > 0x10FFFF) { + error(ts.Diagnostics.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive); + isInvalidExtendedEscape = true; + } + if (pos >= len) { + error(ts.Diagnostics.Unexpected_end_of_text); + isInvalidExtendedEscape = true; + } + else if (text.charCodeAt(pos) == 125) { + pos++; + } + else { + error(ts.Diagnostics.Unterminated_Unicode_escape_sequence); + isInvalidExtendedEscape = true; + } + if (isInvalidExtendedEscape) { + return ""; + } + return utf16EncodeAsString(escapedValue); + } + function utf16EncodeAsString(codePoint) { + ts.Debug.assert(0x0 <= codePoint && codePoint <= 0x10FFFF); + if (codePoint <= 65535) { + return String.fromCharCode(codePoint); + } + var codeUnit1 = Math.floor((codePoint - 65536) / 1024) + 0xD800; + var codeUnit2 = ((codePoint - 65536) % 1024) + 0xDC00; + return String.fromCharCode(codeUnit1, codeUnit2); + } function peekUnicodeEscape() { if (pos + 5 < len && text.charCodeAt(pos + 1) === 117) { var start = pos; pos += 2; - var value = scanHexDigits(4, true); + var value = scanExactNumberOfHexDigits(4); pos = start; return value; } @@ -2634,6 +2694,7 @@ var ts; } function scan() { startPos = pos; + hasExtendedUnicodeEscape = false; precedingLineBreak = false; tokenIsUnterminated = false; while (true) { @@ -2785,7 +2846,7 @@ var ts; case 48: if (pos + 2 < len && (text.charCodeAt(pos + 1) === 88 || text.charCodeAt(pos + 1) === 120)) { pos += 2; - var value = scanHexDigits(1, false); + var value = scanMinimumNumberOfHexDigits(1); if (value < 0) { error(ts.Diagnostics.Hexadecimal_digit_expected); value = 0; @@ -3055,6 +3116,7 @@ var ts; getTokenPos: function () { return tokenPos; }, getTokenText: function () { return text.substring(tokenPos, pos); }, getTokenValue: function () { return tokenValue; }, + hasExtendedUnicodeEscape: function () { return hasExtendedUnicodeEscape; }, hasPrecedingLineBreak: function () { return precedingLineBreak; }, isIdentifier: function () { return token === 64 || token > 100; }, isReservedWord: function () { return token >= 65 && token <= 100; }, @@ -3203,35 +3265,51 @@ var ts; return ts.getBaseFileName(moduleName).replace(/\W/g, "_"); } ts.makeIdentifierFromModuleName = makeIdentifierFromModuleName; + function isBlockOrCatchScoped(declaration) { + return (getCombinedNodeFlags(declaration) & 12288) !== 0 || + isCatchClauseVariableDeclaration(declaration); + } + ts.isBlockOrCatchScoped = isBlockOrCatchScoped; + function isCatchClauseVariableDeclaration(declaration) { + return declaration && + declaration.kind === 193 && + declaration.parent && + declaration.parent.kind === 216; + } + ts.isCatchClauseVariableDeclaration = isCatchClauseVariableDeclaration; function declarationNameToString(name) { return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name); } ts.declarationNameToString = declarationNameToString; function createDiagnosticForNode(node, message, arg0, arg1, arg2) { - node = getErrorSpanForNode(node); - var file = getSourceFileOfNode(node); - var start = getTokenPosOfNode(node, file); - var length = node.end - start; - return ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2); + var sourceFile = getSourceFileOfNode(node); + var span = getErrorSpanForNode(sourceFile, node); + return ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2); } ts.createDiagnosticForNode = createDiagnosticForNode; function createDiagnosticForNodeFromMessageChain(node, messageChain) { - node = getErrorSpanForNode(node); - var file = getSourceFileOfNode(node); - var start = ts.skipTrivia(file.text, node.pos); - var length = node.end - start; + var sourceFile = getSourceFileOfNode(node); + var span = getErrorSpanForNode(sourceFile, node); return { - file: file, - start: start, - length: length, + file: sourceFile, + start: span.start, + length: span.length, code: messageChain.code, category: messageChain.category, messageText: messageChain.next ? messageChain : messageChain.messageText }; } ts.createDiagnosticForNodeFromMessageChain = createDiagnosticForNodeFromMessageChain; - function getErrorSpanForNode(node) { - var errorSpan; + function getSpanOfTokenAtPosition(sourceFile, pos) { + var scanner = ts.createScanner(sourceFile.languageVersion, true, sourceFile.text); + scanner.setTextPos(pos); + scanner.scan(); + var start = scanner.getTokenPos(); + return createTextSpanFromBounds(start, scanner.getTextPos()); + } + ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; + function getErrorSpanForNode(sourceFile, node) { + var errorNode = node; switch (node.kind) { case 193: case 150: @@ -3240,10 +3318,18 @@ var ts; case 200: case 199: case 219: - errorSpan = node.name; + case 195: + case 160: + errorNode = node.name; break; } - return errorSpan && errorSpan.pos < errorSpan.end ? errorSpan : node; + if (errorNode === undefined) { + return getSpanOfTokenAtPosition(sourceFile, node.pos); + } + var pos = nodeIsMissing(errorNode) + ? errorNode.pos + : ts.skipTrivia(sourceFile.text, errorNode.pos); + return createTextSpanFromBounds(pos, errorNode.end); } ts.getErrorSpanForNode = getErrorSpanForNode; function isExternalModule(file) { @@ -3251,7 +3337,7 @@ var ts; } ts.isExternalModule = isExternalModule; function isDeclarationFile(file) { - return (file.flags & 1024) !== 0; + return (file.flags & 2048) !== 0; } ts.isDeclarationFile = isDeclarationFile; function isConstEnumDeclaration(node) { @@ -3281,11 +3367,11 @@ var ts; } ts.getCombinedNodeFlags = getCombinedNodeFlags; function isConst(node) { - return !!(getCombinedNodeFlags(node) & 4096); + return !!(getCombinedNodeFlags(node) & 8192); } ts.isConst = isConst; function isLet(node) { - return !!(getCombinedNodeFlags(node) & 2048); + return !!(getCombinedNodeFlags(node) & 4096); } ts.isLet = isLet; function isPrologueDirective(node) { @@ -3337,7 +3423,24 @@ var ts; } } ts.forEachReturnStatement = forEachReturnStatement; - function isAnyFunction(node) { + function isVariableLike(node) { + if (node) { + switch (node.kind) { + case 150: + case 219: + case 128: + case 217: + case 130: + case 129: + case 218: + case 193: + return true; + } + } + return false; + } + ts.isVariableLike = isVariableLike; + function isFunctionLike(node) { if (node) { switch (node.kind) { case 133: @@ -3361,9 +3464,9 @@ var ts; } return false; } - ts.isAnyFunction = isAnyFunction; + ts.isFunctionLike = isFunctionLike; function isFunctionBlock(node) { - return node && node.kind === 174 && isAnyFunction(node.parent); + return node && node.kind === 174 && isFunctionLike(node.parent); } ts.isFunctionBlock = isFunctionBlock; function isObjectLiteralMethod(node) { @@ -3373,7 +3476,7 @@ var ts; function getContainingFunction(node) { while (true) { node = node.parent; - if (!node || isAnyFunction(node)) { + if (!node || isFunctionLike(node)) { return node; } } @@ -3611,12 +3714,12 @@ var ts; } ts.isTemplateLiteralKind = isTemplateLiteralKind; function isBindingPattern(node) { - return node.kind === 149 || node.kind === 148; + return !!node && (node.kind === 149 || node.kind === 148); } ts.isBindingPattern = isBindingPattern; function isInAmbientContext(node) { while (node) { - if (node.flags & (2 | 1024)) { + if (node.flags & (2 | 2048)) { return true; } node = node.parent; @@ -3626,31 +3729,33 @@ var ts; ts.isInAmbientContext = isInAmbientContext; function isDeclaration(node) { switch (node.kind) { - case 127: - case 128: - case 193: + case 161: case 150: - case 130: - case 129: - case 217: - case 218: + case 196: + case 133: + case 199: case 219: + case 211: + case 195: + case 160: + case 134: + case 204: + case 202: + case 207: + case 197: case 132: case 131: - case 195: - case 134: - case 135: - case 133: - case 196: - case 197: - case 198: - case 199: case 200: - case 202: - case 204: - case 207: case 205: - case 211: + case 128: + case 217: + case 130: + case 129: + case 135: + case 218: + case 198: + case 127: + case 193: return true; } return false; @@ -3683,27 +3788,29 @@ var ts; } } ts.isStatement = isStatement; - function isDeclarationOrFunctionExpressionOrCatchVariableName(name) { + function isDeclarationName(name) { if (name.kind !== 64 && name.kind !== 8 && name.kind !== 7) { return false; } var parent = name.parent; - if (isDeclaration(parent) || parent.kind === 160) { - return parent.name === name; + if (parent.kind === 207 || parent.kind === 211) { + if (parent.propertyName) { + return true; + } } - if (parent.kind === 216) { + if (isDeclaration(parent)) { return parent.name === name; } return false; } - ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName; + ts.isDeclarationName = isDeclarationName; function getClassBaseTypeNode(node) { var heritageClause = getHeritageClause(node.heritageClauses, 78); return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined; } ts.getClassBaseTypeNode = getClassBaseTypeNode; function getClassImplementedTypeNodes(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 103); + var heritageClause = getHeritageClause(node.heritageClauses, 102); return heritageClause ? heritageClause.types : undefined; } ts.getClassImplementedTypeNodes = getClassImplementedTypeNodes; @@ -3817,13 +3924,14 @@ var ts; ts.isESSymbolIdentifier = isESSymbolIdentifier; function isModifier(token) { switch (token) { - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: case 77: - case 115: + case 114: case 69: + case 72: return true; } return false; @@ -3938,6 +4046,42 @@ var ts; return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); } ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; + function nodeStartsNewLexicalEnvironment(n) { + return isFunctionLike(n) || n.kind === 200 || n.kind === 220; + } + ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment; + function nodeIsSynthesized(node) { + return node.pos === -1 && node.end === -1; + } + ts.nodeIsSynthesized = nodeIsSynthesized; + function createSynthesizedNode(kind, startsOnNewLine) { + var node = ts.createNode(kind); + node.pos = -1; + node.end = -1; + node.startsOnNewLine = startsOnNewLine; + return node; + } + ts.createSynthesizedNode = createSynthesizedNode; + function generateUniqueName(baseName, isExistingName) { + if (baseName.charCodeAt(0) !== 95) { + var baseName = "_" + baseName; + if (!isExistingName(baseName)) { + return baseName; + } + } + if (baseName.charCodeAt(baseName.length - 1) !== 95) { + baseName += "_"; + } + var i = 1; + while (true) { + var name = baseName + i; + if (!isExistingName(name)) { + return name; + } + i++; + } + } + ts.generateUniqueName = generateUniqueName; function createDiagnosticCollection() { var nonFileDiagnostics = []; var fileDiagnostics = {}; @@ -4003,6 +4147,41 @@ var ts; } } ts.createDiagnosticCollection = createDiagnosticCollection; + var escapedCharsRegExp = /[\\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g; + var escapedCharsMap = { + "\0": "\\0", + "\t": "\\t", + "\v": "\\v", + "\f": "\\f", + "\b": "\\b", + "\r": "\\r", + "\n": "\\n", + "\\": "\\\\", + "\"": "\\\"", + "\u2028": "\\u2028", + "\u2029": "\\u2029", + "\u0085": "\\u0085" + }; + function escapeString(s) { + s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s; + return s; + function getReplacement(c) { + return escapedCharsMap[c] || get16BitUnicodeEscapeSequence(c.charCodeAt(0)); + } + } + ts.escapeString = escapeString; + function get16BitUnicodeEscapeSequence(charCode) { + var hexCharCode = charCode.toString(16).toUpperCase(); + var paddedHexCode = ("0000" + hexCharCode).slice(-4); + return "\\u" + paddedHexCode; + } + var nonAsciiCharacters = /[^\u0000-\u007F]/g; + function escapeNonAsciiCharacters(s) { + return nonAsciiCharacters.test(s) ? + s.replace(nonAsciiCharacters, function (c) { return get16BitUnicodeEscapeSequence(c.charCodeAt(0)); }) : + s; + } + ts.escapeNonAsciiCharacters = escapeNonAsciiCharacters; })(ts || (ts = {})); var ts; (function (ts) { @@ -4113,6 +4292,7 @@ var ts; return visitNodes(cbNodes, node.properties); case 153: return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.dotToken) || visitNode(cbNode, node.name); case 154: return visitNode(cbNode, node.expression) || @@ -4149,7 +4329,9 @@ var ts; visitNode(cbNode, node.right); case 168: return visitNode(cbNode, node.condition) || + visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || + visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 171: return visitNode(cbNode, node.expression); @@ -4215,8 +4397,7 @@ var ts; visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 216: - return visitNode(cbNode, node.name) || - visitNode(cbNode, node.type) || + return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 196: return visitNodes(cbNodes, node.modifiers) || @@ -4271,7 +4452,7 @@ var ts; visitNode(cbNode, node.name); case 208: return visitNodes(cbNodes, node.modifiers) || - visitNode(cbNode, node.exportName); + visitNode(cbNode, node.expression); case 169: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 173: @@ -4344,13 +4525,14 @@ var ts; ; function modifierToFlag(token) { switch (token) { - case 110: return 128; - case 109: return 16; - case 108: return 64; - case 107: return 32; + case 109: return 128; + case 108: return 16; + case 107: return 64; + case 106: return 32; case 77: return 1; - case 115: return 2; - case 69: return 4096; + case 114: return 2; + case 69: return 8192; + case 72: return 256; } return 0; } @@ -4676,7 +4858,7 @@ var ts; sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = ts.normalizePath(fileName); - sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 1024 : 0; + sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 2048 : 0; var contextFlags = 0; var parseErrorBeforeNextFinishedNode = false; var scanner = ts.createScanner(languageVersion, true, sourceText, scanError); @@ -4804,7 +4986,9 @@ var ts; var saveParseDiagnosticsLength = sourceFile.parseDiagnostics.length; var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; var saveContextFlags = contextFlags; - var result = isLookAhead ? scanner.lookAhead(callback) : scanner.tryScan(callback); + var result = isLookAhead + ? scanner.lookAhead(callback) + : scanner.tryScan(callback); ts.Debug.assert(saveContextFlags === contextFlags); if (!result || isLookAhead) { token = saveToken; @@ -4823,10 +5007,10 @@ var ts; if (token === 64) { return true; } - if (token === 111 && inYieldContext()) { + if (token === 110 && inYieldContext()) { return false; } - return inStrictModeContext() ? token > 111 : token > 100; + return inStrictModeContext() ? token > 110 : token > 100; } function parseExpected(kind, diagnosticMessage) { if (token === kind) { @@ -4850,12 +5034,14 @@ var ts; } function parseOptionalToken(t) { if (token === t) { - var node = createNode(t); - nextToken(); - return finishNode(node); + return parseTokenNode(); } return undefined; } + function parseExpectedToken(t, reportAtCurrentPosition, diagnosticMessage, arg0) { + return parseOptionalToken(t) || + createMissingNode(t, reportAtCurrentPosition, diagnosticMessage, arg0); + } function parseTokenNode() { var node = createNode(token); nextToken(); @@ -4974,13 +5160,26 @@ var ts; } if (token === 77) { nextToken(); + if (token === 72) { + return lookAhead(nextTokenIsClassOrFunction); + } return token !== 35 && token !== 14 && canFollowModifier(); } + if (token === 72) { + return nextTokenIsClassOrFunction(); + } nextToken(); return canFollowModifier(); } function canFollowModifier() { - return token === 18 || token === 14 || token === 35 || isLiteralPropertyName(); + return token === 18 + || token === 14 + || token === 35 + || isLiteralPropertyName(); + } + function nextTokenIsClassOrFunction() { + nextToken(); + return token === 68 || token === 82; } function isListElement(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); @@ -5034,7 +5233,7 @@ var ts; return isIdentifier(); } function isNotHeritageClauseTypeName() { - if (token === 103 || + if (token === 102 || token === 78) { return lookAhead(nextTokenIsIdentifier); } @@ -5058,11 +5257,11 @@ var ts; case 4: return token === 15 || token === 66 || token === 72; case 8: - return token === 14 || token === 78 || token === 103; + return token === 14 || token === 78 || token === 102; case 9: return isVariableDeclaratorListTerminator(); case 16: - return token === 25 || token === 16 || token === 14 || token === 78 || token === 103; + return token === 25 || token === 16 || token === 14 || token === 78 || token === 102; case 12: return token === 17 || token === 22; case 14: @@ -5398,7 +5597,7 @@ var ts; literal = parseLiteralNode(); } else { - literal = createMissingNode(13, false, ts.Diagnostics._0_expected, ts.tokenToString(15)); + literal = parseExpectedToken(13, false, ts.Diagnostics._0_expected, ts.tokenToString(15)); } span.literal = literal; return finishNode(span); @@ -5407,14 +5606,19 @@ var ts; var node = createNode(token); var text = scanner.getTokenValue(); node.text = internName ? internIdentifier(text) : text; + if (scanner.hasExtendedUnicodeEscape()) { + node.hasExtendedUnicodeEscape = true; + } if (scanner.isUnterminated()) { node.isUnterminated = true; } var tokenPos = scanner.getTokenPos(); nextToken(); finishNode(node); - if (node.kind === 7 && sourceText.charCodeAt(tokenPos) === 48 && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { - node.flags |= 8192; + if (node.kind === 7 + && sourceText.charCodeAt(tokenPos) === 48 + && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { + node.flags |= 16384; } return node; } @@ -5452,7 +5656,9 @@ var ts; } function parseParameterType() { if (parseOptional(51)) { - return token === 8 ? parseLiteralNode(true) : parseType(); + return token === 8 + ? parseLiteralNode(true) + : parseType(); } return undefined; } @@ -5622,7 +5828,9 @@ var ts; case 24: return parseSignatureMember(136); case 18: - return isIndexSignature() ? parseIndexSignatureDeclaration(undefined) : parsePropertyOrMethodSignature(); + return isIndexSignature() + ? parseIndexSignatureDeclaration(undefined) + : parsePropertyOrMethodSignature(); case 87: if (lookAhead(isStartOfConstructSignature)) { return parseSignatureMember(137); @@ -5644,7 +5852,9 @@ var ts; } function parseIndexSignatureWithModifiers() { var modifiers = parseModifiers(); - return isIndexSignature() ? parseIndexSignatureDeclaration(modifiers) : undefined; + return isIndexSignature() + ? parseIndexSignatureDeclaration(modifiers) + : undefined; } function isStartOfConstructSignature() { nextToken(); @@ -5692,11 +5902,11 @@ var ts; } function parseNonArrayType() { switch (token) { + case 111: + case 120: + case 118: case 112: case 121: - case 119: - case 113: - case 122: var node = tryParse(parseKeywordAndNoDot); return node || parseTypeReference(); case 98: @@ -5715,11 +5925,11 @@ var ts; } function isStartOfType() { switch (token) { + case 111: + case 120: + case 118: case 112: case 121: - case 119: - case 113: - case 122: case 98: case 96: case 14: @@ -5840,7 +6050,7 @@ var ts; case 39: case 24: case 64: - case 111: + case 110: return true; default: if (isBinaryOperator()) { @@ -5887,7 +6097,7 @@ var ts; return parseConditionalExpressionRest(expr); } function isYieldExpression() { - if (token === 111) { + if (token === 110) { if (inYieldContext()) { return true; } @@ -5933,7 +6143,9 @@ var ts; if (triState === 0) { return undefined; } - var arrowFunction = triState === 1 ? parseParenthesizedArrowFunctionExpressionHead(true) : tryParse(parsePossibleParenthesizedArrowFunctionExpressionHead); + var arrowFunction = triState === 1 + ? parseParenthesizedArrowFunctionExpressionHead(true) + : tryParse(parsePossibleParenthesizedArrowFunctionExpressionHead); if (!arrowFunction) { return undefined; } @@ -6012,13 +6224,15 @@ var ts; return parseAssignmentExpressionOrHigher(); } function parseConditionalExpressionRest(leftOperand) { - if (!parseOptional(50)) { + var questionToken = parseOptionalToken(50); + if (!questionToken) { return leftOperand; } var node = createNode(168, leftOperand.pos); node.condition = leftOperand; + node.questionToken = questionToken; node.whenTrue = allowInAnd(parseAssignmentExpressionOrHigher); - parseExpected(51); + node.colonToken = parseExpectedToken(51, false, ts.Diagnostics._0_expected, ts.tokenToString(51)); node.whenFalse = parseAssignmentExpressionOrHigher(); return finishNode(node); } @@ -6153,7 +6367,9 @@ var ts; return expression; } function parseLeftHandSideExpressionOrHigher() { - var expression = token === 90 ? parseSuperExpression() : parseMemberExpressionOrHigher(); + var expression = token === 90 + ? parseSuperExpression() + : parseMemberExpressionOrHigher(); return parseCallExpressionRest(expression); } function parseMemberExpressionOrHigher() { @@ -6167,7 +6383,7 @@ var ts; } var node = createNode(153, expression.pos); node.expression = expression; - parseExpected(20, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); + node.dotToken = parseExpectedToken(20, false, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); node.name = parseRightSideOfDot(true); return finishNode(node); } @@ -6181,10 +6397,11 @@ var ts; } function parseMemberExpressionRest(expression) { while (true) { - var dotOrBracketStart = scanner.getTokenPos(); - if (parseOptional(20)) { + var dotToken = parseOptionalToken(20); + if (dotToken) { var propertyAccess = createNode(153, expression.pos); propertyAccess.expression = expression; + propertyAccess.dotToken = dotToken; propertyAccess.name = parseRightSideOfDot(true); expression = finishNode(propertyAccess); continue; @@ -6206,7 +6423,9 @@ var ts; if (token === 10 || token === 11) { var tagExpression = createNode(157, expression.pos); tagExpression.tag = expression; - tagExpression.template = token === 10 ? parseLiteralNode() : parseTemplateExpression(); + tagExpression.template = token === 10 + ? parseLiteralNode() + : parseTemplateExpression(); expression = finishNode(tagExpression); continue; } @@ -6252,7 +6471,9 @@ var ts; if (!parseExpected(25)) { return undefined; } - return typeArguments && canFollowTypeArgumentsInExpression() ? typeArguments : undefined; + return typeArguments && canFollowTypeArgumentsInExpression() + ? typeArguments + : undefined; } function canFollowTypeArgumentsInExpression() { switch (token) { @@ -6327,7 +6548,9 @@ var ts; return finishNode(node); } function parseArgumentOrArrayLiteralElement() { - return token === 21 ? parseSpreadElement() : token === 23 ? createNode(172) : parseAssignmentExpressionOrHigher(); + return token === 21 ? parseSpreadElement() : + token === 23 ? createNode(172) : + parseAssignmentExpressionOrHigher(); } function parseArgumentExpression() { return allowInAnd(parseArgumentOrArrayLiteralElement); @@ -6336,16 +6559,16 @@ var ts; var node = createNode(151); parseExpected(18); if (scanner.hasPrecedingLineBreak()) - node.flags |= 256; + node.flags |= 512; node.elements = parseDelimitedList(14, parseArgumentOrArrayLiteralElement); parseExpected(19); return finishNode(node); } function tryParseAccessorDeclaration(fullStart, modifiers) { - if (parseContextualModifier(116)) { + if (parseContextualModifier(115)) { return parseAccessorDeclaration(134, fullStart, modifiers); } - else if (parseContextualModifier(120)) { + else if (parseContextualModifier(119)) { return parseAccessorDeclaration(135, fullStart, modifiers); } return undefined; @@ -6384,7 +6607,7 @@ var ts; var node = createNode(152); parseExpected(14); if (scanner.hasPrecedingLineBreak()) { - node.flags |= 256; + node.flags |= 512; } node.properties = parseDelimitedList(13, parseObjectLiteralElement, true); parseExpected(15); @@ -6471,7 +6694,7 @@ var ts; parseExpected(16); var initializer = undefined; if (token !== 22) { - if (token === 97 || token === 105 || token === 69) { + if (token === 97 || token === 104 || token === 69) { initializer = parseVariableDeclarationList(true); } else { @@ -6587,9 +6810,9 @@ var ts; function parseCatchClause() { var result = createNode(216); parseExpected(67); - parseExpected(16); - result.name = parseIdentifier(); - result.type = parseTypeAnnotation(); + if (parseExpected(16)) { + result.variableDeclaration = parseVariableDeclaration(); + } parseExpected(17); result.block = parseBlock(false, false); return finishNode(result); @@ -6628,7 +6851,7 @@ var ts; return !inErrorRecovery; case 14: case 97: - case 105: + case 104: case 82: case 83: case 74: @@ -6648,18 +6871,18 @@ var ts; case 69: var isConstEnum = lookAhead(nextTokenIsEnumKeyword); return !isConstEnum; - case 104: + case 103: case 68: - case 117: + case 116: case 76: - case 123: + case 122: if (isDeclarationStart()) { return false; } - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { return false; } @@ -6712,7 +6935,7 @@ var ts; return parseTryStatement(); case 71: return parseDebuggerStatement(); - case 105: + case 104: if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), undefined); } @@ -6736,7 +6959,7 @@ var ts; return undefined; } return parseVariableStatement(start, modifiers); - case 105: + case 104: if (!isLetDeclaration()) { return undefined; } @@ -6819,11 +7042,11 @@ var ts; switch (token) { case 97: break; - case 105: - node.flags |= 2048; + case 104: + node.flags |= 4096; break; case 69: - node.flags |= 4096; + node.flags |= 8192; break; default: ts.Debug.fail(); @@ -6855,7 +7078,7 @@ var ts; setModifiers(node, modifiers); parseExpected(82); node.asteriskToken = parseOptionalToken(35); - node.name = parseIdentifier(); + node.name = node.flags & 256 ? parseOptionalIdentifier() : parseIdentifier(); fillSignature(51, !!node.asteriskToken, false, node); node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, ts.Diagnostics.or_expected); return finishNode(node); @@ -6863,7 +7086,7 @@ var ts; function parseConstructorDeclaration(pos, modifiers) { var node = createNode(133, pos); setModifiers(node, modifiers); - parseExpected(114); + parseExpected(113); fillSignature(51, false, false, node); node.body = parseFunctionBlockOrSemicolon(false, ts.Diagnostics.or_expected); return finishNode(node); @@ -6924,7 +7147,7 @@ var ts; return true; } if (idToken !== undefined) { - if (!ts.isKeyword(idToken) || idToken === 120 || idToken === 116) { + if (!ts.isKeyword(idToken) || idToken === 119 || idToken === 115) { return true; } switch (token) { @@ -6969,7 +7192,7 @@ var ts; if (accessor) { return accessor; } - if (token === 114) { + if (token === 113) { return parseConstructorDeclaration(fullStart, modifiers); } if (isIndexSignature()) { @@ -6988,11 +7211,13 @@ var ts; var node = createNode(196, fullStart); setModifiers(node, modifiers); parseExpected(68); - node.name = parseIdentifier(); + node.name = node.flags & 256 ? parseOptionalIdentifier() : parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(true); if (parseExpected(14)) { - node.members = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseClassMembers) : parseClassMembers(); + node.members = inGeneratorParameterContext() + ? doOutsideOfYieldContext(parseClassMembers) + : parseClassMembers(); parseExpected(15); } else { @@ -7002,7 +7227,9 @@ var ts; } function parseHeritageClauses(isClassHeritageClause) { if (isHeritageClause()) { - return isClassHeritageClause && inGeneratorParameterContext() ? doOutsideOfYieldContext(parseHeritageClausesWorker) : parseHeritageClausesWorker(); + return isClassHeritageClause && inGeneratorParameterContext() + ? doOutsideOfYieldContext(parseHeritageClausesWorker) + : parseHeritageClausesWorker(); } return undefined; } @@ -7010,7 +7237,7 @@ var ts; return parseList(19, false, parseHeritageClause); } function parseHeritageClause() { - if (token === 78 || token === 103) { + if (token === 78 || token === 102) { var node = createNode(215); node.token = token; nextToken(); @@ -7020,7 +7247,7 @@ var ts; return undefined; } function isHeritageClause() { - return token === 78 || token === 103; + return token === 78 || token === 102; } function parseClassMembers() { return parseList(6, false, parseClassElement); @@ -7028,7 +7255,7 @@ var ts; function parseInterfaceDeclaration(fullStart, modifiers) { var node = createNode(197, fullStart); setModifiers(node, modifiers); - parseExpected(104); + parseExpected(103); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(false); @@ -7038,7 +7265,7 @@ var ts; function parseTypeAliasDeclaration(fullStart, modifiers) { var node = createNode(198, fullStart); setModifiers(node, modifiers); - parseExpected(123); + parseExpected(122); node.name = parseIdentifier(); parseExpected(52); node.type = parseType(); @@ -7081,7 +7308,9 @@ var ts; setModifiers(node, modifiers); node.flags |= flags; node.name = parseIdentifier(); - node.body = parseOptional(20) ? parseInternalModuleTail(getNodePos(), undefined, 1) : parseModuleBlock(); + node.body = parseOptional(20) + ? parseInternalModuleTail(getNodePos(), undefined, 1) + : parseModuleBlock(); return finishNode(node); } function parseAmbientExternalModuleDeclaration(fullStart, modifiers) { @@ -7092,11 +7321,13 @@ var ts; return finishNode(node); } function parseModuleDeclaration(fullStart, modifiers) { - parseExpected(117); - return token === 8 ? parseAmbientExternalModuleDeclaration(fullStart, modifiers) : parseInternalModuleTail(fullStart, modifiers, modifiers ? modifiers.flags : 0); + parseExpected(116); + return token === 8 + ? parseAmbientExternalModuleDeclaration(fullStart, modifiers) + : parseInternalModuleTail(fullStart, modifiers, modifiers ? modifiers.flags : 0); } function isExternalModuleReference() { - return token === 118 && + return token === 117 && lookAhead(nextTokenIsOpenParen); } function nextTokenIsOpenParen() { @@ -7105,7 +7336,7 @@ var ts; function nextTokenIsCommaOrFromKeyword() { nextToken(); return token === 23 || - token === 102; + token === 123; } function parseImportDeclarationOrImportEqualsDeclaration(fullStart, modifiers) { parseExpected(84); @@ -7113,7 +7344,7 @@ var ts; var identifier; if (isIdentifier()) { identifier = parseIdentifier(); - if (token !== 23 && token !== 102) { + if (token !== 23 && token !== 123) { var importEqualsDeclaration = createNode(202, fullStart); setModifiers(importEqualsDeclaration, modifiers); importEqualsDeclaration.name = identifier; @@ -7129,7 +7360,7 @@ var ts; token === 35 || token === 14) { importDeclaration.importClause = parseImportClause(identifier, afterImportPos); - parseExpected(102); + parseExpected(123); } importDeclaration.moduleSpecifier = parseModuleSpecifier(); parseSemicolon(); @@ -7147,11 +7378,13 @@ var ts; return finishNode(importClause); } function parseModuleReference() { - return isExternalModuleReference() ? parseExternalModuleReference() : parseEntityName(false); + return isExternalModuleReference() + ? parseExternalModuleReference() + : parseEntityName(false); } function parseExternalModuleReference() { var node = createNode(212); - parseExpected(118); + parseExpected(117); parseExpected(16); node.expression = parseModuleSpecifier(); parseExpected(17); @@ -7209,22 +7442,28 @@ var ts; var node = createNode(209, fullStart); setModifiers(node, modifiers); if (parseOptional(35)) { - parseExpected(102); + parseExpected(123); node.moduleSpecifier = parseModuleSpecifier(); } else { node.exportClause = parseNamedImportsOrExports(210); - if (parseOptional(102)) { + if (parseOptional(123)) { node.moduleSpecifier = parseModuleSpecifier(); } } parseSemicolon(); return finishNode(node); } - function parseExportAssignmentTail(fullStart, modifiers) { + function parseExportAssignment(fullStart, modifiers) { var node = createNode(208, fullStart); setModifiers(node, modifiers); - node.exportName = parseIdentifier(); + if (parseOptional(52)) { + node.isExportEquals = true; + } + else { + parseExpected(72); + } + node.expression = parseAssignmentExpressionOrHigher(); parseSemicolon(); return finishNode(node); } @@ -7237,24 +7476,24 @@ var ts; case 69: case 82: return true; - case 105: + case 104: return isLetDeclaration(); case 68: - case 104: + case 103: case 76: - case 123: + case 122: return lookAhead(nextTokenIsIdentifierOrKeyword); case 84: return lookAhead(nextTokenCanFollowImportKeyword); - case 117: + case 116: return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); case 77: return lookAhead(nextTokenCanFollowExportKeyword); - case 115: - case 109: - case 107: + case 114: case 108: - case 110: + case 106: + case 107: + case 109: return lookAhead(nextTokenIsDeclarationStart); } } @@ -7277,7 +7516,7 @@ var ts; function nextTokenCanFollowExportKeyword() { nextToken(); return token === 52 || token === 35 || - token === 14 || isDeclarationStart(); + token === 14 || token === 72 || isDeclarationStart(); } function nextTokenIsDeclarationStart() { nextToken(); @@ -7291,8 +7530,8 @@ var ts; var modifiers = parseModifiers(); if (token === 77) { nextToken(); - if (parseOptional(52)) { - return parseExportAssignmentTail(fullStart, modifiers); + if (token === 72 || token === 52) { + return parseExportAssignment(fullStart, modifiers); } if (token === 35 || token === 14) { return parseExportDeclaration(fullStart, modifiers); @@ -7300,20 +7539,20 @@ var ts; } switch (token) { case 97: - case 105: + case 104: case 69: return parseVariableStatement(fullStart, modifiers); case 82: return parseFunctionDeclaration(fullStart, modifiers); case 68: return parseClassDeclaration(fullStart, modifiers); - case 104: + case 103: return parseInterfaceDeclaration(fullStart, modifiers); - case 123: + case 122: return parseTypeAliasDeclaration(fullStart, modifiers); case 76: return parseEnumDeclaration(fullStart, modifiers); - case 117: + case 116: return parseModuleDeclaration(fullStart, modifiers); case 84: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, modifiers); @@ -7331,7 +7570,9 @@ var ts; return parseSourceElementOrModuleElement(); } function parseSourceElementOrModuleElement() { - return isDeclarationStart() ? parseDeclaration() : parseStatement(); + return isDeclarationStart() + ? parseDeclaration() + : parseStatement(); } function processReferenceComments(sourceFile) { var triviaScanner = ts.createScanner(sourceFile.languageVersion, false, sourceText); @@ -7389,7 +7630,13 @@ var ts; } function setExternalModuleIndicator(sourceFile) { sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { - return node.flags & 1 || node.kind === 202 && node.moduleReference.kind === 212 || node.kind === 203 || node.kind === 208 || node.kind === 209 ? node : undefined; + return node.flags & 1 + || node.kind === 202 && node.moduleReference.kind === 212 + || node.kind === 203 + || node.kind === 208 + || node.kind === 209 + ? node + : undefined; }); } } @@ -7485,7 +7732,8 @@ var ts; var Symbol = ts.objectAllocator.getSymbolConstructor(); if (!file.locals) { file.locals = {}; - container = blockScopeContainer = file; + container = file; + setBlockScopeContainer(file, false); bind(file); file.symbolCount = symbolCount; } @@ -7493,6 +7741,12 @@ var ts; symbolCount++; return new Symbol(flags, name); } + function setBlockScopeContainer(node, cleanLocals) { + blockScopeContainer = node; + if (cleanLocals) { + blockScopeContainer.locals = undefined; + } + } function addDeclarationToSymbol(symbol, node, symbolKind) { symbol.flags |= symbolKind; if (!symbol.declarations) @@ -7529,6 +7783,13 @@ var ts; return "__new"; case 138: return "__index"; + case 209: + return "__export"; + case 208: + return "default"; + case 195: + case 196: + return node.flags & 256 ? "default" : undefined; } } function getDisplayName(node) { @@ -7536,18 +7797,20 @@ var ts; } function declareSymbol(symbols, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); - var name = getDeclarationName(node); + var name = node.flags & 256 && parent ? "default" : getDeclarationName(node); if (name !== undefined) { var symbol = ts.hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); if (symbol.flags & excludes) { if (node.name) { node.name.parent = node; } - var message = symbol.flags & 2 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + var message = symbol.flags & 2 + ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 + : ts.Diagnostics.Duplicate_identifier_0; ts.forEach(symbol.declarations, function (declaration) { - file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name, message, getDisplayName(declaration))); + file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); }); - file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name, message, getDisplayName(node))); + file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message, getDisplayName(node))); symbol = createSymbol(0, name); } } @@ -7617,7 +7880,7 @@ var ts; lastContainer = container; } if (isBlockScopeContainer) { - blockScopeContainer = node; + setBlockScopeContainer(node, (symbolKind & 255504) === 0 && node.kind !== 220); } ts.forEachChild(node, bind); container = saveContainer; @@ -7685,12 +7948,6 @@ var ts; } } } - function bindExportDeclaration(node) { - if (!node.exportClause) { - (container.exportStars || (container.exportStars = [])).push(node); - } - bindChildren(node, 0, false); - } function bindFunctionOrConstructorType(node) { var symbol = createSymbol(131072, getDeclarationName(node)); addDeclarationToSymbol(symbol, node, 131072); @@ -7706,14 +7963,7 @@ var ts; bindChildren(node, symbolKind, isBlockScopeContainer); } function bindCatchVariableDeclaration(node) { - var symbol = createSymbol(1, node.name.text || "__missing"); - addDeclarationToSymbol(symbol, node, 1); - var saveParent = parent; - var savedBlockScopeContainer = blockScopeContainer; - parent = blockScopeContainer = node; - ts.forEachChild(node, bind); - parent = saveParent; - blockScopeContainer = savedBlockScopeContainer; + bindChildren(node, 0, true); } function bindBlockScopedVariableDeclaration(node) { switch (blockScopeContainer.kind) { @@ -7750,7 +8000,7 @@ var ts; if (ts.isBindingPattern(node.name)) { bindChildren(node, 0, false); } - else if (ts.getCombinedNodeFlags(node) & 6144) { + else if (ts.isBlockOrCatchScoped(node)) { bindBlockScopedVariableDeclaration(node); } else { @@ -7832,9 +8082,6 @@ var ts; case 211: bindDeclaration(node, 8388608, 8388608, false); break; - case 209: - bindExportDeclaration(node); - break; case 204: if (node.name) { bindDeclaration(node, 8388608, 8388608, false); @@ -7843,13 +8090,28 @@ var ts; bindChildren(node, 0, false); } break; + case 209: + if (!node.exportClause) { + declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0); + } + bindChildren(node, 0, false); + break; + case 208: + if (node.expression.kind === 64) { + declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 8388608); + } + else { + declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455); + } + bindChildren(node, 0, false); + break; case 220: if (ts.isExternalModule(node)) { bindAnonymousDeclaration(node, 512, '"' + ts.removeFileExtension(node.fileName) + '"', true); break; } case 174: - bindChildren(node, 0, !ts.isAnyFunction(node.parent)); + bindChildren(node, 0, !ts.isFunctionLike(node.parent)); break; case 216: case 181: @@ -7937,8 +8199,9 @@ var ts; isValidPropertyAccess: isValidPropertyAccess, getSignatureFromDeclaration: getSignatureFromDeclaration, isImplementationOfOverload: isImplementationOfOverload, - getAliasedSymbol: resolveImport, - getEmitResolver: getEmitResolver + getAliasedSymbol: resolveAlias, + getEmitResolver: getEmitResolver, + getExportsOfExternalModule: getExportsOfExternalModule }; var undefinedSymbol = createSymbol(4 | 67108864, "undefined"); var argumentsSymbol = createSymbol(4 | 67108864, "arguments"); @@ -7972,6 +8235,7 @@ var ts; var globalRegExpType; var globalTemplateStringsArrayType; var globalESSymbolType; + var globalIterableType; var anyArrayType; var tupleTypes = {}; var unionTypes = {}; @@ -8005,7 +8269,9 @@ var ts; return emitResolver; } function error(location, message, arg0, arg1, arg2) { - var diagnostic = location ? ts.createDiagnosticForNode(location, message, arg0, arg1, arg2) : ts.createCompilerDiagnostic(message, arg0, arg1, arg2); + var diagnostic = location + ? ts.createDiagnosticForNode(location, message, arg0, arg1, arg2) + : ts.createCompilerDiagnostic(message, arg0, arg1, arg2); diagnostics.add(diagnostic); } function createSymbol(flags, name) { @@ -8091,7 +8357,8 @@ var ts; recordMergedSymbol(target, source); } else { - var message = target.flags & 2 || source.flags & 2 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + var message = target.flags & 2 || source.flags & 2 + ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; ts.forEach(source.declarations, function (node) { error(node.name ? node.name : node, message, symbolToString(source)); }); @@ -8125,13 +8392,6 @@ var ts; } } } - function extendSymbolTable(target, source) { - for (var id in source) { - if (!ts.hasProperty(target, id)) { - target[id] = source[id]; - } - } - } function getSymbolLinks(symbol) { if (symbol.flags & 67108864) return symbol; @@ -8158,7 +8418,7 @@ var ts; return symbol; } if (symbol.flags & 8388608) { - var target = resolveImport(symbol); + var target = resolveAlias(symbol); if (target === unknownSymbol || target.flags & meaning) { return symbol; } @@ -8194,7 +8454,7 @@ var ts; break; case 200: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8914931)) { - if (!(result.flags & 8388608 && getDeclarationOfImportSymbol(result).kind === 211)) { + if (!(result.flags & 8388608 && getDeclarationOfAliasSymbol(result).kind === 211)) { break loop; } result = undefined; @@ -8258,13 +8518,6 @@ var ts; break loop; } break; - case 216: - var id = location.name; - if (name === id.text) { - result = location.symbol; - break loop; - } - break; } lastLocation = location; location = location.parent; @@ -8285,7 +8538,7 @@ var ts; return undefined; } if (result.flags & 2) { - var declaration = ts.forEach(result.declarations, function (d) { return ts.getCombinedNodeFlags(d) & 6144 ? d : undefined; }); + var declaration = ts.forEach(result.declarations, function (d) { return ts.isBlockOrCatchScoped(d) ? d : undefined; }); ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); if (!isDefinedBefore(declaration, errorLocation)) { error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name)); @@ -8294,15 +8547,16 @@ var ts; } return result; } - function isImportSymbolDeclaration(node) { + function isAliasSymbolDeclaration(node) { return node.kind === 202 || node.kind === 204 && !!node.name || node.kind === 205 || node.kind === 207 || - node.kind === 211; + node.kind === 211 || + node.kind === 208; } - function getDeclarationOfImportSymbol(symbol) { - return ts.forEach(symbol.declarations, function (d) { return isImportSymbolDeclaration(d) ? d : undefined; }); + function getDeclarationOfAliasSymbol(symbol) { + return ts.forEach(symbol.declarations, function (d) { return isAliasSymbolDeclaration(d) ? d : undefined; }); } function getTargetOfImportEqualsDeclaration(node) { if (node.moduleReference.kind === 212) { @@ -8335,7 +8589,7 @@ var ts; error(name, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name)); return; } - return symbol.flags & (107455 | 793056 | 1536) ? symbol : resolveImport(symbol); + return symbol.flags & (107455 | 793056 | 1536) ? symbol : resolveAlias(symbol); } } } @@ -8343,7 +8597,12 @@ var ts; return getExternalModuleMember(node.parent.parent.parent, node); } function getTargetOfExportSpecifier(node) { - return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : resolveEntityName(node, node.propertyName || node.name, 107455 | 793056 | 1536); + return node.parent.parent.moduleSpecifier ? + getExternalModuleMember(node.parent.parent, node) : + resolveEntityName(node.propertyName || node.name, 107455 | 793056 | 1536); + } + function getTargetOfExportAssignment(node) { + return resolveEntityName(node.expression, 107455 | 793056 | 1536); } function getTargetOfImportDeclaration(node) { switch (node.kind) { @@ -8357,14 +8616,16 @@ var ts; return getTargetOfImportSpecifier(node); case 211: return getTargetOfExportSpecifier(node); + case 208: + return getTargetOfExportAssignment(node); } } - function resolveImport(symbol) { - ts.Debug.assert((symbol.flags & 8388608) !== 0, "Should only get Imports here."); + function resolveAlias(symbol) { + ts.Debug.assert((symbol.flags & 8388608) !== 0, "Should only get Alias here."); var links = getSymbolLinks(symbol); if (!links.target) { links.target = resolvingSymbol; - var node = getDeclarationOfImportSymbol(symbol); + var node = getDeclarationOfAliasSymbol(symbol); var target = getTargetOfImportDeclaration(node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; @@ -8378,6 +8639,29 @@ var ts; } return links.target; } + function markExportAsReferenced(node) { + var symbol = getSymbolOfNode(node); + var target = resolveAlias(symbol); + if (target && target !== unknownSymbol && target.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(target)) { + markAliasSymbolAsReferenced(symbol); + } + } + function markAliasSymbolAsReferenced(symbol) { + var links = getSymbolLinks(symbol); + if (!links.referenced) { + links.referenced = true; + var node = getDeclarationOfAliasSymbol(symbol); + if (node.kind === 208) { + checkExpressionCached(node.expression); + } + else if (node.kind === 211) { + checkExpressionCached(node.propertyName || node.name); + } + else if (ts.isInternalModuleImportEqualsDeclaration(node)) { + checkExpressionCached(node.moduleReference); + } + } + } function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) { if (!importDeclaration) { importDeclaration = ts.getAncestor(entityName, 202); @@ -8387,38 +8671,40 @@ var ts; entityName = entityName.parent; } if (entityName.kind === 64 || entityName.parent.kind === 125) { - return resolveEntityName(importDeclaration, entityName, 1536); + return resolveEntityName(entityName, 1536); } else { ts.Debug.assert(entityName.parent.kind === 202); - return resolveEntityName(importDeclaration, entityName, 107455 | 793056 | 1536); + return resolveEntityName(entityName, 107455 | 793056 | 1536); } } function getFullyQualifiedName(symbol) { return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol); } - function resolveEntityName(location, name, meaning) { + function resolveEntityName(name, meaning) { if (ts.getFullWidth(name) === 0) { return undefined; } if (name.kind === 64) { - var symbol = resolveName(location, name.text, meaning, ts.Diagnostics.Cannot_find_name_0, name); + var symbol = resolveName(name, name.text, meaning, ts.Diagnostics.Cannot_find_name_0, name); if (!symbol) { - return; + return undefined; } } else if (name.kind === 125) { - var namespace = resolveEntityName(location, name.left, 1536); - if (!namespace || namespace === unknownSymbol || ts.getFullWidth(name.right) === 0) - return; - var symbol = getSymbol(getExportsOfSymbol(namespace), name.right.text, meaning); + var namespace = resolveEntityName(name.left, 1536); + if (!namespace || namespace === unknownSymbol || ts.getFullWidth(name.right) === 0) { + return undefined; + } + var right = name.right; + var symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { - error(location, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(name.right)); - return; + error(right, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(right)); + return undefined; } } ts.Debug.assert((symbol.flags & 16777216) === 0, "Should never get an instantiated symbol here."); - return symbol.flags & meaning ? symbol : resolveImport(symbol); + return symbol.flags & meaning ? symbol : resolveAlias(symbol); } function isExternalModuleNameRelative(moduleName) { return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; @@ -8458,6 +8744,9 @@ var ts; } error(moduleReferenceLiteral, ts.Diagnostics.Cannot_find_external_module_0, moduleName); } + function getExportAssignmentSymbol(moduleSymbol) { + return moduleSymbol.exports["default"]; + } function getResolvedExportAssignmentSymbol(moduleSymbol) { var symbol = getExportAssignmentSymbol(moduleSymbol); if (symbol) { @@ -8465,82 +8754,52 @@ var ts; return symbol; } if (symbol.flags & 8388608) { - return resolveImport(symbol); + return resolveAlias(symbol); } } } - function getExportAssignmentSymbol(symbol) { - checkTypeOfExportAssignmentSymbol(symbol); - return getSymbolLinks(symbol).exportAssignmentSymbol; - } - function checkTypeOfExportAssignmentSymbol(containerSymbol) { - var symbolLinks = getSymbolLinks(containerSymbol); - if (!symbolLinks.exportAssignmentChecked) { - var exportInformation = collectExportInformationForSourceFileOrModule(containerSymbol); - if (exportInformation.exportAssignments.length) { - if (exportInformation.exportAssignments.length > 1) { - ts.forEach(exportInformation.exportAssignments, function (node) { return error(node, ts.Diagnostics.A_module_cannot_have_more_than_one_export_assignment); }); - } - var node = exportInformation.exportAssignments[0]; - if (exportInformation.hasExportedMember) { - error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); - } - if (node.exportName.text) { - var meaning = 107455 | 793056 | 1536; - var exportSymbol = resolveName(node, node.exportName.text, meaning, ts.Diagnostics.Cannot_find_name_0, node.exportName); - } - symbolLinks.exportAssignmentSymbol = exportSymbol || unknownSymbol; - } - symbolLinks.exportAssignmentChecked = true; - } - } - function collectExportInformationForSourceFileOrModule(symbol) { - var seenExportedMember = false; - var result = []; - ts.forEach(symbol.declarations, function (declaration) { - var block = (declaration.kind === 220 ? declaration : declaration.body); - ts.forEach(block.statements, function (node) { - if (node.kind === 208) { - result.push(node); - } - else { - seenExportedMember = seenExportedMember || (node.flags & 1) !== 0; - } - }); - }); - return { - hasExportedMember: seenExportedMember, - exportAssignments: result - }; - } function getExportsOfSymbol(symbol) { return symbol.flags & 1536 ? getExportsOfModule(symbol) : symbol.exports; } - function getExportsOfModule(symbol) { - var links = getSymbolLinks(symbol); - return links.resolvedExports || (links.resolvedExports = getExportsForModule(symbol)); + function getExportsOfModule(moduleSymbol) { + var links = getSymbolLinks(moduleSymbol); + return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol)); } - function getExportsForModule(symbol) { + function extendExportSymbols(target, source) { + for (var id in source) { + if (id !== "default" && !ts.hasProperty(target, id)) { + target[id] = source[id]; + } + } + } + function getExportsForModule(moduleSymbol) { + if (compilerOptions.target < 2) { + var defaultSymbol = getExportAssignmentSymbol(moduleSymbol); + if (defaultSymbol) { + return { + "default": defaultSymbol + }; + } + } var result; var visitedSymbols = []; - visit(symbol); - return result; + visit(moduleSymbol); + return result || moduleSymbol.exports; function visit(symbol) { if (!ts.contains(visitedSymbols, symbol)) { visitedSymbols.push(symbol); - if (!result) { - result = symbol.exports; - } - else { - extendSymbolTable(result, symbol.exports); - } - ts.forEach(symbol.declarations, function (node) { - if (node.kind === 220 || node.kind === 200) { - ts.forEach(node.exportStars, function (exportStar) { - visit(resolveExternalModuleName(exportStar, exportStar.moduleSpecifier)); - }); + if (symbol !== moduleSymbol) { + if (!result) { + result = cloneSymbolTable(moduleSymbol.exports); } - }); + extendExportSymbols(result, symbol.exports); + } + var exportStars = symbol.exports["__export"]; + if (exportStars) { + ts.forEach(exportStars.declarations, function (node) { + visit(resolveExternalModuleName(node, node.moduleSpecifier)); + }); + } } } } @@ -8555,7 +8814,9 @@ var ts; return getMergedSymbol(symbol.parent); } function getExportSymbolOfValueSymbolIfExported(symbol) { - return symbol && (symbol.flags & 1048576) !== 0 ? getMergedSymbol(symbol.exportSymbol) : symbol; + return symbol && (symbol.flags & 1048576) !== 0 + ? getMergedSymbol(symbol.exportSymbol) + : symbol; } function symbolIsValue(symbol) { if (symbol.flags & 16777216) { @@ -8565,7 +8826,7 @@ var ts; return true; } if (symbol.flags & 8388608) { - return (resolveImport(symbol).flags & 107455) !== 0; + return (resolveAlias(symbol).flags & 107455) !== 0; } return false; } @@ -8682,8 +8943,8 @@ var ts; if (symbolFromSymbolTable.flags & 8388608) { if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, ts.isExternalModuleImportEqualsDeclaration)) { - var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); - if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { + var resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable); + if (isAccessible(symbolFromSymbolTable, resolveAlias(symbolFromSymbolTable))) { return [symbolFromSymbolTable]; } var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; @@ -8708,7 +8969,7 @@ var ts; if (symbolFromSymbolTable === symbol) { return true; } - symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608) ? resolveImport(symbolFromSymbolTable) : symbolFromSymbolTable; + symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; if (symbolFromSymbolTable.flags & meaning) { qualify = true; return true; @@ -8999,7 +9260,7 @@ var ts; buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); } else { - writeKeyword(writer, 112); + writeKeyword(writer, 111); } } else { @@ -9090,7 +9351,7 @@ var ts; writer.writeParameter(getIndexerParameterName(resolved, 0, "x")); writePunctuation(writer, 51); writeSpace(writer); - writeKeyword(writer, 121); + writeKeyword(writer, 120); writePunctuation(writer, 19); writePunctuation(writer, 51); writeSpace(writer); @@ -9103,7 +9364,7 @@ var ts; writer.writeParameter(getIndexerParameterName(resolved, 1, "x")); writePunctuation(writer, 51); writeSpace(writer); - writeKeyword(writer, 119); + writeKeyword(writer, 118); writePunctuation(writer, 19); writePunctuation(writer, 51); writeSpace(writer); @@ -9268,7 +9529,7 @@ var ts; return true; } if (symbolOfNode.flags & 8388608) { - return isSymbolUsedInExportAssignment(resolveImport(symbolOfNode)); + return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode)); } } function isSymbolUsedInExportAssignment(symbol) { @@ -9276,7 +9537,7 @@ var ts; return true; } if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & 8388608)) { - resolvedExportSymbol = resolvedExportSymbol || resolveImport(exportAssignmentSymbol); + resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol); if (resolvedExportSymbol === symbol) { return true; } @@ -9410,6 +9671,9 @@ var ts; if (declaration.parent.parent.kind === 182) { return anyType; } + if (declaration.parent.parent.kind === 183) { + return getTypeForVariableDeclarationInForOfStatement(declaration.parent.parent); + } if (ts.isBindingPattern(declaration.parent)) { return getTypeForBindingElement(declaration); } @@ -9469,7 +9733,9 @@ var ts; return !elementTypes.length ? anyArrayType : hasSpreadElement ? createArrayType(getUnionType(elementTypes)) : createTupleType(elementTypes); } function getTypeFromBindingPattern(pattern) { - return pattern.kind === 148 ? getTypeFromObjectBindingPattern(pattern) : getTypeFromArrayBindingPattern(pattern); + return pattern.kind === 148 + ? getTypeFromObjectBindingPattern(pattern) + : getTypeFromArrayBindingPattern(pattern); } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { var type = getTypeForVariableLikeDeclaration(declaration); @@ -9498,9 +9764,12 @@ var ts; return links.type = getTypeOfPrototypeProperty(symbol); } var declaration = symbol.valueDeclaration; - if (declaration.kind === 216) { + if (declaration.parent.kind === 216) { return links.type = anyType; } + if (declaration.kind === 208) { + return links.type = checkExpression(declaration.expression); + } links.type = resolvingType; var type = getWidenedTypeForVariableLikeDeclaration(declaration, true); if (links.type === resolvingType) { @@ -9510,7 +9779,9 @@ var ts; else if (links.type === resolvingType) { links.type = anyType; if (compilerOptions.noImplicitAny) { - var diagnostic = symbol.valueDeclaration.type ? ts.Diagnostics._0_implicitly_has_type_any_because_it_is_referenced_directly_or_indirectly_in_its_own_type_annotation : ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer; + var diagnostic = symbol.valueDeclaration.type ? + ts.Diagnostics._0_implicitly_has_type_any_because_it_is_referenced_directly_or_indirectly_in_its_own_type_annotation : + ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer; error(symbol.valueDeclaration, diagnostic, symbolToString(symbol)); } } @@ -9590,10 +9861,10 @@ var ts; } return links.type; } - function getTypeOfImport(symbol) { + function getTypeOfAlias(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { - links.type = getTypeOfSymbol(resolveImport(symbol)); + links.type = getTypeOfSymbol(resolveAlias(symbol)); } return links.type; } @@ -9621,7 +9892,7 @@ var ts; return getTypeOfAccessors(symbol); } if (symbol.flags & 8388608) { - return getTypeOfImport(symbol); + return getTypeOfAlias(symbol); } return unknownType; } @@ -9775,10 +10046,10 @@ var ts; } return links.declaredType; } - function getDeclaredTypeOfImport(symbol) { + function getDeclaredTypeOfAlias(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { - links.declaredType = getDeclaredTypeOfSymbol(resolveImport(symbol)); + links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol)); } return links.declaredType; } @@ -9800,7 +10071,7 @@ var ts; return getDeclaredTypeOfTypeParameter(symbol); } if (symbol.flags & 8388608) { - return getDeclaredTypeOfImport(symbol); + return getDeclaredTypeOfAlias(symbol); } return unknownType; } @@ -9890,7 +10161,8 @@ var ts; var baseType = classType.baseTypes[0]; var baseSignatures = getSignaturesOfType(getTypeOfSymbol(baseType.symbol), 1); return ts.map(baseSignatures, function (baseSignature) { - var signature = baseType.flags & 4096 ? getSignatureInstantiation(baseSignature, baseType.typeArguments) : cloneSignature(baseSignature); + var signature = baseType.flags & 4096 ? + getSignatureInstantiation(baseSignature, baseType.typeArguments) : cloneSignature(baseSignature); signature.typeParameters = classType.typeParameters; signature.resolvedReturnType = classType; return signature; @@ -10171,11 +10443,22 @@ var ts; }); return result; } + function getExportsOfExternalModule(node) { + if (!node.moduleSpecifier) { + return emptyArray; + } + var module = resolveExternalModuleName(node, node.moduleSpecifier); + if (!module || !module.exports) { + return emptyArray; + } + return ts.mapToArray(getExportsOfModule(module)); + } function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { var classType = declaration.kind === 133 ? getDeclaredTypeOfClass(declaration.parent.symbol) : undefined; - var typeParameters = classType ? classType.typeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; + var typeParameters = classType ? classType.typeParameters : + declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; var hasStringLiterals = false; var minArgumentCount = -1; @@ -10316,7 +10599,7 @@ var ts; return symbol.members["__index"]; } function getIndexDeclarationOfSymbol(symbol, kind) { - var syntaxKind = kind === 1 ? 119 : 121; + var syntaxKind = kind === 1 ? 118 : 120; var indexSymbol = getIndexSymbol(symbol); if (indexSymbol) { var len = indexSymbol.declarations.length; @@ -10334,7 +10617,9 @@ var ts; } function getIndexTypeOfSymbol(symbol, kind) { var declaration = getIndexDeclarationOfSymbol(symbol, kind); - return declaration ? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType : undefined; + return declaration + ? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType + : undefined; } function getConstraintOfTypeParameter(type) { if (!type.constraint) { @@ -10419,7 +10704,7 @@ var ts; function getTypeFromTypeReferenceNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { - var symbol = resolveEntityName(node, node.typeName, 793056); + var symbol = resolveEntityName(node.typeName, 793056); if (symbol) { var type; if ((symbol.flags & 262144) && isTypeParameterReferenceIllegalInConstraint(node, symbol)) { @@ -10492,8 +10777,9 @@ var ts; function getGlobalSymbol(name, meaning, diagnostic) { return resolveName(undefined, name, meaning, diagnostic, name); } - function getGlobalType(name) { - return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), 0); + function getGlobalType(name, arity) { + if (arity === void 0) { arity = 0; } + return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity); } function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); @@ -10637,15 +10923,15 @@ var ts; } function getTypeFromTypeNode(node) { switch (node.kind) { - case 112: + case 111: return anyType; - case 121: + case 120: return stringType; - case 119: + case 118: return numberType; - case 113: + case 112: return booleanType; - case 122: + case 121: return esSymbolType; case 98: return voidType; @@ -10797,7 +11083,8 @@ var ts; return mapper(type); } if (type.flags & 32768) { - return type.symbol && type.symbol.flags & (16 | 8192 | 2048 | 4096) ? instantiateAnonymousType(type, mapper) : type; + return type.symbol && type.symbol.flags & (16 | 8192 | 2048 | 4096) ? + instantiateAnonymousType(type, mapper) : type; } if (type.flags & 4096) { return createTypeReference(type.target, instantiateList(type.typeArguments, mapper, instantiateType)); @@ -10826,7 +11113,7 @@ var ts; isContextSensitive(node.whenFalse); case 167: return node.operatorToken.kind === 49 && - (isContextSensitive(node.left) || isContextSensitive(node.right)); + (isContextSensitive(node.left) || isContextSensitive(node.right)); case 217: return isContextSensitive(node.initializer); case 132: @@ -11596,7 +11883,9 @@ var ts; var diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type; break; case 128: - var diagnostic = declaration.dotDotDotToken ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Parameter_0_implicitly_has_an_1_type; + 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 195: case 132: @@ -11697,7 +11986,9 @@ var ts; for (var i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { var inferences = context.inferences[i]; - var candidates = inferiority ? inferences.secondary || (inferences.secondary = []) : inferences.primary || (inferences.primary = []); + var candidates = inferiority ? + inferences.secondary || (inferences.secondary = []) : + inferences.primary || (inferences.primary = []); if (!ts.contains(candidates, source)) candidates.push(source); break; @@ -12106,46 +12397,56 @@ var ts; return type; } } - function markLinkedImportsAsReferenced(node) { - if (node) { - var nodeLinks = getNodeLinks(node); - while (nodeLinks.importOnRightSide) { - var rightSide = nodeLinks.importOnRightSide; - nodeLinks.importOnRightSide = undefined; - getSymbolLinks(rightSide).referenced = true; - ts.Debug.assert((rightSide.flags & 8388608) !== 0); - nodeLinks = getNodeLinks(ts.getDeclarationOfKind(rightSide, 202)); - } - } - } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); if (symbol === argumentsSymbol && ts.getContainingFunction(node).kind === 161) { 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 = getLeftSideOfImportEqualsOrExportAssignment(node); - if (!importOrExportAssignment || - (importOrExportAssignment.flags & 1) || - (importOrExportAssignment.kind === 208)) { - symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); - } - else { - var nodeLinks = getNodeLinks(importOrExportAssignment); - ts.Debug.assert(!nodeLinks.importOnRightSide); - nodeLinks.importOnRightSide = symbol; - } - } - if (symbolLinks.referenced) { - markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 202)); - } + if (symbol.flags & 8388608 && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { + markAliasSymbolAsReferenced(symbol); } checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); + checkBlockScopedBindingCapturedInLoop(node, symbol); return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } + function isInsideFunction(node, threshold) { + var current = node; + while (current && current !== threshold) { + if (ts.isFunctionLike(current)) { + return true; + } + current = current.parent; + } + return false; + } + function checkBlockScopedBindingCapturedInLoop(node, symbol) { + if (languageVersion >= 2 || + (symbol.flags & 2) === 0 || + symbol.valueDeclaration.parent.kind === 216) { + return; + } + var container = symbol.valueDeclaration; + while (container.kind !== 194) { + container = container.parent; + } + container = container.parent; + if (container.kind === 175) { + container = container.parent; + } + var inFunction = isInsideFunction(node.parent, container); + var current = container; + while (current && !ts.nodeStartsNewLexicalEnvironment(current)) { + if (isIterationStatement(current, false)) { + if (inFunction) { + grammarErrorOnFirstToken(current, ts.Diagnostics.Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher, ts.declarationNameToString(node)); + } + getNodeLinks(symbol.valueDeclaration).flags |= 256; + break; + } + current = current.parent; + } + } function captureLexicalThis(node, container) { var classNode = container.parent && container.parent.kind === 196 ? container.parent : undefined; getNodeLinks(node).flags |= 2; @@ -12231,19 +12532,19 @@ var ts; if (container.flags & 128) { canUseSuperExpression = container.kind === 132 || - container.kind === 131 || - container.kind === 134 || - container.kind === 135; + container.kind === 131 || + container.kind === 134 || + container.kind === 135; } else { canUseSuperExpression = container.kind === 132 || - container.kind === 131 || - container.kind === 134 || - container.kind === 135 || - container.kind === 130 || - container.kind === 129 || - container.kind === 133; + container.kind === 131 || + container.kind === 134 || + container.kind === 135 || + container.kind === 130 || + container.kind === 129 || + container.kind === 133; } } } @@ -12428,7 +12729,9 @@ var ts; var type = getContextualType(arrayLiteral); if (type) { var index = ts.indexOf(arrayLiteral.elements, node); - return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1); + return getTypeOfPropertyOfContextualType(type, "" + index) + || getIndexTypeOfContextualType(type, 1) + || (languageVersion >= 2 ? checkIteratedType(type, undefined) : undefined); } return undefined; } @@ -12492,7 +12795,9 @@ var ts; } function getContextualSignature(node) { ts.Debug.assert(node.kind !== 132 || ts.isObjectLiteralMethod(node)); - var type = ts.isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getContextualType(node); + var type = ts.isObjectLiteralMethod(node) + ? getContextualTypeForObjectLiteralMethod(node) + : getContextualType(node); if (!type) { return undefined; } @@ -12618,7 +12923,9 @@ var ts; } else { ts.Debug.assert(memberDecl.kind === 218); - var type = memberDecl.name.kind === 126 ? unknownType : checkExpression(memberDecl.name, contextualMapper); + var type = memberDecl.name.kind === 126 + ? unknownType + : checkExpression(memberDecl.name, contextualMapper); } typeFlags |= type.flags; var prop = createSymbol(4 | 67108864 | member.flags, member.name); @@ -12734,7 +13041,9 @@ var ts; return anyType; } function isValidPropertyAccess(node, propertyName) { - var left = node.kind === 153 ? node.expression : node.left; + var left = node.kind === 153 + ? node.expression + : node.left; var type = checkExpressionOrQualifiedName(left); if (type !== unknownType && type !== anyType) { var prop = getPropertyOfType(getWidenedType(type), propertyName); @@ -13028,7 +13337,9 @@ var ts; var arg = args[i]; if (arg.kind !== 172) { var paramType = getTypeAtPosition(signature, arg.kind === 171 ? -1 : i); - var argType = i === 0 && node.kind === 157 ? globalTemplateStringsArrayType : arg.kind === 8 && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); + var argType = i === 0 && node.kind === 157 ? 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; } @@ -13305,9 +13616,6 @@ var ts; return getReturnTypeOfSignature(signature); } function checkTaggedTemplateExpression(node) { - if (languageVersion < 2) { - grammarErrorOnFirstToken(node.template, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); - } return getReturnTypeOfSignature(getResolvedSignature(node)); } function checkTypeAssertion(node) { @@ -13323,9 +13631,13 @@ var ts; } function getTypeAtPosition(signature, pos) { if (pos >= 0) { - return signature.hasRestParameter ? pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) : pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType; + return signature.hasRestParameter ? + pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) : + pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType; } - return signature.hasRestParameter ? getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]) : anyArrayType; + return signature.hasRestParameter ? + getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]) : + anyArrayType; } function assignContextualParameterTypes(signature, context, mapper) { var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0); @@ -13466,7 +13778,7 @@ var ts; } return true; } - function checkReferenceExpression(n, invalidReferenceMessage, constantVarianleMessage) { + function checkReferenceExpression(n, invalidReferenceMessage, constantVariableMessage) { function findSymbol(n) { var symbol = getNodeLinks(n).resolvedSymbol; return symbol && getExportSymbolOfValueSymbolIfExported(symbol); @@ -13492,14 +13804,14 @@ var ts; case 64: case 153: var symbol = findSymbol(n); - return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 4096) !== 0; + return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 8192) !== 0; case 154: var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8) { var name = index.text; var prop = getPropertyOfType(getTypeOfSymbol(symbol), name); - return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 4096) !== 0; + return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192) !== 0; } return false; case 159: @@ -13513,7 +13825,7 @@ var ts; return false; } if (isConstVariableReference(n)) { - error(n, constantVarianleMessage); + error(n, constantVariableMessage); return false; } return true; @@ -13627,9 +13939,10 @@ var ts; var p = properties[i]; if (p.kind === 217 || p.kind === 218) { var name = p.name; - var type = sourceType.flags & 1 ? sourceType : getTypeOfPropertyOfType(sourceType, name.text) || - isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, 1) || - getIndexTypeOfType(sourceType, 0); + var type = sourceType.flags & 1 ? sourceType : + getTypeOfPropertyOfType(sourceType, name.text) || + isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, 1) || + getIndexTypeOfType(sourceType, 0); if (type) { checkDestructuringAssignment(p.initializer || name, type); } @@ -13654,7 +13967,9 @@ var ts; 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); + var type = sourceType.flags & 1 ? sourceType : + isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : + getIndexTypeOfType(sourceType, 1); if (type) { checkDestructuringAssignment(e, type, contextualMapper); } @@ -13802,7 +14117,9 @@ var ts; return rightType; } function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576) ? node.left : someConstituentTypeHasKind(rightType, 1048576) ? node.right : undefined; + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576) ? node.left : + someConstituentTypeHasKind(rightType, 1048576) ? node.right : + undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); return false; @@ -13913,8 +14230,8 @@ var ts; } if (isConstEnumObjectType(type)) { var ok = (node.parent.kind === 153 && node.parent.expression === node) || - (node.parent.kind === 154 && node.parent.expression === node) || - ((node.kind === 64 || node.kind === 125) && isInRightSideOfImportOrExportAssignment(node)); + (node.parent.kind === 154 && node.parent.expression === node) || + ((node.kind === 64 || node.kind === 125) && 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); } @@ -14064,7 +14381,7 @@ var ts; var declaration = indexSymbol.declarations[i]; if (declaration.parameters.length === 1 && declaration.parameters[0].type) { switch (declaration.parameters[0].type.kind) { - case 121: + case 120: if (!seenStringIndexer) { seenStringIndexer = true; } @@ -14072,7 +14389,7 @@ var ts; error(declaration, ts.Diagnostics.Duplicate_string_index_signature); } break; - case 119: + case 118: if (!seenNumericIndexer) { seenNumericIndexer = true; } @@ -14139,7 +14456,7 @@ var ts; 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); }); + 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 !== 177 || !isSuperCallExpression(statements[0].expression)) { @@ -14461,13 +14778,15 @@ var ts; case 197: return 2097152; case 200: - return d.name.kind === 8 || ts.getModuleInstanceState(d) !== 0 ? 4194304 | 1048576 : 4194304; + return d.name.kind === 8 || ts.getModuleInstanceState(d) !== 0 + ? 4194304 | 1048576 + : 4194304; case 196: case 199: return 2097152 | 1048576; case 202: var result = 0; - var target = resolveImport(getSymbolOfNode(d)); + var target = resolveAlias(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); }); return result; default: @@ -14488,7 +14807,7 @@ var ts; } function checkFunctionLikeDeclaration(node) { checkSignatureDeclaration(node); - if (node.name.kind === 126) { + if (node.name && node.name.kind === 126) { checkComputedPropertyName(node.name); } if (!ts.hasDynamicName(node)) { @@ -14604,24 +14923,24 @@ var ts; } } function checkVarDeclaredNamesNotShadowed(node) { - if (node.initializer && (ts.getCombinedNodeFlags(node) & 6144) === 0) { + if (node.initializer && (ts.getCombinedNodeFlags(node) & 12288) === 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) & 6144) { + if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 12288) { var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 194); var container = varDeclList.parent.kind === 175 && - varDeclList.parent.parent; + varDeclList.parent.parent; var namesShareScope = container && - (container.kind === 174 && ts.isAnyFunction(container.parent) || - (container.kind === 201 && container.kind === 200) || - container.kind === 220); + (container.kind === 174 && ts.isFunctionLike(container.parent) || + (container.kind === 201 && container.kind === 200) || + container.kind === 220); 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); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name); } } } @@ -14777,33 +15096,127 @@ var ts; checkSourceElement(node.statement); } function checkForOfStatement(node) { - checkGrammarForOfStatement(node); + if (languageVersion < 2) { + grammarErrorOnFirstToken(node, ts.Diagnostics.for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher); + return; + } + checkGrammarForInOrForOfStatement(node); + if (node.initializer.kind === 194) { + checkForInOrForOfVariableDeclaration(node); + } + else { + var varExpr = node.initializer; + var rightType = checkExpression(node.expression); + var iteratedType = checkIteratedType(rightType, node.expression); + if (varExpr.kind === 151 || varExpr.kind === 152) { + checkDestructuringAssignment(varExpr, iteratedType || unknownType); + } + else { + var leftType = checkExpression(varExpr); + checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_of_statement, ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant); + if (iteratedType) { + checkTypeAssignableTo(iteratedType, leftType, varExpr, undefined); + } + } + } + checkSourceElement(node.statement); } function checkForInStatement(node) { checkGrammarForInOrForOfStatement(node); if (node.initializer.kind === 194) { - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length >= 1) { - var decl = variableDeclarationList.declarations[0]; - checkVariableDeclaration(decl); + var variable = node.initializer.declarations[0]; + if (variable && ts.isBindingPattern(variable.name)) { + error(variable.name, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } + checkForInOrForOfVariableDeclaration(node); } else { var varExpr = node.initializer; - var exprType = checkExpression(varExpr); - if (!allConstituentTypesHaveKind(exprType, 1 | 258)) { + var leftType = checkExpression(varExpr); + if (varExpr.kind === 151 || varExpr.kind === 152) { + error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); + } + else if (!allConstituentTypesHaveKind(leftType, 1 | 258)) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { - checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant); } } - var exprType = checkExpression(node.expression); - if (!allConstituentTypesHaveKind(exprType, 1 | 48128 | 512)) { + var rightType = checkExpression(node.expression); + if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); } + function checkForInOrForOfVariableDeclaration(iterationStatement) { + var variableDeclarationList = iterationStatement.initializer; + if (variableDeclarationList.declarations.length >= 1) { + var decl = variableDeclarationList.declarations[0]; + checkVariableDeclaration(decl); + } + } + function getTypeForVariableDeclarationInForOfStatement(forOfStatement) { + if (languageVersion < 2) { + return anyType; + } + var expressionType = getTypeOfExpression(forOfStatement.expression); + return checkIteratedType(expressionType, forOfStatement.expression) || anyType; + } + function checkIteratedType(iterable, expressionForError) { + ts.Debug.assert(languageVersion >= 2); + var iteratedType = getIteratedType(iterable, expressionForError); + if (expressionForError && iteratedType) { + var completeIterableType = globalIterableType !== emptyObjectType + ? createTypeReference(globalIterableType, [iteratedType]) + : emptyObjectType; + checkTypeAssignableTo(iterable, completeIterableType, expressionForError); + } + return iteratedType; + function getIteratedType(iterable, expressionForError) { + if (allConstituentTypesHaveKind(iterable, 1)) { + return undefined; + } + var iteratorFunction = getTypeOfPropertyOfType(iterable, ts.getPropertyNameForKnownSymbolName("iterator")); + if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, 1)) { + return undefined; + } + var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray; + if (iteratorFunctionSignatures.length === 0) { + if (expressionForError) { + error(expressionForError, ts.Diagnostics.The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + } + return undefined; + } + var iterator = getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)); + if (allConstituentTypesHaveKind(iterator, 1)) { + return undefined; + } + var iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next"); + if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, 1)) { + return undefined; + } + var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray; + if (iteratorNextFunctionSignatures.length === 0) { + if (expressionForError) { + error(expressionForError, ts.Diagnostics.The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method); + } + return undefined; + } + var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); + if (allConstituentTypesHaveKind(iteratorNextResult, 1)) { + return undefined; + } + var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); + if (!iteratorNextValue) { + if (expressionForError) { + error(expressionForError, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); + } + return undefined; + } + return iteratorNextValue; + } + } function checkBreakOrContinueStatement(node) { checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node); } @@ -14879,7 +15292,7 @@ var ts; if (!checkGrammarStatementInAmbientContext(node)) { var current = node.parent; while (current) { - if (ts.isAnyFunction(current)) { + if (ts.isFunctionLike(current)) { break; } if (current.kind === 189 && current.label.text === node.label.text) { @@ -14907,16 +15320,33 @@ var ts; checkBlock(node.tryBlock); var catchClause = node.catchClause; if (catchClause) { - if (catchClause.type) { - var sourceFile = ts.getSourceFileOfNode(node); - var colonStart = ts.skipTrivia(sourceFile.text, catchClause.name.end); - grammarErrorAtPos(sourceFile, colonStart, ":".length, ts.Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); + if (catchClause.variableDeclaration) { + if (catchClause.variableDeclaration.name.kind !== 64) { + grammarErrorOnFirstToken(catchClause.variableDeclaration.name, ts.Diagnostics.Catch_clause_variable_name_must_be_an_identifier); + } + else if (catchClause.variableDeclaration.type) { + grammarErrorOnFirstToken(catchClause.variableDeclaration.type, ts.Diagnostics.Catch_clause_variable_cannot_have_a_type_annotation); + } + else if (catchClause.variableDeclaration.initializer) { + grammarErrorOnFirstToken(catchClause.variableDeclaration.initializer, ts.Diagnostics.Catch_clause_variable_cannot_have_an_initializer); + } + else { + var identifierName = catchClause.variableDeclaration.name.text; + var locals = catchClause.block.locals; + if (locals && ts.hasProperty(locals, identifierName)) { + var localSymbol = locals[identifierName]; + if (localSymbol && (localSymbol.flags & 2) !== 0) { + grammarErrorOnNode(localSymbol.valueDeclaration, ts.Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName); + } + } + checkGrammarEvalOrArgumentsInStrictMode(node, catchClause.variableDeclaration.name); + } } - checkGrammarEvalOrArgumentsInStrictMode(node, catchClause.name); checkBlock(catchClause.block); } - if (node.finallyBlock) + if (node.finallyBlock) { checkBlock(node.finallyBlock); + } } function checkIndexConstraints(type) { var declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, 1); @@ -14971,7 +15401,9 @@ var ts; errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0]; } if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { - var errorMessage = indexKind === 0 ? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 : ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; + var errorMessage = indexKind === 0 + ? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 + : ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType)); } } @@ -15004,10 +15436,12 @@ var ts; } function checkClassDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); - checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); + if (node.name) { + checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); + checkCollisionWithCapturedThisVariable(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + } checkTypeParameters(node.typeParameters); - checkCollisionWithCapturedThisVariable(node, node.name); - checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); @@ -15020,10 +15454,10 @@ var ts; if (type.baseTypes.length) { if (produceDiagnostics) { var baseType = type.baseTypes[0]; - checkTypeAssignableTo(type, baseType, node.name, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); + checkTypeAssignableTo(type, baseType, node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); var staticBaseType = getTypeOfSymbol(baseType.symbol); - checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); - if (baseType.symbol !== resolveEntityName(node, baseTypeNode.typeName, 107455)) { + checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); + if (baseType.symbol !== resolveEntityName(baseTypeNode.typeName, 107455)) { error(baseTypeNode, ts.Diagnostics.Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_0, typeToString(baseType)); } checkKindsOfPropertyMemberOverrides(type, baseType); @@ -15039,7 +15473,7 @@ var ts; if (t !== unknownType) { var declaredType = (t.flags & 4096) ? t.target : t; if (declaredType.flags & (1024 | 2048)) { - checkTypeAssignableTo(type, t, node.name, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); + checkTypeAssignableTo(type, t, node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); } else { error(typeRefNode, ts.Diagnostics.A_class_may_only_implement_another_class_or_interface); @@ -15387,21 +15821,15 @@ 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 === 201) { - var statements = node.body.statements; - for (var i = 0, n = statements.length; i < n; i++) { - var statement = statements[i]; - if (statement.kind === 208) { - grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); - } - } - } } checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(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)) { + if (symbol.flags & 512 + && symbol.declarations.length > 1 + && !ts.isInAmbientContext(node) + && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums)) { var classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (classOrFunc) { if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(classOrFunc)) { @@ -15437,7 +15865,9 @@ var ts; } var inAmbientExternalModule = node.parent.kind === 201 && node.parent.parent.name.kind === 8; if (node.parent.kind !== 220 && !inAmbientExternalModule) { - error(moduleName, node.kind === 209 ? ts.Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module : ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + error(moduleName, node.kind === 209 ? + ts.Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module : + ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); return false; } if (inAmbientExternalModule && isExternalModuleNameRelative(moduleName.text)) { @@ -15446,15 +15876,17 @@ var ts; } return true; } - function checkImportSymbol(node) { + function checkAliasSymbol(node) { var symbol = getSymbolOfNode(node); - var target = resolveImport(symbol); + var target = resolveAlias(symbol); if (target !== unknownSymbol) { var excludedMeanings = (symbol.flags & 107455 ? 107455 : 0) | - (symbol.flags & 793056 ? 793056 : 0) | - (symbol.flags & 1536 ? 1536 : 0); + (symbol.flags & 793056 ? 793056 : 0) | + (symbol.flags & 1536 ? 1536 : 0); if (target.flags & excludedMeanings) { - var message = node.kind === 211 ? ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; + var message = node.kind === 211 ? + ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : + ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; error(node, message, symbolToString(symbol)); } } @@ -15462,10 +15894,10 @@ var ts; function checkImportBinding(node) { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); - checkImportSymbol(node); + checkAliasSymbol(node); } function checkImportDeclaration(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + if (!checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -15487,50 +15919,107 @@ var ts; } function checkImportEqualsDeclaration(node) { checkGrammarModifiers(node); - if (ts.isInternalModuleImportEqualsDeclaration(node)) { + if (ts.isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); - var symbol = getSymbolOfNode(node); - var target = resolveImport(symbol); - if (target !== unknownSymbol) { - if (target.flags & 107455) { - var moduleName = getFirstIdentifier(node.moduleReference); - if (resolveEntityName(node, moduleName, 107455 | 1536).flags & 1536) { - checkExpressionOrQualifiedName(node.moduleReference); - } - else { - error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName)); - } - } - if (target.flags & 793056) { - checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); - } + if (node.flags & 1) { + markExportAsReferenced(node); } - } - else { - if (checkExternalImportOrExportDeclaration(node)) { - checkImportBinding(node); + if (ts.isInternalModuleImportEqualsDeclaration(node)) { + var target = resolveAlias(getSymbolOfNode(node)); + if (target !== unknownSymbol) { + if (target.flags & 107455) { + var moduleName = getFirstIdentifier(node.moduleReference); + if (!(resolveEntityName(moduleName, 107455 | 1536).flags & 1536)) { + error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName)); + } + } + if (target.flags & 793056) { + checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); + } + } } } } function checkExportDeclaration(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + if (!checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_declaration_cannot_have_modifiers); } if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) { if (node.exportClause) { - ts.forEach(node.exportClause.elements, checkImportSymbol); + ts.forEach(node.exportClause.elements, checkExportSpecifier); } } } + function checkExportSpecifier(node) { + checkAliasSymbol(node); + if (!node.parent.parent.moduleSpecifier) { + markExportAsReferenced(node); + } + } function checkExportAssignment(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + var container = node.parent.kind === 220 ? node.parent : node.parent.parent; + if (container.kind === 200 && container.name.kind === 64) { + error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); + return; + } + if (!checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); } - var container = node.parent; - if (container.kind !== 220) { - container = container.parent; + if (node.expression.kind === 64) { + markExportAsReferenced(node); + } + else { + checkExpressionCached(node.expression); + } + checkExternalModuleExports(container); + } + function getModuleStatements(node) { + if (node.kind === 220) { + return node.statements; + } + if (node.kind === 200 && node.body.kind === 201) { + return node.body.statements; + } + return emptyArray; + } + function hasExportedMembers(moduleSymbol) { + var declarations = moduleSymbol.declarations; + for (var i = 0; i < declarations.length; i++) { + var statements = getModuleStatements(declarations[i]); + for (var j = 0; j < statements.length; j++) { + var node = statements[j]; + if (node.kind === 209) { + var exportClause = node.exportClause; + if (!exportClause) { + return true; + } + var specifiers = exportClause.elements; + for (var k = 0; k < specifiers.length; k++) { + var specifier = specifiers[k]; + if (!(specifier.propertyName && specifier.name && specifier.name.text === "default")) { + return true; + } + } + } + else if (node.kind !== 208 && node.flags & 1 && !(node.flags & 256)) { + return true; + } + } + } + } + function checkExternalModuleExports(node) { + var moduleSymbol = getSymbolOfNode(node); + var links = getSymbolLinks(moduleSymbol); + if (!links.exportsChecked) { + var defaultSymbol = getExportAssignmentSymbol(moduleSymbol); + if (defaultSymbol) { + if (hasExportedMembers(moduleSymbol)) { + var declaration = getDeclarationOfAliasSymbol(defaultSymbol) || defaultSymbol.valueDeclaration; + error(declaration, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); + } + } + links.exportsChecked = true; } - checkTypeOfExportAssignmentSymbol(getSymbolOfNode(container)); } function checkSourceElement(node) { if (!node) @@ -15712,6 +16201,7 @@ var ts; case 196: case 199: case 219: + case 208: case 220: ts.forEachChild(node, checkFunctionExpressionBodies); break; @@ -15731,11 +16221,7 @@ var ts; 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, 202)); - } + checkExternalModuleExports(node); } if (potentialThisCollisions.length) { ts.forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope); @@ -15824,11 +16310,6 @@ var ts; copySymbol(location.symbol, meaning); } break; - case 216: - if (location.name.text) { - copySymbol(location.symbol, meaning); - } - break; } memberFlags = location.flags; location = location.parent; @@ -15862,11 +16343,11 @@ var ts; return true; } switch (node.kind) { + case 111: + case 118: + case 120: case 112: - case 119: case 121: - case 113: - case 122: return true; case 98: return node.parent.kind !== 164; @@ -15925,7 +16406,7 @@ var ts; return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent; } if (nodeOnRightSide.parent.kind === 208) { - return nodeOnRightSide.parent.exportName === nodeOnRightSide && nodeOnRightSide.parent; + return nodeOnRightSide.parent.expression === nodeOnRightSide && nodeOnRightSide.parent; } return undefined; } @@ -15937,11 +16418,11 @@ var ts; (node.parent.kind === 153 && node.parent.name === node); } function getSymbolOfEntityNameOrPropertyAccessExpression(entityName) { - if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { + if (ts.isDeclarationName(entityName)) { return getSymbolOfNode(entityName.parent); } if (entityName.parent.kind === 208) { - return resolveEntityName(entityName.parent.parent, entityName, 107455 | 793056 | 1536 | 8388608); + return resolveEntityName(entityName, 107455 | 793056 | 1536 | 8388608); } if (entityName.kind !== 153) { if (isInRightSideOfImportOrExportAssignment(entityName)) { @@ -15957,7 +16438,7 @@ var ts; } if (entityName.kind === 64) { var meaning = 107455 | 8388608; - return resolveEntityName(entityName, entityName, meaning); + return resolveEntityName(entityName, meaning); } else if (entityName.kind === 153) { var symbol = getNodeLinks(entityName).resolvedSymbol; @@ -15977,7 +16458,7 @@ var ts; else if (isTypeReferenceIdentifier(entityName)) { var meaning = entityName.parent.kind === 139 ? 793056 : 1536; meaning |= 8388608; - return resolveEntityName(entityName, entityName, meaning); + return resolveEntityName(entityName, meaning); } return undefined; } @@ -15985,11 +16466,13 @@ var ts; if (isInsideWithStatementBody(node)) { return undefined; } - if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (ts.isDeclarationName(node)) { return getSymbolOfNode(node.parent); } if (node.kind === 64 && isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 208 ? getSymbolOfEntityNameOrPropertyAccessExpression(node) : getSymbolOfPartOfRightHandSideOfImportEquals(node); + return node.parent.kind === 208 + ? getSymbolOfEntityNameOrPropertyAccessExpression(node) + : getSymbolOfPartOfRightHandSideOfImportEquals(node); } switch (node.kind) { case 64: @@ -16000,18 +16483,19 @@ var ts; case 90: var type = checkExpression(node); return type.symbol; - case 114: + case 113: var constructorDeclaration = node.parent; if (constructorDeclaration && constructorDeclaration.kind === 133) { return constructorDeclaration.parent.symbol; } return undefined; case 8: - if (ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) && - ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) { - var importSymbol = getSymbolOfNode(node.parent.parent); - var moduleType = getTypeOfSymbol(importSymbol); - return moduleType ? moduleType.symbol : undefined; + var moduleName; + if ((ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) && + ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) || + ((node.parent.kind === 203 || node.parent.kind === 209) && + node.parent.moduleSpecifier === node)) { + return resolveExternalModuleName(node, node); } case 7: if (node.parent.kind == 154 && node.parent.argumentExpression === node) { @@ -16029,7 +16513,7 @@ var ts; } function getShorthandAssignmentValueSymbol(location) { if (location && location.kind === 218) { - return resolveEntityName(location, location.name, 107455); + return resolveEntityName(location.name, 107455); } return undefined; } @@ -16055,7 +16539,7 @@ var ts; var symbol = getSymbolOfNode(node); return getTypeOfSymbol(symbol); } - if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (ts.isDeclarationName(node)) { var symbol = getSymbolInfo(node); return symbol && getTypeOfSymbol(symbol); } @@ -16132,6 +16616,10 @@ var ts; return generatedNames; function generateNames(node) { switch (node.kind) { + case 195: + case 196: + generateNameForFunctionOrClassDeclaration(node); + break; case 200: generateNameForModuleOrEnum(node); generateNames(node.body); @@ -16145,6 +16633,9 @@ var ts; case 209: generateNameForExportDeclaration(node); break; + case 208: + generateNameForExportAssignment(node); + break; case 220: case 201: ts.forEach(node.statements, generateNames); @@ -16155,27 +16646,17 @@ var ts; return ts.hasProperty(globals, name) || ts.hasProperty(sourceFile.identifiers, name) || ts.hasProperty(generatedNames, name); } function makeUniqueName(baseName) { - if (baseName.charCodeAt(0) !== 95) { - var baseName = "_" + baseName; - if (!isExistingName(baseName)) { - return generatedNames[baseName] = baseName; - } - } - if (baseName.charCodeAt(baseName.length - 1) !== 95) { - baseName += "_"; - } - var i = 1; - while (true) { - name = baseName + i; - if (!isExistingName(name)) { - return generatedNames[name] = name; - } - i++; - } + var name = ts.generateUniqueName(baseName, isExistingName); + return generatedNames[name] = name; } function assignGeneratedName(node, name) { getNodeLinks(node).generatedName = ts.unescapeIdentifier(name); } + function generateNameForFunctionOrClassDeclaration(node) { + if (!node.name) { + assignGeneratedName(node, makeUniqueName("default")); + } + } function generateNameForModuleOrEnum(node) { if (node.name.kind === 64) { var name = node.name.text; @@ -16184,7 +16665,8 @@ var ts; } function generateNameForImportOrExportDeclaration(node) { var expr = ts.getExternalModuleName(node); - var baseName = expr.kind === 8 ? ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; + var baseName = expr.kind === 8 ? + ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; assignGeneratedName(node, makeUniqueName(baseName)); } function generateNameForImportDeclaration(node) { @@ -16197,6 +16679,11 @@ var ts; generateNameForImportOrExportDeclaration(node); } } + function generateNameForExportAssignment(node) { + if (node.expression.kind !== 64) { + assignGeneratedName(node, makeUniqueName("default")); + } + } } function getGeneratedNameForNode(node) { var links = getNodeLinks(node); @@ -16211,8 +16698,8 @@ var ts; function getLocalNameForImportDeclaration(node) { return getGeneratedNameForNode(node); } - function getImportNameSubstitution(symbol) { - var declaration = getDeclarationOfImportSymbol(symbol); + function getAliasNameSubstitution(symbol) { + var declaration = getDeclarationOfAliasSymbol(symbol); if (declaration && declaration.kind === 207) { var moduleName = getGeneratedNameForNode(declaration.parent.parent.parent); var propertyName = declaration.propertyName || declaration.name; @@ -16243,38 +16730,35 @@ var ts; return getExportNameSubstitution(exportSymbol, node.parent); } if (symbol.flags & 8388608) { - return getImportNameSubstitution(symbol); + return getAliasNameSubstitution(symbol); } } } - function getExportAssignmentName(node) { - var symbol = getExportAssignmentSymbol(getSymbolOfNode(node)); - return symbol && symbol !== unknownSymbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol) ? symbolToString(symbol) : undefined; + function hasExportDefaultValue(node) { + var symbol = getResolvedExportAssignmentSymbol(getSymbolOfNode(node)); + return symbol && symbol !== unknownSymbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol); } function isTopLevelValueImportEqualsWithEntityName(node) { if (node.parent.kind !== 220 || !ts.isInternalModuleImportEqualsDeclaration(node)) { return false; } - return isImportResolvedToValue(getSymbolOfNode(node)); + return isAliasResolvedToValue(getSymbolOfNode(node)); } - function isImportResolvedToValue(symbol) { - var target = resolveImport(symbol); + function isAliasResolvedToValue(symbol) { + var target = resolveAlias(symbol); return target !== unknownSymbol && target.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(target); } function isConstEnumOrConstEnumOnlyModule(s) { return isConstEnumSymbol(s) || s.constEnumOnlyModule; } - function isReferencedImportDeclaration(node) { - if (isImportSymbolDeclaration(node)) { + function isReferencedAliasDeclaration(node) { + if (isAliasSymbolDeclaration(node)) { var symbol = getSymbolOfNode(node); if (getSymbolLinks(symbol).referenced) { return true; } - if (node.kind === 202 && node.flags & 1 && isImportResolvedToValue(symbol)) { - return true; - } } - return ts.forEachChild(node, isReferencedImportDeclaration); + return ts.forEachChild(node, isReferencedAliasDeclaration); } function isImplementationOfOverload(node) { if (ts.nodeIsPresent(node.body)) { @@ -16308,7 +16792,9 @@ var ts; } function writeTypeOfDeclaration(declaration, enclosingDeclaration, flags, writer) { var symbol = getSymbolOfNode(declaration); - var type = symbol && !(symbol.flags & (2048 | 131072)) ? getTypeOfSymbol(symbol) : unknownType; + var type = symbol && !(symbol.flags & (2048 | 131072)) + ? getTypeOfSymbol(symbol) + : unknownType; getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } function writeReturnTypeOfSignatureDeclaration(signatureDeclaration, enclosingDeclaration, flags, writer) { @@ -16319,12 +16805,38 @@ var ts; return !resolveName(location, name, 107455, undefined, undefined) && !ts.hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name); } + function getBlockScopedVariableId(n) { + ts.Debug.assert(!ts.nodeIsSynthesized(n)); + if (n.parent.kind === 153 && + n.parent.name === n) { + return undefined; + } + if (n.parent.kind === 150 && + n.parent.propertyName === n) { + return undefined; + } + var declarationSymbol = (n.parent.kind === 193 && n.parent.name === n) || + n.parent.kind === 150 + ? getSymbolOfNode(n.parent) + : undefined; + var symbol = declarationSymbol || + getNodeLinks(n).resolvedSymbol || + resolveName(n, n.text, 2 | 8388608, undefined, undefined); + var isLetOrConst = symbol && + (symbol.flags & 2) && + symbol.valueDeclaration.parent.kind !== 216; + if (isLetOrConst) { + getSymbolLinks(symbol); + return symbol.id; + } + return undefined; + } function createResolver() { return { getGeneratedNameForNode: getGeneratedNameForNode, getExpressionNameSubstitution: getExpressionNameSubstitution, - getExportAssignmentName: getExportAssignmentName, - isReferencedImportDeclaration: isReferencedImportDeclaration, + hasExportDefaultValue: hasExportDefaultValue, + isReferencedAliasDeclaration: isReferencedAliasDeclaration, getNodeCheckFlags: getNodeCheckFlags, isTopLevelValueImportEqualsWithEntityName: isTopLevelValueImportEqualsWithEntityName, isDeclarationVisible: isDeclarationVisible, @@ -16334,7 +16846,8 @@ var ts; isSymbolAccessible: isSymbolAccessible, isEntityNameVisible: isEntityNameVisible, getConstantValue: getConstantValue, - isUnknownIdentifier: isUnknownIdentifier + isUnknownIdentifier: isUnknownIdentifier, + getBlockScopedVariableId: getBlockScopedVariableId }; } function initializeTypeChecker() { @@ -16362,6 +16875,7 @@ var ts; globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray"); globalESSymbolType = getGlobalType("Symbol"); globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"); + globalIterableType = getGlobalType("Iterable", 1); } else { globalTemplateStringsArrayType = unknownType; @@ -16404,14 +16918,14 @@ var ts; for (var i = 0, n = node.modifiers.length; i < n; i++) { var modifier = node.modifiers[i]; switch (modifier.kind) { - case 109: case 108: case 107: + case 106: var text; - if (modifier.kind === 109) { + if (modifier.kind === 108) { text = "public"; } - else if (modifier.kind === 108) { + else if (modifier.kind === 107) { text = "protected"; lastProtected = modifier; } @@ -16430,7 +16944,7 @@ var ts; } flags |= ts.modifierToFlag(modifier.kind); break; - case 110: + case 109: if (flags & 128) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } @@ -16458,7 +16972,7 @@ var ts; } flags |= 1; break; - case 115: + case 114: if (flags & 2) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); } @@ -16564,7 +17078,7 @@ var ts; if (parameter.dotDotDotToken) { return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter); } - if (parameter.flags & 243) { + if (parameter.flags & 499) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); } if (parameter.questionToken) { @@ -16576,7 +17090,7 @@ var ts; if (!parameter.type) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); } - if (parameter.type.kind !== 121 && parameter.type.kind !== 119) { + if (parameter.type.kind !== 120 && parameter.type.kind !== 118) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); } if (!node.type) { @@ -16584,7 +17098,7 @@ var ts; } } function checkGrammarForIndexSignatureModifier(node) { - if (node.flags & 243) { + if (node.flags & 499) { grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members); } } @@ -16649,7 +17163,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103); + ts.Debug.assert(heritageClause.token === 102); if (seenImplementsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); } @@ -16672,7 +17186,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103); + ts.Debug.assert(heritageClause.token === 102); return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); } checkGrammarHeritageClause(heritageClause); @@ -16769,29 +17283,28 @@ var ts; var variableList = forInOrOfStatement.initializer; if (!checkGrammarVariableDeclarationList(variableList)) { if (variableList.declarations.length > 1) { - var diagnostic = forInOrOfStatement.kind === 182 ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement; + var diagnostic = forInOrOfStatement.kind === 182 + ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement + : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement; return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic); } var firstDeclaration = variableList.declarations[0]; if (firstDeclaration.initializer) { - var diagnostic = forInOrOfStatement.kind === 182 ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer; + var diagnostic = forInOrOfStatement.kind === 182 + ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer + : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer; return grammarErrorOnNode(firstDeclaration.name, diagnostic); } if (firstDeclaration.type) { - var diagnostic = forInOrOfStatement.kind === 182 ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation; + var diagnostic = forInOrOfStatement.kind === 182 + ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation + : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation; return grammarErrorOnNode(firstDeclaration, diagnostic); } } } return false; } - function checkGrammarForOfStatement(forOfStatement) { - return grammarErrorOnFirstToken(forOfStatement, ts.Diagnostics.for_of_statements_are_not_currently_supported); - if (languageVersion < 2) { - return grammarErrorOnFirstToken(forOfStatement, ts.Diagnostics.for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher); - } - return checkGrammarForInOrForOfStatement(forOfStatement); - } function checkGrammarAccessor(accessor) { var kind = accessor.kind; if (languageVersion < 1) { @@ -16821,7 +17334,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 & 499) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } else if (parameter.questionToken) { @@ -16886,13 +17399,14 @@ var ts; function checkGrammarBreakOrContinueStatement(node) { var current = node; while (current) { - if (ts.isAnyFunction(current)) { + if (ts.isFunctionLike(current)) { return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } switch (current.kind) { case 189: if (node.label && current.label.text === node.label.text) { - var isMisplacedContinueLabel = node.kind === 184 && !isIterationStatement(current.statement, true); + var isMisplacedContinueLabel = node.kind === 184 + && !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); } @@ -16913,11 +17427,15 @@ var ts; current = current.parent; } if (node.label) { - var message = node.kind === 185 ? 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 === 185 + ? 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 === 185 ? 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 === 185 + ? 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); } } @@ -16934,16 +17452,17 @@ var ts; return checkGrammarEvalOrArgumentsInStrictMode(node, node.name); } function checkGrammarVariableDeclaration(node) { - if (ts.isInAmbientContext(node)) { - if (ts.isBindingPattern(node.name)) { - return grammarErrorOnNode(node, ts.Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); + if (node.parent.parent.kind !== 182 && node.parent.parent.kind !== 183) { + if (ts.isInAmbientContext(node)) { + if (ts.isBindingPattern(node.name)) { + return grammarErrorOnNode(node, ts.Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); + } + if (node.initializer) { + var equalsTokenLength = "=".length; + return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, equalsTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } } - if (node.initializer) { - return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - 1, 1, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); - } - } - else { - if (!node.initializer) { + else if (!node.initializer) { if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) { return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer); } @@ -16977,14 +17496,6 @@ var ts; if (!declarationList.declarations.length) { return grammarErrorAtPos(ts.getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); } - if (languageVersion < 2) { - if (ts.isLet(declarationList)) { - return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (ts.isConst(declarationList)) { - return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - } } function allowLetAndConstDeclarations(parent) { switch (parent.kind) { @@ -17024,7 +17535,7 @@ var ts; return false; } function checkGrammarEnumDeclaration(enumDecl) { - var enumIsConst = (enumDecl.flags & 4096) !== 0; + var enumIsConst = (enumDecl.flags & 8192) !== 0; var hasError = false; if (!enumIsConst) { var inConstantEnumMemberSection = true; @@ -17052,18 +17563,11 @@ var ts; function hasParseDiagnostics(sourceFile) { return sourceFile.parseDiagnostics.length > 0; } - function scanToken(scanner, pos) { - scanner.setTextPos(pos); - scanner.scan(); - var start = scanner.getTokenPos(); - return start; - } function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = ts.createScanner(languageVersion, true, sourceFile.text); - var start = scanToken(scanner, node.pos); - diagnostics.add(ts.createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2)); + var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos); + diagnostics.add(ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2)); return true; } } @@ -17076,16 +17580,17 @@ var ts; function grammarErrorOnNode(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var span = ts.getErrorSpanForNode(node); - var start = span.end > span.pos ? ts.skipTrivia(sourceFile.text, span.pos) : span.pos; - diagnostics.add(ts.createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2)); + diagnostics.add(ts.createDiagnosticForNode(node, message, arg0, arg1, arg2)); return true; } } - function checkGrammarEvalOrArgumentsInStrictMode(contextNode, identifier) { - if (contextNode && (contextNode.parserContextFlags & 1) && ts.isEvalOrArgumentsIdentifier(identifier)) { - var name = ts.declarationNameToString(identifier); - return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, name); + function checkGrammarEvalOrArgumentsInStrictMode(contextNode, name) { + if (name && name.kind === 64) { + var identifier = name; + if (contextNode && (contextNode.parserContextFlags & 1) && ts.isEvalOrArgumentsIdentifier(identifier)) { + var nameText = ts.declarationNameToString(identifier); + return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); + } } } function checkGrammarConstructorTypeParameters(node) { @@ -17149,7 +17654,7 @@ var ts; return getNodeLinks(node).hasReportedStatementInAmbientContext = true; } var links = getNodeLinks(node); - if (!links.hasReportedStatementInAmbientContext && ts.isAnyFunction(node.parent)) { + if (!links.hasReportedStatementInAmbientContext && ts.isFunctionLike(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); } if (node.parent.kind === 174 || node.parent.kind === 201 || node.parent.kind === 220) { @@ -17163,7 +17668,7 @@ var ts; } } function checkGrammarNumbericLiteral(node) { - if (node.flags & 8192) { + if (node.flags & 16384) { if (node.parserContextFlags & 1) { return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); } @@ -17175,9 +17680,8 @@ var ts; function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = ts.createScanner(languageVersion, true, sourceFile.text); - scanToken(scanner, node.pos); - diagnostics.add(ts.createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2)); + var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos); + diagnostics.add(ts.createFileDiagnostic(sourceFile, ts.textSpanEnd(span), 0, message, arg0, arg1, arg2)); return true; } } @@ -17306,7 +17810,9 @@ var ts; var lineCount = ts.getLineStarts(currentSourceFile).length; var firstCommentLineIndent; for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - var nextLineStart = (currentLine + 1) === lineCount ? currentSourceFile.text.length + 1 : ts.getStartPositionOfLine(currentLine + 1, currentSourceFile); + var nextLineStart = (currentLine + 1) === lineCount + ? currentSourceFile.text.length + 1 + : ts.getStartPositionOfLine(currentLine + 1, currentSourceFile); if (pos !== comment.pos) { if (firstCommentLineIndent === undefined) { firstCommentLineIndent = calculateIndent(ts.getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos); @@ -17384,7 +17890,8 @@ var ts; } else { ts.forEach(declarations, function (member) { - if ((member.kind === 134 || member.kind === 135) && (member.flags & 128) === (accessor.flags & 128)) { + if ((member.kind === 134 || member.kind === 135) + && (member.flags & 128) === (accessor.flags & 128)) { var memberName = ts.getPropertyNameForPropertyNameNode(member.name); var accessorName = ts.getPropertyNameForPropertyNameNode(accessor.name); if (memberName === accessorName) { @@ -17449,7 +17956,7 @@ var ts; var addedGlobalFileReference = false; ts.forEach(root.referencedFiles, function (fileReference) { var referencedFile = ts.tryResolveScriptReference(host, root, fileReference); - if (referencedFile && ((referencedFile.flags & 1024) || + if (referencedFile && ((referencedFile.flags & 2048) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) { writeReferencePath(referencedFile); @@ -17608,11 +18115,11 @@ var ts; } function emitType(type) { switch (type.kind) { + case 111: + case 120: + case 118: case 112: case 121: - case 119: - case 113: - case 122: case 98: case 8: return writeTextOfNode(currentSourceFile, type); @@ -17702,8 +18209,8 @@ var ts; emitLines(node.statements); } function emitExportAssignment(node) { - write("export = "); - writeTextOfNode(currentSourceFile, node.exportName); + write(node.isExportEquals ? "export = " : "export default "); + writeTextOfNode(currentSourceFile, node.expression); write(";"); writeLine(); } @@ -17919,7 +18426,9 @@ var ts; function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; if (node.parent.parent.kind === 196) { - 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; + 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 { diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; @@ -18012,17 +18521,31 @@ var ts; function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; if (node.kind === 193) { - 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; + 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 === 130 || node.kind === 129) { 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; + 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 === 196) { - 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; + 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 { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; } } return diagnosticMessage !== undefined ? { @@ -18084,17 +18607,25 @@ var ts; } function getTypeAnnotationFromAccessor(accessor) { if (accessor) { - return accessor.kind === 134 ? accessor.type : accessor.parameters.length > 0 ? accessor.parameters[0].type : undefined; + return accessor.kind === 134 + ? accessor.type + : accessor.parameters.length > 0 + ? accessor.parameters[0].type + : undefined; } } function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; if (accessorWithTypeAnnotation.kind === 135) { 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; + 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; } else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; } return { diagnosticMessage: diagnosticMessage, @@ -18104,10 +18635,18 @@ var ts; } else { if (accessorWithTypeAnnotation.flags & 128) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === 2 ? + ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; } else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === 2 ? + ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; } return { diagnosticMessage: diagnosticMessage, @@ -18189,28 +18728,48 @@ var ts; var diagnosticMessage; switch (node.kind) { case 137: - 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; + 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 136: - 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; + 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 138: - 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; + 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 132: case 131: 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; + 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 === 196) { - 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; + 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; + 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 195: - 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; + 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: ts.Debug.fail("This is unknown kind for signature: " + node.kind); @@ -18249,28 +18808,50 @@ var ts; var diagnosticMessage; switch (node.parent.kind) { case 133: - 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; + 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 137: - 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; + 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 136: - 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; + 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 132: case 131: 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; + 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 === 196) { - 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; + 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; + 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 195: - 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; + 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: ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind); @@ -18322,7 +18903,11 @@ var ts; } } function writeReferencePath(referencedFile) { - var declFileName = referencedFile.flags & 1024 ? referencedFile.fileName : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; + var declFileName = referencedFile.flags & 2048 + ? referencedFile.fileName + : shouldEmitToOwnFile(referencedFile, compilerOptions) + ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") + : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, host.getCurrentDirectory(), host.getCanonicalFileName, false); referencePathsOutput += "/// " + newLine; } @@ -18374,12 +18959,16 @@ var ts; var increaseIndent = writer.increaseIndent; var decreaseIndent = writer.decreaseIndent; var currentSourceFile; + var lastFrame; + var currentScopeNames; + var generatedBlockScopeNames; var extendsEmitted = false; var tempCount = 0; var tempVariables; var tempParameters; var externalImports; var exportSpecifiers; + var exportDefault; var writeEmittedFiles = writeJavaScriptFile; var emitLeadingComments = compilerOptions.removeComments ? function (node) { } : emitLeadingDeclarationComments; var emitTrailingComments = compilerOptions.removeComments ? function (node) { } : emitTrailingDeclarationComments; @@ -18411,6 +19000,53 @@ var ts; writeLine(); writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); return; + function enterNameScope() { + var names = currentScopeNames; + currentScopeNames = undefined; + if (names) { + lastFrame = { names: names, previous: lastFrame }; + return true; + } + return false; + } + function exitNameScope(popFrame) { + if (popFrame) { + currentScopeNames = lastFrame.names; + lastFrame = lastFrame.previous; + } + else { + currentScopeNames = undefined; + } + } + function generateUniqueNameForLocation(location, baseName) { + var name; + if (!isExistingName(location, baseName)) { + name = baseName; + } + else { + name = ts.generateUniqueName(baseName, function (n) { return isExistingName(location, n); }); + } + if (!currentScopeNames) { + currentScopeNames = {}; + } + return currentScopeNames[name] = name; + } + function isExistingName(location, name) { + if (!resolver.isUnknownIdentifier(location, name)) { + return true; + } + if (currentScopeNames && ts.hasProperty(currentScopeNames, name)) { + return true; + } + var frame = lastFrame; + while (frame) { + if (ts.hasProperty(frame.names, name)) { + return true; + } + frame = frame.previous; + } + return false; + } function initializeEmitterWithSourceMaps() { var sourceMapDir; var sourceMapSourceIndex = -1; @@ -18564,7 +19200,9 @@ var ts; node.kind === 199) { if (node.name) { var name = node.name; - scopeName = name.kind === 126 ? ts.getTextOfNode(name) : node.name.text; + scopeName = name.kind === 126 + ? ts.getTextOfNode(name) + : node.name.text; } recordScopeNameStart(scopeName); } @@ -18670,13 +19308,13 @@ var ts; function createTempVariable(location, forLoopVariable) { var name = forLoopVariable ? "_i" : undefined; while (true) { - if (name && resolver.isUnknownIdentifier(location, name)) { + if (name && !isExistingName(location, name)) { break; } name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + 97) : tempCount - 25); tempCount++; } - var result = ts.createNode(64); + var result = ts.createSynthesizedNode(64); result.text = name; return result; } @@ -18720,7 +19358,7 @@ var ts; emit(node); } } - function emitParenthesized(node, parenthesized) { + function emitParenthesizedIf(node, parenthesized) { if (parenthesized) { write("("); } @@ -18807,37 +19445,109 @@ var ts; emit(nodes[i]); } } - function isBinaryOrOctalIntegerLiteral(text) { - if (text.length <= 0) { - return false; - } - if (text.charCodeAt(1) === 66 || text.charCodeAt(1) === 98 || - text.charCodeAt(1) === 79 || text.charCodeAt(1) === 111) { - return true; + function isBinaryOrOctalIntegerLiteral(node, text) { + if (node.kind === 7 && text.length > 1) { + switch (text.charCodeAt(1)) { + case 98: + case 66: + case 111: + case 79: + return true; + } } 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 = getLiteralText(node); if (compilerOptions.sourceMap && (node.kind === 8 || ts.isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } - else if (languageVersion < 2 && node.kind === 7 && isBinaryOrOctalIntegerLiteral(text)) { + else if (languageVersion < 2 && isBinaryOrOctalIntegerLiteral(node, text)) { write(node.text); } else { write(text); } } - function getTemplateLiteralAsStringLiteral(node) { - return '"' + ts.escapeString(node.text) + '"'; + function getLiteralText(node) { + if (languageVersion < 2 && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { + return getQuotedEscapedLiteralText('"', node.text, '"'); + } + if (node.parent) { + return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + } + switch (node.kind) { + case 8: + return getQuotedEscapedLiteralText('"', node.text, '"'); + case 10: + return getQuotedEscapedLiteralText('`', node.text, '`'); + case 11: + return getQuotedEscapedLiteralText('`', node.text, '${'); + case 12: + return getQuotedEscapedLiteralText('}', node.text, '${'); + case 13: + return getQuotedEscapedLiteralText('}', node.text, '`'); + case 7: + return node.text; + } + ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for."); + } + function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) { + return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote; + } + function emitDownlevelRawTemplateLiteral(node) { + var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + var isLast = node.kind === 10 || node.kind === 13; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + text = text.replace(/\r\n?/g, "\n"); + text = ts.escapeString(text); + write('"' + text + '"'); + } + function emitDownlevelTaggedTemplateArray(node, literalEmitter) { + write("["); + if (node.template.kind === 10) { + literalEmitter(node.template); + } + else { + literalEmitter(node.template.head); + ts.forEach(node.template.templateSpans, function (child) { + write(", "); + literalEmitter(child.literal); + }); + } + write("]"); + } + function emitDownlevelTaggedTemplate(node) { + var tempVariable = createAndRecordTempVariable(node); + write("("); + emit(tempVariable); + write(" = "); + emitDownlevelTaggedTemplateArray(node, emit); + write(", "); + emit(tempVariable); + write(".raw = "); + emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); + write(", "); + emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); + write("("); + emit(tempVariable); + if (node.template.kind === 169) { + ts.forEach(node.template.templateSpans, function (templateSpan) { + write(", "); + var needsParens = templateSpan.expression.kind === 167 + && templateSpan.expression.operatorToken.kind === 23; + emitParenthesizedIf(templateSpan.expression, needsParens); + }); + } + write("))"); } function emitTemplateExpression(node) { if (languageVersion >= 2) { ts.forEachChild(node, emit); return; } - var emitOuterParens = ts.isExpression(node.parent) && templateNeedsParens(node, node.parent); + var emitOuterParens = ts.isExpression(node.parent) + && templateNeedsParens(node, node.parent); if (emitOuterParens) { write("("); } @@ -18848,11 +19558,12 @@ var ts; } for (var i = 0; i < node.templateSpans.length; i++) { var templateSpan = node.templateSpans[i]; - var needsParens = templateSpan.expression.kind !== 159 && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; + var needsParens = templateSpan.expression.kind !== 159 + && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; if (i > 0 || headEmitted) { write(" + "); } - emitParenthesized(templateSpan.expression, needsParens); + emitParenthesizedIf(templateSpan.expression, needsParens); if (templateSpan.literal.text.length !== 0) { write(" + "); emitLiteral(templateSpan.literal); @@ -18950,8 +19661,6 @@ var ts; return false; case 189: return node.parent.label === node; - case 216: - return node.parent.name === node; } } function emitExpressionIdentifier(node) { @@ -18963,7 +19672,18 @@ var ts; writeTextOfNode(currentSourceFile, node); } } + function getBlockScopedVariableId(node) { + return !ts.nodeIsSynthesized(node) && resolver.getBlockScopedVariableId(node); + } function emitIdentifier(node) { + var variableId = getBlockScopedVariableId(node); + if (variableId !== undefined && generatedBlockScopeNames) { + var text = generatedBlockScopeNames[variableId]; + if (text) { + write(text); + return; + } + } if (!node.parent) { write(node.text); } @@ -19026,7 +19746,7 @@ var ts; write("..."); emit(node.expression); } - function needsParenthesisForPropertyAccess(node) { + function needsParenthesisForPropertyAccessOrInvocation(node) { switch (node.kind) { case 64: case 151: @@ -19052,7 +19772,7 @@ var ts; var e = elements[pos]; if (e.kind === 171) { e = e.expression; - emitParenthesized(e, group === 0 && needsParenthesisForPropertyAccess(e)); + emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; } else { @@ -19091,24 +19811,18 @@ var ts; write("]"); } else { - emitListWithSpread(elements, (node.flags & 256) !== 0, elements.hasTrailingComma); + emitListWithSpread(elements, (node.flags & 512) !== 0, elements.hasTrailingComma); } } - function createSynthesizedNode(kind) { - var node = ts.createNode(kind); - node.pos = -1; - node.end = -1; - return node; - } function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) { var parenthesizedObjectLiteral = createDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex); return emit(parenthesizedObjectLiteral); } function createDownlevelObjectLiteralWithComputedProperties(originalObjectLiteral, firstComputedPropertyIndex) { var tempVar = createAndRecordTempVariable(originalObjectLiteral); - var initialObjectLiteral = createSynthesizedNode(152); + var initialObjectLiteral = ts.createSynthesizedNode(152); initialObjectLiteral.properties = originalObjectLiteral.properties.slice(0, firstComputedPropertyIndex); - initialObjectLiteral.flags |= 256; + initialObjectLiteral.flags |= 512; var propertyPatches = createBinaryExpression(tempVar, 52, initialObjectLiteral); ts.forEach(originalObjectLiteral.properties, function (property) { var patchedProperty = tryCreatePatchingPropertyAssignment(originalObjectLiteral, tempVar, property); @@ -19116,7 +19830,7 @@ var ts; propertyPatches = createBinaryExpression(propertyPatches, 23, patchedProperty); } }); - propertyPatches = createBinaryExpression(propertyPatches, 23, tempVar); + propertyPatches = createBinaryExpression(propertyPatches, 23, createIdentifier(tempVar.text, true)); var result = createParenthesizedExpression(propertyPatches); return result; } @@ -19127,7 +19841,7 @@ var ts; function tryCreatePatchingPropertyAssignment(objectLiteral, tempVar, property) { var leftHandSide = createMemberAccessForPropertyName(tempVar, property.name); var maybeRightHandSide = tryGetRightHandSideOfPatchingPropertyAssignment(objectLiteral, property); - return maybeRightHandSide && createBinaryExpression(leftHandSide, 52, maybeRightHandSide); + return maybeRightHandSide && createBinaryExpression(leftHandSide, 52, maybeRightHandSide, true); } function tryGetRightHandSideOfPatchingPropertyAssignment(objectLiteral, property) { switch (property.kind) { @@ -19143,7 +19857,7 @@ var ts; if (firstAccessor !== property) { return undefined; } - var propertyDescriptor = createSynthesizedNode(152); + var propertyDescriptor = ts.createSynthesizedNode(152); var descriptorProperties = []; if (getAccessor) { var getProperty = createPropertyAssignment(createIdentifier("get"), createFunctionExpression(getAccessor.parameters, getAccessor.body)); @@ -19153,7 +19867,7 @@ var ts; var setProperty = createPropertyAssignment(createIdentifier("set"), createFunctionExpression(setAccessor.parameters, setAccessor.body)); descriptorProperties.push(setProperty); } - var trueExpr = createSynthesizedNode(94); + var trueExpr = ts.createSynthesizedNode(94); var enumerableTrue = createPropertyAssignment(createIdentifier("enumerable"), trueExpr); descriptorProperties.push(enumerableTrue); var configurableTrue = createPropertyAssignment(createIdentifier("configurable"), trueExpr); @@ -19166,7 +19880,7 @@ var ts; } } function createParenthesizedExpression(expression) { - var result = createSynthesizedNode(159); + var result = ts.createSynthesizedNode(159); result.expression = expression; return result; } @@ -19180,9 +19894,9 @@ var ts; result.end = -1; return result; } - function createBinaryExpression(left, operator, right) { - var result = createSynthesizedNode(167); - result.operatorToken = createSynthesizedNode(operator); + function createBinaryExpression(left, operator, right, startsOnNewLine) { + var result = ts.createSynthesizedNode(167, startsOnNewLine); + result.operatorToken = ts.createSynthesizedNode(operator); result.left = left; result.right = right; return result; @@ -19202,36 +19916,37 @@ var ts; } } function createPropertyAssignment(name, initializer) { - var result = createSynthesizedNode(217); + var result = ts.createSynthesizedNode(217); result.name = name; result.initializer = initializer; return result; } function createFunctionExpression(parameters, body) { - var result = createSynthesizedNode(160); + var result = ts.createSynthesizedNode(160); result.parameters = parameters; result.body = body; return result; } function createPropertyAccessExpression(expression, name) { - var result = createSynthesizedNode(153); + var result = ts.createSynthesizedNode(153); result.expression = expression; + result.dotToken = ts.createSynthesizedNode(20); result.name = name; return result; } function createElementAccessExpression(expression, argumentExpression) { - var result = createSynthesizedNode(154); + var result = ts.createSynthesizedNode(154); result.expression = expression; result.argumentExpression = argumentExpression; return result; } - function createIdentifier(name) { - var result = createSynthesizedNode(64); + function createIdentifier(name, startsOnNewLine) { + var result = ts.createSynthesizedNode(64, startsOnNewLine); result.text = name; return result; } function createCallExpression(invokedExpression, arguments) { - var result = createSynthesizedNode(155); + var result = ts.createSynthesizedNode(155); result.expression = invokedExpression; result.arguments = arguments; return result; @@ -19296,13 +20011,29 @@ var ts; } return false; } + function indentIfOnDifferentLines(parent, node1, node2) { + var isSynthesized = ts.nodeIsSynthesized(parent); + var realNodesAreOnDifferentLines = !isSynthesized && !nodeEndIsOnSameLineAsNodeStart(node1, node2); + var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2); + if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) { + increaseIndent(); + writeLine(); + return true; + } + return false; + } function emitPropertyAccess(node) { if (tryEmitConstantValue(node)) { return; } emit(node.expression); + var indented = indentIfOnDifferentLines(node, node.expression, node.dotToken); write("."); + indented = indented || indentIfOnDifferentLines(node, node.dotToken, node.name); emit(node.name); + if (indented) { + decreaseIndent(); + } } function emitQualifiedName(node) { emit(node.left); @@ -19416,26 +20147,33 @@ var ts; } } function emitTaggedTemplateExpression(node) { - emit(node.tag); - write(" "); - emit(node.template); + if (compilerOptions.target >= 2) { + emit(node.tag); + write(" "); + emit(node.template); + } + else { + emitDownlevelTaggedTemplate(node); + } } function emitParenExpression(node) { - if (node.expression.kind === 158) { - var operand = node.expression.expression; - while (operand.kind == 158) { - operand = operand.expression; - } - if (operand.kind !== 165 && - operand.kind !== 164 && - operand.kind !== 163 && - operand.kind !== 162 && - operand.kind !== 166 && - operand.kind !== 156 && - !(operand.kind === 155 && node.parent.kind === 156) && - !(operand.kind === 160 && node.parent.kind === 155)) { - emit(operand); - return; + if (!node.parent || node.parent.kind !== 161) { + if (node.expression.kind === 158) { + var operand = node.expression.expression; + while (operand.kind == 158) { + operand = operand.expression; + } + if (operand.kind !== 165 && + operand.kind !== 164 && + operand.kind !== 163 && + operand.kind !== 162 && + operand.kind !== 166 && + operand.kind !== 156 && + !(operand.kind === 155 && node.parent.kind === 156) && + !(operand.kind === 160 && node.parent.kind === 155)) { + emit(operand); + return; + } } } write("("); @@ -19481,48 +20219,58 @@ var ts; } else { emit(node.left); - if (node.operatorToken.kind !== 23) { + var indented1 = indentIfOnDifferentLines(node, node.left, node.operatorToken); + if (!indented1 && node.operatorToken.kind !== 23) { write(" "); } write(ts.tokenToString(node.operatorToken.kind)); - var operatorEnd = ts.getLineAndCharacterOfPosition(currentSourceFile, node.operatorToken.end); - var rightStart = ts.getLineAndCharacterOfPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.right.pos)); - var onDifferentLine = operatorEnd.line !== rightStart.line; - if (onDifferentLine) { - var exprStart = ts.getLineAndCharacterOfPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); - var firstCharOfExpr = getFirstNonWhitespaceCharacterIndexOnLine(exprStart.line); - var shouldIndent = rightStart.character > firstCharOfExpr; - if (shouldIndent) { - increaseIndent(); - } - writeLine(); + if (!indented1) { + var indented2 = indentIfOnDifferentLines(node, node.operatorToken, node.right); } - else { + if (!indented2) { write(" "); } emit(node.right); - if (shouldIndent) { + if (indented1 || indented2) { decreaseIndent(); } } } - function getFirstNonWhitespaceCharacterIndexOnLine(line) { - var lineStart = ts.getLineStarts(currentSourceFile)[line]; - var text = currentSourceFile.text; - for (var i = lineStart; i < text.length; i++) { - var ch = text.charCodeAt(i); - if (!ts.isWhiteSpace(text.charCodeAt(i)) || ts.isLineBreak(ch)) { - break; - } - } - return i - lineStart; + function synthesizedNodeStartsOnNewLine(node) { + return ts.nodeIsSynthesized(node) && node.startsOnNewLine; } function emitConditionalExpression(node) { emit(node.condition); - write(" ? "); + var indent1 = indentIfOnDifferentLines(node, node.condition, node.questionToken); + if (!indent1) { + write(" "); + } + write("?"); + if (!indent1) { + var indent2 = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue); + } + if (!indent2) { + write(" "); + } emit(node.whenTrue); - write(" : "); + if (indent1 || indent2) { + decreaseIndent(); + } + var indent3 = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken); + if (!indent3) { + write(" "); + } + write(":"); + if (!indent3) { + var indent4 = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse); + } + if (!indent4) { + write(" "); + } emit(node.whenFalse); + if (indent3 || indent4) { + decreaseIndent(); + } } function isSingleLineEmptyBlock(node) { if (node && node.kind === 174) { @@ -19566,7 +20314,7 @@ var ts; } } function emitExpressionStatement(node) { - emitParenthesized(node.expression, node.expression.kind === 161); + emitParenthesizedIf(node.expression, node.expression.kind === 161); write(";"); } function emitIfStatement(node) { @@ -19607,6 +20355,30 @@ var ts; write(")"); emitEmbeddedStatement(node.statement); } + function emitStartOfVariableDeclarationList(decl, startPos) { + var tokenKind = 97; + if (decl && languageVersion >= 2) { + if (ts.isLet(decl)) { + tokenKind = 104; + } + else if (ts.isConst(decl)) { + tokenKind = 69; + } + } + if (startPos !== undefined) { + emitToken(tokenKind, startPos); + } + else { + switch (tokenKind) { + case 97: + return write("var "); + case 104: + return write("let "); + case 69: + return write("const "); + } + } + } function emitForStatement(node) { var endPos = emitToken(81, node.pos); write(" "); @@ -19614,17 +20386,9 @@ var ts; if (node.initializer && node.initializer.kind === 194) { var variableDeclarationList = node.initializer; var declarations = variableDeclarationList.declarations; - if (declarations[0] && ts.isLet(declarations[0])) { - emitToken(105, endPos); - } - else if (declarations[0] && ts.isConst(declarations[0])) { - emitToken(69, endPos); - } - else { - emitToken(97, endPos); - } + emitStartOfVariableDeclarationList(declarations[0], endPos); write(" "); - emitCommaList(variableDeclarationList.declarations); + emitCommaList(declarations); } else if (node.initializer) { emit(node.initializer); @@ -19644,12 +20408,7 @@ var ts; var variableDeclarationList = node.initializer; if (variableDeclarationList.declarations.length >= 1) { var decl = variableDeclarationList.declarations[0]; - if (ts.isLet(decl)) { - emitToken(105, endPos); - } - else { - emitToken(97, endPos); - } + emitStartOfVariableDeclarationList(decl, endPos); write(" "); emit(decl); } @@ -19748,8 +20507,8 @@ var ts; var endPos = emitToken(67, node.pos); write(" "); emitToken(16, endPos); - emit(node.name); - emitToken(17, node.name.end); + emit(node.variableDeclaration); + emitToken(17, node.variableDeclaration ? node.variableDeclaration.end : endPos); write(" "); emitBlock(node.block); } @@ -19781,8 +20540,15 @@ var ts; emitNode(node.name); emitEnd(node.name); } + function createVoidZero() { + var zero = ts.createSynthesizedNode(7); + zero.text = "0"; + var result = ts.createSynthesizedNode(164); + result.expression = zero; + return result; + } function emitExportMemberAssignments(name) { - if (exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { + if (!exportDefault && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { ts.forEach(exportSpecifiers[name.text], function (specifier) { writeLine(); emitStart(specifier.name); @@ -19809,6 +20575,7 @@ var ts; if (emitCount++) { write(", "); } + renameNonTopLevelLetAndConst(name); if (name.parent && (name.parent.kind === 193 || name.parent.kind === 150)) { emitModuleMemberName(name.parent); } @@ -19829,27 +20596,25 @@ var ts; } return expr; } - function createVoidZero() { - var zero = ts.createNode(7); - zero.text = "0"; - var result = ts.createNode(164); - result.expression = zero; - return result; - } function createDefaultValueCheck(value, defaultValue) { value = ensureIdentifier(value); - var equals = ts.createNode(167); + var equals = ts.createSynthesizedNode(167); equals.left = value; - equals.operatorToken = ts.createNode(30); + equals.operatorToken = ts.createSynthesizedNode(30); equals.right = createVoidZero(); - var cond = ts.createNode(168); - cond.condition = equals; - cond.whenTrue = defaultValue; - cond.whenFalse = value; + return createConditionalExpression(equals, defaultValue, value); + } + function createConditionalExpression(condition, whenTrue, whenFalse) { + var cond = ts.createSynthesizedNode(168); + cond.condition = condition; + cond.questionToken = ts.createSynthesizedNode(50); + cond.whenTrue = whenTrue; + cond.colonToken = ts.createSynthesizedNode(51); + cond.whenFalse = whenFalse; return cond; } function createNumericLiteral(value) { - var node = ts.createNode(7); + var node = ts.createSynthesizedNode(7); node.text = "" + value; return node; } @@ -19857,7 +20622,7 @@ var ts; if (expr.kind === 64 || expr.kind === 153 || expr.kind === 154) { return expr; } - var node = ts.createNode(159); + var node = ts.createSynthesizedNode(159); node.expression = expr; return node; } @@ -19865,13 +20630,10 @@ var ts; if (propName.kind !== 64) { return createElementAccess(object, propName); } - var node = ts.createNode(153); - node.expression = parenthesizeForAccess(object); - node.name = propName; - return node; + return createPropertyAccessExpression(parenthesizeForAccess(object), propName); } function createElementAccess(object, index) { - var node = ts.createNode(154); + var node = ts.createSynthesizedNode(154); node.expression = parenthesizeForAccess(object); node.argumentExpression = index; return node; @@ -19993,8 +20755,19 @@ var ts; } } else { + var isLet = renameNonTopLevelLetAndConst(node.name); emitModuleMemberName(node); - emitOptional(" = ", node.initializer); + var initializer = node.initializer; + if (!initializer && languageVersion < 2) { + var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 256) && + (getCombinedFlagsForIdentifier(node.name) & 4096); + if (isUninitializedLet && + node.parent.parent.kind !== 182 && + node.parent.parent.kind !== 183) { + initializer = createVoidZero(); + } + } + emitOptional(" = ", initializer); } } function emitExportVariableAssignments(node) { @@ -20006,17 +20779,64 @@ var ts; ts.forEach(name.elements, emitExportVariableAssignments); } } + function getEnclosingBlockScopeContainer(node) { + var current = node; + while (current) { + if (ts.isFunctionLike(current)) { + return current; + } + switch (current.kind) { + case 220: + case 91: + case 216: + case 200: + case 181: + case 182: + case 183: + return current; + case 174: + if (!ts.isFunctionLike(current.parent)) { + return current; + } + } + current = current.parent; + } + } + function getCombinedFlagsForIdentifier(node) { + if (!node.parent || (node.parent.kind !== 193 && node.parent.kind !== 150)) { + return 0; + } + return ts.getCombinedNodeFlags(node.parent); + } + function renameNonTopLevelLetAndConst(node) { + if (languageVersion >= 2 || + ts.nodeIsSynthesized(node) || + node.kind !== 64 || + (node.parent.kind !== 193 && node.parent.kind !== 150)) { + return; + } + var combinedFlags = getCombinedFlagsForIdentifier(node); + if (((combinedFlags & 12288) === 0) || combinedFlags & 1) { + return; + } + var list = ts.getAncestor(node, 194); + if (list.parent.kind === 175 && list.parent.parent.kind === 220) { + return; + } + var blockScopeContainer = getEnclosingBlockScopeContainer(node); + var parent = blockScopeContainer.kind === 220 + ? blockScopeContainer + : blockScopeContainer.parent; + var generatedName = generateUniqueNameForLocation(parent, node.text); + var variableId = resolver.getBlockScopedVariableId(node); + if (!generatedBlockScopeNames) { + generatedBlockScopeNames = []; + } + generatedBlockScopeNames[variableId] = generatedName; + } function emitVariableStatement(node) { if (!(node.flags & 1)) { - if (ts.isLet(node.declarationList)) { - write("let "); - } - else if (ts.isConst(node.declarationList)) { - write("const "); - } - else { - write("var "); - } + emitStartOfVariableDeclarationList(node.declarationList); } emitCommaList(node.declarationList.declarations); write(";"); @@ -20121,6 +20941,14 @@ var ts; function shouldEmitAsArrowFunction(node) { return node.kind === 161 && languageVersion >= 2; } + function emitDeclarationName(node) { + if (node.name) { + emitNode(node.name); + } + else { + write(resolver.getGeneratedNameForNode(node)); + } + } function emitFunctionDeclaration(node) { if (ts.nodeIsMissing(node.body)) { return emitPinnedOrTripleSlashComments(node); @@ -20132,10 +20960,10 @@ var ts; write("function "); } if (node.kind === 195 || (node.kind === 160 && node.name)) { - emit(node.name); + emitDeclarationName(node); } emitSignatureAndBody(node); - if (languageVersion < 2 && node.kind === 195 && node.parent === currentSourceFile) { + if (languageVersion < 2 && node.kind === 195 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } if (node.kind !== 132 && node.kind !== 131) { @@ -20175,6 +21003,7 @@ var ts; tempCount = 0; tempVariables = undefined; tempParameters = undefined; + var popFrame = enterNameScope(); if (shouldEmitAsArrowFunction(node)) { emitSignatureParametersForArrow(node); write(" =>"); @@ -20191,15 +21020,16 @@ var ts; else { emitExpressionFunctionBody(node, node.body); } - if (node.flags & 1) { + if (node.flags & 1 && !(node.flags & 256)) { writeLine(); emitStart(node); emitModuleMemberName(node); write(" = "); - emit(node.name); + emitDeclarationName(node); emitEnd(node); write(";"); } + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; @@ -20215,7 +21045,11 @@ var ts; return; } write(" "); - emit(body); + var current = body; + while (current.kind === 158) { + current = current.expression; + } + emitParenthesizedIf(body, current.kind === 152); } function emitDownLevelExpressionFunctionBody(node, body) { write(" {"); @@ -20254,45 +21088,15 @@ var ts; scopeEmitEnd(); } function emitBlockFunctionBody(node, body) { - if (body.statements.length === 0 && !anyParameterHasBindingPatternOrInitializer(node)) { - emitFunctionBodyWithNoStatements(node, body); - } - else { - emitFunctionBodyWithStatements(node, body); - } - } - function anyParameterHasBindingPatternOrInitializer(func) { - return ts.forEach(func.parameters, hasBindingPatternOrInitializer); - } - function hasBindingPatternOrInitializer(parameter) { - return parameter.initializer || ts.isBindingPattern(parameter.name); - } - function emitFunctionBodyWithNoStatements(node, body) { - var singleLine = isSingleLineEmptyBlock(node.body); - write(" {"); - if (singleLine) { - write(" "); - } - else { - increaseIndent(); - writeLine(); - } - emitLeadingCommentsOfPosition(body.statements.end); - if (!singleLine) { - decreaseIndent(); - } - emitToken(15, body.statements.end); - } - function emitFunctionBodyWithStatements(node, body) { write(" {"); scopeEmitStart(node); - var outPos = writer.getTextPos(); + var initialTextPos = writer.getTextPos(); increaseIndent(); emitDetachedComments(body.statements); var startIndex = emitDirectivePrologues(body.statements, true); emitFunctionBodyPreamble(node); decreaseIndent(); - var preambleEmitted = writer.getTextPos() !== outPos; + var preambleEmitted = writer.getTextPos() !== initialTextPos; if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) { for (var i = 0, n = body.statements.length; i < n; i++) { write(" "); @@ -20365,7 +21169,7 @@ var ts; emitStart(member); emitStart(member.name); if (staticFlag) { - emitNode(node.name); + emitDeclarationName(node); } else { write("this"); @@ -20390,7 +21194,7 @@ var ts; emitLeadingComments(member); emitStart(member); emitStart(member.name); - emitNode(node.name); + emitDeclarationName(node); if (!(member.flags & 128)) { write(".prototype"); } @@ -20411,7 +21215,7 @@ var ts; emitStart(member); write("Object.defineProperty("); emitStart(member.name); - emitNode(node.name); + emitDeclarationName(node); if (!(member.flags & 128)) { write(".prototype"); } @@ -20456,7 +21260,7 @@ var ts; } function emitClassDeclaration(node) { write("var "); - emit(node.name); + emitDeclarationName(node); write(" = (function ("); var baseTypeNode = ts.getClassBaseTypeNode(node); if (baseTypeNode) { @@ -20469,7 +21273,7 @@ var ts; writeLine(); emitStart(baseTypeNode); write("__extends("); - emit(node.name); + emitDeclarationName(node); write(", _super);"); emitEnd(baseTypeNode); } @@ -20478,11 +21282,10 @@ var ts; emitMemberFunctions(node); emitMemberAssignments(node, 128); writeLine(); - function emitClassReturnStatement() { + emitToken(15, node.members.end, function () { write("return "); - emitNode(node.name); - } - emitToken(15, node.members.end, emitClassReturnStatement); + emitDeclarationName(node); + }); write(";"); decreaseIndent(); writeLine(); @@ -20495,16 +21298,16 @@ var ts; } write(");"); emitEnd(node); - if (node.flags & 1) { + if (node.flags & 1 && !(node.flags & 256)) { writeLine(); emitStart(node); emitModuleMemberName(node); write(" = "); - emit(node.name); + emitDeclarationName(node); emitEnd(node); write(";"); } - if (languageVersion < 2 && node.parent === currentSourceFile) { + if (languageVersion < 2 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } function emitConstructorOfClass() { @@ -20514,6 +21317,7 @@ var ts; tempCount = 0; tempVariables = undefined; tempParameters = undefined; + var popFrame = enterNameScope(); ts.forEach(node.members, function (member) { if (member.kind === 133 && !member.body) { emitPinnedOrTripleSlashComments(member); @@ -20525,7 +21329,7 @@ var ts; } emitStart(ctor || node); write("function "); - emit(node.name); + emitDeclarationName(node); emitSignatureParameters(ctor); write(" {"); scopeEmitStart(node, "constructor"); @@ -20573,6 +21377,7 @@ var ts; if (ctor) { emitTrailingComments(ctor); } + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; @@ -20691,7 +21496,9 @@ var ts; var saveTempVariables = tempVariables; tempCount = 0; tempVariables = undefined; + var popFrame = enterNameScope(); emit(node.body); + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; } @@ -20780,7 +21587,7 @@ var ts; emitImportDeclaration(node); return; } - if (resolver.isReferencedImportDeclaration(node) || + if (resolver.isReferencedAliasDeclaration(node) || (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { emitLeadingComments(node); emitStart(node); @@ -20876,17 +21683,29 @@ var ts; function createExternalModuleInfo(sourceFile) { externalImports = []; exportSpecifiers = {}; + exportDefault = undefined; ts.forEach(sourceFile.statements, function (node) { if (node.kind === 209 && !node.moduleSpecifier) { ts.forEach(node.exportClause.elements, function (specifier) { + if (specifier.name.text === "default") { + exportDefault = exportDefault || specifier; + } var name = (specifier.propertyName || specifier.name).text; (exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier); }); } + else if (node.kind === 208) { + exportDefault = exportDefault || node; + } + else if (node.kind === 195 || node.kind === 196) { + if (node.flags & 1 && node.flags & 256) { + exportDefault = exportDefault || node; + } + } else { var info = createExternalImportInfo(node); if (info) { - if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedImportDeclaration(node)) { + if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedAliasDeclaration(node)) { externalImports.push(info); } } @@ -20967,18 +21786,7 @@ var ts; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(true); - var exportName = resolver.getExportAssignmentName(node); - if (exportName) { - writeLine(); - var exportAssignment = getFirstExportAssignment(node); - emitStart(exportAssignment); - write("return "); - emitStart(exportAssignment.exportName); - write(exportName); - emitEnd(exportAssignment.exportName); - write(";"); - emitEnd(exportAssignment); - } + emitExportDefault(node, true); decreaseIndent(); writeLine(); write("});"); @@ -20987,17 +21795,24 @@ var ts; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(true); - var exportName = resolver.getExportAssignmentName(node); - if (exportName) { + emitExportDefault(node, false); + } + function emitExportDefault(sourceFile, emitAsReturn) { + if (exportDefault && resolver.hasExportDefaultValue(sourceFile)) { writeLine(); - var exportAssignment = getFirstExportAssignment(node); - emitStart(exportAssignment); - write("module.exports = "); - emitStart(exportAssignment.exportName); - write(exportName); - emitEnd(exportAssignment.exportName); + emitStart(exportDefault); + write(emitAsReturn ? "return " : "module.exports = "); + if (exportDefault.kind === 208) { + emit(exportDefault.expression); + } + else if (exportDefault.kind === 211) { + emit(exportDefault.propertyName); + } + else { + emitDeclarationName(exportDefault); + } write(";"); - emitEnd(exportAssignment); + emitEnd(exportDefault); } } function emitDirectivePrologues(statements, startWithNewLine) { @@ -21048,6 +21863,7 @@ var ts; else { externalImports = undefined; exportSpecifiers = undefined; + exportDefault = undefined; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(true); @@ -21367,6 +22183,7 @@ var ts; var ts; (function (ts) { ts.emitTime = 0; + ts.ioReadTime = 0; function createCompilerHost(options) { var currentDirectory; var existingDirectories = {}; @@ -21376,11 +22193,15 @@ var ts; var unsupportedFileEncodingErrorCode = -2147024809; function getSourceFile(fileName, languageVersion, onError) { try { + var start = new Date().getTime(); var text = ts.sys.readFile(fileName, options.charset); + ts.ioReadTime += new Date().getTime() - start; } catch (e) { if (onError) { - onError(e.number === unsupportedFileEncodingErrorCode ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText : e.message); + onError(e.number === unsupportedFileEncodingErrorCode + ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText + : e.message); } text = ""; } @@ -21513,8 +22334,9 @@ var ts; if (options.noEmitOnError && getPreEmitDiagnostics(this).length > 0) { return { diagnostics: [], sourceMaps: undefined, emitSkipped: true }; } + var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); var start = new Date().getTime(); - var emitResult = ts.emitFiles(getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile), getEmitHost(writeFileCallback), sourceFile); + var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile); ts.emitTime += new Date().getTime() - start; return emitResult; } @@ -21703,20 +22525,19 @@ var ts; } return; } - var firstExternalModule = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); - if (firstExternalModule && !options.module) { - var externalModuleErrorSpan = ts.getErrorSpanForNode(firstExternalModule.externalModuleIndicator); - var errorStart = ts.skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos); - var errorLength = externalModuleErrorSpan.end - errorStart; - diagnostics.add(ts.createFileDiagnostic(firstExternalModule, errorStart, errorLength, ts.Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); + if (firstExternalModuleSourceFile && !options.module) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + diagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); } if (options.outDir || options.sourceRoot || (options.mapRoot && - (!options.out || firstExternalModule !== undefined))) { + (!options.out || firstExternalModuleSourceFile !== undefined))) { var commonPathComponents; ts.forEach(files, function (sourceFile) { - if (!(sourceFile.flags & 1024) && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { + if (!(sourceFile.flags & 2048) + && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, host.getCurrentDirectory()); sourcePathComponents.pop(); if (commonPathComponents) { @@ -22383,6 +23204,27 @@ var ts; case 149: ts.forEach(node.elements, visit); break; + case 209: + if (node.exportClause) { + ts.forEach(node.exportClause.elements, visit); + } + break; + case 203: + var importClause = node.importClause; + if (importClause) { + if (importClause.name) { + childNodes.push(importClause); + } + if (importClause.namedBindings) { + if (importClause.namedBindings.kind === 205) { + childNodes.push(importClause.namedBindings); + } + else { + ts.forEach(importClause.namedBindings.elements, visit); + } + } + } + break; case 150: case 193: if (ts.isBindingPattern(node.name)) { @@ -22394,7 +23236,11 @@ var ts; case 197: case 200: case 195: + case 202: + case 207: + case 211: childNodes.push(node); + break; } } ts.forEach(nodes, visit); @@ -22507,7 +23353,7 @@ var ts; if (ts.isBindingPattern(node.name)) { break; } - if ((node.flags & 243) === 0) { + if ((node.flags & 499) === 0) { return undefined; } return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); @@ -22559,6 +23405,12 @@ var ts; } case 133: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); + case 211: + case 207: + case 202: + case 204: + case 205: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.alias); } return undefined; function createItem(node, name, scriptElementKind) { @@ -22631,10 +23483,15 @@ var ts; return undefined; } hasGlobalNode = true; - var rootName = ts.isExternalModule(node) ? "\"" + ts.escapeString(ts.getBaseFileName(ts.removeFileExtension(ts.normalizePath(node.fileName)))) + "\"" : ""; + var rootName = ts.isExternalModule(node) + ? "\"" + ts.escapeString(ts.getBaseFileName(ts.removeFileExtension(ts.normalizePath(node.fileName)))) + "\"" + : ""; return getNavigationBarItem(rootName, ts.ScriptElementKind.moduleElement, ts.ScriptElementKindModifier.none, [getNodeSpan(node)], childItems); } function createClassItem(node) { + if (!node.name) { + return undefined; + } var childItems; if (node.members) { var constructor = ts.forEach(node.members, function (member) { @@ -22670,7 +23527,9 @@ var ts; return node; } function getNodeSpan(node) { - return node.kind === 220 ? ts.createTextSpanFromBounds(node.getFullStart(), node.getEnd()) : ts.createTextSpanFromBounds(node.getStart(), node.getEnd()); + return node.kind === 220 + ? ts.createTextSpanFromBounds(node.getFullStart(), node.getEnd()) + : ts.createTextSpanFromBounds(node.getStart(), node.getEnd()); } function getTextOfNode(node) { return ts.getTextOfNodeFromSourceText(sourceFile.text, node); @@ -23124,7 +23983,9 @@ var ts; function transitionFromLowerToUpper(identifier, word, index) { var lastIsUpper = isUpperCaseLetter(identifier.charCodeAt(index - 1)); var currentIsUpper = isUpperCaseLetter(identifier.charCodeAt(index)); - var transition = word ? (currentIsUpper && !lastIsUpper) : currentIsUpper; + var transition = word + ? (currentIsUpper && !lastIsUpper) + : currentIsUpper; return transition; } })(ts || (ts = {})); @@ -23178,12 +24039,14 @@ var ts; var list = listItemInfo.list; var isTypeArgList = callExpression.typeArguments && callExpression.typeArguments.pos === list.pos; var argumentIndex = (listItemInfo.listItemIndex + 1) >> 1; + var argumentCount = getCommaBasedArgCount(list); + ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex); return { kind: isTypeArgList ? 0 : 1, invocation: callExpression, argumentsSpan: getApplicableSpanForArguments(list), argumentIndex: argumentIndex, - argumentCount: getCommaBasedArgCount(list) + argumentCount: argumentCount }; } } @@ -23214,7 +24077,9 @@ var ts; return undefined; } function getCommaBasedArgCount(argumentsList) { - return argumentsList.getChildCount() === 0 ? 0 : 1 + ts.countWhere(argumentsList.getChildren(), function (arg) { return arg.kind === 23; }); + return argumentsList.getChildCount() === 0 + ? 0 + : 1 + ts.countWhere(argumentsList.getChildren(), function (arg) { return arg.kind === 23; }); } function getArgumentIndexForTemplatePiece(spanIndex, node) { ts.Debug.assert(position >= node.getStart(), "Assumed 'position' could not occur before node."); @@ -23227,7 +24092,10 @@ var ts; return spanIndex + 1; } function getArgumentListInfoForTemplate(tagExpression, argumentIndex) { - var argumentCount = tagExpression.template.kind === 10 ? 1 : tagExpression.template.templateSpans.length + 1; + var argumentCount = tagExpression.template.kind === 10 + ? 1 + : tagExpression.template.templateSpans.length + 1; + ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex); return { kind: 2, invocation: tagExpression, @@ -23342,6 +24210,7 @@ var ts; if (selectedItemIndex < 0) { selectedItemIndex = selectBestInvalidOverloadIndex(candidates, argumentCount); } + ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex); return { items: items, applicableSpan: applicableSpan, @@ -23511,7 +24380,7 @@ var ts; for (var i = 0, len = children.length; i < len; ++i) { var child = children[i]; var shouldDiveInChildNode = (child.pos <= previousToken.pos && child.end > previousToken.end) || - (child.pos === previousToken.end); + (child.pos === previousToken.end); if (shouldDiveInChildNode && nodeHasTokens(child)) { return find(child); } @@ -23589,7 +24458,7 @@ var ts; if (node.kind === 139 || node.kind === 155) { return node.typeArguments; } - if (ts.isAnyFunction(node) || node.kind === 196 || node.kind === 197) { + if (ts.isFunctionLike(node) || node.kind === 196 || node.kind === 197) { return node.typeParameters; } return undefined; @@ -23614,7 +24483,8 @@ var ts; } ts.isPunctuation = isPunctuation; function isInsideTemplateLiteral(node, position) { - return ts.isTemplateLiteralKind(node.kind) && (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd()); + return ts.isTemplateLiteralKind(node.kind) + && (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd()); } ts.isInsideTemplateLiteral = isInsideTemplateLiteral; function compareDataObjects(dst, src) { @@ -23895,7 +24765,13 @@ var ts; token: undefined }; } - var expectedScanAction = shouldRescanGreaterThanToken(n) ? 1 : shouldRescanSlashToken(n) ? 2 : shouldRescanTemplateToken(n) ? 3 : 0; + var expectedScanAction = shouldRescanGreaterThanToken(n) + ? 1 + : shouldRescanSlashToken(n) + ? 2 + : shouldRescanTemplateToken(n) + ? 3 + : 0; if (lastTokenInfo && expectedScanAction === lastScanAction) { return fixTokenKind(lastTokenInfo, n); } @@ -24246,7 +25122,7 @@ var ts; this.SpaceAfterSubtractWhenFollowedByPredecrement = new formatting.Rule(formatting.RuleDescriptor.create1(34, 39), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.NoSpaceBeforeComma = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 23), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceAfterCertainKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([97, 93, 87, 73, 89, 96]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([105, 69]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2)); + this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([104, 69]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8)); this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(82, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionDeclContext), 8)); @@ -24254,13 +25130,13 @@ var ts; this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(89, 22), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceBetweenStatements = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([17, 74, 75, 66]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotForContext), 2)); this.SpaceAfterTryFinally = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([95, 80]), 14), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([116, 120]), 64), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); + this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([115, 119]), 64), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); this.SpaceBeforeBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.BinaryKeywordOperators), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); - this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(114, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([117, 118]), 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([68, 115, 76, 77, 78, 116, 103, 84, 104, 117, 107, 109, 120, 110]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([78, 103])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(113, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([116, 117]), 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([68, 114, 76, 77, 78, 115, 102, 84, 103, 116, 106, 108, 119, 109]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([78, 102])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(8, 14), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2)); this.SpaceAfterArrow = new formatting.Rule(formatting.RuleDescriptor.create3(32, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.NoSpaceAfterEllipsis = new formatting.Rule(formatting.RuleDescriptor.create1(21, 64), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); @@ -24272,52 +25148,52 @@ var ts; this.NoSpaceAfterCloseAngularBracket = new formatting.Rule(formatting.RuleDescriptor.create3(25, formatting.Shared.TokenRange.FromTokens([16, 18, 25, 23])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsTypeArgumentOrParameterContext), 8)); this.NoSpaceBetweenEmptyInterfaceBraceBrackets = new formatting.Rule(formatting.RuleDescriptor.create1(14, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsObjectTypeContext), 8)); this.HighPriorityCommonRules = - [ - this.IgnoreBeforeComment, this.IgnoreAfterLineComment, - this.NoSpaceBeforeColon, this.SpaceAfterColon, this.NoSpaceBeforeQuestionMark, this.SpaceAfterQuestionMarkInConditionalOperator, - this.NoSpaceAfterQuestionMark, - this.NoSpaceBeforeDot, this.NoSpaceAfterDot, - this.NoSpaceAfterUnaryPrefixOperator, - this.NoSpaceAfterUnaryPreincrementOperator, this.NoSpaceAfterUnaryPredecrementOperator, - this.NoSpaceBeforeUnaryPostincrementOperator, this.NoSpaceBeforeUnaryPostdecrementOperator, - this.SpaceAfterPostincrementWhenFollowedByAdd, - this.SpaceAfterAddWhenFollowedByUnaryPlus, this.SpaceAfterAddWhenFollowedByPreincrement, - this.SpaceAfterPostdecrementWhenFollowedBySubtract, - this.SpaceAfterSubtractWhenFollowedByUnaryMinus, this.SpaceAfterSubtractWhenFollowedByPredecrement, - this.NoSpaceAfterCloseBrace, - this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext, - this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets, - this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember, - this.NoSpaceBetweenReturnAndSemicolon, - this.SpaceAfterCertainKeywords, - this.SpaceAfterLetConstInVariableDeclaration, - this.NoSpaceBeforeOpenParenInFuncCall, - this.SpaceBeforeBinaryKeywordOperator, this.SpaceAfterBinaryKeywordOperator, - this.SpaceAfterVoidOperator, - this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, - this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, - this.SpaceAfterModuleName, - this.SpaceAfterArrow, - this.NoSpaceAfterEllipsis, - this.NoSpaceAfterOptionalParameters, - this.NoSpaceBetweenEmptyInterfaceBraceBrackets, - this.NoSpaceBeforeOpenAngularBracket, - this.NoSpaceBetweenCloseParenAndAngularBracket, - this.NoSpaceAfterOpenAngularBracket, - this.NoSpaceBeforeCloseAngularBracket, - this.NoSpaceAfterCloseAngularBracket - ]; + [ + this.IgnoreBeforeComment, this.IgnoreAfterLineComment, + this.NoSpaceBeforeColon, this.SpaceAfterColon, this.NoSpaceBeforeQuestionMark, this.SpaceAfterQuestionMarkInConditionalOperator, + this.NoSpaceAfterQuestionMark, + this.NoSpaceBeforeDot, this.NoSpaceAfterDot, + this.NoSpaceAfterUnaryPrefixOperator, + this.NoSpaceAfterUnaryPreincrementOperator, this.NoSpaceAfterUnaryPredecrementOperator, + this.NoSpaceBeforeUnaryPostincrementOperator, this.NoSpaceBeforeUnaryPostdecrementOperator, + this.SpaceAfterPostincrementWhenFollowedByAdd, + this.SpaceAfterAddWhenFollowedByUnaryPlus, this.SpaceAfterAddWhenFollowedByPreincrement, + this.SpaceAfterPostdecrementWhenFollowedBySubtract, + this.SpaceAfterSubtractWhenFollowedByUnaryMinus, this.SpaceAfterSubtractWhenFollowedByPredecrement, + this.NoSpaceAfterCloseBrace, + this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext, + this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets, + this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember, + this.NoSpaceBetweenReturnAndSemicolon, + this.SpaceAfterCertainKeywords, + this.SpaceAfterLetConstInVariableDeclaration, + this.NoSpaceBeforeOpenParenInFuncCall, + this.SpaceBeforeBinaryKeywordOperator, this.SpaceAfterBinaryKeywordOperator, + this.SpaceAfterVoidOperator, + this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, + this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, + this.SpaceAfterModuleName, + this.SpaceAfterArrow, + this.NoSpaceAfterEllipsis, + this.NoSpaceAfterOptionalParameters, + this.NoSpaceBetweenEmptyInterfaceBraceBrackets, + this.NoSpaceBeforeOpenAngularBracket, + this.NoSpaceBetweenCloseParenAndAngularBracket, + this.NoSpaceAfterOpenAngularBracket, + this.NoSpaceBeforeCloseAngularBracket, + this.NoSpaceAfterCloseAngularBracket + ]; this.LowPriorityCommonRules = - [ - this.NoSpaceBeforeSemicolon, - this.SpaceBeforeOpenBraceInControl, this.SpaceBeforeOpenBraceInFunction, this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock, - this.NoSpaceBeforeComma, - this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterOpenBracket, - this.NoSpaceBeforeCloseBracket, this.NoSpaceAfterCloseBracket, - this.SpaceAfterSemicolon, - this.NoSpaceBeforeOpenParenInFuncDecl, - this.SpaceBetweenStatements, this.SpaceAfterTryFinally - ]; + [ + this.NoSpaceBeforeSemicolon, + this.SpaceBeforeOpenBraceInControl, this.SpaceBeforeOpenBraceInFunction, this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock, + this.NoSpaceBeforeComma, + this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterOpenBracket, + this.NoSpaceBeforeCloseBracket, this.NoSpaceAfterCloseBracket, + this.SpaceAfterSemicolon, + this.NoSpaceBeforeOpenParenInFuncDecl, + this.SpaceBetweenStatements, this.SpaceAfterTryFinally + ]; this.SpaceAfterComma = new formatting.Rule(formatting.RuleDescriptor.create3(23, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.NoSpaceAfterComma = new formatting.Rule(formatting.RuleDescriptor.create3(23, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceBeforeBinaryOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.BinaryOperators), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); @@ -24645,13 +25521,19 @@ var ts; RulesBucket.prototype.AddRule = function (rule, specificTokens, constructionState, rulesBucketIndex) { var position; if (rule.Operation.Action == 1) { - position = specificTokens ? 0 : RulesPosition.IgnoreRulesAny; + position = specificTokens ? + 0 : + RulesPosition.IgnoreRulesAny; } else if (!rule.Operation.Context.IsAny()) { - position = specificTokens ? RulesPosition.ContextRulesSpecific : RulesPosition.ContextRulesAny; + position = specificTokens ? + RulesPosition.ContextRulesSpecific : + RulesPosition.ContextRulesAny; } else { - position = specificTokens ? RulesPosition.NoContextRulesSpecific : RulesPosition.NoContextRulesAny; + position = specificTokens ? + RulesPosition.NoContextRulesSpecific : + RulesPosition.NoContextRulesAny; } var state = constructionState[rulesBucketIndex]; if (state === undefined) { @@ -24773,7 +25655,7 @@ var ts; TokenRange.UnaryPredecrementExpressions = TokenRange.FromTokens([64, 16, 92, 87]); TokenRange.UnaryPostdecrementExpressions = TokenRange.FromTokens([64, 17, 19, 87]); TokenRange.Comments = TokenRange.FromTokens([2, 3]); - TokenRange.TypeNames = TokenRange.FromTokens([64, 119, 121, 113, 122, 98, 112]); + TokenRange.TypeNames = TokenRange.FromTokens([64, 118, 120, 112, 121, 98, 111]); return TokenRange; })(); Shared.TokenRange = TokenRange; @@ -24970,7 +25852,9 @@ var ts; if (!errors.length) { return rangeHasNoErrors; } - var sorted = errors.filter(function (d) { return ts.rangeOverlapsWithStartEnd(originalRange, d.start, d.start + d.length); }).sort(function (e1, e2) { return e1.start - e2.start; }); + var sorted = errors + .filter(function (d) { return ts.rangeOverlapsWithStartEnd(originalRange, d.start, d.start + d.length); }) + .sort(function (e1, e2) { return e1.start - e2.start; }); if (!sorted.length) { return rangeHasNoErrors; } @@ -25340,8 +26224,8 @@ var ts; } } trimTrailingWhitespaces = - (rule.Operation.Action & (4 | 2)) && - rule.Flag !== 1; + (rule.Operation.Action & (4 | 2)) && + rule.Flag !== 1; } else { trimTrailingWhitespaces = true; @@ -25396,7 +26280,9 @@ var ts; var delta = indentation - nonWhitespaceColumnInFirstPart.column; for (var i = startIndex, len = parts.length; i < len; ++i, ++startLine) { var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile); - var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart : formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options); + var nonWhitespaceCharacterAndColumn = i === 0 + ? nonWhitespaceColumnInFirstPart + : formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options); var newIndentation = nonWhitespaceCharacterAndColumn.column + delta; if (newIndentation > 0) { var indentationString = getIndentationString(newIndentation, options); @@ -25567,6 +26453,10 @@ var ts; (function (formatting) { var SmartIndenter; (function (SmartIndenter) { + var Value; + (function (Value) { + Value[Value["Unknown"] = -1] = "Unknown"; + })(Value || (Value = {})); function getIndentation(position, sourceFile, options) { if (position > sourceFile.text.length) { return 0; @@ -25576,11 +26466,11 @@ var ts; return 0; } var precedingTokenIsLiteral = precedingToken.kind === 8 || - precedingToken.kind === 9 || - precedingToken.kind === 10 || - precedingToken.kind === 11 || - precedingToken.kind === 12 || - precedingToken.kind === 13; + precedingToken.kind === 9 || + precedingToken.kind === 10 || + precedingToken.kind === 11 || + precedingToken.kind === 12 || + precedingToken.kind === 13; if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { return 0; } @@ -25641,7 +26531,7 @@ var ts; } parentStart = getParentStart(parent, current, sourceFile); var parentAndChildShareLine = parentStart.line === currentStart.line || - childStartsOnTheSameLineWithElseInIfStatement(parent, current, currentStart.line, sourceFile); + childStartsOnTheSameLineWithElseInIfStatement(parent, current, currentStart.line, sourceFile); if (useActualIndentation) { var actualIndentation = getActualIndentationForNode(current, parent, currentStart, parentAndChildShareLine, sourceFile, options); if (actualIndentation !== -1) { @@ -25666,12 +26556,16 @@ var ts; } function getActualIndentationForListItemBeforeComma(commaToken, sourceFile, options) { var commaItemInfo = ts.findListItemInfo(commaToken); - ts.Debug.assert(commaItemInfo && commaItemInfo.listItemIndex > 0); - return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options); + if (commaItemInfo && commaItemInfo.listItemIndex > 0) { + return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options); + } + else { + return -1; + } } function getActualIndentationForNode(current, parent, currentLineAndChar, parentAndChildShareLine, sourceFile, options) { var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && - (parent.kind === 220 || !parentAndChildShareLine); + (parent.kind === 220 || !parentAndChildShareLine); if (!useActualIndentation) { return -1; } @@ -25998,13 +26892,13 @@ var ts; while (pos < end) { var token = scanner.scan(); var textPos = scanner.getTextPos(); - nodes.push(createNode(token, pos, textPos, 512, this)); + nodes.push(createNode(token, pos, textPos, 1024, this)); pos = textPos; } return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(221, nodes.pos, nodes.end, 512, this); + var list = createNode(221, nodes.pos, nodes.end, 1024, this); list._children = []; var pos = nodes.pos; for (var i = 0, len = nodes.length; i < len; i++) { @@ -26426,7 +27320,9 @@ var ts; case 131: var functionDeclaration = node; if (functionDeclaration.name && functionDeclaration.name.getFullWidth() > 0) { - var lastDeclaration = namedDeclarations.length > 0 ? namedDeclarations[namedDeclarations.length - 1] : undefined; + var lastDeclaration = namedDeclarations.length > 0 ? + namedDeclarations[namedDeclarations.length - 1] : + undefined; if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) { if (functionDeclaration.body && !lastDeclaration.body) { namedDeclarations[namedDeclarations.length - 1] = functionDeclaration; @@ -26444,6 +27340,11 @@ var ts; case 199: case 200: case 202: + case 211: + case 207: + case 202: + case 204: + case 205: case 134: case 135: case 143: @@ -26478,6 +27379,27 @@ var ts; case 129: namedDeclarations.push(node); break; + case 209: + if (node.exportClause) { + ts.forEach(node.exportClause.elements, visit); + } + break; + case 203: + var importClause = node.importClause; + if (importClause) { + if (importClause.name) { + namedDeclarations.push(importClause); + } + if (importClause.namedBindings) { + if (importClause.namedBindings.kind === 205) { + namedDeclarations.push(importClause.namedBindings); + } + else { + ts.forEach(importClause.namedBindings.elements, visit); + } + } + } + break; } }); this.namedDeclarations = namedDeclarations; @@ -26798,7 +27720,7 @@ var ts; var entry = entries[i]; sourceFiles.push({ name: i, - refCount: entry.refCount, + refCount: entry.languageServiceRefCount, references: entry.owners.slice(0) }); } @@ -26811,34 +27733,40 @@ var ts; return JSON.stringify(bucketInfoArray, null, 2); } function acquireDocument(fileName, compilationSettings, scriptSnapshot, version) { + return acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, true); + } + function updateDocument(fileName, compilationSettings, scriptSnapshot, version) { + return acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, false); + } + function acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, acquiring) { var bucket = getBucketForCompilationSettings(compilationSettings, true); var entry = ts.lookUp(bucket, fileName); if (!entry) { + ts.Debug.assert(acquiring, "How could we be trying to update a document that the registry doesn't have?"); var sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, compilationSettings.target, version, false); bucket[fileName] = entry = { sourceFile: sourceFile, - refCount: 0, + languageServiceRefCount: 0, owners: [] }; } - entry.refCount++; - return entry.sourceFile; - } - function updateDocument(sourceFile, fileName, compilationSettings, scriptSnapshot, version, textChangeRange) { - var bucket = getBucketForCompilationSettings(compilationSettings, false); - ts.Debug.assert(bucket !== undefined); - var entry = ts.lookUp(bucket, fileName); - ts.Debug.assert(entry !== undefined); - entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, textChangeRange); + else { + if (entry.sourceFile.version !== version) { + entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot)); + } + } + if (acquiring) { + entry.languageServiceRefCount++; + } return entry.sourceFile; } function releaseDocument(fileName, compilationSettings) { var bucket = getBucketForCompilationSettings(compilationSettings, false); ts.Debug.assert(bucket !== undefined); var entry = ts.lookUp(bucket, fileName); - entry.refCount--; - ts.Debug.assert(entry.refCount >= 0); - if (entry.refCount === 0) { + entry.languageServiceRefCount--; + ts.Debug.assert(entry.languageServiceRefCount >= 0); + if (entry.languageServiceRefCount === 0) { delete bucket[fileName]; } } @@ -26869,31 +27797,111 @@ var ts; } }); } + function recordModuleName() { + var importPath = scanner.getTokenValue(); + var pos = scanner.getTokenPos(); + importedFiles.push({ + fileName: importPath, + pos: pos, + end: pos + importPath.length + }); + } function processImport() { scanner.setText(sourceText); var token = scanner.scan(); while (token !== 1) { if (token === 84) { token = scanner.scan(); - if (token === 64) { - token = scanner.scan(); - if (token === 52) { + if (token === 8) { + recordModuleName(); + continue; + } + else { + if (token === 64) { token = scanner.scan(); - if (token === 118) { + if (token === 123) { token = scanner.scan(); - if (token === 16) { + if (token === 8) { + recordModuleName(); + continue; + } + } + else if (token === 52) { + token = scanner.scan(); + if (token === 117) { token = scanner.scan(); - if (token === 8) { - var importPath = scanner.getTokenValue(); - var pos = scanner.getTokenPos(); - importedFiles.push({ - fileName: importPath, - pos: pos, - end: pos + importPath.length - }); + if (token === 16) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + continue; + } } } } + else if (token === 23) { + token = scanner.scan(); + } + else { + continue; + } + } + if (token === 14) { + token = scanner.scan(); + while (token !== 15) { + token = scanner.scan(); + } + if (token === 15) { + token = scanner.scan(); + if (token === 123) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + } + } + } + } + else if (token === 35) { + token = scanner.scan(); + if (token === 101) { + token = scanner.scan(); + if (token === 64) { + token = scanner.scan(); + if (token === 123) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + } + } + } + } + } + } + } + else if (token === 77) { + token = scanner.scan(); + if (token === 14) { + token = scanner.scan(); + while (token !== 15) { + token = scanner.scan(); + } + if (token === 15) { + token = scanner.scan(); + if (token === 123) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + } + } + } + } + else if (token === 35) { + token = scanner.scan(); + if (token === 123) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + } } } } @@ -26961,7 +27969,7 @@ var ts; } function isNameOfFunctionDeclaration(node) { return node.kind === 64 && - ts.isAnyFunction(node.parent) && node.parent.name === node; + ts.isFunctionLike(node.parent) && node.parent.name === node; } function isNameOfPropertyAssignment(node) { return (node.kind === 64 || node.kind === 8 || node.kind === 7) && @@ -27071,7 +28079,11 @@ var ts; case 198: return ScriptElementKind.typeElement; case 199: return ScriptElementKind.enumElement; case 193: - return ts.isConst(node) ? ScriptElementKind.constElement : ts.isLet(node) ? ScriptElementKind.letElement : ScriptElementKind.variableElement; + return ts.isConst(node) + ? ScriptElementKind.constElement + : ts.isLet(node) + ? ScriptElementKind.letElement + : ScriptElementKind.variableElement; case 195: return ScriptElementKind.functionElement; case 134: return ScriptElementKind.memberGetAccessorElement; case 135: return ScriptElementKind.memberSetAccessorElement; @@ -27088,6 +28100,12 @@ var ts; case 127: return ScriptElementKind.typeParameterElement; case 219: return ScriptElementKind.variableElement; case 128: return (node.flags & 112) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; + case 202: + case 207: + case 204: + case 211: + case 205: + return ScriptElementKind.alias; } return ScriptElementKind.unknown; } @@ -27165,11 +28183,7 @@ var ts; if (!changesInCompilationSettingsAffectSyntax) { var oldSourceFile = program && program.getSourceFile(fileName); if (oldSourceFile) { - if (sourceFileUpToDate(oldSourceFile)) { - return oldSourceFile; - } - var textChangeRange = hostFileInformation.scriptSnapshot.getChangeRange(oldSourceFile.scriptSnapshot); - return documentRegistry.updateDocument(oldSourceFile, fileName, newSettings, hostFileInformation.scriptSnapshot, hostFileInformation.version, textChangeRange); + return documentRegistry.updateDocument(fileName, newSettings, hostFileInformation.scriptSnapshot, hostFileInformation.version); } } return documentRegistry.acquireDocument(fileName, newSettings, hostFileInformation.scriptSnapshot, hostFileInformation.version); @@ -27204,7 +28218,9 @@ var ts; } function dispose() { if (program) { - ts.forEach(program.getSourceFiles(), function (f) { documentRegistry.releaseDocument(f.fileName, program.getCompilerOptions()); }); + ts.forEach(program.getSourceFiles(), function (f) { + return documentRegistry.releaseDocument(f.fileName, program.getCompilerOptions()); + }); } } function getSyntacticDiagnostics(fileName) { @@ -27349,6 +28365,17 @@ var ts; getCompletionEntriesFromSymbols(filteredMembers, activeCompletionSession); } } + else if (ts.getAncestor(previousToken, 204)) { + isMemberCompletion = true; + isNewIdentifierLocation = true; + if (showCompletionsInImportsClause(previousToken)) { + var importDeclaration = ts.getAncestor(previousToken, 203); + ts.Debug.assert(importDeclaration !== undefined); + var exports = typeInfoResolver.getExportsOfExternalModule(importDeclaration); + var filteredExports = filterModuleExports(exports, importDeclaration); + getCompletionEntriesFromSymbols(filteredExports, activeCompletionSession); + } + } else { isMemberCompletion = false; isNewIdentifierLocation = isNewIdentifierDefinitionLocation(previousToken); @@ -27389,31 +28416,47 @@ var ts; log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; } + function showCompletionsInImportsClause(node) { + if (node) { + if (node.kind === 14 || node.kind === 23) { + return node.parent.kind === 206; + } + } + return false; + } function isNewIdentifierDefinitionLocation(previousToken) { if (previousToken) { var containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { case 23: - return containingNodeKind === 155 || containingNodeKind === 133 || containingNodeKind === 156 || containingNodeKind === 151 || containingNodeKind === 167; + return containingNodeKind === 155 + || containingNodeKind === 133 + || containingNodeKind === 156 + || containingNodeKind === 151 + || containingNodeKind === 167; case 16: - return containingNodeKind === 155 || containingNodeKind === 133 || containingNodeKind === 156 || containingNodeKind === 159; + return containingNodeKind === 155 + || containingNodeKind === 133 + || containingNodeKind === 156 + || containingNodeKind === 159; case 18: return containingNodeKind === 151; - case 117: + case 116: return true; case 20: return containingNodeKind === 200; case 14: return containingNodeKind === 196; case 52: - return containingNodeKind === 193 || containingNodeKind === 167; + return containingNodeKind === 193 + || containingNodeKind === 167; case 11: return containingNodeKind === 169; case 12: return containingNodeKind === 173; - case 109: - case 107: case 108: + case 106: + case 107: return containingNodeKind === 130; } switch (previousToken.getText()) { @@ -27426,7 +28469,9 @@ var ts; return false; } function isInStringOrRegularExpressionOrTemplateLiteral(previousToken) { - if (previousToken.kind === 8 || previousToken.kind === 9 || ts.isTemplateLiteralKind(previousToken.kind)) { + if (previousToken.kind === 8 + || previousToken.kind === 9 + || ts.isTemplateLiteralKind(previousToken.kind)) { var start = previousToken.getStart(); var end = previousToken.getEnd(); if (start < position && position < end) { @@ -27504,27 +28549,27 @@ var ts; containingNodeKind === 195 || containingNodeKind === 197 || isFunction(containingNodeKind); - case 110: + case 109: return containingNodeKind === 130; case 21: return containingNodeKind === 128 || containingNodeKind === 133 || (previousToken.parent.parent.kind === 149); - case 109: - case 107: case 108: + case 106: + case 107: return containingNodeKind === 128; case 68: case 76: - case 104: + case 103: case 82: case 97: - case 116: - case 120: + case 115: + case 119: case 84: - case 105: + case 104: case 69: - case 111: + case 110: return true; } switch (previousToken.getText()) { @@ -27549,6 +28594,23 @@ var ts; } return false; } + function filterModuleExports(exports, importDeclaration) { + var exisingImports = {}; + if (!importDeclaration.importClause) { + return exports; + } + if (importDeclaration.importClause.namedBindings && + importDeclaration.importClause.namedBindings.kind === 206) { + ts.forEach(importDeclaration.importClause.namedBindings.elements, function (el) { + var name = el.propertyName || el.name; + exisingImports[name.text] = true; + }); + } + if (ts.isEmpty(exisingImports)) { + return exports; + } + return ts.filter(exports, function (e) { return !ts.lookUp(exisingImports, e.name); }); + } function filterContextualMembersList(contextualMemberSymbols, existingMembers) { if (!existingMembers || existingMembers.length === 0) { return contextualMemberSymbols; @@ -27695,7 +28757,9 @@ var ts; return ScriptElementKind.unknown; } function getSymbolModifiers(symbol) { - return symbol && symbol.declarations && symbol.declarations.length > 0 ? ts.getNodeModifiers(symbol.declarations[0]) : ScriptElementKindModifier.none; + return symbol && symbol.declarations && symbol.declarations.length > 0 + ? ts.getNodeModifiers(symbol.declarations[0]) + : ScriptElementKindModifier.none; } function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, enclosingDeclaration, typeResolver, location, semanticMeaning) { if (semanticMeaning === void 0) { semanticMeaning = getMeaningFromLocation(location); } @@ -27779,7 +28843,7 @@ var ts; } } else if ((isNameOfFunctionDeclaration(location) && !(symbol.flags & 98304)) || - (location.kind === 114 && location.parent.kind === 133)) { + (location.kind === 113 && location.parent.kind === 133)) { var signature; var functionDeclaration = location.parent; var allSignatures = functionDeclaration.kind === 133 ? type.getConstructSignatures() : type.getCallSignatures(); @@ -27810,14 +28874,14 @@ var ts; } if ((symbolFlags & 64) && (semanticMeaning & 2)) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(104)); + displayParts.push(ts.keywordPart(103)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); } if (symbolFlags & 524288) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(123)); + displayParts.push(ts.keywordPart(122)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); displayParts.push(ts.spacePart()); @@ -27837,7 +28901,7 @@ var ts; } if (symbolFlags & 1536) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(117)); + displayParts.push(ts.keywordPart(116)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); } @@ -27893,7 +28957,7 @@ var ts; displayParts.push(ts.spacePart()); displayParts.push(ts.operatorPart(52)); displayParts.push(ts.spacePart()); - displayParts.push(ts.keywordPart(118)); + displayParts.push(ts.keywordPart(117)); displayParts.push(ts.punctuationPart(16)); displayParts.push(ts.displayPart(ts.getTextOfNode(ts.getExternalModuleImportEqualsDeclarationExpression(importEqualsDeclaration)), 8)); displayParts.push(ts.punctuationPart(17)); @@ -28056,6 +29120,12 @@ var ts; if (!symbol) { return undefined; } + if (symbol.flags & 8388608) { + var declaration = symbol.declarations[0]; + if (node.kind === 64 && node.parent === declaration) { + symbol = typeInfoResolver.getAliasedSymbol(symbol); + } + } var result = []; if (node.parent.kind === 218) { var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); @@ -28112,7 +29182,7 @@ var ts; return false; } function tryAddConstructSignature(symbol, location, symbolKind, symbolName, containerName, result) { - if (isNewExpressionTarget(location) || location.kind === 114) { + if (isNewExpressionTarget(location) || location.kind === 113) { if (symbol.flags & 32) { var classDeclaration = symbol.getDeclarations()[0]; ts.Debug.assert(classDeclaration && classDeclaration.kind === 196); @@ -28197,13 +29267,13 @@ var ts; return getLoopBreakContinueOccurrences(node.parent); } break; - case 114: + case 113: if (hasKind(node.parent, 133)) { return getConstructorOccurrences(node.parent); } break; - case 116: - case 120: + case 115: + case 119: if (hasKind(node.parent, 134) || hasKind(node.parent, 135)) { return getGetAndSetOccurrences(node.parent); } @@ -28308,7 +29378,7 @@ var ts; aggregate(tryStatement.finallyBlock); } } - else if (!ts.isAnyFunction(node)) { + else if (!ts.isFunctionLike(node)) { ts.forEachChild(node, aggregate); } } @@ -28401,7 +29471,7 @@ var ts; if (node.kind === 185 || node.kind === 184) { statementAccumulator.push(node); } - else if (!ts.isAnyFunction(node)) { + else if (!ts.isFunctionLike(node)) { ts.forEachChild(node, aggregate); } } @@ -28428,7 +29498,7 @@ var ts; } break; default: - if (ts.isAnyFunction(node)) { + if (ts.isFunctionLike(node)) { return undefined; } break; @@ -28441,7 +29511,7 @@ var ts; var keywords = []; ts.forEach(declarations, function (declaration) { ts.forEach(declaration.getChildren(), function (token) { - return pushKeywordIf(keywords, token, 114); + return pushKeywordIf(keywords, token, 113); }); }); return ts.map(keywords, getReferenceEntryFromNode); @@ -28454,7 +29524,7 @@ var ts; function tryPushAccessorKeyword(accessorSymbol, accessorKind) { var accessor = ts.getDeclarationOfKind(accessorSymbol, accessorKind); if (accessor) { - ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 116, 120); }); + ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 115, 119); }); } } } @@ -28512,17 +29582,17 @@ var ts; return ts.map(keywords, getReferenceEntryFromNode); function getFlagFromModifier(modifier) { switch (modifier) { - case 109: - return 16; - case 107: - return 32; case 108: + return 16; + case 106: + return 32; + case 107: return 64; - case 110: + case 109: return 128; case 77: return 1; - case 115: + case 114: return 2; default: ts.Debug.fail(); @@ -28568,24 +29638,6 @@ var ts; ts.Debug.assert(node.kind === 64 || node.kind === 7 || node.kind === 8); return getReferencesForNode(node, program.getSourceFiles(), false, findInStrings, findInComments); } - function initializeNameTable(sourceFile) { - var nameTable = {}; - walk(sourceFile); - sourceFile.nameTable = nameTable; - function walk(node) { - switch (node.kind) { - case 64: - nameTable[node.text] = node.text; - break; - case 8: - case 7: - nameTable[node.text] = node.text; - break; - default: - ts.forEachChild(node, walk); - } - } - } function getReferencesForNode(node, sourceFiles, searchOnlyInCurrentFile, findInStrings, findInComments) { if (isLabelName(node)) { if (isJumpStatementTarget(node)) { @@ -28612,7 +29664,7 @@ var ts; } var result; var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); - var declaredName = getDeclaredName(symbol); + var declaredName = getDeclaredName(symbol, node); var scope = getSymbolScope(symbol); if (scope) { result = []; @@ -28625,14 +29677,11 @@ var ts; getReferencesInNode(sourceFiles[0], symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); } else { - var internedName = getInternedName(symbol, declarations); + var internedName = getInternedName(symbol, node, declarations); ts.forEach(sourceFiles, function (sourceFile) { cancellationToken.throwIfCancellationRequested(); - if (!sourceFile.nameTable) { - initializeNameTable(sourceFile); - } - ts.Debug.assert(sourceFile.nameTable !== undefined); - if (ts.lookUp(sourceFile.nameTable, internedName)) { + var nameTable = getNameTable(sourceFile); + if (ts.lookUp(nameTable, internedName)) { result = result || []; getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); } @@ -28640,11 +29689,31 @@ var ts; } } return result; - function getDeclaredName(symbol) { + function isImportOrExportSpecifierName(location) { + return location.parent && + (location.parent.kind === 207 || location.parent.kind === 211) && + location.parent.propertyName === location; + } + function isImportOrExportSpecifierImportSymbol(symbol) { + return (symbol.flags & 8388608) && ts.forEach(symbol.declarations, function (declaration) { + return declaration.kind === 207 || declaration.kind === 211; + }); + } + function getDeclaredName(symbol, location) { + var functionExpression = ts.forEach(symbol.declarations, function (d) { return d.kind === 160 ? d : undefined; }); + if (functionExpression && functionExpression.name) { + var name = functionExpression.name.text; + } + if (isImportOrExportSpecifierName(location)) { + return location.getText(); + } var name = typeInfoResolver.symbolToString(symbol); return stripQuotes(name); } - function getInternedName(symbol, declarations) { + function getInternedName(symbol, location, declarations) { + if (isImportOrExportSpecifierName(location)) { + return location.getText(); + } var functionExpression = ts.forEach(declarations, function (d) { return d.kind === 160 ? d : undefined; }); if (functionExpression && functionExpression.name) { var name = functionExpression.name.text; @@ -28663,13 +29732,16 @@ var ts; return name; } function getSymbolScope(symbol) { - if (symbol.getFlags() && (4 | 8192)) { + if (symbol.flags & (4 | 8192)) { var privateDeclaration = ts.forEach(symbol.getDeclarations(), function (d) { return (d.flags & 32) ? d : undefined; }); if (privateDeclaration) { return ts.getAncestor(privateDeclaration, 196); } } - if (symbol.parent || (symbol.getFlags() & 268435456)) { + if (symbol.flags & 8388608) { + return undefined; + } + if (symbol.parent || (symbol.flags & 268435456)) { return undefined; } var scope = undefined; @@ -28920,6 +29992,9 @@ var ts; } function populateSearchSymbolSet(symbol, location) { var result = [symbol]; + if (isImportOrExportSpecifierImportSymbol(symbol)) { + result.push(typeInfoResolver.getAliasedSymbol(symbol)); + } if (isNameOfPropertyAssignment(location)) { ts.forEach(getPropertySymbolsFromContextualType(location), function (contextualSymbol) { result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol)); @@ -28969,6 +30044,10 @@ var ts; if (searchSymbols.indexOf(referenceSymbol) >= 0) { return true; } + if (isImportOrExportSpecifierImportSymbol(referenceSymbol) && + searchSymbols.indexOf(typeInfoResolver.getAliasedSymbol(referenceSymbol)) >= 0) { + return true; + } if (isNameOfPropertyAssignment(referenceLocation)) { return ts.forEach(getPropertySymbolsFromContextualType(referenceLocation), function (contextualSymbol) { return ts.forEach(typeInfoResolver.getRootSymbols(contextualSymbol), function (s) { return searchSymbols.indexOf(s) >= 0; }); @@ -29047,7 +30126,7 @@ var ts; }; } function isWriteAccess(node) { - if (node.kind === 64 && ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (node.kind === 64 && ts.isDeclarationName(node)) { return true; } var parent = node.parent; @@ -29124,11 +30203,17 @@ var ts; else { return 4; } + case 206: + case 207: case 202: + case 203: + case 208: + case 209: return 1 | 2 | 4; case 220: return 4 | 1; } + return 1 | 2 | 4; ts.Debug.fail("Unknown declaration type"); } function isTypeReference(node) { @@ -29169,7 +30254,7 @@ var ts; else if (isInRightSideOfImport(node)) { return getMeaningFromRightHandSideOfImportEquals(node); } - else if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + else if (ts.isDeclarationName(node)) { return getMeaningFromDeclaration(node.parent); } else if (isTypeReference(node)) { @@ -29678,6 +30763,41 @@ var ts; }; } ts.createLanguageService = createLanguageService; + function getNameTable(sourceFile) { + if (!sourceFile.nameTable) { + initializeNameTable(sourceFile); + } + return sourceFile.nameTable; + } + ts.getNameTable = getNameTable; + function initializeNameTable(sourceFile) { + var nameTable = {}; + walk(sourceFile); + sourceFile.nameTable = nameTable; + function walk(node) { + switch (node.kind) { + case 64: + nameTable[node.text] = node.text; + break; + case 8: + case 7: + if (ts.isDeclarationName(node) || + node.parent.kind === 212 || + isArgumentOfElementAccessExpression(node)) { + nameTable[node.text] = node.text; + } + break; + default: + ts.forEachChild(node, walk); + } + } + } + function isArgumentOfElementAccessExpression(node) { + return node && + node.parent && + node.parent.kind === 154 && + node.parent.argumentExpression === node; + } function createClassifier() { var scanner = ts.createScanner(2, false); var noRegexTable = []; @@ -29696,19 +30816,19 @@ var ts; var templateStack = []; function isAccessibilityModifier(kind) { switch (kind) { - case 109: - case 107: case 108: + case 106: + case 107: return true; } return false; } function canFollow(keyword1, keyword2) { if (isAccessibilityModifier(keyword1)) { - if (keyword2 === 116 || - keyword2 === 120 || - keyword2 === 114 || - keyword2 === 110) { + if (keyword2 === 115 || + keyword2 === 119 || + keyword2 === 113 || + keyword2 === 109) { return true; } return false; @@ -29773,11 +30893,11 @@ var ts; else if (token === 25 && angleBracketStack > 0) { angleBracketStack--; } - else if (token === 112 || - token === 121 || - token === 119 || - token === 113 || - token === 122) { + else if (token === 111 || + token === 120 || + token === 118 || + token === 112 || + token === 121) { if (angleBracketStack > 0 && !syntacticClassifierAbsent) { token = 64; } @@ -29828,7 +30948,9 @@ var ts; } if (numBackslashes & 1) { var quoteChar = tokenText.charCodeAt(0); - result.finalLexState = quoteChar === 34 ? 3 : 2; + result.finalLexState = quoteChar === 34 + ? 3 + : 2; } } } @@ -29991,7 +31113,7 @@ var ts; var BreakpointResolver; (function (BreakpointResolver) { function spanInSourceFileAtLocation(sourceFile, position) { - if (sourceFile.flags & 1024) { + if (sourceFile.flags & 2048) { return undefined; } var tokenAtLocation = ts.getTokenAtPosition(sourceFile, position); @@ -30095,9 +31217,13 @@ var ts; case 190: return textSpan(node, node.expression); case 208: - return textSpan(node, node.exportName); + return textSpan(node, node.expression); case 202: return textSpan(node, node.moduleReference); + case 203: + return textSpan(node, node.moduleSpecifier); + case 209: + return textSpan(node, node.moduleSpecifier); case 200: if (ts.getModuleInstanceState(node) !== 1) { return undefined; @@ -30144,7 +31270,7 @@ var ts; if (node.parent.kind === 158 && node.parent.type === node) { return spanInNode(node.parent.expression); } - if (ts.isAnyFunction(node.parent) && node.parent.type === node) { + if (ts.isFunctionLike(node.parent) && node.parent.type === node) { return spanInPreviousNode(node); } return spanInNode(node.parent); @@ -30157,7 +31283,11 @@ var ts; } 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; + 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) { if (isParentVariableStatement) { @@ -30317,7 +31447,7 @@ var ts; return spanInNode(node.parent); } function spanInColonToken(node) { - if (ts.isAnyFunction(node.parent) || node.parent.kind === 217) { + if (ts.isFunctionLike(node.parent) || node.parent.kind === 217) { return spanInPreviousNode(node); } return spanInNode(node.parent); diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index 81c5bac2d03..bffa14b5875 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -124,28 +124,28 @@ declare module ts { WhileKeyword = 99, WithKeyword = 100, AsKeyword = 101, - FromKeyword = 102, - ImplementsKeyword = 103, - InterfaceKeyword = 104, - LetKeyword = 105, - PackageKeyword = 106, - PrivateKeyword = 107, - ProtectedKeyword = 108, - PublicKeyword = 109, - StaticKeyword = 110, - YieldKeyword = 111, - AnyKeyword = 112, - BooleanKeyword = 113, - ConstructorKeyword = 114, - DeclareKeyword = 115, - GetKeyword = 116, - ModuleKeyword = 117, - RequireKeyword = 118, - NumberKeyword = 119, - SetKeyword = 120, - StringKeyword = 121, - SymbolKeyword = 122, - TypeKeyword = 123, + ImplementsKeyword = 102, + InterfaceKeyword = 103, + LetKeyword = 104, + PackageKeyword = 105, + PrivateKeyword = 106, + ProtectedKeyword = 107, + PublicKeyword = 108, + StaticKeyword = 109, + YieldKeyword = 110, + AnyKeyword = 111, + BooleanKeyword = 112, + ConstructorKeyword = 113, + DeclareKeyword = 114, + GetKeyword = 115, + ModuleKeyword = 116, + RequireKeyword = 117, + NumberKeyword = 118, + SetKeyword = 119, + StringKeyword = 120, + SymbolKeyword = 121, + TypeKeyword = 122, + FromKeyword = 123, OfKeyword = 124, QualifiedName = 125, ComputedPropertyName = 126, @@ -251,8 +251,8 @@ declare module ts { LastReservedWord = 100, FirstKeyword = 65, LastKeyword = 124, - FirstFutureReservedWord = 103, - LastFutureReservedWord = 111, + FirstFutureReservedWord = 102, + LastFutureReservedWord = 110, FirstTypeNode = 139, LastTypeNode = 147, FirstPunctuation = 14, @@ -276,15 +276,16 @@ declare module ts { Private = 32, Protected = 64, Static = 128, - MultiLine = 256, - Synthetic = 512, - DeclarationFile = 1024, - Let = 2048, - Const = 4096, - OctalLiteral = 8192, - Modifier = 243, + Default = 256, + MultiLine = 512, + Synthetic = 1024, + DeclarationFile = 2048, + Let = 4096, + Const = 8192, + OctalLiteral = 16384, + Modifier = 499, AccessibilityModifier = 112, - BlockScoped = 6144, + BlockScoped = 12288, } const enum ParserContextFlags { StrictMode = 1, @@ -412,7 +413,7 @@ declare module ts { body?: Block | Expression; } interface FunctionDeclaration extends FunctionLikeDeclaration, Statement { - name: Identifier; + name?: Identifier; body?: Block; } interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { @@ -505,7 +506,9 @@ declare module ts { } interface ConditionalExpression extends Expression { condition: Expression; + questionToken: Node; whenTrue: Expression; + colonToken: Node; whenFalse: Expression; } interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclaration { @@ -515,6 +518,7 @@ declare module ts { interface LiteralExpression extends PrimaryExpression { text: string; isUnterminated?: boolean; + hasExtendedUnicodeEscape?: boolean; } interface StringLiteralExpression extends LiteralExpression { _stringLiteralExpressionBrand: any; @@ -541,6 +545,7 @@ declare module ts { } interface PropertyAccessExpression extends MemberExpression { expression: LeftHandSideExpression; + dotToken: Node; name: Identifier; } interface ElementAccessExpression extends MemberExpression { @@ -636,16 +641,15 @@ declare module ts { catchClause?: CatchClause; finallyBlock?: Block; } - interface CatchClause extends Declaration { - name: Identifier; - type?: TypeNode; + interface CatchClause extends Node { + variableDeclaration: VariableDeclaration; block: Block; } interface ModuleElement extends Node { _moduleElementBrand: any; } interface ClassDeclaration extends Declaration, ModuleElement { - name: Identifier; + name?: Identifier; typeParameters?: NodeArray; heritageClauses?: NodeArray; members: NodeArray; @@ -675,10 +679,7 @@ declare module ts { name: Identifier; members: NodeArray; } - interface ExportContainer { - exportStars?: ExportDeclaration[]; - } - interface ModuleDeclaration extends Declaration, ModuleElement, ExportContainer { + interface ModuleDeclaration extends Declaration, ModuleElement { name: Identifier | LiteralExpression; body: ModuleBlock | ModuleDeclaration; } @@ -703,7 +704,7 @@ declare module ts { interface NamespaceImport extends Declaration { name: Identifier; } - interface ExportDeclaration extends Statement, ModuleElement { + interface ExportDeclaration extends Declaration, ModuleElement { exportClause?: NamedExports; moduleSpecifier?: Expression; } @@ -718,8 +719,9 @@ declare module ts { } type ImportSpecifier = ImportOrExportSpecifier; type ExportSpecifier = ImportOrExportSpecifier; - interface ExportAssignment extends Statement, ModuleElement { - exportName: Identifier; + interface ExportAssignment extends Declaration, ModuleElement { + isExportEquals?: boolean; + expression: Expression; } interface FileReference extends TextRange { fileName: string; @@ -727,7 +729,7 @@ declare module ts { interface CommentRange extends TextRange { hasTrailingNewLine?: boolean; } - interface SourceFile extends Declaration, ExportContainer { + interface SourceFile extends Declaration { statements: NodeArray; endOfFileToken: Node; fileName: string; @@ -832,6 +834,7 @@ declare module ts { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean; getAliasedSymbol(symbol: Symbol): Symbol; + getExportsOfExternalModule(node: ImportDeclaration): Symbol[]; } interface SymbolDisplayBuilder { buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; @@ -889,10 +892,10 @@ declare module ts { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; + getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - getExportAssignmentName(node: SourceFile): string; - isReferencedImportDeclaration(node: Node): boolean; + hasExportDefaultValue(node: SourceFile): boolean; + isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; @@ -903,6 +906,7 @@ declare module ts { isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -928,13 +932,14 @@ declare module ts { ExportValue = 1048576, ExportType = 2097152, ExportNamespace = 4194304, - Import = 8388608, + Alias = 8388608, Instantiated = 16777216, Merged = 33554432, Transient = 67108864, Prototype = 134217728, UnionProperty = 268435456, Optional = 536870912, + ExportStar = 1073741824, Enum = 384, Variable = 3, Value = 107455, @@ -959,7 +964,7 @@ declare module ts { SetAccessorExcludes = 74687, TypeParameterExcludes = 530912, TypeAliasExcludes = 793056, - ImportExcludes = 8388608, + AliasExcludes = 8388608, ModuleMember = 8914931, ExportHasLocal = 944, HasLocals = 255504, @@ -988,10 +993,9 @@ declare module ts { declaredType?: Type; mapper?: TypeMapper; referenced?: boolean; - exportAssignmentChecked?: boolean; - exportAssignmentSymbol?: Symbol; unionType?: UnionType; resolvedExports?: SymbolTable; + exportsChecked?: boolean; } interface TransientSymbol extends Symbol, SymbolLinks { } @@ -1007,6 +1011,7 @@ declare module ts { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, + BlockScopedBindingInLoop = 256, } interface NodeLinks { resolvedType?: Type; @@ -1383,6 +1388,7 @@ declare module ts { getTokenPos(): number; getTokenText(): string; getTokenValue(): string; + hasExtendedUnicodeEscape(): boolean; hasPrecedingLineBreak(): boolean; isIdentifier(): boolean; isReservedWord(): boolean; @@ -1479,9 +1485,6 @@ declare module ts { getDocumentationComment(): SymbolDisplayPart[]; } interface SourceFile { - version: string; - scriptSnapshot: IScriptSnapshot; - nameTable: Map; getNamedDeclarations(): Declaration[]; getLineAndCharacterOfPosition(pos: number): LineAndCharacter; getLineStarts(): number[]; @@ -1835,25 +1838,17 @@ declare module ts { acquireDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile; /** * Request an updated version of an already existing SourceFile with a given fileName - * and compilationSettings. The update will intern call updateLanguageServiceSourceFile + * and compilationSettings. The update will in-turn call updateLanguageServiceSourceFile * to get an updated SourceFile. * - * Note: It is not allowed to call update on a SourceFile that was not acquired from this - * registry originally. - * - * @param sourceFile The original sourceFile object to update * @param fileName The name of the file requested * @param compilationSettings Some compilation settings like target affects the * shape of a the resulting SourceFile. This allows the DocumentRegistry to store * multiple copies of the same file for different compilation settings. - * @parm scriptSnapshot Text of the file. Only used if the file was not found - * in the registry and a new one was created. - * @parm version Current version of the file. Only used if the file was not found - * in the registry and a new one was created. - * @parm textChangeRange Change ranges since the last snapshot. Only used if the file - * was not found in the registry and a new one was created. + * @param scriptSnapshot Text of the file. + * @param version Current version of the file. */ - updateDocument(sourceFile: SourceFile, fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange): SourceFile; + updateDocument(fileName: string, compilationSettings: CompilerOptions, scriptSnapshot: IScriptSnapshot, version: string): SourceFile; /** * Informs the DocumentRegistry that a file is not needed any longer. * diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 4ee694a8f19..f3c487b2079 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -118,28 +118,28 @@ var ts; SyntaxKind[SyntaxKind["WhileKeyword"] = 99] = "WhileKeyword"; SyntaxKind[SyntaxKind["WithKeyword"] = 100] = "WithKeyword"; SyntaxKind[SyntaxKind["AsKeyword"] = 101] = "AsKeyword"; - SyntaxKind[SyntaxKind["FromKeyword"] = 102] = "FromKeyword"; - SyntaxKind[SyntaxKind["ImplementsKeyword"] = 103] = "ImplementsKeyword"; - SyntaxKind[SyntaxKind["InterfaceKeyword"] = 104] = "InterfaceKeyword"; - SyntaxKind[SyntaxKind["LetKeyword"] = 105] = "LetKeyword"; - SyntaxKind[SyntaxKind["PackageKeyword"] = 106] = "PackageKeyword"; - SyntaxKind[SyntaxKind["PrivateKeyword"] = 107] = "PrivateKeyword"; - SyntaxKind[SyntaxKind["ProtectedKeyword"] = 108] = "ProtectedKeyword"; - SyntaxKind[SyntaxKind["PublicKeyword"] = 109] = "PublicKeyword"; - SyntaxKind[SyntaxKind["StaticKeyword"] = 110] = "StaticKeyword"; - SyntaxKind[SyntaxKind["YieldKeyword"] = 111] = "YieldKeyword"; - SyntaxKind[SyntaxKind["AnyKeyword"] = 112] = "AnyKeyword"; - SyntaxKind[SyntaxKind["BooleanKeyword"] = 113] = "BooleanKeyword"; - SyntaxKind[SyntaxKind["ConstructorKeyword"] = 114] = "ConstructorKeyword"; - SyntaxKind[SyntaxKind["DeclareKeyword"] = 115] = "DeclareKeyword"; - SyntaxKind[SyntaxKind["GetKeyword"] = 116] = "GetKeyword"; - SyntaxKind[SyntaxKind["ModuleKeyword"] = 117] = "ModuleKeyword"; - SyntaxKind[SyntaxKind["RequireKeyword"] = 118] = "RequireKeyword"; - SyntaxKind[SyntaxKind["NumberKeyword"] = 119] = "NumberKeyword"; - SyntaxKind[SyntaxKind["SetKeyword"] = 120] = "SetKeyword"; - SyntaxKind[SyntaxKind["StringKeyword"] = 121] = "StringKeyword"; - SyntaxKind[SyntaxKind["SymbolKeyword"] = 122] = "SymbolKeyword"; - SyntaxKind[SyntaxKind["TypeKeyword"] = 123] = "TypeKeyword"; + SyntaxKind[SyntaxKind["ImplementsKeyword"] = 102] = "ImplementsKeyword"; + SyntaxKind[SyntaxKind["InterfaceKeyword"] = 103] = "InterfaceKeyword"; + SyntaxKind[SyntaxKind["LetKeyword"] = 104] = "LetKeyword"; + SyntaxKind[SyntaxKind["PackageKeyword"] = 105] = "PackageKeyword"; + SyntaxKind[SyntaxKind["PrivateKeyword"] = 106] = "PrivateKeyword"; + SyntaxKind[SyntaxKind["ProtectedKeyword"] = 107] = "ProtectedKeyword"; + SyntaxKind[SyntaxKind["PublicKeyword"] = 108] = "PublicKeyword"; + SyntaxKind[SyntaxKind["StaticKeyword"] = 109] = "StaticKeyword"; + SyntaxKind[SyntaxKind["YieldKeyword"] = 110] = "YieldKeyword"; + SyntaxKind[SyntaxKind["AnyKeyword"] = 111] = "AnyKeyword"; + SyntaxKind[SyntaxKind["BooleanKeyword"] = 112] = "BooleanKeyword"; + SyntaxKind[SyntaxKind["ConstructorKeyword"] = 113] = "ConstructorKeyword"; + SyntaxKind[SyntaxKind["DeclareKeyword"] = 114] = "DeclareKeyword"; + SyntaxKind[SyntaxKind["GetKeyword"] = 115] = "GetKeyword"; + SyntaxKind[SyntaxKind["ModuleKeyword"] = 116] = "ModuleKeyword"; + SyntaxKind[SyntaxKind["RequireKeyword"] = 117] = "RequireKeyword"; + SyntaxKind[SyntaxKind["NumberKeyword"] = 118] = "NumberKeyword"; + SyntaxKind[SyntaxKind["SetKeyword"] = 119] = "SetKeyword"; + SyntaxKind[SyntaxKind["StringKeyword"] = 120] = "StringKeyword"; + SyntaxKind[SyntaxKind["SymbolKeyword"] = 121] = "SymbolKeyword"; + SyntaxKind[SyntaxKind["TypeKeyword"] = 122] = "TypeKeyword"; + SyntaxKind[SyntaxKind["FromKeyword"] = 123] = "FromKeyword"; SyntaxKind[SyntaxKind["OfKeyword"] = 124] = "OfKeyword"; SyntaxKind[SyntaxKind["QualifiedName"] = 125] = "QualifiedName"; SyntaxKind[SyntaxKind["ComputedPropertyName"] = 126] = "ComputedPropertyName"; @@ -245,8 +245,8 @@ var ts; SyntaxKind[SyntaxKind["LastReservedWord"] = 100] = "LastReservedWord"; SyntaxKind[SyntaxKind["FirstKeyword"] = 65] = "FirstKeyword"; SyntaxKind[SyntaxKind["LastKeyword"] = 124] = "LastKeyword"; - SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 103] = "FirstFutureReservedWord"; - SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 111] = "LastFutureReservedWord"; + SyntaxKind[SyntaxKind["FirstFutureReservedWord"] = 102] = "FirstFutureReservedWord"; + SyntaxKind[SyntaxKind["LastFutureReservedWord"] = 110] = "LastFutureReservedWord"; SyntaxKind[SyntaxKind["FirstTypeNode"] = 139] = "FirstTypeNode"; SyntaxKind[SyntaxKind["LastTypeNode"] = 147] = "LastTypeNode"; SyntaxKind[SyntaxKind["FirstPunctuation"] = 14] = "FirstPunctuation"; @@ -271,15 +271,16 @@ var ts; NodeFlags[NodeFlags["Private"] = 32] = "Private"; NodeFlags[NodeFlags["Protected"] = 64] = "Protected"; NodeFlags[NodeFlags["Static"] = 128] = "Static"; - NodeFlags[NodeFlags["MultiLine"] = 256] = "MultiLine"; - NodeFlags[NodeFlags["Synthetic"] = 512] = "Synthetic"; - NodeFlags[NodeFlags["DeclarationFile"] = 1024] = "DeclarationFile"; - NodeFlags[NodeFlags["Let"] = 2048] = "Let"; - NodeFlags[NodeFlags["Const"] = 4096] = "Const"; - NodeFlags[NodeFlags["OctalLiteral"] = 8192] = "OctalLiteral"; - NodeFlags[NodeFlags["Modifier"] = 243] = "Modifier"; + NodeFlags[NodeFlags["Default"] = 256] = "Default"; + NodeFlags[NodeFlags["MultiLine"] = 512] = "MultiLine"; + NodeFlags[NodeFlags["Synthetic"] = 1024] = "Synthetic"; + NodeFlags[NodeFlags["DeclarationFile"] = 2048] = "DeclarationFile"; + NodeFlags[NodeFlags["Let"] = 4096] = "Let"; + NodeFlags[NodeFlags["Const"] = 8192] = "Const"; + NodeFlags[NodeFlags["OctalLiteral"] = 16384] = "OctalLiteral"; + NodeFlags[NodeFlags["Modifier"] = 499] = "Modifier"; NodeFlags[NodeFlags["AccessibilityModifier"] = 112] = "AccessibilityModifier"; - NodeFlags[NodeFlags["BlockScoped"] = 6144] = "BlockScoped"; + NodeFlags[NodeFlags["BlockScoped"] = 12288] = "BlockScoped"; })(ts.NodeFlags || (ts.NodeFlags = {})); var NodeFlags = ts.NodeFlags; (function (ParserContextFlags) { @@ -353,13 +354,14 @@ var ts; SymbolFlags[SymbolFlags["ExportValue"] = 1048576] = "ExportValue"; SymbolFlags[SymbolFlags["ExportType"] = 2097152] = "ExportType"; SymbolFlags[SymbolFlags["ExportNamespace"] = 4194304] = "ExportNamespace"; - SymbolFlags[SymbolFlags["Import"] = 8388608] = "Import"; + SymbolFlags[SymbolFlags["Alias"] = 8388608] = "Alias"; SymbolFlags[SymbolFlags["Instantiated"] = 16777216] = "Instantiated"; SymbolFlags[SymbolFlags["Merged"] = 33554432] = "Merged"; SymbolFlags[SymbolFlags["Transient"] = 67108864] = "Transient"; SymbolFlags[SymbolFlags["Prototype"] = 134217728] = "Prototype"; SymbolFlags[SymbolFlags["UnionProperty"] = 268435456] = "UnionProperty"; SymbolFlags[SymbolFlags["Optional"] = 536870912] = "Optional"; + SymbolFlags[SymbolFlags["ExportStar"] = 1073741824] = "ExportStar"; SymbolFlags[SymbolFlags["Enum"] = 384] = "Enum"; SymbolFlags[SymbolFlags["Variable"] = 3] = "Variable"; SymbolFlags[SymbolFlags["Value"] = 107455] = "Value"; @@ -384,7 +386,7 @@ var ts; SymbolFlags[SymbolFlags["SetAccessorExcludes"] = 74687] = "SetAccessorExcludes"; SymbolFlags[SymbolFlags["TypeParameterExcludes"] = 530912] = "TypeParameterExcludes"; SymbolFlags[SymbolFlags["TypeAliasExcludes"] = 793056] = "TypeAliasExcludes"; - SymbolFlags[SymbolFlags["ImportExcludes"] = 8388608] = "ImportExcludes"; + SymbolFlags[SymbolFlags["AliasExcludes"] = 8388608] = "AliasExcludes"; SymbolFlags[SymbolFlags["ModuleMember"] = 8914931] = "ModuleMember"; SymbolFlags[SymbolFlags["ExportHasLocal"] = 944] = "ExportHasLocal"; SymbolFlags[SymbolFlags["HasLocals"] = 255504] = "HasLocals"; @@ -404,6 +406,7 @@ var ts; NodeCheckFlags[NodeCheckFlags["SuperStatic"] = 32] = "SuperStatic"; NodeCheckFlags[NodeCheckFlags["ContextChecked"] = 64] = "ContextChecked"; NodeCheckFlags[NodeCheckFlags["EnumValuesComputed"] = 128] = "EnumValuesComputed"; + NodeCheckFlags[NodeCheckFlags["BlockScopedBindingInLoop"] = 256] = "BlockScopedBindingInLoop"; })(ts.NodeCheckFlags || (ts.NodeCheckFlags = {})); var NodeCheckFlags = ts.NodeCheckFlags; (function (TypeFlags) { @@ -825,7 +828,9 @@ var ts; } ts.localizedDiagnosticMessages = undefined; function getLocaleSpecificMessage(message) { - return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message] ? ts.localizedDiagnosticMessages[message] : message; + return ts.localizedDiagnosticMessages && ts.localizedDiagnosticMessages[message] + ? ts.localizedDiagnosticMessages[message] + : message; } ts.getLocaleSpecificMessage = getLocaleSpecificMessage; function createFileDiagnostic(file, start, length, message) { @@ -973,7 +978,9 @@ var ts; normalized.pop(); } else { - normalized.push(part); + if (part) { + normalized.push(part); + } } } } @@ -1116,7 +1123,7 @@ var ts; } ts.removeFileExtension = removeFileExtension; var backslashOrDoubleQuote = /[\"\\]/g; - var escapedCharsRegExp = /[\0-\19\t\v\f\b\0\r\n\u2028\u2029\u0085]/g; + var escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g; var escapedCharsMap = { "\0": "\\0", "\t": "\\t", @@ -1131,20 +1138,6 @@ var ts; "\u2029": "\\u2029", "\u0085": "\\u0085" }; - function escapeString(s) { - s = backslashOrDoubleQuote.test(s) ? s.replace(backslashOrDoubleQuote, getReplacement) : s; - s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s; - return s; - function getReplacement(c) { - return escapedCharsMap[c] || unicodeEscape(c); - } - function unicodeEscape(c) { - var hexCharCode = c.charCodeAt(0).toString(16); - var paddedHexCode = ("0000" + hexCharCode).slice(-4); - return "\\u" + paddedHexCode; - } - } - ts.escapeString = escapeString; function getDefaultLibFileName(options) { return options.target === 2 ? "lib.es6.d.ts" : "lib.d.ts"; } @@ -1464,7 +1457,6 @@ var ts; Trailing_comma_not_allowed: { code: 1009, category: 1, key: "Trailing comma not allowed." }, Asterisk_Slash_expected: { code: 1010, category: 1, key: "'*/' expected." }, Unexpected_token: { code: 1012, category: 1, key: "Unexpected token." }, - Catch_clause_parameter_cannot_have_a_type_annotation: { code: 1013, category: 1, key: "Catch clause parameter cannot have a type annotation." }, A_rest_parameter_must_be_last_in_a_parameter_list: { code: 1014, category: 1, key: "A rest parameter must be last in a parameter list." }, Parameter_cannot_have_question_mark_and_initializer: { code: 1015, category: 1, key: "Parameter cannot have question mark and initializer." }, A_required_parameter_cannot_follow_an_optional_parameter: { code: 1016, category: 1, key: "A required parameter cannot follow an optional parameter." }, @@ -1572,7 +1564,6 @@ var ts; const_declarations_must_be_initialized: { code: 1155, category: 1, key: "'const' declarations must be initialized" }, const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: 1, key: "'const' declarations can only be declared inside a block." }, let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: 1, key: "'let' declarations can only be declared inside a block." }, - Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: 1, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." }, 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." }, @@ -1609,6 +1600,11 @@ var ts; External_module_0_has_no_default_export_or_export_assignment: { code: 1192, category: 1, key: "External module '{0}' has no default export or export assignment." }, An_export_declaration_cannot_have_modifiers: { code: 1193, category: 1, key: "An export declaration cannot have modifiers." }, Export_declarations_are_not_permitted_in_an_internal_module: { code: 1194, category: 1, key: "Export declarations are not permitted in an internal module." }, + Catch_clause_variable_name_must_be_an_identifier: { code: 1195, category: 1, key: "Catch clause variable name must be an identifier." }, + Catch_clause_variable_cannot_have_a_type_annotation: { code: 1196, category: 1, key: "Catch clause variable cannot have a type annotation." }, + Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: 1, key: "Catch clause variable cannot have an initializer." }, + An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: 1, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, + Unterminated_Unicode_escape_sequence: { code: 1199, category: 1, key: "Unterminated Unicode escape sequence." }, 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." }, @@ -1782,6 +1778,14 @@ var ts; for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 2482, category: 1, key: "'for...of' statements are only available when targeting ECMAScript 6 or higher." }, The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation: { code: 2483, category: 1, key: "The left-hand side of a 'for...of' statement cannot use a type annotation." }, Export_declaration_conflicts_with_exported_declaration_of_0: { code: 2484, category: 1, key: "Export declaration conflicts with exported declaration of '{0}'" }, + The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant: { code: 2485, category: 1, key: "The left-hand side of a 'for...of' statement cannot be a previously defined constant." }, + The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant: { code: 2486, category: 1, key: "The left-hand side of a 'for...in' statement cannot be a previously defined constant." }, + Invalid_left_hand_side_in_for_of_statement: { code: 2487, category: 1, key: "Invalid left-hand side in 'for...of' statement." }, + The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator: { code: 2488, category: 1, key: "The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator." }, + The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method: { code: 2489, category: 1, key: "The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method." }, + The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property: { code: 2490, category: 1, key: "The type returned by the 'next()' method of an iterator must have a 'value' property." }, + The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern: { code: 2491, category: 1, key: "The left-hand side of a 'for...in' statement cannot be a destructuring pattern." }, + Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: 1, key: "Cannot redeclare identifier '{0}' in catch clause" }, 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}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: 1, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1851,6 +1855,7 @@ var ts; Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: 1, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: 1, key: "Parameter '{0}' of exported function has or is using private name '{1}'." }, Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: 1, key: "Exported type alias '{0}' has or is using private name '{1}'." }, + Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: 1, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." }, 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}" }, @@ -1926,25 +1931,24 @@ var ts; You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: 1, key: "You cannot rename elements that are defined in the standard TypeScript library." }, yield_expressions_are_not_currently_supported: { code: 9000, category: 1, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: 1, key: "Generators are not currently supported." }, - The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: 1, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, - for_of_statements_are_not_currently_supported: { code: 9003, category: 1, key: "'for...of' statements are not currently supported." } + The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: 1, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." } }; })(ts || (ts = {})); var ts; (function (ts) { var textToToken = { - "any": 112, + "any": 111, "as": 101, - "boolean": 113, + "boolean": 112, "break": 65, "case": 66, "catch": 67, "class": 68, "continue": 70, "const": 69, - "constructor": 114, + "constructor": 113, "debugger": 71, - "declare": 115, + "declare": 114, "default": 72, "delete": 73, "do": 74, @@ -1955,43 +1959,43 @@ var ts; "false": 79, "finally": 80, "for": 81, - "from": 102, + "from": 123, "function": 82, - "get": 116, + "get": 115, "if": 83, - "implements": 103, + "implements": 102, "import": 84, "in": 85, "instanceof": 86, - "interface": 104, - "let": 105, - "module": 117, + "interface": 103, + "let": 104, + "module": 116, "new": 87, "null": 88, - "number": 119, - "package": 106, - "private": 107, - "protected": 108, - "public": 109, - "require": 118, + "number": 118, + "package": 105, + "private": 106, + "protected": 107, + "public": 108, + "require": 117, "return": 89, - "set": 120, - "static": 110, - "string": 121, + "set": 119, + "static": 109, + "string": 120, "super": 90, "switch": 91, - "symbol": 122, + "symbol": 121, "this": 92, "throw": 93, "true": 94, "try": 95, - "type": 123, + "type": 122, "typeof": 96, "var": 97, "void": 98, "while": 99, "with": 100, - "yield": 111, + "yield": 110, "of": 124, "{": 14, "}": 15, @@ -2071,11 +2075,15 @@ var ts; return false; } function isUnicodeIdentifierStart(code, languageVersion) { - return languageVersion >= 1 ? lookupInUnicodeMap(code, unicodeES5IdentifierStart) : lookupInUnicodeMap(code, unicodeES3IdentifierStart); + return languageVersion >= 1 ? + lookupInUnicodeMap(code, unicodeES5IdentifierStart) : + lookupInUnicodeMap(code, unicodeES3IdentifierStart); } ts.isUnicodeIdentifierStart = isUnicodeIdentifierStart; function isUnicodeIdentifierPart(code, languageVersion) { - return languageVersion >= 1 ? lookupInUnicodeMap(code, unicodeES5IdentifierPart) : lookupInUnicodeMap(code, unicodeES3IdentifierPart); + return languageVersion >= 1 ? + lookupInUnicodeMap(code, unicodeES5IdentifierPart) : + lookupInUnicodeMap(code, unicodeES3IdentifierPart); } function makeReverseMap(source) { var result = []; @@ -2364,6 +2372,7 @@ var ts; var token; var tokenValue; var precedingLineBreak; + var hasExtendedUnicodeEscape; var tokenIsUnterminated; function error(message, length) { if (onError) { @@ -2413,10 +2422,16 @@ var ts; } return +(text.substring(start, pos)); } - function scanHexDigits(count, mustMatchCount) { + function scanExactNumberOfHexDigits(count) { + return scanHexDigits(count, false); + } + function scanMinimumNumberOfHexDigits(count) { + return scanHexDigits(count, true); + } + function scanHexDigits(minCount, scanAsManyAsPossible) { var digits = 0; var value = 0; - while (digits < count || !mustMatchCount) { + while (digits < minCount || scanAsManyAsPossible) { var ch = text.charCodeAt(pos); if (ch >= 48 && ch <= 57) { value = value * 16 + ch - 48; @@ -2433,7 +2448,7 @@ var ts; pos++; digits++; } - if (digits < count) { + if (digits < minCount) { value = -1; } return value; @@ -2546,16 +2561,15 @@ var ts; return "\'"; case 34: return "\""; - case 120: case 117: - var ch = scanHexDigits(ch === 120 ? 2 : 4, true); - if (ch >= 0) { - return String.fromCharCode(ch); - } - else { - error(ts.Diagnostics.Hexadecimal_digit_expected); - return ""; + if (pos < len && text.charCodeAt(pos) === 123) { + hasExtendedUnicodeEscape = true; + pos++; + return scanExtendedUnicodeEscape(); } + return scanHexadecimalEscape(4); + case 120: + return scanHexadecimalEscape(2); case 13: if (pos < len && text.charCodeAt(pos) === 10) { pos++; @@ -2568,11 +2582,57 @@ var ts; return String.fromCharCode(ch); } } + function scanHexadecimalEscape(numDigits) { + var escapedValue = scanExactNumberOfHexDigits(numDigits); + if (escapedValue >= 0) { + return String.fromCharCode(escapedValue); + } + else { + error(ts.Diagnostics.Hexadecimal_digit_expected); + return ""; + } + } + function scanExtendedUnicodeEscape() { + var escapedValue = scanMinimumNumberOfHexDigits(1); + var isInvalidExtendedEscape = false; + if (escapedValue < 0) { + error(ts.Diagnostics.Hexadecimal_digit_expected); + isInvalidExtendedEscape = true; + } + else if (escapedValue > 0x10FFFF) { + error(ts.Diagnostics.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive); + isInvalidExtendedEscape = true; + } + if (pos >= len) { + error(ts.Diagnostics.Unexpected_end_of_text); + isInvalidExtendedEscape = true; + } + else if (text.charCodeAt(pos) == 125) { + pos++; + } + else { + error(ts.Diagnostics.Unterminated_Unicode_escape_sequence); + isInvalidExtendedEscape = true; + } + if (isInvalidExtendedEscape) { + return ""; + } + return utf16EncodeAsString(escapedValue); + } + function utf16EncodeAsString(codePoint) { + ts.Debug.assert(0x0 <= codePoint && codePoint <= 0x10FFFF); + if (codePoint <= 65535) { + return String.fromCharCode(codePoint); + } + var codeUnit1 = Math.floor((codePoint - 65536) / 1024) + 0xD800; + var codeUnit2 = ((codePoint - 65536) % 1024) + 0xDC00; + return String.fromCharCode(codeUnit1, codeUnit2); + } function peekUnicodeEscape() { if (pos + 5 < len && text.charCodeAt(pos + 1) === 117) { var start = pos; pos += 2; - var value = scanHexDigits(4, true); + var value = scanExactNumberOfHexDigits(4); pos = start; return value; } @@ -2634,6 +2694,7 @@ var ts; } function scan() { startPos = pos; + hasExtendedUnicodeEscape = false; precedingLineBreak = false; tokenIsUnterminated = false; while (true) { @@ -2785,7 +2846,7 @@ var ts; case 48: if (pos + 2 < len && (text.charCodeAt(pos + 1) === 88 || text.charCodeAt(pos + 1) === 120)) { pos += 2; - var value = scanHexDigits(1, false); + var value = scanMinimumNumberOfHexDigits(1); if (value < 0) { error(ts.Diagnostics.Hexadecimal_digit_expected); value = 0; @@ -3055,6 +3116,7 @@ var ts; getTokenPos: function () { return tokenPos; }, getTokenText: function () { return text.substring(tokenPos, pos); }, getTokenValue: function () { return tokenValue; }, + hasExtendedUnicodeEscape: function () { return hasExtendedUnicodeEscape; }, hasPrecedingLineBreak: function () { return precedingLineBreak; }, isIdentifier: function () { return token === 64 || token > 100; }, isReservedWord: function () { return token >= 65 && token <= 100; }, @@ -3203,35 +3265,51 @@ var ts; return ts.getBaseFileName(moduleName).replace(/\W/g, "_"); } ts.makeIdentifierFromModuleName = makeIdentifierFromModuleName; + function isBlockOrCatchScoped(declaration) { + return (getCombinedNodeFlags(declaration) & 12288) !== 0 || + isCatchClauseVariableDeclaration(declaration); + } + ts.isBlockOrCatchScoped = isBlockOrCatchScoped; + function isCatchClauseVariableDeclaration(declaration) { + return declaration && + declaration.kind === 193 && + declaration.parent && + declaration.parent.kind === 216; + } + ts.isCatchClauseVariableDeclaration = isCatchClauseVariableDeclaration; function declarationNameToString(name) { return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name); } ts.declarationNameToString = declarationNameToString; function createDiagnosticForNode(node, message, arg0, arg1, arg2) { - node = getErrorSpanForNode(node); - var file = getSourceFileOfNode(node); - var start = getTokenPosOfNode(node, file); - var length = node.end - start; - return ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2); + var sourceFile = getSourceFileOfNode(node); + var span = getErrorSpanForNode(sourceFile, node); + return ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2); } ts.createDiagnosticForNode = createDiagnosticForNode; function createDiagnosticForNodeFromMessageChain(node, messageChain) { - node = getErrorSpanForNode(node); - var file = getSourceFileOfNode(node); - var start = ts.skipTrivia(file.text, node.pos); - var length = node.end - start; + var sourceFile = getSourceFileOfNode(node); + var span = getErrorSpanForNode(sourceFile, node); return { - file: file, - start: start, - length: length, + file: sourceFile, + start: span.start, + length: span.length, code: messageChain.code, category: messageChain.category, messageText: messageChain.next ? messageChain : messageChain.messageText }; } ts.createDiagnosticForNodeFromMessageChain = createDiagnosticForNodeFromMessageChain; - function getErrorSpanForNode(node) { - var errorSpan; + function getSpanOfTokenAtPosition(sourceFile, pos) { + var scanner = ts.createScanner(sourceFile.languageVersion, true, sourceFile.text); + scanner.setTextPos(pos); + scanner.scan(); + var start = scanner.getTokenPos(); + return createTextSpanFromBounds(start, scanner.getTextPos()); + } + ts.getSpanOfTokenAtPosition = getSpanOfTokenAtPosition; + function getErrorSpanForNode(sourceFile, node) { + var errorNode = node; switch (node.kind) { case 193: case 150: @@ -3240,10 +3318,18 @@ var ts; case 200: case 199: case 219: - errorSpan = node.name; + case 195: + case 160: + errorNode = node.name; break; } - return errorSpan && errorSpan.pos < errorSpan.end ? errorSpan : node; + if (errorNode === undefined) { + return getSpanOfTokenAtPosition(sourceFile, node.pos); + } + var pos = nodeIsMissing(errorNode) + ? errorNode.pos + : ts.skipTrivia(sourceFile.text, errorNode.pos); + return createTextSpanFromBounds(pos, errorNode.end); } ts.getErrorSpanForNode = getErrorSpanForNode; function isExternalModule(file) { @@ -3251,7 +3337,7 @@ var ts; } ts.isExternalModule = isExternalModule; function isDeclarationFile(file) { - return (file.flags & 1024) !== 0; + return (file.flags & 2048) !== 0; } ts.isDeclarationFile = isDeclarationFile; function isConstEnumDeclaration(node) { @@ -3281,11 +3367,11 @@ var ts; } ts.getCombinedNodeFlags = getCombinedNodeFlags; function isConst(node) { - return !!(getCombinedNodeFlags(node) & 4096); + return !!(getCombinedNodeFlags(node) & 8192); } ts.isConst = isConst; function isLet(node) { - return !!(getCombinedNodeFlags(node) & 2048); + return !!(getCombinedNodeFlags(node) & 4096); } ts.isLet = isLet; function isPrologueDirective(node) { @@ -3337,7 +3423,24 @@ var ts; } } ts.forEachReturnStatement = forEachReturnStatement; - function isAnyFunction(node) { + function isVariableLike(node) { + if (node) { + switch (node.kind) { + case 150: + case 219: + case 128: + case 217: + case 130: + case 129: + case 218: + case 193: + return true; + } + } + return false; + } + ts.isVariableLike = isVariableLike; + function isFunctionLike(node) { if (node) { switch (node.kind) { case 133: @@ -3361,9 +3464,9 @@ var ts; } return false; } - ts.isAnyFunction = isAnyFunction; + ts.isFunctionLike = isFunctionLike; function isFunctionBlock(node) { - return node && node.kind === 174 && isAnyFunction(node.parent); + return node && node.kind === 174 && isFunctionLike(node.parent); } ts.isFunctionBlock = isFunctionBlock; function isObjectLiteralMethod(node) { @@ -3373,7 +3476,7 @@ var ts; function getContainingFunction(node) { while (true) { node = node.parent; - if (!node || isAnyFunction(node)) { + if (!node || isFunctionLike(node)) { return node; } } @@ -3611,12 +3714,12 @@ var ts; } ts.isTemplateLiteralKind = isTemplateLiteralKind; function isBindingPattern(node) { - return node.kind === 149 || node.kind === 148; + return !!node && (node.kind === 149 || node.kind === 148); } ts.isBindingPattern = isBindingPattern; function isInAmbientContext(node) { while (node) { - if (node.flags & (2 | 1024)) { + if (node.flags & (2 | 2048)) { return true; } node = node.parent; @@ -3626,31 +3729,33 @@ var ts; ts.isInAmbientContext = isInAmbientContext; function isDeclaration(node) { switch (node.kind) { - case 127: - case 128: - case 193: + case 161: case 150: - case 130: - case 129: - case 217: - case 218: + case 196: + case 133: + case 199: case 219: + case 211: + case 195: + case 160: + case 134: + case 204: + case 202: + case 207: + case 197: case 132: case 131: - case 195: - case 134: - case 135: - case 133: - case 196: - case 197: - case 198: - case 199: case 200: - case 202: - case 204: - case 207: case 205: - case 211: + case 128: + case 217: + case 130: + case 129: + case 135: + case 218: + case 198: + case 127: + case 193: return true; } return false; @@ -3683,27 +3788,29 @@ var ts; } } ts.isStatement = isStatement; - function isDeclarationOrFunctionExpressionOrCatchVariableName(name) { + function isDeclarationName(name) { if (name.kind !== 64 && name.kind !== 8 && name.kind !== 7) { return false; } var parent = name.parent; - if (isDeclaration(parent) || parent.kind === 160) { - return parent.name === name; + if (parent.kind === 207 || parent.kind === 211) { + if (parent.propertyName) { + return true; + } } - if (parent.kind === 216) { + if (isDeclaration(parent)) { return parent.name === name; } return false; } - ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName; + ts.isDeclarationName = isDeclarationName; function getClassBaseTypeNode(node) { var heritageClause = getHeritageClause(node.heritageClauses, 78); return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined; } ts.getClassBaseTypeNode = getClassBaseTypeNode; function getClassImplementedTypeNodes(node) { - var heritageClause = getHeritageClause(node.heritageClauses, 103); + var heritageClause = getHeritageClause(node.heritageClauses, 102); return heritageClause ? heritageClause.types : undefined; } ts.getClassImplementedTypeNodes = getClassImplementedTypeNodes; @@ -3817,13 +3924,14 @@ var ts; ts.isESSymbolIdentifier = isESSymbolIdentifier; function isModifier(token) { switch (token) { - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: case 77: - case 115: + case 114: case 69: + case 72: return true; } return false; @@ -3938,6 +4046,42 @@ var ts; return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); } ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; + function nodeStartsNewLexicalEnvironment(n) { + return isFunctionLike(n) || n.kind === 200 || n.kind === 220; + } + ts.nodeStartsNewLexicalEnvironment = nodeStartsNewLexicalEnvironment; + function nodeIsSynthesized(node) { + return node.pos === -1 && node.end === -1; + } + ts.nodeIsSynthesized = nodeIsSynthesized; + function createSynthesizedNode(kind, startsOnNewLine) { + var node = ts.createNode(kind); + node.pos = -1; + node.end = -1; + node.startsOnNewLine = startsOnNewLine; + return node; + } + ts.createSynthesizedNode = createSynthesizedNode; + function generateUniqueName(baseName, isExistingName) { + if (baseName.charCodeAt(0) !== 95) { + var baseName = "_" + baseName; + if (!isExistingName(baseName)) { + return baseName; + } + } + if (baseName.charCodeAt(baseName.length - 1) !== 95) { + baseName += "_"; + } + var i = 1; + while (true) { + var name = baseName + i; + if (!isExistingName(name)) { + return name; + } + i++; + } + } + ts.generateUniqueName = generateUniqueName; function createDiagnosticCollection() { var nonFileDiagnostics = []; var fileDiagnostics = {}; @@ -4003,6 +4147,41 @@ var ts; } } ts.createDiagnosticCollection = createDiagnosticCollection; + var escapedCharsRegExp = /[\\\"\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g; + var escapedCharsMap = { + "\0": "\\0", + "\t": "\\t", + "\v": "\\v", + "\f": "\\f", + "\b": "\\b", + "\r": "\\r", + "\n": "\\n", + "\\": "\\\\", + "\"": "\\\"", + "\u2028": "\\u2028", + "\u2029": "\\u2029", + "\u0085": "\\u0085" + }; + function escapeString(s) { + s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s; + return s; + function getReplacement(c) { + return escapedCharsMap[c] || get16BitUnicodeEscapeSequence(c.charCodeAt(0)); + } + } + ts.escapeString = escapeString; + function get16BitUnicodeEscapeSequence(charCode) { + var hexCharCode = charCode.toString(16).toUpperCase(); + var paddedHexCode = ("0000" + hexCharCode).slice(-4); + return "\\u" + paddedHexCode; + } + var nonAsciiCharacters = /[^\u0000-\u007F]/g; + function escapeNonAsciiCharacters(s) { + return nonAsciiCharacters.test(s) ? + s.replace(nonAsciiCharacters, function (c) { return get16BitUnicodeEscapeSequence(c.charCodeAt(0)); }) : + s; + } + ts.escapeNonAsciiCharacters = escapeNonAsciiCharacters; })(ts || (ts = {})); var ts; (function (ts) { @@ -4113,6 +4292,7 @@ var ts; return visitNodes(cbNodes, node.properties); case 153: return visitNode(cbNode, node.expression) || + visitNode(cbNode, node.dotToken) || visitNode(cbNode, node.name); case 154: return visitNode(cbNode, node.expression) || @@ -4149,7 +4329,9 @@ var ts; visitNode(cbNode, node.right); case 168: return visitNode(cbNode, node.condition) || + visitNode(cbNode, node.questionToken) || visitNode(cbNode, node.whenTrue) || + visitNode(cbNode, node.colonToken) || visitNode(cbNode, node.whenFalse); case 171: return visitNode(cbNode, node.expression); @@ -4215,8 +4397,7 @@ var ts; visitNode(cbNode, node.catchClause) || visitNode(cbNode, node.finallyBlock); case 216: - return visitNode(cbNode, node.name) || - visitNode(cbNode, node.type) || + return visitNode(cbNode, node.variableDeclaration) || visitNode(cbNode, node.block); case 196: return visitNodes(cbNodes, node.modifiers) || @@ -4271,7 +4452,7 @@ var ts; visitNode(cbNode, node.name); case 208: return visitNodes(cbNodes, node.modifiers) || - visitNode(cbNode, node.exportName); + visitNode(cbNode, node.expression); case 169: return visitNode(cbNode, node.head) || visitNodes(cbNodes, node.templateSpans); case 173: @@ -4344,13 +4525,14 @@ var ts; ; function modifierToFlag(token) { switch (token) { - case 110: return 128; - case 109: return 16; - case 108: return 64; - case 107: return 32; + case 109: return 128; + case 108: return 16; + case 107: return 64; + case 106: return 32; case 77: return 1; - case 115: return 2; - case 69: return 4096; + case 114: return 2; + case 69: return 8192; + case 72: return 256; } return 0; } @@ -4676,7 +4858,7 @@ var ts; sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = ts.normalizePath(fileName); - sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 1024 : 0; + sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 2048 : 0; var contextFlags = 0; var parseErrorBeforeNextFinishedNode = false; var scanner = ts.createScanner(languageVersion, true, sourceText, scanError); @@ -4804,7 +4986,9 @@ var ts; var saveParseDiagnosticsLength = sourceFile.parseDiagnostics.length; var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; var saveContextFlags = contextFlags; - var result = isLookAhead ? scanner.lookAhead(callback) : scanner.tryScan(callback); + var result = isLookAhead + ? scanner.lookAhead(callback) + : scanner.tryScan(callback); ts.Debug.assert(saveContextFlags === contextFlags); if (!result || isLookAhead) { token = saveToken; @@ -4823,10 +5007,10 @@ var ts; if (token === 64) { return true; } - if (token === 111 && inYieldContext()) { + if (token === 110 && inYieldContext()) { return false; } - return inStrictModeContext() ? token > 111 : token > 100; + return inStrictModeContext() ? token > 110 : token > 100; } function parseExpected(kind, diagnosticMessage) { if (token === kind) { @@ -4850,12 +5034,14 @@ var ts; } function parseOptionalToken(t) { if (token === t) { - var node = createNode(t); - nextToken(); - return finishNode(node); + return parseTokenNode(); } return undefined; } + function parseExpectedToken(t, reportAtCurrentPosition, diagnosticMessage, arg0) { + return parseOptionalToken(t) || + createMissingNode(t, reportAtCurrentPosition, diagnosticMessage, arg0); + } function parseTokenNode() { var node = createNode(token); nextToken(); @@ -4974,13 +5160,26 @@ var ts; } if (token === 77) { nextToken(); + if (token === 72) { + return lookAhead(nextTokenIsClassOrFunction); + } return token !== 35 && token !== 14 && canFollowModifier(); } + if (token === 72) { + return nextTokenIsClassOrFunction(); + } nextToken(); return canFollowModifier(); } function canFollowModifier() { - return token === 18 || token === 14 || token === 35 || isLiteralPropertyName(); + return token === 18 + || token === 14 + || token === 35 + || isLiteralPropertyName(); + } + function nextTokenIsClassOrFunction() { + nextToken(); + return token === 68 || token === 82; } function isListElement(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); @@ -5034,7 +5233,7 @@ var ts; return isIdentifier(); } function isNotHeritageClauseTypeName() { - if (token === 103 || + if (token === 102 || token === 78) { return lookAhead(nextTokenIsIdentifier); } @@ -5058,11 +5257,11 @@ var ts; case 4: return token === 15 || token === 66 || token === 72; case 8: - return token === 14 || token === 78 || token === 103; + return token === 14 || token === 78 || token === 102; case 9: return isVariableDeclaratorListTerminator(); case 16: - return token === 25 || token === 16 || token === 14 || token === 78 || token === 103; + return token === 25 || token === 16 || token === 14 || token === 78 || token === 102; case 12: return token === 17 || token === 22; case 14: @@ -5398,7 +5597,7 @@ var ts; literal = parseLiteralNode(); } else { - literal = createMissingNode(13, false, ts.Diagnostics._0_expected, ts.tokenToString(15)); + literal = parseExpectedToken(13, false, ts.Diagnostics._0_expected, ts.tokenToString(15)); } span.literal = literal; return finishNode(span); @@ -5407,14 +5606,19 @@ var ts; var node = createNode(token); var text = scanner.getTokenValue(); node.text = internName ? internIdentifier(text) : text; + if (scanner.hasExtendedUnicodeEscape()) { + node.hasExtendedUnicodeEscape = true; + } if (scanner.isUnterminated()) { node.isUnterminated = true; } var tokenPos = scanner.getTokenPos(); nextToken(); finishNode(node); - if (node.kind === 7 && sourceText.charCodeAt(tokenPos) === 48 && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { - node.flags |= 8192; + if (node.kind === 7 + && sourceText.charCodeAt(tokenPos) === 48 + && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) { + node.flags |= 16384; } return node; } @@ -5452,7 +5656,9 @@ var ts; } function parseParameterType() { if (parseOptional(51)) { - return token === 8 ? parseLiteralNode(true) : parseType(); + return token === 8 + ? parseLiteralNode(true) + : parseType(); } return undefined; } @@ -5622,7 +5828,9 @@ var ts; case 24: return parseSignatureMember(136); case 18: - return isIndexSignature() ? parseIndexSignatureDeclaration(undefined) : parsePropertyOrMethodSignature(); + return isIndexSignature() + ? parseIndexSignatureDeclaration(undefined) + : parsePropertyOrMethodSignature(); case 87: if (lookAhead(isStartOfConstructSignature)) { return parseSignatureMember(137); @@ -5644,7 +5852,9 @@ var ts; } function parseIndexSignatureWithModifiers() { var modifiers = parseModifiers(); - return isIndexSignature() ? parseIndexSignatureDeclaration(modifiers) : undefined; + return isIndexSignature() + ? parseIndexSignatureDeclaration(modifiers) + : undefined; } function isStartOfConstructSignature() { nextToken(); @@ -5692,11 +5902,11 @@ var ts; } function parseNonArrayType() { switch (token) { + case 111: + case 120: + case 118: case 112: case 121: - case 119: - case 113: - case 122: var node = tryParse(parseKeywordAndNoDot); return node || parseTypeReference(); case 98: @@ -5715,11 +5925,11 @@ var ts; } function isStartOfType() { switch (token) { + case 111: + case 120: + case 118: case 112: case 121: - case 119: - case 113: - case 122: case 98: case 96: case 14: @@ -5840,7 +6050,7 @@ var ts; case 39: case 24: case 64: - case 111: + case 110: return true; default: if (isBinaryOperator()) { @@ -5887,7 +6097,7 @@ var ts; return parseConditionalExpressionRest(expr); } function isYieldExpression() { - if (token === 111) { + if (token === 110) { if (inYieldContext()) { return true; } @@ -5933,7 +6143,9 @@ var ts; if (triState === 0) { return undefined; } - var arrowFunction = triState === 1 ? parseParenthesizedArrowFunctionExpressionHead(true) : tryParse(parsePossibleParenthesizedArrowFunctionExpressionHead); + var arrowFunction = triState === 1 + ? parseParenthesizedArrowFunctionExpressionHead(true) + : tryParse(parsePossibleParenthesizedArrowFunctionExpressionHead); if (!arrowFunction) { return undefined; } @@ -6012,13 +6224,15 @@ var ts; return parseAssignmentExpressionOrHigher(); } function parseConditionalExpressionRest(leftOperand) { - if (!parseOptional(50)) { + var questionToken = parseOptionalToken(50); + if (!questionToken) { return leftOperand; } var node = createNode(168, leftOperand.pos); node.condition = leftOperand; + node.questionToken = questionToken; node.whenTrue = allowInAnd(parseAssignmentExpressionOrHigher); - parseExpected(51); + node.colonToken = parseExpectedToken(51, false, ts.Diagnostics._0_expected, ts.tokenToString(51)); node.whenFalse = parseAssignmentExpressionOrHigher(); return finishNode(node); } @@ -6153,7 +6367,9 @@ var ts; return expression; } function parseLeftHandSideExpressionOrHigher() { - var expression = token === 90 ? parseSuperExpression() : parseMemberExpressionOrHigher(); + var expression = token === 90 + ? parseSuperExpression() + : parseMemberExpressionOrHigher(); return parseCallExpressionRest(expression); } function parseMemberExpressionOrHigher() { @@ -6167,7 +6383,7 @@ var ts; } var node = createNode(153, expression.pos); node.expression = expression; - parseExpected(20, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); + node.dotToken = parseExpectedToken(20, false, ts.Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); node.name = parseRightSideOfDot(true); return finishNode(node); } @@ -6181,10 +6397,11 @@ var ts; } function parseMemberExpressionRest(expression) { while (true) { - var dotOrBracketStart = scanner.getTokenPos(); - if (parseOptional(20)) { + var dotToken = parseOptionalToken(20); + if (dotToken) { var propertyAccess = createNode(153, expression.pos); propertyAccess.expression = expression; + propertyAccess.dotToken = dotToken; propertyAccess.name = parseRightSideOfDot(true); expression = finishNode(propertyAccess); continue; @@ -6206,7 +6423,9 @@ var ts; if (token === 10 || token === 11) { var tagExpression = createNode(157, expression.pos); tagExpression.tag = expression; - tagExpression.template = token === 10 ? parseLiteralNode() : parseTemplateExpression(); + tagExpression.template = token === 10 + ? parseLiteralNode() + : parseTemplateExpression(); expression = finishNode(tagExpression); continue; } @@ -6252,7 +6471,9 @@ var ts; if (!parseExpected(25)) { return undefined; } - return typeArguments && canFollowTypeArgumentsInExpression() ? typeArguments : undefined; + return typeArguments && canFollowTypeArgumentsInExpression() + ? typeArguments + : undefined; } function canFollowTypeArgumentsInExpression() { switch (token) { @@ -6327,7 +6548,9 @@ var ts; return finishNode(node); } function parseArgumentOrArrayLiteralElement() { - return token === 21 ? parseSpreadElement() : token === 23 ? createNode(172) : parseAssignmentExpressionOrHigher(); + return token === 21 ? parseSpreadElement() : + token === 23 ? createNode(172) : + parseAssignmentExpressionOrHigher(); } function parseArgumentExpression() { return allowInAnd(parseArgumentOrArrayLiteralElement); @@ -6336,16 +6559,16 @@ var ts; var node = createNode(151); parseExpected(18); if (scanner.hasPrecedingLineBreak()) - node.flags |= 256; + node.flags |= 512; node.elements = parseDelimitedList(14, parseArgumentOrArrayLiteralElement); parseExpected(19); return finishNode(node); } function tryParseAccessorDeclaration(fullStart, modifiers) { - if (parseContextualModifier(116)) { + if (parseContextualModifier(115)) { return parseAccessorDeclaration(134, fullStart, modifiers); } - else if (parseContextualModifier(120)) { + else if (parseContextualModifier(119)) { return parseAccessorDeclaration(135, fullStart, modifiers); } return undefined; @@ -6384,7 +6607,7 @@ var ts; var node = createNode(152); parseExpected(14); if (scanner.hasPrecedingLineBreak()) { - node.flags |= 256; + node.flags |= 512; } node.properties = parseDelimitedList(13, parseObjectLiteralElement, true); parseExpected(15); @@ -6471,7 +6694,7 @@ var ts; parseExpected(16); var initializer = undefined; if (token !== 22) { - if (token === 97 || token === 105 || token === 69) { + if (token === 97 || token === 104 || token === 69) { initializer = parseVariableDeclarationList(true); } else { @@ -6587,9 +6810,9 @@ var ts; function parseCatchClause() { var result = createNode(216); parseExpected(67); - parseExpected(16); - result.name = parseIdentifier(); - result.type = parseTypeAnnotation(); + if (parseExpected(16)) { + result.variableDeclaration = parseVariableDeclaration(); + } parseExpected(17); result.block = parseBlock(false, false); return finishNode(result); @@ -6628,7 +6851,7 @@ var ts; return !inErrorRecovery; case 14: case 97: - case 105: + case 104: case 82: case 83: case 74: @@ -6648,18 +6871,18 @@ var ts; case 69: var isConstEnum = lookAhead(nextTokenIsEnumKeyword); return !isConstEnum; - case 104: + case 103: case 68: - case 117: + case 116: case 76: - case 123: + case 122: if (isDeclarationStart()) { return false; } - case 109: - case 107: case 108: - case 110: + case 106: + case 107: + case 109: if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { return false; } @@ -6712,7 +6935,7 @@ var ts; return parseTryStatement(); case 71: return parseDebuggerStatement(); - case 105: + case 104: if (isLetDeclaration()) { return parseVariableStatement(scanner.getStartPos(), undefined); } @@ -6736,7 +6959,7 @@ var ts; return undefined; } return parseVariableStatement(start, modifiers); - case 105: + case 104: if (!isLetDeclaration()) { return undefined; } @@ -6819,11 +7042,11 @@ var ts; switch (token) { case 97: break; - case 105: - node.flags |= 2048; + case 104: + node.flags |= 4096; break; case 69: - node.flags |= 4096; + node.flags |= 8192; break; default: ts.Debug.fail(); @@ -6855,7 +7078,7 @@ var ts; setModifiers(node, modifiers); parseExpected(82); node.asteriskToken = parseOptionalToken(35); - node.name = parseIdentifier(); + node.name = node.flags & 256 ? parseOptionalIdentifier() : parseIdentifier(); fillSignature(51, !!node.asteriskToken, false, node); node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, ts.Diagnostics.or_expected); return finishNode(node); @@ -6863,7 +7086,7 @@ var ts; function parseConstructorDeclaration(pos, modifiers) { var node = createNode(133, pos); setModifiers(node, modifiers); - parseExpected(114); + parseExpected(113); fillSignature(51, false, false, node); node.body = parseFunctionBlockOrSemicolon(false, ts.Diagnostics.or_expected); return finishNode(node); @@ -6924,7 +7147,7 @@ var ts; return true; } if (idToken !== undefined) { - if (!ts.isKeyword(idToken) || idToken === 120 || idToken === 116) { + if (!ts.isKeyword(idToken) || idToken === 119 || idToken === 115) { return true; } switch (token) { @@ -6969,7 +7192,7 @@ var ts; if (accessor) { return accessor; } - if (token === 114) { + if (token === 113) { return parseConstructorDeclaration(fullStart, modifiers); } if (isIndexSignature()) { @@ -6988,11 +7211,13 @@ var ts; var node = createNode(196, fullStart); setModifiers(node, modifiers); parseExpected(68); - node.name = parseIdentifier(); + node.name = node.flags & 256 ? parseOptionalIdentifier() : parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(true); if (parseExpected(14)) { - node.members = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseClassMembers) : parseClassMembers(); + node.members = inGeneratorParameterContext() + ? doOutsideOfYieldContext(parseClassMembers) + : parseClassMembers(); parseExpected(15); } else { @@ -7002,7 +7227,9 @@ var ts; } function parseHeritageClauses(isClassHeritageClause) { if (isHeritageClause()) { - return isClassHeritageClause && inGeneratorParameterContext() ? doOutsideOfYieldContext(parseHeritageClausesWorker) : parseHeritageClausesWorker(); + return isClassHeritageClause && inGeneratorParameterContext() + ? doOutsideOfYieldContext(parseHeritageClausesWorker) + : parseHeritageClausesWorker(); } return undefined; } @@ -7010,7 +7237,7 @@ var ts; return parseList(19, false, parseHeritageClause); } function parseHeritageClause() { - if (token === 78 || token === 103) { + if (token === 78 || token === 102) { var node = createNode(215); node.token = token; nextToken(); @@ -7020,7 +7247,7 @@ var ts; return undefined; } function isHeritageClause() { - return token === 78 || token === 103; + return token === 78 || token === 102; } function parseClassMembers() { return parseList(6, false, parseClassElement); @@ -7028,7 +7255,7 @@ var ts; function parseInterfaceDeclaration(fullStart, modifiers) { var node = createNode(197, fullStart); setModifiers(node, modifiers); - parseExpected(104); + parseExpected(103); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); node.heritageClauses = parseHeritageClauses(false); @@ -7038,7 +7265,7 @@ var ts; function parseTypeAliasDeclaration(fullStart, modifiers) { var node = createNode(198, fullStart); setModifiers(node, modifiers); - parseExpected(123); + parseExpected(122); node.name = parseIdentifier(); parseExpected(52); node.type = parseType(); @@ -7081,7 +7308,9 @@ var ts; setModifiers(node, modifiers); node.flags |= flags; node.name = parseIdentifier(); - node.body = parseOptional(20) ? parseInternalModuleTail(getNodePos(), undefined, 1) : parseModuleBlock(); + node.body = parseOptional(20) + ? parseInternalModuleTail(getNodePos(), undefined, 1) + : parseModuleBlock(); return finishNode(node); } function parseAmbientExternalModuleDeclaration(fullStart, modifiers) { @@ -7092,11 +7321,13 @@ var ts; return finishNode(node); } function parseModuleDeclaration(fullStart, modifiers) { - parseExpected(117); - return token === 8 ? parseAmbientExternalModuleDeclaration(fullStart, modifiers) : parseInternalModuleTail(fullStart, modifiers, modifiers ? modifiers.flags : 0); + parseExpected(116); + return token === 8 + ? parseAmbientExternalModuleDeclaration(fullStart, modifiers) + : parseInternalModuleTail(fullStart, modifiers, modifiers ? modifiers.flags : 0); } function isExternalModuleReference() { - return token === 118 && + return token === 117 && lookAhead(nextTokenIsOpenParen); } function nextTokenIsOpenParen() { @@ -7105,7 +7336,7 @@ var ts; function nextTokenIsCommaOrFromKeyword() { nextToken(); return token === 23 || - token === 102; + token === 123; } function parseImportDeclarationOrImportEqualsDeclaration(fullStart, modifiers) { parseExpected(84); @@ -7113,7 +7344,7 @@ var ts; var identifier; if (isIdentifier()) { identifier = parseIdentifier(); - if (token !== 23 && token !== 102) { + if (token !== 23 && token !== 123) { var importEqualsDeclaration = createNode(202, fullStart); setModifiers(importEqualsDeclaration, modifiers); importEqualsDeclaration.name = identifier; @@ -7129,7 +7360,7 @@ var ts; token === 35 || token === 14) { importDeclaration.importClause = parseImportClause(identifier, afterImportPos); - parseExpected(102); + parseExpected(123); } importDeclaration.moduleSpecifier = parseModuleSpecifier(); parseSemicolon(); @@ -7147,11 +7378,13 @@ var ts; return finishNode(importClause); } function parseModuleReference() { - return isExternalModuleReference() ? parseExternalModuleReference() : parseEntityName(false); + return isExternalModuleReference() + ? parseExternalModuleReference() + : parseEntityName(false); } function parseExternalModuleReference() { var node = createNode(212); - parseExpected(118); + parseExpected(117); parseExpected(16); node.expression = parseModuleSpecifier(); parseExpected(17); @@ -7209,22 +7442,28 @@ var ts; var node = createNode(209, fullStart); setModifiers(node, modifiers); if (parseOptional(35)) { - parseExpected(102); + parseExpected(123); node.moduleSpecifier = parseModuleSpecifier(); } else { node.exportClause = parseNamedImportsOrExports(210); - if (parseOptional(102)) { + if (parseOptional(123)) { node.moduleSpecifier = parseModuleSpecifier(); } } parseSemicolon(); return finishNode(node); } - function parseExportAssignmentTail(fullStart, modifiers) { + function parseExportAssignment(fullStart, modifiers) { var node = createNode(208, fullStart); setModifiers(node, modifiers); - node.exportName = parseIdentifier(); + if (parseOptional(52)) { + node.isExportEquals = true; + } + else { + parseExpected(72); + } + node.expression = parseAssignmentExpressionOrHigher(); parseSemicolon(); return finishNode(node); } @@ -7237,24 +7476,24 @@ var ts; case 69: case 82: return true; - case 105: + case 104: return isLetDeclaration(); case 68: - case 104: + case 103: case 76: - case 123: + case 122: return lookAhead(nextTokenIsIdentifierOrKeyword); case 84: return lookAhead(nextTokenCanFollowImportKeyword); - case 117: + case 116: return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); case 77: return lookAhead(nextTokenCanFollowExportKeyword); - case 115: - case 109: - case 107: + case 114: case 108: - case 110: + case 106: + case 107: + case 109: return lookAhead(nextTokenIsDeclarationStart); } } @@ -7277,7 +7516,7 @@ var ts; function nextTokenCanFollowExportKeyword() { nextToken(); return token === 52 || token === 35 || - token === 14 || isDeclarationStart(); + token === 14 || token === 72 || isDeclarationStart(); } function nextTokenIsDeclarationStart() { nextToken(); @@ -7291,8 +7530,8 @@ var ts; var modifiers = parseModifiers(); if (token === 77) { nextToken(); - if (parseOptional(52)) { - return parseExportAssignmentTail(fullStart, modifiers); + if (token === 72 || token === 52) { + return parseExportAssignment(fullStart, modifiers); } if (token === 35 || token === 14) { return parseExportDeclaration(fullStart, modifiers); @@ -7300,20 +7539,20 @@ var ts; } switch (token) { case 97: - case 105: + case 104: case 69: return parseVariableStatement(fullStart, modifiers); case 82: return parseFunctionDeclaration(fullStart, modifiers); case 68: return parseClassDeclaration(fullStart, modifiers); - case 104: + case 103: return parseInterfaceDeclaration(fullStart, modifiers); - case 123: + case 122: return parseTypeAliasDeclaration(fullStart, modifiers); case 76: return parseEnumDeclaration(fullStart, modifiers); - case 117: + case 116: return parseModuleDeclaration(fullStart, modifiers); case 84: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, modifiers); @@ -7331,7 +7570,9 @@ var ts; return parseSourceElementOrModuleElement(); } function parseSourceElementOrModuleElement() { - return isDeclarationStart() ? parseDeclaration() : parseStatement(); + return isDeclarationStart() + ? parseDeclaration() + : parseStatement(); } function processReferenceComments(sourceFile) { var triviaScanner = ts.createScanner(sourceFile.languageVersion, false, sourceText); @@ -7389,7 +7630,13 @@ var ts; } function setExternalModuleIndicator(sourceFile) { sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { - return node.flags & 1 || node.kind === 202 && node.moduleReference.kind === 212 || node.kind === 203 || node.kind === 208 || node.kind === 209 ? node : undefined; + return node.flags & 1 + || node.kind === 202 && node.moduleReference.kind === 212 + || node.kind === 203 + || node.kind === 208 + || node.kind === 209 + ? node + : undefined; }); } } @@ -7485,7 +7732,8 @@ var ts; var Symbol = ts.objectAllocator.getSymbolConstructor(); if (!file.locals) { file.locals = {}; - container = blockScopeContainer = file; + container = file; + setBlockScopeContainer(file, false); bind(file); file.symbolCount = symbolCount; } @@ -7493,6 +7741,12 @@ var ts; symbolCount++; return new Symbol(flags, name); } + function setBlockScopeContainer(node, cleanLocals) { + blockScopeContainer = node; + if (cleanLocals) { + blockScopeContainer.locals = undefined; + } + } function addDeclarationToSymbol(symbol, node, symbolKind) { symbol.flags |= symbolKind; if (!symbol.declarations) @@ -7529,6 +7783,13 @@ var ts; return "__new"; case 138: return "__index"; + case 209: + return "__export"; + case 208: + return "default"; + case 195: + case 196: + return node.flags & 256 ? "default" : undefined; } } function getDisplayName(node) { @@ -7536,18 +7797,20 @@ var ts; } function declareSymbol(symbols, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); - var name = getDeclarationName(node); + var name = node.flags & 256 && parent ? "default" : getDeclarationName(node); if (name !== undefined) { var symbol = ts.hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); if (symbol.flags & excludes) { if (node.name) { node.name.parent = node; } - var message = symbol.flags & 2 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + var message = symbol.flags & 2 + ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 + : ts.Diagnostics.Duplicate_identifier_0; ts.forEach(symbol.declarations, function (declaration) { - file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name, message, getDisplayName(declaration))); + file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); }); - file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name, message, getDisplayName(node))); + file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message, getDisplayName(node))); symbol = createSymbol(0, name); } } @@ -7617,7 +7880,7 @@ var ts; lastContainer = container; } if (isBlockScopeContainer) { - blockScopeContainer = node; + setBlockScopeContainer(node, (symbolKind & 255504) === 0 && node.kind !== 220); } ts.forEachChild(node, bind); container = saveContainer; @@ -7685,12 +7948,6 @@ var ts; } } } - function bindExportDeclaration(node) { - if (!node.exportClause) { - (container.exportStars || (container.exportStars = [])).push(node); - } - bindChildren(node, 0, false); - } function bindFunctionOrConstructorType(node) { var symbol = createSymbol(131072, getDeclarationName(node)); addDeclarationToSymbol(symbol, node, 131072); @@ -7706,14 +7963,7 @@ var ts; bindChildren(node, symbolKind, isBlockScopeContainer); } function bindCatchVariableDeclaration(node) { - var symbol = createSymbol(1, node.name.text || "__missing"); - addDeclarationToSymbol(symbol, node, 1); - var saveParent = parent; - var savedBlockScopeContainer = blockScopeContainer; - parent = blockScopeContainer = node; - ts.forEachChild(node, bind); - parent = saveParent; - blockScopeContainer = savedBlockScopeContainer; + bindChildren(node, 0, true); } function bindBlockScopedVariableDeclaration(node) { switch (blockScopeContainer.kind) { @@ -7750,7 +8000,7 @@ var ts; if (ts.isBindingPattern(node.name)) { bindChildren(node, 0, false); } - else if (ts.getCombinedNodeFlags(node) & 6144) { + else if (ts.isBlockOrCatchScoped(node)) { bindBlockScopedVariableDeclaration(node); } else { @@ -7832,9 +8082,6 @@ var ts; case 211: bindDeclaration(node, 8388608, 8388608, false); break; - case 209: - bindExportDeclaration(node); - break; case 204: if (node.name) { bindDeclaration(node, 8388608, 8388608, false); @@ -7843,13 +8090,28 @@ var ts; bindChildren(node, 0, false); } break; + case 209: + if (!node.exportClause) { + declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0); + } + bindChildren(node, 0, false); + break; + case 208: + if (node.expression.kind === 64) { + declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 8388608); + } + else { + declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455); + } + bindChildren(node, 0, false); + break; case 220: if (ts.isExternalModule(node)) { bindAnonymousDeclaration(node, 512, '"' + ts.removeFileExtension(node.fileName) + '"', true); break; } case 174: - bindChildren(node, 0, !ts.isAnyFunction(node.parent)); + bindChildren(node, 0, !ts.isFunctionLike(node.parent)); break; case 216: case 181: @@ -7937,8 +8199,9 @@ var ts; isValidPropertyAccess: isValidPropertyAccess, getSignatureFromDeclaration: getSignatureFromDeclaration, isImplementationOfOverload: isImplementationOfOverload, - getAliasedSymbol: resolveImport, - getEmitResolver: getEmitResolver + getAliasedSymbol: resolveAlias, + getEmitResolver: getEmitResolver, + getExportsOfExternalModule: getExportsOfExternalModule }; var undefinedSymbol = createSymbol(4 | 67108864, "undefined"); var argumentsSymbol = createSymbol(4 | 67108864, "arguments"); @@ -7972,6 +8235,7 @@ var ts; var globalRegExpType; var globalTemplateStringsArrayType; var globalESSymbolType; + var globalIterableType; var anyArrayType; var tupleTypes = {}; var unionTypes = {}; @@ -8005,7 +8269,9 @@ var ts; return emitResolver; } function error(location, message, arg0, arg1, arg2) { - var diagnostic = location ? ts.createDiagnosticForNode(location, message, arg0, arg1, arg2) : ts.createCompilerDiagnostic(message, arg0, arg1, arg2); + var diagnostic = location + ? ts.createDiagnosticForNode(location, message, arg0, arg1, arg2) + : ts.createCompilerDiagnostic(message, arg0, arg1, arg2); diagnostics.add(diagnostic); } function createSymbol(flags, name) { @@ -8091,7 +8357,8 @@ var ts; recordMergedSymbol(target, source); } else { - var message = target.flags & 2 || source.flags & 2 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + var message = target.flags & 2 || source.flags & 2 + ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; ts.forEach(source.declarations, function (node) { error(node.name ? node.name : node, message, symbolToString(source)); }); @@ -8125,13 +8392,6 @@ var ts; } } } - function extendSymbolTable(target, source) { - for (var id in source) { - if (!ts.hasProperty(target, id)) { - target[id] = source[id]; - } - } - } function getSymbolLinks(symbol) { if (symbol.flags & 67108864) return symbol; @@ -8158,7 +8418,7 @@ var ts; return symbol; } if (symbol.flags & 8388608) { - var target = resolveImport(symbol); + var target = resolveAlias(symbol); if (target === unknownSymbol || target.flags & meaning) { return symbol; } @@ -8194,7 +8454,7 @@ var ts; break; case 200: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8914931)) { - if (!(result.flags & 8388608 && getDeclarationOfImportSymbol(result).kind === 211)) { + if (!(result.flags & 8388608 && getDeclarationOfAliasSymbol(result).kind === 211)) { break loop; } result = undefined; @@ -8258,13 +8518,6 @@ var ts; break loop; } break; - case 216: - var id = location.name; - if (name === id.text) { - result = location.symbol; - break loop; - } - break; } lastLocation = location; location = location.parent; @@ -8285,7 +8538,7 @@ var ts; return undefined; } if (result.flags & 2) { - var declaration = ts.forEach(result.declarations, function (d) { return ts.getCombinedNodeFlags(d) & 6144 ? d : undefined; }); + var declaration = ts.forEach(result.declarations, function (d) { return ts.isBlockOrCatchScoped(d) ? d : undefined; }); ts.Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); if (!isDefinedBefore(declaration, errorLocation)) { error(errorLocation, ts.Diagnostics.Block_scoped_variable_0_used_before_its_declaration, ts.declarationNameToString(declaration.name)); @@ -8294,15 +8547,16 @@ var ts; } return result; } - function isImportSymbolDeclaration(node) { + function isAliasSymbolDeclaration(node) { return node.kind === 202 || node.kind === 204 && !!node.name || node.kind === 205 || node.kind === 207 || - node.kind === 211; + node.kind === 211 || + node.kind === 208; } - function getDeclarationOfImportSymbol(symbol) { - return ts.forEach(symbol.declarations, function (d) { return isImportSymbolDeclaration(d) ? d : undefined; }); + function getDeclarationOfAliasSymbol(symbol) { + return ts.forEach(symbol.declarations, function (d) { return isAliasSymbolDeclaration(d) ? d : undefined; }); } function getTargetOfImportEqualsDeclaration(node) { if (node.moduleReference.kind === 212) { @@ -8335,7 +8589,7 @@ var ts; error(name, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name)); return; } - return symbol.flags & (107455 | 793056 | 1536) ? symbol : resolveImport(symbol); + return symbol.flags & (107455 | 793056 | 1536) ? symbol : resolveAlias(symbol); } } } @@ -8343,7 +8597,12 @@ var ts; return getExternalModuleMember(node.parent.parent.parent, node); } function getTargetOfExportSpecifier(node) { - return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : resolveEntityName(node, node.propertyName || node.name, 107455 | 793056 | 1536); + return node.parent.parent.moduleSpecifier ? + getExternalModuleMember(node.parent.parent, node) : + resolveEntityName(node.propertyName || node.name, 107455 | 793056 | 1536); + } + function getTargetOfExportAssignment(node) { + return resolveEntityName(node.expression, 107455 | 793056 | 1536); } function getTargetOfImportDeclaration(node) { switch (node.kind) { @@ -8357,14 +8616,16 @@ var ts; return getTargetOfImportSpecifier(node); case 211: return getTargetOfExportSpecifier(node); + case 208: + return getTargetOfExportAssignment(node); } } - function resolveImport(symbol) { - ts.Debug.assert((symbol.flags & 8388608) !== 0, "Should only get Imports here."); + function resolveAlias(symbol) { + ts.Debug.assert((symbol.flags & 8388608) !== 0, "Should only get Alias here."); var links = getSymbolLinks(symbol); if (!links.target) { links.target = resolvingSymbol; - var node = getDeclarationOfImportSymbol(symbol); + var node = getDeclarationOfAliasSymbol(symbol); var target = getTargetOfImportDeclaration(node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; @@ -8378,6 +8639,29 @@ var ts; } return links.target; } + function markExportAsReferenced(node) { + var symbol = getSymbolOfNode(node); + var target = resolveAlias(symbol); + if (target && target !== unknownSymbol && target.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(target)) { + markAliasSymbolAsReferenced(symbol); + } + } + function markAliasSymbolAsReferenced(symbol) { + var links = getSymbolLinks(symbol); + if (!links.referenced) { + links.referenced = true; + var node = getDeclarationOfAliasSymbol(symbol); + if (node.kind === 208) { + checkExpressionCached(node.expression); + } + else if (node.kind === 211) { + checkExpressionCached(node.propertyName || node.name); + } + else if (ts.isInternalModuleImportEqualsDeclaration(node)) { + checkExpressionCached(node.moduleReference); + } + } + } function getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importDeclaration) { if (!importDeclaration) { importDeclaration = ts.getAncestor(entityName, 202); @@ -8387,38 +8671,40 @@ var ts; entityName = entityName.parent; } if (entityName.kind === 64 || entityName.parent.kind === 125) { - return resolveEntityName(importDeclaration, entityName, 1536); + return resolveEntityName(entityName, 1536); } else { ts.Debug.assert(entityName.parent.kind === 202); - return resolveEntityName(importDeclaration, entityName, 107455 | 793056 | 1536); + return resolveEntityName(entityName, 107455 | 793056 | 1536); } } function getFullyQualifiedName(symbol) { return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol); } - function resolveEntityName(location, name, meaning) { + function resolveEntityName(name, meaning) { if (ts.getFullWidth(name) === 0) { return undefined; } if (name.kind === 64) { - var symbol = resolveName(location, name.text, meaning, ts.Diagnostics.Cannot_find_name_0, name); + var symbol = resolveName(name, name.text, meaning, ts.Diagnostics.Cannot_find_name_0, name); if (!symbol) { - return; + return undefined; } } else if (name.kind === 125) { - var namespace = resolveEntityName(location, name.left, 1536); - if (!namespace || namespace === unknownSymbol || ts.getFullWidth(name.right) === 0) - return; - var symbol = getSymbol(getExportsOfSymbol(namespace), name.right.text, meaning); + var namespace = resolveEntityName(name.left, 1536); + if (!namespace || namespace === unknownSymbol || ts.getFullWidth(name.right) === 0) { + return undefined; + } + var right = name.right; + var symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { - error(location, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(name.right)); - return; + error(right, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), ts.declarationNameToString(right)); + return undefined; } } ts.Debug.assert((symbol.flags & 16777216) === 0, "Should never get an instantiated symbol here."); - return symbol.flags & meaning ? symbol : resolveImport(symbol); + return symbol.flags & meaning ? symbol : resolveAlias(symbol); } function isExternalModuleNameRelative(moduleName) { return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; @@ -8458,6 +8744,9 @@ var ts; } error(moduleReferenceLiteral, ts.Diagnostics.Cannot_find_external_module_0, moduleName); } + function getExportAssignmentSymbol(moduleSymbol) { + return moduleSymbol.exports["default"]; + } function getResolvedExportAssignmentSymbol(moduleSymbol) { var symbol = getExportAssignmentSymbol(moduleSymbol); if (symbol) { @@ -8465,82 +8754,52 @@ var ts; return symbol; } if (symbol.flags & 8388608) { - return resolveImport(symbol); + return resolveAlias(symbol); } } } - function getExportAssignmentSymbol(symbol) { - checkTypeOfExportAssignmentSymbol(symbol); - return getSymbolLinks(symbol).exportAssignmentSymbol; - } - function checkTypeOfExportAssignmentSymbol(containerSymbol) { - var symbolLinks = getSymbolLinks(containerSymbol); - if (!symbolLinks.exportAssignmentChecked) { - var exportInformation = collectExportInformationForSourceFileOrModule(containerSymbol); - if (exportInformation.exportAssignments.length) { - if (exportInformation.exportAssignments.length > 1) { - ts.forEach(exportInformation.exportAssignments, function (node) { return error(node, ts.Diagnostics.A_module_cannot_have_more_than_one_export_assignment); }); - } - var node = exportInformation.exportAssignments[0]; - if (exportInformation.hasExportedMember) { - error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); - } - if (node.exportName.text) { - var meaning = 107455 | 793056 | 1536; - var exportSymbol = resolveName(node, node.exportName.text, meaning, ts.Diagnostics.Cannot_find_name_0, node.exportName); - } - symbolLinks.exportAssignmentSymbol = exportSymbol || unknownSymbol; - } - symbolLinks.exportAssignmentChecked = true; - } - } - function collectExportInformationForSourceFileOrModule(symbol) { - var seenExportedMember = false; - var result = []; - ts.forEach(symbol.declarations, function (declaration) { - var block = (declaration.kind === 220 ? declaration : declaration.body); - ts.forEach(block.statements, function (node) { - if (node.kind === 208) { - result.push(node); - } - else { - seenExportedMember = seenExportedMember || (node.flags & 1) !== 0; - } - }); - }); - return { - hasExportedMember: seenExportedMember, - exportAssignments: result - }; - } function getExportsOfSymbol(symbol) { return symbol.flags & 1536 ? getExportsOfModule(symbol) : symbol.exports; } - function getExportsOfModule(symbol) { - var links = getSymbolLinks(symbol); - return links.resolvedExports || (links.resolvedExports = getExportsForModule(symbol)); + function getExportsOfModule(moduleSymbol) { + var links = getSymbolLinks(moduleSymbol); + return links.resolvedExports || (links.resolvedExports = getExportsForModule(moduleSymbol)); } - function getExportsForModule(symbol) { + function extendExportSymbols(target, source) { + for (var id in source) { + if (id !== "default" && !ts.hasProperty(target, id)) { + target[id] = source[id]; + } + } + } + function getExportsForModule(moduleSymbol) { + if (compilerOptions.target < 2) { + var defaultSymbol = getExportAssignmentSymbol(moduleSymbol); + if (defaultSymbol) { + return { + "default": defaultSymbol + }; + } + } var result; var visitedSymbols = []; - visit(symbol); - return result; + visit(moduleSymbol); + return result || moduleSymbol.exports; function visit(symbol) { if (!ts.contains(visitedSymbols, symbol)) { visitedSymbols.push(symbol); - if (!result) { - result = symbol.exports; - } - else { - extendSymbolTable(result, symbol.exports); - } - ts.forEach(symbol.declarations, function (node) { - if (node.kind === 220 || node.kind === 200) { - ts.forEach(node.exportStars, function (exportStar) { - visit(resolveExternalModuleName(exportStar, exportStar.moduleSpecifier)); - }); + if (symbol !== moduleSymbol) { + if (!result) { + result = cloneSymbolTable(moduleSymbol.exports); } - }); + extendExportSymbols(result, symbol.exports); + } + var exportStars = symbol.exports["__export"]; + if (exportStars) { + ts.forEach(exportStars.declarations, function (node) { + visit(resolveExternalModuleName(node, node.moduleSpecifier)); + }); + } } } } @@ -8555,7 +8814,9 @@ var ts; return getMergedSymbol(symbol.parent); } function getExportSymbolOfValueSymbolIfExported(symbol) { - return symbol && (symbol.flags & 1048576) !== 0 ? getMergedSymbol(symbol.exportSymbol) : symbol; + return symbol && (symbol.flags & 1048576) !== 0 + ? getMergedSymbol(symbol.exportSymbol) + : symbol; } function symbolIsValue(symbol) { if (symbol.flags & 16777216) { @@ -8565,7 +8826,7 @@ var ts; return true; } if (symbol.flags & 8388608) { - return (resolveImport(symbol).flags & 107455) !== 0; + return (resolveAlias(symbol).flags & 107455) !== 0; } return false; } @@ -8682,8 +8943,8 @@ var ts; if (symbolFromSymbolTable.flags & 8388608) { if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, ts.isExternalModuleImportEqualsDeclaration)) { - var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); - if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { + var resolvedImportedSymbol = resolveAlias(symbolFromSymbolTable); + if (isAccessible(symbolFromSymbolTable, resolveAlias(symbolFromSymbolTable))) { return [symbolFromSymbolTable]; } var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; @@ -8708,7 +8969,7 @@ var ts; if (symbolFromSymbolTable === symbol) { return true; } - symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608) ? resolveImport(symbolFromSymbolTable) : symbolFromSymbolTable; + symbolFromSymbolTable = (symbolFromSymbolTable.flags & 8388608) ? resolveAlias(symbolFromSymbolTable) : symbolFromSymbolTable; if (symbolFromSymbolTable.flags & meaning) { qualify = true; return true; @@ -8999,7 +9260,7 @@ var ts; buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, 793056, 0, flags); } else { - writeKeyword(writer, 112); + writeKeyword(writer, 111); } } else { @@ -9090,7 +9351,7 @@ var ts; writer.writeParameter(getIndexerParameterName(resolved, 0, "x")); writePunctuation(writer, 51); writeSpace(writer); - writeKeyword(writer, 121); + writeKeyword(writer, 120); writePunctuation(writer, 19); writePunctuation(writer, 51); writeSpace(writer); @@ -9103,7 +9364,7 @@ var ts; writer.writeParameter(getIndexerParameterName(resolved, 1, "x")); writePunctuation(writer, 51); writeSpace(writer); - writeKeyword(writer, 119); + writeKeyword(writer, 118); writePunctuation(writer, 19); writePunctuation(writer, 51); writeSpace(writer); @@ -9268,7 +9529,7 @@ var ts; return true; } if (symbolOfNode.flags & 8388608) { - return isSymbolUsedInExportAssignment(resolveImport(symbolOfNode)); + return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode)); } } function isSymbolUsedInExportAssignment(symbol) { @@ -9276,7 +9537,7 @@ var ts; return true; } if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & 8388608)) { - resolvedExportSymbol = resolvedExportSymbol || resolveImport(exportAssignmentSymbol); + resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol); if (resolvedExportSymbol === symbol) { return true; } @@ -9410,6 +9671,9 @@ var ts; if (declaration.parent.parent.kind === 182) { return anyType; } + if (declaration.parent.parent.kind === 183) { + return getTypeForVariableDeclarationInForOfStatement(declaration.parent.parent); + } if (ts.isBindingPattern(declaration.parent)) { return getTypeForBindingElement(declaration); } @@ -9469,7 +9733,9 @@ var ts; return !elementTypes.length ? anyArrayType : hasSpreadElement ? createArrayType(getUnionType(elementTypes)) : createTupleType(elementTypes); } function getTypeFromBindingPattern(pattern) { - return pattern.kind === 148 ? getTypeFromObjectBindingPattern(pattern) : getTypeFromArrayBindingPattern(pattern); + return pattern.kind === 148 + ? getTypeFromObjectBindingPattern(pattern) + : getTypeFromArrayBindingPattern(pattern); } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { var type = getTypeForVariableLikeDeclaration(declaration); @@ -9498,9 +9764,12 @@ var ts; return links.type = getTypeOfPrototypeProperty(symbol); } var declaration = symbol.valueDeclaration; - if (declaration.kind === 216) { + if (declaration.parent.kind === 216) { return links.type = anyType; } + if (declaration.kind === 208) { + return links.type = checkExpression(declaration.expression); + } links.type = resolvingType; var type = getWidenedTypeForVariableLikeDeclaration(declaration, true); if (links.type === resolvingType) { @@ -9510,7 +9779,9 @@ var ts; else if (links.type === resolvingType) { links.type = anyType; if (compilerOptions.noImplicitAny) { - var diagnostic = symbol.valueDeclaration.type ? ts.Diagnostics._0_implicitly_has_type_any_because_it_is_referenced_directly_or_indirectly_in_its_own_type_annotation : ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer; + var diagnostic = symbol.valueDeclaration.type ? + ts.Diagnostics._0_implicitly_has_type_any_because_it_is_referenced_directly_or_indirectly_in_its_own_type_annotation : + ts.Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer; error(symbol.valueDeclaration, diagnostic, symbolToString(symbol)); } } @@ -9590,10 +9861,10 @@ var ts; } return links.type; } - function getTypeOfImport(symbol) { + function getTypeOfAlias(symbol) { var links = getSymbolLinks(symbol); if (!links.type) { - links.type = getTypeOfSymbol(resolveImport(symbol)); + links.type = getTypeOfSymbol(resolveAlias(symbol)); } return links.type; } @@ -9621,7 +9892,7 @@ var ts; return getTypeOfAccessors(symbol); } if (symbol.flags & 8388608) { - return getTypeOfImport(symbol); + return getTypeOfAlias(symbol); } return unknownType; } @@ -9775,10 +10046,10 @@ var ts; } return links.declaredType; } - function getDeclaredTypeOfImport(symbol) { + function getDeclaredTypeOfAlias(symbol) { var links = getSymbolLinks(symbol); if (!links.declaredType) { - links.declaredType = getDeclaredTypeOfSymbol(resolveImport(symbol)); + links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol)); } return links.declaredType; } @@ -9800,7 +10071,7 @@ var ts; return getDeclaredTypeOfTypeParameter(symbol); } if (symbol.flags & 8388608) { - return getDeclaredTypeOfImport(symbol); + return getDeclaredTypeOfAlias(symbol); } return unknownType; } @@ -9890,7 +10161,8 @@ var ts; var baseType = classType.baseTypes[0]; var baseSignatures = getSignaturesOfType(getTypeOfSymbol(baseType.symbol), 1); return ts.map(baseSignatures, function (baseSignature) { - var signature = baseType.flags & 4096 ? getSignatureInstantiation(baseSignature, baseType.typeArguments) : cloneSignature(baseSignature); + var signature = baseType.flags & 4096 ? + getSignatureInstantiation(baseSignature, baseType.typeArguments) : cloneSignature(baseSignature); signature.typeParameters = classType.typeParameters; signature.resolvedReturnType = classType; return signature; @@ -10171,11 +10443,22 @@ var ts; }); return result; } + function getExportsOfExternalModule(node) { + if (!node.moduleSpecifier) { + return emptyArray; + } + var module = resolveExternalModuleName(node, node.moduleSpecifier); + if (!module || !module.exports) { + return emptyArray; + } + return ts.mapToArray(getExportsOfModule(module)); + } function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { var classType = declaration.kind === 133 ? getDeclaredTypeOfClass(declaration.parent.symbol) : undefined; - var typeParameters = classType ? classType.typeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; + var typeParameters = classType ? classType.typeParameters : + declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; var hasStringLiterals = false; var minArgumentCount = -1; @@ -10316,7 +10599,7 @@ var ts; return symbol.members["__index"]; } function getIndexDeclarationOfSymbol(symbol, kind) { - var syntaxKind = kind === 1 ? 119 : 121; + var syntaxKind = kind === 1 ? 118 : 120; var indexSymbol = getIndexSymbol(symbol); if (indexSymbol) { var len = indexSymbol.declarations.length; @@ -10334,7 +10617,9 @@ var ts; } function getIndexTypeOfSymbol(symbol, kind) { var declaration = getIndexDeclarationOfSymbol(symbol, kind); - return declaration ? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType : undefined; + return declaration + ? declaration.type ? getTypeFromTypeNode(declaration.type) : anyType + : undefined; } function getConstraintOfTypeParameter(type) { if (!type.constraint) { @@ -10419,7 +10704,7 @@ var ts; function getTypeFromTypeReferenceNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { - var symbol = resolveEntityName(node, node.typeName, 793056); + var symbol = resolveEntityName(node.typeName, 793056); if (symbol) { var type; if ((symbol.flags & 262144) && isTypeParameterReferenceIllegalInConstraint(node, symbol)) { @@ -10492,8 +10777,9 @@ var ts; function getGlobalSymbol(name, meaning, diagnostic) { return resolveName(undefined, name, meaning, diagnostic, name); } - function getGlobalType(name) { - return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), 0); + function getGlobalType(name, arity) { + if (arity === void 0) { arity = 0; } + return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity); } function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); @@ -10637,15 +10923,15 @@ var ts; } function getTypeFromTypeNode(node) { switch (node.kind) { - case 112: + case 111: return anyType; - case 121: + case 120: return stringType; - case 119: + case 118: return numberType; - case 113: + case 112: return booleanType; - case 122: + case 121: return esSymbolType; case 98: return voidType; @@ -10797,7 +11083,8 @@ var ts; return mapper(type); } if (type.flags & 32768) { - return type.symbol && type.symbol.flags & (16 | 8192 | 2048 | 4096) ? instantiateAnonymousType(type, mapper) : type; + return type.symbol && type.symbol.flags & (16 | 8192 | 2048 | 4096) ? + instantiateAnonymousType(type, mapper) : type; } if (type.flags & 4096) { return createTypeReference(type.target, instantiateList(type.typeArguments, mapper, instantiateType)); @@ -10826,7 +11113,7 @@ var ts; isContextSensitive(node.whenFalse); case 167: return node.operatorToken.kind === 49 && - (isContextSensitive(node.left) || isContextSensitive(node.right)); + (isContextSensitive(node.left) || isContextSensitive(node.right)); case 217: return isContextSensitive(node.initializer); case 132: @@ -11596,7 +11883,9 @@ var ts; var diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type; break; case 128: - var diagnostic = declaration.dotDotDotToken ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Parameter_0_implicitly_has_an_1_type; + 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 195: case 132: @@ -11697,7 +11986,9 @@ var ts; for (var i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { var inferences = context.inferences[i]; - var candidates = inferiority ? inferences.secondary || (inferences.secondary = []) : inferences.primary || (inferences.primary = []); + var candidates = inferiority ? + inferences.secondary || (inferences.secondary = []) : + inferences.primary || (inferences.primary = []); if (!ts.contains(candidates, source)) candidates.push(source); break; @@ -12106,46 +12397,56 @@ var ts; return type; } } - function markLinkedImportsAsReferenced(node) { - if (node) { - var nodeLinks = getNodeLinks(node); - while (nodeLinks.importOnRightSide) { - var rightSide = nodeLinks.importOnRightSide; - nodeLinks.importOnRightSide = undefined; - getSymbolLinks(rightSide).referenced = true; - ts.Debug.assert((rightSide.flags & 8388608) !== 0); - nodeLinks = getNodeLinks(ts.getDeclarationOfKind(rightSide, 202)); - } - } - } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); if (symbol === argumentsSymbol && ts.getContainingFunction(node).kind === 161) { 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 = getLeftSideOfImportEqualsOrExportAssignment(node); - if (!importOrExportAssignment || - (importOrExportAssignment.flags & 1) || - (importOrExportAssignment.kind === 208)) { - symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); - } - else { - var nodeLinks = getNodeLinks(importOrExportAssignment); - ts.Debug.assert(!nodeLinks.importOnRightSide); - nodeLinks.importOnRightSide = symbol; - } - } - if (symbolLinks.referenced) { - markLinkedImportsAsReferenced(ts.getDeclarationOfKind(symbol, 202)); - } + if (symbol.flags & 8388608 && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { + markAliasSymbolAsReferenced(symbol); } checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); + checkBlockScopedBindingCapturedInLoop(node, symbol); return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } + function isInsideFunction(node, threshold) { + var current = node; + while (current && current !== threshold) { + if (ts.isFunctionLike(current)) { + return true; + } + current = current.parent; + } + return false; + } + function checkBlockScopedBindingCapturedInLoop(node, symbol) { + if (languageVersion >= 2 || + (symbol.flags & 2) === 0 || + symbol.valueDeclaration.parent.kind === 216) { + return; + } + var container = symbol.valueDeclaration; + while (container.kind !== 194) { + container = container.parent; + } + container = container.parent; + if (container.kind === 175) { + container = container.parent; + } + var inFunction = isInsideFunction(node.parent, container); + var current = container; + while (current && !ts.nodeStartsNewLexicalEnvironment(current)) { + if (isIterationStatement(current, false)) { + if (inFunction) { + grammarErrorOnFirstToken(current, ts.Diagnostics.Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher, ts.declarationNameToString(node)); + } + getNodeLinks(symbol.valueDeclaration).flags |= 256; + break; + } + current = current.parent; + } + } function captureLexicalThis(node, container) { var classNode = container.parent && container.parent.kind === 196 ? container.parent : undefined; getNodeLinks(node).flags |= 2; @@ -12231,19 +12532,19 @@ var ts; if (container.flags & 128) { canUseSuperExpression = container.kind === 132 || - container.kind === 131 || - container.kind === 134 || - container.kind === 135; + container.kind === 131 || + container.kind === 134 || + container.kind === 135; } else { canUseSuperExpression = container.kind === 132 || - container.kind === 131 || - container.kind === 134 || - container.kind === 135 || - container.kind === 130 || - container.kind === 129 || - container.kind === 133; + container.kind === 131 || + container.kind === 134 || + container.kind === 135 || + container.kind === 130 || + container.kind === 129 || + container.kind === 133; } } } @@ -12428,7 +12729,9 @@ var ts; var type = getContextualType(arrayLiteral); if (type) { var index = ts.indexOf(arrayLiteral.elements, node); - return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1); + return getTypeOfPropertyOfContextualType(type, "" + index) + || getIndexTypeOfContextualType(type, 1) + || (languageVersion >= 2 ? checkIteratedType(type, undefined) : undefined); } return undefined; } @@ -12492,7 +12795,9 @@ var ts; } function getContextualSignature(node) { ts.Debug.assert(node.kind !== 132 || ts.isObjectLiteralMethod(node)); - var type = ts.isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getContextualType(node); + var type = ts.isObjectLiteralMethod(node) + ? getContextualTypeForObjectLiteralMethod(node) + : getContextualType(node); if (!type) { return undefined; } @@ -12618,7 +12923,9 @@ var ts; } else { ts.Debug.assert(memberDecl.kind === 218); - var type = memberDecl.name.kind === 126 ? unknownType : checkExpression(memberDecl.name, contextualMapper); + var type = memberDecl.name.kind === 126 + ? unknownType + : checkExpression(memberDecl.name, contextualMapper); } typeFlags |= type.flags; var prop = createSymbol(4 | 67108864 | member.flags, member.name); @@ -12734,7 +13041,9 @@ var ts; return anyType; } function isValidPropertyAccess(node, propertyName) { - var left = node.kind === 153 ? node.expression : node.left; + var left = node.kind === 153 + ? node.expression + : node.left; var type = checkExpressionOrQualifiedName(left); if (type !== unknownType && type !== anyType) { var prop = getPropertyOfType(getWidenedType(type), propertyName); @@ -13028,7 +13337,9 @@ var ts; var arg = args[i]; if (arg.kind !== 172) { var paramType = getTypeAtPosition(signature, arg.kind === 171 ? -1 : i); - var argType = i === 0 && node.kind === 157 ? globalTemplateStringsArrayType : arg.kind === 8 && !reportErrors ? getStringLiteralType(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); + var argType = i === 0 && node.kind === 157 ? 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; } @@ -13305,9 +13616,6 @@ var ts; return getReturnTypeOfSignature(signature); } function checkTaggedTemplateExpression(node) { - if (languageVersion < 2) { - grammarErrorOnFirstToken(node.template, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); - } return getReturnTypeOfSignature(getResolvedSignature(node)); } function checkTypeAssertion(node) { @@ -13323,9 +13631,13 @@ var ts; } function getTypeAtPosition(signature, pos) { if (pos >= 0) { - return signature.hasRestParameter ? pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) : pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType; + return signature.hasRestParameter ? + pos < signature.parameters.length - 1 ? getTypeOfSymbol(signature.parameters[pos]) : getRestTypeOfSignature(signature) : + pos < signature.parameters.length ? getTypeOfSymbol(signature.parameters[pos]) : anyType; } - return signature.hasRestParameter ? getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]) : anyArrayType; + return signature.hasRestParameter ? + getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]) : + anyArrayType; } function assignContextualParameterTypes(signature, context, mapper) { var len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0); @@ -13466,7 +13778,7 @@ var ts; } return true; } - function checkReferenceExpression(n, invalidReferenceMessage, constantVarianleMessage) { + function checkReferenceExpression(n, invalidReferenceMessage, constantVariableMessage) { function findSymbol(n) { var symbol = getNodeLinks(n).resolvedSymbol; return symbol && getExportSymbolOfValueSymbolIfExported(symbol); @@ -13492,14 +13804,14 @@ var ts; case 64: case 153: var symbol = findSymbol(n); - return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 4096) !== 0; + return symbol && (symbol.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & 8192) !== 0; case 154: var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8) { var name = index.text; var prop = getPropertyOfType(getTypeOfSymbol(symbol), name); - return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 4096) !== 0; + return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192) !== 0; } return false; case 159: @@ -13513,7 +13825,7 @@ var ts; return false; } if (isConstVariableReference(n)) { - error(n, constantVarianleMessage); + error(n, constantVariableMessage); return false; } return true; @@ -13627,9 +13939,10 @@ var ts; var p = properties[i]; if (p.kind === 217 || p.kind === 218) { var name = p.name; - var type = sourceType.flags & 1 ? sourceType : getTypeOfPropertyOfType(sourceType, name.text) || - isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, 1) || - getIndexTypeOfType(sourceType, 0); + var type = sourceType.flags & 1 ? sourceType : + getTypeOfPropertyOfType(sourceType, name.text) || + isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, 1) || + getIndexTypeOfType(sourceType, 0); if (type) { checkDestructuringAssignment(p.initializer || name, type); } @@ -13654,7 +13967,9 @@ var ts; 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); + var type = sourceType.flags & 1 ? sourceType : + isTupleLikeType(sourceType) ? getTypeOfPropertyOfType(sourceType, propName) : + getIndexTypeOfType(sourceType, 1); if (type) { checkDestructuringAssignment(e, type, contextualMapper); } @@ -13802,7 +14117,9 @@ var ts; return rightType; } function checkForDisallowedESSymbolOperand(operator) { - var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576) ? node.left : someConstituentTypeHasKind(rightType, 1048576) ? node.right : undefined; + var offendingSymbolOperand = someConstituentTypeHasKind(leftType, 1048576) ? node.left : + someConstituentTypeHasKind(rightType, 1048576) ? node.right : + undefined; if (offendingSymbolOperand) { error(offendingSymbolOperand, ts.Diagnostics.The_0_operator_cannot_be_applied_to_type_symbol, ts.tokenToString(operator)); return false; @@ -13913,8 +14230,8 @@ var ts; } if (isConstEnumObjectType(type)) { var ok = (node.parent.kind === 153 && node.parent.expression === node) || - (node.parent.kind === 154 && node.parent.expression === node) || - ((node.kind === 64 || node.kind === 125) && isInRightSideOfImportOrExportAssignment(node)); + (node.parent.kind === 154 && node.parent.expression === node) || + ((node.kind === 64 || node.kind === 125) && 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); } @@ -14064,7 +14381,7 @@ var ts; var declaration = indexSymbol.declarations[i]; if (declaration.parameters.length === 1 && declaration.parameters[0].type) { switch (declaration.parameters[0].type.kind) { - case 121: + case 120: if (!seenStringIndexer) { seenStringIndexer = true; } @@ -14072,7 +14389,7 @@ var ts; error(declaration, ts.Diagnostics.Duplicate_string_index_signature); } break; - case 119: + case 118: if (!seenNumericIndexer) { seenNumericIndexer = true; } @@ -14139,7 +14456,7 @@ var ts; 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); }); + 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 !== 177 || !isSuperCallExpression(statements[0].expression)) { @@ -14461,13 +14778,15 @@ var ts; case 197: return 2097152; case 200: - return d.name.kind === 8 || ts.getModuleInstanceState(d) !== 0 ? 4194304 | 1048576 : 4194304; + return d.name.kind === 8 || ts.getModuleInstanceState(d) !== 0 + ? 4194304 | 1048576 + : 4194304; case 196: case 199: return 2097152 | 1048576; case 202: var result = 0; - var target = resolveImport(getSymbolOfNode(d)); + var target = resolveAlias(getSymbolOfNode(d)); ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); }); return result; default: @@ -14488,7 +14807,7 @@ var ts; } function checkFunctionLikeDeclaration(node) { checkSignatureDeclaration(node); - if (node.name.kind === 126) { + if (node.name && node.name.kind === 126) { checkComputedPropertyName(node.name); } if (!ts.hasDynamicName(node)) { @@ -14604,24 +14923,24 @@ var ts; } } function checkVarDeclaredNamesNotShadowed(node) { - if (node.initializer && (ts.getCombinedNodeFlags(node) & 6144) === 0) { + if (node.initializer && (ts.getCombinedNodeFlags(node) & 12288) === 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) & 6144) { + if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & 12288) { var varDeclList = ts.getAncestor(localDeclarationSymbol.valueDeclaration, 194); var container = varDeclList.parent.kind === 175 && - varDeclList.parent.parent; + varDeclList.parent.parent; var namesShareScope = container && - (container.kind === 174 && ts.isAnyFunction(container.parent) || - (container.kind === 201 && container.kind === 200) || - container.kind === 220); + (container.kind === 174 && ts.isFunctionLike(container.parent) || + (container.kind === 201 && container.kind === 200) || + container.kind === 220); 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); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name); } } } @@ -14777,33 +15096,127 @@ var ts; checkSourceElement(node.statement); } function checkForOfStatement(node) { - checkGrammarForOfStatement(node); + if (languageVersion < 2) { + grammarErrorOnFirstToken(node, ts.Diagnostics.for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher); + return; + } + checkGrammarForInOrForOfStatement(node); + if (node.initializer.kind === 194) { + checkForInOrForOfVariableDeclaration(node); + } + else { + var varExpr = node.initializer; + var rightType = checkExpression(node.expression); + var iteratedType = checkIteratedType(rightType, node.expression); + if (varExpr.kind === 151 || varExpr.kind === 152) { + checkDestructuringAssignment(varExpr, iteratedType || unknownType); + } + else { + var leftType = checkExpression(varExpr); + checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_of_statement, ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_be_a_previously_defined_constant); + if (iteratedType) { + checkTypeAssignableTo(iteratedType, leftType, varExpr, undefined); + } + } + } + checkSourceElement(node.statement); } function checkForInStatement(node) { checkGrammarForInOrForOfStatement(node); if (node.initializer.kind === 194) { - var variableDeclarationList = node.initializer; - if (variableDeclarationList.declarations.length >= 1) { - var decl = variableDeclarationList.declarations[0]; - checkVariableDeclaration(decl); + var variable = node.initializer.declarations[0]; + if (variable && ts.isBindingPattern(variable.name)) { + error(variable.name, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); } + checkForInOrForOfVariableDeclaration(node); } else { var varExpr = node.initializer; - var exprType = checkExpression(varExpr); - if (!allConstituentTypesHaveKind(exprType, 1 | 258)) { + var leftType = checkExpression(varExpr); + if (varExpr.kind === 151 || varExpr.kind === 152) { + error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_destructuring_pattern); + } + else if (!allConstituentTypesHaveKind(leftType, 1 | 258)) { error(varExpr, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_must_be_of_type_string_or_any); } else { - checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.Left_hand_side_of_assignment_expression_cannot_be_a_constant); + checkReferenceExpression(varExpr, ts.Diagnostics.Invalid_left_hand_side_in_for_in_statement, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_be_a_previously_defined_constant); } } - var exprType = checkExpression(node.expression); - if (!allConstituentTypesHaveKind(exprType, 1 | 48128 | 512)) { + var rightType = checkExpression(node.expression); + if (!allConstituentTypesHaveKind(rightType, 1 | 48128 | 512)) { error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); } + function checkForInOrForOfVariableDeclaration(iterationStatement) { + var variableDeclarationList = iterationStatement.initializer; + if (variableDeclarationList.declarations.length >= 1) { + var decl = variableDeclarationList.declarations[0]; + checkVariableDeclaration(decl); + } + } + function getTypeForVariableDeclarationInForOfStatement(forOfStatement) { + if (languageVersion < 2) { + return anyType; + } + var expressionType = getTypeOfExpression(forOfStatement.expression); + return checkIteratedType(expressionType, forOfStatement.expression) || anyType; + } + function checkIteratedType(iterable, expressionForError) { + ts.Debug.assert(languageVersion >= 2); + var iteratedType = getIteratedType(iterable, expressionForError); + if (expressionForError && iteratedType) { + var completeIterableType = globalIterableType !== emptyObjectType + ? createTypeReference(globalIterableType, [iteratedType]) + : emptyObjectType; + checkTypeAssignableTo(iterable, completeIterableType, expressionForError); + } + return iteratedType; + function getIteratedType(iterable, expressionForError) { + if (allConstituentTypesHaveKind(iterable, 1)) { + return undefined; + } + var iteratorFunction = getTypeOfPropertyOfType(iterable, ts.getPropertyNameForKnownSymbolName("iterator")); + if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, 1)) { + return undefined; + } + var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray; + if (iteratorFunctionSignatures.length === 0) { + if (expressionForError) { + error(expressionForError, ts.Diagnostics.The_right_hand_side_of_a_for_of_statement_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + } + return undefined; + } + var iterator = getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)); + if (allConstituentTypesHaveKind(iterator, 1)) { + return undefined; + } + var iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next"); + if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, 1)) { + return undefined; + } + var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray; + if (iteratorNextFunctionSignatures.length === 0) { + if (expressionForError) { + error(expressionForError, ts.Diagnostics.The_iterator_returned_by_the_right_hand_side_of_a_for_of_statement_must_have_a_next_method); + } + return undefined; + } + var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); + if (allConstituentTypesHaveKind(iteratorNextResult, 1)) { + return undefined; + } + var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); + if (!iteratorNextValue) { + if (expressionForError) { + error(expressionForError, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); + } + return undefined; + } + return iteratorNextValue; + } + } function checkBreakOrContinueStatement(node) { checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node); } @@ -14879,7 +15292,7 @@ var ts; if (!checkGrammarStatementInAmbientContext(node)) { var current = node.parent; while (current) { - if (ts.isAnyFunction(current)) { + if (ts.isFunctionLike(current)) { break; } if (current.kind === 189 && current.label.text === node.label.text) { @@ -14907,16 +15320,33 @@ var ts; checkBlock(node.tryBlock); var catchClause = node.catchClause; if (catchClause) { - if (catchClause.type) { - var sourceFile = ts.getSourceFileOfNode(node); - var colonStart = ts.skipTrivia(sourceFile.text, catchClause.name.end); - grammarErrorAtPos(sourceFile, colonStart, ":".length, ts.Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation); + if (catchClause.variableDeclaration) { + if (catchClause.variableDeclaration.name.kind !== 64) { + grammarErrorOnFirstToken(catchClause.variableDeclaration.name, ts.Diagnostics.Catch_clause_variable_name_must_be_an_identifier); + } + else if (catchClause.variableDeclaration.type) { + grammarErrorOnFirstToken(catchClause.variableDeclaration.type, ts.Diagnostics.Catch_clause_variable_cannot_have_a_type_annotation); + } + else if (catchClause.variableDeclaration.initializer) { + grammarErrorOnFirstToken(catchClause.variableDeclaration.initializer, ts.Diagnostics.Catch_clause_variable_cannot_have_an_initializer); + } + else { + var identifierName = catchClause.variableDeclaration.name.text; + var locals = catchClause.block.locals; + if (locals && ts.hasProperty(locals, identifierName)) { + var localSymbol = locals[identifierName]; + if (localSymbol && (localSymbol.flags & 2) !== 0) { + grammarErrorOnNode(localSymbol.valueDeclaration, ts.Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName); + } + } + checkGrammarEvalOrArgumentsInStrictMode(node, catchClause.variableDeclaration.name); + } } - checkGrammarEvalOrArgumentsInStrictMode(node, catchClause.name); checkBlock(catchClause.block); } - if (node.finallyBlock) + if (node.finallyBlock) { checkBlock(node.finallyBlock); + } } function checkIndexConstraints(type) { var declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, 1); @@ -14971,7 +15401,9 @@ var ts; errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0]; } if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { - var errorMessage = indexKind === 0 ? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 : ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; + var errorMessage = indexKind === 0 + ? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 + : ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType)); } } @@ -15004,10 +15436,12 @@ var ts; } function checkClassDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); - checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); + if (node.name) { + checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0); + checkCollisionWithCapturedThisVariable(node, node.name); + checkCollisionWithRequireExportsInGeneratedCode(node, node.name); + } checkTypeParameters(node.typeParameters); - checkCollisionWithCapturedThisVariable(node, node.name); - checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); var symbol = getSymbolOfNode(node); var type = getDeclaredTypeOfSymbol(symbol); @@ -15020,10 +15454,10 @@ var ts; if (type.baseTypes.length) { if (produceDiagnostics) { var baseType = type.baseTypes[0]; - checkTypeAssignableTo(type, baseType, node.name, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); + checkTypeAssignableTo(type, baseType, node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1); var staticBaseType = getTypeOfSymbol(baseType.symbol); - checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); - if (baseType.symbol !== resolveEntityName(node, baseTypeNode.typeName, 107455)) { + checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1); + if (baseType.symbol !== resolveEntityName(baseTypeNode.typeName, 107455)) { error(baseTypeNode, ts.Diagnostics.Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_0, typeToString(baseType)); } checkKindsOfPropertyMemberOverrides(type, baseType); @@ -15039,7 +15473,7 @@ var ts; if (t !== unknownType) { var declaredType = (t.flags & 4096) ? t.target : t; if (declaredType.flags & (1024 | 2048)) { - checkTypeAssignableTo(type, t, node.name, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); + checkTypeAssignableTo(type, t, node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1); } else { error(typeRefNode, ts.Diagnostics.A_class_may_only_implement_another_class_or_interface); @@ -15387,21 +15821,15 @@ 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 === 201) { - var statements = node.body.statements; - for (var i = 0, n = statements.length; i < n; i++) { - var statement = statements[i]; - if (statement.kind === 208) { - grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); - } - } - } } checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(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)) { + if (symbol.flags & 512 + && symbol.declarations.length > 1 + && !ts.isInAmbientContext(node) + && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums)) { var classOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (classOrFunc) { if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(classOrFunc)) { @@ -15437,7 +15865,9 @@ var ts; } var inAmbientExternalModule = node.parent.kind === 201 && node.parent.parent.name.kind === 8; if (node.parent.kind !== 220 && !inAmbientExternalModule) { - error(moduleName, node.kind === 209 ? ts.Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module : ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + error(moduleName, node.kind === 209 ? + ts.Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module : + ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); return false; } if (inAmbientExternalModule && isExternalModuleNameRelative(moduleName.text)) { @@ -15446,15 +15876,17 @@ var ts; } return true; } - function checkImportSymbol(node) { + function checkAliasSymbol(node) { var symbol = getSymbolOfNode(node); - var target = resolveImport(symbol); + var target = resolveAlias(symbol); if (target !== unknownSymbol) { var excludedMeanings = (symbol.flags & 107455 ? 107455 : 0) | - (symbol.flags & 793056 ? 793056 : 0) | - (symbol.flags & 1536 ? 1536 : 0); + (symbol.flags & 793056 ? 793056 : 0) | + (symbol.flags & 1536 ? 1536 : 0); if (target.flags & excludedMeanings) { - var message = node.kind === 211 ? ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; + var message = node.kind === 211 ? + ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : + ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; error(node, message, symbolToString(symbol)); } } @@ -15462,10 +15894,10 @@ var ts; function checkImportBinding(node) { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); - checkImportSymbol(node); + checkAliasSymbol(node); } function checkImportDeclaration(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + if (!checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -15487,50 +15919,107 @@ var ts; } function checkImportEqualsDeclaration(node) { checkGrammarModifiers(node); - if (ts.isInternalModuleImportEqualsDeclaration(node)) { + if (ts.isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); - var symbol = getSymbolOfNode(node); - var target = resolveImport(symbol); - if (target !== unknownSymbol) { - if (target.flags & 107455) { - var moduleName = getFirstIdentifier(node.moduleReference); - if (resolveEntityName(node, moduleName, 107455 | 1536).flags & 1536) { - checkExpressionOrQualifiedName(node.moduleReference); - } - else { - error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName)); - } - } - if (target.flags & 793056) { - checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); - } + if (node.flags & 1) { + markExportAsReferenced(node); } - } - else { - if (checkExternalImportOrExportDeclaration(node)) { - checkImportBinding(node); + if (ts.isInternalModuleImportEqualsDeclaration(node)) { + var target = resolveAlias(getSymbolOfNode(node)); + if (target !== unknownSymbol) { + if (target.flags & 107455) { + var moduleName = getFirstIdentifier(node.moduleReference); + if (!(resolveEntityName(moduleName, 107455 | 1536).flags & 1536)) { + error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName)); + } + } + if (target.flags & 793056) { + checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); + } + } } } } function checkExportDeclaration(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + if (!checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_declaration_cannot_have_modifiers); } if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) { if (node.exportClause) { - ts.forEach(node.exportClause.elements, checkImportSymbol); + ts.forEach(node.exportClause.elements, checkExportSpecifier); } } } + function checkExportSpecifier(node) { + checkAliasSymbol(node); + if (!node.parent.parent.moduleSpecifier) { + markExportAsReferenced(node); + } + } function checkExportAssignment(node) { - if (!checkGrammarModifiers(node) && (node.flags & 243)) { + var container = node.parent.kind === 220 ? node.parent : node.parent.parent; + if (container.kind === 200 && container.name.kind === 64) { + error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); + return; + } + if (!checkGrammarModifiers(node) && (node.flags & 499)) { grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers); } - var container = node.parent; - if (container.kind !== 220) { - container = container.parent; + if (node.expression.kind === 64) { + markExportAsReferenced(node); + } + else { + checkExpressionCached(node.expression); + } + checkExternalModuleExports(container); + } + function getModuleStatements(node) { + if (node.kind === 220) { + return node.statements; + } + if (node.kind === 200 && node.body.kind === 201) { + return node.body.statements; + } + return emptyArray; + } + function hasExportedMembers(moduleSymbol) { + var declarations = moduleSymbol.declarations; + for (var i = 0; i < declarations.length; i++) { + var statements = getModuleStatements(declarations[i]); + for (var j = 0; j < statements.length; j++) { + var node = statements[j]; + if (node.kind === 209) { + var exportClause = node.exportClause; + if (!exportClause) { + return true; + } + var specifiers = exportClause.elements; + for (var k = 0; k < specifiers.length; k++) { + var specifier = specifiers[k]; + if (!(specifier.propertyName && specifier.name && specifier.name.text === "default")) { + return true; + } + } + } + else if (node.kind !== 208 && node.flags & 1 && !(node.flags & 256)) { + return true; + } + } + } + } + function checkExternalModuleExports(node) { + var moduleSymbol = getSymbolOfNode(node); + var links = getSymbolLinks(moduleSymbol); + if (!links.exportsChecked) { + var defaultSymbol = getExportAssignmentSymbol(moduleSymbol); + if (defaultSymbol) { + if (hasExportedMembers(moduleSymbol)) { + var declaration = getDeclarationOfAliasSymbol(defaultSymbol) || defaultSymbol.valueDeclaration; + error(declaration, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); + } + } + links.exportsChecked = true; } - checkTypeOfExportAssignmentSymbol(getSymbolOfNode(container)); } function checkSourceElement(node) { if (!node) @@ -15712,6 +16201,7 @@ var ts; case 196: case 199: case 219: + case 208: case 220: ts.forEachChild(node, checkFunctionExpressionBodies); break; @@ -15731,11 +16221,7 @@ var ts; 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, 202)); - } + checkExternalModuleExports(node); } if (potentialThisCollisions.length) { ts.forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope); @@ -15824,11 +16310,6 @@ var ts; copySymbol(location.symbol, meaning); } break; - case 216: - if (location.name.text) { - copySymbol(location.symbol, meaning); - } - break; } memberFlags = location.flags; location = location.parent; @@ -15862,11 +16343,11 @@ var ts; return true; } switch (node.kind) { + case 111: + case 118: + case 120: case 112: - case 119: case 121: - case 113: - case 122: return true; case 98: return node.parent.kind !== 164; @@ -15925,7 +16406,7 @@ var ts; return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent; } if (nodeOnRightSide.parent.kind === 208) { - return nodeOnRightSide.parent.exportName === nodeOnRightSide && nodeOnRightSide.parent; + return nodeOnRightSide.parent.expression === nodeOnRightSide && nodeOnRightSide.parent; } return undefined; } @@ -15937,11 +16418,11 @@ var ts; (node.parent.kind === 153 && node.parent.name === node); } function getSymbolOfEntityNameOrPropertyAccessExpression(entityName) { - if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) { + if (ts.isDeclarationName(entityName)) { return getSymbolOfNode(entityName.parent); } if (entityName.parent.kind === 208) { - return resolveEntityName(entityName.parent.parent, entityName, 107455 | 793056 | 1536 | 8388608); + return resolveEntityName(entityName, 107455 | 793056 | 1536 | 8388608); } if (entityName.kind !== 153) { if (isInRightSideOfImportOrExportAssignment(entityName)) { @@ -15957,7 +16438,7 @@ var ts; } if (entityName.kind === 64) { var meaning = 107455 | 8388608; - return resolveEntityName(entityName, entityName, meaning); + return resolveEntityName(entityName, meaning); } else if (entityName.kind === 153) { var symbol = getNodeLinks(entityName).resolvedSymbol; @@ -15977,7 +16458,7 @@ var ts; else if (isTypeReferenceIdentifier(entityName)) { var meaning = entityName.parent.kind === 139 ? 793056 : 1536; meaning |= 8388608; - return resolveEntityName(entityName, entityName, meaning); + return resolveEntityName(entityName, meaning); } return undefined; } @@ -15985,11 +16466,13 @@ var ts; if (isInsideWithStatementBody(node)) { return undefined; } - if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (ts.isDeclarationName(node)) { return getSymbolOfNode(node.parent); } if (node.kind === 64 && isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === 208 ? getSymbolOfEntityNameOrPropertyAccessExpression(node) : getSymbolOfPartOfRightHandSideOfImportEquals(node); + return node.parent.kind === 208 + ? getSymbolOfEntityNameOrPropertyAccessExpression(node) + : getSymbolOfPartOfRightHandSideOfImportEquals(node); } switch (node.kind) { case 64: @@ -16000,18 +16483,19 @@ var ts; case 90: var type = checkExpression(node); return type.symbol; - case 114: + case 113: var constructorDeclaration = node.parent; if (constructorDeclaration && constructorDeclaration.kind === 133) { return constructorDeclaration.parent.symbol; } return undefined; case 8: - if (ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) && - ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) { - var importSymbol = getSymbolOfNode(node.parent.parent); - var moduleType = getTypeOfSymbol(importSymbol); - return moduleType ? moduleType.symbol : undefined; + var moduleName; + if ((ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) && + ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) || + ((node.parent.kind === 203 || node.parent.kind === 209) && + node.parent.moduleSpecifier === node)) { + return resolveExternalModuleName(node, node); } case 7: if (node.parent.kind == 154 && node.parent.argumentExpression === node) { @@ -16029,7 +16513,7 @@ var ts; } function getShorthandAssignmentValueSymbol(location) { if (location && location.kind === 218) { - return resolveEntityName(location, location.name, 107455); + return resolveEntityName(location.name, 107455); } return undefined; } @@ -16055,7 +16539,7 @@ var ts; var symbol = getSymbolOfNode(node); return getTypeOfSymbol(symbol); } - if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (ts.isDeclarationName(node)) { var symbol = getSymbolInfo(node); return symbol && getTypeOfSymbol(symbol); } @@ -16132,6 +16616,10 @@ var ts; return generatedNames; function generateNames(node) { switch (node.kind) { + case 195: + case 196: + generateNameForFunctionOrClassDeclaration(node); + break; case 200: generateNameForModuleOrEnum(node); generateNames(node.body); @@ -16145,6 +16633,9 @@ var ts; case 209: generateNameForExportDeclaration(node); break; + case 208: + generateNameForExportAssignment(node); + break; case 220: case 201: ts.forEach(node.statements, generateNames); @@ -16155,27 +16646,17 @@ var ts; return ts.hasProperty(globals, name) || ts.hasProperty(sourceFile.identifiers, name) || ts.hasProperty(generatedNames, name); } function makeUniqueName(baseName) { - if (baseName.charCodeAt(0) !== 95) { - var baseName = "_" + baseName; - if (!isExistingName(baseName)) { - return generatedNames[baseName] = baseName; - } - } - if (baseName.charCodeAt(baseName.length - 1) !== 95) { - baseName += "_"; - } - var i = 1; - while (true) { - name = baseName + i; - if (!isExistingName(name)) { - return generatedNames[name] = name; - } - i++; - } + var name = ts.generateUniqueName(baseName, isExistingName); + return generatedNames[name] = name; } function assignGeneratedName(node, name) { getNodeLinks(node).generatedName = ts.unescapeIdentifier(name); } + function generateNameForFunctionOrClassDeclaration(node) { + if (!node.name) { + assignGeneratedName(node, makeUniqueName("default")); + } + } function generateNameForModuleOrEnum(node) { if (node.name.kind === 64) { var name = node.name.text; @@ -16184,7 +16665,8 @@ var ts; } function generateNameForImportOrExportDeclaration(node) { var expr = ts.getExternalModuleName(node); - var baseName = expr.kind === 8 ? ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; + var baseName = expr.kind === 8 ? + ts.escapeIdentifier(ts.makeIdentifierFromModuleName(expr.text)) : "module"; assignGeneratedName(node, makeUniqueName(baseName)); } function generateNameForImportDeclaration(node) { @@ -16197,6 +16679,11 @@ var ts; generateNameForImportOrExportDeclaration(node); } } + function generateNameForExportAssignment(node) { + if (node.expression.kind !== 64) { + assignGeneratedName(node, makeUniqueName("default")); + } + } } function getGeneratedNameForNode(node) { var links = getNodeLinks(node); @@ -16211,8 +16698,8 @@ var ts; function getLocalNameForImportDeclaration(node) { return getGeneratedNameForNode(node); } - function getImportNameSubstitution(symbol) { - var declaration = getDeclarationOfImportSymbol(symbol); + function getAliasNameSubstitution(symbol) { + var declaration = getDeclarationOfAliasSymbol(symbol); if (declaration && declaration.kind === 207) { var moduleName = getGeneratedNameForNode(declaration.parent.parent.parent); var propertyName = declaration.propertyName || declaration.name; @@ -16243,38 +16730,35 @@ var ts; return getExportNameSubstitution(exportSymbol, node.parent); } if (symbol.flags & 8388608) { - return getImportNameSubstitution(symbol); + return getAliasNameSubstitution(symbol); } } } - function getExportAssignmentName(node) { - var symbol = getExportAssignmentSymbol(getSymbolOfNode(node)); - return symbol && symbol !== unknownSymbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol) ? symbolToString(symbol) : undefined; + function hasExportDefaultValue(node) { + var symbol = getResolvedExportAssignmentSymbol(getSymbolOfNode(node)); + return symbol && symbol !== unknownSymbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol); } function isTopLevelValueImportEqualsWithEntityName(node) { if (node.parent.kind !== 220 || !ts.isInternalModuleImportEqualsDeclaration(node)) { return false; } - return isImportResolvedToValue(getSymbolOfNode(node)); + return isAliasResolvedToValue(getSymbolOfNode(node)); } - function isImportResolvedToValue(symbol) { - var target = resolveImport(symbol); + function isAliasResolvedToValue(symbol) { + var target = resolveAlias(symbol); return target !== unknownSymbol && target.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(target); } function isConstEnumOrConstEnumOnlyModule(s) { return isConstEnumSymbol(s) || s.constEnumOnlyModule; } - function isReferencedImportDeclaration(node) { - if (isImportSymbolDeclaration(node)) { + function isReferencedAliasDeclaration(node) { + if (isAliasSymbolDeclaration(node)) { var symbol = getSymbolOfNode(node); if (getSymbolLinks(symbol).referenced) { return true; } - if (node.kind === 202 && node.flags & 1 && isImportResolvedToValue(symbol)) { - return true; - } } - return ts.forEachChild(node, isReferencedImportDeclaration); + return ts.forEachChild(node, isReferencedAliasDeclaration); } function isImplementationOfOverload(node) { if (ts.nodeIsPresent(node.body)) { @@ -16308,7 +16792,9 @@ var ts; } function writeTypeOfDeclaration(declaration, enclosingDeclaration, flags, writer) { var symbol = getSymbolOfNode(declaration); - var type = symbol && !(symbol.flags & (2048 | 131072)) ? getTypeOfSymbol(symbol) : unknownType; + var type = symbol && !(symbol.flags & (2048 | 131072)) + ? getTypeOfSymbol(symbol) + : unknownType; getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } function writeReturnTypeOfSignatureDeclaration(signatureDeclaration, enclosingDeclaration, flags, writer) { @@ -16319,12 +16805,38 @@ var ts; return !resolveName(location, name, 107455, undefined, undefined) && !ts.hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name); } + function getBlockScopedVariableId(n) { + ts.Debug.assert(!ts.nodeIsSynthesized(n)); + if (n.parent.kind === 153 && + n.parent.name === n) { + return undefined; + } + if (n.parent.kind === 150 && + n.parent.propertyName === n) { + return undefined; + } + var declarationSymbol = (n.parent.kind === 193 && n.parent.name === n) || + n.parent.kind === 150 + ? getSymbolOfNode(n.parent) + : undefined; + var symbol = declarationSymbol || + getNodeLinks(n).resolvedSymbol || + resolveName(n, n.text, 2 | 8388608, undefined, undefined); + var isLetOrConst = symbol && + (symbol.flags & 2) && + symbol.valueDeclaration.parent.kind !== 216; + if (isLetOrConst) { + getSymbolLinks(symbol); + return symbol.id; + } + return undefined; + } function createResolver() { return { getGeneratedNameForNode: getGeneratedNameForNode, getExpressionNameSubstitution: getExpressionNameSubstitution, - getExportAssignmentName: getExportAssignmentName, - isReferencedImportDeclaration: isReferencedImportDeclaration, + hasExportDefaultValue: hasExportDefaultValue, + isReferencedAliasDeclaration: isReferencedAliasDeclaration, getNodeCheckFlags: getNodeCheckFlags, isTopLevelValueImportEqualsWithEntityName: isTopLevelValueImportEqualsWithEntityName, isDeclarationVisible: isDeclarationVisible, @@ -16334,7 +16846,8 @@ var ts; isSymbolAccessible: isSymbolAccessible, isEntityNameVisible: isEntityNameVisible, getConstantValue: getConstantValue, - isUnknownIdentifier: isUnknownIdentifier + isUnknownIdentifier: isUnknownIdentifier, + getBlockScopedVariableId: getBlockScopedVariableId }; } function initializeTypeChecker() { @@ -16362,6 +16875,7 @@ var ts; globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray"); globalESSymbolType = getGlobalType("Symbol"); globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"); + globalIterableType = getGlobalType("Iterable", 1); } else { globalTemplateStringsArrayType = unknownType; @@ -16404,14 +16918,14 @@ var ts; for (var i = 0, n = node.modifiers.length; i < n; i++) { var modifier = node.modifiers[i]; switch (modifier.kind) { - case 109: case 108: case 107: + case 106: var text; - if (modifier.kind === 109) { + if (modifier.kind === 108) { text = "public"; } - else if (modifier.kind === 108) { + else if (modifier.kind === 107) { text = "protected"; lastProtected = modifier; } @@ -16430,7 +16944,7 @@ var ts; } flags |= ts.modifierToFlag(modifier.kind); break; - case 110: + case 109: if (flags & 128) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static"); } @@ -16458,7 +16972,7 @@ var ts; } flags |= 1; break; - case 115: + case 114: if (flags & 2) { return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare"); } @@ -16564,7 +17078,7 @@ var ts; if (parameter.dotDotDotToken) { return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter); } - if (parameter.flags & 243) { + if (parameter.flags & 499) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier); } if (parameter.questionToken) { @@ -16576,7 +17090,7 @@ var ts; if (!parameter.type) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); } - if (parameter.type.kind !== 121 && parameter.type.kind !== 119) { + if (parameter.type.kind !== 120 && parameter.type.kind !== 118) { return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); } if (!node.type) { @@ -16584,7 +17098,7 @@ var ts; } } function checkGrammarForIndexSignatureModifier(node) { - if (node.flags & 243) { + if (node.flags & 499) { grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members); } } @@ -16649,7 +17163,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103); + ts.Debug.assert(heritageClause.token === 102); if (seenImplementsClause) { return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen); } @@ -16672,7 +17186,7 @@ var ts; seenExtendsClause = true; } else { - ts.Debug.assert(heritageClause.token === 103); + ts.Debug.assert(heritageClause.token === 102); return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause); } checkGrammarHeritageClause(heritageClause); @@ -16769,29 +17283,28 @@ var ts; var variableList = forInOrOfStatement.initializer; if (!checkGrammarVariableDeclarationList(variableList)) { if (variableList.declarations.length > 1) { - var diagnostic = forInOrOfStatement.kind === 182 ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement; + var diagnostic = forInOrOfStatement.kind === 182 + ? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement + : ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement; return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic); } var firstDeclaration = variableList.declarations[0]; if (firstDeclaration.initializer) { - var diagnostic = forInOrOfStatement.kind === 182 ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer; + var diagnostic = forInOrOfStatement.kind === 182 + ? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer + : ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer; return grammarErrorOnNode(firstDeclaration.name, diagnostic); } if (firstDeclaration.type) { - var diagnostic = forInOrOfStatement.kind === 182 ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation; + var diagnostic = forInOrOfStatement.kind === 182 + ? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation + : ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation; return grammarErrorOnNode(firstDeclaration, diagnostic); } } } return false; } - function checkGrammarForOfStatement(forOfStatement) { - return grammarErrorOnFirstToken(forOfStatement, ts.Diagnostics.for_of_statements_are_not_currently_supported); - if (languageVersion < 2) { - return grammarErrorOnFirstToken(forOfStatement, ts.Diagnostics.for_of_statements_are_only_available_when_targeting_ECMAScript_6_or_higher); - } - return checkGrammarForInOrForOfStatement(forOfStatement); - } function checkGrammarAccessor(accessor) { var kind = accessor.kind; if (languageVersion < 1) { @@ -16821,7 +17334,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 & 499) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } else if (parameter.questionToken) { @@ -16886,13 +17399,14 @@ var ts; function checkGrammarBreakOrContinueStatement(node) { var current = node; while (current) { - if (ts.isAnyFunction(current)) { + if (ts.isFunctionLike(current)) { return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary); } switch (current.kind) { case 189: if (node.label && current.label.text === node.label.text) { - var isMisplacedContinueLabel = node.kind === 184 && !isIterationStatement(current.statement, true); + var isMisplacedContinueLabel = node.kind === 184 + && !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); } @@ -16913,11 +17427,15 @@ var ts; current = current.parent; } if (node.label) { - var message = node.kind === 185 ? 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 === 185 + ? 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 === 185 ? 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 === 185 + ? 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); } } @@ -16934,16 +17452,17 @@ var ts; return checkGrammarEvalOrArgumentsInStrictMode(node, node.name); } function checkGrammarVariableDeclaration(node) { - if (ts.isInAmbientContext(node)) { - if (ts.isBindingPattern(node.name)) { - return grammarErrorOnNode(node, ts.Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); + if (node.parent.parent.kind !== 182 && node.parent.parent.kind !== 183) { + if (ts.isInAmbientContext(node)) { + if (ts.isBindingPattern(node.name)) { + return grammarErrorOnNode(node, ts.Diagnostics.Destructuring_declarations_are_not_allowed_in_ambient_contexts); + } + if (node.initializer) { + var equalsTokenLength = "=".length; + return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, equalsTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } } - if (node.initializer) { - return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - 1, 1, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); - } - } - else { - if (!node.initializer) { + else if (!node.initializer) { if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) { return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer); } @@ -16977,14 +17496,6 @@ var ts; if (!declarationList.declarations.length) { return grammarErrorAtPos(ts.getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty); } - if (languageVersion < 2) { - if (ts.isLet(declarationList)) { - return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - else if (ts.isConst(declarationList)) { - return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); - } - } } function allowLetAndConstDeclarations(parent) { switch (parent.kind) { @@ -17024,7 +17535,7 @@ var ts; return false; } function checkGrammarEnumDeclaration(enumDecl) { - var enumIsConst = (enumDecl.flags & 4096) !== 0; + var enumIsConst = (enumDecl.flags & 8192) !== 0; var hasError = false; if (!enumIsConst) { var inConstantEnumMemberSection = true; @@ -17052,18 +17563,11 @@ var ts; function hasParseDiagnostics(sourceFile) { return sourceFile.parseDiagnostics.length > 0; } - function scanToken(scanner, pos) { - scanner.setTextPos(pos); - scanner.scan(); - var start = scanner.getTokenPos(); - return start; - } function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = ts.createScanner(languageVersion, true, sourceFile.text); - var start = scanToken(scanner, node.pos); - diagnostics.add(ts.createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2)); + var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos); + diagnostics.add(ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2)); return true; } } @@ -17076,16 +17580,17 @@ var ts; function grammarErrorOnNode(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var span = ts.getErrorSpanForNode(node); - var start = span.end > span.pos ? ts.skipTrivia(sourceFile.text, span.pos) : span.pos; - diagnostics.add(ts.createFileDiagnostic(sourceFile, start, span.end - start, message, arg0, arg1, arg2)); + diagnostics.add(ts.createDiagnosticForNode(node, message, arg0, arg1, arg2)); return true; } } - function checkGrammarEvalOrArgumentsInStrictMode(contextNode, identifier) { - if (contextNode && (contextNode.parserContextFlags & 1) && ts.isEvalOrArgumentsIdentifier(identifier)) { - var name = ts.declarationNameToString(identifier); - return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, name); + function checkGrammarEvalOrArgumentsInStrictMode(contextNode, name) { + if (name && name.kind === 64) { + var identifier = name; + if (contextNode && (contextNode.parserContextFlags & 1) && ts.isEvalOrArgumentsIdentifier(identifier)) { + var nameText = ts.declarationNameToString(identifier); + return grammarErrorOnNode(identifier, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); + } } } function checkGrammarConstructorTypeParameters(node) { @@ -17149,7 +17654,7 @@ var ts; return getNodeLinks(node).hasReportedStatementInAmbientContext = true; } var links = getNodeLinks(node); - if (!links.hasReportedStatementInAmbientContext && ts.isAnyFunction(node.parent)) { + if (!links.hasReportedStatementInAmbientContext && ts.isFunctionLike(node.parent)) { return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); } if (node.parent.kind === 174 || node.parent.kind === 201 || node.parent.kind === 220) { @@ -17163,7 +17668,7 @@ var ts; } } function checkGrammarNumbericLiteral(node) { - if (node.flags & 8192) { + if (node.flags & 16384) { if (node.parserContextFlags & 1) { return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); } @@ -17175,9 +17680,8 @@ var ts; function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = ts.createScanner(languageVersion, true, sourceFile.text); - scanToken(scanner, node.pos); - diagnostics.add(ts.createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2)); + var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos); + diagnostics.add(ts.createFileDiagnostic(sourceFile, ts.textSpanEnd(span), 0, message, arg0, arg1, arg2)); return true; } } @@ -17306,7 +17810,9 @@ var ts; var lineCount = ts.getLineStarts(currentSourceFile).length; var firstCommentLineIndent; for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - var nextLineStart = (currentLine + 1) === lineCount ? currentSourceFile.text.length + 1 : ts.getStartPositionOfLine(currentLine + 1, currentSourceFile); + var nextLineStart = (currentLine + 1) === lineCount + ? currentSourceFile.text.length + 1 + : ts.getStartPositionOfLine(currentLine + 1, currentSourceFile); if (pos !== comment.pos) { if (firstCommentLineIndent === undefined) { firstCommentLineIndent = calculateIndent(ts.getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos); @@ -17384,7 +17890,8 @@ var ts; } else { ts.forEach(declarations, function (member) { - if ((member.kind === 134 || member.kind === 135) && (member.flags & 128) === (accessor.flags & 128)) { + if ((member.kind === 134 || member.kind === 135) + && (member.flags & 128) === (accessor.flags & 128)) { var memberName = ts.getPropertyNameForPropertyNameNode(member.name); var accessorName = ts.getPropertyNameForPropertyNameNode(accessor.name); if (memberName === accessorName) { @@ -17449,7 +17956,7 @@ var ts; var addedGlobalFileReference = false; ts.forEach(root.referencedFiles, function (fileReference) { var referencedFile = ts.tryResolveScriptReference(host, root, fileReference); - if (referencedFile && ((referencedFile.flags & 1024) || + if (referencedFile && ((referencedFile.flags & 2048) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) { writeReferencePath(referencedFile); @@ -17608,11 +18115,11 @@ var ts; } function emitType(type) { switch (type.kind) { + case 111: + case 120: + case 118: case 112: case 121: - case 119: - case 113: - case 122: case 98: case 8: return writeTextOfNode(currentSourceFile, type); @@ -17702,8 +18209,8 @@ var ts; emitLines(node.statements); } function emitExportAssignment(node) { - write("export = "); - writeTextOfNode(currentSourceFile, node.exportName); + write(node.isExportEquals ? "export = " : "export default "); + writeTextOfNode(currentSourceFile, node.expression); write(";"); writeLine(); } @@ -17919,7 +18426,9 @@ var ts; function getHeritageClauseVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; if (node.parent.parent.kind === 196) { - 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; + 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 { diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; @@ -18012,17 +18521,31 @@ var ts; function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; if (node.kind === 193) { - 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; + 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 === 130 || node.kind === 129) { 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; + 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 === 196) { - 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; + 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 { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; } } return diagnosticMessage !== undefined ? { @@ -18084,17 +18607,25 @@ var ts; } function getTypeAnnotationFromAccessor(accessor) { if (accessor) { - return accessor.kind === 134 ? accessor.type : accessor.parameters.length > 0 ? accessor.parameters[0].type : undefined; + return accessor.kind === 134 + ? accessor.type + : accessor.parameters.length > 0 + ? accessor.parameters[0].type + : undefined; } } function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) { var diagnosticMessage; if (accessorWithTypeAnnotation.kind === 135) { 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; + 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; } else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; } return { diagnosticMessage: diagnosticMessage, @@ -18104,10 +18635,18 @@ var ts; } else { if (accessorWithTypeAnnotation.flags & 128) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === 2 ? + ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; } else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 ? ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === 2 ? + ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; } return { diagnosticMessage: diagnosticMessage, @@ -18189,28 +18728,48 @@ var ts; var diagnosticMessage; switch (node.kind) { case 137: - 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; + 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 136: - 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; + 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 138: - 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; + 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 132: case 131: 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; + 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 === 196) { - 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; + 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; + 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 195: - 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; + 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: ts.Debug.fail("This is unknown kind for signature: " + node.kind); @@ -18249,28 +18808,50 @@ var ts; var diagnosticMessage; switch (node.parent.kind) { case 133: - 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; + 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 137: - 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; + 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 136: - 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; + 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 132: case 131: 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; + 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 === 196) { - 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; + 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; + 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 195: - 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; + 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: ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind); @@ -18322,7 +18903,11 @@ var ts; } } function writeReferencePath(referencedFile) { - var declFileName = referencedFile.flags & 1024 ? referencedFile.fileName : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; + var declFileName = referencedFile.flags & 2048 + ? referencedFile.fileName + : shouldEmitToOwnFile(referencedFile, compilerOptions) + ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") + : ts.removeFileExtension(compilerOptions.out) + ".d.ts"; declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, host.getCurrentDirectory(), host.getCanonicalFileName, false); referencePathsOutput += "/// " + newLine; } @@ -18374,12 +18959,16 @@ var ts; var increaseIndent = writer.increaseIndent; var decreaseIndent = writer.decreaseIndent; var currentSourceFile; + var lastFrame; + var currentScopeNames; + var generatedBlockScopeNames; var extendsEmitted = false; var tempCount = 0; var tempVariables; var tempParameters; var externalImports; var exportSpecifiers; + var exportDefault; var writeEmittedFiles = writeJavaScriptFile; var emitLeadingComments = compilerOptions.removeComments ? function (node) { } : emitLeadingDeclarationComments; var emitTrailingComments = compilerOptions.removeComments ? function (node) { } : emitTrailingDeclarationComments; @@ -18411,6 +19000,53 @@ var ts; writeLine(); writeEmittedFiles(writer.getText(), compilerOptions.emitBOM); return; + function enterNameScope() { + var names = currentScopeNames; + currentScopeNames = undefined; + if (names) { + lastFrame = { names: names, previous: lastFrame }; + return true; + } + return false; + } + function exitNameScope(popFrame) { + if (popFrame) { + currentScopeNames = lastFrame.names; + lastFrame = lastFrame.previous; + } + else { + currentScopeNames = undefined; + } + } + function generateUniqueNameForLocation(location, baseName) { + var name; + if (!isExistingName(location, baseName)) { + name = baseName; + } + else { + name = ts.generateUniqueName(baseName, function (n) { return isExistingName(location, n); }); + } + if (!currentScopeNames) { + currentScopeNames = {}; + } + return currentScopeNames[name] = name; + } + function isExistingName(location, name) { + if (!resolver.isUnknownIdentifier(location, name)) { + return true; + } + if (currentScopeNames && ts.hasProperty(currentScopeNames, name)) { + return true; + } + var frame = lastFrame; + while (frame) { + if (ts.hasProperty(frame.names, name)) { + return true; + } + frame = frame.previous; + } + return false; + } function initializeEmitterWithSourceMaps() { var sourceMapDir; var sourceMapSourceIndex = -1; @@ -18564,7 +19200,9 @@ var ts; node.kind === 199) { if (node.name) { var name = node.name; - scopeName = name.kind === 126 ? ts.getTextOfNode(name) : node.name.text; + scopeName = name.kind === 126 + ? ts.getTextOfNode(name) + : node.name.text; } recordScopeNameStart(scopeName); } @@ -18670,13 +19308,13 @@ var ts; function createTempVariable(location, forLoopVariable) { var name = forLoopVariable ? "_i" : undefined; while (true) { - if (name && resolver.isUnknownIdentifier(location, name)) { + if (name && !isExistingName(location, name)) { break; } name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + 97) : tempCount - 25); tempCount++; } - var result = ts.createNode(64); + var result = ts.createSynthesizedNode(64); result.text = name; return result; } @@ -18720,7 +19358,7 @@ var ts; emit(node); } } - function emitParenthesized(node, parenthesized) { + function emitParenthesizedIf(node, parenthesized) { if (parenthesized) { write("("); } @@ -18807,37 +19445,109 @@ var ts; emit(nodes[i]); } } - function isBinaryOrOctalIntegerLiteral(text) { - if (text.length <= 0) { - return false; - } - if (text.charCodeAt(1) === 66 || text.charCodeAt(1) === 98 || - text.charCodeAt(1) === 79 || text.charCodeAt(1) === 111) { - return true; + function isBinaryOrOctalIntegerLiteral(node, text) { + if (node.kind === 7 && text.length > 1) { + switch (text.charCodeAt(1)) { + case 98: + case 66: + case 111: + case 79: + return true; + } } 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 = getLiteralText(node); if (compilerOptions.sourceMap && (node.kind === 8 || ts.isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } - else if (languageVersion < 2 && node.kind === 7 && isBinaryOrOctalIntegerLiteral(text)) { + else if (languageVersion < 2 && isBinaryOrOctalIntegerLiteral(node, text)) { write(node.text); } else { write(text); } } - function getTemplateLiteralAsStringLiteral(node) { - return '"' + ts.escapeString(node.text) + '"'; + function getLiteralText(node) { + if (languageVersion < 2 && (ts.isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { + return getQuotedEscapedLiteralText('"', node.text, '"'); + } + if (node.parent) { + return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + } + switch (node.kind) { + case 8: + return getQuotedEscapedLiteralText('"', node.text, '"'); + case 10: + return getQuotedEscapedLiteralText('`', node.text, '`'); + case 11: + return getQuotedEscapedLiteralText('`', node.text, '${'); + case 12: + return getQuotedEscapedLiteralText('}', node.text, '${'); + case 13: + return getQuotedEscapedLiteralText('}', node.text, '`'); + case 7: + return node.text; + } + ts.Debug.fail("Literal kind '" + node.kind + "' not accounted for."); + } + function getQuotedEscapedLiteralText(leftQuote, text, rightQuote) { + return leftQuote + ts.escapeNonAsciiCharacters(ts.escapeString(text)) + rightQuote; + } + function emitDownlevelRawTemplateLiteral(node) { + var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + var isLast = node.kind === 10 || node.kind === 13; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + text = text.replace(/\r\n?/g, "\n"); + text = ts.escapeString(text); + write('"' + text + '"'); + } + function emitDownlevelTaggedTemplateArray(node, literalEmitter) { + write("["); + if (node.template.kind === 10) { + literalEmitter(node.template); + } + else { + literalEmitter(node.template.head); + ts.forEach(node.template.templateSpans, function (child) { + write(", "); + literalEmitter(child.literal); + }); + } + write("]"); + } + function emitDownlevelTaggedTemplate(node) { + var tempVariable = createAndRecordTempVariable(node); + write("("); + emit(tempVariable); + write(" = "); + emitDownlevelTaggedTemplateArray(node, emit); + write(", "); + emit(tempVariable); + write(".raw = "); + emitDownlevelTaggedTemplateArray(node, emitDownlevelRawTemplateLiteral); + write(", "); + emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); + write("("); + emit(tempVariable); + if (node.template.kind === 169) { + ts.forEach(node.template.templateSpans, function (templateSpan) { + write(", "); + var needsParens = templateSpan.expression.kind === 167 + && templateSpan.expression.operatorToken.kind === 23; + emitParenthesizedIf(templateSpan.expression, needsParens); + }); + } + write("))"); } function emitTemplateExpression(node) { if (languageVersion >= 2) { ts.forEachChild(node, emit); return; } - var emitOuterParens = ts.isExpression(node.parent) && templateNeedsParens(node, node.parent); + var emitOuterParens = ts.isExpression(node.parent) + && templateNeedsParens(node, node.parent); if (emitOuterParens) { write("("); } @@ -18848,11 +19558,12 @@ var ts; } for (var i = 0; i < node.templateSpans.length; i++) { var templateSpan = node.templateSpans[i]; - var needsParens = templateSpan.expression.kind !== 159 && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; + var needsParens = templateSpan.expression.kind !== 159 + && comparePrecedenceToBinaryPlus(templateSpan.expression) !== 1; if (i > 0 || headEmitted) { write(" + "); } - emitParenthesized(templateSpan.expression, needsParens); + emitParenthesizedIf(templateSpan.expression, needsParens); if (templateSpan.literal.text.length !== 0) { write(" + "); emitLiteral(templateSpan.literal); @@ -18950,8 +19661,6 @@ var ts; return false; case 189: return node.parent.label === node; - case 216: - return node.parent.name === node; } } function emitExpressionIdentifier(node) { @@ -18963,7 +19672,18 @@ var ts; writeTextOfNode(currentSourceFile, node); } } + function getBlockScopedVariableId(node) { + return !ts.nodeIsSynthesized(node) && resolver.getBlockScopedVariableId(node); + } function emitIdentifier(node) { + var variableId = getBlockScopedVariableId(node); + if (variableId !== undefined && generatedBlockScopeNames) { + var text = generatedBlockScopeNames[variableId]; + if (text) { + write(text); + return; + } + } if (!node.parent) { write(node.text); } @@ -19026,7 +19746,7 @@ var ts; write("..."); emit(node.expression); } - function needsParenthesisForPropertyAccess(node) { + function needsParenthesisForPropertyAccessOrInvocation(node) { switch (node.kind) { case 64: case 151: @@ -19052,7 +19772,7 @@ var ts; var e = elements[pos]; if (e.kind === 171) { e = e.expression; - emitParenthesized(e, group === 0 && needsParenthesisForPropertyAccess(e)); + emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; } else { @@ -19091,24 +19811,18 @@ var ts; write("]"); } else { - emitListWithSpread(elements, (node.flags & 256) !== 0, elements.hasTrailingComma); + emitListWithSpread(elements, (node.flags & 512) !== 0, elements.hasTrailingComma); } } - function createSynthesizedNode(kind) { - var node = ts.createNode(kind); - node.pos = -1; - node.end = -1; - return node; - } function emitDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex) { var parenthesizedObjectLiteral = createDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex); return emit(parenthesizedObjectLiteral); } function createDownlevelObjectLiteralWithComputedProperties(originalObjectLiteral, firstComputedPropertyIndex) { var tempVar = createAndRecordTempVariable(originalObjectLiteral); - var initialObjectLiteral = createSynthesizedNode(152); + var initialObjectLiteral = ts.createSynthesizedNode(152); initialObjectLiteral.properties = originalObjectLiteral.properties.slice(0, firstComputedPropertyIndex); - initialObjectLiteral.flags |= 256; + initialObjectLiteral.flags |= 512; var propertyPatches = createBinaryExpression(tempVar, 52, initialObjectLiteral); ts.forEach(originalObjectLiteral.properties, function (property) { var patchedProperty = tryCreatePatchingPropertyAssignment(originalObjectLiteral, tempVar, property); @@ -19116,7 +19830,7 @@ var ts; propertyPatches = createBinaryExpression(propertyPatches, 23, patchedProperty); } }); - propertyPatches = createBinaryExpression(propertyPatches, 23, tempVar); + propertyPatches = createBinaryExpression(propertyPatches, 23, createIdentifier(tempVar.text, true)); var result = createParenthesizedExpression(propertyPatches); return result; } @@ -19127,7 +19841,7 @@ var ts; function tryCreatePatchingPropertyAssignment(objectLiteral, tempVar, property) { var leftHandSide = createMemberAccessForPropertyName(tempVar, property.name); var maybeRightHandSide = tryGetRightHandSideOfPatchingPropertyAssignment(objectLiteral, property); - return maybeRightHandSide && createBinaryExpression(leftHandSide, 52, maybeRightHandSide); + return maybeRightHandSide && createBinaryExpression(leftHandSide, 52, maybeRightHandSide, true); } function tryGetRightHandSideOfPatchingPropertyAssignment(objectLiteral, property) { switch (property.kind) { @@ -19143,7 +19857,7 @@ var ts; if (firstAccessor !== property) { return undefined; } - var propertyDescriptor = createSynthesizedNode(152); + var propertyDescriptor = ts.createSynthesizedNode(152); var descriptorProperties = []; if (getAccessor) { var getProperty = createPropertyAssignment(createIdentifier("get"), createFunctionExpression(getAccessor.parameters, getAccessor.body)); @@ -19153,7 +19867,7 @@ var ts; var setProperty = createPropertyAssignment(createIdentifier("set"), createFunctionExpression(setAccessor.parameters, setAccessor.body)); descriptorProperties.push(setProperty); } - var trueExpr = createSynthesizedNode(94); + var trueExpr = ts.createSynthesizedNode(94); var enumerableTrue = createPropertyAssignment(createIdentifier("enumerable"), trueExpr); descriptorProperties.push(enumerableTrue); var configurableTrue = createPropertyAssignment(createIdentifier("configurable"), trueExpr); @@ -19166,7 +19880,7 @@ var ts; } } function createParenthesizedExpression(expression) { - var result = createSynthesizedNode(159); + var result = ts.createSynthesizedNode(159); result.expression = expression; return result; } @@ -19180,9 +19894,9 @@ var ts; result.end = -1; return result; } - function createBinaryExpression(left, operator, right) { - var result = createSynthesizedNode(167); - result.operatorToken = createSynthesizedNode(operator); + function createBinaryExpression(left, operator, right, startsOnNewLine) { + var result = ts.createSynthesizedNode(167, startsOnNewLine); + result.operatorToken = ts.createSynthesizedNode(operator); result.left = left; result.right = right; return result; @@ -19202,36 +19916,37 @@ var ts; } } function createPropertyAssignment(name, initializer) { - var result = createSynthesizedNode(217); + var result = ts.createSynthesizedNode(217); result.name = name; result.initializer = initializer; return result; } function createFunctionExpression(parameters, body) { - var result = createSynthesizedNode(160); + var result = ts.createSynthesizedNode(160); result.parameters = parameters; result.body = body; return result; } function createPropertyAccessExpression(expression, name) { - var result = createSynthesizedNode(153); + var result = ts.createSynthesizedNode(153); result.expression = expression; + result.dotToken = ts.createSynthesizedNode(20); result.name = name; return result; } function createElementAccessExpression(expression, argumentExpression) { - var result = createSynthesizedNode(154); + var result = ts.createSynthesizedNode(154); result.expression = expression; result.argumentExpression = argumentExpression; return result; } - function createIdentifier(name) { - var result = createSynthesizedNode(64); + function createIdentifier(name, startsOnNewLine) { + var result = ts.createSynthesizedNode(64, startsOnNewLine); result.text = name; return result; } function createCallExpression(invokedExpression, arguments) { - var result = createSynthesizedNode(155); + var result = ts.createSynthesizedNode(155); result.expression = invokedExpression; result.arguments = arguments; return result; @@ -19296,13 +20011,29 @@ var ts; } return false; } + function indentIfOnDifferentLines(parent, node1, node2) { + var isSynthesized = ts.nodeIsSynthesized(parent); + var realNodesAreOnDifferentLines = !isSynthesized && !nodeEndIsOnSameLineAsNodeStart(node1, node2); + var synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2); + if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) { + increaseIndent(); + writeLine(); + return true; + } + return false; + } function emitPropertyAccess(node) { if (tryEmitConstantValue(node)) { return; } emit(node.expression); + var indented = indentIfOnDifferentLines(node, node.expression, node.dotToken); write("."); + indented = indented || indentIfOnDifferentLines(node, node.dotToken, node.name); emit(node.name); + if (indented) { + decreaseIndent(); + } } function emitQualifiedName(node) { emit(node.left); @@ -19416,26 +20147,33 @@ var ts; } } function emitTaggedTemplateExpression(node) { - emit(node.tag); - write(" "); - emit(node.template); + if (compilerOptions.target >= 2) { + emit(node.tag); + write(" "); + emit(node.template); + } + else { + emitDownlevelTaggedTemplate(node); + } } function emitParenExpression(node) { - if (node.expression.kind === 158) { - var operand = node.expression.expression; - while (operand.kind == 158) { - operand = operand.expression; - } - if (operand.kind !== 165 && - operand.kind !== 164 && - operand.kind !== 163 && - operand.kind !== 162 && - operand.kind !== 166 && - operand.kind !== 156 && - !(operand.kind === 155 && node.parent.kind === 156) && - !(operand.kind === 160 && node.parent.kind === 155)) { - emit(operand); - return; + if (!node.parent || node.parent.kind !== 161) { + if (node.expression.kind === 158) { + var operand = node.expression.expression; + while (operand.kind == 158) { + operand = operand.expression; + } + if (operand.kind !== 165 && + operand.kind !== 164 && + operand.kind !== 163 && + operand.kind !== 162 && + operand.kind !== 166 && + operand.kind !== 156 && + !(operand.kind === 155 && node.parent.kind === 156) && + !(operand.kind === 160 && node.parent.kind === 155)) { + emit(operand); + return; + } } } write("("); @@ -19481,48 +20219,58 @@ var ts; } else { emit(node.left); - if (node.operatorToken.kind !== 23) { + var indented1 = indentIfOnDifferentLines(node, node.left, node.operatorToken); + if (!indented1 && node.operatorToken.kind !== 23) { write(" "); } write(ts.tokenToString(node.operatorToken.kind)); - var operatorEnd = ts.getLineAndCharacterOfPosition(currentSourceFile, node.operatorToken.end); - var rightStart = ts.getLineAndCharacterOfPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.right.pos)); - var onDifferentLine = operatorEnd.line !== rightStart.line; - if (onDifferentLine) { - var exprStart = ts.getLineAndCharacterOfPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos)); - var firstCharOfExpr = getFirstNonWhitespaceCharacterIndexOnLine(exprStart.line); - var shouldIndent = rightStart.character > firstCharOfExpr; - if (shouldIndent) { - increaseIndent(); - } - writeLine(); + if (!indented1) { + var indented2 = indentIfOnDifferentLines(node, node.operatorToken, node.right); } - else { + if (!indented2) { write(" "); } emit(node.right); - if (shouldIndent) { + if (indented1 || indented2) { decreaseIndent(); } } } - function getFirstNonWhitespaceCharacterIndexOnLine(line) { - var lineStart = ts.getLineStarts(currentSourceFile)[line]; - var text = currentSourceFile.text; - for (var i = lineStart; i < text.length; i++) { - var ch = text.charCodeAt(i); - if (!ts.isWhiteSpace(text.charCodeAt(i)) || ts.isLineBreak(ch)) { - break; - } - } - return i - lineStart; + function synthesizedNodeStartsOnNewLine(node) { + return ts.nodeIsSynthesized(node) && node.startsOnNewLine; } function emitConditionalExpression(node) { emit(node.condition); - write(" ? "); + var indent1 = indentIfOnDifferentLines(node, node.condition, node.questionToken); + if (!indent1) { + write(" "); + } + write("?"); + if (!indent1) { + var indent2 = indentIfOnDifferentLines(node, node.questionToken, node.whenTrue); + } + if (!indent2) { + write(" "); + } emit(node.whenTrue); - write(" : "); + if (indent1 || indent2) { + decreaseIndent(); + } + var indent3 = indentIfOnDifferentLines(node, node.whenTrue, node.colonToken); + if (!indent3) { + write(" "); + } + write(":"); + if (!indent3) { + var indent4 = indentIfOnDifferentLines(node, node.colonToken, node.whenFalse); + } + if (!indent4) { + write(" "); + } emit(node.whenFalse); + if (indent3 || indent4) { + decreaseIndent(); + } } function isSingleLineEmptyBlock(node) { if (node && node.kind === 174) { @@ -19566,7 +20314,7 @@ var ts; } } function emitExpressionStatement(node) { - emitParenthesized(node.expression, node.expression.kind === 161); + emitParenthesizedIf(node.expression, node.expression.kind === 161); write(";"); } function emitIfStatement(node) { @@ -19607,6 +20355,30 @@ var ts; write(")"); emitEmbeddedStatement(node.statement); } + function emitStartOfVariableDeclarationList(decl, startPos) { + var tokenKind = 97; + if (decl && languageVersion >= 2) { + if (ts.isLet(decl)) { + tokenKind = 104; + } + else if (ts.isConst(decl)) { + tokenKind = 69; + } + } + if (startPos !== undefined) { + emitToken(tokenKind, startPos); + } + else { + switch (tokenKind) { + case 97: + return write("var "); + case 104: + return write("let "); + case 69: + return write("const "); + } + } + } function emitForStatement(node) { var endPos = emitToken(81, node.pos); write(" "); @@ -19614,17 +20386,9 @@ var ts; if (node.initializer && node.initializer.kind === 194) { var variableDeclarationList = node.initializer; var declarations = variableDeclarationList.declarations; - if (declarations[0] && ts.isLet(declarations[0])) { - emitToken(105, endPos); - } - else if (declarations[0] && ts.isConst(declarations[0])) { - emitToken(69, endPos); - } - else { - emitToken(97, endPos); - } + emitStartOfVariableDeclarationList(declarations[0], endPos); write(" "); - emitCommaList(variableDeclarationList.declarations); + emitCommaList(declarations); } else if (node.initializer) { emit(node.initializer); @@ -19644,12 +20408,7 @@ var ts; var variableDeclarationList = node.initializer; if (variableDeclarationList.declarations.length >= 1) { var decl = variableDeclarationList.declarations[0]; - if (ts.isLet(decl)) { - emitToken(105, endPos); - } - else { - emitToken(97, endPos); - } + emitStartOfVariableDeclarationList(decl, endPos); write(" "); emit(decl); } @@ -19748,8 +20507,8 @@ var ts; var endPos = emitToken(67, node.pos); write(" "); emitToken(16, endPos); - emit(node.name); - emitToken(17, node.name.end); + emit(node.variableDeclaration); + emitToken(17, node.variableDeclaration ? node.variableDeclaration.end : endPos); write(" "); emitBlock(node.block); } @@ -19781,8 +20540,15 @@ var ts; emitNode(node.name); emitEnd(node.name); } + function createVoidZero() { + var zero = ts.createSynthesizedNode(7); + zero.text = "0"; + var result = ts.createSynthesizedNode(164); + result.expression = zero; + return result; + } function emitExportMemberAssignments(name) { - if (exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { + if (!exportDefault && exportSpecifiers && ts.hasProperty(exportSpecifiers, name.text)) { ts.forEach(exportSpecifiers[name.text], function (specifier) { writeLine(); emitStart(specifier.name); @@ -19809,6 +20575,7 @@ var ts; if (emitCount++) { write(", "); } + renameNonTopLevelLetAndConst(name); if (name.parent && (name.parent.kind === 193 || name.parent.kind === 150)) { emitModuleMemberName(name.parent); } @@ -19829,27 +20596,25 @@ var ts; } return expr; } - function createVoidZero() { - var zero = ts.createNode(7); - zero.text = "0"; - var result = ts.createNode(164); - result.expression = zero; - return result; - } function createDefaultValueCheck(value, defaultValue) { value = ensureIdentifier(value); - var equals = ts.createNode(167); + var equals = ts.createSynthesizedNode(167); equals.left = value; - equals.operatorToken = ts.createNode(30); + equals.operatorToken = ts.createSynthesizedNode(30); equals.right = createVoidZero(); - var cond = ts.createNode(168); - cond.condition = equals; - cond.whenTrue = defaultValue; - cond.whenFalse = value; + return createConditionalExpression(equals, defaultValue, value); + } + function createConditionalExpression(condition, whenTrue, whenFalse) { + var cond = ts.createSynthesizedNode(168); + cond.condition = condition; + cond.questionToken = ts.createSynthesizedNode(50); + cond.whenTrue = whenTrue; + cond.colonToken = ts.createSynthesizedNode(51); + cond.whenFalse = whenFalse; return cond; } function createNumericLiteral(value) { - var node = ts.createNode(7); + var node = ts.createSynthesizedNode(7); node.text = "" + value; return node; } @@ -19857,7 +20622,7 @@ var ts; if (expr.kind === 64 || expr.kind === 153 || expr.kind === 154) { return expr; } - var node = ts.createNode(159); + var node = ts.createSynthesizedNode(159); node.expression = expr; return node; } @@ -19865,13 +20630,10 @@ var ts; if (propName.kind !== 64) { return createElementAccess(object, propName); } - var node = ts.createNode(153); - node.expression = parenthesizeForAccess(object); - node.name = propName; - return node; + return createPropertyAccessExpression(parenthesizeForAccess(object), propName); } function createElementAccess(object, index) { - var node = ts.createNode(154); + var node = ts.createSynthesizedNode(154); node.expression = parenthesizeForAccess(object); node.argumentExpression = index; return node; @@ -19993,8 +20755,19 @@ var ts; } } else { + var isLet = renameNonTopLevelLetAndConst(node.name); emitModuleMemberName(node); - emitOptional(" = ", node.initializer); + var initializer = node.initializer; + if (!initializer && languageVersion < 2) { + var isUninitializedLet = (resolver.getNodeCheckFlags(node) & 256) && + (getCombinedFlagsForIdentifier(node.name) & 4096); + if (isUninitializedLet && + node.parent.parent.kind !== 182 && + node.parent.parent.kind !== 183) { + initializer = createVoidZero(); + } + } + emitOptional(" = ", initializer); } } function emitExportVariableAssignments(node) { @@ -20006,17 +20779,64 @@ var ts; ts.forEach(name.elements, emitExportVariableAssignments); } } + function getEnclosingBlockScopeContainer(node) { + var current = node; + while (current) { + if (ts.isFunctionLike(current)) { + return current; + } + switch (current.kind) { + case 220: + case 91: + case 216: + case 200: + case 181: + case 182: + case 183: + return current; + case 174: + if (!ts.isFunctionLike(current.parent)) { + return current; + } + } + current = current.parent; + } + } + function getCombinedFlagsForIdentifier(node) { + if (!node.parent || (node.parent.kind !== 193 && node.parent.kind !== 150)) { + return 0; + } + return ts.getCombinedNodeFlags(node.parent); + } + function renameNonTopLevelLetAndConst(node) { + if (languageVersion >= 2 || + ts.nodeIsSynthesized(node) || + node.kind !== 64 || + (node.parent.kind !== 193 && node.parent.kind !== 150)) { + return; + } + var combinedFlags = getCombinedFlagsForIdentifier(node); + if (((combinedFlags & 12288) === 0) || combinedFlags & 1) { + return; + } + var list = ts.getAncestor(node, 194); + if (list.parent.kind === 175 && list.parent.parent.kind === 220) { + return; + } + var blockScopeContainer = getEnclosingBlockScopeContainer(node); + var parent = blockScopeContainer.kind === 220 + ? blockScopeContainer + : blockScopeContainer.parent; + var generatedName = generateUniqueNameForLocation(parent, node.text); + var variableId = resolver.getBlockScopedVariableId(node); + if (!generatedBlockScopeNames) { + generatedBlockScopeNames = []; + } + generatedBlockScopeNames[variableId] = generatedName; + } function emitVariableStatement(node) { if (!(node.flags & 1)) { - if (ts.isLet(node.declarationList)) { - write("let "); - } - else if (ts.isConst(node.declarationList)) { - write("const "); - } - else { - write("var "); - } + emitStartOfVariableDeclarationList(node.declarationList); } emitCommaList(node.declarationList.declarations); write(";"); @@ -20121,6 +20941,14 @@ var ts; function shouldEmitAsArrowFunction(node) { return node.kind === 161 && languageVersion >= 2; } + function emitDeclarationName(node) { + if (node.name) { + emitNode(node.name); + } + else { + write(resolver.getGeneratedNameForNode(node)); + } + } function emitFunctionDeclaration(node) { if (ts.nodeIsMissing(node.body)) { return emitPinnedOrTripleSlashComments(node); @@ -20132,10 +20960,10 @@ var ts; write("function "); } if (node.kind === 195 || (node.kind === 160 && node.name)) { - emit(node.name); + emitDeclarationName(node); } emitSignatureAndBody(node); - if (languageVersion < 2 && node.kind === 195 && node.parent === currentSourceFile) { + if (languageVersion < 2 && node.kind === 195 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } if (node.kind !== 132 && node.kind !== 131) { @@ -20175,6 +21003,7 @@ var ts; tempCount = 0; tempVariables = undefined; tempParameters = undefined; + var popFrame = enterNameScope(); if (shouldEmitAsArrowFunction(node)) { emitSignatureParametersForArrow(node); write(" =>"); @@ -20191,15 +21020,16 @@ var ts; else { emitExpressionFunctionBody(node, node.body); } - if (node.flags & 1) { + if (node.flags & 1 && !(node.flags & 256)) { writeLine(); emitStart(node); emitModuleMemberName(node); write(" = "); - emit(node.name); + emitDeclarationName(node); emitEnd(node); write(";"); } + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; @@ -20215,7 +21045,11 @@ var ts; return; } write(" "); - emit(body); + var current = body; + while (current.kind === 158) { + current = current.expression; + } + emitParenthesizedIf(body, current.kind === 152); } function emitDownLevelExpressionFunctionBody(node, body) { write(" {"); @@ -20254,45 +21088,15 @@ var ts; scopeEmitEnd(); } function emitBlockFunctionBody(node, body) { - if (body.statements.length === 0 && !anyParameterHasBindingPatternOrInitializer(node)) { - emitFunctionBodyWithNoStatements(node, body); - } - else { - emitFunctionBodyWithStatements(node, body); - } - } - function anyParameterHasBindingPatternOrInitializer(func) { - return ts.forEach(func.parameters, hasBindingPatternOrInitializer); - } - function hasBindingPatternOrInitializer(parameter) { - return parameter.initializer || ts.isBindingPattern(parameter.name); - } - function emitFunctionBodyWithNoStatements(node, body) { - var singleLine = isSingleLineEmptyBlock(node.body); - write(" {"); - if (singleLine) { - write(" "); - } - else { - increaseIndent(); - writeLine(); - } - emitLeadingCommentsOfPosition(body.statements.end); - if (!singleLine) { - decreaseIndent(); - } - emitToken(15, body.statements.end); - } - function emitFunctionBodyWithStatements(node, body) { write(" {"); scopeEmitStart(node); - var outPos = writer.getTextPos(); + var initialTextPos = writer.getTextPos(); increaseIndent(); emitDetachedComments(body.statements); var startIndex = emitDirectivePrologues(body.statements, true); emitFunctionBodyPreamble(node); decreaseIndent(); - var preambleEmitted = writer.getTextPos() !== outPos; + var preambleEmitted = writer.getTextPos() !== initialTextPos; if (!preambleEmitted && nodeEndIsOnSameLineAsNodeStart(body, body)) { for (var i = 0, n = body.statements.length; i < n; i++) { write(" "); @@ -20365,7 +21169,7 @@ var ts; emitStart(member); emitStart(member.name); if (staticFlag) { - emitNode(node.name); + emitDeclarationName(node); } else { write("this"); @@ -20390,7 +21194,7 @@ var ts; emitLeadingComments(member); emitStart(member); emitStart(member.name); - emitNode(node.name); + emitDeclarationName(node); if (!(member.flags & 128)) { write(".prototype"); } @@ -20411,7 +21215,7 @@ var ts; emitStart(member); write("Object.defineProperty("); emitStart(member.name); - emitNode(node.name); + emitDeclarationName(node); if (!(member.flags & 128)) { write(".prototype"); } @@ -20456,7 +21260,7 @@ var ts; } function emitClassDeclaration(node) { write("var "); - emit(node.name); + emitDeclarationName(node); write(" = (function ("); var baseTypeNode = ts.getClassBaseTypeNode(node); if (baseTypeNode) { @@ -20469,7 +21273,7 @@ var ts; writeLine(); emitStart(baseTypeNode); write("__extends("); - emit(node.name); + emitDeclarationName(node); write(", _super);"); emitEnd(baseTypeNode); } @@ -20478,11 +21282,10 @@ var ts; emitMemberFunctions(node); emitMemberAssignments(node, 128); writeLine(); - function emitClassReturnStatement() { + emitToken(15, node.members.end, function () { write("return "); - emitNode(node.name); - } - emitToken(15, node.members.end, emitClassReturnStatement); + emitDeclarationName(node); + }); write(";"); decreaseIndent(); writeLine(); @@ -20495,16 +21298,16 @@ var ts; } write(");"); emitEnd(node); - if (node.flags & 1) { + if (node.flags & 1 && !(node.flags & 256)) { writeLine(); emitStart(node); emitModuleMemberName(node); write(" = "); - emit(node.name); + emitDeclarationName(node); emitEnd(node); write(";"); } - if (languageVersion < 2 && node.parent === currentSourceFile) { + if (languageVersion < 2 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } function emitConstructorOfClass() { @@ -20514,6 +21317,7 @@ var ts; tempCount = 0; tempVariables = undefined; tempParameters = undefined; + var popFrame = enterNameScope(); ts.forEach(node.members, function (member) { if (member.kind === 133 && !member.body) { emitPinnedOrTripleSlashComments(member); @@ -20525,7 +21329,7 @@ var ts; } emitStart(ctor || node); write("function "); - emit(node.name); + emitDeclarationName(node); emitSignatureParameters(ctor); write(" {"); scopeEmitStart(node, "constructor"); @@ -20573,6 +21377,7 @@ var ts; if (ctor) { emitTrailingComments(ctor); } + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; @@ -20691,7 +21496,9 @@ var ts; var saveTempVariables = tempVariables; tempCount = 0; tempVariables = undefined; + var popFrame = enterNameScope(); emit(node.body); + exitNameScope(popFrame); tempCount = saveTempCount; tempVariables = saveTempVariables; } @@ -20780,7 +21587,7 @@ var ts; emitImportDeclaration(node); return; } - if (resolver.isReferencedImportDeclaration(node) || + if (resolver.isReferencedAliasDeclaration(node) || (!ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { emitLeadingComments(node); emitStart(node); @@ -20876,17 +21683,29 @@ var ts; function createExternalModuleInfo(sourceFile) { externalImports = []; exportSpecifiers = {}; + exportDefault = undefined; ts.forEach(sourceFile.statements, function (node) { if (node.kind === 209 && !node.moduleSpecifier) { ts.forEach(node.exportClause.elements, function (specifier) { + if (specifier.name.text === "default") { + exportDefault = exportDefault || specifier; + } var name = (specifier.propertyName || specifier.name).text; (exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier); }); } + else if (node.kind === 208) { + exportDefault = exportDefault || node; + } + else if (node.kind === 195 || node.kind === 196) { + if (node.flags & 1 && node.flags & 256) { + exportDefault = exportDefault || node; + } + } else { var info = createExternalImportInfo(node); if (info) { - if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedImportDeclaration(node)) { + if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedAliasDeclaration(node)) { externalImports.push(info); } } @@ -20967,18 +21786,7 @@ var ts; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(true); - var exportName = resolver.getExportAssignmentName(node); - if (exportName) { - writeLine(); - var exportAssignment = getFirstExportAssignment(node); - emitStart(exportAssignment); - write("return "); - emitStart(exportAssignment.exportName); - write(exportName); - emitEnd(exportAssignment.exportName); - write(";"); - emitEnd(exportAssignment); - } + emitExportDefault(node, true); decreaseIndent(); writeLine(); write("});"); @@ -20987,17 +21795,24 @@ var ts; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(true); - var exportName = resolver.getExportAssignmentName(node); - if (exportName) { + emitExportDefault(node, false); + } + function emitExportDefault(sourceFile, emitAsReturn) { + if (exportDefault && resolver.hasExportDefaultValue(sourceFile)) { writeLine(); - var exportAssignment = getFirstExportAssignment(node); - emitStart(exportAssignment); - write("module.exports = "); - emitStart(exportAssignment.exportName); - write(exportName); - emitEnd(exportAssignment.exportName); + emitStart(exportDefault); + write(emitAsReturn ? "return " : "module.exports = "); + if (exportDefault.kind === 208) { + emit(exportDefault.expression); + } + else if (exportDefault.kind === 211) { + emit(exportDefault.propertyName); + } + else { + emitDeclarationName(exportDefault); + } write(";"); - emitEnd(exportAssignment); + emitEnd(exportDefault); } } function emitDirectivePrologues(statements, startWithNewLine) { @@ -21048,6 +21863,7 @@ var ts; else { externalImports = undefined; exportSpecifiers = undefined; + exportDefault = undefined; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(true); @@ -21367,6 +22183,7 @@ var ts; var ts; (function (ts) { ts.emitTime = 0; + ts.ioReadTime = 0; function createCompilerHost(options) { var currentDirectory; var existingDirectories = {}; @@ -21376,11 +22193,15 @@ var ts; var unsupportedFileEncodingErrorCode = -2147024809; function getSourceFile(fileName, languageVersion, onError) { try { + var start = new Date().getTime(); var text = ts.sys.readFile(fileName, options.charset); + ts.ioReadTime += new Date().getTime() - start; } catch (e) { if (onError) { - onError(e.number === unsupportedFileEncodingErrorCode ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText : e.message); + onError(e.number === unsupportedFileEncodingErrorCode + ? ts.createCompilerDiagnostic(ts.Diagnostics.Unsupported_file_encoding).messageText + : e.message); } text = ""; } @@ -21513,8 +22334,9 @@ var ts; if (options.noEmitOnError && getPreEmitDiagnostics(this).length > 0) { return { diagnostics: [], sourceMaps: undefined, emitSkipped: true }; } + var emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); var start = new Date().getTime(); - var emitResult = ts.emitFiles(getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile), getEmitHost(writeFileCallback), sourceFile); + var emitResult = ts.emitFiles(emitResolver, getEmitHost(writeFileCallback), sourceFile); ts.emitTime += new Date().getTime() - start; return emitResult; } @@ -21703,20 +22525,19 @@ var ts; } return; } - var firstExternalModule = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); - if (firstExternalModule && !options.module) { - var externalModuleErrorSpan = ts.getErrorSpanForNode(firstExternalModule.externalModuleIndicator); - var errorStart = ts.skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos); - var errorLength = externalModuleErrorSpan.end - errorStart; - diagnostics.add(ts.createFileDiagnostic(firstExternalModule, errorStart, errorLength, ts.Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); + if (firstExternalModuleSourceFile && !options.module) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + diagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); } if (options.outDir || options.sourceRoot || (options.mapRoot && - (!options.out || firstExternalModule !== undefined))) { + (!options.out || firstExternalModuleSourceFile !== undefined))) { var commonPathComponents; ts.forEach(files, function (sourceFile) { - if (!(sourceFile.flags & 1024) && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { + if (!(sourceFile.flags & 2048) + && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, host.getCurrentDirectory()); sourcePathComponents.pop(); if (commonPathComponents) { @@ -22383,6 +23204,27 @@ var ts; case 149: ts.forEach(node.elements, visit); break; + case 209: + if (node.exportClause) { + ts.forEach(node.exportClause.elements, visit); + } + break; + case 203: + var importClause = node.importClause; + if (importClause) { + if (importClause.name) { + childNodes.push(importClause); + } + if (importClause.namedBindings) { + if (importClause.namedBindings.kind === 205) { + childNodes.push(importClause.namedBindings); + } + else { + ts.forEach(importClause.namedBindings.elements, visit); + } + } + } + break; case 150: case 193: if (ts.isBindingPattern(node.name)) { @@ -22394,7 +23236,11 @@ var ts; case 197: case 200: case 195: + case 202: + case 207: + case 211: childNodes.push(node); + break; } } ts.forEach(nodes, visit); @@ -22507,7 +23353,7 @@ var ts; if (ts.isBindingPattern(node.name)) { break; } - if ((node.flags & 243) === 0) { + if ((node.flags & 499) === 0) { return undefined; } return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); @@ -22559,6 +23405,12 @@ var ts; } case 133: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); + case 211: + case 207: + case 202: + case 204: + case 205: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.alias); } return undefined; function createItem(node, name, scriptElementKind) { @@ -22631,10 +23483,15 @@ var ts; return undefined; } hasGlobalNode = true; - var rootName = ts.isExternalModule(node) ? "\"" + ts.escapeString(ts.getBaseFileName(ts.removeFileExtension(ts.normalizePath(node.fileName)))) + "\"" : ""; + var rootName = ts.isExternalModule(node) + ? "\"" + ts.escapeString(ts.getBaseFileName(ts.removeFileExtension(ts.normalizePath(node.fileName)))) + "\"" + : ""; return getNavigationBarItem(rootName, ts.ScriptElementKind.moduleElement, ts.ScriptElementKindModifier.none, [getNodeSpan(node)], childItems); } function createClassItem(node) { + if (!node.name) { + return undefined; + } var childItems; if (node.members) { var constructor = ts.forEach(node.members, function (member) { @@ -22670,7 +23527,9 @@ var ts; return node; } function getNodeSpan(node) { - return node.kind === 220 ? ts.createTextSpanFromBounds(node.getFullStart(), node.getEnd()) : ts.createTextSpanFromBounds(node.getStart(), node.getEnd()); + return node.kind === 220 + ? ts.createTextSpanFromBounds(node.getFullStart(), node.getEnd()) + : ts.createTextSpanFromBounds(node.getStart(), node.getEnd()); } function getTextOfNode(node) { return ts.getTextOfNodeFromSourceText(sourceFile.text, node); @@ -23124,7 +23983,9 @@ var ts; function transitionFromLowerToUpper(identifier, word, index) { var lastIsUpper = isUpperCaseLetter(identifier.charCodeAt(index - 1)); var currentIsUpper = isUpperCaseLetter(identifier.charCodeAt(index)); - var transition = word ? (currentIsUpper && !lastIsUpper) : currentIsUpper; + var transition = word + ? (currentIsUpper && !lastIsUpper) + : currentIsUpper; return transition; } })(ts || (ts = {})); @@ -23178,12 +24039,14 @@ var ts; var list = listItemInfo.list; var isTypeArgList = callExpression.typeArguments && callExpression.typeArguments.pos === list.pos; var argumentIndex = (listItemInfo.listItemIndex + 1) >> 1; + var argumentCount = getCommaBasedArgCount(list); + ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex); return { kind: isTypeArgList ? 0 : 1, invocation: callExpression, argumentsSpan: getApplicableSpanForArguments(list), argumentIndex: argumentIndex, - argumentCount: getCommaBasedArgCount(list) + argumentCount: argumentCount }; } } @@ -23214,7 +24077,9 @@ var ts; return undefined; } function getCommaBasedArgCount(argumentsList) { - return argumentsList.getChildCount() === 0 ? 0 : 1 + ts.countWhere(argumentsList.getChildren(), function (arg) { return arg.kind === 23; }); + return argumentsList.getChildCount() === 0 + ? 0 + : 1 + ts.countWhere(argumentsList.getChildren(), function (arg) { return arg.kind === 23; }); } function getArgumentIndexForTemplatePiece(spanIndex, node) { ts.Debug.assert(position >= node.getStart(), "Assumed 'position' could not occur before node."); @@ -23227,7 +24092,10 @@ var ts; return spanIndex + 1; } function getArgumentListInfoForTemplate(tagExpression, argumentIndex) { - var argumentCount = tagExpression.template.kind === 10 ? 1 : tagExpression.template.templateSpans.length + 1; + var argumentCount = tagExpression.template.kind === 10 + ? 1 + : tagExpression.template.templateSpans.length + 1; + ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex); return { kind: 2, invocation: tagExpression, @@ -23342,6 +24210,7 @@ var ts; if (selectedItemIndex < 0) { selectedItemIndex = selectBestInvalidOverloadIndex(candidates, argumentCount); } + ts.Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount, "argumentCount < argumentIndex, " + argumentCount + " < " + argumentIndex); return { items: items, applicableSpan: applicableSpan, @@ -23511,7 +24380,7 @@ var ts; for (var i = 0, len = children.length; i < len; ++i) { var child = children[i]; var shouldDiveInChildNode = (child.pos <= previousToken.pos && child.end > previousToken.end) || - (child.pos === previousToken.end); + (child.pos === previousToken.end); if (shouldDiveInChildNode && nodeHasTokens(child)) { return find(child); } @@ -23589,7 +24458,7 @@ var ts; if (node.kind === 139 || node.kind === 155) { return node.typeArguments; } - if (ts.isAnyFunction(node) || node.kind === 196 || node.kind === 197) { + if (ts.isFunctionLike(node) || node.kind === 196 || node.kind === 197) { return node.typeParameters; } return undefined; @@ -23614,7 +24483,8 @@ var ts; } ts.isPunctuation = isPunctuation; function isInsideTemplateLiteral(node, position) { - return ts.isTemplateLiteralKind(node.kind) && (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd()); + return ts.isTemplateLiteralKind(node.kind) + && (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd()); } ts.isInsideTemplateLiteral = isInsideTemplateLiteral; function compareDataObjects(dst, src) { @@ -23895,7 +24765,13 @@ var ts; token: undefined }; } - var expectedScanAction = shouldRescanGreaterThanToken(n) ? 1 : shouldRescanSlashToken(n) ? 2 : shouldRescanTemplateToken(n) ? 3 : 0; + var expectedScanAction = shouldRescanGreaterThanToken(n) + ? 1 + : shouldRescanSlashToken(n) + ? 2 + : shouldRescanTemplateToken(n) + ? 3 + : 0; if (lastTokenInfo && expectedScanAction === lastScanAction) { return fixTokenKind(lastTokenInfo, n); } @@ -24246,7 +25122,7 @@ var ts; this.SpaceAfterSubtractWhenFollowedByPredecrement = new formatting.Rule(formatting.RuleDescriptor.create1(34, 39), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.NoSpaceBeforeComma = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 23), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceAfterCertainKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([97, 93, 87, 73, 89, 96]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([105, 69]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2)); + this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([104, 69]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8)); this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(82, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionDeclContext), 8)); @@ -24254,13 +25130,13 @@ var ts; this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(89, 22), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceBetweenStatements = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([17, 74, 75, 66]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotForContext), 2)); this.SpaceAfterTryFinally = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([95, 80]), 14), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([116, 120]), 64), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); + this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([115, 119]), 64), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); this.SpaceBeforeBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.BinaryKeywordOperators), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); - this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(114, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([117, 118]), 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([68, 115, 76, 77, 78, 116, 103, 84, 104, 117, 107, 109, 120, 110]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([78, 103])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(113, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([116, 117]), 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([68, 114, 76, 77, 78, 115, 102, 84, 103, 116, 106, 108, 119, 109]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([78, 102])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(8, 14), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2)); this.SpaceAfterArrow = new formatting.Rule(formatting.RuleDescriptor.create3(32, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.NoSpaceAfterEllipsis = new formatting.Rule(formatting.RuleDescriptor.create1(21, 64), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); @@ -24272,52 +25148,52 @@ var ts; this.NoSpaceAfterCloseAngularBracket = new formatting.Rule(formatting.RuleDescriptor.create3(25, formatting.Shared.TokenRange.FromTokens([16, 18, 25, 23])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsTypeArgumentOrParameterContext), 8)); this.NoSpaceBetweenEmptyInterfaceBraceBrackets = new formatting.Rule(formatting.RuleDescriptor.create1(14, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsObjectTypeContext), 8)); this.HighPriorityCommonRules = - [ - this.IgnoreBeforeComment, this.IgnoreAfterLineComment, - this.NoSpaceBeforeColon, this.SpaceAfterColon, this.NoSpaceBeforeQuestionMark, this.SpaceAfterQuestionMarkInConditionalOperator, - this.NoSpaceAfterQuestionMark, - this.NoSpaceBeforeDot, this.NoSpaceAfterDot, - this.NoSpaceAfterUnaryPrefixOperator, - this.NoSpaceAfterUnaryPreincrementOperator, this.NoSpaceAfterUnaryPredecrementOperator, - this.NoSpaceBeforeUnaryPostincrementOperator, this.NoSpaceBeforeUnaryPostdecrementOperator, - this.SpaceAfterPostincrementWhenFollowedByAdd, - this.SpaceAfterAddWhenFollowedByUnaryPlus, this.SpaceAfterAddWhenFollowedByPreincrement, - this.SpaceAfterPostdecrementWhenFollowedBySubtract, - this.SpaceAfterSubtractWhenFollowedByUnaryMinus, this.SpaceAfterSubtractWhenFollowedByPredecrement, - this.NoSpaceAfterCloseBrace, - this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext, - this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets, - this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember, - this.NoSpaceBetweenReturnAndSemicolon, - this.SpaceAfterCertainKeywords, - this.SpaceAfterLetConstInVariableDeclaration, - this.NoSpaceBeforeOpenParenInFuncCall, - this.SpaceBeforeBinaryKeywordOperator, this.SpaceAfterBinaryKeywordOperator, - this.SpaceAfterVoidOperator, - this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, - this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, - this.SpaceAfterModuleName, - this.SpaceAfterArrow, - this.NoSpaceAfterEllipsis, - this.NoSpaceAfterOptionalParameters, - this.NoSpaceBetweenEmptyInterfaceBraceBrackets, - this.NoSpaceBeforeOpenAngularBracket, - this.NoSpaceBetweenCloseParenAndAngularBracket, - this.NoSpaceAfterOpenAngularBracket, - this.NoSpaceBeforeCloseAngularBracket, - this.NoSpaceAfterCloseAngularBracket - ]; + [ + this.IgnoreBeforeComment, this.IgnoreAfterLineComment, + this.NoSpaceBeforeColon, this.SpaceAfterColon, this.NoSpaceBeforeQuestionMark, this.SpaceAfterQuestionMarkInConditionalOperator, + this.NoSpaceAfterQuestionMark, + this.NoSpaceBeforeDot, this.NoSpaceAfterDot, + this.NoSpaceAfterUnaryPrefixOperator, + this.NoSpaceAfterUnaryPreincrementOperator, this.NoSpaceAfterUnaryPredecrementOperator, + this.NoSpaceBeforeUnaryPostincrementOperator, this.NoSpaceBeforeUnaryPostdecrementOperator, + this.SpaceAfterPostincrementWhenFollowedByAdd, + this.SpaceAfterAddWhenFollowedByUnaryPlus, this.SpaceAfterAddWhenFollowedByPreincrement, + this.SpaceAfterPostdecrementWhenFollowedBySubtract, + this.SpaceAfterSubtractWhenFollowedByUnaryMinus, this.SpaceAfterSubtractWhenFollowedByPredecrement, + this.NoSpaceAfterCloseBrace, + this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext, + this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets, + this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember, + this.NoSpaceBetweenReturnAndSemicolon, + this.SpaceAfterCertainKeywords, + this.SpaceAfterLetConstInVariableDeclaration, + this.NoSpaceBeforeOpenParenInFuncCall, + this.SpaceBeforeBinaryKeywordOperator, this.SpaceAfterBinaryKeywordOperator, + this.SpaceAfterVoidOperator, + this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, + this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, + this.SpaceAfterModuleName, + this.SpaceAfterArrow, + this.NoSpaceAfterEllipsis, + this.NoSpaceAfterOptionalParameters, + this.NoSpaceBetweenEmptyInterfaceBraceBrackets, + this.NoSpaceBeforeOpenAngularBracket, + this.NoSpaceBetweenCloseParenAndAngularBracket, + this.NoSpaceAfterOpenAngularBracket, + this.NoSpaceBeforeCloseAngularBracket, + this.NoSpaceAfterCloseAngularBracket + ]; this.LowPriorityCommonRules = - [ - this.NoSpaceBeforeSemicolon, - this.SpaceBeforeOpenBraceInControl, this.SpaceBeforeOpenBraceInFunction, this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock, - this.NoSpaceBeforeComma, - this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterOpenBracket, - this.NoSpaceBeforeCloseBracket, this.NoSpaceAfterCloseBracket, - this.SpaceAfterSemicolon, - this.NoSpaceBeforeOpenParenInFuncDecl, - this.SpaceBetweenStatements, this.SpaceAfterTryFinally - ]; + [ + this.NoSpaceBeforeSemicolon, + this.SpaceBeforeOpenBraceInControl, this.SpaceBeforeOpenBraceInFunction, this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock, + this.NoSpaceBeforeComma, + this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterOpenBracket, + this.NoSpaceBeforeCloseBracket, this.NoSpaceAfterCloseBracket, + this.SpaceAfterSemicolon, + this.NoSpaceBeforeOpenParenInFuncDecl, + this.SpaceBetweenStatements, this.SpaceAfterTryFinally + ]; this.SpaceAfterComma = new formatting.Rule(formatting.RuleDescriptor.create3(23, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.NoSpaceAfterComma = new formatting.Rule(formatting.RuleDescriptor.create3(23, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceBeforeBinaryOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.BinaryOperators), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsBinaryOpContext), 2)); @@ -24645,13 +25521,19 @@ var ts; RulesBucket.prototype.AddRule = function (rule, specificTokens, constructionState, rulesBucketIndex) { var position; if (rule.Operation.Action == 1) { - position = specificTokens ? 0 : RulesPosition.IgnoreRulesAny; + position = specificTokens ? + 0 : + RulesPosition.IgnoreRulesAny; } else if (!rule.Operation.Context.IsAny()) { - position = specificTokens ? RulesPosition.ContextRulesSpecific : RulesPosition.ContextRulesAny; + position = specificTokens ? + RulesPosition.ContextRulesSpecific : + RulesPosition.ContextRulesAny; } else { - position = specificTokens ? RulesPosition.NoContextRulesSpecific : RulesPosition.NoContextRulesAny; + position = specificTokens ? + RulesPosition.NoContextRulesSpecific : + RulesPosition.NoContextRulesAny; } var state = constructionState[rulesBucketIndex]; if (state === undefined) { @@ -24773,7 +25655,7 @@ var ts; TokenRange.UnaryPredecrementExpressions = TokenRange.FromTokens([64, 16, 92, 87]); TokenRange.UnaryPostdecrementExpressions = TokenRange.FromTokens([64, 17, 19, 87]); TokenRange.Comments = TokenRange.FromTokens([2, 3]); - TokenRange.TypeNames = TokenRange.FromTokens([64, 119, 121, 113, 122, 98, 112]); + TokenRange.TypeNames = TokenRange.FromTokens([64, 118, 120, 112, 121, 98, 111]); return TokenRange; })(); Shared.TokenRange = TokenRange; @@ -24970,7 +25852,9 @@ var ts; if (!errors.length) { return rangeHasNoErrors; } - var sorted = errors.filter(function (d) { return ts.rangeOverlapsWithStartEnd(originalRange, d.start, d.start + d.length); }).sort(function (e1, e2) { return e1.start - e2.start; }); + var sorted = errors + .filter(function (d) { return ts.rangeOverlapsWithStartEnd(originalRange, d.start, d.start + d.length); }) + .sort(function (e1, e2) { return e1.start - e2.start; }); if (!sorted.length) { return rangeHasNoErrors; } @@ -25340,8 +26224,8 @@ var ts; } } trimTrailingWhitespaces = - (rule.Operation.Action & (4 | 2)) && - rule.Flag !== 1; + (rule.Operation.Action & (4 | 2)) && + rule.Flag !== 1; } else { trimTrailingWhitespaces = true; @@ -25396,7 +26280,9 @@ var ts; var delta = indentation - nonWhitespaceColumnInFirstPart.column; for (var i = startIndex, len = parts.length; i < len; ++i, ++startLine) { var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile); - var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart : formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options); + var nonWhitespaceCharacterAndColumn = i === 0 + ? nonWhitespaceColumnInFirstPart + : formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(parts[i].pos, parts[i].end, sourceFile, options); var newIndentation = nonWhitespaceCharacterAndColumn.column + delta; if (newIndentation > 0) { var indentationString = getIndentationString(newIndentation, options); @@ -25567,6 +26453,10 @@ var ts; (function (formatting) { var SmartIndenter; (function (SmartIndenter) { + var Value; + (function (Value) { + Value[Value["Unknown"] = -1] = "Unknown"; + })(Value || (Value = {})); function getIndentation(position, sourceFile, options) { if (position > sourceFile.text.length) { return 0; @@ -25576,11 +26466,11 @@ var ts; return 0; } var precedingTokenIsLiteral = precedingToken.kind === 8 || - precedingToken.kind === 9 || - precedingToken.kind === 10 || - precedingToken.kind === 11 || - precedingToken.kind === 12 || - precedingToken.kind === 13; + precedingToken.kind === 9 || + precedingToken.kind === 10 || + precedingToken.kind === 11 || + precedingToken.kind === 12 || + precedingToken.kind === 13; if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { return 0; } @@ -25641,7 +26531,7 @@ var ts; } parentStart = getParentStart(parent, current, sourceFile); var parentAndChildShareLine = parentStart.line === currentStart.line || - childStartsOnTheSameLineWithElseInIfStatement(parent, current, currentStart.line, sourceFile); + childStartsOnTheSameLineWithElseInIfStatement(parent, current, currentStart.line, sourceFile); if (useActualIndentation) { var actualIndentation = getActualIndentationForNode(current, parent, currentStart, parentAndChildShareLine, sourceFile, options); if (actualIndentation !== -1) { @@ -25666,12 +26556,16 @@ var ts; } function getActualIndentationForListItemBeforeComma(commaToken, sourceFile, options) { var commaItemInfo = ts.findListItemInfo(commaToken); - ts.Debug.assert(commaItemInfo && commaItemInfo.listItemIndex > 0); - return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options); + if (commaItemInfo && commaItemInfo.listItemIndex > 0) { + return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options); + } + else { + return -1; + } } function getActualIndentationForNode(current, parent, currentLineAndChar, parentAndChildShareLine, sourceFile, options) { var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && - (parent.kind === 220 || !parentAndChildShareLine); + (parent.kind === 220 || !parentAndChildShareLine); if (!useActualIndentation) { return -1; } @@ -25998,13 +26892,13 @@ var ts; while (pos < end) { var token = scanner.scan(); var textPos = scanner.getTextPos(); - nodes.push(createNode(token, pos, textPos, 512, this)); + nodes.push(createNode(token, pos, textPos, 1024, this)); pos = textPos; } return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(221, nodes.pos, nodes.end, 512, this); + var list = createNode(221, nodes.pos, nodes.end, 1024, this); list._children = []; var pos = nodes.pos; for (var i = 0, len = nodes.length; i < len; i++) { @@ -26426,7 +27320,9 @@ var ts; case 131: var functionDeclaration = node; if (functionDeclaration.name && functionDeclaration.name.getFullWidth() > 0) { - var lastDeclaration = namedDeclarations.length > 0 ? namedDeclarations[namedDeclarations.length - 1] : undefined; + var lastDeclaration = namedDeclarations.length > 0 ? + namedDeclarations[namedDeclarations.length - 1] : + undefined; if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) { if (functionDeclaration.body && !lastDeclaration.body) { namedDeclarations[namedDeclarations.length - 1] = functionDeclaration; @@ -26444,6 +27340,11 @@ var ts; case 199: case 200: case 202: + case 211: + case 207: + case 202: + case 204: + case 205: case 134: case 135: case 143: @@ -26478,6 +27379,27 @@ var ts; case 129: namedDeclarations.push(node); break; + case 209: + if (node.exportClause) { + ts.forEach(node.exportClause.elements, visit); + } + break; + case 203: + var importClause = node.importClause; + if (importClause) { + if (importClause.name) { + namedDeclarations.push(importClause); + } + if (importClause.namedBindings) { + if (importClause.namedBindings.kind === 205) { + namedDeclarations.push(importClause.namedBindings); + } + else { + ts.forEach(importClause.namedBindings.elements, visit); + } + } + } + break; } }); this.namedDeclarations = namedDeclarations; @@ -26798,7 +27720,7 @@ var ts; var entry = entries[i]; sourceFiles.push({ name: i, - refCount: entry.refCount, + refCount: entry.languageServiceRefCount, references: entry.owners.slice(0) }); } @@ -26811,34 +27733,40 @@ var ts; return JSON.stringify(bucketInfoArray, null, 2); } function acquireDocument(fileName, compilationSettings, scriptSnapshot, version) { + return acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, true); + } + function updateDocument(fileName, compilationSettings, scriptSnapshot, version) { + return acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, false); + } + function acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, acquiring) { var bucket = getBucketForCompilationSettings(compilationSettings, true); var entry = ts.lookUp(bucket, fileName); if (!entry) { + ts.Debug.assert(acquiring, "How could we be trying to update a document that the registry doesn't have?"); var sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, compilationSettings.target, version, false); bucket[fileName] = entry = { sourceFile: sourceFile, - refCount: 0, + languageServiceRefCount: 0, owners: [] }; } - entry.refCount++; - return entry.sourceFile; - } - function updateDocument(sourceFile, fileName, compilationSettings, scriptSnapshot, version, textChangeRange) { - var bucket = getBucketForCompilationSettings(compilationSettings, false); - ts.Debug.assert(bucket !== undefined); - var entry = ts.lookUp(bucket, fileName); - ts.Debug.assert(entry !== undefined); - entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, textChangeRange); + else { + if (entry.sourceFile.version !== version) { + entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot)); + } + } + if (acquiring) { + entry.languageServiceRefCount++; + } return entry.sourceFile; } function releaseDocument(fileName, compilationSettings) { var bucket = getBucketForCompilationSettings(compilationSettings, false); ts.Debug.assert(bucket !== undefined); var entry = ts.lookUp(bucket, fileName); - entry.refCount--; - ts.Debug.assert(entry.refCount >= 0); - if (entry.refCount === 0) { + entry.languageServiceRefCount--; + ts.Debug.assert(entry.languageServiceRefCount >= 0); + if (entry.languageServiceRefCount === 0) { delete bucket[fileName]; } } @@ -26869,31 +27797,111 @@ var ts; } }); } + function recordModuleName() { + var importPath = scanner.getTokenValue(); + var pos = scanner.getTokenPos(); + importedFiles.push({ + fileName: importPath, + pos: pos, + end: pos + importPath.length + }); + } function processImport() { scanner.setText(sourceText); var token = scanner.scan(); while (token !== 1) { if (token === 84) { token = scanner.scan(); - if (token === 64) { - token = scanner.scan(); - if (token === 52) { + if (token === 8) { + recordModuleName(); + continue; + } + else { + if (token === 64) { token = scanner.scan(); - if (token === 118) { + if (token === 123) { token = scanner.scan(); - if (token === 16) { + if (token === 8) { + recordModuleName(); + continue; + } + } + else if (token === 52) { + token = scanner.scan(); + if (token === 117) { token = scanner.scan(); - if (token === 8) { - var importPath = scanner.getTokenValue(); - var pos = scanner.getTokenPos(); - importedFiles.push({ - fileName: importPath, - pos: pos, - end: pos + importPath.length - }); + if (token === 16) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + continue; + } } } } + else if (token === 23) { + token = scanner.scan(); + } + else { + continue; + } + } + if (token === 14) { + token = scanner.scan(); + while (token !== 15) { + token = scanner.scan(); + } + if (token === 15) { + token = scanner.scan(); + if (token === 123) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + } + } + } + } + else if (token === 35) { + token = scanner.scan(); + if (token === 101) { + token = scanner.scan(); + if (token === 64) { + token = scanner.scan(); + if (token === 123) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + } + } + } + } + } + } + } + else if (token === 77) { + token = scanner.scan(); + if (token === 14) { + token = scanner.scan(); + while (token !== 15) { + token = scanner.scan(); + } + if (token === 15) { + token = scanner.scan(); + if (token === 123) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + } + } + } + } + else if (token === 35) { + token = scanner.scan(); + if (token === 123) { + token = scanner.scan(); + if (token === 8) { + recordModuleName(); + } } } } @@ -26961,7 +27969,7 @@ var ts; } function isNameOfFunctionDeclaration(node) { return node.kind === 64 && - ts.isAnyFunction(node.parent) && node.parent.name === node; + ts.isFunctionLike(node.parent) && node.parent.name === node; } function isNameOfPropertyAssignment(node) { return (node.kind === 64 || node.kind === 8 || node.kind === 7) && @@ -27071,7 +28079,11 @@ var ts; case 198: return ScriptElementKind.typeElement; case 199: return ScriptElementKind.enumElement; case 193: - return ts.isConst(node) ? ScriptElementKind.constElement : ts.isLet(node) ? ScriptElementKind.letElement : ScriptElementKind.variableElement; + return ts.isConst(node) + ? ScriptElementKind.constElement + : ts.isLet(node) + ? ScriptElementKind.letElement + : ScriptElementKind.variableElement; case 195: return ScriptElementKind.functionElement; case 134: return ScriptElementKind.memberGetAccessorElement; case 135: return ScriptElementKind.memberSetAccessorElement; @@ -27088,6 +28100,12 @@ var ts; case 127: return ScriptElementKind.typeParameterElement; case 219: return ScriptElementKind.variableElement; case 128: return (node.flags & 112) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; + case 202: + case 207: + case 204: + case 211: + case 205: + return ScriptElementKind.alias; } return ScriptElementKind.unknown; } @@ -27165,11 +28183,7 @@ var ts; if (!changesInCompilationSettingsAffectSyntax) { var oldSourceFile = program && program.getSourceFile(fileName); if (oldSourceFile) { - if (sourceFileUpToDate(oldSourceFile)) { - return oldSourceFile; - } - var textChangeRange = hostFileInformation.scriptSnapshot.getChangeRange(oldSourceFile.scriptSnapshot); - return documentRegistry.updateDocument(oldSourceFile, fileName, newSettings, hostFileInformation.scriptSnapshot, hostFileInformation.version, textChangeRange); + return documentRegistry.updateDocument(fileName, newSettings, hostFileInformation.scriptSnapshot, hostFileInformation.version); } } return documentRegistry.acquireDocument(fileName, newSettings, hostFileInformation.scriptSnapshot, hostFileInformation.version); @@ -27204,7 +28218,9 @@ var ts; } function dispose() { if (program) { - ts.forEach(program.getSourceFiles(), function (f) { documentRegistry.releaseDocument(f.fileName, program.getCompilerOptions()); }); + ts.forEach(program.getSourceFiles(), function (f) { + return documentRegistry.releaseDocument(f.fileName, program.getCompilerOptions()); + }); } } function getSyntacticDiagnostics(fileName) { @@ -27349,6 +28365,17 @@ var ts; getCompletionEntriesFromSymbols(filteredMembers, activeCompletionSession); } } + else if (ts.getAncestor(previousToken, 204)) { + isMemberCompletion = true; + isNewIdentifierLocation = true; + if (showCompletionsInImportsClause(previousToken)) { + var importDeclaration = ts.getAncestor(previousToken, 203); + ts.Debug.assert(importDeclaration !== undefined); + var exports = typeInfoResolver.getExportsOfExternalModule(importDeclaration); + var filteredExports = filterModuleExports(exports, importDeclaration); + getCompletionEntriesFromSymbols(filteredExports, activeCompletionSession); + } + } else { isMemberCompletion = false; isNewIdentifierLocation = isNewIdentifierDefinitionLocation(previousToken); @@ -27389,31 +28416,47 @@ var ts; log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; } + function showCompletionsInImportsClause(node) { + if (node) { + if (node.kind === 14 || node.kind === 23) { + return node.parent.kind === 206; + } + } + return false; + } function isNewIdentifierDefinitionLocation(previousToken) { if (previousToken) { var containingNodeKind = previousToken.parent.kind; switch (previousToken.kind) { case 23: - return containingNodeKind === 155 || containingNodeKind === 133 || containingNodeKind === 156 || containingNodeKind === 151 || containingNodeKind === 167; + return containingNodeKind === 155 + || containingNodeKind === 133 + || containingNodeKind === 156 + || containingNodeKind === 151 + || containingNodeKind === 167; case 16: - return containingNodeKind === 155 || containingNodeKind === 133 || containingNodeKind === 156 || containingNodeKind === 159; + return containingNodeKind === 155 + || containingNodeKind === 133 + || containingNodeKind === 156 + || containingNodeKind === 159; case 18: return containingNodeKind === 151; - case 117: + case 116: return true; case 20: return containingNodeKind === 200; case 14: return containingNodeKind === 196; case 52: - return containingNodeKind === 193 || containingNodeKind === 167; + return containingNodeKind === 193 + || containingNodeKind === 167; case 11: return containingNodeKind === 169; case 12: return containingNodeKind === 173; - case 109: - case 107: case 108: + case 106: + case 107: return containingNodeKind === 130; } switch (previousToken.getText()) { @@ -27426,7 +28469,9 @@ var ts; return false; } function isInStringOrRegularExpressionOrTemplateLiteral(previousToken) { - if (previousToken.kind === 8 || previousToken.kind === 9 || ts.isTemplateLiteralKind(previousToken.kind)) { + if (previousToken.kind === 8 + || previousToken.kind === 9 + || ts.isTemplateLiteralKind(previousToken.kind)) { var start = previousToken.getStart(); var end = previousToken.getEnd(); if (start < position && position < end) { @@ -27504,27 +28549,27 @@ var ts; containingNodeKind === 195 || containingNodeKind === 197 || isFunction(containingNodeKind); - case 110: + case 109: return containingNodeKind === 130; case 21: return containingNodeKind === 128 || containingNodeKind === 133 || (previousToken.parent.parent.kind === 149); - case 109: - case 107: case 108: + case 106: + case 107: return containingNodeKind === 128; case 68: case 76: - case 104: + case 103: case 82: case 97: - case 116: - case 120: + case 115: + case 119: case 84: - case 105: + case 104: case 69: - case 111: + case 110: return true; } switch (previousToken.getText()) { @@ -27549,6 +28594,23 @@ var ts; } return false; } + function filterModuleExports(exports, importDeclaration) { + var exisingImports = {}; + if (!importDeclaration.importClause) { + return exports; + } + if (importDeclaration.importClause.namedBindings && + importDeclaration.importClause.namedBindings.kind === 206) { + ts.forEach(importDeclaration.importClause.namedBindings.elements, function (el) { + var name = el.propertyName || el.name; + exisingImports[name.text] = true; + }); + } + if (ts.isEmpty(exisingImports)) { + return exports; + } + return ts.filter(exports, function (e) { return !ts.lookUp(exisingImports, e.name); }); + } function filterContextualMembersList(contextualMemberSymbols, existingMembers) { if (!existingMembers || existingMembers.length === 0) { return contextualMemberSymbols; @@ -27695,7 +28757,9 @@ var ts; return ScriptElementKind.unknown; } function getSymbolModifiers(symbol) { - return symbol && symbol.declarations && symbol.declarations.length > 0 ? ts.getNodeModifiers(symbol.declarations[0]) : ScriptElementKindModifier.none; + return symbol && symbol.declarations && symbol.declarations.length > 0 + ? ts.getNodeModifiers(symbol.declarations[0]) + : ScriptElementKindModifier.none; } function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, sourceFile, enclosingDeclaration, typeResolver, location, semanticMeaning) { if (semanticMeaning === void 0) { semanticMeaning = getMeaningFromLocation(location); } @@ -27779,7 +28843,7 @@ var ts; } } else if ((isNameOfFunctionDeclaration(location) && !(symbol.flags & 98304)) || - (location.kind === 114 && location.parent.kind === 133)) { + (location.kind === 113 && location.parent.kind === 133)) { var signature; var functionDeclaration = location.parent; var allSignatures = functionDeclaration.kind === 133 ? type.getConstructSignatures() : type.getCallSignatures(); @@ -27810,14 +28874,14 @@ var ts; } if ((symbolFlags & 64) && (semanticMeaning & 2)) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(104)); + displayParts.push(ts.keywordPart(103)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); } if (symbolFlags & 524288) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(123)); + displayParts.push(ts.keywordPart(122)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); displayParts.push(ts.spacePart()); @@ -27837,7 +28901,7 @@ var ts; } if (symbolFlags & 1536) { addNewLineIfDisplayPartsExist(); - displayParts.push(ts.keywordPart(117)); + displayParts.push(ts.keywordPart(116)); displayParts.push(ts.spacePart()); addFullSymbolName(symbol); } @@ -27893,7 +28957,7 @@ var ts; displayParts.push(ts.spacePart()); displayParts.push(ts.operatorPart(52)); displayParts.push(ts.spacePart()); - displayParts.push(ts.keywordPart(118)); + displayParts.push(ts.keywordPart(117)); displayParts.push(ts.punctuationPart(16)); displayParts.push(ts.displayPart(ts.getTextOfNode(ts.getExternalModuleImportEqualsDeclarationExpression(importEqualsDeclaration)), 8)); displayParts.push(ts.punctuationPart(17)); @@ -28056,6 +29120,12 @@ var ts; if (!symbol) { return undefined; } + if (symbol.flags & 8388608) { + var declaration = symbol.declarations[0]; + if (node.kind === 64 && node.parent === declaration) { + symbol = typeInfoResolver.getAliasedSymbol(symbol); + } + } var result = []; if (node.parent.kind === 218) { var shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); @@ -28112,7 +29182,7 @@ var ts; return false; } function tryAddConstructSignature(symbol, location, symbolKind, symbolName, containerName, result) { - if (isNewExpressionTarget(location) || location.kind === 114) { + if (isNewExpressionTarget(location) || location.kind === 113) { if (symbol.flags & 32) { var classDeclaration = symbol.getDeclarations()[0]; ts.Debug.assert(classDeclaration && classDeclaration.kind === 196); @@ -28197,13 +29267,13 @@ var ts; return getLoopBreakContinueOccurrences(node.parent); } break; - case 114: + case 113: if (hasKind(node.parent, 133)) { return getConstructorOccurrences(node.parent); } break; - case 116: - case 120: + case 115: + case 119: if (hasKind(node.parent, 134) || hasKind(node.parent, 135)) { return getGetAndSetOccurrences(node.parent); } @@ -28308,7 +29378,7 @@ var ts; aggregate(tryStatement.finallyBlock); } } - else if (!ts.isAnyFunction(node)) { + else if (!ts.isFunctionLike(node)) { ts.forEachChild(node, aggregate); } } @@ -28401,7 +29471,7 @@ var ts; if (node.kind === 185 || node.kind === 184) { statementAccumulator.push(node); } - else if (!ts.isAnyFunction(node)) { + else if (!ts.isFunctionLike(node)) { ts.forEachChild(node, aggregate); } } @@ -28428,7 +29498,7 @@ var ts; } break; default: - if (ts.isAnyFunction(node)) { + if (ts.isFunctionLike(node)) { return undefined; } break; @@ -28441,7 +29511,7 @@ var ts; var keywords = []; ts.forEach(declarations, function (declaration) { ts.forEach(declaration.getChildren(), function (token) { - return pushKeywordIf(keywords, token, 114); + return pushKeywordIf(keywords, token, 113); }); }); return ts.map(keywords, getReferenceEntryFromNode); @@ -28454,7 +29524,7 @@ var ts; function tryPushAccessorKeyword(accessorSymbol, accessorKind) { var accessor = ts.getDeclarationOfKind(accessorSymbol, accessorKind); if (accessor) { - ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 116, 120); }); + ts.forEach(accessor.getChildren(), function (child) { return pushKeywordIf(keywords, child, 115, 119); }); } } } @@ -28512,17 +29582,17 @@ var ts; return ts.map(keywords, getReferenceEntryFromNode); function getFlagFromModifier(modifier) { switch (modifier) { - case 109: - return 16; - case 107: - return 32; case 108: + return 16; + case 106: + return 32; + case 107: return 64; - case 110: + case 109: return 128; case 77: return 1; - case 115: + case 114: return 2; default: ts.Debug.fail(); @@ -28568,24 +29638,6 @@ var ts; ts.Debug.assert(node.kind === 64 || node.kind === 7 || node.kind === 8); return getReferencesForNode(node, program.getSourceFiles(), false, findInStrings, findInComments); } - function initializeNameTable(sourceFile) { - var nameTable = {}; - walk(sourceFile); - sourceFile.nameTable = nameTable; - function walk(node) { - switch (node.kind) { - case 64: - nameTable[node.text] = node.text; - break; - case 8: - case 7: - nameTable[node.text] = node.text; - break; - default: - ts.forEachChild(node, walk); - } - } - } function getReferencesForNode(node, sourceFiles, searchOnlyInCurrentFile, findInStrings, findInComments) { if (isLabelName(node)) { if (isJumpStatementTarget(node)) { @@ -28612,7 +29664,7 @@ var ts; } var result; var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); - var declaredName = getDeclaredName(symbol); + var declaredName = getDeclaredName(symbol, node); var scope = getSymbolScope(symbol); if (scope) { result = []; @@ -28625,14 +29677,11 @@ var ts; getReferencesInNode(sourceFiles[0], symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); } else { - var internedName = getInternedName(symbol, declarations); + var internedName = getInternedName(symbol, node, declarations); ts.forEach(sourceFiles, function (sourceFile) { cancellationToken.throwIfCancellationRequested(); - if (!sourceFile.nameTable) { - initializeNameTable(sourceFile); - } - ts.Debug.assert(sourceFile.nameTable !== undefined); - if (ts.lookUp(sourceFile.nameTable, internedName)) { + var nameTable = getNameTable(sourceFile); + if (ts.lookUp(nameTable, internedName)) { result = result || []; getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); } @@ -28640,11 +29689,31 @@ var ts; } } return result; - function getDeclaredName(symbol) { + function isImportOrExportSpecifierName(location) { + return location.parent && + (location.parent.kind === 207 || location.parent.kind === 211) && + location.parent.propertyName === location; + } + function isImportOrExportSpecifierImportSymbol(symbol) { + return (symbol.flags & 8388608) && ts.forEach(symbol.declarations, function (declaration) { + return declaration.kind === 207 || declaration.kind === 211; + }); + } + function getDeclaredName(symbol, location) { + var functionExpression = ts.forEach(symbol.declarations, function (d) { return d.kind === 160 ? d : undefined; }); + if (functionExpression && functionExpression.name) { + var name = functionExpression.name.text; + } + if (isImportOrExportSpecifierName(location)) { + return location.getText(); + } var name = typeInfoResolver.symbolToString(symbol); return stripQuotes(name); } - function getInternedName(symbol, declarations) { + function getInternedName(symbol, location, declarations) { + if (isImportOrExportSpecifierName(location)) { + return location.getText(); + } var functionExpression = ts.forEach(declarations, function (d) { return d.kind === 160 ? d : undefined; }); if (functionExpression && functionExpression.name) { var name = functionExpression.name.text; @@ -28663,13 +29732,16 @@ var ts; return name; } function getSymbolScope(symbol) { - if (symbol.getFlags() && (4 | 8192)) { + if (symbol.flags & (4 | 8192)) { var privateDeclaration = ts.forEach(symbol.getDeclarations(), function (d) { return (d.flags & 32) ? d : undefined; }); if (privateDeclaration) { return ts.getAncestor(privateDeclaration, 196); } } - if (symbol.parent || (symbol.getFlags() & 268435456)) { + if (symbol.flags & 8388608) { + return undefined; + } + if (symbol.parent || (symbol.flags & 268435456)) { return undefined; } var scope = undefined; @@ -28920,6 +29992,9 @@ var ts; } function populateSearchSymbolSet(symbol, location) { var result = [symbol]; + if (isImportOrExportSpecifierImportSymbol(symbol)) { + result.push(typeInfoResolver.getAliasedSymbol(symbol)); + } if (isNameOfPropertyAssignment(location)) { ts.forEach(getPropertySymbolsFromContextualType(location), function (contextualSymbol) { result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol)); @@ -28969,6 +30044,10 @@ var ts; if (searchSymbols.indexOf(referenceSymbol) >= 0) { return true; } + if (isImportOrExportSpecifierImportSymbol(referenceSymbol) && + searchSymbols.indexOf(typeInfoResolver.getAliasedSymbol(referenceSymbol)) >= 0) { + return true; + } if (isNameOfPropertyAssignment(referenceLocation)) { return ts.forEach(getPropertySymbolsFromContextualType(referenceLocation), function (contextualSymbol) { return ts.forEach(typeInfoResolver.getRootSymbols(contextualSymbol), function (s) { return searchSymbols.indexOf(s) >= 0; }); @@ -29047,7 +30126,7 @@ var ts; }; } function isWriteAccess(node) { - if (node.kind === 64 && ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + if (node.kind === 64 && ts.isDeclarationName(node)) { return true; } var parent = node.parent; @@ -29124,11 +30203,17 @@ var ts; else { return 4; } + case 206: + case 207: case 202: + case 203: + case 208: + case 209: return 1 | 2 | 4; case 220: return 4 | 1; } + return 1 | 2 | 4; ts.Debug.fail("Unknown declaration type"); } function isTypeReference(node) { @@ -29169,7 +30254,7 @@ var ts; else if (isInRightSideOfImport(node)) { return getMeaningFromRightHandSideOfImportEquals(node); } - else if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { + else if (ts.isDeclarationName(node)) { return getMeaningFromDeclaration(node.parent); } else if (isTypeReference(node)) { @@ -29678,6 +30763,41 @@ var ts; }; } ts.createLanguageService = createLanguageService; + function getNameTable(sourceFile) { + if (!sourceFile.nameTable) { + initializeNameTable(sourceFile); + } + return sourceFile.nameTable; + } + ts.getNameTable = getNameTable; + function initializeNameTable(sourceFile) { + var nameTable = {}; + walk(sourceFile); + sourceFile.nameTable = nameTable; + function walk(node) { + switch (node.kind) { + case 64: + nameTable[node.text] = node.text; + break; + case 8: + case 7: + if (ts.isDeclarationName(node) || + node.parent.kind === 212 || + isArgumentOfElementAccessExpression(node)) { + nameTable[node.text] = node.text; + } + break; + default: + ts.forEachChild(node, walk); + } + } + } + function isArgumentOfElementAccessExpression(node) { + return node && + node.parent && + node.parent.kind === 154 && + node.parent.argumentExpression === node; + } function createClassifier() { var scanner = ts.createScanner(2, false); var noRegexTable = []; @@ -29696,19 +30816,19 @@ var ts; var templateStack = []; function isAccessibilityModifier(kind) { switch (kind) { - case 109: - case 107: case 108: + case 106: + case 107: return true; } return false; } function canFollow(keyword1, keyword2) { if (isAccessibilityModifier(keyword1)) { - if (keyword2 === 116 || - keyword2 === 120 || - keyword2 === 114 || - keyword2 === 110) { + if (keyword2 === 115 || + keyword2 === 119 || + keyword2 === 113 || + keyword2 === 109) { return true; } return false; @@ -29773,11 +30893,11 @@ var ts; else if (token === 25 && angleBracketStack > 0) { angleBracketStack--; } - else if (token === 112 || - token === 121 || - token === 119 || - token === 113 || - token === 122) { + else if (token === 111 || + token === 120 || + token === 118 || + token === 112 || + token === 121) { if (angleBracketStack > 0 && !syntacticClassifierAbsent) { token = 64; } @@ -29828,7 +30948,9 @@ var ts; } if (numBackslashes & 1) { var quoteChar = tokenText.charCodeAt(0); - result.finalLexState = quoteChar === 34 ? 3 : 2; + result.finalLexState = quoteChar === 34 + ? 3 + : 2; } } } @@ -29991,7 +31113,7 @@ var ts; var BreakpointResolver; (function (BreakpointResolver) { function spanInSourceFileAtLocation(sourceFile, position) { - if (sourceFile.flags & 1024) { + if (sourceFile.flags & 2048) { return undefined; } var tokenAtLocation = ts.getTokenAtPosition(sourceFile, position); @@ -30095,9 +31217,13 @@ var ts; case 190: return textSpan(node, node.expression); case 208: - return textSpan(node, node.exportName); + return textSpan(node, node.expression); case 202: return textSpan(node, node.moduleReference); + case 203: + return textSpan(node, node.moduleSpecifier); + case 209: + return textSpan(node, node.moduleSpecifier); case 200: if (ts.getModuleInstanceState(node) !== 1) { return undefined; @@ -30144,7 +31270,7 @@ var ts; if (node.parent.kind === 158 && node.parent.type === node) { return spanInNode(node.parent.expression); } - if (ts.isAnyFunction(node.parent) && node.parent.type === node) { + if (ts.isFunctionLike(node.parent) && node.parent.type === node) { return spanInPreviousNode(node); } return spanInNode(node.parent); @@ -30157,7 +31283,11 @@ var ts; } 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; + 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) { if (isParentVariableStatement) { @@ -30317,7 +31447,7 @@ var ts; return spanInNode(node.parent); } function spanInColonToken(node) { - if (ts.isAnyFunction(node.parent) || node.parent.kind === 217) { + if (ts.isFunctionLike(node.parent) || node.parent.kind === 217) { return spanInPreviousNode(node); } return spanInNode(node.parent); diff --git a/bin/typescriptServices_internal.d.ts b/bin/typescriptServices_internal.d.ts index 16616795233..2cd2257c3e1 100644 --- a/bin/typescriptServices_internal.d.ts +++ b/bin/typescriptServices_internal.d.ts @@ -87,12 +87,6 @@ declare module ts { function combinePaths(path1: string, path2: string): string; function fileExtensionIs(path: string, extension: string): boolean; function removeFileExtension(path: string): string; - /** - * Based heavily on the abstract 'Quote' operation from ECMA-262 (24.3.2.2), - * but augmented for a few select characters. - * Note that this doesn't actually wrap the input in double quotes. - */ - function escapeString(s: string): string; function getDefaultLibFileName(options: CompilerOptions): string; interface ObjectAllocator { getNodeConstructor(kind: SyntaxKind): new () => Node; @@ -143,6 +137,11 @@ declare module ts { diagnosticMessage?: DiagnosticMessage; isNoDefaultLib?: boolean; } + interface SynthesizedNode extends Node { + leadingCommentRanges?: CommentRange[]; + trailingCommentRanges?: CommentRange[]; + startsOnNewLine: boolean; + } function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration; interface StringSymbolWriter extends SymbolWriter { string(): string; @@ -171,10 +170,12 @@ declare module ts { function escapeIdentifier(identifier: string): string; function unescapeIdentifier(identifier: string): string; function makeIdentifierFromModuleName(moduleName: string): string; + function isBlockOrCatchScoped(declaration: Declaration): boolean; + function isCatchClauseVariableDeclaration(declaration: Declaration): boolean; function declarationNameToString(name: DeclarationName): string; function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic; function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain): Diagnostic; - function getErrorSpanForNode(node: Node): Node; + function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpan; function isExternalModule(file: SourceFile): boolean; function isDeclarationFile(file: SourceFile): boolean; function isConstEnumDeclaration(node: Node): boolean; @@ -186,7 +187,7 @@ declare module ts { function getJsDocComments(node: Node, sourceFileOfNode: SourceFile): CommentRange[]; var fullTripleSlashReferencePathRegEx: RegExp; function forEachReturnStatement(body: Block, visitor: (stmt: ReturnStatement) => T): T; - function isAnyFunction(node: Node): boolean; + function isFunctionLike(node: Node): boolean; function isFunctionBlock(node: Node): boolean; function isObjectLiteralMethod(node: Node): boolean; function getContainingFunction(node: Node): FunctionLikeDeclaration; @@ -209,7 +210,7 @@ declare module ts { function isInAmbientContext(node: Node): boolean; function isDeclaration(node: Node): boolean; function isStatement(n: Node): boolean; - function isDeclarationOrFunctionExpressionOrCatchVariableName(name: Node): boolean; + function isDeclarationName(name: Node): boolean; function getClassBaseTypeNode(node: ClassDeclaration): TypeReferenceNode; function getClassImplementedTypeNodes(node: ClassDeclaration): NodeArray; function getInterfaceBaseTypeNodes(node: InterfaceDeclaration): NodeArray; @@ -265,6 +266,18 @@ declare module ts { * Vn. */ function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; + function nodeStartsNewLexicalEnvironment(n: Node): boolean; + function nodeIsSynthesized(node: Node): boolean; + function createSynthesizedNode(kind: SyntaxKind, startsOnNewLine?: boolean): Node; + function generateUniqueName(baseName: string, isExistingName: (name: string) => boolean): string; + function createDiagnosticCollection(): DiagnosticCollection; + /** + * Based heavily on the abstract 'Quote'/'QuoteJSONString' operation from ECMA-262 (24.3.2.2), + * but augmented for a few select characters (e.g. lineSeparator, paragraphSeparator, nextLine) + * Note that this doesn't actually wrap the input in double quotes. + */ + function escapeString(s: string): string; + function escapeNonAsciiCharacters(s: string): string; } declare module ts { var optionDeclarations: CommandLineOption[]; diff --git a/bin/typescript_internal.d.ts b/bin/typescript_internal.d.ts index aaa72fa2254..e2e18df5726 100644 --- a/bin/typescript_internal.d.ts +++ b/bin/typescript_internal.d.ts @@ -87,12 +87,6 @@ declare module "typescript" { function combinePaths(path1: string, path2: string): string; function fileExtensionIs(path: string, extension: string): boolean; function removeFileExtension(path: string): string; - /** - * Based heavily on the abstract 'Quote' operation from ECMA-262 (24.3.2.2), - * but augmented for a few select characters. - * Note that this doesn't actually wrap the input in double quotes. - */ - function escapeString(s: string): string; function getDefaultLibFileName(options: CompilerOptions): string; interface ObjectAllocator { getNodeConstructor(kind: SyntaxKind): new () => Node; @@ -143,6 +137,11 @@ declare module "typescript" { diagnosticMessage?: DiagnosticMessage; isNoDefaultLib?: boolean; } + interface SynthesizedNode extends Node { + leadingCommentRanges?: CommentRange[]; + trailingCommentRanges?: CommentRange[]; + startsOnNewLine: boolean; + } function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration; interface StringSymbolWriter extends SymbolWriter { string(): string; @@ -171,10 +170,12 @@ declare module "typescript" { function escapeIdentifier(identifier: string): string; function unescapeIdentifier(identifier: string): string; function makeIdentifierFromModuleName(moduleName: string): string; + function isBlockOrCatchScoped(declaration: Declaration): boolean; + function isCatchClauseVariableDeclaration(declaration: Declaration): boolean; function declarationNameToString(name: DeclarationName): string; function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic; function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain): Diagnostic; - function getErrorSpanForNode(node: Node): Node; + function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpan; function isExternalModule(file: SourceFile): boolean; function isDeclarationFile(file: SourceFile): boolean; function isConstEnumDeclaration(node: Node): boolean; @@ -186,7 +187,7 @@ declare module "typescript" { function getJsDocComments(node: Node, sourceFileOfNode: SourceFile): CommentRange[]; var fullTripleSlashReferencePathRegEx: RegExp; function forEachReturnStatement(body: Block, visitor: (stmt: ReturnStatement) => T): T; - function isAnyFunction(node: Node): boolean; + function isFunctionLike(node: Node): boolean; function isFunctionBlock(node: Node): boolean; function isObjectLiteralMethod(node: Node): boolean; function getContainingFunction(node: Node): FunctionLikeDeclaration; @@ -209,7 +210,7 @@ declare module "typescript" { function isInAmbientContext(node: Node): boolean; function isDeclaration(node: Node): boolean; function isStatement(n: Node): boolean; - function isDeclarationOrFunctionExpressionOrCatchVariableName(name: Node): boolean; + function isDeclarationName(name: Node): boolean; function getClassBaseTypeNode(node: ClassDeclaration): TypeReferenceNode; function getClassImplementedTypeNodes(node: ClassDeclaration): NodeArray; function getInterfaceBaseTypeNodes(node: InterfaceDeclaration): NodeArray; @@ -265,6 +266,18 @@ declare module "typescript" { * Vn. */ function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; + function nodeStartsNewLexicalEnvironment(n: Node): boolean; + function nodeIsSynthesized(node: Node): boolean; + function createSynthesizedNode(kind: SyntaxKind, startsOnNewLine?: boolean): Node; + function generateUniqueName(baseName: string, isExistingName: (name: string) => boolean): string; + function createDiagnosticCollection(): DiagnosticCollection; + /** + * Based heavily on the abstract 'Quote'/'QuoteJSONString' operation from ECMA-262 (24.3.2.2), + * but augmented for a few select characters (e.g. lineSeparator, paragraphSeparator, nextLine) + * Note that this doesn't actually wrap the input in double quotes. + */ + function escapeString(s: string): string; + function escapeNonAsciiCharacters(s: string): string; } declare module "typescript" { var optionDeclarations: CommandLineOption[];