diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index b241fe94909f..57f30276b364 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 90a12941bb12..6f494db71d15 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/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) {