Skip to content

Commit b07da1b

Browse files
authored
Merge pull request #16 from MStoykov/fixMappingParsing
Better detection that a value should be pushed
2 parents eed1c20 + 2c2989c commit b07da1b

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

mappings.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ type mappings struct {
2323
rd *strings.Reader
2424
dec base64vlq.Decoder
2525

26-
hasName bool
27-
value mapping
26+
hasValue bool
27+
hasName bool
28+
value mapping
2829

2930
values []mapping
3031
}
@@ -91,6 +92,7 @@ func (m *mappings) parse() error {
9192
if err != nil {
9293
return err
9394
}
95+
m.hasValue = true
9496
}
9597
}
9698
}
@@ -142,10 +144,10 @@ func parseNamesInd(m *mappings) (fn, error) {
142144
}
143145

144146
func (m *mappings) pushValue() {
145-
if m.value.sourceLine == 1 && m.value.sourceColumn == 0 {
147+
if !m.hasValue {
146148
return
147149
}
148-
150+
m.hasValue = false
149151
if m.hasName {
150152
m.values = append(m.values, m.value)
151153
m.hasName = false

mappings_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package sourcemap
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func TestParseMappings(t *testing.T) {
9+
t.Parallel()
10+
cases := map[string][]mapping{
11+
";;;;;;kBAEe,YAAY,CAC1B,C;;AAHD": {
12+
{genLine: 7, genColumn: 18, sourceLine: 3, sourceColumn: 15, namesInd: -1},
13+
{genLine: 7, genColumn: 30, sourceLine: 3, sourceColumn: 27, namesInd: -1},
14+
{genLine: 7, genColumn: 31, sourceLine: 4, sourceColumn: 1, namesInd: -1},
15+
{genLine: 7, genColumn: 32, sourceLine: 4, sourceColumn: 1, namesInd: -1},
16+
{genLine: 9, genColumn: 0, sourceLine: 1, sourceColumn: 0, namesInd: -1},
17+
},
18+
}
19+
for k, c := range cases {
20+
k, c := k, c
21+
t.Run(k, func(t *testing.T) {
22+
t.Parallel()
23+
v, err := parseMappings(k)
24+
if err != nil {
25+
t.Fatalf("got error %s", err)
26+
}
27+
if !reflect.DeepEqual(v, c) {
28+
t.Fatalf("expected %v got %v", c, v)
29+
}
30+
})
31+
}
32+
}

0 commit comments

Comments
 (0)