diff --git a/src/compiler/parse/errors.ts b/src/compiler/parse/errors.ts index b563b7572a..b2fc5b72a4 100644 --- a/src/compiler/parse/errors.ts +++ b/src/compiler/parse/errors.ts @@ -169,6 +169,10 @@ export default { code: 'unclosed-comment', message: 'comment was left open, expected -->' }, + unclosed_attribute_value: (token: string) => ({ + code: 'unclosed-attribute-value', + message: `Expected to close the attribute value with ${token}` + }), unexpected_block_close: { code: 'unexpected-block-close', message: 'Unexpected block closing tag' diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index 28821edb01..c6901dbdcc 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -438,7 +438,21 @@ function read_attribute_value(parser: Parser) { /(\/>|[\s"'=<>`])/ ); - const value = read_sequence(parser, () => !!parser.match_regex(regex)); + let value; + try { + value = read_sequence(parser, () => !!parser.match_regex(regex)); + } catch (error) { + if (error.code === 'parse-error') { + // if the attribute value didn't close + self-closing tag + // eg: `` + // acorn may throw a `Unterminated regular expression` because of `/>` + if (parser.template.slice(error.pos - 1, error.pos + 1) === '/>') { + parser.index = error.pos; + parser.error(parser_errors.unclosed_attribute_value(quote_mark || '}')); + } + } + throw error; + } if (quote_mark) parser.index += 1; return value; diff --git a/test/parser/samples/error-unclosed-attribute-self-close-tag/error.json b/test/parser/samples/error-unclosed-attribute-self-close-tag/error.json new file mode 100644 index 0000000000..790b430913 --- /dev/null +++ b/test/parser/samples/error-unclosed-attribute-self-close-tag/error.json @@ -0,0 +1,10 @@ +{ + "code": "unclosed-attribute-value", + "message": "Expected to close the attribute value with }", + "pos": 25, + "start": { + "character": 25, + "column": 25, + "line": 1 + } +} diff --git a/test/parser/samples/error-unclosed-attribute-self-close-tag/input.svelte b/test/parser/samples/error-unclosed-attribute-self-close-tag/input.svelte new file mode 100644 index 0000000000..609b5532f4 --- /dev/null +++ b/test/parser/samples/error-unclosed-attribute-self-close-tag/input.svelte @@ -0,0 +1 @@ + \ No newline at end of file