summaryrefslogtreecommitdiff
path: root/src/js_errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/js_errors.rs')
-rw-r--r--src/js_errors.rs53
1 files changed, 29 insertions, 24 deletions
diff --git a/src/js_errors.rs b/src/js_errors.rs
index f42d9cb51..90c9f2007 100644
--- a/src/js_errors.rs
+++ b/src/js_errors.rs
@@ -206,36 +206,41 @@ pub fn apply_source_map(
}
}
-fn parse_map_string(
- script_name: &str,
- getter: &dyn SourceMapGetter,
-) -> Option<SourceMap> {
+// The bundle does not get built for 'cargo check', so we don't embed the
+// bundle source map.
+#[cfg(feature = "check-only")]
+fn builtin_source_map(script_name: &str) -> Option<Vec<u8>> {
+ None
+}
+
+#[cfg(not(feature = "check-only"))]
+fn builtin_source_map(script_name: &str) -> Option<Vec<u8>> {
match script_name {
- // The bundle does not get built for 'cargo check', so we don't embed the
- // bundle source map.
- #[cfg(not(feature = "check-only"))]
- "gen/bundle/main.js" => {
- let s =
- include_str!(concat!(env!("GN_OUT_DIR"), "/gen/bundle/main.js.map"));
- SourceMap::from_json(s)
- }
- #[cfg(not(feature = "check-only"))]
- "gen/bundle/compiler.js" => {
- let s = include_str!(concat!(
+ "gen/bundle/main.js" => Some(
+ include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/bundle/main.js.map"))
+ .to_vec(),
+ ),
+ "gen/bundle/compiler.js" => Some(
+ include_bytes!(concat!(
env!("GN_OUT_DIR"),
"/gen/bundle/compiler.js.map"
- ));
- SourceMap::from_json(s)
- }
- _ => match getter.get_source_map(script_name) {
- None => None,
- Some(raw_source_map) => {
- SourceMap::from_json(str::from_utf8(&raw_source_map).unwrap())
- }
- },
+ )).to_vec(),
+ ),
+ _ => None,
}
}
+fn parse_map_string(
+ script_name: &str,
+ getter: &dyn SourceMapGetter,
+) -> Option<SourceMap> {
+ builtin_source_map(script_name)
+ .or_else(|| getter.get_source_map(script_name))
+ .and_then(|raw_source_map| {
+ SourceMap::from_json(str::from_utf8(&raw_source_map).unwrap())
+ })
+}
+
fn get_mappings<'a>(
script_name: &str,
mappings_map: &'a mut CachedMaps,