Skip to content

Nested snippets cause parsing error #522

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
4 tasks done
vojtechsimetka opened this issue May 20, 2024 · 0 comments · Fixed by #540
Closed
4 tasks done

Nested snippets cause parsing error #522

vojtechsimetka opened this issue May 20, 2024 · 0 comments · Fixed by #540
Labels
bug Something isn't working

Comments

@vojtechsimetka
Copy link

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

  • I'm using eslint-plugin-svelte. (*.svelte file linting does not work with the parser alone. You should also use eslint-plugin-svelte with it.)
  • I'm sure the problem is a parser problem. (If you are not sure, search for the issue in eslint-plugin-svelte repo and open the issue in eslint-plugin-svelte repo if there is no solution.
  • 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.56.0

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

What did you do?

Configuration
/** @type { import("eslint").Linter.Config } */
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'
			}
		}
	]
};

src/lib/foo.svelte

<script>
	const { foo } = $props();
</script>

<div>
	{@render foo()}
</div>

src/page/+page.svelte

<script>
	import Foo from '$lib/foo.svelte';
</script>

{#snippet foo()}
	{#snippet bar()}Bar{/snippet}
	Foo {@render bar()}
{/snippet}

<Foo {foo} />

What did you expect to happen?

No error

What actually happened?

pnpm lint

> [email protected] lint nested-snippet-linter-error
> prettier --check . && eslint .

Checking formatting...
All matched files use Prettier code style!

nested-snippet-linter-error/src/routes/+page.svelte
0:0  error  Parsing error: Cannot read properties of undefined (reading 'length')

✖ 1 problem (1 error, 0 warnings)

 ELIFECYCLE  Command failed with exit code 1.


 However, issue in another project was even more cryptic but I can't recreate in minimal example

...src/routes/+page.svelte
0:0  error  Parsing error: fnDecl.params is not iterable

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/vojtechsimetka/nested-snippet-linter-error

Additional comments

Same happens with eslint@9

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

Successfully merging a pull request may close this issue.

2 participants