11import type * as Compiler from "./svelte-ast-types-for-v5.js" ;
22import type * as SvAST from "./svelte-ast-types.js" ;
3- import type * as ESTree from "estree" ;
43import type { NormalizedParserOptions } from "./parser-options.js" ;
54import { compilerVersion , svelteVersion } from "./svelte-version.js" ;
65import type { SvelteConfig } from "../svelte-config/index.js" ;
76import { traverseNodes } from "../traverse.js" ;
7+ import type { ESLintProgram } from "./index.js" ;
88
99const runeSymbols : string [ ] = [
1010 "$state" ,
@@ -19,11 +19,16 @@ const runeSymbols: string[] = [
1919/** The context for parsing. */
2020export type SvelteParseContext = {
2121 /**
22- * Whether to use Runes mode.
23- * May be `true` if the user is using Svelte v5.
24- * Resolved from `svelte.config.js` or `parserOptions`, but may be overridden by `<svelte:options>`.
22+ * Determines if the file is in Runes mode.
23+ *
24+ * - Svelte 3/4 does not support Runes mode.
25+ * - Checks if `runes` configuration exists in:
26+ * - `parserOptions`
27+ * - `svelte.config.js`
28+ * - `<svelte:options>` in the Svelte file.
29+ * - Returns `true` if the `runes` symbol is present in the Svelte file.
2530 */
26- runes : boolean ;
31+ runes ? : boolean ;
2732 /** The version of "svelte/compiler". */
2833 compilerVersion : string ;
2934 /** The result of static analysis of `svelte.config.js`. */
@@ -36,7 +41,7 @@ export function resolveSvelteParseContextForSvelte(
3641 svelteAst : Compiler . Root | SvAST . AstLegacy ,
3742) : SvelteParseContext {
3843 return {
39- runes : isRunes ( svelteConfig , parserOptions , svelteAst ) ,
44+ runes : isRunesAsParseContext ( svelteConfig , parserOptions , svelteAst ) ,
4045 compilerVersion,
4146 svelteConfig,
4247 } ;
@@ -53,11 +58,11 @@ export function resolveSvelteParseContextForSvelteScript(
5358 } ;
5459}
5560
56- function isRunes (
61+ function isRunesAsParseContext (
5762 svelteConfig : SvelteConfig | null ,
5863 parserOptions : NormalizedParserOptions ,
5964 svelteAst : Compiler . Root | SvAST . AstLegacy ,
60- ) : boolean {
65+ ) : boolean | undefined {
6166 // Svelte 3/4 does not support Runes mode.
6267 if ( ! svelteVersion . gte ( 5 ) ) {
6368 return false ;
@@ -77,17 +82,12 @@ function isRunes(
7782 return svelteOptions ?. runes ;
7883 }
7984
80- // Static analysis.
81- const { module, instance } = svelteAst ;
82- return (
83- ( module != null && hasRuneSymbol ( module ) ) ||
84- ( instance != null && hasRuneSymbol ( instance ) )
85- ) ;
85+ return undefined ;
8686}
8787
88- function hasRuneSymbol ( ast : Compiler . Script | SvAST . Script ) : boolean {
88+ export function hasRunesSymbol ( ast : ESLintProgram ) : boolean {
8989 let hasRuneSymbol = false ;
90- traverseNodes ( ast as unknown as ESTree . Node , {
90+ traverseNodes ( ast , {
9191 enterNode ( node ) {
9292 if ( hasRuneSymbol ) {
9393 return ;
0 commit comments