From 06e27557a126f04067e04e7c5683f1522c722e31 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Mon, 17 Jun 2024 22:29:34 +0900 Subject: [PATCH 1/4] wip --- README.md | 24 ++++++++++++------------ src/parser/parser-options.ts | 9 +++++---- src/parser/svelte-parse-context.ts | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index d27cabc2..628930aa 100644 --- a/README.md +++ b/README.md @@ -286,10 +286,11 @@ export default [ svelteFeatures: { /* -- Experimental Svelte Features -- */ /* It may be changed or removed in minor versions without notice. */ - // If true, it will analyze Runes. - // By default, it will try to read `compilerOptions.runes` from `svelte.config.js`. - // However, note that if `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `false`. - runes: false, + // This option is for Svelte 5. The default value is `true`. + // If `false`, ESLint will not recognize rune symbols. + // If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`. + // If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`. + runes: true, /* -- Experimental Svelte Features -- */ /* It may be changed or removed in minor versions without notice. */ // Whether to parse the `generics` attribute. @@ -311,10 +312,11 @@ For example in `.eslintrc.*`: "svelteFeatures": { /* -- Experimental Svelte Features -- */ /* It may be changed or removed in minor versions without notice. */ - // If true, it will analyze Runes. - // By default, it will try to read `compilerOptions.runes` from `svelte.config.js`. - // However, note that if the file cannot be parsed by static analysis, it will behave as false. - "runes": false, + // This option is for Svelte 5. The default value is `true`. + // If `false`, ESLint will not recognize rune symbols. + // If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`. + // If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`. + "runes": true, /* -- Experimental Svelte Features -- */ /* It may be changed or removed in minor versions without notice. */ // Whether to parse the `generics` attribute. @@ -329,7 +331,8 @@ For example in `.eslintrc.*`: **_This is an experimental feature. It may be changed or removed in minor versions without notice._** -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. +If you install Svelte v5 the parser will be able to parse runes, and will also be able to parse `*.js` and `*.ts` files. +If you don't want to use Runes, you may need to configure. Please read [parserOptions.svelteFeatures](#parseroptionssveltefeatures) for more details. When using this mode in an ESLint configuration, it is recommended to set it per file pattern as below. @@ -383,7 +386,6 @@ For example in `.eslintrc.*`: "parser": "svelte-eslint-parser", "parserOptions": { "parser": "...", - "svelteFeatures": { "runes": true }, /* ... */ }, }, @@ -391,7 +393,6 @@ For example in `.eslintrc.*`: "files": ["*.svelte.js"], "parser": "svelte-eslint-parser", "parserOptions": { - "svelteFeatures": { "runes": true }, /* ... */ }, }, @@ -400,7 +401,6 @@ For example in `.eslintrc.*`: "parser": "svelte-eslint-parser", "parserOptions": { "parser": "...(ts parser)...", - "svelteFeatures": { "runes": true }, /* ... */ }, }, diff --git a/src/parser/parser-options.ts b/src/parser/parser-options.ts index 3bfc818d..b8f15d1a 100644 --- a/src/parser/parser-options.ts +++ b/src/parser/parser-options.ts @@ -20,11 +20,12 @@ export type NormalizedParserOptions = { [key: string]: any; }; svelteFeatures?: { - // If true, it will analyze Runes. - // By default, it will try to read `compilerOptions.runes` from `svelte.config.js`. - // However, note that if it cannot be resolved due to static analysis, it will behave as false. - runes?: boolean; /* -- Experimental Svelte Features -- */ + // This option is for Svelte 5. The default value is `true`. + // If `false`, ESLint will not recognize rune symbols. + // If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`. + // If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`. + runes?: boolean; // Whether to parse the `generics` attribute. // See https://github.com/sveltejs/rfcs/pull/38 experimentalGenerics?: boolean; diff --git a/src/parser/svelte-parse-context.ts b/src/parser/svelte-parse-context.ts index 33ec8ee0..eb954012 100644 --- a/src/parser/svelte-parse-context.ts +++ b/src/parser/svelte-parse-context.ts @@ -28,7 +28,7 @@ export function isEnableRunes( } else if (svelteConfig?.compilerOptions?.runes != null) { return Boolean(svelteConfig.compilerOptions.runes); } - return false; + return true; } export function resolveSvelteParseContextForSvelte( From bee9fd29ade61ce9ead1a52674927dc0475e7d20 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Mon, 17 Jun 2024 22:38:25 +0900 Subject: [PATCH 2/4] add changeset --- .changeset/brave-penguins-compete.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/brave-penguins-compete.md diff --git a/.changeset/brave-penguins-compete.md b/.changeset/brave-penguins-compete.md new file mode 100644 index 00000000..eae091b1 --- /dev/null +++ b/.changeset/brave-penguins-compete.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": patch +--- + +fix: Set `svelteFeatures.runes` to `true` by default for Svelte 5 From 94cfc8259429ce81746e54f02e0ef86896dde831 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Mon, 17 Jun 2024 22:49:13 +0900 Subject: [PATCH 3/4] tidy --- src/parser/svelte-parse-context.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/parser/svelte-parse-context.ts b/src/parser/svelte-parse-context.ts index eb954012..71c8c353 100644 --- a/src/parser/svelte-parse-context.ts +++ b/src/parser/svelte-parse-context.ts @@ -25,7 +25,8 @@ export function isEnableRunes( if (!svelteVersion.gte(5)) return false; if (parserOptions.svelteFeatures?.runes != null) { return Boolean(parserOptions.svelteFeatures.runes); - } else if (svelteConfig?.compilerOptions?.runes != null) { + } + if (svelteConfig?.compilerOptions?.runes != null) { return Boolean(svelteConfig.compilerOptions.runes); } return true; From 9dea20b3f5566b465df15726c51955dfa3a7f953 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Mon, 17 Jun 2024 23:01:16 +0900 Subject: [PATCH 4/4] fix test --- .../parser/ast/svelte5/$props-without-runes02-config.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/fixtures/parser/ast/svelte5/$props-without-runes02-config.json b/tests/fixtures/parser/ast/svelte5/$props-without-runes02-config.json index 2a0441e5..f5145143 100644 --- a/tests/fixtures/parser/ast/svelte5/$props-without-runes02-config.json +++ b/tests/fixtures/parser/ast/svelte5/$props-without-runes02-config.json @@ -1,5 +1,7 @@ { - "svelteConfig": { - "runes": false - } + "svelteConfig": { + "compilerOptions": { + "runes": false + } + } }