Skip to content

Commit 70f0d06

Browse files
committed
fix: support for new ConstTag node
1 parent dd7374f commit 70f0d06

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/context/script-let.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ export class ScriptLetContext {
246246
}
247247

248248
public addVariableDeclarator(
249-
expression: ESTree.AssignmentExpression,
249+
declarator: ESTree.VariableDeclarator | ESTree.AssignmentExpression,
250250
parent: SvelteNode,
251251
...callbacks: ScriptLetCallback<ESTree.VariableDeclarator>[]
252252
): ScriptLetCallback<ESTree.VariableDeclarator>[] {
253-
const range = getNodeRange(expression);
253+
const range = getNodeRange(declarator);
254254
const part = this.ctx.code.slice(...range);
255255
this.appendScript(
256256
`const ${part};`,

src/parser/compat.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ export function getThenFromAwaitBlock(
204204
}
205205
return then.skip ? null : then;
206206
}
207-
208207
export 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+
}

src/parser/converts/const.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import type { SvelteConstTag } from "../../ast";
22
import type { Context } from "../../context";
3+
import { getDeclaratorFromConstTag } from "../compat";
34
import type * as SvAST from "../svelte-ast-types";
5+
import type * as Compiler from "svelte/compiler";
46

57
/** Convert for ConstTag */
68
export 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;

0 commit comments

Comments
 (0)