Author: mprobst Date: Tue Aug 1 10:19:32 2017 New Revision: 309707 URL: http://llvm.org/viewvc/llvm-project?rev=309707&view=rev Log: clang-format: [JS] handle union types in arrow functions.
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 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=309707&r1=309706&r2=309707&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Aug 1 10:19:32 2017 @@ -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; } Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=309707&r1=309706&r2=309707&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTestJS.cpp (original) +++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Aug 1 10:19:32 2017 @@ -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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits