From de6d0c66d3762db52dce180abe0bf3709b02bd51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn?= Date: Tue, 22 Jun 2021 15:33:50 +0200 Subject: [PATCH] Add a more descriptive message for the error generated by an empty shorthand attribute (#6217) Added error message "empty-attribute-shorthand" for when the shorthand attribute is empty, giving a more explicit error for #6086 --- src/compiler/parse/state/tag.ts | 7 +++++++ .../samples/error-empty-attribute-shorthand/error.json | 10 ++++++++++ .../error-empty-attribute-shorthand/input.svelte | 1 + 3 files changed, 18 insertions(+) create mode 100644 test/parser/samples/error-empty-attribute-shorthand/error.json create mode 100644 test/parser/samples/error-empty-attribute-shorthand/input.svelte diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index 799124b2bd..1a18bd3115 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -330,6 +330,13 @@ function read_attribute(parser: Parser, unique_names: Set) { parser.allow_whitespace(); parser.eat('}', true); + if (name === null) { + parser.error({ + code: 'empty-attribute-shorthand', + message: 'Attribute shorthand cannot be empty' + }, start); + } + check_unique(name); return { diff --git a/test/parser/samples/error-empty-attribute-shorthand/error.json b/test/parser/samples/error-empty-attribute-shorthand/error.json new file mode 100644 index 0000000000..f465b3468a --- /dev/null +++ b/test/parser/samples/error-empty-attribute-shorthand/error.json @@ -0,0 +1,10 @@ +{ + "code": "empty-attribute-shorthand", + "message": "Attribute shorthand cannot be empty", + "start": { + "line": 1, + "column": 6, + "character": 6 + }, + "pos": 6 +} \ No newline at end of file diff --git a/test/parser/samples/error-empty-attribute-shorthand/input.svelte b/test/parser/samples/error-empty-attribute-shorthand/input.svelte new file mode 100644 index 0000000000..2e137c8c6d --- /dev/null +++ b/test/parser/samples/error-empty-attribute-shorthand/input.svelte @@ -0,0 +1 @@ + \ No newline at end of file