From 85956fc1be4182c90bb670cb526154dac1fd1083 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 30 Jan 2017 07:08:40 +0000 Subject: [PATCH] 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('+'); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293465 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 9 ++++++++- unittests/Format/FormatTestJS.cpp | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 7f1ac848f4..05408bfa4f 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -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) diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 53800de9d2..8e33346d63 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -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" -- 2.40.0