package parser

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

Index

Constants

const (
	// These are arranged such that ESNext is the default zero value and such
	// that earlier releases are less than later releases
	ES2015 = -6
	ES2016 = -5
	ES2017 = -4
	ES2018 = -3
	ES2019 = -2
	ES2020 = -1
	ESNext = 0
)

Functions

func ModuleExportsAST

func ModuleExportsAST(log logging.Log, source logging.Source, options ParseOptions, expr ast.Expr) ast.AST

func Parse

func Parse(log logging.Log, source logging.Source, options ParseOptions) (result ast.AST, ok bool)

func ParseJSON

func ParseJSON(log logging.Log, source logging.Source, options ParseJSONOptions) (result ast.Expr, ok bool)

Types

type DefineFunc

type DefineFunc func(FindSymbol) ast.E

type DotDefine

type DotDefine struct {
	Parts      []string
	DefineFunc DefineFunc

	// This is used to whitelist certain functions that are known to be safe to
	// remove if their result is unused
	CanBeRemovedIfUnused bool
}

type FindSymbol

type FindSymbol func(name string) ast.Ref

type JSXOptions

type JSXOptions struct {
	Parse    bool
	Factory  []string
	Fragment []string
}

type LanguageTarget

type LanguageTarget int8

type ParseJSONOptions

type ParseJSONOptions struct {
	AllowComments       bool
	AllowTrailingCommas bool
}

type ParseOptions

type ParseOptions struct {
	// true: imports are scanned and bundled along with the file
	// false: imports are left alone and the file is passed through as-is
	IsBundling bool

	MangleSyntax bool
	Strict       StrictOptions
	Defines      *ProcessedDefines
	TS           TypeScriptOptions
	JSX          JSXOptions
	Target       LanguageTarget
	Platform     Platform
}

type Platform

type Platform uint8
const (
	PlatformBrowser Platform = iota
	PlatformNode
)

type ProcessedDefines

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

func ProcessDefines

func ProcessDefines(userDefines map[string]DefineFunc) 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 StrictOptions

type StrictOptions struct {
	// Loose:  "a ?? b" => "a != null ? a : b"
	// Strict: "a ?? b" => "a !== null && a !== void 0 ? a : b"
	//
	// The disadvantage of strictness here is code bloat. The only observable
	// difference between the two is when the left operand is the bizarre legacy
	// value "document.all". This value is special-cased in the standard for
	// legacy reasons such that "document.all != null" is false even though it's
	// not "null" or "undefined".
	NullishCoalescing bool

	// Loose:  "class Foo { foo = 1 }" => "class Foo { constructor() { this.foo = 1; } }"
	// Strict: "class Foo { foo = 1 }" => "class Foo { constructor() { __publicField(this, 'foo', 1); } }"
	//
	// The disadvantage of strictness here is code bloat and performance. The
	// advantage is following the class field specification accurately. For
	// example, loose mode will incorrectly trigger setter methods while strict
	// mode won't.
	ClassFields bool
}

type TypeScriptOptions

type TypeScriptOptions struct {
	Parse bool
}

Source Files

globals.go parser.go parser_json.go parser_lower.go

Version
v0.5.11
Published
Jun 23, 2020
Platform
windows/amd64
Imports
9 packages
Last checked
2 minutes ago

Tools for package owners.