This is a reproduction of the bug of Svelte's $host() rune:
If you assign $host() to a variable, the assignment statement will be removed after compilation.
function fail(greeting: string) {
const element = $host() as HTMLElement;
element.dispatchEvent(
new CustomEvent('greeting', { detail: greeting })
);
}
function fail(greeting) {
element.dispatchEvent(new CustomEvent("greeting", { detail: greeting }));
}
Which will throw ReferenceError: element is not defined
in runtime.