config

package
v0.19.6 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LoaderToString = []string{
	"none",
	"base64",
	"binary",
	"copy",
	"css",
	"dataurl",
	"default",
	"empty",
	"file",
	"global-css",
	"js",
	"json",
	"jsx",
	"local-css",
	"text",
	"ts",
	"ts",
	"tsx",
}

Functions

func CompileFilterForPlugin added in v0.8.1

func CompileFilterForPlugin(pluginName string, kind string, filter string) (*regexp.Regexp, error)

func HasPlaceholder added in v0.8.53

func HasPlaceholder(template []PathTemplate, placeholder PathPlaceholder) bool

func PluginAppliesToPath added in v0.8.1

func PluginAppliesToPath(path logger.Path, filter *regexp.Regexp, namespace string) bool

func ShouldCallRuntimeRequire added in v0.11.23

func ShouldCallRuntimeRequire(mode Mode, outputFormat Format) bool

func TemplateToString added in v0.8.53

func TemplateToString(template []PathTemplate) string

Types

type APICall added in v0.18.0

type APICall uint8
const (
	BuildCall APICall = iota
	TransformCall
)

type CancelFlag added in v0.17.1

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

func (*CancelFlag) Cancel added in v0.17.1

func (flag *CancelFlag) Cancel()

func (*CancelFlag) DidCancel added in v0.17.1

func (flag *CancelFlag) DidCancel() bool

This checks for nil in one place so we don't have to do that everywhere

type DefineData added in v0.5.22

type DefineData struct {
	DefineExpr *DefineExpr

	// True if accessing this value is known to not have any side effects. For
	// example, a bare reference to "Object.create" can be removed because it
	// does not have any observable side effects.
	CanBeRemovedIfUnused bool

	// True if a call to this value is known to not have any side effects. For
	// example, a bare call to "Object()" can be removed because it does not
	// have any observable side effects.
	CallCanBeUnwrappedIfUnused bool

	// If true, the user has indicated that every direct calls to a property on
	// this object and all of that call's arguments are to be removed from the
	// output, even when the arguments have side effects. This is used to
	// implement the "--drop:console" flag.
	MethodCallsMustBeReplacedWithUndefined bool
}

type DefineExpr added in v0.14.44

type DefineExpr struct {
	Constant            js_ast.E
	Parts               []string
	InjectedDefineIndex ast.Index32
}

We currently only support compile-time replacement with certain expressions:

  • Primitive literals
  • Identifiers
  • "Entity names" which are identifiers followed by property accesses

We don't support arbitrary expressions because arbitrary expressions may require the full AST. For example, there could be "import()" or "require()" expressions that need an import record. We also need to re-generate some nodes such as identifiers within the injected context so that they can bind to symbols in that context. Other expressions such as "this" may also be contextual.

type DotDefine

type DotDefine struct {
	Data  DefineData
	Parts []string
}

type ExternalMatchers added in v0.14.13

type ExternalMatchers struct {
	Exact    map[string]bool
	Patterns []WildcardPattern
}

func (ExternalMatchers) HasMatchers added in v0.14.13

func (matchers ExternalMatchers) HasMatchers() bool

type ExternalSettings added in v0.14.13

type ExternalSettings struct {
	PreResolve  ExternalMatchers
	PostResolve ExternalMatchers
}

type Format

type Format uint8
const (
	// This is used when not bundling. It means to preserve whatever form the
	// import or export was originally in. ES6 syntax stays ES6 syntax and
	// CommonJS syntax stays CommonJS syntax.
	FormatPreserve Format = iota

	// IIFE stands for immediately-invoked function expression. That looks like
	// this:
	//
	//   (() => {
	//     ... bundled code ...
	//   })();
	//
	// If the optional GlobalName is configured, then we'll write out this:
	//
	//   let globalName = (() => {
	//     ... bundled code ...
	//     return exports;
	//   })();
	//
	FormatIIFE

	// The CommonJS format looks like this:
	//
	//   ... bundled code ...
	//   module.exports = exports;
	//
	FormatCommonJS

	// The ES module format looks like this:
	//
	//   ... bundled code ...
	//   export {...};
	//
	FormatESModule
)

func (Format) KeepESMImportExportSyntax added in v0.17.4

func (f Format) KeepESMImportExportSyntax() bool

func (Format) String added in v0.6.32

func (f Format) String() string

type InjectableExport added in v0.12.0

type InjectableExport struct {
	Alias string
	Loc   logger.Loc
}

type InjectedDefine added in v0.8.27

type InjectedDefine struct {
	Data   js_ast.E
	Name   string
	Source logger.Source
}

type InjectedFile added in v0.7.17

type InjectedFile struct {
	Exports      []InjectableExport
	DefineName   string // For injected files generated when you "--define" a non-literal
	Source       logger.Source
	IsCopyLoader bool // If you set the loader to "copy" (see https://github.com/evanw/esbuild/issues/3041)
}

type JSXOptions

type JSXOptions struct {
	Factory          DefineExpr
	Fragment         DefineExpr
	Parse            bool
	Preserve         bool
	AutomaticRuntime bool
	ImportSource     string
	Development      bool
	SideEffects      bool
}

type LegalComments added in v0.11.15

type LegalComments uint8
const (
	LegalCommentsInline LegalComments = iota
	LegalCommentsNone
	LegalCommentsEndOfFile
	LegalCommentsLinkedWithComment
	LegalCommentsExternalWithoutComment
)

func (LegalComments) HasExternalFile added in v0.11.15

func (lc LegalComments) HasExternalFile() bool

type Loader

type Loader uint8
const (
	LoaderNone Loader = iota
	LoaderBase64
	LoaderBinary
	LoaderCopy
	LoaderCSS
	LoaderDataURL
	LoaderDefault
	LoaderEmpty
	LoaderFile
	LoaderGlobalCSS
	LoaderJS
	LoaderJSON
	LoaderJSX
	LoaderLocalCSS
	LoaderText
	LoaderTS
	LoaderTSNoAmbiguousLessThan // Used with ".mts" and ".cts"
	LoaderTSX
)

func (Loader) CanHaveSourceMap added in v0.6.13

func (loader Loader) CanHaveSourceMap() bool

func (Loader) IsCSS added in v0.18.17

func (loader Loader) IsCSS() bool

func (Loader) IsTypeScript added in v0.6.13

func (loader Loader) IsTypeScript() bool

type MaybeBool added in v0.11.7

type MaybeBool uint8
const (
	Unspecified MaybeBool = iota
	True
	False
)

type Mode added in v0.6.32

type Mode uint8
const (
	ModePassThrough Mode = iota
	ModeConvertFormat
	ModeBundle
)

type OnLoad added in v0.8.1

type OnLoad struct {
	Filter    *regexp.Regexp
	Callback  func(OnLoadArgs) OnLoadResult
	Name      string
	Namespace string
}

type OnLoadArgs added in v0.8.1

type OnLoadArgs struct {
	PluginData interface{}
	Path       logger.Path
}

type OnLoadResult added in v0.8.1

type OnLoadResult struct {
	PluginName string

	Contents      *string
	AbsResolveDir string
	PluginData    interface{}

	Msgs        []logger.Msg
	ThrownError error

	AbsWatchFiles []string
	AbsWatchDirs  []string

	Loader Loader
}

type OnResolve added in v0.8.1

type OnResolve struct {
	Filter    *regexp.Regexp
	Callback  func(OnResolveArgs) OnResolveResult
	Name      string
	Namespace string
}

type OnResolveArgs added in v0.8.1

type OnResolveArgs struct {
	Path       string
	ResolveDir string
	PluginData interface{}
	Importer   logger.Path
	Kind       ast.ImportKind
}

type OnResolveResult added in v0.8.1

type OnResolveResult struct {
	PluginName string

	Msgs        []logger.Msg
	ThrownError error

	AbsWatchFiles []string
	AbsWatchDirs  []string

	PluginData       interface{}
	Path             logger.Path
	External         bool
	IsSideEffectFree bool
}

type OnStart added in v0.11.15

type OnStart struct {
	Callback func() OnStartResult
	Name     string
}

type OnStartResult added in v0.11.15

type OnStartResult struct {
	ThrownError error
	Msgs        []logger.Msg
}

type Options

type Options struct {
	ModuleTypeData js_ast.ModuleTypeData
	Defines        *ProcessedDefines
	TSAlwaysStrict *TSAlwaysStrict
	MangleProps    *regexp.Regexp
	ReserveProps   *regexp.Regexp
	CancelFlag     *CancelFlag

	// When mangling property names, call this function with a callback and do
	// the property name mangling inside the callback. The callback takes an
	// argument which is the mangle cache map to mutate. These callbacks are
	// serialized so mutating the map does not require extra synchronization.
	//
	// This is a callback for determinism reasons. We may be building multiple
	// entry points in parallel that are supposed to share a single cache. We
	// don't want the order that each entry point mangles properties in to cause
	// the output to change, so we serialize the property mangling over all entry
	// points in entry point order. However, we still want to link everything in
	// parallel so only property mangling is serialized, which is implemented by
	// this function blocking until the previous entry point's property mangling
	// has finished.
	ExclusiveMangleCacheUpdate func(cb func(
		mangleCache map[string]interface{},
		cssUsedLocalNames map[string]bool,
	))

	// This is the original information that was used to generate the
	// unsupported feature sets above. It's used for error messages.
	OriginalTargetEnv string

	DropLabels       []string
	ExtensionOrder   []string
	MainFields       []string
	Conditions       []string
	AbsNodePaths     []string // The "NODE_PATH" variable from Node.js
	ExternalSettings ExternalSettings
	ExternalPackages bool
	PackageAliases   map[string]string

	AbsOutputFile      string
	AbsOutputDir       string
	AbsOutputBase      string
	OutputExtensionJS  string
	OutputExtensionCSS string
	GlobalName         []string
	TSConfigPath       string
	TSConfigRaw        string
	ExtensionToLoader  map[string]Loader

	PublicPath      string
	InjectPaths     []string
	InjectedDefines []InjectedDefine
	InjectedFiles   []InjectedFile

	JSBanner  string
	JSFooter  string
	CSSBanner string
	CSSFooter string

	EntryPathTemplate []PathTemplate
	ChunkPathTemplate []PathTemplate
	AssetPathTemplate []PathTemplate

	Plugins    []Plugin
	SourceRoot string
	Stdin      *StdinInfo
	JSX        JSXOptions
	LineLimit  int

	CSSPrefixData          map[css_ast.D]compat.CSSPrefix
	UnsupportedJSFeatures  compat.JSFeature
	UnsupportedCSSFeatures compat.CSSFeature

	UnsupportedJSFeatureOverrides      compat.JSFeature
	UnsupportedJSFeatureOverridesMask  compat.JSFeature
	UnsupportedCSSFeatureOverrides     compat.CSSFeature
	UnsupportedCSSFeatureOverridesMask compat.CSSFeature

	TS                TSOptions
	Mode              Mode
	PreserveSymlinks  bool
	MinifyWhitespace  bool
	MinifyIdentifiers bool
	MinifySyntax      bool
	ProfilerNames     bool
	CodeSplitting     bool
	WatchMode         bool
	AllowOverwrite    bool
	LegalComments     LegalComments

	// If true, make sure to generate a single file that can be written to stdout
	WriteToStdout bool

	OmitRuntimeForTests    bool
	OmitJSXRuntimeForTests bool
	ASCIIOnly              bool
	KeepNames              bool
	IgnoreDCEAnnotations   bool
	TreeShaking            bool
	DropDebugger           bool
	MangleQuoted           bool
	Platform               Platform
	OutputFormat           Format
	NeedsMetafile          bool
	SourceMap              SourceMap
	ExcludeSourcesContent  bool
}

type PathPlaceholder added in v0.8.53

type PathPlaceholder uint8
const (
	NoPlaceholder PathPlaceholder = iota

	// The relative path from the original parent directory to the configured
	// "outbase" directory, or to the lowest common ancestor directory
	DirPlaceholder

	// The original name of the file, or the manual chunk name, or the name of
	// the type of output file ("entry" or "chunk" or "asset")
	NamePlaceholder

	// A hash of the contents of this file, and the contents and output paths of
	// all dependencies (except for their hash placeholders)
	HashPlaceholder

	// The original extension of the file, or the name of the output file
	// (e.g. "css", "svg", "png")
	ExtPlaceholder
)

type PathPlaceholders added in v0.8.53

type PathPlaceholders struct {
	Dir  *string
	Name *string
	Hash *string
	Ext  *string
}

func (PathPlaceholders) Get added in v0.8.53

func (placeholders PathPlaceholders) Get(placeholder PathPlaceholder) *string

type PathTemplate added in v0.8.53

type PathTemplate struct {
	Data        string
	Placeholder PathPlaceholder
}

func SubstituteTemplate added in v0.8.53

func SubstituteTemplate(template []PathTemplate, placeholders PathPlaceholders) []PathTemplate

type Platform

type Platform uint8
const (
	PlatformBrowser Platform = iota
	PlatformNode
	PlatformNeutral
)

type Plugin added in v0.8.1

type Plugin struct {
	Name      string
	OnStart   []OnStart
	OnResolve []OnResolve
	OnLoad    []OnLoad
}

type ProcessedDefines

type ProcessedDefines struct {
	IdentifierDefines map[string]DefineData
	DotDefines        map[string][]DotDefine
}

func ProcessDefines

func ProcessDefines(userDefines map[string]DefineData) ProcessedDefines

This transformation is expensive, so we only want to do it once. Make sure to only call processDefines() once per compilation. Unfortunately Golang doesn't have an efficient way to copy a map and the overhead of copying all of the properties into a new map once for every new parser noticeably slows down our benchmarks.

type SourceMap

type SourceMap uint8
const (
	SourceMapNone SourceMap = iota
	SourceMapInline
	SourceMapLinkedWithComment
	SourceMapExternalWithoutComment
	SourceMapInlineAndExternal
)

type StdinInfo

type StdinInfo struct {
	Contents      string
	SourceFile    string
	AbsResolveDir string
	Loader        Loader
}

type TSAlwaysStrict added in v0.14.44

type TSAlwaysStrict struct {
	// This information is only used for error messages
	Name   string
	Source logger.Source
	Range  logger.Range

	// This information can affect code transformation
	Value bool
}

type TSConfig added in v0.18.0

type TSConfig struct {
	ExperimentalDecorators  MaybeBool
	ImportsNotUsedAsValues  TSImportsNotUsedAsValues
	PreserveValueImports    MaybeBool
	Target                  TSTarget
	UseDefineForClassFields MaybeBool
	VerbatimModuleSyntax    MaybeBool
}

Note: This can currently only contain primitive values. It's compared for equality using a structural equality comparison by the JS parser.

func (*TSConfig) ApplyExtendedConfig added in v0.18.0

func (derived *TSConfig) ApplyExtendedConfig(base TSConfig)

This is used for "extends" in "tsconfig.json"

func (*TSConfig) UnusedImportFlags added in v0.18.0

func (cfg *TSConfig) UnusedImportFlags() (flags TSUnusedImportFlags)

type TSConfigJSX added in v0.18.0

type TSConfigJSX struct {
	// If not empty, these should override the default values
	JSXFactory         []string // Default if empty: "React.createElement"
	JSXFragmentFactory []string // Default if empty: "React.Fragment"
	JSXImportSource    *string  // Default if empty: "react"
	JSX                TSJSX
}

func (*TSConfigJSX) ApplyExtendedConfig added in v0.18.0

func (derived *TSConfigJSX) ApplyExtendedConfig(base TSConfigJSX)

This is used for "extends" in "tsconfig.json"

func (*TSConfigJSX) ApplyTo added in v0.18.0

func (tsConfig *TSConfigJSX) ApplyTo(jsxOptions *JSXOptions)

type TSImportsNotUsedAsValues added in v0.18.0

type TSImportsNotUsedAsValues uint8
const (
	TSImportsNotUsedAsValues_None TSImportsNotUsedAsValues = iota
	TSImportsNotUsedAsValues_Remove
	TSImportsNotUsedAsValues_Preserve
	TSImportsNotUsedAsValues_Error
)

type TSJSX added in v0.14.51

type TSJSX uint8
const (
	TSJSXNone TSJSX = iota
	TSJSXPreserve
	TSJSXReactNative
	TSJSXReact
	TSJSXReactJSX
	TSJSXReactJSXDev
)

type TSOptions

type TSOptions struct {
	Config              TSConfig
	Parse               bool
	NoAmbiguousLessThan bool
}

type TSTarget added in v0.12.4

type TSTarget uint8
const (
	TSTargetUnspecified     TSTarget = iota
	TSTargetBelowES2022              // "useDefineForClassFields" defaults to false
	TSTargetAtOrAboveES2022          // "useDefineForClassFields" defaults to true
)

type TSUnusedImportFlags added in v0.18.0

type TSUnusedImportFlags uint8

These flags represent the following separate "tsconfig.json" settings:

- importsNotUsedAsValues - preserveValueImports - verbatimModuleSyntax

TypeScript prefers for people to use "verbatimModuleSyntax" and has deprecated the other two settings, but we must still support them. All settings are combined into these two behavioral flags for us.

const (
	TSUnusedImport_KeepStmt   TSUnusedImportFlags = 1 << iota // "importsNotUsedAsValues" != "remove"
	TSUnusedImport_KeepValues                                 // "preserveValueImports" == true
)

With !TSUnusedImport_KeepStmt && !TSUnusedImport_KeepValues:

"import 'foo'"                      => "import 'foo'"
"import * as unused from 'foo'"     => ""
"import { unused } from 'foo'"      => ""
"import { type unused } from 'foo'" => ""

With TSUnusedImport_KeepStmt && !TSUnusedImport_KeepValues:

"import 'foo'"                      => "import 'foo'"
"import * as unused from 'foo'"     => "import 'foo'"
"import { unused } from 'foo'"      => "import 'foo'"
"import { type unused } from 'foo'" => "import 'foo'"

With !TSUnusedImport_KeepStmt && TSUnusedImport_KeepValues:

"import 'foo'"                      => "import 'foo'"
"import * as unused from 'foo'"     => "import * as unused from 'foo'"
"import { unused } from 'foo'"      => "import { unused } from 'foo'"
"import { type unused } from 'foo'" => ""

With TSUnusedImport_KeepStmt && TSUnusedImport_KeepValues:

"import 'foo'"                      => "import 'foo'"
"import * as unused from 'foo'"     => "import * as unused from 'foo'"
"import { unused } from 'foo'"      => "import { unused } from 'foo'"
"import { type unused } from 'foo'" => "import {} from 'foo'"

type WildcardPattern added in v0.8.11

type WildcardPattern struct {
	Prefix string
	Suffix string
}

Jump to

Keyboard shortcuts

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