diff --git a/src/compile/nodes/Slot.ts b/src/compile/nodes/Slot.ts index fe9e1ff0e8..0a4f4af848 100644 --- a/src/compile/nodes/Slot.ts +++ b/src/compile/nodes/Slot.ts @@ -34,13 +34,6 @@ export default class Slot extends Element { message: `default is a reserved word — it cannot be used as a slot name` }); } - - if (/^[0-9]/.test(slot_name)) { - component.error(attr, { - code: `invalid-slot-name`, - message: ` name cannot start with a digit` - }); - } } // TODO should duplicate slots be disallowed? Feels like it's more likely to be a @@ -77,4 +70,4 @@ export default class Slot extends Element { return null; } -} +} \ No newline at end of file diff --git a/src/utils/names.ts b/src/utils/names.ts index 317379198f..1f0a9cc29e 100644 --- a/src/utils/names.ts +++ b/src/utils/names.ts @@ -111,5 +111,9 @@ export function quote_prop_if_necessary(name: string) { } export function sanitize(name: string) { - return name.replace(/[^a-zA-Z0-9_]+/g, '_').replace(/^_/, '').replace(/_$/, ''); + return name + .replace(/[^a-zA-Z0-9_]+/g, '_') + .replace(/^_/, '') + .replace(/_$/, '') + .replace(/^[0-9]/, '_$&'); } diff --git a/test/js/samples/slot-names/expected.js b/test/js/samples/slot-names/expected.js deleted file mode 100644 index a538888651..0000000000 --- a/test/js/samples/slot-names/expected.js +++ /dev/null @@ -1,121 +0,0 @@ -/* 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 deleted file mode 100644 index 986fb798f4..0000000000 --- a/test/js/samples/slot-names/input.svelte +++ /dev/null @@ -1,5 +0,0 @@ -
- - - -
diff --git a/test/runtime/samples/slot-names/Nested.svelte b/test/runtime/samples/slot-names/Nested.svelte new file mode 100644 index 0000000000..70037db27e --- /dev/null +++ b/test/runtime/samples/slot-names/Nested.svelte @@ -0,0 +1,6 @@ +
+ + + + +
diff --git a/test/runtime/samples/slot-names/_config.js b/test/runtime/samples/slot-names/_config.js new file mode 100644 index 0000000000..c94d09edef --- /dev/null +++ b/test/runtime/samples/slot-names/_config.js @@ -0,0 +1,10 @@ +export default { + html: ` +
+

Header 1

+

Header 2

+

Header 3

+

Header 4

+
+ ` +}; diff --git a/test/runtime/samples/slot-names/main.svelte b/test/runtime/samples/slot-names/main.svelte new file mode 100644 index 0000000000..3538bc49e3 --- /dev/null +++ b/test/runtime/samples/slot-names/main.svelte @@ -0,0 +1,10 @@ + + + +

Header 1

+

Header 2

+

Header 3

+

Header 4

+
diff --git a/test/validator/samples/slot-name-starts-with-a-digit/errors.json b/test/validator/samples/slot-name-starts-with-a-digit/errors.json deleted file mode 100644 index a898e6e282..0000000000 --- a/test/validator/samples/slot-name-starts-with-a-digit/errors.json +++ /dev/null @@ -1,15 +0,0 @@ -[{ - "code": "invalid-slot-name", - "message": " name cannot start with a digit", - "start": { - "line": 2, - "column": 7, - "character": 13 - }, - "end": { - "line": 2, - "column": 21, - "character": 27 - }, - "pos": 13 -}] diff --git a/test/validator/samples/slot-name-starts-with-a-digit/input.svelte b/test/validator/samples/slot-name-starts-with-a-digit/input.svelte deleted file mode 100644 index ae9ede75ba..0000000000 --- a/test/validator/samples/slot-name-starts-with-a-digit/input.svelte +++ /dev/null @@ -1,3 +0,0 @@ -
- -