MCPcopy Create free account
hub / github.com/coder/guts / ToTypescriptNode

Method ToTypescriptNode

bindings/bindings.go:25–74  ·  view source on GitHub ↗
(ety Node)

Source from the content-addressed store, hash-verified

23}
24
25func (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
76func (b *Bindings) ToTypescriptDeclarationNode(ety DeclarationType) (*goja.Object, error) {
77 var siObj *goja.Object

Callers 15

ReferenceMethod · 0.95
PropertySignatureMethod · 0.95
InterfaceMethod · 0.95
ArrayMethod · 0.95
TupleMethod · 0.95
AliasMethod · 0.95
UnionMethod · 0.95
ArrayLiteralMethod · 0.95
VariableStatementMethod · 0.95
VariableDeclarationMethod · 0.95
OperatorNodeMethod · 0.95

Calls 10

HeritageClauseMethod · 0.95
PropertySignatureMethod · 0.95
TypeParameterMethod · 0.95
PropertyAssignmentMethod · 0.95
ParameterMethod · 0.95
CommentGojaObjectMethod · 0.95
SourceCommentMethod · 0.65
CommentsMethod · 0.65

Tested by 3

roundTripFunction · 0.64
TestImportDeclarationFunction · 0.64
TestSyntheticCommentsFunction · 0.64