@@ -7097,4 +7097,71 @@ namespace ts {
7097
7097
export function containsIgnoredPath ( path : string ) {
7098
7098
return some ( ignoredPaths , p => stringContains ( path , p ) ) ;
7099
7099
}
7100
+
7101
+ export function getContainingNodeArray ( node : Node ) : NodeArray < Node > | undefined {
7102
+ if ( ! node . parent ) return undefined ;
7103
+ switch ( node . kind ) {
7104
+ case SyntaxKind . TypeParameter :
7105
+ const { parent } = node as TypeParameterDeclaration ;
7106
+ return parent . kind === SyntaxKind . InferType ? undefined : parent . typeParameters ;
7107
+ case SyntaxKind . Parameter :
7108
+ return ( node as ParameterDeclaration ) . parent . parameters ;
7109
+ case SyntaxKind . TemplateLiteralTypeSpan :
7110
+ return ( node as TemplateLiteralTypeSpan ) . parent . templateSpans ;
7111
+ case SyntaxKind . TemplateSpan :
7112
+ return ( node as TemplateSpan ) . parent . templateSpans ;
7113
+ case SyntaxKind . Decorator :
7114
+ return ( node as Decorator ) . parent . decorators ;
7115
+ case SyntaxKind . HeritageClause :
7116
+ return ( node as HeritageClause ) . parent . heritageClauses ;
7117
+ }
7118
+
7119
+ const { parent } = node ;
7120
+ if ( isJSDocTag ( node ) ) {
7121
+ return isJSDocTypeLiteral ( node . parent ) ? undefined : node . parent . tags ;
7122
+ }
7123
+
7124
+ switch ( parent . kind ) {
7125
+ case SyntaxKind . TypeLiteral :
7126
+ case SyntaxKind . InterfaceDeclaration :
7127
+ return isTypeElement ( node ) ? ( parent as TypeLiteralNode | InterfaceDeclaration ) . members : undefined ;
7128
+ case SyntaxKind . UnionType :
7129
+ case SyntaxKind . IntersectionType :
7130
+ return ( parent as UnionOrIntersectionTypeNode ) . types ;
7131
+ case SyntaxKind . TupleType :
7132
+ case SyntaxKind . ArrayLiteralExpression :
7133
+ case SyntaxKind . CommaListExpression :
7134
+ case SyntaxKind . NamedImports :
7135
+ case SyntaxKind . NamedExports :
7136
+ return ( parent as TupleTypeNode | ArrayLiteralExpression | CommaListExpression | NamedImports | NamedExports ) . elements ;
7137
+ case SyntaxKind . ObjectLiteralExpression :
7138
+ case SyntaxKind . JsxAttributes :
7139
+ return ( parent as ObjectLiteralExpressionBase < ObjectLiteralElement > ) . properties ;
7140
+ case SyntaxKind . CallExpression :
7141
+ case SyntaxKind . NewExpression :
7142
+ return isTypeNode ( node ) ? ( parent as CallExpression | NewExpression ) . typeArguments :
7143
+ ( parent as CallExpression | NewExpression ) . expression === node ? undefined :
7144
+ ( parent as CallExpression | NewExpression ) . arguments ;
7145
+ case SyntaxKind . JsxElement :
7146
+ case SyntaxKind . JsxFragment :
7147
+ return isJsxChild ( node ) ? ( parent as JsxElement | JsxFragment ) . children : undefined ;
7148
+ case SyntaxKind . JsxOpeningElement :
7149
+ case SyntaxKind . JsxSelfClosingElement :
7150
+ return isTypeNode ( node ) ? ( parent as JsxOpeningElement | JsxSelfClosingElement ) . typeArguments : undefined ;
7151
+ case SyntaxKind . Block :
7152
+ case SyntaxKind . CaseClause :
7153
+ case SyntaxKind . DefaultClause :
7154
+ case SyntaxKind . ModuleBlock :
7155
+ return ( parent as Block | CaseOrDefaultClause | ModuleBlock ) . statements ;
7156
+ case SyntaxKind . CaseBlock :
7157
+ return ( parent as CaseBlock ) . clauses ;
7158
+ case SyntaxKind . ClassDeclaration :
7159
+ case SyntaxKind . ClassExpression :
7160
+ return isClassElement ( node ) ? ( parent as ClassLikeDeclaration ) . members : undefined ;
7161
+ case SyntaxKind . EnumDeclaration :
7162
+ return isEnumMember ( node ) ? ( parent as EnumDeclaration ) . members : undefined ;
7163
+ case SyntaxKind . SourceFile :
7164
+ return ( parent as SourceFile ) . statements ;
7165
+ }
7166
+ }
7100
7167
}
0 commit comments