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

llvm-svn: 319415
This commit is contained in:
Martin Probst 2017-11-30 10:25:17 +00:00
parent f59056ff93
commit 27b6603f90
2 changed files with 11 additions and 6 deletions

View 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))

View 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) {