From ab31e47c2a166b3139adbef4a05cd0a1b5f3c003 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 9 Apr 2022 09:25:46 +0900 Subject: [PATCH] Support for `` --- src/parser/converts/element.ts | 27 +- src/parser/svelte-ast-types.ts | 12 +- .../01-input.svelte | 0 .../01-no-undef-result.json | 0 .../01-output.json | 0 .../01-scope-output.json | 0 .../02-input.svelte | 0 .../02-no-undef-result.json | 0 .../02-output.json | 0 .../02-scope-output.json | 0 .../15_2-svelte-element/01-input.svelte | 1 + .../01-no-undef-result.json | 8 + .../15_2-svelte-element/01-output.json | 296 ++ .../15_2-svelte-element/01-scope-output.json | 106 + .../15_2-svelte-element/02-input.svelte | 6 + .../15_2-svelte-element/02-output.json | 1147 ++++++++ .../02-prefer-const-result.json | 8 + .../15_2-svelte-element/02-scope-output.json | 502 ++++ ...svelte-element-with-bind-this-input.svelte | 7 + .../svelte-element-with-bind-this-output.json | 1400 +++++++++ ...e-element-with-bind-this-scope-output.json | 613 ++++ .../ast/tutorial/svelte-element-input.svelte | 12 + .../ast/tutorial/svelte-element-output.json | 2603 +++++++++++++++++ .../tutorial/svelte-element-scope-output.json | 1355 +++++++++ 24 files changed, 8090 insertions(+), 13 deletions(-) rename tests/fixtures/parser/ast/docs/template-syntax/{15-svelte-component => 15_1-svelte-component}/01-input.svelte (100%) rename tests/fixtures/parser/ast/docs/template-syntax/{15-svelte-component => 15_1-svelte-component}/01-no-undef-result.json (100%) rename tests/fixtures/parser/ast/docs/template-syntax/{15-svelte-component => 15_1-svelte-component}/01-output.json (100%) rename tests/fixtures/parser/ast/docs/template-syntax/{15-svelte-component => 15_1-svelte-component}/01-scope-output.json (100%) rename tests/fixtures/parser/ast/docs/template-syntax/{15-svelte-component => 15_1-svelte-component}/02-input.svelte (100%) rename tests/fixtures/parser/ast/docs/template-syntax/{15-svelte-component => 15_1-svelte-component}/02-no-undef-result.json (100%) rename tests/fixtures/parser/ast/docs/template-syntax/{15-svelte-component => 15_1-svelte-component}/02-output.json (100%) rename tests/fixtures/parser/ast/docs/template-syntax/{15-svelte-component => 15_1-svelte-component}/02-scope-output.json (100%) create mode 100644 tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-input.svelte create mode 100644 tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-no-undef-result.json create mode 100644 tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-output.json create mode 100644 tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-scope-output.json create mode 100644 tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-input.svelte create mode 100644 tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-output.json create mode 100644 tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-prefer-const-result.json create mode 100644 tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte-element-with-bind-this-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte-element-with-bind-this-output.json create mode 100644 tests/fixtures/parser/ast/svelte-element-with-bind-this-scope-output.json create mode 100644 tests/fixtures/parser/ast/tutorial/svelte-element-input.svelte create mode 100644 tests/fixtures/parser/ast/tutorial/svelte-element-output.json create mode 100644 tests/fixtures/parser/ast/tutorial/svelte-element-scope-output.json diff --git a/src/parser/converts/element.ts b/src/parser/converts/element.ts index a818d22c..885b0d48 100644 --- a/src/parser/converts/element.ts +++ b/src/parser/converts/element.ts @@ -82,7 +82,11 @@ export function* convertChildren( continue } if (child.type === "Element") { - yield convertHTMLElement(child, parent, ctx) + if (child.name.includes(":")) { + yield convertSpecialElement(child, parent, ctx) + } else { + yield convertHTMLElement(child, parent, ctx) + } continue } if (child.type === "InlineComponent") { @@ -277,6 +281,7 @@ function convertHTMLElement( function convertSpecialElement( node: | SvAST.InlineComponent + | SvAST.Element | SvAST.Window | SvAST.Body | SvAST.Head @@ -330,20 +335,18 @@ function convertSpecialElement( ctx.scriptLet.closeScope() } - if ( - node.type === "InlineComponent" && - node.expression && - node.name === "svelte:component" - ) { + const thisExpression = + (node.type === "InlineComponent" && + node.name === "svelte:component" && + node.expression) || + (node.type === "Element" && node.name === "svelte:element" && node.tag) + if (thisExpression) { const eqIndex = ctx.code.lastIndexOf( "=", - getWithLoc(node.expression).start, + getWithLoc(thisExpression).start, ) const startIndex = ctx.code.lastIndexOf("this", eqIndex) - const closeIndex = ctx.code.indexOf( - "}", - getWithLoc(node.expression).end, - ) + const closeIndex = ctx.code.indexOf("}", getWithLoc(thisExpression).end) const endIndex = indexOf( ctx.code, (c) => c === ">" || !c.trim(), @@ -366,7 +369,7 @@ function convertSpecialElement( start: startIndex, end: eqIndex, }) - ctx.scriptLet.addExpression(node.expression, thisAttr, null, (es) => { + ctx.scriptLet.addExpression(thisExpression, thisAttr, null, (es) => { thisAttr.expression = es }) element.startTag.attributes.push(thisAttr) diff --git a/src/parser/svelte-ast-types.ts b/src/parser/svelte-ast-types.ts index 5ddb770d..a5cce579 100644 --- a/src/parser/svelte-ast-types.ts +++ b/src/parser/svelte-ast-types.ts @@ -106,12 +106,22 @@ export interface KeyBlock extends BaseNode { children: TemplateNode[] } -export interface Element extends BaseNode { +export interface BaseElement extends BaseNode { type: "Element" name: string children: TemplateNode[] attributes: AttributeOrDirective[] } + +export interface BasicElement extends BaseElement { + tag?: undefined +} +export interface SvelteComponent extends BaseElement { + name: "svelte:element" + tag: ESTree.Expression +} +export type Element = BasicElement | SvelteComponent + export interface BaseInlineComponent extends BaseNode { type: "InlineComponent" name: string diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/01-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/01-input.svelte similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/01-input.svelte rename to tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/01-input.svelte diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/01-no-undef-result.json b/tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/01-no-undef-result.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/01-no-undef-result.json rename to tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/01-no-undef-result.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/01-output.json b/tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/01-output.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/01-output.json rename to tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/01-output.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/01-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/01-scope-output.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/01-scope-output.json rename to tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/01-scope-output.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/02-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/02-input.svelte similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/02-input.svelte rename to tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/02-input.svelte diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/02-no-undef-result.json b/tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/02-no-undef-result.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/02-no-undef-result.json rename to tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/02-no-undef-result.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/02-output.json b/tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/02-output.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/02-output.json rename to tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/02-output.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/02-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/02-scope-output.json similarity index 100% rename from tests/fixtures/parser/ast/docs/template-syntax/15-svelte-component/02-scope-output.json rename to tests/fixtures/parser/ast/docs/template-syntax/15_1-svelte-component/02-scope-output.json diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-input.svelte new file mode 100644 index 00000000..cc47876a --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-input.svelte @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-no-undef-result.json b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-no-undef-result.json new file mode 100644 index 00000000..2f7fc262 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-no-undef-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "no-undef", + "code": "expression", + "line": 1, + "column": 23 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-output.json b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-output.json new file mode 100644 index 00000000..a5e06767 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-output.json @@ -0,0 +1,296 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteElement", + "kind": "special", + "name": { + "type": "SvelteName", + "name": "svelte:element", + "range": [ + 1, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteSpecialDirective", + "kind": "this", + "key": { + "type": "SvelteSpecialDirectiveKey", + "range": [ + 16, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + "expression": { + "type": "Identifier", + "name": "expression", + "range": [ + 22, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 32 + } + } + }, + "range": [ + 16, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 34 + } + } + } + ], + "selfClosing": true, + "range": [ + 0, + 35 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 0, + 35 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + } + } + ], + "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:element", + "range": [ + 1, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "this", + "range": [ + 16, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "expression", + "range": [ + 22, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 33, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 35 + } + } + } + ], + "range": [ + 0, + 35 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/01-scope-output.json new file mode 100644 index 00000000..b7452abe --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/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": "expression", + "range": [ + 22, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 32 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "expression", + "range": [ + 22, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 32 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "expression", + "range": [ + 22, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 32 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-input.svelte new file mode 100644 index 00000000..989c824e --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-input.svelte @@ -0,0 +1,6 @@ + + +Foo diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-output.json b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-output.json new file mode 100644 index 00000000..8bb6ab45 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-output.json @@ -0,0 +1,1147 @@ +{ + "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": "tag", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + "init": { + "type": "Literal", + "raw": "'div'", + "value": "div", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "range": [ + 14, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + ], + "range": [ + 10, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "ExportNamedDeclaration", + "declaration": { + "type": "VariableDeclaration", + "kind": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "handler", + "range": [ + 39, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "init": null, + "range": [ + 39, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + } + ], + "range": [ + 35, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + "source": null, + "specifiers": [], + "range": [ + 28, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 20 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 48, + 57 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + "range": [ + 0, + 57 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 57, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "special", + "name": { + "type": "SvelteName", + "name": "svelte:element", + "range": [ + 60, + 74 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 15 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "EventHandler", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "click", + "range": [ + 89, + 94 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 6, + "column": 35 + } + } + }, + "modifiers": [], + "range": [ + 86, + 94 + ], + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 6, + "column": 35 + } + } + }, + "expression": { + "type": "Identifier", + "name": "handler", + "range": [ + 96, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 37 + }, + "end": { + "line": 6, + "column": 44 + } + } + }, + "range": [ + 86, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 6, + "column": 45 + } + } + }, + { + "type": "SvelteSpecialDirective", + "kind": "this", + "key": { + "type": "SvelteSpecialDirectiveKey", + "range": [ + 75, + 79 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + "expression": { + "type": "Identifier", + "name": "tag", + "range": [ + 81, + 84 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 75, + 85 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 26 + } + } + } + ], + "selfClosing": false, + "range": [ + 59, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 46 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "Foo", + "range": [ + 105, + 108 + ], + "loc": { + "start": { + "line": 6, + "column": 46 + }, + "end": { + "line": 6, + "column": 49 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 108, + 125 + ], + "loc": { + "start": { + "line": 6, + "column": 49 + }, + "end": { + "line": 6, + "column": 66 + } + } + }, + "range": [ + 59, + 125 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 66 + } + } + } + ], + "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": "tag", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "String", + "value": "'div'", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "Keyword", + "value": "export", + "range": [ + 28, + 34 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 7 + } + } + }, + { + "type": "Keyword", + "value": "let", + "range": [ + 35, + 38 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "handler", + "range": [ + 39, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 50, + 56 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 57, + 59 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "svelte:element", + "range": [ + 60, + 74 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 15 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "this", + "range": [ + 75, + 79 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 80, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "tag", + "range": [ + 81, + 84 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 84, + 85 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "on", + "range": [ + 86, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 6, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "click", + "range": [ + 89, + 94 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 6, + "column": 35 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 6, + "column": 35 + }, + "end": { + "line": 6, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 95, + 96 + ], + "loc": { + "start": { + "line": 6, + "column": 36 + }, + "end": { + "line": 6, + "column": 37 + } + } + }, + { + "type": "Identifier", + "value": "handler", + "range": [ + 96, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 37 + }, + "end": { + "line": 6, + "column": 44 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 44 + }, + "end": { + "line": 6, + "column": 45 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 45 + }, + "end": { + "line": 6, + "column": 46 + } + } + }, + { + "type": "HTMLText", + "value": "Foo", + "range": [ + 105, + 108 + ], + "loc": { + "start": { + "line": 6, + "column": 46 + }, + "end": { + "line": 6, + "column": 49 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 108, + 109 + ], + "loc": { + "start": { + "line": 6, + "column": 49 + }, + "end": { + "line": 6, + "column": 50 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 109, + 110 + ], + "loc": { + "start": { + "line": 6, + "column": 50 + }, + "end": { + "line": 6, + "column": 51 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "svelte:element", + "range": [ + 110, + 124 + ], + "loc": { + "start": { + "line": 6, + "column": 51 + }, + "end": { + "line": 6, + "column": 65 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 124, + 125 + ], + "loc": { + "start": { + "line": 6, + "column": 65 + }, + "end": { + "line": 6, + "column": 66 + } + } + } + ], + "range": [ + 0, + 126 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-prefer-const-result.json b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-prefer-const-result.json new file mode 100644 index 00000000..a2f3ac8a --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-prefer-const-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "prefer-const", + "code": "tag", + "line": 2, + "column": 6 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-scope-output.json new file mode 100644 index 00000000..5dac67b2 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/15_2-svelte-element/02-scope-output.json @@ -0,0 +1,502 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "tag", + "identifiers": [ + { + "type": "Identifier", + "name": "tag", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "tag", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "tag", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + "init": { + "type": "Literal", + "raw": "'div'", + "value": "div", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "range": [ + 14, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "tag", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "tag", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "tag", + "range": [ + 81, + 84 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "tag", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + } + ] + }, + { + "name": "handler", + "identifiers": [ + { + "type": "Identifier", + "name": "handler", + "range": [ + 39, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "handler", + "range": [ + 39, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "handler", + "range": [ + 39, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "init": null, + "range": [ + 39, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "handler", + "range": [ + 96, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 37 + }, + "end": { + "line": 6, + "column": 44 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "handler", + "range": [ + 39, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "handler", + "range": [ + 39, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "handler", + "range": [ + 39, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "tag", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "tag", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "handler", + "range": [ + 96, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 37 + }, + "end": { + "line": 6, + "column": 44 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "handler", + "range": [ + 39, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "tag", + "range": [ + 81, + 84 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "tag", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte-element-with-bind-this-input.svelte b/tests/fixtures/parser/ast/svelte-element-with-bind-this-input.svelte new file mode 100644 index 00000000..335344fc --- /dev/null +++ b/tests/fixtures/parser/ast/svelte-element-with-bind-this-input.svelte @@ -0,0 +1,7 @@ + + +Foo diff --git a/tests/fixtures/parser/ast/svelte-element-with-bind-this-output.json b/tests/fixtures/parser/ast/svelte-element-with-bind-this-output.json new file mode 100644 index 00000000..74e9e4f9 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte-element-with-bind-this-output.json @@ -0,0 +1,1400 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "tag", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "init": { + "type": "Literal", + "raw": "'div'", + "value": "div", + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "range": [ + 16, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + ], + "range": [ + 10, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + { + "type": "VariableDeclaration", + "kind": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + "init": null, + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + } + ], + "range": [ + 30, + 36 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 7 + } + } + }, + { + "type": "SvelteReactiveStatement", + "label": { + "type": "Identifier", + "name": "$", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + } + }, + "body": { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "arguments": [ + { + "type": "Identifier", + "name": "a", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + } + } + } + ], + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "console", + "range": [ + 41, + 48 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "log", + "range": [ + 49, + 52 + ], + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + "range": [ + 41, + 52 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + "optional": false, + "range": [ + 41, + 55 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 18 + } + } + }, + "range": [ + 41, + 55 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 18 + } + } + }, + "range": [ + 38, + 55 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 18 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 56, + 65 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + } + }, + "range": [ + 0, + 65 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 65, + 67 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 7, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "special", + "name": { + "type": "SvelteName", + "name": "svelte:element", + "range": [ + 68, + 82 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 15 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Binding", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "this", + "range": [ + 99, + 103 + ], + "loc": { + "start": { + "line": 7, + "column": 32 + }, + "end": { + "line": 7, + "column": 36 + } + } + }, + "modifiers": [], + "range": [ + 94, + 103 + ], + "loc": { + "start": { + "line": 7, + "column": 27 + }, + "end": { + "line": 7, + "column": 36 + } + } + }, + "expression": { + "type": "Identifier", + "name": "a", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 7, + "column": 38 + }, + "end": { + "line": 7, + "column": 39 + } + } + }, + "shorthand": false, + "range": [ + 94, + 107 + ], + "loc": { + "start": { + "line": 7, + "column": 27 + }, + "end": { + "line": 7, + "column": 40 + } + } + }, + { + "type": "SvelteSpecialDirective", + "kind": "this", + "key": { + "type": "SvelteSpecialDirectiveKey", + "range": [ + 83, + 87 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "expression": { + "type": "Identifier", + "name": "tag", + "range": [ + 89, + 92 + ], + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 25 + } + } + }, + "range": [ + 83, + 93 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 26 + } + } + } + ], + "selfClosing": false, + "range": [ + 67, + 108 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 41 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "Foo", + "range": [ + 108, + 111 + ], + "loc": { + "start": { + "line": 7, + "column": 41 + }, + "end": { + "line": 7, + "column": 44 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 111, + 128 + ], + "loc": { + "start": { + "line": 7, + "column": 44 + }, + "end": { + "line": 7, + "column": 61 + } + } + }, + "range": [ + 67, + 128 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 61 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "tag", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + { + "type": "String", + "value": "'div'", + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + { + "type": "Keyword", + "value": "let", + "range": [ + 30, + 33 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "$", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + } + }, + { + "type": "Identifier", + "value": "console", + "range": [ + 41, + 48 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + { + "type": "Identifier", + "value": "log", + "range": [ + 49, + 52 + ], + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 58, + 64 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 65, + 67 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 7, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "svelte:element", + "range": [ + 68, + 82 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 15 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "this", + "range": [ + 83, + 87 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 7, + "column": 20 + }, + "end": { + "line": 7, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "tag", + "range": [ + 89, + 92 + ], + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 7, + "column": 25 + }, + "end": { + "line": 7, + "column": 26 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "bind", + "range": [ + 94, + 98 + ], + "loc": { + "start": { + "line": 7, + "column": 27 + }, + "end": { + "line": 7, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 7, + "column": 31 + }, + "end": { + "line": 7, + "column": 32 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "this", + "range": [ + 99, + 103 + ], + "loc": { + "start": { + "line": 7, + "column": 32 + }, + "end": { + "line": 7, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 7, + "column": 36 + }, + "end": { + "line": 7, + "column": 37 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 7, + "column": 37 + }, + "end": { + "line": 7, + "column": 38 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 7, + "column": 38 + }, + "end": { + "line": 7, + "column": 39 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 7, + "column": 39 + }, + "end": { + "line": 7, + "column": 40 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 107, + 108 + ], + "loc": { + "start": { + "line": 7, + "column": 40 + }, + "end": { + "line": 7, + "column": 41 + } + } + }, + { + "type": "HTMLText", + "value": "Foo", + "range": [ + 108, + 111 + ], + "loc": { + "start": { + "line": 7, + "column": 41 + }, + "end": { + "line": 7, + "column": 44 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 111, + 112 + ], + "loc": { + "start": { + "line": 7, + "column": 44 + }, + "end": { + "line": 7, + "column": 45 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 7, + "column": 45 + }, + "end": { + "line": 7, + "column": 46 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "svelte:element", + "range": [ + 113, + 127 + ], + "loc": { + "start": { + "line": 7, + "column": 46 + }, + "end": { + "line": 7, + "column": 60 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 127, + 128 + ], + "loc": { + "start": { + "line": 7, + "column": 60 + }, + "end": { + "line": 7, + "column": 61 + } + } + } + ], + "range": [ + 0, + 129 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte-element-with-bind-this-scope-output.json b/tests/fixtures/parser/ast/svelte-element-with-bind-this-scope-output.json new file mode 100644 index 00000000..dde610ce --- /dev/null +++ b/tests/fixtures/parser/ast/svelte-element-with-bind-this-scope-output.json @@ -0,0 +1,613 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "tag", + "identifiers": [ + { + "type": "Identifier", + "name": "tag", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "tag", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "tag", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "init": { + "type": "Literal", + "raw": "'div'", + "value": "div", + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "range": [ + 16, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "tag", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "tag", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "tag", + "range": [ + 89, + 92 + ], + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 25 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "tag", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + } + ] + }, + { + "name": "a", + "identifiers": [ + { + "type": "Identifier", + "name": "a", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "a", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + "init": null, + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "a", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "a", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "a", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 7, + "column": 38 + }, + "end": { + "line": 7, + "column": 39 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "a", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "tag", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "tag", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "console", + "range": [ + 41, + 48 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "a", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "a", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "a", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 7, + "column": 38 + }, + "end": { + "line": 7, + "column": 39 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "a", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "tag", + "range": [ + 89, + 92 + ], + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 25 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "tag", + "range": [ + 16, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "console", + "range": [ + 41, + 48 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "console", + "range": [ + 41, + 48 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/tutorial/svelte-element-input.svelte b/tests/fixtures/parser/ast/tutorial/svelte-element-input.svelte new file mode 100644 index 00000000..068f7b3c --- /dev/null +++ b/tests/fixtures/parser/ast/tutorial/svelte-element-input.svelte @@ -0,0 +1,12 @@ + + + + +I'm a {selected} tag diff --git a/tests/fixtures/parser/ast/tutorial/svelte-element-output.json b/tests/fixtures/parser/ast/tutorial/svelte-element-output.json new file mode 100644 index 00000000..fa459ba7 --- /dev/null +++ b/tests/fixtures/parser/ast/tutorial/svelte-element-output.json @@ -0,0 +1,2603 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "Literal", + "raw": "'h1'", + "value": "h1", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Literal", + "raw": "'h3'", + "value": "h3", + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + { + "type": "Literal", + "raw": "'p'", + "value": "p", + "range": [ + 39, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 33 + } + } + } + ], + "range": [ + 26, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 34 + } + } + }, + "range": [ + 16, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 34 + } + } + } + ], + "range": [ + 10, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 35 + } + } + }, + { + "type": "VariableDeclaration", + "kind": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + "init": { + "type": "MemberExpression", + "computed": true, + "object": { + "type": "Identifier", + "name": "options", + "range": [ + 61, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "optional": false, + "property": { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + "range": [ + 61, + 71 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 26 + } + } + }, + "range": [ + 50, + 71 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 26 + } + } + } + ], + "range": [ + 46, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 27 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 73, + 82 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + "range": [ + 0, + 82 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 82, + 84 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "select", + "range": [ + 85, + 91 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Binding", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "value", + "range": [ + 97, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 18 + } + } + }, + "modifiers": [], + "range": [ + 92, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 18 + } + } + }, + "expression": { + "type": "Identifier", + "name": "selected", + "range": [ + 104, + 112 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 28 + } + } + }, + "shorthand": false, + "range": [ + 92, + 113 + ], + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 29 + } + } + } + ], + "selfClosing": false, + "range": [ + 84, + 114 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "\n\t", + "range": [ + 114, + 116 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + { + "type": "SvelteEachBlock", + "expression": { + "type": "Identifier", + "name": "options", + "range": [ + 123, + 130 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 15 + } + } + }, + "context": { + "type": "Identifier", + "name": "option", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 25 + } + } + }, + "index": null, + "key": null, + "children": [ + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "option", + "range": [ + 145, + 151 + ], + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "value", + "range": [ + 152, + 157 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "option", + "range": [ + 159, + 165 + ], + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 23 + } + } + }, + "range": [ + 158, + 166 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 24 + } + } + } + ], + "range": [ + 152, + 166 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 24 + } + } + } + ], + "selfClosing": false, + "range": [ + 144, + 167 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 25 + } + } + }, + "children": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "option", + "range": [ + 168, + 174 + ], + "loc": { + "start": { + "line": 8, + "column": 26 + }, + "end": { + "line": 8, + "column": 32 + } + } + }, + "range": [ + 167, + 175 + ], + "loc": { + "start": { + "line": 8, + "column": 25 + }, + "end": { + "line": 8, + "column": 33 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 175, + 184 + ], + "loc": { + "start": { + "line": 8, + "column": 33 + }, + "end": { + "line": 8, + "column": 42 + } + } + }, + "range": [ + 144, + 184 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 42 + } + } + } + ], + "else": null, + "range": [ + 116, + 193 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 9, + "column": 8 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 193, + 194 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 10, + "column": 0 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 194, + 203 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + "range": [ + 84, + 203 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 203, + 205 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 12, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "special", + "name": { + "type": "SvelteName", + "name": "svelte:element", + "range": [ + 206, + 220 + ], + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 15 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteSpecialDirective", + "kind": "this", + "key": { + "type": "SvelteSpecialDirectiveKey", + "range": [ + 221, + 225 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 12, + "column": 20 + } + } + }, + "expression": { + "type": "Identifier", + "name": "selected", + "range": [ + 227, + 235 + ], + "loc": { + "start": { + "line": 12, + "column": 22 + }, + "end": { + "line": 12, + "column": 30 + } + } + }, + "range": [ + 221, + 236 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 12, + "column": 31 + } + } + } + ], + "selfClosing": false, + "range": [ + 205, + 237 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 32 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "I'm a ", + "range": [ + 237, + 243 + ], + "loc": { + "start": { + "line": 12, + "column": 32 + }, + "end": { + "line": 12, + "column": 38 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "selected", + "range": [ + 244, + 252 + ], + "loc": { + "start": { + "line": 12, + "column": 39 + }, + "end": { + "line": 12, + "column": 47 + } + } + }, + "range": [ + 243, + 253 + ], + "loc": { + "start": { + "line": 12, + "column": 38 + }, + "end": { + "line": 12, + "column": 48 + } + } + }, + { + "type": "SvelteText", + "value": " tag", + "range": [ + 253, + 257 + ], + "loc": { + "start": { + "line": 12, + "column": 48 + }, + "end": { + "line": 12, + "column": 52 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 257, + 274 + ], + "loc": { + "start": { + "line": 12, + "column": 52 + }, + "end": { + "line": 12, + "column": 69 + } + } + }, + "range": [ + 205, + 274 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 69 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "[", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + { + "type": "String", + "value": "'h1'", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "String", + "value": "'h3'", + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + } + } + }, + { + "type": "String", + "value": "'p'", + "range": [ + 39, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": "]", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 35 + } + } + }, + { + "type": "Keyword", + "value": "let", + "range": [ + 46, + 49 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + { + "type": "Identifier", + "value": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "Identifier", + "value": "options", + "range": [ + 61, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "[", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + } + } + }, + { + "type": "Numeric", + "value": "0", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "]", + "range": [ + 70, + 71 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 3, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 71, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 75, + 81 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 82, + 84 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 84, + 85 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "select", + "range": [ + 85, + 91 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "bind", + "range": [ + 92, + 96 + ], + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 96, + 97 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "value", + "range": [ + 97, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + { + "type": "Identifier", + "value": "selected", + "range": [ + 104, + 112 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 6, + "column": 28 + }, + "end": { + "line": 6, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 113, + 114 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + { + "type": "HTMLText", + "value": "\n\t", + "range": [ + 114, + 116 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 2 + } + } + }, + { + "type": "MustacheKeyword", + "value": "#each", + "range": [ + 117, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "options", + "range": [ + 123, + 130 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 15 + } + } + }, + { + "type": "Keyword", + "value": "as", + "range": [ + 131, + 133 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "option", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 7, + "column": 25 + }, + "end": { + "line": 7, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "option", + "range": [ + 145, + 151 + ], + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "value", + "range": [ + 152, + 157 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 157, + 158 + ], + "loc": { + "start": { + "line": 8, + "column": 15 + }, + "end": { + "line": 8, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 158, + 159 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "option", + "range": [ + 159, + 165 + ], + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 8, + "column": 23 + }, + "end": { + "line": 8, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 8, + "column": 24 + }, + "end": { + "line": 8, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 8, + "column": 25 + }, + "end": { + "line": 8, + "column": 26 + } + } + }, + { + "type": "Identifier", + "value": "option", + "range": [ + 168, + 174 + ], + "loc": { + "start": { + "line": 8, + "column": 26 + }, + "end": { + "line": 8, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 174, + 175 + ], + "loc": { + "start": { + "line": 8, + "column": 32 + }, + "end": { + "line": 8, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 8, + "column": 33 + }, + "end": { + "line": 8, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 8, + "column": 34 + }, + "end": { + "line": 8, + "column": 35 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "option", + "range": [ + 177, + 183 + ], + "loc": { + "start": { + "line": 8, + "column": 35 + }, + "end": { + "line": 8, + "column": 41 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 183, + 184 + ], + "loc": { + "start": { + "line": 8, + "column": 41 + }, + "end": { + "line": 8, + "column": 42 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 186, + 187 + ], + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + { + "type": "MustacheKeyword", + "value": "/each", + "range": [ + 187, + 192 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 192, + 193 + ], + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 193, + 194 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 10, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 194, + 195 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 195, + 196 + ], + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "select", + "range": [ + 196, + 202 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 202, + 203 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 203, + 205 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 12, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 205, + 206 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "svelte:element", + "range": [ + 206, + 220 + ], + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 15 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "this", + "range": [ + 221, + 225 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 12, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 225, + 226 + ], + "loc": { + "start": { + "line": 12, + "column": 20 + }, + "end": { + "line": 12, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 226, + 227 + ], + "loc": { + "start": { + "line": 12, + "column": 21 + }, + "end": { + "line": 12, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "selected", + "range": [ + 227, + 235 + ], + "loc": { + "start": { + "line": 12, + "column": 22 + }, + "end": { + "line": 12, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 235, + 236 + ], + "loc": { + "start": { + "line": 12, + "column": 30 + }, + "end": { + "line": 12, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 236, + 237 + ], + "loc": { + "start": { + "line": 12, + "column": 31 + }, + "end": { + "line": 12, + "column": 32 + } + } + }, + { + "type": "HTMLText", + "value": "I'm", + "range": [ + 237, + 240 + ], + "loc": { + "start": { + "line": 12, + "column": 32 + }, + "end": { + "line": 12, + "column": 35 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 240, + 241 + ], + "loc": { + "start": { + "line": 12, + "column": 35 + }, + "end": { + "line": 12, + "column": 36 + } + } + }, + { + "type": "HTMLText", + "value": "a", + "range": [ + 241, + 242 + ], + "loc": { + "start": { + "line": 12, + "column": 36 + }, + "end": { + "line": 12, + "column": 37 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 242, + 243 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 38 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 243, + 244 + ], + "loc": { + "start": { + "line": 12, + "column": 38 + }, + "end": { + "line": 12, + "column": 39 + } + } + }, + { + "type": "Identifier", + "value": "selected", + "range": [ + 244, + 252 + ], + "loc": { + "start": { + "line": 12, + "column": 39 + }, + "end": { + "line": 12, + "column": 47 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 252, + 253 + ], + "loc": { + "start": { + "line": 12, + "column": 47 + }, + "end": { + "line": 12, + "column": 48 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 253, + 254 + ], + "loc": { + "start": { + "line": 12, + "column": 48 + }, + "end": { + "line": 12, + "column": 49 + } + } + }, + { + "type": "HTMLText", + "value": "tag", + "range": [ + 254, + 257 + ], + "loc": { + "start": { + "line": 12, + "column": 49 + }, + "end": { + "line": 12, + "column": 52 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 257, + 258 + ], + "loc": { + "start": { + "line": 12, + "column": 52 + }, + "end": { + "line": 12, + "column": 53 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 258, + 259 + ], + "loc": { + "start": { + "line": 12, + "column": 53 + }, + "end": { + "line": 12, + "column": 54 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "svelte:element", + "range": [ + 259, + 273 + ], + "loc": { + "start": { + "line": 12, + "column": 54 + }, + "end": { + "line": 12, + "column": 68 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 273, + 274 + ], + "loc": { + "start": { + "line": 12, + "column": 68 + }, + "end": { + "line": 12, + "column": 69 + } + } + } + ], + "range": [ + 0, + 275 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 13, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/tutorial/svelte-element-scope-output.json b/tests/fixtures/parser/ast/tutorial/svelte-element-scope-output.json new file mode 100644 index 00000000..1ffb9b82 --- /dev/null +++ b/tests/fixtures/parser/ast/tutorial/svelte-element-scope-output.json @@ -0,0 +1,1355 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "options", + "identifiers": [ + { + "type": "Identifier", + "name": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "Literal", + "raw": "'h1'", + "value": "h1", + "range": [ + 27, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Literal", + "raw": "'h3'", + "value": "h3", + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + { + "type": "Literal", + "raw": "'p'", + "value": "p", + "range": [ + 39, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 33 + } + } + } + ], + "range": [ + 26, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 34 + } + } + }, + "range": [ + 16, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 34 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "options", + "range": [ + 61, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "options", + "range": [ + 123, + 130 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 15 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + } + ] + }, + { + "name": "selected", + "identifiers": [ + { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + "init": { + "type": "MemberExpression", + "computed": true, + "object": { + "type": "Identifier", + "name": "options", + "range": [ + 61, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "optional": false, + "property": { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + "range": [ + 61, + 71 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 26 + } + } + }, + "range": [ + 50, + 71 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 26 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "selected", + "range": [ + 104, + 112 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 28 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "selected", + "range": [ + 244, + 252 + ], + "loc": { + "start": { + "line": 12, + "column": 39 + }, + "end": { + "line": 12, + "column": 47 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "selected", + "range": [ + 227, + 235 + ], + "loc": { + "start": { + "line": 12, + "column": 22 + }, + "end": { + "line": 12, + "column": 30 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "options", + "range": [ + 61, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "selected", + "range": [ + 104, + 112 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 28 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "options", + "range": [ + 123, + 130 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 15 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "options", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "selected", + "range": [ + 244, + 252 + ], + "loc": { + "start": { + "line": 12, + "column": 39 + }, + "end": { + "line": 12, + "column": 47 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "selected", + "range": [ + 227, + 235 + ], + "loc": { + "start": { + "line": 12, + "column": 22 + }, + "end": { + "line": 12, + "column": 30 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "selected", + "range": [ + 50, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 13 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "option", + "identifiers": [ + { + "type": "Identifier", + "name": "option", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 25 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "option", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 25 + } + } + }, + "node": { + "type": "SvelteEachBlock", + "expression": { + "type": "Identifier", + "name": "options", + "range": [ + 123, + 130 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 15 + } + } + }, + "context": { + "type": "Identifier", + "name": "option", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 25 + } + } + }, + "index": null, + "key": null, + "children": [ + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "option", + "range": [ + 145, + 151 + ], + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "value", + "range": [ + 152, + 157 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "option", + "range": [ + 159, + 165 + ], + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 23 + } + } + }, + "range": [ + 158, + 166 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 24 + } + } + } + ], + "range": [ + 152, + 166 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 24 + } + } + } + ], + "selfClosing": false, + "range": [ + 144, + 167 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 25 + } + } + }, + "children": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "option", + "range": [ + 168, + 174 + ], + "loc": { + "start": { + "line": 8, + "column": 26 + }, + "end": { + "line": 8, + "column": 32 + } + } + }, + "range": [ + 167, + 175 + ], + "loc": { + "start": { + "line": 8, + "column": 25 + }, + "end": { + "line": 8, + "column": 33 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 175, + 184 + ], + "loc": { + "start": { + "line": 8, + "column": 33 + }, + "end": { + "line": 8, + "column": 42 + } + } + }, + "range": [ + 144, + 184 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 42 + } + } + } + ], + "else": null, + "range": [ + 116, + 193 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 9, + "column": 8 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "option", + "range": [ + 159, + 165 + ], + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 23 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "option", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 25 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "option", + "range": [ + 168, + 174 + ], + "loc": { + "start": { + "line": 8, + "column": 26 + }, + "end": { + "line": 8, + "column": 32 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "option", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 25 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "option", + "range": [ + 159, + 165 + ], + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 23 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "option", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 25 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "option", + "range": [ + 168, + 174 + ], + "loc": { + "start": { + "line": 8, + "column": 26 + }, + "end": { + "line": 8, + "column": 32 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "option", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 25 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file