@ -33,14 +33,19 @@ export function get_loose_identifier(parser, opening_token) {
* @ returns { Expression }
* @ returns { Expression }
* /
* /
export default function read _expression ( parser , opening _token , disallow _loose ) {
export default function read _expression ( parser , opening _token , disallow _loose ) {
/** @type {Expression | undefined} */
let node ;
try {
try {
let comment _index = parser . root . comments . length ;
let comment _index = parser . root . comments . length ;
const node = parse _expression _at (
node = /** @type {Expression} */ (
parser . template ,
parse _expression _at (
parser . root . comments ,
parser . template ,
parser . ts ,
parser . root . comments ,
parser . index
parser . ts ,
parser . index
)
) ;
) ;
let num _parens = 0 ;
let num _parens = 0 ;
@ -76,8 +81,6 @@ export default function read_expression(parser, opening_token, disallow_loose) {
}
}
parser . index = index ;
parser . index = index ;
return /** @type {Expression} */ ( node ) ;
} catch ( err ) {
} catch ( err ) {
// If we are in an each loop we need the error to be thrown in cases like
// 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
// `as { y = z }` so we still throw and handle the error there
@ -90,4 +93,22 @@ export default function read_expression(parser, opening_token, disallow_loose) {
parser . acorn _error ( err ) ;
parser . acorn _error ( err ) ;
}
}
if ( ! parser . ts ) {
let j = parser . index ;
while ( j < parser . template . length && regex _whitespace . test ( parser . template [ j ] ) ) j ++ ;
const remaining = parser . template . slice ( j ) ;
if (
remaining [ 0 ] === ':' ||
/^satisfies[\s(]/ . test ( remaining ) ||
( remaining [ 0 ] === '!' && remaining [ 1 ] !== '=' ) ||
( /^as[\s(]/ . test ( remaining ) && ! disallow _loose )
) {
e . js _parse _error ( j , ` Unexpected token (did you forget to add \` lang="ts" \` ?) ` ) ;
}
}
return node ;
}
}