r293465 - clang-format: [JavaScript] Undo r291974 for JavaScript.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 29 23:08:41 PST 2017


Author: djasper
Date: Mon Jan 30 01:08:40 2017
New Revision: 293465

URL: http://llvm.org/viewvc/llvm-project?rev=293465&view=rev
Log:
clang-format: [JavaScript] Undo r291974 for JavaScript.

This had significant negative consequences and I don't have a good
solution for it yet.

Before:
  var string =
      [
        'aaaaaa',
        'bbbbbb',
      ]
          .join('+');

After:
  var string = [
    'aaaaaa',
    'bbbbbb',
  ].join('+');

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=293465&r1=293464&r2=293465&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Jan 30 01:08:40 2017
@@ -199,7 +199,14 @@ bool ContinuationIndenter::mustBreak(con
 
   if (startsSegmentOfBuilderTypeCall(Current) &&
       (State.Stack.back().CallContinuation != 0 ||
-       State.Stack.back().BreakBeforeParameter))
+       State.Stack.back().BreakBeforeParameter) &&
+      // JavaScript is treated different here as there is a frequent pattern:
+      //   SomeFunction(function() {
+      //     ...
+      //   }.bind(...));
+      // FIXME: We should find a more generic solution to this problem.
+      !(State.Column <= NewLineColumn &&
+        Style.Language == FormatStyle::LK_JavaScript))
     return true;
 
   if (State.Column <= NewLineColumn)

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=293465&r1=293464&r2=293465&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Jan 30 01:08:40 2017
@@ -497,6 +497,11 @@ TEST_F(FormatTestJS, ArrayLiterals) {
                "    [];");
 
   verifyFormat("someFunction([], {a: a});");
+
+  verifyFormat("var string = [\n"
+               "  'aaaaaa',\n"
+               "  'bbbbbb',\n"
+               "].join('+');");
 }
 
 TEST_F(FormatTestJS, ColumnLayoutForArrayLiterals) {
@@ -587,6 +592,11 @@ TEST_F(FormatTestJS, FunctionLiterals) {
                "  doSomething();\n"
                "}, this));");
 
+  verifyFormat("SomeFunction(function() {\n"
+               "  foo();\n"
+               "  bar();\n"
+               "}.bind(this));");
+
   // FIXME: This is bad, we should be wrapping before "function() {".
   verifyFormat("someFunction(function() {\n"
                "  doSomething();  // break\n"




More information about the cfe-commits mailing list