From: Daniel Jasper Date: Tue, 29 Nov 2016 09:40:36 +0000 (+0000) Subject: clang-format: [JS] Properly format dict literals that skip labels. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f34c48f369bc2a581caf4f57e219f75ace58d7d4;p=clang 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 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index b241fe9490..57f30276b3 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 90a12941bb..6f494db71d 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) {