mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Fix(54376) (#54975)
This commit is contained in:
parent
48c356b452
commit
a602c668fb
@ -194,7 +194,7 @@ export interface ImportAdder {
|
||||
hasFixes(): boolean;
|
||||
addImportFromDiagnostic: (diagnostic: DiagnosticWithLocation, context: CodeFixContextBase) => void;
|
||||
addImportFromExportedSymbol: (exportedSymbol: Symbol, isValidTypeOnlyUseSite?: boolean) => void;
|
||||
writeFixes: (changeTracker: textChanges.ChangeTracker) => void;
|
||||
writeFixes: (changeTracker: textChanges.ChangeTracker, oldFileQuotePreference?: QuotePreference) => void;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
@ -345,8 +345,15 @@ function createImportAdderWorker(sourceFile: SourceFile, program: Program, useAu
|
||||
}
|
||||
}
|
||||
|
||||
function writeFixes(changeTracker: textChanges.ChangeTracker) {
|
||||
const quotePreference = getQuotePreference(sourceFile, preferences);
|
||||
function writeFixes(changeTracker: textChanges.ChangeTracker, oldFileQuotePreference?: QuotePreference) {
|
||||
let quotePreference: QuotePreference;
|
||||
if (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.
|
||||
quotePreference = oldFileQuotePreference;
|
||||
}
|
||||
else {
|
||||
quotePreference = getQuotePreference(sourceFile, preferences);
|
||||
}
|
||||
for (const fix of addToNamespace) {
|
||||
addNamespaceQualifier(changeTracker, sourceFile, fix);
|
||||
}
|
||||
|
||||
@ -254,7 +254,7 @@ function getNewStatementsAndRemoveFromOldFile(
|
||||
}
|
||||
}
|
||||
if (importAdder) {
|
||||
importAdder.writeFixes(changes);
|
||||
importAdder.writeFixes(changes, quotePreference);
|
||||
}
|
||||
if (imports.length && body.length) {
|
||||
return [
|
||||
|
||||
@ -22,7 +22,7 @@ verify.moveToFile({
|
||||
import { p } from './a';
|
||||
|
||||
|
||||
import { b } from "./other";
|
||||
import { b } from './other';
|
||||
|
||||
|
||||
const y: Date = p + b;
|
||||
|
||||
36
tests/cases/fourslash/moveToFile_consistentQuoteStyle.ts
Normal file
36
tests/cases/fourslash/moveToFile_consistentQuoteStyle.ts
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /bar.ts
|
||||
////export const tt = 2;
|
||||
|
||||
// @Filename: /a.ts
|
||||
////import { b } from './other';
|
||||
////const a = 1;
|
||||
////[|const c = a + b;|]
|
||||
|
||||
// @Filename: /other.ts
|
||||
////export const b = 2;
|
||||
|
||||
|
||||
verify.moveToFile({
|
||||
newFileContents: {
|
||||
"/a.ts":
|
||||
`export const a = 1;
|
||||
`,
|
||||
|
||||
"/bar.ts":
|
||||
`import { a } from './a';
|
||||
|
||||
import { b } from './other';
|
||||
|
||||
export const tt = 2;
|
||||
const c = a + b;
|
||||
`,
|
||||
},
|
||||
interactiveRefactorArguments: { targetFile: "/bar.ts" },
|
||||
|
||||
preferences: {
|
||||
quotePreference: "single",
|
||||
}
|
||||
});
|
||||
@ -25,7 +25,7 @@ y;`,
|
||||
"/src/dir2/bar.ts":
|
||||
`import { a } from '../dir1/a';
|
||||
|
||||
import { b } from "../dir1/other";
|
||||
import { b } from '../dir1/other';
|
||||
|
||||
|
||||
export const y = b + a;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user