From 4426059193061d6467536cc2af2ae3c62cccf4fe Mon Sep 17 00:00:00 2001 From: "Oleksandr T." Date: Fri, 23 Aug 2024 02:46:28 +0300 Subject: [PATCH] fix(59649): ts Move to a new file doesn't respect importModuleSpecifier setting (#59670) --- src/compiler/moduleSpecifiers.ts | 3 +- src/services/codefixes/importFixes.ts | 1 + .../moveToNewFile_nonRelativePaths.ts | 38 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/moveToNewFile_nonRelativePaths.ts 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", + } +}); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy