From: Martin Probst Date: Fri, 12 May 2017 13:00:33 +0000 (+0000) Subject: clang-format: [JS] support non-null assertions after all identifiers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=53df6f973c0c33b3520e9ee5cd9fde927c7f346f;p=clang clang-format: [JS] support non-null assertions after all identifiers. Summary: Previously: x = namespace !; Now: x = namespace!; Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D33113 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302893 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index c274d7bf07..d3b2cf4e84 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1034,7 +1034,8 @@ private: if (Style.Language == FormatStyle::LK_JavaScript) { if (Current.is(tok::exclaim)) { if (Current.Previous && - (Current.Previous->isOneOf(tok::identifier, tok::r_paren, + (Current.Previous->Tok.getIdentifierInfo() || + Current.Previous->isOneOf(tok::identifier, tok::r_paren, tok::r_square, tok::r_brace) || Current.Previous->Tok.isLiteral())) { Current.Type = TT_JsNonNullAssertion; diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 4a2da1abe0..8387152bca 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -1799,6 +1799,7 @@ TEST_F(FormatTestJS, NonNullAssertionOperator) { " .foo()!\n" " .foo()!;\n", getGoogleJSStyleWithColumns(20)); + verifyFormat("let x = namespace!;\n"); } TEST_F(FormatTestJS, Conditional) {