diff --git a/bindings/declarations.go b/bindings/declarations.go index 80cad6c..35025d4 100644 --- a/bindings/declarations.go +++ b/bindings/declarations.go @@ -115,6 +115,7 @@ type Enum struct { Name Identifier Modifiers []Modifier Members []*EnumMember + SupportComments Source } diff --git a/convert.go b/convert.go index ae68df0..dc53c1e 100644 --- a/convert.go +++ b/convert.go @@ -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: diff --git a/node.go b/node.go index 3b19a07..074be0e 100644 --- a/node.go +++ b/node.go @@ -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 } diff --git a/testdata/enums/enums.ts b/testdata/enums/enums.ts index 76bc778..6fecd38 100644 --- a/testdata/enums/enums.ts +++ b/testdata/enums/enums.ts @@ -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