Documentation
¶
Overview ¶
Package tsbuf builds one TypeScript file.
It is github.com/simonjanss/rig/internal/gen/gobuf for TypeScript, and the differences are the ones the language forces. There is no gofmt here: Go generators can emit approximately correct source and let the formatter settle the layout, and nothing in the Go toolchain formats TypeScript. So this emits what it means, already laid out — four spaces, one import per module, a trailing comma where Prettier would put one — and the output is compared against a golden file rather than against a formatter.
The other difference is imports. A Go import is a path and a package name; a TypeScript import is a module specifier and a set of names, and the same module can be imported twice over — once for values and once for types. So Buf.Import and Buf.ImportType collect names per module and the two are emitted as separate statements, because `import type` is what tells a bundler the import disappears at build time.
Index ¶
- func Ident(s string) bool
- func Key(s string) string
- func Quote(s string) string
- type Buf
- func (b *Buf) Bytes() ([]byte, error)
- func (b *Buf) Comment(text string)
- func (b *Buf) Doc(text string)
- func (b *Buf) Import(module, name string) string
- func (b *Buf) ImportType(module, name string) string
- func (b *Buf) Indent()
- func (b *Buf) L(format string, args ...any)
- func (b *Buf) NL()
- func (b *Buf) Outdent()
- func (b *Buf) P(format string, args ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ident ¶
Ident reports whether a name can be written bare as an object key, or has to be quoted. A column called `order` is fine; one called `full-name` is not.
Types ¶
type Buf ¶
type Buf struct {
// contains filtered or unexported fields
}
Buf accumulates one file.
func New ¶
func New() *Buf
New builds a buffer for a generated file, which carries the do-not-edit banner.
func NewHandOwned ¶
func NewHandOwned() *Buf
NewHandOwned builds a buffer for a file a developer owns, which carries no banner and is written once.
func (*Buf) Comment ¶
Comment writes a JSDoc block, wrapped.
A block rather than `//`, because this is the form an editor shows on hover and the form TypeDoc reads: a description the document carries is documentation, and a `//` comment above a member is invisible to everything that would display it.
func (*Buf) Import ¶
Import records a value import and returns the name, so a caller can write the name it was given rather than the one it asked for.
func (*Buf) ImportType ¶
ImportType records a type-only import. Separate from Buf.Import because `import type` is what says the import is erased at build time — and a type imported as a value is a runtime dependency on a module that may have no runtime at all.
func (*Buf) Indent ¶
func (b *Buf) Indent()
Indent shifts everything written after it one level right.