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 shorthand props not working inside expressions and update error handling #246

Merged
merged 5 commits into from
Aug 4, 2022

Conversation

Princesseuh
Copy link
Member

@Princesseuh Princesseuh commented Aug 3, 2022

Changes

This PR does two things:

  • Fixed shorthands props not working in expression. This is a more complicated issue than it might seems because inside expressions, we use a TypeScript parser and as such, Astro-isms will cause a parsing error. I solve this by first transforming the expression into a JSX compatible one and then re-adding the Astro-ism once it's formatted
  • Changed how error handling works when we can't parse an expression, now the plugin will report the error, but won't actually fail. Instead the node will be left as-is. This is consistant with how other Prettier plugins work (ex: the Svelte one does this, so does the official MDX one (I believe?)). If PRETTIER_DEBUG=1 is set, then the plugin will throw like before (just like official Prettier plugins does)

Both changes didn't need to be done in the same PR, however updating the error handling made it easier to implement the shorthand fix in a nice way

Fix #168
Fix #224

Testing

Added a test

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Aug 3, 2022

🦋 Changeset detected

Latest commit: 7ad992b

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 Minor

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

@Princesseuh Princesseuh changed the title Fix shorthand props not working inside expressions Fix shorthand props not working inside expressions and update error handling Aug 3, 2022
@antonyfaris
Copy link
Member

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants