fix: surround template literal type unions with newlines when too long#794
Open
divybot wants to merge 1 commit into
Open
fix: surround template literal type unions with newlines when too long#794divybot wants to merge 1 commit into
divybot wants to merge 1 commit into
Conversation
…i-line
When a template literal type's `${...}` placeholder contains an expression
that does not fit on a single line (notably a `TsUnionType` or
`TsIntersectionType`), the generator broke on the separator (`|` / `&`)
without adding the surrounding newlines + indent that `BinExpr`,
`CondExpr`, etc. already trigger. This produced output like
export type SortSelector = `${
| typeof Descending
| typeof Ascending}${SortItems}`;
instead of
export type SortSelector = `${
typeof Descending | typeof Ascending
}${SortItems}`;
Adding `TsUnionType` and `TsIntersectionType` to
`get_possible_surround_newlines` reuses the existing
`surround_with_newlines_indented_if_multi_line` codepath, so the union
expression stays on one line whenever it fits inside the indented inner
column and otherwise gets a clean indented block — matching how
`BinExpr` is already handled.
Closes denoland/deno#29868
55b9e22 to
120197e
Compare
Open
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This PR was authored with the help of an AI coding assistant (Claude Code) running as a bot on behalf of @littledivy. The diagnosis, fix, and tests were reviewed before opening.
Summary
When a template literal type contains a
TsUnionTypeorTsIntersectionTypeinside a${...}placeholder, the generatorbreaks on the separator (
|/&) when the line is too long butnever inserts the surrounding newlines + indent that other
expression-like nodes (
BinExpr,CondExpr, etc.) already get.Reported downstream as denoland/deno#29868.
Before
formats to
(closing
}is stuck on the last union element's line).After
Fix
Add
TsUnionTypeandTsIntersectionTypetoget_possible_surround_newlinesinsidegen_template_literal. Thisreuses the existing
surround_with_newlines_indented_if_multi_linecodepath, so theunion expression stays on one line whenever it fits inside the
indented inner column and otherwise gets a clean indented block.
Test plan
tests/specs/types/TplLitType/TplLitType_All.txtcover: union short enough to stay inline, union too long for one
line, intersection too long for one line.