Hi djasper,
Casts in TS syntax (`foo = <type>bar;`) should not be followed by whitespace.
http://reviews.llvm.org/D8333
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1757,6 +1757,14 @@
return false;
if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
return false;
+ if (Left.is(TT_TemplateCloser) &&
+ Style.Language == FormatStyle::LK_JavaScript &&
+ !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;
return true;
}
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -613,5 +613,17 @@
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
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1757,6 +1757,14 @@
return false;
if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
return false;
+ if (Left.is(TT_TemplateCloser) &&
+ Style.Language == FormatStyle::LK_JavaScript &&
+ !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;
return true;
}
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -613,5 +613,17 @@
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
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits