]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Properly format dict literals that skip labels.
authorDaniel Jasper <djasper@google.com>
Tue, 29 Nov 2016 09:40:36 +0000 (09:40 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 29 Nov 2016 09:40:36 +0000 (09:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288121 91177308-0d34-0410-b5e6-96231b3b80d8

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

index b241fe94909f792ed465d6c2c381940879ebbe6d..57f30276b364a622cc61f46bd73dd0e67b4180a8 100644 (file)
@@ -442,6 +442,9 @@ private:
               Style.Language == FormatStyle::LK_JavaScript)
             Left->Type = TT_DictLiteral;
         }
+        if (CurrentToken->is(tok::comma) &&
+            Style.Language == FormatStyle::LK_JavaScript)
+          Left->Type = TT_DictLiteral;
         if (!consumeToken())
           return false;
       }
index 90a12941bb12c580207e30431ef74bc4953aa63d..6f494db71d156d0d8a94a10659adc7c273339e68 100644 (file)
@@ -259,6 +259,13 @@ TEST_F(FormatTestJS, ContainerLiterals) {
                "  b: b,\n"
                "  'c': c,\n"
                "};");
+
+  // Dict literals can skip the label names.
+  verifyFormat("var x = {\n"
+               "  aaa,\n"
+               "  aaa,\n"
+               "  aaa,\n"
+               "};");
 }
 
 TEST_F(FormatTestJS, MethodsInObjectLiterals) {