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

Svelte 5 TS: class property in template literal causes Unterminated template / Unexpected token! #13188

Closed
cshaa opened this issue Sep 10, 2024 · 4 comments
Labels

Comments

@cshaa
Copy link

cshaa commented Sep 10, 2024

Describe the bug

Optional chaining to a property named class inside a template literal in a TypeScript script breaks the Svelte 5 parser.

Reproduction

<script lang="ts">
  const str = `${obj?.class}`;
</script>

Throws Unterminated template.

<script lang="ts">
  const str = `${obj?.class} ${42}`;
</script>

Throws Unexpected token.

Severity

blocking an upgrade

@GeoffCox
Copy link
Contributor

+1 This happens for <script> tags as well. Maybe the compiler continues parsing for svelte within template strings.

<script>
	let example = `<script></script>`;
</script>

<pre>{example}</pre>

@MotionlessTrain
Copy link
Contributor

+1 This happens for <script> tags as well. Maybe the compiler continues parsing for svelte within template strings.

<script>
	let example = `<script></script>`;
</script>

<pre>{example}</pre>

For script tags, this is to be expected (this breaks in exactly the same way in vanilla html)

The optional class property does look strange

@dummdidumm
Copy link
Member

May be related to the acorn-typescript plugin we use to parse TS; without lang="ts" it works.

@elron
Copy link

elron commented Nov 22, 2024

I encounter this too

[plugin:vite-plugin-svelte] src/lib/components/UnicodeItem.svelte:4:9 Unexpected token
When I remove lang="ts" it works, but I need TS in some components so its blocking my upgrade.

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

No branches or pull requests

5 participants