]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Don't count shortened object literals as blocks.
authorDaniel Jasper <djasper@google.com>
Sun, 7 Feb 2016 22:17:13 +0000 (22:17 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 7 Feb 2016 22:17:13 +0000 (22:17 +0000)
Before:
  f({a},
    () => {
      g();  //
    });

After:
  f({a}, () => {
    g();  //
  });

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

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

index 2089d9d3165f3a21677471633bf73fdbab2db13a..a53cceb9a30f6d14ae55600df4761fccb2566ee2 100644 (file)
@@ -423,7 +423,7 @@ private:
   }
 
   void updateParameterCount(FormatToken *Left, FormatToken *Current) {
-    if (Current->is(tok::l_brace) && !Current->is(TT_DictLiteral))
+    if (Current->is(tok::l_brace) && Current->BlockKind == BK_Block)
       ++Left->BlockParameterCount;
     if (Current->is(tok::comma)) {
       ++Left->ParameterCount;
index 7f25d5921b3a71e46abe79d9c77814b626b1a786..7fad83aab12af08949078e2a274818e55524f63d 100644 (file)
@@ -200,6 +200,11 @@ TEST_F(FormatTestJS, ContainerLiterals) {
                "  b: 2,\n"
                "  [c]: 3,\n"
                "};");
+
+  // Object literals can leave out labels.
+  verifyFormat("f({a}, () => {\n"
+               "  g();  //\n"
+               "});");
 }
 
 TEST_F(FormatTestJS, MethodsInObjectLiterals) {