r232321 - clang-format: [JS] support cast syntax and type arguments.
Daniel Jasper
djasper at google.com
Sun Mar 15 06:59:51 PDT 2015
Author: djasper
Date: Sun Mar 15 08:59:51 2015
New Revision: 232321
URL: http://llvm.org/viewvc/llvm-project?rev=232321&view=rev
Log:
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.
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=232321&r1=232320&r2=232321&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sun Mar 15 08:59:51 2015
@@ -1779,6 +1779,13 @@ bool TokenAnnotator::spaceRequiredBefore
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;
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=232321&r1=232320&r2=232321&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Sun Mar 15 08:59:51 2015
@@ -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
More information about the cfe-commits
mailing list