better error for unclosed curly brace in props

pull/6612/head
Tan Li Hau 5 years ago
parent b554e343e8
commit d1d999b558

@ -169,6 +169,10 @@ export default {
code: 'unclosed-comment', code: 'unclosed-comment',
message: 'comment was left open, expected -->' 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: { unexpected_block_close: {
code: 'unexpected-block-close', code: 'unexpected-block-close',
message: 'Unexpected block closing tag' message: 'Unexpected block closing tag'

@ -438,7 +438,21 @@ function read_attribute_value(parser: Parser) {
/(\/>|[\s"'=<>`])/ /(\/>|[\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: `<Component test={{a:1} />`
// 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; if (quote_mark) parser.index += 1;
return value; return value;

@ -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
}
}
Loading…
Cancel
Save