Skip to content

Commit

Permalink
fix: infinite loop in attr.ts (#409)
Browse files Browse the repository at this point in the history
* fix: infinite loop

* Create weak-lizards-listen.md

* fix
  • Loading branch information
ota-meshi authored Oct 3, 2023
1 parent f92689e commit b63c305
Show file tree
Hide file tree
Showing 5 changed files with 2,684 additions and 2 deletions.
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

0 comments on commit b63c305

Please sign in to comment.