r288121 - clang-format: [JS] Properly format dict literals that skip labels.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 29 01:40:37 PST 2016


Author: djasper
Date: Tue Nov 29 03:40:36 2016
New Revision: 288121

URL: http://llvm.org/viewvc/llvm-project?rev=288121&view=rev
Log:
clang-format: [JS] Properly format dict literals that skip labels.

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=288121&r1=288120&r2=288121&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Nov 29 03:40:36 2016
@@ -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;
       }

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=288121&r1=288120&r2=288121&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Nov 29 03:40:36 2016
@@ -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) {




More information about the cfe-commits mailing list