r309710 - clang-format: [JS] whitespace between keywords and parenthesized expressions.

Martin Probst via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 1 10:22:15 PDT 2017


Author: mprobst
Date: Tue Aug  1 10:22:15 2017
New Revision: 309710

URL: http://llvm.org/viewvc/llvm-project?rev=309710&view=rev
Log:
clang-format: [JS] whitespace between keywords and parenthesized expressions.

Summary: `throw (...)` should have a whitespace following it, as do await and void.

Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D36146

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=309710&r1=309709&r2=309710&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Aug  1 10:22:15 2017
@@ -2349,6 +2349,9 @@ bool TokenAnnotator::spaceRequiredBefore
     if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
         Left.Tok.getIdentifierInfo())
       return false;
+    if (Right.is(tok::l_paren) &&
+        Left.isOneOf(tok::kw_throw, Keywords.kw_await, tok::kw_void))
+      return true;
     if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
                       tok::kw_const) ||
          // "of" is only a keyword if it appears after another identifier

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=309710&r1=309709&r2=309710&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Aug  1 10:22:15 2017
@@ -259,6 +259,15 @@ TEST_F(FormatTestJS, ReservedWordsMethod
       "}\n");
 }
 
+TEST_F(FormatTestJS, ReservedWordsParenthesized) {
+  // All of these are statements using the keyword, not function calls.
+  verifyFormat("throw (x + y);\n"
+               "await (await x).y;\n"
+               "void (0);\n"
+               "delete (x.y);\n"
+               "return (x);\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