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 = new Foo();");
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) {