Skip to content

Commit

Permalink
fix: adjust render tag printing for Svelte 5 AST changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Feb 28, 2024
1 parent 08d7a8b commit c968fef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,19 @@ export function embed(path: FastPath, _options: Options) {
printJS(parent, false, false, true, 'expression');
break;
case 'RenderTag':
// We merge the two parts into one expression, which future-proofs this for template TS support
if (node === parent.expression) {
parent.expression.end =
options.originalText.indexOf(
')',
parent.argument?.end ?? // TODO: remove at some point, snippet API changed in .next-..
parent.arguments?.[parent.arguments.length - 1]?.end ??
parent.expression.end,
) + 1;
parent.argument = null;
// TODO: remove this if block at some point, snippet API changed in .next-..
if ('argument' in parent || 'arguments' in parent) {
parent.expression.end =
options.originalText.indexOf(
')',
parent.argument?.end ??
parent.arguments?.[parent.arguments.length - 1]?.end ??
parent.expression.end,
) + 1;
parent.argument = null;
parent.arguments = null;
}
printJS(parent, false, false, false, 'expression');
}
break;
Expand Down
3 changes: 3 additions & 0 deletions test/printer/samples/snippet.html.skip
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
</div>

{@render foo()}
{@render foo?.()}
{@render bar(x)}
{@render bar.baz[buzz](x)}
{@render (why ? not : like ?? thiss)(x)}
{@render test((() => "a")())}
{@render test(t())}

0 comments on commit c968fef

Please sign in to comment.