[PATCH] D36146: clang-format: [JS] whitespace between keywords and parenthesized expressions.
Martin Probst via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 1 06:16:48 PDT 2017
mprobst created this revision.
Herald added a subscriber: klimek.
`throw (...)` should have a whitespace following it, as do await and void.
https://reviews.llvm.org/D36146
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -259,6 +259,15 @@
"}\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);");
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2347,6 +2347,9 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36146.109096.patch
Type: text/x-patch
Size: 1305 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170801/ea2507b6/attachment.bin>
More information about the cfe-commits
mailing list