Skip to content

Commit

Permalink
feat: Add support for sourcemap debugid property (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish authored Jan 8, 2025
1 parent 10b6a4c commit a847aae
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ pub struct SourceMap {
mappings: Arc<str>,
#[serde(rename = "sourceRoot", skip_serializing_if = "Option::is_none")]
source_root: Option<Arc<str>>,
#[serde(rename = "debugId", skip_serializing_if = "Option::is_none")]
debug_id: Option<Arc<str>>,
}

impl Hash for SourceMap {
Expand Down Expand Up @@ -241,6 +243,7 @@ impl SourceMap {
sources_content: sources_content.into(),
names: names.into(),
source_root: None,
debug_id: None,
}
}

Expand Down Expand Up @@ -321,6 +324,16 @@ impl SourceMap {
pub fn set_source_root<T: Into<Arc<str>>>(&mut self, source_root: Option<T>) {
self.source_root = source_root.map(Into::into);
}

/// Set the debug_id field in [SourceMap].
pub fn set_debug_id<T: Into<Arc<str>>>(&mut self, debug_id: Option<T>) {
self.debug_id = debug_id.map(Into::into);
}

/// Get the debug_id field in [SourceMap].
pub fn get_debug_id(&self) -> Option<&str> {
self.debug_id.as_deref()
}
}

#[derive(Debug, Default, Deserialize)]
Expand All @@ -333,6 +346,8 @@ struct RawSourceMap {
pub sources_content: Option<Vec<Option<String>>>,
pub names: Option<Vec<Option<String>>>,
pub mappings: String,
#[serde(rename = "debugId")]
pub debug_id: Option<String>,
}

impl RawSourceMap {
Expand Down Expand Up @@ -411,6 +426,7 @@ impl TryFrom<RawSourceMap> for SourceMap {
.collect::<Vec<_>>()
.into();
let source_root = raw.source_root.map(Into::into);
let debug_id = raw.debug_id.map(Into::into);

Ok(Self {
version: 3,
Expand All @@ -420,6 +436,7 @@ impl TryFrom<RawSourceMap> for SourceMap {
sources_content,
names,
source_root,
debug_id,
})
}
}
Expand Down

0 comments on commit a847aae

Please sign in to comment.