Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalCueValue ¶
MarshalCueValue returns a typescript type given a cue value.
func MarshalString ¶
MarshalString marshals a Cue string into a Typescript type string, returning an error.
Types ¶
type AstKind ¶
type AstKind interface { String() string // contains filtered or unexported methods }
ASTKind is a generalization of all elements in our AST.
This is intended for typescript generation only; it's a higher level abstraction than concrete JS syntax, and a single AST node can represent a large swath of JS (eg. an entire enum, or an entire key/value line).
type Binding ¶
type Binding struct { IndentLevel int Kind BindingKind Members []AstKind }
Binding represents a complex type: an array, enum, object, etc.
type BindingKind ¶
type BindingKind uint8
const ( // BindingArray represents a plain ol' javascript array with contents: // [1, 2, 3, 4]. BindingArray BindingKind = iota // BindingTypedArray represents a TS Array definition: Array<T>. When used // within a Binding, any members are automatically assumed to be bound using // a disjunction. However, the Members field can also contain a single // BindingDisjunction with many values - it does the same thing. // // Examples: // // Binding{ // Kind: BindingTypedArray, // Members: []AstKind{ // Type{"string"}, // automatically a disjunction. // Type{"number"}, // }, // } // // is equivalent to: // // Binding{ // Kind: BindingTypedArray, // Members: []AstKind{ // Binding{ // Kind: BindingDisjunction, // Members: []AstKind{ // Type{"string"}, // Type{"number"}, // }, // }, // }, // } // BindingTypedArray // BindingObject represents a pojo. BindingObject // BindingType represents an object used for a type. These use // semi-colons as their field terminators. BindingType // BindingDisjunction represents an ADT enum - values combined // with " | " BindingDisjunction )
type Enum ¶
An Enum is an ADT - a union type within Cue. We special-case enums because of typescript limitations. A pure `enum Foo {...}` in typescript isn't that fun to use; it's recommended by many to create an Object containing the enum values, then use `typeof EnumName[keyof typeof EnumName]` to define the enum.
In effect, this enum is a higher-kind helper for generating Typescript. It creates concrete AST for enums depending on the members that it contains.
func (Enum) ExprAST ¶
ExprAST is used when creating an enum that has concrete values or complex data types. It creates top-level exports using consts and `keyof typeof` to generate enums.
func (Enum) IsScalarType ¶
IsScalarType returns true if the enum is made out of basic scalar types, eg. `string | number`, or `string | null`
type Expr ¶
type Expr struct {
Data AstKind
}
Expr represents a single TS expression, such as a type defintion.
TODO (tonyhb): refactor. We probably dont need Expr wrappers, and it makes typescript code gen function signatures a little ugly (see generateStructBinding). We can probably work with Local being the single top-level identifier.
type Lit ¶
type Lit struct {
Value string
}
Lit represents literal text, such as newlines, comments, spaces, etc.
type Local ¶
type Local struct { // Kind is the type of definition for the variable. Kind LocalKind // Name represents the name for the identifier Name string // Type represents the optional type definition for the identifier. // This is valid for const definitions only. Type *string // IsExport defines whether this identifier should be exported. IsExport bool // Value is the value that this identifier refers to. This could be // a scalar, a type, a binding, etc. Value AstKind // AsType records the "as T" suffix for an identifier, eg: // "const Foo = 1 as int; AsType *string }
Local is a concrete AST expr which represents a definition for a variable or type.