`asserts` is a pseudo keyword in TypeScript used in return types.
Wrapping after it triggers automatic semicolon insertion, which
breaks the code semantics/syntax.
`asserts` is different from other pseudo keywords in that it is
specific to TS and only carries meaning in a very specific location.
Thus introducing a token type is probably overkill.
Differential Revision: https://reviews.llvm.org/D100953
Left.isOneOf(tok::r_square, tok::r_paren)) &&
Right.isOneOf(tok::l_square, tok::l_paren))
return false; // Otherwise automatic semicolon insertion would trigger.
+ if (NonComment && NonComment->is(tok::identifier) &&
+ NonComment->TokenText == "asserts")
+ return false;
if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
return false;
if (Left.is(TT_JsTypeColon))
"}\n");
}
+TEST_F(FormatTestJS, NoBreakAfterAsserts) {
+ verifyFormat(
+ "interface Assertable<State extends {}> {\n"
+ " assert<ExportedState extends {}, DependencyState extends State = "
+ "State>(\n"
+ " callback: Callback<ExportedState, DependencyState>):\n"
+ " asserts this is ExtendedState<DependencyState&ExportedState>;\n"
+ "}\n",
+ "interface Assertable<State extends {}> {\n"
+ " assert<ExportedState extends {}, DependencyState extends State = "
+ "State>(callback: Callback<ExportedState, DependencyState>): asserts "
+ "this is ExtendedState<DependencyState&ExportedState>;\n"
+ "}\n");
+}
+
} // namespace format
} // end namespace clang