diff --git a/.npmignore b/.npmignore index 02d8fe428f9ce..d3c27afeff45a 100644 --- a/.npmignore +++ b/.npmignore @@ -1,8 +1,11 @@ built doc +Gulpfile.ts internal issue_template.md +jenkins.sh lib/README.md +netci.groovy pull_request_template.md scripts src diff --git a/lib/protocol.d.ts b/lib/protocol.d.ts index b6d99c0904305..2b92c06c66829 100644 --- a/lib/protocol.d.ts +++ b/lib/protocol.d.ts @@ -1734,12 +1734,14 @@ declare namespace ts.server.protocol { insertSpaceAfterCommaDelimiter?: boolean; insertSpaceAfterSemicolonInForStatements?: boolean; insertSpaceBeforeAndAfterBinaryOperators?: boolean; + insertSpaceAfterConstructor?: boolean; insertSpaceAfterKeywordsInControlFlowStatements?: boolean; insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean; insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean; insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean; insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean; insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; + insertSpaceBeforeFunctionParenthesis?: boolean; placeOpenBraceOnNewLineForFunctions?: boolean; placeOpenBraceOnNewLineForControlBlocks?: boolean; } diff --git a/lib/tsc.js b/lib/tsc.js index 7ea3b71e5d8a2..233f930ab080a 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -2470,7 +2470,7 @@ var ts; _0_modifier_cannot_appear_on_an_index_signature: { code: 1071, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_an_index_signature_1071", message: "'{0}' modifier cannot appear on an index signature." }, A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A_0_modifier_cannot_be_used_with_an_import_declaration_1079", message: "A '{0}' modifier cannot be used with an import declaration." }, Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid_reference_directive_syntax_1084", message: "Invalid 'reference' directive syntax." }, - Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_1085", message: "Octal literals are not available when targeting ECMAScript 5 and higher." }, + Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0_1085", message: "Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o{0}'." }, An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: ts.DiagnosticCategory.Error, key: "An_accessor_cannot_be_declared_in_an_ambient_context_1086", message: "An accessor cannot be declared in an ambient context." }, _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_a_constructor_declaration_1089", message: "'{0}' modifier cannot appear on a constructor declaration." }, _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_a_parameter_1090", message: "'{0}' modifier cannot appear on a parameter." }, @@ -3084,6 +3084,7 @@ var ts; Disallow_inconsistently_cased_references_to_the_same_file: { code: 6078, category: ts.DiagnosticCategory.Message, key: "Disallow_inconsistently_cased_references_to_the_same_file_6078", message: "Disallow inconsistently-cased references to the same file." }, Specify_library_files_to_be_included_in_the_compilation_Colon: { code: 6079, category: ts.DiagnosticCategory.Message, key: "Specify_library_files_to_be_included_in_the_compilation_Colon_6079", message: "Specify library files to be included in the compilation: " }, Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify_JSX_code_generation_Colon_preserve_or_react_6080", message: "Specify JSX code generation: 'preserve' or 'react'" }, + File_0_has_an_unsupported_extension_so_skipping_it: { code: 6081, category: ts.DiagnosticCategory.Message, key: "File_0_has_an_unsupported_extension_so_skipping_it_6081", message: "File '{0}' has an unsupported extension, so skipping it." }, Only_amd_and_system_modules_are_supported_alongside_0: { code: 6082, category: ts.DiagnosticCategory.Error, key: "Only_amd_and_system_modules_are_supported_alongside_0_6082", message: "Only 'amd' and 'system' modules are supported alongside --{0}." }, Base_directory_to_resolve_non_absolute_module_names: { code: 6083, category: ts.DiagnosticCategory.Message, key: "Base_directory_to_resolve_non_absolute_module_names_6083", message: "Base directory to resolve non-absolute module names." }, Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit: { code: 6084, category: ts.DiagnosticCategory.Message, key: "Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit_6084", message: "Specify the object invoked for createElement and __spread when targeting 'react' JSX emit" }, @@ -3149,6 +3150,7 @@ var ts; Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1: { code: 6144, category: ts.DiagnosticCategory.Message, key: "Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1_6144", message: "Module '{0}' was resolved as locally declared ambient module in file '{1}'." }, Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified: { code: 6145, category: ts.DiagnosticCategory.Message, key: "Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified_6145", message: "Module '{0}' was resolved as ambient module declared in '{1}' since this file was not modified." }, Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h: { code: 6146, category: ts.DiagnosticCategory.Message, key: "Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h_6146", message: "Specify the JSX factory function to use when targeting 'react' JSX emit, e.g. 'React.createElement' or 'h'." }, + Resolution_for_module_0_was_found_in_cache: { code: 6147, category: ts.DiagnosticCategory.Message, key: "Resolution_for_module_0_was_found_in_cache_6147", message: "Resolution for module '{0}' was found in cache" }, 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." }, @@ -3221,6 +3223,7 @@ var ts; Import_0_from_1: { code: 90013, category: ts.DiagnosticCategory.Message, key: "Import_0_from_1_90013", message: "Import {0} from {1}" }, Change_0_to_1: { code: 90014, category: ts.DiagnosticCategory.Message, key: "Change_0_to_1_90014", message: "Change {0} to {1}" }, Add_0_to_existing_import_declaration_from_1: { code: 90015, category: ts.DiagnosticCategory.Message, key: "Add_0_to_existing_import_declaration_from_1_90015", message: "Add {0} to existing import declaration from {1}" }, + Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0: { code: 8017, category: ts.DiagnosticCategory.Error, key: "Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0_8017", message: "Octal literal types must use ES2015 syntax. Use the syntax '0o{0}'." }, }; })(ts || (ts = {})); var ts; @@ -5381,6 +5384,16 @@ var ts; return false; } ts.isPartOfTypeNode = isPartOfTypeNode; + function isChildOfLiteralType(node) { + while (node) { + if (node.kind === 171) { + return true; + } + node = node.parent; + } + return false; + } + ts.isChildOfLiteralType = isChildOfLiteralType; function forEachReturnStatement(body, visitor) { return traverse(body); function traverse(node) { @@ -18925,9 +18938,6 @@ var ts; ts.Debug.assert(ts.extensionIsTypeScript(resolved.extension)); return resolved.path; } - function resolvedFromAnyFile(path) { - return { path: path, extension: ts.extensionFromPath(path) }; - } function resolvedModuleFromResolved(_a, isExternalLibraryImport) { var path = _a.path, extension = _a.extension; return { resolvedFileName: path, extension: extension, isExternalLibraryImport: isExternalLibraryImport }; @@ -18939,7 +18949,7 @@ var ts; return !(ts.isRootedDiskPath(moduleName) || ts.isExternalModuleNameRelative(moduleName)); } ts.moduleHasNonRelativeName = moduleHasNonRelativeName; - function tryReadTypesSection(extensions, packageJsonPath, baseDirectory, state) { + function tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, baseDirectory, state) { var jsonContent = readJson(packageJsonPath, state.host); switch (extensions) { case 2: @@ -19118,31 +19128,56 @@ var ts; return result; } ts.getAutomaticTypeDirectiveNames = getAutomaticTypeDirectiveNames; - function resolveModuleName(moduleName, containingFile, compilerOptions, host) { + function createModuleResolutionCache(currentDirectory, getCanonicalFileName) { + var map = ts.createFileMap(); + return { getOrCreateCacheForDirectory: getOrCreateCacheForDirectory }; + function getOrCreateCacheForDirectory(directoryName) { + var path = ts.toPath(directoryName, currentDirectory, getCanonicalFileName); + var perFolderCache = map.get(path); + if (!perFolderCache) { + perFolderCache = ts.createMap(); + map.set(path, perFolderCache); + } + return perFolderCache; + } + } + ts.createModuleResolutionCache = createModuleResolutionCache; + function resolveModuleName(moduleName, containingFile, compilerOptions, host, cache) { var traceEnabled = isTraceEnabled(compilerOptions, host); if (traceEnabled) { trace(host, ts.Diagnostics.Resolving_module_0_from_1, moduleName, containingFile); } - var moduleResolution = compilerOptions.moduleResolution; - if (moduleResolution === undefined) { - moduleResolution = ts.getEmitModuleKind(compilerOptions) === ts.ModuleKind.CommonJS ? ts.ModuleResolutionKind.NodeJs : ts.ModuleResolutionKind.Classic; + var perFolderCache = cache && cache.getOrCreateCacheForDirectory(ts.getDirectoryPath(containingFile)); + var result = perFolderCache && perFolderCache[moduleName]; + if (result) { if (traceEnabled) { - trace(host, ts.Diagnostics.Module_resolution_kind_is_not_specified_using_0, ts.ModuleResolutionKind[moduleResolution]); + trace(host, ts.Diagnostics.Resolution_for_module_0_was_found_in_cache, moduleName); } } else { - if (traceEnabled) { - trace(host, ts.Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ts.ModuleResolutionKind[moduleResolution]); + var moduleResolution = compilerOptions.moduleResolution; + if (moduleResolution === undefined) { + moduleResolution = ts.getEmitModuleKind(compilerOptions) === ts.ModuleKind.CommonJS ? ts.ModuleResolutionKind.NodeJs : ts.ModuleResolutionKind.Classic; + if (traceEnabled) { + trace(host, ts.Diagnostics.Module_resolution_kind_is_not_specified_using_0, ts.ModuleResolutionKind[moduleResolution]); + } + } + else { + if (traceEnabled) { + trace(host, ts.Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ts.ModuleResolutionKind[moduleResolution]); + } + } + switch (moduleResolution) { + case ts.ModuleResolutionKind.NodeJs: + result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); + break; + case ts.ModuleResolutionKind.Classic: + result = classicNameResolver(moduleName, containingFile, compilerOptions, host); + break; + } + if (perFolderCache) { + perFolderCache[moduleName] = result; } - } - var result; - switch (moduleResolution) { - case ts.ModuleResolutionKind.NodeJs: - result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); - break; - case ts.ModuleResolutionKind.Classic: - result = classicNameResolver(moduleName, containingFile, compilerOptions, host); - break; } if (traceEnabled) { if (result.resolvedModule) { @@ -19375,16 +19410,20 @@ var ts; if (state.traceEnabled) { trace(state.host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath); } - var typesFile = tryReadTypesSection(extensions, packageJsonPath, candidate, state); - if (typesFile) { - var onlyRecordFailures_1 = !directoryProbablyExists(ts.getDirectoryPath(typesFile), state.host); - var fromFile = tryFile(typesFile, failedLookupLocations, onlyRecordFailures_1, state); - if (fromFile) { - return resolvedFromAnyFile(fromFile); + var mainOrTypesFile = tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, candidate, state); + if (mainOrTypesFile) { + var onlyRecordFailures_1 = !directoryProbablyExists(ts.getDirectoryPath(mainOrTypesFile), state.host); + var fromExactFile = tryFile(mainOrTypesFile, failedLookupLocations, onlyRecordFailures_1, state); + if (fromExactFile) { + var resolved_3 = fromExactFile && resolvedIfExtensionMatches(extensions, fromExactFile); + if (resolved_3) { + return resolved_3; + } + trace(state.host, ts.Diagnostics.File_0_has_an_unsupported_extension_so_skipping_it, fromExactFile); } - var x = tryAddingExtensions(typesFile, 0, failedLookupLocations, onlyRecordFailures_1, state); - if (x) { - return x; + var resolved = tryAddingExtensions(mainOrTypesFile, 0, failedLookupLocations, onlyRecordFailures_1, state); + if (resolved) { + return resolved; } } else { @@ -19401,6 +19440,20 @@ var ts; } return loadModuleFromFile(extensions, ts.combinePaths(candidate, "index"), failedLookupLocations, !directoryExists, state); } + function resolvedIfExtensionMatches(extensions, path) { + var extension = ts.tryGetExtensionFromPath(path); + return extension !== undefined && extensionIsOk(extensions, extension) ? { path: path, extension: extension } : undefined; + } + function extensionIsOk(extensions, extension) { + switch (extensions) { + case 1: + return extension === ts.Extension.Js || extension === ts.Extension.Jsx; + case 0: + return extension === ts.Extension.Ts || extension === ts.Extension.Tsx || extension === ts.Extension.Dts; + case 2: + return extension === ts.Extension.Dts; + } + } function pathToPackageJson(directory) { return ts.combinePaths(directory, "package.json"); } @@ -19447,12 +19500,12 @@ var ts; return resolvedUsingSettings; } if (moduleHasNonRelativeName(moduleName)) { - var resolved_3 = forEachAncestorDirectory(containingDirectory, function (directory) { + var resolved_4 = forEachAncestorDirectory(containingDirectory, function (directory) { var searchName = ts.normalizePath(ts.combinePaths(directory, moduleName)); return loadModuleFromFile(extensions, searchName, failedLookupLocations, false, state); }); - if (resolved_3) { - return resolved_3; + if (resolved_4) { + return resolved_4; } if (extensions === 0) { return loadModuleFromNodeModulesAtTypes(moduleName, containingDirectory, failedLookupLocations, state); @@ -23122,8 +23175,8 @@ var ts; else { var declaredType = getTypeFromMappedTypeNode(type.declaration); var constraint = getConstraintTypeFromMappedType(declaredType); - var extendedConstraint = constraint.flags & 16384 ? getConstraintOfTypeParameter(constraint) : constraint; - type.modifiersType = extendedConstraint.flags & 262144 ? instantiateType(extendedConstraint.type, type.mapper || identityMapper) : emptyObjectType; + var extendedConstraint = constraint && constraint.flags & 16384 ? getConstraintOfTypeParameter(constraint) : constraint; + type.modifiersType = extendedConstraint && extendedConstraint.flags & 262144 ? instantiateType(extendedConstraint.type, type.mapper || identityMapper) : emptyObjectType; } } return type.modifiersType; @@ -25689,8 +25742,11 @@ var ts; } } } - else if (relation !== identityRelation && isEmptyObjectType(resolveStructuredTypeMembers(target))) { - return -1; + else if (relation !== identityRelation) { + var resolved = resolveStructuredTypeMembers(target); + if (isEmptyObjectType(resolved) || resolved.stringIndexInfo && resolved.stringIndexInfo.type.flags & 1) { + return -1; + } } return 0; } @@ -36380,8 +36436,13 @@ var ts; } } function checkGrammarNumericLiteral(node) { - if (node.isOctalLiteral && languageVersion >= 1) { - return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); + if (node.isOctalLiteral) { + if (languageVersion >= 1) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0, node.text); + } + if (ts.isChildOfLiteralType(node)) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0, node.text); + } } } function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { @@ -41167,7 +41228,7 @@ var ts; } } startLexicalEnvironment(); - var loopBody = ts.visitNode(node.statement, visitor, ts.isStatement); + var loopBody = ts.visitNode(node.statement, visitor, ts.isStatement, false, ts.liftToBlock); var lexicalEnvironment = endLexicalEnvironment(); var currentState = convertedLoopState; convertedLoopState = outerConvertedLoopState; @@ -41179,7 +41240,10 @@ var ts; ts.addRange(statements_4, lexicalEnvironment); loopBody = ts.createBlock(statements_4, undefined, true); } - if (!ts.isBlock(loopBody)) { + if (ts.isBlock(loopBody)) { + loopBody.multiLine = true; + } + else { loopBody = ts.createBlock([loopBody], undefined, true); } var isAsyncBlockContainingAwait = enclosingNonArrowFunction @@ -43320,6 +43384,17 @@ var ts; var ts; (function (ts) { function transformES5(context) { + var compilerOptions = context.getCompilerOptions(); + var previousOnEmitNode; + var noSubstitution; + if (compilerOptions.jsx === 1) { + previousOnEmitNode = context.onEmitNode; + context.onEmitNode = onEmitNode; + context.enableEmitNotification(248); + context.enableEmitNotification(249); + context.enableEmitNotification(247); + noSubstitution = []; + } var previousOnSubstituteNode = context.onSubstituteNode; context.onSubstituteNode = onSubstituteNode; context.enableSubstitution(177); @@ -43328,7 +43403,21 @@ var ts; function transformSourceFile(node) { return node; } + function onEmitNode(emitContext, node, emitCallback) { + switch (node.kind) { + case 248: + case 249: + case 247: + var tagName = node.tagName; + noSubstitution[ts.getOriginalNodeId(tagName)] = true; + break; + } + previousOnEmitNode(emitContext, node, emitCallback); + } function onSubstituteNode(emitContext, node) { + if (node.id && noSubstitution && noSubstitution[node.id]) { + return previousOnSubstituteNode(emitContext, node); + } node = previousOnSubstituteNode(emitContext, node); if (ts.isPropertyAccessExpression(node)) { return substitutePropertyAccessExpression(node); @@ -49426,6 +49515,7 @@ var ts; var currentDirectory = host.getCurrentDirectory(); var supportedExtensions = ts.getSupportedExtensions(options); var hasEmitBlockingDiagnostics = ts.createFileMap(getCanonicalFileName); + var moduleResolutionCache; var resolveModuleNamesWorker; if (host.resolveModuleNames) { resolveModuleNamesWorker = function (moduleNames, containingFile) { return host.resolveModuleNames(moduleNames, containingFile).map(function (resolved) { @@ -49438,7 +49528,8 @@ var ts; }); }; } else { - var loader_1 = function (moduleName, containingFile) { return ts.resolveModuleName(moduleName, containingFile, options, host).resolvedModule; }; + moduleResolutionCache = ts.createModuleResolutionCache(currentDirectory, function (x) { return host.getCanonicalFileName(x); }); + var loader_1 = function (moduleName, containingFile) { return ts.resolveModuleName(moduleName, containingFile, options, host, moduleResolutionCache).resolvedModule; }; resolveModuleNamesWorker = function (moduleNames, containingFile) { return loadWithLocalCache(moduleNames, containingFile, loader_1); }; } var resolveTypeReferenceDirectiveNamesWorker; @@ -49474,6 +49565,7 @@ var ts; } } } + moduleResolutionCache = undefined; oldProgram = undefined; program = { getRootFileNames: function () { return rootNames; }, diff --git a/lib/tsserver.js b/lib/tsserver.js index 3730124ae0fb9..df429f72f8f44 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -2475,7 +2475,7 @@ var ts; _0_modifier_cannot_appear_on_an_index_signature: { code: 1071, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_an_index_signature_1071", message: "'{0}' modifier cannot appear on an index signature." }, A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A_0_modifier_cannot_be_used_with_an_import_declaration_1079", message: "A '{0}' modifier cannot be used with an import declaration." }, Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid_reference_directive_syntax_1084", message: "Invalid 'reference' directive syntax." }, - Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_1085", message: "Octal literals are not available when targeting ECMAScript 5 and higher." }, + Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0_1085", message: "Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o{0}'." }, An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: ts.DiagnosticCategory.Error, key: "An_accessor_cannot_be_declared_in_an_ambient_context_1086", message: "An accessor cannot be declared in an ambient context." }, _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_a_constructor_declaration_1089", message: "'{0}' modifier cannot appear on a constructor declaration." }, _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_a_parameter_1090", message: "'{0}' modifier cannot appear on a parameter." }, @@ -3089,6 +3089,7 @@ var ts; Disallow_inconsistently_cased_references_to_the_same_file: { code: 6078, category: ts.DiagnosticCategory.Message, key: "Disallow_inconsistently_cased_references_to_the_same_file_6078", message: "Disallow inconsistently-cased references to the same file." }, Specify_library_files_to_be_included_in_the_compilation_Colon: { code: 6079, category: ts.DiagnosticCategory.Message, key: "Specify_library_files_to_be_included_in_the_compilation_Colon_6079", message: "Specify library files to be included in the compilation: " }, Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify_JSX_code_generation_Colon_preserve_or_react_6080", message: "Specify JSX code generation: 'preserve' or 'react'" }, + File_0_has_an_unsupported_extension_so_skipping_it: { code: 6081, category: ts.DiagnosticCategory.Message, key: "File_0_has_an_unsupported_extension_so_skipping_it_6081", message: "File '{0}' has an unsupported extension, so skipping it." }, Only_amd_and_system_modules_are_supported_alongside_0: { code: 6082, category: ts.DiagnosticCategory.Error, key: "Only_amd_and_system_modules_are_supported_alongside_0_6082", message: "Only 'amd' and 'system' modules are supported alongside --{0}." }, Base_directory_to_resolve_non_absolute_module_names: { code: 6083, category: ts.DiagnosticCategory.Message, key: "Base_directory_to_resolve_non_absolute_module_names_6083", message: "Base directory to resolve non-absolute module names." }, Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit: { code: 6084, category: ts.DiagnosticCategory.Message, key: "Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit_6084", message: "Specify the object invoked for createElement and __spread when targeting 'react' JSX emit" }, @@ -3154,6 +3155,7 @@ var ts; Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1: { code: 6144, category: ts.DiagnosticCategory.Message, key: "Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1_6144", message: "Module '{0}' was resolved as locally declared ambient module in file '{1}'." }, Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified: { code: 6145, category: ts.DiagnosticCategory.Message, key: "Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified_6145", message: "Module '{0}' was resolved as ambient module declared in '{1}' since this file was not modified." }, Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h: { code: 6146, category: ts.DiagnosticCategory.Message, key: "Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h_6146", message: "Specify the JSX factory function to use when targeting 'react' JSX emit, e.g. 'React.createElement' or 'h'." }, + Resolution_for_module_0_was_found_in_cache: { code: 6147, category: ts.DiagnosticCategory.Message, key: "Resolution_for_module_0_was_found_in_cache_6147", message: "Resolution for module '{0}' was found in cache" }, 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." }, @@ -3226,6 +3228,7 @@ var ts; Import_0_from_1: { code: 90013, category: ts.DiagnosticCategory.Message, key: "Import_0_from_1_90013", message: "Import {0} from {1}" }, Change_0_to_1: { code: 90014, category: ts.DiagnosticCategory.Message, key: "Change_0_to_1_90014", message: "Change {0} to {1}" }, Add_0_to_existing_import_declaration_from_1: { code: 90015, category: ts.DiagnosticCategory.Message, key: "Add_0_to_existing_import_declaration_from_1_90015", message: "Add {0} to existing import declaration from {1}" }, + Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0: { code: 8017, category: ts.DiagnosticCategory.Error, key: "Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0_8017", message: "Octal literal types must use ES2015 syntax. Use the syntax '0o{0}'." }, }; })(ts || (ts = {})); var ts; @@ -6156,6 +6159,7 @@ var ts; newLineCharacter: host.newLine || "\n", convertTabsToSpaces: true, indentStyle: ts.IndentStyle.Smart, + insertSpaceAfterConstructor: false, insertSpaceAfterCommaDelimiter: true, insertSpaceAfterSemicolonInForStatements: true, insertSpaceBeforeAndAfterBinaryOperators: true, @@ -6165,6 +6169,7 @@ var ts; insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false, insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false, insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false, + insertSpaceBeforeFunctionParenthesis: false, placeOpenBraceOnNewLineForFunctions: false, placeOpenBraceOnNewLineForControlBlocks: false, }; @@ -6300,9 +6305,6 @@ var ts; ts.Debug.assert(ts.extensionIsTypeScript(resolved.extension)); return resolved.path; } - function resolvedFromAnyFile(path) { - return { path: path, extension: ts.extensionFromPath(path) }; - } function resolvedModuleFromResolved(_a, isExternalLibraryImport) { var path = _a.path, extension = _a.extension; return { resolvedFileName: path, extension: extension, isExternalLibraryImport: isExternalLibraryImport }; @@ -6314,7 +6316,7 @@ var ts; return !(ts.isRootedDiskPath(moduleName) || ts.isExternalModuleNameRelative(moduleName)); } ts.moduleHasNonRelativeName = moduleHasNonRelativeName; - function tryReadTypesSection(extensions, packageJsonPath, baseDirectory, state) { + function tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, baseDirectory, state) { var jsonContent = readJson(packageJsonPath, state.host); switch (extensions) { case 2: @@ -6493,31 +6495,56 @@ var ts; return result; } ts.getAutomaticTypeDirectiveNames = getAutomaticTypeDirectiveNames; - function resolveModuleName(moduleName, containingFile, compilerOptions, host) { + function createModuleResolutionCache(currentDirectory, getCanonicalFileName) { + var map = ts.createFileMap(); + return { getOrCreateCacheForDirectory: getOrCreateCacheForDirectory }; + function getOrCreateCacheForDirectory(directoryName) { + var path = ts.toPath(directoryName, currentDirectory, getCanonicalFileName); + var perFolderCache = map.get(path); + if (!perFolderCache) { + perFolderCache = ts.createMap(); + map.set(path, perFolderCache); + } + return perFolderCache; + } + } + ts.createModuleResolutionCache = createModuleResolutionCache; + function resolveModuleName(moduleName, containingFile, compilerOptions, host, cache) { var traceEnabled = isTraceEnabled(compilerOptions, host); if (traceEnabled) { trace(host, ts.Diagnostics.Resolving_module_0_from_1, moduleName, containingFile); } - var moduleResolution = compilerOptions.moduleResolution; - if (moduleResolution === undefined) { - moduleResolution = ts.getEmitModuleKind(compilerOptions) === ts.ModuleKind.CommonJS ? ts.ModuleResolutionKind.NodeJs : ts.ModuleResolutionKind.Classic; + var perFolderCache = cache && cache.getOrCreateCacheForDirectory(ts.getDirectoryPath(containingFile)); + var result = perFolderCache && perFolderCache[moduleName]; + if (result) { if (traceEnabled) { - trace(host, ts.Diagnostics.Module_resolution_kind_is_not_specified_using_0, ts.ModuleResolutionKind[moduleResolution]); + trace(host, ts.Diagnostics.Resolution_for_module_0_was_found_in_cache, moduleName); } } else { - if (traceEnabled) { - trace(host, ts.Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ts.ModuleResolutionKind[moduleResolution]); + var moduleResolution = compilerOptions.moduleResolution; + if (moduleResolution === undefined) { + moduleResolution = ts.getEmitModuleKind(compilerOptions) === ts.ModuleKind.CommonJS ? ts.ModuleResolutionKind.NodeJs : ts.ModuleResolutionKind.Classic; + if (traceEnabled) { + trace(host, ts.Diagnostics.Module_resolution_kind_is_not_specified_using_0, ts.ModuleResolutionKind[moduleResolution]); + } + } + else { + if (traceEnabled) { + trace(host, ts.Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ts.ModuleResolutionKind[moduleResolution]); + } + } + switch (moduleResolution) { + case ts.ModuleResolutionKind.NodeJs: + result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); + break; + case ts.ModuleResolutionKind.Classic: + result = classicNameResolver(moduleName, containingFile, compilerOptions, host); + break; + } + if (perFolderCache) { + perFolderCache[moduleName] = result; } - } - var result; - switch (moduleResolution) { - case ts.ModuleResolutionKind.NodeJs: - result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); - break; - case ts.ModuleResolutionKind.Classic: - result = classicNameResolver(moduleName, containingFile, compilerOptions, host); - break; } if (traceEnabled) { if (result.resolvedModule) { @@ -6750,16 +6777,20 @@ var ts; if (state.traceEnabled) { trace(state.host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath); } - var typesFile = tryReadTypesSection(extensions, packageJsonPath, candidate, state); - if (typesFile) { - var onlyRecordFailures_1 = !directoryProbablyExists(ts.getDirectoryPath(typesFile), state.host); - var fromFile = tryFile(typesFile, failedLookupLocations, onlyRecordFailures_1, state); - if (fromFile) { - return resolvedFromAnyFile(fromFile); + var mainOrTypesFile = tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, candidate, state); + if (mainOrTypesFile) { + var onlyRecordFailures_1 = !directoryProbablyExists(ts.getDirectoryPath(mainOrTypesFile), state.host); + var fromExactFile = tryFile(mainOrTypesFile, failedLookupLocations, onlyRecordFailures_1, state); + if (fromExactFile) { + var resolved_3 = fromExactFile && resolvedIfExtensionMatches(extensions, fromExactFile); + if (resolved_3) { + return resolved_3; + } + trace(state.host, ts.Diagnostics.File_0_has_an_unsupported_extension_so_skipping_it, fromExactFile); } - var x = tryAddingExtensions(typesFile, 0, failedLookupLocations, onlyRecordFailures_1, state); - if (x) { - return x; + var resolved = tryAddingExtensions(mainOrTypesFile, 0, failedLookupLocations, onlyRecordFailures_1, state); + if (resolved) { + return resolved; } } else { @@ -6776,6 +6807,20 @@ var ts; } return loadModuleFromFile(extensions, ts.combinePaths(candidate, "index"), failedLookupLocations, !directoryExists, state); } + function resolvedIfExtensionMatches(extensions, path) { + var extension = ts.tryGetExtensionFromPath(path); + return extension !== undefined && extensionIsOk(extensions, extension) ? { path: path, extension: extension } : undefined; + } + function extensionIsOk(extensions, extension) { + switch (extensions) { + case 1: + return extension === ts.Extension.Js || extension === ts.Extension.Jsx; + case 0: + return extension === ts.Extension.Ts || extension === ts.Extension.Tsx || extension === ts.Extension.Dts; + case 2: + return extension === ts.Extension.Dts; + } + } function pathToPackageJson(directory) { return ts.combinePaths(directory, "package.json"); } @@ -6822,12 +6867,12 @@ var ts; return resolvedUsingSettings; } if (moduleHasNonRelativeName(moduleName)) { - var resolved_3 = forEachAncestorDirectory(containingDirectory, function (directory) { + var resolved_4 = forEachAncestorDirectory(containingDirectory, function (directory) { var searchName = ts.normalizePath(ts.combinePaths(directory, moduleName)); return loadModuleFromFile(extensions, searchName, failedLookupLocations, false, state); }); - if (resolved_3) { - return resolved_3; + if (resolved_4) { + return resolved_4; } if (extensions === 0) { return loadModuleFromNodeModulesAtTypes(moduleName, containingDirectory, failedLookupLocations, state); @@ -7471,6 +7516,16 @@ var ts; return false; } ts.isPartOfTypeNode = isPartOfTypeNode; + function isChildOfLiteralType(node) { + while (node) { + if (node.kind === 171) { + return true; + } + node = node.parent; + } + return false; + } + ts.isChildOfLiteralType = isChildOfLiteralType; function forEachReturnStatement(body, visitor) { return traverse(body); function traverse(node) { @@ -24630,8 +24685,8 @@ var ts; else { var declaredType = getTypeFromMappedTypeNode(type.declaration); var constraint = getConstraintTypeFromMappedType(declaredType); - var extendedConstraint = constraint.flags & 16384 ? getConstraintOfTypeParameter(constraint) : constraint; - type.modifiersType = extendedConstraint.flags & 262144 ? instantiateType(extendedConstraint.type, type.mapper || identityMapper) : emptyObjectType; + var extendedConstraint = constraint && constraint.flags & 16384 ? getConstraintOfTypeParameter(constraint) : constraint; + type.modifiersType = extendedConstraint && extendedConstraint.flags & 262144 ? instantiateType(extendedConstraint.type, type.mapper || identityMapper) : emptyObjectType; } } return type.modifiersType; @@ -27197,8 +27252,11 @@ var ts; } } } - else if (relation !== identityRelation && isEmptyObjectType(resolveStructuredTypeMembers(target))) { - return -1; + else if (relation !== identityRelation) { + var resolved = resolveStructuredTypeMembers(target); + if (isEmptyObjectType(resolved) || resolved.stringIndexInfo && resolved.stringIndexInfo.type.flags & 1) { + return -1; + } } return 0; } @@ -37888,8 +37946,13 @@ var ts; } } function checkGrammarNumericLiteral(node) { - if (node.isOctalLiteral && languageVersion >= 1) { - return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); + if (node.isOctalLiteral) { + if (languageVersion >= 1) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0, node.text); + } + if (ts.isChildOfLiteralType(node)) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0, node.text); + } } } function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { @@ -42675,7 +42738,7 @@ var ts; } } startLexicalEnvironment(); - var loopBody = ts.visitNode(node.statement, visitor, ts.isStatement); + var loopBody = ts.visitNode(node.statement, visitor, ts.isStatement, false, ts.liftToBlock); var lexicalEnvironment = endLexicalEnvironment(); var currentState = convertedLoopState; convertedLoopState = outerConvertedLoopState; @@ -42687,7 +42750,10 @@ var ts; ts.addRange(statements_4, lexicalEnvironment); loopBody = ts.createBlock(statements_4, undefined, true); } - if (!ts.isBlock(loopBody)) { + if (ts.isBlock(loopBody)) { + loopBody.multiLine = true; + } + else { loopBody = ts.createBlock([loopBody], undefined, true); } var isAsyncBlockContainingAwait = enclosingNonArrowFunction @@ -44828,6 +44894,17 @@ var ts; var ts; (function (ts) { function transformES5(context) { + var compilerOptions = context.getCompilerOptions(); + var previousOnEmitNode; + var noSubstitution; + if (compilerOptions.jsx === 1) { + previousOnEmitNode = context.onEmitNode; + context.onEmitNode = onEmitNode; + context.enableEmitNotification(248); + context.enableEmitNotification(249); + context.enableEmitNotification(247); + noSubstitution = []; + } var previousOnSubstituteNode = context.onSubstituteNode; context.onSubstituteNode = onSubstituteNode; context.enableSubstitution(177); @@ -44836,7 +44913,21 @@ var ts; function transformSourceFile(node) { return node; } + function onEmitNode(emitContext, node, emitCallback) { + switch (node.kind) { + case 248: + case 249: + case 247: + var tagName = node.tagName; + noSubstitution[ts.getOriginalNodeId(tagName)] = true; + break; + } + previousOnEmitNode(emitContext, node, emitCallback); + } function onSubstituteNode(emitContext, node) { + if (node.id && noSubstitution && noSubstitution[node.id]) { + return previousOnSubstituteNode(emitContext, node); + } node = previousOnSubstituteNode(emitContext, node); if (ts.isPropertyAccessExpression(node)) { return substitutePropertyAccessExpression(node); @@ -50934,6 +51025,7 @@ var ts; var currentDirectory = host.getCurrentDirectory(); var supportedExtensions = ts.getSupportedExtensions(options); var hasEmitBlockingDiagnostics = ts.createFileMap(getCanonicalFileName); + var moduleResolutionCache; var resolveModuleNamesWorker; if (host.resolveModuleNames) { resolveModuleNamesWorker = function (moduleNames, containingFile) { return host.resolveModuleNames(moduleNames, containingFile).map(function (resolved) { @@ -50946,7 +51038,8 @@ var ts; }); }; } else { - var loader_1 = function (moduleName, containingFile) { return ts.resolveModuleName(moduleName, containingFile, options, host).resolvedModule; }; + moduleResolutionCache = ts.createModuleResolutionCache(currentDirectory, function (x) { return host.getCanonicalFileName(x); }); + var loader_1 = function (moduleName, containingFile) { return ts.resolveModuleName(moduleName, containingFile, options, host, moduleResolutionCache).resolvedModule; }; resolveModuleNamesWorker = function (moduleNames, containingFile) { return loadWithLocalCache(moduleNames, containingFile, loader_1); }; } var resolveTypeReferenceDirectiveNamesWorker; @@ -50982,6 +51075,7 @@ var ts; } } } + moduleResolutionCache = undefined; oldProgram = undefined; program = { getRootFileNames: function () { return rootNames; }, @@ -60790,6 +60884,7 @@ var ts; this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([109, 75]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8)); this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(88, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); + this.SpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionDeclContext), 2)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionDeclContext), 8)); this.SpaceAfterVoidOperator = new formatting.Rule(formatting.RuleDescriptor.create3(104, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsVoidOpContext), 2)); this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(95, 24), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8)); @@ -60798,9 +60893,10 @@ var ts; this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([124, 133]), 70), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); this.SpaceBeforeBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.BinaryKeywordOperators), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsBinaryOpContext), 2)); + this.SpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(122, 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(122, 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8)); this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([127, 131]), 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8)); - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([116, 74, 123, 78, 82, 83, 84, 124, 107, 90, 108, 127, 128, 111, 113, 112, 133, 114, 136, 138]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([116, 74, 123, 78, 82, 83, 84, 124, 107, 90, 108, 127, 128, 111, 113, 112, 130, 133, 114, 136, 138]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([84, 107, 138])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(9, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2)); this.SpaceBeforeArrow = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 35), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); @@ -60856,7 +60952,7 @@ var ts; this.NoSpaceBetweenTagAndTemplateString, this.SpaceBeforeJsxAttribute, this.SpaceBeforeSlashInJsxOpeningElement, this.NoSpaceBeforeGreaterThanTokenInJsxOpeningElement, this.NoSpaceBeforeEqualInJsxAttribute, this.NoSpaceAfterEqualInJsxAttribute, - this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, + this.NoSpaceAfterModuleImport, this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, this.SpaceAfterModuleName, this.SpaceBeforeArrow, this.SpaceAfterArrow, @@ -60879,7 +60975,6 @@ var ts; this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterCloseBracket, this.SpaceAfterSemicolon, - this.NoSpaceBeforeOpenParenInFuncDecl, this.SpaceBetweenStatements, this.SpaceAfterTryFinally ]; this.SpaceAfterComma = new formatting.Rule(formatting.RuleDescriptor.create3(25, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNonJsxElementContext, Rules.IsNextTokenNotCloseBracket), 2)); @@ -61454,6 +61549,12 @@ var ts; }; RulesProvider.prototype.createActiveRules = function (options) { var rules = this.globalRules.HighPriorityCommonRules.slice(0); + if (options.insertSpaceAfterConstructor) { + rules.push(this.globalRules.SpaceAfterConstructor); + } + else { + rules.push(this.globalRules.NoSpaceAfterConstructor); + } if (options.insertSpaceAfterCommaDelimiter) { rules.push(this.globalRules.SpaceAfterComma); } @@ -61532,6 +61633,12 @@ var ts; rules.push(this.globalRules.NoSpaceBeforeBinaryOperator); rules.push(this.globalRules.NoSpaceAfterBinaryOperator); } + if (options.insertSpaceBeforeFunctionParenthesis) { + rules.push(this.globalRules.SpaceBeforeOpenParenInFuncDecl); + } + else { + rules.push(this.globalRules.NoSpaceBeforeOpenParenInFuncDecl); + } if (options.placeOpenBraceOnNewLineForControlBlocks) { rules.push(this.globalRules.NewLineBeforeOpenBraceInControl); } diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index bb16e6737c464..ea2e9ecad5dd2 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -767,12 +767,14 @@ declare namespace ts.server.protocol { insertSpaceAfterCommaDelimiter?: boolean; insertSpaceAfterSemicolonInForStatements?: boolean; insertSpaceBeforeAndAfterBinaryOperators?: boolean; + insertSpaceAfterConstructor?: boolean; insertSpaceAfterKeywordsInControlFlowStatements?: boolean; insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean; insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean; insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean; insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean; insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; + insertSpaceBeforeFunctionParenthesis?: boolean; placeOpenBraceOnNewLineForFunctions?: boolean; placeOpenBraceOnNewLineForControlBlocks?: boolean; } @@ -4181,7 +4183,7 @@ declare namespace ts { key: string; message: string; }; - Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { + Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0: { code: number; category: DiagnosticCategory; key: string; @@ -7865,6 +7867,12 @@ declare namespace ts { key: string; message: string; }; + File_0_has_an_unsupported_extension_so_skipping_it: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; Only_amd_and_system_modules_are_supported_alongside_0: { code: number; category: DiagnosticCategory; @@ -8255,6 +8263,12 @@ declare namespace ts { key: string; message: string; }; + Resolution_for_module_0_was_found_in_cache: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; Variable_0_implicitly_has_an_1_type: { code: number; category: DiagnosticCategory; @@ -8687,6 +8701,12 @@ declare namespace ts { key: string; message: string; }; + Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; }; } declare namespace ts { @@ -8907,7 +8927,13 @@ declare namespace ts { }): string[] | undefined; function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost): ResolvedTypeReferenceDirectiveWithFailedLookupLocations; function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[]; - function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; + interface ModuleResolutionCache { + getOrCreateCacheForDirectory(directoryName: string): Map; + } + function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string): { + getOrCreateCacheForDirectory: (directoryName: string) => Map; + }; + function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations; function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; function directoryProbablyExists(directoryName: string, host: { directoryExists?: (directoryName: string) => boolean; @@ -8991,6 +9017,7 @@ declare namespace ts { let fullTripleSlashReferenceTypeReferenceDirectiveRegEx: RegExp; let fullTripleSlashAMDReferencePathRegEx: RegExp; function isPartOfTypeNode(node: Node): boolean; + function isChildOfLiteralType(node: Node): boolean; function forEachReturnStatement(body: Block, visitor: (stmt: ReturnStatement) => T): T; function forEachYieldExpression(body: Block, visitor: (expr: YieldExpression) => void): void; function getRestParameterElementType(node: TypeNode): TypeNode; @@ -10049,6 +10076,7 @@ declare namespace ts { InsertSpaceAfterCommaDelimiter: boolean; InsertSpaceAfterSemicolonInForStatements: boolean; InsertSpaceBeforeAndAfterBinaryOperators: boolean; + InsertSpaceAfterConstructor?: boolean; InsertSpaceAfterKeywordsInControlFlowStatements: boolean; InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean; InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean; @@ -10057,6 +10085,7 @@ declare namespace ts { InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; InsertSpaceAfterTypeAssertion?: boolean; + InsertSpaceBeforeFunctionParenthesis?: boolean; PlaceOpenBraceOnNewLineForFunctions: boolean; PlaceOpenBraceOnNewLineForControlBlocks: boolean; } @@ -10064,6 +10093,7 @@ declare namespace ts { insertSpaceAfterCommaDelimiter?: boolean; insertSpaceAfterSemicolonInForStatements?: boolean; insertSpaceBeforeAndAfterBinaryOperators?: boolean; + insertSpaceAfterConstructor?: boolean; insertSpaceAfterKeywordsInControlFlowStatements?: boolean; insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean; insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean; @@ -10072,6 +10102,7 @@ declare namespace ts { insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean; insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; insertSpaceAfterTypeAssertion?: boolean; + insertSpaceBeforeFunctionParenthesis?: boolean; placeOpenBraceOnNewLineForFunctions?: boolean; placeOpenBraceOnNewLineForControlBlocks?: boolean; } @@ -10710,6 +10741,7 @@ declare namespace ts.formatting { SpaceAfterLetConstInVariableDeclaration: Rule; NoSpaceBeforeOpenParenInFuncCall: Rule; SpaceAfterFunctionInFuncDecl: Rule; + SpaceBeforeOpenParenInFuncDecl: Rule; NoSpaceBeforeOpenParenInFuncDecl: Rule; SpaceAfterVoidOperator: Rule; NoSpaceBetweenReturnAndSemicolon: Rule; @@ -10718,6 +10750,7 @@ declare namespace ts.formatting { SpaceAfterGetSetInMember: Rule; SpaceBeforeBinaryKeywordOperator: Rule; SpaceAfterBinaryKeywordOperator: Rule; + SpaceAfterConstructor: Rule; NoSpaceAfterConstructor: Rule; NoSpaceAfterModuleImport: Rule; SpaceAfterCertainTypeScriptKeywords: Rule; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 038148db28d5f..20082c7fd2578 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -2475,7 +2475,7 @@ var ts; _0_modifier_cannot_appear_on_an_index_signature: { code: 1071, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_an_index_signature_1071", message: "'{0}' modifier cannot appear on an index signature." }, A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A_0_modifier_cannot_be_used_with_an_import_declaration_1079", message: "A '{0}' modifier cannot be used with an import declaration." }, Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid_reference_directive_syntax_1084", message: "Invalid 'reference' directive syntax." }, - Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_1085", message: "Octal literals are not available when targeting ECMAScript 5 and higher." }, + Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0_1085", message: "Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o{0}'." }, An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: ts.DiagnosticCategory.Error, key: "An_accessor_cannot_be_declared_in_an_ambient_context_1086", message: "An accessor cannot be declared in an ambient context." }, _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_a_constructor_declaration_1089", message: "'{0}' modifier cannot appear on a constructor declaration." }, _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_a_parameter_1090", message: "'{0}' modifier cannot appear on a parameter." }, @@ -3089,6 +3089,7 @@ var ts; Disallow_inconsistently_cased_references_to_the_same_file: { code: 6078, category: ts.DiagnosticCategory.Message, key: "Disallow_inconsistently_cased_references_to_the_same_file_6078", message: "Disallow inconsistently-cased references to the same file." }, Specify_library_files_to_be_included_in_the_compilation_Colon: { code: 6079, category: ts.DiagnosticCategory.Message, key: "Specify_library_files_to_be_included_in_the_compilation_Colon_6079", message: "Specify library files to be included in the compilation: " }, Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify_JSX_code_generation_Colon_preserve_or_react_6080", message: "Specify JSX code generation: 'preserve' or 'react'" }, + File_0_has_an_unsupported_extension_so_skipping_it: { code: 6081, category: ts.DiagnosticCategory.Message, key: "File_0_has_an_unsupported_extension_so_skipping_it_6081", message: "File '{0}' has an unsupported extension, so skipping it." }, Only_amd_and_system_modules_are_supported_alongside_0: { code: 6082, category: ts.DiagnosticCategory.Error, key: "Only_amd_and_system_modules_are_supported_alongside_0_6082", message: "Only 'amd' and 'system' modules are supported alongside --{0}." }, Base_directory_to_resolve_non_absolute_module_names: { code: 6083, category: ts.DiagnosticCategory.Message, key: "Base_directory_to_resolve_non_absolute_module_names_6083", message: "Base directory to resolve non-absolute module names." }, Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit: { code: 6084, category: ts.DiagnosticCategory.Message, key: "Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit_6084", message: "Specify the object invoked for createElement and __spread when targeting 'react' JSX emit" }, @@ -3154,6 +3155,7 @@ var ts; Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1: { code: 6144, category: ts.DiagnosticCategory.Message, key: "Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1_6144", message: "Module '{0}' was resolved as locally declared ambient module in file '{1}'." }, Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified: { code: 6145, category: ts.DiagnosticCategory.Message, key: "Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified_6145", message: "Module '{0}' was resolved as ambient module declared in '{1}' since this file was not modified." }, Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h: { code: 6146, category: ts.DiagnosticCategory.Message, key: "Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h_6146", message: "Specify the JSX factory function to use when targeting 'react' JSX emit, e.g. 'React.createElement' or 'h'." }, + Resolution_for_module_0_was_found_in_cache: { code: 6147, category: ts.DiagnosticCategory.Message, key: "Resolution_for_module_0_was_found_in_cache_6147", message: "Resolution for module '{0}' was found in cache" }, 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." }, @@ -3226,6 +3228,7 @@ var ts; Import_0_from_1: { code: 90013, category: ts.DiagnosticCategory.Message, key: "Import_0_from_1_90013", message: "Import {0} from {1}" }, Change_0_to_1: { code: 90014, category: ts.DiagnosticCategory.Message, key: "Change_0_to_1_90014", message: "Change {0} to {1}" }, Add_0_to_existing_import_declaration_from_1: { code: 90015, category: ts.DiagnosticCategory.Message, key: "Add_0_to_existing_import_declaration_from_1_90015", message: "Add {0} to existing import declaration from {1}" }, + Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0: { code: 8017, category: ts.DiagnosticCategory.Error, key: "Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0_8017", message: "Octal literal types must use ES2015 syntax. Use the syntax '0o{0}'." }, }; })(ts || (ts = {})); var ts; @@ -6156,6 +6159,7 @@ var ts; newLineCharacter: host.newLine || "\n", convertTabsToSpaces: true, indentStyle: ts.IndentStyle.Smart, + insertSpaceAfterConstructor: false, insertSpaceAfterCommaDelimiter: true, insertSpaceAfterSemicolonInForStatements: true, insertSpaceBeforeAndAfterBinaryOperators: true, @@ -6165,6 +6169,7 @@ var ts; insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false, insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false, insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false, + insertSpaceBeforeFunctionParenthesis: false, placeOpenBraceOnNewLineForFunctions: false, placeOpenBraceOnNewLineForControlBlocks: false, }; @@ -6300,9 +6305,6 @@ var ts; ts.Debug.assert(ts.extensionIsTypeScript(resolved.extension)); return resolved.path; } - function resolvedFromAnyFile(path) { - return { path: path, extension: ts.extensionFromPath(path) }; - } function resolvedModuleFromResolved(_a, isExternalLibraryImport) { var path = _a.path, extension = _a.extension; return { resolvedFileName: path, extension: extension, isExternalLibraryImport: isExternalLibraryImport }; @@ -6314,7 +6316,7 @@ var ts; return !(ts.isRootedDiskPath(moduleName) || ts.isExternalModuleNameRelative(moduleName)); } ts.moduleHasNonRelativeName = moduleHasNonRelativeName; - function tryReadTypesSection(extensions, packageJsonPath, baseDirectory, state) { + function tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, baseDirectory, state) { var jsonContent = readJson(packageJsonPath, state.host); switch (extensions) { case 2: @@ -6493,31 +6495,56 @@ var ts; return result; } ts.getAutomaticTypeDirectiveNames = getAutomaticTypeDirectiveNames; - function resolveModuleName(moduleName, containingFile, compilerOptions, host) { + function createModuleResolutionCache(currentDirectory, getCanonicalFileName) { + var map = ts.createFileMap(); + return { getOrCreateCacheForDirectory: getOrCreateCacheForDirectory }; + function getOrCreateCacheForDirectory(directoryName) { + var path = ts.toPath(directoryName, currentDirectory, getCanonicalFileName); + var perFolderCache = map.get(path); + if (!perFolderCache) { + perFolderCache = ts.createMap(); + map.set(path, perFolderCache); + } + return perFolderCache; + } + } + ts.createModuleResolutionCache = createModuleResolutionCache; + function resolveModuleName(moduleName, containingFile, compilerOptions, host, cache) { var traceEnabled = isTraceEnabled(compilerOptions, host); if (traceEnabled) { trace(host, ts.Diagnostics.Resolving_module_0_from_1, moduleName, containingFile); } - var moduleResolution = compilerOptions.moduleResolution; - if (moduleResolution === undefined) { - moduleResolution = ts.getEmitModuleKind(compilerOptions) === ts.ModuleKind.CommonJS ? ts.ModuleResolutionKind.NodeJs : ts.ModuleResolutionKind.Classic; + var perFolderCache = cache && cache.getOrCreateCacheForDirectory(ts.getDirectoryPath(containingFile)); + var result = perFolderCache && perFolderCache[moduleName]; + if (result) { if (traceEnabled) { - trace(host, ts.Diagnostics.Module_resolution_kind_is_not_specified_using_0, ts.ModuleResolutionKind[moduleResolution]); + trace(host, ts.Diagnostics.Resolution_for_module_0_was_found_in_cache, moduleName); } } else { - if (traceEnabled) { - trace(host, ts.Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ts.ModuleResolutionKind[moduleResolution]); + var moduleResolution = compilerOptions.moduleResolution; + if (moduleResolution === undefined) { + moduleResolution = ts.getEmitModuleKind(compilerOptions) === ts.ModuleKind.CommonJS ? ts.ModuleResolutionKind.NodeJs : ts.ModuleResolutionKind.Classic; + if (traceEnabled) { + trace(host, ts.Diagnostics.Module_resolution_kind_is_not_specified_using_0, ts.ModuleResolutionKind[moduleResolution]); + } + } + else { + if (traceEnabled) { + trace(host, ts.Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ts.ModuleResolutionKind[moduleResolution]); + } + } + switch (moduleResolution) { + case ts.ModuleResolutionKind.NodeJs: + result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); + break; + case ts.ModuleResolutionKind.Classic: + result = classicNameResolver(moduleName, containingFile, compilerOptions, host); + break; + } + if (perFolderCache) { + perFolderCache[moduleName] = result; } - } - var result; - switch (moduleResolution) { - case ts.ModuleResolutionKind.NodeJs: - result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); - break; - case ts.ModuleResolutionKind.Classic: - result = classicNameResolver(moduleName, containingFile, compilerOptions, host); - break; } if (traceEnabled) { if (result.resolvedModule) { @@ -6750,16 +6777,20 @@ var ts; if (state.traceEnabled) { trace(state.host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath); } - var typesFile = tryReadTypesSection(extensions, packageJsonPath, candidate, state); - if (typesFile) { - var onlyRecordFailures_1 = !directoryProbablyExists(ts.getDirectoryPath(typesFile), state.host); - var fromFile = tryFile(typesFile, failedLookupLocations, onlyRecordFailures_1, state); - if (fromFile) { - return resolvedFromAnyFile(fromFile); + var mainOrTypesFile = tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, candidate, state); + if (mainOrTypesFile) { + var onlyRecordFailures_1 = !directoryProbablyExists(ts.getDirectoryPath(mainOrTypesFile), state.host); + var fromExactFile = tryFile(mainOrTypesFile, failedLookupLocations, onlyRecordFailures_1, state); + if (fromExactFile) { + var resolved_3 = fromExactFile && resolvedIfExtensionMatches(extensions, fromExactFile); + if (resolved_3) { + return resolved_3; + } + trace(state.host, ts.Diagnostics.File_0_has_an_unsupported_extension_so_skipping_it, fromExactFile); } - var x = tryAddingExtensions(typesFile, 0, failedLookupLocations, onlyRecordFailures_1, state); - if (x) { - return x; + var resolved = tryAddingExtensions(mainOrTypesFile, 0, failedLookupLocations, onlyRecordFailures_1, state); + if (resolved) { + return resolved; } } else { @@ -6776,6 +6807,20 @@ var ts; } return loadModuleFromFile(extensions, ts.combinePaths(candidate, "index"), failedLookupLocations, !directoryExists, state); } + function resolvedIfExtensionMatches(extensions, path) { + var extension = ts.tryGetExtensionFromPath(path); + return extension !== undefined && extensionIsOk(extensions, extension) ? { path: path, extension: extension } : undefined; + } + function extensionIsOk(extensions, extension) { + switch (extensions) { + case 1: + return extension === ts.Extension.Js || extension === ts.Extension.Jsx; + case 0: + return extension === ts.Extension.Ts || extension === ts.Extension.Tsx || extension === ts.Extension.Dts; + case 2: + return extension === ts.Extension.Dts; + } + } function pathToPackageJson(directory) { return ts.combinePaths(directory, "package.json"); } @@ -6822,12 +6867,12 @@ var ts; return resolvedUsingSettings; } if (moduleHasNonRelativeName(moduleName)) { - var resolved_3 = forEachAncestorDirectory(containingDirectory, function (directory) { + var resolved_4 = forEachAncestorDirectory(containingDirectory, function (directory) { var searchName = ts.normalizePath(ts.combinePaths(directory, moduleName)); return loadModuleFromFile(extensions, searchName, failedLookupLocations, false, state); }); - if (resolved_3) { - return resolved_3; + if (resolved_4) { + return resolved_4; } if (extensions === 0) { return loadModuleFromNodeModulesAtTypes(moduleName, containingDirectory, failedLookupLocations, state); @@ -7471,6 +7516,16 @@ var ts; return false; } ts.isPartOfTypeNode = isPartOfTypeNode; + function isChildOfLiteralType(node) { + while (node) { + if (node.kind === 171) { + return true; + } + node = node.parent; + } + return false; + } + ts.isChildOfLiteralType = isChildOfLiteralType; function forEachReturnStatement(body, visitor) { return traverse(body); function traverse(node) { @@ -24630,8 +24685,8 @@ var ts; else { var declaredType = getTypeFromMappedTypeNode(type.declaration); var constraint = getConstraintTypeFromMappedType(declaredType); - var extendedConstraint = constraint.flags & 16384 ? getConstraintOfTypeParameter(constraint) : constraint; - type.modifiersType = extendedConstraint.flags & 262144 ? instantiateType(extendedConstraint.type, type.mapper || identityMapper) : emptyObjectType; + var extendedConstraint = constraint && constraint.flags & 16384 ? getConstraintOfTypeParameter(constraint) : constraint; + type.modifiersType = extendedConstraint && extendedConstraint.flags & 262144 ? instantiateType(extendedConstraint.type, type.mapper || identityMapper) : emptyObjectType; } } return type.modifiersType; @@ -27197,8 +27252,11 @@ var ts; } } } - else if (relation !== identityRelation && isEmptyObjectType(resolveStructuredTypeMembers(target))) { - return -1; + else if (relation !== identityRelation) { + var resolved = resolveStructuredTypeMembers(target); + if (isEmptyObjectType(resolved) || resolved.stringIndexInfo && resolved.stringIndexInfo.type.flags & 1) { + return -1; + } } return 0; } @@ -37888,8 +37946,13 @@ var ts; } } function checkGrammarNumericLiteral(node) { - if (node.isOctalLiteral && languageVersion >= 1) { - return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); + if (node.isOctalLiteral) { + if (languageVersion >= 1) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0, node.text); + } + if (ts.isChildOfLiteralType(node)) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0, node.text); + } } } function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { @@ -42675,7 +42738,7 @@ var ts; } } startLexicalEnvironment(); - var loopBody = ts.visitNode(node.statement, visitor, ts.isStatement); + var loopBody = ts.visitNode(node.statement, visitor, ts.isStatement, false, ts.liftToBlock); var lexicalEnvironment = endLexicalEnvironment(); var currentState = convertedLoopState; convertedLoopState = outerConvertedLoopState; @@ -42687,7 +42750,10 @@ var ts; ts.addRange(statements_4, lexicalEnvironment); loopBody = ts.createBlock(statements_4, undefined, true); } - if (!ts.isBlock(loopBody)) { + if (ts.isBlock(loopBody)) { + loopBody.multiLine = true; + } + else { loopBody = ts.createBlock([loopBody], undefined, true); } var isAsyncBlockContainingAwait = enclosingNonArrowFunction @@ -44828,6 +44894,17 @@ var ts; var ts; (function (ts) { function transformES5(context) { + var compilerOptions = context.getCompilerOptions(); + var previousOnEmitNode; + var noSubstitution; + if (compilerOptions.jsx === 1) { + previousOnEmitNode = context.onEmitNode; + context.onEmitNode = onEmitNode; + context.enableEmitNotification(248); + context.enableEmitNotification(249); + context.enableEmitNotification(247); + noSubstitution = []; + } var previousOnSubstituteNode = context.onSubstituteNode; context.onSubstituteNode = onSubstituteNode; context.enableSubstitution(177); @@ -44836,7 +44913,21 @@ var ts; function transformSourceFile(node) { return node; } + function onEmitNode(emitContext, node, emitCallback) { + switch (node.kind) { + case 248: + case 249: + case 247: + var tagName = node.tagName; + noSubstitution[ts.getOriginalNodeId(tagName)] = true; + break; + } + previousOnEmitNode(emitContext, node, emitCallback); + } function onSubstituteNode(emitContext, node) { + if (node.id && noSubstitution && noSubstitution[node.id]) { + return previousOnSubstituteNode(emitContext, node); + } node = previousOnSubstituteNode(emitContext, node); if (ts.isPropertyAccessExpression(node)) { return substitutePropertyAccessExpression(node); @@ -50934,6 +51025,7 @@ var ts; var currentDirectory = host.getCurrentDirectory(); var supportedExtensions = ts.getSupportedExtensions(options); var hasEmitBlockingDiagnostics = ts.createFileMap(getCanonicalFileName); + var moduleResolutionCache; var resolveModuleNamesWorker; if (host.resolveModuleNames) { resolveModuleNamesWorker = function (moduleNames, containingFile) { return host.resolveModuleNames(moduleNames, containingFile).map(function (resolved) { @@ -50946,7 +51038,8 @@ var ts; }); }; } else { - var loader_1 = function (moduleName, containingFile) { return ts.resolveModuleName(moduleName, containingFile, options, host).resolvedModule; }; + moduleResolutionCache = ts.createModuleResolutionCache(currentDirectory, function (x) { return host.getCanonicalFileName(x); }); + var loader_1 = function (moduleName, containingFile) { return ts.resolveModuleName(moduleName, containingFile, options, host, moduleResolutionCache).resolvedModule; }; resolveModuleNamesWorker = function (moduleNames, containingFile) { return loadWithLocalCache(moduleNames, containingFile, loader_1); }; } var resolveTypeReferenceDirectiveNamesWorker; @@ -50982,6 +51075,7 @@ var ts; } } } + moduleResolutionCache = undefined; oldProgram = undefined; program = { getRootFileNames: function () { return rootNames; }, @@ -60790,6 +60884,7 @@ var ts; this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([109, 75]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8)); this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(88, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); + this.SpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionDeclContext), 2)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionDeclContext), 8)); this.SpaceAfterVoidOperator = new formatting.Rule(formatting.RuleDescriptor.create3(104, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsVoidOpContext), 2)); this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(95, 24), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8)); @@ -60798,9 +60893,10 @@ var ts; this.SpaceAfterGetSetInMember = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([124, 133]), 70), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2)); this.SpaceBeforeBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.BinaryKeywordOperators), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsBinaryOpContext), 2)); + this.SpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(122, 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(122, 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8)); this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([127, 131]), 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8)); - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([116, 74, 123, 78, 82, 83, 84, 124, 107, 90, 108, 127, 128, 111, 113, 112, 133, 114, 136, 138]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([116, 74, 123, 78, 82, 83, 84, 124, 107, 90, 108, 127, 128, 111, 113, 112, 130, 133, 114, 136, 138]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([84, 107, 138])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(9, 16), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2)); this.SpaceBeforeArrow = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 35), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); @@ -60856,7 +60952,7 @@ var ts; this.NoSpaceBetweenTagAndTemplateString, this.SpaceBeforeJsxAttribute, this.SpaceBeforeSlashInJsxOpeningElement, this.NoSpaceBeforeGreaterThanTokenInJsxOpeningElement, this.NoSpaceBeforeEqualInJsxAttribute, this.NoSpaceAfterEqualInJsxAttribute, - this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, + this.NoSpaceAfterModuleImport, this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, this.SpaceAfterModuleName, this.SpaceBeforeArrow, this.SpaceAfterArrow, @@ -60879,7 +60975,6 @@ var ts; this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterCloseBracket, this.SpaceAfterSemicolon, - this.NoSpaceBeforeOpenParenInFuncDecl, this.SpaceBetweenStatements, this.SpaceAfterTryFinally ]; this.SpaceAfterComma = new formatting.Rule(formatting.RuleDescriptor.create3(25, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNonJsxElementContext, Rules.IsNextTokenNotCloseBracket), 2)); @@ -61454,6 +61549,12 @@ var ts; }; RulesProvider.prototype.createActiveRules = function (options) { var rules = this.globalRules.HighPriorityCommonRules.slice(0); + if (options.insertSpaceAfterConstructor) { + rules.push(this.globalRules.SpaceAfterConstructor); + } + else { + rules.push(this.globalRules.NoSpaceAfterConstructor); + } if (options.insertSpaceAfterCommaDelimiter) { rules.push(this.globalRules.SpaceAfterComma); } @@ -61532,6 +61633,12 @@ var ts; rules.push(this.globalRules.NoSpaceBeforeBinaryOperator); rules.push(this.globalRules.NoSpaceAfterBinaryOperator); } + if (options.insertSpaceBeforeFunctionParenthesis) { + rules.push(this.globalRules.SpaceBeforeOpenParenInFuncDecl); + } + else { + rules.push(this.globalRules.NoSpaceBeforeOpenParenInFuncDecl); + } if (options.placeOpenBraceOnNewLineForControlBlocks) { rules.push(this.globalRules.NewLineBeforeOpenBraceInControl); } diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 71e59c99f8585..0138c8c3d2e0c 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -2325,7 +2325,17 @@ declare namespace ts { * this list is only the set of defaults that are implicitly included. */ function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[]; - function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; + /** + * Cached module resolutions per containing directory. + * This assumes that any module id will have the same resolution for sibling files located in the same folder. + */ + interface ModuleResolutionCache { + getOrCreateCacheForDirectory(directoryName: string): Map; + } + function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string): { + getOrCreateCacheForDirectory: (directoryName: string) => Map; + }; + function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations; function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; } @@ -2344,6 +2354,7 @@ declare namespace ts { function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program; } declare namespace ts { + function parseCommandLine(commandLine: string[], readFile?: (path: string) => string): ParsedCommandLine; /** * Read tsconfig.json file * @param fileName The path to the config file @@ -2675,6 +2686,7 @@ declare namespace ts { InsertSpaceAfterCommaDelimiter: boolean; InsertSpaceAfterSemicolonInForStatements: boolean; InsertSpaceBeforeAndAfterBinaryOperators: boolean; + InsertSpaceAfterConstructor?: boolean; InsertSpaceAfterKeywordsInControlFlowStatements: boolean; InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean; InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean; @@ -2683,6 +2695,7 @@ declare namespace ts { InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; InsertSpaceAfterTypeAssertion?: boolean; + InsertSpaceBeforeFunctionParenthesis?: boolean; PlaceOpenBraceOnNewLineForFunctions: boolean; PlaceOpenBraceOnNewLineForControlBlocks: boolean; } @@ -2690,6 +2703,7 @@ declare namespace ts { insertSpaceAfterCommaDelimiter?: boolean; insertSpaceAfterSemicolonInForStatements?: boolean; insertSpaceBeforeAndAfterBinaryOperators?: boolean; + insertSpaceAfterConstructor?: boolean; insertSpaceAfterKeywordsInControlFlowStatements?: boolean; insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean; insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean; @@ -2698,6 +2712,7 @@ declare namespace ts { insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean; insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; insertSpaceAfterTypeAssertion?: boolean; + insertSpaceBeforeFunctionParenthesis?: boolean; placeOpenBraceOnNewLineForFunctions?: boolean; placeOpenBraceOnNewLineForControlBlocks?: boolean; } diff --git a/lib/typescript.js b/lib/typescript.js index 82c7bea3a40cf..a931f73c19a78 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -3915,7 +3915,7 @@ var ts; _0_modifier_cannot_appear_on_an_index_signature: { code: 1071, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_an_index_signature_1071", message: "'{0}' modifier cannot appear on an index signature." }, A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A_0_modifier_cannot_be_used_with_an_import_declaration_1079", message: "A '{0}' modifier cannot be used with an import declaration." }, Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid_reference_directive_syntax_1084", message: "Invalid 'reference' directive syntax." }, - Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_1085", message: "Octal literals are not available when targeting ECMAScript 5 and higher." }, + Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0_1085", message: "Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o{0}'." }, An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: ts.DiagnosticCategory.Error, key: "An_accessor_cannot_be_declared_in_an_ambient_context_1086", message: "An accessor cannot be declared in an ambient context." }, _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_a_constructor_declaration_1089", message: "'{0}' modifier cannot appear on a constructor declaration." }, _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_a_parameter_1090", message: "'{0}' modifier cannot appear on a parameter." }, @@ -4529,6 +4529,7 @@ var ts; Disallow_inconsistently_cased_references_to_the_same_file: { code: 6078, category: ts.DiagnosticCategory.Message, key: "Disallow_inconsistently_cased_references_to_the_same_file_6078", message: "Disallow inconsistently-cased references to the same file." }, Specify_library_files_to_be_included_in_the_compilation_Colon: { code: 6079, category: ts.DiagnosticCategory.Message, key: "Specify_library_files_to_be_included_in_the_compilation_Colon_6079", message: "Specify library files to be included in the compilation: " }, Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify_JSX_code_generation_Colon_preserve_or_react_6080", message: "Specify JSX code generation: 'preserve' or 'react'" }, + File_0_has_an_unsupported_extension_so_skipping_it: { code: 6081, category: ts.DiagnosticCategory.Message, key: "File_0_has_an_unsupported_extension_so_skipping_it_6081", message: "File '{0}' has an unsupported extension, so skipping it." }, Only_amd_and_system_modules_are_supported_alongside_0: { code: 6082, category: ts.DiagnosticCategory.Error, key: "Only_amd_and_system_modules_are_supported_alongside_0_6082", message: "Only 'amd' and 'system' modules are supported alongside --{0}." }, Base_directory_to_resolve_non_absolute_module_names: { code: 6083, category: ts.DiagnosticCategory.Message, key: "Base_directory_to_resolve_non_absolute_module_names_6083", message: "Base directory to resolve non-absolute module names." }, Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit: { code: 6084, category: ts.DiagnosticCategory.Message, key: "Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit_6084", message: "Specify the object invoked for createElement and __spread when targeting 'react' JSX emit" }, @@ -4594,6 +4595,7 @@ var ts; Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1: { code: 6144, category: ts.DiagnosticCategory.Message, key: "Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1_6144", message: "Module '{0}' was resolved as locally declared ambient module in file '{1}'." }, Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified: { code: 6145, category: ts.DiagnosticCategory.Message, key: "Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified_6145", message: "Module '{0}' was resolved as ambient module declared in '{1}' since this file was not modified." }, Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h: { code: 6146, category: ts.DiagnosticCategory.Message, key: "Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h_6146", message: "Specify the JSX factory function to use when targeting 'react' JSX emit, e.g. 'React.createElement' or 'h'." }, + Resolution_for_module_0_was_found_in_cache: { code: 6147, category: ts.DiagnosticCategory.Message, key: "Resolution_for_module_0_was_found_in_cache_6147", message: "Resolution for module '{0}' was found in cache" }, 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." }, @@ -4666,6 +4668,7 @@ var ts; Import_0_from_1: { code: 90013, category: ts.DiagnosticCategory.Message, key: "Import_0_from_1_90013", message: "Import {0} from {1}" }, Change_0_to_1: { code: 90014, category: ts.DiagnosticCategory.Message, key: "Change_0_to_1_90014", message: "Change {0} to {1}" }, Add_0_to_existing_import_declaration_from_1: { code: 90015, category: ts.DiagnosticCategory.Message, key: "Add_0_to_existing_import_declaration_from_1_90015", message: "Add {0} to existing import declaration from {1}" }, + Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0: { code: 8017, category: ts.DiagnosticCategory.Error, key: "Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0_8017", message: "Octal literal types must use ES2015 syntax. Use the syntax '0o{0}'." }, }; })(ts || (ts = {})); /// @@ -7081,6 +7084,16 @@ var ts; return false; } ts.isPartOfTypeNode = isPartOfTypeNode; + function isChildOfLiteralType(node) { + while (node) { + if (node.kind === 171 /* LiteralType */) { + return true; + } + node = node.parent; + } + return false; + } + ts.isChildOfLiteralType = isChildOfLiteralType; // Warning: This has the same semantics as the forEach family of functions, // in that traversal terminates in the event that 'visitor' supplies a truthy value. function forEachReturnStatement(body, visitor) { @@ -23387,10 +23400,6 @@ var ts; ts.Debug.assert(ts.extensionIsTypeScript(resolved.extension)); return resolved.path; } - /** Create Resolved from a file with unknown extension. */ - function resolvedFromAnyFile(path) { - return { path: path, extension: ts.extensionFromPath(path) }; - } /** Adds `isExernalLibraryImport` to a Resolved to get a ResolvedModule. */ function resolvedModuleFromResolved(_a, isExternalLibraryImport) { var path = _a.path, extension = _a.extension; @@ -23403,7 +23412,8 @@ var ts; return !(ts.isRootedDiskPath(moduleName) || ts.isExternalModuleNameRelative(moduleName)); } ts.moduleHasNonRelativeName = moduleHasNonRelativeName; - function tryReadTypesSection(extensions, packageJsonPath, baseDirectory, state) { + /** Reads from "main" or "types"/"typings" depending on `extensions`. */ + function tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, baseDirectory, state) { var jsonContent = readJson(packageJsonPath, state.host); switch (extensions) { case 2 /* DtsOnly */: @@ -23606,31 +23616,56 @@ var ts; return result; } ts.getAutomaticTypeDirectiveNames = getAutomaticTypeDirectiveNames; - function resolveModuleName(moduleName, containingFile, compilerOptions, host) { + function createModuleResolutionCache(currentDirectory, getCanonicalFileName) { + var map = ts.createFileMap(); + return { getOrCreateCacheForDirectory: getOrCreateCacheForDirectory }; + function getOrCreateCacheForDirectory(directoryName) { + var path = ts.toPath(directoryName, currentDirectory, getCanonicalFileName); + var perFolderCache = map.get(path); + if (!perFolderCache) { + perFolderCache = ts.createMap(); + map.set(path, perFolderCache); + } + return perFolderCache; + } + } + ts.createModuleResolutionCache = createModuleResolutionCache; + function resolveModuleName(moduleName, containingFile, compilerOptions, host, cache) { var traceEnabled = isTraceEnabled(compilerOptions, host); if (traceEnabled) { trace(host, ts.Diagnostics.Resolving_module_0_from_1, moduleName, containingFile); } - var moduleResolution = compilerOptions.moduleResolution; - if (moduleResolution === undefined) { - moduleResolution = ts.getEmitModuleKind(compilerOptions) === ts.ModuleKind.CommonJS ? ts.ModuleResolutionKind.NodeJs : ts.ModuleResolutionKind.Classic; + var perFolderCache = cache && cache.getOrCreateCacheForDirectory(ts.getDirectoryPath(containingFile)); + var result = perFolderCache && perFolderCache[moduleName]; + if (result) { if (traceEnabled) { - trace(host, ts.Diagnostics.Module_resolution_kind_is_not_specified_using_0, ts.ModuleResolutionKind[moduleResolution]); + trace(host, ts.Diagnostics.Resolution_for_module_0_was_found_in_cache, moduleName); } } else { - if (traceEnabled) { - trace(host, ts.Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ts.ModuleResolutionKind[moduleResolution]); + var moduleResolution = compilerOptions.moduleResolution; + if (moduleResolution === undefined) { + moduleResolution = ts.getEmitModuleKind(compilerOptions) === ts.ModuleKind.CommonJS ? ts.ModuleResolutionKind.NodeJs : ts.ModuleResolutionKind.Classic; + if (traceEnabled) { + trace(host, ts.Diagnostics.Module_resolution_kind_is_not_specified_using_0, ts.ModuleResolutionKind[moduleResolution]); + } + } + else { + if (traceEnabled) { + trace(host, ts.Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ts.ModuleResolutionKind[moduleResolution]); + } + } + switch (moduleResolution) { + case ts.ModuleResolutionKind.NodeJs: + result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); + break; + case ts.ModuleResolutionKind.Classic: + result = classicNameResolver(moduleName, containingFile, compilerOptions, host); + break; + } + if (perFolderCache) { + perFolderCache[moduleName] = result; } - } - var result; - switch (moduleResolution) { - case ts.ModuleResolutionKind.NodeJs: - result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); - break; - case ts.ModuleResolutionKind.Classic: - result = classicNameResolver(moduleName, containingFile, compilerOptions, host); - break; } if (traceEnabled) { if (result.resolvedModule) { @@ -23944,18 +23979,21 @@ var ts; if (state.traceEnabled) { trace(state.host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath); } - var typesFile = tryReadTypesSection(extensions, packageJsonPath, candidate, state); - if (typesFile) { - var onlyRecordFailures_1 = !directoryProbablyExists(ts.getDirectoryPath(typesFile), state.host); + var mainOrTypesFile = tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, candidate, state); + if (mainOrTypesFile) { + var onlyRecordFailures_1 = !directoryProbablyExists(ts.getDirectoryPath(mainOrTypesFile), state.host); // A package.json "typings" may specify an exact filename, or may choose to omit an extension. - var fromFile = tryFile(typesFile, failedLookupLocations, onlyRecordFailures_1, state); - if (fromFile) { - // Note: this would allow a package.json to specify a ".js" file as typings. Maybe that should be forbidden. - return resolvedFromAnyFile(fromFile); + var fromExactFile = tryFile(mainOrTypesFile, failedLookupLocations, onlyRecordFailures_1, state); + if (fromExactFile) { + var resolved_3 = fromExactFile && resolvedIfExtensionMatches(extensions, fromExactFile); + if (resolved_3) { + return resolved_3; + } + trace(state.host, ts.Diagnostics.File_0_has_an_unsupported_extension_so_skipping_it, fromExactFile); } - var x = tryAddingExtensions(typesFile, 0 /* TypeScript */, failedLookupLocations, onlyRecordFailures_1, state); - if (x) { - return x; + var resolved = tryAddingExtensions(mainOrTypesFile, 0 /* TypeScript */, failedLookupLocations, onlyRecordFailures_1, state); + if (resolved) { + return resolved; } } else { @@ -23973,6 +24011,22 @@ var ts; } return loadModuleFromFile(extensions, ts.combinePaths(candidate, "index"), failedLookupLocations, !directoryExists, state); } + /** Resolve from an arbitrarily specified file. Return `undefined` if it has an unsupported extension. */ + function resolvedIfExtensionMatches(extensions, path) { + var extension = ts.tryGetExtensionFromPath(path); + return extension !== undefined && extensionIsOk(extensions, extension) ? { path: path, extension: extension } : undefined; + } + /** True if `extension` is one of the supported `extensions`. */ + function extensionIsOk(extensions, extension) { + switch (extensions) { + case 1 /* JavaScript */: + return extension === ts.Extension.Js || extension === ts.Extension.Jsx; + case 0 /* TypeScript */: + return extension === ts.Extension.Ts || extension === ts.Extension.Tsx || extension === ts.Extension.Dts; + case 2 /* DtsOnly */: + return extension === ts.Extension.Dts; + } + } function pathToPackageJson(directory) { return ts.combinePaths(directory, "package.json"); } @@ -24022,12 +24076,12 @@ var ts; } if (moduleHasNonRelativeName(moduleName)) { // Climb up parent directories looking for a module. - var resolved_3 = forEachAncestorDirectory(containingDirectory, function (directory) { + var resolved_4 = forEachAncestorDirectory(containingDirectory, function (directory) { var searchName = ts.normalizePath(ts.combinePaths(directory, moduleName)); return loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state); }); - if (resolved_3) { - return resolved_3; + if (resolved_4) { + return resolved_4; } if (extensions === 0 /* TypeScript */) { // If we didn't find the file normally, look it up in @types. @@ -28307,8 +28361,8 @@ var ts; // the modifiers type is T. Otherwise, the modifiers type is {}. var declaredType = getTypeFromMappedTypeNode(type.declaration); var constraint = getConstraintTypeFromMappedType(declaredType); - var extendedConstraint = constraint.flags & 16384 /* TypeParameter */ ? getConstraintOfTypeParameter(constraint) : constraint; - type.modifiersType = extendedConstraint.flags & 262144 /* Index */ ? instantiateType(extendedConstraint.type, type.mapper || identityMapper) : emptyObjectType; + var extendedConstraint = constraint && constraint.flags & 16384 /* TypeParameter */ ? getConstraintOfTypeParameter(constraint) : constraint; + type.modifiersType = extendedConstraint && extendedConstraint.flags & 262144 /* Index */ ? instantiateType(extendedConstraint.type, type.mapper || identityMapper) : emptyObjectType; } } return type.modifiersType; @@ -31178,8 +31232,11 @@ var ts; } } } - else if (relation !== identityRelation && isEmptyObjectType(resolveStructuredTypeMembers(target))) { - return -1 /* True */; + else if (relation !== identityRelation) { + var resolved = resolveStructuredTypeMembers(target); + if (isEmptyObjectType(resolved) || resolved.stringIndexInfo && resolved.stringIndexInfo.type.flags & 1 /* Any */) { + return -1 /* True */; + } } return 0 /* False */; } @@ -43933,8 +43990,13 @@ var ts; } function checkGrammarNumericLiteral(node) { // Grammar checking - if (node.isOctalLiteral && languageVersion >= 1 /* ES5 */) { - return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); + if (node.isOctalLiteral) { + if (languageVersion >= 1 /* ES5 */) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0, node.text); + } + if (ts.isChildOfLiteralType(node)) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0, node.text); + } } } function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { @@ -50940,7 +51002,7 @@ var ts; } } startLexicalEnvironment(); - var loopBody = ts.visitNode(node.statement, visitor, ts.isStatement); + var loopBody = ts.visitNode(node.statement, visitor, ts.isStatement, /*optional*/ false, ts.liftToBlock); var lexicalEnvironment = endLexicalEnvironment(); var currentState = convertedLoopState; convertedLoopState = outerConvertedLoopState; @@ -50952,7 +51014,10 @@ var ts; ts.addRange(statements_4, lexicalEnvironment); loopBody = ts.createBlock(statements_4, /*location*/ undefined, /*multiline*/ true); } - if (!ts.isBlock(loopBody)) { + if (ts.isBlock(loopBody)) { + loopBody.multiLine = true; + } + else { loopBody = ts.createBlock([loopBody], /*location*/ undefined, /*multiline*/ true); } var isAsyncBlockContainingAwait = enclosingNonArrowFunction @@ -54412,6 +54477,18 @@ var ts; * @param context Context and state information for the transformation. */ function transformES5(context) { + var compilerOptions = context.getCompilerOptions(); + // enable emit notification only if using --jsx preserve + var previousOnEmitNode; + var noSubstitution; + if (compilerOptions.jsx === 1 /* Preserve */) { + previousOnEmitNode = context.onEmitNode; + context.onEmitNode = onEmitNode; + context.enableEmitNotification(248 /* JsxOpeningElement */); + context.enableEmitNotification(249 /* JsxClosingElement */); + context.enableEmitNotification(247 /* JsxSelfClosingElement */); + noSubstitution = []; + } var previousOnSubstituteNode = context.onSubstituteNode; context.onSubstituteNode = onSubstituteNode; context.enableSubstitution(177 /* PropertyAccessExpression */); @@ -54425,6 +54502,22 @@ var ts; function transformSourceFile(node) { return node; } + /** + * Called by the printer just before a node is printed. + * + * @param node The node to be printed. + */ + function onEmitNode(emitContext, node, emitCallback) { + switch (node.kind) { + case 248 /* JsxOpeningElement */: + case 249 /* JsxClosingElement */: + case 247 /* JsxSelfClosingElement */: + var tagName = node.tagName; + noSubstitution[ts.getOriginalNodeId(tagName)] = true; + break; + } + previousOnEmitNode(emitContext, node, emitCallback); + } /** * Hooks node substitutions. * @@ -54432,6 +54525,9 @@ var ts; * @param node The node to substitute. */ function onSubstituteNode(emitContext, node) { + if (node.id && noSubstitution && noSubstitution[node.id]) { + return previousOnSubstituteNode(emitContext, node); + } node = previousOnSubstituteNode(emitContext, node); if (ts.isPropertyAccessExpression(node)) { return substitutePropertyAccessExpression(node); @@ -62277,6 +62373,7 @@ var ts; var supportedExtensions = ts.getSupportedExtensions(options); // Map storing if there is emit blocking diagnostics for given input var hasEmitBlockingDiagnostics = ts.createFileMap(getCanonicalFileName); + var moduleResolutionCache; var resolveModuleNamesWorker; if (host.resolveModuleNames) { resolveModuleNamesWorker = function (moduleNames, containingFile) { return host.resolveModuleNames(moduleNames, containingFile).map(function (resolved) { @@ -62290,7 +62387,8 @@ var ts; }); }; } else { - var loader_1 = function (moduleName, containingFile) { return ts.resolveModuleName(moduleName, containingFile, options, host).resolvedModule; }; + moduleResolutionCache = ts.createModuleResolutionCache(currentDirectory, function (x) { return host.getCanonicalFileName(x); }); + var loader_1 = function (moduleName, containingFile) { return ts.resolveModuleName(moduleName, containingFile, options, host, moduleResolutionCache).resolvedModule; }; resolveModuleNamesWorker = function (moduleNames, containingFile) { return loadWithLocalCache(moduleNames, containingFile, loader_1); }; } var resolveTypeReferenceDirectiveNamesWorker; @@ -62336,6 +62434,8 @@ var ts; } } } + // unconditionally set moduleResolutionCache to undefined to avoid unnecessary leaks + moduleResolutionCache = undefined; // unconditionally set oldProgram to undefined to prevent it from being captured in closure oldProgram = undefined; program = { @@ -64098,7 +64198,6 @@ var ts; } } ts.parseListTypeOption = parseListTypeOption; - /* @internal */ function parseCommandLine(commandLine, readFile) { var options = {}; var fileNames = []; @@ -75106,6 +75205,7 @@ var ts; this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([109 /* LetKeyword */, 75 /* ConstKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2 /* Space */)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8 /* Delete */)); this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(88 /* FunctionKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); + this.SpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionDeclContext), 2 /* Space */)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionDeclContext), 8 /* Delete */)); this.SpaceAfterVoidOperator = new formatting.Rule(formatting.RuleDescriptor.create3(104 /* VoidKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsVoidOpContext), 2 /* Space */)); this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(95 /* ReturnKeyword */, 24 /* SemicolonToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8 /* Delete */)); @@ -75122,11 +75222,12 @@ var ts; this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); // TypeScript-specific higher priority rules // Treat constructor as an identifier in a function declaration, and remove spaces between constructor and following left parentheses + this.SpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(122 /* ConstructorKeyword */, 18 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(122 /* ConstructorKeyword */, 18 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8 /* Delete */)); // Use of module as a function call. e.g.: import m2 = module("m2"); this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([127 /* ModuleKeyword */, 131 /* RequireKeyword */]), 18 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8 /* Delete */)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([116 /* AbstractKeyword */, 74 /* ClassKeyword */, 123 /* DeclareKeyword */, 78 /* DefaultKeyword */, 82 /* EnumKeyword */, 83 /* ExportKeyword */, 84 /* ExtendsKeyword */, 124 /* GetKeyword */, 107 /* ImplementsKeyword */, 90 /* ImportKeyword */, 108 /* InterfaceKeyword */, 127 /* ModuleKeyword */, 128 /* NamespaceKeyword */, 111 /* PrivateKeyword */, 113 /* PublicKeyword */, 112 /* ProtectedKeyword */, 133 /* SetKeyword */, 114 /* StaticKeyword */, 136 /* TypeKeyword */, 138 /* FromKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([116 /* AbstractKeyword */, 74 /* ClassKeyword */, 123 /* DeclareKeyword */, 78 /* DefaultKeyword */, 82 /* EnumKeyword */, 83 /* ExportKeyword */, 84 /* ExtendsKeyword */, 124 /* GetKeyword */, 107 /* ImplementsKeyword */, 90 /* ImportKeyword */, 108 /* InterfaceKeyword */, 127 /* ModuleKeyword */, 128 /* NamespaceKeyword */, 111 /* PrivateKeyword */, 113 /* PublicKeyword */, 112 /* ProtectedKeyword */, 130 /* ReadonlyKeyword */, 133 /* SetKeyword */, 114 /* StaticKeyword */, 136 /* TypeKeyword */, 138 /* FromKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([84 /* ExtendsKeyword */, 107 /* ImplementsKeyword */, 138 /* FromKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(9 /* StringLiteral */, 16 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2 /* Space */)); @@ -75193,7 +75294,7 @@ var ts; this.SpaceBeforeJsxAttribute, this.SpaceBeforeSlashInJsxOpeningElement, this.NoSpaceBeforeGreaterThanTokenInJsxOpeningElement, this.NoSpaceBeforeEqualInJsxAttribute, this.NoSpaceAfterEqualInJsxAttribute, // TypeScript-specific rules - this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, + this.NoSpaceAfterModuleImport, this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, this.SpaceAfterModuleName, this.SpaceBeforeArrow, this.SpaceAfterArrow, @@ -75217,7 +75318,6 @@ var ts; this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterCloseBracket, this.SpaceAfterSemicolon, - this.NoSpaceBeforeOpenParenInFuncDecl, this.SpaceBetweenStatements, this.SpaceAfterTryFinally ]; /// @@ -75879,6 +75979,12 @@ var ts; }; RulesProvider.prototype.createActiveRules = function (options) { var rules = this.globalRules.HighPriorityCommonRules.slice(0); + if (options.insertSpaceAfterConstructor) { + rules.push(this.globalRules.SpaceAfterConstructor); + } + else { + rules.push(this.globalRules.NoSpaceAfterConstructor); + } if (options.insertSpaceAfterCommaDelimiter) { rules.push(this.globalRules.SpaceAfterComma); } @@ -75959,6 +76065,12 @@ var ts; rules.push(this.globalRules.NoSpaceBeforeBinaryOperator); rules.push(this.globalRules.NoSpaceAfterBinaryOperator); } + if (options.insertSpaceBeforeFunctionParenthesis) { + rules.push(this.globalRules.SpaceBeforeOpenParenInFuncDecl); + } + else { + rules.push(this.globalRules.NoSpaceBeforeOpenParenInFuncDecl); + } if (options.placeOpenBraceOnNewLineForControlBlocks) { rules.push(this.globalRules.NewLineBeforeOpenBraceInControl); } diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index ff51221209122..6c669ef0f03e6 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -2325,7 +2325,17 @@ declare namespace ts { * this list is only the set of defaults that are implicitly included. */ function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[]; - function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; + /** + * Cached module resolutions per containing directory. + * This assumes that any module id will have the same resolution for sibling files located in the same folder. + */ + interface ModuleResolutionCache { + getOrCreateCacheForDirectory(directoryName: string): Map; + } + function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string): { + getOrCreateCacheForDirectory: (directoryName: string) => Map; + }; + function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations; function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; } @@ -2344,6 +2354,7 @@ declare namespace ts { function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program; } declare namespace ts { + function parseCommandLine(commandLine: string[], readFile?: (path: string) => string): ParsedCommandLine; /** * Read tsconfig.json file * @param fileName The path to the config file @@ -2675,6 +2686,7 @@ declare namespace ts { InsertSpaceAfterCommaDelimiter: boolean; InsertSpaceAfterSemicolonInForStatements: boolean; InsertSpaceBeforeAndAfterBinaryOperators: boolean; + InsertSpaceAfterConstructor?: boolean; InsertSpaceAfterKeywordsInControlFlowStatements: boolean; InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean; InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean; @@ -2683,6 +2695,7 @@ declare namespace ts { InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; InsertSpaceAfterTypeAssertion?: boolean; + InsertSpaceBeforeFunctionParenthesis?: boolean; PlaceOpenBraceOnNewLineForFunctions: boolean; PlaceOpenBraceOnNewLineForControlBlocks: boolean; } @@ -2690,6 +2703,7 @@ declare namespace ts { insertSpaceAfterCommaDelimiter?: boolean; insertSpaceAfterSemicolonInForStatements?: boolean; insertSpaceBeforeAndAfterBinaryOperators?: boolean; + insertSpaceAfterConstructor?: boolean; insertSpaceAfterKeywordsInControlFlowStatements?: boolean; insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean; insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean; @@ -2698,6 +2712,7 @@ declare namespace ts { insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean; insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; insertSpaceAfterTypeAssertion?: boolean; + insertSpaceBeforeFunctionParenthesis?: boolean; placeOpenBraceOnNewLineForFunctions?: boolean; placeOpenBraceOnNewLineForControlBlocks?: boolean; } diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 82c7bea3a40cf..a931f73c19a78 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -3915,7 +3915,7 @@ var ts; _0_modifier_cannot_appear_on_an_index_signature: { code: 1071, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_an_index_signature_1071", message: "'{0}' modifier cannot appear on an index signature." }, A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A_0_modifier_cannot_be_used_with_an_import_declaration_1079", message: "A '{0}' modifier cannot be used with an import declaration." }, Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid_reference_directive_syntax_1084", message: "Invalid 'reference' directive syntax." }, - Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_1085", message: "Octal literals are not available when targeting ECMAScript 5 and higher." }, + Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0_1085", message: "Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o{0}'." }, An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: ts.DiagnosticCategory.Error, key: "An_accessor_cannot_be_declared_in_an_ambient_context_1086", message: "An accessor cannot be declared in an ambient context." }, _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_a_constructor_declaration_1089", message: "'{0}' modifier cannot appear on a constructor declaration." }, _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_a_parameter_1090", message: "'{0}' modifier cannot appear on a parameter." }, @@ -4529,6 +4529,7 @@ var ts; Disallow_inconsistently_cased_references_to_the_same_file: { code: 6078, category: ts.DiagnosticCategory.Message, key: "Disallow_inconsistently_cased_references_to_the_same_file_6078", message: "Disallow inconsistently-cased references to the same file." }, Specify_library_files_to_be_included_in_the_compilation_Colon: { code: 6079, category: ts.DiagnosticCategory.Message, key: "Specify_library_files_to_be_included_in_the_compilation_Colon_6079", message: "Specify library files to be included in the compilation: " }, Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify_JSX_code_generation_Colon_preserve_or_react_6080", message: "Specify JSX code generation: 'preserve' or 'react'" }, + File_0_has_an_unsupported_extension_so_skipping_it: { code: 6081, category: ts.DiagnosticCategory.Message, key: "File_0_has_an_unsupported_extension_so_skipping_it_6081", message: "File '{0}' has an unsupported extension, so skipping it." }, Only_amd_and_system_modules_are_supported_alongside_0: { code: 6082, category: ts.DiagnosticCategory.Error, key: "Only_amd_and_system_modules_are_supported_alongside_0_6082", message: "Only 'amd' and 'system' modules are supported alongside --{0}." }, Base_directory_to_resolve_non_absolute_module_names: { code: 6083, category: ts.DiagnosticCategory.Message, key: "Base_directory_to_resolve_non_absolute_module_names_6083", message: "Base directory to resolve non-absolute module names." }, Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit: { code: 6084, category: ts.DiagnosticCategory.Message, key: "Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit_6084", message: "Specify the object invoked for createElement and __spread when targeting 'react' JSX emit" }, @@ -4594,6 +4595,7 @@ var ts; Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1: { code: 6144, category: ts.DiagnosticCategory.Message, key: "Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1_6144", message: "Module '{0}' was resolved as locally declared ambient module in file '{1}'." }, Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified: { code: 6145, category: ts.DiagnosticCategory.Message, key: "Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified_6145", message: "Module '{0}' was resolved as ambient module declared in '{1}' since this file was not modified." }, Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h: { code: 6146, category: ts.DiagnosticCategory.Message, key: "Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h_6146", message: "Specify the JSX factory function to use when targeting 'react' JSX emit, e.g. 'React.createElement' or 'h'." }, + Resolution_for_module_0_was_found_in_cache: { code: 6147, category: ts.DiagnosticCategory.Message, key: "Resolution_for_module_0_was_found_in_cache_6147", message: "Resolution for module '{0}' was found in cache" }, 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." }, @@ -4666,6 +4668,7 @@ var ts; Import_0_from_1: { code: 90013, category: ts.DiagnosticCategory.Message, key: "Import_0_from_1_90013", message: "Import {0} from {1}" }, Change_0_to_1: { code: 90014, category: ts.DiagnosticCategory.Message, key: "Change_0_to_1_90014", message: "Change {0} to {1}" }, Add_0_to_existing_import_declaration_from_1: { code: 90015, category: ts.DiagnosticCategory.Message, key: "Add_0_to_existing_import_declaration_from_1_90015", message: "Add {0} to existing import declaration from {1}" }, + Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0: { code: 8017, category: ts.DiagnosticCategory.Error, key: "Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0_8017", message: "Octal literal types must use ES2015 syntax. Use the syntax '0o{0}'." }, }; })(ts || (ts = {})); /// @@ -7081,6 +7084,16 @@ var ts; return false; } ts.isPartOfTypeNode = isPartOfTypeNode; + function isChildOfLiteralType(node) { + while (node) { + if (node.kind === 171 /* LiteralType */) { + return true; + } + node = node.parent; + } + return false; + } + ts.isChildOfLiteralType = isChildOfLiteralType; // Warning: This has the same semantics as the forEach family of functions, // in that traversal terminates in the event that 'visitor' supplies a truthy value. function forEachReturnStatement(body, visitor) { @@ -23387,10 +23400,6 @@ var ts; ts.Debug.assert(ts.extensionIsTypeScript(resolved.extension)); return resolved.path; } - /** Create Resolved from a file with unknown extension. */ - function resolvedFromAnyFile(path) { - return { path: path, extension: ts.extensionFromPath(path) }; - } /** Adds `isExernalLibraryImport` to a Resolved to get a ResolvedModule. */ function resolvedModuleFromResolved(_a, isExternalLibraryImport) { var path = _a.path, extension = _a.extension; @@ -23403,7 +23412,8 @@ var ts; return !(ts.isRootedDiskPath(moduleName) || ts.isExternalModuleNameRelative(moduleName)); } ts.moduleHasNonRelativeName = moduleHasNonRelativeName; - function tryReadTypesSection(extensions, packageJsonPath, baseDirectory, state) { + /** Reads from "main" or "types"/"typings" depending on `extensions`. */ + function tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, baseDirectory, state) { var jsonContent = readJson(packageJsonPath, state.host); switch (extensions) { case 2 /* DtsOnly */: @@ -23606,31 +23616,56 @@ var ts; return result; } ts.getAutomaticTypeDirectiveNames = getAutomaticTypeDirectiveNames; - function resolveModuleName(moduleName, containingFile, compilerOptions, host) { + function createModuleResolutionCache(currentDirectory, getCanonicalFileName) { + var map = ts.createFileMap(); + return { getOrCreateCacheForDirectory: getOrCreateCacheForDirectory }; + function getOrCreateCacheForDirectory(directoryName) { + var path = ts.toPath(directoryName, currentDirectory, getCanonicalFileName); + var perFolderCache = map.get(path); + if (!perFolderCache) { + perFolderCache = ts.createMap(); + map.set(path, perFolderCache); + } + return perFolderCache; + } + } + ts.createModuleResolutionCache = createModuleResolutionCache; + function resolveModuleName(moduleName, containingFile, compilerOptions, host, cache) { var traceEnabled = isTraceEnabled(compilerOptions, host); if (traceEnabled) { trace(host, ts.Diagnostics.Resolving_module_0_from_1, moduleName, containingFile); } - var moduleResolution = compilerOptions.moduleResolution; - if (moduleResolution === undefined) { - moduleResolution = ts.getEmitModuleKind(compilerOptions) === ts.ModuleKind.CommonJS ? ts.ModuleResolutionKind.NodeJs : ts.ModuleResolutionKind.Classic; + var perFolderCache = cache && cache.getOrCreateCacheForDirectory(ts.getDirectoryPath(containingFile)); + var result = perFolderCache && perFolderCache[moduleName]; + if (result) { if (traceEnabled) { - trace(host, ts.Diagnostics.Module_resolution_kind_is_not_specified_using_0, ts.ModuleResolutionKind[moduleResolution]); + trace(host, ts.Diagnostics.Resolution_for_module_0_was_found_in_cache, moduleName); } } else { - if (traceEnabled) { - trace(host, ts.Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ts.ModuleResolutionKind[moduleResolution]); + var moduleResolution = compilerOptions.moduleResolution; + if (moduleResolution === undefined) { + moduleResolution = ts.getEmitModuleKind(compilerOptions) === ts.ModuleKind.CommonJS ? ts.ModuleResolutionKind.NodeJs : ts.ModuleResolutionKind.Classic; + if (traceEnabled) { + trace(host, ts.Diagnostics.Module_resolution_kind_is_not_specified_using_0, ts.ModuleResolutionKind[moduleResolution]); + } + } + else { + if (traceEnabled) { + trace(host, ts.Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ts.ModuleResolutionKind[moduleResolution]); + } + } + switch (moduleResolution) { + case ts.ModuleResolutionKind.NodeJs: + result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); + break; + case ts.ModuleResolutionKind.Classic: + result = classicNameResolver(moduleName, containingFile, compilerOptions, host); + break; + } + if (perFolderCache) { + perFolderCache[moduleName] = result; } - } - var result; - switch (moduleResolution) { - case ts.ModuleResolutionKind.NodeJs: - result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); - break; - case ts.ModuleResolutionKind.Classic: - result = classicNameResolver(moduleName, containingFile, compilerOptions, host); - break; } if (traceEnabled) { if (result.resolvedModule) { @@ -23944,18 +23979,21 @@ var ts; if (state.traceEnabled) { trace(state.host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath); } - var typesFile = tryReadTypesSection(extensions, packageJsonPath, candidate, state); - if (typesFile) { - var onlyRecordFailures_1 = !directoryProbablyExists(ts.getDirectoryPath(typesFile), state.host); + var mainOrTypesFile = tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, candidate, state); + if (mainOrTypesFile) { + var onlyRecordFailures_1 = !directoryProbablyExists(ts.getDirectoryPath(mainOrTypesFile), state.host); // A package.json "typings" may specify an exact filename, or may choose to omit an extension. - var fromFile = tryFile(typesFile, failedLookupLocations, onlyRecordFailures_1, state); - if (fromFile) { - // Note: this would allow a package.json to specify a ".js" file as typings. Maybe that should be forbidden. - return resolvedFromAnyFile(fromFile); + var fromExactFile = tryFile(mainOrTypesFile, failedLookupLocations, onlyRecordFailures_1, state); + if (fromExactFile) { + var resolved_3 = fromExactFile && resolvedIfExtensionMatches(extensions, fromExactFile); + if (resolved_3) { + return resolved_3; + } + trace(state.host, ts.Diagnostics.File_0_has_an_unsupported_extension_so_skipping_it, fromExactFile); } - var x = tryAddingExtensions(typesFile, 0 /* TypeScript */, failedLookupLocations, onlyRecordFailures_1, state); - if (x) { - return x; + var resolved = tryAddingExtensions(mainOrTypesFile, 0 /* TypeScript */, failedLookupLocations, onlyRecordFailures_1, state); + if (resolved) { + return resolved; } } else { @@ -23973,6 +24011,22 @@ var ts; } return loadModuleFromFile(extensions, ts.combinePaths(candidate, "index"), failedLookupLocations, !directoryExists, state); } + /** Resolve from an arbitrarily specified file. Return `undefined` if it has an unsupported extension. */ + function resolvedIfExtensionMatches(extensions, path) { + var extension = ts.tryGetExtensionFromPath(path); + return extension !== undefined && extensionIsOk(extensions, extension) ? { path: path, extension: extension } : undefined; + } + /** True if `extension` is one of the supported `extensions`. */ + function extensionIsOk(extensions, extension) { + switch (extensions) { + case 1 /* JavaScript */: + return extension === ts.Extension.Js || extension === ts.Extension.Jsx; + case 0 /* TypeScript */: + return extension === ts.Extension.Ts || extension === ts.Extension.Tsx || extension === ts.Extension.Dts; + case 2 /* DtsOnly */: + return extension === ts.Extension.Dts; + } + } function pathToPackageJson(directory) { return ts.combinePaths(directory, "package.json"); } @@ -24022,12 +24076,12 @@ var ts; } if (moduleHasNonRelativeName(moduleName)) { // Climb up parent directories looking for a module. - var resolved_3 = forEachAncestorDirectory(containingDirectory, function (directory) { + var resolved_4 = forEachAncestorDirectory(containingDirectory, function (directory) { var searchName = ts.normalizePath(ts.combinePaths(directory, moduleName)); return loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state); }); - if (resolved_3) { - return resolved_3; + if (resolved_4) { + return resolved_4; } if (extensions === 0 /* TypeScript */) { // If we didn't find the file normally, look it up in @types. @@ -28307,8 +28361,8 @@ var ts; // the modifiers type is T. Otherwise, the modifiers type is {}. var declaredType = getTypeFromMappedTypeNode(type.declaration); var constraint = getConstraintTypeFromMappedType(declaredType); - var extendedConstraint = constraint.flags & 16384 /* TypeParameter */ ? getConstraintOfTypeParameter(constraint) : constraint; - type.modifiersType = extendedConstraint.flags & 262144 /* Index */ ? instantiateType(extendedConstraint.type, type.mapper || identityMapper) : emptyObjectType; + var extendedConstraint = constraint && constraint.flags & 16384 /* TypeParameter */ ? getConstraintOfTypeParameter(constraint) : constraint; + type.modifiersType = extendedConstraint && extendedConstraint.flags & 262144 /* Index */ ? instantiateType(extendedConstraint.type, type.mapper || identityMapper) : emptyObjectType; } } return type.modifiersType; @@ -31178,8 +31232,11 @@ var ts; } } } - else if (relation !== identityRelation && isEmptyObjectType(resolveStructuredTypeMembers(target))) { - return -1 /* True */; + else if (relation !== identityRelation) { + var resolved = resolveStructuredTypeMembers(target); + if (isEmptyObjectType(resolved) || resolved.stringIndexInfo && resolved.stringIndexInfo.type.flags & 1 /* Any */) { + return -1 /* True */; + } } return 0 /* False */; } @@ -43933,8 +43990,13 @@ var ts; } function checkGrammarNumericLiteral(node) { // Grammar checking - if (node.isOctalLiteral && languageVersion >= 1 /* ES5 */) { - return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); + if (node.isOctalLiteral) { + if (languageVersion >= 1 /* ES5 */) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0, node.text); + } + if (ts.isChildOfLiteralType(node)) { + return grammarErrorOnNode(node, ts.Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0, node.text); + } } } function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) { @@ -50940,7 +51002,7 @@ var ts; } } startLexicalEnvironment(); - var loopBody = ts.visitNode(node.statement, visitor, ts.isStatement); + var loopBody = ts.visitNode(node.statement, visitor, ts.isStatement, /*optional*/ false, ts.liftToBlock); var lexicalEnvironment = endLexicalEnvironment(); var currentState = convertedLoopState; convertedLoopState = outerConvertedLoopState; @@ -50952,7 +51014,10 @@ var ts; ts.addRange(statements_4, lexicalEnvironment); loopBody = ts.createBlock(statements_4, /*location*/ undefined, /*multiline*/ true); } - if (!ts.isBlock(loopBody)) { + if (ts.isBlock(loopBody)) { + loopBody.multiLine = true; + } + else { loopBody = ts.createBlock([loopBody], /*location*/ undefined, /*multiline*/ true); } var isAsyncBlockContainingAwait = enclosingNonArrowFunction @@ -54412,6 +54477,18 @@ var ts; * @param context Context and state information for the transformation. */ function transformES5(context) { + var compilerOptions = context.getCompilerOptions(); + // enable emit notification only if using --jsx preserve + var previousOnEmitNode; + var noSubstitution; + if (compilerOptions.jsx === 1 /* Preserve */) { + previousOnEmitNode = context.onEmitNode; + context.onEmitNode = onEmitNode; + context.enableEmitNotification(248 /* JsxOpeningElement */); + context.enableEmitNotification(249 /* JsxClosingElement */); + context.enableEmitNotification(247 /* JsxSelfClosingElement */); + noSubstitution = []; + } var previousOnSubstituteNode = context.onSubstituteNode; context.onSubstituteNode = onSubstituteNode; context.enableSubstitution(177 /* PropertyAccessExpression */); @@ -54425,6 +54502,22 @@ var ts; function transformSourceFile(node) { return node; } + /** + * Called by the printer just before a node is printed. + * + * @param node The node to be printed. + */ + function onEmitNode(emitContext, node, emitCallback) { + switch (node.kind) { + case 248 /* JsxOpeningElement */: + case 249 /* JsxClosingElement */: + case 247 /* JsxSelfClosingElement */: + var tagName = node.tagName; + noSubstitution[ts.getOriginalNodeId(tagName)] = true; + break; + } + previousOnEmitNode(emitContext, node, emitCallback); + } /** * Hooks node substitutions. * @@ -54432,6 +54525,9 @@ var ts; * @param node The node to substitute. */ function onSubstituteNode(emitContext, node) { + if (node.id && noSubstitution && noSubstitution[node.id]) { + return previousOnSubstituteNode(emitContext, node); + } node = previousOnSubstituteNode(emitContext, node); if (ts.isPropertyAccessExpression(node)) { return substitutePropertyAccessExpression(node); @@ -62277,6 +62373,7 @@ var ts; var supportedExtensions = ts.getSupportedExtensions(options); // Map storing if there is emit blocking diagnostics for given input var hasEmitBlockingDiagnostics = ts.createFileMap(getCanonicalFileName); + var moduleResolutionCache; var resolveModuleNamesWorker; if (host.resolveModuleNames) { resolveModuleNamesWorker = function (moduleNames, containingFile) { return host.resolveModuleNames(moduleNames, containingFile).map(function (resolved) { @@ -62290,7 +62387,8 @@ var ts; }); }; } else { - var loader_1 = function (moduleName, containingFile) { return ts.resolveModuleName(moduleName, containingFile, options, host).resolvedModule; }; + moduleResolutionCache = ts.createModuleResolutionCache(currentDirectory, function (x) { return host.getCanonicalFileName(x); }); + var loader_1 = function (moduleName, containingFile) { return ts.resolveModuleName(moduleName, containingFile, options, host, moduleResolutionCache).resolvedModule; }; resolveModuleNamesWorker = function (moduleNames, containingFile) { return loadWithLocalCache(moduleNames, containingFile, loader_1); }; } var resolveTypeReferenceDirectiveNamesWorker; @@ -62336,6 +62434,8 @@ var ts; } } } + // unconditionally set moduleResolutionCache to undefined to avoid unnecessary leaks + moduleResolutionCache = undefined; // unconditionally set oldProgram to undefined to prevent it from being captured in closure oldProgram = undefined; program = { @@ -64098,7 +64198,6 @@ var ts; } } ts.parseListTypeOption = parseListTypeOption; - /* @internal */ function parseCommandLine(commandLine, readFile) { var options = {}; var fileNames = []; @@ -75106,6 +75205,7 @@ var ts; this.SpaceAfterLetConstInVariableDeclaration = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([109 /* LetKeyword */, 75 /* ConstKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), 2 /* Space */)); this.NoSpaceBeforeOpenParenInFuncCall = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), 8 /* Delete */)); this.SpaceAfterFunctionInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create3(88 /* FunctionKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext), 2 /* Space */)); + this.SpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionDeclContext), 2 /* Space */)); this.NoSpaceBeforeOpenParenInFuncDecl = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionDeclContext), 8 /* Delete */)); this.SpaceAfterVoidOperator = new formatting.Rule(formatting.RuleDescriptor.create3(104 /* VoidKeyword */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsVoidOpContext), 2 /* Space */)); this.NoSpaceBetweenReturnAndSemicolon = new formatting.Rule(formatting.RuleDescriptor.create1(95 /* ReturnKeyword */, 24 /* SemicolonToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8 /* Delete */)); @@ -75122,11 +75222,12 @@ var ts; this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsBinaryOpContext), 2 /* Space */)); // TypeScript-specific higher priority rules // Treat constructor as an identifier in a function declaration, and remove spaces between constructor and following left parentheses + this.SpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(122 /* ConstructorKeyword */, 18 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(122 /* ConstructorKeyword */, 18 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8 /* Delete */)); // Use of module as a function call. e.g.: import m2 = module("m2"); this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([127 /* ModuleKeyword */, 131 /* RequireKeyword */]), 18 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8 /* Delete */)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([116 /* AbstractKeyword */, 74 /* ClassKeyword */, 123 /* DeclareKeyword */, 78 /* DefaultKeyword */, 82 /* EnumKeyword */, 83 /* ExportKeyword */, 84 /* ExtendsKeyword */, 124 /* GetKeyword */, 107 /* ImplementsKeyword */, 90 /* ImportKeyword */, 108 /* InterfaceKeyword */, 127 /* ModuleKeyword */, 128 /* NamespaceKeyword */, 111 /* PrivateKeyword */, 113 /* PublicKeyword */, 112 /* ProtectedKeyword */, 133 /* SetKeyword */, 114 /* StaticKeyword */, 136 /* TypeKeyword */, 138 /* FromKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([116 /* AbstractKeyword */, 74 /* ClassKeyword */, 123 /* DeclareKeyword */, 78 /* DefaultKeyword */, 82 /* EnumKeyword */, 83 /* ExportKeyword */, 84 /* ExtendsKeyword */, 124 /* GetKeyword */, 107 /* ImplementsKeyword */, 90 /* ImportKeyword */, 108 /* InterfaceKeyword */, 127 /* ModuleKeyword */, 128 /* NamespaceKeyword */, 111 /* PrivateKeyword */, 113 /* PublicKeyword */, 112 /* ProtectedKeyword */, 130 /* ReadonlyKeyword */, 133 /* SetKeyword */, 114 /* StaticKeyword */, 136 /* TypeKeyword */, 138 /* FromKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([84 /* ExtendsKeyword */, 107 /* ImplementsKeyword */, 138 /* FromKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(9 /* StringLiteral */, 16 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2 /* Space */)); @@ -75193,7 +75294,7 @@ var ts; this.SpaceBeforeJsxAttribute, this.SpaceBeforeSlashInJsxOpeningElement, this.NoSpaceBeforeGreaterThanTokenInJsxOpeningElement, this.NoSpaceBeforeEqualInJsxAttribute, this.NoSpaceAfterEqualInJsxAttribute, // TypeScript-specific rules - this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, + this.NoSpaceAfterModuleImport, this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, this.SpaceAfterModuleName, this.SpaceBeforeArrow, this.SpaceAfterArrow, @@ -75217,7 +75318,6 @@ var ts; this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterCloseBracket, this.SpaceAfterSemicolon, - this.NoSpaceBeforeOpenParenInFuncDecl, this.SpaceBetweenStatements, this.SpaceAfterTryFinally ]; /// @@ -75879,6 +75979,12 @@ var ts; }; RulesProvider.prototype.createActiveRules = function (options) { var rules = this.globalRules.HighPriorityCommonRules.slice(0); + if (options.insertSpaceAfterConstructor) { + rules.push(this.globalRules.SpaceAfterConstructor); + } + else { + rules.push(this.globalRules.NoSpaceAfterConstructor); + } if (options.insertSpaceAfterCommaDelimiter) { rules.push(this.globalRules.SpaceAfterComma); } @@ -75959,6 +76065,12 @@ var ts; rules.push(this.globalRules.NoSpaceBeforeBinaryOperator); rules.push(this.globalRules.NoSpaceAfterBinaryOperator); } + if (options.insertSpaceBeforeFunctionParenthesis) { + rules.push(this.globalRules.SpaceBeforeOpenParenInFuncDecl); + } + else { + rules.push(this.globalRules.NoSpaceBeforeOpenParenInFuncDecl); + } if (options.placeOpenBraceOnNewLineForControlBlocks) { rules.push(this.globalRules.NewLineBeforeOpenBraceInControl); } diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 7773567caa2fb..e4109e443ab63 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -2475,7 +2475,7 @@ var ts; _0_modifier_cannot_appear_on_an_index_signature: { code: 1071, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_an_index_signature_1071", message: "'{0}' modifier cannot appear on an index signature." }, A_0_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: ts.DiagnosticCategory.Error, key: "A_0_modifier_cannot_be_used_with_an_import_declaration_1079", message: "A '{0}' modifier cannot be used with an import declaration." }, Invalid_reference_directive_syntax: { code: 1084, category: ts.DiagnosticCategory.Error, key: "Invalid_reference_directive_syntax_1084", message: "Invalid 'reference' directive syntax." }, - Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_1085", message: "Octal literals are not available when targeting ECMAScript 5 and higher." }, + Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0: { code: 1085, category: ts.DiagnosticCategory.Error, key: "Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0_1085", message: "Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o{0}'." }, An_accessor_cannot_be_declared_in_an_ambient_context: { code: 1086, category: ts.DiagnosticCategory.Error, key: "An_accessor_cannot_be_declared_in_an_ambient_context_1086", message: "An accessor cannot be declared in an ambient context." }, _0_modifier_cannot_appear_on_a_constructor_declaration: { code: 1089, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_a_constructor_declaration_1089", message: "'{0}' modifier cannot appear on a constructor declaration." }, _0_modifier_cannot_appear_on_a_parameter: { code: 1090, category: ts.DiagnosticCategory.Error, key: "_0_modifier_cannot_appear_on_a_parameter_1090", message: "'{0}' modifier cannot appear on a parameter." }, @@ -3089,6 +3089,7 @@ var ts; Disallow_inconsistently_cased_references_to_the_same_file: { code: 6078, category: ts.DiagnosticCategory.Message, key: "Disallow_inconsistently_cased_references_to_the_same_file_6078", message: "Disallow inconsistently-cased references to the same file." }, Specify_library_files_to_be_included_in_the_compilation_Colon: { code: 6079, category: ts.DiagnosticCategory.Message, key: "Specify_library_files_to_be_included_in_the_compilation_Colon_6079", message: "Specify library files to be included in the compilation: " }, Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: ts.DiagnosticCategory.Message, key: "Specify_JSX_code_generation_Colon_preserve_or_react_6080", message: "Specify JSX code generation: 'preserve' or 'react'" }, + File_0_has_an_unsupported_extension_so_skipping_it: { code: 6081, category: ts.DiagnosticCategory.Message, key: "File_0_has_an_unsupported_extension_so_skipping_it_6081", message: "File '{0}' has an unsupported extension, so skipping it." }, Only_amd_and_system_modules_are_supported_alongside_0: { code: 6082, category: ts.DiagnosticCategory.Error, key: "Only_amd_and_system_modules_are_supported_alongside_0_6082", message: "Only 'amd' and 'system' modules are supported alongside --{0}." }, Base_directory_to_resolve_non_absolute_module_names: { code: 6083, category: ts.DiagnosticCategory.Message, key: "Base_directory_to_resolve_non_absolute_module_names_6083", message: "Base directory to resolve non-absolute module names." }, Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit: { code: 6084, category: ts.DiagnosticCategory.Message, key: "Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit_6084", message: "Specify the object invoked for createElement and __spread when targeting 'react' JSX emit" }, @@ -3154,6 +3155,7 @@ var ts; Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1: { code: 6144, category: ts.DiagnosticCategory.Message, key: "Module_0_was_resolved_as_locally_declared_ambient_module_in_file_1_6144", message: "Module '{0}' was resolved as locally declared ambient module in file '{1}'." }, Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified: { code: 6145, category: ts.DiagnosticCategory.Message, key: "Module_0_was_resolved_as_ambient_module_declared_in_1_since_this_file_was_not_modified_6145", message: "Module '{0}' was resolved as ambient module declared in '{1}' since this file was not modified." }, Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h: { code: 6146, category: ts.DiagnosticCategory.Message, key: "Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h_6146", message: "Specify the JSX factory function to use when targeting 'react' JSX emit, e.g. 'React.createElement' or 'h'." }, + Resolution_for_module_0_was_found_in_cache: { code: 6147, category: ts.DiagnosticCategory.Message, key: "Resolution_for_module_0_was_found_in_cache_6147", message: "Resolution for module '{0}' was found in cache" }, 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." }, @@ -3226,6 +3228,7 @@ var ts; Import_0_from_1: { code: 90013, category: ts.DiagnosticCategory.Message, key: "Import_0_from_1_90013", message: "Import {0} from {1}" }, Change_0_to_1: { code: 90014, category: ts.DiagnosticCategory.Message, key: "Change_0_to_1_90014", message: "Change {0} to {1}" }, Add_0_to_existing_import_declaration_from_1: { code: 90015, category: ts.DiagnosticCategory.Message, key: "Add_0_to_existing_import_declaration_from_1_90015", message: "Add {0} to existing import declaration from {1}" }, + Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0: { code: 8017, category: ts.DiagnosticCategory.Error, key: "Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0_8017", message: "Octal literal types must use ES2015 syntax. Use the syntax '0o{0}'." }, }; })(ts || (ts = {})); var ts; @@ -6109,9 +6112,6 @@ var ts; ts.Debug.assert(ts.extensionIsTypeScript(resolved.extension)); return resolved.path; } - function resolvedFromAnyFile(path) { - return { path: path, extension: ts.extensionFromPath(path) }; - } function resolvedModuleFromResolved(_a, isExternalLibraryImport) { var path = _a.path, extension = _a.extension; return { resolvedFileName: path, extension: extension, isExternalLibraryImport: isExternalLibraryImport }; @@ -6123,7 +6123,7 @@ var ts; return !(ts.isRootedDiskPath(moduleName) || ts.isExternalModuleNameRelative(moduleName)); } ts.moduleHasNonRelativeName = moduleHasNonRelativeName; - function tryReadTypesSection(extensions, packageJsonPath, baseDirectory, state) { + function tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, baseDirectory, state) { var jsonContent = readJson(packageJsonPath, state.host); switch (extensions) { case 2: @@ -6302,31 +6302,56 @@ var ts; return result; } ts.getAutomaticTypeDirectiveNames = getAutomaticTypeDirectiveNames; - function resolveModuleName(moduleName, containingFile, compilerOptions, host) { + function createModuleResolutionCache(currentDirectory, getCanonicalFileName) { + var map = ts.createFileMap(); + return { getOrCreateCacheForDirectory: getOrCreateCacheForDirectory }; + function getOrCreateCacheForDirectory(directoryName) { + var path = ts.toPath(directoryName, currentDirectory, getCanonicalFileName); + var perFolderCache = map.get(path); + if (!perFolderCache) { + perFolderCache = ts.createMap(); + map.set(path, perFolderCache); + } + return perFolderCache; + } + } + ts.createModuleResolutionCache = createModuleResolutionCache; + function resolveModuleName(moduleName, containingFile, compilerOptions, host, cache) { var traceEnabled = isTraceEnabled(compilerOptions, host); if (traceEnabled) { trace(host, ts.Diagnostics.Resolving_module_0_from_1, moduleName, containingFile); } - var moduleResolution = compilerOptions.moduleResolution; - if (moduleResolution === undefined) { - moduleResolution = ts.getEmitModuleKind(compilerOptions) === ts.ModuleKind.CommonJS ? ts.ModuleResolutionKind.NodeJs : ts.ModuleResolutionKind.Classic; + var perFolderCache = cache && cache.getOrCreateCacheForDirectory(ts.getDirectoryPath(containingFile)); + var result = perFolderCache && perFolderCache[moduleName]; + if (result) { if (traceEnabled) { - trace(host, ts.Diagnostics.Module_resolution_kind_is_not_specified_using_0, ts.ModuleResolutionKind[moduleResolution]); + trace(host, ts.Diagnostics.Resolution_for_module_0_was_found_in_cache, moduleName); } } else { - if (traceEnabled) { - trace(host, ts.Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ts.ModuleResolutionKind[moduleResolution]); + var moduleResolution = compilerOptions.moduleResolution; + if (moduleResolution === undefined) { + moduleResolution = ts.getEmitModuleKind(compilerOptions) === ts.ModuleKind.CommonJS ? ts.ModuleResolutionKind.NodeJs : ts.ModuleResolutionKind.Classic; + if (traceEnabled) { + trace(host, ts.Diagnostics.Module_resolution_kind_is_not_specified_using_0, ts.ModuleResolutionKind[moduleResolution]); + } + } + else { + if (traceEnabled) { + trace(host, ts.Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ts.ModuleResolutionKind[moduleResolution]); + } + } + switch (moduleResolution) { + case ts.ModuleResolutionKind.NodeJs: + result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); + break; + case ts.ModuleResolutionKind.Classic: + result = classicNameResolver(moduleName, containingFile, compilerOptions, host); + break; + } + if (perFolderCache) { + perFolderCache[moduleName] = result; } - } - var result; - switch (moduleResolution) { - case ts.ModuleResolutionKind.NodeJs: - result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); - break; - case ts.ModuleResolutionKind.Classic: - result = classicNameResolver(moduleName, containingFile, compilerOptions, host); - break; } if (traceEnabled) { if (result.resolvedModule) { @@ -6559,16 +6584,20 @@ var ts; if (state.traceEnabled) { trace(state.host, ts.Diagnostics.Found_package_json_at_0, packageJsonPath); } - var typesFile = tryReadTypesSection(extensions, packageJsonPath, candidate, state); - if (typesFile) { - var onlyRecordFailures_1 = !directoryProbablyExists(ts.getDirectoryPath(typesFile), state.host); - var fromFile = tryFile(typesFile, failedLookupLocations, onlyRecordFailures_1, state); - if (fromFile) { - return resolvedFromAnyFile(fromFile); + var mainOrTypesFile = tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, candidate, state); + if (mainOrTypesFile) { + var onlyRecordFailures_1 = !directoryProbablyExists(ts.getDirectoryPath(mainOrTypesFile), state.host); + var fromExactFile = tryFile(mainOrTypesFile, failedLookupLocations, onlyRecordFailures_1, state); + if (fromExactFile) { + var resolved_3 = fromExactFile && resolvedIfExtensionMatches(extensions, fromExactFile); + if (resolved_3) { + return resolved_3; + } + trace(state.host, ts.Diagnostics.File_0_has_an_unsupported_extension_so_skipping_it, fromExactFile); } - var x = tryAddingExtensions(typesFile, 0, failedLookupLocations, onlyRecordFailures_1, state); - if (x) { - return x; + var resolved = tryAddingExtensions(mainOrTypesFile, 0, failedLookupLocations, onlyRecordFailures_1, state); + if (resolved) { + return resolved; } } else { @@ -6585,6 +6614,20 @@ var ts; } return loadModuleFromFile(extensions, ts.combinePaths(candidate, "index"), failedLookupLocations, !directoryExists, state); } + function resolvedIfExtensionMatches(extensions, path) { + var extension = ts.tryGetExtensionFromPath(path); + return extension !== undefined && extensionIsOk(extensions, extension) ? { path: path, extension: extension } : undefined; + } + function extensionIsOk(extensions, extension) { + switch (extensions) { + case 1: + return extension === ts.Extension.Js || extension === ts.Extension.Jsx; + case 0: + return extension === ts.Extension.Ts || extension === ts.Extension.Tsx || extension === ts.Extension.Dts; + case 2: + return extension === ts.Extension.Dts; + } + } function pathToPackageJson(directory) { return ts.combinePaths(directory, "package.json"); } @@ -6631,12 +6674,12 @@ var ts; return resolvedUsingSettings; } if (moduleHasNonRelativeName(moduleName)) { - var resolved_3 = forEachAncestorDirectory(containingDirectory, function (directory) { + var resolved_4 = forEachAncestorDirectory(containingDirectory, function (directory) { var searchName = ts.normalizePath(ts.combinePaths(directory, moduleName)); return loadModuleFromFile(extensions, searchName, failedLookupLocations, false, state); }); - if (resolved_3) { - return resolved_3; + if (resolved_4) { + return resolved_4; } if (extensions === 0) { return loadModuleFromNodeModulesAtTypes(moduleName, containingDirectory, failedLookupLocations, state); diff --git a/package.json b/package.json index 7b6a739acf9a8..c27e428dbccd0 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "through2": "latest", "travis-fold": "latest", "ts-node": "latest", - "tslint": "4.0.0-dev.2", + "tslint": "4.0.0-dev.3", "typescript": "^2.1" }, "scripts": { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5246bbfc7001b..36b952dd046fa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4612,8 +4612,8 @@ namespace ts { // the modifiers type is T. Otherwise, the modifiers type is {}. const declaredType = getTypeFromMappedTypeNode(type.declaration); const constraint = getConstraintTypeFromMappedType(declaredType); - const extendedConstraint = constraint.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(constraint) : constraint; - type.modifiersType = extendedConstraint.flags & TypeFlags.Index ? instantiateType((extendedConstraint).type, type.mapper || identityMapper) : emptyObjectType; + const extendedConstraint = constraint && constraint.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(constraint) : constraint; + type.modifiersType = extendedConstraint && extendedConstraint.flags & TypeFlags.Index ? instantiateType((extendedConstraint).type, type.mapper || identityMapper) : emptyObjectType; } } return type.modifiersType; @@ -7730,8 +7730,11 @@ namespace ts { } } } - else if (relation !== identityRelation && isEmptyObjectType(resolveStructuredTypeMembers(target))) { - return Ternary.True; + else if (relation !== identityRelation) { + const resolved = resolveStructuredTypeMembers(target); + if (isEmptyObjectType(resolved) || resolved.stringIndexInfo && resolved.stringIndexInfo.type.flags & TypeFlags.Any) { + return Ternary.True; + } } return Ternary.False; } @@ -21845,8 +21848,13 @@ namespace ts { function checkGrammarNumericLiteral(node: NumericLiteral): boolean { // Grammar checking - if (node.isOctalLiteral && languageVersion >= ScriptTarget.ES5) { - return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher); + if (node.isOctalLiteral) { + if (languageVersion >= ScriptTarget.ES5) { + return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0o_0, node.text); + } + if (isChildOfLiteralType(node)) { + return grammarErrorOnNode(node, Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0o_0, node.text); + } } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 251eeb58b1569..a4257a610e181 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -572,7 +572,6 @@ namespace ts { } } - /* @internal */ export function parseCommandLine(commandLine: string[], readFile?: (path: string) => string): ParsedCommandLine { const options: CompilerOptions = {}; const fileNames: string[] = []; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b59921c29489b..6d19826e9519d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -227,7 +227,7 @@ "category": "Error", "code": 1084 }, - "Octal literals are not available when targeting ECMAScript 5 and higher.": { + "Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o{0}'.": { "category": "Error", "code": 1085 }, @@ -2685,6 +2685,10 @@ "category": "Message", "code": 6080 }, + "File '{0}' has an unsupported extension, so skipping it.": { + "category": "Message", + "code": 6081 + }, "Only 'amd' and 'system' modules are supported alongside --{0}.": { "category": "Error", "code": 6082 @@ -2945,6 +2949,10 @@ "category": "Message", "code": 6146 }, + "Resolution for module '{0}' was found in cache": { + "category": "Message", + "code": 6147 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 @@ -3234,5 +3242,9 @@ "Add {0} to existing import declaration from {1}": { "category": "Message", "code": 90015 + }, + "Octal literal types must use ES2015 syntax. Use the syntax '0o{0}'.": { + "category": "Error", + "code": 8017 } } diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 0daca9156d1fc..c2fcbddaa61dc 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -47,11 +47,6 @@ namespace ts { return resolved.path; } - /** Create Resolved from a file with unknown extension. */ - function resolvedFromAnyFile(path: string): Resolved | undefined { - return { path, extension: extensionFromPath(path) }; - } - /** Adds `isExernalLibraryImport` to a Resolved to get a ResolvedModule. */ function resolvedModuleFromResolved({ path, extension }: Resolved, isExternalLibraryImport: boolean): ResolvedModuleFull { return { resolvedFileName: path, extension, isExternalLibraryImport }; @@ -71,7 +66,8 @@ namespace ts { traceEnabled: boolean; } - function tryReadTypesSection(extensions: Extensions, packageJsonPath: string, baseDirectory: string, state: ModuleResolutionState): string { + /** Reads from "main" or "types"/"typings" depending on `extensions`. */ + function tryReadPackageJsonMainOrTypes(extensions: Extensions, packageJsonPath: string, baseDirectory: string, state: ModuleResolutionState): string { const jsonContent = readJson(packageJsonPath, state.host); switch (extensions) { @@ -293,33 +289,69 @@ namespace ts { return result; } - export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { + /** + * Cached module resolutions per containing directory. + * This assumes that any module id will have the same resolution for sibling files located in the same folder. + */ + export interface ModuleResolutionCache { + getOrCreateCacheForDirectory(directoryName: string): Map; + } + + export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string) { + const map = createFileMap>(); + + return { getOrCreateCacheForDirectory }; + + function getOrCreateCacheForDirectory(directoryName: string) { + const path = toPath(directoryName, currentDirectory, getCanonicalFileName); + let perFolderCache = map.get(path); + if (!perFolderCache) { + perFolderCache = createMap(); + map.set(path, perFolderCache); + } + return perFolderCache; + } + } + + export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations { const traceEnabled = isTraceEnabled(compilerOptions, host); if (traceEnabled) { trace(host, Diagnostics.Resolving_module_0_from_1, moduleName, containingFile); } + const perFolderCache = cache && cache.getOrCreateCacheForDirectory(getDirectoryPath(containingFile)); + let result = perFolderCache && perFolderCache[moduleName]; - let moduleResolution = compilerOptions.moduleResolution; - if (moduleResolution === undefined) { - moduleResolution = getEmitModuleKind(compilerOptions) === ModuleKind.CommonJS ? ModuleResolutionKind.NodeJs : ModuleResolutionKind.Classic; + if (result) { if (traceEnabled) { - trace(host, Diagnostics.Module_resolution_kind_is_not_specified_using_0, ModuleResolutionKind[moduleResolution]); + trace(host, Diagnostics.Resolution_for_module_0_was_found_in_cache, moduleName); } } else { - if (traceEnabled) { - trace(host, Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ModuleResolutionKind[moduleResolution]); + let moduleResolution = compilerOptions.moduleResolution; + if (moduleResolution === undefined) { + moduleResolution = getEmitModuleKind(compilerOptions) === ModuleKind.CommonJS ? ModuleResolutionKind.NodeJs : ModuleResolutionKind.Classic; + if (traceEnabled) { + trace(host, Diagnostics.Module_resolution_kind_is_not_specified_using_0, ModuleResolutionKind[moduleResolution]); + } + } + else { + if (traceEnabled) { + trace(host, Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ModuleResolutionKind[moduleResolution]); + } + } + + switch (moduleResolution) { + case ModuleResolutionKind.NodeJs: + result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); + break; + case ModuleResolutionKind.Classic: + result = classicNameResolver(moduleName, containingFile, compilerOptions, host); + break; } - } - let result: ResolvedModuleWithFailedLookupLocations; - switch (moduleResolution) { - case ModuleResolutionKind.NodeJs: - result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host); - break; - case ModuleResolutionKind.Classic: - result = classicNameResolver(moduleName, containingFile, compilerOptions, host); - break; + if (perFolderCache) { + perFolderCache[moduleName] = result; + } } if (traceEnabled) { @@ -678,18 +710,21 @@ namespace ts { if (state.traceEnabled) { trace(state.host, Diagnostics.Found_package_json_at_0, packageJsonPath); } - const typesFile = tryReadTypesSection(extensions, packageJsonPath, candidate, state); - if (typesFile) { - const onlyRecordFailures = !directoryProbablyExists(getDirectoryPath(typesFile), state.host); + const mainOrTypesFile = tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, candidate, state); + if (mainOrTypesFile) { + const onlyRecordFailures = !directoryProbablyExists(getDirectoryPath(mainOrTypesFile), state.host); // A package.json "typings" may specify an exact filename, or may choose to omit an extension. - const fromFile = tryFile(typesFile, failedLookupLocations, onlyRecordFailures, state); - if (fromFile) { - // Note: this would allow a package.json to specify a ".js" file as typings. Maybe that should be forbidden. - return resolvedFromAnyFile(fromFile); + const fromExactFile = tryFile(mainOrTypesFile, failedLookupLocations, onlyRecordFailures, state); + if (fromExactFile) { + const resolved = fromExactFile && resolvedIfExtensionMatches(extensions, fromExactFile); + if (resolved) { + return resolved; + } + trace(state.host, Diagnostics.File_0_has_an_unsupported_extension_so_skipping_it, fromExactFile); } - const x = tryAddingExtensions(typesFile, Extensions.TypeScript, failedLookupLocations, onlyRecordFailures, state); - if (x) { - return x; + const resolved = tryAddingExtensions(mainOrTypesFile, Extensions.TypeScript, failedLookupLocations, onlyRecordFailures, state); + if (resolved) { + return resolved; } } else { @@ -709,6 +744,24 @@ namespace ts { return loadModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocations, !directoryExists, state); } + /** Resolve from an arbitrarily specified file. Return `undefined` if it has an unsupported extension. */ + function resolvedIfExtensionMatches(extensions: Extensions, path: string): Resolved | undefined { + const extension = tryGetExtensionFromPath(path); + return extension !== undefined && extensionIsOk(extensions, extension) ? { path, extension } : undefined; + } + + /** True if `extension` is one of the supported `extensions`. */ + function extensionIsOk(extensions: Extensions, extension: Extension): boolean { + switch (extensions) { + case Extensions.JavaScript: + return extension === Extension.Js || extension === Extension.Jsx; + case Extensions.TypeScript: + return extension === Extension.Ts || extension === Extension.Tsx || extension === Extension.Dts; + case Extensions.DtsOnly: + return extension === Extension.Dts; + } + } + function pathToPackageJson(directory: string): string { return combinePaths(directory, "package.json"); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 73976d5d02e73..4ab709d845598 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -325,6 +325,7 @@ namespace ts { // Map storing if there is emit blocking diagnostics for given input const hasEmitBlockingDiagnostics = createFileMap(getCanonicalFileName); + let moduleResolutionCache: ModuleResolutionCache; let resolveModuleNamesWorker: (moduleNames: string[], containingFile: string) => ResolvedModuleFull[]; if (host.resolveModuleNames) { resolveModuleNamesWorker = (moduleNames, containingFile) => host.resolveModuleNames(moduleNames, containingFile).map(resolved => { @@ -338,7 +339,8 @@ namespace ts { }); } else { - const loader = (moduleName: string, containingFile: string) => resolveModuleName(moduleName, containingFile, options, host).resolvedModule; + moduleResolutionCache = createModuleResolutionCache(currentDirectory, x => host.getCanonicalFileName(x)); + const loader = (moduleName: string, containingFile: string) => resolveModuleName(moduleName, containingFile, options, host, moduleResolutionCache).resolvedModule; resolveModuleNamesWorker = (moduleNames, containingFile) => loadWithLocalCache(moduleNames, containingFile, loader); } @@ -391,6 +393,9 @@ namespace ts { } } + // unconditionally set moduleResolutionCache to undefined to avoid unnecessary leaks + moduleResolutionCache = undefined; + // unconditionally set oldProgram to undefined to prevent it from being captured in closure oldProgram = undefined; diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 3c7f3539e76bc..5dae1da7b742b 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -2290,7 +2290,7 @@ namespace ts { } startLexicalEnvironment(); - let loopBody = visitNode(node.statement, visitor, isStatement); + let loopBody = visitNode(node.statement, visitor, isStatement, /*optional*/ false, liftToBlock); const lexicalEnvironment = endLexicalEnvironment(); const currentState = convertedLoopState; @@ -2305,7 +2305,10 @@ namespace ts { loopBody = createBlock(statements, /*location*/ undefined, /*multiline*/ true); } - if (!isBlock(loopBody)) { + if (isBlock(loopBody)) { + loopBody.multiLine = true; + } + else { loopBody = createBlock([loopBody], /*location*/ undefined, /*multiline*/ true); } diff --git a/src/compiler/transformers/es5.ts b/src/compiler/transformers/es5.ts index 9e5a72c2bad6f..6dd875965d96d 100644 --- a/src/compiler/transformers/es5.ts +++ b/src/compiler/transformers/es5.ts @@ -9,6 +9,20 @@ namespace ts { * @param context Context and state information for the transformation. */ export function transformES5(context: TransformationContext) { + const compilerOptions = context.getCompilerOptions(); + + // enable emit notification only if using --jsx preserve + let previousOnEmitNode: (emitContext: EmitContext, node: Node, emitCallback: (emitContext: EmitContext, node: Node) => void) => void; + let noSubstitution: boolean[]; + if (compilerOptions.jsx === JsxEmit.Preserve) { + previousOnEmitNode = context.onEmitNode; + context.onEmitNode = onEmitNode; + context.enableEmitNotification(SyntaxKind.JsxOpeningElement); + context.enableEmitNotification(SyntaxKind.JsxClosingElement); + context.enableEmitNotification(SyntaxKind.JsxSelfClosingElement); + noSubstitution = []; + } + const previousOnSubstituteNode = context.onSubstituteNode; context.onSubstituteNode = onSubstituteNode; context.enableSubstitution(SyntaxKind.PropertyAccessExpression); @@ -24,6 +38,24 @@ namespace ts { return node; } + /** + * Called by the printer just before a node is printed. + * + * @param node The node to be printed. + */ + function onEmitNode(emitContext: EmitContext, node: Node, emitCallback: (emitContext: EmitContext, node: Node) => void) { + switch (node.kind) { + case SyntaxKind.JsxOpeningElement: + case SyntaxKind.JsxClosingElement: + case SyntaxKind.JsxSelfClosingElement: + const tagName = (node).tagName; + noSubstitution[getOriginalNodeId(tagName)] = true; + break; + } + + previousOnEmitNode(emitContext, node, emitCallback); + } + /** * Hooks node substitutions. * @@ -31,6 +63,10 @@ namespace ts { * @param node The node to substitute. */ function onSubstituteNode(emitContext: EmitContext, node: Node) { + if (node.id && noSubstitution && noSubstitution[node.id]) { + return previousOnSubstituteNode(emitContext, node); + } + node = previousOnSubstituteNode(emitContext, node); if (isPropertyAccessExpression(node)) { return substitutePropertyAccessExpression(node); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9574400becbf7..07a092350a40f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -732,6 +732,16 @@ namespace ts { return false; } + export function isChildOfLiteralType(node: Node): boolean { + while (node) { + if (node.kind === SyntaxKind.LiteralType) { + return true; + } + node = node.parent; + } + return false; + } + // Warning: This has the same semantics as the forEach family of functions, // in that traversal terminates in the event that 'visitor' supplies a truthy value. export function forEachReturnStatement(body: Block, visitor: (stmt: ReturnStatement) => T): T { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 13df86aafe34d..2a635ae575c38 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -341,6 +341,7 @@ namespace FourSlash { insertSpaceAfterCommaDelimiter: true, insertSpaceAfterSemicolonInForStatements: true, insertSpaceBeforeAndAfterBinaryOperators: true, + insertSpaceAfterConstructor: false, insertSpaceAfterKeywordsInControlFlowStatements: true, insertSpaceAfterFunctionKeywordForAnonymousFunctions: false, insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false, diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 8440ed0c718ac..ec35db384ccfe 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2209,12 +2209,14 @@ namespace ts.server.protocol { insertSpaceAfterCommaDelimiter?: boolean; insertSpaceAfterSemicolonInForStatements?: boolean; insertSpaceBeforeAndAfterBinaryOperators?: boolean; + insertSpaceAfterConstructor?: boolean; insertSpaceAfterKeywordsInControlFlowStatements?: boolean; insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean; insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean; insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean; insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean; insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; + insertSpaceBeforeFunctionParenthesis?: boolean; placeOpenBraceOnNewLineForFunctions?: boolean; placeOpenBraceOnNewLineForControlBlocks?: boolean; } diff --git a/src/server/utilities.ts b/src/server/utilities.ts index 839e79268fad8..641ca128e634d 100644 --- a/src/server/utilities.ts +++ b/src/server/utilities.ts @@ -78,6 +78,7 @@ namespace ts.server { newLineCharacter: host.newLine || "\n", convertTabsToSpaces: true, indentStyle: ts.IndentStyle.Smart, + insertSpaceAfterConstructor: false, insertSpaceAfterCommaDelimiter: true, insertSpaceAfterSemicolonInForStatements: true, insertSpaceBeforeAndAfterBinaryOperators: true, @@ -87,6 +88,7 @@ namespace ts.server { insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false, insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false, insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false, + insertSpaceBeforeFunctionParenthesis: false, placeOpenBraceOnNewLineForFunctions: false, placeOpenBraceOnNewLineForControlBlocks: false, }; diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 2095f062bd103..a6bec97ed539c 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -87,6 +87,7 @@ namespace ts.formatting { public SpaceAfterLetConstInVariableDeclaration: Rule; public NoSpaceBeforeOpenParenInFuncCall: Rule; public SpaceAfterFunctionInFuncDecl: Rule; + public SpaceBeforeOpenParenInFuncDecl: Rule; public NoSpaceBeforeOpenParenInFuncDecl: Rule; public SpaceAfterVoidOperator: Rule; @@ -112,6 +113,7 @@ namespace ts.formatting { // TypeScript-specific rules // Treat constructor as an identifier in a function declaration, and remove spaces between constructor and following left parentheses + public SpaceAfterConstructor: Rule; public NoSpaceAfterConstructor: Rule; // Use of module as a function call. e.g.: import m2 = module("m2"); @@ -329,6 +331,7 @@ namespace ts.formatting { this.SpaceAfterLetConstInVariableDeclaration = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.LetKeyword, SyntaxKind.ConstKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), RuleAction.Space)); this.NoSpaceBeforeOpenParenInFuncCall = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), RuleAction.Delete)); this.SpaceAfterFunctionInFuncDecl = new Rule(RuleDescriptor.create3(SyntaxKind.FunctionKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space)); + this.SpaceBeforeOpenParenInFuncDecl = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionDeclContext), RuleAction.Space)); this.NoSpaceBeforeOpenParenInFuncDecl = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionDeclContext), RuleAction.Delete)); this.SpaceAfterVoidOperator = new Rule(RuleDescriptor.create3(SyntaxKind.VoidKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsVoidOpContext), RuleAction.Space)); @@ -352,13 +355,14 @@ namespace ts.formatting { // TypeScript-specific higher priority rules // Treat constructor as an identifier in a function declaration, and remove spaces between constructor and following left parentheses + this.SpaceAfterConstructor = new Rule(RuleDescriptor.create1(SyntaxKind.ConstructorKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space)); this.NoSpaceAfterConstructor = new Rule(RuleDescriptor.create1(SyntaxKind.ConstructorKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete)); // Use of module as a function call. e.g.: import m2 = module("m2"); this.NoSpaceAfterModuleImport = new Rule(RuleDescriptor.create2(Shared.TokenRange.FromTokens([SyntaxKind.ModuleKeyword, SyntaxKind.RequireKeyword]), SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.AbstractKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword, SyntaxKind.TypeKeyword, SyntaxKind.FromKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space)); + this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.AbstractKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.ReadonlyKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword, SyntaxKind.TypeKeyword, SyntaxKind.FromKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space)); this.SpaceBeforeCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.ExtendsKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.FromKeyword])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { @@ -437,7 +441,7 @@ namespace ts.formatting { this.NoSpaceBeforeEqualInJsxAttribute, this.NoSpaceAfterEqualInJsxAttribute, // TypeScript-specific rules - this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, + this.NoSpaceAfterModuleImport, this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords, this.SpaceAfterModuleName, this.SpaceBeforeArrow, this.SpaceAfterArrow, @@ -462,7 +466,6 @@ namespace ts.formatting { this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterCloseBracket, this.SpaceAfterSemicolon, - this.NoSpaceBeforeOpenParenInFuncDecl, this.SpaceBetweenStatements, this.SpaceAfterTryFinally ]; diff --git a/src/services/formatting/rulesProvider.ts b/src/services/formatting/rulesProvider.ts index 4a2c9d0f15586..14e08e4857aee 100644 --- a/src/services/formatting/rulesProvider.ts +++ b/src/services/formatting/rulesProvider.ts @@ -38,6 +38,13 @@ namespace ts.formatting { private createActiveRules(options: ts.FormatCodeSettings): Rule[] { let rules = this.globalRules.HighPriorityCommonRules.slice(0); + if (options.insertSpaceAfterConstructor) { + rules.push(this.globalRules.SpaceAfterConstructor); + } + else { + rules.push(this.globalRules.NoSpaceAfterConstructor); + } + if (options.insertSpaceAfterCommaDelimiter) { rules.push(this.globalRules.SpaceAfterComma); } @@ -128,6 +135,13 @@ namespace ts.formatting { rules.push(this.globalRules.NoSpaceAfterBinaryOperator); } + if (options.insertSpaceBeforeFunctionParenthesis) { + rules.push(this.globalRules.SpaceBeforeOpenParenInFuncDecl); + } + else { + rules.push(this.globalRules.NoSpaceBeforeOpenParenInFuncDecl); + } + if (options.placeOpenBraceOnNewLineForControlBlocks) { rules.push(this.globalRules.NewLineBeforeOpenBraceInControl); } diff --git a/src/services/types.ts b/src/services/types.ts index 48d7423510549..2558ca9abadb2 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -420,6 +420,7 @@ namespace ts { InsertSpaceAfterCommaDelimiter: boolean; InsertSpaceAfterSemicolonInForStatements: boolean; InsertSpaceBeforeAndAfterBinaryOperators: boolean; + InsertSpaceAfterConstructor?: boolean; InsertSpaceAfterKeywordsInControlFlowStatements: boolean; InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean; InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean; @@ -428,6 +429,7 @@ namespace ts { InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; InsertSpaceAfterTypeAssertion?: boolean; + InsertSpaceBeforeFunctionParenthesis?: boolean; PlaceOpenBraceOnNewLineForFunctions: boolean; PlaceOpenBraceOnNewLineForControlBlocks: boolean; } @@ -436,6 +438,7 @@ namespace ts { insertSpaceAfterCommaDelimiter?: boolean; insertSpaceAfterSemicolonInForStatements?: boolean; insertSpaceBeforeAndAfterBinaryOperators?: boolean; + insertSpaceAfterConstructor?: boolean; insertSpaceAfterKeywordsInControlFlowStatements?: boolean; insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean; insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean; @@ -444,6 +447,7 @@ namespace ts { insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean; insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; insertSpaceAfterTypeAssertion?: boolean; + insertSpaceBeforeFunctionParenthesis?: boolean; placeOpenBraceOnNewLineForFunctions?: boolean; placeOpenBraceOnNewLineForControlBlocks?: boolean; } diff --git a/tests/baselines/reference/cacheResolutions.js b/tests/baselines/reference/cacheResolutions.js new file mode 100644 index 0000000000000..1d0f918bf98db --- /dev/null +++ b/tests/baselines/reference/cacheResolutions.js @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/cacheResolutions.ts] //// + +//// [app.ts] + +export let x = 1; + +//// [lib1.ts] +export let x = 1; + +//// [lib2.ts] +export let x = 1; + +//// [app.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.x = 1; +}); +//// [lib1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.x = 1; +}); +//// [lib2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.x = 1; +}); diff --git a/tests/baselines/reference/cacheResolutions.symbols b/tests/baselines/reference/cacheResolutions.symbols new file mode 100644 index 0000000000000..362ce5c308c9f --- /dev/null +++ b/tests/baselines/reference/cacheResolutions.symbols @@ -0,0 +1,13 @@ +=== /a/b/c/app.ts === + +export let x = 1; +>x : Symbol(x, Decl(app.ts, 1, 10)) + +=== /a/b/c/lib1.ts === +export let x = 1; +>x : Symbol(x, Decl(lib1.ts, 0, 10)) + +=== /a/b/c/lib2.ts === +export let x = 1; +>x : Symbol(x, Decl(lib2.ts, 0, 10)) + diff --git a/tests/baselines/reference/cacheResolutions.trace.json b/tests/baselines/reference/cacheResolutions.trace.json new file mode 100644 index 0000000000000..8e7adfb989840 --- /dev/null +++ b/tests/baselines/reference/cacheResolutions.trace.json @@ -0,0 +1,43 @@ +[ + "======== Resolving module 'tslib' from '/a/b/c/app.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "File '/a/b/c/tslib.ts' does not exist.", + "File '/a/b/c/tslib.tsx' does not exist.", + "File '/a/b/c/tslib.d.ts' does not exist.", + "File '/a/b/tslib.ts' does not exist.", + "File '/a/b/tslib.tsx' does not exist.", + "File '/a/b/tslib.d.ts' does not exist.", + "File '/a/tslib.ts' does not exist.", + "File '/a/tslib.tsx' does not exist.", + "File '/a/tslib.d.ts' does not exist.", + "File '/tslib.ts' does not exist.", + "File '/tslib.tsx' does not exist.", + "File '/tslib.d.ts' does not exist.", + "File '/a/b/c/node_modules/@types/tslib.d.ts' does not exist.", + "File '/a/b/c/node_modules/@types/tslib/package.json' does not exist.", + "File '/a/b/c/node_modules/@types/tslib/index.d.ts' does not exist.", + "File '/a/b/node_modules/@types/tslib.d.ts' does not exist.", + "File '/a/b/node_modules/@types/tslib/package.json' does not exist.", + "File '/a/b/node_modules/@types/tslib/index.d.ts' does not exist.", + "File '/a/node_modules/@types/tslib.d.ts' does not exist.", + "File '/a/node_modules/@types/tslib/package.json' does not exist.", + "File '/a/node_modules/@types/tslib/index.d.ts' does not exist.", + "File '/node_modules/@types/tslib.d.ts' does not exist.", + "File '/node_modules/@types/tslib/package.json' does not exist.", + "File '/node_modules/@types/tslib/index.d.ts' does not exist.", + "File '/a/b/c/tslib.js' does not exist.", + "File '/a/b/c/tslib.jsx' does not exist.", + "File '/a/b/tslib.js' does not exist.", + "File '/a/b/tslib.jsx' does not exist.", + "File '/a/tslib.js' does not exist.", + "File '/a/tslib.jsx' does not exist.", + "File '/tslib.js' does not exist.", + "File '/tslib.jsx' does not exist.", + "======== Module name 'tslib' was not resolved. ========", + "======== Resolving module 'tslib' from '/a/b/c/lib1.ts'. ========", + "Resolution for module 'tslib' was found in cache", + "======== Module name 'tslib' was not resolved. ========", + "======== Resolving module 'tslib' from '/a/b/c/lib2.ts'. ========", + "Resolution for module 'tslib' was found in cache", + "======== Module name 'tslib' was not resolved. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/cacheResolutions.types b/tests/baselines/reference/cacheResolutions.types new file mode 100644 index 0000000000000..fdcc0a6c46c07 --- /dev/null +++ b/tests/baselines/reference/cacheResolutions.types @@ -0,0 +1,16 @@ +=== /a/b/c/app.ts === + +export let x = 1; +>x : number +>1 : 1 + +=== /a/b/c/lib1.ts === +export let x = 1; +>x : number +>1 : 1 + +=== /a/b/c/lib2.ts === +export let x = 1; +>x : number +>1 : 1 + diff --git a/tests/baselines/reference/jsxViaImport.2.js b/tests/baselines/reference/jsxViaImport.2.js new file mode 100644 index 0000000000000..19432238e0bb3 --- /dev/null +++ b/tests/baselines/reference/jsxViaImport.2.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/jsxViaImport.2.tsx] //// + +//// [component.d.ts] + +declare module JSX { + interface ElementAttributesProperty { props; } +} +declare module React { + class Component { } +} +declare module "BaseComponent" { + export default class extends React.Component { + } +} + +//// [consumer.tsx] +/// +import BaseComponent from 'BaseComponent'; +class TestComponent extends React.Component { + render() { + return ; + } +} + + +//// [consumer.jsx] +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +/// +var BaseComponent_1 = require("BaseComponent"); +var TestComponent = (function (_super) { + __extends(TestComponent, _super); + function TestComponent() { + return _super.apply(this, arguments) || this; + } + TestComponent.prototype.render = function () { + return ; + }; + return TestComponent; +}(React.Component)); diff --git a/tests/baselines/reference/jsxViaImport.2.symbols b/tests/baselines/reference/jsxViaImport.2.symbols new file mode 100644 index 0000000000000..5fb24088d2e85 --- /dev/null +++ b/tests/baselines/reference/jsxViaImport.2.symbols @@ -0,0 +1,44 @@ +=== tests/cases/compiler/consumer.tsx === +/// +import BaseComponent from 'BaseComponent'; +>BaseComponent : Symbol(BaseComponent, Decl(consumer.tsx, 1, 6)) + +class TestComponent extends React.Component { +>TestComponent : Symbol(TestComponent, Decl(consumer.tsx, 1, 42)) +>React.Component : Symbol(React.Component, Decl(component.d.ts, 4, 22)) +>React : Symbol(React, Decl(component.d.ts, 3, 1)) +>Component : Symbol(React.Component, Decl(component.d.ts, 4, 22)) + + render() { +>render : Symbol(TestComponent.render, Decl(consumer.tsx, 2, 54)) + + return ; +>BaseComponent : Symbol(BaseComponent, Decl(consumer.tsx, 1, 6)) + } +} + +=== tests/cases/compiler/component.d.ts === + +declare module JSX { +>JSX : Symbol(JSX, Decl(component.d.ts, 0, 0)) + + interface ElementAttributesProperty { props; } +>ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(component.d.ts, 1, 20)) +>props : Symbol(ElementAttributesProperty.props, Decl(component.d.ts, 2, 39)) +} +declare module React { +>React : Symbol(React, Decl(component.d.ts, 3, 1)) + + class Component { } +>Component : Symbol(Component, Decl(component.d.ts, 4, 22)) +>T : Symbol(T, Decl(component.d.ts, 5, 18)) +>U : Symbol(U, Decl(component.d.ts, 5, 20)) +} +declare module "BaseComponent" { + export default class extends React.Component { +>React.Component : Symbol(React.Component, Decl(component.d.ts, 4, 22)) +>React : Symbol(React, Decl(component.d.ts, 3, 1)) +>Component : Symbol(React.Component, Decl(component.d.ts, 4, 22)) + } +} + diff --git a/tests/baselines/reference/jsxViaImport.2.types b/tests/baselines/reference/jsxViaImport.2.types new file mode 100644 index 0000000000000..c1e418c6b3221 --- /dev/null +++ b/tests/baselines/reference/jsxViaImport.2.types @@ -0,0 +1,45 @@ +=== tests/cases/compiler/consumer.tsx === +/// +import BaseComponent from 'BaseComponent'; +>BaseComponent : typeof BaseComponent + +class TestComponent extends React.Component { +>TestComponent : TestComponent +>React.Component : React.Component +>React : typeof React +>Component : typeof React.Component + + render() { +>render : () => any + + return ; +> : any +>BaseComponent : typeof BaseComponent + } +} + +=== tests/cases/compiler/component.d.ts === + +declare module JSX { +>JSX : any + + interface ElementAttributesProperty { props; } +>ElementAttributesProperty : ElementAttributesProperty +>props : any +} +declare module React { +>React : typeof React + + class Component { } +>Component : Component +>T : T +>U : U +} +declare module "BaseComponent" { + export default class extends React.Component { +>React.Component : React.Component +>React : typeof React +>Component : typeof React.Component + } +} + diff --git a/tests/baselines/reference/literals.errors.txt b/tests/baselines/reference/literals.errors.txt index d43e89bb4db81..2920498bde478 100644 --- a/tests/baselines/reference/literals.errors.txt +++ b/tests/baselines/reference/literals.errors.txt @@ -2,8 +2,8 @@ tests/cases/conformance/expressions/literals/literals.ts(9,10): error TS2362: Th tests/cases/conformance/expressions/literals/literals.ts(9,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/literals/literals.ts(10,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/literals/literals.ts(10,21): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/literals/literals.ts(20,9): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. -tests/cases/conformance/expressions/literals/literals.ts(25,10): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/literals/literals.ts(20,9): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'. +tests/cases/conformance/expressions/literals/literals.ts(25,10): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o3'. ==== tests/cases/conformance/expressions/literals/literals.ts (6 errors) ==== @@ -36,14 +36,14 @@ tests/cases/conformance/expressions/literals/literals.ts(25,10): error TS1085: O var n = 1e4; var n = 001; // Error in ES5 ~~~ -!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. +!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'. var n = 0x1; var n = -1; var n = -1.0; var n = -1e-4; var n = -003; // Error in ES5 ~~~ -!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. +!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o3'. var n = -0x1; var s: string; diff --git a/tests/baselines/reference/mappedTypeErrors.errors.txt b/tests/baselines/reference/mappedTypeErrors.errors.txt index f98a11dbaf9be..94644a96af9bd 100644 --- a/tests/baselines/reference/mappedTypeErrors.errors.txt +++ b/tests/baselines/reference/mappedTypeErrors.errors.txt @@ -45,9 +45,11 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(130,5): error TS2322: T tests/cases/conformance/types/mapped/mappedTypeErrors.ts(131,5): error TS2322: Type '{ a: string; }' is not assignable to type '{ [x: string]: any; a?: number | undefined; }'. Types of property 'a' are incompatible. Type 'string' is not assignable to type 'number | undefined'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(137,16): error TS2322: Type '{}' is not assignable to type 'string'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(137,21): error TS2536: Type 'P' cannot be used to index type 'T'. -==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (24 errors) ==== +==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (26 errors) ==== interface Shape { name: string; @@ -249,4 +251,22 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(131,5): error TS2322: T ~~ !!! error TS2322: Type '{ a: string; }' is not assignable to type '{ [x: string]: any; a?: number | undefined; }'. !!! error TS2322: Types of property 'a' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number | undefined'. \ No newline at end of file +!!! error TS2322: Type 'string' is not assignable to type 'number | undefined'. + + // Repro from #13044 + + type Foo2 = { + pf: {[P in F]?: T[P]}, + pt: {[P in T]?: T[P]}, // note: should be in keyof T + ~ +!!! error TS2322: Type '{}' is not assignable to type 'string'. + ~~~~ +!!! error TS2536: Type 'P' cannot be used to index type 'T'. + }; + type O = {x: number, y: boolean}; + let o: O = {x: 5, y: false}; + let f: Foo2 = { + pf: {x: 7}, + pt: {x: 7, y: false}, + }; + \ No newline at end of file diff --git a/tests/baselines/reference/mappedTypeErrors.js b/tests/baselines/reference/mappedTypeErrors.js index 83dc235c7059e..f194b6193fc37 100644 --- a/tests/baselines/reference/mappedTypeErrors.js +++ b/tests/baselines/reference/mappedTypeErrors.js @@ -129,7 +129,21 @@ type T2 = { a?: number, [key: string]: any }; let x1: T2 = { a: 'no' }; // Error let x2: Partial = { a: 'no' }; // Error -let x3: { [P in keyof T2]: T2[P]} = { a: 'no' }; // Error +let x3: { [P in keyof T2]: T2[P]} = { a: 'no' }; // Error + +// Repro from #13044 + +type Foo2 = { + pf: {[P in F]?: T[P]}, + pt: {[P in T]?: T[P]}, // note: should be in keyof T +}; +type O = {x: number, y: boolean}; +let o: O = {x: 5, y: false}; +let f: Foo2 = { + pf: {x: 7}, + pt: {x: 7, y: false}, +}; + //// [mappedTypeErrors.js] function f1(x) { @@ -204,6 +218,11 @@ c.setState({ c: true }); // Error var x1 = { a: 'no' }; // Error var x2 = { a: 'no' }; // Error var x3 = { a: 'no' }; // Error +var o = { x: 5, y: false }; +var f = { + pf: { x: 7 }, + pt: { x: 7, y: false } +}; //// [mappedTypeErrors.d.ts] @@ -268,3 +287,17 @@ declare let x2: Partial; declare let x3: { [P in keyof T2]: T2[P]; }; +declare type Foo2 = { + pf: { + [P in F]?: T[P]; + }; + pt: { + [P in T]?: T[P]; + }; +}; +declare type O = { + x: number; + y: boolean; +}; +declare let o: O; +declare let f: Foo2; diff --git a/tests/baselines/reference/mappedTypesAndObjects.js b/tests/baselines/reference/mappedTypesAndObjects.js new file mode 100644 index 0000000000000..53b39209693b8 --- /dev/null +++ b/tests/baselines/reference/mappedTypesAndObjects.js @@ -0,0 +1,72 @@ +//// [mappedTypesAndObjects.ts] + +function f1(x: Partial, y: Readonly) { + let obj: {}; + obj = x; + obj = y; +} + +function f2(x: Partial, y: Readonly) { + let obj: { [x: string]: any }; + obj = x; + obj = y; +} + +// Repro from #12900 + +interface Base { + foo: { [key: string]: any }; + bar: any; + baz: any; +} + +interface E1 extends Base { + foo: T; +} + +interface Something { name: string, value: string }; +interface E2 extends Base { + foo: Partial; // or other mapped type +} + +interface E3 extends Base { + foo: Partial; // or other mapped type +} + +//// [mappedTypesAndObjects.js] +function f1(x, y) { + var obj; + obj = x; + obj = y; +} +function f2(x, y) { + var obj; + obj = x; + obj = y; +} +; + + +//// [mappedTypesAndObjects.d.ts] +declare function f1(x: Partial, y: Readonly): void; +declare function f2(x: Partial, y: Readonly): void; +interface Base { + foo: { + [key: string]: any; + }; + bar: any; + baz: any; +} +interface E1 extends Base { + foo: T; +} +interface Something { + name: string; + value: string; +} +interface E2 extends Base { + foo: Partial; +} +interface E3 extends Base { + foo: Partial; +} diff --git a/tests/baselines/reference/mappedTypesAndObjects.symbols b/tests/baselines/reference/mappedTypesAndObjects.symbols new file mode 100644 index 0000000000000..1690f1b6b04e5 --- /dev/null +++ b/tests/baselines/reference/mappedTypesAndObjects.symbols @@ -0,0 +1,98 @@ +=== tests/cases/conformance/types/mapped/mappedTypesAndObjects.ts === + +function f1(x: Partial, y: Readonly) { +>f1 : Symbol(f1, Decl(mappedTypesAndObjects.ts, 0, 0)) +>T : Symbol(T, Decl(mappedTypesAndObjects.ts, 1, 12)) +>x : Symbol(x, Decl(mappedTypesAndObjects.ts, 1, 15)) +>Partial : Symbol(Partial, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypesAndObjects.ts, 1, 12)) +>y : Symbol(y, Decl(mappedTypesAndObjects.ts, 1, 29)) +>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypesAndObjects.ts, 1, 12)) + + let obj: {}; +>obj : Symbol(obj, Decl(mappedTypesAndObjects.ts, 2, 7)) + + obj = x; +>obj : Symbol(obj, Decl(mappedTypesAndObjects.ts, 2, 7)) +>x : Symbol(x, Decl(mappedTypesAndObjects.ts, 1, 15)) + + obj = y; +>obj : Symbol(obj, Decl(mappedTypesAndObjects.ts, 2, 7)) +>y : Symbol(y, Decl(mappedTypesAndObjects.ts, 1, 29)) +} + +function f2(x: Partial, y: Readonly) { +>f2 : Symbol(f2, Decl(mappedTypesAndObjects.ts, 5, 1)) +>T : Symbol(T, Decl(mappedTypesAndObjects.ts, 7, 12)) +>x : Symbol(x, Decl(mappedTypesAndObjects.ts, 7, 15)) +>Partial : Symbol(Partial, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypesAndObjects.ts, 7, 12)) +>y : Symbol(y, Decl(mappedTypesAndObjects.ts, 7, 29)) +>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypesAndObjects.ts, 7, 12)) + + let obj: { [x: string]: any }; +>obj : Symbol(obj, Decl(mappedTypesAndObjects.ts, 8, 7)) +>x : Symbol(x, Decl(mappedTypesAndObjects.ts, 8, 16)) + + obj = x; +>obj : Symbol(obj, Decl(mappedTypesAndObjects.ts, 8, 7)) +>x : Symbol(x, Decl(mappedTypesAndObjects.ts, 7, 15)) + + obj = y; +>obj : Symbol(obj, Decl(mappedTypesAndObjects.ts, 8, 7)) +>y : Symbol(y, Decl(mappedTypesAndObjects.ts, 7, 29)) +} + +// Repro from #12900 + +interface Base { +>Base : Symbol(Base, Decl(mappedTypesAndObjects.ts, 11, 1)) + + foo: { [key: string]: any }; +>foo : Symbol(Base.foo, Decl(mappedTypesAndObjects.ts, 15, 16)) +>key : Symbol(key, Decl(mappedTypesAndObjects.ts, 16, 11)) + + bar: any; +>bar : Symbol(Base.bar, Decl(mappedTypesAndObjects.ts, 16, 31)) + + baz: any; +>baz : Symbol(Base.baz, Decl(mappedTypesAndObjects.ts, 17, 12)) +} + +interface E1 extends Base { +>E1 : Symbol(E1, Decl(mappedTypesAndObjects.ts, 19, 1)) +>T : Symbol(T, Decl(mappedTypesAndObjects.ts, 21, 13)) +>Base : Symbol(Base, Decl(mappedTypesAndObjects.ts, 11, 1)) + + foo: T; +>foo : Symbol(E1.foo, Decl(mappedTypesAndObjects.ts, 21, 30)) +>T : Symbol(T, Decl(mappedTypesAndObjects.ts, 21, 13)) +} + +interface Something { name: string, value: string }; +>Something : Symbol(Something, Decl(mappedTypesAndObjects.ts, 23, 1)) +>name : Symbol(Something.name, Decl(mappedTypesAndObjects.ts, 25, 21)) +>value : Symbol(Something.value, Decl(mappedTypesAndObjects.ts, 25, 35)) + +interface E2 extends Base { +>E2 : Symbol(E2, Decl(mappedTypesAndObjects.ts, 25, 52)) +>Base : Symbol(Base, Decl(mappedTypesAndObjects.ts, 11, 1)) + + foo: Partial; // or other mapped type +>foo : Symbol(E2.foo, Decl(mappedTypesAndObjects.ts, 26, 27)) +>Partial : Symbol(Partial, Decl(lib.d.ts, --, --)) +>Something : Symbol(Something, Decl(mappedTypesAndObjects.ts, 23, 1)) +} + +interface E3 extends Base { +>E3 : Symbol(E3, Decl(mappedTypesAndObjects.ts, 28, 1)) +>T : Symbol(T, Decl(mappedTypesAndObjects.ts, 30, 13)) +>Base : Symbol(Base, Decl(mappedTypesAndObjects.ts, 11, 1)) + + foo: Partial; // or other mapped type +>foo : Symbol(E3.foo, Decl(mappedTypesAndObjects.ts, 30, 30)) +>Partial : Symbol(Partial, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypesAndObjects.ts, 30, 13)) +} diff --git a/tests/baselines/reference/mappedTypesAndObjects.types b/tests/baselines/reference/mappedTypesAndObjects.types new file mode 100644 index 0000000000000..e6f8e53f5584c --- /dev/null +++ b/tests/baselines/reference/mappedTypesAndObjects.types @@ -0,0 +1,102 @@ +=== tests/cases/conformance/types/mapped/mappedTypesAndObjects.ts === + +function f1(x: Partial, y: Readonly) { +>f1 : (x: Partial, y: Readonly) => void +>T : T +>x : Partial +>Partial : Partial +>T : T +>y : Readonly +>Readonly : Readonly +>T : T + + let obj: {}; +>obj : {} + + obj = x; +>obj = x : Partial +>obj : {} +>x : Partial + + obj = y; +>obj = y : Readonly +>obj : {} +>y : Readonly +} + +function f2(x: Partial, y: Readonly) { +>f2 : (x: Partial, y: Readonly) => void +>T : T +>x : Partial +>Partial : Partial +>T : T +>y : Readonly +>Readonly : Readonly +>T : T + + let obj: { [x: string]: any }; +>obj : { [x: string]: any; } +>x : string + + obj = x; +>obj = x : Partial +>obj : { [x: string]: any; } +>x : Partial + + obj = y; +>obj = y : Readonly +>obj : { [x: string]: any; } +>y : Readonly +} + +// Repro from #12900 + +interface Base { +>Base : Base + + foo: { [key: string]: any }; +>foo : { [key: string]: any; } +>key : string + + bar: any; +>bar : any + + baz: any; +>baz : any +} + +interface E1 extends Base { +>E1 : E1 +>T : T +>Base : Base + + foo: T; +>foo : T +>T : T +} + +interface Something { name: string, value: string }; +>Something : Something +>name : string +>value : string + +interface E2 extends Base { +>E2 : E2 +>Base : Base + + foo: Partial; // or other mapped type +>foo : Partial +>Partial : Partial +>Something : Something +} + +interface E3 extends Base { +>E3 : E3 +>T : T +>Base : Base + + foo: Partial; // or other mapped type +>foo : Partial +>Partial : Partial +>T : T +} diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.js b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.js new file mode 100644 index 0000000000000..b5d4ae20a4db7 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/moduleResolutionWithExtensions_unexpected.ts] //// + +//// [normalize.css] +// This tests that a package.json "main" with an unexpected extension is ignored. + +This file is not read. + +//// [package.json] +{ "main": "normalize.css" } + +//// [a.ts] +import "normalize.css"; + + +//// [a.js] +"use strict"; +require("normalize.css"); diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.symbols b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.symbols new file mode 100644 index 0000000000000..a73d58fd7d8e9 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.symbols @@ -0,0 +1,4 @@ +=== /a.ts === +import "normalize.css"; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.trace.json new file mode 100644 index 0000000000000..84532e8db7b22 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.trace.json @@ -0,0 +1,29 @@ +[ + "======== Resolving module 'normalize.css' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module 'normalize.css' from 'node_modules' folder.", + "File '/node_modules/normalize.css.ts' does not exist.", + "File '/node_modules/normalize.css.tsx' does not exist.", + "File '/node_modules/normalize.css.d.ts' does not exist.", + "Found 'package.json' at '/node_modules/normalize.css/package.json'.", + "'package.json' does not have a 'types' or 'main' field.", + "File '/node_modules/normalize.css/index.ts' does not exist.", + "File '/node_modules/normalize.css/index.tsx' does not exist.", + "File '/node_modules/normalize.css/index.d.ts' does not exist.", + "File '/node_modules/@types/normalize.css.d.ts' does not exist.", + "File '/node_modules/@types/normalize.css/package.json' does not exist.", + "File '/node_modules/@types/normalize.css/index.d.ts' does not exist.", + "Loading module 'normalize.css' from 'node_modules' folder.", + "File '/node_modules/normalize.css.js' does not exist.", + "File '/node_modules/normalize.css.jsx' does not exist.", + "Found 'package.json' at '/node_modules/normalize.css/package.json'.", + "No types specified in 'package.json', so returning 'main' value of 'normalize.css'", + "File '/node_modules/normalize.css/normalize.css' exist - use it as a name resolution result.", + "File '/node_modules/normalize.css/normalize.css' has an unsupported extension, so skipping it.", + "File '/node_modules/normalize.css/normalize.css.ts' does not exist.", + "File '/node_modules/normalize.css/normalize.css.tsx' does not exist.", + "File '/node_modules/normalize.css/normalize.css.d.ts' does not exist.", + "File '/node_modules/normalize.css/index.js' does not exist.", + "File '/node_modules/normalize.css/index.jsx' does not exist.", + "======== Module name 'normalize.css' was not resolved. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.types b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.types new file mode 100644 index 0000000000000..a73d58fd7d8e9 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.types @@ -0,0 +1,4 @@ +=== /a.ts === +import "normalize.css"; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.js b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.js new file mode 100644 index 0000000000000..dc9df79e4dfb7 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/moduleResolutionWithExtensions_unexpected2.ts] //// + +//// [foo.js] +// This tests that a package.json "types" with an unexpected extension is ignored. + +This file is not read. + +//// [package.json] +{ "types": "foo.js" } + +//// [a.ts] +import "foo"; + + +//// [a.js] +"use strict"; +require("foo"); diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.symbols b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.symbols new file mode 100644 index 0000000000000..11c9c72cc6907 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.symbols @@ -0,0 +1,4 @@ +=== /a.ts === +import "foo"; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.trace.json new file mode 100644 index 0000000000000..27c9d2243e5f2 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.trace.json @@ -0,0 +1,29 @@ +[ + "======== Resolving module 'foo' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module 'foo' from 'node_modules' folder.", + "File '/node_modules/foo.ts' does not exist.", + "File '/node_modules/foo.tsx' does not exist.", + "File '/node_modules/foo.d.ts' does not exist.", + "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' has 'types' field 'foo.js' that references '/node_modules/foo/foo.js'.", + "File '/node_modules/foo/foo.js' exist - use it as a name resolution result.", + "File '/node_modules/foo/foo.js' has an unsupported extension, so skipping it.", + "File '/node_modules/foo/foo.js.ts' does not exist.", + "File '/node_modules/foo/foo.js.tsx' does not exist.", + "File '/node_modules/foo/foo.js.d.ts' does not exist.", + "File '/node_modules/foo/index.ts' does not exist.", + "File '/node_modules/foo/index.tsx' does not exist.", + "File '/node_modules/foo/index.d.ts' does not exist.", + "File '/node_modules/@types/foo.d.ts' does not exist.", + "File '/node_modules/@types/foo/package.json' does not exist.", + "File '/node_modules/@types/foo/index.d.ts' does not exist.", + "Loading module 'foo' from 'node_modules' folder.", + "File '/node_modules/foo.js' does not exist.", + "File '/node_modules/foo.jsx' does not exist.", + "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'types' or 'main' field.", + "File '/node_modules/foo/index.js' does not exist.", + "File '/node_modules/foo/index.jsx' does not exist.", + "======== Module name 'foo' was not resolved. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.types b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.types new file mode 100644 index 0000000000000..11c9c72cc6907 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.types @@ -0,0 +1,4 @@ +=== /a.ts === +import "foo"; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/nestedLoops.js b/tests/baselines/reference/nestedLoops.js new file mode 100644 index 0000000000000..c29311c38de95 --- /dev/null +++ b/tests/baselines/reference/nestedLoops.js @@ -0,0 +1,47 @@ +//// [nestedLoops.ts] +export class Test { + constructor() { + + let outerArray: Array = [1, 2, 3]; + let innerArray: Array = [1, 2, 3]; + + for (let outer of outerArray) + for (let inner of innerArray) { + this.aFunction((newValue, oldValue) => { + let x = outer + inner + newValue; + }); + } + } + + public aFunction(func: (newValue: any, oldValue: any) => void): void { + } +} + +//// [nestedLoops.js] +"use strict"; +var Test = (function () { + function Test() { + var outerArray = [1, 2, 3]; + var innerArray = [1, 2, 3]; + var _loop_1 = function (outer) { + var _loop_2 = function (inner) { + this_1.aFunction(function (newValue, oldValue) { + var x = outer + inner + newValue; + }); + }; + for (var _i = 0, innerArray_1 = innerArray; _i < innerArray_1.length; _i++) { + var inner = innerArray_1[_i]; + _loop_2(inner); + } + }; + var this_1 = this; + for (var _i = 0, outerArray_1 = outerArray; _i < outerArray_1.length; _i++) { + var outer = outerArray_1[_i]; + _loop_1(outer); + } + } + Test.prototype.aFunction = function (func) { + }; + return Test; +}()); +exports.Test = Test; diff --git a/tests/baselines/reference/nestedLoops.symbols b/tests/baselines/reference/nestedLoops.symbols new file mode 100644 index 0000000000000..0ab1c4651a6c5 --- /dev/null +++ b/tests/baselines/reference/nestedLoops.symbols @@ -0,0 +1,46 @@ +=== tests/cases/compiler/nestedLoops.ts === +export class Test { +>Test : Symbol(Test, Decl(nestedLoops.ts, 0, 0)) + + constructor() { + + let outerArray: Array = [1, 2, 3]; +>outerArray : Symbol(outerArray, Decl(nestedLoops.ts, 3, 11)) +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + + let innerArray: Array = [1, 2, 3]; +>innerArray : Symbol(innerArray, Decl(nestedLoops.ts, 4, 11)) +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + + for (let outer of outerArray) +>outer : Symbol(outer, Decl(nestedLoops.ts, 6, 16)) +>outerArray : Symbol(outerArray, Decl(nestedLoops.ts, 3, 11)) + + for (let inner of innerArray) { +>inner : Symbol(inner, Decl(nestedLoops.ts, 7, 20)) +>innerArray : Symbol(innerArray, Decl(nestedLoops.ts, 4, 11)) + + this.aFunction((newValue, oldValue) => { +>this.aFunction : Symbol(Test.aFunction, Decl(nestedLoops.ts, 12, 5)) +>this : Symbol(Test, Decl(nestedLoops.ts, 0, 0)) +>aFunction : Symbol(Test.aFunction, Decl(nestedLoops.ts, 12, 5)) +>newValue : Symbol(newValue, Decl(nestedLoops.ts, 8, 32)) +>oldValue : Symbol(oldValue, Decl(nestedLoops.ts, 8, 41)) + + let x = outer + inner + newValue; +>x : Symbol(x, Decl(nestedLoops.ts, 9, 23)) +>outer : Symbol(outer, Decl(nestedLoops.ts, 6, 16)) +>inner : Symbol(inner, Decl(nestedLoops.ts, 7, 20)) +>newValue : Symbol(newValue, Decl(nestedLoops.ts, 8, 32)) + + }); + } + } + + public aFunction(func: (newValue: any, oldValue: any) => void): void { +>aFunction : Symbol(Test.aFunction, Decl(nestedLoops.ts, 12, 5)) +>func : Symbol(func, Decl(nestedLoops.ts, 14, 21)) +>newValue : Symbol(newValue, Decl(nestedLoops.ts, 14, 28)) +>oldValue : Symbol(oldValue, Decl(nestedLoops.ts, 14, 42)) + } +} diff --git a/tests/baselines/reference/nestedLoops.types b/tests/baselines/reference/nestedLoops.types new file mode 100644 index 0000000000000..f4a743f4aaf84 --- /dev/null +++ b/tests/baselines/reference/nestedLoops.types @@ -0,0 +1,58 @@ +=== tests/cases/compiler/nestedLoops.ts === +export class Test { +>Test : Test + + constructor() { + + let outerArray: Array = [1, 2, 3]; +>outerArray : number[] +>Array : T[] +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 + + let innerArray: Array = [1, 2, 3]; +>innerArray : number[] +>Array : T[] +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 + + for (let outer of outerArray) +>outer : number +>outerArray : number[] + + for (let inner of innerArray) { +>inner : number +>innerArray : number[] + + this.aFunction((newValue, oldValue) => { +>this.aFunction((newValue, oldValue) => { let x = outer + inner + newValue; }) : void +>this.aFunction : (func: (newValue: any, oldValue: any) => void) => void +>this : this +>aFunction : (func: (newValue: any, oldValue: any) => void) => void +>(newValue, oldValue) => { let x = outer + inner + newValue; } : (newValue: any, oldValue: any) => void +>newValue : any +>oldValue : any + + let x = outer + inner + newValue; +>x : any +>outer + inner + newValue : any +>outer + inner : number +>outer : number +>inner : number +>newValue : any + + }); + } + } + + public aFunction(func: (newValue: any, oldValue: any) => void): void { +>aFunction : (func: (newValue: any, oldValue: any) => void) => void +>func : (newValue: any, oldValue: any) => void +>newValue : any +>oldValue : any + } +} diff --git a/tests/baselines/reference/objectLiteralErrors.errors.txt b/tests/baselines/reference/objectLiteralErrors.errors.txt index 234ac24a8fdc5..03b4b74eacd7b 100644 --- a/tests/baselines/reference/objectLiteralErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralErrors.errors.txt @@ -12,7 +12,7 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(13,21) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(14,19): error TS2300: Duplicate identifier '0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(15,19): error TS2300: Duplicate identifier '0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(16,19): error TS2300: Duplicate identifier '0x0'. -tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,19): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,19): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(17,19): error TS2300: Duplicate identifier '000'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(18,23): error TS2300: Duplicate identifier '1e2'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(19,22): error TS2300: Duplicate identifier '3.2e1'. @@ -125,7 +125,7 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(45,55) !!! error TS2300: Duplicate identifier '0x0'. var e14 = { 0: 0, 000: 0 }; ~~~ -!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. +!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o0'. ~~~ !!! error TS2300: Duplicate identifier '000'. var e15 = { "100": 0, 1e2: 0 }; diff --git a/tests/baselines/reference/oldStyleOctalLiteralTypes.errors.txt b/tests/baselines/reference/oldStyleOctalLiteralTypes.errors.txt new file mode 100644 index 0000000000000..4dc81f370a40b --- /dev/null +++ b/tests/baselines/reference/oldStyleOctalLiteralTypes.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/oldStyleOctalLiteralTypes.ts(1,8): error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o10'. +tests/cases/compiler/oldStyleOctalLiteralTypes.ts(2,9): error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o20'. + + +==== tests/cases/compiler/oldStyleOctalLiteralTypes.ts (2 errors) ==== + let x: 010; + ~~~ +!!! error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o10'. + let y: -020; + ~~~ +!!! error TS8017: Octal literal types must use ES2015 syntax. Use the syntax '0o20'. + \ No newline at end of file diff --git a/tests/baselines/reference/oldStyleOctalLiteralTypes.js b/tests/baselines/reference/oldStyleOctalLiteralTypes.js new file mode 100644 index 0000000000000..28b275774c3dd --- /dev/null +++ b/tests/baselines/reference/oldStyleOctalLiteralTypes.js @@ -0,0 +1,8 @@ +//// [oldStyleOctalLiteralTypes.ts] +let x: 010; +let y: -020; + + +//// [oldStyleOctalLiteralTypes.js] +var x; +var y; diff --git a/tests/baselines/reference/scannerNumericLiteral2.errors.txt b/tests/baselines/reference/scannerNumericLiteral2.errors.txt index 5860be78c1b2d..faf5429f8b754 100644 --- a/tests/baselines/reference/scannerNumericLiteral2.errors.txt +++ b/tests/baselines/reference/scannerNumericLiteral2.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral2.ts(1,1): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. +tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral2.ts(1,1): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'. ==== tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral2.ts (1 errors) ==== 01 ~~ -!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. \ No newline at end of file +!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o1'. \ No newline at end of file diff --git a/tests/baselines/reference/scannerNumericLiteral8.errors.txt b/tests/baselines/reference/scannerNumericLiteral8.errors.txt index 94916626fe660..5aad01449f283 100644 --- a/tests/baselines/reference/scannerNumericLiteral8.errors.txt +++ b/tests/baselines/reference/scannerNumericLiteral8.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts(1,2): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. +tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts(1,2): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o3'. ==== tests/cases/conformance/scanner/ecmascript5/scannerNumericLiteral8.ts (1 errors) ==== -03 ~~ -!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. \ No newline at end of file +!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o3'. \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives12.trace.json b/tests/baselines/reference/typeReferenceDirectives12.trace.json index f232228a351e4..5f87ab7ea395b 100644 --- a/tests/baselines/reference/typeReferenceDirectives12.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives12.trace.json @@ -16,9 +16,7 @@ "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving module './main' from '/mod1.ts'. ========", - "Module resolution kind is not specified, using 'NodeJs'.", - "Loading module as file / folder, candidate module location '/main'.", - "File '/main.ts' exist - use it as a name resolution result.", + "Resolution for module './main' was found in cache", "======== Module name './main' was successfully resolved to '/main.ts'. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", diff --git a/tests/baselines/reference/typeReferenceDirectives9.trace.json b/tests/baselines/reference/typeReferenceDirectives9.trace.json index f232228a351e4..5f87ab7ea395b 100644 --- a/tests/baselines/reference/typeReferenceDirectives9.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives9.trace.json @@ -16,9 +16,7 @@ "Resolving real path for '/types/lib/index.d.ts', result '/types/lib/index.d.ts'", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", "======== Resolving module './main' from '/mod1.ts'. ========", - "Module resolution kind is not specified, using 'NodeJs'.", - "Loading module as file / folder, candidate module location '/main'.", - "File '/main.ts' exist - use it as a name resolution result.", + "Resolution for module './main' was found in cache", "======== Module name './main' was successfully resolved to '/main.ts'. ========", "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'", diff --git a/tests/cases/compiler/cacheResolutions.ts b/tests/cases/compiler/cacheResolutions.ts new file mode 100644 index 0000000000000..c6962e25db6bb --- /dev/null +++ b/tests/cases/compiler/cacheResolutions.ts @@ -0,0 +1,12 @@ +// @module: amd +// @importHelpers: true +// @traceResolution: true + +// @filename: /a/b/c/app.ts +export let x = 1; + +// @filename: /a/b/c/lib1.ts +export let x = 1; + +// @filename: /a/b/c/lib2.ts +export let x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/jsxViaImport.2.tsx b/tests/cases/compiler/jsxViaImport.2.tsx new file mode 100644 index 0000000000000..1849fef62539c --- /dev/null +++ b/tests/cases/compiler/jsxViaImport.2.tsx @@ -0,0 +1,23 @@ +//@jsx: preserve +//@module: commonjs + +//@filename: component.d.ts +declare module JSX { + interface ElementAttributesProperty { props; } +} +declare module React { + class Component { } +} +declare module "BaseComponent" { + export default class extends React.Component { + } +} + +//@filename: consumer.tsx +/// +import BaseComponent from 'BaseComponent'; +class TestComponent extends React.Component { + render() { + return ; + } +} diff --git a/tests/cases/compiler/moduleResolutionWithExtensions_unexpected.ts b/tests/cases/compiler/moduleResolutionWithExtensions_unexpected.ts new file mode 100644 index 0000000000000..3af02eabb7656 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithExtensions_unexpected.ts @@ -0,0 +1,12 @@ +// @noImplicitReferences: true +// @traceResolution: true +// This tests that a package.json "main" with an unexpected extension is ignored. + +// @Filename: /node_modules/normalize.css/normalize.css +This file is not read. + +// @Filename: /node_modules/normalize.css/package.json +{ "main": "normalize.css" } + +// @Filename: /a.ts +import "normalize.css"; diff --git a/tests/cases/compiler/moduleResolutionWithExtensions_unexpected2.ts b/tests/cases/compiler/moduleResolutionWithExtensions_unexpected2.ts new file mode 100644 index 0000000000000..1c960fa67e9a6 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithExtensions_unexpected2.ts @@ -0,0 +1,12 @@ +// @noImplicitReferences: true +// @traceResolution: true +// This tests that a package.json "types" with an unexpected extension is ignored. + +// @Filename: /node_modules/foo/foo.js +This file is not read. + +// @Filename: /node_modules/foo/package.json +{ "types": "foo.js" } + +// @Filename: /a.ts +import "foo"; diff --git a/tests/cases/compiler/nestedLoops.ts b/tests/cases/compiler/nestedLoops.ts new file mode 100644 index 0000000000000..c480b4b1c68f7 --- /dev/null +++ b/tests/cases/compiler/nestedLoops.ts @@ -0,0 +1,18 @@ +// @target: es5 +export class Test { + constructor() { + + let outerArray: Array = [1, 2, 3]; + let innerArray: Array = [1, 2, 3]; + + for (let outer of outerArray) + for (let inner of innerArray) { + this.aFunction((newValue, oldValue) => { + let x = outer + inner + newValue; + }); + } + } + + public aFunction(func: (newValue: any, oldValue: any) => void): void { + } +} \ No newline at end of file diff --git a/tests/cases/compiler/oldStyleOctalLiteralTypes.ts b/tests/cases/compiler/oldStyleOctalLiteralTypes.ts new file mode 100644 index 0000000000000..c5a5475e30029 --- /dev/null +++ b/tests/cases/compiler/oldStyleOctalLiteralTypes.ts @@ -0,0 +1,3 @@ +// @target: ES3 +let x: 010; +let y: -020; diff --git a/tests/cases/conformance/types/mapped/mappedTypeErrors.ts b/tests/cases/conformance/types/mapped/mappedTypeErrors.ts index 458dbe9caa412..cec1fbf839554 100644 --- a/tests/cases/conformance/types/mapped/mappedTypeErrors.ts +++ b/tests/cases/conformance/types/mapped/mappedTypeErrors.ts @@ -130,4 +130,17 @@ type T2 = { a?: number, [key: string]: any }; let x1: T2 = { a: 'no' }; // Error let x2: Partial = { a: 'no' }; // Error -let x3: { [P in keyof T2]: T2[P]} = { a: 'no' }; // Error \ No newline at end of file +let x3: { [P in keyof T2]: T2[P]} = { a: 'no' }; // Error + +// Repro from #13044 + +type Foo2 = { + pf: {[P in F]?: T[P]}, + pt: {[P in T]?: T[P]}, // note: should be in keyof T +}; +type O = {x: number, y: boolean}; +let o: O = {x: 5, y: false}; +let f: Foo2 = { + pf: {x: 7}, + pt: {x: 7, y: false}, +}; diff --git a/tests/cases/conformance/types/mapped/mappedTypesAndObjects.ts b/tests/cases/conformance/types/mapped/mappedTypesAndObjects.ts new file mode 100644 index 0000000000000..8023f6e7d8d92 --- /dev/null +++ b/tests/cases/conformance/types/mapped/mappedTypesAndObjects.ts @@ -0,0 +1,35 @@ +// @strictNullChecks: true +// @declaration: true + +function f1(x: Partial, y: Readonly) { + let obj: {}; + obj = x; + obj = y; +} + +function f2(x: Partial, y: Readonly) { + let obj: { [x: string]: any }; + obj = x; + obj = y; +} + +// Repro from #12900 + +interface Base { + foo: { [key: string]: any }; + bar: any; + baz: any; +} + +interface E1 extends Base { + foo: T; +} + +interface Something { name: string, value: string }; +interface E2 extends Base { + foo: Partial; // or other mapped type +} + +interface E3 extends Base { + foo: Partial; // or other mapped type +} \ No newline at end of file diff --git a/tests/cases/fourslash/formattingReadonly.ts b/tests/cases/fourslash/formattingReadonly.ts new file mode 100644 index 0000000000000..e9ec9860032c3 --- /dev/null +++ b/tests/cases/fourslash/formattingReadonly.ts @@ -0,0 +1,12 @@ +/// + +////class C { +//// readonly property1 {};/*1*/ +//// public readonly property2 {};/*2*/ +////} + +format.document(); +goTo.marker("1"); +verify.currentLineContentIs(" readonly property1 {};"); +goTo.marker("2"); +verify.currentLineContentIs(" public readonly property2 {};"); \ No newline at end of file diff --git a/tests/cases/fourslash/formattingSpaceBeforeFunctionParen.ts b/tests/cases/fourslash/formattingSpaceBeforeFunctionParen.ts new file mode 100644 index 0000000000000..ce85521879ed3 --- /dev/null +++ b/tests/cases/fourslash/formattingSpaceBeforeFunctionParen.ts @@ -0,0 +1,19 @@ +/// + +/////*1*/function foo() { } +/////*2*/function boo () { } +/////*3*/var bar = function foo() { }; +/////*4*/var foo = { bar() { } }; + +format.setOption("InsertSpaceBeforeFunctionParenthesis", true); + +format.document(); + +goTo.marker('1'); +verify.currentLineContentIs('function foo () { }'); +goTo.marker('2'); +verify.currentLineContentIs('function boo () { }'); +goTo.marker('3'); +verify.currentLineContentIs('var bar = function foo () { };'); +goTo.marker('4'); +verify.currentLineContentIs('var foo = { bar () { } };'); \ No newline at end of file diff --git a/tests/cases/fourslash/formattingSpacesAfterConstructor.ts b/tests/cases/fourslash/formattingSpacesAfterConstructor.ts index 8df762def20a1..2195d74adbc1d 100644 --- a/tests/cases/fourslash/formattingSpacesAfterConstructor.ts +++ b/tests/cases/fourslash/formattingSpacesAfterConstructor.ts @@ -3,4 +3,11 @@ /////*1*/class test { constructor () { } } format.document(); goTo.marker("1"); -verify.currentLineContentIs("class test { constructor() { } }"); \ No newline at end of file +verify.currentLineContentIs("class test { constructor() { } }"); + +/////*2*/class test { constructor () { } } +format.setOption("InsertSpaceAfterConstructor", true); + +format.document(); +goTo.marker("2"); +verify.currentLineContentIs("class test { constructor () { } }"); \ No newline at end of file