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

fix(js_formatter): fix binaryish and ts type handling for grouping call arguments #1152

Merged
merged 3 commits into from
Dec 12, 2023

Conversation

faultyserver
Copy link
Contributor

@faultyserver faultyserver commented Dec 12, 2023

Summary

When I added is_relatively_short_argument in #777, I added JsBinaryExpression as a match arm, but didn't realize that wouldn't encompass expressions like a ?? b, which are actually JsLogicalExpression. This PR just adds a similar arm to that function for handling logicals exactly like binaries, which matches Prettier's isBinaryish function used in the same place.

This PR also implements the missing half of Prettier's isSimpleTsType, introspecting arrays and generic types to extract the core type before checking for simplicity.

Test Plan

Added to the spec test for simple_arguments and grouping to cover logical expressions.

Copy link

netlify bot commented Dec 12, 2023

Deploy Preview for biomejs canceled.

Name Link
🔨 Latest commit b697e3a
🔍 Latest deploy log https://app.netlify.com/sites/biomejs/deploys/657808fad750570008dd2b76

@github-actions github-actions bot added A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages labels Dec 12, 2023
@faultyserver faultyserver changed the title fix(js_formatter): treat logical expressions as "binaryish" when grouping call aarguments fix(js_formatter): fix binaryish and ts type handling for grouping call arguments Dec 12, 2023
generic.type_arguments().map_or(None, |type_arguments| {
let argument_list = type_arguments.ts_type_argument_list();
if argument_list.len() == 1 {
argument_list.first().map_or(None, |first| first.ok())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This looks a little weird, but it's unwrapping Option<SyntaxResult<Node>> into just Option<Node> to match the structure of the rest of the types here.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Looks good to me

@ematipico ematipico merged commit 1986916 into main Dec 12, 2023
18 checks passed
@ematipico ematipico deleted the faulty/group-first-logical branch December 12, 2023 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants