[PATCH] D24155: clang-format: [JS] merge requoting replacements.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 1 14:07:05 PDT 2016
mprobst created this revision.
mprobst added a reviewer: djasper.
mprobst added a subscriber: cfe-commits.
Herald added a subscriber: klimek.
When formatting source code that needs both requoting and reindentation,
merge the replacements to avoid erroring out for conflicting replacements.
https://reviews.llvm.org/D24155
Files:
lib/Format/Format.cpp
unittests/Format/FormatTestJS.cpp
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1318,6 +1318,13 @@
"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;
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -803,13 +803,14 @@
analyze(TokenAnnotator &Annotator,
SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
FormatTokenLexer &Tokens, tooling::Replacements &Result) override {
+ tooling::Replacements RunResult;
deriveLocalStyle(AnnotatedLines);
AffectedRangeMgr.computeAffectedLines(AnnotatedLines.begin(),
AnnotatedLines.end());
if (Style.Language == FormatStyle::LK_JavaScript &&
Style.JavaScriptQuotes != FormatStyle::JSQS_Leave)
- requoteJSStringLiteral(AnnotatedLines, Result);
+ requoteJSStringLiteral(AnnotatedLines, RunResult);
for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
Annotator.calculateFormattingInformation(*AnnotatedLines[i]);
@@ -826,7 +827,8 @@
UnwrappedLineFormatter(&Indenter, &Whitespaces, Style, Tokens.getKeywords(),
IncompleteFormat)
.format(AnnotatedLines);
- return Whitespaces.generateReplacements();
+ RunResult = RunResult.merge(Whitespaces.generateReplacements());
+ return RunResult;
}
private:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24155.70066.patch
Type: text/x-patch
Size: 2016 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160901/52e3761c/attachment.bin>
More information about the cfe-commits
mailing list