]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] do not wrap after async/await.
authorMartin Probst <martin@probst.io>
Thu, 30 Nov 2017 10:25:17 +0000 (10:25 +0000)
committerMartin Probst <martin@probst.io>
Thu, 30 Nov 2017 10:25:17 +0000 (10:25 +0000)
Summary:
Otherwise automatic semicolon insertion can trigger, i.e. wrapping
produces invalid syntax.

Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D40642

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319415 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 4463f89755fb0536c07580a20e6004d4d7f18801..c394fa03b2661d6b288d949dd564da9172e182cf 100644 (file)
@@ -2701,12 +2701,12 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
   } 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))
index 390772db8badfed9eb67449b60af2d8a179e2bfe..2a929563f754489c7e4b654c24b288d9364c67e5 100644 (file)
@@ -1152,6 +1152,11 @@ TEST_F(FormatTestJS, WrapRespectsAutomaticSemicolonInsertion) {
                "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) {