From b63c3050f4f33b16ebc5902d98556efc4c58cf4c Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Wed, 4 Oct 2023 08:21:54 +0900 Subject: [PATCH] fix: infinite loop in attr.ts (#409) * fix: infinite loop * Create weak-lizards-listen.md * fix --- .changeset/weak-lizards-listen.md | 5 + src/parser/converts/attr.ts | 10 +- .../parser/ast/let-directive04-input.svelte | 12 + .../parser/ast/let-directive04-output.json | 1844 +++++++++++++++++ .../ast/let-directive04-scope-output.json | 815 ++++++++ 5 files changed, 2684 insertions(+), 2 deletions(-) create mode 100644 .changeset/weak-lizards-listen.md create mode 100644 tests/fixtures/parser/ast/let-directive04-input.svelte create mode 100644 tests/fixtures/parser/ast/let-directive04-output.json create mode 100644 tests/fixtures/parser/ast/let-directive04-scope-output.json diff --git a/.changeset/weak-lizards-listen.md b/.changeset/weak-lizards-listen.md new file mode 100644 index 00000000..3ffd10f2 --- /dev/null +++ b/.changeset/weak-lizards-listen.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": patch +--- + +fix: infinite loop in attr.ts diff --git a/src/parser/converts/attr.ts b/src/parser/converts/attr.ts index 0e5eebf7..19d16af1 100644 --- a/src/parser/converts/attr.ts +++ b/src/parser/converts/attr.ts @@ -18,6 +18,8 @@ import type { SvelteElement, SvelteScriptElement, SvelteStyleElement, + SvelteElseBlock, + SvelteAwaitBlock, } from "../../ast"; import type ESTree from "estree"; import type { Context } from "../../context"; @@ -678,9 +680,13 @@ function buildLetDirectiveType( /** Find parent component element */ function findParentComponent(node: SvelteElement) { - let parent: SvelteElement["parent"] | null = node.parent; + let parent: + | SvelteElement["parent"] + | SvelteElseBlock + | SvelteAwaitBlock + | null = node.parent; while (parent && parent.type !== "SvelteElement") { - parent = node.parent; + parent = parent.parent; } if (!parent || parent.kind !== "component") { return null; diff --git a/tests/fixtures/parser/ast/let-directive04-input.svelte b/tests/fixtures/parser/ast/let-directive04-input.svelte new file mode 100644 index 00000000..ffb1683e --- /dev/null +++ b/tests/fixtures/parser/ast/let-directive04-input.svelte @@ -0,0 +1,12 @@ + + + +
+ {#if !collapsed} + + + + {/if} +
diff --git a/tests/fixtures/parser/ast/let-directive04-output.json b/tests/fixtures/parser/ast/let-directive04-output.json new file mode 100644 index 00000000..952c0104 --- /dev/null +++ b/tests/fixtures/parser/ast/let-directive04-output.json @@ -0,0 +1,1844 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteHTMLComment", + "value": " Copied from https://github.com/sveltejs/svelte-eslint-parser/issues/408", + "range": [ + 0, + 79 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 79 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 1, + "column": 79 + }, + "end": { + "line": 2, + "column": 0 + } + } + }, + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 81, + 87 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "lang", + "range": [ + 88, + 92 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteLiteral", + "value": "ts", + "range": [ + 94, + 96 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + ], + "range": [ + 88, + 97 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 17 + } + } + } + ], + "selfClosing": false, + "range": [ + 80, + 98 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "body": [ + { + "type": "ExportNamedDeclaration", + "declaration": { + "type": "VariableDeclaration", + "kind": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + "init": { + "type": "Literal", + "raw": "false", + "value": false, + "range": [ + 122, + 127 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + "range": [ + 110, + 127 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 28 + } + } + } + ], + "range": [ + 106, + 128 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 29 + } + } + }, + "exportKind": "value", + "source": null, + "specifiers": [], + "range": [ + 99, + 128 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 29 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 129, + 138 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + "range": [ + 80, + 138 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 138, + 140 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 141, + 144 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 140, + 145 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "\n ", + "range": [ + 145, + 150 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 7, + "column": 4 + } + } + }, + { + "type": "SvelteIfBlock", + "elseif": false, + "expression": { + "type": "UnaryExpression", + "argument": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 156, + 165 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 19 + } + } + }, + "operator": "!", + "prefix": true, + "range": [ + 155, + 165 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 19 + } + } + }, + "children": [ + { + "type": "SvelteElement", + "kind": "special", + "name": { + "type": "SvelteName", + "name": "svelte:self", + "range": [ + 176, + 187 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 20 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "collapsed", + "range": [ + 188, + 197 + ], + "loc": { + "start": { + "line": 8, + "column": 21 + }, + "end": { + "line": 8, + "column": 30 + } + } + }, + "boolean": true, + "value": [], + "range": [ + 188, + 197 + ], + "loc": { + "start": { + "line": 8, + "column": 21 + }, + "end": { + "line": 8, + "column": 30 + } + } + }, + { + "type": "SvelteDirective", + "kind": "Let", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "something", + "range": [ + 202, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 35 + }, + "end": { + "line": 8, + "column": 44 + } + } + }, + "modifiers": [], + "range": [ + 198, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 31 + }, + "end": { + "line": 8, + "column": 44 + } + } + }, + "expression": { + "type": "Identifier", + "name": "something", + "range": [ + 202, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 35 + }, + "end": { + "line": 8, + "column": 44 + } + } + }, + "range": [ + 198, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 31 + }, + "end": { + "line": 8, + "column": 44 + } + } + } + ], + "selfClosing": false, + "range": [ + 175, + 212 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 45 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "\n ", + "range": [ + 212, + 225 + ], + "loc": { + "start": { + "line": 8, + "column": 45 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "slot", + "range": [ + 226, + 230 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 17 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteShorthandAttribute", + "key": { + "type": "Identifier", + "name": "something", + "range": [ + 232, + 241 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 28 + } + } + }, + "value": { + "type": "Identifier", + "name": "something", + "range": [ + 232, + 241 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 28 + } + } + }, + "range": [ + 231, + 242 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 29 + } + } + } + ], + "selfClosing": true, + "range": [ + 225, + 245 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 32 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 225, + 245 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 32 + } + } + }, + { + "type": "SvelteText", + "value": "\n ", + "range": [ + 245, + 254 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 10, + "column": 8 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 254, + 268 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 22 + } + } + }, + "range": [ + 175, + 268 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 10, + "column": 22 + } + } + } + ], + "else": null, + "range": [ + 150, + 278 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 11, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 278, + 279 + ], + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 12, + "column": 0 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 279, + 285 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 6 + } + } + }, + "range": [ + 140, + 285 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 12, + "column": 6 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "HTMLComment", + "value": "", + "range": [ + 0, + 79 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 79 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 1, + "column": 79 + }, + "end": { + "line": 2, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 80, + 81 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 81, + 87 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "lang", + "range": [ + 88, + 92 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 93, + 94 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "HTMLText", + "value": "ts", + "range": [ + 94, + 96 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 96, + 97 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + { + "type": "Keyword", + "value": "export", + "range": [ + 99, + 105 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + { + "type": "Keyword", + "value": "let", + "range": [ + 106, + 109 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 22 + } + } + }, + { + "type": "Boolean", + "value": "false", + "range": [ + 122, + 127 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 127, + 128 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 130, + 131 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 131, + 137 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 137, + 138 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 138, + 140 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 141, + 144 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + { + "type": "HTMLText", + "value": "\n ", + "range": [ + 145, + 150 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 7, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 150, + 151 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + } + }, + { + "type": "MustacheKeyword", + "value": "#if", + "range": [ + 151, + 154 + ], + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "!", + "range": [ + 155, + 156 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "collapsed", + "range": [ + 156, + 165 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "svelte:self", + "range": [ + 176, + 187 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 20 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "collapsed", + "range": [ + 188, + 197 + ], + "loc": { + "start": { + "line": 8, + "column": 21 + }, + "end": { + "line": 8, + "column": 30 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "let", + "range": [ + 198, + 201 + ], + "loc": { + "start": { + "line": 8, + "column": 31 + }, + "end": { + "line": 8, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 201, + 202 + ], + "loc": { + "start": { + "line": 8, + "column": 34 + }, + "end": { + "line": 8, + "column": 35 + } + } + }, + { + "type": "Identifier", + "value": "something", + "range": [ + 202, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 35 + }, + "end": { + "line": 8, + "column": 44 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 211, + 212 + ], + "loc": { + "start": { + "line": 8, + "column": 44 + }, + "end": { + "line": 8, + "column": 45 + } + } + }, + { + "type": "HTMLText", + "value": "\n ", + "range": [ + 212, + 225 + ], + "loc": { + "start": { + "line": 8, + "column": 45 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 225, + 226 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "slot", + "range": [ + 226, + 230 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 231, + 232 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 19 + } + } + }, + { + "type": "Identifier", + "value": "something", + "range": [ + 232, + 241 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 241, + 242 + ], + "loc": { + "start": { + "line": 9, + "column": 28 + }, + "end": { + "line": 9, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 243, + 244 + ], + "loc": { + "start": { + "line": 9, + "column": 30 + }, + "end": { + "line": 9, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 244, + 245 + ], + "loc": { + "start": { + "line": 9, + "column": 31 + }, + "end": { + "line": 9, + "column": 32 + } + } + }, + { + "type": "HTMLText", + "value": "\n ", + "range": [ + 245, + 254 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 10, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 254, + 255 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 255, + 256 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 10 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "svelte:self", + "range": [ + 256, + 267 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 267, + 268 + ], + "loc": { + "start": { + "line": 10, + "column": 21 + }, + "end": { + "line": 10, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 273, + 274 + ], + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + } + } + }, + { + "type": "MustacheKeyword", + "value": "/if", + "range": [ + 274, + 277 + ], + "loc": { + "start": { + "line": 11, + "column": 5 + }, + "end": { + "line": 11, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 277, + 278 + ], + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 11, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 278, + 279 + ], + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 12, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 279, + 280 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 280, + 281 + ], + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 281, + 284 + ], + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 284, + 285 + ], + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 12, + "column": 6 + } + } + } + ], + "range": [ + 0, + 286 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 13, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/let-directive04-scope-output.json b/tests/fixtures/parser/ast/let-directive04-scope-output.json new file mode 100644 index 00000000..c275de6d --- /dev/null +++ b/tests/fixtures/parser/ast/let-directive04-scope-output.json @@ -0,0 +1,815 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "collapsed", + "identifiers": [ + { + "type": "Identifier", + "name": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + "init": { + "type": "Literal", + "raw": "false", + "value": false, + "range": [ + 122, + 127 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + "range": [ + 110, + 127 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 28 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 156, + 165 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 19 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 156, + 165 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 19 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "collapsed", + "range": [ + 110, + 119 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 20 + } + } + } + } + ], + "childScopes": [ + { + "type": "block", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "something", + "identifiers": [ + { + "type": "Identifier", + "name": "something", + "range": [ + 202, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 35 + }, + "end": { + "line": 8, + "column": 44 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "something", + "range": [ + 202, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 35 + }, + "end": { + "line": 8, + "column": 44 + } + } + }, + "node": { + "type": "SvelteElement", + "kind": "special", + "name": { + "type": "SvelteName", + "name": "svelte:self", + "range": [ + 176, + 187 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 20 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "collapsed", + "range": [ + 188, + 197 + ], + "loc": { + "start": { + "line": 8, + "column": 21 + }, + "end": { + "line": 8, + "column": 30 + } + } + }, + "boolean": true, + "value": [], + "range": [ + 188, + 197 + ], + "loc": { + "start": { + "line": 8, + "column": 21 + }, + "end": { + "line": 8, + "column": 30 + } + } + }, + { + "type": "SvelteDirective", + "kind": "Let", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "something", + "range": [ + 202, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 35 + }, + "end": { + "line": 8, + "column": 44 + } + } + }, + "modifiers": [], + "range": [ + 198, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 31 + }, + "end": { + "line": 8, + "column": 44 + } + } + }, + "expression": { + "type": "Identifier", + "name": "something", + "range": [ + 202, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 35 + }, + "end": { + "line": 8, + "column": 44 + } + } + }, + "range": [ + 198, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 31 + }, + "end": { + "line": 8, + "column": 44 + } + } + } + ], + "selfClosing": false, + "range": [ + 175, + 212 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 45 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "\n ", + "range": [ + 212, + 225 + ], + "loc": { + "start": { + "line": 8, + "column": 45 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "slot", + "range": [ + 226, + 230 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 17 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteShorthandAttribute", + "key": { + "type": "Identifier", + "name": "something", + "range": [ + 232, + 241 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 28 + } + } + }, + "value": { + "type": "Identifier", + "name": "something", + "range": [ + 232, + 241 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 28 + } + } + }, + "range": [ + 231, + 242 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 29 + } + } + } + ], + "selfClosing": true, + "range": [ + 225, + 245 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 32 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 225, + 245 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 32 + } + } + }, + { + "type": "SvelteText", + "value": "\n ", + "range": [ + 245, + 254 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 10, + "column": 8 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 254, + 268 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 22 + } + } + }, + "range": [ + 175, + 268 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 10, + "column": 22 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "something", + "range": [ + 232, + 241 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 28 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "something", + "range": [ + 202, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 35 + }, + "end": { + "line": 8, + "column": 44 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "something", + "range": [ + 232, + 241 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 28 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "something", + "range": [ + 202, + 211 + ], + "loc": { + "start": { + "line": 8, + "column": 35 + }, + "end": { + "line": 8, + "column": 44 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file