@@ -18,6 +18,7 @@ import {
18
18
ClassDeclaration ,
19
19
codefix ,
20
20
combinePaths ,
21
+ Comparison ,
21
22
concatenate ,
22
23
contains ,
23
24
createModuleSpecifierResolutionHost ,
@@ -53,12 +54,14 @@ import {
53
54
getLineAndCharacterOfPosition ,
54
55
getLocaleSpecificMessage ,
55
56
getModifiers ,
57
+ getNormalizedAbsolutePath ,
56
58
getPropertySymbolFromBindingElement ,
57
59
getQuotePreference ,
58
60
getRangesWhere ,
59
61
getRefactorContextSpan ,
60
62
getRelativePathFromFile ,
61
63
getSourceFileOfNode ,
64
+ getStringComparer ,
62
65
getSynthesizedDeepClone ,
63
66
getTokenAtPosition ,
64
67
getUniqueName ,
@@ -434,7 +437,12 @@ export function updateImportsInOtherFiles(
434
437
} ;
435
438
deleteUnusedImports ( sourceFile , importNode , changes , shouldMove ) ; // These will be changed to imports from the new file
436
439
437
- const pathToTargetFileWithExtension = resolvePath ( getDirectoryPath ( oldFile . path ) , targetFileName ) ;
440
+ const pathToTargetFileWithExtension = resolvePath ( getDirectoryPath ( getNormalizedAbsolutePath ( oldFile . fileName , program . getCurrentDirectory ( ) ) ) , targetFileName ) ;
441
+
442
+ // no self-imports
443
+
444
+ if ( getStringComparer ( ! program . useCaseSensitiveFileNames ( ) ) ( pathToTargetFileWithExtension , sourceFile . fileName ) === Comparison . EqualTo ) return ;
445
+
438
446
const newModuleSpecifier = getModuleSpecifier ( program . getCompilerOptions ( ) , sourceFile , sourceFile . fileName , pathToTargetFileWithExtension , createModuleSpecifierResolutionHost ( program , host ) ) ;
439
447
const newImportDeclaration = filterImport ( importNode , makeStringLiteral ( newModuleSpecifier , quotePreference ) , shouldMove ) ;
440
448
if ( newImportDeclaration ) changes . insertNodeAfter ( sourceFile , statement , newImportDeclaration ) ;
@@ -586,7 +594,7 @@ export function makeImportOrRequire(
586
594
useEs6Imports : boolean ,
587
595
quotePreference : QuotePreference ,
588
596
) : AnyImportOrRequireStatement | undefined {
589
- const pathToTargetFile = resolvePath ( getDirectoryPath ( sourceFile . path ) , targetFileNameWithExtension ) ;
597
+ const pathToTargetFile = resolvePath ( getDirectoryPath ( getNormalizedAbsolutePath ( sourceFile . fileName , program . getCurrentDirectory ( ) ) ) , targetFileNameWithExtension ) ;
590
598
const pathToTargetFileWithCorrectExtension = getModuleSpecifier ( program . getCompilerOptions ( ) , sourceFile , sourceFile . fileName , pathToTargetFile , createModuleSpecifierResolutionHost ( program , host ) ) ;
591
599
592
600
if ( useEs6Imports ) {
0 commit comments