From f34c48f369bc2a581caf4f57e219f75ace58d7d4 Mon Sep 17 00:00:00 2001
From: Daniel Jasper <djasper@google.com>
Date: Tue, 29 Nov 2016 09:40:36 +0000
Subject: [PATCH] clang-format: [JS] Properly format dict literals that skip
 labels.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288121 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Format/TokenAnnotator.cpp     | 3 +++
 unittests/Format/FormatTestJS.cpp | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index b241fe94909..57f30276b36 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -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;
       }
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp
index 90a12941bb1..6f494db71d1 100644
--- a/unittests/Format/FormatTestJS.cpp
+++ b/unittests/Format/FormatTestJS.cpp
@@ -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) {
-- 
GitLab