[PATCH] D40642: clang-format: [JS] do not wrap after async/await.

Martin Probst via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 30 02:10:37 PST 2017


mprobst created this revision.
Herald added subscribers: cfe-commits, klimek.

Otherwise automatic semicolon insertion can trigger, i.e. wrapping
produces invalid syntax.


Repository:
  rC Clang

https://reviews.llvm.org/D40642

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1152,6 +1152,11 @@
                "const y = 3\n",
                "const x = (   5 +    9)\n"
                "const y = 3\n");
+  // Ideally the foo() bit should be indented relative to the async function().
+  verifyFormat("async function\n"
+               "foo() {}",
+               getGoogleJSStyleWithColumns(10));
+  verifyFormat("await theReckoning;", getGoogleJSStyleWithColumns(10));
 }
 
 TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2701,12 +2701,12 @@
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
     const FormatToken *NonComment = Right.getPreviousNonComment();
     if (NonComment &&
-        NonComment->isOneOf(tok::kw_return, Keywords.kw_yield, tok::kw_continue,
-                            tok::kw_break, tok::kw_throw, Keywords.kw_interface,
-                            Keywords.kw_type, tok::kw_static, tok::kw_public,
-                            tok::kw_private, tok::kw_protected,
-                            Keywords.kw_readonly, Keywords.kw_abstract,
-                            Keywords.kw_get, Keywords.kw_set))
+        NonComment->isOneOf(
+            tok::kw_return, Keywords.kw_yield, tok::kw_continue, tok::kw_break,
+            tok::kw_throw, Keywords.kw_interface, Keywords.kw_type,
+            tok::kw_static, tok::kw_public, tok::kw_private, tok::kw_protected,
+            Keywords.kw_readonly, Keywords.kw_abstract, Keywords.kw_get,
+            Keywords.kw_set, Keywords.kw_async, Keywords.kw_await))
       return false; // Otherwise automatic semicolon insertion would trigger.
     if (Left.Tok.getIdentifierInfo() &&
         Right.startsSequence(tok::l_square, tok::r_square))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40642.124887.patch
Type: text/x-patch
Size: 2033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171130/677ea4e8/attachment-0001.bin>


More information about the cfe-commits mailing list