diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 591ac5c4719cb57079624014de83f6aa9ac8d5e0..ea869307289fc4063930da1f9da1fa41130a15ae 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 255f11e0ef3ed3017a20259c49e61724af798033..39e4ea8566b86cff212b289cf94f5352394282c7 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) {