From 41368e9e073dc419f62ae016b079a7b0288e4977 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 27 Nov 2014 15:37:42 +0000 Subject: [PATCH] clang-format: [JS] Contract fewer functions to a single line. Before: var someVariable = function(x) { return x.zIsTooLongForOneLineWithTheDeclarationLine(); }; After: var someVariable = function(x) { return x.zIsTooLongForOneLineWithTheDeclarationLine(); }; llvm-svn: 222893 --- clang/lib/Format/TokenAnnotator.cpp | 5 +++-- clang/unittests/Format/FormatTestJS.cpp | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 718a01936248..6c04a014a119 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1480,6 +1480,9 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, return 2; if (Left.is(tok::comma) && Left.NestingLevel == 0) return 3; + } else if (Style.Language == FormatStyle::LK_JavaScript) { + if (Right.is(Keywords.kw_function)) + return 100; } if (Left.is(tok::comma) || (Right.is(tok::identifier) && Right.Next && @@ -1548,8 +1551,6 @@ 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 d6785649cb37..0d29c178f8b0 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -232,6 +232,11 @@ TEST_F(FormatTestJS, FunctionLiterals) { " };\n" " }\n" "};"); + verifyFormat("{\n" + " var someVariable = function(x) {\n" + " return x.zIsTooLongForOneLineWithTheDeclarationLine();\n" + " };\n" + "}"); verifyFormat("var x = {a: function() { return 1; }};", getGoogleJSStyleWithColumns(38));