mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-11 09:24:19 -06:00
moveToNewFile: fix quotes for module specifiers (#60203)
This commit is contained in:
parent
c003609d59
commit
aeb74cc721
@ -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 {
|
||||
|
||||
24
tests/cases/fourslash/moveToNewFile_inferQuoteStyle2.ts
Normal file
24
tests/cases/fourslash/moveToNewFile_inferQuoteStyle2.ts
Normal 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":
|
||||
`
|
||||
`
|
||||
},
|
||||
});
|
||||
22
tests/cases/fourslash/moveToNewFile_moveNamedImport2.ts
Normal file
22
tests/cases/fourslash/moveToNewFile_moveNamedImport2.ts
Normal 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();
|
||||
`
|
||||
},
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user