1
1
import type * as Compiler from "./svelte-ast-types-for-v5.js" ;
2
2
import type * as SvAST from "./svelte-ast-types.js" ;
3
- import type * as ESTree from "estree" ;
4
3
import type { NormalizedParserOptions } from "./parser-options.js" ;
5
4
import { compilerVersion , svelteVersion } from "./svelte-version.js" ;
6
5
import type { SvelteConfig } from "../svelte-config/index.js" ;
7
6
import { traverseNodes } from "../traverse.js" ;
7
+ import type { ESLintProgram } from "./index.js" ;
8
8
9
9
const runeSymbols : string [ ] = [
10
10
"$state" ,
@@ -19,11 +19,16 @@ const runeSymbols: string[] = [
19
19
/** The context for parsing. */
20
20
export type SvelteParseContext = {
21
21
/**
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.
25
30
*/
26
- runes : boolean ;
31
+ runes ? : boolean ;
27
32
/** The version of "svelte/compiler". */
28
33
compilerVersion : string ;
29
34
/** The result of static analysis of `svelte.config.js`. */
@@ -36,7 +41,7 @@ export function resolveSvelteParseContextForSvelte(
36
41
svelteAst : Compiler . Root | SvAST . AstLegacy ,
37
42
) : SvelteParseContext {
38
43
return {
39
- runes : isRunes ( svelteConfig , parserOptions , svelteAst ) ,
44
+ runes : isRunesAsParseContext ( svelteConfig , parserOptions , svelteAst ) ,
40
45
compilerVersion,
41
46
svelteConfig,
42
47
} ;
@@ -53,11 +58,11 @@ export function resolveSvelteParseContextForSvelteScript(
53
58
} ;
54
59
}
55
60
56
- function isRunes (
61
+ function isRunesAsParseContext (
57
62
svelteConfig : SvelteConfig | null ,
58
63
parserOptions : NormalizedParserOptions ,
59
64
svelteAst : Compiler . Root | SvAST . AstLegacy ,
60
- ) : boolean {
65
+ ) : boolean | undefined {
61
66
// Svelte 3/4 does not support Runes mode.
62
67
if ( ! svelteVersion . gte ( 5 ) ) {
63
68
return false ;
@@ -77,17 +82,12 @@ function isRunes(
77
82
return svelteOptions ?. runes ;
78
83
}
79
84
80
- // Static analysis.
81
- const { module, instance } = svelteAst ;
82
- return (
83
- ( module != null && hasRuneSymbol ( module ) ) ||
84
- ( instance != null && hasRuneSymbol ( instance ) )
85
- ) ;
85
+ return undefined ;
86
86
}
87
87
88
- function hasRuneSymbol ( ast : Compiler . Script | SvAST . Script ) : boolean {
88
+ export function hasRunesSymbol ( ast : ESLintProgram ) : boolean {
89
89
let hasRuneSymbol = false ;
90
- traverseNodes ( ast as unknown as ESTree . Node , {
90
+ traverseNodes ( ast , {
91
91
enterNode ( node ) {
92
92
if ( hasRuneSymbol ) {
93
93
return ;
0 commit comments