forked from OSchip/llvm-project
clang-format: [JS] post-fix non-null assertion operator.
Summary: Do not insert whitespace preceding the "!" postfix operator. This is an incomplete fix, but should cover common usage. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D21204 llvm-svn: 272524
This commit is contained in:
parent
1e74fc564c
commit
0eb40cfa6f
|
@ -2126,6 +2126,11 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
|
|||
// 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;
|
||||
|
|
|
@ -1293,5 +1293,14 @@ TEST_F(FormatTestJS, SupportShebangLines) {
|
|||
"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
|
||||
|
|
Loading…
Reference in New Issue