Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed May 31, 2024
1 parent 9f9682c commit 85420bb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/services/refactors/moveToFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
ExportKind,
Expression,
ExpressionStatement,
extensionFromPath,
Extension,
ExternalModuleReference,
factory,
fileShouldUseJavaScriptRequire,
Expand Down Expand Up @@ -133,6 +133,7 @@ import {
RefactorEditInfo,
RequireOrImportCall,
resolvePath,
ScriptKind,
ScriptTarget,
skipAlias,
some,
Expand All @@ -147,6 +148,7 @@ import {
textChanges,
TransformFlags,
tryCast,
tryGetExtensionFromPath,
TypeAliasDeclaration,
TypeChecker,
TypeNode,
Expand Down Expand Up @@ -771,7 +773,18 @@ export function createNewFileName(oldFile: SourceFile, program: Program, host: L
if (toMove) {
const usage = getUsageInfo(oldFile, toMove.all, checker);
const currentDirectory = getDirectoryPath(oldFile.fileName);
const extension = extensionFromPath(oldFile.fileName);
let extension = tryGetExtensionFromPath(oldFile.fileName);
if (!extension) {
const scriptKind = host.getScriptKind?.(oldFile.fileName);
switch (scriptKind) {
case ScriptKind.TS: extension = Extension.Ts; break;
case ScriptKind.TSX: extension = Extension.Tsx; break;
case ScriptKind.JS: extension = Extension.Js; break;
case ScriptKind.JSX: extension = Extension.Jsx; break;
case ScriptKind.JSON: extension = Extension.Json; break;
default: extension = Extension.Ts; break;
}
}
const newFileName = combinePaths(
// new file is always placed in the same directory as the old file
currentDirectory,
Expand Down

0 comments on commit 85420bb

Please sign in to comment.