diff --git a/.changeset/rare-teachers-search.md b/.changeset/rare-teachers-search.md new file mode 100644 index 00000000..0ebd2c19 --- /dev/null +++ b/.changeset/rare-teachers-search.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": minor +--- + +feat: add support for `$derived.by` type diff --git a/src/parser/typescript/analyze/index.ts b/src/parser/typescript/analyze/index.ts index 5ad20be8..52700c85 100644 --- a/src/parser/typescript/analyze/index.ts +++ b/src/parser/typescript/analyze/index.ts @@ -328,6 +328,9 @@ function analyzeRuneVariables( appendDeclareFunctionVirtualScripts(globalName, [ "(expression: T): T", ]); + appendDeclareNamespaceVirtualScripts(globalName, [ + "export function by(fn: () => T): T;", + ]); break; } case "$effect": { diff --git a/tests/fixtures/parser/ast/svelte5/docs/runes/02-2-$derived-by-input.svelte b/tests/fixtures/parser/ast/svelte5/docs/runes/02-2-$derived-by-input.svelte new file mode 100644 index 00000000..c3552989 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/docs/runes/02-2-$derived-by-input.svelte @@ -0,0 +1,14 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/docs/runes/02-2-$derived-by-output.json b/tests/fixtures/parser/ast/svelte5/docs/runes/02-2-$derived-by-output.json new file mode 100644 index 00000000..8c3bb93d --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/docs/runes/02-2-$derived-by-output.json @@ -0,0 +1,3047 @@ +{ + "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": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [ + { + "type": "ArrayExpression", + "elements": [ + { + "type": "Literal", + "raw": "1", + "value": 1, + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + { + "type": "Literal", + "raw": "2", + "value": 2, + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 27 + } + } + }, + { + "type": "Literal", + "raw": "3", + "value": 3, + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + } + } + ], + "range": [ + 31, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 31 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "$state", + "range": [ + 24, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "optional": false, + "range": [ + 24, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + "range": [ + 14, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 32 + } + } + } + ], + "range": [ + 10, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + { + "type": "VariableDeclaration", + "kind": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "total", + "range": [ + 48, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [ + { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "init": { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + "range": [ + 82, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 15 + } + } + } + ], + "range": [ + 78, + 92 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + { + "type": "ForOfStatement", + "await": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "left": { + "type": "Identifier", + "name": "total", + "range": [ + 125, + 130 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "operator": "+=", + "right": { + "type": "Identifier", + "name": "n", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "range": [ + 125, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "range": [ + 125, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 14 + } + } + } + ], + "range": [ + 120, + 140 + ], + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + "left": { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "init": null, + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + ], + "range": [ + 100, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "right": { + "type": "Identifier", + "name": "numbers", + "range": [ + 111, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 95, + 140 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "total", + "range": [ + 150, + 155 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "range": [ + 143, + 156 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 15 + } + } + } + ], + "range": [ + 74, + 159 + ], + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [], + "range": [ + 68, + 159 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 9, + "column": 2 + } + } + } + ], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "$derived", + "range": [ + 56, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "by", + "range": [ + 65, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 22 + }, + "end": { + "line": 3, + "column": 24 + } + } + }, + "range": [ + 56, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 24 + } + } + }, + "optional": false, + "range": [ + 56, + 160 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + "range": [ + 48, + 160 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 9, + "column": 3 + } + } + } + ], + "range": [ + 44, + 161 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 9, + "column": 4 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 162, + 171 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + "range": [ + 0, + 171 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 171, + 173 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 12, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "button", + "range": [ + 174, + 180 + ], + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "EventHandler", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "click", + "range": [ + 184, + 189 + ], + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + "modifiers": [], + "range": [ + 181, + 189 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "CallExpression", + "arguments": [ + { + "type": "BinaryExpression", + "left": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "numbers", + "range": [ + 210, + 217 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 44 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "length", + "range": [ + 218, + 224 + ], + "loc": { + "start": { + "line": 12, + "column": 45 + }, + "end": { + "line": 12, + "column": 51 + } + } + }, + "range": [ + 210, + 224 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 51 + } + } + }, + "operator": "+", + "right": { + "type": "Literal", + "raw": "1", + "value": 1, + "range": [ + 227, + 228 + ], + "loc": { + "start": { + "line": 12, + "column": 54 + }, + "end": { + "line": 12, + "column": 55 + } + } + }, + "range": [ + 210, + 228 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 55 + } + } + } + ], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "numbers", + "range": [ + 197, + 204 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 31 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "push", + "range": [ + 205, + 209 + ], + "loc": { + "start": { + "line": 12, + "column": 32 + }, + "end": { + "line": 12, + "column": 36 + } + } + }, + "range": [ + 197, + 209 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 36 + } + } + }, + "optional": false, + "range": [ + 197, + 229 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 56 + } + } + }, + "expression": true, + "generator": false, + "id": null, + "params": [], + "range": [ + 191, + 229 + ], + "loc": { + "start": { + "line": 12, + "column": 18 + }, + "end": { + "line": 12, + "column": 56 + } + } + }, + "range": [ + 181, + 230 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 57 + } + } + } + ], + "selfClosing": false, + "range": [ + 173, + 231 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 58 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "\n\t", + "range": [ + 231, + 233 + ], + "loc": { + "start": { + "line": 12, + "column": 58 + }, + "end": { + "line": 13, + "column": 1 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "CallExpression", + "arguments": [ + { + "type": "Literal", + "raw": "' + '", + "value": " + ", + "range": [ + 247, + 252 + ], + "loc": { + "start": { + "line": 13, + "column": 15 + }, + "end": { + "line": 13, + "column": 20 + } + } + } + ], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "numbers", + "range": [ + 234, + 241 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 9 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "join", + "range": [ + 242, + 246 + ], + "loc": { + "start": { + "line": 13, + "column": 10 + }, + "end": { + "line": 13, + "column": 14 + } + } + }, + "range": [ + 234, + 246 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 14 + } + } + }, + "optional": false, + "range": [ + 234, + 253 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 21 + } + } + }, + "range": [ + 233, + 254 + ], + "loc": { + "start": { + "line": 13, + "column": 1 + }, + "end": { + "line": 13, + "column": 22 + } + } + }, + { + "type": "SvelteText", + "value": " = ", + "range": [ + 254, + 257 + ], + "loc": { + "start": { + "line": 13, + "column": 22 + }, + "end": { + "line": 13, + "column": 25 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "total", + "range": [ + 258, + 263 + ], + "loc": { + "start": { + "line": 13, + "column": 26 + }, + "end": { + "line": 13, + "column": 31 + } + } + }, + "range": [ + 257, + 264 + ], + "loc": { + "start": { + "line": 13, + "column": 25 + }, + "end": { + "line": 13, + "column": 32 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 264, + 265 + ], + "loc": { + "start": { + "line": 13, + "column": 32 + }, + "end": { + "line": 14, + "column": 0 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 265, + 274 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 9 + } + } + }, + "range": [ + 173, + 274 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 14, + "column": 9 + } + } + } + ], + "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": "let", + "range": [ + 10, + 13 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + { + "type": "Identifier", + "value": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 22, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "$state", + "range": [ + 24, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "[", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "Numeric", + "value": "1", + "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": "Numeric", + "value": "2", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + { + "type": "Numeric", + "value": "3", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "]", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 40, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + { + "type": "Keyword", + "value": "let", + "range": [ + 44, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + { + "type": "Identifier", + "value": "total", + "range": [ + 48, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + { + "type": "Identifier", + "value": "$derived", + "range": [ + 56, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "by", + "range": [ + 65, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 22 + }, + "end": { + "line": 3, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 3, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 71, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 32 + } + } + }, + { + "type": "Keyword", + "value": "let", + "range": [ + 78, + 81 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 13 + } + } + }, + { + "type": "Numeric", + "value": "0", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + { + "type": "Keyword", + "value": "for", + "range": [ + 95, + 98 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 100, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + { + "type": "Identifier", + "value": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "of", + "range": [ + 108, + 110 + ], + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "numbers", + "range": [ + 111, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 5, + "column": 28 + } + } + }, + { + "type": "Identifier", + "value": "total", + "range": [ + 125, + 130 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "+=", + "range": [ + 131, + 133 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "n", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "return", + "range": [ + 143, + 149 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "total", + "range": [ + 150, + 155 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 155, + 156 + ], + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 158, + 159 + ], + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 159, + 160 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 160, + 161 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 162, + 163 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 163, + 164 + ], + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 164, + 170 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 170, + 171 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 171, + 173 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 12, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 173, + 174 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 174, + 180 + ], + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "on", + "range": [ + 181, + 183 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 183, + 184 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "click", + "range": [ + 184, + 189 + ], + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 189, + 190 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 12, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 190, + 191 + ], + "loc": { + "start": { + "line": 12, + "column": 17 + }, + "end": { + "line": 12, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 191, + 192 + ], + "loc": { + "start": { + "line": 12, + "column": 18 + }, + "end": { + "line": 12, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 192, + 193 + ], + "loc": { + "start": { + "line": 12, + "column": 19 + }, + "end": { + "line": 12, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 194, + 196 + ], + "loc": { + "start": { + "line": 12, + "column": 21 + }, + "end": { + "line": 12, + "column": 23 + } + } + }, + { + "type": "Identifier", + "value": "numbers", + "range": [ + 197, + 204 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 204, + 205 + ], + "loc": { + "start": { + "line": 12, + "column": 31 + }, + "end": { + "line": 12, + "column": 32 + } + } + }, + { + "type": "Identifier", + "value": "push", + "range": [ + 205, + 209 + ], + "loc": { + "start": { + "line": 12, + "column": 32 + }, + "end": { + "line": 12, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 209, + 210 + ], + "loc": { + "start": { + "line": 12, + "column": 36 + }, + "end": { + "line": 12, + "column": 37 + } + } + }, + { + "type": "Identifier", + "value": "numbers", + "range": [ + 210, + 217 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 44 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 217, + 218 + ], + "loc": { + "start": { + "line": 12, + "column": 44 + }, + "end": { + "line": 12, + "column": 45 + } + } + }, + { + "type": "Identifier", + "value": "length", + "range": [ + 218, + 224 + ], + "loc": { + "start": { + "line": 12, + "column": 45 + }, + "end": { + "line": 12, + "column": 51 + } + } + }, + { + "type": "Punctuator", + "value": "+", + "range": [ + 225, + 226 + ], + "loc": { + "start": { + "line": 12, + "column": 52 + }, + "end": { + "line": 12, + "column": 53 + } + } + }, + { + "type": "Numeric", + "value": "1", + "range": [ + 227, + 228 + ], + "loc": { + "start": { + "line": 12, + "column": 54 + }, + "end": { + "line": 12, + "column": 55 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 228, + 229 + ], + "loc": { + "start": { + "line": 12, + "column": 55 + }, + "end": { + "line": 12, + "column": 56 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 229, + 230 + ], + "loc": { + "start": { + "line": 12, + "column": 56 + }, + "end": { + "line": 12, + "column": 57 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 230, + 231 + ], + "loc": { + "start": { + "line": 12, + "column": 57 + }, + "end": { + "line": 12, + "column": 58 + } + } + }, + { + "type": "HTMLText", + "value": "\n\t", + "range": [ + 231, + 233 + ], + "loc": { + "start": { + "line": 12, + "column": 58 + }, + "end": { + "line": 13, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 233, + 234 + ], + "loc": { + "start": { + "line": 13, + "column": 1 + }, + "end": { + "line": 13, + "column": 2 + } + } + }, + { + "type": "Identifier", + "value": "numbers", + "range": [ + 234, + 241 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 241, + 242 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "join", + "range": [ + 242, + 246 + ], + "loc": { + "start": { + "line": 13, + "column": 10 + }, + "end": { + "line": 13, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 246, + 247 + ], + "loc": { + "start": { + "line": 13, + "column": 14 + }, + "end": { + "line": 13, + "column": 15 + } + } + }, + { + "type": "String", + "value": "' + '", + "range": [ + 247, + 252 + ], + "loc": { + "start": { + "line": 13, + "column": 15 + }, + "end": { + "line": 13, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 252, + 253 + ], + "loc": { + "start": { + "line": 13, + "column": 20 + }, + "end": { + "line": 13, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 253, + 254 + ], + "loc": { + "start": { + "line": 13, + "column": 21 + }, + "end": { + "line": 13, + "column": 22 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 254, + 255 + ], + "loc": { + "start": { + "line": 13, + "column": 22 + }, + "end": { + "line": 13, + "column": 23 + } + } + }, + { + "type": "HTMLText", + "value": "=", + "range": [ + 255, + 256 + ], + "loc": { + "start": { + "line": 13, + "column": 23 + }, + "end": { + "line": 13, + "column": 24 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 256, + 257 + ], + "loc": { + "start": { + "line": 13, + "column": 24 + }, + "end": { + "line": 13, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 257, + 258 + ], + "loc": { + "start": { + "line": 13, + "column": 25 + }, + "end": { + "line": 13, + "column": 26 + } + } + }, + { + "type": "Identifier", + "value": "total", + "range": [ + 258, + 263 + ], + "loc": { + "start": { + "line": 13, + "column": 26 + }, + "end": { + "line": 13, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 263, + 264 + ], + "loc": { + "start": { + "line": 13, + "column": 31 + }, + "end": { + "line": 13, + "column": 32 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 264, + 265 + ], + "loc": { + "start": { + "line": 13, + "column": 32 + }, + "end": { + "line": 14, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 265, + 266 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 266, + 267 + ], + "loc": { + "start": { + "line": 14, + "column": 1 + }, + "end": { + "line": 14, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 267, + 273 + ], + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 273, + 274 + ], + "loc": { + "start": { + "line": 14, + "column": 8 + }, + "end": { + "line": 14, + "column": 9 + } + } + } + ], + "range": [ + 0, + 275 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 15, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/docs/runes/02-2-$derived-by-prefer-const-result.json b/tests/fixtures/parser/ast/svelte5/docs/runes/02-2-$derived-by-prefer-const-result.json new file mode 100644 index 00000000..90791a09 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/docs/runes/02-2-$derived-by-prefer-const-result.json @@ -0,0 +1,14 @@ +[ + { + "ruleId": "prefer-const", + "code": "numbers", + "line": 2, + "column": 6 + }, + { + "ruleId": "prefer-const", + "code": "total", + "line": 3, + "column": 6 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/docs/runes/02-2-$derived-by-scope-output.json b/tests/fixtures/parser/ast/svelte5/docs/runes/02-2-$derived-by-scope-output.json new file mode 100644 index 00000000..75ed1aa4 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/docs/runes/02-2-$derived-by-scope-output.json @@ -0,0 +1,2361 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "$state", + "range": [ + 24, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 56, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$inspect", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "numbers", + "identifiers": [ + { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [ + { + "type": "ArrayExpression", + "elements": [ + { + "type": "Literal", + "raw": "1", + "value": 1, + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + { + "type": "Literal", + "raw": "2", + "value": 2, + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 27 + } + } + }, + { + "type": "Literal", + "raw": "3", + "value": 3, + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + } + } + ], + "range": [ + 31, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 31 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "$state", + "range": [ + 24, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "optional": false, + "range": [ + 24, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + "range": [ + 14, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 32 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 111, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "from": "for", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 197, + 204 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 31 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 210, + 217 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 44 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 234, + 241 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 9 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + } + ] + }, + { + "name": "total", + "identifiers": [ + { + "type": "Identifier", + "name": "total", + "range": [ + 48, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "total", + "range": [ + 48, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "total", + "range": [ + 48, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [ + { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "init": { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + "range": [ + 82, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 15 + } + } + } + ], + "range": [ + 78, + 92 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + { + "type": "ForOfStatement", + "await": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "left": { + "type": "Identifier", + "name": "total", + "range": [ + 125, + 130 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "operator": "+=", + "right": { + "type": "Identifier", + "name": "n", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "range": [ + 125, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "range": [ + 125, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 14 + } + } + } + ], + "range": [ + 120, + 140 + ], + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + "left": { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "init": null, + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + ], + "range": [ + 100, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "right": { + "type": "Identifier", + "name": "numbers", + "range": [ + 111, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 95, + 140 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "total", + "range": [ + 150, + 155 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "range": [ + 143, + 156 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 15 + } + } + } + ], + "range": [ + 74, + 159 + ], + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [], + "range": [ + 68, + 159 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 9, + "column": 2 + } + } + } + ], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "$derived", + "range": [ + 56, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "by", + "range": [ + 65, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 22 + }, + "end": { + "line": 3, + "column": 24 + } + } + }, + "range": [ + 56, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 24 + } + } + }, + "optional": false, + "range": [ + 56, + 160 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + "range": [ + 48, + 160 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 9, + "column": 3 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 48, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 48, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 258, + 263 + ], + "loc": { + "start": { + "line": 13, + "column": 26 + }, + "end": { + "line": 13, + "column": 31 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 48, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "$state", + "range": [ + 24, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 48, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 48, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 56, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 234, + 241 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 9 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 258, + 263 + ], + "loc": { + "start": { + "line": 13, + "column": 26 + }, + "end": { + "line": 13, + "column": 31 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 48, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "total", + "identifiers": [ + { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "init": { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + "range": [ + 82, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 15 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "from": "function", + "init": true, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 125, + 130 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "from": "block", + "init": false, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 150, + 155 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "from": "function", + "init": true, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 150, + 155 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + } + ], + "childScopes": [ + { + "type": "for", + "variables": [ + { + "name": "n", + "identifiers": [ + { + "type": "Identifier", + "name": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "init": null, + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "from": "for", + "init": true, + "resolved": { + "type": "Identifier", + "name": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "n", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "from": "block", + "init": null, + "resolved": { + "type": "Identifier", + "name": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "from": "for", + "init": true, + "resolved": { + "type": "Identifier", + "name": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 111, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "from": "for", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + } + ], + "childScopes": [ + { + "type": "block", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 125, + 130 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "from": "block", + "init": false, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "n", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "from": "block", + "init": null, + "resolved": { + "type": "Identifier", + "name": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 125, + 130 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "from": "block", + "init": false, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "n", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "from": "block", + "init": null, + "resolved": { + "type": "Identifier", + "name": "n", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 111, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "from": "for", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 125, + 130 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "from": "block", + "init": false, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 111, + 118 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "from": "for", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + } + ] + }, + { + "type": "function", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 197, + 204 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 31 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 210, + 217 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 44 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 197, + 204 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 31 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 210, + 217 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 44 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "$state", + "range": [ + 24, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 56, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-input.svelte b/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-input.svelte new file mode 100644 index 00000000..c061fb66 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-input.svelte @@ -0,0 +1,14 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-output.json b/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-output.json new file mode 100644 index 00000000..941ab0a4 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-output.json @@ -0,0 +1,3194 @@ +{ + "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": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteLiteral", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ], + "range": [ + 8, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 17 + } + } + } + ], + "selfClosing": false, + "range": [ + 0, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [ + { + "type": "ArrayExpression", + "elements": [ + { + "type": "Literal", + "raw": "1", + "value": 1, + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + { + "type": "Literal", + "raw": "2", + "value": 2, + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + } + } + }, + { + "type": "Literal", + "raw": "3", + "value": 3, + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 32 + } + } + } + ], + "range": [ + 43, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 33 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "$state", + "range": [ + 36, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "optional": false, + "range": [ + 36, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 34 + } + } + }, + "range": [ + 26, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 34 + } + } + } + ], + "range": [ + 20, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 35 + } + } + }, + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "total", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [ + { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "init": { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + "range": [ + 96, + 105 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 15 + } + } + } + ], + "range": [ + 92, + 106 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + { + "type": "ForOfStatement", + "await": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "left": { + "type": "Identifier", + "name": "total", + "range": [ + 139, + 144 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "operator": "+=", + "right": { + "type": "Identifier", + "name": "n", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "range": [ + 139, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "range": [ + 139, + 150 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 14 + } + } + } + ], + "range": [ + 134, + 154 + ], + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + "left": { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "init": null, + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + ], + "range": [ + 114, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "right": { + "type": "Identifier", + "name": "numbers", + "range": [ + 125, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 109, + 154 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "total", + "range": [ + 164, + 169 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "range": [ + 157, + 170 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 15 + } + } + } + ], + "range": [ + 88, + 173 + ], + "loc": { + "start": { + "line": 3, + "column": 33 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [], + "range": [ + 82, + 173 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 9, + "column": 2 + } + } + } + ], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "$derived", + "range": [ + 70, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "by", + "range": [ + 79, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 26 + } + } + }, + "range": [ + 70, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 26 + } + } + }, + "optional": false, + "range": [ + 70, + 174 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + "range": [ + 62, + 174 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 9, + "column": 3 + } + } + } + ], + "range": [ + 56, + 175 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 9, + "column": 4 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 176, + 185 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + "range": [ + 0, + 185 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 185, + 187 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 12, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "button", + "range": [ + 188, + 194 + ], + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "EventHandler", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "click", + "range": [ + 198, + 203 + ], + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + "modifiers": [], + "range": [ + 195, + 203 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "CallExpression", + "arguments": [ + { + "type": "BinaryExpression", + "left": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "numbers", + "range": [ + 224, + 231 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 44 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "length", + "range": [ + 232, + 238 + ], + "loc": { + "start": { + "line": 12, + "column": 45 + }, + "end": { + "line": 12, + "column": 51 + } + } + }, + "range": [ + 224, + 238 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 51 + } + } + }, + "operator": "+", + "right": { + "type": "Literal", + "raw": "1", + "value": 1, + "range": [ + 241, + 242 + ], + "loc": { + "start": { + "line": 12, + "column": 54 + }, + "end": { + "line": 12, + "column": 55 + } + } + }, + "range": [ + 224, + 242 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 55 + } + } + } + ], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "numbers", + "range": [ + 211, + 218 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 31 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "push", + "range": [ + 219, + 223 + ], + "loc": { + "start": { + "line": 12, + "column": 32 + }, + "end": { + "line": 12, + "column": 36 + } + } + }, + "range": [ + 211, + 223 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 36 + } + } + }, + "optional": false, + "range": [ + 211, + 243 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 56 + } + } + }, + "expression": true, + "generator": false, + "id": null, + "params": [], + "range": [ + 205, + 243 + ], + "loc": { + "start": { + "line": 12, + "column": 18 + }, + "end": { + "line": 12, + "column": 56 + } + } + }, + "range": [ + 195, + 244 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 57 + } + } + } + ], + "selfClosing": false, + "range": [ + 187, + 245 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 58 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "\n\t", + "range": [ + 245, + 247 + ], + "loc": { + "start": { + "line": 12, + "column": 58 + }, + "end": { + "line": 13, + "column": 1 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "CallExpression", + "arguments": [ + { + "type": "Literal", + "raw": "' + '", + "value": " + ", + "range": [ + 261, + 266 + ], + "loc": { + "start": { + "line": 13, + "column": 15 + }, + "end": { + "line": 13, + "column": 20 + } + } + } + ], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "numbers", + "range": [ + 248, + 255 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 9 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "join", + "range": [ + 256, + 260 + ], + "loc": { + "start": { + "line": 13, + "column": 10 + }, + "end": { + "line": 13, + "column": 14 + } + } + }, + "range": [ + 248, + 260 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 14 + } + } + }, + "optional": false, + "range": [ + 248, + 267 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 21 + } + } + }, + "range": [ + 247, + 268 + ], + "loc": { + "start": { + "line": 13, + "column": 1 + }, + "end": { + "line": 13, + "column": 22 + } + } + }, + { + "type": "SvelteText", + "value": " = ", + "range": [ + 268, + 271 + ], + "loc": { + "start": { + "line": 13, + "column": 22 + }, + "end": { + "line": 13, + "column": 25 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "total", + "range": [ + 272, + 277 + ], + "loc": { + "start": { + "line": 13, + "column": 26 + }, + "end": { + "line": 13, + "column": 31 + } + } + }, + "range": [ + 271, + 278 + ], + "loc": { + "start": { + "line": 13, + "column": 25 + }, + "end": { + "line": 13, + "column": 32 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 278, + 279 + ], + "loc": { + "start": { + "line": 13, + "column": 32 + }, + "end": { + "line": 14, + "column": 0 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 279, + 288 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 9 + } + } + }, + "range": [ + 187, + 288 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 14, + "column": 9 + } + } + } + ], + "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": "HTMLIdentifier", + "value": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "HTMLText", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Identifier", + "value": "$state", + "range": [ + 36, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "[", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "Numeric", + "value": "1", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 27 + } + } + }, + { + "type": "Numeric", + "value": "2", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + { + "type": "Numeric", + "value": "3", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": "]", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 35 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "total", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "$derived", + "range": [ + 70, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 78, + 79 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + } + } + }, + { + "type": "Identifier", + "value": "by", + "range": [ + 79, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 85, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 30 + }, + "end": { + "line": 3, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 33 + }, + "end": { + "line": 3, + "column": 34 + } + } + }, + { + "type": "Keyword", + "value": "let", + "range": [ + 92, + 95 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 13 + } + } + }, + { + "type": "Numeric", + "value": "0", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + { + "type": "Keyword", + "value": "for", + "range": [ + 109, + 112 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 113, + 114 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 114, + 119 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + { + "type": "Identifier", + "value": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "of", + "range": [ + 122, + 124 + ], + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "numbers", + "range": [ + 125, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 5, + "column": 28 + } + } + }, + { + "type": "Identifier", + "value": "total", + "range": [ + 139, + 144 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "+=", + "range": [ + 145, + 147 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "n", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 153, + 154 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "return", + "range": [ + 157, + 163 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "total", + "range": [ + 164, + 169 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 169, + 170 + ], + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 173, + 174 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 174, + 175 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 178, + 184 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 184, + 185 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 185, + 187 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 12, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 187, + 188 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 188, + 194 + ], + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "on", + "range": [ + 195, + 197 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 197, + 198 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "click", + "range": [ + 198, + 203 + ], + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 203, + 204 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 12, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 204, + 205 + ], + "loc": { + "start": { + "line": 12, + "column": 17 + }, + "end": { + "line": 12, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 205, + 206 + ], + "loc": { + "start": { + "line": 12, + "column": 18 + }, + "end": { + "line": 12, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 206, + 207 + ], + "loc": { + "start": { + "line": 12, + "column": 19 + }, + "end": { + "line": 12, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 208, + 210 + ], + "loc": { + "start": { + "line": 12, + "column": 21 + }, + "end": { + "line": 12, + "column": 23 + } + } + }, + { + "type": "Identifier", + "value": "numbers", + "range": [ + 211, + 218 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 218, + 219 + ], + "loc": { + "start": { + "line": 12, + "column": 31 + }, + "end": { + "line": 12, + "column": 32 + } + } + }, + { + "type": "Identifier", + "value": "push", + "range": [ + 219, + 223 + ], + "loc": { + "start": { + "line": 12, + "column": 32 + }, + "end": { + "line": 12, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 223, + 224 + ], + "loc": { + "start": { + "line": 12, + "column": 36 + }, + "end": { + "line": 12, + "column": 37 + } + } + }, + { + "type": "Identifier", + "value": "numbers", + "range": [ + 224, + 231 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 44 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 231, + 232 + ], + "loc": { + "start": { + "line": 12, + "column": 44 + }, + "end": { + "line": 12, + "column": 45 + } + } + }, + { + "type": "Identifier", + "value": "length", + "range": [ + 232, + 238 + ], + "loc": { + "start": { + "line": 12, + "column": 45 + }, + "end": { + "line": 12, + "column": 51 + } + } + }, + { + "type": "Punctuator", + "value": "+", + "range": [ + 239, + 240 + ], + "loc": { + "start": { + "line": 12, + "column": 52 + }, + "end": { + "line": 12, + "column": 53 + } + } + }, + { + "type": "Identifier", + "value": "1", + "range": [ + 241, + 242 + ], + "loc": { + "start": { + "line": 12, + "column": 54 + }, + "end": { + "line": 12, + "column": 55 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 242, + 243 + ], + "loc": { + "start": { + "line": 12, + "column": 55 + }, + "end": { + "line": 12, + "column": 56 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 243, + 244 + ], + "loc": { + "start": { + "line": 12, + "column": 56 + }, + "end": { + "line": 12, + "column": 57 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 244, + 245 + ], + "loc": { + "start": { + "line": 12, + "column": 57 + }, + "end": { + "line": 12, + "column": 58 + } + } + }, + { + "type": "HTMLText", + "value": "\n\t", + "range": [ + 245, + 247 + ], + "loc": { + "start": { + "line": 12, + "column": 58 + }, + "end": { + "line": 13, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 247, + 248 + ], + "loc": { + "start": { + "line": 13, + "column": 1 + }, + "end": { + "line": 13, + "column": 2 + } + } + }, + { + "type": "Identifier", + "value": "numbers", + "range": [ + 248, + 255 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 255, + 256 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "join", + "range": [ + 256, + 260 + ], + "loc": { + "start": { + "line": 13, + "column": 10 + }, + "end": { + "line": 13, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 260, + 261 + ], + "loc": { + "start": { + "line": 13, + "column": 14 + }, + "end": { + "line": 13, + "column": 15 + } + } + }, + { + "type": "String", + "value": "' + '", + "range": [ + 261, + 266 + ], + "loc": { + "start": { + "line": 13, + "column": 15 + }, + "end": { + "line": 13, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 266, + 267 + ], + "loc": { + "start": { + "line": 13, + "column": 20 + }, + "end": { + "line": 13, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 267, + 268 + ], + "loc": { + "start": { + "line": 13, + "column": 21 + }, + "end": { + "line": 13, + "column": 22 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 268, + 269 + ], + "loc": { + "start": { + "line": 13, + "column": 22 + }, + "end": { + "line": 13, + "column": 23 + } + } + }, + { + "type": "HTMLText", + "value": "=", + "range": [ + 269, + 270 + ], + "loc": { + "start": { + "line": 13, + "column": 23 + }, + "end": { + "line": 13, + "column": 24 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 270, + 271 + ], + "loc": { + "start": { + "line": 13, + "column": 24 + }, + "end": { + "line": 13, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 271, + 272 + ], + "loc": { + "start": { + "line": 13, + "column": 25 + }, + "end": { + "line": 13, + "column": 26 + } + } + }, + { + "type": "Identifier", + "value": "total", + "range": [ + 272, + 277 + ], + "loc": { + "start": { + "line": 13, + "column": 26 + }, + "end": { + "line": 13, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 277, + 278 + ], + "loc": { + "start": { + "line": 13, + "column": 31 + }, + "end": { + "line": 13, + "column": 32 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 278, + 279 + ], + "loc": { + "start": { + "line": 13, + "column": 32 + }, + "end": { + "line": 14, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 279, + 280 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 280, + 281 + ], + "loc": { + "start": { + "line": 14, + "column": 1 + }, + "end": { + "line": 14, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 281, + 287 + ], + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 287, + 288 + ], + "loc": { + "start": { + "line": 14, + "column": 8 + }, + "end": { + "line": 14, + "column": 9 + } + } + } + ], + "range": [ + 0, + 289 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 15, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-scope-output.json b/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-scope-output.json new file mode 100644 index 00000000..536e0848 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-scope-output.json @@ -0,0 +1,2361 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "$state", + "range": [ + 36, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 70, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$inspect", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "numbers", + "identifiers": [ + { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [ + { + "type": "ArrayExpression", + "elements": [ + { + "type": "Literal", + "raw": "1", + "value": 1, + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + { + "type": "Literal", + "raw": "2", + "value": 2, + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + } + } + }, + { + "type": "Literal", + "raw": "3", + "value": 3, + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 32 + } + } + } + ], + "range": [ + 43, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 33 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "$state", + "range": [ + 36, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "optional": false, + "range": [ + 36, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 34 + } + } + }, + "range": [ + 26, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 34 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 125, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "from": "for", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 211, + 218 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 31 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 224, + 231 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 44 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 248, + 255 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 9 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + } + ] + }, + { + "name": "total", + "identifiers": [ + { + "type": "Identifier", + "name": "total", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "total", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "total", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [ + { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "init": { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + "range": [ + 96, + 105 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 15 + } + } + } + ], + "range": [ + 92, + 106 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + { + "type": "ForOfStatement", + "await": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "left": { + "type": "Identifier", + "name": "total", + "range": [ + 139, + 144 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "operator": "+=", + "right": { + "type": "Identifier", + "name": "n", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "range": [ + 139, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "range": [ + 139, + 150 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 14 + } + } + } + ], + "range": [ + 134, + 154 + ], + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + "left": { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "init": null, + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + ], + "range": [ + 114, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "right": { + "type": "Identifier", + "name": "numbers", + "range": [ + 125, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 109, + 154 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "total", + "range": [ + 164, + 169 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "range": [ + 157, + 170 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 15 + } + } + } + ], + "range": [ + 88, + 173 + ], + "loc": { + "start": { + "line": 3, + "column": 33 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [], + "range": [ + 82, + 173 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 9, + "column": 2 + } + } + } + ], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "$derived", + "range": [ + 70, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "by", + "range": [ + 79, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 26 + } + } + }, + "range": [ + 70, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 26 + } + } + }, + "optional": false, + "range": [ + 70, + 174 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + "range": [ + 62, + 174 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 9, + "column": 3 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 272, + 277 + ], + "loc": { + "start": { + "line": 13, + "column": 26 + }, + "end": { + "line": 13, + "column": 31 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "$state", + "range": [ + 36, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 70, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 248, + 255 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 9 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 272, + 277 + ], + "loc": { + "start": { + "line": 13, + "column": 26 + }, + "end": { + "line": 13, + "column": 31 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 62, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "total", + "identifiers": [ + { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "init": { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + "range": [ + 96, + 105 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 15 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "from": "function", + "init": true, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 139, + 144 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "from": "block", + "init": false, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 164, + 169 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "from": "function", + "init": true, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 164, + 169 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + } + ], + "childScopes": [ + { + "type": "for", + "variables": [ + { + "name": "n", + "identifiers": [ + { + "type": "Identifier", + "name": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "init": null, + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "from": "for", + "init": true, + "resolved": { + "type": "Identifier", + "name": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "n", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "from": "block", + "init": null, + "resolved": { + "type": "Identifier", + "name": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "from": "for", + "init": true, + "resolved": { + "type": "Identifier", + "name": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 125, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "from": "for", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + } + ], + "childScopes": [ + { + "type": "block", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 139, + 144 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "from": "block", + "init": false, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "n", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "from": "block", + "init": null, + "resolved": { + "type": "Identifier", + "name": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 139, + 144 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "from": "block", + "init": false, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "n", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "from": "block", + "init": null, + "resolved": { + "type": "Identifier", + "name": "n", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + } + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 125, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "from": "for", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "total", + "range": [ + 139, + 144 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "from": "block", + "init": false, + "resolved": { + "type": "Identifier", + "name": "total", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 11 + } + } + } + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 125, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "from": "for", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + } + ] + }, + { + "type": "function", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 211, + 218 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 31 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 224, + 231 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 44 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 211, + 218 + ], + "loc": { + "start": { + "line": 12, + "column": 24 + }, + "end": { + "line": 12, + "column": 31 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "numbers", + "range": [ + 224, + 231 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 44 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "numbers", + "range": [ + 26, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "$state", + "range": [ + 36, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "$derived", + "range": [ + 70, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-type-output.svelte new file mode 100644 index 00000000..53769941 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-$derived-by01-type-output.svelte @@ -0,0 +1,14 @@ + + +