Skip to content
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

CompileError [ParseError]: <script> must have a closing tag #115

Open
silkroadnomad opened this issue Aug 23, 2023 · 4 comments
Open

CompileError [ParseError]: <script> must have a closing tag #115

silkroadnomad opened this issue Aug 23, 2023 · 4 comments

Comments

@silkroadnomad
Copy link

silkroadnomad commented Aug 23, 2023

When creating a const String variable inside <script></script> which contains the string <style> (e.g. while injecting a css style into an iframe later on), I receive CompileError [ParseError]: <script> must have a closing tag as an error and sveld stops generating.

The code works fine under normal Svelte conditions. Wondering if another preprocessor must run before rollup-plugin.js:164

Example:

<script>
const css=`<style>
		body{ color: white; }
		a:link { color: #ccc; }
		ins { background: green; text-decoration: none; }
		del { background:red;text-decoration: none; }
</style>`
....
</script>

Output:


CompileError [ParseError]: <script> must have a closing tag
    at error (/Users/xyz/node_modules/sveld/node_modules/svelte/compiler.js:13213:20)
    at Parser$1.error (/Users/xyz/code/improve-carbon/node_modules/sveld/node_modules/svelte/compiler.js:13291:10)
    at Object.read_script [as read] (/Users/xyz/code/improve-carbon/node_modules/sveld/node_modules/svelte/compiler.js:9001:17)
    at tag (/Users/xyz/code//node_modules/sveld/node_modules/svelte/compiler.js:12237:34)
    at new Parser$1 (/Users/xyz/code/node_modules/sveld/node_modules/svelte/compiler.js:13250:22)
    at parse$b (/Users/xyz/code//node_modules/sveld/node_modules/svelte/compiler.js:13390:21)
    at compile (/Users/xyz/code/node_modules/sveld/node_modules/svelte/compiler.js:44085:18)
    at ComponentParser.parseSvelteComponent (/Users//code//node_modules/sveld/lib/ComponentParser.js:240:48)
    at /Users/xyz//node_modules/sveld/lib/rollup-plugin.js:164:112
    at step (/Users/xyz//node_modules/sveld/lib/rollup-plugin.js:67:23) {
  code: 'unclosed-script',
  start: { line: 35, column: 13, character: 1064 },
  end: { line: 35, column: 13, character: 1064 },
  pos: 1064,
  filename: undefined,
  frame: '33: \n' +
    "34:   if (themeValue === 'g90' || themeValue === 'g80' || themeValue === 'g100') { //dark mode\n" +
    '35:     const css="\n' +
@metonym
Copy link
Collaborator

metonym commented Aug 23, 2023

Try escaping the closing "style" tag:

- </style>
+ <\/style>

@silkroadnomad
Copy link
Author

silkroadnomad commented Aug 23, 2023

I tried but no success. I also tried double escape via \\.
Imho, the string <style> is somehow caught for interpretation from the svelte compiler before </script> is closing, even tho it appears inside of a string variable.

@silkroadnomad
Copy link
Author

silkroadnomad commented Aug 24, 2023

I found a good workaround to put my ...

const css=`<style>
		body{ color: white; }
		a:link { color: #ccc; }
		ins { background: green; text-decoration: none; }
		del { background:red;text-decoration: none; }
</style>`

... into a separate style.js file. Exporting/Importing it again solves the problem.
But in general, there's still an issue.

@silkroadnomad
Copy link
Author

silkroadnomad commented Aug 31, 2023

btw. there is a similar issue here...
probably not related but noteworthy alexprey/sveltedoc-parser#58

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

2 participants