Skip to content

Commit 437e463

Browse files
authored
fix: set svelteFeatures.runes to true by default for Svelte 5 (#538)
1 parent 8d75802 commit 437e463

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

.changeset/brave-penguins-compete.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": patch
3+
---
4+
5+
fix: Set `svelteFeatures.runes` to `true` by default for Svelte 5

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,11 @@ export default [
286286
svelteFeatures: {
287287
/* -- Experimental Svelte Features -- */
288288
/* It may be changed or removed in minor versions without notice. */
289-
// If true, it will analyze Runes.
290-
// By default, it will try to read `compilerOptions.runes` from `svelte.config.js`.
291-
// However, note that if `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `false`.
292-
runes: false,
289+
// This option is for Svelte 5. The default value is `true`.
290+
// If `false`, ESLint will not recognize rune symbols.
291+
// If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`.
292+
// If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`.
293+
runes: true,
293294
/* -- Experimental Svelte Features -- */
294295
/* It may be changed or removed in minor versions without notice. */
295296
// Whether to parse the `generics` attribute.
@@ -311,10 +312,11 @@ For example in `.eslintrc.*`:
311312
"svelteFeatures": {
312313
/* -- Experimental Svelte Features -- */
313314
/* It may be changed or removed in minor versions without notice. */
314-
// If true, it will analyze Runes.
315-
// By default, it will try to read `compilerOptions.runes` from `svelte.config.js`.
316-
// However, note that if the file cannot be parsed by static analysis, it will behave as false.
317-
"runes": false,
315+
// This option is for Svelte 5. The default value is `true`.
316+
// If `false`, ESLint will not recognize rune symbols.
317+
// If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`.
318+
// If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`.
319+
"runes": true,
318320
/* -- Experimental Svelte Features -- */
319321
/* It may be changed or removed in minor versions without notice. */
320322
// Whether to parse the `generics` attribute.
@@ -329,7 +331,8 @@ For example in `.eslintrc.*`:
329331

330332
**_This is an experimental feature. It may be changed or removed in minor versions without notice._**
331333

332-
If you install Svelte v5 and turn on runes (`compilerOptions.runes` in `svelte.config.js` or `parserOptions.svelteFeatures.runes` in ESLint config is `true`), the parser will be able to parse runes, and will also be able to parse `*.js` and `*.ts` files.
334+
If you install Svelte v5 the parser will be able to parse runes, and will also be able to parse `*.js` and `*.ts` files.
335+
If you don't want to use Runes, you may need to configure. Please read [parserOptions.svelteFeatures](#parseroptionssveltefeatures) for more details.
333336

334337
When using this mode in an ESLint configuration, it is recommended to set it per file pattern as below.
335338

@@ -383,15 +386,13 @@ For example in `.eslintrc.*`:
383386
"parser": "svelte-eslint-parser",
384387
"parserOptions": {
385388
"parser": "...",
386-
"svelteFeatures": { "runes": true },
387389
/* ... */
388390
},
389391
},
390392
{
391393
"files": ["*.svelte.js"],
392394
"parser": "svelte-eslint-parser",
393395
"parserOptions": {
394-
"svelteFeatures": { "runes": true },
395396
/* ... */
396397
},
397398
},
@@ -400,7 +401,6 @@ For example in `.eslintrc.*`:
400401
"parser": "svelte-eslint-parser",
401402
"parserOptions": {
402403
"parser": "...(ts parser)...",
403-
"svelteFeatures": { "runes": true },
404404
/* ... */
405405
},
406406
},

src/parser/parser-options.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ export type NormalizedParserOptions = {
2020
[key: string]: any;
2121
};
2222
svelteFeatures?: {
23-
// If true, it will analyze Runes.
24-
// By default, it will try to read `compilerOptions.runes` from `svelte.config.js`.
25-
// However, note that if it cannot be resolved due to static analysis, it will behave as false.
26-
runes?: boolean;
2723
/* -- Experimental Svelte Features -- */
24+
// This option is for Svelte 5. The default value is `true`.
25+
// If `false`, ESLint will not recognize rune symbols.
26+
// If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`.
27+
// If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`.
28+
runes?: boolean;
2829
// Whether to parse the `generics` attribute.
2930
// See https://github.com/sveltejs/rfcs/pull/38
3031
experimentalGenerics?: boolean;

src/parser/svelte-parse-context.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ export function isEnableRunes(
2525
if (!svelteVersion.gte(5)) return false;
2626
if (parserOptions.svelteFeatures?.runes != null) {
2727
return Boolean(parserOptions.svelteFeatures.runes);
28-
} else if (svelteConfig?.compilerOptions?.runes != null) {
28+
}
29+
if (svelteConfig?.compilerOptions?.runes != null) {
2930
return Boolean(svelteConfig.compilerOptions.runes);
3031
}
31-
return false;
32+
return true;
3233
}
3334

3435
export function resolveSvelteParseContextForSvelte(
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"svelteConfig": {
3-
"runes": false
4-
}
2+
"svelteConfig": {
3+
"compilerOptions": {
4+
"runes": false
5+
}
6+
}
57
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy