Skip to content

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

Merged
ematipico merged 3 commits into
mainfrom
faulty/group-first-logical
Dec 12, 2023
Merged

fix(js_formatter): fix binaryish and ts type handling for grouping call arguments#1152
ematipico merged 3 commits into
mainfrom
faulty/group-first-logical

Conversation

@faultyserver

@faultyserver faultyserver commented Dec 12, 2023

Copy link
Copy Markdown
Contributor

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.

@netlify

netlify Bot commented Dec 12, 2023

Copy link
Copy Markdown

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
Copy Markdown
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.

@faultyserver faultyserver force-pushed the faulty/group-first-logical branch from d5c81f4 to 1923357 Compare December 12, 2023 06:21

@ematipico ematipico left a comment

Copy link
Copy Markdown
Member

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
@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