Skip to content

Commit

Permalink
clang-format: [JS] supports casts to types starting with punctuation …
Browse files Browse the repository at this point in the history
…("{[(").

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
  • Loading branch information
mprobst committed Aug 22, 2016
1 parent 13fa330 commit ed87d78
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/Format/TokenAnnotator.cpp
Expand Up @@ -2121,6 +2121,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
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;
Expand Down
3 changes: 3 additions & 0 deletions clang/unittests/Format/FormatTestJS.cpp
Expand Up @@ -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) {
Expand Down

0 comments on commit ed87d78

Please sign in to comment.