diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-05-02 18:30:45 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-05-02 18:30:45 +0000 |
| commit | 570918821a8492048e6ab54955c9864bd6c3e952 (patch) | |
| tree | f9d0d3f3478c298aaf51987483bbbbefe8e6631b /lib/Format | |
| parent | f0c55418e2b09eaab37c820d3756cc1b4584d084 (diff) | |
Diffstat (limited to 'lib/Format')
| -rw-r--r-- | lib/Format/UnwrappedLineParser.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 5be68ad5c6b82..2d788b52dfda4 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1040,13 +1040,15 @@ void UnwrappedLineParser::parseStructuralElement() { return; } - // Parse function literal unless 'function' is the first token in a line - // in which case this should be treated as a free-standing function. + // Function declarations (as opposed to function expressions) are parsed + // on their own unwrapped line by continuing this loop. Function + // expressions (functions that are not on their own line) must not create + // a new unwrapped line, so they are special cased below. + size_t TokenCount = Line->Tokens.size(); if (Style.Language == FormatStyle::LK_JavaScript && - (FormatTok->is(Keywords.kw_function) || - FormatTok->startsSequence(Keywords.kw_async, - Keywords.kw_function)) && - Line->Tokens.size() > 0) { + FormatTok->is(Keywords.kw_function) && + (TokenCount > 1 || (TokenCount == 1 && !Line->Tokens.front().Tok->is( + Keywords.kw_async)))) { tryToParseJSFunction(); break; } |
