Skip to content

fix: infinite loop in attr.ts #409

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

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/weak-lizards-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": patch
---

fix: infinite loop in attr.ts
10 changes: 8 additions & 2 deletions src/parser/converts/attr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import type {
SvelteElement,
SvelteScriptElement,
SvelteStyleElement,
SvelteElseBlock,
SvelteAwaitBlock,
} from "../../ast";
import type ESTree from "estree";
import type { Context } from "../../context";
Expand Down Expand Up @@ -678,9 +680,13 @@ function buildLetDirectiveType(

/** Find parent component element */
function findParentComponent(node: SvelteElement) {
let parent: SvelteElement["parent"] | null = node.parent;
let parent:
| SvelteElement["parent"]
| SvelteElseBlock
| SvelteAwaitBlock
| null = node.parent;
while (parent && parent.type !== "SvelteElement") {
parent = node.parent;
parent = parent.parent;
}
if (!parent || parent.kind !== "component") {
return null;
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/parser/ast/let-directive04-input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Copied from https://github.com/sveltejs/svelte-eslint-parser/issues/408-->
<script lang="ts">
export let collapsed = false;
</script>

<div>
{#if !collapsed}
<svelte:self collapsed let:something>
<slot {something} />
</svelte:self>
{/if}
</div>
Loading