@@ -5,6 +5,7 @@ import type { NormalizedParserOptions } from "./parser-options.js";
5
5
import { compilerVersion , svelteVersion } from "./svelte-version.js" ;
6
6
import type { SvelteConfig } from "../svelte-config/index.js" ;
7
7
import { traverseNodes } from "../traverse.js" ;
8
+ import type { ESLintProgram } from "./index.js" ;
8
9
9
10
const runeSymbols : string [ ] = [
10
11
"$state" ,
@@ -23,7 +24,7 @@ export type SvelteParseContext = {
23
24
* May be `true` if the user is using Svelte v5.
24
25
* Resolved from `svelte.config.js` or `parserOptions`, but may be overridden by `<svelte:options>`.
25
26
*/
26
- runes : boolean ;
27
+ runes ? : boolean ;
27
28
/** The version of "svelte/compiler". */
28
29
compilerVersion : string ;
29
30
/** The result of static analysis of `svelte.config.js`. */
@@ -36,7 +37,7 @@ export function resolveSvelteParseContextForSvelte(
36
37
svelteAst : Compiler . Root | SvAST . AstLegacy ,
37
38
) : SvelteParseContext {
38
39
return {
39
- runes : isRunes ( svelteConfig , parserOptions , svelteAst ) ,
40
+ runes : isRunesAsParseContext ( svelteConfig , parserOptions , svelteAst ) ,
40
41
compilerVersion,
41
42
svelteConfig,
42
43
} ;
@@ -53,11 +54,11 @@ export function resolveSvelteParseContextForSvelteScript(
53
54
} ;
54
55
}
55
56
56
- function isRunes (
57
+ function isRunesAsParseContext (
57
58
svelteConfig : SvelteConfig | null ,
58
59
parserOptions : NormalizedParserOptions ,
59
60
svelteAst : Compiler . Root | SvAST . AstLegacy ,
60
- ) : boolean {
61
+ ) : boolean | undefined {
61
62
// Svelte 3/4 does not support Runes mode.
62
63
if ( ! svelteVersion . gte ( 5 ) ) {
63
64
return false ;
@@ -77,17 +78,12 @@ function isRunes(
77
78
return svelteOptions ?. runes ;
78
79
}
79
80
80
- // Static analysis.
81
- const { module, instance } = svelteAst ;
82
- return (
83
- ( module != null && hasRuneSymbol ( module ) ) ||
84
- ( instance != null && hasRuneSymbol ( instance ) )
85
- ) ;
81
+ return undefined ;
86
82
}
87
83
88
- function hasRuneSymbol ( ast : Compiler . Script | SvAST . Script ) : boolean {
84
+ export function hasRunesSymbol ( ast : ESLintProgram ) : boolean {
89
85
let hasRuneSymbol = false ;
90
- traverseNodes ( ast as unknown as ESTree . Node , {
86
+ traverseNodes ( ast , {
91
87
enterNode ( node ) {
92
88
if ( hasRuneSymbol ) {
93
89
return ;
0 commit comments