This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [JS] wrap optional properties in type aliases.
ClosedPublic

Authored by mprobst on Aug 14 2017, 8:45 AM.

Details

Summary

clang-format wraps object literal keys in an object literal if they are
marked as TT_SelectorNames and/or the colon is marked as
TT_DictLiteral. Previously, clang-format would accidentally work
because colons in type aliases were marked as TT_DictLiteral. r310367
fixed this to assing TT_JsTypeColon, which broke wrapping in certain
situations. However the root cause was that clang-format incorrectly
didn't skip questionmarks when detecting selector name.

This change fixes both locations to (1) assign TT_SelectorName and (2)
treat TT_JsTypeColon like TT_DictLiteral.

Previously:

type X = {
  a: string, b?: string,
};

Now:

type X = {
  a: string,
  b?: string,
};

Diff Detail

Repository
rL LLVM

Event Timeline

mprobst created this revision.Aug 14 2017, 8:45 AM
djasper accepted this revision.Aug 14 2017, 9:03 AM

Looks good.

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