From a3e88a66f571c8543ded4fcd3cd22e4c13acfd00 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 12 Apr 2025 02:45:18 +0000 Subject: [PATCH 1/3] chore(deps): update dependency prettier-plugin-pkg to ^0.19.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bc680ca8..6b2d3d4f 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "magic-string": "^0.30.17", "mocha": "^11.1.0", "prettier": "~3.5.3", - "prettier-plugin-pkg": "^0.18.1", + "prettier-plugin-pkg": "^0.19.0", "prettier-plugin-svelte": "^3.3.3", "rimraf": "^6.0.1", "semver": "^7.7.1", From 33c70db2d975657f994b4e67969a0bca600dcd6b Mon Sep 17 00:00:00 2001 From: JounQin Date: Sat, 12 Apr 2025 10:56:08 +0800 Subject: [PATCH 2/3] chore: config `prettier` correctly --- .prettierignore | 1 + .prettierrc | 3 ++ docs/AST.md | 2 +- docs/internal-mechanism.md | 84 +++++++++++++++++++------------------- package.json | 4 +- 5 files changed, 49 insertions(+), 45 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..44e54133 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +tests/fixtures diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..877131f6 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,3 @@ +{ + "plugins": ["prettier-plugin-pkg", "prettier-plugin-svelte"] +} diff --git a/docs/AST.md b/docs/AST.md index b8eec7b4..c0f90492 100644 --- a/docs/AST.md +++ b/docs/AST.md @@ -15,7 +15,7 @@ See [ESTree] for the AST node of the script generated by `espree`. [variabledeclarator]: https://github.com/estree/estree/blob/master/es5.md#variabledeclarator [pattern]: https://github.com/estree/estree/blob/master/es5.md#patterns -See details: [../src/ast/*](../src/ast/) +See details: [../src/ast/\*](../src/ast/) ## Common diff --git a/docs/internal-mechanism.md b/docs/internal-mechanism.md index 9cc25972..2fa59a0f 100644 --- a/docs/internal-mechanism.md +++ b/docs/internal-mechanism.md @@ -38,23 +38,26 @@ For example, if you enter `*.svelte` template to listen for input events: ```svelte - + + ``` Parse the following virtual script code as a script: ```ts - - function inputHandler () { - // process - } -;function $_render1(){ - -(inputHandler) as ((e:'input' extends keyof HTMLElementEventMap ? HTMLElementEventMap['input'] : CustomEvent) => void ); +function inputHandler() { + // process +} +function $_render1() { + inputHandler as ( + e: "input" extends keyof HTMLElementEventMap + ? HTMLElementEventMap["input"] + : CustomEvent, + ) => void; } ``` @@ -78,25 +81,24 @@ For example, when using `{#each}` and `{@const}`: ```svelte + {#each array as e} - {@const ee = e * 2} - {ee} + {@const ee = e * 2} + {ee} {/each} ``` Parse the following virtual script code as a script: ```ts - - const array = [1, 2, 3] -;function $_render1(){ - -Array.from(array).forEach((e) => { +const array = [1, 2, 3]; +function $_render1() { + Array.from(array).forEach((e) => { const ee = e * 2; - (ee); -}); + ee; + }); } ``` @@ -122,10 +124,10 @@ TypeScript's type inference is pretty good, so parsing Svelte as-is gives some w e.g. ```ts -export let foo: { bar: number } | null = null +export let foo: { bar: number } | null = null; $: console.log(foo && foo.bar); - // ^ never type +// ^ never type ``` (You can see it on [TypeScript Online Playground](https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBAG2PAZhCAuOBvOAjAQyiwDsBXAWz2CjgF84AfOchBOAXhbLYFgAoAQBIsAYwgkAzhCQA6BBADmACjQQ4AMg1w1swlACUAbgFwz5i5YsB6a3AB6LYADcacGAE8wwAUA)) @@ -139,13 +141,13 @@ For example: ```svelte {foo && foo.bar} @@ -154,26 +156,24 @@ $: ({ bar: n } = foo || { bar: 42 }); Parse the following virtual script code as a script: ```ts - -export let foo: { bar: number } | null = null +export let foo: { bar: number } | null = null; -$: function $_reactiveStatementScopeFunction1(){ - console.log(foo && foo.bar); +$: function $_reactiveStatementScopeFunction1() { + console.log(foo && foo.bar); } -$: let r =$_reactiveVariableScopeFunction2(); -function $_reactiveVariableScopeFunction2(){ - let $_tmpVar3; - return ($_tmpVar3 = foo && foo.bar); +$: let r = $_reactiveVariableScopeFunction2(); +function $_reactiveVariableScopeFunction2() { + let $_tmpVar3; + return ($_tmpVar3 = foo && foo.bar); } -$: let { bar: n } =$_reactiveVariableScopeFunction4(); -function $_reactiveVariableScopeFunction4(){ - let $_tmpVar5; - return ($_tmpVar5 = foo || { bar: 42 }); +$: let { bar: n } = $_reactiveVariableScopeFunction4(); +function $_reactiveVariableScopeFunction4() { + let $_tmpVar5; + return ($_tmpVar5 = foo || { bar: 42 }); } -;function $_render6(){ - -(foo && foo.bar); +function $_render6() { + foo && foo.bar; } ``` diff --git a/package.json b/package.json index 6b2d3d4f..f75d2663 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "svelte-eslint-parser", "version": "1.1.2", + "type": "module", "description": "Svelte parser for ESLint", "repository": "git+https://github.com/sveltejs/svelte-eslint-parser.git", "homepage": "https://github.com/sveltejs/svelte-eslint-parser#readme", @@ -14,7 +15,6 @@ "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, - "type": "module", "main": "lib/index.js", "files": [ "lib" @@ -40,10 +40,10 @@ "prerelease": "pnpm run clean && pnpm run build", "preversion": "pnpm run lint && pnpm run test", "release": "changeset publish", + "run-update-fixtures": "pnpm run ts ./tools/update-fixtures.ts", "test": "pnpm run mocha \"tests/src/**/*.ts\" --reporter dot --timeout 60000", "ts": "node --import tsx/esm", "update-fixtures": "git add package.json && pnpm i -D svelte@4 && git checkout package.json && pnpm run run-update-fixtures && pnpm i && pnpm run run-update-fixtures", - "run-update-fixtures": "pnpm run ts ./tools/update-fixtures.ts", "version:ci": "env-cmd -e version-ci pnpm run build:meta && changeset version" }, "peerDependencies": { From 0cf4475b2943c84fa40393313221b96f3f9b9564 Mon Sep 17 00:00:00 2001 From: JounQin Date: Sat, 12 Apr 2025 11:05:15 +0800 Subject: [PATCH 3/3] chore: ignore unexpected formatting --- docs/internal-mechanism.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/internal-mechanism.md b/docs/internal-mechanism.md index 2fa59a0f..80fead11 100644 --- a/docs/internal-mechanism.md +++ b/docs/internal-mechanism.md @@ -123,11 +123,12 @@ TypeScript's type inference is pretty good, so parsing Svelte as-is gives some w e.g. + ```ts export let foo: { bar: number } | null = null; $: console.log(foo && foo.bar); -// ^ never type + // ^ never type ``` (You can see it on [TypeScript Online Playground](https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBAG2PAZhCAuOBvOAjAQyiwDsBXAWz2CjgF84AfOchBOAXhbLYFgAoAQBIsAYwgkAzhCQA6BBADmACjQQ4AMg1w1swlACUAbgFwz5i5YsB6a3AB6LYADcacGAE8wwAUA))