Skip to content

Commit ed87d78

Browse files
committedAug 22, 2016
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 llvm-svn: 279436
1 parent 13fa330 commit ed87d78

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed
 

‎clang/lib/Format/TokenAnnotator.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
21212121
Keywords.kw_of, tok::kw_const) &&
21222122
(!Left.Previous || !Left.Previous->is(tok::period)))
21232123
return true;
2124+
if (Left.is(Keywords.kw_as) &&
2125+
Right.isOneOf(tok::l_square, tok::l_brace, tok::l_paren))
2126+
return true;
21242127
if (Left.is(tok::kw_default) && Left.Previous &&
21252128
Left.Previous->is(tok::kw_export))
21262129
return true;

‎clang/unittests/Format/FormatTestJS.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,9 @@ TEST_F(FormatTestJS, CastSyntax) {
12191219
" 2\n"
12201220
"];");
12211221
verifyFormat("var x = [{x: 1} as type];");
1222+
verifyFormat("x = x as [a, b];");
1223+
verifyFormat("x = x as {a: string};");
1224+
verifyFormat("x = x as (string);");
12221225
}
12231226

12241227
TEST_F(FormatTestJS, TypeArguments) {

0 commit comments

Comments
 (0)
Please sign in to comment.