diff options
author | Martin Probst <martin@probst.io> | 2017-08-01 17:22:15 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2017-08-01 17:22:15 +0000 |
commit | 22e00f09a0eb7c4669347fa6f13283ef5d55668b (patch) | |
tree | d77b65a6cc4287d471ff72e74e7da403737b8319 | |
parent | 11b8731f6bbfbfe00b2e76353bf4416db255c53f (diff) | |
download | bcm5719-llvm-22e00f09a0eb7c4669347fa6f13283ef5d55668b.tar.gz bcm5719-llvm-22e00f09a0eb7c4669347fa6f13283ef5d55668b.zip |
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
llvm-svn: 309710
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 3 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 9 |
2 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 559a547f214..cb3e8335b3f 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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 diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 231026b7c61..4ae6b866b9f 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -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);"); |