diff --git a/lib/lib.d.ts b/lib/lib.d.ts index 6bded7a1135..15745c5d533 100644 --- a/lib/lib.d.ts +++ b/lib/lib.d.ts @@ -965,38 +965,22 @@ interface JSON { * If a member contains nested objects, the nested objects are transformed before the parent object is. */ parse(text: string, reviver?: (key: any, value: any) => any): any; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - */ - stringify(value: any): string; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer A function that transforms the results. - */ - stringify(value: any, replacer: (key: string, value: any) => any): string; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer Array that transforms the results. - */ - stringify(value: any, replacer: any[]): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. * @param replacer A function that transforms the results. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: (key: string, value: any) => any, space: string | number): string; + stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer Array that transforms the results. + * @param replacer An array of strings and numbers that acts as a white list for selecting the object properties that will be stringified. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: any[], space: string | number): string; + stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; } + /** * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. */ diff --git a/lib/lib.es5.d.ts b/lib/lib.es5.d.ts index 3a0f73f3cc7..e4e0334e0cb 100644 --- a/lib/lib.es5.d.ts +++ b/lib/lib.es5.d.ts @@ -965,38 +965,22 @@ interface JSON { * If a member contains nested objects, the nested objects are transformed before the parent object is. */ parse(text: string, reviver?: (key: any, value: any) => any): any; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - */ - stringify(value: any): string; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer A function that transforms the results. - */ - stringify(value: any, replacer: (key: string, value: any) => any): string; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer Array that transforms the results. - */ - stringify(value: any, replacer: any[]): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. * @param replacer A function that transforms the results. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: (key: string, value: any) => any, space: string | number): string; + stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer Array that transforms the results. + * @param replacer An array of strings and numbers that acts as a white list for selecting the object properties that will be stringified. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: any[], space: string | number): string; + stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; } + /** * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. */ diff --git a/lib/lib.es6.d.ts b/lib/lib.es6.d.ts index 6ed743d739a..ae54e8e8570 100644 --- a/lib/lib.es6.d.ts +++ b/lib/lib.es6.d.ts @@ -965,38 +965,22 @@ interface JSON { * If a member contains nested objects, the nested objects are transformed before the parent object is. */ parse(text: string, reviver?: (key: any, value: any) => any): any; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - */ - stringify(value: any): string; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer A function that transforms the results. - */ - stringify(value: any, replacer: (key: string, value: any) => any): string; - /** - * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. - * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer Array that transforms the results. - */ - stringify(value: any, replacer: any[]): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. * @param replacer A function that transforms the results. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: (key: string, value: any) => any, space: string | number): string; + stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. - * @param replacer Array that transforms the results. + * @param replacer An array of strings and numbers that acts as a white list for selecting the object properties that will be stringified. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: any[], space: string | number): string; + stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; } + /** * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. */ diff --git a/lib/tsc.js b/lib/tsc.js index 8dba7a921dc..00c758c0446 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -913,6 +913,10 @@ var ts; } return result.sort(); } + function getDirectories(path) { + var folder = fso.GetFolder(path); + return getNames(folder.subfolders); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -967,6 +971,7 @@ var ts; getCurrentDirectory: function () { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + getDirectories: getDirectories, readDirectory: readDirectory, exit: function (exitCode) { try { @@ -1114,6 +1119,9 @@ var ts; function directoryExists(path) { return fileSystemEntryExists(path, 1); } + function getDirectories(path) { + return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1); }); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -1206,6 +1214,7 @@ var ts; getCurrentDirectory: function () { return process.cwd(); }, + getDirectories: getDirectories, readDirectory: readDirectory, getModifiedTime: function (path) { try { @@ -1256,6 +1265,7 @@ var ts; createDirectory: ChakraHost.createDirectory, getExecutingFilePath: function () { return ChakraHost.executingFile; }, getCurrentDirectory: function () { return ChakraHost.currentDirectory; }, + getDirectories: ChakraHost.getDirectories, readDirectory: ChakraHost.readDirectory, exit: ChakraHost.quit, realpath: realpath @@ -1389,7 +1399,7 @@ var ts; or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "or_expected_1144", message: "'{' or ';' expected." }, Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration_expected_1146", message: "Declaration expected." }, Import_declarations_in_a_namespace_cannot_reference_a_module: { code: 1147, category: ts.DiagnosticCategory.Error, key: "Import_declarations_in_a_namespace_cannot_reference_a_module_1147", message: "Import declarations in a namespace cannot reference a module." }, - Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting__1148", message: "Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file." }, + Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_use_imports_exports_or_module_augmentations_when_module_is_none_1148", message: "Cannot use imports, exports, or module augmentations when '--module' is 'none'." }, File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: ts.DiagnosticCategory.Error, key: "File_name_0_differs_from_already_included_file_name_1_only_in_casing_1149", message: "File name '{0}' differs from already included file name '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: ts.DiagnosticCategory.Error, key: "new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead_1150", message: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "const_declarations_must_be_initialized_1155", message: "'const' declarations must be initialized" }, @@ -1759,6 +1769,8 @@ var ts; this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation: { code: 2683, category: ts.DiagnosticCategory.Error, key: "this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_2683", message: "'this' implicitly has type 'any' because it does not have a type annotation." }, The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1: { code: 2684, category: ts.DiagnosticCategory.Error, key: "The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1_2684", message: "The 'this' context of type '{0}' is not assignable to method's 'this' of type '{1}'." }, The_this_types_of_each_signature_are_incompatible: { code: 2685, category: ts.DiagnosticCategory.Error, key: "The_this_types_of_each_signature_are_incompatible_2685", message: "The 'this' types of each signature are incompatible." }, + Identifier_0_must_be_imported_from_a_module: { code: 2686, category: ts.DiagnosticCategory.Error, key: "Identifier_0_must_be_imported_from_a_module_2686", message: "Identifier '{0}' must be imported from a module" }, + All_declarations_of_0_must_have_identical_modifiers: { code: 2687, category: ts.DiagnosticCategory.Error, key: "All_declarations_of_0_must_have_identical_modifiers_2687", message: "All declarations of '{0}' must have identical modifiers." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import_declaration_0_is_using_private_name_1_4000", message: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", message: "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: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", message: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1852,7 +1864,7 @@ var ts; Option_paths_cannot_be_used_without_specifying_baseUrl_option: { code: 5060, category: ts.DiagnosticCategory.Error, key: "Option_paths_cannot_be_used_without_specifying_baseUrl_option_5060", message: "Option 'paths' cannot be used without specifying '--baseUrl' option." }, Pattern_0_can_have_at_most_one_Asterisk_character: { code: 5061, category: ts.DiagnosticCategory.Error, key: "Pattern_0_can_have_at_most_one_Asterisk_character_5061", message: "Pattern '{0}' can have at most one '*' character" }, Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character: { code: 5062, category: ts.DiagnosticCategory.Error, key: "Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character_5062", message: "Substitution '{0}' in pattern '{1}' in can have at most one '*' character" }, - Substututions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substututions_for_pattern_0_should_be_an_array_5063", message: "Substututions for pattern '{0}' should be an array." }, + Substitutions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substitutions_for_pattern_0_should_be_an_array_5063", message: "Substitutions for pattern '{0}' should be an array." }, Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2: { code: 5064, category: ts.DiagnosticCategory.Error, key: "Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2_5064", message: "Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate_and_emit_output_to_single_file_6001", message: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates_corresponding_d_ts_file_6002", message: "Generates corresponding '.d.ts' file." }, @@ -1865,6 +1877,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_comments_to_output_6009", message: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_outputs_6010", message: "Do not emit outputs." }, Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking: { code: 6011, category: ts.DiagnosticCategory.Message, key: "Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typech_6011", message: "Allow default imports from modules with no default export. This does not affect code emit, just typechecking." }, + Skip_type_checking_of_declaration_files: { code: 6012, category: ts.DiagnosticCategory.Message, key: "Skip_type_checking_of_declaration_files_6012", message: "Skip type checking of declaration files." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015_6015", message: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'" }, Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015_6016", message: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print_this_message_6017", message: "Print this message." }, @@ -1966,6 +1979,7 @@ var ts; Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set: { code: 6128, category: ts.DiagnosticCategory.Message, key: "Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set_6128", message: "======== Resolving type reference directive '{0}', containing file not set, root directory not set. ========" }, The_config_file_0_found_doesn_t_contain_any_source_files: { code: 6129, category: ts.DiagnosticCategory.Error, key: "The_config_file_0_found_doesn_t_contain_any_source_files_6129", message: "The config file '{0}' found doesn't contain any source files." }, Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, + Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -5004,7 +5018,7 @@ var ts; } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 69 || name.kind === 9 || name.kind === 8) { + if (name.kind === 69 || name.kind === 9 || name.kind === 8 || name.kind === 142) { return name.text; } if (name.kind === 140) { @@ -12050,10 +12064,10 @@ var ts; case 145: case 144: case 266: - return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455); + return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 0); case 253: case 254: - return bindPropertyOrMethodOrAccessor(node, 4, 107455); + return bindPropertyOrMethodOrAccessor(node, 4, 0); case 255: return bindPropertyOrMethodOrAccessor(node, 8, 107455); case 247: @@ -12065,7 +12079,7 @@ var ts; return declareSymbolAndAddToSymbolTable(node, 131072, 0); case 147: case 146: - return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263); + return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 0 : 99263); case 220: return bindFunctionDeclaration(node); case 148: @@ -12108,7 +12122,7 @@ var ts; case 238: return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); case 228: - return bindGlobalModuleExportDeclaration(node); + return bindNamespaceExportDeclaration(node); case 231: return bindImportClause(node); case 236: @@ -12144,13 +12158,13 @@ var ts; bindAnonymousDeclaration(node, 8388608, getDeclarationName(node)); } else if (boundExpression.kind === 69 && node.kind === 235) { - declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608); + declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 0 | 8388608); } else { - declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608); + declareSymbol(container.symbol.exports, container.symbol, node, 4, 0 | 8388608); } } - function bindGlobalModuleExportDeclaration(node) { + function bindNamespaceExportDeclaration(node) { if (node.modifiers && node.modifiers.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Modifiers_cannot_appear_here)); } @@ -12202,7 +12216,7 @@ var ts; function bindThisPropertyAssignment(node) { if (container.kind === 179 || container.kind === 220) { container.symbol.members = container.symbol.members || {}; - declareSymbol(container.symbol.members, container.symbol, node, 4, 107455 & ~4); + declareSymbol(container.symbol.members, container.symbol, node, 4, 0 & ~4); } } function bindPrototypePropertyAssignment(node) { @@ -12219,7 +12233,7 @@ var ts; if (!funcSymbol.members) { funcSymbol.members = {}; } - declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4, 107455); + declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4, 0); } function bindCallExpression(node) { if (!file.commonJsModuleIndicator && ts.isRequireCall(node, false)) { @@ -12295,7 +12309,7 @@ var ts; } if (ts.isParameterPropertyDeclaration(node)) { var classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 0); } } function bindFunctionDeclaration(node) { @@ -12595,7 +12609,7 @@ var ts; if (flags & 1) result |= 107454; if (flags & 4) - result |= 107455; + result |= 0; if (flags & 8) result |= 107455; if (flags & 16) @@ -12851,6 +12865,7 @@ var ts; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; + var isInExternalModule = false; loop: while (location) { if (location.locals && !isGlobalSourceFile(location)) { if (result = getSymbol(location.locals, name, meaning)) { @@ -12882,6 +12897,7 @@ var ts; case 256: if (!ts.isExternalOrCommonJsModule(location)) break; + isInExternalModule = true; case 225: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 256 || ts.isAmbientModule(location)) { @@ -13005,6 +13021,12 @@ var ts; checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); } } + if (result && isInExternalModule) { + var decls = result.declarations; + if (decls && decls.length === 1 && decls[0].kind === 228) { + error(errorLocation, ts.Diagnostics.Identifier_0_must_be_imported_from_a_module, name); + } + } } return result; } @@ -14480,7 +14502,7 @@ var ts; } function getTypeForBindingElementParent(node) { var symbol = getSymbolOfNode(node); - return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, false); } function getTextOfPropertyName(name) { switch (name.kind) { @@ -14585,7 +14607,7 @@ var ts; function addOptionality(type, optional) { return strictNullChecks && optional ? addNullableKind(type, 32) : type; } - function getTypeForVariableLikeDeclaration(declaration) { + function getTypeForVariableLikeDeclaration(declaration, includeOptionality) { if (declaration.flags & 134217728) { var type = getTypeForVariableLikeDeclarationFromJSDocComment(declaration); if (type && type !== unknownType) { @@ -14602,7 +14624,7 @@ var ts; return getTypeForBindingElement(declaration); } if (declaration.type) { - return addOptionality(getTypeFromTypeNode(declaration.type), !!declaration.questionToken); + return addOptionality(getTypeFromTypeNode(declaration.type), declaration.questionToken && includeOptionality); } if (declaration.kind === 142) { var func = declaration.parent; @@ -14621,11 +14643,11 @@ var ts; ? getContextuallyTypedThisType(func) : getContextuallyTypedParameterType(declaration); if (type) { - return addOptionality(type, !!declaration.questionToken); + return addOptionality(type, declaration.questionToken && includeOptionality); } } if (declaration.initializer) { - return addOptionality(checkExpressionCached(declaration.initializer), !!declaration.questionToken); + return addOptionality(checkExpressionCached(declaration.initializer), declaration.questionToken && includeOptionality); } if (declaration.kind === 254) { return checkIdentifier(declaration.name); @@ -14693,7 +14715,7 @@ var ts; : getTypeFromArrayBindingPattern(pattern, includePatternInType); } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { - var type = getTypeForVariableLikeDeclaration(declaration); + var type = getTypeForVariableLikeDeclaration(declaration, true); if (type) { if (reportErrors) { reportErrorsFromWidening(declaration, type); @@ -17010,7 +17032,7 @@ var ts; return isIdenticalTo(source, target); } if (!(target.flags & 134217728)) { - if (target.flags & 1) + if (target.flags & 1 || source.flags & 134217728) return -1; if (source.flags & 32) { if (!strictNullChecks || target.flags & (32 | 16) || source === emptyArrayElementType) @@ -17030,7 +17052,7 @@ var ts; if (source.flags & 256 && target === stringType) return -1; if (relation === assignableRelation || relation === comparableRelation) { - if (source.flags & (1 | 134217728)) + if (source.flags & 1) return -1; if (source === numberType && target.flags & 128) return -1; @@ -17807,41 +17829,47 @@ var ts; getSignaturesOfType(type, 0).length === 0 && getSignaturesOfType(type, 1).length === 0; } + function createTransientSymbol(source, type) { + var symbol = createSymbol(source.flags | 67108864, source.name); + symbol.declarations = source.declarations; + symbol.parent = source.parent; + symbol.type = type; + symbol.target = source; + if (source.valueDeclaration) { + symbol.valueDeclaration = source.valueDeclaration; + } + return symbol; + } + function transformTypeOfMembers(type, f) { + var members = {}; + for (var _i = 0, _a = getPropertiesOfObjectType(type); _i < _a.length; _i++) { + var property = _a[_i]; + var original = getTypeOfSymbol(property); + var updated = f(original); + members[property.name] = updated === original ? property : createTransientSymbol(property, updated); + } + ; + return members; + } function getRegularTypeOfObjectLiteral(type) { - if (type.flags & 1048576) { - var regularType = type.regularType; - if (!regularType) { - regularType = createType(type.flags & ~1048576); - regularType.symbol = type.symbol; - regularType.members = type.members; - regularType.properties = type.properties; - regularType.callSignatures = type.callSignatures; - regularType.constructSignatures = type.constructSignatures; - regularType.stringIndexInfo = type.stringIndexInfo; - regularType.numberIndexInfo = type.numberIndexInfo; - type.regularType = regularType; - } + if (!(type.flags & 1048576)) { + return type; + } + var regularType = type.regularType; + if (regularType) { return regularType; } - return type; + var resolved = type; + var members = transformTypeOfMembers(type, getRegularTypeOfObjectLiteral); + var regularNew = createAnonymousType(resolved.symbol, members, resolved.callSignatures, resolved.constructSignatures, resolved.stringIndexInfo, resolved.numberIndexInfo); + regularNew.flags = resolved.flags & ~1048576; + type.regularType = regularNew; + return regularNew; } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfObjectType(type); - var members = {}; - ts.forEach(properties, function (p) { - var propType = getTypeOfSymbol(p); - var widenedType = getWidenedType(propType); - if (propType !== widenedType) { - var symbol = createSymbol(p.flags | 67108864, 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 members = transformTypeOfMembers(type, function (prop) { + var widened = getWidenedType(prop); + return prop === widened ? prop : widened; }); var stringIndexInfo = getIndexInfoOfType(type, 0); var numberIndexInfo = getIndexInfoOfType(type, 1); @@ -19134,7 +19162,7 @@ var ts; } return nodeCheckFlag === 512 ? getBaseConstructorTypeOfClass(classType) - : baseClassType; + : getTypeWithThisArgument(baseClassType, classType.thisType); function isLegalUsageOfSuperExpression(container) { if (!container) { return false; @@ -21182,7 +21210,7 @@ var ts; var types = void 0; var funcIsGenerator = !!func.asteriskToken; if (funcIsGenerator) { - types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + types = checkAndAggregateYieldOperandTypes(func, contextualMapper); if (types.length === 0) { var iterableIteratorAny = createIterableIteratorType(anyType); if (compilerOptions.noImplicitAny) { @@ -21192,8 +21220,7 @@ var ts; } } else { - var hasImplicitReturn = !!(func.flags & 32768); - types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync, hasImplicitReturn); + types = checkAndAggregateReturnExpressionTypes(func, contextualMapper); if (!types) { return neverType; } @@ -21240,9 +21267,9 @@ var ts; return widenedType; } } - function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + function checkAndAggregateYieldOperandTypes(func, contextualMapper) { var aggregatedTypes = []; - ts.forEachYieldExpression(body, function (yieldExpression) { + ts.forEachYieldExpression(func.body, function (yieldExpression) { var expr = yieldExpression.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -21256,28 +21283,34 @@ var ts; }); return aggregatedTypes; } - function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync, hasImplicitReturn) { + function checkAndAggregateReturnExpressionTypes(func, contextualMapper) { + var isAsync = ts.isAsyncFunctionLike(func); var aggregatedTypes = []; - var hasOmittedExpressions = false; - ts.forEachReturnStatement(body, function (returnStatement) { + var hasReturnWithNoExpression = !!(func.flags & 32768); + var hasReturnOfTypeNever = false; + ts.forEachReturnStatement(func.body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); if (isAsync) { - type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); + type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } - if (type !== neverType && !ts.contains(aggregatedTypes, type)) { + if (type === neverType) { + hasReturnOfTypeNever = true; + } + else if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } } else { - hasOmittedExpressions = true; + hasReturnWithNoExpression = true; } }); - if (aggregatedTypes.length === 0 && !hasOmittedExpressions && !hasImplicitReturn) { + if (aggregatedTypes.length === 0 && !hasReturnWithNoExpression && (hasReturnOfTypeNever || + func.kind === 179 || func.kind === 180)) { return undefined; } - if (strictNullChecks && aggregatedTypes.length && (hasOmittedExpressions || hasImplicitReturn)) { + if (strictNullChecks && aggregatedTypes.length && hasReturnWithNoExpression) { if (!ts.contains(aggregatedTypes, undefinedType)) { aggregatedTypes.push(undefinedType); } @@ -21407,7 +21440,9 @@ var ts; (expr.kind === 172 || expr.kind === 173) && expr.expression.kind === 97) { var func = ts.getContainingFunction(expr); - return !(func && func.kind === 148 && func.parent === symbol.valueDeclaration.parent); + if (!(func && func.kind === 148)) + return true; + return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent); } return true; } @@ -22231,6 +22266,79 @@ var ts; } } } + function checkClassForDuplicateDeclarations(node) { + var getter = 1, setter = 2, property = getter | setter; + var instanceNames = {}; + var staticNames = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 148) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var param = _c[_b]; + if (ts.isParameterPropertyDeclaration(param)) { + addName(instanceNames, param.name, param.name.text, property); + } + } + } + else { + var static = ts.forEach(member.modifiers, function (m) { return m.kind === 113; }); + var names = static ? staticNames : instanceNames; + var memberName = member.name && ts.getPropertyNameForPropertyNameNode(member.name); + if (memberName) { + switch (member.kind) { + case 149: + addName(names, member.name, memberName, getter); + break; + case 150: + addName(names, member.name, memberName, setter); + break; + case 145: + addName(names, member.name, memberName, property); + break; + } + } + } + } + function addName(names, location, name, meaning) { + if (ts.hasProperty(names, name)) { + var prev = names[name]; + if (prev & meaning) { + error(location, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(location)); + } + else { + names[name] = prev | meaning; + } + } + else { + names[name] = meaning; + } + } + } + function checkObjectTypeForDuplicateDeclarations(node) { + var names = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind == 144) { + var memberName = void 0; + switch (member.name.kind) { + case 9: + case 8: + case 69: + memberName = member.name.text; + break; + default: + continue; + } + if (ts.hasProperty(names, memberName)) { + error(member.symbol.valueDeclaration.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + error(member.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + } + else { + names[memberName] = true; + } + } + } + } function checkTypeForDuplicateIndexSignatures(node) { if (node.kind === 222) { var nodeSymbol = getSymbolOfNode(node); @@ -22449,6 +22557,7 @@ var ts; var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); + checkObjectTypeForDuplicateDeclarations(node); } } function checkArrayType(node) { @@ -23208,6 +23317,10 @@ var ts; if (node.initializer) { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined); } + if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { + error(symbol.valueDeclaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + error(node.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + } } if (node.kind !== 145 && node.kind !== 144) { checkExportsOnMergedDeclarations(node); @@ -23220,6 +23333,18 @@ var ts; checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } + function areDeclarationFlagsIdentical(left, right) { + if (ts.hasQuestionToken(left) !== ts.hasQuestionToken(right)) { + return false; + } + var interestingFlags = 8 | + 16 | + 256 | + 128 | + 64 | + 32; + return (left.flags & interestingFlags) === (right.flags & interestingFlags); + } function checkVariableDeclaration(node) { checkGrammarVariableDeclaration(node); return checkVariableLikeDeclaration(node); @@ -23770,6 +23895,7 @@ var ts; var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); checkTypeParameterListsIdentical(node, symbol); + checkClassForDuplicateDeclarations(node); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { var baseTypes = getBaseTypes(type); @@ -23981,6 +24107,7 @@ var ts; checkIndexConstraints(type); } } + checkObjectTypeForDuplicateDeclarations(node); } ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) { if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) { @@ -24735,10 +24862,8 @@ var ts; function checkSourceFileWorker(node) { var links = getNodeLinks(node); if (!(links.flags & 1)) { - if (compilerOptions.skipDefaultLibCheck) { - if (node.hasNoDefaultLib) { - return; - } + if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) { + return; } checkGrammarSourceFile(node); potentialThisCollisions.length = 0; @@ -25107,7 +25232,7 @@ var ts; return symbol && getTypeOfSymbol(symbol); } if (ts.isBindingPattern(node)) { - return getTypeForVariableLikeDeclaration(node.parent); + return getTypeForVariableLikeDeclaration(node.parent, true); } if (isInRightSideOfImportOrExportAssignment(node)) { var symbol = getSymbolAtLocation(node); @@ -25546,7 +25671,7 @@ var ts; if (file.moduleAugmentations.length) { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } - if (file.wasReferenced && file.symbol && file.symbol.globalExports) { + if (file.symbol && file.symbol.globalExports) { mergeSymbolTable(globals, file.symbol.globalExports); } }); @@ -26116,7 +26241,6 @@ var ts; if (prop.kind === 193 || name_20.kind === 140) { checkGrammarComputedPropertyName(name_20); - return "continue"; } if (prop.kind === 254 && !inDestructuring && prop.objectAssignmentInitializer) { return { value: grammarErrorOnNode(prop.equalsToken, ts.Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment) }; @@ -26146,17 +26270,21 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_20.text)) { - seen[name_20.text] = currentKind; + var effectiveName = ts.getPropertyNameForPropertyNameNode(name_20); + if (effectiveName === undefined) { + return "continue"; + } + if (!ts.hasProperty(seen, effectiveName)) { + seen[effectiveName] = currentKind; } else { - var existingKind = seen[name_20.text]; + var existingKind = seen[effectiveName]; if (currentKind === Property && existingKind === Property) { - return "continue"; + grammarErrorOnNode(name_20, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name_20)); } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_20.text] = currentKind | existingKind; + seen[effectiveName] = currentKind | existingKind; } else { return { value: grammarErrorOnNode(name_20, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name) }; @@ -34613,7 +34741,7 @@ var ts; skipTsx: true, traceEnabled: traceEnabled }; - var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : undefined); + var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : (host.getCurrentDirectory && host.getCurrentDirectory())); if (traceEnabled) { if (containingFile === undefined) { if (rootDir === undefined) { @@ -35116,12 +35244,25 @@ var ts; } } } + function getDefaultTypeDirectiveNames(rootPath) { + var localTypes = ts.combinePaths(rootPath, "types"); + var npmTypes = ts.combinePaths(rootPath, "node_modules/@types"); + var result = []; + if (ts.sys.directoryExists(localTypes)) { + result = result.concat(ts.sys.getDirectories(localTypes)); + } + if (ts.sys.directoryExists(npmTypes)) { + result = result.concat(ts.sys.getDirectories(npmTypes)); + } + return result; + } function getDefaultLibLocation() { return ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())); } var newLine = ts.getNewLineCharacter(options); var realpath = ts.sys.realpath && (function (path) { return ts.sys.realpath(path); }); return { + getDefaultTypeDirectiveNames: getDefaultTypeDirectiveNames, getSourceFile: getSourceFile, getDefaultLibLocation: getDefaultLibLocation, getDefaultLibFileName: function (options) { return ts.combinePaths(getDefaultLibLocation(), ts.getDefaultLibFileName(options)); }, @@ -35189,6 +35330,19 @@ var ts; } return resolutions; } + function getDefaultTypeDirectiveNames(options, rootFiles, host) { + if (options.types) { + return options.types; + } + if (host && host.getDefaultTypeDirectiveNames) { + var commonRoot = computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), function (f) { return host.getCanonicalFileName(f); }); + if (commonRoot) { + return host.getDefaultTypeDirectiveNames(commonRoot); + } + } + return undefined; + } + ts.getDefaultTypeDirectiveNames = getDefaultTypeDirectiveNames; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; @@ -35224,13 +35378,14 @@ var ts; var filesByName = ts.createFileMap(); var filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? ts.createFileMap(function (fileName) { return fileName.toLowerCase(); }) : undefined; if (!tryReuseStructureFromOldProgram()) { - if (options.types && options.types.length) { - var resolutions = resolveTypeReferenceDirectiveNamesWorker(options.types, undefined); - for (var i = 0; i < options.types.length; i++) { - processTypeReferenceDirective(options.types[i], resolutions[i]); + ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); + var typeReferences = getDefaultTypeDirectiveNames(options, rootNames, host); + if (typeReferences) { + var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, undefined); + for (var i = 0; i < typeReferences.length; i++) { + processTypeReferenceDirective(typeReferences[i], resolutions[i]); } } - ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); if (!skipDefaultLib) { if (!options.lib) { processRootFile(host.getDefaultLibFileName(options), true); @@ -35807,9 +35962,6 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1) { - file_1.wasReferenced = file_1.wasReferenced || isReference; - } return file_1; } var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { @@ -35822,7 +35974,6 @@ var ts; }); filesByName.set(path, file); if (file) { - file.wasReferenced = file.wasReferenced || isReference; file.path = path; if (host.useCaseSensitiveFileNames()) { var existingFile = filesByNameIgnoreCase.get(path); @@ -35923,17 +36074,7 @@ var ts; !options.noResolve && i < file.imports.length; if (shouldAddFile) { - var importedFile = findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); - if (importedFile && resolution.isExternalLibraryImport) { - if (!ts.isExternalModule(importedFile) && importedFile.statements.length) { - var start_5 = ts.getTokenPosOfNode(file.imports[i], file); - fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_5, file.imports[i].end - start_5, ts.Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); - } - else if (importedFile.referencedFiles.length) { - var firstRef = importedFile.referencedFiles[0]; - fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); - } - } + findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } } } @@ -36018,7 +36159,7 @@ var ts; } } else { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substututions_for_pattern_0_should_be_an_array, key)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substitutions_for_pattern_0_should_be_an_array, key)); } } } @@ -36067,13 +36208,19 @@ var ts; } else if (firstExternalModuleSourceFile && languageVersion < 2 && options.module === ts.ModuleKind.None) { var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); } if (options.module === ts.ModuleKind.ES6 && languageVersion < 2) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es2015_when_targeting_ES5_or_lower)); } - if (outFile && options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + if (outFile) { + if (options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + } + else if (options.module === undefined && firstExternalModuleSourceFile) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); + } } if (options.outDir || options.sourceRoot || @@ -36156,6 +36303,11 @@ var ts; type: "boolean", description: ts.Diagnostics.Print_this_message }, + { + name: "help", + shortName: "?", + type: "boolean" + }, { name: "init", type: "boolean", @@ -36258,6 +36410,11 @@ var ts; name: "skipDefaultLibCheck", type: "boolean" }, + { + name: "skipLibCheck", + type: "boolean", + description: ts.Diagnostics.Skip_type_checking_of_declaration_files + }, { name: "out", type: "string", diff --git a/lib/tsserver.js b/lib/tsserver.js index ecb7bfb5509..7eb744a77d3 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -918,6 +918,10 @@ var ts; } return result.sort(); } + function getDirectories(path) { + var folder = fso.GetFolder(path); + return getNames(folder.subfolders); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -972,6 +976,7 @@ var ts; getCurrentDirectory: function () { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + getDirectories: getDirectories, readDirectory: readDirectory, exit: function (exitCode) { try { @@ -1119,6 +1124,9 @@ var ts; function directoryExists(path) { return fileSystemEntryExists(path, 1); } + function getDirectories(path) { + return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1); }); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -1211,6 +1219,7 @@ var ts; getCurrentDirectory: function () { return process.cwd(); }, + getDirectories: getDirectories, readDirectory: readDirectory, getModifiedTime: function (path) { try { @@ -1261,6 +1270,7 @@ var ts; createDirectory: ChakraHost.createDirectory, getExecutingFilePath: function () { return ChakraHost.executingFile; }, getCurrentDirectory: function () { return ChakraHost.currentDirectory; }, + getDirectories: ChakraHost.getDirectories, readDirectory: ChakraHost.readDirectory, exit: ChakraHost.quit, realpath: realpath @@ -1394,7 +1404,7 @@ var ts; or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "or_expected_1144", message: "'{' or ';' expected." }, Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration_expected_1146", message: "Declaration expected." }, Import_declarations_in_a_namespace_cannot_reference_a_module: { code: 1147, category: ts.DiagnosticCategory.Error, key: "Import_declarations_in_a_namespace_cannot_reference_a_module_1147", message: "Import declarations in a namespace cannot reference a module." }, - Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting__1148", message: "Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file." }, + Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_use_imports_exports_or_module_augmentations_when_module_is_none_1148", message: "Cannot use imports, exports, or module augmentations when '--module' is 'none'." }, File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: ts.DiagnosticCategory.Error, key: "File_name_0_differs_from_already_included_file_name_1_only_in_casing_1149", message: "File name '{0}' differs from already included file name '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: ts.DiagnosticCategory.Error, key: "new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead_1150", message: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "const_declarations_must_be_initialized_1155", message: "'const' declarations must be initialized" }, @@ -1764,6 +1774,8 @@ var ts; this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation: { code: 2683, category: ts.DiagnosticCategory.Error, key: "this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_2683", message: "'this' implicitly has type 'any' because it does not have a type annotation." }, The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1: { code: 2684, category: ts.DiagnosticCategory.Error, key: "The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1_2684", message: "The 'this' context of type '{0}' is not assignable to method's 'this' of type '{1}'." }, The_this_types_of_each_signature_are_incompatible: { code: 2685, category: ts.DiagnosticCategory.Error, key: "The_this_types_of_each_signature_are_incompatible_2685", message: "The 'this' types of each signature are incompatible." }, + Identifier_0_must_be_imported_from_a_module: { code: 2686, category: ts.DiagnosticCategory.Error, key: "Identifier_0_must_be_imported_from_a_module_2686", message: "Identifier '{0}' must be imported from a module" }, + All_declarations_of_0_must_have_identical_modifiers: { code: 2687, category: ts.DiagnosticCategory.Error, key: "All_declarations_of_0_must_have_identical_modifiers_2687", message: "All declarations of '{0}' must have identical modifiers." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import_declaration_0_is_using_private_name_1_4000", message: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", message: "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: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", message: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1857,7 +1869,7 @@ var ts; Option_paths_cannot_be_used_without_specifying_baseUrl_option: { code: 5060, category: ts.DiagnosticCategory.Error, key: "Option_paths_cannot_be_used_without_specifying_baseUrl_option_5060", message: "Option 'paths' cannot be used without specifying '--baseUrl' option." }, Pattern_0_can_have_at_most_one_Asterisk_character: { code: 5061, category: ts.DiagnosticCategory.Error, key: "Pattern_0_can_have_at_most_one_Asterisk_character_5061", message: "Pattern '{0}' can have at most one '*' character" }, Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character: { code: 5062, category: ts.DiagnosticCategory.Error, key: "Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character_5062", message: "Substitution '{0}' in pattern '{1}' in can have at most one '*' character" }, - Substututions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substututions_for_pattern_0_should_be_an_array_5063", message: "Substututions for pattern '{0}' should be an array." }, + Substitutions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substitutions_for_pattern_0_should_be_an_array_5063", message: "Substitutions for pattern '{0}' should be an array." }, Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2: { code: 5064, category: ts.DiagnosticCategory.Error, key: "Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2_5064", message: "Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate_and_emit_output_to_single_file_6001", message: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates_corresponding_d_ts_file_6002", message: "Generates corresponding '.d.ts' file." }, @@ -1870,6 +1882,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_comments_to_output_6009", message: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_outputs_6010", message: "Do not emit outputs." }, Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking: { code: 6011, category: ts.DiagnosticCategory.Message, key: "Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typech_6011", message: "Allow default imports from modules with no default export. This does not affect code emit, just typechecking." }, + Skip_type_checking_of_declaration_files: { code: 6012, category: ts.DiagnosticCategory.Message, key: "Skip_type_checking_of_declaration_files_6012", message: "Skip type checking of declaration files." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015_6015", message: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'" }, Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015_6016", message: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print_this_message_6017", message: "Print this message." }, @@ -1971,6 +1984,7 @@ var ts; Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set: { code: 6128, category: ts.DiagnosticCategory.Message, key: "Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set_6128", message: "======== Resolving type reference directive '{0}', containing file not set, root directory not set. ========" }, The_config_file_0_found_doesn_t_contain_any_source_files: { code: 6129, category: ts.DiagnosticCategory.Error, key: "The_config_file_0_found_doesn_t_contain_any_source_files_6129", message: "The config file '{0}' found doesn't contain any source files." }, Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, + Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -3537,6 +3551,11 @@ var ts; type: "boolean", description: ts.Diagnostics.Print_this_message }, + { + name: "help", + shortName: "?", + type: "boolean" + }, { name: "init", type: "boolean", @@ -3639,6 +3658,11 @@ var ts; name: "skipDefaultLibCheck", type: "boolean" }, + { + name: "skipLibCheck", + type: "boolean", + description: ts.Diagnostics.Skip_type_checking_of_declaration_files + }, { name: "out", type: "string", @@ -5758,7 +5782,7 @@ var ts; } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 69 || name.kind === 9 || name.kind === 8) { + if (name.kind === 69 || name.kind === 9 || name.kind === 8 || name.kind === 142) { return name.text; } if (name.kind === 140) { @@ -12804,10 +12828,10 @@ var ts; case 145: case 144: case 266: - return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455); + return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 0); case 253: case 254: - return bindPropertyOrMethodOrAccessor(node, 4, 107455); + return bindPropertyOrMethodOrAccessor(node, 4, 0); case 255: return bindPropertyOrMethodOrAccessor(node, 8, 107455); case 247: @@ -12819,7 +12843,7 @@ var ts; return declareSymbolAndAddToSymbolTable(node, 131072, 0); case 147: case 146: - return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263); + return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 0 : 99263); case 220: return bindFunctionDeclaration(node); case 148: @@ -12862,7 +12886,7 @@ var ts; case 238: return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); case 228: - return bindGlobalModuleExportDeclaration(node); + return bindNamespaceExportDeclaration(node); case 231: return bindImportClause(node); case 236: @@ -12898,13 +12922,13 @@ var ts; bindAnonymousDeclaration(node, 8388608, getDeclarationName(node)); } else if (boundExpression.kind === 69 && node.kind === 235) { - declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608); + declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 0 | 8388608); } else { - declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608); + declareSymbol(container.symbol.exports, container.symbol, node, 4, 0 | 8388608); } } - function bindGlobalModuleExportDeclaration(node) { + function bindNamespaceExportDeclaration(node) { if (node.modifiers && node.modifiers.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Modifiers_cannot_appear_here)); } @@ -12956,7 +12980,7 @@ var ts; function bindThisPropertyAssignment(node) { if (container.kind === 179 || container.kind === 220) { container.symbol.members = container.symbol.members || {}; - declareSymbol(container.symbol.members, container.symbol, node, 4, 107455 & ~4); + declareSymbol(container.symbol.members, container.symbol, node, 4, 0 & ~4); } } function bindPrototypePropertyAssignment(node) { @@ -12973,7 +12997,7 @@ var ts; if (!funcSymbol.members) { funcSymbol.members = {}; } - declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4, 107455); + declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4, 0); } function bindCallExpression(node) { if (!file.commonJsModuleIndicator && ts.isRequireCall(node, false)) { @@ -13049,7 +13073,7 @@ var ts; } if (ts.isParameterPropertyDeclaration(node)) { var classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 0); } } function bindFunctionDeclaration(node) { @@ -13349,7 +13373,7 @@ var ts; if (flags & 1) result |= 107454; if (flags & 4) - result |= 107455; + result |= 0; if (flags & 8) result |= 107455; if (flags & 16) @@ -13605,6 +13629,7 @@ var ts; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; + var isInExternalModule = false; loop: while (location) { if (location.locals && !isGlobalSourceFile(location)) { if (result = getSymbol(location.locals, name, meaning)) { @@ -13636,6 +13661,7 @@ var ts; case 256: if (!ts.isExternalOrCommonJsModule(location)) break; + isInExternalModule = true; case 225: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 256 || ts.isAmbientModule(location)) { @@ -13759,6 +13785,12 @@ var ts; checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); } } + if (result && isInExternalModule) { + var decls = result.declarations; + if (decls && decls.length === 1 && decls[0].kind === 228) { + error(errorLocation, ts.Diagnostics.Identifier_0_must_be_imported_from_a_module, name); + } + } } return result; } @@ -15234,7 +15266,7 @@ var ts; } function getTypeForBindingElementParent(node) { var symbol = getSymbolOfNode(node); - return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, false); } function getTextOfPropertyName(name) { switch (name.kind) { @@ -15339,7 +15371,7 @@ var ts; function addOptionality(type, optional) { return strictNullChecks && optional ? addNullableKind(type, 32) : type; } - function getTypeForVariableLikeDeclaration(declaration) { + function getTypeForVariableLikeDeclaration(declaration, includeOptionality) { if (declaration.flags & 134217728) { var type = getTypeForVariableLikeDeclarationFromJSDocComment(declaration); if (type && type !== unknownType) { @@ -15356,7 +15388,7 @@ var ts; return getTypeForBindingElement(declaration); } if (declaration.type) { - return addOptionality(getTypeFromTypeNode(declaration.type), !!declaration.questionToken); + return addOptionality(getTypeFromTypeNode(declaration.type), declaration.questionToken && includeOptionality); } if (declaration.kind === 142) { var func = declaration.parent; @@ -15375,11 +15407,11 @@ var ts; ? getContextuallyTypedThisType(func) : getContextuallyTypedParameterType(declaration); if (type) { - return addOptionality(type, !!declaration.questionToken); + return addOptionality(type, declaration.questionToken && includeOptionality); } } if (declaration.initializer) { - return addOptionality(checkExpressionCached(declaration.initializer), !!declaration.questionToken); + return addOptionality(checkExpressionCached(declaration.initializer), declaration.questionToken && includeOptionality); } if (declaration.kind === 254) { return checkIdentifier(declaration.name); @@ -15447,7 +15479,7 @@ var ts; : getTypeFromArrayBindingPattern(pattern, includePatternInType); } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { - var type = getTypeForVariableLikeDeclaration(declaration); + var type = getTypeForVariableLikeDeclaration(declaration, true); if (type) { if (reportErrors) { reportErrorsFromWidening(declaration, type); @@ -17764,7 +17796,7 @@ var ts; return isIdenticalTo(source, target); } if (!(target.flags & 134217728)) { - if (target.flags & 1) + if (target.flags & 1 || source.flags & 134217728) return -1; if (source.flags & 32) { if (!strictNullChecks || target.flags & (32 | 16) || source === emptyArrayElementType) @@ -17784,7 +17816,7 @@ var ts; if (source.flags & 256 && target === stringType) return -1; if (relation === assignableRelation || relation === comparableRelation) { - if (source.flags & (1 | 134217728)) + if (source.flags & 1) return -1; if (source === numberType && target.flags & 128) return -1; @@ -18561,41 +18593,47 @@ var ts; getSignaturesOfType(type, 0).length === 0 && getSignaturesOfType(type, 1).length === 0; } + function createTransientSymbol(source, type) { + var symbol = createSymbol(source.flags | 67108864, source.name); + symbol.declarations = source.declarations; + symbol.parent = source.parent; + symbol.type = type; + symbol.target = source; + if (source.valueDeclaration) { + symbol.valueDeclaration = source.valueDeclaration; + } + return symbol; + } + function transformTypeOfMembers(type, f) { + var members = {}; + for (var _i = 0, _a = getPropertiesOfObjectType(type); _i < _a.length; _i++) { + var property = _a[_i]; + var original = getTypeOfSymbol(property); + var updated = f(original); + members[property.name] = updated === original ? property : createTransientSymbol(property, updated); + } + ; + return members; + } function getRegularTypeOfObjectLiteral(type) { - if (type.flags & 1048576) { - var regularType = type.regularType; - if (!regularType) { - regularType = createType(type.flags & ~1048576); - regularType.symbol = type.symbol; - regularType.members = type.members; - regularType.properties = type.properties; - regularType.callSignatures = type.callSignatures; - regularType.constructSignatures = type.constructSignatures; - regularType.stringIndexInfo = type.stringIndexInfo; - regularType.numberIndexInfo = type.numberIndexInfo; - type.regularType = regularType; - } + if (!(type.flags & 1048576)) { + return type; + } + var regularType = type.regularType; + if (regularType) { return regularType; } - return type; + var resolved = type; + var members = transformTypeOfMembers(type, getRegularTypeOfObjectLiteral); + var regularNew = createAnonymousType(resolved.symbol, members, resolved.callSignatures, resolved.constructSignatures, resolved.stringIndexInfo, resolved.numberIndexInfo); + regularNew.flags = resolved.flags & ~1048576; + type.regularType = regularNew; + return regularNew; } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfObjectType(type); - var members = {}; - ts.forEach(properties, function (p) { - var propType = getTypeOfSymbol(p); - var widenedType = getWidenedType(propType); - if (propType !== widenedType) { - var symbol = createSymbol(p.flags | 67108864, 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 members = transformTypeOfMembers(type, function (prop) { + var widened = getWidenedType(prop); + return prop === widened ? prop : widened; }); var stringIndexInfo = getIndexInfoOfType(type, 0); var numberIndexInfo = getIndexInfoOfType(type, 1); @@ -19888,7 +19926,7 @@ var ts; } return nodeCheckFlag === 512 ? getBaseConstructorTypeOfClass(classType) - : baseClassType; + : getTypeWithThisArgument(baseClassType, classType.thisType); function isLegalUsageOfSuperExpression(container) { if (!container) { return false; @@ -21936,7 +21974,7 @@ var ts; var types = void 0; var funcIsGenerator = !!func.asteriskToken; if (funcIsGenerator) { - types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + types = checkAndAggregateYieldOperandTypes(func, contextualMapper); if (types.length === 0) { var iterableIteratorAny = createIterableIteratorType(anyType); if (compilerOptions.noImplicitAny) { @@ -21946,8 +21984,7 @@ var ts; } } else { - var hasImplicitReturn = !!(func.flags & 32768); - types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync, hasImplicitReturn); + types = checkAndAggregateReturnExpressionTypes(func, contextualMapper); if (!types) { return neverType; } @@ -21994,9 +22031,9 @@ var ts; return widenedType; } } - function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + function checkAndAggregateYieldOperandTypes(func, contextualMapper) { var aggregatedTypes = []; - ts.forEachYieldExpression(body, function (yieldExpression) { + ts.forEachYieldExpression(func.body, function (yieldExpression) { var expr = yieldExpression.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -22010,28 +22047,34 @@ var ts; }); return aggregatedTypes; } - function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync, hasImplicitReturn) { + function checkAndAggregateReturnExpressionTypes(func, contextualMapper) { + var isAsync = ts.isAsyncFunctionLike(func); var aggregatedTypes = []; - var hasOmittedExpressions = false; - ts.forEachReturnStatement(body, function (returnStatement) { + var hasReturnWithNoExpression = !!(func.flags & 32768); + var hasReturnOfTypeNever = false; + ts.forEachReturnStatement(func.body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); if (isAsync) { - type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); + type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } - if (type !== neverType && !ts.contains(aggregatedTypes, type)) { + if (type === neverType) { + hasReturnOfTypeNever = true; + } + else if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } } else { - hasOmittedExpressions = true; + hasReturnWithNoExpression = true; } }); - if (aggregatedTypes.length === 0 && !hasOmittedExpressions && !hasImplicitReturn) { + if (aggregatedTypes.length === 0 && !hasReturnWithNoExpression && (hasReturnOfTypeNever || + func.kind === 179 || func.kind === 180)) { return undefined; } - if (strictNullChecks && aggregatedTypes.length && (hasOmittedExpressions || hasImplicitReturn)) { + if (strictNullChecks && aggregatedTypes.length && hasReturnWithNoExpression) { if (!ts.contains(aggregatedTypes, undefinedType)) { aggregatedTypes.push(undefinedType); } @@ -22161,7 +22204,9 @@ var ts; (expr.kind === 172 || expr.kind === 173) && expr.expression.kind === 97) { var func = ts.getContainingFunction(expr); - return !(func && func.kind === 148 && func.parent === symbol.valueDeclaration.parent); + if (!(func && func.kind === 148)) + return true; + return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent); } return true; } @@ -22985,6 +23030,79 @@ var ts; } } } + function checkClassForDuplicateDeclarations(node) { + var getter = 1, setter = 2, property = getter | setter; + var instanceNames = {}; + var staticNames = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 148) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var param = _c[_b]; + if (ts.isParameterPropertyDeclaration(param)) { + addName(instanceNames, param.name, param.name.text, property); + } + } + } + else { + var static = ts.forEach(member.modifiers, function (m) { return m.kind === 113; }); + var names = static ? staticNames : instanceNames; + var memberName = member.name && ts.getPropertyNameForPropertyNameNode(member.name); + if (memberName) { + switch (member.kind) { + case 149: + addName(names, member.name, memberName, getter); + break; + case 150: + addName(names, member.name, memberName, setter); + break; + case 145: + addName(names, member.name, memberName, property); + break; + } + } + } + } + function addName(names, location, name, meaning) { + if (ts.hasProperty(names, name)) { + var prev = names[name]; + if (prev & meaning) { + error(location, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(location)); + } + else { + names[name] = prev | meaning; + } + } + else { + names[name] = meaning; + } + } + } + function checkObjectTypeForDuplicateDeclarations(node) { + var names = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind == 144) { + var memberName = void 0; + switch (member.name.kind) { + case 9: + case 8: + case 69: + memberName = member.name.text; + break; + default: + continue; + } + if (ts.hasProperty(names, memberName)) { + error(member.symbol.valueDeclaration.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + error(member.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + } + else { + names[memberName] = true; + } + } + } + } function checkTypeForDuplicateIndexSignatures(node) { if (node.kind === 222) { var nodeSymbol = getSymbolOfNode(node); @@ -23203,6 +23321,7 @@ var ts; var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); + checkObjectTypeForDuplicateDeclarations(node); } } function checkArrayType(node) { @@ -23962,6 +24081,10 @@ var ts; if (node.initializer) { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined); } + if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { + error(symbol.valueDeclaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + error(node.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + } } if (node.kind !== 145 && node.kind !== 144) { checkExportsOnMergedDeclarations(node); @@ -23974,6 +24097,18 @@ var ts; checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } + function areDeclarationFlagsIdentical(left, right) { + if (ts.hasQuestionToken(left) !== ts.hasQuestionToken(right)) { + return false; + } + var interestingFlags = 8 | + 16 | + 256 | + 128 | + 64 | + 32; + return (left.flags & interestingFlags) === (right.flags & interestingFlags); + } function checkVariableDeclaration(node) { checkGrammarVariableDeclaration(node); return checkVariableLikeDeclaration(node); @@ -24524,6 +24659,7 @@ var ts; var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); checkTypeParameterListsIdentical(node, symbol); + checkClassForDuplicateDeclarations(node); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { var baseTypes = getBaseTypes(type); @@ -24735,6 +24871,7 @@ var ts; checkIndexConstraints(type); } } + checkObjectTypeForDuplicateDeclarations(node); } ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) { if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) { @@ -25489,10 +25626,8 @@ var ts; function checkSourceFileWorker(node) { var links = getNodeLinks(node); if (!(links.flags & 1)) { - if (compilerOptions.skipDefaultLibCheck) { - if (node.hasNoDefaultLib) { - return; - } + if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) { + return; } checkGrammarSourceFile(node); potentialThisCollisions.length = 0; @@ -25861,7 +25996,7 @@ var ts; return symbol && getTypeOfSymbol(symbol); } if (ts.isBindingPattern(node)) { - return getTypeForVariableLikeDeclaration(node.parent); + return getTypeForVariableLikeDeclaration(node.parent, true); } if (isInRightSideOfImportOrExportAssignment(node)) { var symbol = getSymbolAtLocation(node); @@ -26300,7 +26435,7 @@ var ts; if (file.moduleAugmentations.length) { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } - if (file.wasReferenced && file.symbol && file.symbol.globalExports) { + if (file.symbol && file.symbol.globalExports) { mergeSymbolTable(globals, file.symbol.globalExports); } }); @@ -26870,7 +27005,6 @@ var ts; if (prop.kind === 193 || name_20.kind === 140) { checkGrammarComputedPropertyName(name_20); - return "continue"; } if (prop.kind === 254 && !inDestructuring && prop.objectAssignmentInitializer) { return { value: grammarErrorOnNode(prop.equalsToken, ts.Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment) }; @@ -26900,17 +27034,21 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_20.text)) { - seen[name_20.text] = currentKind; + var effectiveName = ts.getPropertyNameForPropertyNameNode(name_20); + if (effectiveName === undefined) { + return "continue"; + } + if (!ts.hasProperty(seen, effectiveName)) { + seen[effectiveName] = currentKind; } else { - var existingKind = seen[name_20.text]; + var existingKind = seen[effectiveName]; if (currentKind === Property && existingKind === Property) { - return "continue"; + grammarErrorOnNode(name_20, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name_20)); } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_20.text] = currentKind | existingKind; + seen[effectiveName] = currentKind | existingKind; } else { return { value: grammarErrorOnNode(name_20, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name) }; @@ -35367,7 +35505,7 @@ var ts; skipTsx: true, traceEnabled: traceEnabled }; - var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : undefined); + var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : (host.getCurrentDirectory && host.getCurrentDirectory())); if (traceEnabled) { if (containingFile === undefined) { if (rootDir === undefined) { @@ -35870,12 +36008,25 @@ var ts; } } } + function getDefaultTypeDirectiveNames(rootPath) { + var localTypes = ts.combinePaths(rootPath, "types"); + var npmTypes = ts.combinePaths(rootPath, "node_modules/@types"); + var result = []; + if (ts.sys.directoryExists(localTypes)) { + result = result.concat(ts.sys.getDirectories(localTypes)); + } + if (ts.sys.directoryExists(npmTypes)) { + result = result.concat(ts.sys.getDirectories(npmTypes)); + } + return result; + } function getDefaultLibLocation() { return ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())); } var newLine = ts.getNewLineCharacter(options); var realpath = ts.sys.realpath && (function (path) { return ts.sys.realpath(path); }); return { + getDefaultTypeDirectiveNames: getDefaultTypeDirectiveNames, getSourceFile: getSourceFile, getDefaultLibLocation: getDefaultLibLocation, getDefaultLibFileName: function (options) { return ts.combinePaths(getDefaultLibLocation(), ts.getDefaultLibFileName(options)); }, @@ -35943,6 +36094,19 @@ var ts; } return resolutions; } + function getDefaultTypeDirectiveNames(options, rootFiles, host) { + if (options.types) { + return options.types; + } + if (host && host.getDefaultTypeDirectiveNames) { + var commonRoot = computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), function (f) { return host.getCanonicalFileName(f); }); + if (commonRoot) { + return host.getDefaultTypeDirectiveNames(commonRoot); + } + } + return undefined; + } + ts.getDefaultTypeDirectiveNames = getDefaultTypeDirectiveNames; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; @@ -35978,13 +36142,14 @@ var ts; var filesByName = ts.createFileMap(); var filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? ts.createFileMap(function (fileName) { return fileName.toLowerCase(); }) : undefined; if (!tryReuseStructureFromOldProgram()) { - if (options.types && options.types.length) { - var resolutions = resolveTypeReferenceDirectiveNamesWorker(options.types, undefined); - for (var i = 0; i < options.types.length; i++) { - processTypeReferenceDirective(options.types[i], resolutions[i]); + ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); + var typeReferences = getDefaultTypeDirectiveNames(options, rootNames, host); + if (typeReferences) { + var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, undefined); + for (var i = 0; i < typeReferences.length; i++) { + processTypeReferenceDirective(typeReferences[i], resolutions[i]); } } - ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); if (!skipDefaultLib) { if (!options.lib) { processRootFile(host.getDefaultLibFileName(options), true); @@ -36561,9 +36726,6 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1) { - file_1.wasReferenced = file_1.wasReferenced || isReference; - } return file_1; } var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { @@ -36576,7 +36738,6 @@ var ts; }); filesByName.set(path, file); if (file) { - file.wasReferenced = file.wasReferenced || isReference; file.path = path; if (host.useCaseSensitiveFileNames()) { var existingFile = filesByNameIgnoreCase.get(path); @@ -36677,17 +36838,7 @@ var ts; !options.noResolve && i < file.imports.length; if (shouldAddFile) { - var importedFile = findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); - if (importedFile && resolution.isExternalLibraryImport) { - if (!ts.isExternalModule(importedFile) && importedFile.statements.length) { - var start_5 = ts.getTokenPosOfNode(file.imports[i], file); - fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_5, file.imports[i].end - start_5, ts.Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); - } - else if (importedFile.referencedFiles.length) { - var firstRef = importedFile.referencedFiles[0]; - fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); - } - } + findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } } } @@ -36772,7 +36923,7 @@ var ts; } } else { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substututions_for_pattern_0_should_be_an_array, key)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substitutions_for_pattern_0_should_be_an_array, key)); } } } @@ -36821,13 +36972,19 @@ var ts; } else if (firstExternalModuleSourceFile && languageVersion < 2 && options.module === ts.ModuleKind.None) { var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); } if (options.module === ts.ModuleKind.ES6 && languageVersion < 2) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es2015_when_targeting_ES5_or_lower)); } - if (outFile && options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + if (outFile) { + if (options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + } + else if (options.module === undefined && firstExternalModuleSourceFile) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); + } } if (options.outDir || options.sourceRoot || @@ -37517,7 +37674,7 @@ var ts; (function (ts) { var NavigateTo; (function (NavigateTo) { - function getNavigateToItems(program, cancellationToken, searchValue, maxResultCount) { + function getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount) { var patternMatcher = ts.createPatternMatcher(searchValue); var rawItems = []; var baseSensitivity = { sensitivity: "base" }; @@ -37550,6 +37707,17 @@ var ts; } } }); + rawItems = ts.filter(rawItems, function (item) { + var decl = item.declaration; + if (decl.kind === 231 || decl.kind === 234 || decl.kind === 229) { + var importer = checker.getSymbolAtLocation(decl.name); + var imported = checker.getAliasedSymbol(importer); + return importer.name !== imported.name; + } + else { + return true; + } + }); rawItems.sort(compareNavigateToItems); if (maxResultCount !== undefined) { rawItems = rawItems.slice(0, maxResultCount); @@ -37892,8 +38060,12 @@ var ts; return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); case 153: return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); + case 224: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.enumElement); case 255: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 222: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.interfaceElement); case 151: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); case 152: @@ -39263,7 +39435,7 @@ var ts; } } function findRightmostChildNodeWithTokens(children, exclusiveStartPosition) { - for (var i = exclusiveStartPosition - 1; i >= 0; --i) { + for (var i = exclusiveStartPosition - 1; i >= 0; i--) { if (nodeHasTokens(children[i])) { return children[i]; } @@ -39889,18 +40061,17 @@ var ts; if (!isStarted) { scanner.scan(); } - var t; var pos = scanner.getStartPos(); while (pos < endPos) { - var t_1 = scanner.getToken(); - if (!ts.isTrivia(t_1)) { + var t = scanner.getToken(); + if (!ts.isTrivia(t)) { break; } scanner.scan(); var item = { pos: pos, end: scanner.getStartPos(), - kind: t_1 + kind: t }; pos = scanner.getStartPos(); if (!leadingTrivia) { @@ -41550,7 +41721,7 @@ var ts; else { parts = []; var startPos = commentRange.pos; - for (var line = startLine; line < endLine; ++line) { + for (var line = startLine; line < endLine; line++) { var endOfLine = ts.getEndLinePosition(line, sourceFile); parts.push({ pos: startPos, end: endOfLine }); startPos = ts.getStartPositionOfLine(line + 1, sourceFile); @@ -41568,7 +41739,7 @@ var ts; startLine++; } var delta = indentation - nonWhitespaceColumnInFirstPart.column; - for (var i = startIndex, len = parts.length; i < len; ++i, ++startLine) { + for (var i = startIndex, len = parts.length; i < len; i++, startLine++) { var startLinePos_1 = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart @@ -41584,7 +41755,7 @@ var ts; } } function trimTrailingWhitespacesForLines(line1, line2, range) { - for (var line = line1; line < line2; ++line) { + for (var line = line1; line < line2; line++) { var lineStartPosition = ts.getStartPositionOfLine(line, sourceFile); var lineEndPosition = ts.getEndLinePosition(line, sourceFile); if (range && (ts.isComment(range.kind) || ts.isStringOrRegularExpressionOrTemplateLiteral(range.kind)) && range.pos <= lineEndPosition && range.end > lineEndPosition) { @@ -41627,7 +41798,6 @@ var ts; } } function applyRuleEdits(rule, previousRange, previousStartLine, currentRange, currentStartLine) { - var between; switch (rule.Operation.Action) { case 1: return; @@ -41657,14 +41827,6 @@ var ts; } } } - function isSomeBlock(kind) { - switch (kind) { - case 199: - case 226: - return true; - } - return false; - } function getOpenTokenForList(node, list) { switch (node.kind) { case 148: @@ -41722,7 +41884,7 @@ var ts; internedTabsIndentation = []; } if (internedTabsIndentation[tabs] === undefined) { - internedTabsIndentation[tabs] = tabString = repeat('\t', tabs); + internedTabsIndentation[tabs] = tabString = repeat("\t", tabs); } else { tabString = internedTabsIndentation[tabs]; @@ -41747,7 +41909,7 @@ var ts; } function repeat(value, count) { var s = ""; - for (var i = 0; i < count; ++i) { + for (var i = 0; i < count; i++) { s += value; } return s; @@ -42015,7 +42177,7 @@ var ts; ts.Debug.assert(index >= 0 && index < list.length); var node = list[index]; var lineAndCharacter = getStartLineAndCharacterForNode(node, sourceFile); - for (var i = index - 1; i >= 0; --i) { + for (var i = index - 1; i >= 0; i--) { if (list[i].kind === 24) { continue; } @@ -42034,7 +42196,7 @@ var ts; function findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options) { var character = 0; var column = 0; - for (var pos = startPos; pos < endPos; ++pos) { + for (var pos = startPos; pos < endPos; pos++) { var ch = sourceFile.text.charCodeAt(pos); if (!ts.isWhiteSpace(ch)) { break; @@ -44005,9 +44167,9 @@ var ts; log("getCompletionData: Get previous token 1: " + (new Date().getTime() - start)); var contextToken = previousToken; if (contextToken && position <= contextToken.end && ts.isWord(contextToken.kind)) { - var start_6 = new Date().getTime(); + var start_5 = new Date().getTime(); contextToken = ts.findPrecedingToken(contextToken.getFullStart(), sourceFile); - log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_6)); + log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_5)); } var node = currentToken; var isRightOfDot = false; @@ -44234,9 +44396,9 @@ var ts; || contextToken.kind === 166 || contextToken.kind === 10 || ts.isTemplateLiteralKind(contextToken.kind)) { - var start_7 = contextToken.getStart(); + var start_6 = contextToken.getStart(); var end = contextToken.getEnd(); - if (start_7 < position && position < end) { + if (start_6 < position && position < end) { return true; } if (position === end) { @@ -45314,8 +45476,7 @@ var ts; } function getDocumentHighlights(fileName, position, filesToSearch) { synchronizeHostData(); - filesToSearch = ts.map(filesToSearch, ts.normalizeSlashes); - var sourceFilesToSearch = ts.filter(program.getSourceFiles(), function (f) { return ts.contains(filesToSearch, f.fileName); }); + var sourceFilesToSearch = ts.map(filesToSearch, function (f) { return program.getSourceFile(f); }); var sourceFile = getValidSourceFile(fileName); var node = ts.getTouchingWord(sourceFile, position); if (!node) { @@ -46498,7 +46659,8 @@ var ts; } function getNavigateToItems(searchValue, maxResultCount) { synchronizeHostData(); - return ts.NavigateTo.getNavigateToItems(program, cancellationToken, searchValue, maxResultCount); + var checker = getProgram().getTypeChecker(); + return ts.NavigateTo.getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount); } function getEmitOutput(fileName) { synchronizeHostData(); @@ -51195,6 +51357,9 @@ var ts; LanguageServiceShimHostAdapter.prototype.getCurrentDirectory = function () { return this.shimHost.getCurrentDirectory(); }; + LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { + return this.shimHost.getDirectories(path); + }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); }; diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index 0629ad983a3..76b66dda93b 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -247,7 +247,7 @@ declare namespace ts { ModuleDeclaration = 225, ModuleBlock = 226, CaseBlock = 227, - GlobalModuleExportDeclaration = 228, + NamespaceExportDeclaration = 228, ImportEqualsDeclaration = 229, ImportDeclaration = 230, ImportClause = 231, @@ -925,7 +925,7 @@ declare namespace ts { interface NamespaceImport extends Declaration { name: Identifier; } - interface GlobalModuleExportDeclaration extends DeclarationStatement { + interface NamespaceExportDeclaration extends DeclarationStatement { name: Identifier; moduleReference: LiteralLikeNode; } @@ -1087,7 +1087,6 @@ declare namespace ts { scriptKind: ScriptKind; externalModuleIndicator: Node; commonJsModuleIndicator: Node; - wasReferenced?: boolean; identifiers: Map; nodeCount: number; identifierCount: number; @@ -1381,7 +1380,7 @@ declare namespace ts { FunctionScopedVariableExcludes = 107454, BlockScopedVariableExcludes = 107455, ParameterExcludes = 107455, - PropertyExcludes = 107455, + PropertyExcludes = 0, EnumMemberExcludes = 107455, FunctionExcludes = 106927, ClassExcludes = 899519, @@ -1735,6 +1734,7 @@ declare namespace ts { allowJs?: boolean; noImplicitUseStrict?: boolean; strictNullChecks?: boolean; + skipLibCheck?: boolean; listEmittedFiles?: boolean; lib?: string[]; stripInternal?: boolean; @@ -1967,6 +1967,7 @@ declare namespace ts { trace?(s: string): void; directoryExists?(directoryName: string): boolean; realpath?(path: string): string; + getCurrentDirectory?(): string; } interface ResolvedModule { resolvedFileName: string; @@ -1990,6 +1991,7 @@ declare namespace ts { getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; + getDefaultTypeDirectiveNames?(rootPath: string): string[]; writeFile: WriteFileCallback; getCurrentDirectory(): string; getCanonicalFileName(fileName: string): string; @@ -2136,6 +2138,7 @@ declare namespace ts { createDirectory(path: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; + getDirectories(path: string): string[]; readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getModifiedTime?(path: string): Date; createHash?(data: string): string; @@ -2820,7 +2823,7 @@ declare namespace ts { key: string; message: string; }; - Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file: { + Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: { code: number; category: DiagnosticCategory; key: string; @@ -5040,6 +5043,18 @@ declare namespace ts { key: string; message: string; }; + Identifier_0_must_be_imported_from_a_module: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; + All_declarations_of_0_must_have_identical_modifiers: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; Import_declaration_0_is_using_private_name_1: { code: number; category: DiagnosticCategory; @@ -5598,7 +5613,7 @@ declare namespace ts { key: string; message: string; }; - Substututions_for_pattern_0_should_be_an_array: { + Substitutions_for_pattern_0_should_be_an_array: { code: number; category: DiagnosticCategory; key: string; @@ -5676,6 +5691,12 @@ declare namespace ts { key: string; message: string; }; + Skip_type_checking_of_declaration_files: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015: { code: number; category: DiagnosticCategory; @@ -6282,6 +6303,12 @@ declare namespace ts { key: string; message: string; }; + Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; Variable_0_implicitly_has_an_1_type: { code: number; category: DiagnosticCategory; @@ -7024,6 +7051,7 @@ declare namespace ts { function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; + function getDefaultTypeDirectiveNames(options: CompilerOptions, rootFiles: string[], host: CompilerHost): string[]; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program; } declare namespace ts.BreakpointResolver { @@ -7033,7 +7061,7 @@ declare namespace ts.OutliningElementsCollector { function collectElements(sourceFile: SourceFile): OutliningSpan[]; } declare namespace ts.NavigateTo { - function getNavigateToItems(program: Program, cancellationToken: CancellationToken, searchValue: string, maxResultCount: number): NavigateToItem[]; + function getNavigateToItems(program: Program, checker: TypeChecker, cancellationToken: CancellationToken, searchValue: string, maxResultCount: number): NavigateToItem[]; } declare namespace ts.NavigationBar { function getNavigationBarItems(sourceFile: SourceFile, compilerOptions: CompilerOptions): ts.NavigationBarItem[]; @@ -7431,7 +7459,7 @@ declare namespace ts.formatting { } } declare namespace ts.formatting { - module Shared { + namespace Shared { interface ITokenAccess { GetTokens(): SyntaxKind[]; Contains(token: SyntaxKind): boolean; @@ -7516,7 +7544,7 @@ declare namespace ts.formatting { function getIndentationString(indentation: number, options: FormatCodeOptions): string; } declare namespace ts.formatting { - module SmartIndenter { + namespace SmartIndenter { function getIndentation(position: number, sourceFile: SourceFile, options: EditorOptions): number; function getIndentationForNode(n: Node, ignoreActualIndentationRange: TextRange, sourceFile: SourceFile, options: FormatCodeOptions): number; function childStartsOnTheSameLineWithElseInIfStatement(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFile): boolean; @@ -8487,6 +8515,7 @@ declare namespace ts { getLocalizedDiagnosticMessages(): string; getCancellationToken(): HostCancellationToken; getCurrentDirectory(): string; + getDirectories(path: string): string[]; getDefaultLibFileName(options: string): string; getNewLine?(): string; getProjectVersion?(): string; @@ -8582,6 +8611,7 @@ declare namespace ts { getLocalizedDiagnosticMessages(): any; getCancellationToken(): HostCancellationToken; getCurrentDirectory(): string; + getDirectories(path: string): string[]; getDefaultLibFileName(options: CompilerOptions): string; } class CoreServicesShimHostAdapter implements ParseConfigHost, ModuleResolutionHost { diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 050d9ca265d..902bfcf610e 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -918,6 +918,10 @@ var ts; } return result.sort(); } + function getDirectories(path) { + var folder = fso.GetFolder(path); + return getNames(folder.subfolders); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -972,6 +976,7 @@ var ts; getCurrentDirectory: function () { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + getDirectories: getDirectories, readDirectory: readDirectory, exit: function (exitCode) { try { @@ -1119,6 +1124,9 @@ var ts; function directoryExists(path) { return fileSystemEntryExists(path, 1); } + function getDirectories(path) { + return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1); }); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -1211,6 +1219,7 @@ var ts; getCurrentDirectory: function () { return process.cwd(); }, + getDirectories: getDirectories, readDirectory: readDirectory, getModifiedTime: function (path) { try { @@ -1261,6 +1270,7 @@ var ts; createDirectory: ChakraHost.createDirectory, getExecutingFilePath: function () { return ChakraHost.executingFile; }, getCurrentDirectory: function () { return ChakraHost.currentDirectory; }, + getDirectories: ChakraHost.getDirectories, readDirectory: ChakraHost.readDirectory, exit: ChakraHost.quit, realpath: realpath @@ -1394,7 +1404,7 @@ var ts; or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "or_expected_1144", message: "'{' or ';' expected." }, Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration_expected_1146", message: "Declaration expected." }, Import_declarations_in_a_namespace_cannot_reference_a_module: { code: 1147, category: ts.DiagnosticCategory.Error, key: "Import_declarations_in_a_namespace_cannot_reference_a_module_1147", message: "Import declarations in a namespace cannot reference a module." }, - Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting__1148", message: "Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file." }, + Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_use_imports_exports_or_module_augmentations_when_module_is_none_1148", message: "Cannot use imports, exports, or module augmentations when '--module' is 'none'." }, File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: ts.DiagnosticCategory.Error, key: "File_name_0_differs_from_already_included_file_name_1_only_in_casing_1149", message: "File name '{0}' differs from already included file name '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: ts.DiagnosticCategory.Error, key: "new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead_1150", message: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "const_declarations_must_be_initialized_1155", message: "'const' declarations must be initialized" }, @@ -1764,6 +1774,8 @@ var ts; this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation: { code: 2683, category: ts.DiagnosticCategory.Error, key: "this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_2683", message: "'this' implicitly has type 'any' because it does not have a type annotation." }, The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1: { code: 2684, category: ts.DiagnosticCategory.Error, key: "The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1_2684", message: "The 'this' context of type '{0}' is not assignable to method's 'this' of type '{1}'." }, The_this_types_of_each_signature_are_incompatible: { code: 2685, category: ts.DiagnosticCategory.Error, key: "The_this_types_of_each_signature_are_incompatible_2685", message: "The 'this' types of each signature are incompatible." }, + Identifier_0_must_be_imported_from_a_module: { code: 2686, category: ts.DiagnosticCategory.Error, key: "Identifier_0_must_be_imported_from_a_module_2686", message: "Identifier '{0}' must be imported from a module" }, + All_declarations_of_0_must_have_identical_modifiers: { code: 2687, category: ts.DiagnosticCategory.Error, key: "All_declarations_of_0_must_have_identical_modifiers_2687", message: "All declarations of '{0}' must have identical modifiers." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import_declaration_0_is_using_private_name_1_4000", message: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", message: "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: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", message: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1857,7 +1869,7 @@ var ts; Option_paths_cannot_be_used_without_specifying_baseUrl_option: { code: 5060, category: ts.DiagnosticCategory.Error, key: "Option_paths_cannot_be_used_without_specifying_baseUrl_option_5060", message: "Option 'paths' cannot be used without specifying '--baseUrl' option." }, Pattern_0_can_have_at_most_one_Asterisk_character: { code: 5061, category: ts.DiagnosticCategory.Error, key: "Pattern_0_can_have_at_most_one_Asterisk_character_5061", message: "Pattern '{0}' can have at most one '*' character" }, Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character: { code: 5062, category: ts.DiagnosticCategory.Error, key: "Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character_5062", message: "Substitution '{0}' in pattern '{1}' in can have at most one '*' character" }, - Substututions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substututions_for_pattern_0_should_be_an_array_5063", message: "Substututions for pattern '{0}' should be an array." }, + Substitutions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substitutions_for_pattern_0_should_be_an_array_5063", message: "Substitutions for pattern '{0}' should be an array." }, Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2: { code: 5064, category: ts.DiagnosticCategory.Error, key: "Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2_5064", message: "Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate_and_emit_output_to_single_file_6001", message: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates_corresponding_d_ts_file_6002", message: "Generates corresponding '.d.ts' file." }, @@ -1870,6 +1882,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_comments_to_output_6009", message: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_outputs_6010", message: "Do not emit outputs." }, Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking: { code: 6011, category: ts.DiagnosticCategory.Message, key: "Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typech_6011", message: "Allow default imports from modules with no default export. This does not affect code emit, just typechecking." }, + Skip_type_checking_of_declaration_files: { code: 6012, category: ts.DiagnosticCategory.Message, key: "Skip_type_checking_of_declaration_files_6012", message: "Skip type checking of declaration files." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015_6015", message: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'" }, Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015_6016", message: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print_this_message_6017", message: "Print this message." }, @@ -1971,6 +1984,7 @@ var ts; Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set: { code: 6128, category: ts.DiagnosticCategory.Message, key: "Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set_6128", message: "======== Resolving type reference directive '{0}', containing file not set, root directory not set. ========" }, The_config_file_0_found_doesn_t_contain_any_source_files: { code: 6129, category: ts.DiagnosticCategory.Error, key: "The_config_file_0_found_doesn_t_contain_any_source_files_6129", message: "The config file '{0}' found doesn't contain any source files." }, Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, + Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -3537,6 +3551,11 @@ var ts; type: "boolean", description: ts.Diagnostics.Print_this_message }, + { + name: "help", + shortName: "?", + type: "boolean" + }, { name: "init", type: "boolean", @@ -3639,6 +3658,11 @@ var ts; name: "skipDefaultLibCheck", type: "boolean" }, + { + name: "skipLibCheck", + type: "boolean", + description: ts.Diagnostics.Skip_type_checking_of_declaration_files + }, { name: "out", type: "string", @@ -5758,7 +5782,7 @@ var ts; } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 69 || name.kind === 9 || name.kind === 8) { + if (name.kind === 69 || name.kind === 9 || name.kind === 8 || name.kind === 142) { return name.text; } if (name.kind === 140) { @@ -12804,10 +12828,10 @@ var ts; case 145: case 144: case 266: - return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455); + return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 0); case 253: case 254: - return bindPropertyOrMethodOrAccessor(node, 4, 107455); + return bindPropertyOrMethodOrAccessor(node, 4, 0); case 255: return bindPropertyOrMethodOrAccessor(node, 8, 107455); case 247: @@ -12819,7 +12843,7 @@ var ts; return declareSymbolAndAddToSymbolTable(node, 131072, 0); case 147: case 146: - return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263); + return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 0 : 99263); case 220: return bindFunctionDeclaration(node); case 148: @@ -12862,7 +12886,7 @@ var ts; case 238: return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); case 228: - return bindGlobalModuleExportDeclaration(node); + return bindNamespaceExportDeclaration(node); case 231: return bindImportClause(node); case 236: @@ -12898,13 +12922,13 @@ var ts; bindAnonymousDeclaration(node, 8388608, getDeclarationName(node)); } else if (boundExpression.kind === 69 && node.kind === 235) { - declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608); + declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 0 | 8388608); } else { - declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608); + declareSymbol(container.symbol.exports, container.symbol, node, 4, 0 | 8388608); } } - function bindGlobalModuleExportDeclaration(node) { + function bindNamespaceExportDeclaration(node) { if (node.modifiers && node.modifiers.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Modifiers_cannot_appear_here)); } @@ -12956,7 +12980,7 @@ var ts; function bindThisPropertyAssignment(node) { if (container.kind === 179 || container.kind === 220) { container.symbol.members = container.symbol.members || {}; - declareSymbol(container.symbol.members, container.symbol, node, 4, 107455 & ~4); + declareSymbol(container.symbol.members, container.symbol, node, 4, 0 & ~4); } } function bindPrototypePropertyAssignment(node) { @@ -12973,7 +12997,7 @@ var ts; if (!funcSymbol.members) { funcSymbol.members = {}; } - declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4, 107455); + declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4, 0); } function bindCallExpression(node) { if (!file.commonJsModuleIndicator && ts.isRequireCall(node, false)) { @@ -13049,7 +13073,7 @@ var ts; } if (ts.isParameterPropertyDeclaration(node)) { var classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 0); } } function bindFunctionDeclaration(node) { @@ -13349,7 +13373,7 @@ var ts; if (flags & 1) result |= 107454; if (flags & 4) - result |= 107455; + result |= 0; if (flags & 8) result |= 107455; if (flags & 16) @@ -13605,6 +13629,7 @@ var ts; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; + var isInExternalModule = false; loop: while (location) { if (location.locals && !isGlobalSourceFile(location)) { if (result = getSymbol(location.locals, name, meaning)) { @@ -13636,6 +13661,7 @@ var ts; case 256: if (!ts.isExternalOrCommonJsModule(location)) break; + isInExternalModule = true; case 225: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 256 || ts.isAmbientModule(location)) { @@ -13759,6 +13785,12 @@ var ts; checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); } } + if (result && isInExternalModule) { + var decls = result.declarations; + if (decls && decls.length === 1 && decls[0].kind === 228) { + error(errorLocation, ts.Diagnostics.Identifier_0_must_be_imported_from_a_module, name); + } + } } return result; } @@ -15234,7 +15266,7 @@ var ts; } function getTypeForBindingElementParent(node) { var symbol = getSymbolOfNode(node); - return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, false); } function getTextOfPropertyName(name) { switch (name.kind) { @@ -15339,7 +15371,7 @@ var ts; function addOptionality(type, optional) { return strictNullChecks && optional ? addNullableKind(type, 32) : type; } - function getTypeForVariableLikeDeclaration(declaration) { + function getTypeForVariableLikeDeclaration(declaration, includeOptionality) { if (declaration.flags & 134217728) { var type = getTypeForVariableLikeDeclarationFromJSDocComment(declaration); if (type && type !== unknownType) { @@ -15356,7 +15388,7 @@ var ts; return getTypeForBindingElement(declaration); } if (declaration.type) { - return addOptionality(getTypeFromTypeNode(declaration.type), !!declaration.questionToken); + return addOptionality(getTypeFromTypeNode(declaration.type), declaration.questionToken && includeOptionality); } if (declaration.kind === 142) { var func = declaration.parent; @@ -15375,11 +15407,11 @@ var ts; ? getContextuallyTypedThisType(func) : getContextuallyTypedParameterType(declaration); if (type) { - return addOptionality(type, !!declaration.questionToken); + return addOptionality(type, declaration.questionToken && includeOptionality); } } if (declaration.initializer) { - return addOptionality(checkExpressionCached(declaration.initializer), !!declaration.questionToken); + return addOptionality(checkExpressionCached(declaration.initializer), declaration.questionToken && includeOptionality); } if (declaration.kind === 254) { return checkIdentifier(declaration.name); @@ -15447,7 +15479,7 @@ var ts; : getTypeFromArrayBindingPattern(pattern, includePatternInType); } function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { - var type = getTypeForVariableLikeDeclaration(declaration); + var type = getTypeForVariableLikeDeclaration(declaration, true); if (type) { if (reportErrors) { reportErrorsFromWidening(declaration, type); @@ -17764,7 +17796,7 @@ var ts; return isIdenticalTo(source, target); } if (!(target.flags & 134217728)) { - if (target.flags & 1) + if (target.flags & 1 || source.flags & 134217728) return -1; if (source.flags & 32) { if (!strictNullChecks || target.flags & (32 | 16) || source === emptyArrayElementType) @@ -17784,7 +17816,7 @@ var ts; if (source.flags & 256 && target === stringType) return -1; if (relation === assignableRelation || relation === comparableRelation) { - if (source.flags & (1 | 134217728)) + if (source.flags & 1) return -1; if (source === numberType && target.flags & 128) return -1; @@ -18561,41 +18593,47 @@ var ts; getSignaturesOfType(type, 0).length === 0 && getSignaturesOfType(type, 1).length === 0; } + function createTransientSymbol(source, type) { + var symbol = createSymbol(source.flags | 67108864, source.name); + symbol.declarations = source.declarations; + symbol.parent = source.parent; + symbol.type = type; + symbol.target = source; + if (source.valueDeclaration) { + symbol.valueDeclaration = source.valueDeclaration; + } + return symbol; + } + function transformTypeOfMembers(type, f) { + var members = {}; + for (var _i = 0, _a = getPropertiesOfObjectType(type); _i < _a.length; _i++) { + var property = _a[_i]; + var original = getTypeOfSymbol(property); + var updated = f(original); + members[property.name] = updated === original ? property : createTransientSymbol(property, updated); + } + ; + return members; + } function getRegularTypeOfObjectLiteral(type) { - if (type.flags & 1048576) { - var regularType = type.regularType; - if (!regularType) { - regularType = createType(type.flags & ~1048576); - regularType.symbol = type.symbol; - regularType.members = type.members; - regularType.properties = type.properties; - regularType.callSignatures = type.callSignatures; - regularType.constructSignatures = type.constructSignatures; - regularType.stringIndexInfo = type.stringIndexInfo; - regularType.numberIndexInfo = type.numberIndexInfo; - type.regularType = regularType; - } + if (!(type.flags & 1048576)) { + return type; + } + var regularType = type.regularType; + if (regularType) { return regularType; } - return type; + var resolved = type; + var members = transformTypeOfMembers(type, getRegularTypeOfObjectLiteral); + var regularNew = createAnonymousType(resolved.symbol, members, resolved.callSignatures, resolved.constructSignatures, resolved.stringIndexInfo, resolved.numberIndexInfo); + regularNew.flags = resolved.flags & ~1048576; + type.regularType = regularNew; + return regularNew; } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfObjectType(type); - var members = {}; - ts.forEach(properties, function (p) { - var propType = getTypeOfSymbol(p); - var widenedType = getWidenedType(propType); - if (propType !== widenedType) { - var symbol = createSymbol(p.flags | 67108864, 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 members = transformTypeOfMembers(type, function (prop) { + var widened = getWidenedType(prop); + return prop === widened ? prop : widened; }); var stringIndexInfo = getIndexInfoOfType(type, 0); var numberIndexInfo = getIndexInfoOfType(type, 1); @@ -19888,7 +19926,7 @@ var ts; } return nodeCheckFlag === 512 ? getBaseConstructorTypeOfClass(classType) - : baseClassType; + : getTypeWithThisArgument(baseClassType, classType.thisType); function isLegalUsageOfSuperExpression(container) { if (!container) { return false; @@ -21936,7 +21974,7 @@ var ts; var types = void 0; var funcIsGenerator = !!func.asteriskToken; if (funcIsGenerator) { - types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + types = checkAndAggregateYieldOperandTypes(func, contextualMapper); if (types.length === 0) { var iterableIteratorAny = createIterableIteratorType(anyType); if (compilerOptions.noImplicitAny) { @@ -21946,8 +21984,7 @@ var ts; } } else { - var hasImplicitReturn = !!(func.flags & 32768); - types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync, hasImplicitReturn); + types = checkAndAggregateReturnExpressionTypes(func, contextualMapper); if (!types) { return neverType; } @@ -21994,9 +22031,9 @@ var ts; return widenedType; } } - function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + function checkAndAggregateYieldOperandTypes(func, contextualMapper) { var aggregatedTypes = []; - ts.forEachYieldExpression(body, function (yieldExpression) { + ts.forEachYieldExpression(func.body, function (yieldExpression) { var expr = yieldExpression.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -22010,28 +22047,34 @@ var ts; }); return aggregatedTypes; } - function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync, hasImplicitReturn) { + function checkAndAggregateReturnExpressionTypes(func, contextualMapper) { + var isAsync = ts.isAsyncFunctionLike(func); var aggregatedTypes = []; - var hasOmittedExpressions = false; - ts.forEachReturnStatement(body, function (returnStatement) { + var hasReturnWithNoExpression = !!(func.flags & 32768); + var hasReturnOfTypeNever = false; + ts.forEachReturnStatement(func.body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); if (isAsync) { - type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); + type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } - if (type !== neverType && !ts.contains(aggregatedTypes, type)) { + if (type === neverType) { + hasReturnOfTypeNever = true; + } + else if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } } else { - hasOmittedExpressions = true; + hasReturnWithNoExpression = true; } }); - if (aggregatedTypes.length === 0 && !hasOmittedExpressions && !hasImplicitReturn) { + if (aggregatedTypes.length === 0 && !hasReturnWithNoExpression && (hasReturnOfTypeNever || + func.kind === 179 || func.kind === 180)) { return undefined; } - if (strictNullChecks && aggregatedTypes.length && (hasOmittedExpressions || hasImplicitReturn)) { + if (strictNullChecks && aggregatedTypes.length && hasReturnWithNoExpression) { if (!ts.contains(aggregatedTypes, undefinedType)) { aggregatedTypes.push(undefinedType); } @@ -22161,7 +22204,9 @@ var ts; (expr.kind === 172 || expr.kind === 173) && expr.expression.kind === 97) { var func = ts.getContainingFunction(expr); - return !(func && func.kind === 148 && func.parent === symbol.valueDeclaration.parent); + if (!(func && func.kind === 148)) + return true; + return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent); } return true; } @@ -22985,6 +23030,79 @@ var ts; } } } + function checkClassForDuplicateDeclarations(node) { + var getter = 1, setter = 2, property = getter | setter; + var instanceNames = {}; + var staticNames = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 148) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var param = _c[_b]; + if (ts.isParameterPropertyDeclaration(param)) { + addName(instanceNames, param.name, param.name.text, property); + } + } + } + else { + var static = ts.forEach(member.modifiers, function (m) { return m.kind === 113; }); + var names = static ? staticNames : instanceNames; + var memberName = member.name && ts.getPropertyNameForPropertyNameNode(member.name); + if (memberName) { + switch (member.kind) { + case 149: + addName(names, member.name, memberName, getter); + break; + case 150: + addName(names, member.name, memberName, setter); + break; + case 145: + addName(names, member.name, memberName, property); + break; + } + } + } + } + function addName(names, location, name, meaning) { + if (ts.hasProperty(names, name)) { + var prev = names[name]; + if (prev & meaning) { + error(location, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(location)); + } + else { + names[name] = prev | meaning; + } + } + else { + names[name] = meaning; + } + } + } + function checkObjectTypeForDuplicateDeclarations(node) { + var names = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind == 144) { + var memberName = void 0; + switch (member.name.kind) { + case 9: + case 8: + case 69: + memberName = member.name.text; + break; + default: + continue; + } + if (ts.hasProperty(names, memberName)) { + error(member.symbol.valueDeclaration.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + error(member.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + } + else { + names[memberName] = true; + } + } + } + } function checkTypeForDuplicateIndexSignatures(node) { if (node.kind === 222) { var nodeSymbol = getSymbolOfNode(node); @@ -23203,6 +23321,7 @@ var ts; var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); + checkObjectTypeForDuplicateDeclarations(node); } } function checkArrayType(node) { @@ -23962,6 +24081,10 @@ var ts; if (node.initializer) { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, undefined); } + if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { + error(symbol.valueDeclaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + error(node.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + } } if (node.kind !== 145 && node.kind !== 144) { checkExportsOnMergedDeclarations(node); @@ -23974,6 +24097,18 @@ var ts; checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } + function areDeclarationFlagsIdentical(left, right) { + if (ts.hasQuestionToken(left) !== ts.hasQuestionToken(right)) { + return false; + } + var interestingFlags = 8 | + 16 | + 256 | + 128 | + 64 | + 32; + return (left.flags & interestingFlags) === (right.flags & interestingFlags); + } function checkVariableDeclaration(node) { checkGrammarVariableDeclaration(node); return checkVariableLikeDeclaration(node); @@ -24524,6 +24659,7 @@ var ts; var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); checkTypeParameterListsIdentical(node, symbol); + checkClassForDuplicateDeclarations(node); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { var baseTypes = getBaseTypes(type); @@ -24735,6 +24871,7 @@ var ts; checkIndexConstraints(type); } } + checkObjectTypeForDuplicateDeclarations(node); } ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) { if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) { @@ -25489,10 +25626,8 @@ var ts; function checkSourceFileWorker(node) { var links = getNodeLinks(node); if (!(links.flags & 1)) { - if (compilerOptions.skipDefaultLibCheck) { - if (node.hasNoDefaultLib) { - return; - } + if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) { + return; } checkGrammarSourceFile(node); potentialThisCollisions.length = 0; @@ -25861,7 +25996,7 @@ var ts; return symbol && getTypeOfSymbol(symbol); } if (ts.isBindingPattern(node)) { - return getTypeForVariableLikeDeclaration(node.parent); + return getTypeForVariableLikeDeclaration(node.parent, true); } if (isInRightSideOfImportOrExportAssignment(node)) { var symbol = getSymbolAtLocation(node); @@ -26300,7 +26435,7 @@ var ts; if (file.moduleAugmentations.length) { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } - if (file.wasReferenced && file.symbol && file.symbol.globalExports) { + if (file.symbol && file.symbol.globalExports) { mergeSymbolTable(globals, file.symbol.globalExports); } }); @@ -26870,7 +27005,6 @@ var ts; if (prop.kind === 193 || name_20.kind === 140) { checkGrammarComputedPropertyName(name_20); - return "continue"; } if (prop.kind === 254 && !inDestructuring && prop.objectAssignmentInitializer) { return { value: grammarErrorOnNode(prop.equalsToken, ts.Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment) }; @@ -26900,17 +27034,21 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_20.text)) { - seen[name_20.text] = currentKind; + var effectiveName = ts.getPropertyNameForPropertyNameNode(name_20); + if (effectiveName === undefined) { + return "continue"; + } + if (!ts.hasProperty(seen, effectiveName)) { + seen[effectiveName] = currentKind; } else { - var existingKind = seen[name_20.text]; + var existingKind = seen[effectiveName]; if (currentKind === Property && existingKind === Property) { - return "continue"; + grammarErrorOnNode(name_20, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name_20)); } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_20.text] = currentKind | existingKind; + seen[effectiveName] = currentKind | existingKind; } else { return { value: grammarErrorOnNode(name_20, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name) }; @@ -35367,7 +35505,7 @@ var ts; skipTsx: true, traceEnabled: traceEnabled }; - var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : undefined); + var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : (host.getCurrentDirectory && host.getCurrentDirectory())); if (traceEnabled) { if (containingFile === undefined) { if (rootDir === undefined) { @@ -35870,12 +36008,25 @@ var ts; } } } + function getDefaultTypeDirectiveNames(rootPath) { + var localTypes = ts.combinePaths(rootPath, "types"); + var npmTypes = ts.combinePaths(rootPath, "node_modules/@types"); + var result = []; + if (ts.sys.directoryExists(localTypes)) { + result = result.concat(ts.sys.getDirectories(localTypes)); + } + if (ts.sys.directoryExists(npmTypes)) { + result = result.concat(ts.sys.getDirectories(npmTypes)); + } + return result; + } function getDefaultLibLocation() { return ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())); } var newLine = ts.getNewLineCharacter(options); var realpath = ts.sys.realpath && (function (path) { return ts.sys.realpath(path); }); return { + getDefaultTypeDirectiveNames: getDefaultTypeDirectiveNames, getSourceFile: getSourceFile, getDefaultLibLocation: getDefaultLibLocation, getDefaultLibFileName: function (options) { return ts.combinePaths(getDefaultLibLocation(), ts.getDefaultLibFileName(options)); }, @@ -35943,6 +36094,19 @@ var ts; } return resolutions; } + function getDefaultTypeDirectiveNames(options, rootFiles, host) { + if (options.types) { + return options.types; + } + if (host && host.getDefaultTypeDirectiveNames) { + var commonRoot = computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), function (f) { return host.getCanonicalFileName(f); }); + if (commonRoot) { + return host.getDefaultTypeDirectiveNames(commonRoot); + } + } + return undefined; + } + ts.getDefaultTypeDirectiveNames = getDefaultTypeDirectiveNames; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; @@ -35978,13 +36142,14 @@ var ts; var filesByName = ts.createFileMap(); var filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? ts.createFileMap(function (fileName) { return fileName.toLowerCase(); }) : undefined; if (!tryReuseStructureFromOldProgram()) { - if (options.types && options.types.length) { - var resolutions = resolveTypeReferenceDirectiveNamesWorker(options.types, undefined); - for (var i = 0; i < options.types.length; i++) { - processTypeReferenceDirective(options.types[i], resolutions[i]); + ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); + var typeReferences = getDefaultTypeDirectiveNames(options, rootNames, host); + if (typeReferences) { + var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, undefined); + for (var i = 0; i < typeReferences.length; i++) { + processTypeReferenceDirective(typeReferences[i], resolutions[i]); } } - ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); if (!skipDefaultLib) { if (!options.lib) { processRootFile(host.getDefaultLibFileName(options), true); @@ -36561,9 +36726,6 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1) { - file_1.wasReferenced = file_1.wasReferenced || isReference; - } return file_1; } var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { @@ -36576,7 +36738,6 @@ var ts; }); filesByName.set(path, file); if (file) { - file.wasReferenced = file.wasReferenced || isReference; file.path = path; if (host.useCaseSensitiveFileNames()) { var existingFile = filesByNameIgnoreCase.get(path); @@ -36677,17 +36838,7 @@ var ts; !options.noResolve && i < file.imports.length; if (shouldAddFile) { - var importedFile = findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); - if (importedFile && resolution.isExternalLibraryImport) { - if (!ts.isExternalModule(importedFile) && importedFile.statements.length) { - var start_5 = ts.getTokenPosOfNode(file.imports[i], file); - fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_5, file.imports[i].end - start_5, ts.Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); - } - else if (importedFile.referencedFiles.length) { - var firstRef = importedFile.referencedFiles[0]; - fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); - } - } + findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } } } @@ -36772,7 +36923,7 @@ var ts; } } else { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substututions_for_pattern_0_should_be_an_array, key)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substitutions_for_pattern_0_should_be_an_array, key)); } } } @@ -36821,13 +36972,19 @@ var ts; } else if (firstExternalModuleSourceFile && languageVersion < 2 && options.module === ts.ModuleKind.None) { var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); } if (options.module === ts.ModuleKind.ES6 && languageVersion < 2) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es2015_when_targeting_ES5_or_lower)); } - if (outFile && options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + if (outFile) { + if (options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + } + else if (options.module === undefined && firstExternalModuleSourceFile) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); + } } if (options.outDir || options.sourceRoot || @@ -37517,7 +37674,7 @@ var ts; (function (ts) { var NavigateTo; (function (NavigateTo) { - function getNavigateToItems(program, cancellationToken, searchValue, maxResultCount) { + function getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount) { var patternMatcher = ts.createPatternMatcher(searchValue); var rawItems = []; var baseSensitivity = { sensitivity: "base" }; @@ -37550,6 +37707,17 @@ var ts; } } }); + rawItems = ts.filter(rawItems, function (item) { + var decl = item.declaration; + if (decl.kind === 231 || decl.kind === 234 || decl.kind === 229) { + var importer = checker.getSymbolAtLocation(decl.name); + var imported = checker.getAliasedSymbol(importer); + return importer.name !== imported.name; + } + else { + return true; + } + }); rawItems.sort(compareNavigateToItems); if (maxResultCount !== undefined) { rawItems = rawItems.slice(0, maxResultCount); @@ -37892,8 +38060,12 @@ var ts; return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); case 153: return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); + case 224: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.enumElement); case 255: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 222: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.interfaceElement); case 151: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); case 152: @@ -39263,7 +39435,7 @@ var ts; } } function findRightmostChildNodeWithTokens(children, exclusiveStartPosition) { - for (var i = exclusiveStartPosition - 1; i >= 0; --i) { + for (var i = exclusiveStartPosition - 1; i >= 0; i--) { if (nodeHasTokens(children[i])) { return children[i]; } @@ -39889,18 +40061,17 @@ var ts; if (!isStarted) { scanner.scan(); } - var t; var pos = scanner.getStartPos(); while (pos < endPos) { - var t_1 = scanner.getToken(); - if (!ts.isTrivia(t_1)) { + var t = scanner.getToken(); + if (!ts.isTrivia(t)) { break; } scanner.scan(); var item = { pos: pos, end: scanner.getStartPos(), - kind: t_1 + kind: t }; pos = scanner.getStartPos(); if (!leadingTrivia) { @@ -41550,7 +41721,7 @@ var ts; else { parts = []; var startPos = commentRange.pos; - for (var line = startLine; line < endLine; ++line) { + for (var line = startLine; line < endLine; line++) { var endOfLine = ts.getEndLinePosition(line, sourceFile); parts.push({ pos: startPos, end: endOfLine }); startPos = ts.getStartPositionOfLine(line + 1, sourceFile); @@ -41568,7 +41739,7 @@ var ts; startLine++; } var delta = indentation - nonWhitespaceColumnInFirstPart.column; - for (var i = startIndex, len = parts.length; i < len; ++i, ++startLine) { + for (var i = startIndex, len = parts.length; i < len; i++, startLine++) { var startLinePos_1 = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart @@ -41584,7 +41755,7 @@ var ts; } } function trimTrailingWhitespacesForLines(line1, line2, range) { - for (var line = line1; line < line2; ++line) { + for (var line = line1; line < line2; line++) { var lineStartPosition = ts.getStartPositionOfLine(line, sourceFile); var lineEndPosition = ts.getEndLinePosition(line, sourceFile); if (range && (ts.isComment(range.kind) || ts.isStringOrRegularExpressionOrTemplateLiteral(range.kind)) && range.pos <= lineEndPosition && range.end > lineEndPosition) { @@ -41627,7 +41798,6 @@ var ts; } } function applyRuleEdits(rule, previousRange, previousStartLine, currentRange, currentStartLine) { - var between; switch (rule.Operation.Action) { case 1: return; @@ -41657,14 +41827,6 @@ var ts; } } } - function isSomeBlock(kind) { - switch (kind) { - case 199: - case 226: - return true; - } - return false; - } function getOpenTokenForList(node, list) { switch (node.kind) { case 148: @@ -41722,7 +41884,7 @@ var ts; internedTabsIndentation = []; } if (internedTabsIndentation[tabs] === undefined) { - internedTabsIndentation[tabs] = tabString = repeat('\t', tabs); + internedTabsIndentation[tabs] = tabString = repeat("\t", tabs); } else { tabString = internedTabsIndentation[tabs]; @@ -41747,7 +41909,7 @@ var ts; } function repeat(value, count) { var s = ""; - for (var i = 0; i < count; ++i) { + for (var i = 0; i < count; i++) { s += value; } return s; @@ -42015,7 +42177,7 @@ var ts; ts.Debug.assert(index >= 0 && index < list.length); var node = list[index]; var lineAndCharacter = getStartLineAndCharacterForNode(node, sourceFile); - for (var i = index - 1; i >= 0; --i) { + for (var i = index - 1; i >= 0; i--) { if (list[i].kind === 24) { continue; } @@ -42034,7 +42196,7 @@ var ts; function findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options) { var character = 0; var column = 0; - for (var pos = startPos; pos < endPos; ++pos) { + for (var pos = startPos; pos < endPos; pos++) { var ch = sourceFile.text.charCodeAt(pos); if (!ts.isWhiteSpace(ch)) { break; @@ -44005,9 +44167,9 @@ var ts; log("getCompletionData: Get previous token 1: " + (new Date().getTime() - start)); var contextToken = previousToken; if (contextToken && position <= contextToken.end && ts.isWord(contextToken.kind)) { - var start_6 = new Date().getTime(); + var start_5 = new Date().getTime(); contextToken = ts.findPrecedingToken(contextToken.getFullStart(), sourceFile); - log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_6)); + log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_5)); } var node = currentToken; var isRightOfDot = false; @@ -44234,9 +44396,9 @@ var ts; || contextToken.kind === 166 || contextToken.kind === 10 || ts.isTemplateLiteralKind(contextToken.kind)) { - var start_7 = contextToken.getStart(); + var start_6 = contextToken.getStart(); var end = contextToken.getEnd(); - if (start_7 < position && position < end) { + if (start_6 < position && position < end) { return true; } if (position === end) { @@ -45314,8 +45476,7 @@ var ts; } function getDocumentHighlights(fileName, position, filesToSearch) { synchronizeHostData(); - filesToSearch = ts.map(filesToSearch, ts.normalizeSlashes); - var sourceFilesToSearch = ts.filter(program.getSourceFiles(), function (f) { return ts.contains(filesToSearch, f.fileName); }); + var sourceFilesToSearch = ts.map(filesToSearch, function (f) { return program.getSourceFile(f); }); var sourceFile = getValidSourceFile(fileName); var node = ts.getTouchingWord(sourceFile, position); if (!node) { @@ -46498,7 +46659,8 @@ var ts; } function getNavigateToItems(searchValue, maxResultCount) { synchronizeHostData(); - return ts.NavigateTo.getNavigateToItems(program, cancellationToken, searchValue, maxResultCount); + var checker = getProgram().getTypeChecker(); + return ts.NavigateTo.getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount); } function getEmitOutput(fileName) { synchronizeHostData(); @@ -50961,6 +51123,9 @@ var ts; LanguageServiceShimHostAdapter.prototype.getCurrentDirectory = function () { return this.shimHost.getCurrentDirectory(); }; + LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { + return this.shimHost.getDirectories(path); + }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); }; diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 84a06001d14..1ac624055d7 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -261,7 +261,7 @@ declare namespace ts { ModuleDeclaration = 225, ModuleBlock = 226, CaseBlock = 227, - GlobalModuleExportDeclaration = 228, + NamespaceExportDeclaration = 228, ImportEqualsDeclaration = 229, ImportDeclaration = 230, ImportClause = 231, @@ -934,7 +934,7 @@ declare namespace ts { interface NamespaceImport extends Declaration { name: Identifier; } - interface GlobalModuleExportDeclaration extends DeclarationStatement { + interface NamespaceExportDeclaration extends DeclarationStatement { name: Identifier; moduleReference: LiteralLikeNode; } @@ -1329,7 +1329,7 @@ declare namespace ts { FunctionScopedVariableExcludes = 107454, BlockScopedVariableExcludes = 107455, ParameterExcludes = 107455, - PropertyExcludes = 107455, + PropertyExcludes = 0, EnumMemberExcludes = 107455, FunctionExcludes = 106927, ClassExcludes = 899519, @@ -1554,6 +1554,7 @@ declare namespace ts { allowJs?: boolean; noImplicitUseStrict?: boolean; strictNullChecks?: boolean; + skipLibCheck?: boolean; listEmittedFiles?: boolean; lib?: string[]; types?: string[]; @@ -1627,6 +1628,7 @@ declare namespace ts { trace?(s: string): void; directoryExists?(directoryName: string): boolean; realpath?(path: string): string; + getCurrentDirectory?(): string; } interface ResolvedModule { resolvedFileName: string; @@ -1650,6 +1652,7 @@ declare namespace ts { getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; + getDefaultTypeDirectiveNames?(rootPath: string): string[]; writeFile: WriteFileCallback; getCurrentDirectory(): string; getCanonicalFileName(fileName: string): string; @@ -1693,6 +1696,7 @@ declare namespace ts { createDirectory(path: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; + getDirectories(path: string): string[]; readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getModifiedTime?(path: string): Date; createHash?(data: string): string; @@ -1812,6 +1816,7 @@ declare namespace ts { function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; + function getDefaultTypeDirectiveNames(options: CompilerOptions, rootFiles: string[], host: CompilerHost): string[]; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program; } declare namespace ts { @@ -2345,26 +2350,55 @@ declare namespace ts { namespace ScriptElementKind { const unknown: string; const warning: string; + /** predefined type (void) or keyword (class) */ const keyword: string; + /** top level script node */ const scriptElement: string; + /** module foo {} */ const moduleElement: string; + /** class X {} */ const classElement: string; + /** var x = class X {} */ const localClassElement: string; + /** interface Y {} */ const interfaceElement: string; + /** type T = ... */ const typeElement: string; + /** enum E */ const enumElement: string; + /** + * Inside module and script only + * const v = .. + */ const variableElement: string; + /** Inside function */ const localVariableElement: string; + /** + * Inside module and script only + * function f() { } + */ const functionElement: string; + /** Inside function */ const localFunctionElement: string; + /** class X { [public|private]* foo() {} } */ const memberFunctionElement: string; + /** class X { [public|private]* [get|set] foo:number; } */ const memberGetAccessorElement: string; const memberSetAccessorElement: string; + /** + * class X { [public|private]* foo:number; } + * interface Y { foo:number; } + */ const memberVariableElement: string; + /** class X { constructor() { } } */ const constructorImplementationElement: string; + /** interface Y { ():number; } */ const callSignatureElement: string; + /** interface Y { []:number; } */ const indexSignatureElement: string; + /** interface Y { new():Y; } */ const constructSignatureElement: string; + /** function foo(*Y*: string) */ const parameterElement: string; const typeParameterElement: string; const primitiveType: string; diff --git a/lib/typescript.js b/lib/typescript.js index e78eda7b0bb..19fffd35501 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -271,7 +271,7 @@ var ts; SyntaxKind[SyntaxKind["ModuleDeclaration"] = 225] = "ModuleDeclaration"; SyntaxKind[SyntaxKind["ModuleBlock"] = 226] = "ModuleBlock"; SyntaxKind[SyntaxKind["CaseBlock"] = 227] = "CaseBlock"; - SyntaxKind[SyntaxKind["GlobalModuleExportDeclaration"] = 228] = "GlobalModuleExportDeclaration"; + SyntaxKind[SyntaxKind["NamespaceExportDeclaration"] = 228] = "NamespaceExportDeclaration"; SyntaxKind[SyntaxKind["ImportEqualsDeclaration"] = 229] = "ImportEqualsDeclaration"; SyntaxKind[SyntaxKind["ImportDeclaration"] = 230] = "ImportDeclaration"; SyntaxKind[SyntaxKind["ImportClause"] = 231] = "ImportClause"; @@ -561,7 +561,7 @@ var ts; // they can not merge with anything in the value space SymbolFlags[SymbolFlags["BlockScopedVariableExcludes"] = 107455] = "BlockScopedVariableExcludes"; SymbolFlags[SymbolFlags["ParameterExcludes"] = 107455] = "ParameterExcludes"; - SymbolFlags[SymbolFlags["PropertyExcludes"] = 107455] = "PropertyExcludes"; + SymbolFlags[SymbolFlags["PropertyExcludes"] = 0] = "PropertyExcludes"; SymbolFlags[SymbolFlags["EnumMemberExcludes"] = 107455] = "EnumMemberExcludes"; SymbolFlags[SymbolFlags["FunctionExcludes"] = 106927] = "FunctionExcludes"; SymbolFlags[SymbolFlags["ClassExcludes"] = 899519] = "ClassExcludes"; @@ -1841,6 +1841,10 @@ var ts; } return result.sort(); } + function getDirectories(path) { + var folder = fso.GetFolder(path); + return getNames(folder.subfolders); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -1895,6 +1899,7 @@ var ts; getCurrentDirectory: function () { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + getDirectories: getDirectories, readDirectory: readDirectory, exit: function (exitCode) { try { @@ -2057,6 +2062,9 @@ var ts; function directoryExists(path) { return fileSystemEntryExists(path, 1 /* Directory */); } + function getDirectories(path) { + return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1 /* Directory */); }); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -2157,6 +2165,7 @@ var ts; getCurrentDirectory: function () { return process.cwd(); }, + getDirectories: getDirectories, readDirectory: readDirectory, getModifiedTime: function (path) { try { @@ -2209,6 +2218,7 @@ var ts; createDirectory: ChakraHost.createDirectory, getExecutingFilePath: function () { return ChakraHost.executingFile; }, getCurrentDirectory: function () { return ChakraHost.currentDirectory; }, + getDirectories: ChakraHost.getDirectories, readDirectory: ChakraHost.readDirectory, exit: ChakraHost.quit, realpath: realpath @@ -2347,7 +2357,7 @@ var ts; or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "or_expected_1144", message: "'{' or ';' expected." }, Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration_expected_1146", message: "Declaration expected." }, Import_declarations_in_a_namespace_cannot_reference_a_module: { code: 1147, category: ts.DiagnosticCategory.Error, key: "Import_declarations_in_a_namespace_cannot_reference_a_module_1147", message: "Import declarations in a namespace cannot reference a module." }, - Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting__1148", message: "Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file." }, + Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_use_imports_exports_or_module_augmentations_when_module_is_none_1148", message: "Cannot use imports, exports, or module augmentations when '--module' is 'none'." }, File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: ts.DiagnosticCategory.Error, key: "File_name_0_differs_from_already_included_file_name_1_only_in_casing_1149", message: "File name '{0}' differs from already included file name '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: ts.DiagnosticCategory.Error, key: "new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead_1150", message: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "const_declarations_must_be_initialized_1155", message: "'const' declarations must be initialized" }, @@ -2717,6 +2727,8 @@ var ts; this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation: { code: 2683, category: ts.DiagnosticCategory.Error, key: "this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_2683", message: "'this' implicitly has type 'any' because it does not have a type annotation." }, The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1: { code: 2684, category: ts.DiagnosticCategory.Error, key: "The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1_2684", message: "The 'this' context of type '{0}' is not assignable to method's 'this' of type '{1}'." }, The_this_types_of_each_signature_are_incompatible: { code: 2685, category: ts.DiagnosticCategory.Error, key: "The_this_types_of_each_signature_are_incompatible_2685", message: "The 'this' types of each signature are incompatible." }, + Identifier_0_must_be_imported_from_a_module: { code: 2686, category: ts.DiagnosticCategory.Error, key: "Identifier_0_must_be_imported_from_a_module_2686", message: "Identifier '{0}' must be imported from a module" }, + All_declarations_of_0_must_have_identical_modifiers: { code: 2687, category: ts.DiagnosticCategory.Error, key: "All_declarations_of_0_must_have_identical_modifiers_2687", message: "All declarations of '{0}' must have identical modifiers." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import_declaration_0_is_using_private_name_1_4000", message: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", message: "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: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", message: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -2810,7 +2822,7 @@ var ts; Option_paths_cannot_be_used_without_specifying_baseUrl_option: { code: 5060, category: ts.DiagnosticCategory.Error, key: "Option_paths_cannot_be_used_without_specifying_baseUrl_option_5060", message: "Option 'paths' cannot be used without specifying '--baseUrl' option." }, Pattern_0_can_have_at_most_one_Asterisk_character: { code: 5061, category: ts.DiagnosticCategory.Error, key: "Pattern_0_can_have_at_most_one_Asterisk_character_5061", message: "Pattern '{0}' can have at most one '*' character" }, Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character: { code: 5062, category: ts.DiagnosticCategory.Error, key: "Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character_5062", message: "Substitution '{0}' in pattern '{1}' in can have at most one '*' character" }, - Substututions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substututions_for_pattern_0_should_be_an_array_5063", message: "Substututions for pattern '{0}' should be an array." }, + Substitutions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substitutions_for_pattern_0_should_be_an_array_5063", message: "Substitutions for pattern '{0}' should be an array." }, Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2: { code: 5064, category: ts.DiagnosticCategory.Error, key: "Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2_5064", message: "Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate_and_emit_output_to_single_file_6001", message: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates_corresponding_d_ts_file_6002", message: "Generates corresponding '.d.ts' file." }, @@ -2823,6 +2835,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_comments_to_output_6009", message: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_outputs_6010", message: "Do not emit outputs." }, Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking: { code: 6011, category: ts.DiagnosticCategory.Message, key: "Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typech_6011", message: "Allow default imports from modules with no default export. This does not affect code emit, just typechecking." }, + Skip_type_checking_of_declaration_files: { code: 6012, category: ts.DiagnosticCategory.Message, key: "Skip_type_checking_of_declaration_files_6012", message: "Skip type checking of declaration files." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015_6015", message: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'" }, Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015_6016", message: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print_this_message_6017", message: "Print this message." }, @@ -2924,6 +2937,7 @@ var ts; Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set: { code: 6128, category: ts.DiagnosticCategory.Message, key: "Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set_6128", message: "======== Resolving type reference directive '{0}', containing file not set, root directory not set. ========" }, The_config_file_0_found_doesn_t_contain_any_source_files: { code: 6129, category: ts.DiagnosticCategory.Error, key: "The_config_file_0_found_doesn_t_contain_any_source_files_6129", message: "The config file '{0}' found doesn't contain any source files." }, Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, + Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -6172,7 +6186,7 @@ var ts; // export default ... function isAliasSymbolDeclaration(node) { return node.kind === 229 /* ImportEqualsDeclaration */ || - node.kind === 228 /* GlobalModuleExportDeclaration */ || + node.kind === 228 /* NamespaceExportDeclaration */ || node.kind === 231 /* ImportClause */ && !!node.name || node.kind === 232 /* NamespaceImport */ || node.kind === 234 /* ImportSpecifier */ || @@ -6301,7 +6315,7 @@ var ts; } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 69 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */) { + if (name.kind === 69 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */ || name.kind === 142 /* Parameter */) { return name.text; } if (name.kind === 140 /* ComputedPropertyName */) { @@ -7773,7 +7787,7 @@ var ts; case 231 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); - case 228 /* GlobalModuleExportDeclaration */: + case 228 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 232 /* NamespaceImport */: return visitNode(cbNode, node.name); @@ -12182,7 +12196,7 @@ var ts; return nextToken() === 39 /* SlashToken */; } function parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers) { - var exportDeclaration = createNode(228 /* GlobalModuleExportDeclaration */, fullStart); + var exportDeclaration = createNode(228 /* NamespaceExportDeclaration */, fullStart); exportDeclaration.decorators = decorators; exportDeclaration.modifiers = modifiers; parseExpected(116 /* AsKeyword */); @@ -15018,10 +15032,10 @@ var ts; case 145 /* PropertyDeclaration */: case 144 /* PropertySignature */: case 266 /* JSDocRecordMember */: - return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 107455 /* PropertyExcludes */); + return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 0 /* PropertyExcludes */); case 253 /* PropertyAssignment */: case 254 /* ShorthandPropertyAssignment */: - return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */); + return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 0 /* PropertyExcludes */); case 255 /* EnumMember */: return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */); case 247 /* JsxSpreadAttribute */: @@ -15037,7 +15051,7 @@ var ts; // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. - return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */); + return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 0 /* PropertyExcludes */ : 99263 /* MethodExcludes */); case 220 /* FunctionDeclaration */: return bindFunctionDeclaration(node); case 148 /* Constructor */: @@ -15081,8 +15095,8 @@ var ts; case 234 /* ImportSpecifier */: case 238 /* ExportSpecifier */: return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); - case 228 /* GlobalModuleExportDeclaration */: - return bindGlobalModuleExportDeclaration(node); + case 228 /* NamespaceExportDeclaration */: + return bindNamespaceExportDeclaration(node); case 231 /* ImportClause */: return bindImportClause(node); case 236 /* ExportDeclaration */: @@ -15120,14 +15134,14 @@ var ts; } else if (boundExpression.kind === 69 /* Identifier */ && node.kind === 235 /* ExportAssignment */) { // An export default clause with an identifier exports all meanings of that identifier - declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); + declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 0 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); } else { // An export default clause with an expression exports a value - declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); + declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 0 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); } } - function bindGlobalModuleExportDeclaration(node) { + function bindNamespaceExportDeclaration(node) { if (node.modifiers && node.modifiers.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Modifiers_cannot_appear_here)); } @@ -15186,7 +15200,7 @@ var ts; if (container.kind === 179 /* FunctionExpression */ || container.kind === 220 /* FunctionDeclaration */) { container.symbol.members = container.symbol.members || {}; // It's acceptable for multiple 'this' assignments of the same identifier to occur - declareSymbol(container.symbol.members, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ & ~4 /* Property */); + declareSymbol(container.symbol.members, container.symbol, node, 4 /* Property */, 0 /* PropertyExcludes */ & ~4 /* Property */); } } function bindPrototypePropertyAssignment(node) { @@ -15209,7 +15223,7 @@ var ts; funcSymbol.members = {}; } // Declare the method/property - declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4 /* Property */, 107455 /* PropertyExcludes */); + declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4 /* Property */, 0 /* PropertyExcludes */); } function bindCallExpression(node) { // We're only inspecting call expressions to detect CommonJS modules, so we can skip @@ -15310,7 +15324,7 @@ var ts; // containing class. if (ts.isParameterPropertyDeclaration(node)) { var classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 0 /* PropertyExcludes */); } } function bindFunctionDeclaration(node) { @@ -15696,7 +15710,7 @@ var ts; if (flags & 1 /* FunctionScopedVariable */) result |= 107454 /* FunctionScopedVariableExcludes */; if (flags & 4 /* Property */) - result |= 107455 /* PropertyExcludes */; + result |= 0 /* PropertyExcludes */; if (flags & 8 /* EnumMember */) result |= 107455 /* EnumMemberExcludes */; if (flags & 16 /* Function */) @@ -15982,6 +15996,7 @@ var ts; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; + var isInExternalModule = false; loop: while (location) { // Locals of a source file are not in scope (because they get merged into the global symbol table) if (location.locals && !isGlobalSourceFile(location)) { @@ -16024,6 +16039,7 @@ var ts; case 256 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; + isInExternalModule = true; case 225 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 256 /* SourceFile */ || ts.isAmbientModule(location)) { @@ -16207,6 +16223,13 @@ var ts; checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); } } + // If we're in an external module, we can't reference symbols created from UMD export declarations + if (result && isInExternalModule) { + var decls = result.declarations; + if (decls && decls.length === 1 && decls[0].kind === 228 /* NamespaceExportDeclaration */) { + error(errorLocation, ts.Diagnostics.Identifier_0_must_be_imported_from_a_module, name); + } + } } return result; } @@ -16409,7 +16432,7 @@ var ts; return getTargetOfExportSpecifier(node); case 235 /* ExportAssignment */: return getTargetOfExportAssignment(node); - case 228 /* GlobalModuleExportDeclaration */: + case 228 /* NamespaceExportDeclaration */: return getTargetOfGlobalModuleExportDeclaration(node); } } @@ -17883,7 +17906,7 @@ var ts; // assigned by contextual typing. function getTypeForBindingElementParent(node) { var symbol = getSymbolOfNode(node); - return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false); } function getTextOfPropertyName(name) { switch (name.kind) { @@ -18009,7 +18032,7 @@ var ts; return strictNullChecks && optional ? addNullableKind(type, 32 /* Undefined */) : type; } // Return the inferred type for a variable, parameter, or property declaration - function getTypeForVariableLikeDeclaration(declaration) { + function getTypeForVariableLikeDeclaration(declaration, includeOptionality) { if (declaration.flags & 134217728 /* JavaScriptFile */) { // If this is a variable in a JavaScript file, then use the JSDoc type (if it has // one as its type), otherwise fallback to the below standard TS codepaths to @@ -18035,7 +18058,7 @@ var ts; } // Use type from type annotation if one is present if (declaration.type) { - return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ !!declaration.questionToken); + return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality); } if (declaration.kind === 142 /* Parameter */) { var func = declaration.parent; @@ -18056,12 +18079,12 @@ var ts; ? getContextuallyTypedThisType(func) : getContextuallyTypedParameterType(declaration); if (type) { - return addOptionality(type, /*optional*/ !!declaration.questionToken); + return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality); } } // Use the type of the initializer expression if one is present if (declaration.initializer) { - return addOptionality(checkExpressionCached(declaration.initializer), /*optional*/ !!declaration.questionToken); + return addOptionality(checkExpressionCached(declaration.initializer), /*optional*/ declaration.questionToken && includeOptionality); } // If it is a short-hand property assignment, use the type of the identifier if (declaration.kind === 254 /* ShorthandPropertyAssignment */) { @@ -18155,7 +18178,7 @@ var ts; // binding pattern [x, s = ""]. Because the contextual type is a tuple type, the resulting type of [1, "one"] is the // tuple type [number, string]. Thus, the type inferred for 'x' is number and the type inferred for 's' is string. function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { - var type = getTypeForVariableLikeDeclaration(declaration); + var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true); if (type) { if (reportErrors) { reportErrorsFromWidening(declaration, type); @@ -20719,7 +20742,7 @@ var ts; return isIdenticalTo(source, target); } if (!(target.flags & 134217728 /* Never */)) { - if (target.flags & 1 /* Any */) + if (target.flags & 1 /* Any */ || source.flags & 134217728 /* Never */) return -1 /* True */; if (source.flags & 32 /* Undefined */) { if (!strictNullChecks || target.flags & (32 /* Undefined */ | 16 /* Void */) || source === emptyArrayElementType) @@ -20739,7 +20762,7 @@ var ts; if (source.flags & 256 /* StringLiteral */ && target === stringType) return -1 /* True */; if (relation === assignableRelation || relation === comparableRelation) { - if (source.flags & (1 /* Any */ | 134217728 /* Never */)) + if (source.flags & 1 /* Any */) return -1 /* True */; if (source === numberType && target.flags & 128 /* Enum */) return -1 /* True */; @@ -21634,41 +21657,52 @@ var ts; getSignaturesOfType(type, 0 /* Call */).length === 0 && getSignaturesOfType(type, 1 /* Construct */).length === 0; } + function createTransientSymbol(source, type) { + var symbol = createSymbol(source.flags | 67108864 /* Transient */, source.name); + symbol.declarations = source.declarations; + symbol.parent = source.parent; + symbol.type = type; + symbol.target = source; + if (source.valueDeclaration) { + symbol.valueDeclaration = source.valueDeclaration; + } + return symbol; + } + function transformTypeOfMembers(type, f) { + var members = {}; + for (var _i = 0, _a = getPropertiesOfObjectType(type); _i < _a.length; _i++) { + var property = _a[_i]; + var original = getTypeOfSymbol(property); + var updated = f(original); + members[property.name] = updated === original ? property : createTransientSymbol(property, updated); + } + ; + return members; + } + /** + * If the the provided object literal is subject to the excess properties check, + * create a new that is exempt. Recursively mark object literal members as exempt. + * Leave signatures alone since they are not subject to the check. + */ function getRegularTypeOfObjectLiteral(type) { - if (type.flags & 1048576 /* FreshObjectLiteral */) { - var regularType = type.regularType; - if (!regularType) { - regularType = createType(type.flags & ~1048576 /* FreshObjectLiteral */); - regularType.symbol = type.symbol; - regularType.members = type.members; - regularType.properties = type.properties; - regularType.callSignatures = type.callSignatures; - regularType.constructSignatures = type.constructSignatures; - regularType.stringIndexInfo = type.stringIndexInfo; - regularType.numberIndexInfo = type.numberIndexInfo; - type.regularType = regularType; - } + if (!(type.flags & 1048576 /* FreshObjectLiteral */)) { + return type; + } + var regularType = type.regularType; + if (regularType) { return regularType; } - return type; + var resolved = type; + var members = transformTypeOfMembers(type, getRegularTypeOfObjectLiteral); + var regularNew = createAnonymousType(resolved.symbol, members, resolved.callSignatures, resolved.constructSignatures, resolved.stringIndexInfo, resolved.numberIndexInfo); + regularNew.flags = resolved.flags & ~1048576 /* FreshObjectLiteral */; + type.regularType = regularNew; + return regularNew; } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfObjectType(type); - var members = {}; - ts.forEach(properties, function (p) { - 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 members = transformTypeOfMembers(type, function (prop) { + var widened = getWidenedType(prop); + return prop === widened ? prop : widened; }); var stringIndexInfo = getIndexInfoOfType(type, 0 /* String */); var numberIndexInfo = getIndexInfoOfType(type, 1 /* Number */); @@ -23224,7 +23258,7 @@ var ts; } return nodeCheckFlag === 512 /* SuperStatic */ ? getBaseConstructorTypeOfClass(classType) - : baseClassType; + : getTypeWithThisArgument(baseClassType, classType.thisType); function isLegalUsageOfSuperExpression(container) { if (!container) { return false; @@ -25936,7 +25970,7 @@ var ts; var types = void 0; var funcIsGenerator = !!func.asteriskToken; if (funcIsGenerator) { - types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + types = checkAndAggregateYieldOperandTypes(func, contextualMapper); if (types.length === 0) { var iterableIteratorAny = createIterableIteratorType(anyType); if (compilerOptions.noImplicitAny) { @@ -25946,8 +25980,7 @@ var ts; } } else { - var hasImplicitReturn = !!(func.flags & 32768 /* HasImplicitReturn */); - types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync, hasImplicitReturn); + types = checkAndAggregateReturnExpressionTypes(func, contextualMapper); if (!types) { return neverType; } @@ -26001,9 +26034,9 @@ var ts; return widenedType; } } - function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + function checkAndAggregateYieldOperandTypes(func, contextualMapper) { var aggregatedTypes = []; - ts.forEachYieldExpression(body, function (yieldExpression) { + ts.forEachYieldExpression(func.body, function (yieldExpression) { var expr = yieldExpression.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -26018,10 +26051,12 @@ var ts; }); return aggregatedTypes; } - function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync, hasImplicitReturn) { + function checkAndAggregateReturnExpressionTypes(func, contextualMapper) { + var isAsync = ts.isAsyncFunctionLike(func); var aggregatedTypes = []; - var hasOmittedExpressions = false; - ts.forEachReturnStatement(body, function (returnStatement) { + var hasReturnWithNoExpression = !!(func.flags & 32768 /* HasImplicitReturn */); + var hasReturnOfTypeNever = false; + ts.forEachReturnStatement(func.body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -26030,20 +26065,24 @@ var ts; // Promise/A+ compatible implementation will always assimilate any foreign promise, so the // return type of the body should be unwrapped to its awaited type, which should be wrapped in // the native Promise type by the caller. - type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); + type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } - if (type !== neverType && !ts.contains(aggregatedTypes, type)) { + if (type === neverType) { + hasReturnOfTypeNever = true; + } + else if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } } else { - hasOmittedExpressions = true; + hasReturnWithNoExpression = true; } }); - if (aggregatedTypes.length === 0 && !hasOmittedExpressions && !hasImplicitReturn) { + if (aggregatedTypes.length === 0 && !hasReturnWithNoExpression && (hasReturnOfTypeNever || + func.kind === 179 /* FunctionExpression */ || func.kind === 180 /* ArrowFunction */)) { return undefined; } - if (strictNullChecks && aggregatedTypes.length && (hasOmittedExpressions || hasImplicitReturn)) { + if (strictNullChecks && aggregatedTypes.length && hasReturnWithNoExpression) { if (!ts.contains(aggregatedTypes, undefinedType)) { aggregatedTypes.push(undefinedType); } @@ -26215,8 +26254,14 @@ var ts; if (symbol.flags & 4 /* Property */ && (expr.kind === 172 /* PropertyAccessExpression */ || expr.kind === 173 /* ElementAccessExpression */) && expr.expression.kind === 97 /* ThisKeyword */) { + // Look for if this is the constructor for the class that `symbol` is a property of. var func = ts.getContainingFunction(expr); - return !(func && func.kind === 148 /* Constructor */ && func.parent === symbol.valueDeclaration.parent); + if (!(func && func.kind === 148 /* Constructor */)) + return true; + // If func.parent is a class and symbol is a (readonly) property of that class, or + // if func is a constructor and symbol is a (readonly) parameter property declared in it, + // then symbol is writeable here. + return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent); } return true; } @@ -27148,6 +27193,79 @@ var ts; } } } + function checkClassForDuplicateDeclarations(node) { + var getter = 1, setter = 2, property = getter | setter; + var instanceNames = {}; + var staticNames = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 148 /* Constructor */) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var param = _c[_b]; + if (ts.isParameterPropertyDeclaration(param)) { + addName(instanceNames, param.name, param.name.text, property); + } + } + } + else { + var static = ts.forEach(member.modifiers, function (m) { return m.kind === 113 /* StaticKeyword */; }); + var names = static ? staticNames : instanceNames; + var memberName = member.name && ts.getPropertyNameForPropertyNameNode(member.name); + if (memberName) { + switch (member.kind) { + case 149 /* GetAccessor */: + addName(names, member.name, memberName, getter); + break; + case 150 /* SetAccessor */: + addName(names, member.name, memberName, setter); + break; + case 145 /* PropertyDeclaration */: + addName(names, member.name, memberName, property); + break; + } + } + } + } + function addName(names, location, name, meaning) { + if (ts.hasProperty(names, name)) { + var prev = names[name]; + if (prev & meaning) { + error(location, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(location)); + } + else { + names[name] = prev | meaning; + } + } + else { + names[name] = meaning; + } + } + } + function checkObjectTypeForDuplicateDeclarations(node) { + var names = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind == 144 /* PropertySignature */) { + var memberName = void 0; + switch (member.name.kind) { + case 9 /* StringLiteral */: + case 8 /* NumericLiteral */: + case 69 /* Identifier */: + memberName = member.name.text; + break; + default: + continue; + } + if (ts.hasProperty(names, memberName)) { + error(member.symbol.valueDeclaration.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + error(member.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + } + else { + names[memberName] = true; + } + } + } + } function checkTypeForDuplicateIndexSignatures(node) { if (node.kind === 222 /* InterfaceDeclaration */) { var nodeSymbol = getSymbolOfNode(node); @@ -27399,6 +27517,7 @@ var ts; var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); + checkObjectTypeForDuplicateDeclarations(node); } } function checkArrayType(node) { @@ -28444,6 +28563,10 @@ var ts; if (node.initializer) { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, /*headMessage*/ undefined); } + if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { + error(symbol.valueDeclaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + error(node.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + } } if (node.kind !== 145 /* PropertyDeclaration */ && node.kind !== 144 /* PropertySignature */) { // We know we don't have a binding pattern or computed name here @@ -28457,6 +28580,18 @@ var ts; checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } + function areDeclarationFlagsIdentical(left, right) { + if (ts.hasQuestionToken(left) !== ts.hasQuestionToken(right)) { + return false; + } + var interestingFlags = 8 /* Private */ | + 16 /* Protected */ | + 256 /* Async */ | + 128 /* Abstract */ | + 64 /* Readonly */ | + 32 /* Static */; + return (left.flags & interestingFlags) === (right.flags & interestingFlags); + } function checkVariableDeclaration(node) { checkGrammarVariableDeclaration(node); return checkVariableLikeDeclaration(node); @@ -29150,6 +29285,7 @@ var ts; var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); checkTypeParameterListsIdentical(node, symbol); + checkClassForDuplicateDeclarations(node); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { var baseTypes = getBaseTypes(type); @@ -29398,6 +29534,7 @@ var ts; checkIndexConstraints(type); } } + checkObjectTypeForDuplicateDeclarations(node); } ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) { if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) { @@ -30241,14 +30378,11 @@ var ts; function checkSourceFileWorker(node) { var links = getNodeLinks(node); if (!(links.flags & 1 /* TypeChecked */)) { - // Check whether the file has declared it is the default lib, - // and whether the user has specifically chosen to avoid checking it. - if (compilerOptions.skipDefaultLibCheck) { - // If the user specified '--noLib' and a file has a '/// ', - // then we should treat that file as a default lib. - if (node.hasNoDefaultLib) { - return; - } + // If skipLibCheck is enabled, skip type checking if file is a declaration file. + // If skipDefaultLibCheck is enabled, skip type checking if file contains a + // '/// ' directive. + if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) { + return; } // Grammar checking checkGrammarSourceFile(node); @@ -30665,7 +30799,7 @@ var ts; return symbol && getTypeOfSymbol(symbol); } if (ts.isBindingPattern(node)) { - return getTypeForVariableLikeDeclaration(node.parent); + return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true); } if (isInRightSideOfImportOrExportAssignment(node)) { var symbol = getSymbolAtLocation(node); @@ -31204,7 +31338,7 @@ var ts; if (file.moduleAugmentations.length) { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } - if (file.wasReferenced && file.symbol && file.symbol.globalExports) { + if (file.symbol && file.symbol.globalExports) { mergeSymbolTable(globals, file.symbol.globalExports); } }); @@ -31787,7 +31921,6 @@ var ts; name_20.kind === 140 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it checkGrammarComputedPropertyName(name_20); - return "continue"; } if (prop.kind === 254 /* ShorthandPropertyAssignment */ && !inDestructuring && prop.objectAssignmentInitializer) { // having objectAssignmentInitializer is only valid in ObjectAssignmentPattern @@ -31829,17 +31962,21 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_20.text)) { - seen[name_20.text] = currentKind; + var effectiveName = ts.getPropertyNameForPropertyNameNode(name_20); + if (effectiveName === undefined) { + return "continue"; + } + if (!ts.hasProperty(seen, effectiveName)) { + seen[effectiveName] = currentKind; } else { - var existingKind = seen[name_20.text]; + var existingKind = seen[effectiveName]; if (currentKind === Property && existingKind === Property) { - return "continue"; + grammarErrorOnNode(name_20, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name_20)); } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_20.text] = currentKind | existingKind; + seen[effectiveName] = currentKind | existingKind; } else { return { value: grammarErrorOnNode(name_20, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name) }; @@ -41638,8 +41775,8 @@ var ts; skipTsx: true, traceEnabled: traceEnabled }; - // use typesRoot and fallback to directory that contains tsconfig if typesRoot is not set - var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : undefined); + // use typesRoot and fallback to directory that contains tsconfig or current directory if typesRoot is not set + var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : (host.getCurrentDirectory && host.getCurrentDirectory())); if (traceEnabled) { if (containingFile === undefined) { if (rootDir === undefined) { @@ -42229,12 +42366,25 @@ var ts; } } } + function getDefaultTypeDirectiveNames(rootPath) { + var localTypes = ts.combinePaths(rootPath, "types"); + var npmTypes = ts.combinePaths(rootPath, "node_modules/@types"); + var result = []; + if (ts.sys.directoryExists(localTypes)) { + result = result.concat(ts.sys.getDirectories(localTypes)); + } + if (ts.sys.directoryExists(npmTypes)) { + result = result.concat(ts.sys.getDirectories(npmTypes)); + } + return result; + } function getDefaultLibLocation() { return ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())); } var newLine = ts.getNewLineCharacter(options); var realpath = ts.sys.realpath && (function (path) { return ts.sys.realpath(path); }); return { + getDefaultTypeDirectiveNames: getDefaultTypeDirectiveNames, getSourceFile: getSourceFile, getDefaultLibLocation: getDefaultLibLocation, getDefaultLibFileName: function (options) { return ts.combinePaths(getDefaultLibLocation(), ts.getDefaultLibFileName(options)); }, @@ -42302,6 +42452,21 @@ var ts; } return resolutions; } + function getDefaultTypeDirectiveNames(options, rootFiles, host) { + // Use explicit type list from tsconfig.json + if (options.types) { + return options.types; + } + // or load all types from the automatic type import fields + if (host && host.getDefaultTypeDirectiveNames) { + var commonRoot = computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), function (f) { return host.getCanonicalFileName(f); }); + if (commonRoot) { + return host.getDefaultTypeDirectiveNames(commonRoot); + } + } + return undefined; + } + ts.getDefaultTypeDirectiveNames = getDefaultTypeDirectiveNames; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; @@ -42340,14 +42505,15 @@ var ts; // used to track cases when two file names differ only in casing var filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? ts.createFileMap(function (fileName) { return fileName.toLowerCase(); }) : undefined; if (!tryReuseStructureFromOldProgram()) { + ts.forEach(rootNames, function (name) { return processRootFile(name, /*isDefaultLib*/ false); }); // load type declarations specified via 'types' argument - if (options.types && options.types.length) { - var resolutions = resolveTypeReferenceDirectiveNamesWorker(options.types, /*containingFile*/ undefined); - for (var i = 0; i < options.types.length; i++) { - processTypeReferenceDirective(options.types[i], resolutions[i]); + var typeReferences = getDefaultTypeDirectiveNames(options, rootNames, host); + if (typeReferences) { + var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, /*containingFile*/ undefined); + for (var i = 0; i < typeReferences.length; i++) { + processTypeReferenceDirective(typeReferences[i], resolutions[i]); } } - ts.forEach(rootNames, function (name) { return processRootFile(name, /*isDefaultLib*/ false); }); // Do not process the default library if: // - The '--noLib' flag is used. // - A 'no-default-lib' reference comment is encountered in @@ -42999,9 +43165,6 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1) { - file_1.wasReferenced = file_1.wasReferenced || isReference; - } return file_1; } // We haven't looked for this file, do so now and cache result @@ -43015,7 +43178,6 @@ var ts; }); filesByName.set(path, file); if (file) { - file.wasReferenced = file.wasReferenced || isReference; file.path = path; if (host.useCaseSensitiveFileNames()) { // for case-sensitive file systems check if we've already seen some file with similar filename ignoring case @@ -43129,19 +43291,7 @@ var ts; !options.noResolve && i < file.imports.length; if (shouldAddFile) { - var importedFile = findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, /*isReference*/ false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); - if (importedFile && resolution.isExternalLibraryImport) { - // Since currently irrespective of allowJs, we only look for supportedTypeScript extension external module files, - // this check is ok. Otherwise this would be never true for javascript file - if (!ts.isExternalModule(importedFile) && importedFile.statements.length) { - var start_5 = ts.getTokenPosOfNode(file.imports[i], file); - fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_5, file.imports[i].end - start_5, ts.Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); - } - else if (importedFile.referencedFiles.length) { - var firstRef = importedFile.referencedFiles[0]; - fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); - } - } + findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, /*isReference*/ false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } } } @@ -43227,7 +43377,7 @@ var ts; } } else { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substututions_for_pattern_0_should_be_an_array, key)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substitutions_for_pattern_0_should_be_an_array, key)); } } } @@ -43278,15 +43428,21 @@ var ts; else if (firstExternalModuleSourceFile && languageVersion < 2 /* ES6 */ && options.module === ts.ModuleKind.None) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); } // Cannot specify module gen target of es6 when below es6 if (options.module === ts.ModuleKind.ES6 && languageVersion < 2 /* ES6 */) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es2015_when_targeting_ES5_or_lower)); } // Cannot specify module gen that isn't amd or system with --out - if (outFile && options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + if (outFile) { + if (options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + } + else if (options.module === undefined && firstExternalModuleSourceFile) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); + } } // there has to be common source directory if user specified --outdir || --sourceRoot // if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted @@ -43384,6 +43540,11 @@ var ts; type: "boolean", description: ts.Diagnostics.Print_this_message }, + { + name: "help", + shortName: "?", + type: "boolean" + }, { name: "init", type: "boolean", @@ -43486,6 +43647,11 @@ var ts; name: "skipDefaultLibCheck", type: "boolean" }, + { + name: "skipLibCheck", + type: "boolean", + description: ts.Diagnostics.Skip_type_checking_of_declaration_files + }, { name: "out", type: "string", @@ -44315,7 +44481,7 @@ var ts; (function (ts) { var NavigateTo; (function (NavigateTo) { - function getNavigateToItems(program, cancellationToken, searchValue, maxResultCount) { + function getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount) { var patternMatcher = ts.createPatternMatcher(searchValue); var rawItems = []; // This means "compare in a case insensitive manner." @@ -44354,6 +44520,18 @@ var ts; } } }); + // Remove imports when the imported declaration is already in the list and has the same name. + rawItems = ts.filter(rawItems, function (item) { + var decl = item.declaration; + if (decl.kind === 231 /* ImportClause */ || decl.kind === 234 /* ImportSpecifier */ || decl.kind === 229 /* ImportEqualsDeclaration */) { + var importer = checker.getSymbolAtLocation(decl.name); + var imported = checker.getAliasedSymbol(importer); + return importer.name !== imported.name; + } + else { + return true; + } + }); rawItems.sort(compareNavigateToItems); if (maxResultCount !== undefined) { rawItems = rawItems.slice(0, maxResultCount); @@ -44752,8 +44930,12 @@ var ts; return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); case 153 /* IndexSignature */: return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); + case 224 /* EnumDeclaration */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.enumElement); case 255 /* EnumMember */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 222 /* InterfaceDeclaration */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.interfaceElement); case 151 /* CallSignature */: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); case 152 /* ConstructSignature */: @@ -45714,7 +45896,7 @@ var ts; // To do this, the method will back parse the expression starting at the position required. it will try to parse the current expression as a generic type expression, if it did succeed it // will return the generic identifier that started the expression (e.g. "foo" in "foo= 0; --i) { + for (var i = exclusiveStartPosition - 1; i >= 0; i--) { if (nodeHasTokens(children[i])) { return children[i]; } @@ -47337,12 +47519,11 @@ var ts; if (!isStarted) { scanner.scan(); } - var t; var pos = scanner.getStartPos(); // Read leading trivia and token while (pos < endPos) { - var t_1 = scanner.getToken(); - if (!ts.isTrivia(t_1)) { + var t = scanner.getToken(); + if (!ts.isTrivia(t)) { break; } // consume leading trivia @@ -47350,7 +47531,7 @@ var ts; var item = { pos: pos, end: scanner.getStartPos(), - kind: t_1 + kind: t }; pos = scanner.getStartPos(); if (!leadingTrivia) { @@ -47690,6 +47871,7 @@ var ts; })(formatting = ts.formatting || (ts.formatting = {})); })(ts || (ts = {})); /// +/* tslint:disable:no-null-keyword */ /* @internal */ var ts; (function (ts) { @@ -47951,7 +48133,7 @@ var ts; this.SpaceAfterKeywordInControl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Keywords, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext), 2 /* Space */)); this.NoSpaceAfterKeywordInControl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Keywords, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext), 8 /* Delete */)); // Open Brace braces after function - //TypeScript: Function can have return types, which can be made of tons of different token kinds + // TypeScript: Function can have return types, which can be made of tons of different token kinds this.NewLineBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeMultilineBlockContext), 4 /* NewLine */), 1 /* CanDeleteNewLines */); // Open Brace braces after TypeScript module/class/interface this.NewLineBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsBeforeMultilineBlockContext), 4 /* NewLine */), 1 /* CanDeleteNewLines */); @@ -48092,17 +48274,17 @@ var ts; case 220 /* FunctionDeclaration */: case 147 /* MethodDeclaration */: case 146 /* MethodSignature */: - //case SyntaxKind.MemberFunctionDeclaration: + // case SyntaxKind.MemberFunctionDeclaration: case 149 /* GetAccessor */: case 150 /* SetAccessor */: - ///case SyntaxKind.MethodSignature: + // case SyntaxKind.MethodSignature: case 151 /* CallSignature */: case 179 /* FunctionExpression */: case 148 /* Constructor */: case 180 /* ArrowFunction */: - //case SyntaxKind.ConstructorDeclaration: - //case SyntaxKind.SimpleArrowFunctionExpression: - //case SyntaxKind.ParenthesizedArrowFunctionExpression: + // case SyntaxKind.ConstructorDeclaration: + // case SyntaxKind.SimpleArrowFunctionExpression: + // case SyntaxKind.ParenthesizedArrowFunctionExpression: case 222 /* InterfaceDeclaration */: return true; } @@ -48254,6 +48436,7 @@ var ts; })(formatting = ts.formatting || (ts.formatting = {})); })(ts || (ts = {})); /// +/* tslint:disable:no-null-keyword */ /* @internal */ var ts; (function (ts) { @@ -48271,9 +48454,9 @@ var ts; }; RulesMap.prototype.Initialize = function (rules) { this.mapRowLength = 138 /* LastToken */ + 1; - this.map = new Array(this.mapRowLength * this.mapRowLength); //new Array(this.mapRowLength * this.mapRowLength); + this.map = new Array(this.mapRowLength * this.mapRowLength); // new Array(this.mapRowLength * this.mapRowLength); // This array is used only during construction of the rulesbucket in the map - var rulesBucketConstructionStateList = new Array(this.map.length); //new Array(this.map.length); + var rulesBucketConstructionStateList = new Array(this.map.length); // new Array(this.map.length); this.FillRules(rules, rulesBucketConstructionStateList); return this.map; }; @@ -48285,7 +48468,7 @@ var ts; }; RulesMap.prototype.GetRuleBucketIndex = function (row, column) { var rulesBucketIndex = (row * this.mapRowLength) + column; - //Debug.Assert(rulesBucketIndex < this.map.Length, "Trying to access an index outside the array."); + // Debug.Assert(rulesBucketIndex < this.map.Length, "Trying to access an index outside the array."); return rulesBucketIndex; }; RulesMap.prototype.FillRule = function (rule, rulesBucketConstructionStateList) { @@ -48537,6 +48720,7 @@ var ts; /// /// /// +/* tslint:disable:no-null-keyword */ /* @internal */ var ts; (function (ts) { @@ -49058,7 +49242,7 @@ var ts; // if there are any tokens that logically belong to node and interleave child nodes // such tokens will be consumed in processChildNode for for the child that follows them ts.forEachChild(node, function (child) { - processChildNode(child, /*inheritedIndentation*/ -1 /* Unknown */, node, nodeDynamicIndentation, nodeStartLine, undecoratedNodeStartLine, /*isListElement*/ false); + processChildNode(child, /*inheritedIndentation*/ -1 /* Unknown */, node, nodeDynamicIndentation, nodeStartLine, undecoratedNodeStartLine, /*isListItem*/ false); }, function (nodes) { processChildNodes(nodes, node, nodeStartLine, nodeDynamicIndentation); }); @@ -49149,7 +49333,7 @@ var ts; var inheritedIndentation = -1 /* Unknown */; for (var i = 0; i < nodes.length; i++) { var child = nodes[i]; - inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListElement*/ true, /*isFirstListItem*/ i === 0); + inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListItem*/ true, /*isFirstListItem*/ i === 0); } if (listEndToken !== 0 /* Unknown */) { if (formattingScanner.isOnToken()) { @@ -49279,7 +49463,7 @@ var ts; // Handle the case where the next line is moved to be the end of this line. // In this case we don't indent the next line in the next pass. if (currentParent.getStart(sourceFile) === currentItem.pos) { - dynamicIndentation.recomputeIndentation(/*lineAdded*/ false); + dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ false); } } else if (rule.Operation.Action & 4 /* NewLine */ && currentStartLine === previousStartLine) { @@ -49288,7 +49472,7 @@ var ts; // In this case we indent token2 in the next pass but we set // sameLineIndent flag to notify the indenter that the indentation is within the line. if (currentParent.getStart(sourceFile) === currentItem.pos) { - dynamicIndentation.recomputeIndentation(/*lineAdded*/ true); + dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ true); } } // We need to trim trailing whitespace between the tokens if they were on different lines, and no rule was applied to put them on the same line @@ -49336,7 +49520,7 @@ var ts; else { parts = []; var startPos = commentRange.pos; - for (var line = startLine; line < endLine; ++line) { + for (var line = startLine; line < endLine; line++) { var endOfLine = ts.getEndLinePosition(line, sourceFile); parts.push({ pos: startPos, end: endOfLine }); startPos = ts.getStartPositionOfLine(line + 1, sourceFile); @@ -49355,7 +49539,7 @@ var ts; } // shift all parts on the delta size var delta = indentation - nonWhitespaceColumnInFirstPart.column; - for (var i = startIndex, len = parts.length; i < len; ++i, ++startLine) { + for (var i = startIndex, len = parts.length; i < len; i++, startLine++) { var startLinePos_1 = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart @@ -49371,7 +49555,7 @@ var ts; } } function trimTrailingWhitespacesForLines(line1, line2, range) { - for (var line = line1; line < line2; ++line) { + for (var line = line1; line < line2; line++) { var lineStartPosition = ts.getStartPositionOfLine(line, sourceFile); var lineEndPosition = ts.getEndLinePosition(line, sourceFile); // do not trim whitespaces in comments or template expression @@ -49422,7 +49606,6 @@ var ts; } } function applyRuleEdits(rule, previousRange, previousStartLine, currentRange, currentStartLine) { - var between; switch (rule.Operation.Action) { case 1 /* Ignore */: // no action required @@ -49459,14 +49642,6 @@ var ts; } } } - function isSomeBlock(kind) { - switch (kind) { - case 199 /* Block */: - case 226 /* ModuleBlock */: - return true; - } - return false; - } function getOpenTokenForList(node, list) { switch (node.kind) { case 148 /* Constructor */: @@ -49525,7 +49700,7 @@ var ts; internedTabsIndentation = []; } if (internedTabsIndentation[tabs] === undefined) { - internedTabsIndentation[tabs] = tabString = repeat('\t', tabs); + internedTabsIndentation[tabs] = tabString = repeat("\t", tabs); } else { tabString = internedTabsIndentation[tabs]; @@ -49550,7 +49725,7 @@ var ts; } function repeat(value, count) { var s = ""; - for (var i = 0; i < count; ++i) { + for (var i = 0; i < count; i++) { s += value; } return s; @@ -49866,7 +50041,7 @@ var ts; // walk toward the start of the list starting from current node and check if the line is the same for all items. // if end line for item [i - 1] differs from the start line for item [i] - find column of the first non-whitespace character on the line of item [i] var lineAndCharacter = getStartLineAndCharacterForNode(node, sourceFile); - for (var i = index - 1; i >= 0; --i) { + for (var i = index - 1; i >= 0; i--) { if (list[i].kind === 24 /* CommaToken */) { continue; } @@ -49893,7 +50068,7 @@ var ts; function findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options) { var character = 0; var column = 0; - for (var pos = startPos; pos < endPos; ++pos) { + for (var pos = startPos; pos < endPos; pos++) { var ch = sourceFile.text.charCodeAt(pos); if (!ts.isWhiteSpace(ch)) { break; @@ -49987,7 +50162,7 @@ var ts; Function returns true when the parent node should indent the given child by an explicit rule */ function shouldIndentChildNode(parent, child) { - return nodeContentIsAlwaysIndented(parent.kind) || nodeWillIndentChild(parent, child, false); + return nodeContentIsAlwaysIndented(parent.kind) || nodeWillIndentChild(parent, child, /*indentByDefault*/ false); } SmartIndenter.shouldIndentChildNode = shouldIndentChildNode; })(SmartIndenter = formatting.SmartIndenter || (formatting.SmartIndenter = {})); @@ -50809,49 +50984,55 @@ var ts; (function (ScriptElementKind) { ScriptElementKind.unknown = ""; ScriptElementKind.warning = "warning"; - // predefined type (void) or keyword (class) + /** predefined type (void) or keyword (class) */ ScriptElementKind.keyword = "keyword"; - // top level script node + /** top level script node */ ScriptElementKind.scriptElement = "script"; - // module foo {} + /** module foo {} */ ScriptElementKind.moduleElement = "module"; - // class X {} + /** class X {} */ ScriptElementKind.classElement = "class"; - // var x = class X {} + /** var x = class X {} */ ScriptElementKind.localClassElement = "local class"; - // interface Y {} + /** interface Y {} */ ScriptElementKind.interfaceElement = "interface"; - // type T = ... + /** type T = ... */ ScriptElementKind.typeElement = "type"; - // enum E + /** enum E */ ScriptElementKind.enumElement = "enum"; - // Inside module and script only - // const v = .. + /** + * Inside module and script only + * const v = .. + */ ScriptElementKind.variableElement = "var"; - // Inside function + /** Inside function */ ScriptElementKind.localVariableElement = "local var"; - // Inside module and script only - // function f() { } + /** + * Inside module and script only + * function f() { } + */ ScriptElementKind.functionElement = "function"; - // Inside function + /** Inside function */ ScriptElementKind.localFunctionElement = "local function"; - // class X { [public|private]* foo() {} } + /** class X { [public|private]* foo() {} } */ ScriptElementKind.memberFunctionElement = "method"; - // class X { [public|private]* [get|set] foo:number; } + /** class X { [public|private]* [get|set] foo:number; } */ ScriptElementKind.memberGetAccessorElement = "getter"; ScriptElementKind.memberSetAccessorElement = "setter"; - // class X { [public|private]* foo:number; } - // interface Y { foo:number; } + /** + * class X { [public|private]* foo:number; } + * interface Y { foo:number; } + */ ScriptElementKind.memberVariableElement = "property"; - // class X { constructor() { } } + /** class X { constructor() { } } */ ScriptElementKind.constructorImplementationElement = "constructor"; - // interface Y { ():number; } + /** interface Y { ():number; } */ ScriptElementKind.callSignatureElement = "call"; - // interface Y { []:number; } + /** interface Y { []:number; } */ ScriptElementKind.indexSignatureElement = "index"; - // interface Y { new():Y; } + /** interface Y { new():Y; } */ ScriptElementKind.constructSignatureElement = "construct"; - // function foo(*Y*: string) + /** function foo(*Y*: string) */ ScriptElementKind.parameterElement = "parameter"; ScriptElementKind.typeParameterElement = "type parameter"; ScriptElementKind.primitiveType = "primitive type"; @@ -52236,9 +52417,9 @@ var ts; // Check if the caret is at the end of an identifier; this is a partial identifier that we want to complete: e.g. a.toS| // Skip this partial identifier and adjust the contextToken to the token that precedes it. if (contextToken && position <= contextToken.end && ts.isWord(contextToken.kind)) { - var start_6 = new Date().getTime(); + var start_5 = new Date().getTime(); contextToken = ts.findPrecedingToken(contextToken.getFullStart(), sourceFile); - log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_6)); + log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_5)); } // Find the node where completion is requested on. // Also determine whether we are trying to complete with members of that node @@ -52518,13 +52699,13 @@ var ts; || contextToken.kind === 166 /* StringLiteralType */ || contextToken.kind === 10 /* RegularExpressionLiteral */ || ts.isTemplateLiteralKind(contextToken.kind)) { - var start_7 = contextToken.getStart(); + var start_6 = contextToken.getStart(); var end = contextToken.getEnd(); // To be "in" one of these literals, the position has to be: // 1. entirely within the token text. // 2. at the end position of an unterminated token. // 3. at the end of a regular expression (due to trailing flags like '/foo/g'). - if (start_7 < position && position < end) { + if (start_6 < position && position < end) { return true; } if (position === end) { @@ -53759,8 +53940,7 @@ var ts; } function getDocumentHighlights(fileName, position, filesToSearch) { synchronizeHostData(); - filesToSearch = ts.map(filesToSearch, ts.normalizeSlashes); - var sourceFilesToSearch = ts.filter(program.getSourceFiles(), function (f) { return ts.contains(filesToSearch, f.fileName); }); + var sourceFilesToSearch = ts.map(filesToSearch, function (f) { return program.getSourceFile(f); }); var sourceFile = getValidSourceFile(fileName); var node = ts.getTouchingWord(sourceFile, position); if (!node) { @@ -55150,7 +55330,8 @@ var ts; /// NavigateTo function getNavigateToItems(searchValue, maxResultCount) { synchronizeHostData(); - return ts.NavigateTo.getNavigateToItems(program, cancellationToken, searchValue, maxResultCount); + var checker = getProgram().getTypeChecker(); + return ts.NavigateTo.getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount); } function getEmitOutput(fileName) { synchronizeHostData(); @@ -57559,6 +57740,9 @@ var ts; LanguageServiceShimHostAdapter.prototype.getCurrentDirectory = function () { return this.shimHost.getCurrentDirectory(); }; + LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { + return this.shimHost.getDirectories(path); + }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); }; diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index cd459201d8b..67530e211bc 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -261,7 +261,7 @@ declare namespace ts { ModuleDeclaration = 225, ModuleBlock = 226, CaseBlock = 227, - GlobalModuleExportDeclaration = 228, + NamespaceExportDeclaration = 228, ImportEqualsDeclaration = 229, ImportDeclaration = 230, ImportClause = 231, @@ -934,7 +934,7 @@ declare namespace ts { interface NamespaceImport extends Declaration { name: Identifier; } - interface GlobalModuleExportDeclaration extends DeclarationStatement { + interface NamespaceExportDeclaration extends DeclarationStatement { name: Identifier; moduleReference: LiteralLikeNode; } @@ -1329,7 +1329,7 @@ declare namespace ts { FunctionScopedVariableExcludes = 107454, BlockScopedVariableExcludes = 107455, ParameterExcludes = 107455, - PropertyExcludes = 107455, + PropertyExcludes = 0, EnumMemberExcludes = 107455, FunctionExcludes = 106927, ClassExcludes = 899519, @@ -1554,6 +1554,7 @@ declare namespace ts { allowJs?: boolean; noImplicitUseStrict?: boolean; strictNullChecks?: boolean; + skipLibCheck?: boolean; listEmittedFiles?: boolean; lib?: string[]; types?: string[]; @@ -1627,6 +1628,7 @@ declare namespace ts { trace?(s: string): void; directoryExists?(directoryName: string): boolean; realpath?(path: string): string; + getCurrentDirectory?(): string; } interface ResolvedModule { resolvedFileName: string; @@ -1650,6 +1652,7 @@ declare namespace ts { getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; + getDefaultTypeDirectiveNames?(rootPath: string): string[]; writeFile: WriteFileCallback; getCurrentDirectory(): string; getCanonicalFileName(fileName: string): string; @@ -1693,6 +1696,7 @@ declare namespace ts { createDirectory(path: string): void; getExecutingFilePath(): string; getCurrentDirectory(): string; + getDirectories(path: string): string[]; readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getModifiedTime?(path: string): Date; createHash?(data: string): string; @@ -1812,6 +1816,7 @@ declare namespace ts { function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; + function getDefaultTypeDirectiveNames(options: CompilerOptions, rootFiles: string[], host: CompilerHost): string[]; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program; } declare namespace ts { @@ -2345,26 +2350,55 @@ declare namespace ts { namespace ScriptElementKind { const unknown: string; const warning: string; + /** predefined type (void) or keyword (class) */ const keyword: string; + /** top level script node */ const scriptElement: string; + /** module foo {} */ const moduleElement: string; + /** class X {} */ const classElement: string; + /** var x = class X {} */ const localClassElement: string; + /** interface Y {} */ const interfaceElement: string; + /** type T = ... */ const typeElement: string; + /** enum E */ const enumElement: string; + /** + * Inside module and script only + * const v = .. + */ const variableElement: string; + /** Inside function */ const localVariableElement: string; + /** + * Inside module and script only + * function f() { } + */ const functionElement: string; + /** Inside function */ const localFunctionElement: string; + /** class X { [public|private]* foo() {} } */ const memberFunctionElement: string; + /** class X { [public|private]* [get|set] foo:number; } */ const memberGetAccessorElement: string; const memberSetAccessorElement: string; + /** + * class X { [public|private]* foo:number; } + * interface Y { foo:number; } + */ const memberVariableElement: string; + /** class X { constructor() { } } */ const constructorImplementationElement: string; + /** interface Y { ():number; } */ const callSignatureElement: string; + /** interface Y { []:number; } */ const indexSignatureElement: string; + /** interface Y { new():Y; } */ const constructSignatureElement: string; + /** function foo(*Y*: string) */ const parameterElement: string; const typeParameterElement: string; const primitiveType: string; diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index e78eda7b0bb..19fffd35501 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -271,7 +271,7 @@ var ts; SyntaxKind[SyntaxKind["ModuleDeclaration"] = 225] = "ModuleDeclaration"; SyntaxKind[SyntaxKind["ModuleBlock"] = 226] = "ModuleBlock"; SyntaxKind[SyntaxKind["CaseBlock"] = 227] = "CaseBlock"; - SyntaxKind[SyntaxKind["GlobalModuleExportDeclaration"] = 228] = "GlobalModuleExportDeclaration"; + SyntaxKind[SyntaxKind["NamespaceExportDeclaration"] = 228] = "NamespaceExportDeclaration"; SyntaxKind[SyntaxKind["ImportEqualsDeclaration"] = 229] = "ImportEqualsDeclaration"; SyntaxKind[SyntaxKind["ImportDeclaration"] = 230] = "ImportDeclaration"; SyntaxKind[SyntaxKind["ImportClause"] = 231] = "ImportClause"; @@ -561,7 +561,7 @@ var ts; // they can not merge with anything in the value space SymbolFlags[SymbolFlags["BlockScopedVariableExcludes"] = 107455] = "BlockScopedVariableExcludes"; SymbolFlags[SymbolFlags["ParameterExcludes"] = 107455] = "ParameterExcludes"; - SymbolFlags[SymbolFlags["PropertyExcludes"] = 107455] = "PropertyExcludes"; + SymbolFlags[SymbolFlags["PropertyExcludes"] = 0] = "PropertyExcludes"; SymbolFlags[SymbolFlags["EnumMemberExcludes"] = 107455] = "EnumMemberExcludes"; SymbolFlags[SymbolFlags["FunctionExcludes"] = 106927] = "FunctionExcludes"; SymbolFlags[SymbolFlags["ClassExcludes"] = 899519] = "ClassExcludes"; @@ -1841,6 +1841,10 @@ var ts; } return result.sort(); } + function getDirectories(path) { + var folder = fso.GetFolder(path); + return getNames(folder.subfolders); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -1895,6 +1899,7 @@ var ts; getCurrentDirectory: function () { return new ActiveXObject("WScript.Shell").CurrentDirectory; }, + getDirectories: getDirectories, readDirectory: readDirectory, exit: function (exitCode) { try { @@ -2057,6 +2062,9 @@ var ts; function directoryExists(path) { return fileSystemEntryExists(path, 1 /* Directory */); } + function getDirectories(path) { + return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1 /* Directory */); }); + } function readDirectory(path, extension, exclude) { var result = []; exclude = ts.map(exclude, function (s) { return getCanonicalPath(ts.combinePaths(path, s)); }); @@ -2157,6 +2165,7 @@ var ts; getCurrentDirectory: function () { return process.cwd(); }, + getDirectories: getDirectories, readDirectory: readDirectory, getModifiedTime: function (path) { try { @@ -2209,6 +2218,7 @@ var ts; createDirectory: ChakraHost.createDirectory, getExecutingFilePath: function () { return ChakraHost.executingFile; }, getCurrentDirectory: function () { return ChakraHost.currentDirectory; }, + getDirectories: ChakraHost.getDirectories, readDirectory: ChakraHost.readDirectory, exit: ChakraHost.quit, realpath: realpath @@ -2347,7 +2357,7 @@ var ts; or_expected: { code: 1144, category: ts.DiagnosticCategory.Error, key: "or_expected_1144", message: "'{' or ';' expected." }, Declaration_expected: { code: 1146, category: ts.DiagnosticCategory.Error, key: "Declaration_expected_1146", message: "Declaration expected." }, Import_declarations_in_a_namespace_cannot_reference_a_module: { code: 1147, category: ts.DiagnosticCategory.Error, key: "Import_declarations_in_a_namespace_cannot_reference_a_module_1147", message: "Import declarations in a namespace cannot reference a module." }, - Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting__1148", message: "Cannot compile modules unless the '--module' flag is provided with a valid module type. Consider setting the 'module' compiler option in a 'tsconfig.json' file." }, + Cannot_use_imports_exports_or_module_augmentations_when_module_is_none: { code: 1148, category: ts.DiagnosticCategory.Error, key: "Cannot_use_imports_exports_or_module_augmentations_when_module_is_none_1148", message: "Cannot use imports, exports, or module augmentations when '--module' is 'none'." }, File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: ts.DiagnosticCategory.Error, key: "File_name_0_differs_from_already_included_file_name_1_only_in_casing_1149", message: "File name '{0}' differs from already included file name '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: ts.DiagnosticCategory.Error, key: "new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead_1150", message: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, const_declarations_must_be_initialized: { code: 1155, category: ts.DiagnosticCategory.Error, key: "const_declarations_must_be_initialized_1155", message: "'const' declarations must be initialized" }, @@ -2717,6 +2727,8 @@ var ts; this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation: { code: 2683, category: ts.DiagnosticCategory.Error, key: "this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_2683", message: "'this' implicitly has type 'any' because it does not have a type annotation." }, The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1: { code: 2684, category: ts.DiagnosticCategory.Error, key: "The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1_2684", message: "The 'this' context of type '{0}' is not assignable to method's 'this' of type '{1}'." }, The_this_types_of_each_signature_are_incompatible: { code: 2685, category: ts.DiagnosticCategory.Error, key: "The_this_types_of_each_signature_are_incompatible_2685", message: "The 'this' types of each signature are incompatible." }, + Identifier_0_must_be_imported_from_a_module: { code: 2686, category: ts.DiagnosticCategory.Error, key: "Identifier_0_must_be_imported_from_a_module_2686", message: "Identifier '{0}' must be imported from a module" }, + All_declarations_of_0_must_have_identical_modifiers: { code: 2687, category: ts.DiagnosticCategory.Error, key: "All_declarations_of_0_must_have_identical_modifiers_2687", message: "All declarations of '{0}' must have identical modifiers." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import_declaration_0_is_using_private_name_1_4000", message: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", message: "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: ts.DiagnosticCategory.Error, key: "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", message: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -2810,7 +2822,7 @@ var ts; Option_paths_cannot_be_used_without_specifying_baseUrl_option: { code: 5060, category: ts.DiagnosticCategory.Error, key: "Option_paths_cannot_be_used_without_specifying_baseUrl_option_5060", message: "Option 'paths' cannot be used without specifying '--baseUrl' option." }, Pattern_0_can_have_at_most_one_Asterisk_character: { code: 5061, category: ts.DiagnosticCategory.Error, key: "Pattern_0_can_have_at_most_one_Asterisk_character_5061", message: "Pattern '{0}' can have at most one '*' character" }, Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character: { code: 5062, category: ts.DiagnosticCategory.Error, key: "Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character_5062", message: "Substitution '{0}' in pattern '{1}' in can have at most one '*' character" }, - Substututions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substututions_for_pattern_0_should_be_an_array_5063", message: "Substututions for pattern '{0}' should be an array." }, + Substitutions_for_pattern_0_should_be_an_array: { code: 5063, category: ts.DiagnosticCategory.Error, key: "Substitutions_for_pattern_0_should_be_an_array_5063", message: "Substitutions for pattern '{0}' should be an array." }, Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2: { code: 5064, category: ts.DiagnosticCategory.Error, key: "Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2_5064", message: "Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: ts.DiagnosticCategory.Message, key: "Concatenate_and_emit_output_to_single_file_6001", message: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: ts.DiagnosticCategory.Message, key: "Generates_corresponding_d_ts_file_6002", message: "Generates corresponding '.d.ts' file." }, @@ -2823,6 +2835,7 @@ var ts; Do_not_emit_comments_to_output: { code: 6009, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_comments_to_output_6009", message: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: ts.DiagnosticCategory.Message, key: "Do_not_emit_outputs_6010", message: "Do not emit outputs." }, Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking: { code: 6011, category: ts.DiagnosticCategory.Message, key: "Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typech_6011", message: "Allow default imports from modules with no default export. This does not affect code emit, just typechecking." }, + Skip_type_checking_of_declaration_files: { code: 6012, category: ts.DiagnosticCategory.Message, key: "Skip_type_checking_of_declaration_files_6012", message: "Skip type checking of declaration files." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015: { code: 6015, category: ts.DiagnosticCategory.Message, key: "Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015_6015", message: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'" }, Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015: { code: 6016, category: ts.DiagnosticCategory.Message, key: "Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015_6016", message: "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'" }, Print_this_message: { code: 6017, category: ts.DiagnosticCategory.Message, key: "Print_this_message_6017", message: "Print this message." }, @@ -2924,6 +2937,7 @@ var ts; Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set: { code: 6128, category: ts.DiagnosticCategory.Message, key: "Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set_6128", message: "======== Resolving type reference directive '{0}', containing file not set, root directory not set. ========" }, The_config_file_0_found_doesn_t_contain_any_source_files: { code: 6129, category: ts.DiagnosticCategory.Error, key: "The_config_file_0_found_doesn_t_contain_any_source_files_6129", message: "The config file '{0}' found doesn't contain any source files." }, Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, + Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -6172,7 +6186,7 @@ var ts; // export default ... function isAliasSymbolDeclaration(node) { return node.kind === 229 /* ImportEqualsDeclaration */ || - node.kind === 228 /* GlobalModuleExportDeclaration */ || + node.kind === 228 /* NamespaceExportDeclaration */ || node.kind === 231 /* ImportClause */ && !!node.name || node.kind === 232 /* NamespaceImport */ || node.kind === 234 /* ImportSpecifier */ || @@ -6301,7 +6315,7 @@ var ts; } ts.isWellKnownSymbolSyntactically = isWellKnownSymbolSyntactically; function getPropertyNameForPropertyNameNode(name) { - if (name.kind === 69 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */) { + if (name.kind === 69 /* Identifier */ || name.kind === 9 /* StringLiteral */ || name.kind === 8 /* NumericLiteral */ || name.kind === 142 /* Parameter */) { return name.text; } if (name.kind === 140 /* ComputedPropertyName */) { @@ -7773,7 +7787,7 @@ var ts; case 231 /* ImportClause */: return visitNode(cbNode, node.name) || visitNode(cbNode, node.namedBindings); - case 228 /* GlobalModuleExportDeclaration */: + case 228 /* NamespaceExportDeclaration */: return visitNode(cbNode, node.name); case 232 /* NamespaceImport */: return visitNode(cbNode, node.name); @@ -12182,7 +12196,7 @@ var ts; return nextToken() === 39 /* SlashToken */; } function parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers) { - var exportDeclaration = createNode(228 /* GlobalModuleExportDeclaration */, fullStart); + var exportDeclaration = createNode(228 /* NamespaceExportDeclaration */, fullStart); exportDeclaration.decorators = decorators; exportDeclaration.modifiers = modifiers; parseExpected(116 /* AsKeyword */); @@ -15018,10 +15032,10 @@ var ts; case 145 /* PropertyDeclaration */: case 144 /* PropertySignature */: case 266 /* JSDocRecordMember */: - return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 107455 /* PropertyExcludes */); + return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 0 /* PropertyExcludes */); case 253 /* PropertyAssignment */: case 254 /* ShorthandPropertyAssignment */: - return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */); + return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 0 /* PropertyExcludes */); case 255 /* EnumMember */: return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */); case 247 /* JsxSpreadAttribute */: @@ -15037,7 +15051,7 @@ var ts; // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. - return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */); + return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 0 /* PropertyExcludes */ : 99263 /* MethodExcludes */); case 220 /* FunctionDeclaration */: return bindFunctionDeclaration(node); case 148 /* Constructor */: @@ -15081,8 +15095,8 @@ var ts; case 234 /* ImportSpecifier */: case 238 /* ExportSpecifier */: return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); - case 228 /* GlobalModuleExportDeclaration */: - return bindGlobalModuleExportDeclaration(node); + case 228 /* NamespaceExportDeclaration */: + return bindNamespaceExportDeclaration(node); case 231 /* ImportClause */: return bindImportClause(node); case 236 /* ExportDeclaration */: @@ -15120,14 +15134,14 @@ var ts; } else if (boundExpression.kind === 69 /* Identifier */ && node.kind === 235 /* ExportAssignment */) { // An export default clause with an identifier exports all meanings of that identifier - declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); + declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 0 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); } else { // An export default clause with an expression exports a value - declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); + declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 0 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); } } - function bindGlobalModuleExportDeclaration(node) { + function bindNamespaceExportDeclaration(node) { if (node.modifiers && node.modifiers.length) { file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Modifiers_cannot_appear_here)); } @@ -15186,7 +15200,7 @@ var ts; if (container.kind === 179 /* FunctionExpression */ || container.kind === 220 /* FunctionDeclaration */) { container.symbol.members = container.symbol.members || {}; // It's acceptable for multiple 'this' assignments of the same identifier to occur - declareSymbol(container.symbol.members, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ & ~4 /* Property */); + declareSymbol(container.symbol.members, container.symbol, node, 4 /* Property */, 0 /* PropertyExcludes */ & ~4 /* Property */); } } function bindPrototypePropertyAssignment(node) { @@ -15209,7 +15223,7 @@ var ts; funcSymbol.members = {}; } // Declare the method/property - declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4 /* Property */, 107455 /* PropertyExcludes */); + declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, 4 /* Property */, 0 /* PropertyExcludes */); } function bindCallExpression(node) { // We're only inspecting call expressions to detect CommonJS modules, so we can skip @@ -15310,7 +15324,7 @@ var ts; // containing class. if (ts.isParameterPropertyDeclaration(node)) { var classDeclaration = node.parent.parent; - declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 0 /* PropertyExcludes */); } } function bindFunctionDeclaration(node) { @@ -15696,7 +15710,7 @@ var ts; if (flags & 1 /* FunctionScopedVariable */) result |= 107454 /* FunctionScopedVariableExcludes */; if (flags & 4 /* Property */) - result |= 107455 /* PropertyExcludes */; + result |= 0 /* PropertyExcludes */; if (flags & 8 /* EnumMember */) result |= 107455 /* EnumMemberExcludes */; if (flags & 16 /* Function */) @@ -15982,6 +15996,7 @@ var ts; var propertyWithInvalidInitializer; var errorLocation = location; var grandparent; + var isInExternalModule = false; loop: while (location) { // Locals of a source file are not in scope (because they get merged into the global symbol table) if (location.locals && !isGlobalSourceFile(location)) { @@ -16024,6 +16039,7 @@ var ts; case 256 /* SourceFile */: if (!ts.isExternalOrCommonJsModule(location)) break; + isInExternalModule = true; case 225 /* ModuleDeclaration */: var moduleExports = getSymbolOfNode(location).exports; if (location.kind === 256 /* SourceFile */ || ts.isAmbientModule(location)) { @@ -16207,6 +16223,13 @@ var ts; checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation); } } + // If we're in an external module, we can't reference symbols created from UMD export declarations + if (result && isInExternalModule) { + var decls = result.declarations; + if (decls && decls.length === 1 && decls[0].kind === 228 /* NamespaceExportDeclaration */) { + error(errorLocation, ts.Diagnostics.Identifier_0_must_be_imported_from_a_module, name); + } + } } return result; } @@ -16409,7 +16432,7 @@ var ts; return getTargetOfExportSpecifier(node); case 235 /* ExportAssignment */: return getTargetOfExportAssignment(node); - case 228 /* GlobalModuleExportDeclaration */: + case 228 /* NamespaceExportDeclaration */: return getTargetOfGlobalModuleExportDeclaration(node); } } @@ -17883,7 +17906,7 @@ var ts; // assigned by contextual typing. function getTypeForBindingElementParent(node) { var symbol = getSymbolOfNode(node); - return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node); + return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false); } function getTextOfPropertyName(name) { switch (name.kind) { @@ -18009,7 +18032,7 @@ var ts; return strictNullChecks && optional ? addNullableKind(type, 32 /* Undefined */) : type; } // Return the inferred type for a variable, parameter, or property declaration - function getTypeForVariableLikeDeclaration(declaration) { + function getTypeForVariableLikeDeclaration(declaration, includeOptionality) { if (declaration.flags & 134217728 /* JavaScriptFile */) { // If this is a variable in a JavaScript file, then use the JSDoc type (if it has // one as its type), otherwise fallback to the below standard TS codepaths to @@ -18035,7 +18058,7 @@ var ts; } // Use type from type annotation if one is present if (declaration.type) { - return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ !!declaration.questionToken); + return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality); } if (declaration.kind === 142 /* Parameter */) { var func = declaration.parent; @@ -18056,12 +18079,12 @@ var ts; ? getContextuallyTypedThisType(func) : getContextuallyTypedParameterType(declaration); if (type) { - return addOptionality(type, /*optional*/ !!declaration.questionToken); + return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality); } } // Use the type of the initializer expression if one is present if (declaration.initializer) { - return addOptionality(checkExpressionCached(declaration.initializer), /*optional*/ !!declaration.questionToken); + return addOptionality(checkExpressionCached(declaration.initializer), /*optional*/ declaration.questionToken && includeOptionality); } // If it is a short-hand property assignment, use the type of the identifier if (declaration.kind === 254 /* ShorthandPropertyAssignment */) { @@ -18155,7 +18178,7 @@ var ts; // binding pattern [x, s = ""]. Because the contextual type is a tuple type, the resulting type of [1, "one"] is the // tuple type [number, string]. Thus, the type inferred for 'x' is number and the type inferred for 's' is string. function getWidenedTypeForVariableLikeDeclaration(declaration, reportErrors) { - var type = getTypeForVariableLikeDeclaration(declaration); + var type = getTypeForVariableLikeDeclaration(declaration, /*includeOptionality*/ true); if (type) { if (reportErrors) { reportErrorsFromWidening(declaration, type); @@ -20719,7 +20742,7 @@ var ts; return isIdenticalTo(source, target); } if (!(target.flags & 134217728 /* Never */)) { - if (target.flags & 1 /* Any */) + if (target.flags & 1 /* Any */ || source.flags & 134217728 /* Never */) return -1 /* True */; if (source.flags & 32 /* Undefined */) { if (!strictNullChecks || target.flags & (32 /* Undefined */ | 16 /* Void */) || source === emptyArrayElementType) @@ -20739,7 +20762,7 @@ var ts; if (source.flags & 256 /* StringLiteral */ && target === stringType) return -1 /* True */; if (relation === assignableRelation || relation === comparableRelation) { - if (source.flags & (1 /* Any */ | 134217728 /* Never */)) + if (source.flags & 1 /* Any */) return -1 /* True */; if (source === numberType && target.flags & 128 /* Enum */) return -1 /* True */; @@ -21634,41 +21657,52 @@ var ts; getSignaturesOfType(type, 0 /* Call */).length === 0 && getSignaturesOfType(type, 1 /* Construct */).length === 0; } + function createTransientSymbol(source, type) { + var symbol = createSymbol(source.flags | 67108864 /* Transient */, source.name); + symbol.declarations = source.declarations; + symbol.parent = source.parent; + symbol.type = type; + symbol.target = source; + if (source.valueDeclaration) { + symbol.valueDeclaration = source.valueDeclaration; + } + return symbol; + } + function transformTypeOfMembers(type, f) { + var members = {}; + for (var _i = 0, _a = getPropertiesOfObjectType(type); _i < _a.length; _i++) { + var property = _a[_i]; + var original = getTypeOfSymbol(property); + var updated = f(original); + members[property.name] = updated === original ? property : createTransientSymbol(property, updated); + } + ; + return members; + } + /** + * If the the provided object literal is subject to the excess properties check, + * create a new that is exempt. Recursively mark object literal members as exempt. + * Leave signatures alone since they are not subject to the check. + */ function getRegularTypeOfObjectLiteral(type) { - if (type.flags & 1048576 /* FreshObjectLiteral */) { - var regularType = type.regularType; - if (!regularType) { - regularType = createType(type.flags & ~1048576 /* FreshObjectLiteral */); - regularType.symbol = type.symbol; - regularType.members = type.members; - regularType.properties = type.properties; - regularType.callSignatures = type.callSignatures; - regularType.constructSignatures = type.constructSignatures; - regularType.stringIndexInfo = type.stringIndexInfo; - regularType.numberIndexInfo = type.numberIndexInfo; - type.regularType = regularType; - } + if (!(type.flags & 1048576 /* FreshObjectLiteral */)) { + return type; + } + var regularType = type.regularType; + if (regularType) { return regularType; } - return type; + var resolved = type; + var members = transformTypeOfMembers(type, getRegularTypeOfObjectLiteral); + var regularNew = createAnonymousType(resolved.symbol, members, resolved.callSignatures, resolved.constructSignatures, resolved.stringIndexInfo, resolved.numberIndexInfo); + regularNew.flags = resolved.flags & ~1048576 /* FreshObjectLiteral */; + type.regularType = regularNew; + return regularNew; } function getWidenedTypeOfObjectLiteral(type) { - var properties = getPropertiesOfObjectType(type); - var members = {}; - ts.forEach(properties, function (p) { - 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 members = transformTypeOfMembers(type, function (prop) { + var widened = getWidenedType(prop); + return prop === widened ? prop : widened; }); var stringIndexInfo = getIndexInfoOfType(type, 0 /* String */); var numberIndexInfo = getIndexInfoOfType(type, 1 /* Number */); @@ -23224,7 +23258,7 @@ var ts; } return nodeCheckFlag === 512 /* SuperStatic */ ? getBaseConstructorTypeOfClass(classType) - : baseClassType; + : getTypeWithThisArgument(baseClassType, classType.thisType); function isLegalUsageOfSuperExpression(container) { if (!container) { return false; @@ -25936,7 +25970,7 @@ var ts; var types = void 0; var funcIsGenerator = !!func.asteriskToken; if (funcIsGenerator) { - types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + types = checkAndAggregateYieldOperandTypes(func, contextualMapper); if (types.length === 0) { var iterableIteratorAny = createIterableIteratorType(anyType); if (compilerOptions.noImplicitAny) { @@ -25946,8 +25980,7 @@ var ts; } } else { - var hasImplicitReturn = !!(func.flags & 32768 /* HasImplicitReturn */); - types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper, isAsync, hasImplicitReturn); + types = checkAndAggregateReturnExpressionTypes(func, contextualMapper); if (!types) { return neverType; } @@ -26001,9 +26034,9 @@ var ts; return widenedType; } } - function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + function checkAndAggregateYieldOperandTypes(func, contextualMapper) { var aggregatedTypes = []; - ts.forEachYieldExpression(body, function (yieldExpression) { + ts.forEachYieldExpression(func.body, function (yieldExpression) { var expr = yieldExpression.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -26018,10 +26051,12 @@ var ts; }); return aggregatedTypes; } - function checkAndAggregateReturnExpressionTypes(body, contextualMapper, isAsync, hasImplicitReturn) { + function checkAndAggregateReturnExpressionTypes(func, contextualMapper) { + var isAsync = ts.isAsyncFunctionLike(func); var aggregatedTypes = []; - var hasOmittedExpressions = false; - ts.forEachReturnStatement(body, function (returnStatement) { + var hasReturnWithNoExpression = !!(func.flags & 32768 /* HasImplicitReturn */); + var hasReturnOfTypeNever = false; + ts.forEachReturnStatement(func.body, function (returnStatement) { var expr = returnStatement.expression; if (expr) { var type = checkExpressionCached(expr, contextualMapper); @@ -26030,20 +26065,24 @@ var ts; // Promise/A+ compatible implementation will always assimilate any foreign promise, so the // return type of the body should be unwrapped to its awaited type, which should be wrapped in // the native Promise type by the caller. - type = checkAwaitedType(type, body.parent, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); + type = checkAwaitedType(type, func, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } - if (type !== neverType && !ts.contains(aggregatedTypes, type)) { + if (type === neverType) { + hasReturnOfTypeNever = true; + } + else if (!ts.contains(aggregatedTypes, type)) { aggregatedTypes.push(type); } } else { - hasOmittedExpressions = true; + hasReturnWithNoExpression = true; } }); - if (aggregatedTypes.length === 0 && !hasOmittedExpressions && !hasImplicitReturn) { + if (aggregatedTypes.length === 0 && !hasReturnWithNoExpression && (hasReturnOfTypeNever || + func.kind === 179 /* FunctionExpression */ || func.kind === 180 /* ArrowFunction */)) { return undefined; } - if (strictNullChecks && aggregatedTypes.length && (hasOmittedExpressions || hasImplicitReturn)) { + if (strictNullChecks && aggregatedTypes.length && hasReturnWithNoExpression) { if (!ts.contains(aggregatedTypes, undefinedType)) { aggregatedTypes.push(undefinedType); } @@ -26215,8 +26254,14 @@ var ts; if (symbol.flags & 4 /* Property */ && (expr.kind === 172 /* PropertyAccessExpression */ || expr.kind === 173 /* ElementAccessExpression */) && expr.expression.kind === 97 /* ThisKeyword */) { + // Look for if this is the constructor for the class that `symbol` is a property of. var func = ts.getContainingFunction(expr); - return !(func && func.kind === 148 /* Constructor */ && func.parent === symbol.valueDeclaration.parent); + if (!(func && func.kind === 148 /* Constructor */)) + return true; + // If func.parent is a class and symbol is a (readonly) property of that class, or + // if func is a constructor and symbol is a (readonly) parameter property declared in it, + // then symbol is writeable here. + return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent); } return true; } @@ -27148,6 +27193,79 @@ var ts; } } } + function checkClassForDuplicateDeclarations(node) { + var getter = 1, setter = 2, property = getter | setter; + var instanceNames = {}; + var staticNames = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 148 /* Constructor */) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var param = _c[_b]; + if (ts.isParameterPropertyDeclaration(param)) { + addName(instanceNames, param.name, param.name.text, property); + } + } + } + else { + var static = ts.forEach(member.modifiers, function (m) { return m.kind === 113 /* StaticKeyword */; }); + var names = static ? staticNames : instanceNames; + var memberName = member.name && ts.getPropertyNameForPropertyNameNode(member.name); + if (memberName) { + switch (member.kind) { + case 149 /* GetAccessor */: + addName(names, member.name, memberName, getter); + break; + case 150 /* SetAccessor */: + addName(names, member.name, memberName, setter); + break; + case 145 /* PropertyDeclaration */: + addName(names, member.name, memberName, property); + break; + } + } + } + } + function addName(names, location, name, meaning) { + if (ts.hasProperty(names, name)) { + var prev = names[name]; + if (prev & meaning) { + error(location, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(location)); + } + else { + names[name] = prev | meaning; + } + } + else { + names[name] = meaning; + } + } + } + function checkObjectTypeForDuplicateDeclarations(node) { + var names = {}; + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind == 144 /* PropertySignature */) { + var memberName = void 0; + switch (member.name.kind) { + case 9 /* StringLiteral */: + case 8 /* NumericLiteral */: + case 69 /* Identifier */: + memberName = member.name.text; + break; + default: + continue; + } + if (ts.hasProperty(names, memberName)) { + error(member.symbol.valueDeclaration.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + error(member.name, ts.Diagnostics.Duplicate_identifier_0, memberName); + } + else { + names[memberName] = true; + } + } + } + } function checkTypeForDuplicateIndexSignatures(node) { if (node.kind === 222 /* InterfaceDeclaration */) { var nodeSymbol = getSymbolOfNode(node); @@ -27399,6 +27517,7 @@ var ts; var type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); + checkObjectTypeForDuplicateDeclarations(node); } } function checkArrayType(node) { @@ -28444,6 +28563,10 @@ var ts; if (node.initializer) { checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, /*headMessage*/ undefined); } + if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { + error(symbol.valueDeclaration.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + error(node.name, ts.Diagnostics.All_declarations_of_0_must_have_identical_modifiers, ts.declarationNameToString(node.name)); + } } if (node.kind !== 145 /* PropertyDeclaration */ && node.kind !== 144 /* PropertySignature */) { // We know we don't have a binding pattern or computed name here @@ -28457,6 +28580,18 @@ var ts; checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } } + function areDeclarationFlagsIdentical(left, right) { + if (ts.hasQuestionToken(left) !== ts.hasQuestionToken(right)) { + return false; + } + var interestingFlags = 8 /* Private */ | + 16 /* Protected */ | + 256 /* Async */ | + 128 /* Abstract */ | + 64 /* Readonly */ | + 32 /* Static */; + return (left.flags & interestingFlags) === (right.flags & interestingFlags); + } function checkVariableDeclaration(node) { checkGrammarVariableDeclaration(node); return checkVariableLikeDeclaration(node); @@ -29150,6 +29285,7 @@ var ts; var typeWithThis = getTypeWithThisArgument(type); var staticType = getTypeOfSymbol(symbol); checkTypeParameterListsIdentical(node, symbol); + checkClassForDuplicateDeclarations(node); var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { var baseTypes = getBaseTypes(type); @@ -29398,6 +29534,7 @@ var ts; checkIndexConstraints(type); } } + checkObjectTypeForDuplicateDeclarations(node); } ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) { if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) { @@ -30241,14 +30378,11 @@ var ts; function checkSourceFileWorker(node) { var links = getNodeLinks(node); if (!(links.flags & 1 /* TypeChecked */)) { - // Check whether the file has declared it is the default lib, - // and whether the user has specifically chosen to avoid checking it. - if (compilerOptions.skipDefaultLibCheck) { - // If the user specified '--noLib' and a file has a '/// ', - // then we should treat that file as a default lib. - if (node.hasNoDefaultLib) { - return; - } + // If skipLibCheck is enabled, skip type checking if file is a declaration file. + // If skipDefaultLibCheck is enabled, skip type checking if file contains a + // '/// ' directive. + if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) { + return; } // Grammar checking checkGrammarSourceFile(node); @@ -30665,7 +30799,7 @@ var ts; return symbol && getTypeOfSymbol(symbol); } if (ts.isBindingPattern(node)) { - return getTypeForVariableLikeDeclaration(node.parent); + return getTypeForVariableLikeDeclaration(node.parent, /*includeOptionality*/ true); } if (isInRightSideOfImportOrExportAssignment(node)) { var symbol = getSymbolAtLocation(node); @@ -31204,7 +31338,7 @@ var ts; if (file.moduleAugmentations.length) { (augmentations || (augmentations = [])).push(file.moduleAugmentations); } - if (file.wasReferenced && file.symbol && file.symbol.globalExports) { + if (file.symbol && file.symbol.globalExports) { mergeSymbolTable(globals, file.symbol.globalExports); } }); @@ -31787,7 +31921,6 @@ var ts; name_20.kind === 140 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it checkGrammarComputedPropertyName(name_20); - return "continue"; } if (prop.kind === 254 /* ShorthandPropertyAssignment */ && !inDestructuring && prop.objectAssignmentInitializer) { // having objectAssignmentInitializer is only valid in ObjectAssignmentPattern @@ -31829,17 +31962,21 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_20.text)) { - seen[name_20.text] = currentKind; + var effectiveName = ts.getPropertyNameForPropertyNameNode(name_20); + if (effectiveName === undefined) { + return "continue"; + } + if (!ts.hasProperty(seen, effectiveName)) { + seen[effectiveName] = currentKind; } else { - var existingKind = seen[name_20.text]; + var existingKind = seen[effectiveName]; if (currentKind === Property && existingKind === Property) { - return "continue"; + grammarErrorOnNode(name_20, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name_20)); } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_20.text] = currentKind | existingKind; + seen[effectiveName] = currentKind | existingKind; } else { return { value: grammarErrorOnNode(name_20, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name) }; @@ -41638,8 +41775,8 @@ var ts; skipTsx: true, traceEnabled: traceEnabled }; - // use typesRoot and fallback to directory that contains tsconfig if typesRoot is not set - var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : undefined); + // use typesRoot and fallback to directory that contains tsconfig or current directory if typesRoot is not set + var rootDir = options.typesRoot || (options.configFilePath ? ts.getDirectoryPath(options.configFilePath) : (host.getCurrentDirectory && host.getCurrentDirectory())); if (traceEnabled) { if (containingFile === undefined) { if (rootDir === undefined) { @@ -42229,12 +42366,25 @@ var ts; } } } + function getDefaultTypeDirectiveNames(rootPath) { + var localTypes = ts.combinePaths(rootPath, "types"); + var npmTypes = ts.combinePaths(rootPath, "node_modules/@types"); + var result = []; + if (ts.sys.directoryExists(localTypes)) { + result = result.concat(ts.sys.getDirectories(localTypes)); + } + if (ts.sys.directoryExists(npmTypes)) { + result = result.concat(ts.sys.getDirectories(npmTypes)); + } + return result; + } function getDefaultLibLocation() { return ts.getDirectoryPath(ts.normalizePath(ts.sys.getExecutingFilePath())); } var newLine = ts.getNewLineCharacter(options); var realpath = ts.sys.realpath && (function (path) { return ts.sys.realpath(path); }); return { + getDefaultTypeDirectiveNames: getDefaultTypeDirectiveNames, getSourceFile: getSourceFile, getDefaultLibLocation: getDefaultLibLocation, getDefaultLibFileName: function (options) { return ts.combinePaths(getDefaultLibLocation(), ts.getDefaultLibFileName(options)); }, @@ -42302,6 +42452,21 @@ var ts; } return resolutions; } + function getDefaultTypeDirectiveNames(options, rootFiles, host) { + // Use explicit type list from tsconfig.json + if (options.types) { + return options.types; + } + // or load all types from the automatic type import fields + if (host && host.getDefaultTypeDirectiveNames) { + var commonRoot = computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), function (f) { return host.getCanonicalFileName(f); }); + if (commonRoot) { + return host.getDefaultTypeDirectiveNames(commonRoot); + } + } + return undefined; + } + ts.getDefaultTypeDirectiveNames = getDefaultTypeDirectiveNames; function createProgram(rootNames, options, host, oldProgram) { var program; var files = []; @@ -42340,14 +42505,15 @@ var ts; // used to track cases when two file names differ only in casing var filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? ts.createFileMap(function (fileName) { return fileName.toLowerCase(); }) : undefined; if (!tryReuseStructureFromOldProgram()) { + ts.forEach(rootNames, function (name) { return processRootFile(name, /*isDefaultLib*/ false); }); // load type declarations specified via 'types' argument - if (options.types && options.types.length) { - var resolutions = resolveTypeReferenceDirectiveNamesWorker(options.types, /*containingFile*/ undefined); - for (var i = 0; i < options.types.length; i++) { - processTypeReferenceDirective(options.types[i], resolutions[i]); + var typeReferences = getDefaultTypeDirectiveNames(options, rootNames, host); + if (typeReferences) { + var resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, /*containingFile*/ undefined); + for (var i = 0; i < typeReferences.length; i++) { + processTypeReferenceDirective(typeReferences[i], resolutions[i]); } } - ts.forEach(rootNames, function (name) { return processRootFile(name, /*isDefaultLib*/ false); }); // Do not process the default library if: // - The '--noLib' flag is used. // - A 'no-default-lib' reference comment is encountered in @@ -42999,9 +43165,6 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1) { - file_1.wasReferenced = file_1.wasReferenced || isReference; - } return file_1; } // We haven't looked for this file, do so now and cache result @@ -43015,7 +43178,6 @@ var ts; }); filesByName.set(path, file); if (file) { - file.wasReferenced = file.wasReferenced || isReference; file.path = path; if (host.useCaseSensitiveFileNames()) { // for case-sensitive file systems check if we've already seen some file with similar filename ignoring case @@ -43129,19 +43291,7 @@ var ts; !options.noResolve && i < file.imports.length; if (shouldAddFile) { - var importedFile = findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, /*isReference*/ false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); - if (importedFile && resolution.isExternalLibraryImport) { - // Since currently irrespective of allowJs, we only look for supportedTypeScript extension external module files, - // this check is ok. Otherwise this would be never true for javascript file - if (!ts.isExternalModule(importedFile) && importedFile.statements.length) { - var start_5 = ts.getTokenPosOfNode(file.imports[i], file); - fileProcessingDiagnostics.add(ts.createFileDiagnostic(file, start_5, file.imports[i].end - start_5, ts.Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); - } - else if (importedFile.referencedFiles.length) { - var firstRef = importedFile.referencedFiles[0]; - fileProcessingDiagnostics.add(ts.createFileDiagnostic(importedFile, firstRef.pos, firstRef.end - firstRef.pos, ts.Diagnostics.Exported_external_package_typings_file_cannot_contain_tripleslash_references_Please_contact_the_package_author_to_update_the_package_definition)); - } - } + findSourceFile(resolution.resolvedFileName, ts.toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, /*isReference*/ false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } } } @@ -43227,7 +43377,7 @@ var ts; } } else { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substututions_for_pattern_0_should_be_an_array, key)); + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Substitutions_for_pattern_0_should_be_an_array, key)); } } } @@ -43278,15 +43428,21 @@ var ts; else if (firstExternalModuleSourceFile && languageVersion < 2 /* ES6 */ && options.module === ts.ModuleKind.None) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided_with_a_valid_module_type_Consider_setting_the_module_compiler_option_in_a_tsconfig_json_file)); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); } // Cannot specify module gen target of es6 when below es6 if (options.module === ts.ModuleKind.ES6 && languageVersion < 2 /* ES6 */) { programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_compile_modules_into_es2015_when_targeting_ES5_or_lower)); } // Cannot specify module gen that isn't amd or system with --out - if (outFile && options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { - programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + if (outFile) { + if (options.module && !(options.module === ts.ModuleKind.AMD || options.module === ts.ModuleKind.System)) { + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); + } + else if (options.module === undefined && firstExternalModuleSourceFile) { + var span = ts.getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + programDiagnostics.add(ts.createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); + } } // there has to be common source directory if user specified --outdir || --sourceRoot // if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted @@ -43384,6 +43540,11 @@ var ts; type: "boolean", description: ts.Diagnostics.Print_this_message }, + { + name: "help", + shortName: "?", + type: "boolean" + }, { name: "init", type: "boolean", @@ -43486,6 +43647,11 @@ var ts; name: "skipDefaultLibCheck", type: "boolean" }, + { + name: "skipLibCheck", + type: "boolean", + description: ts.Diagnostics.Skip_type_checking_of_declaration_files + }, { name: "out", type: "string", @@ -44315,7 +44481,7 @@ var ts; (function (ts) { var NavigateTo; (function (NavigateTo) { - function getNavigateToItems(program, cancellationToken, searchValue, maxResultCount) { + function getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount) { var patternMatcher = ts.createPatternMatcher(searchValue); var rawItems = []; // This means "compare in a case insensitive manner." @@ -44354,6 +44520,18 @@ var ts; } } }); + // Remove imports when the imported declaration is already in the list and has the same name. + rawItems = ts.filter(rawItems, function (item) { + var decl = item.declaration; + if (decl.kind === 231 /* ImportClause */ || decl.kind === 234 /* ImportSpecifier */ || decl.kind === 229 /* ImportEqualsDeclaration */) { + var importer = checker.getSymbolAtLocation(decl.name); + var imported = checker.getAliasedSymbol(importer); + return importer.name !== imported.name; + } + else { + return true; + } + }); rawItems.sort(compareNavigateToItems); if (maxResultCount !== undefined) { rawItems = rawItems.slice(0, maxResultCount); @@ -44752,8 +44930,12 @@ var ts; return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement); case 153 /* IndexSignature */: return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement); + case 224 /* EnumDeclaration */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.enumElement); case 255 /* EnumMember */: return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement); + case 222 /* InterfaceDeclaration */: + return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.interfaceElement); case 151 /* CallSignature */: return createItem(node, "()", ts.ScriptElementKind.callSignatureElement); case 152 /* ConstructSignature */: @@ -45714,7 +45896,7 @@ var ts; // To do this, the method will back parse the expression starting at the position required. it will try to parse the current expression as a generic type expression, if it did succeed it // will return the generic identifier that started the expression (e.g. "foo" in "foo= 0; --i) { + for (var i = exclusiveStartPosition - 1; i >= 0; i--) { if (nodeHasTokens(children[i])) { return children[i]; } @@ -47337,12 +47519,11 @@ var ts; if (!isStarted) { scanner.scan(); } - var t; var pos = scanner.getStartPos(); // Read leading trivia and token while (pos < endPos) { - var t_1 = scanner.getToken(); - if (!ts.isTrivia(t_1)) { + var t = scanner.getToken(); + if (!ts.isTrivia(t)) { break; } // consume leading trivia @@ -47350,7 +47531,7 @@ var ts; var item = { pos: pos, end: scanner.getStartPos(), - kind: t_1 + kind: t }; pos = scanner.getStartPos(); if (!leadingTrivia) { @@ -47690,6 +47871,7 @@ var ts; })(formatting = ts.formatting || (ts.formatting = {})); })(ts || (ts = {})); /// +/* tslint:disable:no-null-keyword */ /* @internal */ var ts; (function (ts) { @@ -47951,7 +48133,7 @@ var ts; this.SpaceAfterKeywordInControl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Keywords, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext), 2 /* Space */)); this.NoSpaceAfterKeywordInControl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Keywords, 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext), 8 /* Delete */)); // Open Brace braces after function - //TypeScript: Function can have return types, which can be made of tons of different token kinds + // TypeScript: Function can have return types, which can be made of tons of different token kinds this.NewLineBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeMultilineBlockContext), 4 /* NewLine */), 1 /* CanDeleteNewLines */); // Open Brace braces after TypeScript module/class/interface this.NewLineBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsBeforeMultilineBlockContext), 4 /* NewLine */), 1 /* CanDeleteNewLines */); @@ -48092,17 +48274,17 @@ var ts; case 220 /* FunctionDeclaration */: case 147 /* MethodDeclaration */: case 146 /* MethodSignature */: - //case SyntaxKind.MemberFunctionDeclaration: + // case SyntaxKind.MemberFunctionDeclaration: case 149 /* GetAccessor */: case 150 /* SetAccessor */: - ///case SyntaxKind.MethodSignature: + // case SyntaxKind.MethodSignature: case 151 /* CallSignature */: case 179 /* FunctionExpression */: case 148 /* Constructor */: case 180 /* ArrowFunction */: - //case SyntaxKind.ConstructorDeclaration: - //case SyntaxKind.SimpleArrowFunctionExpression: - //case SyntaxKind.ParenthesizedArrowFunctionExpression: + // case SyntaxKind.ConstructorDeclaration: + // case SyntaxKind.SimpleArrowFunctionExpression: + // case SyntaxKind.ParenthesizedArrowFunctionExpression: case 222 /* InterfaceDeclaration */: return true; } @@ -48254,6 +48436,7 @@ var ts; })(formatting = ts.formatting || (ts.formatting = {})); })(ts || (ts = {})); /// +/* tslint:disable:no-null-keyword */ /* @internal */ var ts; (function (ts) { @@ -48271,9 +48454,9 @@ var ts; }; RulesMap.prototype.Initialize = function (rules) { this.mapRowLength = 138 /* LastToken */ + 1; - this.map = new Array(this.mapRowLength * this.mapRowLength); //new Array(this.mapRowLength * this.mapRowLength); + this.map = new Array(this.mapRowLength * this.mapRowLength); // new Array(this.mapRowLength * this.mapRowLength); // This array is used only during construction of the rulesbucket in the map - var rulesBucketConstructionStateList = new Array(this.map.length); //new Array(this.map.length); + var rulesBucketConstructionStateList = new Array(this.map.length); // new Array(this.map.length); this.FillRules(rules, rulesBucketConstructionStateList); return this.map; }; @@ -48285,7 +48468,7 @@ var ts; }; RulesMap.prototype.GetRuleBucketIndex = function (row, column) { var rulesBucketIndex = (row * this.mapRowLength) + column; - //Debug.Assert(rulesBucketIndex < this.map.Length, "Trying to access an index outside the array."); + // Debug.Assert(rulesBucketIndex < this.map.Length, "Trying to access an index outside the array."); return rulesBucketIndex; }; RulesMap.prototype.FillRule = function (rule, rulesBucketConstructionStateList) { @@ -48537,6 +48720,7 @@ var ts; /// /// /// +/* tslint:disable:no-null-keyword */ /* @internal */ var ts; (function (ts) { @@ -49058,7 +49242,7 @@ var ts; // if there are any tokens that logically belong to node and interleave child nodes // such tokens will be consumed in processChildNode for for the child that follows them ts.forEachChild(node, function (child) { - processChildNode(child, /*inheritedIndentation*/ -1 /* Unknown */, node, nodeDynamicIndentation, nodeStartLine, undecoratedNodeStartLine, /*isListElement*/ false); + processChildNode(child, /*inheritedIndentation*/ -1 /* Unknown */, node, nodeDynamicIndentation, nodeStartLine, undecoratedNodeStartLine, /*isListItem*/ false); }, function (nodes) { processChildNodes(nodes, node, nodeStartLine, nodeDynamicIndentation); }); @@ -49149,7 +49333,7 @@ var ts; var inheritedIndentation = -1 /* Unknown */; for (var i = 0; i < nodes.length; i++) { var child = nodes[i]; - inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListElement*/ true, /*isFirstListItem*/ i === 0); + inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListItem*/ true, /*isFirstListItem*/ i === 0); } if (listEndToken !== 0 /* Unknown */) { if (formattingScanner.isOnToken()) { @@ -49279,7 +49463,7 @@ var ts; // Handle the case where the next line is moved to be the end of this line. // In this case we don't indent the next line in the next pass. if (currentParent.getStart(sourceFile) === currentItem.pos) { - dynamicIndentation.recomputeIndentation(/*lineAdded*/ false); + dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ false); } } else if (rule.Operation.Action & 4 /* NewLine */ && currentStartLine === previousStartLine) { @@ -49288,7 +49472,7 @@ var ts; // In this case we indent token2 in the next pass but we set // sameLineIndent flag to notify the indenter that the indentation is within the line. if (currentParent.getStart(sourceFile) === currentItem.pos) { - dynamicIndentation.recomputeIndentation(/*lineAdded*/ true); + dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ true); } } // We need to trim trailing whitespace between the tokens if they were on different lines, and no rule was applied to put them on the same line @@ -49336,7 +49520,7 @@ var ts; else { parts = []; var startPos = commentRange.pos; - for (var line = startLine; line < endLine; ++line) { + for (var line = startLine; line < endLine; line++) { var endOfLine = ts.getEndLinePosition(line, sourceFile); parts.push({ pos: startPos, end: endOfLine }); startPos = ts.getStartPositionOfLine(line + 1, sourceFile); @@ -49355,7 +49539,7 @@ var ts; } // shift all parts on the delta size var delta = indentation - nonWhitespaceColumnInFirstPart.column; - for (var i = startIndex, len = parts.length; i < len; ++i, ++startLine) { + for (var i = startIndex, len = parts.length; i < len; i++, startLine++) { var startLinePos_1 = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceCharacterAndColumn = i === 0 ? nonWhitespaceColumnInFirstPart @@ -49371,7 +49555,7 @@ var ts; } } function trimTrailingWhitespacesForLines(line1, line2, range) { - for (var line = line1; line < line2; ++line) { + for (var line = line1; line < line2; line++) { var lineStartPosition = ts.getStartPositionOfLine(line, sourceFile); var lineEndPosition = ts.getEndLinePosition(line, sourceFile); // do not trim whitespaces in comments or template expression @@ -49422,7 +49606,6 @@ var ts; } } function applyRuleEdits(rule, previousRange, previousStartLine, currentRange, currentStartLine) { - var between; switch (rule.Operation.Action) { case 1 /* Ignore */: // no action required @@ -49459,14 +49642,6 @@ var ts; } } } - function isSomeBlock(kind) { - switch (kind) { - case 199 /* Block */: - case 226 /* ModuleBlock */: - return true; - } - return false; - } function getOpenTokenForList(node, list) { switch (node.kind) { case 148 /* Constructor */: @@ -49525,7 +49700,7 @@ var ts; internedTabsIndentation = []; } if (internedTabsIndentation[tabs] === undefined) { - internedTabsIndentation[tabs] = tabString = repeat('\t', tabs); + internedTabsIndentation[tabs] = tabString = repeat("\t", tabs); } else { tabString = internedTabsIndentation[tabs]; @@ -49550,7 +49725,7 @@ var ts; } function repeat(value, count) { var s = ""; - for (var i = 0; i < count; ++i) { + for (var i = 0; i < count; i++) { s += value; } return s; @@ -49866,7 +50041,7 @@ var ts; // walk toward the start of the list starting from current node and check if the line is the same for all items. // if end line for item [i - 1] differs from the start line for item [i] - find column of the first non-whitespace character on the line of item [i] var lineAndCharacter = getStartLineAndCharacterForNode(node, sourceFile); - for (var i = index - 1; i >= 0; --i) { + for (var i = index - 1; i >= 0; i--) { if (list[i].kind === 24 /* CommaToken */) { continue; } @@ -49893,7 +50068,7 @@ var ts; function findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options) { var character = 0; var column = 0; - for (var pos = startPos; pos < endPos; ++pos) { + for (var pos = startPos; pos < endPos; pos++) { var ch = sourceFile.text.charCodeAt(pos); if (!ts.isWhiteSpace(ch)) { break; @@ -49987,7 +50162,7 @@ var ts; Function returns true when the parent node should indent the given child by an explicit rule */ function shouldIndentChildNode(parent, child) { - return nodeContentIsAlwaysIndented(parent.kind) || nodeWillIndentChild(parent, child, false); + return nodeContentIsAlwaysIndented(parent.kind) || nodeWillIndentChild(parent, child, /*indentByDefault*/ false); } SmartIndenter.shouldIndentChildNode = shouldIndentChildNode; })(SmartIndenter = formatting.SmartIndenter || (formatting.SmartIndenter = {})); @@ -50809,49 +50984,55 @@ var ts; (function (ScriptElementKind) { ScriptElementKind.unknown = ""; ScriptElementKind.warning = "warning"; - // predefined type (void) or keyword (class) + /** predefined type (void) or keyword (class) */ ScriptElementKind.keyword = "keyword"; - // top level script node + /** top level script node */ ScriptElementKind.scriptElement = "script"; - // module foo {} + /** module foo {} */ ScriptElementKind.moduleElement = "module"; - // class X {} + /** class X {} */ ScriptElementKind.classElement = "class"; - // var x = class X {} + /** var x = class X {} */ ScriptElementKind.localClassElement = "local class"; - // interface Y {} + /** interface Y {} */ ScriptElementKind.interfaceElement = "interface"; - // type T = ... + /** type T = ... */ ScriptElementKind.typeElement = "type"; - // enum E + /** enum E */ ScriptElementKind.enumElement = "enum"; - // Inside module and script only - // const v = .. + /** + * Inside module and script only + * const v = .. + */ ScriptElementKind.variableElement = "var"; - // Inside function + /** Inside function */ ScriptElementKind.localVariableElement = "local var"; - // Inside module and script only - // function f() { } + /** + * Inside module and script only + * function f() { } + */ ScriptElementKind.functionElement = "function"; - // Inside function + /** Inside function */ ScriptElementKind.localFunctionElement = "local function"; - // class X { [public|private]* foo() {} } + /** class X { [public|private]* foo() {} } */ ScriptElementKind.memberFunctionElement = "method"; - // class X { [public|private]* [get|set] foo:number; } + /** class X { [public|private]* [get|set] foo:number; } */ ScriptElementKind.memberGetAccessorElement = "getter"; ScriptElementKind.memberSetAccessorElement = "setter"; - // class X { [public|private]* foo:number; } - // interface Y { foo:number; } + /** + * class X { [public|private]* foo:number; } + * interface Y { foo:number; } + */ ScriptElementKind.memberVariableElement = "property"; - // class X { constructor() { } } + /** class X { constructor() { } } */ ScriptElementKind.constructorImplementationElement = "constructor"; - // interface Y { ():number; } + /** interface Y { ():number; } */ ScriptElementKind.callSignatureElement = "call"; - // interface Y { []:number; } + /** interface Y { []:number; } */ ScriptElementKind.indexSignatureElement = "index"; - // interface Y { new():Y; } + /** interface Y { new():Y; } */ ScriptElementKind.constructSignatureElement = "construct"; - // function foo(*Y*: string) + /** function foo(*Y*: string) */ ScriptElementKind.parameterElement = "parameter"; ScriptElementKind.typeParameterElement = "type parameter"; ScriptElementKind.primitiveType = "primitive type"; @@ -52236,9 +52417,9 @@ var ts; // Check if the caret is at the end of an identifier; this is a partial identifier that we want to complete: e.g. a.toS| // Skip this partial identifier and adjust the contextToken to the token that precedes it. if (contextToken && position <= contextToken.end && ts.isWord(contextToken.kind)) { - var start_6 = new Date().getTime(); + var start_5 = new Date().getTime(); contextToken = ts.findPrecedingToken(contextToken.getFullStart(), sourceFile); - log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_6)); + log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start_5)); } // Find the node where completion is requested on. // Also determine whether we are trying to complete with members of that node @@ -52518,13 +52699,13 @@ var ts; || contextToken.kind === 166 /* StringLiteralType */ || contextToken.kind === 10 /* RegularExpressionLiteral */ || ts.isTemplateLiteralKind(contextToken.kind)) { - var start_7 = contextToken.getStart(); + var start_6 = contextToken.getStart(); var end = contextToken.getEnd(); // To be "in" one of these literals, the position has to be: // 1. entirely within the token text. // 2. at the end position of an unterminated token. // 3. at the end of a regular expression (due to trailing flags like '/foo/g'). - if (start_7 < position && position < end) { + if (start_6 < position && position < end) { return true; } if (position === end) { @@ -53759,8 +53940,7 @@ var ts; } function getDocumentHighlights(fileName, position, filesToSearch) { synchronizeHostData(); - filesToSearch = ts.map(filesToSearch, ts.normalizeSlashes); - var sourceFilesToSearch = ts.filter(program.getSourceFiles(), function (f) { return ts.contains(filesToSearch, f.fileName); }); + var sourceFilesToSearch = ts.map(filesToSearch, function (f) { return program.getSourceFile(f); }); var sourceFile = getValidSourceFile(fileName); var node = ts.getTouchingWord(sourceFile, position); if (!node) { @@ -55150,7 +55330,8 @@ var ts; /// NavigateTo function getNavigateToItems(searchValue, maxResultCount) { synchronizeHostData(); - return ts.NavigateTo.getNavigateToItems(program, cancellationToken, searchValue, maxResultCount); + var checker = getProgram().getTypeChecker(); + return ts.NavigateTo.getNavigateToItems(program, checker, cancellationToken, searchValue, maxResultCount); } function getEmitOutput(fileName) { synchronizeHostData(); @@ -57559,6 +57740,9 @@ var ts; LanguageServiceShimHostAdapter.prototype.getCurrentDirectory = function () { return this.shimHost.getCurrentDirectory(); }; + LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { + return this.shimHost.getDirectories(path); + }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); };