diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 26ef38d60c23bc1af0d4d24a47f19917d217ba5f..625f8554defb4178ced21193151f76de32572948 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -801,14 +801,15 @@ public: tooling::Replacements analyze(TokenAnnotator &Annotator, SmallVectorImpl<AnnotatedLine *> &AnnotatedLines, - FormatTokenLexer &Tokens, tooling::Replacements &Result) override { + FormatTokenLexer &Tokens) override { + tooling::Replacements RequoteReplaces; deriveLocalStyle(AnnotatedLines); AffectedRangeMgr.computeAffectedLines(AnnotatedLines.begin(), AnnotatedLines.end()); if (Style.Language == FormatStyle::LK_JavaScript && Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) - requoteJSStringLiteral(AnnotatedLines, Result); + requoteJSStringLiteral(AnnotatedLines, RequoteReplaces); for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) { Annotator.calculateFormattingInformation(*AnnotatedLines[i]); @@ -825,7 +826,7 @@ public: UnwrappedLineFormatter(&Indenter, &Whitespaces, Style, Tokens.getKeywords(), IncompleteFormat) .format(AnnotatedLines); - return Whitespaces.generateReplacements(); + return RequoteReplaces.merge(Whitespaces.generateReplacements()); } private: @@ -997,7 +998,7 @@ public: tooling::Replacements analyze(TokenAnnotator &Annotator, SmallVectorImpl<AnnotatedLine *> &AnnotatedLines, - FormatTokenLexer &Tokens, tooling::Replacements &Result) override { + FormatTokenLexer &Tokens) override { // FIXME: in the current implementation the granularity of affected range // is an annotated line. However, this is not sufficient. Furthermore, // redundant code introduced by replacements does not necessarily diff --git a/lib/Format/SortJavaScriptImports.cpp b/lib/Format/SortJavaScriptImports.cpp index 2a90e9ab760464f1254ec763dc773bf634226175..42089c522ec8f2201d0db6b4c4a3e40243a64601 100644 --- a/lib/Format/SortJavaScriptImports.cpp +++ b/lib/Format/SortJavaScriptImports.cpp @@ -127,7 +127,7 @@ public: tooling::Replacements analyze(TokenAnnotator &Annotator, SmallVectorImpl<AnnotatedLine *> &AnnotatedLines, - FormatTokenLexer &Tokens, tooling::Replacements &) override { + FormatTokenLexer &Tokens) override { tooling::Replacements Result; AffectedRangeMgr.computeAffectedLines(AnnotatedLines.begin(), AnnotatedLines.end()); @@ -282,7 +282,6 @@ private: SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) { SmallVector<JsModuleReference, 16> References; SourceLocation Start; - bool FoundLines = false; AnnotatedLine *FirstNonImportLine = nullptr; bool AnyImportAffected = false; for (auto Line : AnnotatedLines) { @@ -296,7 +295,6 @@ private: Start = Line->First->Tok.getLocation(); if (!Current) continue; // Only comments on this line. - FoundLines = true; JsModuleReference Reference; Reference.Range.setBegin(Start); if (!parseModuleReference(Keywords, Reference)) { diff --git a/lib/Format/TokenAnalyzer.cpp b/lib/Format/TokenAnalyzer.cpp index 7baba62f0a8b2e3cc1a516e98033250be1748392..d3122ca2eeb73dc9382269efebbe6f63508ee959 100644 --- a/lib/Format/TokenAnalyzer.cpp +++ b/lib/Format/TokenAnalyzer.cpp @@ -107,7 +107,7 @@ tooling::Replacements TokenAnalyzer::process() { } tooling::Replacements RunResult = - analyze(Annotator, AnnotatedLines, Tokens, Result); + analyze(Annotator, AnnotatedLines, Tokens); DEBUG({ llvm::dbgs() << "Replacements for run " << Run << ":\n"; diff --git a/lib/Format/TokenAnalyzer.h b/lib/Format/TokenAnalyzer.h index c1aa9c594fc3e3153f8cf75e2df6fcec1cdcb98f..aef1ae316396bc06df5d852bd5b0cb59a757eb1d 100644 --- a/lib/Format/TokenAnalyzer.h +++ b/lib/Format/TokenAnalyzer.h @@ -87,7 +87,7 @@ protected: virtual tooling::Replacements analyze(TokenAnnotator &Annotator, SmallVectorImpl<AnnotatedLine *> &AnnotatedLines, - FormatTokenLexer &Tokens, tooling::Replacements &Result) = 0; + FormatTokenLexer &Tokens) = 0; void consumeUnwrappedLine(const UnwrappedLine &TheLine) override; diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 60063934cd9acf4f1e4c9e8844cb0cb8a67bc5a5..ed227852ef4cb07a0949b26e66fa734b04484705 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -1334,6 +1334,13 @@ TEST_F(FormatTestJS, RequoteStringsSingle) { "let x = \"single\";\n"); } +TEST_F(FormatTestJS, RequoteAndIndent) { + verifyFormat("let x = someVeryLongFunctionThatGoesOnAndOn(\n" + " 'double quoted string that needs wrapping');", + "let x = someVeryLongFunctionThatGoesOnAndOn(" + "\"double quoted string that needs wrapping\");"); +} + TEST_F(FormatTestJS, RequoteStringsDouble) { FormatStyle DoubleQuotes = getGoogleStyle(FormatStyle::LK_JavaScript); DoubleQuotes.JavaScriptQuotes = FormatStyle::JSQS_Double;