summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2018-06-11 16:20:13 +0000
committerMartin Probst <martin@probst.io>2018-06-11 16:20:13 +0000
commitc8b7a41a00591c4852ac583cf2bc4c7d34b2fded (patch)
tree7ce67fd24e86a719e853a512fdfc11fc9be66dc7 /clang/lib/Format
parent5434047862b1439e8ede5388aad4445317bacddd (diff)
downloadbcm5719-llvm-c8b7a41a00591c4852ac583cf2bc4c7d34b2fded.tar.gz
bcm5719-llvm-c8b7a41a00591c4852ac583cf2bc4c7d34b2fded.zip
clang-format: [JS] strict prop init annotation.
Summary: TypeScript uses the `!` token for strict property initialization assertions, as in: class X { strictPropAsserted!: string; } Previously, clang-format would wrap between the `!` and the `:` for overly long lines. This patch fixes that by generally preventing the wrap in that location. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48030 llvm-svn: 334415
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 0a026159a0e..5dce9d248a9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2981,7 +2981,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
// We deal with this case later by detecting an entry
// following a closing paren of this submessage.
}
-
+
// If this is an entry immediately following a submessage, it will be
// preceded by a closing paren of that submessage, like in:
// left---. .---right
@@ -3027,6 +3027,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
return false;
if (Left.is(TT_JsTypeColon))
return true;
+ // Don't wrap between ":" and "!" of a strict prop init ("field!: type;").
+ if (Left.is(tok::exclaim) && Right.is(tok::colon))
+ return false;
if (Right.is(Keywords.kw_is))
return false;
if (Left.is(Keywords.kw_in))
OpenPOWER on IntegriCloud