diff --git a/logic/source_map.go b/logic/source_map.go index 68250522..0d798971 100644 --- a/logic/source_map.go +++ b/logic/source_map.go @@ -1,6 +1,7 @@ package logic import ( + "encoding/json" "fmt" "strings" ) @@ -19,47 +20,20 @@ type SourceMap struct { } func DecodeSourceMap(ism map[string]interface{}) (SourceMap, error) { - sm := SourceMap{} - - if v, ok := ism["version"]; ok { - switch t := v.(type) { - case float64: - sm.Version = int(t) - case uint64: - sm.Version = int(t) - } - } - - if sm.Version != 3 { - return sm, fmt.Errorf("only version 3 is supported") - } - - if f, ok := ism["file"]; ok { - sm.File = f.(string) - } + var sm SourceMap - if sr, ok := ism["sourceRoot"]; ok { - sm.SourceRoot = sr.(string) + buff, err := json.Marshal(ism) + if err != nil { + return sm, err } - if srcs, ok := ism["sources"]; ok { - srcSlice := srcs.([]interface{}) - sm.Sources = make([]string, len(srcSlice)) - for idx, s := range srcSlice { - sm.Sources[idx] = s.(string) - } + err = json.Unmarshal(buff, &sm) + if err != nil { + return sm, err } - if names, ok := ism["names"]; ok { - nameSlice := names.([]interface{}) - sm.Names = make([]string, len(nameSlice)) - for idx, n := range nameSlice { - sm.Names[idx] = n.(string) - } - } - - if m, ok := ism["mappings"]; ok { - sm.Mappings = m.(string) + if sm.Version != 3 { + return sm, fmt.Errorf("only version 3 is supported") } if sm.Mappings == "" {