diff options
| author | Daniel Jasper <djasper@google.com> | 2015-03-15 13:59:51 +0000 | 
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2015-03-15 13:59:51 +0000 | 
| commit | bc46b939e647b9ded4ccad7de7694b388369291a (patch) | |
| tree | 93610082eaec190370a12b60099a6de8cfc333c1 | |
| parent | 60948b12bb91dc38750d3a75c81d79edb86eda86 (diff) | |
| download | bcm5719-llvm-bc46b939e647b9ded4ccad7de7694b388369291a.tar.gz bcm5719-llvm-bc46b939e647b9ded4ccad7de7694b388369291a.zip | |
clang-format: [JS] support cast syntax and type arguments.
Casts in TS syntax (foo = <type>bar;) should not be followed by
whitespace.
Patch by Martin Probst. Thank you.
llvm-svn: 232321
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 7 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 12 | 
2 files changed, 19 insertions, 0 deletions
| diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index c6c81a48912..911d52d7be5 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1779,6 +1779,13 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,      if ((Left.is(tok::l_brace) || Right.is(tok::r_brace)) &&          Line.First->isOneOf(Keywords.kw_import, tok::kw_export))        return false; +    if (Left.is(TT_TemplateCloser) && +        !Right.isOneOf(tok::l_brace, tok::comma, tok::l_square, +                       Keywords.kw_implements, Keywords.kw_extends)) +      // Type assertions ('<type>expr') are not followed by whitespace. Other +      // locations that should have whitespace following are identified by the +      // above set of follower tokens. +      return false;    } else if (Style.Language == FormatStyle::LK_Java) {      if (Left.is(tok::r_square) && Right.is(tok::l_brace))        return true; diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 045b280f187..57070245447 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -616,5 +616,17 @@ TEST_F(FormatTestJS, TemplateStrings) {    verifyFormat("var x = `hello` == `hello`;");  } +TEST_F(FormatTestJS, CastSyntax) { +  verifyFormat("var x = <type>foo;"); +} + +TEST_F(FormatTestJS, TypeArguments) { +  verifyFormat("class X<Y> {}"); +  verifyFormat("new X<Y>();"); +  verifyFormat("foo<Y>(a);"); +  verifyFormat("var x: X<Y>[];"); +  verifyFormat("class C extends D<E> implements F<G>, H<I> {}"); +} +  } // end namespace tooling  } // end namespace clang | 

