]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] whitespace between keywords and parenthesized expressions.
authorMartin Probst <martin@probst.io>
Tue, 1 Aug 2017 17:22:15 +0000 (17:22 +0000)
committerMartin Probst <martin@probst.io>
Tue, 1 Aug 2017 17:22:15 +0000 (17:22 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309710 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp

index 559a547f2142790243df7da67ad0c5b42ac034e8..cb3e8335b3f1ed101da8018e5d0d6b2996094efb 100644 (file)
@@ -2349,6 +2349,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
     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
index 231026b7c61538adc4946ae2e24f5927aae16040..4ae6b866b9f67fb3f07e127c1902bcf8a1a5c4f4 100644 (file)
@@ -259,6 +259,15 @@ TEST_F(FormatTestJS, ReservedWordsMethods) {
       "}\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);");