Author: djasper Date: Tue Jan 31 06:07:35 2017 New Revision: 293618 URL: http://llvm.org/viewvc/llvm-project?rev=293618&view=rev Log: clang-format: [JS] Fix incorrect line break in template strings.
Before: var f = `aaaa ${a ? 'a' : 'b' }`; After: var f = `aaaa ${a ? 'a' : 'b'}`; Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTestJS.cpp Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=293618&r1=293617&r2=293618&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jan 31 06:07:35 2017 @@ -2388,6 +2388,11 @@ bool TokenAnnotator::mustBreakBefore(con if (Right.is(tok::plus) && Left.is(tok::string_literal) && Right.Next && Right.Next->is(tok::string_literal)) return true; + } else if (Style.Language == FormatStyle::LK_Cpp || + Style.Language == FormatStyle::LK_ObjC) { + if (Left.isStringLiteral() && + (Right.isStringLiteral() || Right.is(TT_ObjCStringLiteral))) + return true; } // If the last token before a '}' is a comma or a trailing comment, the @@ -2411,9 +2416,6 @@ bool TokenAnnotator::mustBreakBefore(con (Right.NewlinesBefore > 0 && Right.HasUnescapedNewline); if (Left.isTrailingComment()) return true; - if (Left.isStringLiteral() && - (Right.isStringLiteral() || Right.is(TT_ObjCStringLiteral))) - return true; if (Right.Previous->IsUnterminatedLiteral) return true; if (Right.is(tok::lessless) && Right.Next && Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=293618&r1=293617&r2=293618&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTestJS.cpp (original) +++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Jan 31 06:07:35 2017 @@ -1388,6 +1388,10 @@ TEST_F(FormatTestJS, TemplateStrings) { "var y;"); // Escaped dollar. verifyFormat("var x = ` \\${foo}`;\n"); + + // The token stream can contain two string_literals in sequence, but that + // doesn't mean that they are implicitly concatenated in JavaScript. + verifyFormat("var f = `aaaa ${a ? 'a' : 'b'}`;"); } TEST_F(FormatTestJS, TemplateStringASI) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits