Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2123,6 +2123,10 @@ // 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) && Right.Next && + Right.Next->isNot(tok::identifier) && !Right.Next->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: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -1291,5 +1291,12 @@ "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!;\n"); +} + } // end namespace tooling } // end namespace clang