This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [js] Support type annotations
ClosedPublic

Authored by mprobst on Feb 18 2015, 5:29 AM.

Details

Reviewers
djasper
Summary

This patch adds support for type annotations that follow TypeScript's, Flow's, and AtScript's syntax style.

Diff Detail

Event Timeline

mprobst updated this revision to Diff 20165.Feb 18 2015, 5:29 AM
mprobst retitled this revision from to clang-format: [js] Support type annotations.
mprobst updated this object.
mprobst edited the test plan for this revision. (Show Details)
mprobst added a reviewer: djasper.
mprobst added a subscriber: Unknown Object (MLST).
mprobst updated this revision to Diff 20167.Feb 18 2015, 5:56 AM

Add test for function types.

mprobst updated this revision to Diff 20179.Feb 18 2015, 8:18 AM

One more test.

djasper edited edge metadata.Feb 18 2015, 8:23 AM

I'd use ternary expressions, what do you think? Otherwise looks good, I can submit this for you.

lib/Format/TokenAnnotator.cpp
424–427

Maybe

Tok->Type = Style.Language == FormatStyle::LK_JavaScript
    ? TT_JsTypeColon
    : TT_RangeBasedForLoopColon;

?

433–436

Here, too?

443–446

Here, too?

mprobst updated this revision to Diff 20186.Feb 18 2015, 8:28 AM
mprobst edited edge metadata.

Use ternaries.

lib/Format/TokenAnnotator.cpp
424–427

Done.

433–436

I don't think a double nested ternary is very readable here (note this is three cases).

443–446

Done.

djasper accepted this revision.Feb 18 2015, 9:11 AM
djasper edited edge metadata.
This revision is now accepted and ready to land.Feb 18 2015, 9:11 AM
djasper closed this revision.Feb 18 2015, 9:12 AM

Submitted as r229700.