mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Let AutoImportProvider find non-declaration files in wildcard exports... (#56848)
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
appendIfUnique,
|
||||
arrayIsEqualTo,
|
||||
changeAnyExtension,
|
||||
changeFullExtension,
|
||||
CharacterCodes,
|
||||
combinePaths,
|
||||
CommandLineOption,
|
||||
@@ -41,7 +42,6 @@ import {
|
||||
GetCanonicalFileName,
|
||||
getCommonSourceDirectory,
|
||||
getCompilerOptionValue,
|
||||
getDeclarationEmitExtensionForPath,
|
||||
getDirectoryPath,
|
||||
GetEffectiveTypeRootsHost,
|
||||
getEmitModuleKind,
|
||||
@@ -2291,9 +2291,7 @@ function loadEntrypointsFromExportMap(
|
||||
extensionsToExtensionsArray(extensions),
|
||||
/*excludes*/ undefined,
|
||||
[
|
||||
isDeclarationFileName(target)
|
||||
? replaceFirstStar(target, "**/*")
|
||||
: changeAnyExtension(replaceFirstStar(target, "**/*"), getDeclarationEmitExtensionForPath(target)),
|
||||
changeFullExtension(replaceFirstStar(target, "**/*"), ".*"),
|
||||
],
|
||||
).forEach(entry => {
|
||||
entrypoints = appendIfUnique(entrypoints, {
|
||||
|
||||
+17
-2
@@ -85,7 +85,6 @@ import {
|
||||
Extension,
|
||||
ExternalModuleReference,
|
||||
fileExtensionIs,
|
||||
fileExtensionIsOneOf,
|
||||
findIndex,
|
||||
firstOrUndefined,
|
||||
forEach,
|
||||
@@ -99,6 +98,7 @@ import {
|
||||
FunctionOrConstructorTypeNode,
|
||||
FunctionTypeNode,
|
||||
GetAccessorDeclaration,
|
||||
getAnyExtensionFromPath,
|
||||
getBaseFileName,
|
||||
getBinaryOperatorPrecedence,
|
||||
getFullWidth,
|
||||
@@ -10433,7 +10433,22 @@ namespace IncrementalParser {
|
||||
|
||||
/** @internal */
|
||||
export function isDeclarationFileName(fileName: string): boolean {
|
||||
return fileExtensionIsOneOf(fileName, supportedDeclarationExtensions) || (fileExtensionIs(fileName, Extension.Ts) && getBaseFileName(fileName).includes(".d."));
|
||||
return getDeclarationFileExtension(fileName) !== undefined;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getDeclarationFileExtension(fileName: string): string | undefined {
|
||||
const standardExtension = getAnyExtensionFromPath(fileName, supportedDeclarationExtensions, /*ignoreCase*/ false);
|
||||
if (standardExtension) {
|
||||
return standardExtension;
|
||||
}
|
||||
if (fileExtensionIs(fileName, Extension.Ts)) {
|
||||
const index = getBaseFileName(fileName).lastIndexOf(".d.");
|
||||
if (index >= 0) {
|
||||
return fileName.substring(index);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function parseResolutionMode(mode: string | undefined, pos: number, end: number, reportDiagnostic: PragmaDiagnosticReporter): ResolutionMode {
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
equateStringsCaseInsensitive,
|
||||
equateStringsCaseSensitive,
|
||||
GetCanonicalFileName,
|
||||
getDeclarationFileExtension,
|
||||
getStringComparer,
|
||||
identity,
|
||||
lastOrUndefined,
|
||||
@@ -756,6 +757,25 @@ export function changeAnyExtension(path: string, ext: string, extensions?: strin
|
||||
return pathext ? path.slice(0, path.length - pathext.length) + (startsWith(ext, ".") ? ext : "." + ext) : path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Like `changeAnyExtension`, but declaration file extensions are recognized
|
||||
* and replaced starting from the `.d`.
|
||||
*
|
||||
* ```ts
|
||||
* changeAnyExtension("file.d.ts", ".js") === "file.d.js"
|
||||
* changeFullExtension("file.d.ts", ".js") === "file.js"
|
||||
* ```
|
||||
*/
|
||||
export function changeFullExtension(path: string, newExtension: string) {
|
||||
const declarationExtension = getDeclarationFileExtension(path);
|
||||
if (declarationExtension) {
|
||||
return path.slice(0, path.length - declarationExtension.length) +
|
||||
(startsWith(newExtension, ".") ? newExtension : ("." + newExtension));
|
||||
}
|
||||
return changeAnyExtension(path, newExtension);
|
||||
}
|
||||
|
||||
//// Path Comparisons
|
||||
|
||||
// check path for these segments: '', '.'. '..'
|
||||
|
||||
Reference in New Issue
Block a user