sourcemap

package
v0.14.45 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendSourceMapChunk added in v0.12.20

func AppendSourceMapChunk(j *helpers.Joiner, prevEndState SourceMapState, startState SourceMapState, sourceMap []byte)

Source map chunks are computed in parallel for speed. Each chunk is relative to the zero state instead of being relative to the end state of the previous chunk, since it's impossible to know the end state of the previous chunk in a parallel computation.

After all chunks are computed, they are joined together in a second pass. This rewrites the first mapping in each chunk to be relative to the end state of the previous chunk.

func DecodeVLQ

func DecodeVLQ(encoded []byte, start int) (int, int)

func DecodeVLQUTF16

func DecodeVLQUTF16(encoded []uint16) (int, int, bool)

func EncodeVLQ

func EncodeVLQ(value int) []byte

A single base 64 digit can contain 6 bits of data. For the base 64 variable length quantities we use in the source map spec, the first bit is the sign, the next four bits are the actual value, and the 6th bit is the continuation bit. The continuation bit tells us whether there are more digits in this value following this digit.

Continuation
|    Sign
|    |
V    V
101011

Types

type Chunk added in v0.12.20

type Chunk struct {
	Buffer []byte

	// This end state will be used to rewrite the start of the following source
	// map chunk so that the delta-encoded VLQ numbers are preserved.
	EndState SourceMapState

	// There probably isn't a source mapping at the end of the file (nor should
	// there be) but if we're appending another source map chunk after this one,
	// we'll need to know how many characters were in the last line we generated.
	FinalGeneratedColumn int

	ShouldIgnore bool
}

type ChunkBuilder added in v0.12.20

type ChunkBuilder struct {
	// contains filtered or unexported fields
}

func MakeChunkBuilder added in v0.12.20

func MakeChunkBuilder(inputSourceMap *SourceMap, lineOffsetTables []LineOffsetTable) ChunkBuilder

func (*ChunkBuilder) AddSourceMapping added in v0.12.20

func (b *ChunkBuilder) AddSourceMapping(loc logger.Loc, output []byte)

func (*ChunkBuilder) GenerateChunk added in v0.12.20

func (b *ChunkBuilder) GenerateChunk(output []byte) Chunk

type LineColumnOffset added in v0.9.3

type LineColumnOffset struct {
	Lines   int
	Columns int
}

func (*LineColumnOffset) Add added in v0.9.4

func (*LineColumnOffset) AdvanceBytes added in v0.9.3

func (offset *LineColumnOffset) AdvanceBytes(bytes []byte)

func (*LineColumnOffset) AdvanceString added in v0.9.3

func (offset *LineColumnOffset) AdvanceString(text string)

func (LineColumnOffset) ComesBefore added in v0.9.4

func (a LineColumnOffset) ComesBefore(b LineColumnOffset) bool

type LineOffsetTable added in v0.12.20

type LineOffsetTable struct {
	// contains filtered or unexported fields
}

func GenerateLineOffsetTables added in v0.12.20

func GenerateLineOffsetTables(contents string, approximateLineCount int32) []LineOffsetTable

type Mapping

type Mapping struct {
	GeneratedLine   int32 // 0-based
	GeneratedColumn int32 // 0-based count of UTF-16 code units

	SourceIndex    int32 // 0-based
	OriginalLine   int32 // 0-based
	OriginalColumn int32 // 0-based count of UTF-16 code units
}

type SourceContent added in v0.8.25

type SourceContent struct {
	// This stores both the unquoted and the quoted values. We try to use the
	// already-quoted value if possible so we don't need to re-quote it
	// unnecessarily for maximum performance.
	Quoted string

	// But sometimes we need to re-quote the value, such as when it contains
	// non-ASCII characters and we are in ASCII-only mode. In that case we quote
	// this parsed UTF-16 value.
	Value []uint16
}

type SourceMap

type SourceMap struct {
	Sources        []string
	SourcesContent []SourceContent
	Mappings       []Mapping
}

func (*SourceMap) Find

func (sm *SourceMap) Find(line int32, column int32) *Mapping

type SourceMapPieces added in v0.9.4

type SourceMapPieces struct {
	Prefix   []byte
	Mappings []byte
	Suffix   []byte
}

func (SourceMapPieces) Finalize added in v0.9.4

func (pieces SourceMapPieces) Finalize(shifts []SourceMapShift) []byte

func (SourceMapPieces) HasContent added in v0.11.23

func (pieces SourceMapPieces) HasContent() bool

type SourceMapShift added in v0.9.4

type SourceMapShift struct {
	Before LineColumnOffset
	After  LineColumnOffset
}

type SourceMapState added in v0.12.20

type SourceMapState struct {
	// This isn't stored in the source map. It's only used by the bundler to join
	// source map chunks together correctly.
	GeneratedLine int

	// These are stored in the source map in VLQ format.
	GeneratedColumn int
	SourceIndex     int
	OriginalLine    int
	OriginalColumn  int
}

Coordinates in source maps are stored using relative offsets for size reasons. When joining together chunks of a source map that were emitted in parallel for different parts of a file, we need to fix up the first segment of each chunk to be relative to the end of the previous chunk.

Jump to

Keyboard shortcuts

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