Skip to content

Astro VS Code extension loses syntax highlighting / IntelliSense for <script> when conditionally rendered #15439

@rutvikk

Description

@rutvikk

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

Inside .astro files, placing a <script> tag inside a conditional expression ({cond ? (…) : null} or {cond && (…)}) causes the editor to stop providing JS hints/IntelliSense and sometimes breaks formatting behavior. The Astro compiler still builds and runs fine in dev and production. Inside the conditional, the <script> contents lose JS language features (no hints / incorrect tokenization), formatting fails too.

  1. Open VS Code with the Astro & Prettier extension installed
  2. Create an .astro file with the following content
  3. Observe script block syntax highlighting and IntelliSense
---
const view = 'Gallery';
---

{view === 'Gallery' ? (
  <script>
    for (let index = 0; index < 10; index++) {
      console.log(index);
    }
  </script>
) : null}

What's the expected result?

The <script> contents should behave like normal script content in .astro files:

  • syntax highlighting
  • IntelliSense / errors
  • formatting support

Link to Minimal Reproducible Example

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)feat: syntaxIssue in our syntax highlighting (scope)pkg: language-toolsRelated to language-tooling (scope)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions