sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
17.81k stars 1.78k forks source link

Error parsing +svelte.page when the script section contains "</script>" in comment or in string #12145

Closed voidah closed 3 weeks ago

voidah commented 3 weeks ago

Describe the bug

Parsing fails when the string is contained anywhere in the script section, even if enclosed in a string or a comment.

Reproduction

Create a new +page.svelte and use that code:

<script lang="ts">
    // Case 1:
    // </script>

    // Case 2:
    let text = '</script>';
    let a = 1;
</script>

As you will notice, both case in that code prevent the page from compiling. Case 1 should not have any effect because the tag is in comment, and case 2 should not generate an error as the is enclosed in string (that's how I noticed that problem in the first place)

Logs

[plugin:vite-plugin-svelte] /home/REDACTED/REDACTED/REDACTED/REDACTED/src/routes/test/+page.svelte:4:16 </script> attempted to close an element that was not open

/home/REDACTED/REDACTED/REDACTED/REDACTED/src/routes/test/+page.svelte:4:16

2 |  
 3 |      // Case 2:
 4 |      let text = '</script>';
                      ^
 5 |      let a = 1;
 6 |  </script>

System Info

System:
    OS: Linux 6.8 Arch Linux
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 16.25 GB / 31.00 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 21.7.1 - /usr/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.5.1 - /usr/bin/npm
  Browsers:
    Chromium: 123.0.6312.105
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.1.1 
    @sveltejs/adapter-node: ^4.0.1 => 4.0.1 
    @sveltejs/kit: ^2.0.0 => 2.5.0 
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.0.2 
    svelte: ^4.2.7 => 4.2.9 
    vite: ^5.0.3 => 5.0.12

Severity

serious, but I can work around it

Additional Information

No response

brunnerh commented 3 weeks ago

A list of issues this is a duplicate of: https://github.com/sveltejs/svelte/issues/9039#issuecomment-1650599142