diff options
Diffstat (limited to 'cli/program_state.rs')
-rw-r--r-- | cli/program_state.rs | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/cli/program_state.rs b/cli/program_state.rs index 5eda6b3fa..dfe8aa6c3 100644 --- a/cli/program_state.rs +++ b/cli/program_state.rs @@ -300,24 +300,10 @@ impl SourceMapGetter for ProgramState { maybe_map } else { let code = String::from_utf8(code).unwrap(); - 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 - } - } else { - None - } + source_map_from_code(code) } + } else if let Ok(source) = self.load(specifier, None) { + source_map_from_code(source.code) } else { None } @@ -345,6 +331,26 @@ impl SourceMapGetter for ProgramState { } } +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 + } + } else { + None + } +} + #[test] fn thread_safe() { fn f<S: Send + Sync>(_: S) {} |