Skip to content

Tokenize type on the line after as or satisfies - #1080

Open
Tomer Aberbach (TomerAberbach) wants to merge 1 commit into
microsoft:masterfrom
TomerAberbach:master
Open

Tomer Aberbach (TomerAberbach) wants to merge 1 commit into
microsoft:masterfrom
TomerAberbach:master

Conversation

@TomerAberbach

Copy link
Copy Markdown

When a line ends with as or satisfies, the type on the next line receives expression scopes. In b as\n A | undefined, A is a variable, | a bitwise operator, and undefined a constant. The as/satisfies rule ends the type at $ and ^, so the type ends at the line break right after the keyword. Prettier emits this layout when an as expression exceeds the print width.

A separate rule now matches as or satisfies at the end of a line, modeled on the rule for a return type that starts on the next line. It ends the type at the end of the first non-empty line that lacks a trailing | or &, instead of at the line break after the keyword.

A union written with a leading | on each line still ends after its first member, because the end pattern cannot match past the current line to check whether the next line continues the type. Multi-line return types have the same limitation.

Fixes #1079

When a line ends with `as` or `satisfies`, the type on the next line
receives expression scopes. In `b as\n  A | undefined`, `A` is a
variable, `|` a bitwise operator, and `undefined` a constant. The
`as`/`satisfies` rule ends the type at `$` and `^`, so the type ends
at the line break right after the keyword. Prettier emits this layout
when an `as` expression exceeds the print width.

A separate rule now matches `as` or `satisfies` at the end of a line,
modeled on the rule for a return type that starts on the next line.
It ends the type at the end of the first non-empty line that lacks a
trailing `|` or `&`, instead of at the line break after the keyword.

A union written with a leading `|` on each line still ends after its
first member, because the end pattern cannot match past the current
line to check whether the next line continues the type. Multi-line
return types have the same limitation.

Fixes microsoft#1079
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant