r262291 - clang-format: [JS] Support quoted object literal keys.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 29 20:19:47 PST 2016
Author: djasper
Date: Mon Feb 29 22:19:47 2016
New Revision: 262291
URL: http://llvm.org/viewvc/llvm-project?rev=262291&view=rev
Log:
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,
};
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=262291&r1=262290&r2=262291&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Feb 29 22:19:47 2016
@@ -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)
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=262291&r1=262290&r2=262291&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Feb 29 22:19:47 2016
@@ -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) {
More information about the cfe-commits
mailing list