clang-format: [JS] Understand named function literals.

Before:
  return {a: function SomeFunction(){// ...
                                     return 1;
  }
  }
  ;

After:
  return {
    a: function SomeFunction() {
      // ...
      return 1;
    }
  };

llvm-svn: 210887
This commit is contained in:
Daniel Jasper 2014-06-13 07:02:04 +00:00
parent 5ef4fe7d8e
commit 5217a8b84f
2 changed files with 13 additions and 1 deletions

View File

@ -907,6 +907,11 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
void UnwrappedLineParser::tryToParseJSFunction() {
nextToken();
// Consume function name.
if (FormatTok->is(tok::identifier))
nextToken();
if (FormatTok->isNot(tok::l_paren))
return;
nextToken();

View File

@ -138,7 +138,7 @@ TEST_F(FormatTestJS, GoogScopes) {
"}); // goog.scope");
}
TEST_F(FormatTestJS, Closures) {
TEST_F(FormatTestJS, FunctionLiterals) {
verifyFormat("doFoo(function() { return 1; });");
verifyFormat("var func = function() { return 1; };");
verifyFormat("return {\n"
@ -177,6 +177,13 @@ TEST_F(FormatTestJS, Closures) {
" a: function() { return 1; }\n"
"};",
getGoogleJSStyleWithColumns(37));
verifyFormat("return {\n"
" a: function SomeFunction() {\n"
" // ...\n"
" return 1;\n"
" }\n"
"};");
}
TEST_F(FormatTestJS, MultipleFunctionLiterals) {