Page MenuHomePhabricator

clang-format: [JS] do not insert whitespace in call positions.
ClosedPublic

Authored by mprobst on Aug 1 2017, 5:10 AM.

Details

Summary

In JavaScript, may keywords can be used in method names and thus call sites:

foo.delete();
foo.instanceof();

clang-format would previously insert whitespace after the instanceof. This
change generically skips inserting whitespace between a keyword and a
parenthesis if preceded by a dot, i.e. in a callsite.

Diff Detail

Repository
rL LLVM

Event Timeline

mprobst created this revision.Aug 1 2017, 5:10 AM
mprobst updated this revision to Diff 109089.Aug 1 2017, 5:16 AM
  • support switch, case, delete.
djasper added inline comments.Aug 1 2017, 8:44 AM
lib/Format/TokenAnnotator.cpp
2355 ↗(On Diff #109089)

Why is instanceof not required in this list?

unittests/Format/FormatTestJS.cpp
237 ↗(On Diff #109089)

no test for delete?

mprobst updated this revision to Diff 110959.Aug 14 2017, 6:53 AM
mprobst marked 2 inline comments as done.
  • clean up implementation, just use getIdentifierInfo
  • clean up tests, remove illegal syntax, add more tests
mprobst added inline comments.Aug 14 2017, 6:55 AM
lib/Format/TokenAnnotator.cpp
2355 ↗(On Diff #109089)

instanceof is not a keyword in the C++ sense, so it is covered by the getIdentifierInfo part. But this was actually a misunderstanding - getIdentifierInfo actually covers all keyword-ish tokens, so we don't need the list of tokens here at all.

djasper accepted this revision.Aug 14 2017, 9:04 AM

Looks good.

This revision is now accepted and ready to land.Aug 14 2017, 9:04 AM
This revision was automatically updated to reflect the committed changes.