1- /* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
21import { AST } from '@codemod-utils/ast-javascript' ;
32
43import { getTemplate , preprocessor } from './content-tag.js' ;
@@ -13,15 +12,6 @@ type Marker = {
1312 } ;
1413} ;
1514
16- function getMarker ( nodeValue : unknown ) : Marker {
17- return {
18- // @ts -expect-error: Incorrect type
19- code : AST . print ( nodeValue ) ,
20- // @ts -expect-error: Incorrect type
21- end : nodeValue . loc . end ,
22- } ;
23- }
24-
2515function sortMarkers ( a : Marker , b : Marker ) : number {
2616 if ( a . end . line > b . end . line ) {
2717 return - 1 ;
@@ -49,36 +39,44 @@ export function findMarkers(file: string): Marker[] {
4939 const markers : Marker [ ] = [ ] ;
5040
5141 traverse ( code , {
52- visitCallExpression ( node ) {
53- const template = getTemplate ( node . value ) ;
42+ visitCallExpression ( path ) {
43+ const template = getTemplate ( path . node ) ;
5444
5545 if ( template === undefined ) {
56- this . traverse ( node ) ;
46+ this . traverse ( path ) ;
5747
5848 return false ;
5949 }
6050
61- markers . push ( getMarker ( node . value ) ) ;
51+ markers . push ( {
52+ code : AST . print ( path . node ) ,
53+ // @ts -expect-error: Incorrect type
54+ end : path . node . loc ! . end ,
55+ } ) ;
6256
6357 return false ;
6458 } ,
6559
66- visitExportDefaultDeclaration ( node ) {
67- const template = getTemplate ( node . value . declaration ) ;
60+ visitExportDefaultDeclaration ( path ) {
61+ const template = getTemplate ( path . node . declaration ) ;
6862
6963 if ( template === undefined ) {
70- this . traverse ( node ) ;
64+ this . traverse ( path ) ;
7165
7266 return false ;
7367 }
7468
75- markers . push ( getMarker ( node . value ) ) ;
69+ markers . push ( {
70+ code : AST . print ( path . node ) ,
71+ // @ts -expect-error: Incorrect type
72+ end : path . node . loc ! . end ,
73+ } ) ;
7674
7775 return false ;
7876 } ,
7977
80- visitStaticBlock ( node ) {
81- const bodyNode = node . value . body [ 0 ] ;
78+ visitStaticBlock ( path ) {
79+ const bodyNode = path . node . body [ 0 ] ! ;
8280
8381 if ( bodyNode . type !== 'ExpressionStatement' ) {
8482 return false ;
@@ -90,7 +88,11 @@ export function findMarkers(file: string): Marker[] {
9088 return false ;
9189 }
9290
93- markers . push ( getMarker ( node . value ) ) ;
91+ markers . push ( {
92+ code : AST . print ( path . node ) ,
93+ // @ts -expect-error: Incorrect type
94+ end : path . node . loc ! . end ,
95+ } ) ;
9496
9597 return false ;
9698 } ,
0 commit comments