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 | bd49e321d34ed62412071f3a9ebe4d4ce26f3861 (patch) | |
tree | 463cc976698032ac81ab77f0e71c4c9fe3651e49 /clang/lib/Format/TokenAnnotator.cpp | |
parent | 878715f978f0b673ce44feaf84e31b029e8d0c5b (diff) | |
download | bcm5719-llvm-bd49e321d34ed62412071f3a9ebe4d4ce26f3861.tar.gz bcm5719-llvm-bd49e321d34ed62412071f3a9ebe4d4ce26f3861.zip |
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
llvm-svn: 303106
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index ad2166cfd3b..387768a6ee5 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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(); |