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,
  };

llvm-svn: 262291
This commit is contained in:
Daniel Jasper 2016-03-01 04:19:47 +00:00
parent d7511c8a22
commit b18425bf96
2 changed files with 9 additions and 1 deletions

View File

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

View File

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