]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Improve line-flow when calling functions on array literals.
authorDaniel Jasper <djasper@google.com>
Mon, 11 Jan 2016 11:00:58 +0000 (11:00 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 11 Jan 2016 11:00:58 +0000 (11:00 +0000)
Before:
  return [
    aaaaaaaaaaaaaaaaaaaaaa
  ].aaaaaaa(function() {
     //
   })
   .bbbbbb();

After:
  return [aaaaaaaaaaaaaaaaaaaaaa]
      .aaaaaaa(function() {
//
      })
      .bbbbbb();

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

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTestJS.cpp

index ff2569d41aab8b7a427369eef4413abcd0edf7ff..cb5999e60ef93c43efa23dee115eb0239141361c 100644 (file)
@@ -178,13 +178,15 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
     return true;
 
   unsigned NewLineColumn = getNewLineColumn(State);
-  if (State.Column <= NewLineColumn)
-    return false;
-
   if (Current.isMemberAccess() &&
-      State.Column + getLengthToNextOperator(Current) > Style.ColumnLimit)
+      State.Column + getLengthToNextOperator(Current) > Style.ColumnLimit &&
+      (State.Column > NewLineColumn ||
+       Current.NestingLevel < State.StartOfLineLevel))
     return true;
 
+  if (State.Column <= NewLineColumn)
+    return false;
+
   if (Style.AlwaysBreakBeforeMultilineStrings &&
       (NewLineColumn == State.FirstIndent + Style.ContinuationIndentWidth ||
        Previous.is(tok::comma) || Current.NestingLevel < 2) &&
index 4e974d7285ded0d118b85014dbebb556dae3f51a..9477580016a676c28f785982e3a25128c5a360a2 100644 (file)
@@ -530,6 +530,12 @@ TEST_F(FormatTestJS, MultipleFunctionLiterals) {
   verifyFormat("getSomeLongPromise()\n"
                "    .then(function(value) { body(); })\n"
                "    .thenCatch(function(error) { body(); });");
+
+  verifyFormat("return [aaaaaaaaaaaaaaaaaaaaaa]\n"
+               "    .aaaaaaa(function() {\n"
+               "      //\n"
+               "    })\n"
+               "    .bbbbbb();");
 }
 
 TEST_F(FormatTestJS, ArrowFunctions) {