diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-05-21 10:35:36 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2020-06-06 09:07:59 -0400 |
commit | 8a4533eb75ff505f8aa16c206af1ca13f0e6c166 (patch) | |
tree | 2c0b7dec8df5dba684b9f35f2bfbbe9fd51ff7d4 /cli/main.rs | |
parent | 2093ee55d4c728448a3db373dd416b6eea845c14 (diff) |
feat: deno eval -p (#5682)
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/cli/main.rs b/cli/main.rs index 6d9aacf37..7da0e2df3 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -333,6 +333,7 @@ async fn eval_command( flags: Flags, code: String, as_typescript: bool, + print: bool, ) -> Result<(), ErrBox> { // Force TypeScript compile. let main_module = @@ -341,6 +342,13 @@ async fn eval_command( let mut worker = MainWorker::create(global_state, main_module.clone())?; let main_module_url = main_module.as_url().to_owned(); // Create a dummy source file. + let source_code = if print { + "console.log(".to_string() + &code + ")" + } else { + code.clone() + } + .into_bytes(); + let source_file = SourceFile { filename: main_module_url.to_file_path().unwrap(), url: main_module_url, @@ -351,7 +359,7 @@ async fn eval_command( } else { MediaType::JavaScript }, - source_code: code.clone().into_bytes(), + source_code, }; // Save our fake file into file fetcher cache // to allow module access by TS compiler (e.g. op_fetch_source_files) @@ -627,9 +635,10 @@ pub fn main() { filter, } => doc_command(flags, source_file, json, filter).boxed_local(), DenoSubcommand::Eval { + print, code, as_typescript, - } => eval_command(flags, code, as_typescript).boxed_local(), + } => eval_command(flags, code, as_typescript, print).boxed_local(), DenoSubcommand::Cache { files } => { cache_command(flags, files).boxed_local() } |