From: Daniel Jasper Date: Thu, 27 Nov 2014 15:24:48 +0000 (+0000) Subject: clang-format: [JS] Try not to break in container literals. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4087432f8b74f9f738604a064c37825dba57b7d1;p=platform%2Fupstream%2Fllvm.git 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(); } }; llvm-svn: 222892 --- diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index d6c823e..718a019 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 6c8fd29..d678564 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/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) {