Skip to content

Commit 180fcef

Browse files
authored
Merge pull request #17 from MStoykov/getLastMappingEvenIfColumnIsBigger
Get last mapping if line matches but column is way bigger
2 parents b07da1b + 73a0ee2 commit 180fcef

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

consumer.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,24 @@ func (c *Consumer) source(
192192
return int(m.genLine) >= genLine
193193
})
194194

195-
// Mapping not found.
195+
var match *mapping
196+
// Mapping not found
196197
if i == len(m.mappings) {
197-
return
198-
}
199-
200-
match := &m.mappings[i]
201-
202-
// Fuzzy match.
203-
if int(match.genLine) > genLine || int(match.genColumn) > genColumn {
204-
if i == 0 {
198+
// lets see if the line is correct but the column is bigger
199+
match = &m.mappings[i-1]
200+
if int(match.genLine) != genLine {
205201
return
206202
}
207-
match = &m.mappings[i-1]
203+
} else {
204+
match = &m.mappings[i]
205+
206+
// Fuzzy match.
207+
if int(match.genLine) > genLine || int(match.genColumn) > genColumn {
208+
if i == 0 {
209+
return
210+
}
211+
match = &m.mappings[i-1]
212+
}
208213
}
209214

210215
if match.sourcesInd >= 0 {

consumer_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ func testSourceMap(t *testing.T, json string) {
9696
{2, 21, "/the/root/two.js", "", 2, 3},
9797
{2, 28, "/the/root/two.js", "n", 2, 10},
9898

99+
// line correct, column bigger than last mapping
100+
{2, 29, "/the/root/two.js", "n", 2, 10},
101+
99102
// Fuzzy match.
100103
{1, 20, "/the/root/one.js", "bar", 1, 21},
101104
{1, 30, "/the/root/one.js", "baz", 2, 10},

0 commit comments

Comments
 (0)