File tree Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -243,11 +243,11 @@ export class ScriptLetContext {
243243 }
244244
245245 public addVariableDeclarator (
246- expression : ESTree . AssignmentExpression ,
246+ declarator : ESTree . VariableDeclarator | ESTree . AssignmentExpression ,
247247 parent : SvelteNode ,
248248 ...callbacks : ScriptLetCallback < ESTree . VariableDeclarator > [ ]
249249 ) : ScriptLetCallback < ESTree . VariableDeclarator > [ ] {
250- const range = getNodeRange ( expression ) ;
250+ const range = getNodeRange ( declarator ) ;
251251 const part = this . ctx . code . slice ( ...range ) ;
252252 this . appendScript (
253253 `const ${ part } ;` ,
Original file line number Diff line number Diff line change @@ -204,7 +204,6 @@ export function getThenFromAwaitBlock(
204204 }
205205 return then . skip ? null : then ;
206206}
207-
208207export function getCatchFromAwaitBlock (
209208 block : SvAST . AwaitBlock | Compiler . AwaitBlock ,
210209) : Compiler . Fragment | SvAST . CatchBlock | null {
@@ -217,3 +216,15 @@ export function getCatchFromAwaitBlock(
217216 }
218217 return catchFragment . skip ? null : catchFragment ;
219218}
219+
220+ // ConstTag
221+ export function getDeclaratorFromConstTag (
222+ node : SvAST . ConstTag | Compiler . ConstTag ,
223+ ) :
224+ | ESTree . AssignmentExpression
225+ | Compiler . ConstTag [ "declaration" ] [ "declarations" ] [ 0 ] {
226+ return (
227+ ( node as Compiler . ConstTag ) . declaration ?. declarations ?. [ 0 ] ??
228+ ( node as SvAST . ConstTag ) . expression
229+ ) ;
230+ }
Original file line number Diff line number Diff line change 11import type { SvelteConstTag } from "../../ast" ;
22import type { Context } from "../../context" ;
3+ import { getDeclaratorFromConstTag } from "../compat" ;
34import type * as SvAST from "../svelte-ast-types" ;
5+ import type * as Compiler from "svelte/compiler" ;
46
57/** Convert for ConstTag */
68export function convertConstTag (
7- node : SvAST . ConstTag ,
9+ node : SvAST . ConstTag | Compiler . ConstTag ,
810 parent : SvelteConstTag [ "parent" ] ,
911 ctx : Context ,
1012) : SvelteConstTag {
@@ -15,7 +17,7 @@ export function convertConstTag(
1517 ...ctx . getConvertLocation ( node ) ,
1618 } ;
1719 ctx . scriptLet . addVariableDeclarator (
18- node . expression ,
20+ getDeclaratorFromConstTag ( node ) ,
1921 mustache ,
2022 ( declaration ) => {
2123 mustache . declaration = declaration ;
You can’t perform that action at this time.
0 commit comments