diff options
author | Martin Probst <martin@probst.io> | 2017-04-27 13:07:24 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2017-04-27 13:07:24 +0000 |
commit | 973ff79e2979abe41b1ff9d18599f7c87b6ef432 (patch) | |
tree | a886864142bd730b07884412ac068a51c0541848 /clang/lib/Format | |
parent | 63a978ff090444923be34e4022b2d15937d5f139 (diff) | |
download | bcm5719-llvm-973ff79e2979abe41b1ff9d18599f7c87b6ef432.tar.gz bcm5719-llvm-973ff79e2979abe41b1ff9d18599f7c87b6ef432.zip |
clang-format: [JS] parse async function declarations.
Summary:
Previously, clang-format would accidentally parse an async function
declaration as a function expression, and thus not insert an unwrapped
line for async functions, causing subsequent functions to run into the
function:
async function f() {
x();
} function g() { ...
With this change, async functions get parsed as top level function
declarations and get their own unwrapped line context.
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D32590
llvm-svn: 301538
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 5be68ad5c6b..2d788b52dfd 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/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; } |