diff options
author | Maayan Hanin <maayan.asa.hanin@gmail.com> | 2020-08-04 00:39:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-03 23:39:48 +0200 |
commit | 5fc5e7b54a9fba421dfc473016625a4f592403ed (patch) | |
tree | e66bbbdaa30b34b7cef8072ded8ea3f0575c47f0 /cli/main.rs | |
parent | d615ebefe2e306f2877afb40dc603f71263407d6 (diff) |
fix(cli): add support for non-UTF8 source files (#6789)
Fixes: #5542
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/cli/main.rs b/cli/main.rs index cff401fba..191355a0c 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -11,6 +11,7 @@ extern crate futures; extern crate serde_json; extern crate clap; extern crate deno_core; +extern crate encoding_rs; extern crate indexmap; #[cfg(unix)] extern crate nix; @@ -60,6 +61,7 @@ mod startup_data; pub mod state; mod swc_util; mod test_runner; +mod text_encoding; mod tokio_util; mod tsc; mod upgrade; @@ -70,6 +72,7 @@ pub mod worker; use crate::doc::parser::DocFileLoader; use crate::file_fetcher::SourceFile; use crate::file_fetcher::SourceFileFetcher; +use crate::file_fetcher::TextDocument; use crate::fs as deno_fs; use crate::global_state::GlobalState; use crate::msg::MediaType; @@ -412,7 +415,7 @@ async fn eval_command( } else { MediaType::JavaScript }, - source_code, + source_code: TextDocument::new(source_code, Some("utf-8")), }; // Save our fake file into file fetcher cache // to allow module access by TS compiler (e.g. op_fetch_source_files) @@ -525,8 +528,7 @@ async fn doc_command( let source_file = fetcher .fetch_source_file(&specifier, None, Permissions::allow_all()) .await?; - String::from_utf8(source_file.source_code) - .map_err(|_| OpError::other("failed to parse".to_string())) + source_file.source_code.to_string().map_err(OpError::from) } .boxed_local() } @@ -601,7 +603,7 @@ async fn run_command(flags: Flags, script: String) -> Result<(), ErrBox> { url: main_module_url, types_header: None, media_type: MediaType::TypeScript, - source_code: source, + source_code: source.into(), }; // Save our fake file into file fetcher cache // to allow module access by TS compiler (e.g. op_fetch_source_files) @@ -657,7 +659,10 @@ async fn test_command( url: test_file_url, types_header: None, media_type: MediaType::TypeScript, - source_code: test_file.clone().into_bytes(), + source_code: TextDocument::new( + test_file.clone().into_bytes(), + Some("utf-8"), + ), }; // Save our fake file into file fetcher cache // to allow module access by TS compiler (e.g. op_fetch_source_files) |