diff options
Diffstat (limited to 'cli/file_fetcher.rs')
-rw-r--r-- | cli/file_fetcher.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index 17bbb76f0..1e4c5d453 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -6,10 +6,10 @@ use crate::http_cache::HttpCache; use crate::http_util::fetch_once; use crate::http_util::FetchOnceArgs; use crate::http_util::FetchOnceResult; -use crate::media_type::MediaType; use crate::text_encoding; use crate::version::get_user_agent; use data_url::DataUrl; +use deno_ast::MediaType; use deno_core::error::custom_error; use deno_core::error::generic_error; use deno_core::error::uri_error; @@ -52,7 +52,7 @@ pub struct File { /// The resolved media type for the file. pub media_type: MediaType, /// The source of the file as a string. - pub source: String, + pub source: Arc<String>, /// The _final_ specifier for the file. The requested specifier and the final /// specifier maybe different for remote files that have been redirected. pub specifier: ModuleSpecifier, @@ -137,7 +137,7 @@ fn fetch_local(specifier: &ModuleSpecifier) -> Result<File, AnyError> { local, maybe_types: None, media_type, - source, + source: Arc::new(source), specifier: specifier.clone(), maybe_headers: None, }) @@ -275,7 +275,7 @@ impl FileFetcher { local, maybe_types, media_type, - source, + source: Arc::new(source), specifier: specifier.clone(), maybe_headers: Some(headers.clone()), }) @@ -367,7 +367,7 @@ impl FileFetcher { local, maybe_types: None, media_type, - source, + source: Arc::new(source), specifier: specifier.clone(), maybe_headers: None, }) @@ -429,7 +429,7 @@ impl FileFetcher { local, maybe_types: None, media_type, - source, + source: Arc::new(source), specifier: specifier.clone(), maybe_headers: None, }) @@ -673,7 +673,7 @@ mod tests { let url_str = format!("http://127.0.0.1:4545/encoding/{}", fixture); let specifier = resolve_url(&url_str).unwrap(); let (file, headers) = test_fetch_remote(&specifier).await; - assert_eq!(file.source, expected); + assert_eq!(file.source.as_str(), expected); assert_eq!(file.media_type, MediaType::TypeScript); assert_eq!( headers.get("content-type").unwrap(), @@ -685,7 +685,7 @@ mod tests { let p = test_util::testdata_path().join(format!("encoding/{}.ts", charset)); let specifier = resolve_url_or_path(p.to_str().unwrap()).unwrap(); let (file, _) = test_fetch(&specifier).await; - assert_eq!(file.source, expected); + assert_eq!(file.source.as_str(), expected); } #[test] @@ -898,7 +898,7 @@ mod tests { local, maybe_types: None, media_type: MediaType::TypeScript, - source: "some source code".to_string(), + source: Arc::new("some source code".to_string()), specifier: specifier.clone(), maybe_headers: None, }; @@ -928,7 +928,7 @@ mod tests { let maybe_file = file_fetcher.get_source(&specifier); assert!(maybe_file.is_some()); let file = maybe_file.unwrap(); - assert_eq!(file.source, "export const redirect = 1;\n"); + assert_eq!(file.source.as_str(), "export const redirect = 1;\n"); assert_eq!( file.specifier, resolve_url("http://localhost:4545/subdir/redirects/redirect1.js") @@ -955,7 +955,7 @@ mod tests { assert!(result.is_ok()); let file = result.unwrap(); assert_eq!( - file.source, + file.source.as_str(), "export const a = \"a\";\n\nexport enum A {\n A,\n B,\n C,\n}\n" ); assert_eq!(file.media_type, MediaType::TypeScript); @@ -987,7 +987,7 @@ mod tests { assert!(result.is_ok()); let file = result.unwrap(); assert_eq!( - file.source, + file.source.as_str(), "export const a = \"a\";\n\nexport enum A {\n A,\n B,\n C,\n}\n" ); assert_eq!(file.media_type, MediaType::TypeScript); @@ -1010,7 +1010,7 @@ mod tests { assert!(result.is_ok()); let file = result.unwrap(); assert_eq!( - file.source, + file.source.as_str(), "export { printHello } from \"./print_hello.ts\";\n" ); assert_eq!(file.media_type, MediaType::TypeScript); @@ -1033,7 +1033,7 @@ mod tests { assert!(result.is_ok()); let file = result.unwrap(); assert_eq!( - file.source, + file.source.as_str(), "export { printHello } from \"./print_hello.ts\";\n" ); // This validates that when using the cached value, because we modified @@ -1054,7 +1054,7 @@ mod tests { assert!(result.is_ok()); let file = result.unwrap(); assert_eq!( - file.source, + file.source.as_str(), "export { printHello } from \"./print_hello.ts\";\n" ); assert_eq!(file.media_type, MediaType::Json); @@ -1077,7 +1077,7 @@ mod tests { assert!(result.is_ok()); let file = result.unwrap(); assert_eq!( - file.source, + file.source.as_str(), "export { printHello } from \"./print_hello.ts\";\n" ); assert_eq!(file.media_type, MediaType::TypeScript); @@ -1497,7 +1497,7 @@ mod tests { .await; assert!(result.is_ok()); let file = result.unwrap(); - assert_eq!(file.source, r#"console.log("hello deno");"#); + assert_eq!(file.source.as_str(), r#"console.log("hello deno");"#); fs::write(fixture_path, r#"console.log("goodbye deno");"#) .expect("could not write file"); @@ -1506,7 +1506,7 @@ mod tests { .await; assert!(result.is_ok()); let file = result.unwrap(); - assert_eq!(file.source, r#"console.log("goodbye deno");"#); + assert_eq!(file.source.as_str(), r#"console.log("goodbye deno");"#); } #[tokio::test] |