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

fix: Resolve conflict between "debugId" and "debug_id" #100

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

### Various fixes & improvements

- Fixed an error when deserializing sourcemaps with
both `"debugId"` and `"debug_id"` keys (#100) by @loewenheim

## 9.1.0

### Various fixes & improvements
Expand Down
4 changes: 3 additions & 1 deletion src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ pub fn decode_regular(rsm: RawSourceMap) -> Result<SourceMap> {

let mut sm = SourceMap::new(file, tokens, names, sources, source_content);
sm.set_source_root(rsm.source_root);
sm.set_debug_id(rsm.debug_id);
// Use debug_id_old (from "debug_id" key) only if debug_id
// from ( "debugId" key) is unset
sm.set_debug_id(rsm.debug_id.or(rsm.debug_id_old));
if let Some(ignore_list) = rsm.ignore_list {
for idx in ignore_list {
sm.add_to_ignore_list(idx);
Expand Down
2 changes: 2 additions & 0 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ impl Encodable for SourceMap {
x_metro_module_paths: None,
x_facebook_sources: None,
debug_id: self.get_debug_id(),
debug_id_old: None,
}
}
}
Expand Down Expand Up @@ -213,6 +214,7 @@ impl Encodable for SourceMapIndex {
x_metro_module_paths: None,
x_facebook_sources: None,
debug_id: None,
debug_id_old: None,
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/jsontypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ pub struct RawSourceMap {
pub x_metro_module_paths: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub x_facebook_sources: FacebookSources,
#[serde(skip_serializing_if = "Option::is_none", alias = "debugId")]
#[serde(skip_serializing_if = "Option::is_none", rename = "debugId")]
pub debug_id: Option<DebugId>,
// This field only exists to be able to deserialize from "debug_id" keys
// if "debugId" is unset.
#[serde(skip_serializing_if = "Option::is_none", rename = "debug_id")]
pub debug_id_old: Option<DebugId>,
}

#[derive(Deserialize)]
Expand Down
1 change: 1 addition & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ mod tests {
"sources":["coolstuff.js"],
"names":["x","alert"],
"mappings":"AAAA,GAAIA,GAAI,EACR,IAAIA,GAAK,EAAG,CACVC,MAAM",
"debug_id": "11111111-1111-1111-1111-111111111111",
"debugId":"00000000-0000-0000-0000-000000000000"
}"#;

Expand Down