This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [JS] allow breaking after non-null assertions.
ClosedPublic

Authored by mprobst on Mar 7 2017, 10:30 AM.

Details

Summary

Previously clang-format would not break after any !. However in TypeScript, ! can be used as a post fix operator for non-nullability:

x.foo()!.bar()!;

With this change, clang-format will wrap after the ! if it is likely a post-fix non null operator.

Event Timeline

mprobst created this revision.Mar 7 2017, 10:30 AM
djasper added inline comments.Mar 7 2017, 10:38 AM
lib/Format/TokenAnnotator.cpp
2295

Hm. Generally, we try to set the TokenType instead of computing this information multiple times. It's not overly important here, but I can easily foresee that we are going to need to know what kind of "!" this is in ContinuationIndenter.cpp at some point. So I'd suggest to move this code into the huge mess that is determineTokenType (and define corresponding token type in FormatToken.h).

mprobst updated this revision to Diff 90889.Mar 7 2017, 11:04 AM
  • Introduce TT_JsNonNullAssertion to centralize determining token types.
djasper accepted this revision.Mar 8 2017, 1:41 AM
djasper added inline comments.
lib/Format/TokenAnnotator.cpp
1056

I wonder whether we should do this logic "inside out", i.e. have language-specific parts at the top (or in a separate function). We have started that in mustBreakBefore and I think that's helpful.

I can do this in a follow-up, though.

1063
This revision is now accepted and ready to land.Mar 8 2017, 1:41 AM
mprobst marked 2 inline comments as done.Mar 8 2017, 2:03 AM
mprobst added inline comments.
lib/Format/TokenAnnotator.cpp
1056

Yeah, I was debating that but wanted to stick with the code style. Done.

mprobst updated this revision to Diff 90988.Mar 8 2017, 2:04 AM
mprobst marked an inline comment as done.
  • Introduce TT_JsNonNullAssertion to centralize determining token types.
  • Move up language specific code in determineTokenType.
This revision was automatically updated to reflect the committed changes.