r319415 - clang-format: [JS] do not wrap after async/await.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 30 02:25:17 PST 2017
Author: mprobst
Date: Thu Nov 30 02:25:17 2017
New Revision: 319415
URL: http://llvm.org/viewvc/llvm-project?rev=319415&view=rev
Log:
clang-format: [JS] do not wrap after async/await.
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
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=319415&r1=319414&r2=319415&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Nov 30 02:25:17 2017
@@ -2701,12 +2701,12 @@ bool TokenAnnotator::canBreakBefore(cons
} 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))
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=319415&r1=319414&r2=319415&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Thu Nov 30 02:25:17 2017
@@ -1152,6 +1152,11 @@ TEST_F(FormatTestJS, WrapRespectsAutomat
"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) {
More information about the cfe-commits
mailing list