From 4ace26b3754bea5f81194312b1a2f15ffd71fa8f Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 14 Jun 2016 13:54:38 +0000 Subject: [PATCH] clang-format: [JS] Fix failing format with TypeScript casts. Before, this could be formatted at all (with BracketAlignmentStyle AlwaysBreak): foo = [ 1, /* */ 2 ]; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272668 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 6 +++--- unittests/Format/FormatTestJS.cpp | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 7df3bdd781..fe7e001daa 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -319,9 +319,9 @@ private: Left->Type = TT_JsComputedPropertyName; } else if (Style.Language == FormatStyle::LK_Proto || (Parent && - Parent->isOneOf(TT_BinaryOperator, tok::at, tok::comma, - tok::l_paren, tok::l_square, tok::question, - tok::colon, tok::kw_return, + Parent->isOneOf(TT_BinaryOperator, TT_TemplateCloser, tok::at, + tok::comma, tok::l_paren, tok::l_square, + tok::question, tok::colon, tok::kw_return, // Should only be relevant to JavaScript: tok::kw_default))) { Left->Type = TT_ArrayInitializerLSquare; diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 8410a0c996..f71571c16a 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -1205,6 +1205,10 @@ TEST_F(FormatTestJS, TemplateStrings) { TEST_F(FormatTestJS, CastSyntax) { verifyFormat("var x = foo;"); verifyFormat("var x = foo as type;"); + verifyFormat("foo = [\n" + " 1, //\n" + " 2\n" + "];"); } TEST_F(FormatTestJS, TypeArguments) { -- 2.40.0