Skip to content

Commit 713eee2

Browse files
authored
fix(sourcemapcache): Tokens only extend to the end of the line (#932)
Previously, when looking up a line and column, we would always return the token at or immediately before that position, even if it belonged to an earlier minified line. This is 1. wrong—tokens are only meant to extend to the end of a line. 2. inconsistent—this means that an unmapped line before any mapped line would return no mapping, but an unmapped line after a mapped line would.
1 parent 11c7ebb commit 713eee2

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
**Fixes**
6+
7+
- sourcemapcache: Tokens are now considered to only extend to the end of the line
8+
(as intended). This means that some lookups that would previously (incorrectly)
9+
have returned unminified source positions now return nothing. ([#932](https://github.com/getsentry/symbolic/pull/932))
10+
311
## 12.16.1
412

513
**Fixes**

symbolic-sourcemapcache/src/lookup.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ impl<'data> SourceMapCache<'data> {
177177
Err(idx) => idx - 1,
178178
};
179179

180+
// If the token has a lower minified line number,
181+
// it actually belongs to the previous line. That means it should
182+
// not match.
183+
if self.min_source_positions.get(idx)?.line < sp.line {
184+
return None;
185+
}
186+
180187
let sl = self.orig_source_locations.get(idx)?;
181188

182189
// If file, line, and column are all absent (== `u32::MAX`), this location is simply unmapped.

symbolic-sourcemapcache/tests/integration.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ fn resolves_inlined_function() {
3838
assert_eq!(sl.line(), 1);
3939
assert_eq!(sl.column(), 8);
4040
assert_eq!(sl.scope(), ScopeLookupResult::AnonymousScope);
41+
42+
// There are no mappings for line 1 in the sourcemap.
43+
assert!(cache.lookup(SourcePosition::new(1, 17)).is_none());
4144
}
4245

4346
#[test]

0 commit comments

Comments
 (0)