]> granicus.if.org Git - clang/commitdiff
clang-format: [JavaScript] Undo r291974 for JavaScript.
authorDaniel Jasper <djasper@google.com>
Mon, 30 Jan 2017 07:08:40 +0000 (07:08 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 30 Jan 2017 07:08:40 +0000 (07:08 +0000)
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('+');

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

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

index 7f1ac848f4f945cec3b31fe8bdf39d5fa980f008..05408bfa4f5643492262f527fc765aa79681557a 100644 (file)
@@ -199,7 +199,14 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
 
   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)
index 53800de9d2327973cdf2dcefdb7edb95795faa3f..8e33346d630bd15edbd3b39d38a88215a25ec6ca 100644 (file)
@@ -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"