From 4a2cc84acf63bec24fd412d5545cd665a4a252da Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Mon, 20 Nov 2023 23:09:01 +0900 Subject: [PATCH 1/2] feat: improve props type --- src/parser/converts/attr.ts | 95 +- src/parser/converts/element.ts | 2 +- src/parser/converts/mustache.ts | 7 +- .../ast/svelte5/ts-event01-input.svelte | 5 + .../ts-event01-no-unused-vars-result.json | 14 + .../parser/ast/svelte5/ts-event01-output.json | 1577 ++++++++++ .../ast/svelte5/ts-event01-requirements.json | 5 + .../ast/svelte5/ts-event01-scope-output.json | 452 +++ .../ast/svelte5/ts-event02-input.svelte | 5 + .../ts-event02-no-unused-vars-result.json | 14 + .../parser/ast/svelte5/ts-event02-output.json | 1577 ++++++++++ .../ast/svelte5/ts-event02-requirements.json | 6 + .../ast/svelte5/ts-event02-scope-output.json | 452 +++ .../ast/svelte5/ts-event02-type-output.svelte | 5 + .../ast/svelte5/ts-event03-input.svelte | 13 + ...-event03-no-unused-expressions-result.json | 14 + .../ts-event03-no-unused-vars-result.json | 8 + .../parser/ast/svelte5/ts-event03-output.json | 2777 +++++++++++++++++ .../ast/svelte5/ts-event03-requirements.json | 8 + .../ast/svelte5/ts-event03-scope-output.json | 1720 ++++++++++ .../ast/svelte5/ts-event03-type-output.svelte | 13 + .../ast/svelte5/ts-event04-input.svelte | 6 + ...-event04-no-unused-expressions-result.json | 8 + .../parser/ast/svelte5/ts-event04-output.json | 1044 +++++++ .../ast/svelte5/ts-event04-requirements.json | 5 + .../ast/svelte5/ts-event04-scope-output.json | 328 ++ .../ast/svelte5/ts-event04-type-output.svelte | 6 + .../ast/svelte5/ts-event05-input.svelte | 11 + ...-event05-no-unused-expressions-result.json | 8 + .../parser/ast/svelte5/ts-event05-output.json | 1212 +++++++ .../ast/svelte5/ts-event05-requirements.json | 5 + .../ast/svelte5/ts-event05-scope-output.json | 493 +++ .../ast/svelte5/ts-event05-type-output.svelte | 11 + .../parser/ast/svelte5/ts-event06-config.json | 3 + .../ast/svelte5/ts-event06-input.svelte | 8 + ...-event06-no-unused-expressions-result.json | 8 + .../parser/ast/svelte5/ts-event06-output.json | 1158 +++++++ .../ast/svelte5/ts-event06-requirements.json | 5 + .../ast/svelte5/ts-event06-scope-output.json | 493 +++ .../ast/svelte5/ts-event06-type-output.svelte | 8 + tools/update-fixtures.ts | 7 + 41 files changed, 13579 insertions(+), 17 deletions(-) create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event01-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event01-no-unused-vars-result.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event01-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event01-requirements.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event01-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event02-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event02-no-unused-vars-result.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event02-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event02-requirements.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event02-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event02-type-output.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event03-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event03-no-unused-expressions-result.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event03-no-unused-vars-result.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event03-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event03-requirements.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event03-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event03-type-output.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event04-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event04-no-unused-expressions-result.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event04-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event04-requirements.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event04-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event04-type-output.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event05-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event05-no-unused-expressions-result.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event05-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event05-requirements.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event05-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event05-type-output.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event06-config.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event06-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event06-no-unused-expressions-result.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event06-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event06-requirements.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event06-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event06-type-output.svelte diff --git a/src/parser/converts/attr.ts b/src/parser/converts/attr.ts index 19d16af1..adc6d753 100644 --- a/src/parser/converts/attr.ts +++ b/src/parser/converts/attr.ts @@ -33,6 +33,7 @@ import { import { ParseError } from "../../errors"; import type { ScriptLetCallback } from "../../context/script-let"; import type { AttributeToken } from "../html"; +import { svelteVersion } from "../svelte-version"; /** Convert for Attributes */ export function* convertAttributes( @@ -200,6 +201,7 @@ function convertAttribute( processAttributeValue( node.value as (SvAST.Text | SvAST.MustacheTag)[], attribute, + parent, ctx, ); @@ -213,27 +215,51 @@ function convertAttribute( function processAttributeValue( nodeValue: (SvAST.Text | SvAST.MustacheTag)[], attribute: SvelteAttribute | SvelteStyleDirectiveLongform, + attributeParent: (SvelteAttribute | SvelteStyleDirectiveLongform)["parent"], ctx: Context, ) { - for (let index = 0; index < nodeValue.length; index++) { - const v = nodeValue[index]; - if (v.type === "Text") { - if (v.start === v.end) { - // Empty + const nodes = nodeValue + .filter( + (v) => + v.type !== "Text" || + // ignore empty // https://github.com/sveltejs/svelte/pull/6539 - continue; - } - const next = nodeValue[index + 1]; - if (next && next.start < v.end) { - // Maybe bug in Svelte can cause the completion index to shift. - // console.log(ctx.getText(v), v.data) - v.end = next.start; + v.start < v.end, + ) + .map((v, index, array) => { + if (v.type === "Text") { + const next = array[index + 1]; + if (next && next.start < v.end) { + // Maybe bug in Svelte can cause the completion index to shift. + return { + ...v, + end: next.start, + }; + } } + return v; + }); + if ( + nodes.length === 1 && + nodes[0].type === "MustacheTag" && + attribute.type === "SvelteAttribute" + ) { + const typing = buildAttributeType( + attributeParent.parent, + attribute.key.name, + ctx, + ); + const mustache = convertMustacheTag(nodes[0], attribute, typing, ctx); + attribute.value.push(mustache); + return; + } + for (const v of nodes) { + if (v.type === "Text") { attribute.value.push(convertTextToLiteral(v, attribute, ctx)); continue; } if (v.type === "MustacheTag") { - const mustache = convertMustacheTag(v, attribute, ctx); + const mustache = convertMustacheTag(v, attribute, null, ctx); attribute.value.push(mustache); continue; } @@ -246,6 +272,47 @@ function processAttributeValue( } } +/** Build attribute type */ +function buildAttributeType( + element: SvelteElement | SvelteScriptElement | SvelteStyleElement, + attrName: string, + ctx: Context, +) { + if ( + svelteVersion.gte(5) && + attrName.startsWith("on") && + (element.type !== "SvelteElement" || element.kind === "html") + ) { + return buildEventHandlerType(element, attrName.slice(2), ctx); + } + if (element.type !== "SvelteElement" || element.kind !== "component") { + return null; + } + const elementName = ctx.elements.get(element)!.name; + const componentPropsType = `import('svelte').ComponentProps<${elementName}>`; + return conditional({ + check: `'${attrName}'`, + extends: `infer PROP`, + true: conditional({ + check: `PROP`, + extends: `keyof ${componentPropsType}`, + true: `${componentPropsType}[PROP]`, + false: `never`, + }), + false: `never`, + }); + + /** Generate `C extends E ? T : F` type. */ + function conditional(types: { + check: string; + extends: string; + true: string; + false: string; + }) { + return `${types.check} extends ${types.extends}?(${types.true}):(${types.false})`; + } +} + /** Convert for Spread */ function convertSpreadAttribute( node: SvAST.Spread, @@ -491,7 +558,7 @@ function convertStyleDirective( end: keyName.range[1], }); - processAttributeValue(node.value, directive, ctx); + processAttributeValue(node.value, directive, parent, ctx); return directive; } diff --git a/src/parser/converts/element.ts b/src/parser/converts/element.ts index 7255d8f7..1970838d 100644 --- a/src/parser/converts/element.ts +++ b/src/parser/converts/element.ts @@ -117,7 +117,7 @@ export function* convertChildren( continue; } if (child.type === "MustacheTag") { - yield convertMustacheTag(child, parent, ctx); + yield convertMustacheTag(child, parent, null, ctx); continue; } if (child.type === "RawMustacheTag") { diff --git a/src/parser/converts/mustache.ts b/src/parser/converts/mustache.ts index d784bf87..757f96e1 100644 --- a/src/parser/converts/mustache.ts +++ b/src/parser/converts/mustache.ts @@ -10,9 +10,10 @@ import type * as SvAST from "../svelte-ast-types"; export function convertMustacheTag( node: SvAST.MustacheTag, parent: SvelteMustacheTag["parent"], + typing: string | null, ctx: Context, ): SvelteMustacheTagText { - return convertMustacheTag0(node, "text", parent, ctx); + return convertMustacheTag0(node, "text", parent, typing, ctx); } /** Convert for MustacheTag */ export function convertRawMustacheTag( @@ -24,6 +25,7 @@ export function convertRawMustacheTag( node, "raw", parent, + null, ctx, ); const atHtmlStart = ctx.code.indexOf("@html", mustache.range[0]); @@ -64,6 +66,7 @@ function convertMustacheTag0( node: SvAST.MustacheTag | SvAST.RawMustacheTag, kind: T["kind"], parent: T["parent"], + typing: string | null, ctx: Context, ): T { const mustache = { @@ -73,7 +76,7 @@ function convertMustacheTag0( parent, ...ctx.getConvertLocation(node), } as T; - ctx.scriptLet.addExpression(node.expression, mustache, null, (es) => { + ctx.scriptLet.addExpression(node.expression, mustache, typing, (es) => { mustache.expression = es; }); return mustache; diff --git a/tests/fixtures/parser/ast/svelte5/ts-event01-input.svelte b/tests/fixtures/parser/ast/svelte5/ts-event01-input.svelte new file mode 100644 index 00000000..8033e190 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event01-input.svelte @@ -0,0 +1,5 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-event01-no-unused-vars-result.json b/tests/fixtures/parser/ast/svelte5/ts-event01-no-unused-vars-result.json new file mode 100644 index 00000000..13b5b81c --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event01-no-unused-vars-result.json @@ -0,0 +1,14 @@ +[ + { + "ruleId": "no-unused-vars", + "code": "e", + "line": 4, + "column": 19 + }, + { + "ruleId": "no-unused-vars", + "code": "e", + "line": 5, + "column": 22 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event01-output.json b/tests/fixtures/parser/ast/svelte5/ts-event01-output.json new file mode 100644 index 00000000..024511a7 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event01-output.json @@ -0,0 +1,1577 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteLiteral", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ], + "range": [ + 8, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 17 + } + } + } + ], + "selfClosing": false, + "range": [ + 0, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + "body": [ + { + "type": "ImportDeclaration", + "importKind": "value", + "source": { + "type": "Literal", + "raw": "'foo.svelte'", + "value": "foo.svelte", + "range": [ + 45, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 38 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + ], + "range": [ + 23, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 38 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 58, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 67 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 4, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "button", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "onclick", + "range": [ + 76, + 83 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 89, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 23 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + } + } + ], + "range": [ + 86, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 23 + } + } + }, + "range": [ + 85, + 92 + ], + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 24 + } + } + } + ], + "range": [ + 76, + 93 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 25 + } + } + } + ], + "selfClosing": false, + "range": [ + 68, + 94 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 26 + } + } + }, + "children": [], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 94, + 103 + ], + "loc": { + "start": { + "line": 4, + "column": 26 + }, + "end": { + "line": 4, + "column": 35 + } + } + }, + "range": [ + 68, + 103 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 35 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 35 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "component", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 105, + 114 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "onclick", + "range": [ + 115, + 122 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 128, + 130 + ], + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 26 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + } + } + ], + "range": [ + 125, + 130 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 26 + } + } + }, + "range": [ + 124, + 131 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 27 + } + } + } + ], + "range": [ + 115, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 28 + } + } + } + ], + "selfClosing": false, + "range": [ + 104, + 133 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 29 + } + } + }, + "children": [], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 133, + 145 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 41 + } + } + }, + "range": [ + 104, + 145 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 41 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "HTMLText", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Keyword", + "value": "import", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "Identifier", + "value": "from", + "range": [ + 40, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "String", + "value": "'foo.svelte'", + "range": [ + 45, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 38 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 60, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 66, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 4, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "onclick", + "range": [ + 76, + 83 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 84, + 85 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 87, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 19 + }, + "end": { + "line": 4, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 4, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 4, + "column": 24 + }, + "end": { + "line": 4, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 93, + 94 + ], + "loc": { + "start": { + "line": 4, + "column": 25 + }, + "end": { + "line": 4, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 4, + "column": 26 + }, + "end": { + "line": 4, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 95, + 96 + ], + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 4, + "column": 28 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 96, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 28 + }, + "end": { + "line": 4, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 4, + "column": 34 + }, + "end": { + "line": 4, + "column": 35 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 35 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Identifier", + "value": "Component", + "range": [ + 105, + 114 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "onclick", + "range": [ + 115, + 122 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 122, + 123 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 123, + 124 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 124, + 125 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 126, + 128 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 128, + 129 + ], + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 130, + 131 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 5, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 5, + "column": 28 + }, + "end": { + "line": 5, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 5, + "column": 30 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "Component", + "range": [ + 135, + 144 + ], + "loc": { + "start": { + "line": 5, + "column": 31 + }, + "end": { + "line": 5, + "column": 40 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 5, + "column": 40 + }, + "end": { + "line": 5, + "column": 41 + } + } + } + ], + "range": [ + 0, + 146 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event01-requirements.json b/tests/fixtures/parser/ast/svelte5/ts-event01-requirements.json new file mode 100644 index 00000000..b0d8202a --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event01-requirements.json @@ -0,0 +1,5 @@ +{ + "scope": { + "@typescript-eslint/parser": ">=6.5.0" + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event01-scope-output.json b/tests/fixtures/parser/ast/svelte5/ts-event01-scope-output.json new file mode 100644 index 00000000..fd4ca9f8 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event01-scope-output.json @@ -0,0 +1,452 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "Component", + "identifiers": [ + { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "node": { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 105, + 114 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 105, + 114 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 89, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 23 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + } + } + ], + "range": [ + 86, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 23 + } + } + } + } + ], + "references": [] + } + ], + "references": [], + "childScopes": [], + "through": [] + }, + { + "type": "function", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 128, + 130 + ], + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 26 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + } + } + ], + "range": [ + 125, + 130 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 26 + } + } + } + } + ], + "references": [] + } + ], + "references": [], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event02-input.svelte b/tests/fixtures/parser/ast/svelte5/ts-event02-input.svelte new file mode 100644 index 00000000..c079afb3 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event02-input.svelte @@ -0,0 +1,5 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-event02-no-unused-vars-result.json b/tests/fixtures/parser/ast/svelte5/ts-event02-no-unused-vars-result.json new file mode 100644 index 00000000..13b5b81c --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event02-no-unused-vars-result.json @@ -0,0 +1,14 @@ +[ + { + "ruleId": "no-unused-vars", + "code": "e", + "line": 4, + "column": 19 + }, + { + "ruleId": "no-unused-vars", + "code": "e", + "line": 5, + "column": 22 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event02-output.json b/tests/fixtures/parser/ast/svelte5/ts-event02-output.json new file mode 100644 index 00000000..83d40f33 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event02-output.json @@ -0,0 +1,1577 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteLiteral", + "value": "typescript", + "range": [ + 14, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 24 + } + } + } + ], + "range": [ + 8, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 25 + } + } + } + ], + "selfClosing": false, + "range": [ + 0, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + "body": [ + { + "type": "ImportDeclaration", + "importKind": "value", + "source": { + "type": "Literal", + "raw": "'foo.svelte'", + "value": "foo.svelte", + "range": [ + 53, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 38 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 38, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "range": [ + 38, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + ], + "range": [ + 31, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 38 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 66, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 75 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 4, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "button", + "range": [ + 77, + 83 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "onclick", + "range": [ + 84, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 97, + 99 + ], + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 23 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + } + } + ], + "range": [ + 94, + 99 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 23 + } + } + }, + "range": [ + 93, + 100 + ], + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 24 + } + } + } + ], + "range": [ + 84, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 25 + } + } + } + ], + "selfClosing": false, + "range": [ + 76, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 26 + } + } + }, + "children": [], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 102, + 111 + ], + "loc": { + "start": { + "line": 4, + "column": 26 + }, + "end": { + "line": 4, + "column": 35 + } + } + }, + "range": [ + 76, + 111 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 35 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 111, + 112 + ], + "loc": { + "start": { + "line": 4, + "column": 35 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "component", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 113, + 122 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "onclick", + "range": [ + 123, + 130 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 136, + 138 + ], + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 26 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + } + } + ], + "range": [ + 133, + 138 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 26 + } + } + }, + "range": [ + 132, + 139 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 27 + } + } + } + ], + "range": [ + 123, + 140 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 28 + } + } + } + ], + "selfClosing": false, + "range": [ + 112, + 141 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 29 + } + } + }, + "children": [], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 141, + 153 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 41 + } + } + }, + "range": [ + 112, + 153 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 41 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "HTMLText", + "value": "typescript", + "range": [ + 14, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + { + "type": "Keyword", + "value": "import", + "range": [ + 31, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "Component", + "range": [ + 38, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "Identifier", + "value": "from", + "range": [ + 48, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "String", + "value": "'foo.svelte'", + "range": [ + 53, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 38 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 66, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 68, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 4, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 77, + 83 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "onclick", + "range": [ + 84, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 93, + 94 + ], + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 95, + 97 + ], + "loc": { + "start": { + "line": 4, + "column": 19 + }, + "end": { + "line": 4, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 4, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 24 + }, + "end": { + "line": 4, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 25 + }, + "end": { + "line": 4, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 4, + "column": 26 + }, + "end": { + "line": 4, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 4, + "column": 28 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 104, + 110 + ], + "loc": { + "start": { + "line": 4, + "column": 28 + }, + "end": { + "line": 4, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "line": 4, + "column": 34 + }, + "end": { + "line": 4, + "column": 35 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 111, + 112 + ], + "loc": { + "start": { + "line": 4, + "column": 35 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Identifier", + "value": "Component", + "range": [ + 113, + 122 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "onclick", + "range": [ + 123, + 130 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 130, + 131 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 134, + 136 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 137, + 138 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 138, + 139 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 5, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 5, + "column": 28 + }, + "end": { + "line": 5, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 141, + 142 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 142, + 143 + ], + "loc": { + "start": { + "line": 5, + "column": 30 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "Component", + "range": [ + 143, + 152 + ], + "loc": { + "start": { + "line": 5, + "column": 31 + }, + "end": { + "line": 5, + "column": 40 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 152, + 153 + ], + "loc": { + "start": { + "line": 5, + "column": 40 + }, + "end": { + "line": 5, + "column": 41 + } + } + } + ], + "range": [ + 0, + 154 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event02-requirements.json b/tests/fixtures/parser/ast/svelte5/ts-event02-requirements.json new file mode 100644 index 00000000..b0822c89 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event02-requirements.json @@ -0,0 +1,6 @@ + +{ + "scope": { + "@typescript-eslint/parser": ">=6.5.0" + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event02-scope-output.json b/tests/fixtures/parser/ast/svelte5/ts-event02-scope-output.json new file mode 100644 index 00000000..7382637a --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event02-scope-output.json @@ -0,0 +1,452 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "Component", + "identifiers": [ + { + "type": "Identifier", + "name": "Component", + "range": [ + 38, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 38, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "node": { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 38, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "range": [ + 38, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 113, + 122 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 38, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 113, + 122 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 38, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 97, + 99 + ], + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 23 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + } + } + ], + "range": [ + 94, + 99 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 23 + } + } + } + } + ], + "references": [] + } + ], + "references": [], + "childScopes": [], + "through": [] + }, + { + "type": "function", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 136, + 138 + ], + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 26 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + } + } + ], + "range": [ + 133, + 138 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 26 + } + } + } + } + ], + "references": [] + } + ], + "references": [], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event02-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-event02-type-output.svelte new file mode 100644 index 00000000..e7ffa138 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event02-type-output.svelte @@ -0,0 +1,5 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-event03-input.svelte b/tests/fixtures/parser/ast/svelte5/ts-event03-input.svelte new file mode 100644 index 00000000..afb1098f --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event03-input.svelte @@ -0,0 +1,13 @@ + + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-event03-no-unused-expressions-result.json b/tests/fixtures/parser/ast/svelte5/ts-event03-no-unused-expressions-result.json new file mode 100644 index 00000000..ad8bb47e --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event03-no-unused-expressions-result.json @@ -0,0 +1,14 @@ +[ + { + "ruleId": "no-unused-expressions", + "code": "e.currentTarget;", + "line": 9, + "column": 5 + }, + { + "ruleId": "no-unused-expressions", + "code": "e.currentTarget;", + "line": 12, + "column": 5 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event03-no-unused-vars-result.json b/tests/fixtures/parser/ast/svelte5/ts-event03-no-unused-vars-result.json new file mode 100644 index 00000000..45a9b1af --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event03-no-unused-vars-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "no-unused-vars", + "code": "e: { detail: number }", + "line": 3, + "column": 17 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event03-output.json b/tests/fixtures/parser/ast/svelte5/ts-event03-output.json new file mode 100644 index 00000000..7cd7a34d --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event03-output.json @@ -0,0 +1,2777 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteLiteral", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ], + "range": [ + 8, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 17 + } + } + } + ], + "selfClosing": false, + "range": [ + 0, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "method": false, + "shorthand": true, + "value": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + ], + "range": [ + 29, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "Identifier", + "name": "$props", + "range": [ + 39, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + "optional": false, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSFunctionType", + "params": [ + { + "type": "Identifier", + "name": "e", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "detail", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 77, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 3, + "column": 35 + } + } + }, + "range": [ + 75, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 35 + } + } + }, + "range": [ + 69, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 35 + } + } + } + ], + "range": [ + 67, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 37 + } + } + }, + "range": [ + 65, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 37 + } + } + }, + "range": [ + 64, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 37 + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSVoidKeyword", + "range": [ + 90, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 42 + }, + "end": { + "line": 3, + "column": 46 + } + } + }, + "range": [ + 87, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 39 + }, + "end": { + "line": 3, + "column": 46 + } + } + }, + "range": [ + 63, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 46 + } + } + }, + "range": [ + 61, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 46 + } + } + }, + "range": [ + 56, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 46 + } + } + } + ], + "range": [ + 46, + 100 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 4, + "column": 5 + } + } + } + ], + "range": [ + 45, + 101 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 4, + "column": 6 + } + } + }, + "range": [ + 39, + 103 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + "range": [ + 29, + 103 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 4, + "column": 8 + } + } + } + ], + "range": [ + 23, + 103 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "arguments": [ + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "detail", + "range": [ + 115, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + "method": false, + "shorthand": false, + "value": { + "type": "Literal", + "raw": "1", + "value": 1, + "range": [ + 123, + 124 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + "range": [ + 115, + 124 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + ], + "range": [ + 114, + 125 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 21 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 108, + 113 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 9 + } + } + }, + "optional": false, + "range": [ + 108, + 126 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 22 + } + } + }, + "range": [ + 108, + 126 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 22 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 127, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + "range": [ + 0, + 136 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 136, + 138 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 8, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "button", + "range": [ + 139, + 145 + ], + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "onclick", + "range": [ + 146, + 153 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "e", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "currentTarget", + "range": [ + 167, + 180 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 19 + } + } + }, + "range": [ + 165, + 180 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 19 + } + } + }, + "range": [ + 165, + 181 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 20 + } + } + } + ], + "range": [ + 159, + 183 + ], + "loc": { + "start": { + "line": 8, + "column": 21 + }, + "end": { + "line": 10, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 156, + 157 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + } + } + ], + "range": [ + 156, + 183 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 10, + "column": 1 + } + } + }, + "range": [ + 155, + 184 + ], + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 10, + "column": 2 + } + } + } + ], + "range": [ + 146, + 185 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 10, + "column": 3 + } + } + } + ], + "selfClosing": false, + "range": [ + 138, + 186 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 10, + "column": 4 + } + } + }, + "children": [], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 186, + 195 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 13 + } + } + }, + "range": [ + 138, + 195 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 10, + "column": 13 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 195, + 196 + ], + "loc": { + "start": { + "line": 10, + "column": 13 + }, + "end": { + "line": 11, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "input", + "range": [ + 197, + 202 + ], + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 11, + "column": 6 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "oninput", + "range": [ + 203, + 210 + ], + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 14 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "e", + "range": [ + 222, + 223 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 5 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "currentTarget", + "range": [ + 224, + 237 + ], + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 12, + "column": 19 + } + } + }, + "range": [ + 222, + 237 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 19 + } + } + }, + "range": [ + 222, + 238 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 20 + } + } + } + ], + "range": [ + 216, + 240 + ], + "loc": { + "start": { + "line": 11, + "column": 20 + }, + "end": { + "line": 13, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 213, + 214 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 11, + "column": 18 + } + } + } + ], + "range": [ + 213, + 240 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 13, + "column": 1 + } + } + }, + "range": [ + 212, + 241 + ], + "loc": { + "start": { + "line": 11, + "column": 16 + }, + "end": { + "line": 13, + "column": 2 + } + } + } + ], + "range": [ + 203, + 242 + ], + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 13, + "column": 3 + } + } + } + ], + "selfClosing": false, + "range": [ + 196, + 243 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 13, + "column": 4 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 196, + 243 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 13, + "column": 4 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "HTMLText", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 23, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + { + "type": "Identifier", + "value": "$props", + "range": [ + 39, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + { + "type": "Identifier", + "value": "onfoo", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 16 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "Identifier", + "value": "detail", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + { + "type": "Identifier", + "value": "number", + "range": [ + 77, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 3, + "column": 35 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 84, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 36 + }, + "end": { + "line": 3, + "column": 37 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 37 + }, + "end": { + "line": 3, + "column": 38 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 87, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 39 + }, + "end": { + "line": 3, + "column": 41 + } + } + }, + { + "type": "Keyword", + "value": "void", + "range": [ + 90, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 42 + }, + "end": { + "line": 3, + "column": 46 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "onfoo", + "range": [ + 108, + 113 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 113, + 114 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 114, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "detail", + "range": [ + 115, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 121, + 122 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + { + "type": "Numeric", + "value": "1", + "range": [ + 123, + 124 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 124, + 125 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 127, + 128 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 128, + 129 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 129, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 136, + 138 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 8, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 138, + 139 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 139, + 145 + ], + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "onclick", + "range": [ + 146, + 153 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 153, + 154 + ], + "loc": { + "start": { + "line": 8, + "column": 15 + }, + "end": { + "line": 8, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 8, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 155, + 156 + ], + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 156, + 157 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 157, + 159 + ], + "loc": { + "start": { + "line": 8, + "column": 19 + }, + "end": { + "line": 8, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 159, + 160 + ], + "loc": { + "start": { + "line": 8, + "column": 21 + }, + "end": { + "line": 8, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "currentTarget", + "range": [ + 167, + 180 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 180, + 181 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 182, + 183 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 183, + 184 + ], + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 184, + 185 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 185, + 186 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 186, + 187 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 187, + 188 + ], + "loc": { + "start": { + "line": 10, + "column": 5 + }, + "end": { + "line": 10, + "column": 6 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 188, + 194 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 194, + 195 + ], + "loc": { + "start": { + "line": 10, + "column": 12 + }, + "end": { + "line": 10, + "column": 13 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 195, + 196 + ], + "loc": { + "start": { + "line": 10, + "column": 13 + }, + "end": { + "line": 11, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 196, + 197 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "input", + "range": [ + 197, + 202 + ], + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 11, + "column": 6 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "oninput", + "range": [ + 203, + 210 + ], + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 210, + 211 + ], + "loc": { + "start": { + "line": 11, + "column": 14 + }, + "end": { + "line": 11, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 211, + 212 + ], + "loc": { + "start": { + "line": 11, + "column": 15 + }, + "end": { + "line": 11, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 212, + 213 + ], + "loc": { + "start": { + "line": 11, + "column": 16 + }, + "end": { + "line": 11, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 213, + 214 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 11, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 214, + 216 + ], + "loc": { + "start": { + "line": 11, + "column": 18 + }, + "end": { + "line": 11, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 216, + 217 + ], + "loc": { + "start": { + "line": 11, + "column": 20 + }, + "end": { + "line": 11, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 222, + 223 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 223, + 224 + ], + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 12, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "currentTarget", + "range": [ + 224, + 237 + ], + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 12, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 237, + 238 + ], + "loc": { + "start": { + "line": 12, + "column": 19 + }, + "end": { + "line": 12, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 239, + 240 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 240, + 241 + ], + "loc": { + "start": { + "line": 13, + "column": 1 + }, + "end": { + "line": 13, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 241, + 242 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 242, + 243 + ], + "loc": { + "start": { + "line": 13, + "column": 3 + }, + "end": { + "line": 13, + "column": 4 + } + } + } + ], + "range": [ + 0, + 244 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 14, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event03-requirements.json b/tests/fixtures/parser/ast/svelte5/ts-event03-requirements.json new file mode 100644 index 00000000..e218e93c --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event03-requirements.json @@ -0,0 +1,8 @@ +{ + "test": { + "@typescript-eslint/parser": ">=5.0.0" + }, + "scope": { + "@typescript-eslint/parser": ">=6.5.0" + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event03-scope-output.json b/tests/fixtures/parser/ast/svelte5/ts-event03-scope-output.json new file mode 100644 index 00000000..b5f0e409 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event03-scope-output.json @@ -0,0 +1,1720 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 39, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "onfoo", + "identifiers": [ + { + "type": "Identifier", + "name": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "method": false, + "shorthand": true, + "value": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + ], + "range": [ + 29, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [], + "callee": { + "type": "Identifier", + "name": "$props", + "range": [ + 39, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + "optional": false, + "typeArguments": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 56, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSFunctionType", + "params": [ + { + "type": "Identifier", + "name": "e", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "detail", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 77, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 3, + "column": 35 + } + } + }, + "range": [ + 75, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 35 + } + } + }, + "range": [ + 69, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 35 + } + } + } + ], + "range": [ + 67, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 37 + } + } + }, + "range": [ + 65, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 37 + } + } + }, + "range": [ + 64, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 37 + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSVoidKeyword", + "range": [ + 90, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 42 + }, + "end": { + "line": 3, + "column": 46 + } + } + }, + "range": [ + 87, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 39 + }, + "end": { + "line": 3, + "column": 46 + } + } + }, + "range": [ + 63, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 46 + } + } + }, + "range": [ + 61, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 46 + } + } + }, + "range": [ + 56, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 46 + } + } + } + ], + "range": [ + 46, + 100 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 4, + "column": 5 + } + } + } + ], + "range": [ + 45, + 101 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 4, + "column": 6 + } + } + }, + "range": [ + 39, + 103 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + "range": [ + 29, + 103 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 4, + "column": 8 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 108, + 113 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 9 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 39, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 108, + 113 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 9 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "onfoo", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + } + ], + "childScopes": [ + { + "type": "functionType", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "detail", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 77, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 3, + "column": 35 + } + } + }, + "range": [ + 75, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 35 + } + } + }, + "range": [ + 69, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 35 + } + } + } + ], + "range": [ + 67, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 37 + } + } + }, + "range": [ + 65, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 37 + } + } + }, + "range": [ + 64, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 37 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "detail", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 77, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 3, + "column": 35 + } + } + }, + "range": [ + 75, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 35 + } + } + }, + "range": [ + 69, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 35 + } + } + } + ], + "range": [ + 67, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 37 + } + } + }, + "range": [ + 65, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 37 + } + } + }, + "range": [ + 64, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 37 + } + } + }, + "node": { + "type": "TSFunctionType", + "params": [ + { + "type": "Identifier", + "name": "e", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "detail", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 77, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 3, + "column": 35 + } + } + }, + "range": [ + 75, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 35 + } + } + }, + "range": [ + 69, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 35 + } + } + } + ], + "range": [ + 67, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 37 + } + } + }, + "range": [ + 65, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 37 + } + } + }, + "range": [ + 64, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 37 + } + } + } + ], + "returnType": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSVoidKeyword", + "range": [ + 90, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 42 + }, + "end": { + "line": 3, + "column": 46 + } + } + }, + "range": [ + 87, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 39 + }, + "end": { + "line": 3, + "column": 46 + } + } + }, + "range": [ + 63, + 94 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 46 + } + } + } + } + ], + "references": [] + } + ], + "references": [], + "childScopes": [], + "through": [] + }, + { + "type": "function", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 156, + 157 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "range": [ + 156, + 157 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "e", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "currentTarget", + "range": [ + 167, + 180 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 19 + } + } + }, + "range": [ + 165, + 180 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 19 + } + } + }, + "range": [ + 165, + 181 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 20 + } + } + } + ], + "range": [ + 159, + 183 + ], + "loc": { + "start": { + "line": 8, + "column": 21 + }, + "end": { + "line": 10, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 156, + 157 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + } + } + ], + "range": [ + 156, + 183 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 10, + "column": 1 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "e", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "e", + "range": [ + 156, + 157 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "e", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "e", + "range": [ + 156, + 157 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + } + } + } + ], + "childScopes": [], + "through": [] + }, + { + "type": "function", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 213, + 214 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 11, + "column": 18 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "range": [ + 213, + 214 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 11, + "column": 18 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "e", + "range": [ + 222, + 223 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 5 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "currentTarget", + "range": [ + 224, + 237 + ], + "loc": { + "start": { + "line": 12, + "column": 6 + }, + "end": { + "line": 12, + "column": 19 + } + } + }, + "range": [ + 222, + 237 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 19 + } + } + }, + "range": [ + 222, + 238 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 20 + } + } + } + ], + "range": [ + 216, + 240 + ], + "loc": { + "start": { + "line": 11, + "column": 20 + }, + "end": { + "line": 13, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 213, + 214 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 11, + "column": 18 + } + } + } + ], + "range": [ + 213, + 240 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 13, + "column": 1 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "e", + "range": [ + 222, + 223 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 5 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "e", + "range": [ + 213, + 214 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 11, + "column": 18 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "e", + "range": [ + 222, + 223 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 5 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "e", + "range": [ + 213, + 214 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 11, + "column": 18 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "$props", + "range": [ + 39, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event03-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-event03-type-output.svelte new file mode 100644 index 00000000..c5deb9f4 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event03-type-output.svelte @@ -0,0 +1,13 @@ + + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-event04-input.svelte b/tests/fixtures/parser/ast/svelte5/ts-event04-input.svelte new file mode 100644 index 00000000..9855d037 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event04-input.svelte @@ -0,0 +1,6 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-event04-no-unused-expressions-result.json b/tests/fixtures/parser/ast/svelte5/ts-event04-no-unused-expressions-result.json new file mode 100644 index 00000000..6e23ea8e --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event04-no-unused-expressions-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "no-unused-expressions", + "code": "e.currentTarget;", + "line": 5, + "column": 5 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event04-output.json b/tests/fixtures/parser/ast/svelte5/ts-event04-output.json new file mode 100644 index 00000000..f88b1dc3 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event04-output.json @@ -0,0 +1,1044 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteLiteral", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ], + "range": [ + 8, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 17 + } + } + } + ], + "selfClosing": false, + "range": [ + 0, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + "body": [], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 19, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "range": [ + 0, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 28, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 4, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "button", + "range": [ + 31, + 37 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "onunknown", + "range": [ + 38, + 47 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "e", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "currentTarget", + "range": [ + 61, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + "range": [ + 59, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + "range": [ + 59, + 75 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + ], + "range": [ + 53, + 77 + ], + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 21 + } + } + } + ], + "range": [ + 50, + 77 + ], + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + "range": [ + 49, + 78 + ], + "loc": { + "start": { + "line": 4, + "column": 19 + }, + "end": { + "line": 6, + "column": 2 + } + } + } + ], + "range": [ + 38, + 79 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 6, + "column": 3 + } + } + } + ], + "selfClosing": false, + "range": [ + 30, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 6, + "column": 4 + } + } + }, + "children": [], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 80, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "range": [ + 30, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 6, + "column": 13 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "HTMLText", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 21, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 28, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 4, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 31, + 37 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "onunknown", + "range": [ + 38, + 47 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 4, + "column": 19 + }, + "end": { + "line": 4, + "column": 20 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 51, + 53 + ], + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 4, + "column": 24 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "currentTarget", + "range": [ + 61, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 77, + 78 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 78, + 79 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 80, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 82, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + } + ], + "range": [ + 0, + 90 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event04-requirements.json b/tests/fixtures/parser/ast/svelte5/ts-event04-requirements.json new file mode 100644 index 00000000..b0d8202a --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event04-requirements.json @@ -0,0 +1,5 @@ +{ + "scope": { + "@typescript-eslint/parser": ">=6.5.0" + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event04-scope-output.json b/tests/fixtures/parser/ast/svelte5/ts-event04-scope-output.json new file mode 100644 index 00000000..27145165 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event04-scope-output.json @@ -0,0 +1,328 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 21 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 21 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "e", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "currentTarget", + "range": [ + 61, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + "range": [ + 59, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + "range": [ + 59, + 75 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + ], + "range": [ + 53, + 77 + ], + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 21 + } + } + } + ], + "range": [ + 50, + 77 + ], + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 6, + "column": 1 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "e", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "e", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 21 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "e", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "e", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 21 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event04-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-event04-type-output.svelte new file mode 100644 index 00000000..2a1b4c92 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event04-type-output.svelte @@ -0,0 +1,6 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-event05-input.svelte b/tests/fixtures/parser/ast/svelte5/ts-event05-input.svelte new file mode 100644 index 00000000..fad8b77f --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event05-input.svelte @@ -0,0 +1,11 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-event05-no-unused-expressions-result.json b/tests/fixtures/parser/ast/svelte5/ts-event05-no-unused-expressions-result.json new file mode 100644 index 00000000..f0f3f2e4 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event05-no-unused-expressions-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "no-unused-expressions", + "code": "e.detail;", + "line": 10, + "column": 5 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event05-output.json b/tests/fixtures/parser/ast/svelte5/ts-event05-output.json new file mode 100644 index 00000000..02578cd7 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event05-output.json @@ -0,0 +1,1212 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteLiteral", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ], + "range": [ + 8, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 17 + } + } + } + ], + "selfClosing": false, + "range": [ + 0, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + "body": [ + { + "type": "ImportDeclaration", + "importKind": "value", + "source": { + "type": "Literal", + "raw": "'./ts-event03-input.svelte'", + "value": "./ts-event03-input.svelte", + "range": [ + 45, + 72 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 53 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + ], + "range": [ + 23, + 73 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 54 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 74, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 83 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 83, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "component", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 86, + 95 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "onfoo", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 16 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "e", + "range": [ + 346, + 347 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "detail", + "range": [ + 348, + 354 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 12 + } + } + }, + "range": [ + 346, + 354 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 12 + } + } + }, + "range": [ + 346, + 355 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 13 + } + } + } + ], + "range": [ + 107, + 357 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 11, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + ], + "range": [ + 104, + 357 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 11, + "column": 1 + } + } + }, + "range": [ + 103, + 358 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 11, + "column": 2 + } + } + } + ], + "range": [ + 96, + 359 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 11, + "column": 3 + } + } + } + ], + "selfClosing": true, + "range": [ + 85, + 362 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 11, + "column": 6 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 85, + 362 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 11, + "column": 6 + } + } + } + ], + "sourceType": "module", + "comments": [ + { + "type": "Line", + "value": " e.detail is number", + "range": [ + 113, + 134 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + { + "type": "Line", + "value": " `@typescript-eslint/parser` doesn't get the correct types.", + "range": [ + 139, + 202 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 67 + } + } + }, + { + "type": "Line", + "value": " Using `typescript-eslint-parser-for-extra-files` will give we the correct types.", + "range": [ + 207, + 292 + ], + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 89 + } + } + }, + { + "type": "Line", + "value": " See `ts-event06-input.svelte` test case", + "range": [ + 297, + 341 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 48 + } + } + } + ], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "HTMLText", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Keyword", + "value": "import", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "Identifier", + "value": "from", + "range": [ + 40, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "String", + "value": "'./ts-event03-input.svelte'", + "range": [ + 45, + 72 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 53 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 2, + "column": 53 + }, + "end": { + "line": 2, + "column": 54 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 76, + 82 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 83, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Identifier", + "value": "Component", + "range": [ + 86, + 95 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "onfoo", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 105, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 107, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 23 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 346, + 347 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 347, + 348 + ], + "loc": { + "start": { + "line": 10, + "column": 5 + }, + "end": { + "line": 10, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "detail", + "range": [ + 348, + 354 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 354, + 355 + ], + "loc": { + "start": { + "line": 10, + "column": 12 + }, + "end": { + "line": 10, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 356, + 357 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 357, + 358 + ], + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 11, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 358, + 359 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 360, + 361 + ], + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 361, + 362 + ], + "loc": { + "start": { + "line": 11, + "column": 5 + }, + "end": { + "line": 11, + "column": 6 + } + } + } + ], + "range": [ + 0, + 363 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 12, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event05-requirements.json b/tests/fixtures/parser/ast/svelte5/ts-event05-requirements.json new file mode 100644 index 00000000..b0d8202a --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event05-requirements.json @@ -0,0 +1,5 @@ +{ + "scope": { + "@typescript-eslint/parser": ">=6.5.0" + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event05-scope-output.json b/tests/fixtures/parser/ast/svelte5/ts-event05-scope-output.json new file mode 100644 index 00000000..c068e6c4 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event05-scope-output.json @@ -0,0 +1,493 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "Component", + "identifiers": [ + { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "node": { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 86, + 95 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 86, + 95 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "e", + "range": [ + 346, + 347 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "detail", + "range": [ + 348, + 354 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 12 + } + } + }, + "range": [ + 346, + 354 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 12 + } + } + }, + "range": [ + 346, + 355 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 13 + } + } + } + ], + "range": [ + 107, + 357 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 11, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + ], + "range": [ + 104, + 357 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 11, + "column": 1 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "e", + "range": [ + 346, + 347 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "e", + "range": [ + 346, + 347 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event05-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-event05-type-output.svelte new file mode 100644 index 00000000..a89921da --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event05-type-output.svelte @@ -0,0 +1,11 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-event06-config.json b/tests/fixtures/parser/ast/svelte5/ts-event06-config.json new file mode 100644 index 00000000..73510cc2 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event06-config.json @@ -0,0 +1,3 @@ +{ + "parser": "typescript-eslint-parser-for-extra-files" +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event06-input.svelte b/tests/fixtures/parser/ast/svelte5/ts-event06-input.svelte new file mode 100644 index 00000000..2ece551a --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event06-input.svelte @@ -0,0 +1,8 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-event06-no-unused-expressions-result.json b/tests/fixtures/parser/ast/svelte5/ts-event06-no-unused-expressions-result.json new file mode 100644 index 00000000..0fe83e99 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event06-no-unused-expressions-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "no-unused-expressions", + "code": "e.detail;", + "line": 7, + "column": 5 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event06-output.json b/tests/fixtures/parser/ast/svelte5/ts-event06-output.json new file mode 100644 index 00000000..7ed03c64 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event06-output.json @@ -0,0 +1,1158 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteLiteral", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ], + "range": [ + 8, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 17 + } + } + } + ], + "selfClosing": false, + "range": [ + 0, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + "body": [ + { + "type": "ImportDeclaration", + "importKind": "value", + "source": { + "type": "Literal", + "raw": "'./ts-event03-input.svelte'", + "value": "./ts-event03-input.svelte", + "range": [ + 45, + 72 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 53 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + ], + "range": [ + 23, + 73 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 54 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 74, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 83 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 83, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "component", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 86, + 95 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "onfoo", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 16 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "e", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "detail", + "range": [ + 141, + 147 + ], + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 139, + 147 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 139, + 148 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 13 + } + } + } + ], + "range": [ + 107, + 150 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 8, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + ], + "range": [ + 104, + 150 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 8, + "column": 1 + } + } + }, + "range": [ + 103, + 151 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 8, + "column": 2 + } + } + } + ], + "range": [ + 96, + 152 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 8, + "column": 3 + } + } + } + ], + "selfClosing": true, + "range": [ + 85, + 155 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 8, + "column": 6 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 85, + 155 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 8, + "column": 6 + } + } + } + ], + "sourceType": "module", + "comments": [ + { + "type": "Line", + "value": " e.detail is number", + "range": [ + 113, + 134 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 25 + } + } + } + ], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "lang", + "range": [ + 8, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "HTMLText", + "value": "ts", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Keyword", + "value": "import", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "Identifier", + "value": "from", + "range": [ + 40, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "String", + "value": "'./ts-event03-input.svelte'", + "range": [ + 45, + 72 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 53 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 2, + "column": 53 + }, + "end": { + "line": 2, + "column": 54 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 76, + 82 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 83, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "Identifier", + "value": "Component", + "range": [ + 86, + 95 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "onfoo", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 105, + 107 + ], + "loc": { + "start": { + "line": 5, + "column": 20 + }, + "end": { + "line": 5, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 107, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 23 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 7, + "column": 5 + }, + "end": { + "line": 7, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "detail", + "range": [ + 141, + 147 + ], + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 147, + 148 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 150, + 151 + ], + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 151, + 152 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 153, + 154 + ], + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 6 + } + } + } + ], + "range": [ + 0, + 156 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event06-requirements.json b/tests/fixtures/parser/ast/svelte5/ts-event06-requirements.json new file mode 100644 index 00000000..b0d8202a --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event06-requirements.json @@ -0,0 +1,5 @@ +{ + "scope": { + "@typescript-eslint/parser": ">=6.5.0" + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event06-scope-output.json b/tests/fixtures/parser/ast/svelte5/ts-event06-scope-output.json new file mode 100644 index 00000000..c1c755fe --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event06-scope-output.json @@ -0,0 +1,493 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "Component", + "identifiers": [ + { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "name": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "node": { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 86, + 95 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Component", + "range": [ + 86, + 95 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Component", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 20 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "e", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "detail", + "range": [ + 141, + 147 + ], + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 139, + 147 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 139, + 148 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 13 + } + } + } + ], + "range": [ + 107, + 150 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 8, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + ], + "range": [ + 104, + 150 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 8, + "column": 1 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "e", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "e", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 5 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "e", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event06-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-event06-type-output.svelte new file mode 100644 index 00000000..30db5378 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event06-type-output.svelte @@ -0,0 +1,8 @@ + + + diff --git a/tools/update-fixtures.ts b/tools/update-fixtures.ts index 51d165ca..40994a7d 100644 --- a/tools/update-fixtures.ts +++ b/tools/update-fixtures.ts @@ -212,6 +212,13 @@ function buildTypes( node.expression.loc!.end.line - 2, ]); } + if (node.type === "SvelteMustacheTag") { + if (node.loc.start.line !== node.loc.end.line) + scriptLineRange.push([ + node.loc.start.line - 1, + node.loc.end.line - 2, + ]); + } }, leaveNode() { // noop From c1ae837088c65b03b2df161b0f26738a4da3a0de Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Mon, 20 Nov 2023 23:11:22 +0900 Subject: [PATCH 2/2] Create yellow-cooks-end.md --- .changeset/yellow-cooks-end.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/yellow-cooks-end.md diff --git a/.changeset/yellow-cooks-end.md b/.changeset/yellow-cooks-end.md new file mode 100644 index 00000000..8d8071f4 --- /dev/null +++ b/.changeset/yellow-cooks-end.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": minor +--- + +feat: improve props type