r282138 - clang-format: [JS] reserved words in method names.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 22 00:18:01 PDT 2016
Author: mprobst
Date: Thu Sep 22 02:18:00 2016
New Revision: 282138
URL: http://llvm.org/viewvc/llvm-project?rev=282138&view=rev
Log:
clang-format: [JS] reserved words in method names.
Summary:
Before:
class X {
delete () {
...
}
}
After:
class X {
delete() {
...
}
}
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D24804
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=282138&r1=282137&r2=282138&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Sep 22 02:18:00 2016
@@ -2125,6 +2125,10 @@ bool TokenAnnotator::spaceRequiredBefore
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)))
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=282138&r1=282137&r2=282138&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Thu Sep 22 02:18:00 2016
@@ -147,6 +147,21 @@ TEST_F(FormatTestJS, ReservedWords) {
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);");
More information about the cfe-commits
mailing list