`</script>` in script block breaks SFC parsing
Vue version
3.2.45
Link to minimal reproduction
Steps to reproduce
Include </script>
within a string in the script block
What is expected?
The template should still compile.
What is actually happening?
The <script>
block is not correctly parsed.
System Info
No response
Any additional comments?
Upstream issue: https://github.com/nuxt/nuxt.js/issues/15624 Fuller reproduction: https://stackblitz.com/edit/github-mgrldc
I guess we have to avoid </script>
string in <script>
block since the compiler cannot perceive if it's a JavaScript string or the end tag when parsing SFC.
There's a workaround, splitting the string.
<script lang="ts" setup>
const myVar = "</" + "script>";
</script>
A note from #7944: the syntax highlighting in VS Code doesn't correctly handle this situation, while in the SFC playground, we can clearly see the first closing tag.
The easiest and safest way to avoid [..] is to always escape an ASCII case-insensitive match for
<!--
as\x3C!--
,<script
as\x3Cscript
, and</script
as\x3C/script
when these sequences appear in literals in scripts [..]
So according to the WHATWG HTML Standard, as long as the Vue SFC template
aims to be a superset(?) of HTML, this behavior is the feature, rather than a bug :(