@@ -523,9 +523,8 @@ impl TmplGroup {
523523 ) -> Result < TmplConvertedExpr , TmplError > {
524524 let tree = self . get_tree ( path) ?;
525525 let env = crate :: stringify:: typescript:: tmpl_converted_expr_runtime_string ( ) ;
526- let ( code, source_map) = crate :: stringify:: typescript:: generate_tmpl_converted_expr (
527- tree, ts_env, env,
528- ) ;
526+ let ( code, source_map) =
527+ crate :: stringify:: typescript:: generate_tmpl_converted_expr ( tree, ts_env, env) ;
529528 Ok ( TmplConvertedExpr { code, source_map } )
530529 }
531530
@@ -546,7 +545,7 @@ impl TmplGroup {
546545}
547546
548547/// A string for TypeScript type checks with metadata.
549- ///
548+ ///
550549/// This is the result of `get_tmpl_converted_expr`.
551550#[ wasm_bindgen]
552551pub struct TmplConvertedExpr {
@@ -562,29 +561,40 @@ impl TmplConvertedExpr {
562561
563562 /// Get the source code location for given TypeScript code location.
564563 pub fn get_source_location ( & self , loc : Range < Position > ) -> Option < Range < Position > > {
565- let start = self . source_map . lookup_token ( loc. start . line , loc. start . utf16_col ) ?;
564+ let start = self
565+ . source_map
566+ . lookup_token ( loc. start . line , loc. start . utf16_col ) ?;
566567 let ( line, utf16_col) = start. get_src ( ) ;
567568 let ret_pos = Position { line, utf16_col } ;
568569 if loc. start == loc. end {
569570 return Some ( ret_pos..ret_pos) ;
570571 }
571572 let end_diff = if loc. end . utf16_col > 0 { 1 } else { 0 } ;
572- let ret_end_pos = match self . source_map . lookup_token ( loc. end . line , loc. end . utf16_col - end_diff) {
573+ let ret_end_pos = match self
574+ . source_map
575+ . lookup_token ( loc. end . line , loc. end . utf16_col - end_diff)
576+ {
573577 None => ret_pos,
574578 Some ( token) => {
575579 let line = token. get_src_line ( ) ;
576580 let col = token. get_src_col ( ) ;
577581 let len = token. get_name ( ) . map ( |s| s. len ( ) as u32 ) . unwrap_or ( 0 ) ;
578- Position { line, utf16_col : col + len }
582+ Position {
583+ line,
584+ utf16_col : col + len,
585+ }
579586 }
580587 } ;
581588 Some ( ret_pos..ret_end_pos)
582589 }
583590
584591 /// Get the token information of the given source code location.
585- ///
592+ ///
586593 /// Returns the range in the source code and the start position in the TypeScript code.
587- pub fn get_token_at_source_position ( & self , pos : Position ) -> Option < ( Range < Position > , Position ) > {
594+ pub fn get_token_at_source_position (
595+ & self ,
596+ pos : Position ,
597+ ) -> Option < ( Range < Position > , Position ) > {
588598 for token in self . source_map . tokens ( ) {
589599 let Some ( name) = token. get_name ( ) else {
590600 continue ;
@@ -599,9 +609,18 @@ impl TmplConvertedExpr {
599609 continue ;
600610 }
601611 let ( dst_start_line, dst_start_col) = token. get_dst ( ) ;
602- let source_start = Position { line : src_start_line, utf16_col : src_start_col } ;
603- let source_end = Position { line : src_end_line, utf16_col : src_end_col } ;
604- let dest = Position { line : dst_start_line, utf16_col : dst_start_col } ;
612+ let source_start = Position {
613+ line : src_start_line,
614+ utf16_col : src_start_col,
615+ } ;
616+ let source_end = Position {
617+ line : src_end_line,
618+ utf16_col : src_end_col,
619+ } ;
620+ let dest = Position {
621+ line : dst_start_line,
622+ utf16_col : dst_start_col,
623+ } ;
605624 return Some ( ( source_start..source_end, dest) ) ;
606625 }
607626 None
@@ -623,15 +642,36 @@ impl TmplConvertedExpr {
623642 end_line : u32 ,
624643 end_col : u32 ,
625644 ) -> Option < Vec < u32 > > {
626- let start = Position { line : start_line, utf16_col : start_col } ;
627- let end = Position { line : end_line, utf16_col : end_col } ;
645+ let start = Position {
646+ line : start_line,
647+ utf16_col : start_col,
648+ } ;
649+ let end = Position {
650+ line : end_line,
651+ utf16_col : end_col,
652+ } ;
628653 let ret = self . get_source_location ( start..end) ?;
629- Some ( vec ! [ ret. start. line, ret. start. utf16_col, ret. end. line, ret. end. utf16_col] )
654+ Some ( vec ! [
655+ ret. start. line,
656+ ret. start. utf16_col,
657+ ret. end. line,
658+ ret. end. utf16_col,
659+ ] )
630660 }
631661
632662 #[ wasm_bindgen( js_name = "getTokenAtSourcePosition" ) ]
633663 pub fn js_get_token_at_source_position ( & self , line : u32 , col : u32 ) -> Option < Vec < u32 > > {
634- let ( src, dest) = self . get_token_at_source_position ( Position { line, utf16_col : col } ) ?;
635- Some ( vec ! [ src. start. line, src. start. utf16_col, src. end. line, src. end. utf16_col, dest. line, dest. utf16_col] )
664+ let ( src, dest) = self . get_token_at_source_position ( Position {
665+ line,
666+ utf16_col : col,
667+ } ) ?;
668+ Some ( vec ! [
669+ src. start. line,
670+ src. start. utf16_col,
671+ src. end. line,
672+ src. end. utf16_col,
673+ dest. line,
674+ dest. utf16_col,
675+ ] )
636676 }
637677}
0 commit comments