Skip to content
Closed
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 src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,13 @@ impl SourceMap {
let (idx, raw) =
greatest_lower_bound(&self.tokens, &(line, col), |t| (t.dst_line, t.dst_col))?;

// If the token has a lower minified line number,
// it actually belongs to the previous line. That means it should
// not match.
if raw.dst_line < line {
return None;
}

let mut token = Token {
raw,
sm: self,
Expand Down
9 changes: 5 additions & 4 deletions tests/test_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ fn test_basic_indexed_sourcemap() {
ism.lookup_token(0, 0).unwrap().to_tuple(),
("file1.js", 0, 0, None)
);
assert_eq!(
ism.lookup_token(1, 0).unwrap().to_tuple(),
("file1.js", 2, 12, Some("b"))
);

// Line 1, column 0 (zero-based) falls into the first section,
// but there are no mappings for line 1 there.
assert!(ism.lookup_token(1, 0).is_none());

assert_eq!(
ism.lookup_token(1, 1).unwrap().to_tuple(),
("file2.js", 0, 0, None)
Expand Down
7 changes: 2 additions & 5 deletions tests/test_regular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ fn test_basic_sourcemap() {
("coolstuff.js", 2, 8, None)
);

// Token can return prior lines.
assert_eq!(
sm.lookup_token(1000, 0).unwrap().to_tuple(),
("coolstuff.js", 2, 8, None)
);
// There are no mappings for line 1000.
assert!(sm.lookup_token(1000, 0).is_none());
}

#[test]
Expand Down
Loading