diff --git a/.changeset/friendly-moles-appear.md b/.changeset/friendly-moles-appear.md new file mode 100644 index 00000000..29911099 --- /dev/null +++ b/.changeset/friendly-moles-appear.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": minor +--- + +feat: add support for `` diff --git a/package.json b/package.json index de5badb9..d5678a1c 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,7 @@ "prettier-plugin-svelte": "^2.5.0", "semver": "^7.3.5", "string-replace-loader": "^3.0.3", - "svelte": "^3.46.1", + "svelte": "^3.57.0", "typescript": "~5.0.0", "vue-eslint-parser": "^9.0.0" }, diff --git a/src/parser/converts/element.ts b/src/parser/converts/element.ts index 0918a394..9373e409 100644 --- a/src/parser/converts/element.ts +++ b/src/parser/converts/element.ts @@ -166,6 +166,10 @@ export function* convertChildren( yield convertConstTag(child, parent, ctx); continue; } + if (child.type === "Document") { + yield convertDocumentElement(child, parent, ctx); + continue; + } throw new Error(`Unknown type:${(child as any).type}`); } @@ -328,6 +332,7 @@ function convertSpecialElement( | SvAST.InlineComponent | SvAST.Element | SvAST.Window + | SvAST.Document | SvAST.Body | SvAST.Head | SvAST.Options @@ -590,6 +595,15 @@ function convertWindowElement( return convertSpecialElement(node, parent, ctx); } +/** Convert for document element. e.g. */ +function convertDocumentElement( + node: SvAST.Document, + parent: SvelteSpecialElement["parent"], + ctx: Context +): SvelteSpecialElement { + return convertSpecialElement(node, parent, ctx); +} + /** Convert for body element. e.g. */ function convertBodyElement( node: SvAST.Body, diff --git a/src/parser/svelte-ast-types.ts b/src/parser/svelte-ast-types.ts index 1824c76e..8c026db3 100644 --- a/src/parser/svelte-ast-types.ts +++ b/src/parser/svelte-ast-types.ts @@ -20,6 +20,7 @@ export declare type TemplateNode = | Element | InlineComponent | Window + | Document | Body | Head | Title @@ -134,6 +135,12 @@ export interface Window extends BaseNode { children: TemplateNode[]; attributes: AttributeOrDirective[]; } +export interface Document extends BaseNode { + type: "Document"; + name: "svelte:document"; + children: TemplateNode[]; + attributes: AttributeOrDirective[]; +} export interface Body extends BaseNode { type: "Body"; name: "svelte:body"; diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/01-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/01-input.svelte similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/01-input.svelte rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/01-input.svelte diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/01-no-undef-result.json b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/01-no-undef-result.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/01-no-undef-result.json rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/01-no-undef-result.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/01-output.json b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/01-output.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/01-output.json rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/01-output.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/01-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/01-scope-output.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/01-scope-output.json rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/01-scope-output.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/02-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/02-input.svelte similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/02-input.svelte rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/02-input.svelte diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/02-no-undef-result.json b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/02-no-undef-result.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/02-no-undef-result.json rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/02-no-undef-result.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/02-output.json b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/02-output.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/02-output.json rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/02-output.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/02-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/02-scope-output.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/02-scope-output.json rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/02-scope-output.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/03-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/03-input.svelte similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/03-input.svelte rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/03-input.svelte diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/03-output.json b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/03-output.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/03-output.json rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/03-output.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/03-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/03-scope-output.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/03-scope-output.json rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/03-scope-output.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/04-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/04-input.svelte similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/04-input.svelte rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/04-input.svelte diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/04-no-undef-result.json b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/04-no-undef-result.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/04-no-undef-result.json rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/04-no-undef-result.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/04-output.json b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/04-output.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/04-output.json rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/04-output.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/04-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/04-scope-output.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/16-svelte-window/04-scope-output.json rename to tests/fixtures/parser/ast/docs/template-syntax/16_1-svelte-window/04-scope-output.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/01-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/01-input.svelte new file mode 100644 index 00000000..ff9f8662 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/01-input.svelte @@ -0,0 +1 @@ + diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/01-no-undef-result.json b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/01-no-undef-result.json new file mode 100644 index 00000000..11d87bad --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/01-no-undef-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "no-undef", + "code": "handler", + "line": 1, + "column": 28 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/01-output.json b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/01-output.json new file mode 100644 index 00000000..75517298 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/01-output.json @@ -0,0 +1,351 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteElement", + "kind": "special", + "name": { + "type": "SvelteName", + "name": "svelte:document", + "range": [ + 1, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "EventHandler", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "event", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 25 + } + } + }, + "modifiers": [], + "range": [ + 17, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 25 + } + } + }, + "expression": { + "type": "Identifier", + "name": "handler", + "range": [ + 27, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 34 + } + } + }, + "range": [ + 17, + 35 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 35 + } + } + } + ], + "selfClosing": true, + "range": [ + 0, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 0, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "svelte:document", + "range": [ + 1, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "on", + "range": [ + 17, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "event", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + } + }, + { + "type": "Identifier", + "value": "handler", + "range": [ + 27, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 35 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 37 + } + } + } + ], + "range": [ + 0, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/01-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/01-scope-output.json new file mode 100644 index 00000000..e3be4aef --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/01-scope-output.json @@ -0,0 +1,106 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "handler", + "range": [ + 27, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 34 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "handler", + "range": [ + 27, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 34 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "handler", + "range": [ + 27, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 34 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/02-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/02-input.svelte new file mode 100644 index 00000000..c235e352 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/02-input.svelte @@ -0,0 +1,4 @@ + diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/02-no-undef-result.json b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/02-no-undef-result.json new file mode 100644 index 00000000..e774b2db --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/02-no-undef-result.json @@ -0,0 +1,14 @@ +[ + { + "ruleId": "no-undef", + "code": "handleVisibilityChange", + "line": 2, + "column": 23 + }, + { + "ruleId": "no-undef", + "code": "someAction", + "line": 3, + "column": 6 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/02-output.json b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/02-output.json new file mode 100644 index 00000000..f87bf992 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/02-output.json @@ -0,0 +1,460 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteElement", + "kind": "special", + "name": { + "type": "SvelteName", + "name": "svelte:document", + "range": [ + 1, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "EventHandler", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "visibilitychange", + "range": [ + 21, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "modifiers": [], + "range": [ + 18, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "expression": { + "type": "Identifier", + "name": "handleVisibilityChange", + "range": [ + 39, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 44 + } + } + }, + "range": [ + 18, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 45 + } + } + }, + { + "type": "SvelteDirective", + "kind": "Action", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "Identifier", + "name": "someAction", + "range": [ + 68, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + "modifiers": [], + "range": [ + 64, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + "expression": null, + "range": [ + 64, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 15 + } + } + } + ], + "selfClosing": true, + "range": [ + 0, + 81 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 2 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 0, + 81 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 2 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "svelte:document", + "range": [ + 1, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "on", + "range": [ + 18, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "visibilitychange", + "range": [ + 21, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "handleVisibilityChange", + "range": [ + 39, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 44 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 44 + }, + "end": { + "line": 2, + "column": 45 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "use", + "range": [ + 64, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "someAction", + "range": [ + 68, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 80, + 81 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + } + } + ], + "range": [ + 0, + 82 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/02-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/02-scope-output.json new file mode 100644 index 00000000..0b12bfe2 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/16_2-svelte-document/02-scope-output.json @@ -0,0 +1,175 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "handleVisibilityChange", + "range": [ + 39, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 44 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "someAction", + "range": [ + 68, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "handleVisibilityChange", + "range": [ + 39, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 44 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "someAction", + "range": [ + 68, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "handleVisibilityChange", + "range": [ + 39, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 44 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "someAction", + "range": [ + 68, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/tutorial/svelte-document-input.svelte b/tests/fixtures/parser/ast/tutorial/svelte-document-input.svelte new file mode 100644 index 00000000..5dd44aa3 --- /dev/null +++ b/tests/fixtures/parser/ast/tutorial/svelte-document-input.svelte @@ -0,0 +1,10 @@ + + + + +

Select this text to fire events

+

Selection: {selection}

diff --git a/tests/fixtures/parser/ast/tutorial/svelte-document-no-unused-vars-result.json b/tests/fixtures/parser/ast/tutorial/svelte-document-no-unused-vars-result.json new file mode 100644 index 00000000..5ec664d8 --- /dev/null +++ b/tests/fixtures/parser/ast/tutorial/svelte-document-no-unused-vars-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "no-unused-vars", + "code": "e", + "line": 4, + "column": 33 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/tutorial/svelte-document-output.json b/tests/fixtures/parser/ast/tutorial/svelte-document-output.json new file mode 100644 index 00000000..f03b2b46 --- /dev/null +++ b/tests/fixtures/parser/ast/tutorial/svelte-document-output.json @@ -0,0 +1,2058 @@ +{ + "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": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "init": { + "type": "Literal", + "raw": "''", + "value": "", + "range": [ + 26, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "range": [ + 14, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 19 + } + } + } + ], + "range": [ + 10, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 38, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 28 + } + } + }, + "init": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "AssignmentExpression", + "left": { + "type": "Identifier", + "name": "selection", + "range": [ + 69, + 78 + ], + "loc": { + "start": { + "line": 4, + "column": 38 + }, + "end": { + "line": 4, + "column": 47 + } + } + }, + "operator": "=", + "right": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "document", + "range": [ + 81, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 58 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "getSelection", + "range": [ + 90, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 59 + }, + "end": { + "line": 4, + "column": 71 + } + } + }, + "range": [ + 81, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 71 + } + } + }, + "optional": false, + "range": [ + 81, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 73 + } + } + }, + "range": [ + 69, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 38 + }, + "end": { + "line": 4, + "column": 73 + } + } + }, + "expression": true, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 4, + "column": 32 + }, + "end": { + "line": 4, + "column": 33 + } + } + } + ], + "range": [ + 62, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 31 + }, + "end": { + "line": 4, + "column": 73 + } + } + }, + "range": [ + 38, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 73 + } + } + } + ], + "range": [ + 32, + 105 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 74 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 106, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + } + }, + "range": [ + 0, + 115 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 115, + 117 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 7, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "special", + "name": { + "type": "SvelteName", + "name": "svelte:document", + "range": [ + 118, + 133 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 16 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "EventHandler", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "selectionchange", + "range": [ + 137, + 152 + ], + "loc": { + "start": { + "line": 7, + "column": 20 + }, + "end": { + "line": 7, + "column": 35 + } + } + }, + "modifiers": [], + "range": [ + 134, + 152 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 35 + } + } + }, + "expression": { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 154, + 175 + ], + "loc": { + "start": { + "line": 7, + "column": 37 + }, + "end": { + "line": 7, + "column": 58 + } + } + }, + "range": [ + 134, + 176 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 59 + } + } + } + ], + "selfClosing": true, + "range": [ + 117, + 179 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 62 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 117, + 179 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 62 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 179, + 181 + ], + "loc": { + "start": { + "line": 7, + "column": 62 + }, + "end": { + "line": 9, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "p", + "range": [ + 182, + 183 + ], + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 181, + 184 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "Select this text to fire events", + "range": [ + 184, + 215 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 34 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 215, + 219 + ], + "loc": { + "start": { + "line": 9, + "column": 34 + }, + "end": { + "line": 9, + "column": 38 + } + } + }, + "range": [ + 181, + 219 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 38 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 219, + 220 + ], + "loc": { + "start": { + "line": 9, + "column": 38 + }, + "end": { + "line": 10, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "p", + "range": [ + 221, + 222 + ], + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 2 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 220, + 223 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 3 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "Selection: ", + "range": [ + 223, + 234 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 14 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "selection", + "range": [ + 235, + 244 + ], + "loc": { + "start": { + "line": 10, + "column": 15 + }, + "end": { + "line": 10, + "column": 24 + } + } + }, + "range": [ + 234, + 245 + ], + "loc": { + "start": { + "line": 10, + "column": 14 + }, + "end": { + "line": 10, + "column": 25 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 245, + 249 + ], + "loc": { + "start": { + "line": 10, + "column": 25 + }, + "end": { + "line": 10, + "column": 29 + } + } + }, + "range": [ + 220, + 249 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 29 + } + } + } + ], + "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": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "String", + "value": "''", + "range": [ + 26, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 32, + 37 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "handleSelectionChange", + "range": [ + 38, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 4, + "column": 29 + }, + "end": { + "line": 4, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 4, + "column": 31 + }, + "end": { + "line": 4, + "column": 32 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 4, + "column": 32 + }, + "end": { + "line": 4, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 4, + "column": 33 + }, + "end": { + "line": 4, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 66, + 68 + ], + "loc": { + "start": { + "line": 4, + "column": 35 + }, + "end": { + "line": 4, + "column": 37 + } + } + }, + { + "type": "Identifier", + "value": "selection", + "range": [ + 69, + 78 + ], + "loc": { + "start": { + "line": 4, + "column": 38 + }, + "end": { + "line": 4, + "column": 47 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 48 + }, + "end": { + "line": 4, + "column": 49 + } + } + }, + { + "type": "Identifier", + "value": "document", + "range": [ + 81, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 58 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 4, + "column": 58 + }, + "end": { + "line": 4, + "column": 59 + } + } + }, + { + "type": "Identifier", + "value": "getSelection", + "range": [ + 90, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 59 + }, + "end": { + "line": 4, + "column": 71 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 4, + "column": 71 + }, + "end": { + "line": 4, + "column": 72 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 72 + }, + "end": { + "line": 4, + "column": 73 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 4, + "column": 73 + }, + "end": { + "line": 4, + "column": 74 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 107, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 114, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 115, + 117 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 7, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "svelte:document", + "range": [ + 118, + 133 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 16 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "on", + "range": [ + 134, + 136 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "selectionchange", + "range": [ + 137, + 152 + ], + "loc": { + "start": { + "line": 7, + "column": 20 + }, + "end": { + "line": 7, + "column": 35 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 152, + 153 + ], + "loc": { + "start": { + "line": 7, + "column": 35 + }, + "end": { + "line": 7, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 153, + 154 + ], + "loc": { + "start": { + "line": 7, + "column": 36 + }, + "end": { + "line": 7, + "column": 37 + } + } + }, + { + "type": "Identifier", + "value": "handleSelectionChange", + "range": [ + 154, + 175 + ], + "loc": { + "start": { + "line": 7, + "column": 37 + }, + "end": { + "line": 7, + "column": 58 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 7, + "column": 58 + }, + "end": { + "line": 7, + "column": 59 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 7, + "column": 60 + }, + "end": { + "line": 7, + "column": 61 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 178, + 179 + ], + "loc": { + "start": { + "line": 7, + "column": 61 + }, + "end": { + "line": 7, + "column": 62 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 179, + 181 + ], + "loc": { + "start": { + "line": 7, + "column": 62 + }, + "end": { + "line": 9, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 181, + 182 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "p", + "range": [ + 182, + 183 + ], + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 183, + 184 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + { + "type": "HTMLText", + "value": "Select", + "range": [ + 184, + 190 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 190, + 191 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 10 + } + } + }, + { + "type": "HTMLText", + "value": "this", + "range": [ + 191, + 195 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 14 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 195, + 196 + ], + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 15 + } + } + }, + { + "type": "HTMLText", + "value": "text", + "range": [ + 196, + 200 + ], + "loc": { + "start": { + "line": 9, + "column": 15 + }, + "end": { + "line": 9, + "column": 19 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 200, + 201 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 20 + } + } + }, + { + "type": "HTMLText", + "value": "to", + "range": [ + 201, + 203 + ], + "loc": { + "start": { + "line": 9, + "column": 20 + }, + "end": { + "line": 9, + "column": 22 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 203, + 204 + ], + "loc": { + "start": { + "line": 9, + "column": 22 + }, + "end": { + "line": 9, + "column": 23 + } + } + }, + { + "type": "HTMLText", + "value": "fire", + "range": [ + 204, + 208 + ], + "loc": { + "start": { + "line": 9, + "column": 23 + }, + "end": { + "line": 9, + "column": 27 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 208, + 209 + ], + "loc": { + "start": { + "line": 9, + "column": 27 + }, + "end": { + "line": 9, + "column": 28 + } + } + }, + { + "type": "HTMLText", + "value": "events", + "range": [ + 209, + 215 + ], + "loc": { + "start": { + "line": 9, + "column": 28 + }, + "end": { + "line": 9, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 215, + 216 + ], + "loc": { + "start": { + "line": 9, + "column": 34 + }, + "end": { + "line": 9, + "column": 35 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 216, + 217 + ], + "loc": { + "start": { + "line": 9, + "column": 35 + }, + "end": { + "line": 9, + "column": 36 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "p", + "range": [ + 217, + 218 + ], + "loc": { + "start": { + "line": 9, + "column": 36 + }, + "end": { + "line": 9, + "column": 37 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 218, + 219 + ], + "loc": { + "start": { + "line": 9, + "column": 37 + }, + "end": { + "line": 9, + "column": 38 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 219, + 220 + ], + "loc": { + "start": { + "line": 9, + "column": 38 + }, + "end": { + "line": 10, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 220, + 221 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "p", + "range": [ + 221, + 222 + ], + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 222, + 223 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + } + }, + { + "type": "HTMLText", + "value": "Selection:", + "range": [ + 223, + 233 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 13 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 233, + 234 + ], + "loc": { + "start": { + "line": 10, + "column": 13 + }, + "end": { + "line": 10, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 234, + 235 + ], + "loc": { + "start": { + "line": 10, + "column": 14 + }, + "end": { + "line": 10, + "column": 15 + } + } + }, + { + "type": "Identifier", + "value": "selection", + "range": [ + 235, + 244 + ], + "loc": { + "start": { + "line": 10, + "column": 15 + }, + "end": { + "line": 10, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 244, + 245 + ], + "loc": { + "start": { + "line": 10, + "column": 24 + }, + "end": { + "line": 10, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 245, + 246 + ], + "loc": { + "start": { + "line": 10, + "column": 25 + }, + "end": { + "line": 10, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 246, + 247 + ], + "loc": { + "start": { + "line": 10, + "column": 26 + }, + "end": { + "line": 10, + "column": 27 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "p", + "range": [ + 247, + 248 + ], + "loc": { + "start": { + "line": 10, + "column": 27 + }, + "end": { + "line": 10, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 248, + 249 + ], + "loc": { + "start": { + "line": 10, + "column": 28 + }, + "end": { + "line": 10, + "column": 29 + } + } + } + ], + "range": [ + 0, + 250 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/tutorial/svelte-document-scope-output.json b/tests/fixtures/parser/ast/tutorial/svelte-document-scope-output.json new file mode 100644 index 00000000..8e6c9ce7 --- /dev/null +++ b/tests/fixtures/parser/ast/tutorial/svelte-document-scope-output.json @@ -0,0 +1,1115 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "selection", + "identifiers": [ + { + "type": "Identifier", + "name": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "init": { + "type": "Literal", + "raw": "''", + "value": "", + "range": [ + 26, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "range": [ + 14, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 19 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "selection", + "range": [ + 69, + 78 + ], + "loc": { + "start": { + "line": 4, + "column": 38 + }, + "end": { + "line": 4, + "column": 47 + } + } + }, + "from": "function", + "init": false, + "resolved": { + "type": "Identifier", + "name": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "selection", + "range": [ + 235, + 244 + ], + "loc": { + "start": { + "line": 10, + "column": 15 + }, + "end": { + "line": 10, + "column": 24 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + } + ] + }, + { + "name": "handleSelectionChange", + "identifiers": [ + { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 38, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 28 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 38, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 28 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 38, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 28 + } + } + }, + "init": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "AssignmentExpression", + "left": { + "type": "Identifier", + "name": "selection", + "range": [ + 69, + 78 + ], + "loc": { + "start": { + "line": 4, + "column": 38 + }, + "end": { + "line": 4, + "column": 47 + } + } + }, + "operator": "=", + "right": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "document", + "range": [ + 81, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 58 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "getSelection", + "range": [ + 90, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 59 + }, + "end": { + "line": 4, + "column": 71 + } + } + }, + "range": [ + 81, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 71 + } + } + }, + "optional": false, + "range": [ + 81, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 73 + } + } + }, + "range": [ + 69, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 38 + }, + "end": { + "line": 4, + "column": 73 + } + } + }, + "expression": true, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 4, + "column": 32 + }, + "end": { + "line": 4, + "column": 33 + } + } + } + ], + "range": [ + 62, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 31 + }, + "end": { + "line": 4, + "column": 73 + } + } + }, + "range": [ + 38, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 73 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 38, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 28 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 38, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 28 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 154, + 175 + ], + "loc": { + "start": { + "line": 7, + "column": 37 + }, + "end": { + "line": 7, + "column": 58 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 38, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 28 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 38, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 28 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 38, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 28 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 154, + 175 + ], + "loc": { + "start": { + "line": 7, + "column": 37 + }, + "end": { + "line": 7, + "column": 58 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "handleSelectionChange", + "range": [ + 38, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 28 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "selection", + "range": [ + 235, + 244 + ], + "loc": { + "start": { + "line": 10, + "column": 15 + }, + "end": { + "line": 10, + "column": 24 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 4, + "column": 32 + }, + "end": { + "line": 4, + "column": 33 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 4, + "column": 32 + }, + "end": { + "line": 4, + "column": 33 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "AssignmentExpression", + "left": { + "type": "Identifier", + "name": "selection", + "range": [ + 69, + 78 + ], + "loc": { + "start": { + "line": 4, + "column": 38 + }, + "end": { + "line": 4, + "column": 47 + } + } + }, + "operator": "=", + "right": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "document", + "range": [ + 81, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 58 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "getSelection", + "range": [ + 90, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 59 + }, + "end": { + "line": 4, + "column": 71 + } + } + }, + "range": [ + 81, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 71 + } + } + }, + "optional": false, + "range": [ + 81, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 73 + } + } + }, + "range": [ + 69, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 38 + }, + "end": { + "line": 4, + "column": 73 + } + } + }, + "expression": true, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 4, + "column": 32 + }, + "end": { + "line": 4, + "column": 33 + } + } + } + ], + "range": [ + 62, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 31 + }, + "end": { + "line": 4, + "column": 73 + } + } + } + } + ], + "references": [] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "selection", + "range": [ + 69, + 78 + ], + "loc": { + "start": { + "line": 4, + "column": 38 + }, + "end": { + "line": 4, + "column": 47 + } + } + }, + "from": "function", + "init": false, + "resolved": { + "type": "Identifier", + "name": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "document", + "range": [ + 81, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 58 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "selection", + "range": [ + 69, + 78 + ], + "loc": { + "start": { + "line": 4, + "column": 38 + }, + "end": { + "line": 4, + "column": 47 + } + } + }, + "from": "function", + "init": false, + "resolved": { + "type": "Identifier", + "name": "selection", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "document", + "range": [ + 81, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 58 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "document", + "range": [ + 81, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 58 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "document", + "range": [ + 81, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 50 + }, + "end": { + "line": 4, + "column": 58 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] +} \ No newline at end of file