Skip to content

Commit

Permalink
fix: handle updated Snippet block AST shape
Browse files Browse the repository at this point in the history
fixes #428
  • Loading branch information
dummdidumm committed Feb 13, 2024
1 parent 99c885e commit 288d915
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/print/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}

Expand Down

0 comments on commit 288d915

Please sign in to comment.