r334415 - clang-format: [JS] strict prop init annotation.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 11 09:20:13 PDT 2018
Author: mprobst
Date: Mon Jun 11 09:20:13 2018
New Revision: 334415
URL: http://llvm.org/viewvc/llvm-project?rev=334415&view=rev
Log:
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
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=334415&r1=334414&r2=334415&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jun 11 09:20:13 2018
@@ -2981,7 +2981,7 @@ bool TokenAnnotator::mustBreakBefore(con
// 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(cons
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))
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=334415&r1=334414&r2=334415&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Jun 11 09:20:13 2018
@@ -1540,6 +1540,15 @@ TEST_F(FormatTestJS, ClassDeclarations)
"}");
}
+TEST_F(FormatTestJS, StrictPropInitWrap) {
+ const FormatStyle &Style = getGoogleJSStyleWithColumns(22);
+ verifyFormat("class X {\n"
+ " strictPropInitField!:\n"
+ " string;\n"
+ "}",
+ Style);
+}
+
TEST_F(FormatTestJS, InterfaceDeclarations) {
verifyFormat("interface I {\n"
" x: string;\n"
More information about the cfe-commits
mailing list