package js_printer

import "github.com/evanw/esbuild/internal/js_printer"

Index

Functions

func CanEscapeIdentifier

func CanEscapeIdentifier(name string, UnsupportedFeatures compat.JSFeature, asciiOnly bool) bool

func QuoteIdentifier

func QuoteIdentifier(js []byte, name string, unsupportedFeatures compat.JSFeature) []byte

Types

type Options

type Options struct {
	RequireOrImportMetaForSource func(uint32) RequireOrImportMeta

	// Cross-module inlining of TypeScript enums is actually done during printing
	TSEnums map[ast.Ref]map[string]js_ast.TSEnumValue

	// Cross-module inlining of detected inlinable constants is also done during printing
	ConstValues map[ast.Ref]js_ast.ConstValue

	// Property mangling results go here
	MangledProps map[ast.Ref]string

	// This will be present if the input file had a source map. In that case we
	// want to map all the way back to the original input file(s).
	InputSourceMap *sourcemap.SourceMap

	// If we're writing out a source map, this table of line start indices lets
	// us do binary search on to figure out what line a given AST node came from
	LineOffsetTables []sourcemap.LineOffsetTable

	ToCommonJSRef       ast.Ref
	ToESMRef            ast.Ref
	RuntimeRequireRef   ast.Ref
	UnsupportedFeatures compat.JSFeature
	Indent              int
	LineLimit           int
	OutputFormat        config.Format
	MinifyWhitespace    bool
	MinifyIdentifiers   bool
	MinifySyntax        bool
	ASCIIOnly           bool
	LegalComments       config.LegalComments
	SourceMap           config.SourceMap
	AddSourceMappings   bool
	NeedsMetafile       bool
}

type PrintResult

type PrintResult struct {
	JS                     []byte
	ExtractedLegalComments []string
	JSONMetadataImports    []string

	// 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 sourcemap.Chunk
}

func Print

func Print(tree js_ast.AST, symbols ast.SymbolMap, r renamer.Renamer, options Options) PrintResult

type RequireOrImportMeta

type RequireOrImportMeta struct {
	// CommonJS files will return the "require_*" wrapper function and an invalid
	// exports object reference. Lazily-initialized ESM files will return the
	// "init_*" wrapper function and the exports object for that file.
	WrapperRef     ast.Ref
	ExportsRef     ast.Ref
	IsWrapperAsync bool
}

Source Files

js_printer.go

Version
v0.25.0 (latest)
Published
Feb 8, 2025
Platform
linux/amd64
Imports
15 packages
Last checked
4 days ago

Tools for package owners.