diff options
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 5 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 9 |
2 files changed, 13 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)) diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 1d610555778..9975b7d3112 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -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" |