Skip to content

Commit 37f0061

Browse files
authored
feat: update svelte to 5.0.0-next.115 && minor refactor (#513)
1 parent 7c0861b commit 37f0061

File tree

92 files changed

+1017
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1017
-70
lines changed

.changeset/new-ways-mix.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": minor
3+
---
4+
5+
feat: add support for $host and $state.snapshot

.changeset/violet-adults-knock.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": minor
3+
---
4+
5+
feat: update svelte to 5.0.0-next.115 && minor refactor

package.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"version:ci": "env-cmd -e version-ci pnpm run build:meta && changeset version"
4848
},
4949
"peerDependencies": {
50-
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.112"
50+
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.115"
5151
},
5252
"peerDependenciesMeta": {
5353
"svelte": {
@@ -68,16 +68,16 @@
6868
"@ota-meshi/eslint-plugin": "^0.15.3",
6969
"@types/benchmark": "^2.1.5",
7070
"@types/chai": "^4.3.14",
71-
"@types/eslint": "^8.56.7",
71+
"@types/eslint": "^8.56.10",
7272
"@types/eslint-scope": "^3.7.7",
7373
"@types/eslint-visitor-keys": "^3.3.0",
7474
"@types/estree": "^1.0.5",
7575
"@types/mocha": "^10.0.6",
76-
"@types/node": "^20.12.5",
76+
"@types/node": "^20.12.7",
7777
"@types/semver": "^7.5.8",
78-
"@typescript-eslint/eslint-plugin": "^7.5.0",
79-
"@typescript-eslint/parser": "~7.7.0",
80-
"@typescript-eslint/types": "~7.7.0",
78+
"@typescript-eslint/eslint-plugin": "^7.7.1",
79+
"@typescript-eslint/parser": "~7.7.1",
80+
"@typescript-eslint/types": "~7.7.1",
8181
"benchmark": "^2.1.4",
8282
"chai": "^4.4.1",
8383
"env-cmd": "^10.1.0",
@@ -87,27 +87,27 @@
8787
"eslint-config-prettier": "^9.1.0",
8888
"eslint-plugin-eslint-comments": "^3.2.0",
8989
"eslint-plugin-json-schema-validator": "^5.1.0",
90-
"eslint-plugin-jsonc": "^2.15.0",
91-
"eslint-plugin-n": "^17.0.0",
90+
"eslint-plugin-jsonc": "^2.15.1",
91+
"eslint-plugin-n": "^17.3.1",
9292
"eslint-plugin-node-dependencies": "^0.12.0",
9393
"eslint-plugin-prettier": "^5.1.3",
94-
"eslint-plugin-regexp": "^2.4.0",
95-
"eslint-plugin-svelte": "^2.35.1",
94+
"eslint-plugin-regexp": "^2.5.0",
95+
"eslint-plugin-svelte": "^2.38.0",
9696
"eslint-plugin-yml": "^1.14.0",
9797
"estree-walker": "^3.0.3",
9898
"locate-character": "^3.0.0",
99-
"magic-string": "^0.30.9",
99+
"magic-string": "^0.30.10",
100100
"mocha": "^10.4.0",
101101
"mocha-chai-jest-snapshot": "^1.1.4",
102102
"nyc": "^15.1.0",
103103
"prettier": "~3.2.5",
104104
"prettier-plugin-pkg": "^0.18.1",
105-
"prettier-plugin-svelte": "^3.2.2",
105+
"prettier-plugin-svelte": "^3.2.3",
106106
"rimraf": "^5.0.5",
107107
"semver": "^7.6.0",
108-
"svelte": "^5.0.0-next.112",
109-
"svelte2tsx": "^0.7.6",
110-
"typescript": "~5.4.4",
108+
"svelte": "^5.0.0-next.115",
109+
"svelte2tsx": "^0.7.7",
110+
"typescript": "~5.4.5",
111111
"typescript-eslint-parser-for-extra-files": "^0.6.0"
112112
},
113113
"publishConfig": {

src/parser/compat.ts

+13-45
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import type ESTree from "estree";
33
import type * as SvAST from "./svelte-ast-types";
44
import type * as Compiler from "svelte/compiler";
5-
import { parseAttributes } from "./html";
65

76
export type Child =
87
| Compiler.Text
@@ -31,16 +30,22 @@ export function getModuleFromRoot(
3130
}
3231
export function getOptionsFromRoot(
3332
svelteAst: Compiler.Root | SvAST.AstLegacy,
34-
code: string,
3533
): Compiler.SvelteOptionsRaw | null {
3634
const root = svelteAst as Compiler.Root;
3735
if (root.options) {
38-
if ((root.options as any).__raw__) {
39-
return (root.options as any).__raw__;
40-
}
41-
// If there is no `__raw__` property in the `SvelteOptions` node,
42-
// we will parse `<svelte:options>` ourselves.
43-
return parseSvelteOptions(root.options, code);
36+
return {
37+
type: "SvelteOptions",
38+
name: "svelte:options",
39+
attributes: root.options.attributes,
40+
fragment: {
41+
type: "Fragment",
42+
nodes: [],
43+
transparent: true,
44+
},
45+
start: root.options.start,
46+
end: root.options.end,
47+
parent: null as any,
48+
};
4449
}
4550
return null;
4651
}
@@ -239,40 +244,3 @@ export function getDeclaratorFromConstTag(
239244
(node as SvAST.ConstTag).expression
240245
);
241246
}
242-
243-
function parseSvelteOptions(
244-
options: Compiler.SvelteOptions,
245-
code: string,
246-
): Compiler.SvelteOptionsRaw {
247-
const { start, end } = options;
248-
const nameEndName = start + "<svelte:options".length;
249-
const { attributes, index: tagEndIndex } = parseAttributes(
250-
code,
251-
nameEndName + 1,
252-
);
253-
const fragment: Compiler.Fragment = {
254-
type: "Fragment",
255-
nodes: [],
256-
transparent: true,
257-
};
258-
if (code.startsWith(">", tagEndIndex)) {
259-
const childEndIndex = code.indexOf("</svelte:options", tagEndIndex);
260-
fragment.nodes.push({
261-
type: "Text",
262-
data: code.slice(tagEndIndex + 1, childEndIndex),
263-
start: tagEndIndex + 1,
264-
end: childEndIndex,
265-
raw: code.slice(tagEndIndex + 1, childEndIndex),
266-
parent: fragment,
267-
});
268-
}
269-
return {
270-
type: "SvelteOptions",
271-
name: "svelte:options",
272-
attributes,
273-
fragment,
274-
start,
275-
end,
276-
parent: null as any,
277-
};
278-
}

src/parser/converts/root.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function convertSvelteRoot(
4949
const fragment = getFragmentFromRoot(svelteAst);
5050
if (fragment) {
5151
let children = getChildren(fragment);
52-
const options = getOptionsFromRoot(svelteAst, ctx.code);
52+
const options = getOptionsFromRoot(svelteAst);
5353
if (options) {
5454
children = [...children];
5555
if (

src/parser/globals.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const globalsForRunes = [
88
"$props",
99
"$bindable",
1010
"$inspect",
11+
"$host",
1112
] as const;
1213
const globalsForSvelte5 = [...globalsForSvelte4, ...globalsForRunes];
1314
export const globals = svelteVersion.gte(5)

src/parser/template.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ export function parseTemplate(
2121
svelteAst: Compiler.Root | SvAST.AstLegacy;
2222
} {
2323
try {
24-
const svelteAst = parse(code, {
24+
const options: {
25+
filename?: string | undefined;
26+
modern: true;
27+
} = {
2528
filename: parserOptions.filePath,
26-
...(svelteVersion.gte(5) ? { modern: true } : {}),
27-
}) as never as Compiler.Root | SvAST.AstLegacy;
29+
...(svelteVersion.gte(5) ? { modern: true } : ({} as never)),
30+
};
31+
const svelteAst = parse(code, options) as never as
32+
| Compiler.Root
33+
| SvAST.AstLegacy;
2834
const ast = convertSvelteRoot(svelteAst, ctx);
2935

3036
return {

src/parser/typescript/analyze/index.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ function analyzeDollarDollarVariables(
262262
case "$props":
263263
case "$bindable":
264264
case "$inspect":
265+
case "$host":
265266
// Processed by `analyzeRuneVariables`.
266267
break;
267268
default: {
@@ -318,7 +319,7 @@ function analyzeRuneVariables(
318319
continue;
319320
}
320321
switch (globalName) {
321-
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2492
322+
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2585
322323
case "$state": {
323324
appendDeclareFunctionVirtualScripts(globalName, [
324325
"<T>(initial: T): T",
@@ -328,9 +329,12 @@ function analyzeRuneVariables(
328329
"export function frozen<T>(initial: T): Readonly<T>;",
329330
"export function frozen<T>(): Readonly<T> | undefined;",
330331
]);
332+
appendDeclareNamespaceVirtualScripts(globalName, [
333+
"export function snapshot<T>(state: T): T;",
334+
]);
331335
break;
332336
}
333-
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2535
337+
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2648
334338
case "$derived": {
335339
appendDeclareFunctionVirtualScripts(globalName, [
336340
"<T>(expression: T): T",
@@ -340,7 +344,7 @@ function analyzeRuneVariables(
340344
]);
341345
break;
342346
}
343-
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2574
347+
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2687
344348
case "$effect": {
345349
appendDeclareFunctionVirtualScripts(globalName, [
346350
"(fn: () => void | (() => void)): void",
@@ -352,23 +356,30 @@ function analyzeRuneVariables(
352356
]);
353357
break;
354358
}
355-
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2655
359+
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2768
356360
case "$props": {
357361
appendDeclareFunctionVirtualScripts(globalName, ["(): any"]);
358362
break;
359363
}
360-
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2666
364+
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2779
361365
case "$bindable": {
362366
appendDeclareFunctionVirtualScripts(globalName, ["<T>(t?: T): T"]);
363367
break;
364368
}
365-
// See https://github.com/sveltejs/svelte/blob/dfc55c18f010f620b966e13eb0ad1f9791b5798f/packages/svelte/types/index.d.ts#L2686
369+
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2799
366370
case "$inspect": {
367371
appendDeclareFunctionVirtualScripts(globalName, [
368372
`<T extends any[]>(...values: T): { with: (fn: (type: 'init' | 'update', ...values: T) => void) => void }`,
369373
]);
370374
break;
371375
}
376+
// See https://github.com/sveltejs/svelte/blob/bda32edb1a4f2d383d96071750d6bfa9421b2175/packages/svelte/types/index.d.ts#L2822
377+
case "$host": {
378+
appendDeclareFunctionVirtualScripts(globalName, [
379+
`<El extends HTMLElement = HTMLElement>(): El`,
380+
]);
381+
break;
382+
}
372383
default: {
373384
const _: never = globalName;
374385
throw Error(`Unknown global: ${_}`);

tests/fixtures/parser/ast/$$slots-scope-output-svelte5.json

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
"identifiers": [],
7878
"defs": [],
7979
"references": []
80+
},
81+
{
82+
"name": "$host",
83+
"identifiers": [],
84+
"defs": [],
85+
"references": []
8086
}
8187
]
8288
}

tests/fixtures/parser/ast/docs/template-syntax/02-attributes-and-props/10-scope-output-svelte5.json

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
"identifiers": [],
7878
"defs": [],
7979
"references": []
80+
},
81+
{
82+
"name": "$host",
83+
"identifiers": [],
84+
"defs": [],
85+
"references": []
8086
}
8187
]
8288
}

tests/fixtures/parser/ast/docs/template-syntax/02-attributes-and-props/11-scope-output-svelte5.json

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
"identifiers": [],
7878
"defs": [],
7979
"references": []
80+
},
81+
{
82+
"name": "$host",
83+
"identifiers": [],
84+
"defs": [],
85+
"references": []
8086
}
8187
]
8288
}

tests/fixtures/parser/ast/docs/template-syntax/13-slot/02-$$slots/01-scope-output-svelte5.json

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
"identifiers": [],
7878
"defs": [],
7979
"references": []
80+
},
81+
{
82+
"name": "$host",
83+
"identifiers": [],
84+
"defs": [],
85+
"references": []
8086
}
8187
]
8288
}

tests/fixtures/parser/ast/svelte5/docs/fine-grained-reactivity/example01-scope-output.json

+6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@
124124
"identifiers": [],
125125
"defs": [],
126126
"references": []
127+
},
128+
{
129+
"name": "$host",
130+
"identifiers": [],
131+
"defs": [],
132+
"references": []
127133
}
128134
],
129135
"references": [],

tests/fixtures/parser/ast/svelte5/docs/functions/01-untrack-scope-output.json

+6
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@
102102
"identifiers": [],
103103
"defs": [],
104104
"references": []
105+
},
106+
{
107+
"name": "$host",
108+
"identifiers": [],
109+
"defs": [],
110+
"references": []
105111
}
106112
],
107113
"references": [],

tests/fixtures/parser/ast/svelte5/docs/old-vs-new/01-counter-scope-output.json

+6
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@
126126
"identifiers": [],
127127
"defs": [],
128128
"references": []
129+
},
130+
{
131+
"name": "$host",
132+
"identifiers": [],
133+
"defs": [],
134+
"references": []
129135
}
130136
],
131137
"references": [],

tests/fixtures/parser/ast/svelte5/docs/old-vs-new/02-tracking-dependencies-scope-output.json

+6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@
125125
"identifiers": [],
126126
"defs": [],
127127
"references": []
128+
},
129+
{
130+
"name": "$host",
131+
"identifiers": [],
132+
"defs": [],
133+
"references": []
128134
}
129135
],
130136
"references": [],

tests/fixtures/parser/ast/svelte5/docs/old-vs-new/03-untracking-dependencies-scope-output.json

+6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@
125125
"identifiers": [],
126126
"defs": [],
127127
"references": []
128+
},
129+
{
130+
"name": "$host",
131+
"identifiers": [],
132+
"defs": [],
133+
"references": []
128134
}
129135
],
130136
"references": [],

0 commit comments

Comments
 (0)