Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/svelte2tsx/src/htmlxtojsx/nodes/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export function handleBinding(htmlx: string, str: MagicString, attr: Node, el: N
return;
}

const supportsBindThis = ['InlineComponent', 'Element', 'Body'];
const supportsBindThis = [
'InlineComponent',
'Element',
'Body',
'Slot' // only valid for Web Components compile target
];

//bind this
if (attr.name === 'this' && supportsBindThis.includes(el.type)) {
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte2tsx/src/htmlxtojsx/utils/node-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export function getThisType(node: Node): string | undefined {
return `__sveltets_ctorOf(__sveltets_mapElementTag('${node.name}'))`;
case 'Body':
return 'HTMLBodyElement';
case 'Slot': // Web Components only
return 'HTMLSlotElement';
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/svelte2tsx/src/svelte2tsx/nodes/slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class SlotHandler {
const attributes = new Map<string, string>();
for (const attr of node.attributes) {
if (attr.name == 'name') continue;
if (!attr.value.length) continue;
if (!attr.value?.length) continue;

if (attributeValueIsString(attr)) {
attributes.set(attr.name, attributeStrValueAsJsExpression(attr));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
///<reference types="svelte" />
<></>;function render() {
<><slot name="s" {...__sveltets_ensureType(HTMLSlotElement, s)} /></>
return { props: {}, slots: {'s': {}}, getters: {}, events: {} }}

export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<slot name="s" bind:this={s} />