diff --git a/package.json b/package.json index 37508be4..6d4b5d4c 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.10" + "svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.15" }, "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.10", + "svelte": "^5.0.0-next.15", "svelte2tsx": "^0.6.25", "typescript": "~5.1.3", "typescript-eslint-parser-for-extra-files": "^0.5.0" diff --git a/src/context/script-let.ts b/src/context/script-let.ts index 7d594dc5..103f9db4 100644 --- a/src/context/script-let.ts +++ b/src/context/script-let.ts @@ -243,11 +243,11 @@ export class ScriptLetContext { } public addVariableDeclarator( - expression: ESTree.AssignmentExpression, + declarator: ESTree.VariableDeclarator | ESTree.AssignmentExpression, parent: SvelteNode, ...callbacks: ScriptLetCallback[] ): ScriptLetCallback[] { - const range = getNodeRange(expression); + const range = getNodeRange(declarator); const part = this.ctx.code.slice(...range); this.appendScript( `const ${part};`, diff --git a/src/parser/compat.ts b/src/parser/compat.ts index d7d04bc8..17cb73bd 100644 --- a/src/parser/compat.ts +++ b/src/parser/compat.ts @@ -204,7 +204,6 @@ export function getThenFromAwaitBlock( } return then.skip ? null : then; } - export function getCatchFromAwaitBlock( block: SvAST.AwaitBlock | Compiler.AwaitBlock, ): Compiler.Fragment | SvAST.CatchBlock | null { @@ -217,3 +216,15 @@ export function getCatchFromAwaitBlock( } return catchFragment.skip ? null : catchFragment; } + +// ConstTag +export function getDeclaratorFromConstTag( + node: SvAST.ConstTag | Compiler.ConstTag, +): + | ESTree.AssignmentExpression + | Compiler.ConstTag["declaration"]["declarations"][0] { + return ( + (node as Compiler.ConstTag).declaration?.declarations?.[0] ?? + (node as SvAST.ConstTag).expression + ); +} diff --git a/src/parser/converts/const.ts b/src/parser/converts/const.ts index 9aeea7b6..3f9684c5 100644 --- a/src/parser/converts/const.ts +++ b/src/parser/converts/const.ts @@ -1,10 +1,12 @@ import type { SvelteConstTag } from "../../ast"; import type { Context } from "../../context"; +import { getDeclaratorFromConstTag } from "../compat"; import type * as SvAST from "../svelte-ast-types"; +import type * as Compiler from "svelte/compiler"; /** Convert for ConstTag */ export function convertConstTag( - node: SvAST.ConstTag, + node: SvAST.ConstTag | Compiler.ConstTag, parent: SvelteConstTag["parent"], ctx: Context, ): SvelteConstTag { @@ -15,7 +17,7 @@ export function convertConstTag( ...ctx.getConvertLocation(node), }; ctx.scriptLet.addVariableDeclarator( - node.expression, + getDeclaratorFromConstTag(node), mustache, (declaration) => { mustache.declaration = declaration;