@@ -5,6 +5,7 @@ import type { NormalizedParserOptions } from "./parser-options.js";
55import { compilerVersion , svelteVersion } from "./svelte-version.js" ;
66import type { SvelteConfig } from "../svelte-config/index.js" ;
77import { traverseNodes } from "../traverse.js" ;
8+ import type { ESLintProgram } from "./index.js" ;
89
910const runeSymbols : string [ ] = [
1011 "$state" ,
@@ -23,7 +24,7 @@ export type SvelteParseContext = {
2324 * May be `true` if the user is using Svelte v5.
2425 * Resolved from `svelte.config.js` or `parserOptions`, but may be overridden by `<svelte:options>`.
2526 */
26- runes : boolean ;
27+ runes ? : boolean ;
2728 /** The version of "svelte/compiler". */
2829 compilerVersion : string ;
2930 /** The result of static analysis of `svelte.config.js`. */
@@ -36,7 +37,7 @@ export function resolveSvelteParseContextForSvelte(
3637 svelteAst : Compiler . Root | SvAST . AstLegacy ,
3738) : SvelteParseContext {
3839 return {
39- runes : isRunes ( svelteConfig , parserOptions , svelteAst ) ,
40+ runes : isRunesAsParseContext ( svelteConfig , parserOptions , svelteAst ) ,
4041 compilerVersion,
4142 svelteConfig,
4243 } ;
@@ -53,11 +54,11 @@ export function resolveSvelteParseContextForSvelteScript(
5354 } ;
5455}
5556
56- function isRunes (
57+ function isRunesAsParseContext (
5758 svelteConfig : SvelteConfig | null ,
5859 parserOptions : NormalizedParserOptions ,
5960 svelteAst : Compiler . Root | SvAST . AstLegacy ,
60- ) : boolean {
61+ ) : boolean | undefined {
6162 // Svelte 3/4 does not support Runes mode.
6263 if ( ! svelteVersion . gte ( 5 ) ) {
6364 return false ;
@@ -77,17 +78,12 @@ function isRunes(
7778 return svelteOptions ?. runes ;
7879 }
7980
80- // Static analysis.
81- const { module, instance } = svelteAst ;
82- return (
83- ( module != null && hasRuneSymbol ( module ) ) ||
84- ( instance != null && hasRuneSymbol ( instance ) )
85- ) ;
81+ return undefined ;
8682}
8783
88- function hasRuneSymbol ( ast : Compiler . Script | SvAST . Script ) : boolean {
84+ export function hasRunesSymbol ( ast : ESLintProgram ) : boolean {
8985 let hasRuneSymbol = false ;
90- traverseNodes ( ast as unknown as ESTree . Node , {
86+ traverseNodes ( ast , {
9187 enterNode ( node ) {
9288 if ( hasRuneSymbol ) {
9389 return ;
0 commit comments