diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index 799124b2bdf7..11dd6ce95920 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -378,6 +378,13 @@ function read_attribute(parser: Parser, unique_names: Set) { if (type) { const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|'); + if (directive_name === '') { + parser.error({ + code: 'empty-directive-name', + message: `${type} name cannot be empty` + }, start + colon_index + 1); + } + if (type === 'Binding' && directive_name !== 'this') { check_unique(directive_name); } else if (type !== 'EventHandler' && type !== 'Action') { @@ -391,13 +398,6 @@ function read_attribute(parser: Parser, unique_names: Set) { }, start); } - if (type === 'Class' && directive_name === '') { - parser.error({ - code: 'invalid-class-directive', - message: 'Class binding name cannot be empty' - }, start + colon_index + 1); - } - if (value[0]) { if ((value as any[]).length > 1 || value[0].type === 'Text') { parser.error({ diff --git a/test/parser/samples/error-empty-classname-binding/error.json b/test/parser/samples/error-empty-classname-binding/error.json index edc09ff8e120..6ece5ff37378 100644 --- a/test/parser/samples/error-empty-classname-binding/error.json +++ b/test/parser/samples/error-empty-classname-binding/error.json @@ -1,6 +1,6 @@ { - "code": "invalid-class-directive", - "message": "Class binding name cannot be empty", + "code": "empty-directive-name", + "message": "Class name cannot be empty", "start": { "line": 1, "column": 10, diff --git a/test/parser/samples/error-empty-directive-name/error.json b/test/parser/samples/error-empty-directive-name/error.json new file mode 100644 index 000000000000..4fed0d86069e --- /dev/null +++ b/test/parser/samples/error-empty-directive-name/error.json @@ -0,0 +1,10 @@ +{ + "code": "empty-directive-name", + "message": "Action name cannot be empty", + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "pos": 8 +} diff --git a/test/parser/samples/error-empty-directive-name/input.svelte b/test/parser/samples/error-empty-directive-name/input.svelte new file mode 100644 index 000000000000..b07875f398b6 --- /dev/null +++ b/test/parser/samples/error-empty-directive-name/input.svelte @@ -0,0 +1 @@ +

Hello