Skip to content

Commit df461c3

Browse files
authored
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 6 additions & 2 deletions
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",
Lines changed: 5 additions & 0 deletions
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>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy