[PATCH] D21204: clang-format: [JS] post-fix non-null assertion operator.

Martin Probst via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 12 17:56:45 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL272524: clang-format: [JS] post-fix non-null assertion operator. (authored by mprobst).

Changed prior to commit:
  http://reviews.llvm.org/D21204?vs=60311&id=60482#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D21204

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp

Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2126,6 +2126,11 @@
       // locations that should have whitespace following are identified by the
       // above set of follower tokens.
       return false;
+    // Postfix non-null assertion operator, as in `foo!.bar()`.
+    if (Right.is(tok::exclaim) && (Left.isOneOf(tok::identifier, tok::r_paren,
+                                                tok::r_square, tok::r_brace) ||
+                                   Left.Tok.isLiteral()))
+      return false;
   } else if (Style.Language == FormatStyle::LK_Java) {
     if (Left.is(tok::r_square) && Right.is(tok::l_brace))
       return true;
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1293,5 +1293,14 @@
                "var x   =  hello();");
 }
 
+TEST_F(FormatTestJS, NonNullAssertionOperator) {
+  verifyFormat("let x = foo!.bar();\n");
+  verifyFormat("let x = foo ? bar! : baz;\n");
+  verifyFormat("let x = !foo;\n");
+  verifyFormat("let x = foo[0]!;\n");
+  verifyFormat("let x = (foo)!;\n");
+  verifyFormat("let x = {foo: 1}!;\n");
+}
+
 } // end namespace tooling
 } // end namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21204.60482.patch
Type: text/x-patch
Size: 1444 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160613/d9252863/attachment.bin>


More information about the cfe-commits mailing list