summaryrefslogtreecommitdiff
path: root/cli/program_state.rs
diff options
context:
space:
mode:
authorLuca Casonato <lucacasonato@yahoo.com>2021-01-06 00:10:36 +0100
committerGitHub <noreply@github.com>2021-01-06 00:10:36 +0100
commit39bbbbce70c13575857b216b79ec21c37a923760 (patch)
tree7791fb712083a8471d132e42b3f3f4ae851d2e55 /cli/program_state.rs
parent8d1ee3bfaf9f062356858b6b7113be0ab7fa5ba6 (diff)
fix: use inline source maps when present in js (#8995)
Diffstat (limited to 'cli/program_state.rs')
-rw-r--r--cli/program_state.rs40
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) {}