moveToNewFile: fix quotes for module specifiers (#60203)

This commit is contained in:
Isabel Duan 2024-10-14 10:24:49 -07:00 committed by GitHub
parent c003609d59
commit aeb74cc721
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 48 additions and 2 deletions

View File

@ -494,8 +494,8 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog
function writeFixes(changeTracker: textChanges.ChangeTracker, oldFileQuotePreference?: QuotePreference) {
let quotePreference: QuotePreference;
if (isFullSourceFile(sourceFile) && sourceFile.imports.length === 0 && oldFileQuotePreference !== undefined) {
// If the target file has no imports, we must use the same quote preference as the file we are importing from.
if (sourceFile.imports !== undefined && sourceFile.imports.length === 0 && oldFileQuotePreference !== undefined) {
// If the target file (including future files) has no imports, we must use the same quote preference as the file we are importing from.
quotePreference = oldFileQuotePreference;
}
else {

View File

@ -0,0 +1,24 @@
/// <reference path='fourslash.ts' />
// @Filename: /a.ts
////export const x = 0;
////x;
// @Filename: /b.ts
////import { x } from './a'
////
////[|x|];
verify.moveToNewFile({
newFileContents: {
"/newFile.ts": // module specifier should have the same quotes as import in the original file
`import { x } from './a';
x;
`,
"/b.ts":
`
`
},
});

View File

@ -0,0 +1,22 @@
/// <reference path='fourslash.ts' />
// @Filename: /other.ts
//// export function foo() { return 1 };
// @Filename: /a.ts
////import { foo as oFoo } from './other';
////[|export const x = oFoo();|]
////export const a = 0;
verify.moveToNewFile({
newFileContents: {
"/a.ts":
`export const a = 0;`,
"/x.ts":
`import { foo as oFoo } from './other';
export const x = oFoo();
`
},
});