Skip to content

Svelte parser can crash while facing style tag inside a script tag. #15215

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

Closed
HighFunctioningSociopathSH opened this issue Feb 5, 2025 · 3 comments

Comments

@HighFunctioningSociopathSH

Describe the bug

currently if you have a the string of a style tag anywhere in your script tag, you can possibly run into parsing errors because Svelte thinks I'm trying to declare a style tag and I was wondering if it can be fixed without having to cheat around it.

Reproduction

For example

<script lang="ts">
  const currentComponentCustomStyles = "h1{background:red}";
  const styleTag = `<style type="text/css">${currentComponentCustomStyles}</style>`
</script>

The above code will crash unless you do something like the following

<script lang="ts">
  const currentComponentCustomStyles = "h1{background:red}";
  const styleTag = "<" + `style type="text/css">${currentComponentCustomStyles}</style>`
</script>

Maybe Svelte's parser can treat the style tag as a simple string if its inside a string or tempalate literals?

Logs

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
    Memory: 7.60 GB / 15.63 GB
  Binaries:
    Node: 23.7.0 - C:\Program Files\nodejs\node.EXE
    npm: 11.1.0 - C:\Program Files\nodejs\npm.CMD
    bun: 1.1.3 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (129.0.2792.52)
    Internet Explorer: 11.0.22621.3527

Severity

annoyance

@brunnerh
Copy link
Member

brunnerh commented Feb 5, 2025

Probably duplicate of:

@sukeshpabolu
Copy link

you can find possible workarounds here: sveltejs/svelte-eslint-parser#346

@Conduitry
Copy link
Member

The Svelte compiler itself is fine with this code (as can be seen in the playground), so, yes, this is presumably a preprocessing issue, and is a duplicate of the above issue.

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

No branches or pull requests

4 participants