Skip to content

Commit def6f17

Browse files
authored
Merge pull request #19 from codebien/fix-zero-mappings
Exclude empty mappings
2 parents 180fcef + 1c272b9 commit def6f17

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

consumer.go

+4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ func (c *Consumer) source(
195195
var match *mapping
196196
// Mapping not found
197197
if i == len(m.mappings) {
198+
// Empty mappings
199+
if len(m.mappings) == 0 {
200+
return
201+
}
198202
// lets see if the line is correct but the column is bigger
199203
match = &m.mappings[i-1]
200204
if int(match.genLine) != genLine {

consumer_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ func (test *sourceMapTest) assert(t *testing.T, smap *sourcemap.Consumer) {
6666
}
6767
}
6868

69+
func TestSourceWithEmptySourceMap(t *testing.T) {
70+
var jsmap = `{
71+
"version": 3,
72+
"mappings": ";;"
73+
}`
74+
75+
smap, err := sourcemap.Parse("noname", []byte(jsmap))
76+
if err != nil {
77+
t.Fatal(err)
78+
}
79+
80+
_, _, _, _, matched := smap.Source(1, 1)
81+
if matched {
82+
t.Error("it is unexpected to match an empty SourceMap")
83+
}
84+
}
85+
6986
func TestSourceMap(t *testing.T) {
7087
testSourceMap(t, sourceMapJSON)
7188
}

0 commit comments

Comments
 (0)