pull/7324/head
Ivan Hofer 4 years ago
parent c2e05e1939
commit c5594717ab

@ -350,15 +350,9 @@ export function set_svg_attributes(node: Element & ElementCSSInlineStyle, attrib
} }
} }
export function set_custom_element_data_map(node, data_map: Record<string, unknown>) { export function set_custom_element_data_map(node: Element, data_map: Record<string, unknown>) {
Object.keys(data_map).forEach((key) => { Object.keys(data_map).forEach((key) => {
set_custom_element_data(node, key, data_map[key]); set_custom_element_data(node, key, data_map[key] as TODO<string>);
});
}
export function set_custom_element_data_map(node, data_map: Record<string, unknown>) {
Object.keys(data_map).forEach((key) => {
set_custom_element_data(node, key, data_map[key]);
}); });
} }
@ -548,6 +542,7 @@ export function claim_html_tag(nodes: ChildNodeArray, is_svg: boolean) {
const start_index = find_comment(nodes, 'HTML_TAG_START', 0); const start_index = find_comment(nodes, 'HTML_TAG_START', 0);
const end_index = find_comment(nodes, 'HTML_TAG_END', start_index); const end_index = find_comment(nodes, 'HTML_TAG_END', start_index);
if (start_index === end_index) { if (start_index === end_index) {
// @ts-expect-error `HtmlTagHydration` does not expect a second parameter
return new HtmlTagHydration(undefined, is_svg); return new HtmlTagHydration(undefined, is_svg);
} }
@ -560,6 +555,7 @@ export function claim_html_tag(nodes: ChildNodeArray, is_svg: boolean) {
n.claim_order = (nodes.claim_info as TODO<ClaimInfo>).total_claimed; n.claim_order = (nodes.claim_info as TODO<ClaimInfo>).total_claimed;
(nodes.claim_info as TODO<ClaimInfo>).total_claimed += 1; (nodes.claim_info as TODO<ClaimInfo>).total_claimed += 1;
} }
// @ts-expect-error `HtmlTagHydration` does not expect a second parameter
return new HtmlTagHydration(claimed_nodes, is_svg); return new HtmlTagHydration(claimed_nodes, is_svg);
} }
@ -779,8 +775,8 @@ export class HtmlTagHydration extends HtmlTag {
// hydration claimed nodes // hydration claimed nodes
l: ChildNode[] | void; l: ChildNode[] | void;
constructor(claimed_nodes?: ChildNode[], is_svg: boolean = false) { constructor(claimed_nodes?: ChildNode[]) {
super(is_svg); super();
this.e = this.n = null; this.e = this.n = null;
this.l = claimed_nodes; this.l = claimed_nodes;
} }
@ -814,6 +810,6 @@ export function get_custom_elements_slots(element: HTMLElement) {
return result; return result;
} }
export function construct_svelte_component(component, props) { export function construct_svelte_component(component: TODO, props: Record<string, unknown>) {
return new component(props); return new component(props);
} }

@ -56,6 +56,10 @@ export function onDestroy(fn: () => any) {
get_current_component().$$.on_destroy.push(fn); get_current_component().$$.on_destroy.push(fn);
} }
export interface DispatchOptions {
cancelable?: boolean;
}
/** /**
* Creates an event dispatcher that can be used to dispatch [component events](/docs#template-syntax-component-directives-on-eventname). * Creates an event dispatcher that can be used to dispatch [component events](/docs#template-syntax-component-directives-on-eventname).
* Event dispatchers are functions that can take two arguments: `name` and `detail`. * Event dispatchers are functions that can take two arguments: `name` and `detail`.

@ -1,5 +1,5 @@
import { Readable, Subscriber, Invalidator, Writable } from 'svelte/store'; import { Readable, Subscriber, Invalidator, Writable } from 'svelte/store';
import { SvelteComponent } from '..'; import { SvelteComponent } from '../index.js';
export function noop() { } export function noop() { }

@ -1,33 +1,35 @@
import { createEventDispatcher } from '$runtime/internal/lifecycle'; // TODO: enable those tests when #7224 got merged
const dispatch = createEventDispatcher<{ // import { createEventDispatcher } from '$runtime/internal/lifecycle';
loaded: never
change: string
valid: boolean
optional: number | null
}>();
// @ts-expect-error: dispatch invalid event // const dispatch = createEventDispatcher<{
dispatch('some-event'); // loaded: never
// change: string
// valid: boolean
// optional: number | null
// }>();
dispatch('loaded'); // // @ts-expect-error: dispatch invalid event
// @ts-expect-error: no detail accepted // dispatch('some-event');
dispatch('loaded', 123);
// @ts-expect-error: detail not provided // dispatch('loaded');
dispatch('change'); // // @ts-expect-error: no detail accepted
dispatch('change', 'string'); // dispatch('loaded', 123);
// @ts-expect-error: wrong type of detail
dispatch('change', 123);
// @ts-expect-error: wrong type of detail
dispatch('change', undefined);
dispatch('valid', true); // // @ts-expect-error: detail not provided
// @ts-expect-error: wrong type of detail // dispatch('change');
dispatch('valid', 'string'); // dispatch('change', 'string');
// // @ts-expect-error: wrong type of detail
// dispatch('change', 123);
// // @ts-expect-error: wrong type of detail
// dispatch('change', undefined);
dispatch('optional'); // dispatch('valid', true);
dispatch('optional', 123); // // @ts-expect-error: wrong type of detail
dispatch('optional', null); // dispatch('valid', 'string');
// @ts-expect-error: wrong type of optional detail
dispatch('optional', 'string'); // dispatch('optional');
// dispatch('optional', 123);
// dispatch('optional', null);
// // @ts-expect-error: wrong type of optional detail
// dispatch('optional', 'string');

Loading…
Cancel
Save