From ac8718b3a4c514683d5683f5382ee9da4e33ec1f Mon Sep 17 00:00:00 2001 From: mhmd-22 Date: Tue, 4 May 2021 22:55:29 +0300 Subject: [PATCH] Compile error when passing empty directive names --- src/compiler/parse/state/tag.ts | 14 +++++++------- .../error-empty-classname-binding/error.json | 10 ---------- .../error-empty-classname-binding/input.svelte | 1 - .../samples/error-empty-directive-name/error.json | 10 ++++++++++ .../error-empty-directive-name/input.svelte | 1 + 5 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 test/parser/samples/error-empty-classname-binding/error.json delete mode 100644 test/parser/samples/error-empty-classname-binding/input.svelte create mode 100644 test/parser/samples/error-empty-directive-name/error.json create mode 100644 test/parser/samples/error-empty-directive-name/input.svelte 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