Skip to content
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/twenty-cats-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": minor
---

feat: add support for `$inspect` and `$effect.root`
2 changes: 1 addition & 1 deletion explorer-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"eslint-scope": "^7.2.2",
"esquery": "^1.5.0",
"pako": "^2.1.0",
"svelte": "^5.0.0-next.10",
"svelte": "^5.0.0-next.17",
"svelte-eslint-parser": "link:..",
"tslib": "^2.6.2"
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"version:ci": "env-cmd -e version-ci pnpm run build:meta && changeset version"
},
"peerDependencies": {
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.10"
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.17"
},
"peerDependenciesMeta": {
"svelte": {
Expand Down Expand Up @@ -104,7 +104,7 @@
"prettier-plugin-svelte": "^3.0.0",
"rimraf": "^5.0.1",
"semver": "^7.5.1",
"svelte": "^5.0.0-next.10",
"svelte": "^5.0.0-next.17",
"svelte2tsx": "^0.6.25",
"typescript": "~5.1.3",
"typescript-eslint-parser-for-extra-files": "^0.5.0"
Expand Down
1 change: 1 addition & 0 deletions src/parser/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const globalsForRunes = [
"$derived",
"$effect",
"$props",
"$inspect",
] as const;
const globalsForSvelte5 = [...globalsForSvelte4, ...globalsForRunes];
export const globals = svelteVersion.gte(5)
Expand Down
8 changes: 8 additions & 0 deletions src/parser/typescript/analyze/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ function analyzeDollarDollarVariables(
case "$derived":
case "$effect":
case "$props":
case "$inspect":
// Processed by `analyzeRuneVariables`.
break;
default: {
Expand Down Expand Up @@ -332,13 +333,20 @@ function analyzeRuneVariables(
appendDeclareNamespaceVirtualScripts(globalName, [
"export function pre(fn: () => void | (() => void)): void;",
"export function active(): boolean;",
"export function root(fn: () => void | (() => void)): () => void;",
]);
break;
}
case "$props": {
appendDeclareFunctionVirtualScripts(globalName, ["<T>(): T"]);
break;
}
case "$inspect": {
appendDeclareFunctionVirtualScripts(globalName, [
`<T>(value: T, callback?: (value: T, type: 'init' | 'update') => void): void`,
]);
break;
}
default: {
const _: never = globalName;
throw Error(`Unknown global: ${_}`);
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/parser/ast/$$slots-scope-output-svelte5.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
"resolved": null
}
]
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"resolved": null
}
]
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"resolved": null
}
]
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"resolved": null
}
]
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"resolved": null
}
]
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"resolved": null
}
]
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"resolved": null
}
]
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
"identifiers": [],
"defs": [],
"references": []
},
{
"name": "$inspect",
"identifiers": [],
"defs": [],
"references": []
}
],
"references": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
let count = $state(0);

const cleanup = $effect.root(() => {
$effect(() => {
console.log(count);
});

return () => {
console.log('effect root cleanup');
};
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"ruleId": "no-unused-vars",
"code": "cleanup",
"line": 4,
"column": 8
}
]
Loading