-
Notifications
You must be signed in to change notification settings - Fork 657
feat(rome_js_formatter): Conditional JSX Chain layout #3150
Conversation
57b8c32
to
4d11dff
Compare
Deploying with Cloudflare Pages
|
4d11dff
to
c948a72
Compare
/// Gets passed through from the root to the consequent and alternate of [JsConditionalExpression]s. | ||
/// | ||
/// Doesn't apply for [TsConditionalType]. | ||
jsx_chain: ConditionalJsxChain, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to create a new FormatJsAnyConditionalRule
so that it's possible to pass option values without cluttering the JsAnyConditional
node. The reason for this is that it's necessary to know if a JsxTagExpression
appears in any of the parent conditional expressions.
Checking this for every conditional is expensive, so we only check it at the root and then pass the information down to the consequent
and alternate
formatting.
/// : c | ||
/// ).member | ||
/// ``` | ||
fn should_extra_indent( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only moved this method from the impl JsAnyConditional
to implement it on the rule instead.
This PR implements Prettier's conditional JSX chain layout. ``` abcdefgh ? ( <Element> <Sub /> <Sub /> </Element> ) : ( <Element2> <Sub /> <Sub /> </Element2> ); ``` That parenthesizes the `consequent` and `alternate` except for `null`, `undefined`, and nested conditionals in the alternate. This PR further removes the `Default` implementation from `JsFormatOptions` because passing a `SourceType` that matches with the type of the AST is mandatory to get correct formatting results. ## Tests I verified the prettier snapshots and added our own tests to cover the exceptions of `null`, `undefined` and nested alternates that don't get parenthesized.
c948a72
to
9b3ba60
Compare
✅ Deploy Preview for rometools canceled.
|
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
Co-authored-by: Emanuele Stoppa <[email protected]>
Co-authored-by: Emanuele Stoppa <[email protected]>
This PR implements Prettier's conditional JSX chain layout.
That parenthesizes the
consequent
andalternate
except fornull
,undefined
, and nested conditionals in the alternate.This PR further removes the
Default
implementation fromJsFormatOptions
because passing aSourceType
that matches with the type of the AST is mandatory to get correct formatting results.Tests
I verified the prettier snapshots and added our own tests to cover the exceptions of
null
,undefined
and nested alternates that don't get parenthesized.Average compatibility: 85.41 -> 85.53
Compatible lines: 83.70 -> 83.95
It's expected for the tests to fail until #3149 is merged