diff --git a/CHANGELOG.md b/CHANGELOG.md index ef0f13d..988f36f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - (feat) format JSON script tags - (fix) don't duplicate comments of nested script/style tags +- (fix) handle updated `Snippet` block AST shape ## 3.1.2 diff --git a/src/embed.ts b/src/embed.ts index c04a953..6af912c 100644 --- a/src/embed.ts +++ b/src/embed.ts @@ -75,7 +75,7 @@ export function embed(path: FastPath, _options: Options) { // embed does depth first traversal with deepest node called first, therefore we need to // check the parent to see if we are inside an expression that should be embedded. - const parent = path.getParentNode(); + const parent: Node = path.getParentNode(); const printJsExpression = () => (parent as any).expression ? printJS(parent, options.svelteStrictMode ?? false, false, false, 'expression') @@ -99,9 +99,12 @@ export function embed(path: FastPath, _options: Options) { parent.expression.end = options.originalText.indexOf( ')', - parent.context?.end ?? parent.expression.end, + parent.context?.end ?? // TODO: remove at some point, snippet API changed in .next-.. + parent.parameters?.[parent.parameters.length - 1]?.end ?? + parent.expression.end, ) + 1; parent.context = null; + parent.parameters = null; printSvelteBlockJS('expression'); } break; diff --git a/src/print/nodes.ts b/src/print/nodes.ts index b5e56b5..c8c13ce 100644 --- a/src/print/nodes.ts +++ b/src/print/nodes.ts @@ -294,7 +294,8 @@ export interface CommentInfo { export interface SnippetBlock extends BaseNode { type: 'SnippetBlock'; expression: IdentifierNode; - context: null | any; + context?: BaseNode | null; // TODO: remove at some point, snippet API changed in .next-.. + parameters: BaseNode[] | null; children: Node[]; }