[PATCH] D24804: clang-format: [JS] reserved words in method names.

Martin Probst via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 22 00:26:49 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL282138: clang-format: [JS] reserved words in method names. (authored by mprobst).

Changed prior to commit:
  https://reviews.llvm.org/D24804?vs=72061&id=72140#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24804

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp

Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -147,6 +147,21 @@
   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);");
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2125,6 +2125,10 @@
     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)))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24804.72140.patch
Type: text/x-patch
Size: 1439 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160922/0109eb3f/attachment-0001.bin>


More information about the cfe-commits mailing list