Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore pretty-printing TypeScript type T = {...} and interface T {...} semicolons between child members #1247

Merged
merged 4 commits into from
Dec 11, 2022

Conversation

benjamn
Copy link
Owner

@benjamn benjamn commented Dec 10, 2022

PR #1157 correctly stopped the Recast pretty-printer from adding unnecessary extra commas between the fields of object-like TypeScript declarations.

However, many/most TypeScript programmers would probably expect to see semicolons here instead of commas/nothing. We could make this configurable, but I'm not sure it's even controversial, so I'll wait for someone to ask.

This PR enables the Recast pretty-printer (which is only invoked when the AST changes enough to require reprinting) to print those semicolons properly.

The subtlety is to avoid printing extra semicolons, but we already have precedent for using lastNonSpaceCharacter to determine what's already at the end of printed Lines output.

Follow-up to PR #1157 that I caught while trying to regenerate the
TypeScript declarations for ast-types, and noticed a bunch of (IMHO
reasonable) semicolons going missing.
@benjamn benjamn self-assigned this Dec 10, 2022
Copy link
Collaborator

@eventualbuddha eventualbuddha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had wondered why some of the generated code I was seeing in ant-types no longer had semicolons. Maybe this was why?

This reverts commit 808e539.

I usually bump the main package version on the main/master branch after
merging PRs, but I wanted the commit I published to npm (git tag
v0.23.0-pr-1247, [email protected], npm dist-tag pr-1247) to appear
in the Git history somewhere, even though this commit reverts it.
@benjamn benjamn merged commit 56416d1 into master Dec 11, 2022
@benjamn benjamn deleted the restore-pretty-printing-ts-object-type-semicolons branch December 11, 2022 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants