r256758 - clang-format: [JS] Support ES6 exports of array literals.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 4 07:51:56 PST 2016
Author: djasper
Date: Mon Jan 4 09:51:56 2016
New Revision: 256758
URL: http://llvm.org/viewvc/llvm-project?rev=256758&view=rev
Log:
clang-format: [JS] Support ES6 exports of array literals.
Before:
export default[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb];
export default[];
After:
export default [
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
];
export default [];
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=256758&r1=256757&r2=256758&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jan 4 09:51:56 2016
@@ -289,7 +289,9 @@ private:
(Parent &&
Parent->isOneOf(TT_BinaryOperator, tok::at, tok::comma,
tok::l_paren, tok::l_square, tok::question,
- tok::colon, tok::kw_return))) {
+ tok::colon, tok::kw_return,
+ // Should only be relevant to JavaScript:
+ tok::kw_default))) {
Left->Type = TT_ArrayInitializerLSquare;
} else {
BindingIncrease = 10;
@@ -1999,6 +2001,8 @@ bool TokenAnnotator::spaceRequiredBefore
if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, TT_JsFatArrow,
Keywords.kw_in))
return true;
+ if (Left.is(tok::kw_default) && Right.is(TT_ArrayInitializerLSquare))
+ return true; // For "export default [];".
if (Left.is(Keywords.kw_is) && Right.is(tok::l_brace))
return true;
if (Right.isOneOf(TT_JsTypeColon, TT_JsTypeOptionalQuestion))
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=256758&r1=256757&r2=256758&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Jan 4 09:51:56 2016
@@ -865,6 +865,11 @@ TEST_F(FormatTestJS, Modules) {
" // adsdasd\n"
" BAZ\n"
"}");
+ verifyFormat("export default [\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
+ "];");
+ verifyFormat("export default [];");
}
TEST_F(FormatTestJS, TemplateStrings) {
More information about the cfe-commits
mailing list