[PATCH] D21206: clang-format: [JS] recognized named functions in AnnotatingParser.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 9 15:55:41 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL272330: clang-format: [JS] recognized named functions in AnnotatingParser. (authored by mprobst).
Changed prior to commit:
http://reviews.llvm.org/D21206?vs=60254&id=60268#toc
Repository:
rL LLVM
http://reviews.llvm.org/D21206
Files:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -142,7 +142,10 @@
// static_assert, if and while usually contain expressions.
Contexts.back().IsExpression = true;
} else if (Style.Language == FormatStyle::LK_JavaScript && Left->Previous &&
- Left->Previous->is(Keywords.kw_function)) {
+ (Left->Previous->is(Keywords.kw_function) ||
+ (Left->Previous->endsSequence(tok::identifier,
+ Keywords.kw_function)))) {
+ // function(...) or function f(...)
Contexts.back().IsExpression = false;
} else if (Left->Previous && Left->Previous->is(tok::r_square) &&
Left->Previous->MatchingParen &&
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -903,6 +903,8 @@
verifyFormat("let x: Foo<A|B> = new Foo<A|B>();");
verifyFormat("function(x: A|B): C&D {}");
verifyFormat("function(x: A|B = A | B): C&D {}");
+ verifyFormat("function x(path: number|string) {}");
+ verifyFormat("function x(): string|number {}");
}
TEST_F(FormatTestJS, ClassDeclarations) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21206.60268.patch
Type: text/x-patch
Size: 1425 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160609/d6582270/attachment-0001.bin>
More information about the cfe-commits
mailing list