File tree 3 files changed +18
-5
lines changed
3 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -243,11 +243,11 @@ export class ScriptLetContext {
243
243
}
244
244
245
245
public addVariableDeclarator (
246
- expression : ESTree . AssignmentExpression ,
246
+ declarator : ESTree . VariableDeclarator | ESTree . AssignmentExpression ,
247
247
parent : SvelteNode ,
248
248
...callbacks : ScriptLetCallback < ESTree . VariableDeclarator > [ ]
249
249
) : ScriptLetCallback < ESTree . VariableDeclarator > [ ] {
250
- const range = getNodeRange ( expression ) ;
250
+ const range = getNodeRange ( declarator ) ;
251
251
const part = this . ctx . code . slice ( ...range ) ;
252
252
this . appendScript (
253
253
`const ${ part } ;` ,
Original file line number Diff line number Diff line change @@ -204,7 +204,6 @@ export function getThenFromAwaitBlock(
204
204
}
205
205
return then . skip ? null : then ;
206
206
}
207
-
208
207
export function getCatchFromAwaitBlock (
209
208
block : SvAST . AwaitBlock | Compiler . AwaitBlock ,
210
209
) : Compiler . Fragment | SvAST . CatchBlock | null {
@@ -217,3 +216,15 @@ export function getCatchFromAwaitBlock(
217
216
}
218
217
return catchFragment . skip ? null : catchFragment ;
219
218
}
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 1
1
import type { SvelteConstTag } from "../../ast" ;
2
2
import type { Context } from "../../context" ;
3
+ import { getDeclaratorFromConstTag } from "../compat" ;
3
4
import type * as SvAST from "../svelte-ast-types" ;
5
+ import type * as Compiler from "svelte/compiler" ;
4
6
5
7
/** Convert for ConstTag */
6
8
export function convertConstTag (
7
- node : SvAST . ConstTag ,
9
+ node : SvAST . ConstTag | Compiler . ConstTag ,
8
10
parent : SvelteConstTag [ "parent" ] ,
9
11
ctx : Context ,
10
12
) : SvelteConstTag {
@@ -15,7 +17,7 @@ export function convertConstTag(
15
17
...ctx . getConvertLocation ( node ) ,
16
18
} ;
17
19
ctx . scriptLet . addVariableDeclarator (
18
- node . expression ,
20
+ getDeclaratorFromConstTag ( node ) ,
19
21
mustache ,
20
22
( declaration ) => {
21
23
mustache . declaration = declaration ;
You can’t perform that action at this time.
0 commit comments