Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- python bindings: Expose SourceMapView.get_source_contents function. ([#921](https://github.com/getsentry/symbolic/pull/921))

**Fixes**

- sourcemapcache: Don't return unmapped source locations. ([#922](https://github.com/getsentry/symbolic/pull/922))

## 12.15.5

**Fixes**
Expand Down
75 changes: 21 additions & 54 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ serde = { version = "1.0.171", features = ["derive"] }
serde_json = "1.0.102"
similar-asserts = "1.4.2"
smallvec = "1.10.0"
sourcemap = "9.1.2"
sourcemap = "9.2.2"
stable_deref_trait = "1.2.0"
tempfile = "3.4.0"
thiserror = "1.0.39"
Expand Down
46 changes: 45 additions & 1 deletion symbolic-sourcemapcache/src/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,17 @@ impl<'data> SourceMapCache<'data> {
pub fn lookup(&self, sp: SourcePosition) -> Option<SourceLocation> {
let idx = match self.min_source_positions.binary_search(&sp.into()) {
Ok(idx) => idx,
Err(0) => 0,
Err(0) => return None,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Swatinem can you think of a reason it would make sense to return 0 here? Surely the Err(0) case means our input location is unmapped?

Err(idx) => idx - 1,
};

let sl = self.orig_source_locations.get(idx)?;

// If file, line, and column are all absent (== `u32::MAX`), this location is simply unmapped.
if sl.file_idx == raw::NO_FILE_SENTINEL && sl.line == u32::MAX && sl.column == u32::MAX {
return None;
}

let line = sl.line;
let column = sl.column;

Expand Down Expand Up @@ -376,4 +381,43 @@ mod tests {
assert_eq!(file.line(3), Some("c\n"));
assert_eq!(file.line(4), Some(""));
}

#[test]
fn unmapped_token() {
let minified = r#""foo"; /*added by bundler*/ "bar";"#;
let sourcemap = r#"{"version":3,"file":"test.min.js","sources":["test.js"],"sourcesContent":["\"foo\":\n\"baz\";"],"names":[],"mappings":"AAAA,M,sBACA"}"#;

let mut buf = vec![];
SourceMapCacheWriter::new(minified, sourcemap)
.unwrap()
.serialize(&mut buf)
.unwrap();

let cache = SourceMapCache::parse(&buf).unwrap();

// "foo";
let foo = cache.lookup(SourcePosition { line: 0, column: 4 }).unwrap();
assert_eq!(foo.file_name().unwrap(), "test.js");
assert_eq!(foo.line, 0);
assert_eq!(foo.column, 0);

// comment
// this should be unmapped
assert!(dbg!(cache.lookup(SourcePosition {
line: 0,
column: 17
}))
.is_none());

// "bar";
let bar = cache
.lookup(SourcePosition {
line: 0,
column: 30,
})
.unwrap();
assert_eq!(bar.file_name().unwrap(), "test.js");
assert_eq!(bar.line, 1);
assert_eq!(bar.column, 0);
}
}
Loading