From a6b1f70c1eff7f8feeabe8ab598ce18a9f5e8d1e Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 27 Nov 2014 15:24:48 +0000 Subject: [PATCH] clang-format: [JS] Try not to break in container literals. Before: var obj = { fooooooooo: function(x) { return x.zIsTooLongForOneLineWithTheDeclarationLine(); } }; After: var obj = { fooooooooo: function(x) { return x.zIsTooLongForOneLineWithTheDeclarationLine(); } }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222892 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 ++ unittests/Format/FormatTestJS.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index d6c823e39b..718a019362 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1548,6 +1548,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, return 0; if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr)) return Line.MightBeFunctionDecl ? 50 : 500; + if (Left.is(tok::colon) && Left.is(TT_DictLiteral)) + return 100; if (Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket) return 100; diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 6c8fd2962a..d6785649cb 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -131,6 +131,11 @@ TEST_F(FormatTestJS, ContainerLiterals) { " //\n" " a\n" "};"); + verifyFormat("var obj = {\n" + " fooooooooo: function(x) {\n" + " return x.zIsTooLongForOneLineWithTheDeclarationLine();\n" + " }\n" + "};"); } TEST_F(FormatTestJS, SpacesInContainerLiterals) { -- 2.50.1