diff options
| author | Bert Belder <bertbelder@gmail.com> | 2020-09-14 18:48:57 +0200 |
|---|---|---|
| committer | Bert Belder <bertbelder@gmail.com> | 2020-09-15 01:50:52 +0200 |
| commit | f5b40c918c7d602827622d167728a3e7bae87d9d (patch) | |
| tree | fb51722e043f4d6bce64a2c7e897cce4ead06c82 /cli/source_maps.rs | |
| parent | 3da20d19a14ab6838897d281f1b11e49d68bd1a7 (diff) | |
refactor: use the 'anyhow' crate instead of 'ErrBox' (#7476)
Diffstat (limited to 'cli/source_maps.rs')
| -rw-r--r-- | cli/source_maps.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/cli/source_maps.rs b/cli/source_maps.rs index 9f57814d4..70b9faac6 100644 --- a/cli/source_maps.rs +++ b/cli/source_maps.rs @@ -1,5 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -//! This mod provides functions to remap a deno_core::deno_core::JsError based on a source map + +//! This mod provides functions to remap a `JsError` based on a source map. + +use deno_core::error::JsError as CoreJsError; use sourcemap::SourceMap; use std::collections::HashMap; use std::str; @@ -18,13 +21,13 @@ pub trait SourceMapGetter { /// find a SourceMap. pub type CachedMaps = HashMap<String, Option<SourceMap>>; -/// Apply a source map to a deno_core::JsError, returning a JsError where file -/// names and line/column numbers point to the location in the original source, -/// rather than the transpiled source code. +/// Apply a source map to a `deno_core::JsError`, returning a `JsError` where +/// file names and line/column numbers point to the location in the original +/// source, rather than the transpiled source code. pub fn apply_source_map<G: SourceMapGetter>( - js_error: &deno_core::JsError, + js_error: &CoreJsError, getter: &G, -) -> deno_core::JsError { +) -> CoreJsError { // Note that js_error.frames has already been source mapped in // prepareStackTrace(). let mut mappings_map: CachedMaps = HashMap::new(); @@ -67,7 +70,7 @@ pub fn apply_source_map<G: SourceMapGetter>( _ => js_error.source_line.clone(), }; - deno_core::JsError { + CoreJsError { message: js_error.message.clone(), source_line, script_resource_name, @@ -194,7 +197,7 @@ mod tests { #[test] fn apply_source_map_line() { - let e = deno_core::JsError { + let e = CoreJsError { message: "TypeError: baz".to_string(), source_line: Some("foo".to_string()), script_resource_name: Some("foo_bar.ts".to_string()), |
