Skip to content

Commit 288d915

Browse files
committed
fix: handle updated Snippet block AST shape
fixes #428
1 parent 99c885e commit 288d915

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- (feat) format JSON script tags
66
- (fix) don't duplicate comments of nested script/style tags
7+
- (fix) handle updated `Snippet` block AST shape
78

89
## 3.1.2
910

src/embed.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function embed(path: FastPath, _options: Options) {
7575

7676
// embed does depth first traversal with deepest node called first, therefore we need to
7777
// check the parent to see if we are inside an expression that should be embedded.
78-
const parent = path.getParentNode();
78+
const parent: Node = path.getParentNode();
7979
const printJsExpression = () =>
8080
(parent as any).expression
8181
? printJS(parent, options.svelteStrictMode ?? false, false, false, 'expression')
@@ -99,9 +99,12 @@ export function embed(path: FastPath, _options: Options) {
9999
parent.expression.end =
100100
options.originalText.indexOf(
101101
')',
102-
parent.context?.end ?? parent.expression.end,
102+
parent.context?.end ?? // TODO: remove at some point, snippet API changed in .next-..
103+
parent.parameters?.[parent.parameters.length - 1]?.end ??
104+
parent.expression.end,
103105
) + 1;
104106
parent.context = null;
107+
parent.parameters = null;
105108
printSvelteBlockJS('expression');
106109
}
107110
break;

src/print/nodes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ export interface CommentInfo {
294294
export interface SnippetBlock extends BaseNode {
295295
type: 'SnippetBlock';
296296
expression: IdentifierNode;
297-
context: null | any;
297+
context?: BaseNode | null; // TODO: remove at some point, snippet API changed in .next-..
298+
parameters: BaseNode[] | null;
298299
children: Node[];
299300
}
300301

0 commit comments

Comments
 (0)