MCPcopy Index your code
hub / github.com/microsoft/typescript-go / getContainingNodeArray

Function getContainingNodeArray

internal/printer/utilities.go:443–551  ·  view source on GitHub ↗
(node *ast.Node)

Source from the content-addressed store, hash-verified

441}
442
443func getContainingNodeArray(node *ast.Node) *ast.NodeList {
444 parent := node.Parent
445 if parent == nil {
446 return nil
447 }
448
449 switch node.Kind {
450 case ast.KindTypeParameter:
451 switch {
452 case ast.IsFunctionLike(parent) || ast.IsClassLike(parent) || ast.IsInterfaceDeclaration(parent) || ast.IsTypeOrJSTypeAliasDeclaration(parent):
453 return parent.TypeParameterList()
454 case ast.IsInferTypeNode(parent):
455 break
456 default:
457 panic(fmt.Sprintf("Unexpected TypeParameter parent: %#v", parent.Kind))
458 }
459
460 case ast.KindParameter:
461 return node.Parent.FunctionLikeData().Parameters
462 case ast.KindTemplateLiteralTypeSpan:
463 return node.Parent.AsTemplateLiteralTypeNode().TemplateSpans
464 case ast.KindTemplateSpan:
465 return node.Parent.AsTemplateExpression().TemplateSpans
466 case ast.KindDecorator:
467 if canHaveDecorators(node.Parent) {
468 if modifiers := node.Parent.Modifiers(); modifiers != nil {
469 return &modifiers.NodeList
470 }
471 }
472 return nil
473 case ast.KindHeritageClause:
474 if ast.IsClassLike(node.Parent) {
475 return node.Parent.ClassLikeData().HeritageClauses
476 } else {
477 return node.Parent.AsInterfaceDeclaration().HeritageClauses
478 }
479 }
480
481 // TODO(rbuckton)
482 // if ast.IsJSDocTag(node) {
483 // if ast.IsJSDocTypeLiteral(node.parent) {
484 // return nil
485 // }
486 // return node.parent.tags
487 // }
488
489 switch parent.Kind {
490 case ast.KindTypeLiteral, ast.KindInterfaceDeclaration:
491 if ast.IsTypeElement(node) {
492 return parent.MemberList()
493 }
494 case ast.KindUnionType:
495 return parent.AsUnionTypeNode().Types
496 case ast.KindIntersectionType:
497 return parent.AsIntersectionTypeNode().Types
498 case ast.KindArrayLiteralExpression, ast.KindTupleType, ast.KindNamedImports, ast.KindNamedExports:
499 return parent.ElementList()
500 case ast.KindObjectLiteralExpression, ast.KindJsxAttributes:

Callers 1

Calls 15

IsFunctionLikeFunction · 0.92
IsClassLikeFunction · 0.92
IsInterfaceDeclarationFunction · 0.92
IsInferTypeNodeFunction · 0.92
IsTypeElementFunction · 0.92
IsTypeNodeFunction · 0.92
IsJsxChildFunction · 0.92
IsClassElementFunction · 0.92
IsEnumMemberFunction · 0.92
IsStatementFunction · 0.92
IsModifierFunction · 0.92

Tested by

no test coverage detected