Fix(54376) (#54975)

This commit is contained in:
navya9singh
2023-07-12 10:00:32 -07:00
committed by GitHub
parent 48c356b452
commit a602c668fb
5 changed files with 49 additions and 6 deletions

View File

@@ -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);
}

View File

@@ -254,7 +254,7 @@ function getNewStatementsAndRemoveFromOldFile(
}
}
if (importAdder) {
importAdder.writeFixes(changes);
importAdder.writeFixes(changes, quotePreference);
}
if (imports.length && body.length) {
return [