summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2017-05-18 21:19:29 +0000
committerMartin Probst <martin@probst.io>2017-05-18 21:19:29 +0000
commit86fb5b7268f41cf895f7f36099c99d799d3dc004 (patch)
treecdcb5e0b7e9c8f2d51e0de94cfe56d72c40caee8
parent8f8b650525b0c48938b44c29dfd3df1699851d82 (diff)
clang-format: [JS] for await, and fix a crash with for loops.
Summary: The syntax is actually `for await (const x of y)` (d'oh). This also fixes a crash for `for` tokens not followed by additional tokens. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D33329 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303382 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Format/TokenAnnotator.cpp8
-rw-r--r--lib/Format/UnwrappedLineParser.cpp4
-rw-r--r--unittests/Format/FormatTestJS.cpp5
3 files changed, 8 insertions, 9 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index feb0c13fe0..5273791114 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -579,8 +579,8 @@ private:
if (Style.Language == FormatStyle::LK_JavaScript)
if (Tok->Previous && Tok->Previous->is(tok::period))
break;
- // JS' for async ( ...
- if (CurrentToken->is(Keywords.kw_async))
+ // JS' for await ( ...
+ if (CurrentToken && CurrentToken->is(Keywords.kw_await))
next();
Contexts.back().ColonIsForRangeExpr = true;
next();
@@ -2252,8 +2252,8 @@ 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) &&
+ // for await ( ...
+ if (Right.is(tok::l_paren) && Left.is(Keywords.kw_await) &&
Left.Previous && Left.Previous->is(tok::kw_for))
return true;
if (Left.is(Keywords.kw_async) && Right.is(tok::l_paren) &&
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index e2762cd42c..5758854e7c 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -1636,9 +1636,9 @@ void UnwrappedLineParser::parseForOrWhileLoop() {
assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) &&
"'for', 'while' or foreach macro expected");
nextToken();
- // JS' for async ( ...
+ // JS' for await ( ...
if (Style.Language == FormatStyle::LK_JavaScript &&
- FormatTok->is(Keywords.kw_async))
+ FormatTok->is(Keywords.kw_await))
nextToken();
if (FormatTok->Tok.is(tok::l_paren))
parseParens();
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp
index ff28f304be..c36b4359c2 100644
--- a/unittests/Format/FormatTestJS.cpp
+++ b/unittests/Format/FormatTestJS.cpp
@@ -548,15 +548,14 @@ TEST_F(FormatTestJS, AsyncFunctions) {
" // Comment.\n"
" return async.then();\n"
"}\n");
- verifyFormat("for async (const x of y) {\n"
+ verifyFormat("for await (const x of y) {\n"
" console.log(x);\n"
"}\n");
verifyFormat("function asyncLoop() {\n"
- " for async (const x of y) {\n"
+ " for await (const x of y) {\n"
" console.log(x);\n"
" }\n"
"}\n");
-
}
TEST_F(FormatTestJS, FunctionParametersTrailingComma) {