-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Labels
needs triageIssue needs to be triagedIssue needs to be triaged
Description
Astro Info
Astro v5.17.1
Vite v6.4.1
Node v22.14.0
System macOS (arm64)
Package Manager pnpm
Output static
Adapter none
Integrations astro-sitemap (v1.0.0)
astro-robots-txt (v1.0.0)
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When a <script> tag is placed inside a conditional expression in an .astro file (ternary or &&), Prettier fails to format the file and throws a parsing error. The code compiles and runs correctly in both dev and build; the issue appears to be in Prettier parsing. This might be related to <script> being treated as a special Astro tag and not a normal JSX/HTML node when nested under expression containers.
Reproduction
- Create a new Astro project
- Install and enable prettier + prettier-plugin-astro
- Add the following to a .astro file
- Run Prettier on the file (Format Document / CLI)
---
const view = 'Gallery';
---
{view === 'Gallery' ? (
<script>
for (let index = 0; index < 10; index++) {
console.log(index);
}
</script>
) : null}
{view === 'Gallery' &&
(<script>
for (let index = 0; index < 10; index++) {
console.log(index);
}
</script>)
}
What's the expected result?
Prettier formats the file without errors, and preserves the script contents (or formats them consistently).
Link to Minimal Reproducible Example
Participation
- I am willing to submit a pull request for this issue.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
needs triageIssue needs to be triagedIssue needs to be triaged