Skip to content

Commit f7c311b

Browse files
authored
(fix) handle action on svelte:body (#1170)
Narrows the type to HTMLBodyElement
1 parent 6300670 commit f7c311b

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

packages/svelte2tsx/src/htmlxtojsx/nodes/action-directive.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ export function handleActionDirective(
1212
parent: BaseNode
1313
): void {
1414
str.overwrite(attr.start, attr.start + 'use:'.length, '{...__sveltets_1_ensureAction(');
15+
const name = parent.name === 'svelte:body' ? 'body' : parent.name;
1516

1617
if (!attr.expression) {
17-
str.appendLeft(attr.end, `(__sveltets_1_mapElementTag('${parent.name}')))}`);
18+
str.appendLeft(attr.end, `(__sveltets_1_mapElementTag('${name}')))}`);
1819
return;
1920
}
2021

2122
str.overwrite(
2223
attr.start + `use:${attr.name}`.length,
2324
attr.expression.start,
24-
`(__sveltets_1_mapElementTag('${parent.name}'),(`
25+
`(__sveltets_1_mapElementTag('${name}'),(`
2526
);
2627
str.appendLeft(attr.expression.end, ')))');
2728
const lastChar = htmlx[attr.end - 1];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<><sveltebody {...__sveltets_1_ensureAction(blink(__sveltets_1_mapElementTag('body')))} /></>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<svelte:body use:blink />

0 commit comments

Comments
 (0)