diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index 799124b2bdf7..80ba6b102b52 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); + } + 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 deleted file mode 100644 index edc09ff8e120..000000000000 --- a/test/parser/samples/error-empty-classname-binding/error.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "code": "invalid-class-directive", - "message": "Class binding name cannot be empty", - "start": { - "line": 1, - "column": 10, - "character": 10 - }, - "pos": 10 -} diff --git a/test/parser/samples/error-empty-classname-binding/input.svelte b/test/parser/samples/error-empty-classname-binding/input.svelte deleted file mode 100644 index 3a4e5980eea3..000000000000 --- a/test/parser/samples/error-empty-classname-binding/input.svelte +++ /dev/null @@ -1 +0,0 @@ -

Hello

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..49e5a891a1f0 --- /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": 7, + "character": 7 + }, + "pos": 7 +} 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