Support TS4.9 satisfies operator#13764
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
| (node.type === "TSTypeAssertion" || | ||
| node.type === "TSAsExpression" || | ||
| // babel-parser cannot parse `satisfies` operator in left side of assignment | ||
| // https://github.com/babel/babel/issues/15095 |
There was a problem hiding this comment.
| case "TSAsExpression": | ||
| // example: foo as unknown as Bar | ||
| return node.type !== "TSAsExpression"; | ||
|
|
||
| case "TSSatisfiesExpression": | ||
| // example: foo satisfies unknown satisfies Bar | ||
| return node.type !== "TSSatisfiesExpression"; |
There was a problem hiding this comment.
Maybe mixed should not add parens either
Prettier pr-13764
Playground link
--parser babel-tsInput:
foo satisfies unknown satisfies Bar
foo as unknown as Bar
foo satisfies unknown as Bar
foo as unknown satisfies BarOutput:
foo satisfies unknown satisfies Bar;
foo as unknown as Bar;
(foo satisfies unknown) as Bar;
(foo as unknown) satisfies Bar;| case "TSInstantiationExpression": | ||
| return [print("expression"), print("typeParameters")]; | ||
| case "TSSatisfiesExpression": | ||
| return [print("expression"), " satisfies ", print("typeAnnotation")]; |
There was a problem hiding this comment.
Merge this into TSAsExpression too? There is an extra check there.
| return ( | ||
| node.type !== "TSAsExpression" && | ||
| node.type !== "TSSatisfiesExpression" | ||
| ); |
There was a problem hiding this comment.
| return ( | |
| node.type !== "TSAsExpression" && | |
| node.type !== "TSSatisfiesExpression" | |
| ); | |
| return !isTSTypeExpression(node); |
| (node.type === "TSTypeAssertion" || | ||
| node.type === "TSAsExpression" || | ||
| // babel-parser cannot parse `satisfies` operator in left side of assignment | ||
| // https://github.com/babel/babel/issues/15095 | ||
| // TODO: Add tests after the bug is fixed | ||
| node.type === "TSSatisfiesExpression") |
There was a problem hiding this comment.
We can reuse isTSTypeExpression here too.
fisker
left a comment
There was a problem hiding this comment.
Looks very good, thanks for the hard work, we can either wait for babel or update later.
|
FYI: @thorn0 may disagree to use |
|
Would it be possible to release this in 2.x? Upgrading to Prettier 3.0 may be more involved, so another 2.x release will allow folks to support TS 4.9 much faster.
|
|
It should not be easy, let's merge to |
|
This is great, thanks @sosukesuzuki 🙌 Will this be released in |
|
Maybe yes. |
When will it be released? |
|
@hiyangguo please follow #13792 and #13813 for progress. |
* Print `satisfies` operators * Add tests * Add changelog * Add `hug-args` tests * Add more tests for TSAsExpression * Add tests for argument expansion * Add tests for template literal * Add tests for ternary * Add tests for export default satisfies * Add tests for no lookahead tokens * Add more tests for needs parens 1 * Add more tests for needs-parens 2 * Add more tests for needs parens 3 * Add tests for needs parens 4 * Add comment * Add more tests for needs parens 5 * Add more tests for needs parens 6 * Fix test cases * Fix snapshots * Fix unstable tests * No parens for mixed * Merge printing logic * More reuse `isTSTypeExpression`
Description
babel-tsparser onlyPartial of #13516
Ref #13750
Checklist
changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.✨Try the playground for this PR✨