From: Daniel Jasper Date: Fri, 5 Sep 2014 08:42:27 +0000 (+0000) Subject: clang-format: [JS] Better support for empty function literals. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b69f76c2f1438bc8224df6a43412f7d9378edeaf;p=clang clang-format: [JS] Better support for empty function literals. Before: SomeFunction(function(){}); After: SomeFunction(function() {}); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217236 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 56cad19277..edb68a3d79 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1041,6 +1041,13 @@ void UnwrappedLineParser::parseParens() { if (FormatTok->Tok.is(tok::l_brace)) parseBracedList(); break; + case tok::identifier: + if (Style.Language == FormatStyle::LK_JavaScript && + FormatTok->TokenText == "function") + tryToParseJSFunction(); + else + nextToken(); + break; default: nextToken(); break; diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 55e7cc6fe1..a4bd84a324 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -167,6 +167,7 @@ TEST_F(FormatTestJS, FormatsFreestandingFunctions) { } TEST_F(FormatTestJS, FunctionLiterals) { + verifyFormat("doFoo(function() {});"); verifyFormat("doFoo(function() { return 1; });"); verifyFormat("var func = function() { return 1; };"); verifyFormat("return {\n"