]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] support non-null assertions after all identifiers.
authorMartin Probst <martin@probst.io>
Fri, 12 May 2017 13:00:33 +0000 (13:00 +0000)
committerMartin Probst <martin@probst.io>
Fri, 12 May 2017 13:00:33 +0000 (13:00 +0000)
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

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

index c274d7bf07f82a21ea65ec5b6602fe5ce5aa8625..d3b2cf4e84c24a96a1e9cfb664fedb00a19f5acb 100644 (file)
@@ -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;
index 4a2da1abe0f41ab67ca9cd46d5410afd406b7914..8387152bcacc2f1f262e2df8239ad6b6e603ec83 100644 (file)
@@ -1799,6 +1799,7 @@ TEST_F(FormatTestJS, NonNullAssertionOperator) {
       "            .foo()!\n"
       "            .foo()!;\n",
       getGoogleJSStyleWithColumns(20));
+  verifyFormat("let x = namespace!;\n");
 }
 
 TEST_F(FormatTestJS, Conditional) {