[PATCH] D36147: clang-format: [JS] handle union types in arrow functions.
Martin Probst via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 1 06:29:42 PDT 2017
mprobst created this revision.
Herald added a subscriber: klimek.
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.
https://reviews.llvm.org/D36147
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -988,6 +988,9 @@
" .doSomethingElse(\n"
" // break\n"
" );");
+ verifyFormat("const f = (x: string|null): string|null => {\n"
+ " return x;\n"
+ "}\n");
}
TEST_F(FormatTestJS, ReturnStatements) {
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -533,6 +533,7 @@
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36147.109097.patch
Type: text/x-patch
Size: 974 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170801/eb10888a/attachment.bin>
More information about the cfe-commits
mailing list