1- use anyhow:: anyhow;
2- use anyhow:: bail;
3- use anyhow:: Result ;
41use deno_ast:: swc:: parser:: error:: SyntaxError ;
52use deno_ast:: swc:: parser:: Syntax ;
63use deno_ast:: ModuleSpecifier ;
74use deno_ast:: ParsedSource ;
85use std:: path:: Path ;
96use std:: sync:: Arc ;
107
8+ use crate :: Result ;
9+
1110pub fn parse_swc_ast ( file_path : & Path , file_extension : Option < & str > , file_text : Arc < str > ) -> Result < ParsedSource > {
1211 match parse_inner ( file_path, file_extension, file_text. clone ( ) ) {
1312 Ok ( result) => Ok ( result) ,
@@ -53,7 +52,7 @@ fn parse_inner_no_diagnostic_check(file_path: &Path, file_extension: Option<&str
5352 scope_analysis : false ,
5453 text,
5554 } )
56- . map_err ( |diagnostic| anyhow ! ( "{:#}" , & diagnostic ) )
55+ . map_err ( Into :: into )
5756}
5857
5958fn path_to_specifier ( path : & Path ) -> Result < ModuleSpecifier > {
@@ -62,10 +61,10 @@ fn path_to_specifier(path: &Path) -> Result<ModuleSpecifier> {
6261 } else if let Some ( file_name) = path. file_name ( ) {
6362 match ModuleSpecifier :: parse ( & format ! ( "file:///{}" , file_name. to_string_lossy( ) ) ) {
6463 Ok ( specifier) => Ok ( specifier) ,
65- Err ( err) => bail ! ( "could not convert path to specifier: '{}', error: {:#}" , path. display( ) , err) ,
64+ Err ( err) => Err ( format ! ( "could not convert path to specifier: '{}', error: {:#}" , path. display( ) , err) . into ( ) ) ,
6665 }
6766 } else {
68- bail ! ( "could not convert path to specifier: '{}'" , path. display( ) )
67+ Err ( format ! ( "could not convert path to specifier: '{}'" , path. display( ) ) . into ( ) )
6968 }
7069}
7170
@@ -140,19 +139,13 @@ pub fn ensure_no_specific_syntax_errors(parsed_source: &ParsedSource) -> Result<
140139 SyntaxError :: TS1185
141140 )
142141 } )
142+ . cloned ( )
143143 . collect :: < Vec < _ > > ( ) ;
144144
145145 if diagnostics. is_empty ( ) {
146146 Ok ( ( ) )
147147 } else {
148- let mut final_message = String :: new ( ) ;
149- for diagnostic in diagnostics {
150- if !final_message. is_empty ( ) {
151- final_message. push_str ( "\n \n " ) ;
152- }
153- final_message. push_str ( & format ! ( "{diagnostic}" ) ) ;
154- }
155- bail ! ( "{}" , final_message)
148+ Err ( deno_ast:: ParseDiagnosticsError ( diagnostics) . into ( ) )
156149 }
157150}
158151
0 commit comments