diff --git a/src/types.rs b/src/types.rs index cc6fd7b..5e6ec3c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -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, diff --git a/tests/test_index.rs b/tests/test_index.rs index b398357..4e8fd12 100644 --- a/tests/test_index.rs +++ b/tests/test_index.rs @@ -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) diff --git a/tests/test_regular.rs b/tests/test_regular.rs index 93db0d4..a115329 100644 --- a/tests/test_regular.rs +++ b/tests/test_regular.rs @@ -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]