diff --git a/src/utils/names.ts b/src/utils/names.ts index 5047fe850c..317379198f 100644 --- a/src/utils/names.ts +++ b/src/utils/names.ts @@ -111,5 +111,5 @@ export function quote_prop_if_necessary(name: string) { } export function sanitize(name: string) { - return name.replace(/[^a-zA-Z]+/g, '_').replace(/^_/, '').replace(/_$/, ''); -} \ No newline at end of file + return name.replace(/[^a-zA-Z0-9_]+/g, '_').replace(/^_/, '').replace(/_$/, ''); +} diff --git a/test/js/samples/slot-names/expected.js b/test/js/samples/slot-names/expected.js new file mode 100644 index 0000000000..a538888651 --- /dev/null +++ b/test/js/samples/slot-names/expected.js @@ -0,0 +1,121 @@ +/* generated by Svelte vX.Y.Z */ +import { + SvelteComponent as SvelteComponent_1, + append, + create_slot, + detach, + element, + get_slot_changes, + get_slot_context, + init, + insert, + noop, + safe_not_equal, + space +} from "svelte/internal"; + +function create_fragment(ctx) { + var div, t0, t1; + + const header_1_slot_1 = ctx.$$slot_header_1; + const header_1_slot = create_slot(header_1_slot_1, ctx, null); + + const header_2__slot_1 = ctx.$$slot_header_2_; + const header_2__slot = create_slot(header_2__slot_1, ctx, null); + + const header_3_slot_1 = ctx.$$slot_header_3; + const header_3_slot = create_slot(header_3_slot_1, ctx, null); + + return { + c() { + div = element("div"); + + if (header_1_slot) header_1_slot.c(); + t0 = space(); + + if (header_2__slot) header_2__slot.c(); + t1 = space(); + + if (header_3_slot) header_3_slot.c(); + }, + + l(nodes) { + if (header_1_slot) header_1_slot.l(div_nodes); + if (header_2__slot) header_2__slot.l(div_nodes); + if (header_3_slot) header_3_slot.l(div_nodes); + }, + + m(target, anchor) { + insert(target, div, anchor); + + if (header_1_slot) { + header_1_slot.m(div, null); + } + + append(div, t0); + + if (header_2__slot) { + header_2__slot.m(div, null); + } + + append(div, t1); + + if (header_3_slot) { + header_3_slot.m(div, null); + } + }, + + p(changed, ctx) { + if (header_1_slot && header_1_slot.p && changed.$$scope) { + header_1_slot.p(get_slot_changes(header_1_slot_1, ctx, changed,), get_slot_context(header_1_slot_1, ctx, null)); + } + + if (header_2__slot && header_2__slot.p && changed.$$scope) { + header_2__slot.p(get_slot_changes(header_2__slot_1, ctx, changed,), get_slot_context(header_2__slot_1, ctx, null)); + } + + if (header_3_slot && header_3_slot.p && changed.$$scope) { + header_3_slot.p(get_slot_changes(header_3_slot_1, ctx, changed,), get_slot_context(header_3_slot_1, ctx, null)); + } + }, + + i: noop, + o: noop, + + d(detaching) { + if (detaching) { + detach(div); + } + + if (header_1_slot) header_1_slot.d(detaching); + + if (header_2__slot) header_2__slot.d(detaching); + + if (header_3_slot) header_3_slot.d(detaching); + } + }; +} + +function instance($$self, $$props, $$invalidate) { + let { $$slot_header_1, $$slot_header_2_, $$slot_header_3, $$scope } = $$props; + + $$self.$set = $$props => { + if ('$$scope' in $$props) $$invalidate('$$scope', $$scope = $$props.$$scope); + }; + + return { + $$slot_header_1, + $$slot_header_2_, + $$slot_header_3, + $$scope + }; +} + +class SvelteComponent extends SvelteComponent_1 { + constructor(options) { + super(); + init(this, options, instance, create_fragment, safe_not_equal, []); + } +} + +export default SvelteComponent; diff --git a/test/js/samples/slot-names/input.svelte b/test/js/samples/slot-names/input.svelte new file mode 100644 index 0000000000..986fb798f4 --- /dev/null +++ b/test/js/samples/slot-names/input.svelte @@ -0,0 +1,5 @@ +