From e94910f37f5796a0abac2824ccd11aa320d3259a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 24 Jul 2018 16:48:26 -0700 Subject: [PATCH] Update LKG --- lib/tsc.js | 127 +++++++++----- lib/tsserver.js | 355 +++++++++++++++++++++---------------- lib/tsserverlibrary.d.ts | 2 - lib/tsserverlibrary.js | 361 ++++++++++++++++++++++---------------- lib/typescript.js | 181 ++++++++++++------- lib/typescriptServices.js | 181 ++++++++++++------- lib/typingsInstaller.js | 133 +++++++++----- 7 files changed, 815 insertions(+), 525 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index c068dcddbf8..33f11a4dcf1 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -8159,27 +8159,35 @@ var ts; return referencePath ? ts.ensurePathIsNonModuleName(extensionless) : extensionless; } ts.getExternalModuleNameFromPath = getExternalModuleNameFromPath; - function getOwnEmitOutputFilePath(sourceFile, host, extension) { + function getOwnEmitOutputFilePath(fileName, host, extension) { var compilerOptions = host.getCompilerOptions(); var emitOutputFilePathWithoutExtension; if (compilerOptions.outDir) { - emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); + emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(fileName, host, compilerOptions.outDir)); } else { - emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName); + emitOutputFilePathWithoutExtension = ts.removeFileExtension(fileName); } return emitOutputFilePathWithoutExtension + extension; } ts.getOwnEmitOutputFilePath = getOwnEmitOutputFilePath; - function getDeclarationEmitOutputFilePath(sourceFile, host) { + function getDeclarationEmitOutputFilePath(fileName, host) { var options = host.getCompilerOptions(); var outputDir = options.declarationDir || options.outDir; var path = outputDir - ? getSourceFilePathInNewDir(sourceFile, host, outputDir) - : sourceFile.fileName; + ? getSourceFilePathInNewDir(fileName, host, outputDir) + : fileName; return ts.removeFileExtension(path) + ".d.ts"; } ts.getDeclarationEmitOutputFilePath = getDeclarationEmitOutputFilePath; + function getDeclarationEmitOutputFilePathWorker(fileName, options, currentDirectory, commonSourceDirectory, getCanonicalFileName) { + var outputDir = options.declarationDir || options.outDir; + var path = outputDir + ? getSourceFilePathInNewDirWorker(fileName, outputDir, currentDirectory, commonSourceDirectory, getCanonicalFileName) + : fileName; + return ts.removeFileExtension(path) + ".d.ts"; + } + ts.getDeclarationEmitOutputFilePathWorker = getDeclarationEmitOutputFilePathWorker; function getSourceFilesToEmit(host, targetSourceFile) { var options = host.getCompilerOptions(); var isSourceFileFromExternalLibrary = function (file) { return host.isSourceFileFromExternalLibrary(file); }; @@ -8200,14 +8208,17 @@ var ts; return !(options.noEmitForJsFiles && isSourceFileJavaScript(sourceFile)) && !sourceFile.isDeclarationFile && !isSourceFileFromExternalLibrary(sourceFile); } ts.sourceFileMayBeEmitted = sourceFileMayBeEmitted; - function getSourceFilePathInNewDir(sourceFile, host, newDirPath) { - var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); - var commonSourceDirectory = host.getCommonSourceDirectory(); - var isSourceFileInCommonSourceDirectory = host.getCanonicalFileName(sourceFilePath).indexOf(host.getCanonicalFileName(commonSourceDirectory)) === 0; + function getSourceFilePathInNewDir(fileName, host, newDirPath) { + return getSourceFilePathInNewDirWorker(fileName, newDirPath, host.getCurrentDirectory(), host.getCommonSourceDirectory(), function (f) { return host.getCanonicalFileName(f); }); + } + ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir; + function getSourceFilePathInNewDirWorker(fileName, newDirPath, currentDirectory, commonSourceDirectory, getCanonicalFileName) { + var sourceFilePath = ts.getNormalizedAbsolutePath(fileName, currentDirectory); + var isSourceFileInCommonSourceDirectory = getCanonicalFileName(sourceFilePath).indexOf(getCanonicalFileName(commonSourceDirectory)) === 0; sourceFilePath = isSourceFileInCommonSourceDirectory ? sourceFilePath.substring(commonSourceDirectory.length) : sourceFilePath; return ts.combinePaths(newDirPath, sourceFilePath); } - ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir; + ts.getSourceFilePathInNewDirWorker = getSourceFilePathInNewDirWorker; function writeFile(host, diagnostics, fileName, data, writeByteOrderMark, sourceFiles) { host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) { diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage)); @@ -20891,7 +20902,7 @@ var ts; } } function getDisplayName(node) { - return ts.isNamedDeclaration(node) ? ts.declarationNameToString(node.name) : ts.unescapeLeadingUnderscores(getDeclarationName(node)); + return ts.isNamedDeclaration(node) ? ts.declarationNameToString(node.name) : ts.unescapeLeadingUnderscores(ts.Debug.assertDefined(getDeclarationName(node))); } function declareSymbol(symbolTable, parent, node, includes, excludes, isReplaceableByMethod) { ts.Debug.assert(!ts.hasDynamicName(node)); @@ -20925,24 +20936,29 @@ var ts; var message_1 = symbol.flags & 2 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + var messageNeedsName_1 = true; if (symbol.flags & 384 || includes & 384) { message_1 = ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations; + messageNeedsName_1 = false; } if (symbol.declarations && symbol.declarations.length) { if (isDefaultExport) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName_1 = false; } else { if (symbol.declarations && symbol.declarations.length && (node.kind === 252 && !node.isExportEquals)) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName_1 = false; } } } - ts.forEach(symbol.declarations, function (declaration) { - file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(declaration) || declaration, message_1, getDisplayName(declaration))); - }); - file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(node) || node, message_1, getDisplayName(node))); + var addError = function (decl) { + file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(decl) || decl, message_1, messageNeedsName_1 ? getDisplayName(decl) : undefined)); + }; + ts.forEach(symbol.declarations, addError); + addError(node); symbol = createSymbol(0, name); } } @@ -32233,9 +32249,9 @@ var ts; source = instantiateSignatureInContextOf(source, target, undefined, compareTypes); } var sourceCount = getParameterCount(source); - var sourceRestTypeParameter = getRestTypeParameter(source); - var targetRestTypeParameter = sourceRestTypeParameter ? getRestTypeParameter(target) : undefined; - if (sourceRestTypeParameter && !(targetRestTypeParameter && sourceCount === targetCount)) { + var sourceGenericRestType = getGenericRestType(source); + var targetGenericRestType = sourceGenericRestType ? getGenericRestType(target) : undefined; + if (sourceGenericRestType && !(targetGenericRestType && sourceCount === targetCount)) { return 0; } var kind = target.declaration ? target.declaration.kind : 0; @@ -32260,8 +32276,8 @@ var ts; var paramCount = Math.max(sourceCount, targetCount); var lastIndex = paramCount - 1; for (var i = 0; i < paramCount; i++) { - var sourceType = i === lastIndex && sourceRestTypeParameter || getTypeAtPosition(source, i); - var targetType = i === lastIndex && targetRestTypeParameter || getTypeAtPosition(target, i); + var sourceType = i === lastIndex && sourceGenericRestType || getTypeAtPosition(source, i); + var targetType = i === lastIndex && targetGenericRestType || getTypeAtPosition(target, i); var sourceSig = callbackCheck ? undefined : getSingleCallSignature(getNonNullableType(sourceType)); var targetSig = callbackCheck ? undefined : getSingleCallSignature(getNonNullableType(targetType)); var callbacks = sourceSig && targetSig && !signatureHasTypePredicate(sourceSig) && !signatureHasTypePredicate(targetSig) && @@ -32795,7 +32811,8 @@ var ts; } if (reportErrors) { var bestMatchingType = findMatchingDiscriminantType(source, target) || - findMatchingTypeReferenceOrTypeAliasReference(source, target); + findMatchingTypeReferenceOrTypeAliasReference(source, target) || + findBestTypeForObjectLiteral(source, target); isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], true); } return 0; @@ -32817,6 +32834,11 @@ var ts; }); } } + function findBestTypeForObjectLiteral(source, unionTarget) { + if (ts.getObjectFlags(source) & 128 && forEachType(unionTarget, isArrayLikeType)) { + return ts.find(unionTarget.types, function (t) { return !isArrayLikeType(t); }); + } + } function findMatchingDiscriminantType(source, target) { var match; var sourceProperties = getPropertiesOfObjectType(source); @@ -34114,13 +34136,13 @@ var ts; sourceHasRest ? targetCount : targetHasRest ? sourceCount : Math.min(sourceCount, targetCount); - var targetRestTypeVariable = getRestTypeParameter(target); - var paramCount = targetRestTypeVariable ? Math.min(targetCount - 1, maxCount) : maxCount; + var targetGenericRestType = getGenericRestType(target); + var paramCount = targetGenericRestType ? Math.min(targetCount - 1, maxCount) : maxCount; for (var i = 0; i < paramCount; i++) { callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i)); } - if (targetRestTypeVariable) { - callback(getRestTypeAtPosition(source, paramCount), targetRestTypeVariable); + if (targetGenericRestType) { + callback(getRestTypeAtPosition(source, paramCount), targetGenericRestType); } } function createInferenceContext(typeParameters, signature, flags, compareTypes, baseInferences) { @@ -38349,8 +38371,8 @@ var ts; inferTypes(context.inferences, thisArgumentType, thisType); } var effectiveArgCount = getEffectiveArgumentCount(node, args, signature); - var restTypeParameter = getRestTypeParameter(signature); - var argCount = restTypeParameter ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; + var genericRestType = getGenericRestType(signature); + var argCount = genericRestType ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); if (arg === undefined || arg.kind !== 208) { @@ -38363,9 +38385,9 @@ var ts; inferTypes(context.inferences, argType, paramType); } } - if (restTypeParameter) { - var spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, restTypeParameter, context); - inferTypes(context.inferences, spreadType, restTypeParameter); + if (genericRestType) { + var spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, genericRestType, context); + inferTypes(context.inferences, spreadType, genericRestType); } if (excludeArgument) { for (var i = 0; i < argCount; i++) { @@ -38835,7 +38857,7 @@ var ts; } var isJavascript = ts.isInJavaScriptFile(candidate.declaration); candidate = getSignatureInstantiation(candidate, typeArgumentTypes, isJavascript); - if (getRestTypeParameter(originalCandidate) && !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { + if (getGenericRestType(originalCandidate) && !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { candidateForArgumentArityError = candidate; break; } @@ -39532,9 +39554,9 @@ var ts; var paramCount = getParameterCount(source); var hasRest = hasEffectiveRestParameter(source); if (hasRest && pos === paramCount - 1) { - var restTypeVariable = getRestTypeParameter(source); - if (restTypeVariable) { - return restTypeVariable; + var genericRestType = getGenericRestType(source); + if (genericRestType) { + return genericRestType; } } var start = hasRest ? Math.min(pos, paramCount - 1) : pos; @@ -39580,10 +39602,10 @@ var ts; } return signature.minArgumentCount; } - function getRestTypeParameter(signature) { + function getGenericRestType(signature) { if (signature.hasRestParameter) { var restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]); - if (restType.flags & 65536) { + if (restType.flags & 15794176) { return restType; } } @@ -51583,7 +51605,7 @@ var ts; function decode(host, mapPath, map, program, fallbackCache) { if (fallbackCache === void 0) { fallbackCache = ts.createSourceFileLikeCache(host); } var currentDirectory = ts.getDirectoryPath(mapPath); - var sourceRoot = map.sourceRoot || currentDirectory; + var sourceRoot = map.sourceRoot ? ts.getNormalizedAbsolutePath(map.sourceRoot, currentDirectory) : currentDirectory; var decodedMappings; var generatedOrderedMappings; var sourceOrderedMappings; @@ -51615,9 +51637,9 @@ var ts; return { fileName: ts.toPath(maps[targetIndex].sourcePath, sourceRoot, host.getCanonicalFileName), position: maps[targetIndex].sourcePosition }; } function getSourceFileLike(fileName, location) { - var file = program && program.getSourceFile(fileName); + var path = ts.toPath(fileName, location, host.getCanonicalFileName); + var file = program && program.getSourceFile(path); if (!file) { - var path = ts.toPath(fileName, location, host.getCanonicalFileName); return fallbackCache.get(path); } return file; @@ -62671,7 +62693,7 @@ var ts; if (compilerOptions.mapRoot) { sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot); if (sourceFileOrBundle.kind === 277) { - sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(sourceFileOrBundle, host, sourceMapDir)); + sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(sourceFileOrBundle.fileName, host, sourceMapDir)); } if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { sourceMapDir = ts.combinePaths(host.getCommonSourceDirectory(), sourceMapDir); @@ -63328,10 +63350,10 @@ var ts; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath }; } else { - var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options)); + var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); var sourceMapFilePath = ts.isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); var isJs = ts.isSourceFileJavaScript(sourceFile); - var declarationFilePath = ((forceDtsPaths || ts.getEmitDeclarations(options)) && !isJs) ? ts.getDeclarationEmitOutputFilePath(sourceFile, host) : undefined; + var declarationFilePath = ((forceDtsPaths || ts.getEmitDeclarations(options)) && !isJs) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; var declarationMapPath = ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: undefined }; } @@ -68048,8 +68070,16 @@ var ts; function findSourceFile(fileName, path, isDefaultLib, ignoreNoDefaultLib, refFile, refPos, refEnd, packageId) { if (filesByName.has(path)) { var file_1 = filesByName.get(path); - if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { - reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); + if (file_1 && options.forceConsistentCasingInFileNames) { + var inputName = fileName; + var checkedName = file_1.fileName; + var isRedirect = toPath(checkedName) !== toPath(inputName); + if (isRedirect) { + inputName = getProjectReferenceRedirect(fileName) || fileName; + } + if (ts.getNormalizedAbsolutePath(checkedName, currentDirectory) !== ts.getNormalizedAbsolutePath(inputName, currentDirectory)) { + reportFileNamesDifferOnlyInCasingError(inputName, checkedName, refFile, refPos, refEnd); + } } if (file_1 && sourceFilesFoundSearchingNodeModules.get(file_1.path) && currentNodeModulesDepth === 0) { sourceFilesFoundSearchingNodeModules.set(file_1.path, false); @@ -69915,7 +69945,12 @@ var ts; return res && res.resolvedFileName === importedFileName ? res.originalPath : undefined; }); }); - return symlinks.length === 0 ? getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, host.getCurrentDirectory ? host.getCurrentDirectory() : ""), getCanonicalFileName, host) : symlinks; + var cwd = host.getCurrentDirectory ? host.getCurrentDirectory() : ""; + var baseOptions = getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host); + if (symlinks.length === 0) { + return baseOptions; + } + return ts.deduplicate(ts.concatenate(baseOptions, ts.flatMap(symlinks, function (importedFileName) { return getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host); }))); } function getRelativePathNParents(relativePath) { var components = ts.getPathComponents(relativePath); diff --git a/lib/tsserver.js b/lib/tsserver.js index 6ae31807397..f038fe37f5d 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -10509,27 +10509,37 @@ var ts; return referencePath ? ts.ensurePathIsNonModuleName(extensionless) : extensionless; } ts.getExternalModuleNameFromPath = getExternalModuleNameFromPath; - function getOwnEmitOutputFilePath(sourceFile, host, extension) { + function getOwnEmitOutputFilePath(fileName, host, extension) { var compilerOptions = host.getCompilerOptions(); var emitOutputFilePathWithoutExtension; if (compilerOptions.outDir) { - emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); + emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(fileName, host, compilerOptions.outDir)); } else { - emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName); + emitOutputFilePathWithoutExtension = ts.removeFileExtension(fileName); } return emitOutputFilePathWithoutExtension + extension; } ts.getOwnEmitOutputFilePath = getOwnEmitOutputFilePath; - function getDeclarationEmitOutputFilePath(sourceFile, host) { + function getDeclarationEmitOutputFilePath(fileName, host) { + // TODO: GH#25810 following should work but makes the build break: + // return getDeclarationEmitOutputFilePathWorker(fileName, host.getCompilerOptions(), host.getCurrentDirectory(), host.getCommonSourceDirectory(), f => host.getCanonicalFileName(f)); var options = host.getCompilerOptions(); var outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified var path = outputDir - ? getSourceFilePathInNewDir(sourceFile, host, outputDir) - : sourceFile.fileName; + ? getSourceFilePathInNewDir(fileName, host, outputDir) + : fileName; return ts.removeFileExtension(path) + ".d.ts" /* Dts */; } ts.getDeclarationEmitOutputFilePath = getDeclarationEmitOutputFilePath; + function getDeclarationEmitOutputFilePathWorker(fileName, options, currentDirectory, commonSourceDirectory, getCanonicalFileName) { + var outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified + var path = outputDir + ? getSourceFilePathInNewDirWorker(fileName, outputDir, currentDirectory, commonSourceDirectory, getCanonicalFileName) + : fileName; + return ts.removeFileExtension(path) + ".d.ts" /* Dts */; + } + ts.getDeclarationEmitOutputFilePathWorker = getDeclarationEmitOutputFilePathWorker; /** * Gets the source files that are expected to have an emit output. * @@ -10561,14 +10571,17 @@ var ts; return !(options.noEmitForJsFiles && isSourceFileJavaScript(sourceFile)) && !sourceFile.isDeclarationFile && !isSourceFileFromExternalLibrary(sourceFile); } ts.sourceFileMayBeEmitted = sourceFileMayBeEmitted; - function getSourceFilePathInNewDir(sourceFile, host, newDirPath) { - var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); - var commonSourceDirectory = host.getCommonSourceDirectory(); - var isSourceFileInCommonSourceDirectory = host.getCanonicalFileName(sourceFilePath).indexOf(host.getCanonicalFileName(commonSourceDirectory)) === 0; + function getSourceFilePathInNewDir(fileName, host, newDirPath) { + return getSourceFilePathInNewDirWorker(fileName, newDirPath, host.getCurrentDirectory(), host.getCommonSourceDirectory(), function (f) { return host.getCanonicalFileName(f); }); + } + ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir; + function getSourceFilePathInNewDirWorker(fileName, newDirPath, currentDirectory, commonSourceDirectory, getCanonicalFileName) { + var sourceFilePath = ts.getNormalizedAbsolutePath(fileName, currentDirectory); + var isSourceFileInCommonSourceDirectory = getCanonicalFileName(sourceFilePath).indexOf(getCanonicalFileName(commonSourceDirectory)) === 0; sourceFilePath = isSourceFileInCommonSourceDirectory ? sourceFilePath.substring(commonSourceDirectory.length) : sourceFilePath; return ts.combinePaths(newDirPath, sourceFilePath); } - ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir; + ts.getSourceFilePathInNewDirWorker = getSourceFilePathInNewDirWorker; function writeFile(host, diagnostics, fileName, data, writeByteOrderMark, sourceFiles) { host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) { diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage)); @@ -25798,7 +25811,7 @@ var ts; } } function getDisplayName(node) { - return ts.isNamedDeclaration(node) ? ts.declarationNameToString(node.name) : ts.unescapeLeadingUnderscores(getDeclarationName(node)); // TODO: GH#18217 + return ts.isNamedDeclaration(node) ? ts.declarationNameToString(node.name) : ts.unescapeLeadingUnderscores(ts.Debug.assertDefined(getDeclarationName(node))); } /** * Declares a Symbol for the node and adds it to symbols. Reports errors for conflicting identifier names. @@ -25869,8 +25882,10 @@ var ts; var message_1 = symbol.flags & 2 /* BlockScopedVariable */ ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + var messageNeedsName_1 = true; if (symbol.flags & 384 /* Enum */ || includes & 384 /* Enum */) { message_1 = ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations; + messageNeedsName_1 = false; } if (symbol.declarations && symbol.declarations.length) { // If the current node is a default export of some sort, then check if @@ -25878,6 +25893,7 @@ var ts; // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. if (isDefaultExport) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName_1 = false; } else { // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration. @@ -25887,13 +25903,15 @@ var ts; if (symbol.declarations && symbol.declarations.length && (node.kind === 252 /* ExportAssignment */ && !node.isExportEquals)) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName_1 = false; } } } - ts.forEach(symbol.declarations, function (declaration) { - file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(declaration) || declaration, message_1, getDisplayName(declaration))); - }); - file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(node) || node, message_1, getDisplayName(node))); + var addError = function (decl) { + file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(decl) || decl, message_1, messageNeedsName_1 ? getDisplayName(decl) : undefined)); + }; + ts.forEach(symbol.declarations, addError); + addError(node); symbol = createSymbol(0 /* None */, name); } } @@ -38865,9 +38883,9 @@ var ts; source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes); } var sourceCount = getParameterCount(source); - var sourceRestTypeParameter = getRestTypeParameter(source); - var targetRestTypeParameter = sourceRestTypeParameter ? getRestTypeParameter(target) : undefined; - if (sourceRestTypeParameter && !(targetRestTypeParameter && sourceCount === targetCount)) { + var sourceGenericRestType = getGenericRestType(source); + var targetGenericRestType = sourceGenericRestType ? getGenericRestType(target) : undefined; + if (sourceGenericRestType && !(targetGenericRestType && sourceCount === targetCount)) { return 0 /* False */; } var kind = target.declaration ? target.declaration.kind : 0 /* Unknown */; @@ -38893,8 +38911,8 @@ var ts; var paramCount = Math.max(sourceCount, targetCount); var lastIndex = paramCount - 1; for (var i = 0; i < paramCount; i++) { - var sourceType = i === lastIndex && sourceRestTypeParameter || getTypeAtPosition(source, i); - var targetType = i === lastIndex && targetRestTypeParameter || getTypeAtPosition(target, i); + var sourceType = i === lastIndex && sourceGenericRestType || getTypeAtPosition(source, i); + var targetType = i === lastIndex && targetGenericRestType || getTypeAtPosition(target, i); // In order to ensure that any generic type Foo is at least co-variant with respect to T no matter // how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions, // they naturally relate only contra-variantly). However, if the source and target parameters both have @@ -39512,7 +39530,8 @@ var ts; } if (reportErrors) { var bestMatchingType = findMatchingDiscriminantType(source, target) || - findMatchingTypeReferenceOrTypeAliasReference(source, target); + findMatchingTypeReferenceOrTypeAliasReference(source, target) || + findBestTypeForObjectLiteral(source, target); isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true); } return 0 /* False */; @@ -39534,6 +39553,11 @@ var ts; }); } } + function findBestTypeForObjectLiteral(source, unionTarget) { + if (ts.getObjectFlags(source) & 128 /* ObjectLiteral */ && forEachType(unionTarget, isArrayLikeType)) { + return ts.find(unionTarget.types, function (t) { return !isArrayLikeType(t); }); + } + } // Keep this up-to-date with the same logic within `getApparentTypeOfContextualType`, since they should behave similarly function findMatchingDiscriminantType(source, target) { var match; @@ -41038,13 +41062,13 @@ var ts; sourceHasRest ? targetCount : targetHasRest ? sourceCount : Math.min(sourceCount, targetCount); - var targetRestTypeVariable = getRestTypeParameter(target); - var paramCount = targetRestTypeVariable ? Math.min(targetCount - 1, maxCount) : maxCount; + var targetGenericRestType = getGenericRestType(target); + var paramCount = targetGenericRestType ? Math.min(targetCount - 1, maxCount) : maxCount; for (var i = 0; i < paramCount; i++) { callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i)); } - if (targetRestTypeVariable) { - callback(getRestTypeAtPosition(source, paramCount), targetRestTypeVariable); + if (targetGenericRestType) { + callback(getRestTypeAtPosition(source, paramCount), targetGenericRestType); } } function createInferenceContext(typeParameters, signature, flags, compareTypes, baseInferences) { @@ -46145,8 +46169,8 @@ var ts; // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. var effectiveArgCount = getEffectiveArgumentCount(node, args, signature); - var restTypeParameter = getRestTypeParameter(signature); - var argCount = restTypeParameter ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; + var genericRestType = getGenericRestType(signature); + var argCount = genericRestType ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. @@ -46164,9 +46188,9 @@ var ts; inferTypes(context.inferences, argType, paramType); } } - if (restTypeParameter) { - var spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, restTypeParameter, context); - inferTypes(context.inferences, spreadType, restTypeParameter); + if (genericRestType) { + var spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, genericRestType, context); + inferTypes(context.inferences, spreadType, genericRestType); } // In the second pass we visit only context sensitive arguments, and only those that aren't excluded, this // time treating function expressions normally (which may cause previously inferred type arguments to be fixed @@ -46848,9 +46872,9 @@ var ts; } var isJavascript = ts.isInJavaScriptFile(candidate.declaration); candidate = getSignatureInstantiation(candidate, typeArgumentTypes, isJavascript); - // If the original signature has a rest type parameter, instantiation may produce a + // If the original signature has a generic rest type, instantiation may produce a // signature with different arity and we need to perform another arity check. - if (getRestTypeParameter(originalCandidate) && !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { + if (getGenericRestType(originalCandidate) && !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { candidateForArgumentArityError = candidate; break; } @@ -47674,9 +47698,9 @@ var ts; var paramCount = getParameterCount(source); var hasRest = hasEffectiveRestParameter(source); if (hasRest && pos === paramCount - 1) { - var restTypeVariable = getRestTypeParameter(source); - if (restTypeVariable) { - return restTypeVariable; + var genericRestType = getGenericRestType(source); + if (genericRestType) { + return genericRestType; } } var start = hasRest ? Math.min(pos, paramCount - 1) : pos; @@ -47722,10 +47746,10 @@ var ts; } return signature.minArgumentCount; } - function getRestTypeParameter(signature) { + function getGenericRestType(signature) { if (signature.hasRestParameter) { var restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]); - if (restType.flags & 65536 /* TypeParameter */) { + if (restType.flags & 15794176 /* Instantiable */) { return restType; } } @@ -61529,7 +61553,7 @@ var ts; function decode(host, mapPath, map, program, fallbackCache) { if (fallbackCache === void 0) { fallbackCache = ts.createSourceFileLikeCache(host); } var currentDirectory = ts.getDirectoryPath(mapPath); - var sourceRoot = map.sourceRoot || currentDirectory; + var sourceRoot = map.sourceRoot ? ts.getNormalizedAbsolutePath(map.sourceRoot, currentDirectory) : currentDirectory; var decodedMappings; var generatedOrderedMappings; var sourceOrderedMappings; @@ -61564,10 +61588,10 @@ var ts; } function getSourceFileLike(fileName, location) { // Lookup file in program, if provided - var file = program && program.getSourceFile(fileName); + var path = ts.toPath(fileName, location, host.getCanonicalFileName); + var file = program && program.getSourceFile(path); if (!file) { // Otherwise check the cache (which may hit disk) - var path = ts.toPath(fileName, location, host.getCanonicalFileName); return fallbackCache.get(path); } return file; @@ -77745,7 +77769,7 @@ var ts; if (sourceFileOrBundle.kind === 277 /* SourceFile */) { // emitting single module file // For modules or multiple emit files the mapRoot will have directory structure like the sources // So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map - sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(sourceFileOrBundle, host, sourceMapDir)); + sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(sourceFileOrBundle.fileName, host, sourceMapDir)); } if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { // The relative paths are relative to the common directory @@ -78519,11 +78543,11 @@ var ts; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath }; } else { - var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options)); + var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); var sourceMapFilePath = ts.isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); // For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error var isJs = ts.isSourceFileJavaScript(sourceFile); - var declarationFilePath = ((forceDtsPaths || ts.getEmitDeclarations(options)) && !isJs) ? ts.getDeclarationEmitOutputFilePath(sourceFile, host) : undefined; + var declarationFilePath = ((forceDtsPaths || ts.getEmitDeclarations(options)) && !isJs) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; var declarationMapPath = ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: undefined }; } @@ -83781,9 +83805,17 @@ var ts; if (filesByName.has(path)) { var file_1 = filesByName.get(path); // try to check if we've already seen this file but with a different casing in path - // NOTE: this only makes sense for case-insensitive file systems - if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { - reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); + // NOTE: this only makes sense for case-insensitive file systems, and only on files which are not redirected + if (file_1 && options.forceConsistentCasingInFileNames) { + var inputName = fileName; + var checkedName = file_1.fileName; + var isRedirect = toPath(checkedName) !== toPath(inputName); + if (isRedirect) { + inputName = getProjectReferenceRedirect(fileName) || fileName; + } + if (ts.getNormalizedAbsolutePath(checkedName, currentDirectory) !== ts.getNormalizedAbsolutePath(inputName, currentDirectory)) { + reportFileNamesDifferOnlyInCasingError(inputName, checkedName, refFile, refPos, refEnd); + } } // If the file was previously found via a node_modules search, but is now being processed as a root file, // then everything it sucks in may also be marked incorrectly, and needs to be checked again. @@ -86003,7 +86035,12 @@ var ts; return res && res.resolvedFileName === importedFileName ? res.originalPath : undefined; }); }); - return symlinks.length === 0 ? getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, host.getCurrentDirectory ? host.getCurrentDirectory() : ""), getCanonicalFileName, host) : symlinks; + var cwd = host.getCurrentDirectory ? host.getCurrentDirectory() : ""; + var baseOptions = getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host); + if (symlinks.length === 0) { + return baseOptions; + } + return ts.deduplicate(ts.concatenate(baseOptions, ts.flatMap(symlinks, function (importedFileName) { return getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host); }))); } function getRelativePathNParents(relativePath) { var components = ts.getPathComponents(relativePath); @@ -99226,7 +99263,7 @@ var ts; var base64UrlRegExp = /^data:(?:application\/json(?:;charset=[uU][tT][fF]-8);base64,([A-Za-z0-9+\/=]+)$)?/; function getSourceMapper(getCanonicalFileName, currentDirectory, log, host, getProgram) { var sourcemappedFileCache; - return { tryGetOriginalLocation: tryGetOriginalLocation, toLineColumnOffset: toLineColumnOffset, clearCache: clearCache }; + return { tryGetOriginalLocation: tryGetOriginalLocation, tryGetGeneratedLocation: tryGetGeneratedLocation, toLineColumnOffset: toLineColumnOffset, clearCache: clearCache }; function scanForSourcemapURL(fileName) { var mappedFile = sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); if (!mappedFile) { @@ -99300,12 +99337,26 @@ var ts; function tryGetOriginalLocation(info) { if (!ts.isDeclarationFileName(info.fileName)) return undefined; - var file = getProgram().getSourceFile(info.fileName) || sourcemappedFileCache.get(ts.toPath(info.fileName, currentDirectory, getCanonicalFileName)); + var file = getFile(info.fileName); if (!file) return undefined; var newLoc = getSourceMapper(info.fileName, file).getOriginalPosition(info); return newLoc === info ? undefined : tryGetOriginalLocation(newLoc) || newLoc; } + function tryGetGeneratedLocation(info) { + var program = getProgram(); + var declarationPath = ts.getDeclarationEmitOutputFilePathWorker(info.fileName, program.getCompilerOptions(), currentDirectory, program.getCommonSourceDirectory(), getCanonicalFileName); + if (declarationPath === undefined) + return undefined; + var declarationFile = getFile(declarationPath); + if (!declarationFile) + return undefined; + var newLoc = getSourceMapper(declarationPath, declarationFile).getGeneratedPosition(info); + return newLoc === info ? undefined : newLoc; + } + function getFile(fileName) { + return getProgram().getSourceFile(fileName) || sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); + } function toLineColumnOffset(fileName, position) { var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); var file = getProgram().getSourceFile(path) || sourcemappedFileCache.get(path); // TODO: GH#18217 @@ -101761,7 +101812,6 @@ var ts; function processChildNodes(nodes, parent, parentStartLine, parentDynamicIndentation) { ts.Debug.assert(ts.isNodeArray(nodes)); var listStartToken = getOpenTokenForList(parent, nodes); - var listEndToken = getCloseTokenForOpenToken(listStartToken); var listDynamicIndentation = parentDynamicIndentation; var startLine = parentStartLine; if (listStartToken !== 0 /* Unknown */) { @@ -101790,17 +101840,20 @@ var ts; var child = nodes[i]; inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListItem*/ true, /*isFirstListItem*/ i === 0); } - if (listEndToken !== 0 /* Unknown */) { - if (formattingScanner.isOnToken()) { - var tokenInfo = formattingScanner.readTokenInfo(parent); - // consume the list end token only if it is still belong to the parent - // there might be the case when current token matches end token but does not considered as one - // function (x: function) <-- - // without this check close paren will be interpreted as list end token for function expression which is wrong - if (tokenInfo.token.kind === listEndToken && ts.rangeContainsRange(parent, tokenInfo.token)) { - // consume list end token - consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent); - } + var listEndToken = getCloseTokenForOpenToken(listStartToken); + if (listEndToken !== 0 /* Unknown */ && formattingScanner.isOnToken()) { + var tokenInfo = formattingScanner.readTokenInfo(parent); + if (tokenInfo.token.kind === 26 /* CommaToken */ && ts.isCallLikeExpression(parent)) { + formattingScanner.advance(); + tokenInfo = formattingScanner.readTokenInfo(parent); + } + // consume the list end token only if it is still belong to the parent + // there might be the case when current token matches end token but does not considered as one + // function (x: function) <-- + // without this check close paren will be interpreted as list end token for function expression which is wrong + if (tokenInfo.token.kind === listEndToken && ts.rangeContainsRange(parent, tokenInfo.token)) { + // consume list end token + consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent); } } } @@ -104820,6 +104873,8 @@ var ts; var errorCodes = [ ts.Diagnostics.Cannot_find_name_0.code, ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code, ts.Diagnostics.Cannot_find_namespace_0.code, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code, ts.Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here.code, @@ -105313,6 +105368,8 @@ var ts; var errorCodes = [ ts.Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code, ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_2.code, ]; codefix.registerCodeFix({ @@ -116222,6 +116279,13 @@ var ts; this.configuredProjects.forEach(cb); this.externalProjects.forEach(cb); }; + ProjectService.prototype.forEachEnabledProject = function (cb) { + this.forEachProject(function (project) { + if (!project.isOrphan() && project.languageServiceEnabled) { + cb(project); + } + }); + }; ProjectService.prototype.getDefaultProjectForFile = function (fileName, ensureProject) { return ensureProject ? this.ensureDefaultProjectForFile(fileName) : this.tryGetDefaultProjectForFile(fileName); }; @@ -117751,17 +117815,15 @@ var ts; } function combineProjectOutputFromEveryProject(projectService, action, areEqual) { var outputs = []; - projectService.forEachProject(function (project) { - if (project.isOrphan() || !project.languageServiceEnabled) - return; + projectService.forEachEnabledProject(function (project) { var theseOutputs = action(project); outputs.push.apply(outputs, theseOutputs.filter(function (output) { return !outputs.some(function (o) { return areEqual(o, output); }); })); }); return outputs; } - function combineProjectOutputWhileOpeningReferencedProjects(projects, projectService, action, getLocation, resultsEqual) { + function combineProjectOutputWhileOpeningReferencedProjects(projects, defaultProject, projectService, action, getLocation, resultsEqual) { var outputs = []; - combineProjectOutputWorker(projects, undefined, projectService, function (_a, tryAddToTodo) { + combineProjectOutputWorker(projects, defaultProject, undefined, projectService, function (_a, tryAddToTodo) { var project = _a.project; for (var _i = 0, _b = action(project); _i < _b.length; _i++) { var output = _b[_i]; @@ -117769,12 +117831,12 @@ var ts; outputs.push(output); } } - }); + }, undefined); return outputs; } - function combineProjectOutputForRenameLocations(projects, initialLocation, projectService, findInStrings, findInComments) { + function combineProjectOutputForRenameLocations(projects, defaultProject, initialLocation, projectService, findInStrings, findInComments) { var outputs = []; - combineProjectOutputWorker(projects, initialLocation, projectService, function (_a, tryAddToTodo) { + combineProjectOutputWorker(projects, defaultProject, initialLocation, projectService, function (_a, tryAddToTodo) { var project = _a.project, location = _a.location; for (var _i = 0, _b = project.getLanguageService().findRenameLocations(location.fileName, location.position, findInStrings, findInComments) || server.emptyArray; _i < _b.length; _i++) { var output = _b[_i]; @@ -117782,12 +117844,17 @@ var ts; outputs.push(output); } } - }); + }, function () { return getDefinitionLocation(defaultProject, initialLocation); }); return outputs; } - function combineProjectOutputForReferences(projects, initialLocation, projectService) { + function getDefinitionLocation(defaultProject, initialLocation) { + var infos = defaultProject.getLanguageService().getDefinitionAtPosition(initialLocation.fileName, initialLocation.position); + var info = infos && ts.firstOrUndefined(infos); + return info && { fileName: info.fileName, position: info.textSpan.start }; + } + function combineProjectOutputForReferences(projects, defaultProject, initialLocation, projectService) { var outputs = []; - combineProjectOutputWorker(projects, initialLocation, projectService, function (_a, tryAddToTodo) { + combineProjectOutputWorker(projects, defaultProject, initialLocation, projectService, function (_a, tryAddToTodo) { var project = _a.project, location = _a.location; var _loop_8 = function (outputReferencedSymbol) { var symbolToAddTo = ts.find(outputs, function (o) { return ts.documentSpansEqual(o.definition, outputReferencedSymbol.definition); }); @@ -117806,31 +117873,56 @@ var ts; var outputReferencedSymbol = _b[_i]; _loop_8(outputReferencedSymbol); } - }); + }, function () { return getDefinitionLocation(defaultProject, initialLocation); }); return outputs.filter(function (o) { return o.references.length !== 0; }); } - function combineProjectOutputWorker(projects, initialLocation, projectService, cb) { - var toDoAndSeenProjects; + function forEachProjectInProjects(projects, path, cb) { for (var _i = 0, _a = isProjectsArray(projects) ? projects : projects.projects; _i < _a.length; _i++) { var project = _a[_i]; - toDoAndSeenProjects = callbackProjectAndLocation(projects, { project: project, location: initialLocation }, projectService, toDoAndSeenProjects, cb); + cb(project, path); } if (!ts.isArray(projects) && projects.symLinkedProjects) { - projects.symLinkedProjects.forEach(function (symlinkedProjects, path) { + projects.symLinkedProjects.forEach(function (symlinkedProjects, symlinkedPath) { for (var _i = 0, symlinkedProjects_1 = symlinkedProjects; _i < symlinkedProjects_1.length; _i++) { var project = symlinkedProjects_1[_i]; - toDoAndSeenProjects = callbackProjectAndLocation(projects, { project: project, location: { fileName: path, position: initialLocation.position } }, projectService, toDoAndSeenProjects, cb); + cb(project, symlinkedPath); } }); } - while (toDoAndSeenProjects && toDoAndSeenProjects.toDo.length) { - toDoAndSeenProjects = callbackProjectAndLocation(projects, ts.Debug.assertDefined(toDoAndSeenProjects.toDo.pop()), projectService, toDoAndSeenProjects, cb); + } + function combineProjectOutputWorker(projects, defaultProject, initialLocation, projectService, cb, getDefinition) { + var toDo; + var seenProjects = ts.createMap(); + forEachProjectInProjects(projects, initialLocation && initialLocation.fileName, function (project, path) { + var location = (initialLocation ? { fileName: path, position: initialLocation.position } : undefined); + toDo = callbackProjectAndLocation({ project: project, location: location }, projectService, toDo, seenProjects, cb); + }); + if (getDefinition) { + var memGetDefinition_1 = ts.memoize(getDefinition); + projectService.forEachEnabledProject(function (project) { + if (!ts.addToSeen(seenProjects, project.projectName)) + return; + var definition = getDefinitionInProject(memGetDefinition_1(), defaultProject, project); + if (definition) { + toDo = callbackProjectAndLocation({ project: project, location: definition }, projectService, toDo, seenProjects, cb); + } + }); + } + while (toDo && toDo.length) { + toDo = callbackProjectAndLocation(ts.Debug.assertDefined(toDo.pop()), projectService, toDo, seenProjects, cb); } } - function callbackProjectAndLocation(originalProjects, projectAndLocation, projectService, toDoAndSeenProjects, cb) { + function getDefinitionInProject(definition, definingProject, project) { + if (!definition || project.containsFile(server.toNormalizedPath(definition.fileName))) + return definition; + var mappedDefinition = definingProject.getLanguageService().getSourceMapper().tryGetGeneratedLocation(definition); + return mappedDefinition && project.containsFile(server.toNormalizedPath(mappedDefinition.fileName)) ? mappedDefinition : undefined; + } + function callbackProjectAndLocation(projectAndLocation, projectService, toDo, seenProjects, cb) { if (projectAndLocation.project.getCancellationToken().isCancellationRequested()) return undefined; cb(projectAndLocation, function (project, location) { + seenProjects.set(projectAndLocation.project.projectName, true); var originalLocation = project.getSourceMapper().tryGetOriginalLocation(location); if (!originalLocation) return false; @@ -117838,41 +117930,26 @@ var ts; if (!originalProjectAndScriptInfo) return false; if (originalProjectAndScriptInfo) { - if (toDoAndSeenProjects === undefined) { - toDoAndSeenProjects = { toDo: [], seenProjects: ts.createMap() }; - for (var _i = 0, _a = isProjectsArray(originalProjects) ? originalProjects : originalProjects.projects; _i < _a.length; _i++) { - var project_1 = _a[_i]; - toDoAndSeenProjects.seenProjects.set(project_1.projectName, true); - } - if (!ts.isArray(originalProjects) && originalProjects.symLinkedProjects) { - originalProjects.symLinkedProjects.forEach(function (symlinkedProjects) { - for (var _i = 0, symlinkedProjects_2 = symlinkedProjects; _i < symlinkedProjects_2.length; _i++) { - var project_2 = symlinkedProjects_2[_i]; - toDoAndSeenProjects.seenProjects.set(project_2.projectName, true); - } - }); - } - } - for (var _b = 0, _c = originalProjectAndScriptInfo.projects; _b < _c.length; _b++) { - var project_3 = _c[_b]; - addToTodo({ project: project_3, location: originalLocation }, toDoAndSeenProjects); + toDo = toDo || []; + for (var _i = 0, _a = originalProjectAndScriptInfo.projects; _i < _a.length; _i++) { + var project_1 = _a[_i]; + addToTodo({ project: project_1, location: originalLocation }, toDo, seenProjects); } var symlinkedProjectsMap = projectService.getSymlinkedProjects(originalProjectAndScriptInfo.scriptInfo); if (symlinkedProjectsMap) { symlinkedProjectsMap.forEach(function (symlinkedProjects) { - for (var _i = 0, symlinkedProjects_3 = symlinkedProjects; _i < symlinkedProjects_3.length; _i++) { - var symlinkedProject = symlinkedProjects_3[_i]; - addToTodo({ project: symlinkedProject, location: originalLocation }, toDoAndSeenProjects); + for (var _i = 0, symlinkedProjects_2 = symlinkedProjects; _i < symlinkedProjects_2.length; _i++) { + var symlinkedProject = symlinkedProjects_2[_i]; + addToTodo({ project: symlinkedProject, location: originalLocation }, toDo, seenProjects); } }); } } return true; }); - return toDoAndSeenProjects; + return toDo; } - function addToTodo(projectAndLocation, _a) { - var seenProjects = _a.seenProjects, toDo = _a.toDo; + function addToTodo(projectAndLocation, toDo, seenProjects) { if (ts.addToSeen(seenProjects, projectAndLocation.project.projectName)) toDo.push(projectAndLocation); } @@ -118714,7 +118791,7 @@ var ts; var file = server.toNormalizedPath(args.file); var position = this.getPositionInFile(args, file); var projects = this.getProjects(args); - var locations = combineProjectOutputForRenameLocations(projects, { fileName: args.file, position: position }, this.projectService, !!args.findInStrings, !!args.findInComments); + var locations = combineProjectOutputForRenameLocations(projects, this.getDefaultProject(args), { fileName: args.file, position: position }, this.projectService, !!args.findInStrings, !!args.findInComments); if (!simplifiedResult) return locations; var defaultProject = this.getDefaultProject(args); @@ -118741,7 +118818,7 @@ var ts; var file = server.toNormalizedPath(args.file); var projects = this.getProjects(args); var position = this.getPositionInFile(args, file); - var references = combineProjectOutputForReferences(projects, { fileName: args.file, position: position }, this.projectService); + var references = combineProjectOutputForReferences(projects, this.getDefaultProject(args), { fileName: args.file, position: position }, this.projectService); if (simplifiedResult) { var defaultProject = this.getDefaultProject(args); var scriptInfo = defaultProject.getScriptInfoForNormalizedPath(file); @@ -118979,7 +119056,7 @@ var ts; return project.getLanguageService().getCompletionEntryDetails(file, position, name, formattingOptions, source, _this.getPreferences(file)); }); return simplifiedResult - ? result.map(function (details) { return (__assign({}, details, { codeActions: ts.map(details.codeActions, function (action) { return _this.mapCodeAction(project, action); }) })); }) + ? result.map(function (details) { return (__assign({}, details, { codeActions: ts.map(details.codeActions, function (action) { return _this.mapCodeAction(action); }) })); }) : result; }; Session.prototype.getCompileOnSaveAffectedFileList = function (args) { @@ -119173,7 +119250,7 @@ var ts; return project.getLanguageService().getNavigateToItems(searchValue, maxResultCount, file); } else { - return combineProjectOutputWhileOpeningReferencedProjects(this.getProjects(args), this.projectService, function (project) { + return combineProjectOutputWhileOpeningReferencedProjects(this.getProjects(args), this.getDefaultProject(args), this.projectService, function (project) { return project.getLanguageService().getNavigateToItems(searchValue, maxResultCount, undefined, project.isNonTsProject()); }, documentSpanLocation, navigateToItemIsEqualTo); } @@ -119240,7 +119317,7 @@ var ts; var renameScriptInfo = project.getScriptInfoForNormalizedPath(server.toNormalizedPath(renameFilename)); mappedRenameLocation = getLocationInNewDocument(ts.getSnapshotText(renameScriptInfo.getSnapshot()), renameFilename, renameLocation, edits); } - return { renameLocation: mappedRenameLocation, renameFilename: renameFilename, edits: this.mapTextChangesToCodeEdits(project, edits) }; + return { renameLocation: mappedRenameLocation, renameFilename: renameFilename, edits: this.mapTextChangesToCodeEdits(edits) }; } else { return result; @@ -119252,7 +119329,7 @@ var ts; var _b = this.getFileAndProject(scope.args), file = _b.file, project = _b.project; var changes = project.getLanguageService().organizeImports({ type: "file", fileName: file }, this.getFormatOptions(file), this.getPreferences(file)); if (simplifiedResult) { - return this.mapTextChangesToCodeEdits(project, changes); + return this.mapTextChangesToCodeEdits(changes); } else { return changes; @@ -119265,7 +119342,7 @@ var ts; var formatOptions = this.getHostFormatOptions(); var preferences = this.getHostPreferences(); var changes = combineProjectOutputFromEveryProject(this.projectService, function (project) { return project.getLanguageService().getEditsForFileRename(oldPath, newPath, formatOptions, preferences); }, function (a, b) { return a.fileName === b.fileName; }); - return simplifiedResult ? changes.map(function (c) { return _this.mapTextChangeToCodeEditUsingScriptInfoOrConfigFile(c); }) : changes; + return simplifiedResult ? changes.map(function (c) { return _this.mapTextChangeToCodeEdit(c); }) : changes; }; Session.prototype.getCodeFixes = function (args, simplifiedResult) { var _this = this; @@ -119276,7 +119353,7 @@ var ts; var scriptInfo = project.getScriptInfoForNormalizedPath(file); var _b = this.getStartAndEndPosition(args, scriptInfo), startPosition = _b.startPosition, endPosition = _b.endPosition; var codeActions = project.getLanguageService().getCodeFixesAtPosition(file, startPosition, endPosition, args.errorCodes, this.getFormatOptions(file), this.getPreferences(file)); - return simplifiedResult ? codeActions.map(function (codeAction) { return _this.mapCodeFixAction(project, codeAction); }) : codeActions; + return simplifiedResult ? codeActions.map(function (codeAction) { return _this.mapCodeFixAction(codeAction); }) : codeActions; }; Session.prototype.getCombinedCodeFix = function (_a, simplifiedResult) { var scope = _a.scope, fixId = _a.fixId; @@ -119284,7 +119361,7 @@ var ts; var _b = this.getFileAndProject(scope.args), file = _b.file, project = _b.project; var res = project.getLanguageService().getCombinedCodeFix({ type: "file", fileName: file }, fixId, this.getFormatOptions(file), this.getPreferences(file)); if (simplifiedResult) { - return { changes: this.mapTextChangesToCodeEdits(project, res.changes), commands: res.commands }; + return { changes: this.mapTextChangesToCodeEdits(res.changes), commands: res.commands }; } else { return res; @@ -119317,27 +119394,20 @@ var ts; } return { startPosition: startPosition, endPosition: endPosition }; }; - Session.prototype.mapCodeAction = function (project, _a) { + Session.prototype.mapCodeAction = function (_a) { var description = _a.description, changes = _a.changes, commands = _a.commands; - return { description: description, changes: this.mapTextChangesToCodeEdits(project, changes), commands: commands }; + return { description: description, changes: this.mapTextChangesToCodeEdits(changes), commands: commands }; }; - Session.prototype.mapCodeFixAction = function (project, _a) { + Session.prototype.mapCodeFixAction = function (_a) { var fixName = _a.fixName, description = _a.description, changes = _a.changes, commands = _a.commands, fixId = _a.fixId, fixAllDescription = _a.fixAllDescription; - return { fixName: fixName, description: description, changes: this.mapTextChangesToCodeEdits(project, changes), commands: commands, fixId: fixId, fixAllDescription: fixAllDescription }; + return { fixName: fixName, description: description, changes: this.mapTextChangesToCodeEdits(changes), commands: commands, fixId: fixId, fixAllDescription: fixAllDescription }; }; - Session.prototype.mapTextChangesToCodeEdits = function (project, textChanges) { + Session.prototype.mapTextChangesToCodeEdits = function (textChanges) { var _this = this; - return textChanges.map(function (change) { return _this.mapTextChangeToCodeEdit(project, change); }); + return textChanges.map(function (change) { return _this.mapTextChangeToCodeEdit(change); }); }; - Session.prototype.mapTextChangeToCodeEdit = function (project, change) { - return mapTextChangesToCodeEditsForFile(change, project.getSourceFileOrConfigFile(this.normalizePath(change.fileName))); - }; - Session.prototype.mapTextChangeToCodeEditUsingScriptInfoOrConfigFile = function (change) { - return mapTextChangesToCodeEditsUsingScriptInfoOrConfig(change, this.projectService.getScriptInfoOrConfig(this.normalizePath(change.fileName))); - }; - Session.prototype.normalizePath = function (fileName) { - var _this = this; - return server.normalizedPathToPath(server.toNormalizedPath(fileName), this.host.getCurrentDirectory(), function (fileName) { return _this.getCanonicalFileName(fileName); }); + Session.prototype.mapTextChangeToCodeEdit = function (change) { + return mapTextChangesToCodeEdits(change, this.projectService.getScriptInfoOrConfig(change.fileName)); }; Session.prototype.convertTextChangeToCodeEdit = function (change, scriptInfo) { return { @@ -119503,32 +119573,13 @@ var ts; function toFileSpan(fileName, textSpan, scriptInfo) { return { file: fileName, start: scriptInfo.positionToLineOffset(textSpan.start), end: scriptInfo.positionToLineOffset(ts.textSpanEnd(textSpan)) }; } - function mapTextChangesToCodeEditsForFile(textChanges, sourceFile) { - ts.Debug.assert(!!textChanges.isNewFile === !sourceFile, "Expected isNewFile for (only) new files", function () { return JSON.stringify({ isNewFile: !!textChanges.isNewFile, hasSourceFile: !!sourceFile }); }); - if (sourceFile) { - return { - fileName: textChanges.fileName, - textChanges: textChanges.textChanges.map(function (textChange) { return convertTextChangeToCodeEdit(textChange, sourceFile); }), - }; - } - else { - return convertNewFileTextChangeToCodeEdit(textChanges); - } - } - function mapTextChangesToCodeEditsUsingScriptInfoOrConfig(textChanges, scriptInfo) { + function mapTextChangesToCodeEdits(textChanges, scriptInfo) { ts.Debug.assert(!!textChanges.isNewFile === !scriptInfo, "Expected isNewFile for (only) new files", function () { return JSON.stringify({ isNewFile: !!textChanges.isNewFile, hasScriptInfo: !!scriptInfo }); }); return scriptInfo - ? { fileName: textChanges.fileName, textChanges: textChanges.textChanges.map(function (textChange) { return convertTextChangeToCodeEditUsingScriptInfoOrConfig(textChange, scriptInfo); }) } + ? { fileName: textChanges.fileName, textChanges: textChanges.textChanges.map(function (textChange) { return convertTextChangeToCodeEdit(textChange, scriptInfo); }) } : convertNewFileTextChangeToCodeEdit(textChanges); } - function convertTextChangeToCodeEdit(change, sourceFile) { - return { - start: convertToLocation(sourceFile.getLineAndCharacterOfPosition(change.span.start)), - end: convertToLocation(sourceFile.getLineAndCharacterOfPosition(change.span.start + change.span.length)), - newText: change.newText ? change.newText : "", - }; - } - function convertTextChangeToCodeEditUsingScriptInfoOrConfig(change, scriptInfo) { + function convertTextChangeToCodeEdit(change, scriptInfo) { return { start: positionToLineOffset(scriptInfo, change.span.start), end: positionToLineOffset(scriptInfo, ts.textSpanEnd(change.span)), newText: change.newText }; } function positionToLineOffset(info, position) { diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index 57deee2ab98..4b9c0307810 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -8893,8 +8893,6 @@ declare namespace ts.server { private mapCodeFixAction; private mapTextChangesToCodeEdits; private mapTextChangeToCodeEdit; - private mapTextChangeToCodeEditUsingScriptInfoOrConfigFile; - private normalizePath; private convertTextChangeToCodeEdit; private getBraceMatching; private getDiagnosticsForProject; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 77de91a63b3..54449c3d14d 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -10496,27 +10496,37 @@ var ts; return referencePath ? ts.ensurePathIsNonModuleName(extensionless) : extensionless; } ts.getExternalModuleNameFromPath = getExternalModuleNameFromPath; - function getOwnEmitOutputFilePath(sourceFile, host, extension) { + function getOwnEmitOutputFilePath(fileName, host, extension) { var compilerOptions = host.getCompilerOptions(); var emitOutputFilePathWithoutExtension; if (compilerOptions.outDir) { - emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); + emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(fileName, host, compilerOptions.outDir)); } else { - emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName); + emitOutputFilePathWithoutExtension = ts.removeFileExtension(fileName); } return emitOutputFilePathWithoutExtension + extension; } ts.getOwnEmitOutputFilePath = getOwnEmitOutputFilePath; - function getDeclarationEmitOutputFilePath(sourceFile, host) { + function getDeclarationEmitOutputFilePath(fileName, host) { + // TODO: GH#25810 following should work but makes the build break: + // return getDeclarationEmitOutputFilePathWorker(fileName, host.getCompilerOptions(), host.getCurrentDirectory(), host.getCommonSourceDirectory(), f => host.getCanonicalFileName(f)); var options = host.getCompilerOptions(); var outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified var path = outputDir - ? getSourceFilePathInNewDir(sourceFile, host, outputDir) - : sourceFile.fileName; + ? getSourceFilePathInNewDir(fileName, host, outputDir) + : fileName; return ts.removeFileExtension(path) + ".d.ts" /* Dts */; } ts.getDeclarationEmitOutputFilePath = getDeclarationEmitOutputFilePath; + function getDeclarationEmitOutputFilePathWorker(fileName, options, currentDirectory, commonSourceDirectory, getCanonicalFileName) { + var outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified + var path = outputDir + ? getSourceFilePathInNewDirWorker(fileName, outputDir, currentDirectory, commonSourceDirectory, getCanonicalFileName) + : fileName; + return ts.removeFileExtension(path) + ".d.ts" /* Dts */; + } + ts.getDeclarationEmitOutputFilePathWorker = getDeclarationEmitOutputFilePathWorker; /** * Gets the source files that are expected to have an emit output. * @@ -10548,14 +10558,17 @@ var ts; return !(options.noEmitForJsFiles && isSourceFileJavaScript(sourceFile)) && !sourceFile.isDeclarationFile && !isSourceFileFromExternalLibrary(sourceFile); } ts.sourceFileMayBeEmitted = sourceFileMayBeEmitted; - function getSourceFilePathInNewDir(sourceFile, host, newDirPath) { - var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); - var commonSourceDirectory = host.getCommonSourceDirectory(); - var isSourceFileInCommonSourceDirectory = host.getCanonicalFileName(sourceFilePath).indexOf(host.getCanonicalFileName(commonSourceDirectory)) === 0; + function getSourceFilePathInNewDir(fileName, host, newDirPath) { + return getSourceFilePathInNewDirWorker(fileName, newDirPath, host.getCurrentDirectory(), host.getCommonSourceDirectory(), function (f) { return host.getCanonicalFileName(f); }); + } + ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir; + function getSourceFilePathInNewDirWorker(fileName, newDirPath, currentDirectory, commonSourceDirectory, getCanonicalFileName) { + var sourceFilePath = ts.getNormalizedAbsolutePath(fileName, currentDirectory); + var isSourceFileInCommonSourceDirectory = getCanonicalFileName(sourceFilePath).indexOf(getCanonicalFileName(commonSourceDirectory)) === 0; sourceFilePath = isSourceFileInCommonSourceDirectory ? sourceFilePath.substring(commonSourceDirectory.length) : sourceFilePath; return ts.combinePaths(newDirPath, sourceFilePath); } - ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir; + ts.getSourceFilePathInNewDirWorker = getSourceFilePathInNewDirWorker; function writeFile(host, diagnostics, fileName, data, writeByteOrderMark, sourceFiles) { host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) { diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage)); @@ -25785,7 +25798,7 @@ var ts; } } function getDisplayName(node) { - return ts.isNamedDeclaration(node) ? ts.declarationNameToString(node.name) : ts.unescapeLeadingUnderscores(getDeclarationName(node)); // TODO: GH#18217 + return ts.isNamedDeclaration(node) ? ts.declarationNameToString(node.name) : ts.unescapeLeadingUnderscores(ts.Debug.assertDefined(getDeclarationName(node))); } /** * Declares a Symbol for the node and adds it to symbols. Reports errors for conflicting identifier names. @@ -25856,8 +25869,10 @@ var ts; var message_1 = symbol.flags & 2 /* BlockScopedVariable */ ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + var messageNeedsName_1 = true; if (symbol.flags & 384 /* Enum */ || includes & 384 /* Enum */) { message_1 = ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations; + messageNeedsName_1 = false; } if (symbol.declarations && symbol.declarations.length) { // If the current node is a default export of some sort, then check if @@ -25865,6 +25880,7 @@ var ts; // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. if (isDefaultExport) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName_1 = false; } else { // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration. @@ -25874,13 +25890,15 @@ var ts; if (symbol.declarations && symbol.declarations.length && (node.kind === 252 /* ExportAssignment */ && !node.isExportEquals)) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName_1 = false; } } } - ts.forEach(symbol.declarations, function (declaration) { - file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(declaration) || declaration, message_1, getDisplayName(declaration))); - }); - file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(node) || node, message_1, getDisplayName(node))); + var addError = function (decl) { + file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(decl) || decl, message_1, messageNeedsName_1 ? getDisplayName(decl) : undefined)); + }; + ts.forEach(symbol.declarations, addError); + addError(node); symbol = createSymbol(0 /* None */, name); } } @@ -38852,9 +38870,9 @@ var ts; source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes); } var sourceCount = getParameterCount(source); - var sourceRestTypeParameter = getRestTypeParameter(source); - var targetRestTypeParameter = sourceRestTypeParameter ? getRestTypeParameter(target) : undefined; - if (sourceRestTypeParameter && !(targetRestTypeParameter && sourceCount === targetCount)) { + var sourceGenericRestType = getGenericRestType(source); + var targetGenericRestType = sourceGenericRestType ? getGenericRestType(target) : undefined; + if (sourceGenericRestType && !(targetGenericRestType && sourceCount === targetCount)) { return 0 /* False */; } var kind = target.declaration ? target.declaration.kind : 0 /* Unknown */; @@ -38880,8 +38898,8 @@ var ts; var paramCount = Math.max(sourceCount, targetCount); var lastIndex = paramCount - 1; for (var i = 0; i < paramCount; i++) { - var sourceType = i === lastIndex && sourceRestTypeParameter || getTypeAtPosition(source, i); - var targetType = i === lastIndex && targetRestTypeParameter || getTypeAtPosition(target, i); + var sourceType = i === lastIndex && sourceGenericRestType || getTypeAtPosition(source, i); + var targetType = i === lastIndex && targetGenericRestType || getTypeAtPosition(target, i); // In order to ensure that any generic type Foo is at least co-variant with respect to T no matter // how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions, // they naturally relate only contra-variantly). However, if the source and target parameters both have @@ -39499,7 +39517,8 @@ var ts; } if (reportErrors) { var bestMatchingType = findMatchingDiscriminantType(source, target) || - findMatchingTypeReferenceOrTypeAliasReference(source, target); + findMatchingTypeReferenceOrTypeAliasReference(source, target) || + findBestTypeForObjectLiteral(source, target); isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true); } return 0 /* False */; @@ -39521,6 +39540,11 @@ var ts; }); } } + function findBestTypeForObjectLiteral(source, unionTarget) { + if (ts.getObjectFlags(source) & 128 /* ObjectLiteral */ && forEachType(unionTarget, isArrayLikeType)) { + return ts.find(unionTarget.types, function (t) { return !isArrayLikeType(t); }); + } + } // Keep this up-to-date with the same logic within `getApparentTypeOfContextualType`, since they should behave similarly function findMatchingDiscriminantType(source, target) { var match; @@ -41025,13 +41049,13 @@ var ts; sourceHasRest ? targetCount : targetHasRest ? sourceCount : Math.min(sourceCount, targetCount); - var targetRestTypeVariable = getRestTypeParameter(target); - var paramCount = targetRestTypeVariable ? Math.min(targetCount - 1, maxCount) : maxCount; + var targetGenericRestType = getGenericRestType(target); + var paramCount = targetGenericRestType ? Math.min(targetCount - 1, maxCount) : maxCount; for (var i = 0; i < paramCount; i++) { callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i)); } - if (targetRestTypeVariable) { - callback(getRestTypeAtPosition(source, paramCount), targetRestTypeVariable); + if (targetGenericRestType) { + callback(getRestTypeAtPosition(source, paramCount), targetGenericRestType); } } function createInferenceContext(typeParameters, signature, flags, compareTypes, baseInferences) { @@ -46132,8 +46156,8 @@ var ts; // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. var effectiveArgCount = getEffectiveArgumentCount(node, args, signature); - var restTypeParameter = getRestTypeParameter(signature); - var argCount = restTypeParameter ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; + var genericRestType = getGenericRestType(signature); + var argCount = genericRestType ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. @@ -46151,9 +46175,9 @@ var ts; inferTypes(context.inferences, argType, paramType); } } - if (restTypeParameter) { - var spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, restTypeParameter, context); - inferTypes(context.inferences, spreadType, restTypeParameter); + if (genericRestType) { + var spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, genericRestType, context); + inferTypes(context.inferences, spreadType, genericRestType); } // In the second pass we visit only context sensitive arguments, and only those that aren't excluded, this // time treating function expressions normally (which may cause previously inferred type arguments to be fixed @@ -46835,9 +46859,9 @@ var ts; } var isJavascript = ts.isInJavaScriptFile(candidate.declaration); candidate = getSignatureInstantiation(candidate, typeArgumentTypes, isJavascript); - // If the original signature has a rest type parameter, instantiation may produce a + // If the original signature has a generic rest type, instantiation may produce a // signature with different arity and we need to perform another arity check. - if (getRestTypeParameter(originalCandidate) && !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { + if (getGenericRestType(originalCandidate) && !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { candidateForArgumentArityError = candidate; break; } @@ -47661,9 +47685,9 @@ var ts; var paramCount = getParameterCount(source); var hasRest = hasEffectiveRestParameter(source); if (hasRest && pos === paramCount - 1) { - var restTypeVariable = getRestTypeParameter(source); - if (restTypeVariable) { - return restTypeVariable; + var genericRestType = getGenericRestType(source); + if (genericRestType) { + return genericRestType; } } var start = hasRest ? Math.min(pos, paramCount - 1) : pos; @@ -47709,10 +47733,10 @@ var ts; } return signature.minArgumentCount; } - function getRestTypeParameter(signature) { + function getGenericRestType(signature) { if (signature.hasRestParameter) { var restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]); - if (restType.flags & 65536 /* TypeParameter */) { + if (restType.flags & 15794176 /* Instantiable */) { return restType; } } @@ -61516,7 +61540,7 @@ var ts; function decode(host, mapPath, map, program, fallbackCache) { if (fallbackCache === void 0) { fallbackCache = ts.createSourceFileLikeCache(host); } var currentDirectory = ts.getDirectoryPath(mapPath); - var sourceRoot = map.sourceRoot || currentDirectory; + var sourceRoot = map.sourceRoot ? ts.getNormalizedAbsolutePath(map.sourceRoot, currentDirectory) : currentDirectory; var decodedMappings; var generatedOrderedMappings; var sourceOrderedMappings; @@ -61551,10 +61575,10 @@ var ts; } function getSourceFileLike(fileName, location) { // Lookup file in program, if provided - var file = program && program.getSourceFile(fileName); + var path = ts.toPath(fileName, location, host.getCanonicalFileName); + var file = program && program.getSourceFile(path); if (!file) { // Otherwise check the cache (which may hit disk) - var path = ts.toPath(fileName, location, host.getCanonicalFileName); return fallbackCache.get(path); } return file; @@ -77732,7 +77756,7 @@ var ts; if (sourceFileOrBundle.kind === 277 /* SourceFile */) { // emitting single module file // For modules or multiple emit files the mapRoot will have directory structure like the sources // So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map - sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(sourceFileOrBundle, host, sourceMapDir)); + sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(sourceFileOrBundle.fileName, host, sourceMapDir)); } if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { // The relative paths are relative to the common directory @@ -78506,11 +78530,11 @@ var ts; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath }; } else { - var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options)); + var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); var sourceMapFilePath = ts.isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); // For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error var isJs = ts.isSourceFileJavaScript(sourceFile); - var declarationFilePath = ((forceDtsPaths || ts.getEmitDeclarations(options)) && !isJs) ? ts.getDeclarationEmitOutputFilePath(sourceFile, host) : undefined; + var declarationFilePath = ((forceDtsPaths || ts.getEmitDeclarations(options)) && !isJs) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; var declarationMapPath = ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: undefined }; } @@ -83768,9 +83792,17 @@ var ts; if (filesByName.has(path)) { var file_1 = filesByName.get(path); // try to check if we've already seen this file but with a different casing in path - // NOTE: this only makes sense for case-insensitive file systems - if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { - reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); + // NOTE: this only makes sense for case-insensitive file systems, and only on files which are not redirected + if (file_1 && options.forceConsistentCasingInFileNames) { + var inputName = fileName; + var checkedName = file_1.fileName; + var isRedirect = toPath(checkedName) !== toPath(inputName); + if (isRedirect) { + inputName = getProjectReferenceRedirect(fileName) || fileName; + } + if (ts.getNormalizedAbsolutePath(checkedName, currentDirectory) !== ts.getNormalizedAbsolutePath(inputName, currentDirectory)) { + reportFileNamesDifferOnlyInCasingError(inputName, checkedName, refFile, refPos, refEnd); + } } // If the file was previously found via a node_modules search, but is now being processed as a root file, // then everything it sucks in may also be marked incorrectly, and needs to be checked again. @@ -85990,7 +86022,12 @@ var ts; return res && res.resolvedFileName === importedFileName ? res.originalPath : undefined; }); }); - return symlinks.length === 0 ? getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, host.getCurrentDirectory ? host.getCurrentDirectory() : ""), getCanonicalFileName, host) : symlinks; + var cwd = host.getCurrentDirectory ? host.getCurrentDirectory() : ""; + var baseOptions = getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host); + if (symlinks.length === 0) { + return baseOptions; + } + return ts.deduplicate(ts.concatenate(baseOptions, ts.flatMap(symlinks, function (importedFileName) { return getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host); }))); } function getRelativePathNParents(relativePath) { var components = ts.getPathComponents(relativePath); @@ -99595,7 +99632,7 @@ var ts; var base64UrlRegExp = /^data:(?:application\/json(?:;charset=[uU][tT][fF]-8);base64,([A-Za-z0-9+\/=]+)$)?/; function getSourceMapper(getCanonicalFileName, currentDirectory, log, host, getProgram) { var sourcemappedFileCache; - return { tryGetOriginalLocation: tryGetOriginalLocation, toLineColumnOffset: toLineColumnOffset, clearCache: clearCache }; + return { tryGetOriginalLocation: tryGetOriginalLocation, tryGetGeneratedLocation: tryGetGeneratedLocation, toLineColumnOffset: toLineColumnOffset, clearCache: clearCache }; function scanForSourcemapURL(fileName) { var mappedFile = sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); if (!mappedFile) { @@ -99669,12 +99706,26 @@ var ts; function tryGetOriginalLocation(info) { if (!ts.isDeclarationFileName(info.fileName)) return undefined; - var file = getProgram().getSourceFile(info.fileName) || sourcemappedFileCache.get(ts.toPath(info.fileName, currentDirectory, getCanonicalFileName)); + var file = getFile(info.fileName); if (!file) return undefined; var newLoc = getSourceMapper(info.fileName, file).getOriginalPosition(info); return newLoc === info ? undefined : tryGetOriginalLocation(newLoc) || newLoc; } + function tryGetGeneratedLocation(info) { + var program = getProgram(); + var declarationPath = ts.getDeclarationEmitOutputFilePathWorker(info.fileName, program.getCompilerOptions(), currentDirectory, program.getCommonSourceDirectory(), getCanonicalFileName); + if (declarationPath === undefined) + return undefined; + var declarationFile = getFile(declarationPath); + if (!declarationFile) + return undefined; + var newLoc = getSourceMapper(declarationPath, declarationFile).getGeneratedPosition(info); + return newLoc === info ? undefined : newLoc; + } + function getFile(fileName) { + return getProgram().getSourceFile(fileName) || sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); + } function toLineColumnOffset(fileName, position) { var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); var file = getProgram().getSourceFile(path) || sourcemappedFileCache.get(path); // TODO: GH#18217 @@ -102130,7 +102181,6 @@ var ts; function processChildNodes(nodes, parent, parentStartLine, parentDynamicIndentation) { ts.Debug.assert(ts.isNodeArray(nodes)); var listStartToken = getOpenTokenForList(parent, nodes); - var listEndToken = getCloseTokenForOpenToken(listStartToken); var listDynamicIndentation = parentDynamicIndentation; var startLine = parentStartLine; if (listStartToken !== 0 /* Unknown */) { @@ -102159,17 +102209,20 @@ var ts; var child = nodes[i]; inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListItem*/ true, /*isFirstListItem*/ i === 0); } - if (listEndToken !== 0 /* Unknown */) { - if (formattingScanner.isOnToken()) { - var tokenInfo = formattingScanner.readTokenInfo(parent); - // consume the list end token only if it is still belong to the parent - // there might be the case when current token matches end token but does not considered as one - // function (x: function) <-- - // without this check close paren will be interpreted as list end token for function expression which is wrong - if (tokenInfo.token.kind === listEndToken && ts.rangeContainsRange(parent, tokenInfo.token)) { - // consume list end token - consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent); - } + var listEndToken = getCloseTokenForOpenToken(listStartToken); + if (listEndToken !== 0 /* Unknown */ && formattingScanner.isOnToken()) { + var tokenInfo = formattingScanner.readTokenInfo(parent); + if (tokenInfo.token.kind === 26 /* CommaToken */ && ts.isCallLikeExpression(parent)) { + formattingScanner.advance(); + tokenInfo = formattingScanner.readTokenInfo(parent); + } + // consume the list end token only if it is still belong to the parent + // there might be the case when current token matches end token but does not considered as one + // function (x: function) <-- + // without this check close paren will be interpreted as list end token for function expression which is wrong + if (tokenInfo.token.kind === listEndToken && ts.rangeContainsRange(parent, tokenInfo.token)) { + // consume list end token + consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent); } } } @@ -105189,6 +105242,8 @@ var ts; var errorCodes = [ ts.Diagnostics.Cannot_find_name_0.code, ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code, ts.Diagnostics.Cannot_find_namespace_0.code, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code, ts.Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here.code, @@ -105682,6 +105737,8 @@ var ts; var errorCodes = [ ts.Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code, ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_2.code, ]; codefix.registerCodeFix({ @@ -116541,6 +116598,14 @@ var ts; this.configuredProjects.forEach(cb); this.externalProjects.forEach(cb); }; + /* @internal */ + ProjectService.prototype.forEachEnabledProject = function (cb) { + this.forEachProject(function (project) { + if (!project.isOrphan() && project.languageServiceEnabled) { + cb(project); + } + }); + }; ProjectService.prototype.getDefaultProjectForFile = function (fileName, ensureProject) { return ensureProject ? this.ensureDefaultProjectForFile(fileName) : this.tryGetDefaultProjectForFile(fileName); }; @@ -118423,17 +118488,16 @@ var ts; } function combineProjectOutputFromEveryProject(projectService, action, areEqual) { var outputs = []; - projectService.forEachProject(function (project) { - if (project.isOrphan() || !project.languageServiceEnabled) - return; + projectService.forEachEnabledProject(function (project) { var theseOutputs = action(project); outputs.push.apply(outputs, theseOutputs.filter(function (output) { return !outputs.some(function (o) { return areEqual(o, output); }); })); }); return outputs; } - function combineProjectOutputWhileOpeningReferencedProjects(projects, projectService, action, getLocation, resultsEqual) { + function combineProjectOutputWhileOpeningReferencedProjects(projects, defaultProject, projectService, action, getLocation, resultsEqual) { var outputs = []; - combineProjectOutputWorker(projects, undefined, projectService, function (_a, tryAddToTodo) { + combineProjectOutputWorker(projects, defaultProject, + /*initialLocation*/ undefined, projectService, function (_a, tryAddToTodo) { var project = _a.project; for (var _i = 0, _b = action(project); _i < _b.length; _i++) { var output = _b[_i]; @@ -118441,12 +118505,13 @@ var ts; outputs.push(output); } } - }); + }, + /*getDefinition*/ undefined); return outputs; } - function combineProjectOutputForRenameLocations(projects, initialLocation, projectService, findInStrings, findInComments) { + function combineProjectOutputForRenameLocations(projects, defaultProject, initialLocation, projectService, findInStrings, findInComments) { var outputs = []; - combineProjectOutputWorker(projects, initialLocation, projectService, function (_a, tryAddToTodo) { + combineProjectOutputWorker(projects, defaultProject, initialLocation, projectService, function (_a, tryAddToTodo) { var project = _a.project, location = _a.location; for (var _i = 0, _b = project.getLanguageService().findRenameLocations(location.fileName, location.position, findInStrings, findInComments) || server.emptyArray; _i < _b.length; _i++) { var output = _b[_i]; @@ -118454,12 +118519,17 @@ var ts; outputs.push(output); } } - }); + }, function () { return getDefinitionLocation(defaultProject, initialLocation); }); return outputs; } - function combineProjectOutputForReferences(projects, initialLocation, projectService) { + function getDefinitionLocation(defaultProject, initialLocation) { + var infos = defaultProject.getLanguageService().getDefinitionAtPosition(initialLocation.fileName, initialLocation.position); + var info = infos && ts.firstOrUndefined(infos); + return info && { fileName: info.fileName, position: info.textSpan.start }; + } + function combineProjectOutputForReferences(projects, defaultProject, initialLocation, projectService) { var outputs = []; - combineProjectOutputWorker(projects, initialLocation, projectService, function (_a, tryAddToTodo) { + combineProjectOutputWorker(projects, defaultProject, initialLocation, projectService, function (_a, tryAddToTodo) { var project = _a.project, location = _a.location; var _loop_36 = function (outputReferencedSymbol) { var symbolToAddTo = ts.find(outputs, function (o) { return ts.documentSpansEqual(o.definition, outputReferencedSymbol.definition); }); @@ -118478,32 +118548,58 @@ var ts; var outputReferencedSymbol = _b[_i]; _loop_36(outputReferencedSymbol); } - }); + }, function () { return getDefinitionLocation(defaultProject, initialLocation); }); return outputs.filter(function (o) { return o.references.length !== 0; }); } - function combineProjectOutputWorker(projects, initialLocation, projectService, cb) { - var toDoAndSeenProjects; + function forEachProjectInProjects(projects, path, cb) { for (var _i = 0, _a = isProjectsArray(projects) ? projects : projects.projects; _i < _a.length; _i++) { var project = _a[_i]; - toDoAndSeenProjects = callbackProjectAndLocation(projects, { project: project, location: initialLocation }, projectService, toDoAndSeenProjects, cb); + cb(project, path); } if (!ts.isArray(projects) && projects.symLinkedProjects) { - projects.symLinkedProjects.forEach(function (symlinkedProjects, path) { + projects.symLinkedProjects.forEach(function (symlinkedProjects, symlinkedPath) { for (var _i = 0, symlinkedProjects_1 = symlinkedProjects; _i < symlinkedProjects_1.length; _i++) { var project = symlinkedProjects_1[_i]; - toDoAndSeenProjects = callbackProjectAndLocation(projects, { project: project, location: { fileName: path, position: initialLocation.position } }, projectService, toDoAndSeenProjects, cb); + cb(project, symlinkedPath); } }); } - while (toDoAndSeenProjects && toDoAndSeenProjects.toDo.length) { - toDoAndSeenProjects = callbackProjectAndLocation(projects, ts.Debug.assertDefined(toDoAndSeenProjects.toDo.pop()), projectService, toDoAndSeenProjects, cb); + } + function combineProjectOutputWorker(projects, defaultProject, initialLocation, projectService, cb, getDefinition) { + var toDo; + var seenProjects = ts.createMap(); + forEachProjectInProjects(projects, initialLocation && initialLocation.fileName, function (project, path) { + // TLocation shoud be either `sourcemaps.SourceMappableLocation` or `undefined`. Since `initialLocation` is `TLocation` this cast should be valid. + var location = (initialLocation ? { fileName: path, position: initialLocation.position } : undefined); + toDo = callbackProjectAndLocation({ project: project, location: location }, projectService, toDo, seenProjects, cb); + }); + // After initial references are collected, go over every other project and see if it has a reference for the symbol definition. + if (getDefinition) { + var memGetDefinition_1 = ts.memoize(getDefinition); + projectService.forEachEnabledProject(function (project) { + if (!ts.addToSeen(seenProjects, project.projectName)) + return; + var definition = getDefinitionInProject(memGetDefinition_1(), defaultProject, project); + if (definition) { + toDo = callbackProjectAndLocation({ project: project, location: definition }, projectService, toDo, seenProjects, cb); + } + }); + } + while (toDo && toDo.length) { + toDo = callbackProjectAndLocation(ts.Debug.assertDefined(toDo.pop()), projectService, toDo, seenProjects, cb); } } - function callbackProjectAndLocation(originalProjects, // For lazily populating seenProjects - projectAndLocation, projectService, toDoAndSeenProjects, cb) { + function getDefinitionInProject(definition, definingProject, project) { + if (!definition || project.containsFile(server.toNormalizedPath(definition.fileName))) + return definition; + var mappedDefinition = definingProject.getLanguageService().getSourceMapper().tryGetGeneratedLocation(definition); + return mappedDefinition && project.containsFile(server.toNormalizedPath(mappedDefinition.fileName)) ? mappedDefinition : undefined; + } + function callbackProjectAndLocation(projectAndLocation, projectService, toDo, seenProjects, cb) { if (projectAndLocation.project.getCancellationToken().isCancellationRequested()) return undefined; // Skip rest of toDo if cancelled cb(projectAndLocation, function (project, location) { + seenProjects.set(projectAndLocation.project.projectName, true); var originalLocation = project.getSourceMapper().tryGetOriginalLocation(location); if (!originalLocation) return false; @@ -118511,41 +118607,26 @@ var ts; if (!originalProjectAndScriptInfo) return false; if (originalProjectAndScriptInfo) { - if (toDoAndSeenProjects === undefined) { - toDoAndSeenProjects = { toDo: [], seenProjects: ts.createMap() }; - for (var _i = 0, _a = isProjectsArray(originalProjects) ? originalProjects : originalProjects.projects; _i < _a.length; _i++) { - var project_1 = _a[_i]; - toDoAndSeenProjects.seenProjects.set(project_1.projectName, true); - } - if (!ts.isArray(originalProjects) && originalProjects.symLinkedProjects) { - originalProjects.symLinkedProjects.forEach(function (symlinkedProjects) { - for (var _i = 0, symlinkedProjects_2 = symlinkedProjects; _i < symlinkedProjects_2.length; _i++) { - var project_2 = symlinkedProjects_2[_i]; - toDoAndSeenProjects.seenProjects.set(project_2.projectName, true); - } - }); - } - } - for (var _b = 0, _c = originalProjectAndScriptInfo.projects; _b < _c.length; _b++) { - var project_3 = _c[_b]; - addToTodo({ project: project_3, location: originalLocation }, toDoAndSeenProjects); + toDo = toDo || []; + for (var _i = 0, _a = originalProjectAndScriptInfo.projects; _i < _a.length; _i++) { + var project_1 = _a[_i]; + addToTodo({ project: project_1, location: originalLocation }, toDo, seenProjects); } var symlinkedProjectsMap = projectService.getSymlinkedProjects(originalProjectAndScriptInfo.scriptInfo); if (symlinkedProjectsMap) { symlinkedProjectsMap.forEach(function (symlinkedProjects) { - for (var _i = 0, symlinkedProjects_3 = symlinkedProjects; _i < symlinkedProjects_3.length; _i++) { - var symlinkedProject = symlinkedProjects_3[_i]; - addToTodo({ project: symlinkedProject, location: originalLocation }, toDoAndSeenProjects); + for (var _i = 0, symlinkedProjects_2 = symlinkedProjects; _i < symlinkedProjects_2.length; _i++) { + var symlinkedProject = symlinkedProjects_2[_i]; + addToTodo({ project: symlinkedProject, location: originalLocation }, toDo, seenProjects); } }); } } return true; }); - return toDoAndSeenProjects; + return toDo; } - function addToTodo(projectAndLocation, _a) { - var seenProjects = _a.seenProjects, toDo = _a.toDo; + function addToTodo(projectAndLocation, toDo, seenProjects) { if (ts.addToSeen(seenProjects, projectAndLocation.project.projectName)) toDo.push(projectAndLocation); } @@ -119414,7 +119495,7 @@ var ts; var file = server.toNormalizedPath(args.file); var position = this.getPositionInFile(args, file); var projects = this.getProjects(args); - var locations = combineProjectOutputForRenameLocations(projects, { fileName: args.file, position: position }, this.projectService, !!args.findInStrings, !!args.findInComments); + var locations = combineProjectOutputForRenameLocations(projects, this.getDefaultProject(args), { fileName: args.file, position: position }, this.projectService, !!args.findInStrings, !!args.findInComments); if (!simplifiedResult) return locations; var defaultProject = this.getDefaultProject(args); @@ -119442,7 +119523,7 @@ var ts; var file = server.toNormalizedPath(args.file); var projects = this.getProjects(args); var position = this.getPositionInFile(args, file); - var references = combineProjectOutputForReferences(projects, { fileName: args.file, position: position }, this.projectService); + var references = combineProjectOutputForReferences(projects, this.getDefaultProject(args), { fileName: args.file, position: position }, this.projectService); if (simplifiedResult) { var defaultProject = this.getDefaultProject(args); var scriptInfo = defaultProject.getScriptInfoForNormalizedPath(file); @@ -119695,7 +119776,7 @@ var ts; return project.getLanguageService().getCompletionEntryDetails(file, position, name, formattingOptions, source, _this.getPreferences(file)); }); return simplifiedResult - ? result.map(function (details) { return (__assign({}, details, { codeActions: ts.map(details.codeActions, function (action) { return _this.mapCodeAction(project, action); }) })); }) + ? result.map(function (details) { return (__assign({}, details, { codeActions: ts.map(details.codeActions, function (action) { return _this.mapCodeAction(action); }) })); }) : result; }; Session.prototype.getCompileOnSaveAffectedFileList = function (args) { @@ -119891,7 +119972,7 @@ var ts; return project.getLanguageService().getNavigateToItems(searchValue, maxResultCount, file); } else { - return combineProjectOutputWhileOpeningReferencedProjects(this.getProjects(args), this.projectService, function (project) { + return combineProjectOutputWhileOpeningReferencedProjects(this.getProjects(args), this.getDefaultProject(args), this.projectService, function (project) { return project.getLanguageService().getNavigateToItems(searchValue, maxResultCount, /*fileName*/ undefined, /*excludeDts*/ project.isNonTsProject()); }, documentSpanLocation, navigateToItemIsEqualTo); } @@ -119958,7 +120039,7 @@ var ts; var renameScriptInfo = project.getScriptInfoForNormalizedPath(server.toNormalizedPath(renameFilename)); mappedRenameLocation = getLocationInNewDocument(ts.getSnapshotText(renameScriptInfo.getSnapshot()), renameFilename, renameLocation, edits); } - return { renameLocation: mappedRenameLocation, renameFilename: renameFilename, edits: this.mapTextChangesToCodeEdits(project, edits) }; + return { renameLocation: mappedRenameLocation, renameFilename: renameFilename, edits: this.mapTextChangesToCodeEdits(edits) }; } else { return result; @@ -119970,7 +120051,7 @@ var ts; var _b = this.getFileAndProject(scope.args), file = _b.file, project = _b.project; var changes = project.getLanguageService().organizeImports({ type: "file", fileName: file }, this.getFormatOptions(file), this.getPreferences(file)); if (simplifiedResult) { - return this.mapTextChangesToCodeEdits(project, changes); + return this.mapTextChangesToCodeEdits(changes); } else { return changes; @@ -119983,7 +120064,7 @@ var ts; var formatOptions = this.getHostFormatOptions(); var preferences = this.getHostPreferences(); var changes = combineProjectOutputFromEveryProject(this.projectService, function (project) { return project.getLanguageService().getEditsForFileRename(oldPath, newPath, formatOptions, preferences); }, function (a, b) { return a.fileName === b.fileName; }); - return simplifiedResult ? changes.map(function (c) { return _this.mapTextChangeToCodeEditUsingScriptInfoOrConfigFile(c); }) : changes; + return simplifiedResult ? changes.map(function (c) { return _this.mapTextChangeToCodeEdit(c); }) : changes; }; Session.prototype.getCodeFixes = function (args, simplifiedResult) { var _this = this; @@ -119994,7 +120075,7 @@ var ts; var scriptInfo = project.getScriptInfoForNormalizedPath(file); var _b = this.getStartAndEndPosition(args, scriptInfo), startPosition = _b.startPosition, endPosition = _b.endPosition; var codeActions = project.getLanguageService().getCodeFixesAtPosition(file, startPosition, endPosition, args.errorCodes, this.getFormatOptions(file), this.getPreferences(file)); - return simplifiedResult ? codeActions.map(function (codeAction) { return _this.mapCodeFixAction(project, codeAction); }) : codeActions; + return simplifiedResult ? codeActions.map(function (codeAction) { return _this.mapCodeFixAction(codeAction); }) : codeActions; }; Session.prototype.getCombinedCodeFix = function (_a, simplifiedResult) { var scope = _a.scope, fixId = _a.fixId; @@ -120002,7 +120083,7 @@ var ts; var _b = this.getFileAndProject(scope.args), file = _b.file, project = _b.project; var res = project.getLanguageService().getCombinedCodeFix({ type: "file", fileName: file }, fixId, this.getFormatOptions(file), this.getPreferences(file)); if (simplifiedResult) { - return { changes: this.mapTextChangesToCodeEdits(project, res.changes), commands: res.commands }; + return { changes: this.mapTextChangesToCodeEdits(res.changes), commands: res.commands }; } else { return res; @@ -120036,27 +120117,20 @@ var ts; } return { startPosition: startPosition, endPosition: endPosition }; }; - Session.prototype.mapCodeAction = function (project, _a) { + Session.prototype.mapCodeAction = function (_a) { var description = _a.description, changes = _a.changes, commands = _a.commands; - return { description: description, changes: this.mapTextChangesToCodeEdits(project, changes), commands: commands }; + return { description: description, changes: this.mapTextChangesToCodeEdits(changes), commands: commands }; }; - Session.prototype.mapCodeFixAction = function (project, _a) { + Session.prototype.mapCodeFixAction = function (_a) { var fixName = _a.fixName, description = _a.description, changes = _a.changes, commands = _a.commands, fixId = _a.fixId, fixAllDescription = _a.fixAllDescription; - return { fixName: fixName, description: description, changes: this.mapTextChangesToCodeEdits(project, changes), commands: commands, fixId: fixId, fixAllDescription: fixAllDescription }; + return { fixName: fixName, description: description, changes: this.mapTextChangesToCodeEdits(changes), commands: commands, fixId: fixId, fixAllDescription: fixAllDescription }; }; - Session.prototype.mapTextChangesToCodeEdits = function (project, textChanges) { + Session.prototype.mapTextChangesToCodeEdits = function (textChanges) { var _this = this; - return textChanges.map(function (change) { return _this.mapTextChangeToCodeEdit(project, change); }); + return textChanges.map(function (change) { return _this.mapTextChangeToCodeEdit(change); }); }; - Session.prototype.mapTextChangeToCodeEdit = function (project, change) { - return mapTextChangesToCodeEditsForFile(change, project.getSourceFileOrConfigFile(this.normalizePath(change.fileName))); - }; - Session.prototype.mapTextChangeToCodeEditUsingScriptInfoOrConfigFile = function (change) { - return mapTextChangesToCodeEditsUsingScriptInfoOrConfig(change, this.projectService.getScriptInfoOrConfig(this.normalizePath(change.fileName))); - }; - Session.prototype.normalizePath = function (fileName) { - var _this = this; - return server.normalizedPathToPath(server.toNormalizedPath(fileName), this.host.getCurrentDirectory(), function (fileName) { return _this.getCanonicalFileName(fileName); }); + Session.prototype.mapTextChangeToCodeEdit = function (change) { + return mapTextChangesToCodeEdits(change, this.projectService.getScriptInfoOrConfig(change.fileName)); }; Session.prototype.convertTextChangeToCodeEdit = function (change, scriptInfo) { return { @@ -120229,32 +120303,13 @@ var ts; function toFileSpan(fileName, textSpan, scriptInfo) { return { file: fileName, start: scriptInfo.positionToLineOffset(textSpan.start), end: scriptInfo.positionToLineOffset(ts.textSpanEnd(textSpan)) }; } - function mapTextChangesToCodeEditsForFile(textChanges, sourceFile) { - ts.Debug.assert(!!textChanges.isNewFile === !sourceFile, "Expected isNewFile for (only) new files", function () { return JSON.stringify({ isNewFile: !!textChanges.isNewFile, hasSourceFile: !!sourceFile }); }); - if (sourceFile) { - return { - fileName: textChanges.fileName, - textChanges: textChanges.textChanges.map(function (textChange) { return convertTextChangeToCodeEdit(textChange, sourceFile); }), - }; - } - else { - return convertNewFileTextChangeToCodeEdit(textChanges); - } - } - function mapTextChangesToCodeEditsUsingScriptInfoOrConfig(textChanges, scriptInfo) { + function mapTextChangesToCodeEdits(textChanges, scriptInfo) { ts.Debug.assert(!!textChanges.isNewFile === !scriptInfo, "Expected isNewFile for (only) new files", function () { return JSON.stringify({ isNewFile: !!textChanges.isNewFile, hasScriptInfo: !!scriptInfo }); }); return scriptInfo - ? { fileName: textChanges.fileName, textChanges: textChanges.textChanges.map(function (textChange) { return convertTextChangeToCodeEditUsingScriptInfoOrConfig(textChange, scriptInfo); }) } + ? { fileName: textChanges.fileName, textChanges: textChanges.textChanges.map(function (textChange) { return convertTextChangeToCodeEdit(textChange, scriptInfo); }) } : convertNewFileTextChangeToCodeEdit(textChanges); } - function convertTextChangeToCodeEdit(change, sourceFile) { - return { - start: convertToLocation(sourceFile.getLineAndCharacterOfPosition(change.span.start)), - end: convertToLocation(sourceFile.getLineAndCharacterOfPosition(change.span.start + change.span.length)), - newText: change.newText ? change.newText : "", - }; - } - function convertTextChangeToCodeEditUsingScriptInfoOrConfig(change, scriptInfo) { + function convertTextChangeToCodeEdit(change, scriptInfo) { return { start: positionToLineOffset(scriptInfo, change.span.start), end: positionToLineOffset(scriptInfo, ts.textSpanEnd(change.span)), newText: change.newText }; } function positionToLineOffset(info, position) { diff --git a/lib/typescript.js b/lib/typescript.js index 964a18d2006..8a691e273c9 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -10496,27 +10496,37 @@ var ts; return referencePath ? ts.ensurePathIsNonModuleName(extensionless) : extensionless; } ts.getExternalModuleNameFromPath = getExternalModuleNameFromPath; - function getOwnEmitOutputFilePath(sourceFile, host, extension) { + function getOwnEmitOutputFilePath(fileName, host, extension) { var compilerOptions = host.getCompilerOptions(); var emitOutputFilePathWithoutExtension; if (compilerOptions.outDir) { - emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); + emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(fileName, host, compilerOptions.outDir)); } else { - emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName); + emitOutputFilePathWithoutExtension = ts.removeFileExtension(fileName); } return emitOutputFilePathWithoutExtension + extension; } ts.getOwnEmitOutputFilePath = getOwnEmitOutputFilePath; - function getDeclarationEmitOutputFilePath(sourceFile, host) { + function getDeclarationEmitOutputFilePath(fileName, host) { + // TODO: GH#25810 following should work but makes the build break: + // return getDeclarationEmitOutputFilePathWorker(fileName, host.getCompilerOptions(), host.getCurrentDirectory(), host.getCommonSourceDirectory(), f => host.getCanonicalFileName(f)); var options = host.getCompilerOptions(); var outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified var path = outputDir - ? getSourceFilePathInNewDir(sourceFile, host, outputDir) - : sourceFile.fileName; + ? getSourceFilePathInNewDir(fileName, host, outputDir) + : fileName; return ts.removeFileExtension(path) + ".d.ts" /* Dts */; } ts.getDeclarationEmitOutputFilePath = getDeclarationEmitOutputFilePath; + function getDeclarationEmitOutputFilePathWorker(fileName, options, currentDirectory, commonSourceDirectory, getCanonicalFileName) { + var outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified + var path = outputDir + ? getSourceFilePathInNewDirWorker(fileName, outputDir, currentDirectory, commonSourceDirectory, getCanonicalFileName) + : fileName; + return ts.removeFileExtension(path) + ".d.ts" /* Dts */; + } + ts.getDeclarationEmitOutputFilePathWorker = getDeclarationEmitOutputFilePathWorker; /** * Gets the source files that are expected to have an emit output. * @@ -10548,14 +10558,17 @@ var ts; return !(options.noEmitForJsFiles && isSourceFileJavaScript(sourceFile)) && !sourceFile.isDeclarationFile && !isSourceFileFromExternalLibrary(sourceFile); } ts.sourceFileMayBeEmitted = sourceFileMayBeEmitted; - function getSourceFilePathInNewDir(sourceFile, host, newDirPath) { - var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); - var commonSourceDirectory = host.getCommonSourceDirectory(); - var isSourceFileInCommonSourceDirectory = host.getCanonicalFileName(sourceFilePath).indexOf(host.getCanonicalFileName(commonSourceDirectory)) === 0; + function getSourceFilePathInNewDir(fileName, host, newDirPath) { + return getSourceFilePathInNewDirWorker(fileName, newDirPath, host.getCurrentDirectory(), host.getCommonSourceDirectory(), function (f) { return host.getCanonicalFileName(f); }); + } + ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir; + function getSourceFilePathInNewDirWorker(fileName, newDirPath, currentDirectory, commonSourceDirectory, getCanonicalFileName) { + var sourceFilePath = ts.getNormalizedAbsolutePath(fileName, currentDirectory); + var isSourceFileInCommonSourceDirectory = getCanonicalFileName(sourceFilePath).indexOf(getCanonicalFileName(commonSourceDirectory)) === 0; sourceFilePath = isSourceFileInCommonSourceDirectory ? sourceFilePath.substring(commonSourceDirectory.length) : sourceFilePath; return ts.combinePaths(newDirPath, sourceFilePath); } - ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir; + ts.getSourceFilePathInNewDirWorker = getSourceFilePathInNewDirWorker; function writeFile(host, diagnostics, fileName, data, writeByteOrderMark, sourceFiles) { host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) { diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage)); @@ -25785,7 +25798,7 @@ var ts; } } function getDisplayName(node) { - return ts.isNamedDeclaration(node) ? ts.declarationNameToString(node.name) : ts.unescapeLeadingUnderscores(getDeclarationName(node)); // TODO: GH#18217 + return ts.isNamedDeclaration(node) ? ts.declarationNameToString(node.name) : ts.unescapeLeadingUnderscores(ts.Debug.assertDefined(getDeclarationName(node))); } /** * Declares a Symbol for the node and adds it to symbols. Reports errors for conflicting identifier names. @@ -25856,8 +25869,10 @@ var ts; var message_1 = symbol.flags & 2 /* BlockScopedVariable */ ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + var messageNeedsName_1 = true; if (symbol.flags & 384 /* Enum */ || includes & 384 /* Enum */) { message_1 = ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations; + messageNeedsName_1 = false; } if (symbol.declarations && symbol.declarations.length) { // If the current node is a default export of some sort, then check if @@ -25865,6 +25880,7 @@ var ts; // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. if (isDefaultExport) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName_1 = false; } else { // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration. @@ -25874,13 +25890,15 @@ var ts; if (symbol.declarations && symbol.declarations.length && (node.kind === 252 /* ExportAssignment */ && !node.isExportEquals)) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName_1 = false; } } } - ts.forEach(symbol.declarations, function (declaration) { - file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(declaration) || declaration, message_1, getDisplayName(declaration))); - }); - file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(node) || node, message_1, getDisplayName(node))); + var addError = function (decl) { + file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(decl) || decl, message_1, messageNeedsName_1 ? getDisplayName(decl) : undefined)); + }; + ts.forEach(symbol.declarations, addError); + addError(node); symbol = createSymbol(0 /* None */, name); } } @@ -38852,9 +38870,9 @@ var ts; source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes); } var sourceCount = getParameterCount(source); - var sourceRestTypeParameter = getRestTypeParameter(source); - var targetRestTypeParameter = sourceRestTypeParameter ? getRestTypeParameter(target) : undefined; - if (sourceRestTypeParameter && !(targetRestTypeParameter && sourceCount === targetCount)) { + var sourceGenericRestType = getGenericRestType(source); + var targetGenericRestType = sourceGenericRestType ? getGenericRestType(target) : undefined; + if (sourceGenericRestType && !(targetGenericRestType && sourceCount === targetCount)) { return 0 /* False */; } var kind = target.declaration ? target.declaration.kind : 0 /* Unknown */; @@ -38880,8 +38898,8 @@ var ts; var paramCount = Math.max(sourceCount, targetCount); var lastIndex = paramCount - 1; for (var i = 0; i < paramCount; i++) { - var sourceType = i === lastIndex && sourceRestTypeParameter || getTypeAtPosition(source, i); - var targetType = i === lastIndex && targetRestTypeParameter || getTypeAtPosition(target, i); + var sourceType = i === lastIndex && sourceGenericRestType || getTypeAtPosition(source, i); + var targetType = i === lastIndex && targetGenericRestType || getTypeAtPosition(target, i); // In order to ensure that any generic type Foo is at least co-variant with respect to T no matter // how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions, // they naturally relate only contra-variantly). However, if the source and target parameters both have @@ -39499,7 +39517,8 @@ var ts; } if (reportErrors) { var bestMatchingType = findMatchingDiscriminantType(source, target) || - findMatchingTypeReferenceOrTypeAliasReference(source, target); + findMatchingTypeReferenceOrTypeAliasReference(source, target) || + findBestTypeForObjectLiteral(source, target); isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true); } return 0 /* False */; @@ -39521,6 +39540,11 @@ var ts; }); } } + function findBestTypeForObjectLiteral(source, unionTarget) { + if (ts.getObjectFlags(source) & 128 /* ObjectLiteral */ && forEachType(unionTarget, isArrayLikeType)) { + return ts.find(unionTarget.types, function (t) { return !isArrayLikeType(t); }); + } + } // Keep this up-to-date with the same logic within `getApparentTypeOfContextualType`, since they should behave similarly function findMatchingDiscriminantType(source, target) { var match; @@ -41025,13 +41049,13 @@ var ts; sourceHasRest ? targetCount : targetHasRest ? sourceCount : Math.min(sourceCount, targetCount); - var targetRestTypeVariable = getRestTypeParameter(target); - var paramCount = targetRestTypeVariable ? Math.min(targetCount - 1, maxCount) : maxCount; + var targetGenericRestType = getGenericRestType(target); + var paramCount = targetGenericRestType ? Math.min(targetCount - 1, maxCount) : maxCount; for (var i = 0; i < paramCount; i++) { callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i)); } - if (targetRestTypeVariable) { - callback(getRestTypeAtPosition(source, paramCount), targetRestTypeVariable); + if (targetGenericRestType) { + callback(getRestTypeAtPosition(source, paramCount), targetGenericRestType); } } function createInferenceContext(typeParameters, signature, flags, compareTypes, baseInferences) { @@ -46132,8 +46156,8 @@ var ts; // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. var effectiveArgCount = getEffectiveArgumentCount(node, args, signature); - var restTypeParameter = getRestTypeParameter(signature); - var argCount = restTypeParameter ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; + var genericRestType = getGenericRestType(signature); + var argCount = genericRestType ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. @@ -46151,9 +46175,9 @@ var ts; inferTypes(context.inferences, argType, paramType); } } - if (restTypeParameter) { - var spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, restTypeParameter, context); - inferTypes(context.inferences, spreadType, restTypeParameter); + if (genericRestType) { + var spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, genericRestType, context); + inferTypes(context.inferences, spreadType, genericRestType); } // In the second pass we visit only context sensitive arguments, and only those that aren't excluded, this // time treating function expressions normally (which may cause previously inferred type arguments to be fixed @@ -46835,9 +46859,9 @@ var ts; } var isJavascript = ts.isInJavaScriptFile(candidate.declaration); candidate = getSignatureInstantiation(candidate, typeArgumentTypes, isJavascript); - // If the original signature has a rest type parameter, instantiation may produce a + // If the original signature has a generic rest type, instantiation may produce a // signature with different arity and we need to perform another arity check. - if (getRestTypeParameter(originalCandidate) && !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { + if (getGenericRestType(originalCandidate) && !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { candidateForArgumentArityError = candidate; break; } @@ -47661,9 +47685,9 @@ var ts; var paramCount = getParameterCount(source); var hasRest = hasEffectiveRestParameter(source); if (hasRest && pos === paramCount - 1) { - var restTypeVariable = getRestTypeParameter(source); - if (restTypeVariable) { - return restTypeVariable; + var genericRestType = getGenericRestType(source); + if (genericRestType) { + return genericRestType; } } var start = hasRest ? Math.min(pos, paramCount - 1) : pos; @@ -47709,10 +47733,10 @@ var ts; } return signature.minArgumentCount; } - function getRestTypeParameter(signature) { + function getGenericRestType(signature) { if (signature.hasRestParameter) { var restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]); - if (restType.flags & 65536 /* TypeParameter */) { + if (restType.flags & 15794176 /* Instantiable */) { return restType; } } @@ -61516,7 +61540,7 @@ var ts; function decode(host, mapPath, map, program, fallbackCache) { if (fallbackCache === void 0) { fallbackCache = ts.createSourceFileLikeCache(host); } var currentDirectory = ts.getDirectoryPath(mapPath); - var sourceRoot = map.sourceRoot || currentDirectory; + var sourceRoot = map.sourceRoot ? ts.getNormalizedAbsolutePath(map.sourceRoot, currentDirectory) : currentDirectory; var decodedMappings; var generatedOrderedMappings; var sourceOrderedMappings; @@ -61551,10 +61575,10 @@ var ts; } function getSourceFileLike(fileName, location) { // Lookup file in program, if provided - var file = program && program.getSourceFile(fileName); + var path = ts.toPath(fileName, location, host.getCanonicalFileName); + var file = program && program.getSourceFile(path); if (!file) { // Otherwise check the cache (which may hit disk) - var path = ts.toPath(fileName, location, host.getCanonicalFileName); return fallbackCache.get(path); } return file; @@ -77732,7 +77756,7 @@ var ts; if (sourceFileOrBundle.kind === 277 /* SourceFile */) { // emitting single module file // For modules or multiple emit files the mapRoot will have directory structure like the sources // So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map - sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(sourceFileOrBundle, host, sourceMapDir)); + sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(sourceFileOrBundle.fileName, host, sourceMapDir)); } if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { // The relative paths are relative to the common directory @@ -78506,11 +78530,11 @@ var ts; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath }; } else { - var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options)); + var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); var sourceMapFilePath = ts.isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); // For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error var isJs = ts.isSourceFileJavaScript(sourceFile); - var declarationFilePath = ((forceDtsPaths || ts.getEmitDeclarations(options)) && !isJs) ? ts.getDeclarationEmitOutputFilePath(sourceFile, host) : undefined; + var declarationFilePath = ((forceDtsPaths || ts.getEmitDeclarations(options)) && !isJs) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; var declarationMapPath = ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: undefined }; } @@ -83768,9 +83792,17 @@ var ts; if (filesByName.has(path)) { var file_1 = filesByName.get(path); // try to check if we've already seen this file but with a different casing in path - // NOTE: this only makes sense for case-insensitive file systems - if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { - reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); + // NOTE: this only makes sense for case-insensitive file systems, and only on files which are not redirected + if (file_1 && options.forceConsistentCasingInFileNames) { + var inputName = fileName; + var checkedName = file_1.fileName; + var isRedirect = toPath(checkedName) !== toPath(inputName); + if (isRedirect) { + inputName = getProjectReferenceRedirect(fileName) || fileName; + } + if (ts.getNormalizedAbsolutePath(checkedName, currentDirectory) !== ts.getNormalizedAbsolutePath(inputName, currentDirectory)) { + reportFileNamesDifferOnlyInCasingError(inputName, checkedName, refFile, refPos, refEnd); + } } // If the file was previously found via a node_modules search, but is now being processed as a root file, // then everything it sucks in may also be marked incorrectly, and needs to be checked again. @@ -85990,7 +86022,12 @@ var ts; return res && res.resolvedFileName === importedFileName ? res.originalPath : undefined; }); }); - return symlinks.length === 0 ? getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, host.getCurrentDirectory ? host.getCurrentDirectory() : ""), getCanonicalFileName, host) : symlinks; + var cwd = host.getCurrentDirectory ? host.getCurrentDirectory() : ""; + var baseOptions = getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host); + if (symlinks.length === 0) { + return baseOptions; + } + return ts.deduplicate(ts.concatenate(baseOptions, ts.flatMap(symlinks, function (importedFileName) { return getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host); }))); } function getRelativePathNParents(relativePath) { var components = ts.getPathComponents(relativePath); @@ -99595,7 +99632,7 @@ var ts; var base64UrlRegExp = /^data:(?:application\/json(?:;charset=[uU][tT][fF]-8);base64,([A-Za-z0-9+\/=]+)$)?/; function getSourceMapper(getCanonicalFileName, currentDirectory, log, host, getProgram) { var sourcemappedFileCache; - return { tryGetOriginalLocation: tryGetOriginalLocation, toLineColumnOffset: toLineColumnOffset, clearCache: clearCache }; + return { tryGetOriginalLocation: tryGetOriginalLocation, tryGetGeneratedLocation: tryGetGeneratedLocation, toLineColumnOffset: toLineColumnOffset, clearCache: clearCache }; function scanForSourcemapURL(fileName) { var mappedFile = sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); if (!mappedFile) { @@ -99669,12 +99706,26 @@ var ts; function tryGetOriginalLocation(info) { if (!ts.isDeclarationFileName(info.fileName)) return undefined; - var file = getProgram().getSourceFile(info.fileName) || sourcemappedFileCache.get(ts.toPath(info.fileName, currentDirectory, getCanonicalFileName)); + var file = getFile(info.fileName); if (!file) return undefined; var newLoc = getSourceMapper(info.fileName, file).getOriginalPosition(info); return newLoc === info ? undefined : tryGetOriginalLocation(newLoc) || newLoc; } + function tryGetGeneratedLocation(info) { + var program = getProgram(); + var declarationPath = ts.getDeclarationEmitOutputFilePathWorker(info.fileName, program.getCompilerOptions(), currentDirectory, program.getCommonSourceDirectory(), getCanonicalFileName); + if (declarationPath === undefined) + return undefined; + var declarationFile = getFile(declarationPath); + if (!declarationFile) + return undefined; + var newLoc = getSourceMapper(declarationPath, declarationFile).getGeneratedPosition(info); + return newLoc === info ? undefined : newLoc; + } + function getFile(fileName) { + return getProgram().getSourceFile(fileName) || sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); + } function toLineColumnOffset(fileName, position) { var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); var file = getProgram().getSourceFile(path) || sourcemappedFileCache.get(path); // TODO: GH#18217 @@ -102130,7 +102181,6 @@ var ts; function processChildNodes(nodes, parent, parentStartLine, parentDynamicIndentation) { ts.Debug.assert(ts.isNodeArray(nodes)); var listStartToken = getOpenTokenForList(parent, nodes); - var listEndToken = getCloseTokenForOpenToken(listStartToken); var listDynamicIndentation = parentDynamicIndentation; var startLine = parentStartLine; if (listStartToken !== 0 /* Unknown */) { @@ -102159,17 +102209,20 @@ var ts; var child = nodes[i]; inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListItem*/ true, /*isFirstListItem*/ i === 0); } - if (listEndToken !== 0 /* Unknown */) { - if (formattingScanner.isOnToken()) { - var tokenInfo = formattingScanner.readTokenInfo(parent); - // consume the list end token only if it is still belong to the parent - // there might be the case when current token matches end token but does not considered as one - // function (x: function) <-- - // without this check close paren will be interpreted as list end token for function expression which is wrong - if (tokenInfo.token.kind === listEndToken && ts.rangeContainsRange(parent, tokenInfo.token)) { - // consume list end token - consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent); - } + var listEndToken = getCloseTokenForOpenToken(listStartToken); + if (listEndToken !== 0 /* Unknown */ && formattingScanner.isOnToken()) { + var tokenInfo = formattingScanner.readTokenInfo(parent); + if (tokenInfo.token.kind === 26 /* CommaToken */ && ts.isCallLikeExpression(parent)) { + formattingScanner.advance(); + tokenInfo = formattingScanner.readTokenInfo(parent); + } + // consume the list end token only if it is still belong to the parent + // there might be the case when current token matches end token but does not considered as one + // function (x: function) <-- + // without this check close paren will be interpreted as list end token for function expression which is wrong + if (tokenInfo.token.kind === listEndToken && ts.rangeContainsRange(parent, tokenInfo.token)) { + // consume list end token + consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent); } } } @@ -105189,6 +105242,8 @@ var ts; var errorCodes = [ ts.Diagnostics.Cannot_find_name_0.code, ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code, ts.Diagnostics.Cannot_find_namespace_0.code, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code, ts.Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here.code, @@ -105682,6 +105737,8 @@ var ts; var errorCodes = [ ts.Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code, ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_2.code, ]; codefix.registerCodeFix({ diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 964a18d2006..8a691e273c9 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -10496,27 +10496,37 @@ var ts; return referencePath ? ts.ensurePathIsNonModuleName(extensionless) : extensionless; } ts.getExternalModuleNameFromPath = getExternalModuleNameFromPath; - function getOwnEmitOutputFilePath(sourceFile, host, extension) { + function getOwnEmitOutputFilePath(fileName, host, extension) { var compilerOptions = host.getCompilerOptions(); var emitOutputFilePathWithoutExtension; if (compilerOptions.outDir) { - emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); + emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(fileName, host, compilerOptions.outDir)); } else { - emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName); + emitOutputFilePathWithoutExtension = ts.removeFileExtension(fileName); } return emitOutputFilePathWithoutExtension + extension; } ts.getOwnEmitOutputFilePath = getOwnEmitOutputFilePath; - function getDeclarationEmitOutputFilePath(sourceFile, host) { + function getDeclarationEmitOutputFilePath(fileName, host) { + // TODO: GH#25810 following should work but makes the build break: + // return getDeclarationEmitOutputFilePathWorker(fileName, host.getCompilerOptions(), host.getCurrentDirectory(), host.getCommonSourceDirectory(), f => host.getCanonicalFileName(f)); var options = host.getCompilerOptions(); var outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified var path = outputDir - ? getSourceFilePathInNewDir(sourceFile, host, outputDir) - : sourceFile.fileName; + ? getSourceFilePathInNewDir(fileName, host, outputDir) + : fileName; return ts.removeFileExtension(path) + ".d.ts" /* Dts */; } ts.getDeclarationEmitOutputFilePath = getDeclarationEmitOutputFilePath; + function getDeclarationEmitOutputFilePathWorker(fileName, options, currentDirectory, commonSourceDirectory, getCanonicalFileName) { + var outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified + var path = outputDir + ? getSourceFilePathInNewDirWorker(fileName, outputDir, currentDirectory, commonSourceDirectory, getCanonicalFileName) + : fileName; + return ts.removeFileExtension(path) + ".d.ts" /* Dts */; + } + ts.getDeclarationEmitOutputFilePathWorker = getDeclarationEmitOutputFilePathWorker; /** * Gets the source files that are expected to have an emit output. * @@ -10548,14 +10558,17 @@ var ts; return !(options.noEmitForJsFiles && isSourceFileJavaScript(sourceFile)) && !sourceFile.isDeclarationFile && !isSourceFileFromExternalLibrary(sourceFile); } ts.sourceFileMayBeEmitted = sourceFileMayBeEmitted; - function getSourceFilePathInNewDir(sourceFile, host, newDirPath) { - var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); - var commonSourceDirectory = host.getCommonSourceDirectory(); - var isSourceFileInCommonSourceDirectory = host.getCanonicalFileName(sourceFilePath).indexOf(host.getCanonicalFileName(commonSourceDirectory)) === 0; + function getSourceFilePathInNewDir(fileName, host, newDirPath) { + return getSourceFilePathInNewDirWorker(fileName, newDirPath, host.getCurrentDirectory(), host.getCommonSourceDirectory(), function (f) { return host.getCanonicalFileName(f); }); + } + ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir; + function getSourceFilePathInNewDirWorker(fileName, newDirPath, currentDirectory, commonSourceDirectory, getCanonicalFileName) { + var sourceFilePath = ts.getNormalizedAbsolutePath(fileName, currentDirectory); + var isSourceFileInCommonSourceDirectory = getCanonicalFileName(sourceFilePath).indexOf(getCanonicalFileName(commonSourceDirectory)) === 0; sourceFilePath = isSourceFileInCommonSourceDirectory ? sourceFilePath.substring(commonSourceDirectory.length) : sourceFilePath; return ts.combinePaths(newDirPath, sourceFilePath); } - ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir; + ts.getSourceFilePathInNewDirWorker = getSourceFilePathInNewDirWorker; function writeFile(host, diagnostics, fileName, data, writeByteOrderMark, sourceFiles) { host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) { diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage)); @@ -25785,7 +25798,7 @@ var ts; } } function getDisplayName(node) { - return ts.isNamedDeclaration(node) ? ts.declarationNameToString(node.name) : ts.unescapeLeadingUnderscores(getDeclarationName(node)); // TODO: GH#18217 + return ts.isNamedDeclaration(node) ? ts.declarationNameToString(node.name) : ts.unescapeLeadingUnderscores(ts.Debug.assertDefined(getDeclarationName(node))); } /** * Declares a Symbol for the node and adds it to symbols. Reports errors for conflicting identifier names. @@ -25856,8 +25869,10 @@ var ts; var message_1 = symbol.flags & 2 /* BlockScopedVariable */ ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + var messageNeedsName_1 = true; if (symbol.flags & 384 /* Enum */ || includes & 384 /* Enum */) { message_1 = ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations; + messageNeedsName_1 = false; } if (symbol.declarations && symbol.declarations.length) { // If the current node is a default export of some sort, then check if @@ -25865,6 +25880,7 @@ var ts; // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. if (isDefaultExport) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName_1 = false; } else { // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration. @@ -25874,13 +25890,15 @@ var ts; if (symbol.declarations && symbol.declarations.length && (node.kind === 252 /* ExportAssignment */ && !node.isExportEquals)) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName_1 = false; } } } - ts.forEach(symbol.declarations, function (declaration) { - file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(declaration) || declaration, message_1, getDisplayName(declaration))); - }); - file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(node) || node, message_1, getDisplayName(node))); + var addError = function (decl) { + file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(decl) || decl, message_1, messageNeedsName_1 ? getDisplayName(decl) : undefined)); + }; + ts.forEach(symbol.declarations, addError); + addError(node); symbol = createSymbol(0 /* None */, name); } } @@ -38852,9 +38870,9 @@ var ts; source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes); } var sourceCount = getParameterCount(source); - var sourceRestTypeParameter = getRestTypeParameter(source); - var targetRestTypeParameter = sourceRestTypeParameter ? getRestTypeParameter(target) : undefined; - if (sourceRestTypeParameter && !(targetRestTypeParameter && sourceCount === targetCount)) { + var sourceGenericRestType = getGenericRestType(source); + var targetGenericRestType = sourceGenericRestType ? getGenericRestType(target) : undefined; + if (sourceGenericRestType && !(targetGenericRestType && sourceCount === targetCount)) { return 0 /* False */; } var kind = target.declaration ? target.declaration.kind : 0 /* Unknown */; @@ -38880,8 +38898,8 @@ var ts; var paramCount = Math.max(sourceCount, targetCount); var lastIndex = paramCount - 1; for (var i = 0; i < paramCount; i++) { - var sourceType = i === lastIndex && sourceRestTypeParameter || getTypeAtPosition(source, i); - var targetType = i === lastIndex && targetRestTypeParameter || getTypeAtPosition(target, i); + var sourceType = i === lastIndex && sourceGenericRestType || getTypeAtPosition(source, i); + var targetType = i === lastIndex && targetGenericRestType || getTypeAtPosition(target, i); // In order to ensure that any generic type Foo is at least co-variant with respect to T no matter // how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions, // they naturally relate only contra-variantly). However, if the source and target parameters both have @@ -39499,7 +39517,8 @@ var ts; } if (reportErrors) { var bestMatchingType = findMatchingDiscriminantType(source, target) || - findMatchingTypeReferenceOrTypeAliasReference(source, target); + findMatchingTypeReferenceOrTypeAliasReference(source, target) || + findBestTypeForObjectLiteral(source, target); isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true); } return 0 /* False */; @@ -39521,6 +39540,11 @@ var ts; }); } } + function findBestTypeForObjectLiteral(source, unionTarget) { + if (ts.getObjectFlags(source) & 128 /* ObjectLiteral */ && forEachType(unionTarget, isArrayLikeType)) { + return ts.find(unionTarget.types, function (t) { return !isArrayLikeType(t); }); + } + } // Keep this up-to-date with the same logic within `getApparentTypeOfContextualType`, since they should behave similarly function findMatchingDiscriminantType(source, target) { var match; @@ -41025,13 +41049,13 @@ var ts; sourceHasRest ? targetCount : targetHasRest ? sourceCount : Math.min(sourceCount, targetCount); - var targetRestTypeVariable = getRestTypeParameter(target); - var paramCount = targetRestTypeVariable ? Math.min(targetCount - 1, maxCount) : maxCount; + var targetGenericRestType = getGenericRestType(target); + var paramCount = targetGenericRestType ? Math.min(targetCount - 1, maxCount) : maxCount; for (var i = 0; i < paramCount; i++) { callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i)); } - if (targetRestTypeVariable) { - callback(getRestTypeAtPosition(source, paramCount), targetRestTypeVariable); + if (targetGenericRestType) { + callback(getRestTypeAtPosition(source, paramCount), targetGenericRestType); } } function createInferenceContext(typeParameters, signature, flags, compareTypes, baseInferences) { @@ -46132,8 +46156,8 @@ var ts; // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. var effectiveArgCount = getEffectiveArgumentCount(node, args, signature); - var restTypeParameter = getRestTypeParameter(signature); - var argCount = restTypeParameter ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; + var genericRestType = getGenericRestType(signature); + var argCount = genericRestType ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. @@ -46151,9 +46175,9 @@ var ts; inferTypes(context.inferences, argType, paramType); } } - if (restTypeParameter) { - var spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, restTypeParameter, context); - inferTypes(context.inferences, spreadType, restTypeParameter); + if (genericRestType) { + var spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, genericRestType, context); + inferTypes(context.inferences, spreadType, genericRestType); } // In the second pass we visit only context sensitive arguments, and only those that aren't excluded, this // time treating function expressions normally (which may cause previously inferred type arguments to be fixed @@ -46835,9 +46859,9 @@ var ts; } var isJavascript = ts.isInJavaScriptFile(candidate.declaration); candidate = getSignatureInstantiation(candidate, typeArgumentTypes, isJavascript); - // If the original signature has a rest type parameter, instantiation may produce a + // If the original signature has a generic rest type, instantiation may produce a // signature with different arity and we need to perform another arity check. - if (getRestTypeParameter(originalCandidate) && !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { + if (getGenericRestType(originalCandidate) && !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { candidateForArgumentArityError = candidate; break; } @@ -47661,9 +47685,9 @@ var ts; var paramCount = getParameterCount(source); var hasRest = hasEffectiveRestParameter(source); if (hasRest && pos === paramCount - 1) { - var restTypeVariable = getRestTypeParameter(source); - if (restTypeVariable) { - return restTypeVariable; + var genericRestType = getGenericRestType(source); + if (genericRestType) { + return genericRestType; } } var start = hasRest ? Math.min(pos, paramCount - 1) : pos; @@ -47709,10 +47733,10 @@ var ts; } return signature.minArgumentCount; } - function getRestTypeParameter(signature) { + function getGenericRestType(signature) { if (signature.hasRestParameter) { var restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]); - if (restType.flags & 65536 /* TypeParameter */) { + if (restType.flags & 15794176 /* Instantiable */) { return restType; } } @@ -61516,7 +61540,7 @@ var ts; function decode(host, mapPath, map, program, fallbackCache) { if (fallbackCache === void 0) { fallbackCache = ts.createSourceFileLikeCache(host); } var currentDirectory = ts.getDirectoryPath(mapPath); - var sourceRoot = map.sourceRoot || currentDirectory; + var sourceRoot = map.sourceRoot ? ts.getNormalizedAbsolutePath(map.sourceRoot, currentDirectory) : currentDirectory; var decodedMappings; var generatedOrderedMappings; var sourceOrderedMappings; @@ -61551,10 +61575,10 @@ var ts; } function getSourceFileLike(fileName, location) { // Lookup file in program, if provided - var file = program && program.getSourceFile(fileName); + var path = ts.toPath(fileName, location, host.getCanonicalFileName); + var file = program && program.getSourceFile(path); if (!file) { // Otherwise check the cache (which may hit disk) - var path = ts.toPath(fileName, location, host.getCanonicalFileName); return fallbackCache.get(path); } return file; @@ -77732,7 +77756,7 @@ var ts; if (sourceFileOrBundle.kind === 277 /* SourceFile */) { // emitting single module file // For modules or multiple emit files the mapRoot will have directory structure like the sources // So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map - sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(sourceFileOrBundle, host, sourceMapDir)); + sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(sourceFileOrBundle.fileName, host, sourceMapDir)); } if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { // The relative paths are relative to the common directory @@ -78506,11 +78530,11 @@ var ts; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath }; } else { - var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options)); + var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); var sourceMapFilePath = ts.isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); // For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error var isJs = ts.isSourceFileJavaScript(sourceFile); - var declarationFilePath = ((forceDtsPaths || ts.getEmitDeclarations(options)) && !isJs) ? ts.getDeclarationEmitOutputFilePath(sourceFile, host) : undefined; + var declarationFilePath = ((forceDtsPaths || ts.getEmitDeclarations(options)) && !isJs) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; var declarationMapPath = ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: undefined }; } @@ -83768,9 +83792,17 @@ var ts; if (filesByName.has(path)) { var file_1 = filesByName.get(path); // try to check if we've already seen this file but with a different casing in path - // NOTE: this only makes sense for case-insensitive file systems - if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { - reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); + // NOTE: this only makes sense for case-insensitive file systems, and only on files which are not redirected + if (file_1 && options.forceConsistentCasingInFileNames) { + var inputName = fileName; + var checkedName = file_1.fileName; + var isRedirect = toPath(checkedName) !== toPath(inputName); + if (isRedirect) { + inputName = getProjectReferenceRedirect(fileName) || fileName; + } + if (ts.getNormalizedAbsolutePath(checkedName, currentDirectory) !== ts.getNormalizedAbsolutePath(inputName, currentDirectory)) { + reportFileNamesDifferOnlyInCasingError(inputName, checkedName, refFile, refPos, refEnd); + } } // If the file was previously found via a node_modules search, but is now being processed as a root file, // then everything it sucks in may also be marked incorrectly, and needs to be checked again. @@ -85990,7 +86022,12 @@ var ts; return res && res.resolvedFileName === importedFileName ? res.originalPath : undefined; }); }); - return symlinks.length === 0 ? getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, host.getCurrentDirectory ? host.getCurrentDirectory() : ""), getCanonicalFileName, host) : symlinks; + var cwd = host.getCurrentDirectory ? host.getCurrentDirectory() : ""; + var baseOptions = getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host); + if (symlinks.length === 0) { + return baseOptions; + } + return ts.deduplicate(ts.concatenate(baseOptions, ts.flatMap(symlinks, function (importedFileName) { return getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host); }))); } function getRelativePathNParents(relativePath) { var components = ts.getPathComponents(relativePath); @@ -99595,7 +99632,7 @@ var ts; var base64UrlRegExp = /^data:(?:application\/json(?:;charset=[uU][tT][fF]-8);base64,([A-Za-z0-9+\/=]+)$)?/; function getSourceMapper(getCanonicalFileName, currentDirectory, log, host, getProgram) { var sourcemappedFileCache; - return { tryGetOriginalLocation: tryGetOriginalLocation, toLineColumnOffset: toLineColumnOffset, clearCache: clearCache }; + return { tryGetOriginalLocation: tryGetOriginalLocation, tryGetGeneratedLocation: tryGetGeneratedLocation, toLineColumnOffset: toLineColumnOffset, clearCache: clearCache }; function scanForSourcemapURL(fileName) { var mappedFile = sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); if (!mappedFile) { @@ -99669,12 +99706,26 @@ var ts; function tryGetOriginalLocation(info) { if (!ts.isDeclarationFileName(info.fileName)) return undefined; - var file = getProgram().getSourceFile(info.fileName) || sourcemappedFileCache.get(ts.toPath(info.fileName, currentDirectory, getCanonicalFileName)); + var file = getFile(info.fileName); if (!file) return undefined; var newLoc = getSourceMapper(info.fileName, file).getOriginalPosition(info); return newLoc === info ? undefined : tryGetOriginalLocation(newLoc) || newLoc; } + function tryGetGeneratedLocation(info) { + var program = getProgram(); + var declarationPath = ts.getDeclarationEmitOutputFilePathWorker(info.fileName, program.getCompilerOptions(), currentDirectory, program.getCommonSourceDirectory(), getCanonicalFileName); + if (declarationPath === undefined) + return undefined; + var declarationFile = getFile(declarationPath); + if (!declarationFile) + return undefined; + var newLoc = getSourceMapper(declarationPath, declarationFile).getGeneratedPosition(info); + return newLoc === info ? undefined : newLoc; + } + function getFile(fileName) { + return getProgram().getSourceFile(fileName) || sourcemappedFileCache.get(ts.toPath(fileName, currentDirectory, getCanonicalFileName)); + } function toLineColumnOffset(fileName, position) { var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName); var file = getProgram().getSourceFile(path) || sourcemappedFileCache.get(path); // TODO: GH#18217 @@ -102130,7 +102181,6 @@ var ts; function processChildNodes(nodes, parent, parentStartLine, parentDynamicIndentation) { ts.Debug.assert(ts.isNodeArray(nodes)); var listStartToken = getOpenTokenForList(parent, nodes); - var listEndToken = getCloseTokenForOpenToken(listStartToken); var listDynamicIndentation = parentDynamicIndentation; var startLine = parentStartLine; if (listStartToken !== 0 /* Unknown */) { @@ -102159,17 +102209,20 @@ var ts; var child = nodes[i]; inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, startLine, /*isListItem*/ true, /*isFirstListItem*/ i === 0); } - if (listEndToken !== 0 /* Unknown */) { - if (formattingScanner.isOnToken()) { - var tokenInfo = formattingScanner.readTokenInfo(parent); - // consume the list end token only if it is still belong to the parent - // there might be the case when current token matches end token but does not considered as one - // function (x: function) <-- - // without this check close paren will be interpreted as list end token for function expression which is wrong - if (tokenInfo.token.kind === listEndToken && ts.rangeContainsRange(parent, tokenInfo.token)) { - // consume list end token - consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent); - } + var listEndToken = getCloseTokenForOpenToken(listStartToken); + if (listEndToken !== 0 /* Unknown */ && formattingScanner.isOnToken()) { + var tokenInfo = formattingScanner.readTokenInfo(parent); + if (tokenInfo.token.kind === 26 /* CommaToken */ && ts.isCallLikeExpression(parent)) { + formattingScanner.advance(); + tokenInfo = formattingScanner.readTokenInfo(parent); + } + // consume the list end token only if it is still belong to the parent + // there might be the case when current token matches end token but does not considered as one + // function (x: function) <-- + // without this check close paren will be interpreted as list end token for function expression which is wrong + if (tokenInfo.token.kind === listEndToken && ts.rangeContainsRange(parent, tokenInfo.token)) { + // consume list end token + consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent); } } } @@ -105189,6 +105242,8 @@ var ts; var errorCodes = [ ts.Diagnostics.Cannot_find_name_0.code, ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code, ts.Diagnostics.Cannot_find_namespace_0.code, ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code, ts.Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here.code, @@ -105682,6 +105737,8 @@ var ts; var errorCodes = [ ts.Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2.code, ts.Diagnostics.Cannot_find_name_0_Did_you_mean_1.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code, + ts.Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_2.code, ]; codefix.registerCodeFix({ diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index e39d2a9a58a..3ff8dc1ecbb 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -10509,27 +10509,37 @@ var ts; return referencePath ? ts.ensurePathIsNonModuleName(extensionless) : extensionless; } ts.getExternalModuleNameFromPath = getExternalModuleNameFromPath; - function getOwnEmitOutputFilePath(sourceFile, host, extension) { + function getOwnEmitOutputFilePath(fileName, host, extension) { var compilerOptions = host.getCompilerOptions(); var emitOutputFilePathWithoutExtension; if (compilerOptions.outDir) { - emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); + emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(fileName, host, compilerOptions.outDir)); } else { - emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName); + emitOutputFilePathWithoutExtension = ts.removeFileExtension(fileName); } return emitOutputFilePathWithoutExtension + extension; } ts.getOwnEmitOutputFilePath = getOwnEmitOutputFilePath; - function getDeclarationEmitOutputFilePath(sourceFile, host) { + function getDeclarationEmitOutputFilePath(fileName, host) { + // TODO: GH#25810 following should work but makes the build break: + // return getDeclarationEmitOutputFilePathWorker(fileName, host.getCompilerOptions(), host.getCurrentDirectory(), host.getCommonSourceDirectory(), f => host.getCanonicalFileName(f)); var options = host.getCompilerOptions(); var outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified var path = outputDir - ? getSourceFilePathInNewDir(sourceFile, host, outputDir) - : sourceFile.fileName; + ? getSourceFilePathInNewDir(fileName, host, outputDir) + : fileName; return ts.removeFileExtension(path) + ".d.ts" /* Dts */; } ts.getDeclarationEmitOutputFilePath = getDeclarationEmitOutputFilePath; + function getDeclarationEmitOutputFilePathWorker(fileName, options, currentDirectory, commonSourceDirectory, getCanonicalFileName) { + var outputDir = options.declarationDir || options.outDir; // Prefer declaration folder if specified + var path = outputDir + ? getSourceFilePathInNewDirWorker(fileName, outputDir, currentDirectory, commonSourceDirectory, getCanonicalFileName) + : fileName; + return ts.removeFileExtension(path) + ".d.ts" /* Dts */; + } + ts.getDeclarationEmitOutputFilePathWorker = getDeclarationEmitOutputFilePathWorker; /** * Gets the source files that are expected to have an emit output. * @@ -10561,14 +10571,17 @@ var ts; return !(options.noEmitForJsFiles && isSourceFileJavaScript(sourceFile)) && !sourceFile.isDeclarationFile && !isSourceFileFromExternalLibrary(sourceFile); } ts.sourceFileMayBeEmitted = sourceFileMayBeEmitted; - function getSourceFilePathInNewDir(sourceFile, host, newDirPath) { - var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); - var commonSourceDirectory = host.getCommonSourceDirectory(); - var isSourceFileInCommonSourceDirectory = host.getCanonicalFileName(sourceFilePath).indexOf(host.getCanonicalFileName(commonSourceDirectory)) === 0; + function getSourceFilePathInNewDir(fileName, host, newDirPath) { + return getSourceFilePathInNewDirWorker(fileName, newDirPath, host.getCurrentDirectory(), host.getCommonSourceDirectory(), function (f) { return host.getCanonicalFileName(f); }); + } + ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir; + function getSourceFilePathInNewDirWorker(fileName, newDirPath, currentDirectory, commonSourceDirectory, getCanonicalFileName) { + var sourceFilePath = ts.getNormalizedAbsolutePath(fileName, currentDirectory); + var isSourceFileInCommonSourceDirectory = getCanonicalFileName(sourceFilePath).indexOf(getCanonicalFileName(commonSourceDirectory)) === 0; sourceFilePath = isSourceFileInCommonSourceDirectory ? sourceFilePath.substring(commonSourceDirectory.length) : sourceFilePath; return ts.combinePaths(newDirPath, sourceFilePath); } - ts.getSourceFilePathInNewDir = getSourceFilePathInNewDir; + ts.getSourceFilePathInNewDirWorker = getSourceFilePathInNewDirWorker; function writeFile(host, diagnostics, fileName, data, writeByteOrderMark, sourceFiles) { host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) { diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage)); @@ -25798,7 +25811,7 @@ var ts; } } function getDisplayName(node) { - return ts.isNamedDeclaration(node) ? ts.declarationNameToString(node.name) : ts.unescapeLeadingUnderscores(getDeclarationName(node)); // TODO: GH#18217 + return ts.isNamedDeclaration(node) ? ts.declarationNameToString(node.name) : ts.unescapeLeadingUnderscores(ts.Debug.assertDefined(getDeclarationName(node))); } /** * Declares a Symbol for the node and adds it to symbols. Reports errors for conflicting identifier names. @@ -25869,8 +25882,10 @@ var ts; var message_1 = symbol.flags & 2 /* BlockScopedVariable */ ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0; + var messageNeedsName_1 = true; if (symbol.flags & 384 /* Enum */ || includes & 384 /* Enum */) { message_1 = ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations; + messageNeedsName_1 = false; } if (symbol.declarations && symbol.declarations.length) { // If the current node is a default export of some sort, then check if @@ -25878,6 +25893,7 @@ var ts; // We'll know whether we have other default exports depending on if `symbol` already has a declaration list set. if (isDefaultExport) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName_1 = false; } else { // This is to properly report an error in the case "export default { }" is after export default of class declaration or function declaration. @@ -25887,13 +25903,15 @@ var ts; if (symbol.declarations && symbol.declarations.length && (node.kind === 252 /* ExportAssignment */ && !node.isExportEquals)) { message_1 = ts.Diagnostics.A_module_cannot_have_multiple_default_exports; + messageNeedsName_1 = false; } } } - ts.forEach(symbol.declarations, function (declaration) { - file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(declaration) || declaration, message_1, getDisplayName(declaration))); - }); - file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(node) || node, message_1, getDisplayName(node))); + var addError = function (decl) { + file.bindDiagnostics.push(createDiagnosticForNode(ts.getNameOfDeclaration(decl) || decl, message_1, messageNeedsName_1 ? getDisplayName(decl) : undefined)); + }; + ts.forEach(symbol.declarations, addError); + addError(node); symbol = createSymbol(0 /* None */, name); } } @@ -38865,9 +38883,9 @@ var ts; source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes); } var sourceCount = getParameterCount(source); - var sourceRestTypeParameter = getRestTypeParameter(source); - var targetRestTypeParameter = sourceRestTypeParameter ? getRestTypeParameter(target) : undefined; - if (sourceRestTypeParameter && !(targetRestTypeParameter && sourceCount === targetCount)) { + var sourceGenericRestType = getGenericRestType(source); + var targetGenericRestType = sourceGenericRestType ? getGenericRestType(target) : undefined; + if (sourceGenericRestType && !(targetGenericRestType && sourceCount === targetCount)) { return 0 /* False */; } var kind = target.declaration ? target.declaration.kind : 0 /* Unknown */; @@ -38893,8 +38911,8 @@ var ts; var paramCount = Math.max(sourceCount, targetCount); var lastIndex = paramCount - 1; for (var i = 0; i < paramCount; i++) { - var sourceType = i === lastIndex && sourceRestTypeParameter || getTypeAtPosition(source, i); - var targetType = i === lastIndex && targetRestTypeParameter || getTypeAtPosition(target, i); + var sourceType = i === lastIndex && sourceGenericRestType || getTypeAtPosition(source, i); + var targetType = i === lastIndex && targetGenericRestType || getTypeAtPosition(target, i); // In order to ensure that any generic type Foo is at least co-variant with respect to T no matter // how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions, // they naturally relate only contra-variantly). However, if the source and target parameters both have @@ -39512,7 +39530,8 @@ var ts; } if (reportErrors) { var bestMatchingType = findMatchingDiscriminantType(source, target) || - findMatchingTypeReferenceOrTypeAliasReference(source, target); + findMatchingTypeReferenceOrTypeAliasReference(source, target) || + findBestTypeForObjectLiteral(source, target); isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true); } return 0 /* False */; @@ -39534,6 +39553,11 @@ var ts; }); } } + function findBestTypeForObjectLiteral(source, unionTarget) { + if (ts.getObjectFlags(source) & 128 /* ObjectLiteral */ && forEachType(unionTarget, isArrayLikeType)) { + return ts.find(unionTarget.types, function (t) { return !isArrayLikeType(t); }); + } + } // Keep this up-to-date with the same logic within `getApparentTypeOfContextualType`, since they should behave similarly function findMatchingDiscriminantType(source, target) { var match; @@ -41038,13 +41062,13 @@ var ts; sourceHasRest ? targetCount : targetHasRest ? sourceCount : Math.min(sourceCount, targetCount); - var targetRestTypeVariable = getRestTypeParameter(target); - var paramCount = targetRestTypeVariable ? Math.min(targetCount - 1, maxCount) : maxCount; + var targetGenericRestType = getGenericRestType(target); + var paramCount = targetGenericRestType ? Math.min(targetCount - 1, maxCount) : maxCount; for (var i = 0; i < paramCount; i++) { callback(getTypeAtPosition(source, i), getTypeAtPosition(target, i)); } - if (targetRestTypeVariable) { - callback(getRestTypeAtPosition(source, paramCount), targetRestTypeVariable); + if (targetGenericRestType) { + callback(getRestTypeAtPosition(source, paramCount), targetGenericRestType); } } function createInferenceContext(typeParameters, signature, flags, compareTypes, baseInferences) { @@ -46145,8 +46169,8 @@ var ts; // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. var effectiveArgCount = getEffectiveArgumentCount(node, args, signature); - var restTypeParameter = getRestTypeParameter(signature); - var argCount = restTypeParameter ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; + var genericRestType = getGenericRestType(signature); + var argCount = genericRestType ? Math.min(getParameterCount(signature) - 1, effectiveArgCount) : effectiveArgCount; for (var i = 0; i < argCount; i++) { var arg = getEffectiveArgument(node, args, i); // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. @@ -46164,9 +46188,9 @@ var ts; inferTypes(context.inferences, argType, paramType); } } - if (restTypeParameter) { - var spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, restTypeParameter, context); - inferTypes(context.inferences, spreadType, restTypeParameter); + if (genericRestType) { + var spreadType = getSpreadArgumentType(node, args, argCount, effectiveArgCount, genericRestType, context); + inferTypes(context.inferences, spreadType, genericRestType); } // In the second pass we visit only context sensitive arguments, and only those that aren't excluded, this // time treating function expressions normally (which may cause previously inferred type arguments to be fixed @@ -46848,9 +46872,9 @@ var ts; } var isJavascript = ts.isInJavaScriptFile(candidate.declaration); candidate = getSignatureInstantiation(candidate, typeArgumentTypes, isJavascript); - // If the original signature has a rest type parameter, instantiation may produce a + // If the original signature has a generic rest type, instantiation may produce a // signature with different arity and we need to perform another arity check. - if (getRestTypeParameter(originalCandidate) && !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { + if (getGenericRestType(originalCandidate) && !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { candidateForArgumentArityError = candidate; break; } @@ -47674,9 +47698,9 @@ var ts; var paramCount = getParameterCount(source); var hasRest = hasEffectiveRestParameter(source); if (hasRest && pos === paramCount - 1) { - var restTypeVariable = getRestTypeParameter(source); - if (restTypeVariable) { - return restTypeVariable; + var genericRestType = getGenericRestType(source); + if (genericRestType) { + return genericRestType; } } var start = hasRest ? Math.min(pos, paramCount - 1) : pos; @@ -47722,10 +47746,10 @@ var ts; } return signature.minArgumentCount; } - function getRestTypeParameter(signature) { + function getGenericRestType(signature) { if (signature.hasRestParameter) { var restType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]); - if (restType.flags & 65536 /* TypeParameter */) { + if (restType.flags & 15794176 /* Instantiable */) { return restType; } } @@ -61529,7 +61553,7 @@ var ts; function decode(host, mapPath, map, program, fallbackCache) { if (fallbackCache === void 0) { fallbackCache = ts.createSourceFileLikeCache(host); } var currentDirectory = ts.getDirectoryPath(mapPath); - var sourceRoot = map.sourceRoot || currentDirectory; + var sourceRoot = map.sourceRoot ? ts.getNormalizedAbsolutePath(map.sourceRoot, currentDirectory) : currentDirectory; var decodedMappings; var generatedOrderedMappings; var sourceOrderedMappings; @@ -61564,10 +61588,10 @@ var ts; } function getSourceFileLike(fileName, location) { // Lookup file in program, if provided - var file = program && program.getSourceFile(fileName); + var path = ts.toPath(fileName, location, host.getCanonicalFileName); + var file = program && program.getSourceFile(path); if (!file) { // Otherwise check the cache (which may hit disk) - var path = ts.toPath(fileName, location, host.getCanonicalFileName); return fallbackCache.get(path); } return file; @@ -77745,7 +77769,7 @@ var ts; if (sourceFileOrBundle.kind === 277 /* SourceFile */) { // emitting single module file // For modules or multiple emit files the mapRoot will have directory structure like the sources // So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map - sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(sourceFileOrBundle, host, sourceMapDir)); + sourceMapDir = ts.getDirectoryPath(ts.getSourceFilePathInNewDir(sourceFileOrBundle.fileName, host, sourceMapDir)); } if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) { // The relative paths are relative to the common directory @@ -78519,11 +78543,11 @@ var ts; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath }; } else { - var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options)); + var jsFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); var sourceMapFilePath = ts.isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); // For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error var isJs = ts.isSourceFileJavaScript(sourceFile); - var declarationFilePath = ((forceDtsPaths || ts.getEmitDeclarations(options)) && !isJs) ? ts.getDeclarationEmitOutputFilePath(sourceFile, host) : undefined; + var declarationFilePath = ((forceDtsPaths || ts.getEmitDeclarations(options)) && !isJs) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; var declarationMapPath = ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: undefined }; } @@ -83781,9 +83805,17 @@ var ts; if (filesByName.has(path)) { var file_1 = filesByName.get(path); // try to check if we've already seen this file but with a different casing in path - // NOTE: this only makes sense for case-insensitive file systems - if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { - reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); + // NOTE: this only makes sense for case-insensitive file systems, and only on files which are not redirected + if (file_1 && options.forceConsistentCasingInFileNames) { + var inputName = fileName; + var checkedName = file_1.fileName; + var isRedirect = toPath(checkedName) !== toPath(inputName); + if (isRedirect) { + inputName = getProjectReferenceRedirect(fileName) || fileName; + } + if (ts.getNormalizedAbsolutePath(checkedName, currentDirectory) !== ts.getNormalizedAbsolutePath(inputName, currentDirectory)) { + reportFileNamesDifferOnlyInCasingError(inputName, checkedName, refFile, refPos, refEnd); + } } // If the file was previously found via a node_modules search, but is now being processed as a root file, // then everything it sucks in may also be marked incorrectly, and needs to be checked again. @@ -86003,7 +86035,12 @@ var ts; return res && res.resolvedFileName === importedFileName ? res.originalPath : undefined; }); }); - return symlinks.length === 0 ? getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, host.getCurrentDirectory ? host.getCurrentDirectory() : ""), getCanonicalFileName, host) : symlinks; + var cwd = host.getCurrentDirectory ? host.getCurrentDirectory() : ""; + var baseOptions = getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host); + if (symlinks.length === 0) { + return baseOptions; + } + return ts.deduplicate(ts.concatenate(baseOptions, ts.flatMap(symlinks, function (importedFileName) { return getAllModulePathsUsingIndirectSymlinks(files, ts.getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host); }))); } function getRelativePathNParents(relativePath) { var components = ts.getPathComponents(relativePath);