Skip to content

Fix problems with prettier v3.6.0+#408

Merged
NullVoxPopuli merged 11 commits intomainfrom
upgrade-prettier
Nov 29, 2025
Merged

Fix problems with prettier v3.6.0+#408
NullVoxPopuli merged 11 commits intomainfrom
upgrade-prettier

Conversation

@evoactivity
Copy link
Copy Markdown
Member

@evoactivity evoactivity commented Nov 29, 2025

Supercedes #407
Closes #406

@evoactivity
Copy link
Copy Markdown
Member Author

Can I get opinions please @NullVoxPopuli @gitKrystan

The failure is with semi: false, I think the new output is actually correct, we have this same expectation for prettier to add in an ASI in a different typescript file already

// config > semi: false > it formats ../cases/gts/implied-export-default-satisfies.gts
import type { TemplateOnlyComponent } from "@ember/component/template-only"

;<template>
  Implied Export Default with Satisfies
</template> satisfies TemplateOnlyComponent

@fisker
Copy link
Copy Markdown
Contributor

fisker commented Nov 29, 2025

Is there a problem switching to TaggedTemplateExpression?

@fisker
Copy link
Copy Markdown
Contributor

fisker commented Nov 29, 2025

Is it causing parse failure?

@evoactivity
Copy link
Copy Markdown
Member Author

evoactivity commented Nov 29, 2025

There were quite a few problems with how tagged templates ended up formatting, breaking our expectations of how a template tag should be output.

Some examples comparing the two approaches.

We have about 80 test cases for these idiosyncrasies that fail when using the tagged template approach.

My problem was I didn't fully understand what innerComments was actually being used for (to remove the comment from the AST so prettier wouldn't expect it to be printed as a comment). The comment approach should be fine for us.

@NullVoxPopuli
Copy link
Copy Markdown
Member

NullVoxPopuli commented Nov 29, 2025

I think the comment was for keeping overall character length the same?

@evoactivity
Copy link
Copy Markdown
Member Author

evoactivity commented Nov 29, 2025

@fisker I do have a question actually

On versions 3.6.0, 3.6.1 and 3.6.2 our // prettier-ignore tests fail (as path.node?.leadingComments is now always undefined), but begin passing again on 3.7.x. Looks like there was work done here but I don't understand how that is now making things work for us as I didn't do anything to the ignore code in this plugin (and if I remove that code completely our tests still pass on 3.7.x). Was just curious why those changes (or maybe some other changes) made it all work for us again.

@evoactivity
Copy link
Copy Markdown
Member Author

I think the comment was for keeping overall character length the same?

Yeah partly that, and partly because the formatting around an ObjectExpression/StaticBlock/BlockStatement that only contains a comment, works in such a way that matches our expectations for how templates should be treated as part of the JS. My attempts at using an object with a key and string or a tagged template resulted in a lot of differences around line breaks, ASI etc.

@evoactivity
Copy link
Copy Markdown
Member Author

Ready for review.
I've tested with 3.5.3, 3.6.0, 3.6.1, 3.6.2, 3.7.0, 3.7.1, 3.7.2, 3.7.3

All work as expected.

@NullVoxPopuli
Copy link
Copy Markdown
Member

NullVoxPopuli commented Nov 29, 2025

can we add all those minor versions to CI?

@embroider/try should help out, like how we do with library testing

Comment thread src/parse/index.ts

return (
(commentStart === start && commentEnd === end) ||
(commentStart === start + 1 && commentEnd === end - 1) ||
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.

what do 1 and 7 represent?

Copy link
Copy Markdown
Member Author

@evoactivity evoactivity Nov 29, 2025

Choose a reason for hiding this comment

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

The offsets from the original template don't always match the offsets of the AST comments due to the prefix and suffix.

start + 1 = {
start + 7 = static{
end - 1 = }

eg template start is 14 in a class component. AST sees /*the template */ so starts at 21. So bump the template start to 21 to account for static{ before the comment begins and we can match.

@evoactivity
Copy link
Copy Markdown
Member Author

can we add all those minor versions to CI?

@embroider/try should help out, like how we do with library testing

We should, better in a different PR though

@NullVoxPopuli NullVoxPopuli added the bug Something isn't working label Nov 29, 2025
@NullVoxPopuli NullVoxPopuli merged commit f1a5193 into main Nov 29, 2025
4 checks passed
@NullVoxPopuli NullVoxPopuli deleted the upgrade-prettier branch November 29, 2025 21:08
@github-actions github-actions Bot mentioned this pull request Nov 29, 2025
@fisker
Copy link
Copy Markdown
Contributor

fisker commented Nov 29, 2025

@fisker I do have a question actually

On versions 3.6.0, 3.6.1 and 3.6.2 our // prettier-ignore tests fail (as path.node?.leadingComments is now always undefined), but begin passing again on 3.7.x. Looks like there was work done here but I don't understand how that is now making things work for us as I didn't do anything to the ignore code in this plugin (and if I remove that code completely our tests still pass on 3.7.x). Was just curious why those changes (or maybe some other changes) made it all work for us again.

print function won't receive ignored nodes, if you want access, add printPrettierIgnored.

estree plugin use the same function for print and printPrettierIgnored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Broken with prettier 3.7.x

3 participants