The source map specification is very loose and does not specify what
column numbers actually mean. The popular "source-map" library from Mozilla
appears to interpret them as counts of UTF-16 code units, so we generate
those too for compatibility.
We keep mapping tables around to accelerate conversion from byte offsets
to UTF-16 code unit counts. However, this mapping takes up a lot of memory
and generates a lot of garbage. Since most JavaScript is ASCII and the
mapping for ASCII is 1:1, we avoid creating a table for ASCII-only lines
as an optimization.
byteOffsetToStartOfLineint32columnsForNonASCII[]int32
func GenerateLineOffsetTables(contents string, approximateLineCount int32) []LineOffsetTable
ExtractedCommentsmap[string]boolJS[]byte
This source map chunk just contains the VLQ-encoded offsets for the "JS"
field above. It's not a full source map. The bundler will be joining many
source map chunks together to form the final source map.
func Print(tree js_ast.AST, symbols js_ast.SymbolMap, r renamer.Renamer, options Options) PrintResult
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.
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.
ShouldIgnorebool
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.
These are stored in the source map in VLQ format.
This isn't stored in the source map. It's only used by the bundler to join
source map chunks together correctly.
OriginalColumnintOriginalLineintSourceIndexint
func AppendSourceMapChunk(j *Joiner, prevEndState SourceMapState, startState SourceMapState, sourceMap []byte)
func AppendSourceMapChunk(j *Joiner, prevEndState SourceMapState, startState SourceMapState, sourceMap []byte)
func appendMapping(buffer []byte, lastByte byte, prevState SourceMapState, currentState SourceMapState) []byte
func appendMapping(buffer []byte, lastByte byte, prevState SourceMapState, currentState SourceMapState) []byte
Package-Level Functions (total 10, in which 6 are exported)
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.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.