| 23 | } |
| 24 | |
| 25 | func (b *Bindings) ToTypescriptNode(ety Node) (*goja.Object, error) { |
| 26 | var siObj *goja.Object |
| 27 | var err error |
| 28 | |
| 29 | switch node := ety.(type) { |
| 30 | case *HeritageClause: |
| 31 | siObj, err = b.HeritageClause(node) |
| 32 | case *PropertySignature: |
| 33 | siObj, err = b.PropertySignature(node) |
| 34 | case *TypeParameter: |
| 35 | siObj, err = b.TypeParameter(node) |
| 36 | case *PropertyAssignment: |
| 37 | siObj, err = b.PropertyAssignment(node) |
| 38 | case *Parameter: |
| 39 | siObj, err = b.Parameter(node) |
| 40 | case DeclarationType: |
| 41 | // Defer to the ExpressionType implementation |
| 42 | siObj, err = b.ToTypescriptDeclarationNode(node) |
| 43 | case ExpressionType: |
| 44 | // Defer to the ExpressionType implementation |
| 45 | siObj, err = b.ToTypescriptExpressionNode(node) |
| 46 | default: |
| 47 | return nil, fmt.Errorf("unsupported node type for typescript serialization: %T", node) |
| 48 | } |
| 49 | |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | |
| 54 | // Append any source comments |
| 55 | if hasSource, ok := ety.(HasSource); ok { |
| 56 | cmt, set := hasSource.SourceComment() |
| 57 | if set { |
| 58 | siObj, err = b.CommentGojaObject([]SyntheticComment{cmt}, siObj) |
| 59 | if err != nil { |
| 60 | return nil, xerrors.Errorf("source comment declaration: %w", err) |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // Append any other comments |
| 66 | if commented, ok := ety.(Commentable); ok { |
| 67 | siObj, err = b.CommentGojaObject(commented.Comments(), siObj) |
| 68 | if err != nil { |
| 69 | return nil, xerrors.Errorf("comment declaration: %w", err) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | return siObj, nil |
| 74 | } |
| 75 | |
| 76 | func (b *Bindings) ToTypescriptDeclarationNode(ety DeclarationType) (*goja.Object, error) { |
| 77 | var siObj *goja.Object |