From 3f312231863237b8240c23775563e95ec4a7ea7d Mon Sep 17 00:00:00 2001 From: Emil Tholin Date: Wed, 15 May 2019 17:26:57 +0200 Subject: [PATCH] Add error for missing equals after attribute name --- src/parse/state/tag.ts | 7 ++++++- .../samples/attribute-expected-equals/errors.json | 15 +++++++++++++++ .../attribute-expected-equals/input.svelte | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/validator/samples/attribute-expected-equals/errors.json create mode 100644 test/validator/samples/attribute-expected-equals/input.svelte diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index 365085ca08..56195549d8 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -358,7 +358,7 @@ function read_attribute(parser: Parser, unique_names: Set) { } } - let name = parser.read_until(/(\s|=|\/|>)/); + let name = parser.read_until(/[\s=\/>"']/); if (!name) return null; let end = parser.index; @@ -383,6 +383,11 @@ function read_attribute(parser: Parser, unique_names: Set) { if (parser.eat('=')) { value = read_attribute_value(parser); end = parser.index; + } else if (parser.match_regex(/["']/)) { + parser.error({ + code: `unexpected-token`, + message: `Expected =` + }, parser.index); } if (type) { diff --git a/test/validator/samples/attribute-expected-equals/errors.json b/test/validator/samples/attribute-expected-equals/errors.json new file mode 100644 index 0000000000..a3fa9d3cac --- /dev/null +++ b/test/validator/samples/attribute-expected-equals/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "unexpected-token", + "message": "Expected =", + "start": { + "line": 5, + "column": 9, + "character": 50 + }, + "end": { + "line": 5, + "column": 9, + "character": 50 + }, + "pos": 50 +}] diff --git a/test/validator/samples/attribute-expected-equals/input.svelte b/test/validator/samples/attribute-expected-equals/input.svelte new file mode 100644 index 0000000000..91f4b0ca7b --- /dev/null +++ b/test/validator/samples/attribute-expected-equals/input.svelte @@ -0,0 +1,5 @@ + + +

Hello {name}!