diff --git a/src/compile/nodes/Slot.ts b/src/compile/nodes/Slot.ts index 0a4f4af848..fe9e1ff0e8 100644 --- a/src/compile/nodes/Slot.ts +++ b/src/compile/nodes/Slot.ts @@ -34,6 +34,13 @@ 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 @@ -70,4 +77,4 @@ export default class Slot extends Element { return null; } -} \ No newline at end of file +} 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 new file mode 100644 index 0000000000..a898e6e282 --- /dev/null +++ b/test/validator/samples/slot-name-starts-with-a-digit/errors.json @@ -0,0 +1,15 @@ +[{ + "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 new file mode 100644 index 0000000000..ae9ede75ba --- /dev/null +++ b/test/validator/samples/slot-name-starts-with-a-digit/input.svelte @@ -0,0 +1,3 @@ +
+ +