printer

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendSourceMapChunk

func AppendSourceMapChunk(buffer []byte, prevEndState SourceMapState, startState SourceMapState, sourceMap []byte) []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 Quote

func Quote(text string) string

func QuoteForJSON

func QuoteForJSON(text string) string

Types

type PrintOptions

type PrintOptions struct {
	RemoveWhitespace  bool
	SourceMapContents *string
	Indent            int
	ResolvedImports   map[string]uint32
	RuntimeSymRefs    map[runtime.Sym]ast.Ref
}

type PrintResult

type PrintResult struct {
	JS []byte

	// For minification, it's desirable to strip off unnecessary trailing
	// semicolons from modules inside closures before the ending "}". However,
	// there are some syntax constructs where you can't just remove the trailing
	// semicolon (e.g. "while(foo());"). So we also return the source without the
	// unnecessary trailing semicolon added in case the caller needs it.
	JSWithoutTrailingSemicolon []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.
	SourceMapChunk SourceMapChunk
}

func Print

func Print(tree ast.AST, options PrintOptions) PrintResult

func PrintExpr

func PrintExpr(expr ast.Expr, symbols *ast.SymbolMap, options PrintOptions) PrintResult

type SourceMapChunk

type SourceMapChunk 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
}

type SourceMapState

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