From 664ce273d061dfa586a0f194f46e409aeb7ea8c8 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 5 Sep 2014 09:27:38 +0000 Subject: [PATCH] clang-format: [JS] Format embedded function literals more efficently. Before: return { a: a, link: function() { f(); // }, link: function() { f(); // } }; After: return { a: a, link: function() { f(); // }, link: function() { f(); // } }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217238 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 3 ++- unittests/Format/FormatTestJS.cpp | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 828e750762..afd20b22e3 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -643,7 +643,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, State.Stack[State.Stack.size() - 2].JSFunctionInlined = false; } if (Current.TokenText == "function") - State.Stack.back().JSFunctionInlined = !Newline; + State.Stack.back().JSFunctionInlined = + !Newline && Previous && Previous->Type != TT_DictLiteral; } moveStatePastFakeLParens(State, Newline); diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index bd931aaf0a..b161699d94 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -110,14 +110,12 @@ TEST_F(FormatTestJS, ContainerLiterals) { "};"); verifyFormat("return {\n" " a: a,\n" - " link:\n" - " function() {\n" - " f(); //\n" - " },\n" - " link:\n" - " function() {\n" - " f(); //\n" - " }\n" + " link: function() {\n" + " f(); //\n" + " },\n" + " link: function() {\n" + " f(); //\n" + " }\n" "};"); verifyFormat("var stuff = {\n" " // comment for update\n" -- 2.40.0