-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: apply correct type information to
$derived
argument expression (
#430)
- Loading branch information
Showing
26 changed files
with
522 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"svelte-eslint-parser": minor | ||
--- | ||
|
||
feat: apply correct type information to `$derived` argument expression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { ESLintExtendedProgram } from ".."; | ||
import { traverseNodes } from "../.."; | ||
import type { TSESParseForESLintResult } from "./types"; | ||
|
||
export function setParent( | ||
result: ESLintExtendedProgram | TSESParseForESLintResult, | ||
): void { | ||
if (result.ast.body.some((node) => (node as any).parent)) { | ||
return; | ||
} | ||
traverseNodes(result.ast, { | ||
visitorKeys: result.visitorKeys, | ||
enterNode(node, parent) { | ||
(node as any).parent = parent; | ||
}, | ||
leaveNode() { | ||
// noop | ||
}, | ||
}); | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/fixtures/integrations/type-info-tests/$derived-input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script lang="ts"> | ||
type Info = { foo: number }; | ||
let x: Info | null = { foo: 42 }; | ||
const get = () => "hello"; | ||
x = null; | ||
const y = $derived(x); | ||
const z = $derived(fn(y.foo)); | ||
const foo = $derived(get); | ||
function fn(a: number): number { | ||
return a; | ||
} | ||
</script> | ||
|
||
<input title={z} bind:value={x}> | ||
{foo()} |
1 change: 1 addition & 0 deletions
1
tests/fixtures/integrations/type-info-tests/$derived-output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
5 changes: 5 additions & 0 deletions
5
tests/fixtures/integrations/type-info-tests/$derived-requirements.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"parse": { | ||
"svelte": ">=5.0.0-0" | ||
} | ||
} |
Oops, something went wrong.