summaryrefslogtreecommitdiff
path: root/cli/main.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-04-13 19:24:15 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-04-13 13:24:15 -0400
commit591b5e4a7dfc1c3537c7a2c7091ebe3890271780 (patch)
tree2a202be9e236cf4c3436a4cbdc2d3164ca6f43a9 /cli/main.rs
parentd3bd5879c3b1a26cc09a5374bf2b5ee63071fe29 (diff)
Add deno eval subcommand (#2102)
Diffstat (limited to 'cli/main.rs')
-rw-r--r--cli/main.rs32
1 files changed, 24 insertions, 8 deletions
diff --git a/cli/main.rs b/cli/main.rs
index 5314e4149..dc2099595 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -112,14 +112,30 @@ fn main() {
// Setup runtime.
js_check(main_worker.execute("denoMain()"));
- // Execute main module.
- if let Some(main_module) = state.main_module() {
- debug!("main_module {}", main_module);
- js_check(main_worker.execute_mod(&main_module, should_prefetch));
- if should_display_info {
- // Display file info and exit. Do not run file
- main_worker.print_file_info(&main_module);
- std::process::exit(0);
+ if state.flags.eval {
+ // Wrap provided script in async function so asynchronous methods
+ // work. This is required until top-level await is not supported.
+ let js_source = format!(
+ "async function _topLevelWrapper(){{
+ {}
+ }}
+ _topLevelWrapper();
+ ",
+ &state.argv[1]
+ );
+ // ATM imports in `deno eval` are not allowed
+ // TODO Support ES modules once Worker supports evaluating anonymous modules.
+ js_check(main_worker.execute(&js_source));
+ } else {
+ // Execute main module.
+ if let Some(main_module) = state.main_module() {
+ debug!("main_module {}", main_module);
+ js_check(main_worker.execute_mod(&main_module, should_prefetch));
+ if should_display_info {
+ // Display file info and exit. Do not run file
+ main_worker.print_file_info(&main_module);
+ std::process::exit(0);
+ }
}
}