r296664 - clang-format: [JS] Properly format object literals with shorthands.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 1 11:47:28 PST 2017
Author: djasper
Date: Wed Mar 1 13:47:28 2017
New Revision: 296664
URL: http://llvm.org/viewvc/llvm-project?rev=296664&view=rev
Log:
clang-format: [JS] Properly format object literals with shorthands.
Before:
return {
a,
b: 'b', c,
};
After:
return {
a,
b: 'b',
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=296664&r1=296663&r2=296664&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Mar 1 13:47:28 2017
@@ -1517,13 +1517,14 @@ private:
return prec::Conditional;
if (NextNonComment && NextNonComment->is(tok::colon) &&
NextNonComment->is(TT_DictLiteral))
- return prec::Comma;
+ return prec::Assignment;
+ if (Current->is(TT_JsComputedPropertyName))
+ return prec::Assignment;
if (Current->is(TT_LambdaArrow))
return prec::Comma;
if (Current->is(TT_JsFatArrow))
return prec::Assignment;
- if (Current->isOneOf(tok::semi, TT_InlineASMColon, TT_SelectorName,
- TT_JsComputedPropertyName) ||
+ if (Current->isOneOf(tok::semi, TT_InlineASMColon, TT_SelectorName) ||
(Current->is(tok::comment) && NextNonComment &&
NextNonComment->is(TT_SelectorName)))
return 0;
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=296664&r1=296663&r2=296664&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Mar 1 13:47:28 2017
@@ -278,6 +278,11 @@ TEST_F(FormatTestJS, ContainerLiterals)
" aaa,\n"
" aaa,\n"
"};");
+ verifyFormat("return {\n"
+ " a,\n"
+ " b: 'b',\n"
+ " c,\n"
+ "};");
}
TEST_F(FormatTestJS, MethodsInObjectLiterals) {
More information about the cfe-commits
mailing list