transformers

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindingOrAssignmentElementAssignsToName

func BindingOrAssignmentElementAssignsToName(element *ast.Node, name string) bool

BindingOrAssignmentElementAssignsToName checks if any target in a binding/assignment pattern assigns to the given name.

func BindingOrAssignmentElementContainsNonLiteralComputedName

func BindingOrAssignmentElementContainsNonLiteralComputedName(element *ast.Node) bool

BindingOrAssignmentElementContainsNonLiteralComputedName checks if any element has a non-literal computed property name.

func ConvertBindingPatternToAssignmentPattern

func ConvertBindingPatternToAssignmentPattern(emitContext *printer.EmitContext, element *ast.BindingPattern) *ast.Expression

func ConvertVariableDeclarationToAssignmentExpression

func ConvertVariableDeclarationToAssignmentExpression(emitContext *printer.EmitContext, element *ast.VariableDeclaration) *ast.Expression

func ExtractModifiers

func ExtractModifiers(emitContext *printer.EmitContext, modifiers *ast.ModifierList, allowed ast.ModifierFlags) *ast.ModifierList

func FindSuperStatementIndexPath

func FindSuperStatementIndexPath(statements []*ast.Statement, start int) []int

FindSuperStatementIndexPath finds a path of indices to a statement containing a `super()` call.

func FlattenDestructuringAssignment

func FlattenDestructuringAssignment(
	tx *Transformer,
	node *ast.Node,
	needsValue bool,
	level FlattenLevel,
	createAssignmentCallback CreateAssignmentCallback,
) *ast.Expression

FlattenDestructuringAssignment flattens a destructuring assignment expression into a sequence of individual property/element access assignments. Supports custom assignment callbacks for module export or namespace member expressions.

func FlattenDestructuringBinding

func FlattenDestructuringBinding(
	tx *Transformer,
	node *ast.Node,
	rval *ast.Node,
	level FlattenLevel,
	hoistTempVariables bool,
	skipInitializer bool,
) *ast.Node

FlattenDestructuringBinding flattens a binding pattern in a variable declaration or parameter into individual variable declarations. Returns a single VariableDeclaration, a SyntaxList of declarations, or nil.

func GetInitializerOfBindingOrAssignmentElement

func GetInitializerOfBindingOrAssignmentElement(bindingElement *ast.Node) *ast.Node

GetInitializerOfBindingOrAssignmentElement returns the initializer/default value of a binding or assignment element.

func GetNonAssignmentOperatorForCompoundAssignment

func GetNonAssignmentOperatorForCompoundAssignment(kind ast.Kind) ast.Kind

GetNonAssignmentOperatorForCompoundAssignment returns the non-assignment operator for a compound assignment.

func GetSuperCallFromStatement

func GetSuperCallFromStatement(statement *ast.Statement) *ast.Node

GetSuperCallFromStatement extracts the super() call expression from an expression statement, if any.

func IsExportName

func IsExportName(emitContext *printer.EmitContext, name *ast.IdentifierNode) bool

func IsGeneratedIdentifier

func IsGeneratedIdentifier(emitContext *printer.EmitContext, name *ast.IdentifierNode) bool

func IsHelperName

func IsHelperName(emitContext *printer.EmitContext, name *ast.IdentifierNode) bool

func IsIdentifierReference

func IsIdentifierReference(name *ast.IdentifierNode, parent *ast.Node) bool

func IsLocalName

func IsLocalName(emitContext *printer.EmitContext, name *ast.IdentifierNode) bool

func IsOriginalNodeSingleLine

func IsOriginalNodeSingleLine(emitContext *printer.EmitContext, node *ast.Node) bool

func IsSimpleCopiableExpression

func IsSimpleCopiableExpression(expression *ast.Expression) bool

Used in the module transformer to check if an expression is reasonably without sideeffect,

and thus better to copy into multiple places rather than to cache in a temporary variable
- this is mostly subjective beyond the requirement that the expression not be sideeffecting

Also used by the logical assignment downleveling transform to skip temp variables when they're not needed.

func IsSimpleInlineableExpression

func IsSimpleInlineableExpression(expression *ast.Expression) bool

*

  • A simple inlinable expression is an expression which can be copied into multiple locations
  • without risk of repeating any sideeffects and whose value could not possibly change between
  • any such locations

func MoveRangePastDecorators

func MoveRangePastDecorators(node *ast.Node) core.TextRange

MoveRangePastDecorators returns a text range that starts past any decorators on the node.

func MoveRangePastModifiers

func MoveRangePastModifiers(node *ast.Node) core.TextRange

MoveRangePastModifiers returns a text range that starts past any modifiers on the node.

func SingleOrMany

func SingleOrMany(nodes []*ast.Node, factory *printer.NodeFactory) *ast.Node

Types

type CreateAssignmentCallback

type CreateAssignmentCallback func(name *ast.IdentifierNode, value *ast.Expression, location *core.TextRange) *ast.Expression

CreateAssignmentCallback is a callback used to create custom assignment expressions during destructuring flattening. When provided, the target will always be an Identifier, and the callback can wrap the assignment with additional logic (e.g., export expressions in CJS modules or namespace member assignments).

type FlattenLevel

type FlattenLevel int

FlattenLevel controls how deeply binding/assignment patterns are decomposed.

const (
	FlattenLevelAll        FlattenLevel = iota // Fully decompose all patterns into individual assignments/bindings
	FlattenLevelObjectRest                     // Only decompose patterns containing object rest elements
)

type TransformOptions

type TransformOptions struct {
	Context                   *printer.EmitContext
	CompilerOptions           *core.CompilerOptions
	Resolver                  binder.ReferenceResolver
	EmitResolver              printer.EmitResolver
	GetEmitModuleFormatOfFile func(file ast.HasFileName) core.ModuleKind
}

type Transformer

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

func (*Transformer) EmitContext

func (tx *Transformer) EmitContext() *printer.EmitContext

func (*Transformer) Factory

func (tx *Transformer) Factory() *printer.NodeFactory

func (*Transformer) NewTransformer

func (tx *Transformer) NewTransformer(visit func(node *ast.Node) *ast.Node, emitContext *printer.EmitContext) *Transformer

func (*Transformer) TransformSourceFile

func (tx *Transformer) TransformSourceFile(file *ast.SourceFile) *ast.SourceFile

func (*Transformer) Visitor

func (tx *Transformer) Visitor() *ast.NodeVisitor

type TransformerFactory

type TransformerFactory = func(opt *TransformOptions) *Transformer

func Chain

func Chain(transforms ...TransformerFactory) TransformerFactory

Chains transforms in left-to-right order, running them one at a time in order (as opposed to interleaved at each node) - the resulting combined transform only operates on SourceFile nodes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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