Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bindings/declarations.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type Enum struct {
Name Identifier
Modifiers []Modifier
Members []*EnumMember
SupportComments
Source
}

Expand Down
7 changes: 6 additions & 1 deletion convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,18 @@ func (ts *Typescript) parse(obj types.Object) error {
// If this has 'const's, then it is an enum. The enum code will
// patch this value to be more specific.
ts.updateNode(objectIdentifier.Ref(), func(n *typescriptNode) {
n.Node = &bindings.Alias{
aliasNode := &bindings.Alias{
Name: objectIdentifier,
Modifiers: []bindings.Modifier{},
Type: rhs.Value,
Parameters: rhs.TypeParameters,
Source: ts.location(obj),
}
if ts.preserveComments {
cmts := ts.parsed.CommentForObject(obj)
aliasNode.AppendComments(cmts)
}
n.Node = aliasNode
})
return nil
case *types.Map, *types.Array, *types.Slice:
Expand Down
9 changes: 5 additions & 4 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ func (t *typescriptNode) AddEnum(member *bindings.EnumMember) {
if ok {
// Switch to an enum
enum := &bindings.Enum{
Name: alias.Name,
Modifiers: alias.Modifiers,
Members: []*bindings.EnumMember{member},
Source: alias.Source,
Name: alias.Name,
Modifiers: alias.Modifiers,
Members: []*bindings.EnumMember{member},
SupportComments: alias.SupportComments,
Source: alias.Source,
}
return enum, nil
}
Expand Down
3 changes: 3 additions & 0 deletions testdata/enums/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export enum EnumInt {
export type EnumSliceType = readonly EnumString[];

// From enums/enums.go
/**
* EnumString is a string-based enum
*/
export enum EnumString {
/**
* EnumBar is the "bar" value
Expand Down