diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index 4b7cbf2bae274..fa1727b523b4d 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -435,6 +435,7 @@ export function getLocalModuleSpecifierBetweenFileNames( targetFileName: string, compilerOptions: CompilerOptions, host: ModuleSpecifierResolutionHost, + preferences: UserPreferences, options: ModuleSpecifierOptions = {}, ): string { const info = getInfo(importingFile.fileName, host); @@ -445,7 +446,7 @@ export function getLocalModuleSpecifierBetweenFileNames( compilerOptions, host, importMode, - getModuleSpecifierPreferences({}, host, compilerOptions, importingFile), + getModuleSpecifierPreferences(preferences, host, compilerOptions, importingFile), ); } diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 9940c1794ed9c..5617378119a4b 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -336,6 +336,7 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog exportingFileName, compilerOptions, createModuleSpecifierResolutionHost(program, host), + preferences, ); const importKind = getImportKind(futureExportingSourceFile, exportKind, program); const addAsTypeOnly = getAddAsTypeOnly( diff --git a/tests/cases/fourslash/moveToNewFile_nonRelativePaths.ts b/tests/cases/fourslash/moveToNewFile_nonRelativePaths.ts new file mode 100644 index 0000000000000..9d3af58c8807c --- /dev/null +++ b/tests/cases/fourslash/moveToNewFile_nonRelativePaths.ts @@ -0,0 +1,38 @@ +/// + +// @Filename: /tsconfig.json +//// { +//// "compilerOptions": { +//// "moduleResolution": "Bundler", +//// "baseUrl": "." +//// "paths": { +//// "@foo/*": ["src/*"] +//// } +//// } +//// } + +// @Filename: /src/a.ts +////export function a() { +//// b(); +////} +////[|export function b() { +////}|] + +verify.moveToNewFile({ + newFileContents: { + "/src/a.ts": +`import { b } from "@foo/b"; + +export function a() { + b(); +} +`, + "/src/b.ts": +`export function b() { +} +`, + }, + preferences: { + importModuleSpecifierPreference: "non-relative", + } +});