Skip to content

Preserving comments' placement property#19567

Merged
fisker merged 6 commits into
prettier:mainfrom
Janther:preserving-comment-placement
Jul 9, 2026
Merged

Preserving comments' placement property#19567
fisker merged 6 commits into
prettier:mainfrom
Janther:preserving-comment-placement

Conversation

@Janther

@Janther Janther commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #19515.

Avoid deleting comment.placement since it might be used by plugins.
Updated the documentation to reflect this change.
Updated a snapshot that conveniently checked this particular property so no need for further tests to be added.

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.
  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

@netlify

netlify Bot commented Jul 8, 2026

Copy link
Copy Markdown

Deploy Preview for prettier ready!

Name Link
🔨 Latest commit b708007
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a4fc13d8fee9e000748eca7
😎 Deploy Preview https://deploy-preview-19567--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Jul 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

yarn add https://pkg.pr.new/@prettier/plugin-hermes@19567.tgz
yarn add https://pkg.pr.new/@prettier/plugin-oxc@19567.tgz
yarn add https://pkg.pr.new/prettier@19567.tgz

commit: b708007

@Janther Janther force-pushed the preserving-comment-placement branch from b60e343 to 9d94ba5 Compare July 8, 2026 03:07
@Janther

Janther commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@fisker all tests are passing but I had to attach the placement outside a check for attachPropertiesToComment which takes into account avoidAstMutation. It looks like you worked hard on not touching this so not sure if this is the best way forward.

@Janther Janther force-pushed the preserving-comment-placement branch from fa68055 to f75f652 Compare July 8, 2026 05:26
@fisker

fisker commented Jul 8, 2026

Copy link
Copy Markdown
Member

Thanks for fixing the issue.

It looks like you worked hard on not touching this so not sure if this is the best way forward.

It's fine, we never mentioned avoidAstMutation in any version, and not much progress for years.


  1. Should we document the property? avoidAstMutation is our goal after all, let's still keep it private? (Fine to document it too)
  2. Let's add a test for it? (Can write a simple plugin to require comment to have placement) The existing --debug-print-comments is a debug feature, it can be easily broken by accident.

@fisker fisker changed the title preserving comments' placement property Preserving comments' placement property Jul 9, 2026
@fisker fisker merged commit 2bb67ce into prettier:main Jul 9, 2026
34 checks passed
sys-support pushed a commit to 3caravelle/renovate that referenced this pull request Jul 13, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [prettier](https://prettier.io) ([source](https://github.com/prettier/prettier)) | [`3.9.4` → `3.9.5`](https://renovatebot.com/diffs/npm/prettier/3.9.4/3.9.5) | ![age](https://developer.mend.io/api/mc/badges/age/npm/prettier/3.9.5?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/prettier/3.9.4/3.9.5?slim=true) |

---

### Release Notes

<details>
<summary>prettier/prettier (prettier)</summary>

### [`v3.9.5`](https://github.com/prettier/prettier/blob/HEAD/CHANGELOG.md#395)

[Compare Source](prettier/prettier@3.9.4...3.9.5)

[diff](prettier/prettier@3.9.4...3.9.5)

##### Markdown: Cap ordered list mark at 999,999,999 ([#&#8203;19351](prettier/prettier#19351) by [@&#8203;tats-u](https://github.com/tats-u))

CommonMark parsers only support ordered list item numbers up to 999,999,999.

With this change, Prettier now caps the ordered list item number at 999,999,999 to ensure that the output is correctly parsed as an ordered list by CommonMark parsers. Numbers larger than 999,999,999 are not parsed as list item numbers and are left unchanged in the output:

<!-- prettier-ignore -->

```markdown
<!-- Input -->
999999998. text
999999998. text
999999998. text
999999998. text

1234567890123456789012) text

<!-- Prettier 3.9.4 -->
999999998. text
999999999. text
1000000000. text
1000000001. text

1234567890123456789012) text

<!-- Prettier 3.9.5 -->
999999998. text
999999999. text
999999999. text
999999999. text

1234567890123456789012) text
```

##### Markdown: Avoid corrupting empty link with title ([#&#8203;19487](prettier/prettier#19487) by [@&#8203;andersk](https://github.com/andersk))

Do not remove `<>` from an inline link or image with an empty URL and a title, as this removal would change its interpretation.

<!-- prettier-ignore -->

```md
<!-- Input -->
[link](<> "title")

<!-- Prettier 3.9.4 -->
[link]( "title")

<!-- Prettier 3.9.5 -->
[link](<> "title")
```

##### Less: Remove extra spaces after `[` in map lookups ([#&#8203;19503](prettier/prettier#19503) by [@&#8203;kovsu](https://github.com/kovsu))

<!-- prettier-ignore -->

```less
// Input
.foo {
  color: #theme[ primary];
  color: #theme[@&#8203;name];
  color: #theme[@&#8203;@&#8203;name];
}

// Prettier 3.9.4
.foo {
  color: #theme[ primary];
  color: #theme[ @&#8203;name];
  color: #theme[ @&#8203;@&#8203;name];
}

// Prettier 3.9.5
.foo {
  color: #theme[primary];
  color: #theme[@&#8203;name];
  color: #theme[@&#8203;@&#8203;name];
}
```

##### CSS: Prevent addition space in `type()` with `+` ([#&#8203;19516](prettier/prettier#19516) by [@&#8203;bigandy](https://github.com/bigandy))

This fixes the addition space before `+` in CSS `type()` declaration. For example `type(<number>+)` was being converted into `type(<number> +)` which is invalid CSS and does not work.

<!-- prettier-ignore -->

```css
/* Input */
div {
  border-radius: attr(br type(<length>+));
}

/* Prettier 3.9.4 */
div {
  border-radius: attr(br type(<length> +));
}

/* Prettier 3.9.5 */
div {
  border-radius: attr(br type(<length>+));
}
```

##### Less: Remove spaces between merge markers and colons ([#&#8203;19517](prettier/prettier#19517) by [@&#8203;kovsu](https://github.com/kovsu))

<!-- prettier-ignore -->

```less
// Input
a {
  box-shadow  +  : 0 0 1px #&#8203;000;
}

// Prettier 3.9.4
a {
  box-shadow+  : 0 0 1px #&#8203;000;
}

// Prettier 3.9.5
a {
  box-shadow+: 0 0 1px #&#8203;000;
}
```

##### Markdown: Preserve wiki links with aliases ([#&#8203;19527](prettier/prettier#19527) by [@&#8203;kovsu](https://github.com/kovsu))

<!-- prettier-ignore -->

```markdown
<!-- Input -->
[[Foo:Bar]]

<!-- Prettier 3.9.4 -->
[[Foo]]

<!-- Prettier 3.9.5 -->
[[Foo:Bar]]
```

##### TypeScript: Fix comments being dropped on shorthand `type` import/export specifiers ([#&#8203;19565](prettier/prettier#19565) by [@&#8203;kirkwaiblinger](https://github.com/kirkwaiblinger))

<!-- prettier-ignore -->

```tsx
// Input
export { type /* comment */ T } from "foo";
import { type /* comment */ T } from "foo";

// Prettier 3.9.4
Error: Comment "comment" was not printed. Please report this error!

// Prettier 3.9.5
export { type /* comment */ T } from "foo";
import { type /* comment */ T } from "foo";
```

##### Miscellaneous: Preserving comments' `placement` property ([#&#8203;19567](prettier/prettier#19567) by [@&#8203;Janther](https://github.com/Janther))

Prettier\@&#8203;3.9.0 deleted an undocumented property on comments, which was already used by plugins, `comment.placement` is now available again after comment attach.

##### Flow: Stop enforcing empty module declaration to break ([#&#8203;19568](prettier/prettier#19568) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```flow
// Input
declare module "foo" {}

// Prettier 3.9.4
declare module "foo" {
}

// Prettier 3.9.5
declare module "foo" {}
```

##### Angular: Support expression for exhaustive typechecking ([#&#8203;19571](prettier/prettier#19571) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```html
<!-- Input -->
@&#8203;switch (state.mode) {
  @&#8203;default never(state);
}

<!-- Prettier 3.9.4 -->
@&#8203;switch (state.mode) {
  @&#8203;default never;
}

<!-- Prettier 3.9.5 -->
@&#8203;switch (state.mode) {
  @&#8203;default never(state);
}
```

##### TypeScript: Ignore comments inside mapped type when checking type parameter comments ([#&#8203;19572](prettier/prettier#19572) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```tsx
// Input
foo<{
  // comment
  [key in keyof Foo]: number
}>();

// Prettier 3.9.4
foo<
  {
    // comment
    [key in keyof Foo]: number;
  }
>();

// Prettier 3.9.5
foo<{
  // comment
  [key in keyof Foo]: number;
}>();
```

##### Less: Fix adjacent block comments being corrupted ([#&#8203;19574](prettier/prettier#19574) by [@&#8203;kovsu](https://github.com/kovsu))

<!-- prettier-ignore -->

```less
// Input
/* a *//* b */
/* a */* {
  color: red;
}

// Prettier 3.9.4
/* a */
/* b */
/* a * {
  color: red;
}

// Prettier 3.9.5
/* a */ /* b */
/* a */
* {
  color: red;
}
```

##### JavaScript: Handle dangling comments in `SwitchStatement` ([#&#8203;19581](prettier/prettier#19581) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```jsx
// Input
switch (foo) {
 // comment
}

// Prettier 3.9.4
switch (
  foo
  // comment
) {
}

// Prettier 3.9.5
switch (foo) {
  // comment
}
```

##### TypeScript: Remove space in comment-only object type ([#&#8203;19583](prettier/prettier#19583) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```tsx
// Input
var foo = {
  /* comment */
};
type Foo = {
  /* comment */
};

// Prettier 3.9.4
var foo = {/* comment */};
type Foo = { /* comment */ };

// Prettier 3.9.5
var foo = {/* comment */};
type Foo = {/* comment */};
```

</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:eyJjcmVhdGVkSW5WZXIiOiI0Mi44MS4zIiwidXBkYXRlZEluVmVyIjoiNDIuODEuMyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Reviewed-on: https://git.3caravelle.net/3Caravelle/renovate/pulls/45
Co-authored-by: Renovate Bot <renovate-bot@3caravelle.com>
Co-committed-by: Renovate Bot <renovate-bot@3caravelle.com>
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.

comment.placement is undefined when printing after 3.9.0.

2 participants