@@ -530,22 +530,21 @@ function special(parser) {
530
530
531
531
if ( parser . eat ( 'const' ) ) {
532
532
// {@const a = b }
533
+ const start_index = parser . index - 5 ;
533
534
parser . require_whitespace ( ) ;
534
535
535
- const CONST_LENGTH = 'const ' . length ;
536
- parser . index = parser . index - CONST_LENGTH ;
537
-
538
536
let end_index = parser . index ;
539
537
/** @type {import('estree').VariableDeclaration | undefined } */
540
538
let declaration = undefined ;
541
539
542
- const dummy_spaces = parser . template . substring ( 0 , parser . index ) . replace ( / [ ^ \n ] / g, ' ' ) ;
540
+ // Can't use parse_expression_at here, so we try to parse until we find the correct range
541
+ const dummy_spaces = parser . template . substring ( 0 , start_index ) . replace ( / [ ^ \n ] / g, ' ' ) ;
543
542
while ( true ) {
544
543
end_index = parser . template . indexOf ( '}' , end_index + 1 ) ;
545
544
if ( end_index === - 1 ) break ;
546
545
try {
547
546
const node = parse (
548
- dummy_spaces + parser . template . substring ( parser . index , end_index ) ,
547
+ dummy_spaces + parser . template . substring ( start_index , end_index ) ,
549
548
parser . ts
550
549
) . body [ 0 ] ;
551
550
if ( node ?. type === 'VariableDeclaration' ) {
@@ -568,12 +567,6 @@ function special(parser) {
568
567
parser . index = end_index ;
569
568
parser . eat ( '}' , true ) ;
570
569
571
- const id = declaration . declarations [ 0 ] . id ;
572
- if ( id . type === 'Identifier' ) {
573
- // Tidy up some stuff left behind by acorn-typescript
574
- id . end = ( id . start ?? 0 ) + id . name . length ;
575
- }
576
-
577
570
parser . append (
578
571
/** @type {import('#compiler').ConstTag } */ ( {
579
572
type : 'ConstTag' ,
0 commit comments