mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Fix(54376) (#54975)
This commit is contained in:
@@ -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 [
|
||||
|
||||
Reference in New Issue
Block a user