MCPcopy Index your code
hub / github.com/coder/guts / ToTypescript

Method ToTypescript

convert.go:185–216  ·  view source on GitHub ↗

ToTypescript translates the Go types into the intermediate typescript AST The returned typescript object can be mutated before serializing.

()

Source from the content-addressed store, hash-verified

183// ToTypescript translates the Go types into the intermediate typescript AST
184// The returned typescript object can be mutated before serializing.
185func (p *GoParser) ToTypescript() (*Typescript, error) {
186 typescript := &Typescript{
187 typescriptNodes: make(map[string]*typescriptNode),
188 parsed: p,
189 skip: p.Skips,
190 preserveComments: p.preserveComments,
191 }
192
193 // Parse all go types to the typescript AST
194 err := typescript.parseGolangIdentifiers()
195 if err != nil {
196 return nil, err
197 }
198
199 // Apply any post-processing mutations to the nodes.
200 for key, node := range typescript.typescriptNodes {
201 newNode, err := node.applyMutations()
202 if err != nil {
203 return nil, fmt.Errorf("node %q: %w", key, err)
204 }
205
206 // If the Node is nil, then it serves no purpose and can be
207 // removed from the typescriptNodes map.
208 if newNode.Node == nil {
209 delete(typescript.typescriptNodes, key)
210 } else {
211 typescript.typescriptNodes[key] = &newNode
212 }
213 }
214
215 return typescript, nil
216}
217
218type Typescript struct {
219 // typescriptNodes is a map of typescript nodes that are generated from the

Callers 5

loadTypescriptFunction · 0.80
ExampleNewGolangParserFunction · 0.80
TestGenerationFunction · 0.80
TestNotNullMapsFunction · 0.80
mainFunction · 0.80

Calls 2

applyMutationsMethod · 0.80

Tested by 4

loadTypescriptFunction · 0.64
ExampleNewGolangParserFunction · 0.64
TestGenerationFunction · 0.64
TestNotNullMapsFunction · 0.64