]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Try not to break in container literals.
authorDaniel Jasper <djasper@google.com>
Thu, 27 Nov 2014 15:24:48 +0000 (15:24 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 27 Nov 2014 15:24:48 +0000 (15:24 +0000)
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
unittests/Format/FormatTestJS.cpp

index d6c823e39b89d9612f1262f0c28b8448e997b1dc..718a0193624800df1c8f113cb8276e7640772a1c 100644 (file)
@@ -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;
index 6c8fd2962ad2b09ba3f0dd6c0e316bb64b5337dd..d6785649cb3714d01f10b5716f9007af53548ce5 100644 (file)
@@ -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) {