]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] do not wrap before any `is`.
authorMartin Probst <martin@probst.io>
Tue, 22 May 2018 10:39:07 +0000 (10:39 +0000)
committerMartin Probst <martin@probst.io>
Tue, 22 May 2018 10:39:07 +0000 (10:39 +0000)
Summary:
`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.

Reviewers: krasimir

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D47193

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332968 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp

index 2fe1e24709c834e401f9cc7ea85dc73261a58b3c..56f1841222ce47270d7923c3dce49262692138ee 100644 (file)
@@ -2958,7 +2958,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
       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 0a5c991b36da39000593d2eaec469ce036777c1f..1d6105557781ea3f02e253c35b04a78d3906f42e 100644 (file)
@@ -1164,7 +1164,15 @@ TEST_F(FormatTestJS, WrapRespectsAutomaticSemicolonInsertion) {
   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) {