MCPcopy Create free account
hub / github.com/microsoft/typescript-go / mapToTypeNodes

Method mapToTypeNodes

internal/checker/nodebuilderimpl.go:337–428  ·  view source on GitHub ↗
(list []*Type, isBareList bool)

Source from the content-addressed store, hash-verified

335}
336
337func (b *NodeBuilderImpl) mapToTypeNodes(list []*Type, isBareList bool) *ast.NodeList {
338 if len(list) == 0 {
339 return nil
340 }
341
342 if b.checkTruncationLength() {
343 if !isBareList {
344 var node *ast.Node
345 if b.ctx.flags&nodebuilder.FlagsNoTruncation != 0 {
346 node = b.e.AddSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, "elided", false /*hasTrailingNewLine*/)
347 } else {
348 node = b.f.NewTypeReferenceNode(b.f.NewIdentifier("..."), nil /*typeArguments*/)
349 }
350 return b.f.NewNodeList([]*ast.Node{node})
351 } else if len(list) > 2 {
352 nodes := []*ast.Node{
353 b.typeToTypeNode(list[0]),
354 nil,
355 b.typeToTypeNode(list[len(list)-1]),
356 }
357
358 if b.ctx.flags&nodebuilder.FlagsNoTruncation != 0 {
359 nodes[1] = b.e.AddSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, fmt.Sprintf("... %d more elided ...", len(list)-2), false /*hasTrailingNewLine*/)
360 } else {
361 text := fmt.Sprintf("... %d more ...", len(list)-2)
362 nodes[1] = b.f.NewTypeReferenceNode(b.f.NewIdentifier(text), nil /*typeArguments*/)
363 }
364 return b.f.NewNodeList(nodes)
365 }
366 }
367
368 mayHaveNameCollisions := b.ctx.flags&nodebuilder.FlagsUseFullyQualifiedType == 0
369 type seenName struct {
370 t *Type
371 i int
372 }
373 var seenNames *collections.MultiMap[string, seenName]
374 if mayHaveNameCollisions {
375 seenNames = &collections.MultiMap[string, seenName]{}
376 }
377
378 result := make([]*ast.Node, 0, len(list))
379
380 for i, t := range list {
381 displayIndex := i + 1
382 if b.checkTruncationLength() && (displayIndex+2 < len(list)-1) {
383 if b.ctx.flags&nodebuilder.FlagsNoTruncation != 0 {
384 result = append(result, b.e.AddSyntheticLeadingComment(b.f.NewKeywordTypeNode(ast.KindAnyKeyword), ast.KindMultiLineCommentTrivia, fmt.Sprintf("... %d more elided ...", len(list)-displayIndex), false /*hasTrailingNewLine*/))
385 } else {
386 text := fmt.Sprintf("... %d more ...", len(list)-displayIndex)
387 result = append(result, b.f.NewTypeReferenceNode(b.f.NewIdentifier(text), nil /*typeArguments*/))
388 }
389 typeNode := b.typeToTypeNode(list[len(list)-1])
390 if typeNode != nil {
391 result = append(result, typeNode)
392 }
393 break
394 }

Callers 4

typeToTypeNodeMethod · 0.95
ToTypeReferenceNodeMethod · 0.80

Calls 15

checkTruncationLengthMethod · 0.95
typeToTypeNodeMethod · 0.95
saveRestoreFlagsMethod · 0.95
lenFunction · 0.85
arrayIsHomogeneousFunction · 0.85
typesAreSameReferenceFunction · 0.85
NewKeywordTypeNodeMethod · 0.80
NewTypeReferenceNodeMethod · 0.80
NewIdentifierMethod · 0.80
NewNodeListMethod · 0.80

Tested by

no test coverage detected