]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Fix failing format with TypeScript casts.
authorDaniel Jasper <djasper@google.com>
Tue, 14 Jun 2016 13:54:38 +0000 (13:54 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 14 Jun 2016 13:54:38 +0000 (13:54 +0000)
Before, this could be formatted at all (with BracketAlignmentStyle
AlwaysBreak):

  foo = <Bar[]>[
    1, /* */
    2
  ];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272668 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp

index 7df3bdd7816eaf07719f7ec535ce69741fea792c..fe7e001daaf74d6b5347b2aa0837a210cd0cd9d1 100644 (file)
@@ -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;
index 8410a0c9967ca8ec8d3d946bdad60cf4fe67c480..f71571c16a32207afb7a410ec95eab1d738d3b39 100644 (file)
@@ -1205,6 +1205,10 @@ TEST_F(FormatTestJS, TemplateStrings) {
 TEST_F(FormatTestJS, CastSyntax) {
   verifyFormat("var x = <type>foo;");
   verifyFormat("var x = foo as type;");
+  verifyFormat("foo = <Bar[]>[\n"
+               "  1,  //\n"
+               "  2\n"
+               "];");
 }
 
 TEST_F(FormatTestJS, TypeArguments) {