Documentation
¶
Index ¶
- Constants
- func List[F any, T any](list []F, convert func(F) T) []T
- func ListLazy[F any, T any](convert func(F) T) func(list []F) []T
- func ToInt[T ~int](a T) int
- func ToStrings[T ~string](a []T) []string
- type Alias
- type ArrayLiteralType
- type ArrayType
- type Bindings
- func (b *Bindings) Alias(alias *Alias) (*goja.Object, error)
- func (b *Bindings) Array(arrType ExpressionType) (*goja.Object, error)
- func (b *Bindings) ArrayLiteral(value *ArrayLiteralType) (*goja.Object, error)
- func (b *Bindings) BooleanLiteral(value int) (*goja.Object, error)
- func (b *Bindings) CommentGojaObject(comments []SyntheticComment, object *goja.Object) (*goja.Object, error)
- func (b *Bindings) EnumDeclaration(e *Enum) (*goja.Object, error)
- func (b *Bindings) EnumMember(value *EnumMember) (*goja.Object, error)
- func (b *Bindings) FloatLiteral(value float64) (*goja.Object, error)
- func (b *Bindings) HeritageClause(clause *HeritageClause) (*goja.Object, error)
- func (b *Bindings) Identifier(name string) (*goja.Object, error)
- func (b *Bindings) Interface(ti *Interface) (*goja.Object, error)
- func (b *Bindings) LiteralKeyword(word *LiteralKeyword) (*goja.Object, error)
- func (b *Bindings) Modifier(name Modifier) (*goja.Object, error)
- func (b *Bindings) Null() (*goja.Object, error)
- func (b *Bindings) NumericLiteral(value int64) (*goja.Object, error)
- func (b *Bindings) OperatorNode(value *OperatorNodeType) (*goja.Object, error)
- func (b *Bindings) PropertySignature(sig *PropertySignature) (*goja.Object, error)
- func (b *Bindings) Reference(ref *ReferenceType) (*goja.Object, error)
- func (b *Bindings) SerializeToTypescript(node *goja.Object) (string, error)
- func (b *Bindings) StringLiteral(value string) (*goja.Object, error)
- func (b *Bindings) ToTypescriptDeclarationNode(ety DeclarationType) (*goja.Object, error)
- func (b *Bindings) ToTypescriptExpressionNode(ety ExpressionType) (*goja.Object, error)
- func (b *Bindings) ToTypescriptNode(ety Node) (*goja.Object, error)
- func (b *Bindings) Tuple(length int, tupleType ExpressionType) (*goja.Object, error)
- func (b *Bindings) TypeIntersection(node *TypeIntersection) (*goja.Object, error)
- func (b *Bindings) TypeLiteralNode(node *TypeLiteralNode) (*goja.Object, error)
- func (b *Bindings) TypeParameter(ty *TypeParameter) (*goja.Object, error)
- func (b *Bindings) Union(ty *UnionType) (*goja.Object, error)
- func (b *Bindings) VariableDeclaration(decl *VariableDeclaration) (*goja.Object, error)
- func (b *Bindings) VariableDeclarationList(list *VariableDeclarationList) (*goja.Object, error)
- func (b *Bindings) VariableStatement(stmt *VariableStatement) (*goja.Object, error)
- type Commentable
- type DeclarationType
- type Enum
- type EnumMember
- type ExpressionType
- type ExpressionWithTypeArguments
- type HasSource
- type HeritageClause
- type HeritageType
- type Identifier
- type Interface
- type LiteralKeyword
- type LiteralType
- type Modifier
- type Node
- type NodeFlags
- type Null
- type OperatorNodeType
- type PropertySignature
- type ReferenceType
- type Source
- type SupportComments
- type SyntheticComment
- type TupleType
- type TypeIntersection
- type TypeLiteralNode
- type TypeParameter
- type UnionType
- type VariableDeclaration
- type VariableDeclarationList
- type VariableStatement
Constants ¶
const ( ModifierAbstract = "AbstractKeyword" ModifierAccessor = "AccessorKeyword" ModifierAsync = "AsyncKeyword" ModifierConst = "ConstKeyword" ModifierDeclare = "DeclareKeyword" ModifierDefault = "DefaultKeyword" ModifierExport = "ExportKeyword" ModifierIn = "InKeyword" ModifierPrivate = "PrivateKeyword" ModifierProtected = "ProtectedKeyword" ModifierPublic = "PublicKeyword" ModifierReadonly = "ReadonlyKeyword" ModifierOut = "OutKeyword" ModifierOverride = "OverrideKeyword" ModifierStatic = "StaticKeyword" )
const (
NodeFlagsConstant = 2
)
Variables ¶
This section is empty.
Functions ¶
func List ¶
List is a helper function to reduce boilerplate when converting slices of database types to slices of codersdk types. Only works if the function takes a single argument.
Types ¶
type Alias ¶
type Alias struct {
Name Identifier
Modifiers []Modifier
Type ExpressionType
Parameters []*TypeParameter
SupportComments
Source
}
type ArrayLiteralType ¶
type ArrayLiteralType struct {
Elements []ExpressionType
}
func (ArrayLiteralType) String ¶
func (a ArrayLiteralType) String() string
type ArrayType ¶
type ArrayType struct {
Node ExpressionType
}
func Array ¶
func Array(node ExpressionType) *ArrayType
type Bindings ¶
type Bindings struct {
// contains filtered or unexported fields
}
func (*Bindings) ArrayLiteral ¶
func (b *Bindings) ArrayLiteral(value *ArrayLiteralType) (*goja.Object, error)
func (*Bindings) BooleanLiteral ¶
func (*Bindings) CommentGojaObject ¶ added in v1.6.0
func (*Bindings) EnumDeclaration ¶ added in v1.3.0
func (*Bindings) EnumMember ¶ added in v1.3.0
func (b *Bindings) EnumMember(value *EnumMember) (*goja.Object, error)
func (*Bindings) FloatLiteral ¶
func (*Bindings) HeritageClause ¶
func (b *Bindings) HeritageClause(clause *HeritageClause) (*goja.Object, error)
func (*Bindings) LiteralKeyword ¶
func (b *Bindings) LiteralKeyword(word *LiteralKeyword) (*goja.Object, error)
func (*Bindings) NumericLiteral ¶
func (*Bindings) OperatorNode ¶
func (b *Bindings) OperatorNode(value *OperatorNodeType) (*goja.Object, error)
func (*Bindings) PropertySignature ¶
func (b *Bindings) PropertySignature(sig *PropertySignature) (*goja.Object, error)
func (*Bindings) SerializeToTypescript ¶
func (*Bindings) StringLiteral ¶
func (*Bindings) ToTypescriptDeclarationNode ¶
func (b *Bindings) ToTypescriptDeclarationNode(ety DeclarationType) (*goja.Object, error)
func (*Bindings) ToTypescriptExpressionNode ¶
func (b *Bindings) ToTypescriptExpressionNode(ety ExpressionType) (*goja.Object, error)
func (*Bindings) ToTypescriptNode ¶
func (*Bindings) TypeIntersection ¶ added in v1.6.0
func (b *Bindings) TypeIntersection(node *TypeIntersection) (*goja.Object, error)
func (*Bindings) TypeLiteralNode ¶ added in v1.6.0
func (b *Bindings) TypeLiteralNode(node *TypeLiteralNode) (*goja.Object, error)
func (*Bindings) TypeParameter ¶
func (b *Bindings) TypeParameter(ty *TypeParameter) (*goja.Object, error)
func (*Bindings) VariableDeclaration ¶
func (b *Bindings) VariableDeclaration(decl *VariableDeclaration) (*goja.Object, error)
func (*Bindings) VariableDeclarationList ¶
func (b *Bindings) VariableDeclarationList(list *VariableDeclarationList) (*goja.Object, error)
func (*Bindings) VariableStatement ¶
func (b *Bindings) VariableStatement(stmt *VariableStatement) (*goja.Object, error)
type Commentable ¶ added in v1.6.0
type Commentable interface {
AppendComment(comment SyntheticComment)
Comments() []SyntheticComment
}
Commentable indicates if the AST node supports adding comments. Any number of comments are supported and can be attached to a typescript AST node.
type DeclarationType ¶
type DeclarationType interface {
Node
// contains filtered or unexported methods
}
DeclarationType is any type that can exist at the top level of a AST. Meaning it can be serialized into valid Typescript.
type Enum ¶ added in v1.3.0
type Enum struct {
Name Identifier
Modifiers []Modifier
Members []*EnumMember
Source
}
type EnumMember ¶ added in v1.3.0
type EnumMember struct {
Name string
// Value is allowed to be nil, which results in `undefined`.
Value ExpressionType
}
type ExpressionType ¶
type ExpressionType interface {
Node
// contains filtered or unexported methods
}
ExpressionType
type ExpressionWithTypeArguments ¶
type ExpressionWithTypeArguments struct {
Expression ExpressionType
Arguments []ExpressionType
}
type HasSource ¶ added in v1.6.0
type HasSource interface {
SourceComment() (SyntheticComment, bool)
}
type HeritageClause ¶
type HeritageClause struct {
Token HeritageType
Args []ExpressionType
}
HeritageClause interface Foo extends Bar, Baz {}
func HeritageClauseExtends ¶
func HeritageClauseExtends(args ...ExpressionType) *HeritageClause
type HeritageType ¶
type HeritageType string
const ( HeritageTypeExtends HeritageType = "extends" HeritageTypeImplements HeritageType = "implements" )
type Identifier ¶
Identifier is a name given to a variable, function, class, etc. Identifiers should be unique within a package. Package information is included to help with disambiguation in the case of name collisions.
func (Identifier) GoName ¶
func (i Identifier) GoName() string
GoName should be a unique name for the identifier across all Go packages.
func (Identifier) PkgName ¶
func (i Identifier) PkgName() string
func (Identifier) Ref ¶
func (i Identifier) Ref() string
Ref returns the identifier reference to be used in the generated code. This is the identifier to be used in typescript, since all generated code lands in the same namespace.
func (Identifier) String ¶
func (i Identifier) String() string
type Interface ¶
type Interface struct {
Name Identifier
Modifiers []Modifier
Fields []*PropertySignature
Parameters []*TypeParameter
Heritage []*HeritageClause
SupportComments
Source
}
type LiteralKeyword ¶
type LiteralKeyword string
const ( KeywordVoid LiteralKeyword = "VoidKeyword" KeywordAny LiteralKeyword = "AnyKeyword" KeywordBoolean LiteralKeyword = "BooleanKeyword" KeywordIntrinsic LiteralKeyword = "IntrinsicKeyword" KeywordNever LiteralKeyword = "NeverKeyword" KeywordNumber LiteralKeyword = "NumberKeyword" KeywordObject LiteralKeyword = "ObjectKeyword" KeywordString LiteralKeyword = "StringKeyword" KeywordSymbol LiteralKeyword = "SymbolKeyword" KeywordUndefined LiteralKeyword = "UndefinedKeyword" KeywordUnknown LiteralKeyword = "UnknownKeyword" KeywordBigInt LiteralKeyword = "BigIntKeyword" KeywordReadonly LiteralKeyword = "ReadonlyKeyword" KeywordUnique LiteralKeyword = "UniqueKeyword" KeywordKeyOf LiteralKeyword = "KeyOfKeyword" )
func ToTypescriptLiteralKeyword ¶
func ToTypescriptLiteralKeyword(word string) (LiteralKeyword, error)
func (LiteralKeyword) String ¶
func (k LiteralKeyword) String() string
type LiteralType ¶
type LiteralType struct {
Value any // should be some constant value
}
type OperatorNodeType ¶
type OperatorNodeType struct {
Keyword LiteralKeyword
Type ExpressionType
}
func OperatorNode ¶
func OperatorNode(keyword LiteralKeyword, node ExpressionType) *OperatorNodeType
OperatorNode allows adding a keyword to a type Keyword must be "KeyOfKeyword" | "UniqueKeyword" | "ReadonlyKeyword"
func (OperatorNodeType) String ¶
func (o OperatorNodeType) String() string
type PropertySignature ¶
type PropertySignature struct {
// Name is the field name
Name string
Modifiers []Modifier
QuestionToken bool
Type ExpressionType
SupportComments
}
PropertySignature is a field in an interface
func (PropertySignature) String ¶
func (f PropertySignature) String() string
type ReferenceType ¶
type ReferenceType struct {
Name Identifier `json:"name"`
// TODO: Generics
Arguments []ExpressionType `json:"arguments"`
}
ReferenceType can be used to reference another type by name
func Reference ¶
func Reference(name Identifier, args ...ExpressionType) *ReferenceType
func (ReferenceType) String ¶
func (r ReferenceType) String() string
type Source ¶
Source is the golang file that an entity is sourced from.
func (Source) SourceComment ¶ added in v1.6.0
func (s Source) SourceComment() (SyntheticComment, bool)
SourceComment returns a synthetic comment indicating the source file. If the source file is empty, the second return is false.
type SupportComments ¶ added in v1.6.0
type SupportComments struct {
// contains filtered or unexported fields
}
func (*SupportComments) AppendComment ¶ added in v1.6.0
func (s *SupportComments) AppendComment(comment SyntheticComment)
func (*SupportComments) AppendComments ¶ added in v1.6.0
func (s *SupportComments) AppendComments(comments []SyntheticComment)
func (*SupportComments) Comments ¶ added in v1.6.0
func (s *SupportComments) Comments() []SyntheticComment
func (*SupportComments) LeadingComment ¶ added in v1.6.0
func (s *SupportComments) LeadingComment(text string)
LeadingComment is a helper function for the most common type of comment.
type SyntheticComment ¶ added in v1.6.0
SyntheticComment is the state of a comment for a given AST node. See the compiler for how these are serialized.
type TupleType ¶ added in v1.2.0
type TupleType struct {
// TODO: Technically tuples can be heterogeneous, but golang does not really
// support that. So just assume that all elements are the same type.
Node ExpressionType
Length int
}
func HomogeneousTuple ¶ added in v1.2.0
func HomogeneousTuple(length int, node ExpressionType) *TupleType
type TypeIntersection ¶ added in v1.6.0
type TypeIntersection struct {
Types []ExpressionType
}
type TypeLiteralNode ¶ added in v1.6.0
type TypeLiteralNode struct {
Members []*PropertySignature
}
TypeLiteralNode represents an object type literal like { name: string }
type TypeParameter ¶
type TypeParameter struct {
Name Identifier
Modifiers []Modifier
Type ExpressionType
// DefaultType does not map to any Golang concepts and will never be
// used.
DefaultType ExpressionType
}
TypeParameter are generics in Go Foo[T comparable] -> - name: T - Modifiers: [] - Type: Comparable - DefaultType: nil
func Simplify ¶
func Simplify(p []*TypeParameter) ([]*TypeParameter, error)
Simplify removes duplicate type parameters
func (TypeParameter) String ¶
func (p TypeParameter) String() string
type UnionType ¶
type UnionType struct {
Types []ExpressionType
}
func Union ¶
func Union(types ...ExpressionType) *UnionType
type VariableDeclaration ¶
type VariableDeclaration struct {
Name Identifier
ExclamationMark bool
Type ExpressionType
Initializer ExpressionType
}
func (VariableDeclaration) String ¶
func (v VariableDeclaration) String() string
type VariableDeclarationList ¶
type VariableDeclarationList struct {
Declarations []*VariableDeclaration
Flags NodeFlags
}
type VariableStatement ¶
type VariableStatement struct {
Modifiers []Modifier
Declarations *VariableDeclarationList
Source
SupportComments
}
VariableStatement is a top level declaration of a variable var foo: string = "bar" const foo: string = "bar"