r256753 - clang-format: [JS] Improve empty array literal detection.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 4 05:11:42 PST 2016


Author: djasper
Date: Mon Jan  4 07:11:41 2016
New Revision: 256753

URL: http://llvm.org/viewvc/llvm-project?rev=256753&view=rev
Log:
clang-format: [JS] Improve empty array literal detection.

Previously, the [] in the following example were recognized as an array
subscript leading to weird indentation.

Before:
  var aaaa = aaaaa || // wrap
                          [];

After:
  var aaaa = aaaaa || // wrap
             [];

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=256753&r1=256752&r2=256753&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jan  4 07:11:41 2016
@@ -287,9 +287,9 @@ private:
         Left->Type = TT_JsComputedPropertyName;
       } else if (Style.Language == FormatStyle::LK_Proto ||
                  (Parent &&
-                  Parent->isOneOf(tok::at, tok::equal, tok::comma, tok::l_paren,
-                                  tok::l_square, tok::question, tok::colon,
-                                  tok::kw_return))) {
+                  Parent->isOneOf(TT_BinaryOperator, tok::at, tok::comma,
+                                  tok::l_paren, tok::l_square, tok::question,
+                                  tok::colon, tok::kw_return))) {
         Left->Type = TT_ArrayInitializerLSquare;
       } else {
         BindingIncrease = 10;

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=256753&r1=256752&r2=256753&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Jan  4 07:11:41 2016
@@ -310,6 +310,8 @@ TEST_F(FormatTestJS, ArrayLiterals) {
                "      ccccccccccccccccccccccccccc\n"
                "    ],\n"
                "    aaaa);");
+  verifyFormat("var aaaa = aaaaa ||  // wrap\n"
+               "    [];");
 
   verifyFormat("someFunction([], {a: a});");
 }




More information about the cfe-commits mailing list