@@ -32,6 +32,7 @@ import {
3232 flatten ,
3333 forEach ,
3434 forEachAncestorDirectory ,
35+ FutureSourceFile ,
3536 getBaseFileName ,
3637 GetCanonicalFileName ,
3738 getConditions ,
@@ -65,6 +66,7 @@ import {
6566 isDeclarationFileName ,
6667 isExternalModuleAugmentation ,
6768 isExternalModuleNameRelative ,
69+ isFullSourceFile ,
6870 isMissingPackageJsonInfo ,
6971 isModuleBlock ,
7072 isModuleDeclaration ,
@@ -141,7 +143,7 @@ export interface ModuleSpecifierPreferences {
141143export function getModuleSpecifierPreferences (
142144 { importModuleSpecifierPreference, importModuleSpecifierEnding } : UserPreferences ,
143145 compilerOptions : CompilerOptions ,
144- importingSourceFile : SourceFile ,
146+ importingSourceFile : Pick < SourceFile , "fileName" | "impliedNodeFormat" > ,
145147 oldImportSpecifier ?: string ,
146148) : ModuleSpecifierPreferences {
147149 const filePreferredEnding = getPreferredEnding ( ) ;
@@ -197,7 +199,7 @@ export function getModuleSpecifierPreferences(
197199 importModuleSpecifierEnding ,
198200 resolutionMode ?? importingSourceFile . impliedNodeFormat ,
199201 compilerOptions ,
200- importingSourceFile ,
202+ isFullSourceFile ( importingSourceFile ) ? importingSourceFile : undefined ,
201203 ) ;
202204 }
203205}
@@ -230,7 +232,7 @@ export function updateModuleSpecifier(
230232/** @internal */
231233export function getModuleSpecifier (
232234 compilerOptions : CompilerOptions ,
233- importingSourceFile : SourceFile ,
235+ importingSourceFile : SourceFile | FutureSourceFile ,
234236 importingSourceFileName : string ,
235237 toFileName : string ,
236238 host : ModuleSpecifierResolutionHost ,
@@ -242,7 +244,7 @@ export function getModuleSpecifier(
242244/** @internal */
243245export function getNodeModulesPackageName (
244246 compilerOptions : CompilerOptions ,
245- importingSourceFile : SourceFile ,
247+ importingSourceFile : SourceFile | FutureSourceFile ,
246248 nodeModulesFileName : string ,
247249 host : ModuleSpecifierResolutionHost ,
248250 preferences : UserPreferences ,
@@ -255,7 +257,7 @@ export function getNodeModulesPackageName(
255257
256258function getModuleSpecifierWorker (
257259 compilerOptions : CompilerOptions ,
258- importingSourceFile : SourceFile ,
260+ importingSourceFile : SourceFile | FutureSourceFile ,
259261 importingSourceFileName : string ,
260262 toFileName : string ,
261263 host : ModuleSpecifierResolutionHost ,
@@ -272,7 +274,7 @@ function getModuleSpecifierWorker(
272274/** @internal */
273275export function tryGetModuleSpecifiersFromCache (
274276 moduleSymbol : Symbol ,
275- importingSourceFile : SourceFile ,
277+ importingSourceFile : SourceFile | FutureSourceFile ,
276278 host : ModuleSpecifierResolutionHost ,
277279 userPreferences : UserPreferences ,
278280 options : ModuleSpecifierOptions = { } ,
@@ -288,7 +290,7 @@ export function tryGetModuleSpecifiersFromCache(
288290
289291function tryGetModuleSpecifiersFromCacheWorker (
290292 moduleSymbol : Symbol ,
291- importingSourceFile : SourceFile ,
293+ importingSourceFile : SourceFile | FutureSourceFile ,
292294 host : ModuleSpecifierResolutionHost ,
293295 userPreferences : UserPreferences ,
294296 options : ModuleSpecifierOptions = { } ,
@@ -334,7 +336,7 @@ export function getModuleSpecifiersWithCacheInfo(
334336 moduleSymbol : Symbol ,
335337 checker : TypeChecker ,
336338 compilerOptions : CompilerOptions ,
337- importingSourceFile : SourceFile ,
339+ importingSourceFile : SourceFile | FutureSourceFile ,
338340 host : ModuleSpecifierResolutionHost ,
339341 userPreferences : UserPreferences ,
340342 options : ModuleSpecifierOptions = { } ,
@@ -370,18 +372,38 @@ export function getModuleSpecifiersWithCacheInfo(
370372 return { moduleSpecifiers : result , computedWithoutCache } ;
371373}
372374
375+ /** @internal */
376+ export function getLocalModuleSpecifierBetweenFileNames (
377+ importingFile : Pick < SourceFile , "fileName" | "impliedNodeFormat" > ,
378+ targetFileName : string ,
379+ compilerOptions : CompilerOptions ,
380+ host : ModuleSpecifierResolutionHost ,
381+ options : ModuleSpecifierOptions = { } ,
382+ ) : string {
383+ const info = getInfo ( importingFile . fileName , host ) ;
384+ const importMode = options . overrideImportMode ?? importingFile . impliedNodeFormat ;
385+ return getLocalModuleSpecifier (
386+ targetFileName ,
387+ info ,
388+ compilerOptions ,
389+ host ,
390+ importMode ,
391+ getModuleSpecifierPreferences ( { } , compilerOptions , importingFile ) ,
392+ ) ;
393+ }
394+
373395function computeModuleSpecifiers (
374396 modulePaths : readonly ModulePath [ ] ,
375397 compilerOptions : CompilerOptions ,
376- importingSourceFile : SourceFile ,
398+ importingSourceFile : SourceFile | FutureSourceFile ,
377399 host : ModuleSpecifierResolutionHost ,
378400 userPreferences : UserPreferences ,
379401 options : ModuleSpecifierOptions = { } ,
380402 forAutoImport : boolean ,
381403) : readonly string [ ] {
382404 const info = getInfo ( importingSourceFile . fileName , host ) ;
383405 const preferences = getModuleSpecifierPreferences ( userPreferences , compilerOptions , importingSourceFile ) ;
384- const existingSpecifier = forEach ( modulePaths , modulePath =>
406+ const existingSpecifier = isFullSourceFile ( importingSourceFile ) && forEach ( modulePaths , modulePath =>
385407 forEach (
386408 host . getFileIncludeReasons ( ) . get ( toPath ( modulePath . path , host . getCurrentDirectory ( ) , info . getCanonicalFileName ) ) ,
387409 reason => {
@@ -1014,7 +1036,7 @@ function tryGetModuleNameFromRootDirs(rootDirs: readonly string[], moduleFileNam
10141036 return processEnding ( shortest , allowedEndings , compilerOptions ) ;
10151037}
10161038
1017- function tryGetModuleNameAsNodeModule ( { path, isRedirect } : ModulePath , { getCanonicalFileName, canonicalSourceDirectory } : Info , importingSourceFile : SourceFile , host : ModuleSpecifierResolutionHost , options : CompilerOptions , userPreferences : UserPreferences , packageNameOnly ?: boolean , overrideMode ?: ResolutionMode ) : string | undefined {
1039+ function tryGetModuleNameAsNodeModule ( { path, isRedirect } : ModulePath , { getCanonicalFileName, canonicalSourceDirectory } : Info , importingSourceFile : SourceFile | FutureSourceFile , host : ModuleSpecifierResolutionHost , options : CompilerOptions , userPreferences : UserPreferences , packageNameOnly ?: boolean , overrideMode ?: ResolutionMode ) : string | undefined {
10181040 if ( ! host . fileExists || ! host . readFile ) {
10191041 return undefined ;
10201042 }
0 commit comments