Skip to content

Commit

Permalink
fix: resolve issues in Runes mode detection causing parser malfunctio…
Browse files Browse the repository at this point in the history
…ns (#638)
  • Loading branch information
baseballyama authored Jan 13, 2025
1 parent e1a4d15 commit df461c3
Show file tree
Hide file tree
Showing 8 changed files with 1,371 additions and 5 deletions.
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

0 comments on commit df461c3

Please sign in to comment.