Skip to content

Commit f722d7c

Browse files
authored
fix: for svelte v5.0.0-next.69 & support optional {@render} (#483)
1 parent 30482ac commit f722d7c

18 files changed

+1776
-257
lines changed

.changeset/four-ears-appear.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte-eslint-parser": patch
3+
---
4+
5+
fix: for svelte v5.0.0-next.68 & support optional `{@render}`

package.json

+25-25
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.65"
50+
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.69"
5151
},
5252
"peerDependenciesMeta": {
5353
"svelte": {
@@ -58,7 +58,7 @@
5858
"eslint-scope": "^7.2.2",
5959
"eslint-visitor-keys": "^3.4.3",
6060
"espree": "^9.6.1",
61-
"postcss": "^8.4.32",
61+
"postcss": "^8.4.35",
6262
"postcss-scss": "^4.0.9"
6363
},
6464
"devDependencies": {
@@ -67,47 +67,47 @@
6767
"@changesets/get-release-plan": "^4.0.0",
6868
"@ota-meshi/eslint-plugin": "^0.15.2",
6969
"@types/benchmark": "^2.1.5",
70-
"@types/chai": "^4.3.11",
71-
"@types/eslint": "^8.44.9",
70+
"@types/chai": "^4.3.12",
71+
"@types/eslint": "^8.56.5",
7272
"@types/eslint-scope": "^3.7.7",
7373
"@types/eslint-visitor-keys": "^1.0.0",
7474
"@types/estree": "^1.0.5",
7575
"@types/mocha": "^10.0.6",
76-
"@types/node": "^20.10.4",
77-
"@types/semver": "^7.5.6",
78-
"@typescript-eslint/eslint-plugin": "^7.0.0",
76+
"@types/node": "^20.11.22",
77+
"@types/semver": "^7.5.8",
78+
"@typescript-eslint/eslint-plugin": "^7.1.0",
7979
"@typescript-eslint/parser": "~7.1.0",
8080
"@typescript-eslint/types": "~7.1.0",
8181
"benchmark": "^2.1.4",
82-
"chai": "^4.3.10",
82+
"chai": "^4.4.1",
8383
"env-cmd": "^10.1.0",
84-
"esbuild": "^0.20.0",
84+
"esbuild": "^0.20.1",
8585
"esbuild-register": "^3.5.0",
86-
"eslint": "^8.55.0",
86+
"eslint": "^8.57.0",
8787
"eslint-config-prettier": "^9.1.0",
8888
"eslint-plugin-eslint-comments": "^3.2.0",
89-
"eslint-plugin-json-schema-validator": "^4.7.4",
90-
"eslint-plugin-jsonc": "^2.11.1",
91-
"eslint-plugin-n": "^16.4.0",
92-
"eslint-plugin-node-dependencies": "^0.11.1",
93-
"eslint-plugin-prettier": "^5.0.1",
94-
"eslint-plugin-regexp": "^2.1.2",
89+
"eslint-plugin-json-schema-validator": "^4.8.3",
90+
"eslint-plugin-jsonc": "^2.13.0",
91+
"eslint-plugin-n": "^16.6.2",
92+
"eslint-plugin-node-dependencies": "^0.11.2",
93+
"eslint-plugin-prettier": "^5.1.3",
94+
"eslint-plugin-regexp": "^2.2.0",
9595
"eslint-plugin-svelte": "^2.35.1",
96-
"eslint-plugin-yml": "^1.11.0",
96+
"eslint-plugin-yml": "^1.12.2",
9797
"estree-walker": "^3.0.3",
9898
"locate-character": "^3.0.0",
99-
"magic-string": "^0.30.5",
100-
"mocha": "^10.2.0",
99+
"magic-string": "^0.30.7",
100+
"mocha": "^10.3.0",
101101
"mocha-chai-jest-snapshot": "^1.1.4",
102102
"nyc": "^15.1.0",
103103
"prettier": "~3.2.5",
104-
"prettier-plugin-pkg": "^0.18.0",
105-
"prettier-plugin-svelte": "^3.1.2",
104+
"prettier-plugin-pkg": "^0.18.1",
105+
"prettier-plugin-svelte": "^3.2.2",
106106
"rimraf": "^5.0.5",
107-
"semver": "^7.5.4",
108-
"svelte": "^5.0.0-next.65",
109-
"svelte2tsx": "^0.7.0",
110-
"typescript": "~5.3.0",
107+
"semver": "^7.6.0",
108+
"svelte": "^5.0.0-next.69",
109+
"svelte2tsx": "^0.7.3",
110+
"typescript": "~5.3.3",
111111
"typescript-eslint-parser-for-extra-files": "^0.6.0"
112112
},
113113
"publishConfig": {

src/ast/html.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@ export interface SvelteConstTag extends BaseNode {
276276
/** Node of render tag. e.g. `{@render}` */
277277
export interface SvelteRenderTag extends BaseNode {
278278
type: "SvelteRenderTag";
279-
callee: ESTree.Identifier;
280-
arguments: (ESTree.Expression | ESTree.SpreadElement)[];
279+
expression:
280+
| ESTree.SimpleCallExpression
281+
| (ESTree.ChainExpression & { expression: ESTree.SimpleCallExpression });
281282
parent:
282283
| SvelteProgram
283284
| SvelteElement

src/parser/converts/render.ts

+12-17
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,24 @@ export function convertRenderTag(
1212
): SvelteRenderTag {
1313
const mustache: SvelteRenderTag = {
1414
type: "SvelteRenderTag",
15-
callee: null as any,
16-
arguments: [],
15+
expression: null as any,
1716
parent,
1817
...ctx.getConvertLocation(node),
1918
};
20-
const calleeRange = getWithLoc(node.expression);
21-
const closeParenIndex = ctx.code.indexOf(
22-
")",
23-
node.arguments.length
24-
? getWithLoc(node.arguments[node.arguments.length - 1]).end
25-
: calleeRange.end,
26-
);
19+
const callRange = getWithLoc(node.expression);
2720
ctx.scriptLet.addExpressionFromRange(
28-
[calleeRange.start, closeParenIndex + 1],
21+
[callRange.start, callRange.end],
2922
mustache,
3023
null,
31-
(expression: ESTree.SimpleCallExpression) => {
32-
mustache.callee = expression.callee as ESTree.Identifier;
33-
(mustache.callee as any).parent = mustache;
34-
for (const argument of expression.arguments) {
35-
mustache.arguments.push(argument);
36-
(argument as any).parent = mustache;
37-
}
24+
(
25+
expression:
26+
| ESTree.SimpleCallExpression
27+
| (ESTree.ChainExpression & {
28+
expression: ESTree.SimpleCallExpression;
29+
}),
30+
) => {
31+
mustache.expression = expression;
32+
(mustache.expression as any).parent = mustache;
3833
},
3934
);
4035
const atRenderStart = ctx.code.indexOf("@render", mustache.range[0]);

src/parser/svelte-ast-types.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ export interface ConstTag extends BaseNode {
6060
}
6161
export interface RenderTag extends BaseNode {
6262
type: "RenderTag";
63-
expression: ESTree.Identifier;
64-
arguments: (ESTree.Expression | ESTree.SpreadElement)[];
63+
expression:
64+
| ESTree.SimpleCallExpression
65+
| (ESTree.ChainExpression & { expression: ESTree.SimpleCallExpression });
6566
}
6667
export interface IfBlock extends BaseNode {
6768
type: "IfBlock";

src/visitor-keys.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const svelteKeys: SvelteKeysType = {
2222
SvelteMustacheTag: ["expression"],
2323
SvelteDebugTag: ["identifiers"],
2424
SvelteConstTag: ["declaration"],
25-
SvelteRenderTag: ["callee", "arguments"],
25+
SvelteRenderTag: ["expression"],
2626
SvelteIfBlock: ["expression", "children", "else"],
2727
SvelteElseBlock: ["children"],
2828
SvelteEachBlock: [

tests/fixtures/parser/ast/svelte5/docs/snippets/01-output.json

+64-28
Original file line numberDiff line numberDiff line change
@@ -1126,32 +1126,50 @@
11261126
},
11271127
{
11281128
"type": "SvelteRenderTag",
1129-
"arguments": [
1130-
{
1129+
"expression": {
1130+
"type": "CallExpression",
1131+
"arguments": [
1132+
{
1133+
"type": "Identifier",
1134+
"name": "image",
1135+
"range": [
1136+
288,
1137+
293
1138+
],
1139+
"loc": {
1140+
"start": {
1141+
"line": 16,
1142+
"column": 19
1143+
},
1144+
"end": {
1145+
"line": 16,
1146+
"column": 24
1147+
}
1148+
}
1149+
}
1150+
],
1151+
"callee": {
11311152
"type": "Identifier",
1132-
"name": "image",
1153+
"name": "figure",
11331154
"range": [
1134-
288,
1135-
293
1155+
281,
1156+
287
11361157
],
11371158
"loc": {
11381159
"start": {
11391160
"line": 16,
1140-
"column": 19
1161+
"column": 12
11411162
},
11421163
"end": {
11431164
"line": 16,
1144-
"column": 24
1165+
"column": 18
11451166
}
11461167
}
1147-
}
1148-
],
1149-
"callee": {
1150-
"type": "Identifier",
1151-
"name": "figure",
1168+
},
1169+
"optional": false,
11521170
"range": [
11531171
281,
1154-
287
1172+
294
11551173
],
11561174
"loc": {
11571175
"start": {
@@ -1160,7 +1178,7 @@
11601178
},
11611179
"end": {
11621180
"line": 16,
1163-
"column": 18
1181+
"column": 25
11641182
}
11651183
}
11661184
},
@@ -1237,32 +1255,50 @@
12371255
"children": [
12381256
{
12391257
"type": "SvelteRenderTag",
1240-
"arguments": [
1241-
{
1258+
"expression": {
1259+
"type": "CallExpression",
1260+
"arguments": [
1261+
{
1262+
"type": "Identifier",
1263+
"name": "image",
1264+
"range": [
1265+
330,
1266+
335
1267+
],
1268+
"loc": {
1269+
"start": {
1270+
"line": 19,
1271+
"column": 18
1272+
},
1273+
"end": {
1274+
"line": 19,
1275+
"column": 23
1276+
}
1277+
}
1278+
}
1279+
],
1280+
"callee": {
12421281
"type": "Identifier",
1243-
"name": "image",
1282+
"name": "figure",
12441283
"range": [
1245-
330,
1246-
335
1284+
323,
1285+
329
12471286
],
12481287
"loc": {
12491288
"start": {
12501289
"line": 19,
1251-
"column": 18
1290+
"column": 11
12521291
},
12531292
"end": {
12541293
"line": 19,
1255-
"column": 23
1294+
"column": 17
12561295
}
12571296
}
1258-
}
1259-
],
1260-
"callee": {
1261-
"type": "Identifier",
1262-
"name": "figure",
1297+
},
1298+
"optional": false,
12631299
"range": [
12641300
323,
1265-
329
1301+
336
12661302
],
12671303
"loc": {
12681304
"start": {
@@ -1271,7 +1307,7 @@
12711307
},
12721308
"end": {
12731309
"line": 19,
1274-
"column": 17
1310+
"column": 24
12751311
}
12761312
}
12771313
},

0 commit comments

Comments
 (0)