diff options
author | Martin Probst <martin@probst.io> | 2017-05-15 19:33:20 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2017-05-15 19:33:20 +0000 |
commit | 661305755fa87aba0b986c29af718ece39624778 (patch) | |
tree | 145df9eefca78728b9fa5969b363e1117a6be40c /lib/Format | |
parent | 600a9e6e11f067dbb921c742b6fb676e0ac045bd (diff) |
clang-format: [JS] for async loops.
Summary:
JavaScript supports asynchronous loop iteration in async functions:
for async (const x of y) ...
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D33193
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303106 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format')
-rw-r--r-- | lib/Format/TokenAnnotator.cpp | 13 | ||||
-rw-r--r-- | lib/Format/UnwrappedLineParser.cpp | 4 |
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index ad2166cfd3..387768a6ee 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -576,9 +576,12 @@ private: } break; case tok::kw_for: - if (Style.Language == FormatStyle::LK_JavaScript && Tok->Previous && - Tok->Previous->is(tok::period)) - break; + if (Style.Language == FormatStyle::LK_JavaScript) + if (Tok->Previous && Tok->Previous->is(tok::period)) + break; + // JS' for async ( ... + if (CurrentToken->is(Keywords.kw_async)) + next(); Contexts.back().ColonIsForRangeExpr = true; next(); if (!parseParens()) @@ -2249,6 +2252,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, } else if (Style.Language == FormatStyle::LK_JavaScript) { if (Left.is(TT_JsFatArrow)) return true; + // for async ( ... + if (Right.is(tok::l_paren) && Left.is(Keywords.kw_async) && + Left.Previous && Left.Previous->is(tok::kw_for)) + return true; if (Left.is(Keywords.kw_async) && Right.is(tok::l_paren) && Right.MatchingParen) { const FormatToken *Next = Right.MatchingParen->getNextNonComment(); diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index c28565ddd7..31c66ffb00 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1635,6 +1635,10 @@ void UnwrappedLineParser::parseForOrWhileLoop() { assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) && "'for', 'while' or foreach macro expected"); nextToken(); + // JS' for async ( ... + if (Style.Language == FormatStyle::LK_JavaScript && + FormatTok->is(Keywords.kw_async)) + nextToken(); if (FormatTok->Tok.is(tok::l_paren)) parseParens(); if (FormatTok->Tok.is(tok::l_brace)) { |