Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -906,6 +906,15 @@ } void UnwrappedLineParser::tryToParseJSFunction() { + // If it is regular function declaration parse as regular function. + // FIXME: This is a dirty way to access the previous token. Find a better + // solution. + if (Line->Tokens.empty() || + Line->Tokens.back().Tok->isOneOf(tok::r_brace, tok::semi)) { + nextToken(); + return; + } + nextToken(); // Consume function name. Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -184,6 +184,14 @@ " return 1;\n" " }\n" "};"); + verifyFormat("function outer1(a, b) {\n" + " function inner1(a, b) { return a; }\n" + " inner1(a, b);\n" + "}\n" + "function outer2(a, b) {\n" + " function inner2(a, b) { return a; }\n" + " inner2(a, b);\n" + "}"); } TEST_F(FormatTestJS, MultipleFunctionLiterals) {