This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [JS] support optional methods.
ClosedPublic

Authored by mprobst on May 4 2015, 4:56 PM.

Details

Reviewers
djasper
Summary

Optional methods use ? tokens like this:

interface X { y?(): z; }

It seems easiest to detect and disambiguate these
from ternary expressions by checking if the code
is in a declaration context. Turns out that that
didn't quite work properly for interfaces in Java
and JS, and for JS file root contexts.

Diff Detail

Event Timeline

mprobst updated this revision to Diff 24925.May 4 2015, 4:56 PM
mprobst retitled this revision from to clang-format: [JS] support optional methods..
mprobst updated this object.
mprobst edited the test plan for this revision. (Show Details)
mprobst added a reviewer: djasper.
mprobst added subscribers: klimek, Unknown Object (MLST).
mprobst added inline comments.May 4 2015, 5:00 PM
lib/Format/TokenAnnotator.cpp
1870

Note that this change is unrelated, I just stumbled across this code and found it hard to read with all those boolean clauses. Might be useful to go over this and add comments explaining the individual parts at some point.

For some reason with these changes interfaces are formatted onto one line:

interface X { y: string; }

Instead of

interface X {
  y: string;
}

No idea why, I'll investigate a bit.

Turns out that wasn't a regression, just a missing feature. See D9494.

djasper accepted this revision.May 5 2015, 1:44 AM
djasper edited edge metadata.

Submitted as r236488.

lib/Format/TokenAnnotator.cpp
1870

I have merged the first two, but after starting to write comments, I realized that I would just duplicate what's inside the "if (..)". I think this is pretty readable as is.

This revision is now accepted and ready to land.May 5 2015, 1:44 AM
djasper closed this revision.May 5 2015, 1:44 AM