diff --git a/bin/tsc.js b/bin/tsc.js index 070f535618..ab5386e2b4 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -182,6 +182,19 @@ var ts; return result; } ts.clone = clone; + function extend(first, second) { + var result = {}; + for (var id in first) { + result[id] = first[id]; + } + for (var id in second) { + if (!hasProperty(result, id)) { + result[id] = second[id]; + } + } + return result; + } + ts.extend = extend; function forEachValue(map, callback) { var result; for (var id in map) { @@ -503,7 +516,7 @@ var ts; return path2; if (!(path2 && path2.length)) return path1; - if (path2.charAt(0) === ts.directorySeparator) + if (getRootLength(path2) !== 0) return path2; if (path1.charAt(path1.length - 1) === ts.directorySeparator) return path1 + path2; @@ -666,6 +679,32 @@ var ts; fileStream.Close(); } } + function getNames(collection) { + var result = []; + for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { + result.push(e.item().Name); + } + return result.sort(); + } + function readDirectory(path, extension) { + var result = []; + visitDirectory(path); + return result; + function visitDirectory(path) { + var folder = fso.GetFolder(path || "."); + var files = getNames(folder.files); + for (var i = 0; i < files.length; i++) { + var name = files[i]; + if (!extension || ts.fileExtensionIs(name, extension)) { + result.push(ts.combinePaths(path, name)); + } + } + var subfolders = getNames(folder.subfolders); + for (var i = 0; i < subfolders.length; i++) { + visitDirectory(ts.combinePaths(path, subfolders[i])); + } + } + } return { args: args, newLine: "\r\n", @@ -695,6 +734,7 @@ var ts; getCurrentDirectory: function () { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + readDirectory: readDirectory, exit: function (exitCode) { try { WScript.Quit(exitCode); @@ -739,6 +779,30 @@ var ts; } _fs.writeFileSync(fileName, data, "utf8"); } + function readDirectory(path, extension) { + var result = []; + visitDirectory(path); + return result; + function visitDirectory(path) { + var files = _fs.readdirSync(path || ".").sort(); + var directories = []; + for (var i = 0; i < files.length; i++) { + var name = ts.combinePaths(path, files[i]); + var stat = _fs.lstatSync(name); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); + } + } + for (var i = 0; i < directories.length; i++) { + visitDirectory(directories[i]); + } + } + } return { args: process.argv.slice(2), newLine: _os.EOL, @@ -783,6 +847,7 @@ var ts; getCurrentDirectory: function () { return process.cwd(); }, + readDirectory: readDirectory, getMemoryUsage: function () { if (global.gc) { global.gc(); @@ -952,6 +1017,7 @@ var ts; Modifiers_cannot_appear_here: { code: 1184, category: 1 /* Error */, key: "Modifiers cannot appear here." }, Merge_conflict_marker_encountered: { code: 1185, category: 1 /* Error */, key: "Merge conflict marker encountered." }, A_rest_element_cannot_have_an_initializer: { code: 1186, category: 1 /* Error */, key: "A rest element cannot have an initializer." }, + A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: 1 /* Error */, key: "A parameter property may not be a binding pattern." }, Duplicate_identifier_0: { code: 2300, category: 1 /* Error */, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: 1 /* Error */, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: 1 /* Error */, key: "Static members cannot reference class type parameters." }, @@ -1103,6 +1169,11 @@ var ts; Type_0_has_no_property_1: { code: 2460, category: 1 /* Error */, key: "Type '{0}' has no property '{1}'." }, Type_0_is_not_an_array_type: { code: 2461, category: 1 /* Error */, key: "Type '{0}' is not an array type." }, A_rest_element_must_be_last_in_an_array_destructuring_pattern: { code: 2462, category: 1 /* Error */, key: "A rest element must be last in an array destructuring pattern" }, + A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature: { code: 2463, category: 1 /* Error */, key: "A binding pattern parameter cannot be optional in an implementation signature." }, + A_computed_property_name_must_be_of_type_string_number_or_any: { code: 2464, category: 1 /* Error */, key: "A computed property name must be of type 'string', 'number', or 'any'." }, + this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: 1 /* Error */, key: "'this' cannot be referenced in a computed property name." }, + super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: 1 /* Error */, key: "'super' cannot be referenced in a computed property name." }, + A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2466, category: 1 /* Error */, key: "A computed property name cannot reference a type parameter from its containing type." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1 /* Error */, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: 1 /* Error */, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1175,19 +1246,22 @@ var ts; Enum_declarations_must_all_be_const_or_non_const: { code: 4082, category: 1 /* Error */, key: "Enum declarations must all be const or non-const." }, In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 4083, category: 1 /* Error */, key: "In 'const' enum declarations member initializer must be constant expression.", isEarly: true }, const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 4084, category: 1 /* Error */, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." }, - Index_expression_arguments_in_const_enums_must_be_of_type_string: { code: 4085, category: 1 /* Error */, key: "Index expression arguments in 'const' enums must be of type 'string'." }, + A_const_enum_member_can_only_be_accessed_using_a_string_literal: { code: 4085, category: 1 /* Error */, key: "A const enum member can only be accessed using a string literal.", isEarly: true }, const_enum_member_initializer_was_evaluated_to_a_non_finite_value: { code: 4086, category: 1 /* Error */, key: "'const' enum member initializer was evaluated to a non-finite value." }, const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: { code: 4087, category: 1 /* Error */, key: "'const' enum member initializer was evaluated to disallowed value 'NaN'." }, + Property_0_does_not_exist_on_const_enum_1: { code: 4088, category: 1 /* Error */, key: "Property '{0}' does not exist on 'const' enum '{1}'.", isEarly: true }, The_current_host_does_not_support_the_0_option: { code: 5001, category: 1 /* Error */, key: "The current host does not support the '{0}' option." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: 1 /* Error */, key: "Cannot find the common subdirectory path for the input files." }, Cannot_read_file_0_Colon_1: { code: 5012, category: 1 /* Error */, key: "Cannot read file '{0}': {1}" }, Unsupported_file_encoding: { code: 5013, category: 1 /* Error */, key: "Unsupported file encoding." }, Unknown_compiler_option_0: { code: 5023, category: 1 /* Error */, key: "Unknown compiler option '{0}'." }, + Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: 1 /* Error */, key: "Compiler option '{0}' requires a value of type {1}." }, Could_not_write_file_0_Colon_1: { code: 5033, category: 1 /* Error */, key: "Could not write file '{0}': {1}" }, - Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: 1 /* Error */, key: "Option mapRoot cannot be specified without specifying sourcemap option." }, - Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: 1 /* Error */, key: "Option sourceRoot cannot be specified without specifying sourcemap option." }, - Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: 1 /* Error */, key: "Option noEmit cannot be specified with option out or outDir." }, - Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: 1 /* Error */, key: "Option noEmit cannot be specified with option declaration." }, + Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: 1 /* Error */, key: "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option." }, + Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: 1 /* Error */, key: "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option." }, + Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: 1 /* Error */, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, + Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: 1 /* Error */, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, + Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: 1 /* Error */, key: "Option 'project' cannot be mixed with source files on a command line." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: 2 /* Message */, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: 2 /* Message */, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: 2 /* Message */, key: "Specifies the location where debugger should locate map files instead of generated locations." }, @@ -1202,6 +1276,7 @@ var ts; Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: 2 /* Message */, key: "Specify module code generation: 'commonjs' or 'amd'" }, Print_this_message: { code: 6017, category: 2 /* Message */, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: 2 /* Message */, key: "Print the compiler's version." }, + Compile_the_project_in_the_given_directory: { code: 6020, category: 2 /* Message */, key: "Compile the project in the given directory." }, Syntax_Colon_0: { code: 6023, category: 2 /* Message */, key: "Syntax: {0}" }, options: { code: 6024, category: 2 /* Message */, key: "options" }, file: { code: 6025, category: 2 /* Message */, key: "file" }, @@ -1209,7 +1284,7 @@ var ts; Options_Colon: { code: 6027, category: 2 /* Message */, key: "Options:" }, Version_0: { code: 6029, category: 2 /* Message */, key: "Version {0}" }, Insert_command_line_options_and_files_from_a_file: { code: 6030, category: 2 /* Message */, key: "Insert command line options and files from a file." }, - File_change_detected_Compiling: { code: 6032, category: 2 /* Message */, key: "File change detected. Compiling..." }, + File_change_detected_Starting_incremental_compilation: { code: 6032, category: 2 /* Message */, key: "File change detected. Starting incremental compilation..." }, KIND: { code: 6034, category: 2 /* Message */, key: "KIND" }, FILE: { code: 6035, category: 2 /* Message */, key: "FILE" }, VERSION: { code: 6036, category: 2 /* Message */, key: "VERSION" }, @@ -1225,7 +1300,7 @@ var ts; Unsupported_locale_0: { code: 6049, category: 1 /* Error */, key: "Unsupported locale '{0}'." }, Unable_to_open_file_0: { code: 6050, category: 1 /* Error */, key: "Unable to open file '{0}'." }, Corrupted_locale_file_0: { code: 6051, category: 1 /* Error */, key: "Corrupted locale file {0}." }, - Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: 2 /* Message */, key: "Warn on expressions and declarations with an implied 'any' type." }, + Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: 2 /* Message */, key: "Raise error on expressions and declarations with an implied 'any' type." }, File_0_not_found: { code: 6053, category: 1 /* Error */, key: "File '{0}' not found." }, File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: 1 /* Error */, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: 2 /* Message */, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, @@ -1247,8 +1322,7 @@ var ts; Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: 1 /* Error */, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, You_cannot_rename_this_element: { code: 8000, category: 1 /* Error */, key: "You cannot rename this element." }, yield_expressions_are_not_currently_supported: { code: 9000, category: 1 /* Error */, key: "'yield' expressions are not currently supported.", isEarly: true }, - Generators_are_not_currently_supported: { code: 9001, category: 1 /* Error */, key: "Generators are not currently supported.", isEarly: true }, - Computed_property_names_are_not_currently_supported: { code: 9002, category: 1 /* Error */, key: "Computed property names are not currently supported.", isEarly: true } + Generators_are_not_currently_supported: { code: 9001, category: 1 /* Error */, key: "Generators are not currently supported.", isEarly: true } }; })(ts || (ts = {})); var ts; @@ -1388,10 +1462,10 @@ var ts; return false; } function isUnicodeIdentifierStart(code, languageVersion) { - return languageVersion === 0 /* ES3 */ ? lookupInUnicodeMap(code, unicodeES3IdentifierStart) : lookupInUnicodeMap(code, unicodeES5IdentifierStart); + return languageVersion >= 1 /* ES5 */ ? lookupInUnicodeMap(code, unicodeES5IdentifierStart) : lookupInUnicodeMap(code, unicodeES3IdentifierStart); } function isUnicodeIdentifierPart(code, languageVersion) { - return languageVersion === 0 /* ES3 */ ? lookupInUnicodeMap(code, unicodeES3IdentifierPart) : lookupInUnicodeMap(code, unicodeES5IdentifierPart); + return languageVersion >= 1 /* ES5 */ ? lookupInUnicodeMap(code, unicodeES5IdentifierPart) : lookupInUnicodeMap(code, unicodeES3IdentifierPart); } function makeReverseMap(source) { var result = []; @@ -1435,7 +1509,7 @@ var ts; } ts.computeLineStarts = computeLineStarts; function getPositionFromLineAndCharacter(lineStarts, line, character) { - ts.Debug.assert(line > 0); + ts.Debug.assert(line > 0 && line <= lineStarts.length); return lineStarts[line - 1] + character - 1; } ts.getPositionFromLineAndCharacter = getPositionFromLineAndCharacter; @@ -2099,7 +2173,7 @@ var ts; value = 0; } tokenValue = "" + value; - return 7 /* NumericLiteral */; + return token = 7 /* NumericLiteral */; } else if (pos + 2 < len && (text.charCodeAt(pos + 1) === 79 /* O */ || text.charCodeAt(pos + 1) === 111 /* o */)) { pos += 2; @@ -2109,7 +2183,7 @@ var ts; value = 0; } tokenValue = "" + value; - return 7 /* NumericLiteral */; + return token = 7 /* NumericLiteral */; } if (pos + 1 < len && isOctalDigit(text.charCodeAt(pos + 1))) { tokenValue = "" + scanOctalDigits(); @@ -2667,6 +2741,12 @@ var ts; return undefined; } switch (node.kind) { + case 122 /* ComputedPropertyName */: + if (node.parent.parent.kind === 191 /* ClassDeclaration */) { + return node; + } + node = node.parent; + break; case 157 /* ArrowFunction */: if (!includeArrowFunctions) { continue; @@ -2688,13 +2768,24 @@ var ts; } } ts.getThisContainer = getThisContainer; - function getSuperContainer(node) { + function getSuperContainer(node, includeFunctions) { while (true) { node = node.parent; - if (!node) { - return undefined; - } + if (!node) + return node; switch (node.kind) { + case 122 /* ComputedPropertyName */: + if (node.parent.parent.kind === 191 /* ClassDeclaration */) { + return node; + } + node = node.parent; + break; + case 190 /* FunctionDeclaration */: + case 156 /* FunctionExpression */: + case 157 /* ArrowFunction */: + if (!includeFunctions) { + continue; + } case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: case 128 /* MethodDeclaration */: @@ -2787,6 +2878,8 @@ var ts; return node === parent.expression; case 169 /* TemplateSpan */: return node === parent.expression; + case 122 /* ComputedPropertyName */: + return node === parent.expression; default: if (isExpression(parent)) { return true; @@ -3971,7 +4064,7 @@ var ts; return canFollowModifier(); } function canFollowModifier() { - return token === 18 /* OpenBracketToken */ || token === 35 /* AsteriskToken */ || isLiteralPropertyName(); + return token === 18 /* OpenBracketToken */ || token === 14 /* OpenBraceToken */ || token === 35 /* AsteriskToken */ || isLiteralPropertyName(); } function isListElement(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); @@ -6294,7 +6387,7 @@ var ts; var ts; (function (ts) { function getModuleInstanceState(node) { - if (node.kind === 192 /* InterfaceDeclaration */) { + if (node.kind === 192 /* InterfaceDeclaration */ || node.kind === 193 /* TypeAliasDeclaration */) { return 0 /* NonInstantiated */; } else if (ts.isConstEnumDeclaration(node)) { @@ -6327,10 +6420,10 @@ var ts; } } ts.getModuleInstanceState = getModuleInstanceState; - function hasComputedNameButNotSymbol(declaration) { + function hasDynamicName(declaration) { return declaration.name && declaration.name.kind === 122 /* ComputedPropertyName */; } - ts.hasComputedNameButNotSymbol = hasComputedNameButNotSymbol; + ts.hasDynamicName = hasDynamicName; function bindSourceFile(file) { var parent; var container; @@ -6366,7 +6459,7 @@ var ts; if (node.kind === 195 /* ModuleDeclaration */ && node.name.kind === 8 /* StringLiteral */) { return '"' + node.name.text + '"'; } - ts.Debug.assert(!hasComputedNameButNotSymbol(node)); + ts.Debug.assert(!hasDynamicName(node)); return node.name.text; } switch (node.kind) { @@ -6386,9 +6479,7 @@ var ts; return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node); } function declareSymbol(symbols, parent, node, includes, excludes) { - if (hasComputedNameButNotSymbol(node)) { - return undefined; - } + ts.Debug.assert(!hasDynamicName(node)); var name = getDeclarationName(node); if (name !== undefined) { var symbol = ts.hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); @@ -6607,14 +6698,14 @@ var ts; break; case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: - bindDeclaration(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0), 107455 /* PropertyExcludes */, false); + bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0), 107455 /* PropertyExcludes */, false); break; case 204 /* PropertyAssignment */: case 205 /* ShorthandPropertyAssignment */: - bindDeclaration(node, 4 /* Property */, 107455 /* PropertyExcludes */, false); + bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */, false); break; case 206 /* EnumMember */: - bindDeclaration(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */, false); + bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */, false); break; case 132 /* CallSignature */: case 133 /* ConstructSignature */: @@ -6623,7 +6714,7 @@ var ts; break; case 128 /* MethodDeclaration */: case 127 /* MethodSignature */: - bindDeclaration(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */, true); + bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */, true); break; case 190 /* FunctionDeclaration */: bindDeclaration(node, 16 /* Function */, 106927 /* FunctionExcludes */, true); @@ -6632,10 +6723,10 @@ var ts; bindDeclaration(node, 16384 /* Constructor */, 0, true); break; case 130 /* GetAccessor */: - bindDeclaration(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */, true); + bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */, true); break; case 131 /* SetAccessor */: - bindDeclaration(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */, true); + bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */, true); break; case 136 /* FunctionType */: case 137 /* ConstructorType */: @@ -6708,6 +6799,14 @@ var ts; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); } } + function bindPropertyOrMethodOrAccessor(node, symbolKind, symbolExcludes, isBlockScopeContainer) { + if (hasDynamicName(node)) { + bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer); + } + else { + bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer); + } + } } ts.bindSourceFile = bindSourceFile; })(ts || (ts = {})); @@ -6724,6 +6823,7 @@ var ts; var emptyArray = []; var emptySymbols = {}; var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || 0 /* ES3 */; var emitResolver = createResolver(); var checker = { getNodeCount: function () { return ts.sum(host.getSourceFiles(), "nodeCount"); }, @@ -6769,8 +6869,8 @@ var ts; var numberType = createIntrinsicType(4 /* Number */, "number"); var booleanType = createIntrinsicType(8 /* Boolean */, "boolean"); var voidType = createIntrinsicType(16 /* Void */, "void"); - var undefinedType = createIntrinsicType(32 /* Undefined */ | 131072 /* Unwidened */, "undefined"); - var nullType = createIntrinsicType(64 /* Null */ | 131072 /* Unwidened */, "null"); + var undefinedType = createIntrinsicType(32 /* Undefined */ | 262144 /* ContainsUndefinedOrNull */, "undefined"); + var nullType = createIntrinsicType(64 /* Null */ | 262144 /* ContainsUndefinedOrNull */, "null"); var unknownType = createIntrinsicType(1 /* Any */, "unknown"); var resolvingType = createIntrinsicType(1 /* Any */, "__resolving__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -6800,6 +6900,20 @@ var ts; var potentialThisCollisions = []; var diagnostics = []; var diagnosticsModified = false; + var primitiveTypeInfo = { + "string": { + type: stringType, + flags: 258 /* StringLike */ + }, + "number": { + type: numberType, + flags: 132 /* NumberLike */ + }, + "boolean": { + type: booleanType, + flags: 8 /* Boolean */ + } + }; function addDiagnostic(diagnostic) { diagnostics.push(diagnostic); diagnosticsModified = true; @@ -7016,6 +7130,15 @@ var ts; break loop; } break; + case 122 /* ComputedPropertyName */: + var grandparent = location.parent.parent; + if (grandparent.kind === 191 /* ClassDeclaration */ || grandparent.kind === 192 /* InterfaceDeclaration */) { + if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056 /* Type */)) { + error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); + return undefined; + } + } + break; case 128 /* MethodDeclaration */: case 127 /* MethodSignature */: case 129 /* Constructor */: @@ -8050,7 +8173,7 @@ var ts; } if (pattern.kind === 144 /* ObjectBindingPattern */) { var name = declaration.propertyName || declaration.name; - var type = getTypeOfPropertyOfType(parentType, name.text) || isNumericName(name.text) && getIndexTypeOfType(parentType, 1 /* Number */) || getIndexTypeOfType(parentType, 0 /* String */); + var type = getTypeOfPropertyOfType(parentType, name.text) || isNumericLiteralName(name.text) && getIndexTypeOfType(parentType, 1 /* Number */) || getIndexTypeOfType(parentType, 0 /* String */); if (!type) { error(name, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name)); return unknownType; @@ -8087,7 +8210,7 @@ var ts; } if (declaration.kind === 124 /* Parameter */) { var func = declaration.parent; - if (func.kind === 131 /* SetAccessor */ && !ts.hasComputedNameButNotSymbol(func)) { + if (func.kind === 131 /* SetAccessor */ && !ts.hasDynamicName(func)) { var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 130 /* GetAccessor */); if (getter) { return getReturnTypeOfSignature(getSignatureFromDeclaration(getter)); @@ -8868,7 +8991,7 @@ var ts; returnType = getTypeFromTypeNode(declaration.type); } else { - if (declaration.kind === 130 /* GetAccessor */ && !ts.hasComputedNameButNotSymbol(declaration)) { + if (declaration.kind === 130 /* GetAccessor */ && !ts.hasDynamicName(declaration)) { var setter = ts.getDeclarationOfKind(declaration.symbol, 131 /* SetAccessor */); returnType = getAnnotatedAccessorType(setter); } @@ -9030,14 +9153,18 @@ var ts; return result; } } - function getUnwidenedFlagOfTypes(types) { - return ts.forEach(types, function (t) { return t.flags & 131072 /* Unwidened */; }) || 0; + function getWideningFlagsOfTypes(types) { + var result = 0; + for (var i = 0; i < types.length; i++) { + result |= types[i].flags; + } + return result & 786432 /* RequiresWidening */; } function createTypeReference(target, typeArguments) { var id = getTypeListId(typeArguments); var type = target.instantiations[id]; if (!type) { - var flags = 4096 /* Reference */ | getUnwidenedFlagOfTypes(typeArguments); + var flags = 4096 /* Reference */ | getWideningFlagsOfTypes(typeArguments); type = target.instantiations[id] = createObjectType(flags, target.symbol); type.target = target; type.typeArguments = typeArguments; @@ -9254,7 +9381,7 @@ var ts; var id = getTypeListId(sortedTypes); var type = unionTypes[id]; if (!type) { - type = unionTypes[id] = createObjectType(16384 /* Union */ | getUnwidenedFlagOfTypes(sortedTypes)); + type = unionTypes[id] = createObjectType(16384 /* Union */ | getWideningFlagsOfTypes(sortedTypes)); type.types = sortedTypes; } return type; @@ -9481,6 +9608,8 @@ var ts; case 128 /* MethodDeclaration */: case 127 /* MethodSignature */: return isContextSensitiveFunctionLikeDeclaration(node); + case 155 /* ParenthesizedExpression */: + return isContextSensitive(node.expression); } return false; } @@ -9541,6 +9670,10 @@ var ts; error(errorNode, ts.Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target)); } else if (errorInfo) { + if (errorInfo.next === undefined) { + errorInfo = undefined; + isRelatedTo(source, target, errorNode !== undefined, headMessage, true); + } if (containingMessageChain) { errorInfo = ts.concatenateDiagnosticMessageChains(containingMessageChain, errorInfo); } @@ -9550,7 +9683,8 @@ var ts; function reportError(message, arg0, arg1, arg2) { errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); } - function isRelatedTo(source, target, reportErrors, headMessage) { + function isRelatedTo(source, target, reportErrors, headMessage, elaborateErrors) { + if (elaborateErrors === void 0) { elaborateErrors = false; } var result; if (source === target) return -1 /* True */; @@ -9619,7 +9753,7 @@ var ts; } var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo; var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source); - if (sourceOrApparentType.flags & 48128 /* ObjectType */ && target.flags & 48128 /* ObjectType */ && (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors))) { + if (sourceOrApparentType.flags & 48128 /* ObjectType */ && target.flags & 48128 /* ObjectType */ && (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors, elaborateErrors))) { errorInfo = saveErrorInfo; return result; } @@ -9700,14 +9834,17 @@ var ts; return 0 /* False */; } } - function objectTypeRelatedTo(source, target, reportErrors) { + function objectTypeRelatedTo(source, target, reportErrors, elaborateErrors) { + if (elaborateErrors === void 0) { elaborateErrors = false; } if (overflow) { return 0 /* False */; } var id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id; var related = relation[id]; if (related !== undefined) { - return related ? -1 /* True */ : 0 /* False */; + if (!elaborateErrors || (related === 3 /* FailedAndReported */)) { + return related === 1 /* Succeeded */ ? -1 /* True */ : 0 /* False */; + } } if (depth > 0) { for (var i = 0; i < depth; i++) { @@ -9729,7 +9866,7 @@ var ts; sourceStack[depth] = source; targetStack[depth] = target; maybeStack[depth] = {}; - maybeStack[depth][id] = true; + maybeStack[depth][id] = 1 /* Succeeded */; depth++; var saveExpandingFlags = expandingFlags; if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack)) @@ -9758,11 +9895,11 @@ var ts; depth--; if (result) { var maybeCache = maybeStack[depth]; - var destinationCache = result === -1 /* True */ || depth === 0 ? relation : maybeStack[depth - 1]; + var destinationCache = (result === -1 /* True */ || depth === 0) ? relation : maybeStack[depth - 1]; ts.copyMap(maybeCache, destinationCache); } else { - relation[id] = false; + relation[id] = reportErrors ? 3 /* FailedAndReported */ : 2 /* Failed */; } return result; } @@ -9787,12 +9924,13 @@ var ts; } var result = -1 /* True */; var properties = getPropertiesOfObjectType(target); + var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 131072 /* ObjectLiteral */); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { - if (relation === subtypeRelation || !(targetProp.flags & 536870912 /* Optional */)) { + if (!(targetProp.flags & 536870912 /* Optional */) || requireOptionalProperties) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } @@ -10137,9 +10275,6 @@ var ts; } checkTypeSubtypeOf(bestSupertypeDownfallType, bestSupertype, errorLocation, ts.Diagnostics.Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0, errorMessageChainHead); } - function isTypeOfObjectLiteral(type) { - return (type.flags & 32768 /* Anonymous */) && type.symbol && (type.symbol.flags & 4096 /* ObjectLiteral */) ? true : false; - } function isArrayType(type) { return type.flags & 4096 /* Reference */ && type.target === globalArrayType; } @@ -10150,14 +10285,19 @@ var ts; var properties = getPropertiesOfObjectType(type); var members = {}; ts.forEach(properties, function (p) { - var symbol = createSymbol(p.flags | 67108864 /* Transient */, p.name); - symbol.declarations = p.declarations; - symbol.parent = p.parent; - symbol.type = getWidenedType(getTypeOfSymbol(p)); - symbol.target = p; - if (p.valueDeclaration) - symbol.valueDeclaration = p.valueDeclaration; - members[symbol.name] = symbol; + var propType = getTypeOfSymbol(p); + var widenedType = getWidenedType(propType); + if (propType !== widenedType) { + var symbol = createSymbol(p.flags | 67108864 /* Transient */, p.name); + symbol.declarations = p.declarations; + symbol.parent = p.parent; + symbol.type = widenedType; + symbol.target = p; + if (p.valueDeclaration) + symbol.valueDeclaration = p.valueDeclaration; + p = symbol; + } + members[p.name] = p; }); var stringIndexType = getIndexTypeOfType(type, 0 /* String */); var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); @@ -10168,16 +10308,16 @@ var ts; return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); } function getWidenedType(type) { - if (type.flags & 131072 /* Unwidened */) { + if (type.flags & 786432 /* RequiresWidening */) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } + if (type.flags & 131072 /* ObjectLiteral */) { + return getWidenedTypeOfObjectLiteral(type); + } if (type.flags & 16384 /* Union */) { return getUnionType(ts.map(type.types, getWidenedType)); } - if (isTypeOfObjectLiteral(type)) { - return getWidenedTypeOfObjectLiteral(type); - } if (isArrayType(type)) { return createArrayType(getWidenedType(type.typeArguments[0])); } @@ -10197,11 +10337,11 @@ var ts; if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } - if (isTypeOfObjectLiteral(type)) { + if (type.flags & 131072 /* ObjectLiteral */) { var errorReported = false; ts.forEach(getPropertiesOfObjectType(type), function (p) { var t = getTypeOfSymbol(p); - if (t.flags & 131072 /* Unwidened */) { + if (t.flags & 262144 /* ContainsUndefinedOrNull */) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } @@ -10241,7 +10381,7 @@ var ts; error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); } function reportErrorsFromWidening(declaration, type) { - if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 131072 /* Unwidened */) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 262144 /* ContainsUndefinedOrNull */) { if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); } @@ -10465,11 +10605,14 @@ var ts; } ts.Debug.fail("should not get here"); } - function subtractPrimitiveTypes(type, subtractMask) { + function removeTypesFromUnionType(type, typeKind, isOfTypeKind) { if (type.flags & 16384 /* Union */) { var types = type.types; - if (ts.forEach(types, function (t) { return t.flags & subtractMask; })) { - return getUnionType(ts.filter(types, function (t) { return !(t.flags & subtractMask); })); + if (ts.forEach(types, function (t) { return !!(t.flags & typeKind) === isOfTypeKind; })) { + var narrowedType = getUnionType(ts.filter(types, function (t) { return !(t.flags & typeKind) === isOfTypeKind; })); + if (narrowedType !== emptyObjectType) { + return narrowedType; + } } } return type; @@ -10614,7 +10757,7 @@ var ts; case 129 /* Constructor */: break loop; } - if (narrowedType !== type && isTypeSubtypeOf(narrowedType, type)) { + if (narrowedType !== type) { if (isVariableAssignedWithin(symbol, node)) { break; } @@ -10632,16 +10775,24 @@ var ts; if (left.expression.kind !== 64 /* Identifier */ || getResolvedSymbol(left.expression) !== symbol) { return type; } - var t = right.text; - var checkType = t === "string" ? stringType : t === "number" ? numberType : t === "boolean" ? booleanType : emptyObjectType; + var typeInfo = primitiveTypeInfo[right.text]; if (expr.operator === 31 /* ExclamationEqualsEqualsToken */) { assumeTrue = !assumeTrue; } if (assumeTrue) { - return checkType === emptyObjectType ? subtractPrimitiveTypes(type, 2 /* String */ | 4 /* Number */ | 8 /* Boolean */) : checkType; + if (!typeInfo) { + return removeTypesFromUnionType(type, 258 /* StringLike */ | 132 /* NumberLike */ | 8 /* Boolean */, true); + } + if (isTypeSubtypeOf(typeInfo.type, type)) { + return typeInfo.type; + } + return removeTypesFromUnionType(type, typeInfo.flags, false); } else { - return checkType === emptyObjectType ? type : subtractPrimitiveTypes(type, checkType.flags); + if (typeInfo) { + return removeTypesFromUnionType(type, typeInfo.flags, true); + } + return type; } } function narrowTypeByAnd(type, expr, assumeTrue) { @@ -10678,8 +10829,14 @@ var ts; if (!prototypeProperty) { return type; } - var prototypeType = getTypeOfSymbol(prototypeProperty); - return isTypeSubtypeOf(prototypeType, type) ? prototypeType : type; + var targetType = getTypeOfSymbol(prototypeProperty); + if (isTypeSubtypeOf(targetType, type)) { + return targetType; + } + if (type.flags & 16384 /* Union */) { + return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); })); + } + return type; } function narrowType(type, expr, assumeTrue) { switch (expr.kind) { @@ -10777,6 +10934,9 @@ var ts; error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); } break; + case 122 /* ComputedPropertyName */: + error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_computed_property_name); + break; } if (needToCaptureLexicalThis) { captureLexicalThis(node, container); @@ -10788,26 +10948,6 @@ var ts; } return anyType; } - function getSuperContainer(node) { - while (true) { - node = node.parent; - if (!node) - return node; - switch (node.kind) { - case 190 /* FunctionDeclaration */: - case 156 /* FunctionExpression */: - case 157 /* ArrowFunction */: - case 126 /* PropertyDeclaration */: - case 125 /* PropertySignature */: - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - case 129 /* Constructor */: - case 130 /* GetAccessor */: - case 131 /* SetAccessor */: - return node; - } - } - } function isInConstructorArgumentInitializer(node, constructorDecl) { for (var n = node; n && n !== constructorDecl; n = n.parent) { if (n.kind === 124 /* Parameter */) { @@ -10828,7 +10968,7 @@ var ts; error(node, ts.Diagnostics.super_can_only_be_referenced_in_a_derived_class); return unknownType; } - var container = getSuperContainer(node); + var container = ts.getSuperContainer(node, true); if (container) { var canUseSuperExpression = false; if (isCallExpression) { @@ -10837,7 +10977,7 @@ var ts; else { var needToCaptureLexicalThis = false; while (container && container.kind === 157 /* ArrowFunction */) { - container = getSuperContainer(container); + container = ts.getSuperContainer(container, true); needToCaptureLexicalThis = true; } if (container && container.parent && container.parent.kind === 191 /* ClassDeclaration */) { @@ -10869,7 +11009,10 @@ var ts; return returnType; } } - if (isCallExpression) { + if (container.kind === 122 /* ComputedPropertyName */) { + error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); + } + else if (isCallExpression) { error(node, ts.Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors); } else { @@ -11008,9 +11151,15 @@ var ts; function getContextualTypeForObjectLiteralElement(element) { var objectLiteral = element.parent; var type = getContextualType(objectLiteral); - var name = element.name.text; - if (type && name) { - return getTypeOfPropertyOfContextualType(type, name) || isNumericName(name) && getIndexTypeOfContextualType(type, 1 /* Number */) || getIndexTypeOfContextualType(type, 0 /* String */); + if (type) { + if (!ts.hasDynamicName(element)) { + var symbolName = getSymbolOfNode(element).name; + var propertyType = getTypeOfPropertyOfContextualType(type, symbolName); + if (propertyType) { + return propertyType; + } + } + return isNumericName(element.name) && getIndexTypeOfContextualType(type, 1 /* Number */) || getIndexTypeOfContextualType(type, 0 /* String */); } return undefined; } @@ -11061,6 +11210,8 @@ var ts; case 169 /* TemplateSpan */: ts.Debug.assert(parent.parent.kind === 165 /* TemplateExpression */); return getContextualTypeForSubstitutionExpression(parent.parent, node); + case 155 /* ParenthesizedExpression */: + return getContextualType(parent); } return undefined; } @@ -11165,72 +11316,84 @@ var ts; return createArrayType(getUnionType(elementTypes)); } function isNumericName(name) { + return name.kind === 122 /* ComputedPropertyName */ ? isNumericComputedName(name) : isNumericLiteralName(name.text); + } + function isNumericComputedName(name) { + return isTypeOfKind(checkComputedPropertyName(name), 1 /* Any */ | 132 /* NumberLike */); + } + function isNumericLiteralName(name) { return (+name).toString() === name; } + function checkComputedPropertyName(node) { + var links = getNodeLinks(node.expression); + if (!links.resolvedType) { + links.resolvedType = checkExpression(node.expression); + if (!isTypeOfKind(links.resolvedType, 1 /* Any */ | 132 /* NumberLike */ | 258 /* StringLike */)) { + error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_or_any); + } + } + return links.resolvedType; + } function checkObjectLiteral(node, contextualMapper) { checkGrammarObjectLiteralExpression(node); - var members = node.symbol.members; - var properties = {}; + var propertiesTable = {}; + var propertiesArray = []; var contextualType = getContextualType(node); var typeFlags; - for (var id in members) { - if (ts.hasProperty(members, id)) { - var member = members[id]; - if (member.flags & 4 /* Property */ || ts.isObjectLiteralMethod(member.declarations[0])) { - var memberDecl = member.declarations[0]; - if (memberDecl.kind === 204 /* PropertyAssignment */) { - var type = checkExpression(memberDecl.initializer, contextualMapper); - } - else if (memberDecl.kind === 128 /* MethodDeclaration */) { - var type = checkObjectLiteralMethod(memberDecl, contextualMapper); - } - else { - ts.Debug.assert(memberDecl.kind === 205 /* ShorthandPropertyAssignment */); - var type = memberDecl.name.kind === 122 /* ComputedPropertyName */ ? unknownType : checkExpression(memberDecl.name, contextualMapper); - } - typeFlags |= type.flags; - var prop = createSymbol(4 /* Property */ | 67108864 /* Transient */ | member.flags, member.name); - prop.declarations = member.declarations; - prop.parent = member.parent; - if (member.valueDeclaration) { - prop.valueDeclaration = member.valueDeclaration; - } - prop.type = type; - prop.target = member; - member = prop; + for (var i = 0; i < node.properties.length; i++) { + var memberDecl = node.properties[i]; + var member = memberDecl.symbol; + if (memberDecl.kind === 204 /* PropertyAssignment */ || memberDecl.kind === 205 /* ShorthandPropertyAssignment */ || ts.isObjectLiteralMethod(memberDecl)) { + if (memberDecl.kind === 204 /* PropertyAssignment */) { + var type = checkPropertyAssignment(memberDecl, contextualMapper); + } + else if (memberDecl.kind === 128 /* MethodDeclaration */) { + var type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { - var getAccessor = ts.getDeclarationOfKind(member, 130 /* GetAccessor */); - if (getAccessor) { - checkAccessorDeclaration(getAccessor); - } - var setAccessor = ts.getDeclarationOfKind(member, 131 /* SetAccessor */); - if (setAccessor) { - checkAccessorDeclaration(setAccessor); - } + ts.Debug.assert(memberDecl.kind === 205 /* ShorthandPropertyAssignment */); + var type = memberDecl.name.kind === 122 /* ComputedPropertyName */ ? unknownType : checkExpression(memberDecl.name, contextualMapper); } - properties[member.name] = member; + typeFlags |= type.flags; + var prop = createSymbol(4 /* Property */ | 67108864 /* Transient */ | member.flags, member.name); + prop.declarations = member.declarations; + prop.parent = member.parent; + if (member.valueDeclaration) { + prop.valueDeclaration = member.valueDeclaration; + } + prop.type = type; + prop.target = member; + member = prop; } + else { + ts.Debug.assert(memberDecl.kind === 130 /* GetAccessor */ || memberDecl.kind === 131 /* SetAccessor */); + checkAccessorDeclaration(memberDecl); + } + if (!ts.hasDynamicName(memberDecl)) { + propertiesTable[member.name] = member; + } + propertiesArray.push(member); } var stringIndexType = getIndexType(0 /* String */); var numberIndexType = getIndexType(1 /* Number */); - var result = createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= (typeFlags & 131072 /* Unwidened */); + var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); + result.flags |= 131072 /* ObjectLiteral */ | 524288 /* ContainsObjectLiteral */ | (typeFlags & 262144 /* ContainsUndefinedOrNull */); return result; function getIndexType(kind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { var propTypes = []; - for (var id in properties) { - if (ts.hasProperty(properties, id)) { - if (kind === 0 /* String */ || isNumericName(id)) { - var type = getTypeOfSymbol(properties[id]); - if (!ts.contains(propTypes, type)) { - propTypes.push(type); - } + for (var i = 0; i < propertiesArray.length; i++) { + var propertyDecl = node.properties[i]; + if (kind === 0 /* String */ || isNumericName(propertyDecl.name)) { + var type = getTypeOfSymbol(propertiesArray[i]); + if (!ts.contains(propTypes, type)) { + propTypes.push(type); } } } - return propTypes.length ? getUnionType(propTypes) : undefinedType; + var result = propTypes.length ? getUnionType(propTypes) : undefinedType; + typeFlags |= result.flags; + return result; } return undefined; } @@ -11341,8 +11504,10 @@ var ts; if (objectType === unknownType) { return unknownType; } - if (isConstEnumObjectType(objectType) && node.argumentExpression && node.argumentExpression.kind !== 8 /* StringLiteral */) { - error(node.argumentExpression, ts.Diagnostics.Index_expression_arguments_in_const_enums_must_be_of_type_string); + var isConstEnum = isConstEnumObjectType(objectType); + if (isConstEnum && (!node.argumentExpression || node.argumentExpression.kind !== 8 /* StringLiteral */)) { + error(node.argumentExpression, ts.Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal); + return unknownType; } if (node.argumentExpression) { if (node.argumentExpression.kind === 8 /* StringLiteral */ || node.argumentExpression.kind === 7 /* NumericLiteral */) { @@ -11352,10 +11517,14 @@ var ts; getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } + else if (isConstEnum) { + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name, symbolToString(objectType.symbol)); + return unknownType; + } } } - if (indexType.flags & (1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */)) { - if (indexType.flags & (1 /* Any */ | 132 /* NumberLike */)) { + if (isTypeOfKind(indexType, 1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */)) { + if (isTypeOfKind(indexType, 1 /* Any */ | 132 /* NumberLike */)) { var numberIndexType = getIndexTypeOfType(objectType, 1 /* Number */); if (numberIndexType) { return numberIndexType; @@ -11539,10 +11708,25 @@ var ts; } return args; } + function getEffectiveTypeArguments(callExpression) { + if (callExpression.expression.kind === 90 /* SuperKeyword */) { + var containingClass = ts.getAncestor(callExpression, 191 /* ClassDeclaration */); + var baseClassTypeNode = containingClass && ts.getClassBaseTypeNode(containingClass); + return baseClassTypeNode && baseClassTypeNode.typeArguments; + } + else { + return callExpression.typeArguments; + } + } function resolveCall(node, signatures, candidatesOutArray) { var isTaggedTemplate = node.kind === 153 /* TaggedTemplateExpression */; - var typeArguments = isTaggedTemplate ? undefined : node.typeArguments; - ts.forEach(typeArguments, checkSourceElement); + var typeArguments; + if (!isTaggedTemplate) { + typeArguments = getEffectiveTypeArguments(node); + if (node.expression.kind !== 90 /* SuperKeyword */) { + ts.forEach(typeArguments, checkSourceElement); + } + } var candidates = candidatesOutArray || []; collectCandidates(); if (!candidates.length) { @@ -11659,8 +11843,10 @@ var ts; var result = candidates; var lastParent; var lastSymbol; - var cutoffPos = 0; - var pos; + var cutoffIndex = 0; + var index; + var specializedIndex = -1; + var spliceIndex; ts.Debug.assert(!result.length); for (var i = 0; i < signatures.length; i++) { var signature = signatures[i]; @@ -11668,22 +11854,27 @@ var ts; var parent = signature.declaration && signature.declaration.parent; if (!lastSymbol || symbol === lastSymbol) { if (lastParent && parent === lastParent) { - pos++; + index++; } else { lastParent = parent; - pos = cutoffPos; + index = cutoffIndex; } } else { - pos = cutoffPos = result.length; + index = cutoffIndex = result.length; lastParent = parent; } lastSymbol = symbol; - for (var j = result.length; j > pos; j--) { - result[j] = result[j - 1]; + if (signature.hasStringLiterals) { + specializedIndex++; + spliceIndex = specializedIndex; + cutoffIndex++; } - result[pos] = signature; + else { + spliceIndex = index; + } + result.splice(spliceIndex, 0, signature); } } } @@ -11799,7 +11990,7 @@ var ts; return getReturnTypeOfSignature(signature); } function checkTaggedTemplateExpression(node) { - if (compilerOptions.target < 2 /* ES6 */) { + if (languageVersion < 2 /* ES6 */) { grammarErrorOnFirstToken(node.template, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); } return getReturnTypeOfSignature(getResolvedSignature(node)); @@ -11948,7 +12139,7 @@ var ts; } } function checkArithmeticOperandType(operand, type, diagnostic) { - if (!(type.flags & (1 /* Any */ | 132 /* NumberLike */))) { + if (!isTypeOfKind(type, 1 /* Any */ | 132 /* NumberLike */)) { error(operand, diagnostic); return false; } @@ -12052,11 +12243,20 @@ var ts; } return numberType; } - function isStructuredType(type) { - if (type.flags & 16384 /* Union */) { - return !ts.forEach(type.types, function (t) { return !isStructuredType(t); }); + function isTypeOfKind(type, kind) { + if (type.flags & kind) { + return true; } - return (type.flags & (48128 /* ObjectType */ | 512 /* TypeParameter */)) !== 0; + if (type.flags & 16384 /* Union */) { + var types = type.types; + for (var i = 0; i < types.length; i++) { + if (!(types[i].flags & kind)) { + return false; + } + } + return true; + } + return false; } function isConstEnumObjectType(type) { return type.flags & (48128 /* ObjectType */ | 32768 /* Anonymous */) && type.symbol && isConstEnumSymbol(type.symbol); @@ -12065,7 +12265,7 @@ var ts; return (symbol.flags & 128 /* ConstEnum */) !== 0; } function checkInstanceOfExpression(node, leftType, rightType) { - if (!(leftType.flags & 1 /* Any */ || isStructuredType(leftType))) { + if (isTypeOfKind(leftType, 510 /* Primitive */)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } if (!(rightType.flags & 1 /* Any */ || isTypeSubtypeOf(rightType, globalFunctionType))) { @@ -12074,10 +12274,10 @@ var ts; return booleanType; } function checkInExpression(node, leftType, rightType) { - if (leftType !== anyType && leftType !== stringType && leftType !== numberType) { + if (!isTypeOfKind(leftType, 1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number); } - if (!(rightType.flags & 1 /* Any */ || isStructuredType(rightType))) { + if (!isTypeOfKind(rightType, 1 /* Any */ | 48128 /* ObjectType */ | 512 /* TypeParameter */)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -12088,7 +12288,7 @@ var ts; var p = properties[i]; if (p.kind === 204 /* PropertyAssignment */ || p.kind === 205 /* ShorthandPropertyAssignment */) { var name = p.name; - var type = sourceType.flags & 1 /* Any */ ? sourceType : getTypeOfPropertyOfType(sourceType, name.text) || isNumericName(name.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); + var type = sourceType.flags & 1 /* Any */ ? sourceType : getTypeOfPropertyOfType(sourceType, name.text) || isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); if (type) { checkDestructuringAssignment(p.initializer || name, type); } @@ -12207,13 +12407,13 @@ var ts; if (rightType.flags & (32 /* Undefined */ | 64 /* Null */)) rightType = leftType; var resultType; - if (leftType.flags & 132 /* NumberLike */ && rightType.flags & 132 /* NumberLike */) { + if (isTypeOfKind(leftType, 132 /* NumberLike */) && isTypeOfKind(rightType, 132 /* NumberLike */)) { resultType = numberType; } - else if (leftType.flags & 258 /* StringLike */ || rightType.flags & 258 /* StringLike */) { + else if (isTypeOfKind(leftType, 258 /* StringLike */) || isTypeOfKind(rightType, 258 /* StringLike */)) { resultType = stringType; } - else if (leftType.flags & 1 /* Any */ || leftType === unknownType || rightType.flags & 1 /* Any */ || rightType === unknownType) { + else if (leftType.flags & 1 /* Any */ || rightType.flags & 1 /* Any */) { resultType = anyType; } if (!resultType) { @@ -12311,8 +12511,17 @@ var ts; } return links.resolvedType; } + function checkPropertyAssignment(node, contextualMapper) { + if (ts.hasDynamicName(node)) { + checkComputedPropertyName(node.name); + } + return checkExpression(node.initializer, contextualMapper); + } function checkObjectLiteralMethod(node, contextualMapper) { checkGrammarMethod(node); + if (ts.hasDynamicName(node)) { + checkComputedPropertyName(node.name); + } var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } @@ -12435,12 +12644,15 @@ var ts; checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, node.name); checkVariableLikeDeclaration(node); var func = ts.getContainingFunction(node); - if (node.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */)) { + if (node.flags & 112 /* AccessibilityModifier */) { func = ts.getContainingFunction(node); if (!(func.kind === 129 /* Constructor */ && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } + if (node.questionToken && ts.isBindingPattern(node.name) && func.body) { + error(node, ts.Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature); + } if (node.dotDotDotToken) { if (!isArrayType(getTypeOfSymbol(node.symbol))) { error(node, ts.Diagnostics.A_rest_parameter_must_be_of_an_array_type); @@ -12585,7 +12797,7 @@ var ts; error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement); } } - if (!ts.hasComputedNameButNotSymbol(node)) { + if (!ts.hasDynamicName(node)) { var otherKind = node.kind === 130 /* GetAccessor */ ? 131 /* SetAccessor */ : 130 /* GetAccessor */; var otherAccessor = ts.getDeclarationOfKind(node.symbol, otherKind); if (otherAccessor) { @@ -12600,8 +12812,8 @@ var ts; } } } - checkAndStoreTypeOfAccessors(getSymbolOfNode(node)); } + checkAndStoreTypeOfAccessors(getSymbolOfNode(node)); } checkFunctionLikeDeclaration(node); } @@ -12909,7 +13121,10 @@ var ts; } function checkFunctionLikeDeclaration(node) { checkSignatureDeclaration(node); - if (!ts.hasComputedNameButNotSymbol(node)) { + if (ts.hasDynamicName(node)) { + checkComputedPropertyName(node.name); + } + else { var symbol = getSymbolOfNode(node); var localSymbol = node.localSymbol || symbol; var firstDeclaration = ts.getDeclarationOfKind(localSymbol, node.kind); @@ -13063,7 +13278,8 @@ var ts; } function checkVariableLikeDeclaration(node) { checkSourceElement(node.type); - if (ts.hasComputedNameButNotSymbol(node)) { + if (ts.hasDynamicName(node)) { + checkComputedPropertyName(node.name); if (node.initializer) { checkExpressionCached(node.initializer); } @@ -13207,7 +13423,7 @@ var ts; } } var exprType = checkExpression(node.expression); - if (!(exprType.flags & 1 /* Any */ || isStructuredType(exprType))) { + if (!isTypeOfKind(exprType, 1 /* Any */ | 48128 /* ObjectType */ | 512 /* TypeParameter */)) { 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); @@ -13327,29 +13543,6 @@ var ts; checkBlock(node.finallyBlock); } function checkIndexConstraints(type) { - function checkIndexConstraintForProperty(prop, propertyType, indexDeclaration, indexType, indexKind) { - if (!indexType) { - return; - } - if (indexKind === 1 /* Number */ && !isNumericName(prop.name)) { - return; - } - var errorNode; - if (prop.parent === type.symbol) { - errorNode = prop.valueDeclaration; - } - else if (indexDeclaration) { - errorNode = indexDeclaration; - } - else if (type.flags & 2048 /* Interface */) { - var someBaseClassHasBothPropertyAndIndexer = ts.forEach(type.baseTypes, function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); - errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : type.symbol.declarations[0]; - } - if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { - var errorMessage = indexKind === 0 /* String */ ? 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)); - } - } var declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, 1 /* Number */); var declaredStringIndexer = getIndexDeclarationOfSymbol(type.symbol, 0 /* String */); var stringIndexType = getIndexTypeOfType(type, 0 /* String */); @@ -13357,9 +13550,20 @@ var ts; if (stringIndexType || numberIndexType) { ts.forEach(getPropertiesOfObjectType(type), function (prop) { var propType = getTypeOfSymbol(prop); - checkIndexConstraintForProperty(prop, propType, declaredStringIndexer, stringIndexType, 0 /* String */); - checkIndexConstraintForProperty(prop, propType, declaredNumberIndexer, numberIndexType, 1 /* Number */); + checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, 0 /* String */); + checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, 1 /* Number */); }); + if (type.flags & 1024 /* Class */ && type.symbol.valueDeclaration.kind === 191 /* ClassDeclaration */) { + var classDeclaration = type.symbol.valueDeclaration; + for (var i = 0; i < classDeclaration.members.length; i++) { + var member = classDeclaration.members[i]; + if (!(member.flags & 128 /* Static */) && ts.hasDynamicName(member)) { + var propType = getTypeOfSymbol(member.symbol); + checkIndexConstraintForProperty(member.symbol, propType, type, declaredStringIndexer, stringIndexType, 0 /* String */); + checkIndexConstraintForProperty(member.symbol, propType, type, declaredNumberIndexer, numberIndexType, 1 /* Number */); + } + } + } } var errorNode; if (stringIndexType && numberIndexType) { @@ -13372,6 +13576,29 @@ var ts; if (errorNode && !isTypeAssignableTo(numberIndexType, stringIndexType)) { error(errorNode, ts.Diagnostics.Numeric_index_type_0_is_not_assignable_to_string_index_type_1, typeToString(numberIndexType), typeToString(stringIndexType)); } + function checkIndexConstraintForProperty(prop, propertyType, containingType, indexDeclaration, indexType, indexKind) { + if (!indexType) { + return; + } + if (indexKind === 1 /* Number */ && !isNumericName(prop.valueDeclaration.name)) { + return; + } + var errorNode; + if (prop.valueDeclaration.name.kind === 122 /* ComputedPropertyName */ || prop.parent === containingType.symbol) { + errorNode = prop.valueDeclaration; + } + else if (indexDeclaration) { + errorNode = indexDeclaration; + } + else if (containingType.flags & 2048 /* Interface */) { + var someBaseClassHasBothPropertyAndIndexer = ts.forEach(containingType.baseTypes, function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); + errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0]; + } + if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { + var errorMessage = indexKind === 0 /* String */ ? 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)); + } + } } function checkTypeNameIsReserved(name, message) { switch (name.text) { @@ -13600,7 +13827,7 @@ var ts; var ambient = ts.isInAmbientContext(node); var enumIsConst = ts.isConst(node); ts.forEach(node.members, function (member) { - if (isNumericName(member.name.text)) { + if (member.name.kind !== 122 /* ComputedPropertyName */ && isNumericLiteralName(member.name.text)) { error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name); } var initializer = member.initializer; @@ -14564,8 +14791,8 @@ var ts; if (symbol && (symbol.flags & 8 /* EnumMember */)) { var declaration = symbol.valueDeclaration; var constantValue; - if (declaration.kind === 206 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) { - return constantValue; + if (declaration.kind === 206 /* EnumMember */) { + return getEnumMemberValue(declaration); } } return undefined; @@ -14624,7 +14851,7 @@ var ts; globalNumberType = getGlobalType("Number"); globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); - globalTemplateStringsArrayType = compilerOptions.target >= 2 /* ES6 */ ? getGlobalType("TemplateStringsArray") : unknownType; + globalTemplateStringsArrayType = languageVersion >= 2 /* ES6 */ ? getGlobalType("TemplateStringsArray") : unknownType; anyArrayType = createArrayType(anyType); } function checkGrammarModifiers(node) { @@ -14748,6 +14975,9 @@ var ts; else if (node.kind === 192 /* InterfaceDeclaration */ && flags & 2 /* Ambient */) { return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); } + else if (node.kind === 124 /* Parameter */ && (flags & 112 /* AccessibilityModifier */) && ts.isBindingPattern(node.name)) { + return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); + } } function checkGrammarForDisallowedTrailingComma(list) { if (list && list.hasTrailingComma) { @@ -14932,16 +15162,14 @@ var ts; } function checkGrammarComputedPropertyName(node) { if (node.kind !== 122 /* ComputedPropertyName */) { - return; + return false; } - grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_not_currently_supported); - return; var computedPropertyName = node; - if (compilerOptions.target < 2 /* ES6 */) { - grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); + if (languageVersion < 2 /* ES6 */) { + return grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); } else if (computedPropertyName.expression.kind === 163 /* BinaryExpression */ && computedPropertyName.expression.operator === 23 /* CommaToken */) { - grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); + return grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); } } function checkGrammarForGenerator(node) { @@ -15017,7 +15245,7 @@ var ts; } function checkGrammarAccessor(accessor) { var kind = accessor.kind; - if (compilerOptions.target < 1 /* ES5 */) { + if (languageVersion < 1 /* ES5 */) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); } else if (ts.isInAmbientContext(accessor)) { @@ -15182,7 +15410,7 @@ 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 (compilerOptions.target < 2 /* ES6 */) { + if (languageVersion < 2 /* ES6 */) { if (ts.isLet(declarationList)) { return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } @@ -15265,7 +15493,7 @@ var ts; function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = ts.createScanner(compilerOptions.target, true, sourceFile.text); + var scanner = ts.createScanner(languageVersion, true, sourceFile.text); var start = scanToken(scanner, node.pos); diagnostics.push(ts.createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2)); return true; @@ -15365,7 +15593,7 @@ var ts; if (node.parserContextFlags & 1 /* StrictMode */) { return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); } - else if (compilerOptions.target >= 1 /* ES5 */) { + else if (languageVersion >= 1 /* ES5 */) { return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); } } @@ -15373,7 +15601,7 @@ var ts; function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = ts.createScanner(compilerOptions.target, true, sourceFile.text); + var scanner = ts.createScanner(languageVersion, true, sourceFile.text); scanToken(scanner, node.pos); diagnostics.push(ts.createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2)); return true; @@ -15500,9 +15728,10 @@ var ts; function writeCommentRange(currentSourceFile, writer, comment, newLine) { if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) { var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos); + var lastLine = currentSourceFile.getLineStarts().length; var firstCommentLineIndent; for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, 1); + var nextLineStart = currentLine === lastLine ? (comment.end + 1) : currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, 1); if (pos !== comment.pos) { if (firstCommentLineIndent === undefined) { firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, 1), comment.pos); @@ -15622,6 +15851,7 @@ var ts; function emitDeclarations(host, resolver, diagnostics, jsFilePath, root) { var newLine = host.getNewLine(); var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || 0 /* ES3 */; var write; var writeLine; var increaseIndent; @@ -16114,6 +16344,9 @@ var ts; } } function emitPropertyDeclaration(node) { + if (ts.hasDynamicName(node)) { + return; + } emitJsDocComments(node); emitClassMemberDeclarationFlags(node); emitVariableDeclaration(node); @@ -16182,6 +16415,9 @@ var ts; } } function emitAccessorDeclaration(node) { + if (ts.hasDynamicName(node)) { + return; + } var accessors = getAllAccessorDeclarations(node.parent, node); if (node === accessors.firstAccessor) { emitJsDocComments(accessors.getAccessor); @@ -16239,6 +16475,9 @@ var ts; } } function emitFunctionDeclaration(node) { + if (ts.hasDynamicName(node)) { + return; + } if ((node.kind !== 190 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); if (node.kind === 190 /* FunctionDeclaration */) { @@ -16490,6 +16729,7 @@ var ts; ts.getDeclarationDiagnostics = getDeclarationDiagnostics; function emitFiles(resolver, host, targetSourceFile) { var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || 0 /* ES3 */; var sourceMapDataList = compilerOptions.sourceMap ? [] : undefined; var diagnostics = []; var newLine = host.getNewLine(); @@ -16646,7 +16886,11 @@ var ts; if (scopeName) { var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { - scopeName = sourceMapData.sourceMapNames[parentIndex] + "." + scopeName; + var name = node.name; + if (!name || name.kind !== 122 /* ComputedPropertyName */) { + scopeName = "." + scopeName; + } + scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; } scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); if (scopeNameIndex === undefined) { @@ -16662,7 +16906,8 @@ var ts; } else if (node.kind === 190 /* FunctionDeclaration */ || node.kind === 156 /* FunctionExpression */ || node.kind === 128 /* MethodDeclaration */ || node.kind === 127 /* MethodSignature */ || node.kind === 130 /* GetAccessor */ || node.kind === 131 /* SetAccessor */ || node.kind === 195 /* ModuleDeclaration */ || node.kind === 191 /* ClassDeclaration */ || node.kind === 194 /* EnumDeclaration */) { if (node.name) { - scopeName = node.name.text; + var name = node.name; + scopeName = name.kind === 122 /* ComputedPropertyName */ ? ts.getTextOfNode(name) : node.name.text; } recordScopeNameStart(scopeName); } @@ -16882,11 +17127,11 @@ var ts; return false; } function emitLiteral(node) { - var text = compilerOptions.target < 2 /* ES6 */ && ts.isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; + var text = languageVersion < 2 /* ES6 */ && ts.isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; if (compilerOptions.sourceMap && (node.kind === 8 /* StringLiteral */ || ts.isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } - else if (compilerOptions.target < 2 /* ES6 */ && node.kind === 7 /* NumericLiteral */ && isBinaryOrOctalIntegerLiteral(text)) { + else if (languageVersion < 2 /* ES6 */ && node.kind === 7 /* NumericLiteral */ && isBinaryOrOctalIntegerLiteral(text)) { write(node.text); } else { @@ -16897,7 +17142,7 @@ var ts; return '"' + ts.escapeString(node.text) + '"'; } function emitTemplateExpression(node) { - if (compilerOptions.target >= 2 /* ES6 */) { + if (languageVersion >= 2 /* ES6 */) { ts.forEachChild(node, emit); return; } @@ -16944,7 +17189,7 @@ var ts; } } function comparePrecedenceToBinaryPlus(expression) { - ts.Debug.assert(compilerOptions.target <= 1 /* ES5 */); + ts.Debug.assert(languageVersion < 2 /* ES6 */); switch (expression.kind) { case 163 /* BinaryExpression */: switch (expression.operator) { @@ -17110,7 +17355,7 @@ var ts; write("[]"); return; } - if (compilerOptions.target >= 2 /* ES6 */) { + if (languageVersion >= 2 /* ES6 */) { write("["); emitList(elements, 0, elements.length, (node.flags & 256 /* MultiLine */) !== 0, elements.hasTrailingComma); write("]"); @@ -17155,7 +17400,7 @@ var ts; if (!multiLine) { write(" "); } - emitList(properties, 0, properties.length, multiLine, properties.hasTrailingComma && compilerOptions.target >= 1 /* ES5 */); + emitList(properties, 0, properties.length, multiLine, properties.hasTrailingComma && languageVersion >= 1 /* ES5 */); if (!multiLine) { write(" "); } @@ -17168,32 +17413,23 @@ var ts; write("]"); } function emitMethod(node) { - if (!ts.isObjectLiteralMethod(node)) { - return; - } - emitLeadingComments(node); emit(node.name); - if (compilerOptions.target < 2 /* ES6 */) { + if (languageVersion < 2 /* ES6 */) { write(": function "); } emitSignatureAndBody(node); - emitTrailingComments(node); } function emitPropertyAssignment(node) { - emitLeadingComments(node); emit(node.name); write(": "); emit(node.initializer); - emitTrailingComments(node); } function emitShorthandPropertyAssignment(node) { - emitLeadingComments(node); emit(node.name); - if (compilerOptions.target < 2 /* ES6 */ || resolver.getExpressionNamePrefix(node.name)) { + if (languageVersion < 2 /* ES6 */ || resolver.getExpressionNamePrefix(node.name)) { write(": "); emitExpressionIdentifier(node.name); } - emitTrailingComments(node); } function tryEmitConstantValue(node) { var constantValue = resolver.getConstantValue(node); @@ -17261,7 +17497,7 @@ var ts; } } function emitTaggedTemplateExpression(node) { - ts.Debug.assert(compilerOptions.target >= 2 /* ES6 */, "Trying to emit a tagged template in pre-ES6 mode."); + ts.Debug.assert(languageVersion >= 2 /* ES6 */, "Trying to emit a tagged template in pre-ES6 mode."); emit(node.tag); write(" "); emit(node.template); @@ -17314,7 +17550,7 @@ var ts; write(ts.tokenToString(node.operator)); } function emitBinaryExpression(node) { - if (compilerOptions.target < 2 /* ES6 */ && node.operator === 52 /* EqualsToken */ && (node.left.kind === 148 /* ObjectLiteralExpression */ || node.left.kind === 147 /* ArrayLiteralExpression */)) { + if (languageVersion < 2 /* ES6 */ && node.operator === 52 /* EqualsToken */ && (node.left.kind === 148 /* ObjectLiteralExpression */ || node.left.kind === 147 /* ArrayLiteralExpression */)) { emitDestructuring(node); } else { @@ -17363,13 +17599,10 @@ var ts; } } function emitExpressionStatement(node) { - emitLeadingComments(node); emitParenthesized(node.expression, node.expression.kind === 157 /* ArrowFunction */); write(";"); - emitTrailingComments(node); } function emitIfStatement(node) { - emitLeadingComments(node); var endPos = emitToken(83 /* IfKeyword */, node.pos); write(" "); endPos = emitToken(16 /* OpenParenToken */, endPos); @@ -17387,7 +17620,6 @@ var ts; emitEmbeddedStatement(node.elseStatement); } } - emitTrailingComments(node); } function emitDoStatement(node) { write("do"); @@ -17469,11 +17701,9 @@ var ts; write(";"); } function emitReturnStatement(node) { - emitLeadingComments(node); emitToken(89 /* ReturnKeyword */, node.pos); emitOptional(" ", node.expression); write(";"); - emitTrailingComments(node); } function emitWithStatement(node) { write("with ("); @@ -17754,9 +17984,8 @@ var ts; } } function emitVariableDeclaration(node) { - emitLeadingComments(node); if (ts.isBindingPattern(node.name)) { - if (compilerOptions.target < 2 /* ES6 */) { + if (languageVersion < 2 /* ES6 */) { emitDestructuring(node); } else { @@ -17768,10 +17997,8 @@ var ts; emitModuleMemberName(node); emitOptional(" = ", node.initializer); } - emitTrailingComments(node); } function emitVariableStatement(node) { - emitLeadingComments(node); if (!(node.flags & 1 /* Export */)) { if (ts.isLet(node.declarationList)) { write("let "); @@ -17785,11 +18012,9 @@ var ts; } emitCommaList(node.declarationList.declarations); write(";"); - emitTrailingComments(node); } function emitParameter(node) { - emitLeadingComments(node); - if (compilerOptions.target < 2 /* ES6 */) { + if (languageVersion < 2 /* ES6 */) { if (ts.isBindingPattern(node.name)) { var name = createTempVariable(node); if (!tempParameters) { @@ -17809,10 +18034,9 @@ var ts; emit(node.name); emitOptional(" = ", node.initializer); } - emitTrailingComments(node); } function emitDefaultValueAssignments(node) { - if (compilerOptions.target < 2 /* ES6 */) { + if (languageVersion < 2 /* ES6 */) { var tempIndex = 0; ts.forEach(node.parameters, function (p) { if (ts.isBindingPattern(p.name)) { @@ -17841,7 +18065,7 @@ var ts; } } function emitRestParameter(node) { - if (compilerOptions.target < 2 /* ES6 */ && ts.hasRestParameters(node)) { + if (languageVersion < 2 /* ES6 */ && ts.hasRestParameters(node)) { var restIndex = node.parameters.length - 1; var restParam = node.parameters[restIndex]; var tempName = createTempVariable(node, true).text; @@ -17879,11 +18103,9 @@ var ts; } } function emitAccessor(node) { - emitLeadingComments(node); write(node.kind === 130 /* GetAccessor */ ? "get " : "set "); emit(node.name); emitSignatureAndBody(node); - emitTrailingComments(node); } function emitFunctionDeclaration(node) { if (ts.nodeIsMissing(node.body)) { @@ -17914,7 +18136,7 @@ var ts; write("("); if (node) { var parameters = node.parameters; - var omitCount = compilerOptions.target < 2 /* ES6 */ && ts.hasRestParameters(node) ? 1 : 0; + var omitCount = languageVersion < 2 /* ES6 */ && ts.hasRestParameters(node) ? 1 : 0; emitList(parameters, 0, parameters.length - omitCount, false, false); } write(")"); @@ -17945,7 +18167,7 @@ var ts; write(" "); emitStart(node.body); write("return "); - emitNode(node.body); + emitNode(node.body, true); emitEnd(node.body); write(";"); emitTempDeclarations(false); @@ -17962,7 +18184,7 @@ var ts; writeLine(); emitLeadingComments(node.body); write("return "); - emit(node.body); + emit(node.body, true); write(";"); emitTrailingComments(node.body); } @@ -18136,7 +18358,6 @@ var ts; }); } function emitClassDeclaration(node) { - emitLeadingComments(node); write("var "); emit(node.name); write(" = (function ("); @@ -18186,7 +18407,6 @@ var ts; emitEnd(node); write(";"); } - emitTrailingComments(node); function emitConstructorOfClass() { var saveTempCount = tempCount; var saveTempVariables = tempVariables; @@ -18261,12 +18481,14 @@ var ts; function emitInterfaceDeclaration(node) { emitPinnedOrTripleSlashComments(node); } - function emitEnumDeclaration(node) { + function shouldEmitEnumDeclaration(node) { var isConstEnum = ts.isConst(node); - if (isConstEnum && !compilerOptions.preserveConstEnums) { + return !isConstEnum || compilerOptions.preserveConstEnums; + } + function emitEnumDeclaration(node) { + if (!shouldEmitEnumDeclaration(node)) { return; } - emitLeadingComments(node); if (!(node.flags & 1 /* Export */)) { emitStart(node); write("var "); @@ -18283,7 +18505,7 @@ var ts; write(") {"); increaseIndent(); scopeEmitStart(node); - emitEnumMemberDeclarations(isConstEnum); + emitLines(node.members); decreaseIndent(); writeLine(); emitToken(15 /* CloseBraceToken */, node.members.end); @@ -18304,31 +18526,26 @@ var ts; emitEnd(node); write(";"); } - emitTrailingComments(node); - function emitEnumMemberDeclarations(isConstEnum) { - ts.forEach(node.members, function (member) { - writeLine(); - emitLeadingComments(member); - emitStart(member); - write(resolver.getLocalNameOfContainer(node)); - write("["); - write(resolver.getLocalNameOfContainer(node)); - write("["); - emitExpressionForPropertyName(member.name); - write("] = "); - if (member.initializer && !isConstEnum) { - emit(member.initializer); - } - else { - write(resolver.getEnumMemberValue(member).toString()); - } - write("] = "); - emitExpressionForPropertyName(member.name); - emitEnd(member); - write(";"); - emitTrailingComments(member); - }); + } + function emitEnumMember(node) { + var enumParent = node.parent; + emitStart(node); + write(resolver.getLocalNameOfContainer(enumParent)); + write("["); + write(resolver.getLocalNameOfContainer(enumParent)); + write("["); + emitExpressionForPropertyName(node.name); + write("] = "); + if (node.initializer && !ts.isConst(enumParent)) { + emit(node.initializer); } + else { + write(resolver.getEnumMemberValue(node).toString()); + } + write("] = "); + emitExpressionForPropertyName(node.name); + emitEnd(node); + write(";"); } function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { if (moduleDeclaration.body.kind === 195 /* ModuleDeclaration */) { @@ -18336,12 +18553,14 @@ var ts; return recursiveInnerModule || moduleDeclaration.body; } } + function shouldEmitModuleDeclaration(node) { + return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums); + } function emitModuleDeclaration(node) { - var shouldEmit = ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums); + var shouldEmit = shouldEmitModuleDeclaration(node); if (!shouldEmit) { return emitPinnedOrTripleSlashComments(node); } - emitLeadingComments(node); emitStart(node); write("var "); emit(node.name); @@ -18386,7 +18605,6 @@ var ts; emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - emitTrailingComments(node); } function emitImportDeclaration(node) { var emitImportDeclaration = resolver.isReferencedImportDeclaration(node); @@ -18559,13 +18777,38 @@ var ts; } emitLeadingComments(node.endOfFileToken); } - function emitNode(node) { + function emitNode(node, disableComments) { if (!node) { return; } if (node.flags & 2 /* Ambient */) { return emitPinnedOrTripleSlashComments(node); } + var emitComments = !disableComments && shouldEmitLeadingAndTrailingComments(node); + if (emitComments) { + emitLeadingComments(node); + } + emitJavaScriptWorker(node); + if (emitComments) { + emitTrailingComments(node); + } + } + function shouldEmitLeadingAndTrailingComments(node) { + switch (node.kind) { + case 192 /* InterfaceDeclaration */: + case 190 /* FunctionDeclaration */: + case 197 /* ImportDeclaration */: + case 193 /* TypeAliasDeclaration */: + case 198 /* ExportAssignment */: + return false; + case 195 /* ModuleDeclaration */: + return shouldEmitModuleDeclaration(node); + case 194 /* EnumDeclaration */: + return shouldEmitEnumDeclaration(node); + } + return true; + } + function emitJavaScriptWorker(node) { switch (node.kind) { case 64 /* Identifier */: return emitIdentifier(node); @@ -18702,6 +18945,8 @@ var ts; return emitInterfaceDeclaration(node); case 194 /* EnumDeclaration */: return emitEnumDeclaration(node); + case 206 /* EnumMember */: + return emitEnumMember(node); case 195 /* ModuleDeclaration */: return emitModuleDeclaration(node); case 197 /* ImportDeclaration */: @@ -18724,15 +18969,17 @@ var ts; return leadingComments; } function getLeadingCommentsToEmit(node) { - if (node.parent.kind === 207 /* SourceFile */ || node.pos !== node.parent.pos) { - var leadingComments; - if (hasDetachedComments(node.pos)) { - leadingComments = getLeadingCommentsWithoutDetachedComments(); + if (node.parent) { + if (node.parent.kind === 207 /* SourceFile */ || node.pos !== node.parent.pos) { + var leadingComments; + if (hasDetachedComments(node.pos)) { + leadingComments = getLeadingCommentsWithoutDetachedComments(); + } + else { + leadingComments = ts.getLeadingCommentRangesOfNode(node, currentSourceFile); + } + return leadingComments; } - else { - leadingComments = ts.getLeadingCommentRangesOfNode(node, currentSourceFile); - } - return leadingComments; } } function emitLeadingDeclarationComments(node) { @@ -18741,9 +18988,11 @@ var ts; emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); } function emitTrailingDeclarationComments(node) { - if (node.parent.kind === 207 /* SourceFile */ || node.end !== node.parent.end) { - var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); - emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); + if (node.parent) { + if (node.parent.kind === 207 /* SourceFile */ || node.end !== node.parent.end) { + var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); + emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); + } } } function emitLeadingCommentsOfLocalPosition(pos) { @@ -19181,7 +19430,7 @@ var ts; return; } var firstExternalModule = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); - if (firstExternalModule && options.module === 0 /* None */) { + if (firstExternalModule && !options.module) { var externalModuleErrorSpan = ts.getErrorSpanForNode(firstExternalModule.externalModuleIndicator); var errorStart = ts.skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos); var errorLength = externalModuleErrorSpan.end - errorStart; @@ -19261,6 +19510,10 @@ var ts; type: "boolean", description: ts.Diagnostics.Print_this_message }, + { + name: "listFiles", + type: "boolean" + }, { name: "locale", type: "string" @@ -19268,6 +19521,7 @@ var ts; { name: "mapRoot", type: "string", + isFilePath: true, description: ts.Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations, paramType: ts.Diagnostics.LOCATION }, @@ -19318,6 +19572,7 @@ var ts; { name: "outDir", type: "string", + isFilePath: true, description: ts.Diagnostics.Redirect_output_structure_to_the_directory, paramType: ts.Diagnostics.DIRECTORY }, @@ -19326,6 +19581,14 @@ var ts; type: "boolean", description: ts.Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code }, + { + name: "project", + shortName: "p", + type: "string", + isFilePath: true, + description: ts.Diagnostics.Compile_the_project_in_the_given_directory, + paramType: ts.Diagnostics.DIRECTORY + }, { name: "removeComments", type: "boolean", @@ -19339,6 +19602,7 @@ var ts; { name: "sourceRoot", type: "string", + isFilePath: true, description: ts.Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations, paramType: ts.Diagnostics.LOCATION }, @@ -19368,21 +19632,18 @@ var ts; description: ts.Diagnostics.Watch_input_files } ]; - var shortOptionNames = {}; - var optionNameMap = {}; - ts.forEach(ts.optionDeclarations, function (option) { - optionNameMap[option.name.toLowerCase()] = option; - if (option.shortName) { - shortOptionNames[option.shortName] = option.name; - } - }); function parseCommandLine(commandLine) { - var options = { - target: 0 /* ES3 */, - module: 0 /* None */ - }; + var options = {}; var filenames = []; var errors = []; + var shortOptionNames = {}; + var optionNameMap = {}; + ts.forEach(ts.optionDeclarations, function (option) { + optionNameMap[option.name.toLowerCase()] = option; + if (option.shortName) { + shortOptionNames[option.shortName] = option.name; + } + }); parseStrings(commandLine); return { options: options, @@ -19472,10 +19733,87 @@ var ts; } } ts.parseCommandLine = parseCommandLine; + function readConfigFile(filename) { + try { + var text = ts.sys.readFile(filename); + return /\S/.test(text) ? JSON.parse(text) : {}; + } + catch (e) { + } + } + ts.readConfigFile = readConfigFile; + function parseConfigFile(json, basePath) { + var errors = []; + return { + options: getCompilerOptions(), + filenames: getFiles(), + errors: errors + }; + function getCompilerOptions() { + var options = {}; + var optionNameMap = {}; + ts.forEach(ts.optionDeclarations, function (option) { + optionNameMap[option.name] = option; + }); + var jsonOptions = json["compilerOptions"]; + if (jsonOptions) { + for (var id in jsonOptions) { + if (ts.hasProperty(optionNameMap, id)) { + var opt = optionNameMap[id]; + var optType = opt.type; + var value = jsonOptions[id]; + var expectedType = typeof optType === "string" ? optType : "string"; + if (typeof value === expectedType) { + if (typeof optType !== "string") { + var key = value.toLowerCase(); + if (ts.hasProperty(optType, key)) { + value = optType[key]; + } + else { + errors.push(ts.createCompilerDiagnostic(opt.error)); + value = 0; + } + } + if (opt.isFilePath) { + value = ts.normalizePath(ts.combinePaths(basePath, value)); + } + options[opt.name] = value; + } + else { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType)); + } + } + else { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unknown_compiler_option_0, id)); + } + } + } + return options; + } + function getFiles() { + var files = []; + if (ts.hasProperty(json, "files")) { + if (json["files"] instanceof Array) { + var files = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); + } + } + else { + var sysFiles = ts.sys.readDirectory(basePath, ".ts"); + for (var i = 0; i < sysFiles.length; i++) { + var name = sysFiles[i]; + if (!ts.fileExtensionIs(name, ".d.ts") || !ts.contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { + files.push(name); + } + } + } + return files; + } + } + ts.parseConfigFile = parseConfigFile; })(ts || (ts = {})); var ts; (function (ts) { - var version = "1.4.0.0"; + var version = "1.5.0.0"; function validateLocaleAndSetLanguage(locale, errors) { var matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase()); if (!matchResult) { @@ -19568,13 +19906,39 @@ var ts; function reportTimeStatistic(name, time) { reportStatisticalValue(name, (time / 1000).toFixed(2) + "s"); } + function isJSONSupported() { + return typeof JSON === "object" && typeof JSON.parse === "function"; + } + function findConfigFile() { + var searchPath = ts.normalizePath(ts.sys.getCurrentDirectory()); + var filename = "tsconfig.json"; + while (true) { + if (ts.sys.fileExists(filename)) { + return filename; + } + var parentPath = ts.getDirectoryPath(searchPath); + if (parentPath === searchPath) { + break; + } + searchPath = parentPath; + filename = "../" + filename; + } + return undefined; + } function executeCommandLine(args) { var commandLine = ts.parseCommandLine(args); - var compilerOptions = commandLine.options; - if (compilerOptions.locale) { - if (typeof JSON === "undefined") { + var configFilename; + var configFileWatcher; + var cachedProgram; + var rootFilenames; + var compilerOptions; + var compilerHost; + var hostGetSourceFile; + var timerHandle; + if (commandLine.options.locale) { + if (!isJSONSupported()) { reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--locale")); - return ts.sys.exit(1); + return ts.sys.exit(5 /* CompilerOptionsErrors */); } validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors); } @@ -19582,92 +19946,126 @@ var ts; reportDiagnostics(commandLine.errors); return ts.sys.exit(5 /* CompilerOptionsErrors */); } - if (compilerOptions.version) { + if (commandLine.options.version) { reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Version_0, version)); return ts.sys.exit(0 /* Succeeded */); } - if (compilerOptions.help) { + if (commandLine.options.help) { printVersion(); printHelp(); return ts.sys.exit(0 /* Succeeded */); } - if (commandLine.filenames.length === 0) { + if (commandLine.options.project) { + if (!isJSONSupported()) { + reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--project")); + return ts.sys.exit(5 /* CompilerOptionsErrors */); + } + configFilename = ts.normalizePath(ts.combinePaths(commandLine.options.project, "tsconfig.json")); + if (commandLine.filenames.length !== 0) { + reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line)); + return ts.sys.exit(5 /* CompilerOptionsErrors */); + } + } + else if (commandLine.filenames.length === 0 && isJSONSupported()) { + configFilename = findConfigFile(); + } + if (commandLine.filenames.length === 0 && !configFilename) { printVersion(); printHelp(); return ts.sys.exit(5 /* CompilerOptionsErrors */); } - var defaultCompilerHost = ts.createCompilerHost(compilerOptions); - if (compilerOptions.watch) { + if (commandLine.options.watch) { if (!ts.sys.watchFile) { reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.The_current_host_does_not_support_the_0_option, "--watch")); return ts.sys.exit(5 /* CompilerOptionsErrors */); } - watchProgram(commandLine, defaultCompilerHost); + if (configFilename) { + configFileWatcher = ts.sys.watchFile(configFilename, configFileChanged); + } } - else { - var result = compile(commandLine, defaultCompilerHost).exitStatus; - return ts.sys.exit(result); + performCompilation(); + function performCompilation() { + if (!cachedProgram) { + if (configFilename) { + var configObject = ts.readConfigFile(configFilename); + if (!configObject) { + reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Unable_to_open_file_0, configFilename)); + return ts.sys.exit(5 /* CompilerOptionsErrors */); + } + var configParseResult = ts.parseConfigFile(configObject, ts.getDirectoryPath(configFilename)); + if (configParseResult.errors.length > 0) { + reportDiagnostics(configParseResult.errors); + return ts.sys.exit(5 /* CompilerOptionsErrors */); + } + rootFilenames = configParseResult.filenames; + compilerOptions = ts.extend(commandLine.options, configParseResult.options); + } + else { + rootFilenames = commandLine.filenames; + compilerOptions = commandLine.options; + } + compilerHost = ts.createCompilerHost(compilerOptions); + hostGetSourceFile = compilerHost.getSourceFile; + compilerHost.getSourceFile = getSourceFile; + } + var compileResult = compile(rootFilenames, compilerOptions, compilerHost); + if (!commandLine.options.watch) { + return ts.sys.exit(compileResult.exitStatus); + } + setCachedProgram(compileResult.program); + reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Compilation_complete_Watching_for_file_changes)); + } + function getSourceFile(filename, languageVersion, onError) { + if (cachedProgram) { + var sourceFile = cachedProgram.getSourceFile(filename); + if (sourceFile && sourceFile.fileWatcher) { + return sourceFile; + } + } + var sourceFile = hostGetSourceFile(filename, languageVersion, onError); + if (sourceFile && commandLine.options.watch) { + sourceFile.fileWatcher = ts.sys.watchFile(sourceFile.filename, function () { return sourceFileChanged(sourceFile); }); + } + return sourceFile; + } + function setCachedProgram(program) { + if (cachedProgram) { + var newSourceFiles = program ? program.getSourceFiles() : undefined; + ts.forEach(cachedProgram.getSourceFiles(), function (sourceFile) { + if (!(newSourceFiles && ts.contains(newSourceFiles, sourceFile))) { + if (sourceFile.fileWatcher) { + sourceFile.fileWatcher.close(); + sourceFile.fileWatcher = undefined; + } + } + }); + } + cachedProgram = program; + } + function sourceFileChanged(sourceFile) { + sourceFile.fileWatcher = undefined; + startTimer(); + } + function configFileChanged() { + setCachedProgram(undefined); + startTimer(); + } + function startTimer() { + if (timerHandle) { + clearTimeout(timerHandle); + } + timerHandle = setTimeout(recompile, 250); + } + function recompile() { + timerHandle = undefined; + reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.File_change_detected_Starting_incremental_compilation)); + performCompilation(); } } ts.executeCommandLine = executeCommandLine; - function watchProgram(commandLine, compilerHost) { - var watchers = {}; - var updatedFiles = {}; - var program = compile(commandLine, compilerHost).program; - reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Compilation_complete_Watching_for_file_changes)); - addWatchers(program); - return; - function addWatchers(program) { - ts.forEach(program.getSourceFiles(), function (f) { - var filename = getCanonicalName(f.filename); - watchers[filename] = ts.sys.watchFile(filename, fileUpdated); - }); - } - function removeWatchers(program) { - ts.forEach(program.getSourceFiles(), function (f) { - var filename = getCanonicalName(f.filename); - if (ts.hasProperty(watchers, filename)) { - watchers[filename].close(); - } - }); - watchers = {}; - } - function fileUpdated(filename) { - var firstNotification = ts.isEmpty(updatedFiles); - updatedFiles[getCanonicalName(filename)] = true; - if (firstNotification) { - setTimeout(function () { - var changedFiles = updatedFiles; - updatedFiles = {}; - recompile(changedFiles); - }, 250); - } - } - function recompile(changedFiles) { - reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.File_change_detected_Compiling)); - removeWatchers(program); - var oldSourceFiles = ts.arrayToMap(ts.filter(program.getSourceFiles(), function (file) { return !ts.hasProperty(changedFiles, getCanonicalName(file.filename)); }), function (file) { return getCanonicalName(file.filename); }); - var newCompilerHost = ts.clone(compilerHost); - newCompilerHost.getSourceFile = function (fileName, languageVersion, onError) { - fileName = getCanonicalName(fileName); - var sourceFile = ts.lookUp(oldSourceFiles, fileName); - if (sourceFile) { - return sourceFile; - } - return compilerHost.getSourceFile(fileName, languageVersion, onError); - }; - program = compile(commandLine, newCompilerHost).program; - reportDiagnostic(ts.createCompilerDiagnostic(ts.Diagnostics.Compilation_complete_Watching_for_file_changes)); - addWatchers(program); - } - function getCanonicalName(fileName) { - return compilerHost.getCanonicalFileName(fileName); - } - } - function compile(commandLine, compilerHost) { + function compile(filenames, compilerOptions, compilerHost) { var parseStart = new Date().getTime(); - var compilerOptions = commandLine.options; - var program = ts.createProgram(commandLine.filenames, compilerOptions, compilerHost); + var program = ts.createProgram(filenames, compilerOptions, compilerHost); var bindStart = new Date().getTime(); var errors = program.getDiagnostics(); var exitStatus; @@ -19697,7 +20095,12 @@ var ts; } } reportDiagnostics(errors); - if (commandLine.options.diagnostics) { + if (compilerOptions.listFiles) { + ts.forEach(program.getSourceFiles(), function (file) { + ts.sys.write(file.filename + ts.sys.newLine); + }); + } + if (compilerOptions.diagnostics) { var memoryUsed = ts.sys.getMemoryUsage ? ts.sys.getMemoryUsage() : -1; reportCountStatistic("Files", program.getSourceFiles().length); reportCountStatistic("Lines", countLines(program)); diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 592b73ba8d..11f29d7624 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -283,6 +283,11 @@ declare module "typescript" { ThisNodeOrAnySubNodesHasError = 32, HasAggregatedChildData = 64, } + const enum RelationComparisonResult { + Succeeded = 1, + Failed = 2, + FailedAndReported = 3, + } interface Node extends TextRange { kind: SyntaxKind; flags: NodeFlags; @@ -994,11 +999,15 @@ declare module "typescript" { Union = 16384, Anonymous = 32768, FromSignature = 65536, - Unwidened = 131072, + ObjectLiteral = 131072, + ContainsUndefinedOrNull = 262144, + ContainsObjectLiteral = 524288, Intrinsic = 127, + Primitive = 510, StringLike = 258, NumberLike = 132, ObjectType = 48128, + RequiresWidening = 786432, } interface Type { flags: TypeFlags; @@ -1123,6 +1132,7 @@ declare module "typescript" { diagnostics?: boolean; emitBOM?: boolean; help?: boolean; + listFiles?: boolean; locale?: string; mapRoot?: string; module?: ModuleKind; @@ -1136,6 +1146,7 @@ declare module "typescript" { out?: string; outDir?: string; preserveConstEnums?: boolean; + project?: string; removeComments?: boolean; sourceMap?: boolean; sourceRoot?: string; @@ -1168,6 +1179,7 @@ declare module "typescript" { interface CommandLineOption { name: string; type: string | Map; + isFilePath?: boolean; shortName?: string; description?: DiagnosticMessage; paramType?: DiagnosticMessage; @@ -1428,6 +1440,7 @@ declare module "typescript" { isOpen: boolean; version: string; scriptSnapshot: IScriptSnapshot; + nameTable: Map; getNamedDeclarations(): Declaration[]; } /** @@ -1470,6 +1483,7 @@ declare module "typescript" { } interface LanguageServiceHost extends Logger { getCompilationSettings(): CompilerOptions; + getNewLine?(): string; getScriptFileNames(): string[]; getScriptVersion(fileName: string): string; getScriptIsOpen(fileName: string): boolean; diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index 6fd1cda359..d4fa86da1b 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -283,6 +283,11 @@ declare module ts { ThisNodeOrAnySubNodesHasError = 32, HasAggregatedChildData = 64, } + const enum RelationComparisonResult { + Succeeded = 1, + Failed = 2, + FailedAndReported = 3, + } interface Node extends TextRange { kind: SyntaxKind; flags: NodeFlags; @@ -994,11 +999,15 @@ declare module ts { Union = 16384, Anonymous = 32768, FromSignature = 65536, - Unwidened = 131072, + ObjectLiteral = 131072, + ContainsUndefinedOrNull = 262144, + ContainsObjectLiteral = 524288, Intrinsic = 127, + Primitive = 510, StringLike = 258, NumberLike = 132, ObjectType = 48128, + RequiresWidening = 786432, } interface Type { flags: TypeFlags; @@ -1123,6 +1132,7 @@ declare module ts { diagnostics?: boolean; emitBOM?: boolean; help?: boolean; + listFiles?: boolean; locale?: string; mapRoot?: string; module?: ModuleKind; @@ -1136,6 +1146,7 @@ declare module ts { out?: string; outDir?: string; preserveConstEnums?: boolean; + project?: string; removeComments?: boolean; sourceMap?: boolean; sourceRoot?: string; @@ -1168,6 +1179,7 @@ declare module ts { interface CommandLineOption { name: string; type: string | Map; + isFilePath?: boolean; shortName?: string; description?: DiagnosticMessage; paramType?: DiagnosticMessage; @@ -1428,6 +1440,7 @@ declare module ts { isOpen: boolean; version: string; scriptSnapshot: IScriptSnapshot; + nameTable: Map; getNamedDeclarations(): Declaration[]; } /** @@ -1470,6 +1483,7 @@ declare module ts { } interface LanguageServiceHost extends Logger { getCompilationSettings(): CompilerOptions; + getNewLine?(): string; getScriptFileNames(): string[]; getScriptVersion(fileName: string): string; getScriptIsOpen(fileName: string): boolean; diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index c3725bdc36..0ea95acc9f 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -280,6 +280,12 @@ var ts; ParserContextFlags[ParserContextFlags["HasAggregatedChildData"] = 64] = "HasAggregatedChildData"; })(ts.ParserContextFlags || (ts.ParserContextFlags = {})); var ParserContextFlags = ts.ParserContextFlags; + (function (RelationComparisonResult) { + RelationComparisonResult[RelationComparisonResult["Succeeded"] = 1] = "Succeeded"; + RelationComparisonResult[RelationComparisonResult["Failed"] = 2] = "Failed"; + RelationComparisonResult[RelationComparisonResult["FailedAndReported"] = 3] = "FailedAndReported"; + })(ts.RelationComparisonResult || (ts.RelationComparisonResult = {})); + var RelationComparisonResult = ts.RelationComparisonResult; (function (EmitReturnStatus) { EmitReturnStatus[EmitReturnStatus["Succeeded"] = 0] = "Succeeded"; EmitReturnStatus[EmitReturnStatus["AllOutputGenerationSkipped"] = 1] = "AllOutputGenerationSkipped"; @@ -407,11 +413,15 @@ var ts; TypeFlags[TypeFlags["Union"] = 16384] = "Union"; TypeFlags[TypeFlags["Anonymous"] = 32768] = "Anonymous"; TypeFlags[TypeFlags["FromSignature"] = 65536] = "FromSignature"; - TypeFlags[TypeFlags["Unwidened"] = 131072] = "Unwidened"; + TypeFlags[TypeFlags["ObjectLiteral"] = 131072] = "ObjectLiteral"; + TypeFlags[TypeFlags["ContainsUndefinedOrNull"] = 262144] = "ContainsUndefinedOrNull"; + TypeFlags[TypeFlags["ContainsObjectLiteral"] = 524288] = "ContainsObjectLiteral"; TypeFlags[TypeFlags["Intrinsic"] = 127] = "Intrinsic"; + TypeFlags[TypeFlags["Primitive"] = 510] = "Primitive"; TypeFlags[TypeFlags["StringLike"] = 258] = "StringLike"; TypeFlags[TypeFlags["NumberLike"] = 132] = "NumberLike"; TypeFlags[TypeFlags["ObjectType"] = 48128] = "ObjectType"; + TypeFlags[TypeFlags["RequiresWidening"] = 786432] = "RequiresWidening"; })(ts.TypeFlags || (ts.TypeFlags = {})); var TypeFlags = ts.TypeFlags; (function (SignatureKind) { @@ -733,6 +743,19 @@ var ts; return result; } ts.clone = clone; + function extend(first, second) { + var result = {}; + for (var id in first) { + result[id] = first[id]; + } + for (var id in second) { + if (!hasProperty(result, id)) { + result[id] = second[id]; + } + } + return result; + } + ts.extend = extend; function forEachValue(map, callback) { var result; for (var id in map) { @@ -1054,7 +1077,7 @@ var ts; return path2; if (!(path2 && path2.length)) return path1; - if (path2.charAt(0) === ts.directorySeparator) + if (getRootLength(path2) !== 0) return path2; if (path1.charAt(path1.length - 1) === ts.directorySeparator) return path1 + path2; @@ -1224,6 +1247,32 @@ var ts; fileStream.Close(); } } + function getNames(collection) { + var result = []; + for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { + result.push(e.item().Name); + } + return result.sort(); + } + function readDirectory(path, extension) { + var result = []; + visitDirectory(path); + return result; + function visitDirectory(path) { + var folder = fso.GetFolder(path || "."); + var files = getNames(folder.files); + for (var i = 0; i < files.length; i++) { + var name = files[i]; + if (!extension || ts.fileExtensionIs(name, extension)) { + result.push(ts.combinePaths(path, name)); + } + } + var subfolders = getNames(folder.subfolders); + for (var i = 0; i < subfolders.length; i++) { + visitDirectory(ts.combinePaths(path, subfolders[i])); + } + } + } return { args: args, newLine: "\r\n", @@ -1253,6 +1302,7 @@ var ts; getCurrentDirectory: function () { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + readDirectory: readDirectory, exit: function (exitCode) { try { WScript.Quit(exitCode); @@ -1297,6 +1347,30 @@ var ts; } _fs.writeFileSync(fileName, data, "utf8"); } + function readDirectory(path, extension) { + var result = []; + visitDirectory(path); + return result; + function visitDirectory(path) { + var files = _fs.readdirSync(path || ".").sort(); + var directories = []; + for (var i = 0; i < files.length; i++) { + var name = ts.combinePaths(path, files[i]); + var stat = _fs.lstatSync(name); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name, extension)) { + result.push(name); + } + } + else if (stat.isDirectory()) { + directories.push(name); + } + } + for (var i = 0; i < directories.length; i++) { + visitDirectory(directories[i]); + } + } + } return { args: process.argv.slice(2), newLine: _os.EOL, @@ -1341,6 +1415,7 @@ var ts; getCurrentDirectory: function () { return process.cwd(); }, + readDirectory: readDirectory, getMemoryUsage: function () { if (global.gc) { global.gc(); @@ -1510,6 +1585,7 @@ var ts; Modifiers_cannot_appear_here: { code: 1184, category: 1 /* Error */, key: "Modifiers cannot appear here." }, Merge_conflict_marker_encountered: { code: 1185, category: 1 /* Error */, key: "Merge conflict marker encountered." }, A_rest_element_cannot_have_an_initializer: { code: 1186, category: 1 /* Error */, key: "A rest element cannot have an initializer." }, + A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: 1 /* Error */, key: "A parameter property may not be a binding pattern." }, Duplicate_identifier_0: { code: 2300, category: 1 /* Error */, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: 1 /* Error */, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: 1 /* Error */, key: "Static members cannot reference class type parameters." }, @@ -1661,6 +1737,11 @@ var ts; Type_0_has_no_property_1: { code: 2460, category: 1 /* Error */, key: "Type '{0}' has no property '{1}'." }, Type_0_is_not_an_array_type: { code: 2461, category: 1 /* Error */, key: "Type '{0}' is not an array type." }, A_rest_element_must_be_last_in_an_array_destructuring_pattern: { code: 2462, category: 1 /* Error */, key: "A rest element must be last in an array destructuring pattern" }, + A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature: { code: 2463, category: 1 /* Error */, key: "A binding pattern parameter cannot be optional in an implementation signature." }, + A_computed_property_name_must_be_of_type_string_number_or_any: { code: 2464, category: 1 /* Error */, key: "A computed property name must be of type 'string', 'number', or 'any'." }, + this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: 1 /* Error */, key: "'this' cannot be referenced in a computed property name." }, + super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: 1 /* Error */, key: "'super' cannot be referenced in a computed property name." }, + A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2466, category: 1 /* Error */, key: "A computed property name cannot reference a type parameter from its containing type." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1 /* Error */, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: 1 /* Error */, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1733,19 +1814,22 @@ var ts; Enum_declarations_must_all_be_const_or_non_const: { code: 4082, category: 1 /* Error */, key: "Enum declarations must all be const or non-const." }, In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 4083, category: 1 /* Error */, key: "In 'const' enum declarations member initializer must be constant expression.", isEarly: true }, const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 4084, category: 1 /* Error */, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." }, - Index_expression_arguments_in_const_enums_must_be_of_type_string: { code: 4085, category: 1 /* Error */, key: "Index expression arguments in 'const' enums must be of type 'string'." }, + A_const_enum_member_can_only_be_accessed_using_a_string_literal: { code: 4085, category: 1 /* Error */, key: "A const enum member can only be accessed using a string literal.", isEarly: true }, const_enum_member_initializer_was_evaluated_to_a_non_finite_value: { code: 4086, category: 1 /* Error */, key: "'const' enum member initializer was evaluated to a non-finite value." }, const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN: { code: 4087, category: 1 /* Error */, key: "'const' enum member initializer was evaluated to disallowed value 'NaN'." }, + Property_0_does_not_exist_on_const_enum_1: { code: 4088, category: 1 /* Error */, key: "Property '{0}' does not exist on 'const' enum '{1}'.", isEarly: true }, The_current_host_does_not_support_the_0_option: { code: 5001, category: 1 /* Error */, key: "The current host does not support the '{0}' option." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: 1 /* Error */, key: "Cannot find the common subdirectory path for the input files." }, Cannot_read_file_0_Colon_1: { code: 5012, category: 1 /* Error */, key: "Cannot read file '{0}': {1}" }, Unsupported_file_encoding: { code: 5013, category: 1 /* Error */, key: "Unsupported file encoding." }, Unknown_compiler_option_0: { code: 5023, category: 1 /* Error */, key: "Unknown compiler option '{0}'." }, + Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: 1 /* Error */, key: "Compiler option '{0}' requires a value of type {1}." }, Could_not_write_file_0_Colon_1: { code: 5033, category: 1 /* Error */, key: "Could not write file '{0}': {1}" }, - Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: 1 /* Error */, key: "Option mapRoot cannot be specified without specifying sourcemap option." }, - Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: 1 /* Error */, key: "Option sourceRoot cannot be specified without specifying sourcemap option." }, - Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: 1 /* Error */, key: "Option noEmit cannot be specified with option out or outDir." }, - Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: 1 /* Error */, key: "Option noEmit cannot be specified with option declaration." }, + Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: 1 /* Error */, key: "Option 'mapRoot' cannot be specified without specifying 'sourcemap' option." }, + Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: 1 /* Error */, key: "Option 'sourceRoot' cannot be specified without specifying 'sourcemap' option." }, + Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: 1 /* Error */, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, + Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: 1 /* Error */, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, + Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: 1 /* Error */, key: "Option 'project' cannot be mixed with source files on a command line." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: 2 /* Message */, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: 2 /* Message */, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: 2 /* Message */, key: "Specifies the location where debugger should locate map files instead of generated locations." }, @@ -1760,6 +1844,7 @@ var ts; Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: 2 /* Message */, key: "Specify module code generation: 'commonjs' or 'amd'" }, Print_this_message: { code: 6017, category: 2 /* Message */, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: 2 /* Message */, key: "Print the compiler's version." }, + Compile_the_project_in_the_given_directory: { code: 6020, category: 2 /* Message */, key: "Compile the project in the given directory." }, Syntax_Colon_0: { code: 6023, category: 2 /* Message */, key: "Syntax: {0}" }, options: { code: 6024, category: 2 /* Message */, key: "options" }, file: { code: 6025, category: 2 /* Message */, key: "file" }, @@ -1767,7 +1852,7 @@ var ts; Options_Colon: { code: 6027, category: 2 /* Message */, key: "Options:" }, Version_0: { code: 6029, category: 2 /* Message */, key: "Version {0}" }, Insert_command_line_options_and_files_from_a_file: { code: 6030, category: 2 /* Message */, key: "Insert command line options and files from a file." }, - File_change_detected_Compiling: { code: 6032, category: 2 /* Message */, key: "File change detected. Compiling..." }, + File_change_detected_Starting_incremental_compilation: { code: 6032, category: 2 /* Message */, key: "File change detected. Starting incremental compilation..." }, KIND: { code: 6034, category: 2 /* Message */, key: "KIND" }, FILE: { code: 6035, category: 2 /* Message */, key: "FILE" }, VERSION: { code: 6036, category: 2 /* Message */, key: "VERSION" }, @@ -1783,7 +1868,7 @@ var ts; Unsupported_locale_0: { code: 6049, category: 1 /* Error */, key: "Unsupported locale '{0}'." }, Unable_to_open_file_0: { code: 6050, category: 1 /* Error */, key: "Unable to open file '{0}'." }, Corrupted_locale_file_0: { code: 6051, category: 1 /* Error */, key: "Corrupted locale file {0}." }, - Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: 2 /* Message */, key: "Warn on expressions and declarations with an implied 'any' type." }, + Raise_error_on_expressions_and_declarations_with_an_implied_any_type: { code: 6052, category: 2 /* Message */, key: "Raise error on expressions and declarations with an implied 'any' type." }, File_0_not_found: { code: 6053, category: 1 /* Error */, key: "File '{0}' not found." }, File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: 1 /* Error */, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: 2 /* Message */, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, @@ -1805,8 +1890,7 @@ var ts; Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: 1 /* Error */, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, You_cannot_rename_this_element: { code: 8000, category: 1 /* Error */, key: "You cannot rename this element." }, yield_expressions_are_not_currently_supported: { code: 9000, category: 1 /* Error */, key: "'yield' expressions are not currently supported.", isEarly: true }, - Generators_are_not_currently_supported: { code: 9001, category: 1 /* Error */, key: "Generators are not currently supported.", isEarly: true }, - Computed_property_names_are_not_currently_supported: { code: 9002, category: 1 /* Error */, key: "Computed property names are not currently supported.", isEarly: true } + Generators_are_not_currently_supported: { code: 9001, category: 1 /* Error */, key: "Generators are not currently supported.", isEarly: true } }; })(ts || (ts = {})); var ts; @@ -1946,10 +2030,10 @@ var ts; return false; } function isUnicodeIdentifierStart(code, languageVersion) { - return languageVersion === 0 /* ES3 */ ? lookupInUnicodeMap(code, unicodeES3IdentifierStart) : lookupInUnicodeMap(code, unicodeES5IdentifierStart); + return languageVersion >= 1 /* ES5 */ ? lookupInUnicodeMap(code, unicodeES5IdentifierStart) : lookupInUnicodeMap(code, unicodeES3IdentifierStart); } function isUnicodeIdentifierPart(code, languageVersion) { - return languageVersion === 0 /* ES3 */ ? lookupInUnicodeMap(code, unicodeES3IdentifierPart) : lookupInUnicodeMap(code, unicodeES5IdentifierPart); + return languageVersion >= 1 /* ES5 */ ? lookupInUnicodeMap(code, unicodeES5IdentifierPart) : lookupInUnicodeMap(code, unicodeES3IdentifierPart); } function makeReverseMap(source) { var result = []; @@ -1993,7 +2077,7 @@ var ts; } ts.computeLineStarts = computeLineStarts; function getPositionFromLineAndCharacter(lineStarts, line, character) { - ts.Debug.assert(line > 0); + ts.Debug.assert(line > 0 && line <= lineStarts.length); return lineStarts[line - 1] + character - 1; } ts.getPositionFromLineAndCharacter = getPositionFromLineAndCharacter; @@ -2657,7 +2741,7 @@ var ts; value = 0; } tokenValue = "" + value; - return 7 /* NumericLiteral */; + return token = 7 /* NumericLiteral */; } else if (pos + 2 < len && (text.charCodeAt(pos + 1) === 79 /* O */ || text.charCodeAt(pos + 1) === 111 /* o */)) { pos += 2; @@ -2667,7 +2751,7 @@ var ts; value = 0; } tokenValue = "" + value; - return 7 /* NumericLiteral */; + return token = 7 /* NumericLiteral */; } if (pos + 1 < len && isOctalDigit(text.charCodeAt(pos + 1))) { tokenValue = "" + scanOctalDigits(); @@ -3225,6 +3309,12 @@ var ts; return undefined; } switch (node.kind) { + case 122 /* ComputedPropertyName */: + if (node.parent.parent.kind === 191 /* ClassDeclaration */) { + return node; + } + node = node.parent; + break; case 157 /* ArrowFunction */: if (!includeArrowFunctions) { continue; @@ -3246,13 +3336,24 @@ var ts; } } ts.getThisContainer = getThisContainer; - function getSuperContainer(node) { + function getSuperContainer(node, includeFunctions) { while (true) { node = node.parent; - if (!node) { - return undefined; - } + if (!node) + return node; switch (node.kind) { + case 122 /* ComputedPropertyName */: + if (node.parent.parent.kind === 191 /* ClassDeclaration */) { + return node; + } + node = node.parent; + break; + case 190 /* FunctionDeclaration */: + case 156 /* FunctionExpression */: + case 157 /* ArrowFunction */: + if (!includeFunctions) { + continue; + } case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: case 128 /* MethodDeclaration */: @@ -3345,6 +3446,8 @@ var ts; return node === parent.expression; case 169 /* TemplateSpan */: return node === parent.expression; + case 122 /* ComputedPropertyName */: + return node === parent.expression; default: if (isExpression(parent)) { return true; @@ -4563,7 +4666,7 @@ var ts; return canFollowModifier(); } function canFollowModifier() { - return token === 18 /* OpenBracketToken */ || token === 35 /* AsteriskToken */ || isLiteralPropertyName(); + return token === 18 /* OpenBracketToken */ || token === 14 /* OpenBraceToken */ || token === 35 /* AsteriskToken */ || isLiteralPropertyName(); } function isListElement(parsingContext, inErrorRecovery) { var node = currentNode(parsingContext); @@ -6892,7 +6995,7 @@ var ts; })(ts.ModuleInstanceState || (ts.ModuleInstanceState = {})); var ModuleInstanceState = ts.ModuleInstanceState; function getModuleInstanceState(node) { - if (node.kind === 192 /* InterfaceDeclaration */) { + if (node.kind === 192 /* InterfaceDeclaration */ || node.kind === 193 /* TypeAliasDeclaration */) { return 0 /* NonInstantiated */; } else if (ts.isConstEnumDeclaration(node)) { @@ -6925,10 +7028,10 @@ var ts; } } ts.getModuleInstanceState = getModuleInstanceState; - function hasComputedNameButNotSymbol(declaration) { + function hasDynamicName(declaration) { return declaration.name && declaration.name.kind === 122 /* ComputedPropertyName */; } - ts.hasComputedNameButNotSymbol = hasComputedNameButNotSymbol; + ts.hasDynamicName = hasDynamicName; function bindSourceFile(file) { var parent; var container; @@ -6964,7 +7067,7 @@ var ts; if (node.kind === 195 /* ModuleDeclaration */ && node.name.kind === 8 /* StringLiteral */) { return '"' + node.name.text + '"'; } - ts.Debug.assert(!hasComputedNameButNotSymbol(node)); + ts.Debug.assert(!hasDynamicName(node)); return node.name.text; } switch (node.kind) { @@ -6984,9 +7087,7 @@ var ts; return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node); } function declareSymbol(symbols, parent, node, includes, excludes) { - if (hasComputedNameButNotSymbol(node)) { - return undefined; - } + ts.Debug.assert(!hasDynamicName(node)); var name = getDeclarationName(node); if (name !== undefined) { var symbol = ts.hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); @@ -7205,14 +7306,14 @@ var ts; break; case 126 /* PropertyDeclaration */: case 125 /* PropertySignature */: - bindDeclaration(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0), 107455 /* PropertyExcludes */, false); + bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0), 107455 /* PropertyExcludes */, false); break; case 204 /* PropertyAssignment */: case 205 /* ShorthandPropertyAssignment */: - bindDeclaration(node, 4 /* Property */, 107455 /* PropertyExcludes */, false); + bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */, false); break; case 206 /* EnumMember */: - bindDeclaration(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */, false); + bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */, false); break; case 132 /* CallSignature */: case 133 /* ConstructSignature */: @@ -7221,7 +7322,7 @@ var ts; break; case 128 /* MethodDeclaration */: case 127 /* MethodSignature */: - bindDeclaration(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */, true); + bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */, true); break; case 190 /* FunctionDeclaration */: bindDeclaration(node, 16 /* Function */, 106927 /* FunctionExcludes */, true); @@ -7230,10 +7331,10 @@ var ts; bindDeclaration(node, 16384 /* Constructor */, 0, true); break; case 130 /* GetAccessor */: - bindDeclaration(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */, true); + bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */, true); break; case 131 /* SetAccessor */: - bindDeclaration(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */, true); + bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */, true); break; case 136 /* FunctionType */: case 137 /* ConstructorType */: @@ -7306,6 +7407,14 @@ var ts; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); } } + function bindPropertyOrMethodOrAccessor(node, symbolKind, symbolExcludes, isBlockScopeContainer) { + if (hasDynamicName(node)) { + bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer); + } + else { + bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer); + } + } } ts.bindSourceFile = bindSourceFile; })(ts || (ts = {})); @@ -7322,6 +7431,7 @@ var ts; var emptyArray = []; var emptySymbols = {}; var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || 0 /* ES3 */; var emitResolver = createResolver(); var checker = { getNodeCount: function () { return ts.sum(host.getSourceFiles(), "nodeCount"); }, @@ -7367,8 +7477,8 @@ var ts; var numberType = createIntrinsicType(4 /* Number */, "number"); var booleanType = createIntrinsicType(8 /* Boolean */, "boolean"); var voidType = createIntrinsicType(16 /* Void */, "void"); - var undefinedType = createIntrinsicType(32 /* Undefined */ | 131072 /* Unwidened */, "undefined"); - var nullType = createIntrinsicType(64 /* Null */ | 131072 /* Unwidened */, "null"); + var undefinedType = createIntrinsicType(32 /* Undefined */ | 262144 /* ContainsUndefinedOrNull */, "undefined"); + var nullType = createIntrinsicType(64 /* Null */ | 262144 /* ContainsUndefinedOrNull */, "null"); var unknownType = createIntrinsicType(1 /* Any */, "unknown"); var resolvingType = createIntrinsicType(1 /* Any */, "__resolving__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -7398,6 +7508,20 @@ var ts; var potentialThisCollisions = []; var diagnostics = []; var diagnosticsModified = false; + var primitiveTypeInfo = { + "string": { + type: stringType, + flags: 258 /* StringLike */ + }, + "number": { + type: numberType, + flags: 132 /* NumberLike */ + }, + "boolean": { + type: booleanType, + flags: 8 /* Boolean */ + } + }; function addDiagnostic(diagnostic) { diagnostics.push(diagnostic); diagnosticsModified = true; @@ -7614,6 +7738,15 @@ var ts; break loop; } break; + case 122 /* ComputedPropertyName */: + var grandparent = location.parent.parent; + if (grandparent.kind === 191 /* ClassDeclaration */ || grandparent.kind === 192 /* InterfaceDeclaration */) { + if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & 793056 /* Type */)) { + error(errorLocation, ts.Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type); + return undefined; + } + } + break; case 128 /* MethodDeclaration */: case 127 /* MethodSignature */: case 129 /* Constructor */: @@ -8648,7 +8781,7 @@ var ts; } if (pattern.kind === 144 /* ObjectBindingPattern */) { var name = declaration.propertyName || declaration.name; - var type = getTypeOfPropertyOfType(parentType, name.text) || isNumericName(name.text) && getIndexTypeOfType(parentType, 1 /* Number */) || getIndexTypeOfType(parentType, 0 /* String */); + var type = getTypeOfPropertyOfType(parentType, name.text) || isNumericLiteralName(name.text) && getIndexTypeOfType(parentType, 1 /* Number */) || getIndexTypeOfType(parentType, 0 /* String */); if (!type) { error(name, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name)); return unknownType; @@ -8685,7 +8818,7 @@ var ts; } if (declaration.kind === 124 /* Parameter */) { var func = declaration.parent; - if (func.kind === 131 /* SetAccessor */ && !ts.hasComputedNameButNotSymbol(func)) { + if (func.kind === 131 /* SetAccessor */ && !ts.hasDynamicName(func)) { var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 130 /* GetAccessor */); if (getter) { return getReturnTypeOfSignature(getSignatureFromDeclaration(getter)); @@ -9466,7 +9599,7 @@ var ts; returnType = getTypeFromTypeNode(declaration.type); } else { - if (declaration.kind === 130 /* GetAccessor */ && !ts.hasComputedNameButNotSymbol(declaration)) { + if (declaration.kind === 130 /* GetAccessor */ && !ts.hasDynamicName(declaration)) { var setter = ts.getDeclarationOfKind(declaration.symbol, 131 /* SetAccessor */); returnType = getAnnotatedAccessorType(setter); } @@ -9628,14 +9761,18 @@ var ts; return result; } } - function getUnwidenedFlagOfTypes(types) { - return ts.forEach(types, function (t) { return t.flags & 131072 /* Unwidened */; }) || 0; + function getWideningFlagsOfTypes(types) { + var result = 0; + for (var i = 0; i < types.length; i++) { + result |= types[i].flags; + } + return result & 786432 /* RequiresWidening */; } function createTypeReference(target, typeArguments) { var id = getTypeListId(typeArguments); var type = target.instantiations[id]; if (!type) { - var flags = 4096 /* Reference */ | getUnwidenedFlagOfTypes(typeArguments); + var flags = 4096 /* Reference */ | getWideningFlagsOfTypes(typeArguments); type = target.instantiations[id] = createObjectType(flags, target.symbol); type.target = target; type.typeArguments = typeArguments; @@ -9852,7 +9989,7 @@ var ts; var id = getTypeListId(sortedTypes); var type = unionTypes[id]; if (!type) { - type = unionTypes[id] = createObjectType(16384 /* Union */ | getUnwidenedFlagOfTypes(sortedTypes)); + type = unionTypes[id] = createObjectType(16384 /* Union */ | getWideningFlagsOfTypes(sortedTypes)); type.types = sortedTypes; } return type; @@ -10079,6 +10216,8 @@ var ts; case 128 /* MethodDeclaration */: case 127 /* MethodSignature */: return isContextSensitiveFunctionLikeDeclaration(node); + case 155 /* ParenthesizedExpression */: + return isContextSensitive(node.expression); } return false; } @@ -10139,6 +10278,10 @@ var ts; error(errorNode, ts.Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target)); } else if (errorInfo) { + if (errorInfo.next === undefined) { + errorInfo = undefined; + isRelatedTo(source, target, errorNode !== undefined, headMessage, true); + } if (containingMessageChain) { errorInfo = ts.concatenateDiagnosticMessageChains(containingMessageChain, errorInfo); } @@ -10148,7 +10291,8 @@ var ts; function reportError(message, arg0, arg1, arg2) { errorInfo = ts.chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); } - function isRelatedTo(source, target, reportErrors, headMessage) { + function isRelatedTo(source, target, reportErrors, headMessage, elaborateErrors) { + if (elaborateErrors === void 0) { elaborateErrors = false; } var result; if (source === target) return -1 /* True */; @@ -10217,7 +10361,7 @@ var ts; } var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo; var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source); - if (sourceOrApparentType.flags & 48128 /* ObjectType */ && target.flags & 48128 /* ObjectType */ && (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors))) { + if (sourceOrApparentType.flags & 48128 /* ObjectType */ && target.flags & 48128 /* ObjectType */ && (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors, elaborateErrors))) { errorInfo = saveErrorInfo; return result; } @@ -10298,14 +10442,17 @@ var ts; return 0 /* False */; } } - function objectTypeRelatedTo(source, target, reportErrors) { + function objectTypeRelatedTo(source, target, reportErrors, elaborateErrors) { + if (elaborateErrors === void 0) { elaborateErrors = false; } if (overflow) { return 0 /* False */; } var id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id; var related = relation[id]; if (related !== undefined) { - return related ? -1 /* True */ : 0 /* False */; + if (!elaborateErrors || (related === 3 /* FailedAndReported */)) { + return related === 1 /* Succeeded */ ? -1 /* True */ : 0 /* False */; + } } if (depth > 0) { for (var i = 0; i < depth; i++) { @@ -10327,7 +10474,7 @@ var ts; sourceStack[depth] = source; targetStack[depth] = target; maybeStack[depth] = {}; - maybeStack[depth][id] = true; + maybeStack[depth][id] = 1 /* Succeeded */; depth++; var saveExpandingFlags = expandingFlags; if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack)) @@ -10356,11 +10503,11 @@ var ts; depth--; if (result) { var maybeCache = maybeStack[depth]; - var destinationCache = result === -1 /* True */ || depth === 0 ? relation : maybeStack[depth - 1]; + var destinationCache = (result === -1 /* True */ || depth === 0) ? relation : maybeStack[depth - 1]; ts.copyMap(maybeCache, destinationCache); } else { - relation[id] = false; + relation[id] = reportErrors ? 3 /* FailedAndReported */ : 2 /* Failed */; } return result; } @@ -10385,12 +10532,13 @@ var ts; } var result = -1 /* True */; var properties = getPropertiesOfObjectType(target); + var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 131072 /* ObjectLiteral */); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { - if (relation === subtypeRelation || !(targetProp.flags & 536870912 /* Optional */)) { + if (!(targetProp.flags & 536870912 /* Optional */) || requireOptionalProperties) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } @@ -10735,9 +10883,6 @@ var ts; } checkTypeSubtypeOf(bestSupertypeDownfallType, bestSupertype, errorLocation, ts.Diagnostics.Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0, errorMessageChainHead); } - function isTypeOfObjectLiteral(type) { - return (type.flags & 32768 /* Anonymous */) && type.symbol && (type.symbol.flags & 4096 /* ObjectLiteral */) ? true : false; - } function isArrayType(type) { return type.flags & 4096 /* Reference */ && type.target === globalArrayType; } @@ -10748,14 +10893,19 @@ var ts; var properties = getPropertiesOfObjectType(type); var members = {}; ts.forEach(properties, function (p) { - var symbol = createSymbol(p.flags | 67108864 /* Transient */, p.name); - symbol.declarations = p.declarations; - symbol.parent = p.parent; - symbol.type = getWidenedType(getTypeOfSymbol(p)); - symbol.target = p; - if (p.valueDeclaration) - symbol.valueDeclaration = p.valueDeclaration; - members[symbol.name] = symbol; + var propType = getTypeOfSymbol(p); + var widenedType = getWidenedType(propType); + if (propType !== widenedType) { + var symbol = createSymbol(p.flags | 67108864 /* Transient */, p.name); + symbol.declarations = p.declarations; + symbol.parent = p.parent; + symbol.type = widenedType; + symbol.target = p; + if (p.valueDeclaration) + symbol.valueDeclaration = p.valueDeclaration; + p = symbol; + } + members[p.name] = p; }); var stringIndexType = getIndexTypeOfType(type, 0 /* String */); var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); @@ -10766,16 +10916,16 @@ var ts; return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); } function getWidenedType(type) { - if (type.flags & 131072 /* Unwidened */) { + if (type.flags & 786432 /* RequiresWidening */) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } + if (type.flags & 131072 /* ObjectLiteral */) { + return getWidenedTypeOfObjectLiteral(type); + } if (type.flags & 16384 /* Union */) { return getUnionType(ts.map(type.types, getWidenedType)); } - if (isTypeOfObjectLiteral(type)) { - return getWidenedTypeOfObjectLiteral(type); - } if (isArrayType(type)) { return createArrayType(getWidenedType(type.typeArguments[0])); } @@ -10795,11 +10945,11 @@ var ts; if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } - if (isTypeOfObjectLiteral(type)) { + if (type.flags & 131072 /* ObjectLiteral */) { var errorReported = false; ts.forEach(getPropertiesOfObjectType(type), function (p) { var t = getTypeOfSymbol(p); - if (t.flags & 131072 /* Unwidened */) { + if (t.flags & 262144 /* ContainsUndefinedOrNull */) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } @@ -10839,7 +10989,7 @@ var ts; error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); } function reportErrorsFromWidening(declaration, type) { - if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 131072 /* Unwidened */) { + if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 262144 /* ContainsUndefinedOrNull */) { if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); } @@ -11063,11 +11213,14 @@ var ts; } ts.Debug.fail("should not get here"); } - function subtractPrimitiveTypes(type, subtractMask) { + function removeTypesFromUnionType(type, typeKind, isOfTypeKind) { if (type.flags & 16384 /* Union */) { var types = type.types; - if (ts.forEach(types, function (t) { return t.flags & subtractMask; })) { - return getUnionType(ts.filter(types, function (t) { return !(t.flags & subtractMask); })); + if (ts.forEach(types, function (t) { return !!(t.flags & typeKind) === isOfTypeKind; })) { + var narrowedType = getUnionType(ts.filter(types, function (t) { return !(t.flags & typeKind) === isOfTypeKind; })); + if (narrowedType !== emptyObjectType) { + return narrowedType; + } } } return type; @@ -11212,7 +11365,7 @@ var ts; case 129 /* Constructor */: break loop; } - if (narrowedType !== type && isTypeSubtypeOf(narrowedType, type)) { + if (narrowedType !== type) { if (isVariableAssignedWithin(symbol, node)) { break; } @@ -11230,16 +11383,24 @@ var ts; if (left.expression.kind !== 64 /* Identifier */ || getResolvedSymbol(left.expression) !== symbol) { return type; } - var t = right.text; - var checkType = t === "string" ? stringType : t === "number" ? numberType : t === "boolean" ? booleanType : emptyObjectType; + var typeInfo = primitiveTypeInfo[right.text]; if (expr.operator === 31 /* ExclamationEqualsEqualsToken */) { assumeTrue = !assumeTrue; } if (assumeTrue) { - return checkType === emptyObjectType ? subtractPrimitiveTypes(type, 2 /* String */ | 4 /* Number */ | 8 /* Boolean */) : checkType; + if (!typeInfo) { + return removeTypesFromUnionType(type, 258 /* StringLike */ | 132 /* NumberLike */ | 8 /* Boolean */, true); + } + if (isTypeSubtypeOf(typeInfo.type, type)) { + return typeInfo.type; + } + return removeTypesFromUnionType(type, typeInfo.flags, false); } else { - return checkType === emptyObjectType ? type : subtractPrimitiveTypes(type, checkType.flags); + if (typeInfo) { + return removeTypesFromUnionType(type, typeInfo.flags, true); + } + return type; } } function narrowTypeByAnd(type, expr, assumeTrue) { @@ -11276,8 +11437,14 @@ var ts; if (!prototypeProperty) { return type; } - var prototypeType = getTypeOfSymbol(prototypeProperty); - return isTypeSubtypeOf(prototypeType, type) ? prototypeType : type; + var targetType = getTypeOfSymbol(prototypeProperty); + if (isTypeSubtypeOf(targetType, type)) { + return targetType; + } + if (type.flags & 16384 /* Union */) { + return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); })); + } + return type; } function narrowType(type, expr, assumeTrue) { switch (expr.kind) { @@ -11375,6 +11542,9 @@ var ts; error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); } break; + case 122 /* ComputedPropertyName */: + error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_computed_property_name); + break; } if (needToCaptureLexicalThis) { captureLexicalThis(node, container); @@ -11386,26 +11556,6 @@ var ts; } return anyType; } - function getSuperContainer(node) { - while (true) { - node = node.parent; - if (!node) - return node; - switch (node.kind) { - case 190 /* FunctionDeclaration */: - case 156 /* FunctionExpression */: - case 157 /* ArrowFunction */: - case 126 /* PropertyDeclaration */: - case 125 /* PropertySignature */: - case 128 /* MethodDeclaration */: - case 127 /* MethodSignature */: - case 129 /* Constructor */: - case 130 /* GetAccessor */: - case 131 /* SetAccessor */: - return node; - } - } - } function isInConstructorArgumentInitializer(node, constructorDecl) { for (var n = node; n && n !== constructorDecl; n = n.parent) { if (n.kind === 124 /* Parameter */) { @@ -11426,7 +11576,7 @@ var ts; error(node, ts.Diagnostics.super_can_only_be_referenced_in_a_derived_class); return unknownType; } - var container = getSuperContainer(node); + var container = ts.getSuperContainer(node, true); if (container) { var canUseSuperExpression = false; if (isCallExpression) { @@ -11435,7 +11585,7 @@ var ts; else { var needToCaptureLexicalThis = false; while (container && container.kind === 157 /* ArrowFunction */) { - container = getSuperContainer(container); + container = ts.getSuperContainer(container, true); needToCaptureLexicalThis = true; } if (container && container.parent && container.parent.kind === 191 /* ClassDeclaration */) { @@ -11467,7 +11617,10 @@ var ts; return returnType; } } - if (isCallExpression) { + if (container.kind === 122 /* ComputedPropertyName */) { + error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); + } + else if (isCallExpression) { error(node, ts.Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors); } else { @@ -11606,9 +11759,15 @@ var ts; function getContextualTypeForObjectLiteralElement(element) { var objectLiteral = element.parent; var type = getContextualType(objectLiteral); - var name = element.name.text; - if (type && name) { - return getTypeOfPropertyOfContextualType(type, name) || isNumericName(name) && getIndexTypeOfContextualType(type, 1 /* Number */) || getIndexTypeOfContextualType(type, 0 /* String */); + if (type) { + if (!ts.hasDynamicName(element)) { + var symbolName = getSymbolOfNode(element).name; + var propertyType = getTypeOfPropertyOfContextualType(type, symbolName); + if (propertyType) { + return propertyType; + } + } + return isNumericName(element.name) && getIndexTypeOfContextualType(type, 1 /* Number */) || getIndexTypeOfContextualType(type, 0 /* String */); } return undefined; } @@ -11659,6 +11818,8 @@ var ts; case 169 /* TemplateSpan */: ts.Debug.assert(parent.parent.kind === 165 /* TemplateExpression */); return getContextualTypeForSubstitutionExpression(parent.parent, node); + case 155 /* ParenthesizedExpression */: + return getContextualType(parent); } return undefined; } @@ -11763,72 +11924,84 @@ var ts; return createArrayType(getUnionType(elementTypes)); } function isNumericName(name) { + return name.kind === 122 /* ComputedPropertyName */ ? isNumericComputedName(name) : isNumericLiteralName(name.text); + } + function isNumericComputedName(name) { + return isTypeOfKind(checkComputedPropertyName(name), 1 /* Any */ | 132 /* NumberLike */); + } + function isNumericLiteralName(name) { return (+name).toString() === name; } + function checkComputedPropertyName(node) { + var links = getNodeLinks(node.expression); + if (!links.resolvedType) { + links.resolvedType = checkExpression(node.expression); + if (!isTypeOfKind(links.resolvedType, 1 /* Any */ | 132 /* NumberLike */ | 258 /* StringLike */)) { + error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_or_any); + } + } + return links.resolvedType; + } function checkObjectLiteral(node, contextualMapper) { checkGrammarObjectLiteralExpression(node); - var members = node.symbol.members; - var properties = {}; + var propertiesTable = {}; + var propertiesArray = []; var contextualType = getContextualType(node); var typeFlags; - for (var id in members) { - if (ts.hasProperty(members, id)) { - var member = members[id]; - if (member.flags & 4 /* Property */ || ts.isObjectLiteralMethod(member.declarations[0])) { - var memberDecl = member.declarations[0]; - if (memberDecl.kind === 204 /* PropertyAssignment */) { - var type = checkExpression(memberDecl.initializer, contextualMapper); - } - else if (memberDecl.kind === 128 /* MethodDeclaration */) { - var type = checkObjectLiteralMethod(memberDecl, contextualMapper); - } - else { - ts.Debug.assert(memberDecl.kind === 205 /* ShorthandPropertyAssignment */); - var type = memberDecl.name.kind === 122 /* ComputedPropertyName */ ? unknownType : checkExpression(memberDecl.name, contextualMapper); - } - typeFlags |= type.flags; - var prop = createSymbol(4 /* Property */ | 67108864 /* Transient */ | member.flags, member.name); - prop.declarations = member.declarations; - prop.parent = member.parent; - if (member.valueDeclaration) { - prop.valueDeclaration = member.valueDeclaration; - } - prop.type = type; - prop.target = member; - member = prop; + for (var i = 0; i < node.properties.length; i++) { + var memberDecl = node.properties[i]; + var member = memberDecl.symbol; + if (memberDecl.kind === 204 /* PropertyAssignment */ || memberDecl.kind === 205 /* ShorthandPropertyAssignment */ || ts.isObjectLiteralMethod(memberDecl)) { + if (memberDecl.kind === 204 /* PropertyAssignment */) { + var type = checkPropertyAssignment(memberDecl, contextualMapper); + } + else if (memberDecl.kind === 128 /* MethodDeclaration */) { + var type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { - var getAccessor = ts.getDeclarationOfKind(member, 130 /* GetAccessor */); - if (getAccessor) { - checkAccessorDeclaration(getAccessor); - } - var setAccessor = ts.getDeclarationOfKind(member, 131 /* SetAccessor */); - if (setAccessor) { - checkAccessorDeclaration(setAccessor); - } + ts.Debug.assert(memberDecl.kind === 205 /* ShorthandPropertyAssignment */); + var type = memberDecl.name.kind === 122 /* ComputedPropertyName */ ? unknownType : checkExpression(memberDecl.name, contextualMapper); } - properties[member.name] = member; + typeFlags |= type.flags; + var prop = createSymbol(4 /* Property */ | 67108864 /* Transient */ | member.flags, member.name); + prop.declarations = member.declarations; + prop.parent = member.parent; + if (member.valueDeclaration) { + prop.valueDeclaration = member.valueDeclaration; + } + prop.type = type; + prop.target = member; + member = prop; } + else { + ts.Debug.assert(memberDecl.kind === 130 /* GetAccessor */ || memberDecl.kind === 131 /* SetAccessor */); + checkAccessorDeclaration(memberDecl); + } + if (!ts.hasDynamicName(memberDecl)) { + propertiesTable[member.name] = member; + } + propertiesArray.push(member); } var stringIndexType = getIndexType(0 /* String */); var numberIndexType = getIndexType(1 /* Number */); - var result = createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= (typeFlags & 131072 /* Unwidened */); + var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); + result.flags |= 131072 /* ObjectLiteral */ | 524288 /* ContainsObjectLiteral */ | (typeFlags & 262144 /* ContainsUndefinedOrNull */); return result; function getIndexType(kind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { var propTypes = []; - for (var id in properties) { - if (ts.hasProperty(properties, id)) { - if (kind === 0 /* String */ || isNumericName(id)) { - var type = getTypeOfSymbol(properties[id]); - if (!ts.contains(propTypes, type)) { - propTypes.push(type); - } + for (var i = 0; i < propertiesArray.length; i++) { + var propertyDecl = node.properties[i]; + if (kind === 0 /* String */ || isNumericName(propertyDecl.name)) { + var type = getTypeOfSymbol(propertiesArray[i]); + if (!ts.contains(propTypes, type)) { + propTypes.push(type); } } } - return propTypes.length ? getUnionType(propTypes) : undefinedType; + var result = propTypes.length ? getUnionType(propTypes) : undefinedType; + typeFlags |= result.flags; + return result; } return undefined; } @@ -11939,8 +12112,10 @@ var ts; if (objectType === unknownType) { return unknownType; } - if (isConstEnumObjectType(objectType) && node.argumentExpression && node.argumentExpression.kind !== 8 /* StringLiteral */) { - error(node.argumentExpression, ts.Diagnostics.Index_expression_arguments_in_const_enums_must_be_of_type_string); + var isConstEnum = isConstEnumObjectType(objectType); + if (isConstEnum && (!node.argumentExpression || node.argumentExpression.kind !== 8 /* StringLiteral */)) { + error(node.argumentExpression, ts.Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal); + return unknownType; } if (node.argumentExpression) { if (node.argumentExpression.kind === 8 /* StringLiteral */ || node.argumentExpression.kind === 7 /* NumericLiteral */) { @@ -11950,10 +12125,14 @@ var ts; getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } + else if (isConstEnum) { + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name, symbolToString(objectType.symbol)); + return unknownType; + } } } - if (indexType.flags & (1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */)) { - if (indexType.flags & (1 /* Any */ | 132 /* NumberLike */)) { + if (isTypeOfKind(indexType, 1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */)) { + if (isTypeOfKind(indexType, 1 /* Any */ | 132 /* NumberLike */)) { var numberIndexType = getIndexTypeOfType(objectType, 1 /* Number */); if (numberIndexType) { return numberIndexType; @@ -12137,10 +12316,25 @@ var ts; } return args; } + function getEffectiveTypeArguments(callExpression) { + if (callExpression.expression.kind === 90 /* SuperKeyword */) { + var containingClass = ts.getAncestor(callExpression, 191 /* ClassDeclaration */); + var baseClassTypeNode = containingClass && ts.getClassBaseTypeNode(containingClass); + return baseClassTypeNode && baseClassTypeNode.typeArguments; + } + else { + return callExpression.typeArguments; + } + } function resolveCall(node, signatures, candidatesOutArray) { var isTaggedTemplate = node.kind === 153 /* TaggedTemplateExpression */; - var typeArguments = isTaggedTemplate ? undefined : node.typeArguments; - ts.forEach(typeArguments, checkSourceElement); + var typeArguments; + if (!isTaggedTemplate) { + typeArguments = getEffectiveTypeArguments(node); + if (node.expression.kind !== 90 /* SuperKeyword */) { + ts.forEach(typeArguments, checkSourceElement); + } + } var candidates = candidatesOutArray || []; collectCandidates(); if (!candidates.length) { @@ -12257,8 +12451,10 @@ var ts; var result = candidates; var lastParent; var lastSymbol; - var cutoffPos = 0; - var pos; + var cutoffIndex = 0; + var index; + var specializedIndex = -1; + var spliceIndex; ts.Debug.assert(!result.length); for (var i = 0; i < signatures.length; i++) { var signature = signatures[i]; @@ -12266,22 +12462,27 @@ var ts; var parent = signature.declaration && signature.declaration.parent; if (!lastSymbol || symbol === lastSymbol) { if (lastParent && parent === lastParent) { - pos++; + index++; } else { lastParent = parent; - pos = cutoffPos; + index = cutoffIndex; } } else { - pos = cutoffPos = result.length; + index = cutoffIndex = result.length; lastParent = parent; } lastSymbol = symbol; - for (var j = result.length; j > pos; j--) { - result[j] = result[j - 1]; + if (signature.hasStringLiterals) { + specializedIndex++; + spliceIndex = specializedIndex; + cutoffIndex++; } - result[pos] = signature; + else { + spliceIndex = index; + } + result.splice(spliceIndex, 0, signature); } } } @@ -12397,7 +12598,7 @@ var ts; return getReturnTypeOfSignature(signature); } function checkTaggedTemplateExpression(node) { - if (compilerOptions.target < 2 /* ES6 */) { + if (languageVersion < 2 /* ES6 */) { grammarErrorOnFirstToken(node.template, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); } return getReturnTypeOfSignature(getResolvedSignature(node)); @@ -12546,7 +12747,7 @@ var ts; } } function checkArithmeticOperandType(operand, type, diagnostic) { - if (!(type.flags & (1 /* Any */ | 132 /* NumberLike */))) { + if (!isTypeOfKind(type, 1 /* Any */ | 132 /* NumberLike */)) { error(operand, diagnostic); return false; } @@ -12650,11 +12851,20 @@ var ts; } return numberType; } - function isStructuredType(type) { - if (type.flags & 16384 /* Union */) { - return !ts.forEach(type.types, function (t) { return !isStructuredType(t); }); + function isTypeOfKind(type, kind) { + if (type.flags & kind) { + return true; } - return (type.flags & (48128 /* ObjectType */ | 512 /* TypeParameter */)) !== 0; + if (type.flags & 16384 /* Union */) { + var types = type.types; + for (var i = 0; i < types.length; i++) { + if (!(types[i].flags & kind)) { + return false; + } + } + return true; + } + return false; } function isConstEnumObjectType(type) { return type.flags & (48128 /* ObjectType */ | 32768 /* Anonymous */) && type.symbol && isConstEnumSymbol(type.symbol); @@ -12663,7 +12873,7 @@ var ts; return (symbol.flags & 128 /* ConstEnum */) !== 0; } function checkInstanceOfExpression(node, leftType, rightType) { - if (!(leftType.flags & 1 /* Any */ || isStructuredType(leftType))) { + if (isTypeOfKind(leftType, 510 /* Primitive */)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } if (!(rightType.flags & 1 /* Any */ || isTypeSubtypeOf(rightType, globalFunctionType))) { @@ -12672,10 +12882,10 @@ var ts; return booleanType; } function checkInExpression(node, leftType, rightType) { - if (leftType !== anyType && leftType !== stringType && leftType !== numberType) { + if (!isTypeOfKind(leftType, 1 /* Any */ | 258 /* StringLike */ | 132 /* NumberLike */)) { error(node.left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number); } - if (!(rightType.flags & 1 /* Any */ || isStructuredType(rightType))) { + if (!isTypeOfKind(rightType, 1 /* Any */ | 48128 /* ObjectType */ | 512 /* TypeParameter */)) { error(node.right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -12686,7 +12896,7 @@ var ts; var p = properties[i]; if (p.kind === 204 /* PropertyAssignment */ || p.kind === 205 /* ShorthandPropertyAssignment */) { var name = p.name; - var type = sourceType.flags & 1 /* Any */ ? sourceType : getTypeOfPropertyOfType(sourceType, name.text) || isNumericName(name.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); + var type = sourceType.flags & 1 /* Any */ ? sourceType : getTypeOfPropertyOfType(sourceType, name.text) || isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); if (type) { checkDestructuringAssignment(p.initializer || name, type); } @@ -12805,13 +13015,13 @@ var ts; if (rightType.flags & (32 /* Undefined */ | 64 /* Null */)) rightType = leftType; var resultType; - if (leftType.flags & 132 /* NumberLike */ && rightType.flags & 132 /* NumberLike */) { + if (isTypeOfKind(leftType, 132 /* NumberLike */) && isTypeOfKind(rightType, 132 /* NumberLike */)) { resultType = numberType; } - else if (leftType.flags & 258 /* StringLike */ || rightType.flags & 258 /* StringLike */) { + else if (isTypeOfKind(leftType, 258 /* StringLike */) || isTypeOfKind(rightType, 258 /* StringLike */)) { resultType = stringType; } - else if (leftType.flags & 1 /* Any */ || leftType === unknownType || rightType.flags & 1 /* Any */ || rightType === unknownType) { + else if (leftType.flags & 1 /* Any */ || rightType.flags & 1 /* Any */) { resultType = anyType; } if (!resultType) { @@ -12909,8 +13119,17 @@ var ts; } return links.resolvedType; } + function checkPropertyAssignment(node, contextualMapper) { + if (ts.hasDynamicName(node)) { + checkComputedPropertyName(node.name); + } + return checkExpression(node.initializer, contextualMapper); + } function checkObjectLiteralMethod(node, contextualMapper) { checkGrammarMethod(node); + if (ts.hasDynamicName(node)) { + checkComputedPropertyName(node.name); + } var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } @@ -13033,12 +13252,15 @@ var ts; checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, node.name); checkVariableLikeDeclaration(node); var func = ts.getContainingFunction(node); - if (node.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */)) { + if (node.flags & 112 /* AccessibilityModifier */) { func = ts.getContainingFunction(node); if (!(func.kind === 129 /* Constructor */ && ts.nodeIsPresent(func.body))) { error(node, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } } + if (node.questionToken && ts.isBindingPattern(node.name) && func.body) { + error(node, ts.Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature); + } if (node.dotDotDotToken) { if (!isArrayType(getTypeOfSymbol(node.symbol))) { error(node, ts.Diagnostics.A_rest_parameter_must_be_of_an_array_type); @@ -13183,7 +13405,7 @@ var ts; error(node.name, ts.Diagnostics.A_get_accessor_must_return_a_value_or_consist_of_a_single_throw_statement); } } - if (!ts.hasComputedNameButNotSymbol(node)) { + if (!ts.hasDynamicName(node)) { var otherKind = node.kind === 130 /* GetAccessor */ ? 131 /* SetAccessor */ : 130 /* GetAccessor */; var otherAccessor = ts.getDeclarationOfKind(node.symbol, otherKind); if (otherAccessor) { @@ -13198,8 +13420,8 @@ var ts; } } } - checkAndStoreTypeOfAccessors(getSymbolOfNode(node)); } + checkAndStoreTypeOfAccessors(getSymbolOfNode(node)); } checkFunctionLikeDeclaration(node); } @@ -13507,7 +13729,10 @@ var ts; } function checkFunctionLikeDeclaration(node) { checkSignatureDeclaration(node); - if (!ts.hasComputedNameButNotSymbol(node)) { + if (ts.hasDynamicName(node)) { + checkComputedPropertyName(node.name); + } + else { var symbol = getSymbolOfNode(node); var localSymbol = node.localSymbol || symbol; var firstDeclaration = ts.getDeclarationOfKind(localSymbol, node.kind); @@ -13661,7 +13886,8 @@ var ts; } function checkVariableLikeDeclaration(node) { checkSourceElement(node.type); - if (ts.hasComputedNameButNotSymbol(node)) { + if (ts.hasDynamicName(node)) { + checkComputedPropertyName(node.name); if (node.initializer) { checkExpressionCached(node.initializer); } @@ -13805,7 +14031,7 @@ var ts; } } var exprType = checkExpression(node.expression); - if (!(exprType.flags & 1 /* Any */ || isStructuredType(exprType))) { + if (!isTypeOfKind(exprType, 1 /* Any */ | 48128 /* ObjectType */ | 512 /* TypeParameter */)) { 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); @@ -13925,29 +14151,6 @@ var ts; checkBlock(node.finallyBlock); } function checkIndexConstraints(type) { - function checkIndexConstraintForProperty(prop, propertyType, indexDeclaration, indexType, indexKind) { - if (!indexType) { - return; - } - if (indexKind === 1 /* Number */ && !isNumericName(prop.name)) { - return; - } - var errorNode; - if (prop.parent === type.symbol) { - errorNode = prop.valueDeclaration; - } - else if (indexDeclaration) { - errorNode = indexDeclaration; - } - else if (type.flags & 2048 /* Interface */) { - var someBaseClassHasBothPropertyAndIndexer = ts.forEach(type.baseTypes, function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); - errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : type.symbol.declarations[0]; - } - if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { - var errorMessage = indexKind === 0 /* String */ ? 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)); - } - } var declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, 1 /* Number */); var declaredStringIndexer = getIndexDeclarationOfSymbol(type.symbol, 0 /* String */); var stringIndexType = getIndexTypeOfType(type, 0 /* String */); @@ -13955,9 +14158,20 @@ var ts; if (stringIndexType || numberIndexType) { ts.forEach(getPropertiesOfObjectType(type), function (prop) { var propType = getTypeOfSymbol(prop); - checkIndexConstraintForProperty(prop, propType, declaredStringIndexer, stringIndexType, 0 /* String */); - checkIndexConstraintForProperty(prop, propType, declaredNumberIndexer, numberIndexType, 1 /* Number */); + checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, 0 /* String */); + checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, 1 /* Number */); }); + if (type.flags & 1024 /* Class */ && type.symbol.valueDeclaration.kind === 191 /* ClassDeclaration */) { + var classDeclaration = type.symbol.valueDeclaration; + for (var i = 0; i < classDeclaration.members.length; i++) { + var member = classDeclaration.members[i]; + if (!(member.flags & 128 /* Static */) && ts.hasDynamicName(member)) { + var propType = getTypeOfSymbol(member.symbol); + checkIndexConstraintForProperty(member.symbol, propType, type, declaredStringIndexer, stringIndexType, 0 /* String */); + checkIndexConstraintForProperty(member.symbol, propType, type, declaredNumberIndexer, numberIndexType, 1 /* Number */); + } + } + } } var errorNode; if (stringIndexType && numberIndexType) { @@ -13970,6 +14184,29 @@ var ts; if (errorNode && !isTypeAssignableTo(numberIndexType, stringIndexType)) { error(errorNode, ts.Diagnostics.Numeric_index_type_0_is_not_assignable_to_string_index_type_1, typeToString(numberIndexType), typeToString(stringIndexType)); } + function checkIndexConstraintForProperty(prop, propertyType, containingType, indexDeclaration, indexType, indexKind) { + if (!indexType) { + return; + } + if (indexKind === 1 /* Number */ && !isNumericName(prop.valueDeclaration.name)) { + return; + } + var errorNode; + if (prop.valueDeclaration.name.kind === 122 /* ComputedPropertyName */ || prop.parent === containingType.symbol) { + errorNode = prop.valueDeclaration; + } + else if (indexDeclaration) { + errorNode = indexDeclaration; + } + else if (containingType.flags & 2048 /* Interface */) { + var someBaseClassHasBothPropertyAndIndexer = ts.forEach(containingType.baseTypes, function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); }); + errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0]; + } + if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { + var errorMessage = indexKind === 0 /* String */ ? 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)); + } + } } function checkTypeNameIsReserved(name, message) { switch (name.text) { @@ -14198,7 +14435,7 @@ var ts; var ambient = ts.isInAmbientContext(node); var enumIsConst = ts.isConst(node); ts.forEach(node.members, function (member) { - if (isNumericName(member.name.text)) { + if (member.name.kind !== 122 /* ComputedPropertyName */ && isNumericLiteralName(member.name.text)) { error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name); } var initializer = member.initializer; @@ -15162,8 +15399,8 @@ var ts; if (symbol && (symbol.flags & 8 /* EnumMember */)) { var declaration = symbol.valueDeclaration; var constantValue; - if (declaration.kind === 206 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) { - return constantValue; + if (declaration.kind === 206 /* EnumMember */) { + return getEnumMemberValue(declaration); } } return undefined; @@ -15222,7 +15459,7 @@ var ts; globalNumberType = getGlobalType("Number"); globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); - globalTemplateStringsArrayType = compilerOptions.target >= 2 /* ES6 */ ? getGlobalType("TemplateStringsArray") : unknownType; + globalTemplateStringsArrayType = languageVersion >= 2 /* ES6 */ ? getGlobalType("TemplateStringsArray") : unknownType; anyArrayType = createArrayType(anyType); } function checkGrammarModifiers(node) { @@ -15346,6 +15583,9 @@ var ts; else if (node.kind === 192 /* InterfaceDeclaration */ && flags & 2 /* Ambient */) { return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); } + else if (node.kind === 124 /* Parameter */ && (flags & 112 /* AccessibilityModifier */) && ts.isBindingPattern(node.name)) { + return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); + } } function checkGrammarForDisallowedTrailingComma(list) { if (list && list.hasTrailingComma) { @@ -15530,16 +15770,14 @@ var ts; } function checkGrammarComputedPropertyName(node) { if (node.kind !== 122 /* ComputedPropertyName */) { - return; + return false; } - grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_not_currently_supported); - return; var computedPropertyName = node; - if (compilerOptions.target < 2 /* ES6 */) { - grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); + if (languageVersion < 2 /* ES6 */) { + return grammarErrorOnNode(node, ts.Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher); } else if (computedPropertyName.expression.kind === 163 /* BinaryExpression */ && computedPropertyName.expression.operator === 23 /* CommaToken */) { - grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); + return grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name); } } function checkGrammarForGenerator(node) { @@ -15615,7 +15853,7 @@ var ts; } function checkGrammarAccessor(accessor) { var kind = accessor.kind; - if (compilerOptions.target < 1 /* ES5 */) { + if (languageVersion < 1 /* ES5 */) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); } else if (ts.isInAmbientContext(accessor)) { @@ -15780,7 +16018,7 @@ 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 (compilerOptions.target < 2 /* ES6 */) { + if (languageVersion < 2 /* ES6 */) { if (ts.isLet(declarationList)) { return grammarErrorOnFirstToken(declarationList, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher); } @@ -15863,7 +16101,7 @@ var ts; function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = ts.createScanner(compilerOptions.target, true, sourceFile.text); + var scanner = ts.createScanner(languageVersion, true, sourceFile.text); var start = scanToken(scanner, node.pos); diagnostics.push(ts.createFileDiagnostic(sourceFile, start, scanner.getTextPos() - start, message, arg0, arg1, arg2)); return true; @@ -15963,7 +16201,7 @@ var ts; if (node.parserContextFlags & 1 /* StrictMode */) { return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode); } - else if (compilerOptions.target >= 1 /* ES5 */) { + else if (languageVersion >= 1 /* ES5 */) { return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); } } @@ -15971,7 +16209,7 @@ var ts; function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { var sourceFile = ts.getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { - var scanner = ts.createScanner(compilerOptions.target, true, sourceFile.text); + var scanner = ts.createScanner(languageVersion, true, sourceFile.text); scanToken(scanner, node.pos); diagnostics.push(ts.createFileDiagnostic(sourceFile, scanner.getTextPos(), 0, message, arg0, arg1, arg2)); return true; @@ -16098,9 +16336,10 @@ var ts; function writeCommentRange(currentSourceFile, writer, comment, newLine) { if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) { var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos); + var lastLine = currentSourceFile.getLineStarts().length; var firstCommentLineIndent; for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, 1); + var nextLineStart = currentLine === lastLine ? (comment.end + 1) : currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, 1); if (pos !== comment.pos) { if (firstCommentLineIndent === undefined) { firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, 1), comment.pos); @@ -16220,6 +16459,7 @@ var ts; function emitDeclarations(host, resolver, diagnostics, jsFilePath, root) { var newLine = host.getNewLine(); var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || 0 /* ES3 */; var write; var writeLine; var increaseIndent; @@ -16712,6 +16952,9 @@ var ts; } } function emitPropertyDeclaration(node) { + if (ts.hasDynamicName(node)) { + return; + } emitJsDocComments(node); emitClassMemberDeclarationFlags(node); emitVariableDeclaration(node); @@ -16780,6 +17023,9 @@ var ts; } } function emitAccessorDeclaration(node) { + if (ts.hasDynamicName(node)) { + return; + } var accessors = getAllAccessorDeclarations(node.parent, node); if (node === accessors.firstAccessor) { emitJsDocComments(accessors.getAccessor); @@ -16837,6 +17083,9 @@ var ts; } } function emitFunctionDeclaration(node) { + if (ts.hasDynamicName(node)) { + return; + } if ((node.kind !== 190 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); if (node.kind === 190 /* FunctionDeclaration */) { @@ -17088,6 +17337,7 @@ var ts; ts.getDeclarationDiagnostics = getDeclarationDiagnostics; function emitFiles(resolver, host, targetSourceFile) { var compilerOptions = host.getCompilerOptions(); + var languageVersion = compilerOptions.target || 0 /* ES3 */; var sourceMapDataList = compilerOptions.sourceMap ? [] : undefined; var diagnostics = []; var newLine = host.getNewLine(); @@ -17244,7 +17494,11 @@ var ts; if (scopeName) { var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { - scopeName = sourceMapData.sourceMapNames[parentIndex] + "." + scopeName; + var name = node.name; + if (!name || name.kind !== 122 /* ComputedPropertyName */) { + scopeName = "." + scopeName; + } + scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; } scopeNameIndex = ts.getProperty(sourceMapNameIndexMap, scopeName); if (scopeNameIndex === undefined) { @@ -17260,7 +17514,8 @@ var ts; } else if (node.kind === 190 /* FunctionDeclaration */ || node.kind === 156 /* FunctionExpression */ || node.kind === 128 /* MethodDeclaration */ || node.kind === 127 /* MethodSignature */ || node.kind === 130 /* GetAccessor */ || node.kind === 131 /* SetAccessor */ || node.kind === 195 /* ModuleDeclaration */ || node.kind === 191 /* ClassDeclaration */ || node.kind === 194 /* EnumDeclaration */) { if (node.name) { - scopeName = node.name.text; + var name = node.name; + scopeName = name.kind === 122 /* ComputedPropertyName */ ? ts.getTextOfNode(name) : node.name.text; } recordScopeNameStart(scopeName); } @@ -17480,11 +17735,11 @@ var ts; return false; } function emitLiteral(node) { - var text = compilerOptions.target < 2 /* ES6 */ && ts.isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; + var text = languageVersion < 2 /* ES6 */ && ts.isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : node.text; if (compilerOptions.sourceMap && (node.kind === 8 /* StringLiteral */ || ts.isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } - else if (compilerOptions.target < 2 /* ES6 */ && node.kind === 7 /* NumericLiteral */ && isBinaryOrOctalIntegerLiteral(text)) { + else if (languageVersion < 2 /* ES6 */ && node.kind === 7 /* NumericLiteral */ && isBinaryOrOctalIntegerLiteral(text)) { write(node.text); } else { @@ -17495,7 +17750,7 @@ var ts; return '"' + ts.escapeString(node.text) + '"'; } function emitTemplateExpression(node) { - if (compilerOptions.target >= 2 /* ES6 */) { + if (languageVersion >= 2 /* ES6 */) { ts.forEachChild(node, emit); return; } @@ -17542,7 +17797,7 @@ var ts; } } function comparePrecedenceToBinaryPlus(expression) { - ts.Debug.assert(compilerOptions.target <= 1 /* ES5 */); + ts.Debug.assert(languageVersion < 2 /* ES6 */); switch (expression.kind) { case 163 /* BinaryExpression */: switch (expression.operator) { @@ -17708,7 +17963,7 @@ var ts; write("[]"); return; } - if (compilerOptions.target >= 2 /* ES6 */) { + if (languageVersion >= 2 /* ES6 */) { write("["); emitList(elements, 0, elements.length, (node.flags & 256 /* MultiLine */) !== 0, elements.hasTrailingComma); write("]"); @@ -17753,7 +18008,7 @@ var ts; if (!multiLine) { write(" "); } - emitList(properties, 0, properties.length, multiLine, properties.hasTrailingComma && compilerOptions.target >= 1 /* ES5 */); + emitList(properties, 0, properties.length, multiLine, properties.hasTrailingComma && languageVersion >= 1 /* ES5 */); if (!multiLine) { write(" "); } @@ -17766,32 +18021,23 @@ var ts; write("]"); } function emitMethod(node) { - if (!ts.isObjectLiteralMethod(node)) { - return; - } - emitLeadingComments(node); emit(node.name); - if (compilerOptions.target < 2 /* ES6 */) { + if (languageVersion < 2 /* ES6 */) { write(": function "); } emitSignatureAndBody(node); - emitTrailingComments(node); } function emitPropertyAssignment(node) { - emitLeadingComments(node); emit(node.name); write(": "); emit(node.initializer); - emitTrailingComments(node); } function emitShorthandPropertyAssignment(node) { - emitLeadingComments(node); emit(node.name); - if (compilerOptions.target < 2 /* ES6 */ || resolver.getExpressionNamePrefix(node.name)) { + if (languageVersion < 2 /* ES6 */ || resolver.getExpressionNamePrefix(node.name)) { write(": "); emitExpressionIdentifier(node.name); } - emitTrailingComments(node); } function tryEmitConstantValue(node) { var constantValue = resolver.getConstantValue(node); @@ -17859,7 +18105,7 @@ var ts; } } function emitTaggedTemplateExpression(node) { - ts.Debug.assert(compilerOptions.target >= 2 /* ES6 */, "Trying to emit a tagged template in pre-ES6 mode."); + ts.Debug.assert(languageVersion >= 2 /* ES6 */, "Trying to emit a tagged template in pre-ES6 mode."); emit(node.tag); write(" "); emit(node.template); @@ -17912,7 +18158,7 @@ var ts; write(ts.tokenToString(node.operator)); } function emitBinaryExpression(node) { - if (compilerOptions.target < 2 /* ES6 */ && node.operator === 52 /* EqualsToken */ && (node.left.kind === 148 /* ObjectLiteralExpression */ || node.left.kind === 147 /* ArrayLiteralExpression */)) { + if (languageVersion < 2 /* ES6 */ && node.operator === 52 /* EqualsToken */ && (node.left.kind === 148 /* ObjectLiteralExpression */ || node.left.kind === 147 /* ArrayLiteralExpression */)) { emitDestructuring(node); } else { @@ -17961,13 +18207,10 @@ var ts; } } function emitExpressionStatement(node) { - emitLeadingComments(node); emitParenthesized(node.expression, node.expression.kind === 157 /* ArrowFunction */); write(";"); - emitTrailingComments(node); } function emitIfStatement(node) { - emitLeadingComments(node); var endPos = emitToken(83 /* IfKeyword */, node.pos); write(" "); endPos = emitToken(16 /* OpenParenToken */, endPos); @@ -17985,7 +18228,6 @@ var ts; emitEmbeddedStatement(node.elseStatement); } } - emitTrailingComments(node); } function emitDoStatement(node) { write("do"); @@ -18067,11 +18309,9 @@ var ts; write(";"); } function emitReturnStatement(node) { - emitLeadingComments(node); emitToken(89 /* ReturnKeyword */, node.pos); emitOptional(" ", node.expression); write(";"); - emitTrailingComments(node); } function emitWithStatement(node) { write("with ("); @@ -18352,9 +18592,8 @@ var ts; } } function emitVariableDeclaration(node) { - emitLeadingComments(node); if (ts.isBindingPattern(node.name)) { - if (compilerOptions.target < 2 /* ES6 */) { + if (languageVersion < 2 /* ES6 */) { emitDestructuring(node); } else { @@ -18366,10 +18605,8 @@ var ts; emitModuleMemberName(node); emitOptional(" = ", node.initializer); } - emitTrailingComments(node); } function emitVariableStatement(node) { - emitLeadingComments(node); if (!(node.flags & 1 /* Export */)) { if (ts.isLet(node.declarationList)) { write("let "); @@ -18383,11 +18620,9 @@ var ts; } emitCommaList(node.declarationList.declarations); write(";"); - emitTrailingComments(node); } function emitParameter(node) { - emitLeadingComments(node); - if (compilerOptions.target < 2 /* ES6 */) { + if (languageVersion < 2 /* ES6 */) { if (ts.isBindingPattern(node.name)) { var name = createTempVariable(node); if (!tempParameters) { @@ -18407,10 +18642,9 @@ var ts; emit(node.name); emitOptional(" = ", node.initializer); } - emitTrailingComments(node); } function emitDefaultValueAssignments(node) { - if (compilerOptions.target < 2 /* ES6 */) { + if (languageVersion < 2 /* ES6 */) { var tempIndex = 0; ts.forEach(node.parameters, function (p) { if (ts.isBindingPattern(p.name)) { @@ -18439,7 +18673,7 @@ var ts; } } function emitRestParameter(node) { - if (compilerOptions.target < 2 /* ES6 */ && ts.hasRestParameters(node)) { + if (languageVersion < 2 /* ES6 */ && ts.hasRestParameters(node)) { var restIndex = node.parameters.length - 1; var restParam = node.parameters[restIndex]; var tempName = createTempVariable(node, true).text; @@ -18477,11 +18711,9 @@ var ts; } } function emitAccessor(node) { - emitLeadingComments(node); write(node.kind === 130 /* GetAccessor */ ? "get " : "set "); emit(node.name); emitSignatureAndBody(node); - emitTrailingComments(node); } function emitFunctionDeclaration(node) { if (ts.nodeIsMissing(node.body)) { @@ -18512,7 +18744,7 @@ var ts; write("("); if (node) { var parameters = node.parameters; - var omitCount = compilerOptions.target < 2 /* ES6 */ && ts.hasRestParameters(node) ? 1 : 0; + var omitCount = languageVersion < 2 /* ES6 */ && ts.hasRestParameters(node) ? 1 : 0; emitList(parameters, 0, parameters.length - omitCount, false, false); } write(")"); @@ -18543,7 +18775,7 @@ var ts; write(" "); emitStart(node.body); write("return "); - emitNode(node.body); + emitNode(node.body, true); emitEnd(node.body); write(";"); emitTempDeclarations(false); @@ -18560,7 +18792,7 @@ var ts; writeLine(); emitLeadingComments(node.body); write("return "); - emit(node.body); + emit(node.body, true); write(";"); emitTrailingComments(node.body); } @@ -18734,7 +18966,6 @@ var ts; }); } function emitClassDeclaration(node) { - emitLeadingComments(node); write("var "); emit(node.name); write(" = (function ("); @@ -18784,7 +19015,6 @@ var ts; emitEnd(node); write(";"); } - emitTrailingComments(node); function emitConstructorOfClass() { var saveTempCount = tempCount; var saveTempVariables = tempVariables; @@ -18859,12 +19089,14 @@ var ts; function emitInterfaceDeclaration(node) { emitPinnedOrTripleSlashComments(node); } - function emitEnumDeclaration(node) { + function shouldEmitEnumDeclaration(node) { var isConstEnum = ts.isConst(node); - if (isConstEnum && !compilerOptions.preserveConstEnums) { + return !isConstEnum || compilerOptions.preserveConstEnums; + } + function emitEnumDeclaration(node) { + if (!shouldEmitEnumDeclaration(node)) { return; } - emitLeadingComments(node); if (!(node.flags & 1 /* Export */)) { emitStart(node); write("var "); @@ -18881,7 +19113,7 @@ var ts; write(") {"); increaseIndent(); scopeEmitStart(node); - emitEnumMemberDeclarations(isConstEnum); + emitLines(node.members); decreaseIndent(); writeLine(); emitToken(15 /* CloseBraceToken */, node.members.end); @@ -18902,31 +19134,26 @@ var ts; emitEnd(node); write(";"); } - emitTrailingComments(node); - function emitEnumMemberDeclarations(isConstEnum) { - ts.forEach(node.members, function (member) { - writeLine(); - emitLeadingComments(member); - emitStart(member); - write(resolver.getLocalNameOfContainer(node)); - write("["); - write(resolver.getLocalNameOfContainer(node)); - write("["); - emitExpressionForPropertyName(member.name); - write("] = "); - if (member.initializer && !isConstEnum) { - emit(member.initializer); - } - else { - write(resolver.getEnumMemberValue(member).toString()); - } - write("] = "); - emitExpressionForPropertyName(member.name); - emitEnd(member); - write(";"); - emitTrailingComments(member); - }); + } + function emitEnumMember(node) { + var enumParent = node.parent; + emitStart(node); + write(resolver.getLocalNameOfContainer(enumParent)); + write("["); + write(resolver.getLocalNameOfContainer(enumParent)); + write("["); + emitExpressionForPropertyName(node.name); + write("] = "); + if (node.initializer && !ts.isConst(enumParent)) { + emit(node.initializer); } + else { + write(resolver.getEnumMemberValue(node).toString()); + } + write("] = "); + emitExpressionForPropertyName(node.name); + emitEnd(node); + write(";"); } function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) { if (moduleDeclaration.body.kind === 195 /* ModuleDeclaration */) { @@ -18934,12 +19161,14 @@ var ts; return recursiveInnerModule || moduleDeclaration.body; } } + function shouldEmitModuleDeclaration(node) { + return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums); + } function emitModuleDeclaration(node) { - var shouldEmit = ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums); + var shouldEmit = shouldEmitModuleDeclaration(node); if (!shouldEmit) { return emitPinnedOrTripleSlashComments(node); } - emitLeadingComments(node); emitStart(node); write("var "); emit(node.name); @@ -18984,7 +19213,6 @@ var ts; emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - emitTrailingComments(node); } function emitImportDeclaration(node) { var emitImportDeclaration = resolver.isReferencedImportDeclaration(node); @@ -19157,13 +19385,38 @@ var ts; } emitLeadingComments(node.endOfFileToken); } - function emitNode(node) { + function emitNode(node, disableComments) { if (!node) { return; } if (node.flags & 2 /* Ambient */) { return emitPinnedOrTripleSlashComments(node); } + var emitComments = !disableComments && shouldEmitLeadingAndTrailingComments(node); + if (emitComments) { + emitLeadingComments(node); + } + emitJavaScriptWorker(node); + if (emitComments) { + emitTrailingComments(node); + } + } + function shouldEmitLeadingAndTrailingComments(node) { + switch (node.kind) { + case 192 /* InterfaceDeclaration */: + case 190 /* FunctionDeclaration */: + case 197 /* ImportDeclaration */: + case 193 /* TypeAliasDeclaration */: + case 198 /* ExportAssignment */: + return false; + case 195 /* ModuleDeclaration */: + return shouldEmitModuleDeclaration(node); + case 194 /* EnumDeclaration */: + return shouldEmitEnumDeclaration(node); + } + return true; + } + function emitJavaScriptWorker(node) { switch (node.kind) { case 64 /* Identifier */: return emitIdentifier(node); @@ -19300,6 +19553,8 @@ var ts; return emitInterfaceDeclaration(node); case 194 /* EnumDeclaration */: return emitEnumDeclaration(node); + case 206 /* EnumMember */: + return emitEnumMember(node); case 195 /* ModuleDeclaration */: return emitModuleDeclaration(node); case 197 /* ImportDeclaration */: @@ -19322,15 +19577,17 @@ var ts; return leadingComments; } function getLeadingCommentsToEmit(node) { - if (node.parent.kind === 207 /* SourceFile */ || node.pos !== node.parent.pos) { - var leadingComments; - if (hasDetachedComments(node.pos)) { - leadingComments = getLeadingCommentsWithoutDetachedComments(); + if (node.parent) { + if (node.parent.kind === 207 /* SourceFile */ || node.pos !== node.parent.pos) { + var leadingComments; + if (hasDetachedComments(node.pos)) { + leadingComments = getLeadingCommentsWithoutDetachedComments(); + } + else { + leadingComments = ts.getLeadingCommentRangesOfNode(node, currentSourceFile); + } + return leadingComments; } - else { - leadingComments = ts.getLeadingCommentRangesOfNode(node, currentSourceFile); - } - return leadingComments; } } function emitLeadingDeclarationComments(node) { @@ -19339,9 +19596,11 @@ var ts; emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment); } function emitTrailingDeclarationComments(node) { - if (node.parent.kind === 207 /* SourceFile */ || node.end !== node.parent.end) { - var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); - emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); + if (node.parent) { + if (node.parent.kind === 207 /* SourceFile */ || node.end !== node.parent.end) { + var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end); + emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment); + } } } function emitLeadingCommentsOfLocalPosition(pos) { @@ -19779,7 +20038,7 @@ var ts; return; } var firstExternalModule = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); - if (firstExternalModule && options.module === 0 /* None */) { + if (firstExternalModule && !options.module) { var externalModuleErrorSpan = ts.getErrorSpanForNode(firstExternalModule.externalModuleIndicator); var errorStart = ts.skipTrivia(firstExternalModule.text, externalModuleErrorSpan.pos); var errorLength = externalModuleErrorSpan.end - errorStart; @@ -19859,6 +20118,10 @@ var ts; type: "boolean", description: ts.Diagnostics.Print_this_message }, + { + name: "listFiles", + type: "boolean" + }, { name: "locale", type: "string" @@ -19866,6 +20129,7 @@ var ts; { name: "mapRoot", type: "string", + isFilePath: true, description: ts.Diagnostics.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations, paramType: ts.Diagnostics.LOCATION }, @@ -19916,6 +20180,7 @@ var ts; { name: "outDir", type: "string", + isFilePath: true, description: ts.Diagnostics.Redirect_output_structure_to_the_directory, paramType: ts.Diagnostics.DIRECTORY }, @@ -19924,6 +20189,14 @@ var ts; type: "boolean", description: ts.Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code }, + { + name: "project", + shortName: "p", + type: "string", + isFilePath: true, + description: ts.Diagnostics.Compile_the_project_in_the_given_directory, + paramType: ts.Diagnostics.DIRECTORY + }, { name: "removeComments", type: "boolean", @@ -19937,6 +20210,7 @@ var ts; { name: "sourceRoot", type: "string", + isFilePath: true, description: ts.Diagnostics.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations, paramType: ts.Diagnostics.LOCATION }, @@ -19966,21 +20240,18 @@ var ts; description: ts.Diagnostics.Watch_input_files } ]; - var shortOptionNames = {}; - var optionNameMap = {}; - ts.forEach(ts.optionDeclarations, function (option) { - optionNameMap[option.name.toLowerCase()] = option; - if (option.shortName) { - shortOptionNames[option.shortName] = option.name; - } - }); function parseCommandLine(commandLine) { - var options = { - target: 0 /* ES3 */, - module: 0 /* None */ - }; + var options = {}; var filenames = []; var errors = []; + var shortOptionNames = {}; + var optionNameMap = {}; + ts.forEach(ts.optionDeclarations, function (option) { + optionNameMap[option.name.toLowerCase()] = option; + if (option.shortName) { + shortOptionNames[option.shortName] = option.name; + } + }); parseStrings(commandLine); return { options: options, @@ -20070,6 +20341,83 @@ var ts; } } ts.parseCommandLine = parseCommandLine; + function readConfigFile(filename) { + try { + var text = ts.sys.readFile(filename); + return /\S/.test(text) ? JSON.parse(text) : {}; + } + catch (e) { + } + } + ts.readConfigFile = readConfigFile; + function parseConfigFile(json, basePath) { + var errors = []; + return { + options: getCompilerOptions(), + filenames: getFiles(), + errors: errors + }; + function getCompilerOptions() { + var options = {}; + var optionNameMap = {}; + ts.forEach(ts.optionDeclarations, function (option) { + optionNameMap[option.name] = option; + }); + var jsonOptions = json["compilerOptions"]; + if (jsonOptions) { + for (var id in jsonOptions) { + if (ts.hasProperty(optionNameMap, id)) { + var opt = optionNameMap[id]; + var optType = opt.type; + var value = jsonOptions[id]; + var expectedType = typeof optType === "string" ? optType : "string"; + if (typeof value === expectedType) { + if (typeof optType !== "string") { + var key = value.toLowerCase(); + if (ts.hasProperty(optType, key)) { + value = optType[key]; + } + else { + errors.push(ts.createCompilerDiagnostic(opt.error)); + value = 0; + } + } + if (opt.isFilePath) { + value = ts.normalizePath(ts.combinePaths(basePath, value)); + } + options[opt.name] = value; + } + else { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType)); + } + } + else { + errors.push(ts.createCompilerDiagnostic(ts.Diagnostics.Unknown_compiler_option_0, id)); + } + } + } + return options; + } + function getFiles() { + var files = []; + if (ts.hasProperty(json, "files")) { + if (json["files"] instanceof Array) { + var files = ts.map(json["files"], function (s) { return ts.combinePaths(basePath, s); }); + } + } + else { + var sysFiles = ts.sys.readDirectory(basePath, ".ts"); + for (var i = 0; i < sysFiles.length; i++) { + var name = sysFiles[i]; + if (!ts.fileExtensionIs(name, ".d.ts") || !ts.contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { + files.push(name); + } + } + } + return files; + } + } + ts.parseConfigFile = parseConfigFile; })(ts || (ts = {})); var ts; (function (ts) { @@ -20205,8 +20553,9 @@ var ts; case 145 /* ArrayBindingPattern */: ts.forEach(node.elements, visit); break; + case 146 /* BindingElement */: case 188 /* VariableDeclaration */: - if (ts.isBindingPattern(node)) { + if (ts.isBindingPattern(node.name)) { visit(node.name); break; } @@ -20353,17 +20702,30 @@ var ts; case 190 /* FunctionDeclaration */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.functionElement); case 188 /* VariableDeclaration */: - if (ts.isBindingPattern(node.name)) { - break; - } - if (ts.isConst(node)) { - return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.constElement); - } - else if (ts.isLet(node)) { - return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.letElement); + case 146 /* BindingElement */: + var variableDeclarationNode; + var name; + if (node.kind === 146 /* BindingElement */) { + name = node.name; + variableDeclarationNode = node; + while (variableDeclarationNode && variableDeclarationNode.kind !== 188 /* VariableDeclaration */) { + variableDeclarationNode = variableDeclarationNode.parent; + } + ts.Debug.assert(variableDeclarationNode !== undefined); } else { - return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.variableElement); + ts.Debug.assert(!ts.isBindingPattern(node.name)); + variableDeclarationNode = node; + name = node.name; + } + if (ts.isConst(variableDeclarationNode)) { + return createItem(node, getTextOfNode(name), ts.ScriptElementKind.constElement); + } + else if (ts.isLet(variableDeclarationNode)) { + return createItem(node, getTextOfNode(name), ts.ScriptElementKind.letElement); + } + else { + return createItem(node, getTextOfNode(name), ts.ScriptElementKind.variableElement); } case 129 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -21281,6 +21643,9 @@ var ts; end: scanner.getTextPos(), kind: currentToken }; + if (trailingTrivia) { + trailingTrivia = undefined; + } while (scanner.getStartPos() < endPos) { currentToken = scanner.scan(); if (!ts.isTrivia(currentToken)) { @@ -22227,7 +22592,9 @@ var ts; })(Constants || (Constants = {})); function formatOnEnter(position, sourceFile, rulesProvider, options) { var line = sourceFile.getLineAndCharacterFromPosition(position).line; - ts.Debug.assert(line >= 2); + if (line === 1) { + return []; + } var span = { pos: ts.getStartPositionOfLine(line - 1, sourceFile), end: ts.getEndLinePosition(line, sourceFile) + 1 @@ -22345,7 +22712,13 @@ var ts; return start; } var precedingToken = ts.findPrecedingToken(originalRange.pos, sourceFile); - return precedingToken ? precedingToken.end : enclosingNode.pos; + if (!precedingToken) { + return enclosingNode.pos; + } + if (precedingToken.end >= originalRange.pos) { + return enclosingNode.pos; + } + return precedingToken.end; } function getOwnOrInheritedDelta(n, options, sourceFile) { var previousLine = -1 /* Unknown */; @@ -22556,7 +22929,7 @@ var ts; if (listEndToken !== 0 /* Unknown */) { if (formattingScanner.isOnToken()) { var tokenInfo = formattingScanner.readTokenInfo(parent); - if (tokenInfo.token.kind === listEndToken) { + if (tokenInfo.token.kind === listEndToken && ts.rangeContainsRange(parent, tokenInfo.token)) { consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation); } } @@ -22908,7 +23281,8 @@ var ts; if (!precedingToken) { return 0; } - if ((precedingToken.kind === 8 /* StringLiteral */ || precedingToken.kind === 9 /* RegularExpressionLiteral */) && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { + var precedingTokenIsLiteral = precedingToken.kind === 8 /* StringLiteral */ || precedingToken.kind === 9 /* RegularExpressionLiteral */ || precedingToken.kind === 10 /* NoSubstitutionTemplateLiteral */ || precedingToken.kind === 11 /* TemplateHead */ || precedingToken.kind === 12 /* TemplateMiddle */ || precedingToken.kind === 13 /* TemplateTail */; + if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { return 0; } var lineAtPosition = sourceFile.getLineAndCharacterFromPosition(position).line; @@ -23243,7 +23617,7 @@ var __extends = this.__extends || function (d, b) { }; var ts; (function (ts) { - ts.servicesVersion = "0.4"; + ts.servicesVersion = "0.5"; var ScriptSnapshot; (function (ScriptSnapshot) { var StringScriptSnapshot = (function () { @@ -23440,28 +23814,30 @@ var ts; function getJsDocCommentsSeparatedByNewLines() { var paramTag = "@param"; var jsDocCommentParts = []; - ts.forEach(declarations, function (declaration) { - var sourceFileOfDeclaration = ts.getSourceFileOfNode(declaration); - if (canUseParsedParamTagComments && declaration.kind === 124 /* Parameter */) { - ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), function (jsDocCommentTextRange) { - var cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); - if (cleanedParamJsDocComment) { - jsDocCommentParts.push.apply(jsDocCommentParts, cleanedParamJsDocComment); + ts.forEach(declarations, function (declaration, indexOfDeclaration) { + if (ts.indexOf(declarations, declaration) === indexOfDeclaration) { + var sourceFileOfDeclaration = ts.getSourceFileOfNode(declaration); + if (canUseParsedParamTagComments && declaration.kind === 124 /* Parameter */) { + ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), function (jsDocCommentTextRange) { + var cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); + if (cleanedParamJsDocComment) { + jsDocCommentParts.push.apply(jsDocCommentParts, cleanedParamJsDocComment); + } + }); + } + if (declaration.kind === 195 /* ModuleDeclaration */ && declaration.body.kind === 195 /* ModuleDeclaration */) { + return; + } + while (declaration.kind === 195 /* ModuleDeclaration */ && declaration.parent.kind === 195 /* ModuleDeclaration */) { + declaration = declaration.parent; + } + ts.forEach(getJsDocCommentTextRange(declaration.kind === 188 /* VariableDeclaration */ ? declaration.parent.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { + var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); + if (cleanedJsDocComment) { + jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment); } }); } - if (declaration.kind === 195 /* ModuleDeclaration */ && declaration.body.kind === 195 /* ModuleDeclaration */) { - return; - } - while (declaration.kind === 195 /* ModuleDeclaration */ && declaration.parent.kind === 195 /* ModuleDeclaration */) { - declaration = declaration.parent; - } - ts.forEach(getJsDocCommentTextRange(declaration.kind === 188 /* VariableDeclaration */ ? declaration.parent.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) { - var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); - if (cleanedJsDocComment) { - jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment); - } - }); }); return jsDocCommentParts; function getJsDocCommentTextRange(node, sourceFile) { @@ -24087,6 +24463,7 @@ var ts; function createLanguageServiceSourceFile(filename, scriptSnapshot, scriptTarget, version, isOpen, setNodeParents) { var sourceFile = ts.createSourceFile(filename, scriptSnapshot.getText(0, scriptSnapshot.getLength()), scriptTarget, setNodeParents); setSourceFileFields(sourceFile, scriptSnapshot, version, isOpen); + sourceFile.nameTable = sourceFile.identifiers; return sourceFile; } ts.createLanguageServiceSourceFile = createLanguageServiceSourceFile; @@ -24110,6 +24487,7 @@ var ts; if (!ts.disableIncrementalParsing) { var newSourceFile = sourceFile.update(scriptSnapshot.getText(0, scriptSnapshot.getLength()), textChangeRange); setSourceFileFields(newSourceFile, scriptSnapshot, version, isOpen); + newSourceFile.nameTable = undefined; return newSourceFile; } } @@ -24409,7 +24787,9 @@ var ts; getCancellationToken: function () { return cancellationToken; }, getCanonicalFileName: function (filename) { return useCaseSensitivefilenames ? filename : filename.toLowerCase(); }, useCaseSensitiveFileNames: function () { return useCaseSensitivefilenames; }, - getNewLine: function () { return "\r\n"; }, + getNewLine: function () { + return host.getNewLine ? host.getNewLine() : "\r\n"; + }, getDefaultLibFilename: function (options) { return host.getDefaultLibFilename(options); }, @@ -25395,7 +25775,7 @@ var ts; return undefined; } if (node.kind === 64 /* Identifier */ || node.kind === 92 /* ThisKeyword */ || node.kind === 90 /* SuperKeyword */ || isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { - return getReferencesForNode(node, [sourceFile], false, false); + return getReferencesForNode(node, [sourceFile], true, false, false); } switch (node.kind) { case 83 /* IfKeyword */: @@ -25817,9 +26197,27 @@ var ts; return undefined; } ts.Debug.assert(node.kind === 64 /* Identifier */ || node.kind === 7 /* NumericLiteral */ || node.kind === 8 /* StringLiteral */); - return getReferencesForNode(node, program.getSourceFiles(), findInStrings, findInComments); + return getReferencesForNode(node, program.getSourceFiles(), false, findInStrings, findInComments); } - function getReferencesForNode(node, sourceFiles, findInStrings, findInComments) { + function initializeNameTable(sourceFile) { + var nameTable = {}; + walk(sourceFile); + sourceFile.nameTable = nameTable; + function walk(node) { + switch (node.kind) { + case 64 /* Identifier */: + nameTable[node.text] = node.text; + break; + case 8 /* StringLiteral */: + case 7 /* NumericLiteral */: + nameTable[node.text] = node.text; + break; + default: + ts.forEachChild(node, walk); + } + } + } + function getReferencesForNode(node, sourceFiles, searchOnlyInCurrentFile, findInStrings, findInComments) { if (isLabelName(node)) { if (isJumpStatementTarget(node)) { var labelDefinition = getTargetLabel(node.parent, node.text); @@ -25852,14 +26250,25 @@ var ts; getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); } else { - var internedName = getInternedName(symbol, declarations); - ts.forEach(sourceFiles, function (sourceFile) { - cancellationToken.throwIfCancellationRequested(); - if (ts.lookUp(sourceFile.identifiers, internedName)) { - result = result || []; - getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); - } - }); + if (searchOnlyInCurrentFile) { + ts.Debug.assert(sourceFiles.length === 1); + result = []; + getReferencesInNode(sourceFiles[0], symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); + } + else { + var internedName = getInternedName(symbol, 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)) { + result = result || []; + getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); + } + }); + } } return result; function getDeclaredName(symbol) { @@ -25891,7 +26300,7 @@ var ts; return ts.getAncestor(privateDeclaration, 191 /* ClassDeclaration */); } } - if (symbol.parent) { + if (symbol.parent || (symbol.getFlags() & 268435456 /* UnionProperty */)) { return undefined; } var scope = undefined; @@ -26026,7 +26435,7 @@ var ts; } } function getReferencesForSuperKeyword(superKeyword) { - var searchSpaceNode = ts.getSuperContainer(superKeyword); + var searchSpaceNode = ts.getSuperContainer(superKeyword, false); if (!searchSpaceNode) { return undefined; } @@ -26054,7 +26463,7 @@ var ts; if (!node || node.kind !== 90 /* SuperKeyword */) { return; } - var container = ts.getSuperContainer(node); + var container = ts.getSuperContainer(node, false); if (container && (128 /* Static */ & container.flags) === staticFlag && container.parent.symbol === searchSpaceNode.symbol) { result.push(getReferenceEntryFromNode(node)); } diff --git a/bin/typescriptServices_internal.d.ts b/bin/typescriptServices_internal.d.ts index 5731d6959d..82f5e60675 100644 --- a/bin/typescriptServices_internal.d.ts +++ b/bin/typescriptServices_internal.d.ts @@ -44,6 +44,7 @@ declare module ts { function getProperty(map: Map, key: string): T; function isEmpty(map: Map): boolean; function clone(object: T): T; + function extend(first: Map, second: Map): Map; function forEachValue(map: Map, callback: (value: T) => U): U; function forEachKey(map: Map, callback: (key: string) => U): U; function lookUp(map: Map, key: string): T; @@ -125,6 +126,7 @@ declare module ts { createDirectory(directoryName: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; + readDirectory(path: string, extension?: string): string[]; getMemoryUsage?(): number; exit(exitCode?: number): void; } @@ -186,7 +188,7 @@ declare module ts { function isObjectLiteralMethod(node: Node): boolean; function getContainingFunction(node: Node): FunctionLikeDeclaration; function getThisContainer(node: Node, includeArrowFunctions: boolean): Node; - function getSuperContainer(node: Node): Node; + function getSuperContainer(node: Node, includeFunctions: boolean): Node; function getInvokedExpression(node: CallLikeExpression): Expression; function isExpression(node: Node): boolean; function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean): boolean; @@ -244,6 +246,8 @@ declare module ts { declare module ts { var optionDeclarations: CommandLineOption[]; function parseCommandLine(commandLine: string[]): ParsedCommandLine; + function readConfigFile(filename: string): any; + function parseConfigFile(json: any, basePath?: string): ParsedCommandLine; } declare module ts { interface ListItemInfo { diff --git a/bin/typescript_internal.d.ts b/bin/typescript_internal.d.ts index e9bff0d37f..2758ab3c21 100644 --- a/bin/typescript_internal.d.ts +++ b/bin/typescript_internal.d.ts @@ -44,6 +44,7 @@ declare module "typescript" { function getProperty(map: Map, key: string): T; function isEmpty(map: Map): boolean; function clone(object: T): T; + function extend(first: Map, second: Map): Map; function forEachValue(map: Map, callback: (value: T) => U): U; function forEachKey(map: Map, callback: (key: string) => U): U; function lookUp(map: Map, key: string): T; @@ -125,6 +126,7 @@ declare module "typescript" { createDirectory(directoryName: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; + readDirectory(path: string, extension?: string): string[]; getMemoryUsage?(): number; exit(exitCode?: number): void; } @@ -186,7 +188,7 @@ declare module "typescript" { function isObjectLiteralMethod(node: Node): boolean; function getContainingFunction(node: Node): FunctionLikeDeclaration; function getThisContainer(node: Node, includeArrowFunctions: boolean): Node; - function getSuperContainer(node: Node): Node; + function getSuperContainer(node: Node, includeFunctions: boolean): Node; function getInvokedExpression(node: CallLikeExpression): Expression; function isExpression(node: Node): boolean; function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean): boolean; @@ -244,6 +246,8 @@ declare module "typescript" { declare module "typescript" { var optionDeclarations: CommandLineOption[]; function parseCommandLine(commandLine: string[]): ParsedCommandLine; + function readConfigFile(filename: string): any; + function parseConfigFile(json: any, basePath?: string): ParsedCommandLine; } declare module "typescript" { interface ListItemInfo {