sourcemap

package
v0.1.0-dev.118 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package sourcemap implements V3 source map generation. Reference: https://sourcemaps.info/spec.html

Index

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

func NewGenerator(file, sourceRoot string) *Generator

NewGenerator creates a new source map generator for the given output file.

func (*Generator) AddMapping

func (g *Generator) AddMapping(genLine, genCol, srcIdx, srcLine, srcCol int)

AddMapping adds a source mapping. All line/column values are 0-based.

func (*Generator) AddNamedMapping

func (g *Generator) AddNamedMapping(genLine, genCol, srcIdx, srcLine, srcCol int, name string)

AddNamedMapping adds a source mapping with a name. All line/column values are 0-based.

func (*Generator) AddSource

func (g *Generator) AddSource(path string) int

AddSource registers a source file and returns its index.

func (*Generator) RawSourceMap

func (g *Generator) RawSourceMap() *RawSourceMap

RawSourceMap returns the structured source map.

func (*Generator) SetSourceContent

func (g *Generator) SetSourceContent(idx int, content string)

SetSourceContent sets the original source content for a source index.

func (*Generator) String

func (g *Generator) String() string

String returns the JSON-encoded source map.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL