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
@@ -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)
@@ -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) {