From 7a00144cc649844aaac3e7353c2d986acf1fa5e1 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Thu, 23 Nov 2023 12:35:08 +0900 Subject: [PATCH 1/8] add hasTypeInfo --- explorer-v2/package.json | 2 +- package.json | 4 +- src/parser/converts/attr.ts | 125 +++++++++++++++++++++--------------- 3 files changed, 78 insertions(+), 53 deletions(-) diff --git a/explorer-v2/package.json b/explorer-v2/package.json index 960d7f59..6ebb779a 100644 --- a/explorer-v2/package.json +++ b/explorer-v2/package.json @@ -18,7 +18,7 @@ "eslint-scope": "^7.2.2", "esquery": "^1.5.0", "pako": "^2.1.0", - "svelte": "^5.0.0-next.8", + "svelte": "^5.0.0-next.10", "svelte-eslint-parser": "link:..", "tslib": "^2.6.2" }, diff --git a/package.json b/package.json index 615cb3c6..03a5900a 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "version:ci": "env-cmd -e version-ci pnpm run build:meta && changeset version" }, "peerDependencies": { - "svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.8" + "svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.10" }, "peerDependenciesMeta": { "svelte": { @@ -104,7 +104,7 @@ "prettier-plugin-svelte": "^3.0.0", "rimraf": "^5.0.1", "semver": "^7.5.1", - "svelte": "^5.0.0-next.8", + "svelte": "^5.0.0-next.10", "svelte2tsx": "^0.6.25", "typescript": "~5.1.3", "typescript-eslint-parser-for-extra-files": "^0.5.0" diff --git a/src/parser/converts/attr.ts b/src/parser/converts/attr.ts index adc6d753..5eebd57f 100644 --- a/src/parser/converts/attr.ts +++ b/src/parser/converts/attr.ts @@ -39,7 +39,7 @@ import { svelteVersion } from "../svelte-version"; export function* convertAttributes( attributes: SvAST.AttributeOrDirective[], parent: SvelteStartTag, - ctx: Context, + ctx: Context ): IterableIterator< | SvelteAttribute | SvelteShorthandAttribute @@ -95,13 +95,13 @@ export function* convertAttributes( throw new ParseError( `Svelte v3.46.0 is no longer supported. Please use Svelte>=v3.46.1.`, attr.start, - ctx, + ctx ); } throw new ParseError( `Unknown directive or attribute (${attr.type}) are not supported.`, attr.start, - ctx, + ctx ); } } @@ -110,7 +110,7 @@ export function* convertAttributes( export function* convertAttributeTokens( attributes: AttributeToken[], parent: SvelteStartTag, - ctx: Context, + ctx: Context ): IterableIterator { for (const attr of attributes) { const attribute: SvelteAttribute = { @@ -135,7 +135,7 @@ export function* convertAttributeTokens( attribute.boolean = true; } else { attribute.value.push( - convertAttributeValueTokenToLiteral(attr.value, attribute, ctx), + convertAttributeValueTokenToLiteral(attr.value, attribute, ctx) ); } yield attribute; @@ -146,7 +146,7 @@ export function* convertAttributeTokens( function convertAttribute( node: SvAST.Attribute, parent: SvelteAttribute["parent"], - ctx: Context, + ctx: Context ): SvelteAttribute | SvelteShorthandAttribute { const attribute: SvelteAttribute = { type: "SvelteAttribute", @@ -202,7 +202,7 @@ function convertAttribute( node.value as (SvAST.Text | SvAST.MustacheTag)[], attribute, parent, - ctx, + ctx ); // Not required for shorthands. Therefore, register the token here. @@ -216,7 +216,7 @@ function processAttributeValue( nodeValue: (SvAST.Text | SvAST.MustacheTag)[], attribute: SvelteAttribute | SvelteStyleDirectiveLongform, attributeParent: (SvelteAttribute | SvelteStyleDirectiveLongform)["parent"], - ctx: Context, + ctx: Context ) { const nodes = nodeValue .filter( @@ -224,7 +224,7 @@ function processAttributeValue( v.type !== "Text" || // ignore empty // https://github.com/sveltejs/svelte/pull/6539 - v.start < v.end, + v.start < v.end ) .map((v, index, array) => { if (v.type === "Text") { @@ -247,7 +247,7 @@ function processAttributeValue( const typing = buildAttributeType( attributeParent.parent, attribute.key.name, - ctx, + ctx ); const mustache = convertMustacheTag(nodes[0], attribute, typing, ctx); attribute.value.push(mustache); @@ -267,7 +267,7 @@ function processAttributeValue( throw new ParseError( `Unknown attribute value (${u.type}) are not supported.`, u.start, - ctx, + ctx ); } } @@ -276,7 +276,7 @@ function processAttributeValue( function buildAttributeType( element: SvelteElement | SvelteScriptElement | SvelteStyleElement, attrName: string, - ctx: Context, + ctx: Context ) { if ( svelteVersion.gte(5) && @@ -317,7 +317,7 @@ function buildAttributeType( function convertSpreadAttribute( node: SvAST.Spread, parent: SvelteSpreadAttribute["parent"], - ctx: Context, + ctx: Context ): SvelteSpreadAttribute { const attribute: SvelteSpreadAttribute = { type: "SvelteSpreadAttribute", @@ -343,7 +343,7 @@ function convertSpreadAttribute( function convertBindingDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context, + ctx: Context ): SvelteBindingDirective { const directive: SvelteBindingDirective = { type: "SvelteDirective", @@ -365,7 +365,7 @@ function convertBindingDirective( directive.expression = es; const scope = getScope(es); const reference = scope.references.find( - (ref) => ref.identifier === es, + (ref) => ref.identifier === es ); if (reference) { // The bind directive does read and write. @@ -375,7 +375,7 @@ function convertBindingDirective( reference.isReadOnly = () => false; reference.isRead = () => true; } - }, + } ); }, }); @@ -386,7 +386,7 @@ function convertBindingDirective( function convertEventHandlerDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context, + ctx: Context ): SvelteEventHandlerDirective { const directive: SvelteEventHandlerDirective = { type: "SvelteDirective", @@ -401,7 +401,7 @@ function convertEventHandlerDirective( processExpression: buildProcessExpressionForExpression( directive, ctx, - typing, + typing ), }); return directive; @@ -411,7 +411,7 @@ function convertEventHandlerDirective( function buildEventHandlerType( element: SvelteElement | SvelteScriptElement | SvelteStyleElement, eventName: string, - ctx: Context, + ctx: Context ) { const nativeEventHandlerType = `(e:${conditional({ check: `'${eventName}'`, @@ -495,7 +495,7 @@ function buildEventHandlerType( function convertClassDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context, + ctx: Context ): SvelteClassDirective { const directive: SvelteClassDirective = { type: "SvelteDirective", @@ -519,7 +519,7 @@ function convertClassDirective( function convertStyleDirective( node: SvAST.StyleDirective, parent: SvelteStyleDirective["parent"], - ctx: Context, + ctx: Context ): SvelteStyleDirective { const directive: SvelteStyleDirectiveLongform = { type: "SvelteStyleDirective", @@ -545,11 +545,11 @@ function convertStyleDirective( throw new ParseError( `Expected JS identifier or attribute value.`, expression.range![0], - ctx, + ctx ); } shorthandDirective.key.name = expression; - }, + } ); return shorthandDirective; } @@ -567,7 +567,7 @@ function convertStyleDirective( function convertTransitionDirective( node: SvAST.TransitionDirective, parent: SvelteDirective["parent"], - ctx: Context, + ctx: Context ): SvelteTransitionDirective { const directive: SvelteTransitionDirective = { type: "SvelteDirective", @@ -583,14 +583,14 @@ function convertTransitionDirective( processExpression: buildProcessExpressionForExpression( directive, ctx, - null, + null ), processName: (name) => ctx.scriptLet.addExpression( name, directive.key, null, - buildExpressionTypeChecker(["Identifier"], ctx), + buildExpressionTypeChecker(["Identifier"], ctx) ), }); return directive; @@ -600,7 +600,7 @@ function convertTransitionDirective( function convertAnimationDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context, + ctx: Context ): SvelteAnimationDirective { const directive: SvelteAnimationDirective = { type: "SvelteDirective", @@ -614,14 +614,14 @@ function convertAnimationDirective( processExpression: buildProcessExpressionForExpression( directive, ctx, - null, + null ), processName: (name) => ctx.scriptLet.addExpression( name, directive.key, null, - buildExpressionTypeChecker(["Identifier"], ctx), + buildExpressionTypeChecker(["Identifier"], ctx) ), }); return directive; @@ -631,7 +631,7 @@ function convertAnimationDirective( function convertActionDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context, + ctx: Context ): SvelteActionDirective { const directive: SvelteActionDirective = { type: "SvelteDirective", @@ -645,14 +645,14 @@ function convertActionDirective( processExpression: buildProcessExpressionForExpression( directive, ctx, - `Parameters[1]`, + `Parameters[1]` ), processName: (name) => ctx.scriptLet.addExpression( name, directive.key, null, - buildExpressionTypeChecker(["Identifier", "MemberExpression"], ctx), + buildExpressionTypeChecker(["Identifier", "MemberExpression"], ctx) ), }); return directive; @@ -662,7 +662,7 @@ function convertActionDirective( function convertLetDirective( node: SvAST.LetDirective, parent: SvelteLetDirective["parent"], - ctx: Context, + ctx: Context ): SvelteLetDirective { const directive: SvelteLetDirective = { type: "SvelteDirective", @@ -679,7 +679,7 @@ function convertLetDirective( .addPattern( pattern, directive, - buildLetDirectiveType(parent.parent, node.name, ctx), + buildLetDirectiveType(parent.parent, node.name, ctx) ); }, processName: node.expression @@ -694,7 +694,7 @@ function convertLetDirective( buildLetDirectiveType(parent.parent, node.name, ctx), (es) => { directive.expression = es; - }, + } ); return []; }, @@ -706,7 +706,7 @@ function convertLetDirective( function buildLetDirectiveType( element: SvelteElement | SvelteScriptElement | SvelteStyleElement, letName: string, - ctx: Context, + ctx: Context ) { if (element.type !== "SvelteElement") { return "any"; @@ -717,7 +717,7 @@ function buildLetDirectiveType( const slotAttr = svelteNode.attributes.find( (attr): attr is SvAST.Attribute => { return attr.type === "Attribute" && attr.name === "slot"; - }, + } ); if (slotAttr) { if ( @@ -742,7 +742,7 @@ function buildLetDirectiveType( } } return `${String(componentName)}['$$slot_def'][${JSON.stringify( - slotName, + slotName )}][${JSON.stringify(letName)}]`; /** Find parent component element */ @@ -770,21 +770,21 @@ type DirectiveProcessors< | { processExpression: ( expression: E, - shorthand: boolean, + shorthand: boolean ) => ScriptLetCallback>[]; processPattern?: undefined; processName?: ( - expression: SvelteName, + expression: SvelteName ) => ScriptLetCallback>[]; } | { processExpression?: undefined; processPattern: ( expression: E, - shorthand: boolean, + shorthand: boolean ) => ScriptLetCallback>[]; processName?: ( - expression: SvelteName, + expression: SvelteName ) => ScriptLetCallback>[]; }; @@ -797,7 +797,7 @@ function processDirective< node: D & { expression: null | E }, directive: S, ctx: Context, - processors: DirectiveProcessors, + processors: DirectiveProcessors ) { processDirectiveKey(node, directive, ctx); processDirectiveExpression(node, directive, ctx, processors); @@ -827,7 +827,7 @@ function processDirectiveKey< let nextEnd = indexOf( ctx.code, (c) => c === "=" || c === ">" || c === "/" || c === "|" || !c.trim(), - nextStart, + nextStart ); ctx.addToken("HTMLIdentifier", { start: nextStart, end: nextEnd }); while (ctx.code[nextEnd] === "|") { @@ -835,7 +835,7 @@ function processDirectiveKey< nextEnd = indexOf( ctx.code, (c) => c === "=" || c === ">" || c === "/" || c === "|" || !c.trim(), - nextStart, + nextStart ); ctx.addToken("HTMLIdentifier", { start: nextStart, end: nextEnd }); } @@ -868,7 +868,7 @@ function processDirectiveExpression< node: D & { expression: null | E }, directive: S, ctx: Context, - processors: DirectiveProcessors, + processors: DirectiveProcessors ) { const key = directive.key; const keyName = key.name as SvelteName; @@ -890,7 +890,7 @@ function processDirectiveExpression< throw new ParseError( `Expected ${node.expression.type}, but ${es.type} found.`, es.range![0], - ctx, + ctx ); } directive.expression = es; @@ -919,9 +919,12 @@ function processDirectiveExpression< function buildProcessExpressionForExpression( directive: SvelteDirective & { expression: null | ESTree.Expression }, ctx: Context, - typing: string | null, + typing: string | null ): (expression: ESTree.Expression) => ScriptLetCallback[] { return (expression) => { + if (hasTypeInfo(expression)) { + return ctx.scriptLet.addExpression(expression, directive); + } return ctx.scriptLet.addExpression(expression, directive, typing); }; } @@ -929,15 +932,37 @@ function buildProcessExpressionForExpression( /** Build expression type checker to script let callbacks */ function buildExpressionTypeChecker( expected: T["type"][], - ctx: Context, + ctx: Context ): ScriptLetCallback { return (node) => { if (!expected.includes(node.type)) { throw new ParseError( `Expected JS ${expected.join(", or ")}, but ${node.type} found.`, node.range![0], - ctx, + ctx ); } }; } + +function hasTypeInfo(element: any): boolean { + if ( + element.type === "TSTypeAnnotation" || + element.type === "TSAsExpression" + ) { + return true; + } + for (const key of Object.keys(element)) { + if (key === "parent") continue; + const value = (element as any)[key]; + if (value == null) continue; + if (typeof value === "object") { + if (hasTypeInfo(value)) return true; + } else if (Array.isArray(value)) { + for (const v of value) { + if (typeof v === "object" && hasTypeInfo(v)) return true; + } + } + } + return false; +} From 4e85d8e28b3ae5ed7774019309f0ebb4b6a3b0d8 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Thu, 23 Nov 2023 13:06:36 +0900 Subject: [PATCH 2/8] lint --- src/parser/converts/attr.ts | 102 ++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/parser/converts/attr.ts b/src/parser/converts/attr.ts index 5eebd57f..59034a1e 100644 --- a/src/parser/converts/attr.ts +++ b/src/parser/converts/attr.ts @@ -39,7 +39,7 @@ import { svelteVersion } from "../svelte-version"; export function* convertAttributes( attributes: SvAST.AttributeOrDirective[], parent: SvelteStartTag, - ctx: Context + ctx: Context, ): IterableIterator< | SvelteAttribute | SvelteShorthandAttribute @@ -95,13 +95,13 @@ export function* convertAttributes( throw new ParseError( `Svelte v3.46.0 is no longer supported. Please use Svelte>=v3.46.1.`, attr.start, - ctx + ctx, ); } throw new ParseError( `Unknown directive or attribute (${attr.type}) are not supported.`, attr.start, - ctx + ctx, ); } } @@ -110,7 +110,7 @@ export function* convertAttributes( export function* convertAttributeTokens( attributes: AttributeToken[], parent: SvelteStartTag, - ctx: Context + ctx: Context, ): IterableIterator { for (const attr of attributes) { const attribute: SvelteAttribute = { @@ -135,7 +135,7 @@ export function* convertAttributeTokens( attribute.boolean = true; } else { attribute.value.push( - convertAttributeValueTokenToLiteral(attr.value, attribute, ctx) + convertAttributeValueTokenToLiteral(attr.value, attribute, ctx), ); } yield attribute; @@ -146,7 +146,7 @@ export function* convertAttributeTokens( function convertAttribute( node: SvAST.Attribute, parent: SvelteAttribute["parent"], - ctx: Context + ctx: Context, ): SvelteAttribute | SvelteShorthandAttribute { const attribute: SvelteAttribute = { type: "SvelteAttribute", @@ -202,7 +202,7 @@ function convertAttribute( node.value as (SvAST.Text | SvAST.MustacheTag)[], attribute, parent, - ctx + ctx, ); // Not required for shorthands. Therefore, register the token here. @@ -216,7 +216,7 @@ function processAttributeValue( nodeValue: (SvAST.Text | SvAST.MustacheTag)[], attribute: SvelteAttribute | SvelteStyleDirectiveLongform, attributeParent: (SvelteAttribute | SvelteStyleDirectiveLongform)["parent"], - ctx: Context + ctx: Context, ) { const nodes = nodeValue .filter( @@ -224,7 +224,7 @@ function processAttributeValue( v.type !== "Text" || // ignore empty // https://github.com/sveltejs/svelte/pull/6539 - v.start < v.end + v.start < v.end, ) .map((v, index, array) => { if (v.type === "Text") { @@ -247,7 +247,7 @@ function processAttributeValue( const typing = buildAttributeType( attributeParent.parent, attribute.key.name, - ctx + ctx, ); const mustache = convertMustacheTag(nodes[0], attribute, typing, ctx); attribute.value.push(mustache); @@ -267,7 +267,7 @@ function processAttributeValue( throw new ParseError( `Unknown attribute value (${u.type}) are not supported.`, u.start, - ctx + ctx, ); } } @@ -276,7 +276,7 @@ function processAttributeValue( function buildAttributeType( element: SvelteElement | SvelteScriptElement | SvelteStyleElement, attrName: string, - ctx: Context + ctx: Context, ) { if ( svelteVersion.gte(5) && @@ -317,7 +317,7 @@ function buildAttributeType( function convertSpreadAttribute( node: SvAST.Spread, parent: SvelteSpreadAttribute["parent"], - ctx: Context + ctx: Context, ): SvelteSpreadAttribute { const attribute: SvelteSpreadAttribute = { type: "SvelteSpreadAttribute", @@ -343,7 +343,7 @@ function convertSpreadAttribute( function convertBindingDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context + ctx: Context, ): SvelteBindingDirective { const directive: SvelteBindingDirective = { type: "SvelteDirective", @@ -365,7 +365,7 @@ function convertBindingDirective( directive.expression = es; const scope = getScope(es); const reference = scope.references.find( - (ref) => ref.identifier === es + (ref) => ref.identifier === es, ); if (reference) { // The bind directive does read and write. @@ -375,7 +375,7 @@ function convertBindingDirective( reference.isReadOnly = () => false; reference.isRead = () => true; } - } + }, ); }, }); @@ -386,7 +386,7 @@ function convertBindingDirective( function convertEventHandlerDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context + ctx: Context, ): SvelteEventHandlerDirective { const directive: SvelteEventHandlerDirective = { type: "SvelteDirective", @@ -401,7 +401,7 @@ function convertEventHandlerDirective( processExpression: buildProcessExpressionForExpression( directive, ctx, - typing + typing, ), }); return directive; @@ -411,7 +411,7 @@ function convertEventHandlerDirective( function buildEventHandlerType( element: SvelteElement | SvelteScriptElement | SvelteStyleElement, eventName: string, - ctx: Context + ctx: Context, ) { const nativeEventHandlerType = `(e:${conditional({ check: `'${eventName}'`, @@ -495,7 +495,7 @@ function buildEventHandlerType( function convertClassDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context + ctx: Context, ): SvelteClassDirective { const directive: SvelteClassDirective = { type: "SvelteDirective", @@ -519,7 +519,7 @@ function convertClassDirective( function convertStyleDirective( node: SvAST.StyleDirective, parent: SvelteStyleDirective["parent"], - ctx: Context + ctx: Context, ): SvelteStyleDirective { const directive: SvelteStyleDirectiveLongform = { type: "SvelteStyleDirective", @@ -545,11 +545,11 @@ function convertStyleDirective( throw new ParseError( `Expected JS identifier or attribute value.`, expression.range![0], - ctx + ctx, ); } shorthandDirective.key.name = expression; - } + }, ); return shorthandDirective; } @@ -567,7 +567,7 @@ function convertStyleDirective( function convertTransitionDirective( node: SvAST.TransitionDirective, parent: SvelteDirective["parent"], - ctx: Context + ctx: Context, ): SvelteTransitionDirective { const directive: SvelteTransitionDirective = { type: "SvelteDirective", @@ -583,14 +583,14 @@ function convertTransitionDirective( processExpression: buildProcessExpressionForExpression( directive, ctx, - null + null, ), processName: (name) => ctx.scriptLet.addExpression( name, directive.key, null, - buildExpressionTypeChecker(["Identifier"], ctx) + buildExpressionTypeChecker(["Identifier"], ctx), ), }); return directive; @@ -600,7 +600,7 @@ function convertTransitionDirective( function convertAnimationDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context + ctx: Context, ): SvelteAnimationDirective { const directive: SvelteAnimationDirective = { type: "SvelteDirective", @@ -614,14 +614,14 @@ function convertAnimationDirective( processExpression: buildProcessExpressionForExpression( directive, ctx, - null + null, ), processName: (name) => ctx.scriptLet.addExpression( name, directive.key, null, - buildExpressionTypeChecker(["Identifier"], ctx) + buildExpressionTypeChecker(["Identifier"], ctx), ), }); return directive; @@ -631,7 +631,7 @@ function convertAnimationDirective( function convertActionDirective( node: SvAST.DirectiveForExpression, parent: SvelteDirective["parent"], - ctx: Context + ctx: Context, ): SvelteActionDirective { const directive: SvelteActionDirective = { type: "SvelteDirective", @@ -645,14 +645,14 @@ function convertActionDirective( processExpression: buildProcessExpressionForExpression( directive, ctx, - `Parameters[1]` + `Parameters[1]`, ), processName: (name) => ctx.scriptLet.addExpression( name, directive.key, null, - buildExpressionTypeChecker(["Identifier", "MemberExpression"], ctx) + buildExpressionTypeChecker(["Identifier", "MemberExpression"], ctx), ), }); return directive; @@ -662,7 +662,7 @@ function convertActionDirective( function convertLetDirective( node: SvAST.LetDirective, parent: SvelteLetDirective["parent"], - ctx: Context + ctx: Context, ): SvelteLetDirective { const directive: SvelteLetDirective = { type: "SvelteDirective", @@ -679,7 +679,7 @@ function convertLetDirective( .addPattern( pattern, directive, - buildLetDirectiveType(parent.parent, node.name, ctx) + buildLetDirectiveType(parent.parent, node.name, ctx), ); }, processName: node.expression @@ -694,7 +694,7 @@ function convertLetDirective( buildLetDirectiveType(parent.parent, node.name, ctx), (es) => { directive.expression = es; - } + }, ); return []; }, @@ -706,7 +706,7 @@ function convertLetDirective( function buildLetDirectiveType( element: SvelteElement | SvelteScriptElement | SvelteStyleElement, letName: string, - ctx: Context + ctx: Context, ) { if (element.type !== "SvelteElement") { return "any"; @@ -717,7 +717,7 @@ function buildLetDirectiveType( const slotAttr = svelteNode.attributes.find( (attr): attr is SvAST.Attribute => { return attr.type === "Attribute" && attr.name === "slot"; - } + }, ); if (slotAttr) { if ( @@ -742,7 +742,7 @@ function buildLetDirectiveType( } } return `${String(componentName)}['$$slot_def'][${JSON.stringify( - slotName + slotName, )}][${JSON.stringify(letName)}]`; /** Find parent component element */ @@ -770,21 +770,21 @@ type DirectiveProcessors< | { processExpression: ( expression: E, - shorthand: boolean + shorthand: boolean, ) => ScriptLetCallback>[]; processPattern?: undefined; processName?: ( - expression: SvelteName + expression: SvelteName, ) => ScriptLetCallback>[]; } | { processExpression?: undefined; processPattern: ( expression: E, - shorthand: boolean + shorthand: boolean, ) => ScriptLetCallback>[]; processName?: ( - expression: SvelteName + expression: SvelteName, ) => ScriptLetCallback>[]; }; @@ -797,7 +797,7 @@ function processDirective< node: D & { expression: null | E }, directive: S, ctx: Context, - processors: DirectiveProcessors + processors: DirectiveProcessors, ) { processDirectiveKey(node, directive, ctx); processDirectiveExpression(node, directive, ctx, processors); @@ -827,7 +827,7 @@ function processDirectiveKey< let nextEnd = indexOf( ctx.code, (c) => c === "=" || c === ">" || c === "/" || c === "|" || !c.trim(), - nextStart + nextStart, ); ctx.addToken("HTMLIdentifier", { start: nextStart, end: nextEnd }); while (ctx.code[nextEnd] === "|") { @@ -835,7 +835,7 @@ function processDirectiveKey< nextEnd = indexOf( ctx.code, (c) => c === "=" || c === ">" || c === "/" || c === "|" || !c.trim(), - nextStart + nextStart, ); ctx.addToken("HTMLIdentifier", { start: nextStart, end: nextEnd }); } @@ -868,7 +868,7 @@ function processDirectiveExpression< node: D & { expression: null | E }, directive: S, ctx: Context, - processors: DirectiveProcessors + processors: DirectiveProcessors, ) { const key = directive.key; const keyName = key.name as SvelteName; @@ -890,7 +890,7 @@ function processDirectiveExpression< throw new ParseError( `Expected ${node.expression.type}, but ${es.type} found.`, es.range![0], - ctx + ctx, ); } directive.expression = es; @@ -919,7 +919,7 @@ function processDirectiveExpression< function buildProcessExpressionForExpression( directive: SvelteDirective & { expression: null | ESTree.Expression }, ctx: Context, - typing: string | null + typing: string | null, ): (expression: ESTree.Expression) => ScriptLetCallback[] { return (expression) => { if (hasTypeInfo(expression)) { @@ -932,14 +932,14 @@ function buildProcessExpressionForExpression( /** Build expression type checker to script let callbacks */ function buildExpressionTypeChecker( expected: T["type"][], - ctx: Context + ctx: Context, ): ScriptLetCallback { return (node) => { if (!expected.includes(node.type)) { throw new ParseError( `Expected JS ${expected.join(", or ")}, but ${node.type} found.`, node.range![0], - ctx + ctx, ); } }; @@ -954,7 +954,7 @@ function hasTypeInfo(element: any): boolean { } for (const key of Object.keys(element)) { if (key === "parent") continue; - const value = (element as any)[key]; + const value = element[key]; if (value == null) continue; if (typeof value === "object") { if (hasTypeInfo(value)) return true; From b2b1dac168cc196e325fc4f0b73c107b4cc39757 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Thu, 23 Nov 2023 13:07:42 +0900 Subject: [PATCH 3/8] add changeset --- .changeset/grumpy-dolphins-pay.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/grumpy-dolphins-pay.md diff --git a/.changeset/grumpy-dolphins-pay.md b/.changeset/grumpy-dolphins-pay.md new file mode 100644 index 00000000..12c562c7 --- /dev/null +++ b/.changeset/grumpy-dolphins-pay.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": minor +--- + +feat: skip type injection if template uses TypeScript From 79c194461addae0f0ddacf9190d28e6ffcc2d1ca Mon Sep 17 00:00:00 2001 From: baseballyama Date: Thu, 23 Nov 2023 13:32:03 +0900 Subject: [PATCH 4/8] adding tests --- .../ast/svelte5/ts-event07-input.svelte | 10 + .../ts-event07-no-unused-vars-result.json | 8 + .../parser/ast/svelte5/ts-event07-output.json | 1873 +++++++++++++++++ .../ast/svelte5/ts-event07-requirements.json | 5 + .../ast/svelte5/ts-event07-scope-output.json | 1833 ++++++++++++++++ .../ast/svelte5/ts-event07-type-output.svelte | 10 + .../ast/svelte5/ts-snippet01-input.svelte | 9 + .../ast/svelte5/ts-snippet01-output.json | 1361 ++++++++++++ .../ts-snippet01-prefer-const-result.json | 8 + .../svelte5/ts-snippet01-scope-output.json | 848 ++++++++ .../svelte5/ts-snippet01-type-output.svelte | 9 + 11 files changed, 5974 insertions(+) create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event07-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event07-no-unused-vars-result.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event07-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event07-requirements.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event07-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event07-type-output.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-snippet01-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-snippet01-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-snippet01-prefer-const-result.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-snippet01-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-snippet01-type-output.svelte diff --git a/tests/fixtures/parser/ast/svelte5/ts-event07-input.svelte b/tests/fixtures/parser/ast/svelte5/ts-event07-input.svelte new file mode 100644 index 00000000..f66af827 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event07-input.svelte @@ -0,0 +1,10 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-event07-no-unused-vars-result.json b/tests/fixtures/parser/ast/svelte5/ts-event07-no-unused-vars-result.json new file mode 100644 index 00000000..bdf10808 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event07-no-unused-vars-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "no-unused-vars", + "code": "e: MouseEvent", + "line": 6, + "column": 13 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event07-output.json b/tests/fixtures/parser/ast/svelte5/ts-event07-output.json new file mode 100644 index 00000000..d40404d3 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event07-output.json @@ -0,0 +1,1873 @@ +{ + "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": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [ + { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "$state", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "optional": false, + "range": [ + 32, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "range": [ + 24, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + ], + "range": [ + 20, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 23 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 43, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 52 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 52, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "button", + "range": [ + 55, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "EventHandler", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "click", + "range": [ + 66, + 71 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + "modifiers": [], + "range": [ + 63, + 71 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "next", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 106, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 102, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "init": { + "type": "BinaryExpression", + "left": { + "type": "Identifier", + "name": "count", + "range": [ + 117, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 28 + } + } + }, + "operator": "+", + "right": { + "type": "Literal", + "raw": "1", + "value": 1, + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 31 + }, + "end": { + "line": 7, + "column": 32 + } + } + }, + "range": [ + 117, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 32 + } + } + }, + "range": [ + 102, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 32 + } + } + } + ], + "range": [ + 96, + 127 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 33 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "left": { + "type": "Identifier", + "name": "count", + "range": [ + 130, + 135 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 7 + } + } + }, + "operator": "=", + "right": { + "type": "Identifier", + "name": "next", + "range": [ + 138, + 142 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "range": [ + 130, + 142 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "range": [ + 130, + 143 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 15 + } + } + } + ], + "range": [ + 92, + 146 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "MouseEvent", + "range": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 75, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 74, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 25 + } + } + } + ], + "range": [ + 73, + 146 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + "range": [ + 63, + 147 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 9, + "column": 3 + } + } + } + ], + "selfClosing": false, + "range": [ + 54, + 149 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "clicks: ", + "range": [ + 149, + 157 + ], + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "count", + "range": [ + 158, + 163 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 15 + } + } + }, + "range": [ + 157, + 164 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 16 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 164, + 173 + ], + "loc": { + "start": { + "line": 10, + "column": 16 + }, + "end": { + "line": 10, + "column": 25 + } + } + }, + "range": [ + 54, + 173 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 10, + "column": 25 + } + } + } + ], + "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": "let", + "range": [ + 20, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + { + "type": "Identifier", + "value": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + { + "type": "Identifier", + "value": "$state", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "Numeric", + "value": "0", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 40, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 45, + 51 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 52, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 55, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "on", + "range": [ + 63, + 65 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "click", + "range": [ + 66, + 71 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 71, + 72 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "MouseEvent", + "range": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 89, + 91 + ], + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 6, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 6, + "column": 31 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "next", + "range": [ + 102, + 106 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "number", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 115, + 116 + ], + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 22 + } + } + }, + { + "type": "Identifier", + "value": "count", + "range": [ + 117, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": "+", + "range": [ + 123, + 124 + ], + "loc": { + "start": { + "line": 7, + "column": 29 + }, + "end": { + "line": 7, + "column": 30 + } + } + }, + { + "type": "Numeric", + "value": "1", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 31 + }, + "end": { + "line": 7, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 126, + 127 + ], + "loc": { + "start": { + "line": 7, + "column": 32 + }, + "end": { + "line": 7, + "column": 33 + } + } + }, + { + "type": "Identifier", + "value": "count", + "range": [ + 130, + 135 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + { + "type": "Identifier", + "value": "next", + "range": [ + 138, + 142 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 142, + 143 + ], + "loc": { + "start": { + "line": 8, + "column": 14 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 145, + 146 + ], + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 1 + } + } + }, + { + "type": "HTMLText", + "value": "clicks:", + "range": [ + 149, + 156 + ], + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 10, + "column": 8 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 156, + 157 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 157, + 158 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "count", + "range": [ + 158, + 163 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 163, + 164 + ], + "loc": { + "start": { + "line": 10, + "column": 15 + }, + "end": { + "line": 10, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 164, + 165 + ], + "loc": { + "start": { + "line": 10, + "column": 16 + }, + "end": { + "line": 10, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 10, + "column": 17 + }, + "end": { + "line": 10, + "column": 18 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 166, + 172 + ], + "loc": { + "start": { + "line": 10, + "column": 18 + }, + "end": { + "line": 10, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 10, + "column": 24 + }, + "end": { + "line": 10, + "column": 25 + } + } + } + ], + "range": [ + 0, + 174 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event07-requirements.json b/tests/fixtures/parser/ast/svelte5/ts-event07-requirements.json new file mode 100644 index 00000000..5e330e69 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event07-requirements.json @@ -0,0 +1,5 @@ +{ + "scope": { + "@typescript-eslint/parser": ">=6.5.0" + } +} diff --git a/tests/fixtures/parser/ast/svelte5/ts-event07-scope-output.json b/tests/fixtures/parser/ast/svelte5/ts-event07-scope-output.json new file mode 100644 index 00000000..edb8e8fa --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event07-scope-output.json @@ -0,0 +1,1833 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "$state", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "count", + "identifiers": [ + { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [ + { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "$state", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "optional": false, + "range": [ + 32, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "range": [ + 24, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 117, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 28 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 130, + 135 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 7 + } + } + }, + "from": "function", + "init": false, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 158, + 163 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 15 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "$state", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 158, + 163 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 15 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "e", + "identifiers": [ + { + "type": "Identifier", + "name": "e", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "MouseEvent", + "range": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 75, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 74, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 25 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "e", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "MouseEvent", + "range": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 75, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 74, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "next", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 106, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 102, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "init": { + "type": "BinaryExpression", + "left": { + "type": "Identifier", + "name": "count", + "range": [ + 117, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 28 + } + } + }, + "operator": "+", + "right": { + "type": "Literal", + "raw": "1", + "value": 1, + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 31 + }, + "end": { + "line": 7, + "column": 32 + } + } + }, + "range": [ + 117, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 32 + } + } + }, + "range": [ + 102, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 32 + } + } + } + ], + "range": [ + 96, + 127 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 33 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "left": { + "type": "Identifier", + "name": "count", + "range": [ + 130, + 135 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 7 + } + } + }, + "operator": "=", + "right": { + "type": "Identifier", + "name": "next", + "range": [ + 138, + 142 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "range": [ + 130, + 142 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "range": [ + 130, + 143 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 15 + } + } + } + ], + "range": [ + 92, + 146 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "e", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "MouseEvent", + "range": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 75, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 74, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 25 + } + } + } + ], + "range": [ + 73, + 146 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 9, + "column": 2 + } + } + } + } + ], + "references": [] + }, + { + "name": "next", + "identifiers": [ + { + "type": "Identifier", + "name": "next", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 106, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 102, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 20 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "next", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 106, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 102, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "next", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 106, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 102, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "init": { + "type": "BinaryExpression", + "left": { + "type": "Identifier", + "name": "count", + "range": [ + 117, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 28 + } + } + }, + "operator": "+", + "right": { + "type": "Literal", + "raw": "1", + "value": 1, + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 31 + }, + "end": { + "line": 7, + "column": 32 + } + } + }, + "range": [ + 117, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 32 + } + } + }, + "range": [ + 102, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 32 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "next", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 106, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 102, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "from": "function", + "init": true, + "resolved": { + "type": "Identifier", + "name": "next", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 106, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 102, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 20 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "next", + "range": [ + 138, + 142 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "next", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 106, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 102, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 20 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "MouseEvent", + "range": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "from": "function", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "next", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 106, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 102, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "from": "function", + "init": true, + "resolved": { + "type": "Identifier", + "name": "next", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 106, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 102, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 20 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 117, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 28 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 130, + 135 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 7 + } + } + }, + "from": "function", + "init": false, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "next", + "range": [ + 138, + 142 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 14 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "next", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 106, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "range": [ + 102, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 20 + } + } + } + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "MouseEvent", + "range": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "from": "function", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 117, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 28 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 130, + 135 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 7 + } + } + }, + "from": "function", + "init": false, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "$state", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "MouseEvent", + "range": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event07-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-event07-type-output.svelte new file mode 100644 index 00000000..6c99455f --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event07-type-output.svelte @@ -0,0 +1,10 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-snippet01-input.svelte b/tests/fixtures/parser/ast/svelte5/ts-snippet01-input.svelte new file mode 100644 index 00000000..8c4b133b --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-snippet01-input.svelte @@ -0,0 +1,9 @@ + + +{#snippet foo(msg: string)} +

{msg}

+{/snippet} + +{@render foo(msg)} diff --git a/tests/fixtures/parser/ast/svelte5/ts-snippet01-output.json b/tests/fixtures/parser/ast/svelte5/ts-snippet01-output.json new file mode 100644 index 00000000..274ac1dd --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-snippet01-output.json @@ -0,0 +1,1361 @@ +{ + "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": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "msg", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": { + "type": "Literal", + "raw": "\"\"", + "value": "", + "range": [ + 33, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "range": [ + 27, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + ], + "range": [ + 23, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 36, + 45 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 45 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 45, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteSnippetBlock", + "children": [ + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "p", + "range": [ + 77, + 78 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 76, + 79 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 4 + } + } + }, + "children": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "msg", + "range": [ + 80, + 83 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "range": [ + 79, + 84 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 9 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 84, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + "range": [ + 76, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 13 + } + } + } + ], + "context": { + "type": "Identifier", + "name": "msg", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 66, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 64, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 61, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 57, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 13 + } + } + }, + "range": [ + 47, + 99 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 10 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 99, + 101 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 9, + "column": 0 + } + } + }, + { + "type": "SvelteRenderTag", + "argument": { + "type": "Identifier", + "name": "msg", + "range": [ + 114, + 117 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + "callee": { + "type": "Identifier", + "name": "foo", + "range": [ + 110, + 113 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + "range": [ + 101, + 119 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 18 + } + } + } + ], + "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": "let", + "range": [ + 23, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "msg", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + { + "type": "String", + "value": "\"\"", + "range": [ + 33, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 38, + 44 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 45, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "MustacheKeyword", + "value": "#snippet", + "range": [ + 48, + 56 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 9 + } + } + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 57, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "msg", + "range": [ + 61, + 64 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 66, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "p", + "range": [ + 77, + 78 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 78, + 79 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "msg", + "range": [ + 80, + 83 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 84, + 85 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "p", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + { + "type": "MustacheKeyword", + "value": "/snippet", + "range": [ + 90, + 98 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 10 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 99, + 101 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 9, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + } + }, + { + "type": "MustacheKeyword", + "value": "@render", + "range": [ + 102, + 109 + ], + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 110, + 113 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 113, + 114 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "msg", + "range": [ + 114, + 117 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 9, + "column": 16 + }, + "end": { + "line": 9, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 18 + } + } + } + ], + "range": [ + 0, + 120 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-snippet01-prefer-const-result.json b/tests/fixtures/parser/ast/svelte5/ts-snippet01-prefer-const-result.json new file mode 100644 index 00000000..251523ea --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-snippet01-prefer-const-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "prefer-const", + "code": "msg", + "line": 2, + "column": 9 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-snippet01-scope-output.json b/tests/fixtures/parser/ast/svelte5/ts-snippet01-scope-output.json new file mode 100644 index 00000000..9a8afa35 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-snippet01-scope-output.json @@ -0,0 +1,848 @@ +{ + "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": "msg", + "identifiers": [ + { + "type": "Identifier", + "name": "msg", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "msg", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "msg", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": { + "type": "Literal", + "raw": "\"\"", + "value": "", + "range": [ + 33, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "range": [ + 27, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "msg", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "msg", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "msg", + "range": [ + 114, + 117 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "msg", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + } + } + } + ] + }, + { + "name": "foo", + "identifiers": [ + { + "type": "Identifier", + "name": "foo", + "range": [ + 57, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 13 + } + } + } + ], + "defs": [ + { + "type": "FunctionName", + "name": { + "type": "Identifier", + "name": "foo", + "range": [ + 57, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 13 + } + } + }, + "node": { + "type": "FunctionDeclaration", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": null, + "range": [ + 7, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 13 + } + } + } + ], + "range": [ + 73, + 81 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [], + "range": [ + 48, + 81 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 6, + "column": 6 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "foo", + "range": [ + 110, + 113 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "foo", + "range": [ + 57, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 13 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "msg", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "msg", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "foo", + "range": [ + 110, + 113 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "foo", + "range": [ + 57, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 13 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "msg", + "range": [ + 114, + 117 + ], + "loc": { + "start": { + "line": 9, + "column": 13 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "msg", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 11 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "arguments", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "msg", + "identifiers": [ + { + "type": "Identifier", + "name": "msg", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 66, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 64, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 61, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 25 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "msg", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 66, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 64, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 61, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "node": { + "type": "FunctionDeclaration", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": null, + "range": [ + 7, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 13 + } + } + } + ], + "range": [ + 73, + 81 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [], + "range": [ + 48, + 81 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 6, + "column": 6 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "msg", + "range": [ + 80, + 83 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "msg", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 66, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 64, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 61, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 25 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "msg", + "range": [ + 80, + 83 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 8 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "msg", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 66, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 64, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 61, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 25 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-snippet01-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-snippet01-type-output.svelte new file mode 100644 index 00000000..b1e7053e --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-snippet01-type-output.svelte @@ -0,0 +1,9 @@ + + +{#snippet foo(msg: string)} +

{msg}

+{/snippet} + +{@render foo(msg)} From a15002b45db170854b8367dccc4e20feeb1adac2 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Thu, 23 Nov 2023 13:39:15 +0900 Subject: [PATCH 5/8] update hasTypeInfo --- src/parser/converts/attr.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/parser/converts/attr.ts b/src/parser/converts/attr.ts index 59034a1e..4ae4945c 100644 --- a/src/parser/converts/attr.ts +++ b/src/parser/converts/attr.ts @@ -946,10 +946,7 @@ function buildExpressionTypeChecker( } function hasTypeInfo(element: any): boolean { - if ( - element.type === "TSTypeAnnotation" || - element.type === "TSAsExpression" - ) { + if (element.type.startsWith("TS")) { return true; } for (const key of Object.keys(element)) { From 44d8863586a70cefeabae36d7b6a9ddefd990c35 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Thu, 23 Nov 2023 13:47:10 +0900 Subject: [PATCH 6/8] do we need requirements? --- .../fixtures/parser/ast/svelte5/ts-event07-requirements.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 tests/fixtures/parser/ast/svelte5/ts-event07-requirements.json diff --git a/tests/fixtures/parser/ast/svelte5/ts-event07-requirements.json b/tests/fixtures/parser/ast/svelte5/ts-event07-requirements.json deleted file mode 100644 index 5e330e69..00000000 --- a/tests/fixtures/parser/ast/svelte5/ts-event07-requirements.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "scope": { - "@typescript-eslint/parser": ">=6.5.0" - } -} From c8adb0b0ba254638bc2f5518e0ad31326912e848 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Thu, 23 Nov 2023 13:47:52 +0900 Subject: [PATCH 7/8] fix type error --- src/parser/converts/attr.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/converts/attr.ts b/src/parser/converts/attr.ts index 4ae4945c..35ea5c5f 100644 --- a/src/parser/converts/attr.ts +++ b/src/parser/converts/attr.ts @@ -946,7 +946,7 @@ function buildExpressionTypeChecker( } function hasTypeInfo(element: any): boolean { - if (element.type.startsWith("TS")) { + if (element.type?.startsWith("TS")) { return true; } for (const key of Object.keys(element)) { From 136e6e09178ba9518009dec805d321a846af502d Mon Sep 17 00:00:00 2001 From: baseballyama Date: Thu, 23 Nov 2023 14:10:24 +0900 Subject: [PATCH 8/8] more skip --- src/parser/converts/attr.ts | 22 +- src/parser/converts/mustache.ts | 14 +- src/utils/index.ts | 19 + .../ast/svelte5/ts-event08-input.svelte | 9 + .../parser/ast/svelte5/ts-event08-output.json | 1569 +++++++++++++++++ .../ast/svelte5/ts-event08-scope-output.json | 991 +++++++++++ .../ast/svelte5/ts-event08-type-output.svelte | 9 + 7 files changed, 2610 insertions(+), 23 deletions(-) create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event08-input.svelte create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event08-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event08-scope-output.json create mode 100644 tests/fixtures/parser/ast/svelte5/ts-event08-type-output.svelte diff --git a/src/parser/converts/attr.ts b/src/parser/converts/attr.ts index 35ea5c5f..cc96f7dc 100644 --- a/src/parser/converts/attr.ts +++ b/src/parser/converts/attr.ts @@ -34,6 +34,7 @@ import { ParseError } from "../../errors"; import type { ScriptLetCallback } from "../../context/script-let"; import type { AttributeToken } from "../html"; import { svelteVersion } from "../svelte-version"; +import { hasTypeInfo } from "../../utils"; /** Convert for Attributes */ export function* convertAttributes( @@ -923,7 +924,7 @@ function buildProcessExpressionForExpression( ): (expression: ESTree.Expression) => ScriptLetCallback[] { return (expression) => { if (hasTypeInfo(expression)) { - return ctx.scriptLet.addExpression(expression, directive); + return ctx.scriptLet.addExpression(expression, directive, null); } return ctx.scriptLet.addExpression(expression, directive, typing); }; @@ -944,22 +945,3 @@ function buildExpressionTypeChecker( } }; } - -function hasTypeInfo(element: any): boolean { - if (element.type?.startsWith("TS")) { - return true; - } - for (const key of Object.keys(element)) { - if (key === "parent") continue; - const value = element[key]; - if (value == null) continue; - if (typeof value === "object") { - if (hasTypeInfo(value)) return true; - } else if (Array.isArray(value)) { - for (const v of value) { - if (typeof v === "object" && hasTypeInfo(v)) return true; - } - } - } - return false; -} diff --git a/src/parser/converts/mustache.ts b/src/parser/converts/mustache.ts index 757f96e1..c1be5371 100644 --- a/src/parser/converts/mustache.ts +++ b/src/parser/converts/mustache.ts @@ -6,6 +6,8 @@ import type { } from "../../ast"; import type { Context } from "../../context"; import type * as SvAST from "../svelte-ast-types"; +import { hasTypeInfo } from "../../utils"; + /** Convert for MustacheTag */ export function convertMustacheTag( node: SvAST.MustacheTag, @@ -76,8 +78,14 @@ function convertMustacheTag0( parent, ...ctx.getConvertLocation(node), } as T; - ctx.scriptLet.addExpression(node.expression, mustache, typing, (es) => { - mustache.expression = es; - }); + + ctx.scriptLet.addExpression( + node.expression, + mustache, + hasTypeInfo(node.expression) ? null : typing, + (es) => { + mustache.expression = es; + }, + ); return mustache; } diff --git a/src/utils/index.ts b/src/utils/index.ts index bfbbf380..d54ff0f9 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -59,3 +59,22 @@ export function sortedLastIndex( return upper; } + +export function hasTypeInfo(element: any): boolean { + if (element.type?.startsWith("TS")) { + return true; + } + for (const key of Object.keys(element)) { + if (key === "parent") continue; + const value = element[key]; + if (value == null) continue; + if (typeof value === "object") { + if (hasTypeInfo(value)) return true; + } else if (Array.isArray(value)) { + for (const v of value) { + if (typeof v === "object" && hasTypeInfo(v)) return true; + } + } + } + return false; +} diff --git a/tests/fixtures/parser/ast/svelte5/ts-event08-input.svelte b/tests/fixtures/parser/ast/svelte5/ts-event08-input.svelte new file mode 100644 index 00000000..6856693d --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event08-input.svelte @@ -0,0 +1,9 @@ + + + diff --git a/tests/fixtures/parser/ast/svelte5/ts-event08-output.json b/tests/fixtures/parser/ast/svelte5/ts-event08-output.json new file mode 100644 index 00000000..eced5090 --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event08-output.json @@ -0,0 +1,1569 @@ +{ + "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": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [ + { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "$state", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "optional": false, + "range": [ + 32, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "range": [ + 24, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + ], + "range": [ + 20, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 23 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 43, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 52 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 52, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "button", + "range": [ + 55, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "onclick", + "range": [ + 62, + 69 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 15 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "left": { + "type": "Identifier", + "name": "count", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + "operator": "+=", + "right": { + "type": "Identifier", + "name": "event", + "range": [ + 105, + 110 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 18 + } + } + }, + "range": [ + 96, + 110 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 18 + } + } + }, + "range": [ + 96, + 111 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 19 + } + } + } + ], + "range": [ + 90, + 113 + ], + "loc": { + "start": { + "line": 5, + "column": 36 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "event", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "range": [ + 77, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "range": [ + 72, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 31 + } + } + } + ], + "range": [ + 71, + 113 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + "range": [ + 70, + 114 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 7, + "column": 2 + } + } + } + ], + "range": [ + 62, + 114 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 7, + "column": 2 + } + } + } + ], + "selfClosing": false, + "range": [ + 54, + 115 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "\n\tclicks: ", + "range": [ + 115, + 125 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "count", + "range": [ + 126, + 131 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + "range": [ + 125, + 132 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 16 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 9, + "column": 0 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 133, + 142 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 9 + } + } + }, + "range": [ + 54, + 142 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 9, + "column": 9 + } + } + } + ], + "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": "let", + "range": [ + 20, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + { + "type": "Identifier", + "value": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + { + "type": "Identifier", + "value": "$state", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "Numeric", + "value": "0", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 40, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 45, + 51 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 52, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 55, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 7 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "onclick", + "range": [ + 62, + 69 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 70, + 71 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 71, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "event", + "range": [ + 72, + 77 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 77, + 78 + ], + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 5, + "column": 24 + } + } + }, + { + "type": "Identifier", + "value": "number", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 5, + "column": 31 + }, + "end": { + "line": 5, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 87, + 89 + ], + "loc": { + "start": { + "line": 5, + "column": 33 + }, + "end": { + "line": 5, + "column": 35 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 5, + "column": 36 + }, + "end": { + "line": 5, + "column": 37 + } + } + }, + { + "type": "Identifier", + "value": "count", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "+=", + "range": [ + 102, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 12 + } + } + }, + { + "type": "Identifier", + "value": "event", + "range": [ + 105, + 110 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 113, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 114, + 115 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + { + "type": "HTMLText", + "value": "\n\t", + "range": [ + 115, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 8, + "column": 1 + } + } + }, + { + "type": "HTMLText", + "value": "clicks:", + "range": [ + 117, + 124 + ], + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 8 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 124, + 125 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "count", + "range": [ + 126, + 131 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 8, + "column": 15 + }, + "end": { + "line": 8, + "column": 16 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 8, + "column": 16 + }, + "end": { + "line": 9, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "button", + "range": [ + 135, + 141 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 141, + 142 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + } + } + ], + "range": [ + 0, + 143 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event08-scope-output.json b/tests/fixtures/parser/ast/svelte5/ts-event08-scope-output.json new file mode 100644 index 00000000..85f4859b --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event08-scope-output.json @@ -0,0 +1,991 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$state", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "$state", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + }, + { + "name": "$derived", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$effect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$props", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "count", + "identifiers": [ + { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "arguments": [ + { + "type": "Literal", + "raw": "0", + "value": 0, + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "$state", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "optional": false, + "range": [ + 32, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + "range": [ + 24, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + "from": "function", + "init": false, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 126, + 131 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "$state", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 126, + 131 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "event", + "identifiers": [ + { + "type": "Identifier", + "name": "event", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "range": [ + 77, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "range": [ + 72, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 31 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "event", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "range": [ + 77, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "range": [ + 72, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "left": { + "type": "Identifier", + "name": "count", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + "operator": "+=", + "right": { + "type": "Identifier", + "name": "event", + "range": [ + 105, + 110 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 18 + } + } + }, + "range": [ + 96, + 110 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 18 + } + } + }, + "range": [ + 96, + 111 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 19 + } + } + } + ], + "range": [ + 90, + 113 + ], + "loc": { + "start": { + "line": 5, + "column": 36 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "event", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "range": [ + 77, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "range": [ + 72, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 31 + } + } + } + ], + "range": [ + 71, + 113 + ], + "loc": { + "start": { + "line": 5, + "column": 17 + }, + "end": { + "line": 7, + "column": 1 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "event", + "range": [ + 105, + 110 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 18 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "event", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "range": [ + 77, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "range": [ + 72, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 31 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + "from": "function", + "init": false, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "event", + "range": [ + 105, + 110 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 18 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "event", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "range": [ + 77, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 5, + "column": 31 + } + } + }, + "range": [ + 72, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 18 + }, + "end": { + "line": 5, + "column": 31 + } + } + } + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + "from": "function", + "init": false, + "resolved": { + "type": "Identifier", + "name": "count", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + } + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "$state", + "range": [ + 32, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/svelte5/ts-event08-type-output.svelte b/tests/fixtures/parser/ast/svelte5/ts-event08-type-output.svelte new file mode 100644 index 00000000..acf2de8c --- /dev/null +++ b/tests/fixtures/parser/ast/svelte5/ts-event08-type-output.svelte @@ -0,0 +1,9 @@ + + +