Skip to content

Commit df461c3

Browse files
authoredJan 13, 2025··
fix: resolve issues in Runes mode detection causing parser malfunctions (#638)
1 parent e1a4d15 commit df461c3

File tree

8 files changed

+1371
-5
lines changed

8 files changed

+1371
-5
lines changed
 

‎.changeset/empty-turtles-report.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": patch
3+
---
4+
5+
fix: resolve issues in Runes mode detection causing parser malfunctions

‎src/parser/analyze-scope.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ export function analyzePropsScope(
191191
}
192192
}
193193
} else if (node.type === "VariableDeclaration") {
194-
if (svelteParseContext.runes) {
194+
// Process if not confirmed as non-Runes mode.
195+
if (svelteParseContext.runes !== false) {
195196
// Process for Svelte v5 Runes props. e.g. `let { x = $bindable() } = $props()`;
196197
for (const decl of node.declarations) {
197198
if (

‎src/parser/globals.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ type Global =
1616
export function getGlobalsForSvelte(
1717
svelteParseContext: SvelteParseContext,
1818
): readonly Global[] {
19-
if (svelteParseContext.runes) {
19+
// Process if not confirmed as non-Runes mode.
20+
if (svelteParseContext.runes !== false) {
2021
return [...globalsForSvelte, ...globalsForRunes];
2122
}
2223
return globalsForSvelte;
2324
}
2425
export function getGlobalsForSvelteScript(
2526
svelteParseContext: SvelteParseContext,
2627
): readonly Global[] {
27-
if (svelteParseContext.runes) {
28+
// Process if not confirmed as non-Runes mode.
29+
if (svelteParseContext.runes !== false) {
2830
return globalsForRunes;
2931
}
3032
return [];

‎src/parser/typescript/analyze/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,10 @@ function analyzeRuneVariables(
377377
ctx: VirtualTypeScriptContext,
378378
svelteParseContext: SvelteParseContext,
379379
) {
380-
if (!svelteParseContext.runes) return;
380+
// No processing is needed if the user is determined not to be in Runes mode.
381+
if (svelteParseContext.runes === false) {
382+
return;
383+
}
381384
const scopeManager = result.scopeManager;
382385
for (const globalName of globalsForRunes) {
383386
if (
@@ -583,7 +586,8 @@ function* analyzeDollarDerivedScopes(
583586
result: TSESParseForESLintResult,
584587
svelteParseContext: SvelteParseContext,
585588
): Iterable<TransformInfo> {
586-
if (!svelteParseContext.runes) return;
589+
// No processing is needed if the user is determined not to be in Runes mode.
590+
if (svelteParseContext.runes === false) return;
587591
const scopeManager = result.scopeManager;
588592
const derivedReferences = scopeManager.globalScope!.through.filter(
589593
(reference) => reference.identifier.name === "$derived",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
const { p } = $props();
3+
</script>
4+
5+
<span>{p}</span>

‎tests/fixtures/parser/ast/svelte5/unknown-runes-mode/$props-output.json

+860
Large diffs are not rendered by default.

‎tests/fixtures/parser/ast/svelte5/unknown-runes-mode/$props-scope-output.json

+487
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** Config for testing */
2+
export default {};

0 commit comments

Comments
 (0)
Please sign in to comment.