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

"Unexpected token" error when interpolating a template string that contains <script> tags #563

Open
2 tasks done
sfriedel opened this issue Aug 17, 2023 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working upstream issue

Comments

@sfriedel
Copy link

sfriedel commented Aug 17, 2023

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

8.47.0

What version of eslint-plugin-svelte are you using?

2.32.4

What did you do?

Configuration
module.exports = {
	root: true,
	extends: [
		'eslint:recommended',
		'plugin:@typescript-eslint/recommended',
		'plugin:svelte/recommended',
		'prettier'
	],
	parser: '@typescript-eslint/parser',
	plugins: ['@typescript-eslint'],
	parserOptions: {
		sourceType: 'module',
		ecmaVersion: 2020,
		extraFileExtensions: ['.svelte']
	},
	env: {
		browser: true,
		es2017: true,
		node: true
	},
	overrides: [
		{
			files: ['*.svelte'],
			parser: 'svelte-eslint-parser',
			parserOptions: {
				parser: '@typescript-eslint/parser'
			}
		}
	],
	globals: {
		// workaround for lack of $$Generic support in svelte-eslint-parser.
		// See https://github.com/sveltejs/svelte-eslint-parser/issues/306
		$$Generic: 'readonly'
	}
};
{@html `<script>${'console.log("test")'}</script>`}

What did you expect to happen?

no error

What actually happened?

[1:18]: Parsing error: Unexpected token {

Link to GitHub Repo with Minimal Reproducible Example

https://sveltejs.github.io/eslint-plugin-svelte/playground/#eJyrVkrOT0lVslKqdsgoyc1RSLApTi7KLCixU6lWT87PK87PSdXLyU/XiFEqSS0uiVHSVK+10YcqSahVqgUAz2EWSg==

Additional comments

The component compiles without error in the svelte playground and produces the expected console.log when run locally (though not in the playground for some reason).

@ota-meshi ota-meshi added the bug Something isn't working label Sep 4, 2023
@ota-meshi
Copy link
Member

Thank you for posting the issue.
However that is a parser issue. Check out sveltejs/svelte-eslint-parser#346 and workarounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream issue
Projects
None yet
Development

No branches or pull requests

2 participants