Skip to content

Commit 80e562f

Browse files
committed
wip
1 parent d8add86 commit 80e562f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/parser/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import type { NormalizedParserOptions } from "./parser-options.js";
5050
import { isTypeScript, normalizeParserOptions } from "./parser-options.js";
5151
import { getFragmentFromRoot } from "./compat.js";
5252
import {
53+
hasRunesSymbol,
5354
resolveSvelteParseContextForSvelte,
5455
resolveSvelteParseContextForSvelteScript,
5556
type SvelteParseContext,
@@ -142,6 +143,7 @@ function parseAsSvelte(
142143
ctx,
143144
parserOptions,
144145
);
146+
145147
const svelteParseContext = resolveSvelteParseContextForSvelte(
146148
svelteConfig,
147149
parserOptions,
@@ -161,6 +163,7 @@ function parseAsSvelte(
161163
scripts.attrs,
162164
parserOptions,
163165
);
166+
164167
ctx.scriptLet.restore(resultScript);
165168
ctx.tokens.push(...resultScript.ast.tokens);
166169
ctx.comments.push(...resultScript.ast.comments);
@@ -254,7 +257,10 @@ function parseAsSvelte(
254257
styleNodeLoc,
255258
styleNodeRange,
256259
styleSelectorNodeLoc,
257-
svelteParseContext,
260+
svelteParseContext: {
261+
...svelteParseContext,
262+
runes: svelteParseContext.runes ?? hasRunesSymbol(resultScript.ast),
263+
},
258264
});
259265
resultScript.visitorKeys = Object.assign({}, KEYS, resultScript.visitorKeys);
260266

src/parser/svelte-parse-context.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { NormalizedParserOptions } from "./parser-options.js";
55
import { compilerVersion, svelteVersion } from "./svelte-version.js";
66
import type { SvelteConfig } from "../svelte-config/index.js";
77
import { traverseNodes } from "../traverse.js";
8+
import type { ESLintProgram } from "./index.js";
89

910
const 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

Comments
 (0)