@@ -462,6 +462,98 @@ const EXTRACT_TOKENS: {
462
462
parent : ESTree . Node | null ,
463
463
) => void
464
464
} = EXTRACT_TOKENS0
465
+ const GET_LOC : {
466
+ [ key in ESTree . Node [ "type" ] ] : (
467
+ node : any ,
468
+ ctx : Context ,
469
+ parent : ESTree . Node | null ,
470
+ ) => { start : number ; end : number }
471
+ } = {
472
+ ArrayExpression : getWithLoc ,
473
+ ArrayPattern : getWithLoc ,
474
+ ArrowFunctionExpression : getWithLoc ,
475
+ AssignmentExpression : getWithLoc ,
476
+ AssignmentPattern : getWithLoc ,
477
+ AwaitExpression : getWithLoc ,
478
+ BinaryExpression : getWithLoc ,
479
+ BlockStatement : getWithLoc ,
480
+ BreakStatement : getWithLoc ,
481
+ CallExpression : getWithLoc ,
482
+ CatchClause : getWithLoc ,
483
+ ChainExpression : getWithLoc ,
484
+ ClassBody : getWithLoc ,
485
+ ClassDeclaration : getWithLoc ,
486
+ ClassExpression : getWithLoc ,
487
+ ConditionalExpression : getWithLoc ,
488
+ ContinueStatement : getWithLoc ,
489
+ DebuggerStatement : getWithLoc ,
490
+ DoWhileStatement : getWithLoc ,
491
+ EmptyStatement : getWithLoc ,
492
+ ExportAllDeclaration : getWithLoc ,
493
+ ExportDefaultDeclaration : getWithLoc ,
494
+ ExportNamedDeclaration : getWithLoc ,
495
+ ExportSpecifier : getWithLoc ,
496
+ ExpressionStatement : getWithLoc ,
497
+ ForInStatement : getWithLoc ,
498
+ ForOfStatement : getWithLoc ,
499
+ ForStatement : getWithLoc ,
500
+ FunctionDeclaration : getWithLoc ,
501
+ FunctionExpression : getWithLoc ,
502
+ Identifier : getWithLoc ,
503
+ IfStatement : getWithLoc ,
504
+ ImportDeclaration : getWithLoc ,
505
+ ImportDefaultSpecifier : getWithLoc ,
506
+ ImportExpression : getWithLoc ,
507
+ ImportNamespaceSpecifier : getWithLoc ,
508
+ ImportSpecifier : getWithLoc ,
509
+ LabeledStatement : getWithLoc ,
510
+ Literal : getWithLoc ,
511
+ LogicalExpression : getWithLoc ,
512
+ MemberExpression : getWithLoc ,
513
+ MetaProperty : getWithLoc ,
514
+ MethodDefinition : getWithLoc ,
515
+ NewExpression : getWithLoc ,
516
+ ObjectExpression : getWithLoc ,
517
+ ObjectPattern : getWithLoc ,
518
+ Program : getWithLoc ,
519
+ Property : getWithLoc ,
520
+ RestElement : getWithLoc ,
521
+ ReturnStatement : getWithLoc ,
522
+ SequenceExpression : getWithLoc ,
523
+ SpreadElement : getWithLoc ,
524
+ Super : getWithLoc ,
525
+ SwitchCase : getWithLoc ,
526
+ SwitchStatement : getWithLoc ,
527
+ TaggedTemplateExpression : getWithLoc ,
528
+ TemplateElement (
529
+ node : ESTree . TemplateElement ,
530
+ _ctx : Context ,
531
+ parent : ESTree . Node | null ,
532
+ ) {
533
+ const literal : ESTree . TemplateLiteral = parent as never
534
+
535
+ const start =
536
+ literal . quasis [ 0 ] === node
537
+ ? getWithLoc ( literal ) . start
538
+ : getWithLoc ( node ) . start - 1
539
+ const end =
540
+ literal . quasis [ literal . quasis . length - 1 ] === node
541
+ ? getWithLoc ( literal ) . end
542
+ : getWithLoc ( node ) . end + 2
543
+ return { start, end }
544
+ } ,
545
+ TemplateLiteral : getWithLoc ,
546
+ ThisExpression : getWithLoc ,
547
+ ThrowStatement : getWithLoc ,
548
+ TryStatement : getWithLoc ,
549
+ UnaryExpression : getWithLoc ,
550
+ UpdateExpression : getWithLoc ,
551
+ VariableDeclaration : getWithLoc ,
552
+ VariableDeclarator : getWithLoc ,
553
+ WhileStatement : getWithLoc ,
554
+ WithStatement : getWithLoc ,
555
+ YieldExpression : getWithLoc ,
556
+ }
465
557
466
558
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- ignore
467
559
export function convertESNode < N extends ESTree . Node > (
@@ -524,7 +616,9 @@ function convertESNode0<N extends ESTree.Node>(
524
616
const result = {
525
617
...node ,
526
618
parent,
527
- ...ctx . getConvertLocation ( getWithLoc ( node ) ) ,
619
+ ...ctx . getConvertLocation (
620
+ ( GET_LOC [ node . type ] ?? getWithLoc ) ( node , ctx , parent ) ,
621
+ ) ,
528
622
}
529
623
530
624
for ( const key of getKeys ( node ) ) {
0 commit comments