|
|
|
|
@ -2,26 +2,22 @@
|
|
|
|
|
/** @import { Parser } from '../index.js' */
|
|
|
|
|
import { parse_expression_at } from '../acorn.js';
|
|
|
|
|
import { find_matching_bracket } from '../utils/bracket.js';
|
|
|
|
|
import * as e from '../../../errors.js';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {Parser} parser
|
|
|
|
|
* @param {string} [opening_token]
|
|
|
|
|
* @returns {Expression | undefined}
|
|
|
|
|
* @returns {Expression}
|
|
|
|
|
*/
|
|
|
|
|
export function get_loose_identifier(parser, opening_token) {
|
|
|
|
|
// Find the next } and treat it as the end of the expression
|
|
|
|
|
const start = parser.index;
|
|
|
|
|
const end = find_matching_bracket(parser.template, parser.index, opening_token ?? '{');
|
|
|
|
|
if (end) {
|
|
|
|
|
const start = parser.index;
|
|
|
|
|
parser.index = end;
|
|
|
|
|
// We don't know what the expression is and signal this by returning an empty identifier
|
|
|
|
|
return {
|
|
|
|
|
type: 'Identifier',
|
|
|
|
|
start,
|
|
|
|
|
end,
|
|
|
|
|
name: ''
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parser.index = end;
|
|
|
|
|
|
|
|
|
|
// We don't know what the expression is and signal this by returning an empty identifier
|
|
|
|
|
return { type: 'Identifier', start, end, name: '' };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -36,10 +32,7 @@ export default function read_expression(parser, opening_token) {
|
|
|
|
|
// If we are in an each loop we need the error to be thrown in cases like
|
|
|
|
|
// `as { y = z }` so we still throw and handle the error there
|
|
|
|
|
if (parser.loose) {
|
|
|
|
|
const expression = get_loose_identifier(parser, opening_token);
|
|
|
|
|
if (expression) {
|
|
|
|
|
return expression;
|
|
|
|
|
}
|
|
|
|
|
return get_loose_identifier(parser, opening_token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw err;
|
|
|
|
|
|