@@ -5,11 +5,10 @@ use deno_ast::swc::parser::error::SyntaxError;
55use deno_ast:: swc:: parser:: Syntax ;
66use deno_ast:: ModuleSpecifier ;
77use deno_ast:: ParsedSource ;
8- use deno_ast:: SourceTextInfo ;
98use std:: path:: Path ;
9+ use std:: sync:: Arc ;
1010
11- pub fn parse_swc_ast ( file_path : & Path , file_text : & str ) -> Result < ParsedSource > {
12- let file_text = SourceTextInfo :: from_string ( file_text. to_string ( ) ) ;
11+ pub fn parse_swc_ast ( file_path : & Path , file_text : Arc < str > ) -> Result < ParsedSource > {
1312 match parse_inner ( file_path, file_text. clone ( ) ) {
1413 Ok ( result) => Ok ( result) ,
1514 Err ( err) => {
@@ -28,13 +27,13 @@ pub fn parse_swc_ast(file_path: &Path, file_text: &str) -> Result<ParsedSource>
2827 }
2928}
3029
31- fn parse_inner ( file_path : & Path , text_info : SourceTextInfo ) -> Result < ParsedSource > {
32- let parsed_source = parse_inner_no_diagnostic_check ( file_path, text_info ) ?;
30+ fn parse_inner ( file_path : & Path , text : Arc < str > ) -> Result < ParsedSource > {
31+ let parsed_source = parse_inner_no_diagnostic_check ( file_path, text ) ?;
3332 ensure_no_specific_syntax_errors ( & parsed_source) ?;
3433 Ok ( parsed_source)
3534}
3635
37- fn parse_inner_no_diagnostic_check ( file_path : & Path , text_info : SourceTextInfo ) -> Result < ParsedSource > {
36+ fn parse_inner_no_diagnostic_check ( file_path : & Path , text : Arc < str > ) -> Result < ParsedSource > {
3837 let media_type = deno_ast:: MediaType :: from_path ( file_path) ;
3938 let mut syntax = deno_ast:: get_syntax ( media_type) ;
4039 if let Syntax :: Es ( es) = & mut syntax {
@@ -47,7 +46,7 @@ fn parse_inner_no_diagnostic_check(file_path: &Path, text_info: SourceTextInfo)
4746 maybe_syntax : Some ( syntax) ,
4847 media_type,
4948 scope_analysis : false ,
50- text_info ,
49+ text ,
5150 } )
5251 . map_err ( |diagnostic| anyhow ! ( "{:#}" , & diagnostic) )
5352}
@@ -247,7 +246,7 @@ mod tests {
247246
248247 fn run_fatal_diagnostic_test ( file_path : & str , text : & str , expected : & str ) {
249248 let file_path = PathBuf :: from ( file_path) ;
250- assert_eq ! ( parse_swc_ast( & file_path, text) . err( ) . unwrap( ) . to_string( ) , expected) ;
249+ assert_eq ! ( parse_swc_ast( & file_path, text. into ( ) ) . err( ) . unwrap( ) . to_string( ) , expected) ;
251250 }
252251
253252 #[ test]
@@ -343,11 +342,11 @@ Merge conflict marker encountered. at file:///test.ts:6:1
343342
344343 fn run_non_fatal_diagnostic_test ( file_path : & str , text : & str , expected : & str ) {
345344 let file_path = PathBuf :: from ( file_path) ;
346- assert_eq ! ( format!( "{}" , parse_swc_ast( & file_path, text) . err( ) . unwrap( ) ) , expected) ;
345+ assert_eq ! ( format!( "{}" , parse_swc_ast( & file_path, text. into ( ) ) . err( ) . unwrap( ) ) , expected) ;
347346
348347 // this error should also be surfaced in `format_parsed_source` if someone provides
349348 // a source file that had a non-fatal diagnostic
350- let parsed_source = parse_inner_no_diagnostic_check ( & file_path, SourceTextInfo :: from_string ( text. to_string ( ) ) ) . unwrap ( ) ;
349+ let parsed_source = parse_inner_no_diagnostic_check ( & file_path, text. into ( ) ) . unwrap ( ) ;
351350 let config = ConfigurationBuilder :: new ( ) . build ( ) ;
352351 assert_eq ! ( crate :: format_parsed_source( & parsed_source, & config) . err( ) . unwrap( ) . to_string( ) , expected) ;
353352 }
0 commit comments