Documentation
¶
Overview ¶
Package sourcemap implements V3 source map generation. Reference: https://sourcemaps.info/spec.html
Index ¶
- func DecodeJSON(jsonStr string) (*RawSourceMap, []DecodedMapping, error)
- type DecodedMapping
- type Generator
- func (g *Generator) AddMapping(genLine, genCol, srcIdx, srcLine, srcCol int)
- func (g *Generator) AddNamedMapping(genLine, genCol, srcIdx, srcLine, srcCol int, name string)
- func (g *Generator) AddSource(path string) int
- func (g *Generator) RawSourceMap() *RawSourceMap
- func (g *Generator) SetSourceContent(idx int, content string)
- func (g *Generator) String() string
- type RawSourceMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
func DecodeJSON(jsonStr string) (*RawSourceMap, []DecodedMapping, error)
DecodeJSON parses a JSON source map string into DecodedMappings.
Types ¶
type DecodedMapping ¶
type DecodedMapping struct {
GenLine int // 0-based generated line
GenCol int // 0-based generated column
SrcIdx int // source index into Sources array
SrcLine int // 0-based original line
SrcCol int // 0-based original column
NameIdx int // name index into Names array (-1 if none)
HasSource bool
HasName bool
}
DecodedMapping is a single resolved source map mapping.
func Decode ¶
func Decode(raw *RawSourceMap) ([]DecodedMapping, error)
Decode parses a RawSourceMap into a slice of DecodedMappings.
func MappingForName ¶
func MappingForName(raw *RawSourceMap, mappings []DecodedMapping, name string) DecodedMapping
MappingForName finds a mapping that has the given name in the Names array. Returns a zero DecodedMapping with HasName==false if not found.
func OriginalPositionFor ¶
func OriginalPositionFor(mappings []DecodedMapping, genLine, genCol int) DecodedMapping
OriginalPositionFor finds the mapping at or just before the given generated position. Returns a zero DecodedMapping with HasSource==false if no mapping found.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator builds a V3 source map incrementally.
func NewGenerator ¶
NewGenerator creates a new source map generator for the given output file.
func (*Generator) AddMapping ¶
AddMapping adds a source mapping. All line/column values are 0-based.
func (*Generator) AddNamedMapping ¶
AddNamedMapping adds a source mapping with a name. All line/column values are 0-based.
func (*Generator) RawSourceMap ¶
func (g *Generator) RawSourceMap() *RawSourceMap
RawSourceMap returns the structured source map.
func (*Generator) SetSourceContent ¶
SetSourceContent sets the original source content for a source index.
type RawSourceMap ¶
type RawSourceMap struct {
Version int `json:"version"`
File string `json:"file"`
SourceRoot string `json:"sourceRoot"`
Sources []string `json:"sources"`
Names []string `json:"names"`
Mappings string `json:"mappings"`
SourcesContent []*string `json:"sourcesContent,omitempty"`
}
RawSourceMap is the JSON-serializable V3 source map structure.