Documentation
¶
Index ¶
- func BindingOrAssignmentElementAssignsToName(element *ast.Node, name string) bool
- func BindingOrAssignmentElementContainsNonLiteralComputedName(element *ast.Node) bool
- func ConvertBindingPatternToAssignmentPattern(emitContext *printer.EmitContext, element *ast.BindingPattern) *ast.Expression
- func ConvertVariableDeclarationToAssignmentExpression(emitContext *printer.EmitContext, element *ast.VariableDeclaration) *ast.Expression
- func ExtractModifiers(emitContext *printer.EmitContext, modifiers *ast.ModifierList, ...) *ast.ModifierList
- func FindSuperStatementIndexPath(statements []*ast.Statement, start int) []int
- func FlattenDestructuringAssignment(tx *Transformer, node *ast.Node, needsValue bool, level FlattenLevel, ...) *ast.Expression
- func FlattenDestructuringBinding(tx *Transformer, node *ast.Node, rval *ast.Node, level FlattenLevel, ...) *ast.Node
- func GetInitializerOfBindingOrAssignmentElement(bindingElement *ast.Node) *ast.Node
- func GetNonAssignmentOperatorForCompoundAssignment(kind ast.Kind) ast.Kind
- func GetSuperCallFromStatement(statement *ast.Statement) *ast.Node
- func IsExportName(emitContext *printer.EmitContext, name *ast.IdentifierNode) bool
- func IsGeneratedIdentifier(emitContext *printer.EmitContext, name *ast.IdentifierNode) bool
- func IsHelperName(emitContext *printer.EmitContext, name *ast.IdentifierNode) bool
- func IsIdentifierReference(name *ast.IdentifierNode, parent *ast.Node) bool
- func IsLocalName(emitContext *printer.EmitContext, name *ast.IdentifierNode) bool
- func IsOriginalNodeSingleLine(emitContext *printer.EmitContext, node *ast.Node) bool
- func IsSimpleCopiableExpression(expression *ast.Expression) bool
- func IsSimpleInlineableExpression(expression *ast.Expression) bool
- func MoveRangePastDecorators(node *ast.Node) core.TextRange
- func MoveRangePastModifiers(node *ast.Node) core.TextRange
- func SingleOrMany(nodes []*ast.Node, factory *printer.NodeFactory) *ast.Node
- type CreateAssignmentCallback
- type FlattenLevel
- type TransformOptions
- type Transformer
- func (tx *Transformer) EmitContext() *printer.EmitContext
- func (tx *Transformer) Factory() *printer.NodeFactory
- func (tx *Transformer) NewTransformer(visit func(node *ast.Node) *ast.Node, emitContext *printer.EmitContext) *Transformer
- func (tx *Transformer) TransformSourceFile(file *ast.SourceFile) *ast.SourceFile
- func (tx *Transformer) Visitor() *ast.NodeVisitor
- type TransformerFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindingOrAssignmentElementAssignsToName ¶
BindingOrAssignmentElementAssignsToName checks if any target in a binding/assignment pattern assigns to the given name.
func BindingOrAssignmentElementContainsNonLiteralComputedName ¶
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 ¶
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 ¶
GetInitializerOfBindingOrAssignmentElement returns the initializer/default value of a binding or assignment element.
func GetNonAssignmentOperatorForCompoundAssignment ¶
GetNonAssignmentOperatorForCompoundAssignment returns the non-assignment operator for a compound assignment.
func GetSuperCallFromStatement ¶
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 ¶
MoveRangePastDecorators returns a text range that starts past any decorators on the node.
func MoveRangePastModifiers ¶
MoveRangePastModifiers returns a text range that starts past any modifiers on the node.
func SingleOrMany ¶
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