@@ -33,6 +33,7 @@ function convertAst(ast: File, templates: Template[]): void {
3333 traverse ( ast , {
3434 enter ( path ) {
3535 const { node } = path ;
36+
3637 // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
3738 switch ( node . type ) {
3839 case 'BlockStatement' :
@@ -54,21 +55,27 @@ function convertAst(ast: File, templates: Template[]): void {
5455 utf16Range . end === end + 1
5556 ) ;
5657 } ) ;
58+
5759 if ( templateIndex === - 1 ) {
5860 return null ;
5961 }
62+
6063 const rawTemplate = templates . splice ( templateIndex , 1 ) [ 0 ] ;
64+
6165 if ( ! rawTemplate ) {
6266 throw new Error (
6367 'expected raw template because splice index came from findIndex' ,
6468 ) ;
6569 }
70+
6671 const index =
6772 node . innerComments ?. [ 0 ] &&
6873 ast . comments ?. indexOf ( node . innerComments [ 0 ] ) ;
74+
6975 if ( ast . comments && index !== undefined && index >= 0 ) {
7076 ast . comments . splice ( index , 1 ) ;
7177 }
78+
7279 convertNode ( node , rawTemplate ) ;
7380 }
7481 }
@@ -90,9 +97,11 @@ export const parser: Parser<Node | undefined> = {
9097
9198 async parse ( code : string , options : Options ) : Promise < Node > {
9299 const preprocessed = preprocess ( code , options . filepath ) ;
100+
93101 const ast = await typescript . parse ( preprocessed . code , options ) ;
94102 assert ( 'expected ast' , ast ) ;
95103 convertAst ( ast as File , preprocessed . templates ) ;
104+
96105 return ast ;
97106 } ,
98107} ;
0 commit comments