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 leading comments in mapped types with readonly #13427

Merged
merged 3 commits into from Sep 6, 2022

Conversation

thorn0
Copy link
Member

@thorn0 thorn0 commented Sep 4, 2022

Description

Fixes #11098

@sosukesuzuki I believe this is a more optimal fix than #11190. There is no need to support comments between the modifier and identifier. I used the tests from your PR.

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

Copy link
Member

@sosukesuzuki sosukesuzuki left a comment

Choose a reason for hiding this comment

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

I forgot about that PR I made myself. Your solution is excellent 👍

@bradzacher
Copy link

I noticed that this PR got merged into the next branch which I assume is 3.0?
If it is 3.0 - is there any way we could cherry-pick this across to the v2 main branch?

It seems a shame to wait until the v3 release to have this bug fixed.

@fisker
Copy link
Sponsor Member

fisker commented Feb 7, 2023

Ah, I was reading this part the other day, didn't know it's not shipped yet.

I have to say what a strange AST shape, why readonly not on TSTypeParameter?

@bradzacher
Copy link

why readonly not on TSTypeParameter?

The TSTypeParameter specifically represents the bit within the []:

{ readonly [ Key in Type ]: Value }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TSMappedType
             ^^^^^^^^^^^ .typeParameter -> TSTypeParameter
                            ^^^^^^ .typeAnnotation -> TypeNode

It's not the parameter that the readonly applies to - it's the entire "property". And given that a mapped type may only have one "property" declared in it - really that means the readonly applies to the mapped type itself.

It's worth noting that it's also a REALLY weird AST here - TSTypeParameter is the wrong node for us to emit - it's an abuse of the AST lol. In all other contexts having a .constraint on a type parameter means T extends Constraint, but in a mapped type instead it means T in Constraint.

Should probably change it (filed typescript-eslint/typescript-eslint#6433)

@fisker
Copy link
Sponsor Member

fisker commented Feb 8, 2023

@bradzacher released as 2.8.4

crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Feb 10, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [prettier](https://prettier.io) ([source](https://github.com/prettier/prettier)) | devDependencies | patch | [`2.8.3` -> `2.8.4`](https://renovatebot.com/diffs/npm/prettier/2.8.3/2.8.4) |

---

### Release Notes

<details>
<summary>prettier/prettier</summary>

### [`v2.8.4`](https://github.com/prettier/prettier/blob/HEAD/CHANGELOG.md#&#8203;284)

[Compare Source](prettier/prettier@2.8.3...2.8.4)

[diff](prettier/prettier@2.8.3...2.8.4)

##### Fix leading comments in mapped types with `readonly` ([#&#8203;13427](prettier/prettier#13427) by [@&#8203;thorn0](https://github.com/thorn0), [@&#8203;sosukesuzuki](https://github.com/sosukesuzuki))

<!-- prettier-ignore -->

```tsx
// Input
type Type = {
  // comment
  readonly [key in Foo];
};

// Prettier 2.8.3
type Type = {
  readonly // comment
  [key in Foo];
};

// Prettier 2.8.4
type Type = {
  // comment
  readonly [key in Foo];
};
```

##### Group params in opening block statements ([#&#8203;14067](prettier/prettier#14067) by [@&#8203;jamescdavis](https://github.com/jamescdavis))

This is a follow-up to [#&#8203;13930](prettier/prettier#13930) to establish wrapping consistency between opening block statements and else blocks by
grouping params in opening blocks. This causes params to break to a new line together and not be split across lines
unless the length of params exceeds the print width. This also updates the else block wrapping to behave exactly the
same as opening blocks.

<!-- prettier-ignore -->

```hbs
{{! Input }}
{{#block param param param param param param param param param param as |blockParam|}}
  Hello
{{else block param param param param param param param param param param as |blockParam|}}
  There
{{/block}}

{{! Prettier 2.8.3 }}
{{#block
  param
  param
  param
  param
  param
  param
  param
  param
  param
  param
  as |blockParam|
}}
  Hello
{{else block param
param
param
param
param
param
param
param
param
param}}
  There
{{/block}}

{{! Prettier 2.8.4 }}
{{#block
  param param param param param param param param param param
  as |blockParam|
}}
  Hello
{{else block
  param param param param param param param param param param
  as |blockParam|
}}
  There
{{/block}}
```

##### Ignore files in `.sl/` ([#&#8203;14206](prettier/prettier#14206) by [@&#8203;bolinfest](https://github.com/bolinfest))

In [Sapling SCM](https://sapling-scm.com/), `.sl/` is the folder where it stores its state, analogous to `.git/` in Git. It should be ignored in Prettier like the other SCM folders.

##### Recognize `@satisfies` in Closure-style type casts ([#&#8203;14262](prettier/prettier#14262) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```jsx
// Input
const a = /** @&#8203;satisfies {Record<string, string>} */ ({hello: 1337});
const b = /** @&#8203;type {Record<string, string>} */ ({hello: 1337});

// Prettier 2.8.3
const a = /** @&#8203;satisfies {Record<string, string>} */ { hello: 1337 };
const b = /** @&#8203;type {Record<string, string>} */ ({ hello: 1337 });

// Prettier 2.8.4
const a = /** @&#8203;satisfies {Record<string, string>} */ ({hello: 1337});
const b = /** @&#8203;type {Record<string, string>} */ ({hello: 1337});
```

##### Fix parens in inferred function return types with `extends` ([#&#8203;14279](prettier/prettier#14279) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```ts
// Input
type Foo<T> = T extends ((a) => a is infer R extends string) ? R : never;

// Prettier 2.8.3 (First format)
type Foo<T> = T extends (a) => a is infer R extends string ? R : never;

// Prettier 2.8.3 (Second format)
SyntaxError: '?' expected.

// Prettier 2.8.4
type Foo<T> = T extends ((a) => a is infer R extends string) ? R : never;
```

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMjUuMSIsInVwZGF0ZWRJblZlciI6IjM0LjEyOC4zIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1775
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
medikoo pushed a commit to medikoo/prettier-elastic that referenced this pull request Jan 4, 2024
medikoo pushed a commit to medikoo/prettier-elastic that referenced this pull request Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants