r279436 - clang-format: [JS] supports casts to types starting with punctuation ("{[(").
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 22 07:23:30 PDT 2016
Author: mprobst
Date: Mon Aug 22 09:23:30 2016
New Revision: 279436
URL: http://llvm.org/viewvc/llvm-project?rev=279436&view=rev
Log:
clang-format: [JS] supports casts to types starting with punctuation ("{[(").
Before:
x as{x: number}
After:
x as {x: number}
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D23761
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=279436&r1=279435&r2=279436&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Aug 22 09:23:30 2016
@@ -2121,6 +2121,9 @@ bool TokenAnnotator::spaceRequiredBefore
Keywords.kw_of, tok::kw_const) &&
(!Left.Previous || !Left.Previous->is(tok::period)))
return true;
+ if (Left.is(Keywords.kw_as) &&
+ Right.isOneOf(tok::l_square, tok::l_brace, tok::l_paren))
+ return true;
if (Left.is(tok::kw_default) && Left.Previous &&
Left.Previous->is(tok::kw_export))
return true;
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=279436&r1=279435&r2=279436&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Aug 22 09:23:30 2016
@@ -1219,6 +1219,9 @@ TEST_F(FormatTestJS, CastSyntax) {
" 2\n"
"];");
verifyFormat("var x = [{x: 1} as type];");
+ verifyFormat("x = x as [a, b];");
+ verifyFormat("x = x as {a: string};");
+ verifyFormat("x = x as (string);");
}
TEST_F(FormatTestJS, TypeArguments) {
More information about the cfe-commits
mailing list