r238835 - clang-format: [JS] Fix another regression when detecting array literals.

Daniel Jasper djasper at google.com
Tue Jun 2 07:20:09 PDT 2015


Author: djasper
Date: Tue Jun  2 09:20:08 2015
New Revision: 238835

URL: http://llvm.org/viewvc/llvm-project?rev=238835&view=rev
Log:
clang-format: [JS] Fix another regression when detecting array literals.

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=238835&r1=238834&r2=238835&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jun  2 09:20:08 2015
@@ -276,11 +276,12 @@ private:
       if (StartsObjCMethodExpr) {
         Left->Type = TT_ObjCMethodExpr;
       } else if (Style.Language == FormatStyle::LK_JavaScript && Parent &&
+                 Contexts.back().ContextKind == tok::l_brace &&
                  Parent->isOneOf(tok::l_brace, tok::comma)) {
         Left->Type = TT_JsComputedPropertyName;
       } else if (Parent &&
                  Parent->isOneOf(tok::at, tok::equal, tok::comma,
-                                 tok::l_paren)) {
+                                 tok::l_paren, tok::question, tok::colon)) {
         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=238835&r1=238834&r2=238835&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Jun  2 09:20:08 2015
@@ -257,6 +257,11 @@ TEST_F(FormatTestJS, ArrayLiterals) {
                "  bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
                "  ccccccccccccccccccccccccccc\n"
                "]);");
+  verifyFormat("var someVariable = SomeFuntion(aaaa, [\n"
+               "  aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+               "  bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
+               "  ccccccccccccccccccccccccccc\n"
+               "]);");
 }
 
 TEST_F(FormatTestJS, FunctionLiterals) {





More information about the cfe-commits mailing list