]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Better support for empty function literals.
authorDaniel Jasper <djasper@google.com>
Fri, 5 Sep 2014 08:42:27 +0000 (08:42 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 5 Sep 2014 08:42:27 +0000 (08:42 +0000)
Before:
  SomeFunction(function(){});

After:
  SomeFunction(function() {});

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217236 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJS.cpp

index 56cad19277dff034892360c987b04d9a7186ae54..edb68a3d79cd9e8f54c95b18b99b2a7437d65db5 100644 (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;
index 55e7cc6fe195039459224296e6dbe75f3ee90fd9..a4bd84a3242a65f9c46abf810d374eae098a9d07 100644 (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"