Skip to content

Parsing error when </script> is present in a string literal of a component script #562

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

Closed
2 tasks done
sfriedel opened this issue Aug 17, 2023 · 2 comments
Closed
2 tasks done

Comments

@sfriedel
Copy link

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?

When a string literal in a svelte component script contains "</script>" the eslint plugin produces a parser error.

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'
	}
};
<script>
	const src = '</script>'
	console.log(src)
</script>

<h1>Example</h1>

What did you expect to happen?

Not receiving a parser error for a valid svelte component :)

What actually happened?

[4:0]: Parsing error: </script> attempted to close an element that was not open

Link to GitHub Repo with Minimal Reproducible Example

https://sveltejs.github.io/eslint-plugin-svelte/playground/#eJyrVkrOT0lVslKyKU4uyiwosYvJiylJzs8rLlEoLkpWsFVQt9GHyqjDpPJzUvVy8tM1gAo0Y/Lg8kDpPJsMQzvXisTcgpxUG30gOyZPqRYAykAitA==

Additional comments

No response

@baseballyama
Copy link
Member

This is Svelte compiler's issue.
Not ESLint issue.
https://svelte.dev/repl/104b0cb2a8d94476b097f7fc752dbce8?version=4.2.0

@baseballyama baseballyama closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2023
@sfriedel
Copy link
Author

@baseballyama thanks and sorry for the noise. Apparently this is a known behaviour in svelte that won't be changed.

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