Documentation
¶
Overview ¶
Package sourcemap provides source map generation for the WGSL minifier.
It implements the Source Map v3 format as specified at: https://sourcemaps.info/spec.html
Index ¶
- func DecodeVLQ(input string) (int, int)
- func DecodeVLQSequence(input string, n int) ([]int, error)
- func EncodeVLQ(value int) string
- func EncodeVLQSequence(values []int) string
- type Generator
- func (g *Generator) AddMapping(genLine, genCol, srcOffset int, name string)
- func (g *Generator) Generate() *SourceMap
- func (g *Generator) IncludeSourceContent(include bool)
- func (g *Generator) SetCoverLinesWithoutMappings(cover bool)
- func (g *Generator) SetFile(file string)
- func (g *Generator) SetSourceName(name string)
- type LineIndex
- type Mapping
- type SourceMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeVLQ ¶
DecodeVLQ decodes a VLQ base64 string and returns the value and bytes consumed. Returns (0, 0) if the input is empty or invalid.
func DecodeVLQSequence ¶
DecodeVLQSequence decodes a VLQ sequence expecting n values. Returns an error if not enough values can be decoded.
func EncodeVLQ ¶
EncodeVLQ encodes a signed integer as a VLQ base64 string. The encoding follows the source map v3 specification.
func EncodeVLQSequence ¶
EncodeVLQSequence encodes multiple values as a VLQ sequence.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator builds a source map incrementally.
func NewGenerator ¶
NewGenerator creates a new source map generator for the given original source.
func (*Generator) AddMapping ¶
AddMapping adds a mapping from generated position to source position. genLine and genCol are 0-indexed positions in the generated output. srcOffset is the byte offset in the original source. name is the original name (empty string if no name mapping needed).
func (*Generator) IncludeSourceContent ¶
IncludeSourceContent sets whether to include original source in sourcesContent.
func (*Generator) SetCoverLinesWithoutMappings ¶
SetCoverLinesWithoutMappings enables or disables the line coverage workaround. When enabled (default), a mapping at column 0 is added for any line that would otherwise have no mappings. This works around a bug in Mozilla's source-map library that returns null for lines without a column 0 mapping.
func (*Generator) SetSourceName ¶
SetSourceName sets the original source file name.
type LineIndex ¶
type LineIndex struct {
// contains filtered or unexported fields
}
LineIndex provides efficient byte offset to line/column conversion. It pre-computes line start positions for O(log n) lookups.
func NewLineIndex ¶
NewLineIndex creates a LineIndex for the given source.
func (*LineIndex) ByteOffsetToLineColumn ¶
ByteOffsetToLineColumn converts a byte offset to 0-indexed line and column. The column is in bytes (not UTF-16 code units).
func (*LineIndex) ByteOffsetToLineColumnUTF16 ¶
ByteOffsetToLineColumnUTF16 converts a byte offset to 0-indexed line and column. The column is in UTF-16 code units, as required by the source map spec.
func (*LineIndex) LineColumnToByteOffset ¶
LineColumnToByteOffset converts a 0-indexed line and column to byte offset. The column is expected in bytes.
type Mapping ¶
type Mapping struct {
GenLine int // Generated line (0-indexed)
GenCol int // Generated column (0-indexed)
SrcIndex int // Source file index
SrcLine int // Source line (0-indexed)
SrcCol int // Source column (0-indexed)
NameIndex int // Name index (-1 if no name)
HasName bool // Whether this mapping has a name
}
Mapping represents a decoded source map mapping.
func DecodeMappings ¶
DecodeMappings decodes a VLQ-encoded mappings string.
type SourceMap ¶
type SourceMap struct {
Version int `json:"version"`
File string `json:"file,omitempty"`
SourceRoot string `json:"sourceRoot,omitempty"`
Sources []string `json:"sources"`
SourcesContent []string `json:"sourcesContent,omitempty"`
Names []string `json:"names"`
Mappings string `json:"mappings"`
}
SourceMap represents a Source Map v3. See https://sourcemaps.info/spec.html
func (*SourceMap) ToComment ¶
ToComment returns a source map comment for appending to generated code. For WGSL, we use JavaScript-style comments as WGSL doesn't have a standard.