Skip to content

Conversation

@thecrypticace
Copy link
Contributor

@thecrypticace thecrypticace commented Dec 1, 2025

This is a work in progress.

Fixes #417

Notes:

  1. For some reason embed.getVisitorKeys is being called when using the Svelte plugin — but I'm pretty sure it's supposed to be optional. I don't know why bumping Prettier has caused this to happen. My temporary patch that seems to fix it is to always define it and delegate to printer.getVisitorKeys but that definitely doesn't feel right. Need to figure out why it's being called in the first place. Fixed. We should not (nor do we need to) override options.printer.

  2. Some older versions of some prettier plugins we were testing against aren't compatible with v3.7. Updating them has fixed that issue though.

  3. The current version (v4.0.3) of prettier-plugin-multiline-arrays is broken with Prettier v3.7+ on its own so those tests are going to fail — not related to our plugin at all:

Reproductions for that issue:

import { format } from "prettier";

// getVisitorKeys is not a function or its return value is not iterable
await format("let arr = ['one']", {
  parser: "babel",
  plugins: ["prettier-plugin-multiline-arrays"],
});

// Failed to wrap JS printer call for property "handleComments" and subProperty "remaining": 
// TypeError: Cannot read properties of undefined (reading 'value')
await format("let arr = ['one'] /** test */", {
  parser: "babel",
  plugins: ["prettier-plugin-multiline-arrays"],
});

Some older/outdated plugins don’t work with Prettier v3.7
@noga-dev
Copy link

noga-dev commented Dec 1, 2025

Nice. Current solution until this gets released:

    "prettier-plugin-tailwindcss": "git://github.com:tailwindlabs/prettier-plugin-tailwindcss#ab900fa3ecdca78a2e19647336c503f9bf45e741",

@fisker
Copy link

fisker commented Dec 1, 2025

@thecrypticace

I spend sometime to debug, seem the root cause is here

options.printer = printers[original.astFormat]
after parsing, the printer lost information needed in core.

@thecrypticace thecrypticace marked this pull request as ready for review December 1, 2025 13:14
It’s unncessary and causes an incompatibility with Prettier v3.7+

Most likely a left over from when we *also* supported Prettier v2.
That plugin is currently broken when used with Prettier v3.7

// @ts-ignore
return base.printers['svelte-ast'].embed(path, options)
}
Copy link

@fisker fisker Dec 1, 2025

Choose a reason for hiding this comment

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

Should we consider use a proxy here?

const embed = new Proxy(base.printers['svelte-ast'].embed, {
	apply(target, thisArgument, argumentsList) {
		const [path, options] = argumentsList;
      	mutateOriginalText(path, options)
		return Reflect.apply(target, thisArgument, argumentsList)
	}
})

just incase svelte add visitorKeys for embed in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooh yeah, that's a good idea. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think it's worth doing the same for print as well?

Copy link

Choose a reason for hiding this comment

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

Yes, but currently Prettier doesn't support additional keys on it. So up to you.

@thecrypticace thecrypticace merged commit 90e56c3 into main Dec 1, 2025
1 check passed
@thecrypticace thecrypticace deleted the fix/issue-417 branch December 1, 2025 15:25
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.

Breaks while using compatible plugins after updating to Prettier v3.7

5 participants