Skip to content

fix: Pass options to estree willPrintOwnComments - #494

Merged
Princesseuh merged 4 commits into
withastro:mainfrom
oti:fix/willPrintOwnComments-options
Oct 5, 2026
Merged

Princesseuh merged 4 commits into
withastro:mainfrom
oti:fix/willPrintOwnComments-options

Conversation

@oti

@oti oti commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Changes

  • willPrintOwnComments delegated to Prettier's estree printer without passing options.

  • The estree implementation reads options.semi when an expression statement has a leading comment, so input like this threw TypeError: Cannot read properties of undefined (reading 'semi'):

    <div>
    	{
    		(() => {
    			// comment
    			foo();
    		})()
    	}
    </div>
  • Forward options as the second argument.

Testing

  • Added the other/comment-before-expression-statement fixture.
  • Confirmed the new test fails with the TypeError above without the fix and passes with it.
  • pnpm test passes.

Docs

Bug fix only; no docs changes needed.

oti added 2 commits October 4, 2026 13:01
willPrintOwnComments delegated to Prettier's estree printer without
passing options. The estree implementation reads options.semi, so a
comment before a statement inside a template expression caused:

  `TypeError`: Cannot read properties of undefined (reading 'semi')

Forward options as the second argument.
Add a regression fixture for passing options to estree's
willPrintOwnComments. A comment before an expression statement inside
a template expression made Prettier read options.semi, which threw
before the fix:

  `TypeError`: Cannot read properties of undefined (reading 'semi')
@changeset-bot

changeset-bot Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c870f42

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
prettier-plugin-astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

oti added 2 commits October 4, 2026 13:32
Add a patch changeset for the TypeError thrown when a comment appears
before a statement inside a template expression.
Prettier's type declarations only list the path parameter for
willPrintOwnComments, but the estree implementation also takes options
and reads options.semi. Add options to the estree printer type so
forwarding it type-checks.

@Princesseuh Princesseuh left a comment

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.

Looks great, thank you!

@Princesseuh
Princesseuh merged commit ee01a5d into withastro:main Oct 5, 2026
6 checks passed
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.

2 participants