r222890 - clang-format: [JS] new and delete are valid function names.

Daniel Jasper djasper at google.com
Thu Nov 27 06:55:18 PST 2014


Author: djasper
Date: Thu Nov 27 08:55:17 2014
New Revision: 222890

URL: http://llvm.org/viewvc/llvm-project?rev=222890&view=rev
Log:
clang-format: [JS] new and delete are valid function names.

Before:
  someObject.new ();
  someObject.delete ();

After:
  someObject.new();
  someObject.delete();

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=222890&r1=222889&r2=222890&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Nov 27 08:55:17 2014
@@ -1671,12 +1671,11 @@ bool TokenAnnotator::spaceRequiredBetwee
   if (Right.is(tok::l_paren)) {
     if (Left.is(tok::r_paren) && Left.is(TT_AttributeParen))
       return true;
-    return Line.Type == LT_ObjCDecl ||
-           Left.isOneOf(tok::kw_new, tok::kw_delete, tok::semi) ||
+    return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
            (Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
             (Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while,
                           tok::kw_switch, tok::kw_case) ||
-             (Left.is(tok::kw_catch) &&
+             (Left.isOneOf(tok::kw_catch, tok::kw_new, tok::kw_delete) &&
               (!Left.Previous || Left.Previous->isNot(tok::period))) ||
              Left.IsForEachMacro)) ||
            (Style.SpaceBeforeParens == FormatStyle::SBPO_Always &&

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=222890&r1=222889&r2=222890&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Thu Nov 27 08:55:17 2014
@@ -361,6 +361,8 @@ TEST_F(FormatTestJS, TryCatch) {
 
   // But, of course, "catch" is a perfectly fine function name in JavaScript.
   verifyFormat("someObject.catch();");
+  verifyFormat("someObject.new();");
+  verifyFormat("someObject.delete();");
 }
 
 TEST_F(FormatTestJS, StringLiteralConcatenation) {





More information about the cfe-commits mailing list