Summary:
Before:
class X {
delete () {
...
}
}
After:
class X {
delete() {
...
}
}
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D24804
llvm-svn: 282138
if (Right.is(tok::star) &&
Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))
return false;
+ // JS methods can use some keywords as names (e.g. `delete()`).
+ if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
+ Left.Tok.getIdentifierInfo())
+ return false;
if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
Keywords.kw_of, tok::kw_const) &&
(!Left.Previous || !Left.Previous->is(tok::period)))
verifyFormat("x = interface instanceof y;");
}
+TEST_F(FormatTestJS, ReservedWordsMethods) {
+ verifyFormat(
+ "class X {\n"
+ " delete() {\n"
+ " x();\n"
+ " }\n"
+ " interface() {\n"
+ " x();\n"
+ " }\n"
+ " let() {\n"
+ " x();\n"
+ " }\n"
+ "}\n");
+}
+
TEST_F(FormatTestJS, CppKeywords) {
// Make sure we don't mess stuff up because of C++ keywords.
verifyFormat("return operator && (aa);");