From ed5f86df379b6be25201f26e2776a43ce549d62a Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 1 Mar 2016 04:19:47 +0000 Subject: [PATCH] clang-format: [JS] Support quoted object literal keys. Before: var x = { a: a, b: b, 'c': c, }; After: var x = { a: a, b: b, 'c': c, }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262291 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 3 ++- unittests/Format/FormatTestJS.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 591ac5c471..ea86930728 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -409,7 +409,8 @@ private: (!Contexts.back().ColonIsDictLiteral || Style.Language != FormatStyle::LK_Cpp)) || Style.Language == FormatStyle::LK_Proto) && - Previous->Tok.getIdentifierInfo()) + (Previous->Tok.getIdentifierInfo() || + Previous->is(tok::char_constant))) Previous->Type = TT_SelectorName; if (CurrentToken->is(tok::colon) || Style.Language == FormatStyle::LK_JavaScript) diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 255f11e0ef..39e4ea8566 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -205,6 +205,13 @@ TEST_F(FormatTestJS, ContainerLiterals) { verifyFormat("f({a}, () => {\n" " g(); //\n" "});"); + + // Keys can be quoted. + verifyFormat("var x = {\n" + " a: a,\n" + " b: b,\n" + " 'c': c,\n" + "};"); } TEST_F(FormatTestJS, MethodsInObjectLiterals) { -- 2.40.0