diff --git a/.changeset/yellow-hornets-bow.md b/.changeset/yellow-hornets-bow.md new file mode 100644 index 00000000..d3c5ae1b --- /dev/null +++ b/.changeset/yellow-hornets-bow.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": minor +--- + +feat: change AST of `{@render}` and `{#snippet}` to match the latest version of svelte v5. diff --git a/docs/AST.md b/docs/AST.md index 6173589c..680820a9 100644 --- a/docs/AST.md +++ b/docs/AST.md @@ -423,6 +423,8 @@ interface SvelteConstTag extends Node { } ``` +[VariableDeclarator] is a node defined in ESTree. + ### SvelteRenderTag This is the `{@render}` tag node. @@ -431,12 +433,10 @@ This is the `{@render}` tag node. interface SvelteRenderTag extends Node { type: "SvelteRenderTag"; callee: Identifier; - argument: Expression | null; + arguments: (Expression | SpreadElement)[]; } ``` -[VariableDeclarator] is a node defined in ESTree. - ### SvelteIfBlock This is the `{#if}` tag node. `{:else if}` is also included in this node. @@ -555,7 +555,7 @@ This is the `{#snippet}` tag node. interface SvelteSnippetBlock extends Node { type: "SvelteSnippetBlock"; id: Identifier; - context: null | Pattern; + params: Pattern[]; children: Child[]; } ``` diff --git a/package.json b/package.json index 1edf9901..9b21d518 100644 --- a/package.json +++ b/package.json @@ -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.37" + "svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.65" }, "peerDependenciesMeta": { "svelte": { @@ -105,7 +105,7 @@ "prettier-plugin-svelte": "^3.1.2", "rimraf": "^5.0.5", "semver": "^7.5.4", - "svelte": "^5.0.0-next.37", + "svelte": "^5.0.0-next.65", "svelte2tsx": "^0.7.0", "typescript": "~5.3.0", "typescript-eslint-parser-for-extra-files": "^0.6.0" diff --git a/src/ast/html.ts b/src/ast/html.ts index 081674bb..65fcda64 100644 --- a/src/ast/html.ts +++ b/src/ast/html.ts @@ -277,7 +277,7 @@ export interface SvelteConstTag extends BaseNode { export interface SvelteRenderTag extends BaseNode { type: "SvelteRenderTag"; callee: ESTree.Identifier; - argument: ESTree.Expression | null; + arguments: (ESTree.Expression | ESTree.SpreadElement)[]; parent: | SvelteProgram | SvelteElement @@ -480,7 +480,7 @@ export interface SvelteKeyBlock extends BaseNode { export interface SvelteSnippetBlock extends BaseNode { type: "SvelteSnippetBlock"; id: ESTree.Identifier; - context: null | ESTree.Pattern; + params: ESTree.Pattern[]; children: Child[]; parent: | SvelteProgram diff --git a/src/context/script-let.ts b/src/context/script-let.ts index 8ae1c97a..88b88635 100644 --- a/src/context/script-let.ts +++ b/src/context/script-let.ts @@ -428,7 +428,7 @@ export class ScriptLetContext { id: ESTree.Identifier, closeParentIndex: number, snippetBlock: SvelteSnippetBlock, - callback: (id: ESTree.Identifier, ctx: ESTree.Pattern | null) => void, + callback: (id: ESTree.Identifier, params: ESTree.Pattern[]) => void, ): void { const idRange = getNodeRange(id); const part = this.ctx.code.slice(idRange[0], closeParentIndex + 1); @@ -438,14 +438,14 @@ export class ScriptLetContext { (st, tokens, _comments, result) => { const fnDecl = st as ESTree.FunctionDeclaration; const idNode = fnDecl.id; - const context = fnDecl.params.length > 0 ? fnDecl.params[0] : null; + const params = [...fnDecl.params]; const scope = result.getScope(fnDecl); // Process for nodes - callback(idNode, context); + callback(idNode, params); (idNode as any).parent = snippetBlock; - if (context) { - (context as any).parent = snippetBlock; + for (const param of params) { + (param as any).parent = snippetBlock; } // Process for scope diff --git a/src/parser/converts/block.ts b/src/parser/converts/block.ts index 04992201..66aeb9e9 100644 --- a/src/parser/converts/block.ts +++ b/src/parser/converts/block.ts @@ -462,7 +462,7 @@ export function convertSnippetBlock( const snippetBlock: SvelteSnippetBlock = { type: "SvelteSnippetBlock", id: null as any, - context: null as any, + params: [], children: [], parent, ...ctx.getConvertLocation({ start: nodeStart, end: node.end }), @@ -470,16 +470,20 @@ export function convertSnippetBlock( const closeParenIndex = ctx.code.indexOf( ")", - getWithLoc(node.context || node.expression).end, + getWithLoc( + node.parameters.length > 0 + ? node.parameters[node.parameters.length - 1] + : node.expression, + ).end, ); ctx.scriptLet.nestSnippetBlock( node.expression, closeParenIndex, snippetBlock, - (id, context) => { + (id, params) => { snippetBlock.id = id; - snippetBlock.context = context; + snippetBlock.params = params; }, ); diff --git a/src/parser/converts/render.ts b/src/parser/converts/render.ts index 3e74e2fe..d5ef6ab6 100644 --- a/src/parser/converts/render.ts +++ b/src/parser/converts/render.ts @@ -13,14 +13,16 @@ export function convertRenderTag( const mustache: SvelteRenderTag = { type: "SvelteRenderTag", callee: null as any, - argument: null, + arguments: [], parent, ...ctx.getConvertLocation(node), }; const calleeRange = getWithLoc(node.expression); const closeParenIndex = ctx.code.indexOf( ")", - node.argument ? getWithLoc(node.argument).end : calleeRange.end, + node.arguments.length + ? getWithLoc(node.arguments[node.arguments.length - 1]).end + : calleeRange.end, ); ctx.scriptLet.addExpressionFromRange( [calleeRange.start, closeParenIndex + 1], @@ -29,9 +31,9 @@ export function convertRenderTag( (expression: ESTree.SimpleCallExpression) => { mustache.callee = expression.callee as ESTree.Identifier; (mustache.callee as any).parent = mustache; - if (expression.arguments.length) { - mustache.argument = expression.arguments[0] as ESTree.Expression; - (mustache.argument as any).parent = mustache; + for (const argument of expression.arguments) { + mustache.arguments.push(argument); + (argument as any).parent = mustache; } }, ); diff --git a/src/parser/svelte-ast-types.ts b/src/parser/svelte-ast-types.ts index 4ebf1af2..78ec68c8 100644 --- a/src/parser/svelte-ast-types.ts +++ b/src/parser/svelte-ast-types.ts @@ -61,7 +61,7 @@ export interface ConstTag extends BaseNode { export interface RenderTag extends BaseNode { type: "RenderTag"; expression: ESTree.Identifier; - argument: null | ESTree.Expression; + arguments: (ESTree.Expression | ESTree.SpreadElement)[]; } export interface IfBlock extends BaseNode { type: "IfBlock"; @@ -116,7 +116,7 @@ export interface KeyBlock extends BaseNode { export interface SnippetBlock extends BaseNode { type: "SnippetBlock"; expression: ESTree.Identifier; - context: null | ESTree.Pattern; + parameters: ESTree.Pattern[]; children: TemplateNode[]; } diff --git a/src/visitor-keys.ts b/src/visitor-keys.ts index c9b2caad..99e5a532 100644 --- a/src/visitor-keys.ts +++ b/src/visitor-keys.ts @@ -22,7 +22,7 @@ const svelteKeys: SvelteKeysType = { SvelteMustacheTag: ["expression"], SvelteDebugTag: ["identifiers"], SvelteConstTag: ["declaration"], - SvelteRenderTag: ["callee", "argument"], + SvelteRenderTag: ["callee", "arguments"], SvelteIfBlock: ["expression", "children", "else"], SvelteElseBlock: ["children"], SvelteEachBlock: [ @@ -38,7 +38,7 @@ const svelteKeys: SvelteKeysType = { SvelteAwaitThenBlock: ["value", "children"], SvelteAwaitCatchBlock: ["error", "children"], SvelteKeyBlock: ["expression", "children"], - SvelteSnippetBlock: ["id", "context", "children"], + SvelteSnippetBlock: ["id", "params", "children"], SvelteAttribute: ["key", "value"], SvelteShorthandAttribute: ["key", "value"], SvelteSpreadAttribute: ["argument"], diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/01-output.json b/tests/fixtures/parser/ast/svelte5/docs/snippets/01-output.json index 6cb9ad66..7124ed40 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/01-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/01-output.json @@ -782,24 +782,6 @@ } } ], - "context": { - "type": "Identifier", - "name": "image", - "range": [ - 17, - 22 - ], - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 22 - } - } - }, "id": { "type": "Identifier", "name": "figure", @@ -818,6 +800,26 @@ } } }, + "params": [ + { + "type": "Identifier", + "name": "image", + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 22 + } + } + } + ], "range": [ 0, 201 @@ -1124,24 +1126,26 @@ }, { "type": "SvelteRenderTag", - "argument": { - "type": "Identifier", - "name": "image", - "range": [ - 288, - 293 - ], - "loc": { - "start": { - "line": 16, - "column": 19 - }, - "end": { - "line": 16, - "column": 24 + "arguments": [ + { + "type": "Identifier", + "name": "image", + "range": [ + 288, + 293 + ], + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 24 + } } } - }, + ], "callee": { "type": "Identifier", "name": "figure", @@ -1233,24 +1237,26 @@ "children": [ { "type": "SvelteRenderTag", - "argument": { - "type": "Identifier", - "name": "image", - "range": [ - 330, - 335 - ], - "loc": { - "start": { - "line": 19, - "column": 18 - }, - "end": { - "line": 19, - "column": 23 + "arguments": [ + { + "type": "Identifier", + "name": "image", + "range": [ + 330, + 335 + ], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 23 + } } } - }, + ], "callee": { "type": "Identifier", "name": "figure", diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/01-scope-output.json b/tests/fixtures/parser/ast/svelte5/docs/snippets/01-scope-output.json index 272a4a0e..79dbc140 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/01-scope-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/01-scope-output.json @@ -1254,24 +1254,26 @@ }, { "type": "SvelteRenderTag", - "argument": { - "type": "Identifier", - "name": "image", - "range": [ - 288, - 293 - ], - "loc": { - "start": { - "line": 16, - "column": 19 - }, - "end": { - "line": 16, - "column": 24 + "arguments": [ + { + "type": "Identifier", + "name": "image", + "range": [ + 288, + 293 + ], + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 24 + } } } - }, + ], "callee": { "type": "Identifier", "name": "figure", @@ -1363,24 +1365,26 @@ "children": [ { "type": "SvelteRenderTag", - "argument": { - "type": "Identifier", - "name": "image", - "range": [ - 330, - 335 - ], - "loc": { - "start": { - "line": 19, - "column": 18 - }, - "end": { - "line": 19, - "column": 23 + "arguments": [ + { + "type": "Identifier", + "name": "image", + "range": [ + 330, + 335 + ], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 23 + } } } - }, + ], "callee": { "type": "Identifier", "name": "figure", diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/02-output.json b/tests/fixtures/parser/ast/svelte5/docs/snippets/02-output.json index 7ae7cabe..14dbf662 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/02-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/02-output.json @@ -534,36 +534,70 @@ } } ], - "context": { - "type": "ObjectPattern", - "properties": [ - { - "type": "Property", - "kind": "init", - "computed": false, - "key": { - "type": "Identifier", - "name": "src", - "range": [ - 19, - 22 - ], - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 22 + "id": { + "type": "Identifier", + "name": "figure", + "range": [ + 10, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + "params": [ + { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "src", + "range": [ + 19, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 22 + } } - } - }, - "method": false, - "shorthand": true, - "value": { - "type": "Identifier", - "name": "src", + }, + "method": false, + "shorthand": true, + "value": { + "type": "Identifier", + "name": "src", + "range": [ + 19, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 22 + } + } + }, "range": [ 19, 22 @@ -579,48 +613,48 @@ } } }, - "range": [ - 19, - 22 - ], - "loc": { - "start": { - "line": 1, - "column": 19 + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "caption", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 31 + } + } }, - "end": { - "line": 1, - "column": 22 - } - } - }, - { - "type": "Property", - "kind": "init", - "computed": false, - "key": { - "type": "Identifier", - "name": "caption", - "range": [ - 24, - 31 - ], - "loc": { - "start": { - "line": 1, - "column": 24 - }, - "end": { - "line": 1, - "column": 31 + "method": false, + "shorthand": true, + "value": { + "type": "Identifier", + "name": "caption", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 31 + } } - } - }, - "method": false, - "shorthand": true, - "value": { - "type": "Identifier", - "name": "caption", + }, "range": [ 24, 31 @@ -636,48 +670,48 @@ } } }, - "range": [ - 24, - 31 - ], - "loc": { - "start": { - "line": 1, - "column": 24 + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "width", + "range": [ + 33, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 38 + } + } }, - "end": { - "line": 1, - "column": 31 - } - } - }, - { - "type": "Property", - "kind": "init", - "computed": false, - "key": { - "type": "Identifier", - "name": "width", - "range": [ - 33, - 38 - ], - "loc": { - "start": { - "line": 1, - "column": 33 - }, - "end": { - "line": 1, - "column": 38 + "method": false, + "shorthand": true, + "value": { + "type": "Identifier", + "name": "width", + "range": [ + 33, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 38 + } } - } - }, - "method": false, - "shorthand": true, - "value": { - "type": "Identifier", - "name": "width", + }, "range": [ 33, 38 @@ -693,48 +727,48 @@ } } }, - "range": [ - 33, - 38 - ], - "loc": { - "start": { - "line": 1, - "column": 33 + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "height", + "range": [ + 40, + 46 + ], + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 46 + } + } }, - "end": { - "line": 1, - "column": 38 - } - } - }, - { - "type": "Property", - "kind": "init", - "computed": false, - "key": { - "type": "Identifier", - "name": "height", - "range": [ - 40, - 46 - ], - "loc": { - "start": { - "line": 1, - "column": 40 - }, - "end": { - "line": 1, - "column": 46 + "method": false, + "shorthand": true, + "value": { + "type": "Identifier", + "name": "height", + "range": [ + 40, + 46 + ], + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 46 + } } - } - }, - "method": false, - "shorthand": true, - "value": { - "type": "Identifier", - "name": "height", + }, "range": [ 40, 46 @@ -749,56 +783,24 @@ "column": 46 } } + } + ], + "range": [ + 17, + 48 + ], + "loc": { + "start": { + "line": 1, + "column": 17 }, - "range": [ - 40, - 46 - ], - "loc": { - "start": { - "line": 1, - "column": 40 - }, - "end": { - "line": 1, - "column": 46 - } + "end": { + "line": 1, + "column": 48 } } - ], - "range": [ - 17, - 48 - ], - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 48 - } - } - }, - "id": { - "type": "Identifier", - "name": "figure", - "range": [ - 10, - 16 - ], - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 1, - "column": 16 - } } - }, + ], "range": [ 0, 166 diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/03-snippet-scope-output.json b/tests/fixtures/parser/ast/svelte5/docs/snippets/03-snippet-scope-output.json index c83771cf..0ee78980 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/03-snippet-scope-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/03-snippet-scope-output.json @@ -505,24 +505,6 @@ } } ], - "context": { - "type": "Identifier", - "name": "name", - "range": [ - 92, - 96 - ], - "loc": { - "start": { - "line": 5, - "column": 16 - }, - "end": { - "line": 5, - "column": 20 - } - } - }, "id": { "type": "Identifier", "name": "hello", @@ -541,6 +523,26 @@ } } }, + "params": [ + { + "type": "Identifier", + "name": "name", + "range": [ + 92, + 96 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + ], "range": [ 76, 142 @@ -576,25 +578,27 @@ }, { "type": "SvelteRenderTag", - "argument": { - "type": "Literal", - "raw": "'alice'", - "value": "alice", - "range": [ - 159, - 166 - ], - "loc": { - "start": { - "line": 9, - "column": 15 - }, - "end": { - "line": 9, - "column": 22 + "arguments": [ + { + "type": "Literal", + "raw": "'alice'", + "value": "alice", + "range": [ + 159, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 22 + } } } - }, + ], "callee": { "type": "Identifier", "name": "hello", @@ -648,25 +652,27 @@ }, { "type": "SvelteRenderTag", - "argument": { - "type": "Literal", - "raw": "'bob'", - "value": "bob", - "range": [ - 184, - 189 - ], - "loc": { - "start": { - "line": 10, - "column": 15 - }, - "end": { - "line": 10, - "column": 20 + "arguments": [ + { + "type": "Literal", + "raw": "'bob'", + "value": "bob", + "range": [ + 184, + 189 + ], + "loc": { + "start": { + "line": 10, + "column": 15 + }, + "end": { + "line": 10, + "column": 20 + } } } - }, + ], "callee": { "type": "Identifier", "name": "hello", diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/04-snippet-scope-output.json b/tests/fixtures/parser/ast/svelte5/docs/snippets/04-snippet-scope-output.json index 6bb3d37d..6631c8db 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/04-snippet-scope-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/04-snippet-scope-output.json @@ -85,7 +85,6 @@ } } ], - "context": null, "id": { "type": "Identifier", "name": "y", @@ -104,6 +103,7 @@ } } }, + "params": [], "range": [ 24, 51 @@ -175,7 +175,7 @@ }, { "type": "SvelteRenderTag", - "argument": null, + "arguments": [], "callee": { "type": "Identifier", "name": "y", @@ -210,7 +210,6 @@ } } ], - "context": null, "id": { "type": "Identifier", "name": "x", @@ -229,6 +228,7 @@ } } }, + "params": [], "range": [ 7, 104 @@ -300,7 +300,7 @@ }, { "type": "SvelteRenderTag", - "argument": null, + "arguments": [], "callee": { "type": "Identifier", "name": "y", @@ -441,7 +441,7 @@ }, { "type": "SvelteRenderTag", - "argument": null, + "arguments": [], "callee": { "type": "Identifier", "name": "x", diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/05-snippet-scope-output.json b/tests/fixtures/parser/ast/svelte5/docs/snippets/05-snippet-scope-output.json index a661c203..7a35b3e2 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/05-snippet-scope-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/05-snippet-scope-output.json @@ -97,7 +97,6 @@ } } ], - "context": null, "id": { "type": "Identifier", "name": "blastoff", @@ -116,6 +115,7 @@ } } }, + "params": [], "range": [ 0, 49 @@ -359,61 +359,63 @@ }, { "type": "SvelteRenderTag", - "argument": { - "type": "BinaryExpression", - "left": { - "type": "Identifier", - "name": "n", - "range": [ - 131, - 132 - ], - "loc": { - "start": { - "line": 8, - "column": 21 - }, - "end": { - "line": 8, - "column": 22 + "arguments": [ + { + "type": "BinaryExpression", + "left": { + "type": "Identifier", + "name": "n", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 8, + "column": 21 + }, + "end": { + "line": 8, + "column": 22 + } } - } - }, - "operator": "-", - "right": { - "type": "Literal", - "raw": "1", - "value": 1, + }, + "operator": "-", + "right": { + "type": "Literal", + "raw": "1", + "value": 1, + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 8, + "column": 25 + }, + "end": { + "line": 8, + "column": 26 + } + } + }, "range": [ - 135, + 131, 136 ], "loc": { "start": { "line": 8, - "column": 25 + "column": 21 }, "end": { "line": 8, "column": 26 } } - }, - "range": [ - 131, - 136 - ], - "loc": { - "start": { - "line": 8, - "column": 21 - }, - "end": { - "line": 8, - "column": 26 - } } - }, + ], "callee": { "type": "Identifier", "name": "countdown", @@ -454,7 +456,7 @@ "children": [ { "type": "SvelteRenderTag", - "argument": null, + "arguments": [], "callee": { "type": "Identifier", "name": "blastoff", @@ -520,24 +522,6 @@ } } ], - "context": { - "type": "Identifier", - "name": "n", - "range": [ - 71, - 72 - ], - "loc": { - "start": { - "line": 5, - "column": 20 - }, - "end": { - "line": 5, - "column": 21 - } - } - }, "id": { "type": "Identifier", "name": "countdown", @@ -556,6 +540,26 @@ } } }, + "params": [ + { + "type": "Identifier", + "name": "n", + "range": [ + 71, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + } + } + ], "range": [ 51, 188 @@ -591,25 +595,27 @@ }, { "type": "SvelteRenderTag", - "argument": { - "type": "Literal", - "raw": "10", - "value": 10, - "range": [ - 209, - 211 - ], - "loc": { - "start": { - "line": 14, - "column": 19 - }, - "end": { - "line": 14, - "column": 21 + "arguments": [ + { + "type": "Literal", + "raw": "10", + "value": 10, + "range": [ + 209, + 211 + ], + "loc": { + "start": { + "line": 14, + "column": 19 + }, + "end": { + "line": 14, + "column": 21 + } } } - }, + ], "callee": { "type": "Identifier", "name": "countdown", diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/06-passing-snippets-to-components-output.json b/tests/fixtures/parser/ast/svelte5/docs/snippets/06-passing-snippets-to-components-output.json index 519bfa19..beb3ba5d 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/06-passing-snippets-to-components-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/06-passing-snippets-to-components-output.json @@ -1244,7 +1244,6 @@ } } ], - "context": null, "id": { "type": "Identifier", "name": "header", @@ -1263,6 +1262,7 @@ } } }, + "params": [], "range": [ 206, 298 @@ -2015,24 +2015,6 @@ } } ], - "context": { - "type": "Identifier", - "name": "d", - "range": [ - 314, - 315 - ], - "loc": { - "start": { - "line": 18, - "column": 14 - }, - "end": { - "line": 18, - "column": 15 - } - } - }, "id": { "type": "Identifier", "name": "row", @@ -2051,6 +2033,26 @@ } } }, + "params": [ + { + "type": "Identifier", + "name": "d", + "range": [ + 314, + 315 + ], + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 15 + } + } + } + ], "range": [ 300, 413 diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/07-passing-snippets-to-components-output.json b/tests/fixtures/parser/ast/svelte5/docs/snippets/07-passing-snippets-to-components-output.json index 882c89fa..c48dde3e 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/07-passing-snippets-to-components-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/07-passing-snippets-to-components-output.json @@ -597,7 +597,6 @@ } } ], - "context": null, "id": { "type": "Identifier", "name": "header", @@ -616,6 +615,7 @@ } } }, + "params": [], "range": [ 75, 172 @@ -1368,24 +1368,6 @@ } } ], - "context": { - "type": "Identifier", - "name": "d", - "range": [ - 189, - 190 - ], - "loc": { - "start": { - "line": 10, - "column": 15 - }, - "end": { - "line": 10, - "column": 16 - } - } - }, "id": { "type": "Identifier", "name": "row", @@ -1404,6 +1386,26 @@ } } }, + "params": [ + { + "type": "Identifier", + "name": "d", + "range": [ + 189, + 190 + ], + "loc": { + "start": { + "line": 10, + "column": 15 + }, + "end": { + "line": 10, + "column": 16 + } + } + } + ], "range": [ 175, 293 diff --git a/tests/fixtures/parser/ast/svelte5/docs/snippets/09-passing-snippets-to-components-output.json b/tests/fixtures/parser/ast/svelte5/docs/snippets/09-passing-snippets-to-components-output.json index c5531576..190ffa13 100644 --- a/tests/fixtures/parser/ast/svelte5/docs/snippets/09-passing-snippets-to-components-output.json +++ b/tests/fixtures/parser/ast/svelte5/docs/snippets/09-passing-snippets-to-components-output.json @@ -539,7 +539,7 @@ "children": [ { "type": "SvelteRenderTag", - "argument": null, + "arguments": [], "callee": { "type": "Identifier", "name": "children", diff --git a/tests/fixtures/parser/ast/svelte5/render01-input.svelte b/tests/fixtures/parser/ast/svelte5/render01-input.svelte new file mode 100644 index 00000000..2b4b7683 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/render01-input.svelte @@ -0,0 +1,9 @@ + + +{@render foo(bar())} diff --git a/tests/fixtures/parser/ast/svelte5/render01-output.json b/tests/fixtures/parser/ast/svelte5/render01-output.json new file mode 100644 index 00000000..9cdcf70c --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/render01-output.json @@ -0,0 +1,1062 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "method": false, + "shorthand": true, + "value": { + "type": "Identifier", + "name": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + ], + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "Identifier", + "name": "$props", + "range": [ + 26, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "optional": false, + "range": [ + 26, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "range": [ + 16, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 25 + } + } + } + ], + "range": [ + 10, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + { + "type": "FunctionDeclaration", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Literal", + "raw": "\"baz\"", + "value": "baz", + "range": [ + 64, + 69 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "range": [ + 57, + 70 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 15 + } + } + } + ], + "range": [ + 53, + 73 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 6, + "column": 2 + } + } + }, + "expression": false, + "generator": false, + "id": { + "type": "Identifier", + "name": "bar", + "range": [ + 47, + 50 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 13 + } + } + }, + "params": [], + "range": [ + 38, + 73 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 6, + "column": 2 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 74, + 83 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + "range": [ + 0, + 83 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 83, + 85 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 9, + "column": 0 + } + } + }, + { + "type": "SvelteRenderTag", + "arguments": [ + { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "Identifier", + "name": "bar", + "range": [ + 98, + 101 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + "optional": false, + "range": [ + 98, + 103 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 18 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "foo", + "range": [ + 94, + 97 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + "range": [ + 85, + 105 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 20 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 22, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Identifier", + "value": "$props", + "range": [ + 26, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 33, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + { + "type": "Keyword", + "value": "function", + "range": [ + 38, + 46 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 47, + 50 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + { + "type": "Keyword", + "value": "return", + "range": [ + 57, + 63 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 8 + } + } + }, + { + "type": "String", + "value": "\"baz\"", + "range": [ + 64, + 69 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 76, + 82 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 83, + 85 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 9, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + } + }, + { + "type": "MustacheKeyword", + "value": "@render", + "range": [ + 86, + 93 + ], + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 94, + 97 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 98, + 101 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 9, + "column": 16 + }, + "end": { + "line": 9, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 20 + } + } + } + ], + "range": [ + 0, + 106 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/render01-scope-output.json b/tests/fixtures/parser/ast/svelte5/render01-scope-output.json new file mode 100644 index 00000000..c5adec2d --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/render01-scope-output.json @@ -0,0 +1,712 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 26, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + }, + { + "name": "$inspect", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "foo", + "identifiers": [ + { + "type": "Identifier", + "name": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "method": false, + "shorthand": true, + "value": { + "type": "Identifier", + "name": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + ], + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "Identifier", + "name": "$props", + "range": [ + 26, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "optional": false, + "range": [ + 26, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "range": [ + 16, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 25 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "foo", + "range": [ + 94, + 97 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + } + ] + }, + { + "name": "bar", + "identifiers": [ + { + "type": "Identifier", + "name": "bar", + "range": [ + 47, + 50 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 13 + } + } + } + ], + "defs": [ + { + "type": "FunctionName", + "name": { + "type": "Identifier", + "name": "bar", + "range": [ + 47, + 50 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 13 + } + } + }, + "node": { + "type": "FunctionDeclaration", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Literal", + "raw": "\"baz\"", + "value": "baz", + "range": [ + 64, + 69 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "range": [ + 57, + 70 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 15 + } + } + } + ], + "range": [ + 53, + 73 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 6, + "column": 2 + } + } + }, + "expression": false, + "generator": false, + "id": { + "type": "Identifier", + "name": "bar", + "range": [ + 47, + 50 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 13 + } + } + }, + "params": [], + "range": [ + 38, + 73 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 6, + "column": 2 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "bar", + "range": [ + 98, + 101 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "bar", + "range": [ + 47, + 50 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 13 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 26, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "foo", + "range": [ + 94, + 97 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "foo", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "bar", + "range": [ + 98, + 101 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "bar", + "range": [ + 47, + 50 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 13 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "arguments", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [], + "through": [] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 26, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-snippet01-output.json b/tests/fixtures/parser/ast/svelte5/ts-snippet01-output.json index 274ac1dd..e13eebb3 100644 --- a/tests/fixtures/parser/ast/svelte5/ts-snippet01-output.json +++ b/tests/fixtures/parser/ast/svelte5/ts-snippet01-output.json @@ -337,21 +337,55 @@ } } ], - "context": { + "id": { "type": "Identifier", - "name": "msg", - "typeAnnotation": { - "type": "TSTypeAnnotation", + "name": "foo", + "range": [ + 57, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 13 + } + } + }, + "params": [ + { + "type": "Identifier", + "name": "msg", "typeAnnotation": { - "type": "TSStringKeyword", + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 66, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, "range": [ - 66, + 64, 72 ], "loc": { "start": { "line": 5, - "column": 19 + "column": 17 }, "end": { "line": 5, @@ -360,53 +394,21 @@ } }, "range": [ - 64, + 61, 72 ], "loc": { "start": { "line": 5, - "column": 17 + "column": 14 }, "end": { "line": 5, "column": 25 } } - }, - "range": [ - 61, - 72 - ], - "loc": { - "start": { - "line": 5, - "column": 14 - }, - "end": { - "line": 5, - "column": 25 - } - } - }, - "id": { - "type": "Identifier", - "name": "foo", - "range": [ - 57, - 60 - ], - "loc": { - "start": { - "line": 5, - "column": 10 - }, - "end": { - "line": 5, - "column": 13 - } } - }, + ], "range": [ 47, 99 @@ -442,24 +444,26 @@ }, { "type": "SvelteRenderTag", - "argument": { - "type": "Identifier", - "name": "msg", - "range": [ - 114, - 117 - ], - "loc": { - "start": { - "line": 9, - "column": 13 - }, - "end": { - "line": 9, - "column": 16 + "arguments": [ + { + "type": "Identifier", + "name": "msg", + "range": [ + 114, + 117 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 16 + } } } - }, + ], "callee": { "type": "Identifier", "name": "foo",