This revision was automatically updated to reflect the committed changes.
Closed by commit rL303382: clang-format: [JS] for await, and fix a crash with 
for loops. (authored by mprobst).

Changed prior to commit:
  https://reviews.llvm.org/D33329?vs=99468&id=99496#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33329

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/lib/Format/UnwrappedLineParser.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -579,8 +579,8 @@
       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 @@
   } 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) &&
Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -1636,9 +1636,9 @@
   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();
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -548,15 +548,14 @@
                "  // 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) {


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -579,8 +579,8 @@
       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 @@
   } 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) &&
Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -1636,9 +1636,9 @@
   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();
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -548,15 +548,14 @@
                "  // 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) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to