summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/BUILD.gn1
-rw-r--r--cli/msg.fbs7
-rw-r--r--cli/ops.rs46
-rw-r--r--cli/source_maps.rs6
4 files changed, 57 insertions, 3 deletions
diff --git a/cli/BUILD.gn b/cli/BUILD.gn
index 7f19f8b95..84ffe6da4 100644
--- a/cli/BUILD.gn
+++ b/cli/BUILD.gn
@@ -83,6 +83,7 @@ ts_sources = [
"../js/dispatch_minimal.ts",
"../js/dom_types.ts",
"../js/dom_util.ts",
+ "../js/error_stack.ts",
"../js/errors.ts",
"../js/event.ts",
"../js/event_target.ts",
diff --git a/cli/msg.fbs b/cli/msg.fbs
index 2ab776ef3..014bfb7e9 100644
--- a/cli/msg.fbs
+++ b/cli/msg.fbs
@@ -1,5 +1,6 @@
union Any {
Accept,
+ ApplySourceMap,
Cache,
Chdir,
Chmod,
@@ -257,6 +258,12 @@ table FetchSourceFileRes {
data: [ubyte];
}
+table ApplySourceMap {
+ filename: string;
+ line: int;
+ column: int;
+}
+
table Cache {
extension: string;
module_id: string;
diff --git a/cli/ops.rs b/cli/ops.rs
index d4bc94f75..227bb03b3 100644
--- a/cli/ops.rs
+++ b/cli/ops.rs
@@ -20,6 +20,8 @@ use crate::resources;
use crate::resources::table_entries;
use crate::resources::Resource;
use crate::signal::kill;
+use crate::source_maps::get_orig_position;
+use crate::source_maps::CachedMaps;
use crate::startup_data;
use crate::state::ThreadSafeState;
use crate::tokio_util;
@@ -46,6 +48,7 @@ use log;
use rand::{thread_rng, Rng};
use remove_dir_all::remove_dir_all;
use std;
+use std::collections::HashMap;
use std::convert::From;
use std::fs;
use std::net::Shutdown;
@@ -194,6 +197,7 @@ pub fn dispatch_all_legacy(
pub fn op_selector_std(inner_type: msg::Any) -> Option<CliDispatchFn> {
match inner_type {
msg::Any::Accept => Some(op_accept),
+ msg::Any::ApplySourceMap => Some(op_apply_source_map),
msg::Any::Cache => Some(op_cache),
msg::Any::Chdir => Some(op_chdir),
msg::Any::Chmod => Some(op_chmod),
@@ -532,6 +536,48 @@ fn op_fetch_source_file(
Ok(Op::Sync(result_buf))
}
+fn op_apply_source_map(
+ state: &ThreadSafeState,
+ base: &msg::Base<'_>,
+ data: Option<PinnedBuf>,
+) -> CliOpResult {
+ if !base.sync() {
+ return Err(deno_error::no_async_support());
+ }
+ assert!(data.is_none());
+ let inner = base.inner_as_apply_source_map().unwrap();
+ let cmd_id = base.cmd_id();
+ let filename = inner.filename().unwrap();
+ let line = inner.line();
+ let column = inner.column();
+
+ let mut mappings_map: CachedMaps = HashMap::new();
+ let (orig_filename, orig_line, orig_column) = get_orig_position(
+ filename.to_owned(),
+ line.into(),
+ column.into(),
+ &mut mappings_map,
+ &state.ts_compiler,
+ );
+
+ let builder = &mut FlatBufferBuilder::new();
+ let msg_args = msg::ApplySourceMapArgs {
+ filename: Some(builder.create_string(&orig_filename)),
+ line: orig_line as i32,
+ column: orig_column as i32,
+ };
+ let res_inner = msg::ApplySourceMap::create(builder, &msg_args);
+ ok_buf(serialize_response(
+ cmd_id,
+ builder,
+ msg::BaseArgs {
+ inner: Some(res_inner.as_union_value()),
+ inner_type: msg::Any::ApplySourceMap,
+ ..Default::default()
+ },
+ ))
+}
+
fn op_chdir(
_state: &ThreadSafeState,
base: &msg::Base<'_>,
diff --git a/cli/source_maps.rs b/cli/source_maps.rs
index 6b453d883..a886c6afc 100644
--- a/cli/source_maps.rs
+++ b/cli/source_maps.rs
@@ -17,9 +17,9 @@ pub trait SourceMapGetter {
/// Cached filename lookups. The key can be None if a previous lookup failed to
/// find a SourceMap.
-type CachedMaps = HashMap<String, Option<SourceMap>>;
+pub type CachedMaps = HashMap<String, Option<SourceMap>>;
-struct SourceMap {
+pub struct SourceMap {
mappings: Mappings,
sources: Vec<String>,
}
@@ -202,7 +202,7 @@ fn get_maybe_orig_position<G: SourceMapGetter>(
}
}
-fn get_orig_position<G: SourceMapGetter>(
+pub fn get_orig_position<G: SourceMapGetter>(
script_name: String,
line: i64,
column: i64,