diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-10-23 11:50:15 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-23 11:50:15 +1100 |
commit | 7e2c7fb6c5454e30158d74e1a5786183ea391f07 (patch) | |
tree | 42402aa26a0422b9c46d1d441598dbe803b8ed15 /cli/source_maps.rs | |
parent | 9fa59f0ca8164f5e02ba2a2fa90b6fdbce5c1afb (diff) |
refactor(cli): migrate run and cache to new infrastructure (#7996)
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
Diffstat (limited to 'cli/source_maps.rs')
-rw-r--r-- | cli/source_maps.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/cli/source_maps.rs b/cli/source_maps.rs index 4744482a7..f31228bdc 100644 --- a/cli/source_maps.rs +++ b/cli/source_maps.rs @@ -6,8 +6,9 @@ use deno_core::error::JsError as CoreJsError; use sourcemap::SourceMap; use std::collections::HashMap; use std::str; +use std::sync::Arc; -pub trait SourceMapGetter { +pub trait SourceMapGetter: Sync + Send { /// Returns the raw source map file. fn get_source_map(&self, file_name: &str) -> Option<Vec<u8>>; fn get_source_line( @@ -26,7 +27,7 @@ pub type CachedMaps = HashMap<String, Option<SourceMap>>; /// source, rather than the transpiled source code. pub fn apply_source_map<G: SourceMapGetter>( js_error: &CoreJsError, - getter: &G, + getter: Arc<G>, ) -> CoreJsError { // Note that js_error.frames has already been source mapped in // prepareStackTrace(). @@ -39,7 +40,7 @@ pub fn apply_source_map<G: SourceMapGetter>( // start_column is 0-based, we need 1-based here. js_error.start_column.map(|n| n + 1), &mut mappings_map, - getter, + getter.clone(), ); let start_column = start_column.map(|n| n - 1); // It is better to just move end_column to be the same distance away from @@ -87,7 +88,7 @@ fn get_maybe_orig_position<G: SourceMapGetter>( line_number: Option<i64>, column_number: Option<i64>, mappings_map: &mut CachedMaps, - getter: &G, + getter: Arc<G>, ) -> (Option<String>, Option<i64>, Option<i64>) { match (file_name, line_number, column_number) { (Some(file_name_v), Some(line_v), Some(column_v)) => { @@ -104,7 +105,7 @@ pub fn get_orig_position<G: SourceMapGetter>( line_number: i64, column_number: i64, mappings_map: &mut CachedMaps, - getter: &G, + getter: Arc<G>, ) -> (String, i64, i64) { let maybe_source_map = get_mappings(&file_name, mappings_map, getter); let default_pos = (file_name, line_number, column_number); @@ -134,7 +135,7 @@ pub fn get_orig_position<G: SourceMapGetter>( fn get_mappings<'a, G: SourceMapGetter>( file_name: &str, mappings_map: &'a mut CachedMaps, - getter: &G, + getter: Arc<G>, ) -> &'a Option<SourceMap> { mappings_map .entry(file_name.to_string()) @@ -145,7 +146,7 @@ fn get_mappings<'a, G: SourceMapGetter>( // the module meta data. fn parse_map_string<G: SourceMapGetter>( file_name: &str, - getter: &G, + getter: Arc<G>, ) -> Option<SourceMap> { getter .get_source_map(file_name) @@ -207,8 +208,8 @@ mod tests { frames: vec![], stack: None, }; - let getter = MockSourceMapGetter {}; - let actual = apply_source_map(&e, &getter); + let getter = Arc::new(MockSourceMapGetter {}); + let actual = apply_source_map(&e, getter); assert_eq!(actual.source_line, Some("console.log('foo');".to_string())); } } |