Help us shape the future of Go! Take the 2026 Go Developer Survey

minifier

package
v1.95.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package minifier provides deterministic, scope-aware identifier minification for ELPS source files and parsed programs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadExcludeFile

func ReadExcludeFile(path string) ([]string, error)

ReadExcludeFile loads one symbol per line, ignoring blank lines and comment lines that start with ';'.

Types

type Config

type Config struct {
	Analysis            *analysis.Config
	Exclusions          map[string]bool
	RenameExports       bool
	PreserveParams      bool
	PackageSurfaceForms []PackageSurfaceFormSpec
	Formatter           *formatter.Config
	// Warn receives at most one global-name preservation warning per Minify call.
	Warn func(string)
}

Config controls minification behavior.

type FileResult

type FileResult struct {
	Path    string
	Source  []byte
	Output  []byte
	Program []*lisp.LVal
}

FileResult contains the minified output for one source unit.

type InputFile

type InputFile struct {
	Path   string
	Source []byte
}

InputFile is a source unit to minify.

type PackageSurfaceFormSpec added in v1.38.0

type PackageSurfaceFormSpec struct {
	Head       string
	NameIndex  int
	QuotedName bool
}

PackageSurfaceFormSpec declares a top-level form that creates a stable package-visible binding that should be preserved by default.

type Result

type Result struct {
	Files     []FileResult
	SymbolMap SymbolMap
}

Result contains the outputs of a minify run.

func Minify

func Minify(inputs []InputFile, cfg *Config) (*Result, error)

Minify rewrites one or more source units using a single deterministic symbol-assignment session. Quoted names (including list and quasiquote data) are preserved across all inputs and recorded as quoted-reference exclusions. Package definitions retain package scope even inside lexical forms. Runtime evaluation or symbol creation disables all renaming across inputs. Unproven package flow preserves package-level names; lexical locals can shorten only when dynamic evaluation is absent. Both fallbacks record their reason.

type SymbolExclusion added in v1.62.0

type SymbolExclusion struct {
	Original string `json:"original"`
	Reason   string `json:"reason"`
}

SymbolExclusion records a name that cannot be shortened safely.

type SymbolMap

type SymbolMap struct {
	Excluded           []SymbolExclusion   `json:"excluded,omitempty"`
	Entries            []SymbolMapEntry    `json:"entries"`
	MinifiedToOriginal map[string]string   `json:"minified_to_original"`
	OriginalToMinified map[string][]string `json:"original_to_minified,omitempty"`
}

SymbolMap is the machine-readable symbol mapping emitted by a minify run.

func MinifySource

func MinifySource(source []byte, filename string, cfg *Config) ([]byte, SymbolMap, error)

MinifySource is a convenience wrapper for a single source unit.

func (SymbolMap) JSON

func (m SymbolMap) JSON() ([]byte, error)

JSON returns the symbol map encoded as indented JSON.

type SymbolMapEntry

type SymbolMapEntry struct {
	Minified string `json:"minified"`
	Original string `json:"original"`
	Kind     string `json:"kind"`
	File     string `json:"file,omitempty"`
	Line     int    `json:"line,omitempty"`
	Col      int    `json:"col,omitempty"`
}

SymbolMapEntry records one deterministic symbol assignment.

Jump to

Keyboard shortcuts

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