This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [js] Support ES6 module exports.
ClosedPublic

Authored by mprobst on Feb 19 2015, 5:38 AM.

Details

Reviewers
djasper

Diff Detail

Event Timeline

mprobst updated this revision to Diff 20286.Feb 19 2015, 5:38 AM
mprobst retitled this revision from to clang-format: [js] Support ES6 module exports..
mprobst updated this object.
mprobst edited the test plan for this revision. (Show Details)
mprobst added a reviewer: djasper.
mprobst added subscribers: Unknown Object (MLST), klimek.
mprobst updated this revision to Diff 20287.Feb 19 2015, 6:17 AM

Properly handle exports followed by declarations ((default)? const, class, function, var).

mprobst updated this revision to Diff 20302.Feb 19 2015, 7:56 AM
djasper added inline comments.Feb 19 2015, 7:58 AM
lib/Format/TokenAnnotator.cpp
1762
Line.First->isOneOf(Keywords.kw_import, tok::kw_export)
lib/Format/UnwrappedLineParser.cpp
737

I'd add:

if (Style.Language == FormatStyle::LK_JavaScript) {
  parseJavaScriptEs6ImportExport();
  return;
}
break;

here and not fall through or change the block below.

750
Line.First->isOneOf(Keywords.kw_import, tok::kw_export)
1626

Maybe assert instead of the comment?

1636

I'd probably use if statements instead of the switch. Seems a bit bad to mix switch and if (which you can't avoid because of Keywords):

if (FormatTok->isOneOf(tok::kw_const, tok::kw_class,
                       Keywords.kw_function, Keywords.kw_var))
  return; // Fall through to parsing the corresponding structure.

if (FormatTok->is(tok::kw_default)) {
  nextToken();
  return;
}

if (FormatTok->is(tok::l_brace)) {
  FormatTok->BlockKind = BK_Block;
  parseBracedList();
}
mprobst updated this revision to Diff 20303.Feb 19 2015, 8:11 AM

Addressed comments.

lib/Format/TokenAnnotator.cpp
1762

That wouldn't work in Java without reified generics. Nice :-)

lib/Format/UnwrappedLineParser.cpp
737

Done.

750

No longer needed.

1626

Done.

1636

Yeah, that's better indeed.

mprobst updated this revision to Diff 20304.Feb 19 2015, 8:13 AM
djasper accepted this revision.Feb 19 2015, 8:16 AM
djasper edited edge metadata.
This revision is now accepted and ready to land.Feb 19 2015, 8:16 AM
djasper closed this revision.Feb 19 2015, 8:17 AM

Submitted as r229865.