This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [JS] for async loops.
ClosedPublic

Authored by mprobst on May 15 2017, 6:22 AM.

Details

Summary

JavaScript supports asynchronous loop iteration in async functions:

for async (const x of y) ...

Diff Detail

Repository
rL LLVM

Event Timeline

mprobst created this revision.May 15 2017, 6:22 AM
djasper accepted this revision.May 15 2017, 6:29 AM
djasper added inline comments.
lib/Format/TokenAnnotator.cpp
583 ↗(On Diff #98996)

Can we make this JS specific, e.g. by turning l. 579 into:

if (Style.Language == FormatStyle::LK_JavaScript) {
  if (Tok->Previous && Tok->Previous->is(tok::period))
    break;
  if (CurrentToken->is(Keywords.kw_async))
    next();
}

Alternatively, leave a comment that this is JavaScript's "async"

lib/Format/UnwrappedLineParser.cpp
1638 ↗(On Diff #98996)

Same here.. Make this JS specific or at least leave a comment.

This revision is now accepted and ready to land.May 15 2017, 6:29 AM
mprobst updated this revision to Diff 98997.May 15 2017, 6:32 AM
mprobst marked an inline comment as done.
  • make parsing JS specific
mprobst marked an inline comment as done.May 15 2017, 6:32 AM
mprobst added inline comments.
lib/Format/TokenAnnotator.cpp
583 ↗(On Diff #98996)

My reasoning was that this would at best be a syntax error in other languages, so it's fine to parse. But changed to be JS specific, that might be cleaner.

This revision was automatically updated to reflect the committed changes.
mprobst marked an inline comment as done.