r239722 - clang-format: [JS] Tweak behavior for multiline array initializer parameters

Daniel Jasper djasper at google.com
Mon Jun 15 02:23:17 PDT 2015


Author: djasper
Date: Mon Jun 15 04:23:17 2015
New Revision: 239722

URL: http://llvm.org/viewvc/llvm-project?rev=239722&view=rev
Log:
clang-format: [JS] Tweak behavior for multiline array initializer parameters

Before:
  var someVariable = SomeFuntion(aaaa, [
    aaaaaaaaaaaaaaaaaaaaaaaaaaa,
    bbbbbbbbbbbbbbbbbbbbbbbbbbb,
    ccccccccccccccccccccccccccc
  ],
                                 aaaa);

After:
  var someVariable = SomeFuntion(aaaa,
                                 [
                                   aaaaaaaaaaaaaaaaaaaaaaaaaaa,
                                   bbbbbbbbbbbbbbbbbbbbbbbbbbb,
                                   ccccccccccccccccccccccccccc
                                 ],
                                 aaaa);

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=239722&r1=239721&r2=239722&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Jun 15 04:23:17 2015
@@ -688,7 +688,8 @@ unsigned ContinuationIndenter::moveState
   //     foo();
   //     bar();
   //   }, a, b, c);
-  if (Current.isNot(tok::comment) && Previous && Previous->is(tok::l_brace) &&
+  if (Current.isNot(tok::comment) && Previous &&
+      Previous->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) &&
       State.Stack.size() > 1) {
     if (State.Stack[State.Stack.size() - 2].NestedBlockInlined && Newline)
       for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i)

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=239722&r1=239721&r2=239722&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Jun 15 04:23:17 2015
@@ -278,6 +278,13 @@ TEST_F(FormatTestJS, ArrayLiterals) {
                "  bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
                "  ccccccccccccccccccccccccccc\n"
                "]);");
+  verifyFormat("var someVariable = SomeFuntion(aaaa,\n"
+               "                               [\n"
+               "                                 aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+               "                                 bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
+               "                                 ccccccccccccccccccccccccccc\n"
+               "                               ],\n"
+               "                               aaaa);");
 
   verifyFormat("someFunction([], {a: a});");
 }





More information about the cfe-commits mailing list