summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/fmt_errors.rs5
-rw-r--r--cli/proc_state.rs29
2 files changed, 11 insertions, 23 deletions
diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs
index d30f661a9..37a58364a 100644
--- a/cli/fmt_errors.rs
+++ b/cli/fmt_errors.rs
@@ -8,8 +8,6 @@ use deno_core::error::format_file_name;
use deno_core::error::JsError;
use deno_core::error::JsStackFrame;
-const SOURCE_ABBREV_THRESHOLD: usize = 150;
-
// Keep in sync with `/core/error.js`.
pub fn format_location(frame: &JsStackFrame) -> String {
let _internal = frame
@@ -115,8 +113,7 @@ fn format_maybe_source_line(
let source_line = source_line.unwrap();
// sometimes source_line gets set with an empty string, which then outputs
// an empty source line when displayed, so need just short circuit here.
- // Also short-circuit on error line too long.
- if source_line.is_empty() || source_line.len() > SOURCE_ABBREV_THRESHOLD {
+ if source_line.is_empty() {
return "".to_string();
}
if source_line.contains("Couldn't format source line: ") {
diff --git a/cli/proc_state.rs b/cli/proc_state.rs
index 2c454c0ee..9e948643d 100644
--- a/cli/proc_state.rs
+++ b/cli/proc_state.rs
@@ -694,11 +694,9 @@ impl SourceMapGetter for ProcState {
_ => return None,
}
if let Some((code, maybe_map)) = self.get_emit(&specifier) {
- let code = String::from_utf8(code).unwrap();
- source_map_from_code(code).or(maybe_map)
+ source_map_from_code(&code).or(maybe_map)
} else if let Ok(source) = self.load(specifier, None, false) {
- let code = String::from_utf8(source.code.to_vec()).unwrap();
- source_map_from_code(code)
+ source_map_from_code(&source.code)
} else {
None
}
@@ -756,21 +754,14 @@ pub fn import_map_from_text(
Ok(result.import_map)
}
-fn source_map_from_code(code: String) -> Option<Vec<u8>> {
- let lines: Vec<&str> = code.split('\n').collect();
- if let Some(last_line) = lines.last() {
- if last_line
- .starts_with("//# sourceMappingURL=data:application/json;base64,")
- {
- let input = last_line.trim_start_matches(
- "//# sourceMappingURL=data:application/json;base64,",
- );
- let decoded_map = base64::decode(input)
- .expect("Unable to decode source map from emitted file.");
- Some(decoded_map)
- } else {
- None
- }
+fn source_map_from_code(code: &[u8]) -> Option<Vec<u8>> {
+ static PREFIX: &[u8] = b"//# sourceMappingURL=data:application/json;base64,";
+ let last_line = code.rsplitn(2, |u| u == &b'\n').next().unwrap();
+ if last_line.starts_with(PREFIX) {
+ let input = last_line.split_at(PREFIX.len()).1;
+ let decoded_map = base64::decode(input)
+ .expect("Unable to decode source map from emitted file.");
+ Some(decoded_map)
} else {
None
}