clang-format: [JS] handle union types in arrow functions.
authorMartin Probst <martin@probst.io>
Tue, 1 Aug 2017 17:19:32 +0000 (17:19 +0000)
committerMartin Probst <martin@probst.io>
Tue, 1 Aug 2017 17:19:32 +0000 (17:19 +0000)
Summary: clang-format would previously fail to detect that an arrow functions parameter block is not an expression, and thus insert whitespace around the `|` and `&` type operators in it.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

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

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

index e7a50aa4329a8842c76821f08cbfb2e1fac55c4c..559a547f2142790243df7da67ad0c5b42ac034e8 100644 (file)
@@ -533,6 +533,7 @@ private:
             Contexts.back().ContextKind == tok::l_square || // array type
             (Contexts.size() == 1 &&
              Line.MustBeDeclaration)) { // method/property declaration
+          Contexts.back().IsExpression = false;
           Tok->Type = TT_JsTypeColon;
           break;
         }
index 54e2c8fbe95502d09f1c1500461fc4bf36e31900..231026b7c61538adc4946ae2e24f5927aae16040 100644 (file)
@@ -988,6 +988,9 @@ TEST_F(FormatTestJS, ArrowFunctions) {
                "    .doSomethingElse(\n"
                "        // break\n"
                "    );");
+  verifyFormat("const f = (x: string|null): string|null => {\n"
+               "  return x;\n"
+               "}\n");
 }
 
 TEST_F(FormatTestJS, ReturnStatements) {