]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Improve empty array literal detection.
authorDaniel Jasper <djasper@google.com>
Mon, 4 Jan 2016 13:11:41 +0000 (13:11 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 4 Jan 2016 13:11:41 +0000 (13:11 +0000)
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
             [];

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

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

index badba16a891bd052d06e32066db32dda28226f4b..da0fdb91704571189b11b272ffad948fa081970f 100644 (file)
@@ -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;
index cba2ce3370c9e71df7e4abedf970a90df05f7ac1..d42eed6048f9eff1b311dc7422a783934a3b0118 100644 (file)
@@ -310,6 +310,8 @@ TEST_F(FormatTestJS, ArrayLiterals) {
                "      ccccccccccccccccccccccccccc\n"
                "    ],\n"
                "    aaaa);");
+  verifyFormat("var aaaa = aaaaa ||  // wrap\n"
+               "    [];");
 
   verifyFormat("someFunction([], {a: a});");
 }