a parse error reaches the host as the span the parser saw, and the end of the input is the host's own error whatever was being read

goodbye-acorn
Nic 2 days ago
parent 3ee5cc64af
commit 394fa2c588

@ -169,15 +169,7 @@ export function read_params(parser) {
export function read_statement(parser) { export function read_statement(parser) {
const start = parser.index; const start = parser.index;
const answer = read(parser, (js) => { const answer = read(parser, (js) => js.parseStatementAt(start));
try {
return js.parseStatementAt(start);
} catch (err) {
if (/** @type {any} */ (err).code === 'unexpected_eof')
e.unexpected_eof(parser.template.length);
throw err;
}
});
keep_tables(answer.node, tables(answer)); keep_tables(answer.node, tables(answer));
return answer.node; return answer.node;
} }
@ -209,7 +201,8 @@ function unsupported(kept) {
* @returns {never} * @returns {never}
*/ */
function handle_parse_error(err) { function handle_parse_error(err) {
e.js_parse_error(err.pos, err.message); if (err.code === 'unexpected_eof') e.unexpected_eof(err.pos);
e.js_parse_error({ start: err.pos, end: err.end }, err.message);
} }
/** /**

@ -4,6 +4,6 @@ export default test({
error: { error: {
code: 'js_parse_error', code: 'js_parse_error',
message: 'Unexpected token', message: 'Unexpected token',
position: [21, 21] position: [21, 22]
} }
}); });

@ -8,7 +8,7 @@
}, },
"end": { "end": {
"line": 1, "line": 1,
"column": 17 "column": 21
} }
} }
] ]

Loading…
Cancel
Save