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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 BUG: error if template literal containing html string is used in component script #984

Open
WickyNilliams opened this issue Mar 18, 2024 · 1 comment
Labels
needs triage Issue needs to be triaged

Comments

@WickyNilliams
Copy link

What version of @astrojs/compiler are you using?

2.7.0

What package manager are you using?

npm

What operating system are you using?

mac

Describe the Bug

I have a component which contains some code approximately similar to this in the component script:

const source = `
  ${Math.random() ? `<style>test {}</style>` : ""}
`;

This causes some errors in the vscode extension.

It causes the following error at the end of the component script

Expression expected.ts(1109)

And this error in the component template:

JSX expressions must have one parent element.ts(2657)

Additionally, I get an error page in my site:

Expected ">" but found "class"

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-wfswdw

@github-actions github-actions bot added the needs triage Issue needs to be triaged label Mar 18, 2024
@WickyNilliams
Copy link
Author

WickyNilliams commented Mar 18, 2024

Weirdly the issue goes away if i add a comment like this at the end of the component script block

// `

i guess that the compiler is getting confused by some combination of nested template literals and the html in the string. if i remove the nesting template literal the issue goes away. if i remvoe the html (but keep the nesting) the issue also goes away. only when both are present is there an error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant