]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Contract fewer functions to a single line.
authorDaniel Jasper <djasper@google.com>
Thu, 27 Nov 2014 15:37:42 +0000 (15:37 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 27 Nov 2014 15:37:42 +0000 (15:37 +0000)
Before:
  var someVariable =
      function(x) { return x.zIsTooLongForOneLineWithTheDeclarationLine(); };

After:
  var someVariable = function(x) {
    return x.zIsTooLongForOneLineWithTheDeclarationLine();
  };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222893 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp

index 718a0193624800df1c8f113cb8276e7640772a1c..6c04a014a11965c1444e1162da116134f2f8b153 100644 (file)
@@ -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;
index d6785649cb3714d01f10b5716f9007af53548ce5..0d29c178f8b0e026a3b0f724efdc62cae7618973 100644 (file)
@@ -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));