r286367 - clang-format: [TypeScript] Fix bug in handling of non-null operator.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 9 06:12:55 PST 2016
Author: djasper
Date: Wed Nov 9 08:12:55 2016
New Revision: 286367
URL: http://llvm.org/viewvc/llvm-project?rev=286367&view=rev
Log:
clang-format: [TypeScript] Fix bug in handling of non-null operator.
Before:
var i = x!-1;
After:
var i = x! - 1;
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=286367&r1=286366&r2=286367&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Nov 9 08:12:55 2016
@@ -1311,7 +1311,13 @@ private:
TokenType determinePlusMinusCaretUsage(const FormatToken &Tok) {
const FormatToken *PrevToken = Tok.getPreviousNonComment();
- if (!PrevToken || PrevToken->isOneOf(TT_CastRParen, TT_UnaryOperator))
+ if (!PrevToken)
+ return TT_UnaryOperator;
+
+ if (PrevToken->isOneOf(TT_CastRParen, TT_UnaryOperator) &&
+ !PrevToken->is(tok::exclaim))
+ // There aren't any trailing unary operators except for TypeScript's
+ // non-null operator (!). Thus, this must be squence of leading operators.
return TT_UnaryOperator;
// Use heuristics to recognize unary operators.
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=286367&r1=286366&r2=286367&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Nov 9 08:12:55 2016
@@ -1462,6 +1462,7 @@ TEST_F(FormatTestJS, NonNullAssertionOpe
verifyFormat("let x = !foo;\n");
verifyFormat("let x = foo[0]!;\n");
verifyFormat("let x = (foo)!;\n");
+ verifyFormat("let x = foo! - 1;\n");
verifyFormat("let x = {foo: 1}!;\n");
}
More information about the cfe-commits
mailing list