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

Martin Probst via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 9 22:08:30 PDT 2016


mprobst added inline comments.

================
Comment at: lib/Format/TokenAnnotator.cpp:2127
@@ +2126,3 @@
+    // Postfix non-null assertion operator, as in `foo!.bar()`.
+    if (Right.is(tok::exclaim) && Right.Next &&
+        Right.Next->isNot(tok::identifier) && !Right.Next->Tok.isLiteral())
----------------
djasper wrote:
> From a quick look at our codebase, I think you need to also rule out the following for Right.Next:
> 
>   - (, [, {
>   - !  ('!!' seems to be a thing)
>   - -, +, ~ (don't know exactly what this does to a JS boolean value)
>   - %, $ (not entirely sure whether these become part of the identifier)
> 
> 
Actually, I think inverting the condition and "whitelisting" preceding tokens makes more sense and is probably a lot more robust. PTAL, now checking left for identifier, r_paren, r_square, literal.


http://reviews.llvm.org/D21204





More information about the cfe-commits mailing list