r217236 - clang-format: [JS] Better support for empty function literals.
Daniel Jasper
djasper at google.com
Fri Sep 5 01:42:27 PDT 2014
Author: djasper
Date: Fri Sep 5 03:42:27 2014
New Revision: 217236
URL: http://llvm.org/viewvc/llvm-project?rev=217236&view=rev
Log:
clang-format: [JS] Better support for empty function literals.
Before:
SomeFunction(function(){});
After:
SomeFunction(function() {});
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=217236&r1=217235&r2=217236&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Sep 5 03:42:27 2014
@@ -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;
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=217236&r1=217235&r2=217236&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Fri Sep 5 03:42:27 2014
@@ -167,6 +167,7 @@ TEST_F(FormatTestJS, FormatsFreestanding
}
TEST_F(FormatTestJS, FunctionLiterals) {
+ verifyFormat("doFoo(function() {});");
verifyFormat("doFoo(function() { return 1; });");
verifyFormat("var func = function() { return 1; };");
verifyFormat("return {\n"
More information about the cfe-commits
mailing list