@@ -91,6 +91,7 @@ import {
91
91
ParameterDeclaration ,
92
92
Program ,
93
93
PropertyAccessExpression ,
94
+ PropertyDeclaration ,
94
95
SatisfiesExpression ,
95
96
SetAccessorDeclaration ,
96
97
skipTrivia ,
@@ -117,18 +118,27 @@ function isNamedExpression(node: Node): node is NamedExpression {
117
118
}
118
119
119
120
/** @internal */
120
- export type ConstNamedExpression =
121
- | ClassExpression & { name : undefined ; parent : VariableDeclaration & { name : Identifier ; } ; }
122
- | FunctionExpression & { name : undefined ; parent : VariableDeclaration & { name : Identifier ; } ; }
123
- | ArrowFunction & { name : undefined ; parent : VariableDeclaration & { name : Identifier ; } ; } ;
121
+ export type VariableLike =
122
+ | VariableDeclaration
123
+ | PropertyDeclaration ;
124
124
125
- /** Indicates whether a node is a function, arrow, or class expression assigned to a constant variable. */
126
- function isConstNamedExpression ( node : Node ) : node is ConstNamedExpression {
125
+ function isVariableLike ( node : Node ) : node is VariableLike {
126
+ return isPropertyDeclaration ( node ) || isVariableDeclaration ( node ) ;
127
+ }
128
+
129
+ /** @internal */
130
+ export type AssignedExpression =
131
+ | ClassExpression & { name : undefined ; parent : VariableLike & { name : Identifier ; } ; }
132
+ | FunctionExpression & { name : undefined ; parent : VariableLike & { name : Identifier ; } ; }
133
+ | ArrowFunction & { name : undefined ; parent : VariableLike & { name : Identifier ; } ; } ;
134
+
135
+ /** Indicates whether a node is a function, arrow, or class expression assigned to a constant variable or class property. */
136
+ function isAssignedExpression ( node : Node ) : node is AssignedExpression {
127
137
return ( isFunctionExpression ( node ) || isArrowFunction ( node ) || isClassExpression ( node ) )
128
- && isVariableDeclaration ( node . parent )
138
+ && isVariableLike ( node . parent )
129
139
&& node === node . parent . initializer
130
140
&& isIdentifier ( node . parent . name )
131
- && ! ! ( getCombinedNodeFlags ( node . parent ) & NodeFlags . Const ) ;
141
+ && ( ! ! ( getCombinedNodeFlags ( node . parent ) & NodeFlags . Const ) || isPropertyDeclaration ( node . parent ) ) ;
132
142
}
133
143
134
144
/** @internal */
@@ -142,7 +152,7 @@ export type CallHierarchyDeclaration =
142
152
| GetAccessorDeclaration
143
153
| SetAccessorDeclaration
144
154
| NamedExpression
145
- | ConstNamedExpression ;
155
+ | AssignedExpression ;
146
156
147
157
/**
148
158
* Indicates whether a node could possibly be a call hierarchy declaration.
@@ -179,14 +189,14 @@ function isValidCallHierarchyDeclaration(node: Node): node is CallHierarchyDecla
179
189
|| isGetAccessorDeclaration ( node )
180
190
|| isSetAccessorDeclaration ( node )
181
191
|| isNamedExpression ( node )
182
- || isConstNamedExpression ( node ) ;
192
+ || isAssignedExpression ( node ) ;
183
193
}
184
194
185
195
/** Gets the node that can be used as a reference to a call hierarchy declaration. */
186
196
function getCallHierarchyDeclarationReferenceNode ( node : Exclude < CallHierarchyDeclaration , ClassStaticBlockDeclaration > ) {
187
197
if ( isSourceFile ( node ) ) return node ;
188
198
if ( isNamedDeclaration ( node ) ) return node . name ;
189
- if ( isConstNamedExpression ( node ) ) return node . parent . name ;
199
+ if ( isAssignedExpression ( node ) ) return node . parent . name ;
190
200
return Debug . checkDefined ( node . modifiers && find ( node . modifiers , isDefaultModifier ) ) ;
191
201
}
192
202
@@ -223,7 +233,7 @@ function getCallHierarchyItemName(program: Program, node: CallHierarchyDeclarati
223
233
return { text : `${ prefix } static {}` , pos, end } ;
224
234
}
225
235
226
- const declName = isConstNamedExpression ( node ) ? node . parent . name :
236
+ const declName = isAssignedExpression ( node ) ? node . parent . name :
227
237
Debug . checkDefined ( getNameOfDeclaration ( node ) , "Expected call hierarchy item to have a name" ) ;
228
238
229
239
let text = isIdentifier ( declName ) ? idText ( declName ) :
@@ -248,7 +258,10 @@ function getCallHierarchyItemName(program: Program, node: CallHierarchyDeclarati
248
258
}
249
259
250
260
function getCallHierarchItemContainerName ( node : CallHierarchyDeclaration ) : string | undefined {
251
- if ( isConstNamedExpression ( node ) ) {
261
+ if ( isAssignedExpression ( node ) ) {
262
+ if ( isPropertyDeclaration ( node . parent ) && isClassLike ( node . parent . parent ) ) {
263
+ return isClassExpression ( node . parent . parent ) ? getAssignedName ( node . parent . parent ) ?. getText ( ) : node . parent . parent . name ?. getText ( ) ;
264
+ }
252
265
if ( isModuleBlock ( node . parent . parent . parent . parent ) && isIdentifier ( node . parent . parent . parent . parent . parent . name ) ) {
253
266
return node . parent . parent . parent . parent . parent . name . getText ( ) ;
254
267
}
@@ -364,7 +377,7 @@ export function resolveCallHierarchyDeclaration(program: Program, location: Node
364
377
const ancestor = findAncestor ( location . parent , isValidCallHierarchyDeclaration ) ;
365
378
return ancestor && findImplementationOrAllInitialDeclarations ( typeChecker , ancestor ) ;
366
379
}
367
- if ( isVariableDeclaration ( location . parent ) && location . parent . initializer && isConstNamedExpression ( location . parent . initializer ) ) {
380
+ if ( isVariableLike ( location . parent ) && location . parent . initializer && isAssignedExpression ( location . parent . initializer ) ) {
368
381
return location . parent . initializer ;
369
382
}
370
383
return undefined ;
@@ -380,7 +393,7 @@ export function resolveCallHierarchyDeclaration(program: Program, location: Node
380
393
continue ;
381
394
}
382
395
// #39453
383
- if ( isVariableDeclaration ( location ) && location . initializer && isConstNamedExpression ( location . initializer ) ) {
396
+ if ( isVariableDeclaration ( location ) && location . initializer && isAssignedExpression ( location . initializer ) ) {
384
397
return location . initializer ;
385
398
}
386
399
if ( ! followingSymbol ) {
0 commit comments