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/empty-turtles-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": patch
---

fix: resolve issues in Runes mode detection causing parser malfunctions
3 changes: 2 additions & 1 deletion src/parser/analyze-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export function analyzePropsScope(
}
}
} else if (node.type === "VariableDeclaration") {
if (svelteParseContext.runes) {
// Process if not confirmed as non-Runes mode.
if (svelteParseContext.runes !== false) {
// Process for Svelte v5 Runes props. e.g. `let { x = $bindable() } = $props()`;
for (const decl of node.declarations) {
if (
Expand Down
6 changes: 4 additions & 2 deletions src/parser/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ type Global =
export function getGlobalsForSvelte(
svelteParseContext: SvelteParseContext,
): readonly Global[] {
if (svelteParseContext.runes) {
// Process if not confirmed as non-Runes mode.
if (svelteParseContext.runes !== false) {
return [...globalsForSvelte, ...globalsForRunes];
}
return globalsForSvelte;
}
export function getGlobalsForSvelteScript(
svelteParseContext: SvelteParseContext,
): readonly Global[] {
if (svelteParseContext.runes) {
// Process if not confirmed as non-Runes mode.
if (svelteParseContext.runes !== false) {
return globalsForRunes;
}
return [];
Expand Down
8 changes: 6 additions & 2 deletions src/parser/typescript/analyze/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ function analyzeRuneVariables(
ctx: VirtualTypeScriptContext,
svelteParseContext: SvelteParseContext,
) {
if (!svelteParseContext.runes) return;
// No processing is needed if the user is determined not to be in Runes mode.
if (svelteParseContext.runes === false) {
return;
}
const scopeManager = result.scopeManager;
for (const globalName of globalsForRunes) {
if (
Expand Down Expand Up @@ -583,7 +586,8 @@ function* analyzeDollarDerivedScopes(
result: TSESParseForESLintResult,
svelteParseContext: SvelteParseContext,
): Iterable<TransformInfo> {
if (!svelteParseContext.runes) return;
// No processing is needed if the user is determined not to be in Runes mode.
if (svelteParseContext.runes === false) return;
const scopeManager = result.scopeManager;
const derivedReferences = scopeManager.globalScope!.through.filter(
(reference) => reference.identifier.name === "$derived",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
const { p } = $props();
</script>

<span>{p}</span>
Loading
Loading