Skip to content

Commit

Permalink
fix: support for new ConstTag node
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Nov 30, 2023
1 parent be5eecb commit 9a384fe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/context/script-let.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ export class ScriptLetContext {
}

public addVariableDeclarator(
expression: ESTree.AssignmentExpression,
declarator: ESTree.VariableDeclarator | ESTree.AssignmentExpression,
parent: SvelteNode,
...callbacks: ScriptLetCallback<ESTree.VariableDeclarator>[]
): ScriptLetCallback<ESTree.VariableDeclarator>[] {
const range = getNodeRange(expression);
const range = getNodeRange(declarator);
const part = this.ctx.code.slice(...range);
this.appendScript(
`const ${part};`,
Expand Down
13 changes: 12 additions & 1 deletion src/parser/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
);
}
6 changes: 4 additions & 2 deletions src/parser/converts/const.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -15,7 +17,7 @@ export function convertConstTag(
...ctx.getConvertLocation(node),
};
ctx.scriptLet.addVariableDeclarator(
node.expression,
getDeclaratorFromConstTag(node),
mustache,
(declaration) => {
mustache.declaration = declaration;
Expand Down

0 comments on commit 9a384fe

Please sign in to comment.