Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for sourcemap debugId property #151

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading