clang-format: [JS] Better support for empty function literals.

Before:
  SomeFunction(function(){});

After:
  SomeFunction(function() {});

llvm-svn: 217236
This commit is contained in:
Daniel Jasper 2014-09-05 08:42:27 +00:00
parent 97bfb7b1ba
commit 3f69ba1075
2 changed files with 8 additions and 0 deletions

View File

@ -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;

View File

@ -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"