printer

package
v0.0.0-...-563c3ff Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package printer exports a Printer for pretty-printing TS ASTs and writer interfaces and implementations for using them Intended ultimate usage:

func nodeToInlineStr(node *ast.Node) {
	// Reuse singleton single-line writer (TODO: thread safety?)
	p = printer.NewPrinter(printer.PrinterOptions{ RemoveComments: true }, printer.PrintHandlers{})
	p.Write(node, nil /*sourceFile*/, printer.SingleLineTextWriter)
	return printer.SingleLineTextWriter.getText()
}

// or

func nodeToStr(node *ast.Node, options CompilerOptions) {
	// Use own writer
	p := printer.NewPrinter(printer.PrinterOptions{ NewLine: options.NewLine}, printer.PrintHandlers{})
	return p.Emit(node, nil /*sourceFile*/)
}

Index

Constants

View Source
const (
	EFNone              EmitFlags = 0
	EFNoSourceMap                 = EFNoLeadingSourceMap | EFNoTrailingSourceMap             // Do not emit a source map location for this node.
	EFNoTokenSourceMaps           = EFNoTokenLeadingSourceMaps | EFNoTokenTrailingSourceMaps // Do not emit source map locations for tokens of this node.
	EFNoComments                  = EFNoLeadingComments | EFNoTrailingComments               // Do not emit comments for this node.
)
View Source
const (
	GeneratedIdentifierFlagsNone     = iota // Not automatically generated.
	GeneratedIdentifierFlagsAuto            // Automatically generated identifier.
	GeneratedIdentifierFlagsLoop            // Automatically generated identifier with a preference for '_i'.
	GeneratedIdentifierFlagsUnique          // Unique name based on the 'text' property.
	GeneratedIdentifierFlagsNode            // Unique name based on the node in the 'Node' property.
	GeneratedIdentifierFlagsKindMask = 7    // Mask to extract the kind of identifier from its flags.

	GeneratedIdentifierFlagsReservedInNestedScopes = 1 << 3 // Reserve the generated name in nested scopes
	GeneratedIdentifierFlagsOptimistic             = 1 << 4 // First instance won't use '_#' if there's no conflict
	GeneratedIdentifierFlagsFileLevel              = 1 << 5 // Use only the file identifiers list and not generated names to search for conflicts
	GeneratedIdentifierFlagsAllowNameSubstitution  = 1 << 6 // Used by `module.ts` to indicate generated nodes which can have substitutions performed upon them (as they were generated by an earlier transform phase)
)

Variables

This section is empty.

Functions

func EscapeString

func EscapeString(s string, quoteChar QuoteChar) string

func FormatGeneratedName

func FormatGeneratedName(privateName bool, prefix string, base string, suffix string) string

func GetLinesBetweenPositions

func GetLinesBetweenPositions(sourceFile *ast.SourceFile, pos1 int, pos2 int) int

func IsFileLevelUniqueName

func IsFileLevelUniqueName(sourceFile *ast.SourceFile, name string, hasGlobalName func(string) bool) bool

func IsPinnedComment

func IsPinnedComment(text string, comment ast.CommentRange) bool

func IsRecognizedTripleSlashComment

func IsRecognizedTripleSlashComment(text string, commentRange ast.CommentRange) bool

/// <reference path="..." /> /// <reference types="..." /> /// <reference lib="..." /> /// <reference no-default-lib="..." /> /// <amd-dependency path="..." /> /// <amd-module />

Types

type AssignedNameOptions

type AssignedNameOptions struct {
	AllowComments      bool // indicates whether comments may be emitted for the name.
	AllowSourceMaps    bool // indicates whether source maps may be emitted for the name.
	IgnoreAssignedName bool // indicates whether the assigned name of a declaration shouldn't be considered.
}

type AutoGenerateId

type AutoGenerateId uint32

type AutoGenerateInfo

type AutoGenerateInfo struct {
	Flags  GeneratedIdentifierFlags // Specifies whether to auto-generate the text for an identifier.
	Id     AutoGenerateId           // Ensures unique generated identifiers get unique names, but clones get the same name.
	Prefix string                   // Optional prefix to apply to the start of the generated name
	Suffix string                   // Optional suffix to apply to the end of the generated name
	Node   *ast.Node                // For a GeneratedIdentifierFlagsNode, the node from which to generate an identifier
}

type AutoGenerateOptions

type AutoGenerateOptions struct {
	Flags  GeneratedIdentifierFlags
	Prefix string
	Suffix string
}

type ChangeTrackerWriter

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

func NewChangeTrackerWriter

func NewChangeTrackerWriter(newline string) *ChangeTrackerWriter

func (*ChangeTrackerWriter) AssignPositionsToNode

func (ct *ChangeTrackerWriter) AssignPositionsToNode(node *ast.Node, factory *ast.NodeFactory) *ast.Node

func (*ChangeTrackerWriter) Clear

func (ct *ChangeTrackerWriter) Clear()

func (*ChangeTrackerWriter) DecreaseIndent

func (ct *ChangeTrackerWriter) DecreaseIndent()

func (*ChangeTrackerWriter) GetColumn

func (ct *ChangeTrackerWriter) GetColumn() int

func (*ChangeTrackerWriter) GetIndent

func (ct *ChangeTrackerWriter) GetIndent() int

func (*ChangeTrackerWriter) GetLine

func (ct *ChangeTrackerWriter) GetLine() int

func (*ChangeTrackerWriter) GetPrintHandlers

func (ct *ChangeTrackerWriter) GetPrintHandlers() PrintHandlers

func (*ChangeTrackerWriter) GetTextPos

func (ct *ChangeTrackerWriter) GetTextPos() int

func (*ChangeTrackerWriter) HasTrailingComment

func (ct *ChangeTrackerWriter) HasTrailingComment() bool

func (*ChangeTrackerWriter) HasTrailingWhitespace

func (ct *ChangeTrackerWriter) HasTrailingWhitespace() bool

func (*ChangeTrackerWriter) IncreaseIndent

func (ct *ChangeTrackerWriter) IncreaseIndent()

func (*ChangeTrackerWriter) IsAtStartOfLine

func (ct *ChangeTrackerWriter) IsAtStartOfLine() bool

func (*ChangeTrackerWriter) RawWrite

func (ct *ChangeTrackerWriter) RawWrite(s string)

func (*ChangeTrackerWriter) String

func (ct *ChangeTrackerWriter) String() string

func (*ChangeTrackerWriter) Write

func (ct *ChangeTrackerWriter) Write(text string)

func (*ChangeTrackerWriter) WriteComment

func (ct *ChangeTrackerWriter) WriteComment(text string)

func (*ChangeTrackerWriter) WriteKeyword

func (ct *ChangeTrackerWriter) WriteKeyword(text string)

func (*ChangeTrackerWriter) WriteLine

func (ct *ChangeTrackerWriter) WriteLine()

func (*ChangeTrackerWriter) WriteLineForce

func (ct *ChangeTrackerWriter) WriteLineForce(force bool)

func (*ChangeTrackerWriter) WriteLiteral

func (ct *ChangeTrackerWriter) WriteLiteral(s string)

func (*ChangeTrackerWriter) WriteOperator

func (ct *ChangeTrackerWriter) WriteOperator(text string)

func (*ChangeTrackerWriter) WriteParameter

func (ct *ChangeTrackerWriter) WriteParameter(text string)

func (*ChangeTrackerWriter) WriteProperty

func (ct *ChangeTrackerWriter) WriteProperty(text string)

func (*ChangeTrackerWriter) WritePunctuation

func (ct *ChangeTrackerWriter) WritePunctuation(text string)

func (*ChangeTrackerWriter) WriteSpace

func (ct *ChangeTrackerWriter) WriteSpace(text string)

func (*ChangeTrackerWriter) WriteStringLiteral

func (ct *ChangeTrackerWriter) WriteStringLiteral(text string)

func (*ChangeTrackerWriter) WriteSymbol

func (ct *ChangeTrackerWriter) WriteSymbol(text string, symbol *ast.Symbol)

func (*ChangeTrackerWriter) WriteTrailingSemicolon

func (ct *ChangeTrackerWriter) WriteTrailingSemicolon(text string)

type EmitContext

type EmitContext struct {
	Factory *NodeFactory // Required. The NodeFactory to use to create new nodes
	// contains filtered or unexported fields
}

Stores side-table information used during transformation that can be read by the printer to customize emit

NOTE: EmitContext is not guaranteed to be thread-safe.

func GetEmitContext

func GetEmitContext() (*EmitContext, func())

func NewEmitContext

func NewEmitContext() *EmitContext

func (*EmitContext) AddEmitFlags

func (c *EmitContext) AddEmitFlags(node *ast.Node, flags EmitFlags)

func (*EmitContext) AddEmitHelper

func (c *EmitContext) AddEmitHelper(node *ast.Node, helper ...*EmitHelper)

func (*EmitContext) AddHoistedFunctionDeclaration

func (c *EmitContext) AddHoistedFunctionDeclaration(node *ast.FunctionDeclarationNode)

Adds a hoisted function declaration to the current VariableEnvironment

NOTE: This is the equivalent of `transformContext.hoistFunctionDeclaration` in Strada.

func (*EmitContext) AddInitializationStatement

func (c *EmitContext) AddInitializationStatement(node *ast.Node)

func (*EmitContext) AddLexicalDeclaration

func (c *EmitContext) AddLexicalDeclaration(name *ast.IdentifierNode)

Adds a `let` declaration to the current LexicalEnvironment.

func (*EmitContext) AddSyntheticLeadingComment

func (c *EmitContext) AddSyntheticLeadingComment(node *ast.Node, kind ast.Kind, text string, hasTrailingNewLine bool) *ast.Node

func (*EmitContext) AddSyntheticTrailingComment

func (c *EmitContext) AddSyntheticTrailingComment(node *ast.Node, kind ast.Kind, text string, hasTrailingNewLine bool) *ast.Node

func (*EmitContext) AddVariableDeclaration

func (c *EmitContext) AddVariableDeclaration(name *ast.IdentifierNode)

Adds a `var` declaration to the current VariableEnvironment

NOTE: This is the equivalent of `transformContext.hoistVariableDeclaration` in Strada.

func (*EmitContext) AssignCommentAndSourceMapRanges

func (c *EmitContext) AssignCommentAndSourceMapRanges(to *ast.Node, from *ast.Node)

Sets the range to use for a node when emitting comments and source maps.

func (*EmitContext) AssignCommentRange

func (c *EmitContext) AssignCommentRange(to *ast.Node, from *ast.Node)

Sets the range to use for a node when emitting comments.

func (*EmitContext) AssignSourceMapRange

func (c *EmitContext) AssignSourceMapRange(to *ast.Node, from *ast.Node)

Sets the range to use for a node when emitting source maps.

func (*EmitContext) AssignedName

func (c *EmitContext) AssignedName(node *ast.Node) *ast.Expression

func (*EmitContext) ClassThis

func (c *EmitContext) ClassThis(node *ast.Node) *ast.Expression

func (*EmitContext) CommentRange

func (c *EmitContext) CommentRange(node *ast.Node) core.TextRange

Gets the range to use for a node when emitting comments.

func (*EmitContext) EmitFlags

func (c *EmitContext) EmitFlags(node *ast.Node) EmitFlags

func (*EmitContext) EndAndMergeLexicalEnvironment

func (c *EmitContext) EndAndMergeLexicalEnvironment(statements []*ast.Statement) []*ast.Statement

Invokes c.EndLexicalEnvironment() and merges the results into `statements`

func (*EmitContext) EndAndMergeLexicalEnvironmentList

func (c *EmitContext) EndAndMergeLexicalEnvironmentList(statements *ast.StatementList) *ast.StatementList

Invokes c.EndLexicalEnvironment() and merges the results into `statements`

func (*EmitContext) EndAndMergeVariableEnvironment

func (c *EmitContext) EndAndMergeVariableEnvironment(statements []*ast.Statement) []*ast.Statement

Invokes c.EndVariableEnvironment() and merges the results into `statements`

func (*EmitContext) EndAndMergeVariableEnvironmentList

func (c *EmitContext) EndAndMergeVariableEnvironmentList(statements *ast.StatementList) *ast.StatementList

Invokes c.EndVariableEnvironment() and merges the results into `statements`

func (*EmitContext) EndLexicalEnvironment

func (c *EmitContext) EndLexicalEnvironment() []*ast.Statement

Ends the current EndLexicalEnvironment, returning a list of statements that should be emitted at the start of the current scope.

NOTE: This is the equivalent of `transformContext.endLexicalEnvironment` in Strada. NOTE: This is *not* the same as `endLexicalEnvironment` in Strada as that method is incorrectly named.

func (*EmitContext) EndVariableEnvironment

func (c *EmitContext) EndVariableEnvironment() []*ast.Statement

Ends the current VariableEnvironment, returning a list of statements that should be emitted at the start of the current scope.

NOTE: This is the equivalent of `transformContext.endLexicalEnvironment` in Strada.

func (*EmitContext) GetAutoGenerateInfo

func (c *EmitContext) GetAutoGenerateInfo(name *ast.MemberName) *AutoGenerateInfo

Gets the associated AutoGenerateInfo entry for a given name.

func (*EmitContext) GetEmitHelpers

func (c *EmitContext) GetEmitHelpers(node *ast.Node) []*EmitHelper

func (*EmitContext) GetExternalHelpersModuleName

func (c *EmitContext) GetExternalHelpersModuleName(node *ast.SourceFile) *ast.IdentifierNode

func (*EmitContext) GetNodeForGeneratedName

func (c *EmitContext) GetNodeForGeneratedName(name *ast.MemberName) *ast.Node

Walks the associated AutoGenerateInfo entries of a name to find the root Nopde from which the name should be generated.

func (*EmitContext) GetSyntheticLeadingComments

func (c *EmitContext) GetSyntheticLeadingComments(node *ast.Node) []SynthesizedComment

func (*EmitContext) GetSyntheticTrailingComments

func (c *EmitContext) GetSyntheticTrailingComments(node *ast.Node) []SynthesizedComment

func (*EmitContext) HasAutoGenerateInfo

func (c *EmitContext) HasAutoGenerateInfo(node *ast.MemberName) bool

Gets whether a given name has an associated AutoGenerateInfo entry.

func (*EmitContext) HasRecordedExternalHelpers

func (c *EmitContext) HasRecordedExternalHelpers(node *ast.SourceFile) bool

func (*EmitContext) IsCallToHelper

func (c *EmitContext) IsCallToHelper(firstSegment *ast.Expression, helperName string) bool

func (*EmitContext) MergeEnvironment

func (c *EmitContext) MergeEnvironment(statements []*ast.Statement, declarations []*ast.Statement) []*ast.Statement

Merges declarations produced by c.EndVariableEnvironment() or c.EndLexicalEnvironment() into a slice of statements

func (*EmitContext) MergeEnvironmentList

func (c *EmitContext) MergeEnvironmentList(statements *ast.StatementList, declarations []*ast.Statement) *ast.StatementList

Merges declarations produced by c.EndVariableEnvironment() or c.EndLexicalEnvironment() into a statement list

func (*EmitContext) MostOriginal

func (c *EmitContext) MostOriginal(node *ast.Node) *ast.Node

Gets the most original node associated with this node by walking Original pointers.

NOTE: This method is analogous to `getOriginalNode` in the old compiler, but the name has changed to avoid accidental conflation with `SetOriginal`/`Original`

func (*EmitContext) MoveEmitHelpers

func (c *EmitContext) MoveEmitHelpers(source *ast.Node, target *ast.Node, predicate func(helper *EmitHelper) bool)

func (*EmitContext) NewNodeVisitor

func (c *EmitContext) NewNodeVisitor(visit func(node *ast.Node) *ast.Node) *ast.NodeVisitor

Creates a new NodeVisitor attached to this EmitContext

func (*EmitContext) NewNotEmittedStatement

func (c *EmitContext) NewNotEmittedStatement(node *ast.Node) *ast.Statement

func (*EmitContext) Original

func (c *EmitContext) Original(node *ast.Node) *ast.Node

Gets the original node for a given node.

NOTE: This is the equivalent to reading `node.original` in Strada.

func (*EmitContext) ParseNode

func (c *EmitContext) ParseNode(node *ast.Node) *ast.Node

Gets the original parse tree node for a given node.

NOTE: This is the equivalent to `getParseTreeNode` in Strada.

func (*EmitContext) ReadEmitHelpers

func (c *EmitContext) ReadEmitHelpers() []*EmitHelper

func (*EmitContext) RequestEmitHelper

func (c *EmitContext) RequestEmitHelper(helper *EmitHelper)

func (*EmitContext) Reset

func (c *EmitContext) Reset()

func (*EmitContext) SetAssignedName

func (c *EmitContext) SetAssignedName(node *ast.Node, name *ast.Expression)

func (*EmitContext) SetClassThis

func (c *EmitContext) SetClassThis(node *ast.Node, classThis *ast.IdentifierNode)

func (*EmitContext) SetCommentRange

func (c *EmitContext) SetCommentRange(node *ast.Node, loc core.TextRange)

Sets the range to use for a node when emitting comments.

func (*EmitContext) SetEmitFlags

func (c *EmitContext) SetEmitFlags(node *ast.Node, flags EmitFlags)

func (*EmitContext) SetExternalHelpersModuleName

func (c *EmitContext) SetExternalHelpersModuleName(node *ast.SourceFile, name *ast.IdentifierNode)

func (*EmitContext) SetOriginal

func (c *EmitContext) SetOriginal(node *ast.Node, original *ast.Node)

Sets the original node for a given node.

NOTE: This is the equivalent to `setOriginalNode` in Strada.

func (*EmitContext) SetOriginalEx

func (c *EmitContext) SetOriginalEx(node *ast.Node, original *ast.Node, allowOverwrite bool)

func (*EmitContext) SetSourceMapRange

func (c *EmitContext) SetSourceMapRange(node *ast.Node, loc core.TextRange)

Sets the range to use for a node when emitting source maps.

func (*EmitContext) SetSyntheticLeadingComments

func (c *EmitContext) SetSyntheticLeadingComments(node *ast.Node, comments []SynthesizedComment) *ast.Node

func (*EmitContext) SetSyntheticTrailingComments

func (c *EmitContext) SetSyntheticTrailingComments(node *ast.Node, comments []SynthesizedComment) *ast.Node

func (*EmitContext) SetTokenSourceMapRange

func (c *EmitContext) SetTokenSourceMapRange(node *ast.Node, kind ast.Kind, loc core.TextRange)

Sets the range for a token of a node when emitting source maps.

func (*EmitContext) SourceMapRange

func (c *EmitContext) SourceMapRange(node *ast.Node) core.TextRange

Gets the range to use for a node when emitting source maps.

func (*EmitContext) StartLexicalEnvironment

func (c *EmitContext) StartLexicalEnvironment()

Starts a new LexicalEnvironment used to track block-scoped `let`, `const`, and `using` declarations.

see: https://tc39.es/ecma262/#table-additional-state-components-for-ecmascript-code-execution-contexts

NOTE: This is the equivalent of `transformContext.startBlockScope` in Strada. NOTE: This is *not* the same as `startLexicalEnvironment` in Strada as that method is incorrectly named.

func (*EmitContext) StartVariableEnvironment

func (c *EmitContext) StartVariableEnvironment()

Starts a new VariableEnvironment used to track hoisted `var` statements and function declarations.

see: https://tc39.es/ecma262/#table-additional-state-components-for-ecmascript-code-execution-contexts

NOTE: This is the equivalent of `transformContext.startLexicalEnvironment` in Strada.

func (*EmitContext) TokenSourceMapRange

func (c *EmitContext) TokenSourceMapRange(node *ast.Node, kind ast.Kind) (core.TextRange, bool)

Gets the range for a token of a node when emitting source maps.

func (*EmitContext) VisitEmbeddedStatement

func (c *EmitContext) VisitEmbeddedStatement(node *ast.Statement, visitor *ast.NodeVisitor) *ast.Statement

func (*EmitContext) VisitFunctionBody

func (c *EmitContext) VisitFunctionBody(node *ast.BlockOrExpression, visitor *ast.NodeVisitor) *ast.BlockOrExpression

func (*EmitContext) VisitIterationBody

func (c *EmitContext) VisitIterationBody(body *ast.Statement, visitor *ast.NodeVisitor) *ast.Statement

func (*EmitContext) VisitParameters

func (c *EmitContext) VisitParameters(nodes *ast.ParameterList, visitor *ast.NodeVisitor) *ast.ParameterList

func (*EmitContext) VisitVariableEnvironment

func (c *EmitContext) VisitVariableEnvironment(nodes *ast.StatementList, visitor *ast.NodeVisitor) *ast.StatementList

type EmitFlags

type EmitFlags uint32
const (
	EFSingleLine                EmitFlags = 1 << iota // The contents of this node should be emitted on a single line.
	EFMultiLine                                       // The contents of this node should be emitted on multiple lines.
	EFNoLeadingSourceMap                              // Do not emit a leading source map location for this node.
	EFNoTrailingSourceMap                             // Do not emit a trailing source map location for this node.
	EFNoNestedSourceMaps                              // Do not emit source map locations for children of this node.
	EFNoTokenLeadingSourceMaps                        // Do not emit leading source map location for token nodes.
	EFNoTokenTrailingSourceMaps                       // Do not emit trailing source map location for token nodes.
	EFNoLeadingComments                               // Do not emit leading comments for this node.
	EFNoTrailingComments                              // Do not emit trailing comments for this node.
	EFNoNestedComments                                // Do not emit nested comments for children of this node.
	EFHelperName                                      // The Identifier refers to an *unscoped* emit helper (one that is emitted at the top of the file)
	EFExportName                                      // Ensure an export prefix is added for an identifier that points to an exported declaration with a local name (see SymbolFlags.ExportHasLocal).
	EFLocalName                                       // Ensure an export prefix is not added for an identifier that points to an exported declaration.
	EFInternalName                                    // The name is internal to an ES5 class body function.
	EFIndented                                        // Adds an explicit extra indentation level for class and function bodies when printing (used to match old emitter).
	EFNoIndentation                                   // Do not indent the node.
	EFReuseTempVariableScope                          // Reuse the existing temp variable scope during emit.
	EFCustomPrologue                                  // Treat the statement as if it were a prologue directive (NOTE: Prologue directives are *not* transformed).
	EFNoHoisting                                      // Do not hoist this declaration in --module system
	EFNoAsciiEscaping                                 // When synthesizing nodes that lack an original node or textSourceNode, we want to write the text on the node with ASCII escaping substitutions.
	EFExternalHelpers                                 // This source file has external helpers
	EFNeverApplyImportHelper                          // Do not apply an import helper to this node
	EFStartOnNewLine                                  // Start this node on a new line
	EFIndirectCall                                    // Emit CallExpression as an indirect call: `(0, f)()`
)

type EmitHelper

type EmitHelper struct {
	Name         string                                          // A unique name for this helper.
	Scoped       bool                                            // Indicates whether the helper MUST be emitted in the current scope.
	Text         string                                          // ES3-compatible raw script text
	TextCallback func(makeUniqueName func(string) string) string // A function yielding an ES3-compatible raw script text.
	Priority     *Priority                                       // Helpers with a higher priority are emitted earlier than other helpers on the node.
	Dependencies []*EmitHelper                                   // Emit helpers this helper depends on
	ImportName   string                                          // The name of the helper to use when importing via `--importHelpers`.
}

type EmitHost

type EmitHost interface {
	Options() *core.CompilerOptions
	SourceFiles() []*ast.SourceFile
	UseCaseSensitiveFileNames() bool
	GetCurrentDirectory() string
	CommonSourceDirectory() string
	IsEmitBlocked(file string) bool
	WriteFile(fileName string, text string, writeByteOrderMark bool) error
	GetEmitModuleFormatOfFile(file ast.HasFileName) core.ModuleKind
	GetEmitResolver() EmitResolver
	GetProjectReferenceFromSource(path tspath.Path) *tsoptions.SourceOutputAndProjectReference
	IsSourceFileFromExternalLibrary(file *ast.SourceFile) bool
}

NOTE: EmitHost operations must be thread-safe

type EmitResolver

type EmitResolver interface {
	binder.ReferenceResolver
	IsReferencedAliasDeclaration(node *ast.Node) bool
	IsValueAliasDeclaration(node *ast.Node) bool
	IsTopLevelValueImportEqualsWithEntityName(node *ast.Node) bool
	MarkLinkedReferencesRecursively(file *ast.SourceFile)
	GetExternalModuleFileFromDeclaration(node *ast.Node) *ast.SourceFile
	GetEffectiveDeclarationFlags(node *ast.Node, flags ast.ModifierFlags) ast.ModifierFlags
	GetResolutionModeOverride(node *ast.Node) core.ResolutionMode

	// const enum inlining
	GetConstantValue(node *ast.Node) any

	// JSX Emit
	GetJsxFactoryEntity(location *ast.Node) *ast.Node
	GetJsxFragmentFactoryEntity(location *ast.Node) *ast.Node
	SetReferencedImportDeclaration(node *ast.IdentifierNode, ref *ast.Declaration) // for overriding the reference resolver behavior for generated identifiers

	// declaration emit checker functionality projections
	PrecalculateDeclarationEmitVisibility(file *ast.SourceFile)
	IsSymbolAccessible(symbol *ast.Symbol, enclosingDeclaration *ast.Node, meaning ast.SymbolFlags, shouldComputeAliasToMarkVisible bool) SymbolAccessibilityResult
	IsEntityNameVisible(entityName *ast.Node, enclosingDeclaration *ast.Node) SymbolAccessibilityResult // previously SymbolVisibilityResult in strada - ErrorModuleName never set
	IsExpandoFunctionDeclaration(node *ast.Node) bool
	IsLiteralConstDeclaration(node *ast.Node) bool
	RequiresAddingImplicitUndefined(node *ast.Node, symbol *ast.Symbol, enclosingDeclaration *ast.Node) bool
	IsDeclarationVisible(node *ast.Node) bool
	IsImportRequiredByAugmentation(decl *ast.ImportDeclaration) bool
	IsDefinitelyReferenceToGlobalSymbolObject(node *ast.Node) bool
	IsImplementationOfOverload(node *ast.SignatureDeclaration) bool
	GetEnumMemberValue(node *ast.Node) evaluator.Result
	IsLateBound(node *ast.Node) bool
	IsOptionalParameter(node *ast.Node) bool

	// Node construction for declaration emit
	CreateTypeOfDeclaration(emitContext *EmitContext, declaration *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) *ast.Node
	CreateReturnTypeOfSignatureDeclaration(emitContext *EmitContext, signatureDeclaration *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) *ast.Node
	CreateTypeParametersOfSignatureDeclaration(emitContext *EmitContext, signatureDeclaration *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) []*ast.Node
	CreateLiteralConstValue(emitContext *EmitContext, node *ast.Node, tracker nodebuilder.SymbolTracker) *ast.Node
	CreateTypeOfExpression(emitContext *EmitContext, expression *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) *ast.Node
	CreateLateBoundIndexSignatures(emitContext *EmitContext, container *ast.Node, enclosingDeclaration *ast.Node, flags nodebuilder.Flags, internalFlags nodebuilder.InternalFlags, tracker nodebuilder.SymbolTracker) []*ast.Node
}

type EmitTextWriter

type EmitTextWriter interface {
	Write(s string)
	WriteTrailingSemicolon(text string)
	WriteComment(text string)
	WriteKeyword(text string)
	WriteOperator(text string)
	WritePunctuation(text string)
	WriteSpace(text string)
	WriteStringLiteral(text string)
	WriteParameter(text string)
	WriteProperty(text string)
	WriteSymbol(text string, symbol *ast.Symbol)
	WriteLine()
	WriteLineForce(force bool)
	IncreaseIndent()
	DecreaseIndent()
	Clear()
	String() string
	RawWrite(s string)
	WriteLiteral(s string)
	GetTextPos() int
	GetLine() int
	GetColumn() int
	GetIndent() int
	IsAtStartOfLine() bool
	HasTrailingComment() bool
	HasTrailingWhitespace() bool
}

Externally opaque interface for printing text

func GetSingleLineStringWriter

func GetSingleLineStringWriter() (EmitTextWriter, func())

func NewTextWriter

func NewTextWriter(newLine string) EmitTextWriter

type GeneratedIdentifierFlags

type GeneratedIdentifierFlags int

func (GeneratedIdentifierFlags) HasAllowNameSubstitution

func (f GeneratedIdentifierFlags) HasAllowNameSubstitution() bool

func (GeneratedIdentifierFlags) IsAuto

func (f GeneratedIdentifierFlags) IsAuto() bool

func (GeneratedIdentifierFlags) IsFileLevel

func (f GeneratedIdentifierFlags) IsFileLevel() bool

func (GeneratedIdentifierFlags) IsLoop

func (f GeneratedIdentifierFlags) IsLoop() bool

func (GeneratedIdentifierFlags) IsNode

func (f GeneratedIdentifierFlags) IsNode() bool

func (GeneratedIdentifierFlags) IsOptimistic

func (f GeneratedIdentifierFlags) IsOptimistic() bool

func (GeneratedIdentifierFlags) IsReservedInNestedScopes

func (f GeneratedIdentifierFlags) IsReservedInNestedScopes() bool

func (GeneratedIdentifierFlags) IsUnique

func (f GeneratedIdentifierFlags) IsUnique() bool

func (GeneratedIdentifierFlags) Kind

type ListFormat

type ListFormat int
const (
	LFNone ListFormat = 0

	// Line separators
	LFSingleLine    ListFormat = 0      // Prints the list on a single line (default).
	LFMultiLine     ListFormat = 1 << 0 // Prints the list on multiple lines.
	LFPreserveLines ListFormat = 1 << 1 // Prints the list using line preservation if possible.
	LFLinesMask     ListFormat = LFSingleLine | LFMultiLine | LFPreserveLines

	// Delimiters
	LFNotDelimited       ListFormat = 0      // There is no delimiter between list items (default).
	LFBarDelimited       ListFormat = 1 << 2 // Each list item is space-and-bar (" |") delimited.
	LFAmpersandDelimited ListFormat = 1 << 3 // Each list item is space-and-ampersand (" &") delimited.
	LFCommaDelimited     ListFormat = 1 << 4 // Each list item is comma (",") delimited.
	LFAsteriskDelimited  ListFormat = 1 << 5 // Each list item is asterisk ("\n *") delimited, used with JSDoc.
	LFDelimitersMask     ListFormat = LFBarDelimited | LFAmpersandDelimited | LFCommaDelimited | LFAsteriskDelimited

	LFAllowTrailingComma ListFormat = 1 << 6 // Write a trailing comma (",") if present.

	// Whitespace
	LFIndented             ListFormat = 1 << 7 // The list should be indented.
	LFSpaceBetweenBraces   ListFormat = 1 << 8 // Inserts a space after the opening brace and before the closing brace.
	LFSpaceBetweenSiblings ListFormat = 1 << 9 // Inserts a space between each sibling node.

	// Brackets/Braces
	LFBraces         ListFormat = 1 << 10 // The list is surrounded by "{" and "}".
	LFParenthesis    ListFormat = 1 << 11 // The list is surrounded by "(" and ")".
	LFAngleBrackets  ListFormat = 1 << 12 // The list is surrounded by "<" and ">".
	LFSquareBrackets ListFormat = 1 << 13 // The list is surrounded by "[" and "]".
	LFBracketsMask   ListFormat = LFBraces | LFParenthesis | LFAngleBrackets | LFSquareBrackets

	LFOptionalIfNil   ListFormat = 1 << 14 // Do not emit brackets if the list is nil.
	LFOptionalIfEmpty ListFormat = 1 << 15 // Do not emit brackets if the list is empty.
	LFOptional        ListFormat = LFOptionalIfNil | LFOptionalIfEmpty

	// Other
	LFPreferNewLine         ListFormat = 1 << 16 // Prefer adding a LineTerminator between synthesized nodes.
	LFNoTrailingNewLine     ListFormat = 1 << 17 // Do not emit a trailing NewLine for a MultiLine list.
	LFNoInterveningComments ListFormat = 1 << 18 // Do not emit comments between each node
	LFNoSpaceIfEmpty        ListFormat = 1 << 19 // If the literal is empty, do not add spaces between braces.
	LFSingleElement         ListFormat = 1 << 20
	LFSpaceAfterList        ListFormat = 1 << 21 // Add space after list

	// Precomputed Formats
	LFModifiers                    ListFormat = LFSingleLine | LFSpaceBetweenSiblings | LFNoInterveningComments | LFSpaceAfterList
	LFHeritageClauses              ListFormat = LFSingleLine | LFSpaceBetweenSiblings
	LFSingleLineTypeLiteralMembers ListFormat = LFSingleLine | LFSpaceBetweenBraces | LFSpaceBetweenSiblings
	LFMultiLineTypeLiteralMembers  ListFormat = LFMultiLine | LFIndented | LFOptionalIfEmpty

	LFSingleLineTupleTypeElements       ListFormat = LFCommaDelimited | LFSpaceBetweenSiblings | LFSingleLine
	LFMultiLineTupleTypeElements        ListFormat = LFCommaDelimited | LFIndented | LFSpaceBetweenSiblings | LFMultiLine
	LFUnionTypeConstituents             ListFormat = LFBarDelimited | LFSpaceBetweenSiblings | LFSingleLine
	LFIntersectionTypeConstituents      ListFormat = LFAmpersandDelimited | LFSpaceBetweenSiblings | LFSingleLine
	LFObjectBindingPatternElements      ListFormat = LFSingleLine | LFAllowTrailingComma | LFSpaceBetweenBraces | LFCommaDelimited | LFSpaceBetweenSiblings | LFNoSpaceIfEmpty
	LFArrayBindingPatternElements       ListFormat = LFSingleLine | LFAllowTrailingComma | LFCommaDelimited | LFSpaceBetweenSiblings | LFNoSpaceIfEmpty
	LFObjectLiteralExpressionProperties ListFormat = LFPreserveLines | LFCommaDelimited | LFSpaceBetweenSiblings | LFSpaceBetweenBraces | LFIndented | LFBraces | LFNoSpaceIfEmpty
	LFImportAttributes                  ListFormat = LFPreserveLines | LFCommaDelimited | LFSpaceBetweenSiblings | LFSpaceBetweenBraces | LFIndented | LFBraces | LFNoSpaceIfEmpty
	LFArrayLiteralExpressionElements    ListFormat = LFPreserveLines | LFCommaDelimited | LFSpaceBetweenSiblings | LFAllowTrailingComma | LFIndented | LFSquareBrackets
	LFCommaListElements                 ListFormat = LFCommaDelimited | LFSpaceBetweenSiblings | LFSingleLine
	LFCallExpressionArguments           ListFormat = LFCommaDelimited | LFSpaceBetweenSiblings | LFSingleLine | LFParenthesis
	LFNewExpressionArguments            ListFormat = LFCommaDelimited | LFSpaceBetweenSiblings | LFSingleLine | LFParenthesis | LFOptionalIfNil
	LFTemplateExpressionSpans           ListFormat = LFSingleLine | LFNoInterveningComments
	LFSingleLineBlockStatements         ListFormat = LFSpaceBetweenBraces | LFSpaceBetweenSiblings | LFSingleLine
	LFMultiLineBlockStatements          ListFormat = LFIndented | LFMultiLine
	LFVariableDeclarationList           ListFormat = LFCommaDelimited | LFSpaceBetweenSiblings | LFSingleLine
	LFSingleLineFunctionBodyStatements  ListFormat = LFSingleLine | LFSpaceBetweenSiblings | LFSpaceBetweenBraces
	LFMultiLineFunctionBodyStatements   ListFormat = LFMultiLine
	LFClassHeritageClauses              ListFormat = LFSingleLine
	LFClassMembers                      ListFormat = LFIndented | LFMultiLine
	LFInterfaceMembers                  ListFormat = LFIndented | LFMultiLine
	LFEnumMembers                       ListFormat = LFCommaDelimited | LFIndented | LFMultiLine
	LFCaseBlockClauses                  ListFormat = LFIndented | LFMultiLine
	LFNamedImportsOrExportsElements     ListFormat = LFCommaDelimited | LFSpaceBetweenSiblings | LFAllowTrailingComma | LFSingleLine | LFSpaceBetweenBraces | LFNoSpaceIfEmpty
	LFJsxElementOrFragmentChildren      ListFormat = LFSingleLine | LFNoInterveningComments
	LFJsxElementAttributes              ListFormat = LFSingleLine | LFSpaceBetweenSiblings | LFNoInterveningComments
	LFCaseOrDefaultClauseStatements     ListFormat = LFIndented | LFMultiLine | LFNoTrailingNewLine | LFOptionalIfEmpty
	LFHeritageClauseTypes               ListFormat = LFCommaDelimited | LFSpaceBetweenSiblings | LFSingleLine
	LFSourceFileStatements              ListFormat = LFMultiLine | LFNoTrailingNewLine
	LFDecorators                        ListFormat = LFMultiLine | LFOptional | LFSpaceAfterList
	LFTypeArguments                     ListFormat = LFCommaDelimited | LFSpaceBetweenSiblings | LFSingleLine | LFAngleBrackets | LFOptional
	LFTypeParameters                    ListFormat = LFCommaDelimited | LFSpaceBetweenSiblings | LFSingleLine | LFAngleBrackets | LFOptional
	LFParameters                        ListFormat = LFCommaDelimited | LFSpaceBetweenSiblings | LFSingleLine | LFParenthesis
	LFSingleArrowParameter              ListFormat = LFCommaDelimited | LFSpaceBetweenSiblings | LFSingleLine
	LFIndexSignatureParameters          ListFormat = LFCommaDelimited | LFSpaceBetweenSiblings | LFSingleLine | LFIndented | LFSquareBrackets
	LFJSDocComment                      ListFormat = LFMultiLine | LFAsteriskDelimited
	LFImportClauseEntries               ListFormat = LFImportAttributes // Deprecated: Use LFImportAttributes
)

type NameGenerator

type NameGenerator struct {
	Context                            *EmitContext
	IsFileLevelUniqueNameInCurrentFile func(string, bool) bool // callback for Printer.isFileLevelUniqueNameInCurrentFile
	GetTextOfNode                      func(*ast.Node) string  // callback for Printer.getTextOfNode
	// contains filtered or unexported fields
}

func (*NameGenerator) GenerateName

func (g *NameGenerator) GenerateName(name *ast.MemberName) string

Generate the text for a generated identifier or private identifier

func (*NameGenerator) PopScope

func (g *NameGenerator) PopScope(reuseTempVariableScope bool)

func (*NameGenerator) PushScope

func (g *NameGenerator) PushScope(reuseTempVariableScope bool)

type NameOptions

type NameOptions struct {
	AllowComments   bool // indicates whether comments may be emitted for the name.
	AllowSourceMaps bool // indicates whether source maps may be emitted for the name.
}

type NodeFactory

type NodeFactory struct {
	ast.NodeFactory
	// contains filtered or unexported fields
}

func NewNodeFactory

func NewNodeFactory(context *EmitContext) *NodeFactory

func (*NodeFactory) EnsureUseStrict

func (f *NodeFactory) EnsureUseStrict(statements []*ast.Statement) []*ast.Statement

Ensures `"use strict"` is the first statement of a slice of statements.

func (*NodeFactory) GetDeclarationName

func (f *NodeFactory) GetDeclarationName(node *ast.Declaration) *ast.IdentifierNode

Gets the name of a declaration to use during emit.

func (*NodeFactory) GetDeclarationNameEx

func (f *NodeFactory) GetDeclarationNameEx(node *ast.Declaration, opts NameOptions) *ast.IdentifierNode

Gets the name of a declaration to use during emit.

func (*NodeFactory) GetExportName

func (f *NodeFactory) GetExportName(node *ast.Declaration) *ast.IdentifierNode

Gets the export name of a declaration. This is primarily used for declarations that can be referred to by name in the declaration's immediate scope (classes, enums, namespaces). An export name will *always* be prefixed with an module or namespace export modifier like `"exports."` when emitted as an expression if the name points to an exported symbol.

func (*NodeFactory) GetExportNameEx

func (f *NodeFactory) GetExportNameEx(node *ast.Declaration, opts AssignedNameOptions) *ast.IdentifierNode

Gets the export name of a declaration. This is primarily used for declarations that can be referred to by name in the declaration's immediate scope (classes, enums, namespaces). An export name will *always* be prefixed with an module or namespace export modifier like `"exports."` when emitted as an expression if the name points to an exported symbol.

func (*NodeFactory) GetLocalName

func (f *NodeFactory) GetLocalName(node *ast.Declaration) *ast.IdentifierNode

Gets the local name of a declaration. This is primarily used for declarations that can be referred to by name in the declaration's immediate scope (classes, enums, namespaces). A local name will *never* be prefixed with a module or namespace export modifier like "exports." when emitted as an expression.

func (*NodeFactory) GetLocalNameEx

func (f *NodeFactory) GetLocalNameEx(node *ast.Declaration, opts AssignedNameOptions) *ast.IdentifierNode

Gets the local name of a declaration. This is primarily used for declarations that can be referred to by name in the declaration's immediate scope (classes, enums, namespaces). A local name will *never* be prefixed with a module or namespace export modifier like "exports." when emitted as an expression.

func (*NodeFactory) GetNamespaceMemberName

func (f *NodeFactory) GetNamespaceMemberName(ns *ast.IdentifierNode, name *ast.IdentifierNode, opts NameOptions) *ast.IdentifierNode

func (*NodeFactory) InlineExpressions

func (f *NodeFactory) InlineExpressions(expressions []*ast.Expression) *ast.Expression

Converts a slice of expressions into a single comma-delimited expression. Returns nil if expressions is nil or empty. NOTE: Unlike Strada, the Corsa implementation does not currently use `ast.KindCommaListExpression`.

func (*NodeFactory) NewAddDisposableResourceHelper

func (f *NodeFactory) NewAddDisposableResourceHelper(envBinding *ast.Expression, value *ast.Expression, async bool) *ast.Expression

func (*NodeFactory) NewArraySliceCall

func (f *NodeFactory) NewArraySliceCall(array *ast.Expression, start int) *ast.Node

func (*NodeFactory) NewAssignHelper

func (f *NodeFactory) NewAssignHelper(attributesSegments []*ast.Expression, scriptTarget core.ScriptTarget) *ast.Expression

!!! Class Fields Helpers !!! ES2018 Helpers Chains a sequence of expressions using the __assign helper or Object.assign if available in the target

func (*NodeFactory) NewAssignmentExpression

func (f *NodeFactory) NewAssignmentExpression(left *ast.Expression, right *ast.Expression) *ast.Expression

func (*NodeFactory) NewCommaExpression

func (f *NodeFactory) NewCommaExpression(left *ast.Expression, right *ast.Expression) *ast.Expression

func (*NodeFactory) NewDisposeResourcesHelper

func (f *NodeFactory) NewDisposeResourcesHelper(envBinding *ast.Expression) *ast.Expression

func (*NodeFactory) NewExportStarHelper

func (f *NodeFactory) NewExportStarHelper(moduleExpression *ast.Expression, exportsExpression *ast.Expression) *ast.Expression

Allocates a new Call expression to the `__exportStar` helper.

func (*NodeFactory) NewFalseExpression

func (f *NodeFactory) NewFalseExpression() *ast.Expression

func (*NodeFactory) NewFunctionCallCall

func (f *NodeFactory) NewFunctionCallCall(target *ast.Expression, thisArg *ast.Expression, argumentsList []*ast.Node) *ast.Node

func (*NodeFactory) NewGeneratedNameForNode

func (f *NodeFactory) NewGeneratedNameForNode(node *ast.Node) *ast.IdentifierNode

Allocates a new unique name based on the provided node.

func (*NodeFactory) NewGeneratedNameForNodeEx

func (f *NodeFactory) NewGeneratedNameForNodeEx(node *ast.Node, options AutoGenerateOptions) *ast.IdentifierNode

Allocates a new unique name based on the provided node.

func (*NodeFactory) NewGeneratedPrivateNameForNode

func (f *NodeFactory) NewGeneratedPrivateNameForNode(node *ast.Node) *ast.PrivateIdentifierNode

Allocates a new unique private name based on the provided node.

func (*NodeFactory) NewGeneratedPrivateNameForNodeEx

func (f *NodeFactory) NewGeneratedPrivateNameForNodeEx(node *ast.Node, options AutoGenerateOptions) *ast.PrivateIdentifierNode

Allocates a new unique private name based on the provided node.

func (*NodeFactory) NewGlobalMethodCall

func (f *NodeFactory) NewGlobalMethodCall(globalObjectName string, methodName string, argumentsList []*ast.Node) *ast.Node

func (*NodeFactory) NewImportDefaultHelper

func (f *NodeFactory) NewImportDefaultHelper(expression *ast.Expression) *ast.Expression

Allocates a new Call expression to the `__importDefault` helper.

func (*NodeFactory) NewImportStarHelper

func (f *NodeFactory) NewImportStarHelper(expression *ast.Expression) *ast.Expression

Allocates a new Call expression to the `__importStar` helper.

func (*NodeFactory) NewLogicalORExpression

func (f *NodeFactory) NewLogicalORExpression(left *ast.Expression, right *ast.Expression) *ast.Expression

func (*NodeFactory) NewLoopVariable

func (f *NodeFactory) NewLoopVariable() *ast.IdentifierNode

Allocates a new loop variable name.

func (*NodeFactory) NewLoopVariableEx

func (f *NodeFactory) NewLoopVariableEx(options AutoGenerateOptions) *ast.IdentifierNode

Allocates a new loop variable name.

func (*NodeFactory) NewMethodCall

func (f *NodeFactory) NewMethodCall(object *ast.Node, methodName *ast.Node, argumentsList []*ast.Node) *ast.Node

func (*NodeFactory) NewPropKeyHelper

func (f *NodeFactory) NewPropKeyHelper(expr *ast.Expression) *ast.Expression

func (*NodeFactory) NewRestHelper

func (f *NodeFactory) NewRestHelper(value *ast.Expression, elements []*ast.Node, computedTempVariables []*ast.Node, location core.TextRange) *ast.Expression

func (*NodeFactory) NewRewriteRelativeImportExtensionsHelper

func (f *NodeFactory) NewRewriteRelativeImportExtensionsHelper(firstArgument *ast.Node, preserveJsx bool) *ast.Expression

Allocates a new Call expression to the `__rewriteRelativeImportExtension` helper.

func (*NodeFactory) NewSetFunctionNameHelper

func (f *NodeFactory) NewSetFunctionNameHelper(fn *ast.Expression, name *ast.Expression, prefix string) *ast.Expression

func (*NodeFactory) NewStrictEqualityExpression

func (f *NodeFactory) NewStrictEqualityExpression(left *ast.Expression, right *ast.Expression) *ast.Expression

func (f *NodeFactory) NewLogicalANDExpression(left *ast.Expression, right *ast.Expression) *ast.Expression func (f *NodeFactory) NewBitwiseORExpression(left *ast.Expression, right *ast.Expression) *ast.Expression func (f *NodeFactory) NewBitwiseXORExpression(left *ast.Expression, right *ast.Expression) *ast.Expression func (f *NodeFactory) NewBitwiseANDExpression(left *ast.Expression, right *ast.Expression) *ast.Expression

func (*NodeFactory) NewStrictInequalityExpression

func (f *NodeFactory) NewStrictInequalityExpression(left *ast.Expression, right *ast.Expression) *ast.Expression

func (*NodeFactory) NewStringLiteralFromNode

func (f *NodeFactory) NewStringLiteralFromNode(textSourceNode *ast.Node) *ast.Node

Allocates a new StringLiteral whose source text is derived from the provided node. This is often used to create a string representation of an Identifier or NumericLiteral.

func (*NodeFactory) NewTempVariable

func (f *NodeFactory) NewTempVariable() *ast.IdentifierNode

Allocates a new temp variable name, but does not record it in the environment. It is recommended to pass this to either `AddVariableDeclaration` or `AddLexicalDeclaration` to ensure it is properly tracked, if you are not otherwise handling it yourself.

func (*NodeFactory) NewTempVariableEx

func (f *NodeFactory) NewTempVariableEx(options AutoGenerateOptions) *ast.IdentifierNode

Allocates a new temp variable name, but does not record it in the environment. It is recommended to pass this to either `AddVariableDeclaration` or `AddLexicalDeclaration` to ensure it is properly tracked, if you are not otherwise handling it yourself.

func (*NodeFactory) NewThisExpression

func (f *NodeFactory) NewThisExpression() *ast.Expression

func (*NodeFactory) NewTrueExpression

func (f *NodeFactory) NewTrueExpression() *ast.Expression

func (*NodeFactory) NewTypeCheck

func (f *NodeFactory) NewTypeCheck(value *ast.Node, tag string) *ast.Node

func (*NodeFactory) NewUniqueName

func (f *NodeFactory) NewUniqueName(text string) *ast.IdentifierNode

Allocates a new unique name based on the provided text.

func (*NodeFactory) NewUniqueNameEx

func (f *NodeFactory) NewUniqueNameEx(text string, options AutoGenerateOptions) *ast.IdentifierNode

Allocates a new unique name based on the provided text.

func (*NodeFactory) NewUniquePrivateName

func (f *NodeFactory) NewUniquePrivateName(text string) *ast.PrivateIdentifierNode

Allocates a new unique private name based on the provided text.

func (*NodeFactory) NewUniquePrivateNameEx

func (f *NodeFactory) NewUniquePrivateNameEx(text string, options AutoGenerateOptions) *ast.PrivateIdentifierNode

Allocates a new unique private name based on the provided text.

func (*NodeFactory) NewUnscopedHelperName

func (f *NodeFactory) NewUnscopedHelperName(name string) *ast.IdentifierNode

Allocates a new Identifier representing a reference to a helper function.

func (*NodeFactory) NewVoidZeroExpression

func (f *NodeFactory) NewVoidZeroExpression() *ast.Expression

func (*NodeFactory) RestoreOuterExpressions

func (f *NodeFactory) RestoreOuterExpressions(outerExpression *ast.Expression, innerExpression *ast.Expression, kinds ast.OuterExpressionKinds) *ast.Expression

func (*NodeFactory) SplitCustomPrologue

func (f *NodeFactory) SplitCustomPrologue(source []*ast.Statement) (prologue []*ast.Statement, rest []*ast.Statement)

Splits a slice of statements into two parts: custom prologue statements (e.g., with `EFCustomPrologue` set) and the rest of the statements

func (*NodeFactory) SplitStandardPrologue

func (f *NodeFactory) SplitStandardPrologue(source []*ast.Statement) (prologue []*ast.Statement, rest []*ast.Statement)

Splits a slice of statements into two parts: standard prologue statements and the rest of the statements

type PrintHandlers

type PrintHandlers struct {
	// A hook used by the Printer when generating unique names to avoid collisions with
	// globally defined names that exist outside of the current source file.
	HasGlobalName func(name string) bool

	OnBeforeEmitNode     func(nodeOpt *ast.Node)
	OnAfterEmitNode      func(nodeOpt *ast.Node)
	OnBeforeEmitNodeList func(nodesOpt *ast.NodeList)
	OnAfterEmitNodeList  func(nodesOpt *ast.NodeList)
	OnBeforeEmitToken    func(nodeOpt *ast.TokenNode)
	OnAfterEmitToken     func(nodeOpt *ast.TokenNode)
}

type Printer

type Printer struct {
	PrintHandlers
	Options PrinterOptions
	// contains filtered or unexported fields
}

func NewPrinter

func NewPrinter(options PrinterOptions, handlers PrintHandlers, emitContext *EmitContext) *Printer

func (*Printer) Emit

func (p *Printer) Emit(node *ast.Node, sourceFile *ast.SourceFile) string

func (*Printer) EmitSourceFile

func (p *Printer) EmitSourceFile(sourceFile *ast.SourceFile) string

func (*Printer) Write

func (p *Printer) Write(node *ast.Node, sourceFile *ast.SourceFile, writer EmitTextWriter, sourceMapGenerator *sourcemap.Generator)

type PrinterOptions

type PrinterOptions struct {
	RemoveComments bool
	NewLine        core.NewLineKind
	// OmitTrailingSemicolon         bool
	NoEmitHelpers bool
	// Module                        core.ModuleKind
	// ModuleResolution              core.ModuleResolutionKind
	// Target                        core.ScriptTarget
	SourceMap                   bool
	InlineSourceMap             bool
	InlineSources               bool
	OmitBraceSourceMapPositions bool
	// ExtendedDiagnostics           bool
	OnlyPrintJSDocStyle bool
	NeverAsciiEscape    bool
	// StripInternal                 bool
	PreserveSourceNewlines        bool
	TerminateUnterminatedLiterals bool // !!!
}

type Priority

type Priority struct {
	Value int
}

type QuoteChar

type QuoteChar rune
const (
	QuoteCharSingleQuote QuoteChar = '\''
	QuoteCharDoubleQuote QuoteChar = '"'
	QuoteCharBacktick    QuoteChar = '`'
)

type SourceFileMetaDataProvider

type SourceFileMetaDataProvider interface {
	GetSourceFileMetaData(path tspath.Path) *ast.SourceFileMetaData
}

type SymbolAccessibility

type SymbolAccessibility int32
const (
	SymbolAccessibilityAccessible SymbolAccessibility = iota
	SymbolAccessibilityNotAccessible
	SymbolAccessibilityCannotBeNamed
	SymbolAccessibilityNotResolved
)

type SymbolAccessibilityResult

type SymbolAccessibilityResult struct {
	Accessibility        SymbolAccessibility
	AliasesToMakeVisible []*ast.Node // aliases that need to have this symbol visible
	ErrorSymbolName      string      // Optional - symbol name that results in error
	ErrorNode            *ast.Node   // Optional - node that results in error
	ErrorModuleName      string      // Optional - If the symbol is not visible from module, module's name
}

type SynthesizedComment

type SynthesizedComment struct {
	Kind               ast.Kind
	Loc                core.TextRange
	HasLeadingNewLine  bool
	HasTrailingNewLine bool
	Text               string
}

type WriteKind

type WriteKind int
const (
	WriteKindNone WriteKind = iota
	WriteKindKeyword
	WriteKindOperator
	WriteKindPunctuation
	WriteKindStringLiteral
	WriteKindParameter
	WriteKindProperty
	WriteKindComment
	WriteKindLiteral
)

Jump to

Keyboard shortcuts

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