Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -370,7 +370,9 @@ Keywords.kw_as)) || NextTok->isOneOf(tok::comma, tok::period, tok::colon, tok::r_paren, tok::r_square, tok::l_brace, - tok::l_square, tok::l_paren, tok::ellipsis) || + tok::l_square, tok::ellipsis) || + (Style.Language == FormatStyle::LK_Cpp && + NextTok->is(tok::l_paren)) || (NextTok->is(tok::identifier) && !PrevTok->isOneOf(tok::semi, tok::r_brace, tok::l_brace)) || (NextTok->is(tok::semi) && Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -451,6 +451,16 @@ " inner2(a, b);\n" "}"); verifyFormat("function f() {}"); + verifyFormat("function aFunction() {}\n" + "(function f() {\n" + " var x = 1;\n" + "}());\n"); + // Known issue: this should wrap after {}, but calculateBraceTypes + // misclassifies the first braces as a BK_BracedInit. + verifyFormat("function aFunction(){} {\n" + " let x = 1;\n" + " console.log(x);\n" + "}\n"); } TEST_F(FormatTestJS, GeneratorFunctions) {