Skip to content

Commit

Permalink
fix: for svelte v5.0.0-next.69 & support optional {@render} (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Feb 29, 2024
1 parent 30482ac commit f722d7c
Show file tree
Hide file tree
Showing 18 changed files with 1,776 additions and 257 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-ears-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": patch
---

fix: for svelte v5.0.0-next.68 & support optional `{@render}`
50 changes: 25 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"version:ci": "env-cmd -e version-ci pnpm run build:meta && changeset version"
},
"peerDependencies": {
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.65"
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.69"
},
"peerDependenciesMeta": {
"svelte": {
Expand All @@ -58,7 +58,7 @@
"eslint-scope": "^7.2.2",
"eslint-visitor-keys": "^3.4.3",
"espree": "^9.6.1",
"postcss": "^8.4.32",
"postcss": "^8.4.35",
"postcss-scss": "^4.0.9"
},
"devDependencies": {
Expand All @@ -67,47 +67,47 @@
"@changesets/get-release-plan": "^4.0.0",
"@ota-meshi/eslint-plugin": "^0.15.2",
"@types/benchmark": "^2.1.5",
"@types/chai": "^4.3.11",
"@types/eslint": "^8.44.9",
"@types/chai": "^4.3.12",
"@types/eslint": "^8.56.5",
"@types/eslint-scope": "^3.7.7",
"@types/eslint-visitor-keys": "^1.0.0",
"@types/estree": "^1.0.5",
"@types/mocha": "^10.0.6",
"@types/node": "^20.10.4",
"@types/semver": "^7.5.6",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@types/node": "^20.11.22",
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "~7.1.0",
"@typescript-eslint/types": "~7.1.0",
"benchmark": "^2.1.4",
"chai": "^4.3.10",
"chai": "^4.4.1",
"env-cmd": "^10.1.0",
"esbuild": "^0.20.0",
"esbuild": "^0.20.1",
"esbuild-register": "^3.5.0",
"eslint": "^8.55.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-json-schema-validator": "^4.7.4",
"eslint-plugin-jsonc": "^2.11.1",
"eslint-plugin-n": "^16.4.0",
"eslint-plugin-node-dependencies": "^0.11.1",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-regexp": "^2.1.2",
"eslint-plugin-json-schema-validator": "^4.8.3",
"eslint-plugin-jsonc": "^2.13.0",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-node-dependencies": "^0.11.2",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-regexp": "^2.2.0",
"eslint-plugin-svelte": "^2.35.1",
"eslint-plugin-yml": "^1.11.0",
"eslint-plugin-yml": "^1.12.2",
"estree-walker": "^3.0.3",
"locate-character": "^3.0.0",
"magic-string": "^0.30.5",
"mocha": "^10.2.0",
"magic-string": "^0.30.7",
"mocha": "^10.3.0",
"mocha-chai-jest-snapshot": "^1.1.4",
"nyc": "^15.1.0",
"prettier": "~3.2.5",
"prettier-plugin-pkg": "^0.18.0",
"prettier-plugin-svelte": "^3.1.2",
"prettier-plugin-pkg": "^0.18.1",
"prettier-plugin-svelte": "^3.2.2",
"rimraf": "^5.0.5",
"semver": "^7.5.4",
"svelte": "^5.0.0-next.65",
"svelte2tsx": "^0.7.0",
"typescript": "~5.3.0",
"semver": "^7.6.0",
"svelte": "^5.0.0-next.69",
"svelte2tsx": "^0.7.3",
"typescript": "~5.3.3",
"typescript-eslint-parser-for-extra-files": "^0.6.0"
},
"publishConfig": {
Expand Down
5 changes: 3 additions & 2 deletions src/ast/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,9 @@ export interface SvelteConstTag extends BaseNode {
/** Node of render tag. e.g. `{@render}` */
export interface SvelteRenderTag extends BaseNode {
type: "SvelteRenderTag";
callee: ESTree.Identifier;
arguments: (ESTree.Expression | ESTree.SpreadElement)[];
expression:
| ESTree.SimpleCallExpression
| (ESTree.ChainExpression & { expression: ESTree.SimpleCallExpression });
parent:
| SvelteProgram
| SvelteElement
Expand Down
29 changes: 12 additions & 17 deletions src/parser/converts/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,24 @@ export function convertRenderTag(
): SvelteRenderTag {
const mustache: SvelteRenderTag = {
type: "SvelteRenderTag",
callee: null as any,
arguments: [],
expression: null as any,
parent,
...ctx.getConvertLocation(node),
};
const calleeRange = getWithLoc(node.expression);
const closeParenIndex = ctx.code.indexOf(
")",
node.arguments.length
? getWithLoc(node.arguments[node.arguments.length - 1]).end
: calleeRange.end,
);
const callRange = getWithLoc(node.expression);
ctx.scriptLet.addExpressionFromRange(
[calleeRange.start, closeParenIndex + 1],
[callRange.start, callRange.end],
mustache,
null,
(expression: ESTree.SimpleCallExpression) => {
mustache.callee = expression.callee as ESTree.Identifier;
(mustache.callee as any).parent = mustache;
for (const argument of expression.arguments) {
mustache.arguments.push(argument);
(argument as any).parent = mustache;
}
(
expression:
| ESTree.SimpleCallExpression
| (ESTree.ChainExpression & {
expression: ESTree.SimpleCallExpression;
}),
) => {
mustache.expression = expression;
(mustache.expression as any).parent = mustache;
},
);
const atRenderStart = ctx.code.indexOf("@render", mustache.range[0]);
Expand Down
5 changes: 3 additions & 2 deletions src/parser/svelte-ast-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ export interface ConstTag extends BaseNode {
}
export interface RenderTag extends BaseNode {
type: "RenderTag";
expression: ESTree.Identifier;
arguments: (ESTree.Expression | ESTree.SpreadElement)[];
expression:
| ESTree.SimpleCallExpression
| (ESTree.ChainExpression & { expression: ESTree.SimpleCallExpression });
}
export interface IfBlock extends BaseNode {
type: "IfBlock";
Expand Down
2 changes: 1 addition & 1 deletion src/visitor-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const svelteKeys: SvelteKeysType = {
SvelteMustacheTag: ["expression"],
SvelteDebugTag: ["identifiers"],
SvelteConstTag: ["declaration"],
SvelteRenderTag: ["callee", "arguments"],
SvelteRenderTag: ["expression"],
SvelteIfBlock: ["expression", "children", "else"],
SvelteElseBlock: ["children"],
SvelteEachBlock: [
Expand Down
92 changes: 64 additions & 28 deletions tests/fixtures/parser/ast/svelte5/docs/snippets/01-output.json
Original file line number Diff line number Diff line change
Expand Up @@ -1126,32 +1126,50 @@
},
{
"type": "SvelteRenderTag",
"arguments": [
{
"expression": {
"type": "CallExpression",
"arguments": [
{
"type": "Identifier",
"name": "image",
"range": [
288,
293
],
"loc": {
"start": {
"line": 16,
"column": 19
},
"end": {
"line": 16,
"column": 24
}
}
}
],
"callee": {
"type": "Identifier",
"name": "image",
"name": "figure",
"range": [
288,
293
281,
287
],
"loc": {
"start": {
"line": 16,
"column": 19
"column": 12
},
"end": {
"line": 16,
"column": 24
"column": 18
}
}
}
],
"callee": {
"type": "Identifier",
"name": "figure",
},
"optional": false,
"range": [
281,
287
294
],
"loc": {
"start": {
Expand All @@ -1160,7 +1178,7 @@
},
"end": {
"line": 16,
"column": 18
"column": 25
}
}
},
Expand Down Expand Up @@ -1237,32 +1255,50 @@
"children": [
{
"type": "SvelteRenderTag",
"arguments": [
{
"expression": {
"type": "CallExpression",
"arguments": [
{
"type": "Identifier",
"name": "image",
"range": [
330,
335
],
"loc": {
"start": {
"line": 19,
"column": 18
},
"end": {
"line": 19,
"column": 23
}
}
}
],
"callee": {
"type": "Identifier",
"name": "image",
"name": "figure",
"range": [
330,
335
323,
329
],
"loc": {
"start": {
"line": 19,
"column": 18
"column": 11
},
"end": {
"line": 19,
"column": 23
"column": 17
}
}
}
],
"callee": {
"type": "Identifier",
"name": "figure",
},
"optional": false,
"range": [
323,
329
336
],
"loc": {
"start": {
Expand All @@ -1271,7 +1307,7 @@
},
"end": {
"line": 19,
"column": 17
"column": 24
}
}
},
Expand Down

0 comments on commit f722d7c

Please sign in to comment.