diff options
| author | Martin Probst <martin@probst.io> | 2016-06-13 00:49:54 +0000 |
|---|---|---|
| committer | Martin Probst <martin@probst.io> | 2016-06-13 00:49:54 +0000 |
| commit | 0eb40cfa6fa16626f4bddb25132722b42400b385 (patch) | |
| tree | aaaa5697a37eab0f76232b44e2d82b3cf335c827 /clang | |
| parent | 1e74fc564c32119c4de3c4a304181340bd9b8b61 (diff) | |
| download | bcm5719-llvm-0eb40cfa6fa16626f4bddb25132722b42400b385.tar.gz bcm5719-llvm-0eb40cfa6fa16626f4bddb25132722b42400b385.zip | |
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
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 5 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 9 |
2 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index b469cfad2bb..13bda71127f 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 3d9677922cf..ffcc34d971f 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -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 |

