From a69ee521e5a1f6f100388b4aeda1f1887b5f85d0 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Sun, 1 Dec 2024 11:11:06 +0900 Subject: [PATCH] chore: add tests for slot binding --- .../parser/ast/ts-slot-binding01-config.json | 3 + .../ast/ts-slot-binding01-input-child.svelte | 5 + .../parser/ast/ts-slot-binding01-input.svelte | 7 + .../parser/ast/ts-slot-binding01-output.json | 1403 +++++++++++++++++ .../ast/ts-slot-binding01-requirements.json | 8 + ...s-slot-binding01-scope-output-svelte5.json | 596 +++++++ .../ast/ts-slot-binding01-scope-output.json | 469 ++++++ ...slot-binding01-sveltev4-input-child.svelte | 5 + .../ts-slot-binding01-sveltev4-input.svelte | 7 + .../ts-slot-binding01-sveltev4-output.json | 1403 +++++++++++++++++ ...-slot-binding01-sveltev4-requirements.json | 8 + ...-slot-binding01-sveltev4-scope-output.json | 557 +++++++ ...slot-binding01-sveltev4-type-output.svelte | 7 + .../ast/ts-slot-binding01-type-output.svelte | 7 + 14 files changed, 4485 insertions(+) create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-config.json create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-input-child.svelte create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-input.svelte create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-output.json create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-requirements.json create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-scope-output-svelte5.json create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-scope-output.json create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-input-child.svelte create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-input.svelte create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-output.json create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-requirements.json create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-scope-output.json create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-type-output.svelte create mode 100644 tests/fixtures/parser/ast/ts-slot-binding01-type-output.svelte diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-config.json b/tests/fixtures/parser/ast/ts-slot-binding01-config.json new file mode 100644 index 00000000..73510cc2 --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-config.json @@ -0,0 +1,3 @@ +{ + "parser": "typescript-eslint-parser-for-extra-files" +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-input-child.svelte b/tests/fixtures/parser/ast/ts-slot-binding01-input-child.svelte new file mode 100644 index 00000000..5f5d744f --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-input-child.svelte @@ -0,0 +1,5 @@ + + + diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-input.svelte b/tests/fixtures/parser/ast/ts-slot-binding01-input.svelte new file mode 100644 index 00000000..13fabd20 --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-input.svelte @@ -0,0 +1,7 @@ + + + +
{bar.prop}
+
diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-output.json b/tests/fixtures/parser/ast/ts-slot-binding01-output.json new file mode 100644 index 00000000..901631a7 --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-output.json @@ -0,0 +1,1403 @@ +{ + "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": "ImportDeclaration", + "importKind": "value", + "source": { + "type": "Literal", + "raw": "\"./ts-slot-binding01-input-child.svelte\"", + "value": "./ts-slot-binding01-input-child.svelte", + "range": [ + 43, + 83 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 64 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + ], + "range": [ + 21, + 84 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 65 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 85, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 94 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 94, + 96 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "component", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 97, + 106 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 96, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 11 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "\n ", + "range": [ + 107, + 110 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 6, + "column": 2 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 111, + 114 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Let", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "foo", + "range": [ + 119, + 122 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "modifiers": [], + "range": [ + 115, + 122 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "expression": { + "type": "Identifier", + "name": "bar", + "range": [ + 124, + 127 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + "range": [ + 115, + 128 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 20 + } + } + } + ], + "selfClosing": false, + "range": [ + 110, + 129 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 21 + } + } + }, + "children": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "bar", + "range": [ + 130, + 133 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "prop", + "range": [ + 134, + 138 + ], + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + "range": [ + 130, + 138 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + "range": [ + 129, + 139 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 31 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 139, + 145 + ], + "loc": { + "start": { + "line": 6, + "column": 31 + }, + "end": { + "line": 6, + "column": 37 + } + } + }, + "range": [ + 110, + 145 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 37 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 145, + 146 + ], + "loc": { + "start": { + "line": 6, + "column": 37 + }, + "end": { + "line": 7, + "column": 0 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 146, + 158 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 96, + 158 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 12 + } + } + } + ], + "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": "import", + "range": [ + 21, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "from", + "range": [ + 38, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "String", + "value": "\"./ts-slot-binding01-input-child.svelte\"", + "range": [ + 43, + 83 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 64 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 2, + "column": 64 + }, + "end": { + "line": 2, + "column": 65 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 87, + 93 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 93, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 94, + 96 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 96, + 97 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Identifier", + "value": "Component", + "range": [ + 97, + 106 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 11 + } + } + }, + { + "type": "HTMLText", + "value": "\n ", + "range": [ + 107, + 110 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 6, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 111, + 114 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "let", + "range": [ + 115, + 118 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "foo", + "range": [ + 119, + 122 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 122, + 123 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 123, + 124 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 16 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 124, + 127 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 127, + 128 + ], + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 128, + 129 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 130, + 133 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + { + "type": "Identifier", + "value": "prop", + "range": [ + 134, + 138 + ], + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 138, + 139 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 6, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 6, + "column": 31 + }, + "end": { + "line": 6, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 6, + "column": 32 + }, + "end": { + "line": 6, + "column": 33 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 141, + 144 + ], + "loc": { + "start": { + "line": 6, + "column": 33 + }, + "end": { + "line": 6, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 6, + "column": 36 + }, + "end": { + "line": 6, + "column": 37 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 145, + 146 + ], + "loc": { + "start": { + "line": 6, + "column": 37 + }, + "end": { + "line": 7, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 147, + 148 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "Component", + "range": [ + 148, + 157 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 157, + 158 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 12 + } + } + } + ], + "range": [ + 0, + 159 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-requirements.json b/tests/fixtures/parser/ast/ts-slot-binding01-requirements.json new file mode 100644 index 00000000..cec5a976 --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-requirements.json @@ -0,0 +1,8 @@ +{ + "scope": { + "@typescript-eslint/parser": ">=6.5.0" + }, + "parse": { + "svelte": "^5.0.0-0" + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-scope-output-svelte5.json b/tests/fixtures/parser/ast/ts-slot-binding01-scope-output-svelte5.json new file mode 100644 index 00000000..a5e2efc3 --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-scope-output-svelte5.json @@ -0,0 +1,596 @@ +{ + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$bindable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$inspect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$host", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "Component", + "identifiers": [ + { + "type": "Identifier", + "name": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "node": { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 97, + 106 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 97, + 106 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "bar", + "identifiers": [ + { + "type": "Identifier", + "name": "bar", + "range": [ + 124, + 127 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "bar", + "range": [ + 124, + 127 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + "node": { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 111, + 114 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Let", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "foo", + "range": [ + 119, + 122 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "modifiers": [], + "range": [ + 115, + 122 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "expression": { + "type": "Identifier", + "name": "bar", + "range": [ + 124, + 127 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + "range": [ + 115, + 128 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 20 + } + } + } + ], + "selfClosing": false, + "range": [ + 110, + 129 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 21 + } + } + }, + "children": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "bar", + "range": [ + 130, + 133 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "prop", + "range": [ + 134, + 138 + ], + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + "range": [ + 130, + 138 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + "range": [ + 129, + 139 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 31 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 139, + 145 + ], + "loc": { + "start": { + "line": 6, + "column": 31 + }, + "end": { + "line": 6, + "column": 37 + } + } + }, + "range": [ + 110, + 145 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 37 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "bar", + "range": [ + 130, + 133 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "bar", + "range": [ + 124, + 127 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "bar", + "range": [ + 130, + 133 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "bar", + "range": [ + 124, + 127 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-scope-output.json b/tests/fixtures/parser/ast/ts-slot-binding01-scope-output.json new file mode 100644 index 00000000..6bf44ff7 --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-scope-output.json @@ -0,0 +1,469 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "Component", + "identifiers": [ + { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "node": { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 86, + 95 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 86, + 95 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "e", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "detail", + "range": [ + 142, + 148 + ], + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 140, + 148 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 140, + 149 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 13 + } + } + } + ], + "range": [ + 108, + 151 + ], + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 8, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + } + } + ], + "range": [ + 105, + 151 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 8, + "column": 1 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "e", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "e", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "e", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "e", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-input-child.svelte b/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-input-child.svelte new file mode 100644 index 00000000..5f5d744f --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-input-child.svelte @@ -0,0 +1,5 @@ + + + diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-input.svelte b/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-input.svelte new file mode 100644 index 00000000..75d03acc --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-input.svelte @@ -0,0 +1,7 @@ + + + +
{bar.prop}
+
diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-output.json b/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-output.json new file mode 100644 index 00000000..23cd8219 --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-output.json @@ -0,0 +1,1403 @@ +{ + "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": "ImportDeclaration", + "importKind": "value", + "source": { + "type": "Literal", + "raw": "\"./ts-slot-binding01-sveltev4-input-child.svelte\"", + "value": "./ts-slot-binding01-sveltev4-input-child.svelte", + "range": [ + 43, + 92 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 73 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + ], + "range": [ + 21, + 93 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 74 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 94, + 103 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 103 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 103, + 105 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "component", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 106, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 105, + 116 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 11 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "\n ", + "range": [ + 116, + 119 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 6, + "column": 2 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 120, + 123 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Let", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "foo", + "range": [ + 128, + 131 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "modifiers": [], + "range": [ + 124, + 131 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "expression": { + "type": "Identifier", + "name": "bar", + "range": [ + 133, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + "range": [ + 124, + 137 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 20 + } + } + } + ], + "selfClosing": false, + "range": [ + 119, + 138 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 21 + } + } + }, + "children": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "bar", + "range": [ + 139, + 142 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "prop", + "range": [ + 143, + 147 + ], + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + "range": [ + 139, + 147 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + "range": [ + 138, + 148 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 31 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 148, + 154 + ], + "loc": { + "start": { + "line": 6, + "column": 31 + }, + "end": { + "line": 6, + "column": 37 + } + } + }, + "range": [ + 119, + 154 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 37 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 6, + "column": 37 + }, + "end": { + "line": 7, + "column": 0 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 155, + 167 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 105, + 167 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 12 + } + } + } + ], + "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": "import", + "range": [ + 21, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "from", + "range": [ + 38, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "String", + "value": "\"./ts-slot-binding01-sveltev4-input-child.svelte\"", + "range": [ + 43, + 92 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 73 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 2, + "column": 73 + }, + "end": { + "line": 2, + "column": 74 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 95, + 96 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 96, + 102 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 103, + 105 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Identifier", + "value": "Component", + "range": [ + 106, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 115, + 116 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 11 + } + } + }, + { + "type": "HTMLText", + "value": "\n ", + "range": [ + 116, + 119 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 6, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 119, + 120 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 120, + 123 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "let", + "range": [ + 124, + 127 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 127, + 128 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "foo", + "range": [ + 128, + 131 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 16 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 133, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 137, + 138 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 138, + 139 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 139, + 142 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 142, + 143 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + { + "type": "Identifier", + "value": "prop", + "range": [ + 143, + 147 + ], + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 147, + 148 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 6, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 31 + }, + "end": { + "line": 6, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 6, + "column": 32 + }, + "end": { + "line": 6, + "column": 33 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 150, + 153 + ], + "loc": { + "start": { + "line": 6, + "column": 33 + }, + "end": { + "line": 6, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 153, + 154 + ], + "loc": { + "start": { + "line": 6, + "column": 36 + }, + "end": { + "line": 6, + "column": 37 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 6, + "column": 37 + }, + "end": { + "line": 7, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 155, + 156 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 156, + 157 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "Component", + "range": [ + 157, + 166 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 12 + } + } + } + ], + "range": [ + 0, + 168 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-requirements.json b/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-requirements.json new file mode 100644 index 00000000..5afeb7b2 --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-requirements.json @@ -0,0 +1,8 @@ +{ + "scope": { + "@typescript-eslint/parser": ">=6.5.0" + }, + "parse": { + "svelte": "^3.0.0 || ^4.0.0" + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-scope-output.json b/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-scope-output.json new file mode 100644 index 00000000..0e8a50a1 --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-scope-output.json @@ -0,0 +1,557 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "Component", + "identifiers": [ + { + "type": "Identifier", + "name": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "node": { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 106, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 106, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 28, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "bar", + "identifiers": [ + { + "type": "Identifier", + "name": "bar", + "range": [ + 133, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "bar", + "range": [ + 133, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + "node": { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 120, + 123 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Let", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "foo", + "range": [ + 128, + 131 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "modifiers": [], + "range": [ + 124, + 131 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "expression": { + "type": "Identifier", + "name": "bar", + "range": [ + 133, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + "range": [ + 124, + 137 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 20 + } + } + } + ], + "selfClosing": false, + "range": [ + 119, + 138 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 21 + } + } + }, + "children": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "bar", + "range": [ + 139, + 142 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "prop", + "range": [ + 143, + 147 + ], + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + "range": [ + 139, + 147 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + "range": [ + 138, + 148 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 31 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 148, + 154 + ], + "loc": { + "start": { + "line": 6, + "column": 31 + }, + "end": { + "line": 6, + "column": 37 + } + } + }, + "range": [ + 119, + 154 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 37 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "bar", + "range": [ + 139, + 142 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "bar", + "range": [ + 133, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "bar", + "range": [ + 139, + 142 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "bar", + "range": [ + 133, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 19 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-type-output.svelte b/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-type-output.svelte new file mode 100644 index 00000000..9e15eeb6 --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-sveltev4-type-output.svelte @@ -0,0 +1,7 @@ + + + +
{bar.prop}
+
diff --git a/tests/fixtures/parser/ast/ts-slot-binding01-type-output.svelte b/tests/fixtures/parser/ast/ts-slot-binding01-type-output.svelte new file mode 100644 index 00000000..3b5d8bcc --- /dev/null +++ b/tests/fixtures/parser/ast/ts-slot-binding01-type-output.svelte @@ -0,0 +1,7 @@ + + + +
{bar.prop}
+