getEditsForFileRename: Don't update import with non-relative path if the imported file didn't move (#25159)

This commit is contained in:
Andy 2018-06-22 11:21:45 -07:00 committed by GitHub
parent cb9c3e0f6a
commit 42fc8431f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View file

@ -125,10 +125,11 @@ namespace ts {
// TODO:GH#18217
? getSourceFileToImportFromResolved(resolveModuleName(importLiteral.text, oldImportFromPath, program.getCompilerOptions(), host as ModuleResolutionHost), oldToNew, program)
: getSourceFileToImport(importLiteral, sourceFile, program, host, oldToNew);
// If neither the importing source file nor the imported file moved, do nothing.
return toImport === undefined || !toImport.updated && !importingSourceFileMoved
? undefined
: moduleSpecifiers.getModuleSpecifier(program.getCompilerOptions(), sourceFile, newImportFromPath, toImport.newFileName, host, preferences);
// Need an update if the imported file moved, or the importing file moved and was using a relative path.
return toImport !== undefined && (toImport.updated || (importingSourceFileMoved && pathIsRelative(importLiteral.text)))
? moduleSpecifiers.getModuleSpecifier(program.getCompilerOptions(), sourceFile, newImportFromPath, toImport.newFileName, host, preferences)
: undefined;
});
}
}

View file

@ -0,0 +1,20 @@
/// <reference path='fourslash.ts' />
// @Filename: /sub/a.ts
////export const a = 1;
// @Filename: /sub/b.ts
////import { a } from "sub/a";
// @Filename: /tsconfig.json
////{
//// "compilerOptions": {
//// "baseUrl": "."
//// }
////}
verify.getEditsForFileRename({
oldPath: "/sub/b.ts",
newPath: "/sub/c/d.ts",
newFileContents: {},
});