mprobst created this revision. mprobst added a reviewer: krasimir. Herald added subscribers: cfe-commits, klimek.
`is` type annotations can occur at any nesting level. For example: function x() { return function y(): a is B { ... }; } Breaking before the `is` above breaks TypeScript parsing the code. This change prevents the wrap. Repository: rC Clang https://reviews.llvm.org/D47193 Files: lib/Format/TokenAnnotator.cpp unittests/Format/FormatTestJS.cpp Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -1164,7 +1164,15 @@ verifyFormat("await theReckoning;", getGoogleJSStyleWithColumns(10)); verifyFormat("some['a']['b']", getGoogleJSStyleWithColumns(10)); verifyFormat("x = (a['a']\n" - " ['b']);", getGoogleJSStyleWithColumns(10)); + " ['b']);", + getGoogleJSStyleWithColumns(10)); + verifyFormat("function f() {\n" + " return foo.bar(\n" + " (param): param is {\n" + " a: SomeType\n" + " }&ABC => 1)\n" + "}", + getGoogleJSStyleWithColumns(25)); } TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) { Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2958,7 +2958,7 @@ return false; if (Left.is(TT_JsTypeColon)) return true; - if (Right.NestingLevel == 0 && Right.is(Keywords.kw_is)) + if (Right.is(Keywords.kw_is)) return false; if (Left.is(Keywords.kw_in)) return Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None;
Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -1164,7 +1164,15 @@ verifyFormat("await theReckoning;", getGoogleJSStyleWithColumns(10)); verifyFormat("some['a']['b']", getGoogleJSStyleWithColumns(10)); verifyFormat("x = (a['a']\n" - " ['b']);", getGoogleJSStyleWithColumns(10)); + " ['b']);", + getGoogleJSStyleWithColumns(10)); + verifyFormat("function f() {\n" + " return foo.bar(\n" + " (param): param is {\n" + " a: SomeType\n" + " }&ABC => 1)\n" + "}", + getGoogleJSStyleWithColumns(25)); } TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) { Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2958,7 +2958,7 @@ return false; if (Left.is(TT_JsTypeColon)) return true; - if (Right.NestingLevel == 0 && Right.is(Keywords.kw_is)) + if (Right.is(Keywords.kw_is)) return false; if (Left.is(Keywords.kw_in)) return Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits