summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-05-22 09:10:04 +0000
committerDaniel Jasper <djasper@google.com>2014-05-22 09:10:04 +0000
commit25c29908626548cee8a40bd153bde2b4f98490d3 (patch)
tree794b119e0288f5478b2bfd794f01f3c4cb4fc186
parent643549ba9307e74cae7b5a5bf1711e469f3b190e (diff)
downloadclang-25c29908626548cee8a40bd153bde2b4f98490d3.tar.gz
clang-25c29908626548cee8a40bd153bde2b4f98490d3.tar.bz2
clang-25c29908626548cee8a40bd153bde2b4f98490d3.tar.xz
clang-format: [JS] Understand line breaks in concatenated strings.
Before: var literal = 'hello ' + 'world'; After: var literal = 'hello ' + 'world'; There is no reason to concatenated two string literals with a '+' unless the line break is intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209413 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Format/TokenAnnotator.cpp7
-rw-r--r--unittests/Format/FormatTestJS.cpp5
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index f3d655ace5..ce847d6427 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -1622,6 +1622,13 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
BeforeClosingBrace->isOneOf(tok::comma, tok::comment))
return true;
+ if (Style.Language == FormatStyle::LK_JavaScript) {
+ // FIXME: This might apply to other languages and token kinds.
+ if (Right.is(tok::char_constant) && Left.is(tok::plus) && Left.Previous &&
+ Left.Previous->is(tok::char_constant))
+ return true;
+ }
+
return false;
}
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp
index 33bfe06e5f..ecf4e69999 100644
--- a/unittests/Format/FormatTestJS.cpp
+++ b/unittests/Format/FormatTestJS.cpp
@@ -164,6 +164,11 @@ TEST_F(FormatTestJS, TryCatch) {
"}");
}
+TEST_F(FormatTestJS, StringLiteralConcatenation) {
+ verifyFormat("var literal = 'hello ' +\n"
+ " 'world';");
+}
+
TEST_F(FormatTestJS, RegexLiteralClassification) {
// Regex literals.
verifyFormat("var regex = /abc/;");