Skip to content

Commit aea9727

Browse files
committed
fix: support for new ConstTag node
1 parent c79b0f7 commit aea9727

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"version:ci": "env-cmd -e version-ci pnpm run build:meta && changeset version"
4747
},
4848
"peerDependencies": {
49-
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.10"
49+
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.15"
5050
},
5151
"peerDependenciesMeta": {
5252
"svelte": {
@@ -104,7 +104,7 @@
104104
"prettier-plugin-svelte": "^3.0.0",
105105
"rimraf": "^5.0.1",
106106
"semver": "^7.5.1",
107-
"svelte": "^5.0.0-next.10",
107+
"svelte": "^5.0.0-next.15",
108108
"svelte2tsx": "^0.6.25",
109109
"typescript": "~5.1.3",
110110
"typescript-eslint-parser-for-extra-files": "^0.5.0"

src/context/script-let.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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};`,

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)