Documentation
¶
Overview ¶
Package printer renders the AST to TypeScript source text.
Parentheses are inserted wherever operator precedence requires them, so callers never need to reason about precedence when building trees.
Index ¶
- func Fprint(w io.Writer, n ast.Node, opts ...Option) error
- func Print(n ast.Node, opts ...Option) string
- type MemberSeparator
- type Option
- func GeneratedBanner(by string) Option
- func WithBanner(lines ...string) Option
- func WithDocs(b bool) Option
- func WithIndent(s string) Option
- func WithMaxLineWidth(n int) Option
- func WithMemberSeparator(s MemberSeparator) Option
- func WithQuote(q QuoteStyle) Option
- func WithSemicolons(b bool) Option
- func WithTabs() Option
- func WithTrailingComma(b bool) Option
- type Options
- type Printer
- type QuoteStyle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MemberSeparator ¶
type MemberSeparator uint8
MemberSeparator selects the punctuation between object type members.
const ( SemicolonSeparator MemberSeparator = iota CommaSeparator NewlineSeparator // no punctuation; members separated by line breaks only )
type Option ¶
type Option func(*Options)
Option mutates Options. Options compose.
func GeneratedBanner ¶
GeneratedBanner returns the conventional header for generated files.
func WithBanner ¶
WithBanner sets the file header lines, which are emitted verbatim.
func WithMaxLineWidth ¶
WithMaxLineWidth sets the wrapping column; zero disables wrapping.
func WithMemberSeparator ¶
func WithMemberSeparator(s MemberSeparator) Option
WithMemberSeparator sets the interface member separator.
func WithSemicolons ¶
WithSemicolons enables or disables statement terminators.
func WithTrailingComma ¶
WithTrailingComma enables or disables trailing commas in wrapped lists.
type Options ¶
type Options struct {
// Indent is one level of indentation. Use "\t" for tabs.
Indent string
// Quote is the quote character for string literals.
Quote QuoteStyle
// Semicolons emits statement terminators.
Semicolons bool
// MemberSep is the separator between interface and object type members.
MemberSep MemberSeparator
// TrailingComma emits a trailing comma in multi-line lists.
TrailingComma bool
// MaxLineWidth is the column at which unions, parameter lists, and object
// literals break across lines. Zero disables wrapping entirely.
MaxLineWidth int
// EmitDocs emits JSDoc comments attached to declarations and members.
EmitDocs bool
// Banner is emitted at the top of a SourceFile, before its own Leading
// comments. Each entry becomes one line; the caller supplies any comment
// syntax. This is where a "generated, do not edit" header belongs.
Banner []string
// FinalNewline terminates the output with a line break.
FinalNewline bool
}
Options controls emission. The zero value is not the default; use Default or pass Option values to New.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer renders AST nodes to TypeScript source.
A Printer is single-use and not safe for concurrent use; prefer the package-level Print and Fprint.
type QuoteStyle ¶
type QuoteStyle uint8
QuoteStyle selects the quote character for emitted string literals.
const ( SingleQuote QuoteStyle = iota DoubleQuote BacktickQuote )