diff options
| -rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 4 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index e2613fbc171..5af743bba5a 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -763,6 +763,10 @@ void UnwrappedLineParser::parseStructuralElement() { return; case tok::identifier: { StringRef Text = FormatTok->TokenText; + if (Style.Language == FormatStyle::LK_JavaScript && Text == "function") { + tryToParseJSFunction(); + break; + } nextToken(); if (Line->Tokens.size() == 1) { if (FormatTok->Tok.is(tok::colon)) { diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index f38bf895f21..657f10874e0 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -31,7 +31,9 @@ protected: return Result; } - static std::string format(llvm::StringRef Code, const FormatStyle &Style) { + static std::string format( + llvm::StringRef Code, + const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) { return format(Code, 0, Code.size(), Style); } @@ -116,6 +118,8 @@ TEST_F(FormatTestJS, Closures) { " style: {direction: ''}\n" " }\n" "};"); + EXPECT_EQ("abc = xyz ? function() { return 1; } : function() { return -1; };", + format("abc=xyz?function(){return 1;}:function(){return -1;};")); } TEST_F(FormatTestJS, ReturnStatements) { |

