@@ -9,8 +9,9 @@ namespace ts.SymbolDisplay {
9
9
10
10
const flags = getCombinedLocalAndExportSymbolFlags ( symbol ) ;
11
11
if ( flags & SymbolFlags . Class ) {
12
- return getDeclarationOfKind ( symbol , SyntaxKind . ClassExpression ) ?
13
- ScriptElementKind . localClassElement : ScriptElementKind . classElement ;
12
+ const callExpressionLike = getCallExpressionLike ( climbParentPropertyAccesses ( location ) , symbol ) ;
13
+ return callExpressionLike && shouldUseConstructSignatures ( callExpressionLike ) ? ScriptElementKind . constructorImplementationElement
14
+ : getDeclarationOfKind ( symbol , SyntaxKind . ClassExpression ) ? ScriptElementKind . localClassElement : ScriptElementKind . classElement ;
14
15
}
15
16
if ( flags & SymbolFlags . Enum ) return ScriptElementKind . enumElement ;
16
17
if ( flags & SymbolFlags . TypeAlias ) return ScriptElementKind . typeElement ;
@@ -146,31 +147,15 @@ namespace ts.SymbolDisplay {
146
147
let signature : Signature ;
147
148
type = isThisExpression ? typeChecker . getTypeAtLocation ( location ) : typeChecker . getTypeOfSymbolAtLocation ( symbol . exportSymbol || symbol , location ) ;
148
149
149
- if ( location . parent && location . parent . kind === SyntaxKind . PropertyAccessExpression ) {
150
- const right = ( < PropertyAccessExpression > location . parent ) . name ;
151
- // Either the location is on the right of a property access, or on the left and the right is missing
152
- if ( right === location || ( right && right . getFullWidth ( ) === 0 ) ) {
153
- location = location . parent ;
154
- }
155
- }
150
+ location = climbParentPropertyAccesses ( location ) ;
156
151
157
152
// try get the call/construct signature from the type if it matches
158
- let callExpressionLike : CallExpression | NewExpression | JsxOpeningLikeElement ;
159
- if ( isCallOrNewExpression ( location ) ) {
160
- callExpressionLike = location ;
161
- }
162
- else if ( isCallExpressionTarget ( location ) || isNewExpressionTarget ( location ) ) {
163
- callExpressionLike = < CallExpression | NewExpression > location . parent ;
164
- }
165
- else if ( location . parent && isJsxOpeningLikeElement ( location . parent ) && isFunctionLike ( symbol . valueDeclaration ) ) {
166
- callExpressionLike = location . parent ;
167
- }
168
-
153
+ const callExpressionLike = getCallExpressionLike ( location , symbol ) ;
169
154
if ( callExpressionLike ) {
170
155
const candidateSignatures : Signature [ ] = [ ] ;
171
156
signature = typeChecker . getResolvedSignature ( callExpressionLike , candidateSignatures ) ;
172
157
173
- const useConstructSignatures = callExpressionLike . kind === SyntaxKind . NewExpression || ( isCallExpression ( callExpressionLike ) && callExpressionLike . expression . kind === SyntaxKind . SuperKeyword ) ;
158
+ const useConstructSignatures = shouldUseConstructSignatures ( callExpressionLike ) ;
174
159
175
160
const allSignatures = useConstructSignatures ? type . getConstructSignatures ( ) : type . getCallSignatures ( ) ;
176
161
@@ -651,4 +636,31 @@ namespace ts.SymbolDisplay {
651
636
return true ;
652
637
} ) ;
653
638
}
639
+
640
+ type CallExpressionLike = CallExpression | NewExpression | JsxOpeningLikeElement | undefined ;
641
+ function getCallExpressionLike ( location : Node , symbol : Symbol ) : CallExpressionLike {
642
+ if ( isCallOrNewExpression ( location ) ) {
643
+ return location ;
644
+ }
645
+ else if ( isCallExpressionTarget ( location ) || isNewExpressionTarget ( location ) ) {
646
+ return < CallExpression | NewExpression > location . parent ;
647
+ }
648
+ else if ( location . parent && isJsxOpeningLikeElement ( location . parent ) && isFunctionLike ( symbol . valueDeclaration ) ) {
649
+ return location . parent ;
650
+ }
651
+ }
652
+ function shouldUseConstructSignatures ( callExpressionLike : CallExpressionLike ) : boolean {
653
+ return callExpressionLike . kind === SyntaxKind . NewExpression || ( isCallExpression ( callExpressionLike ) && callExpressionLike . expression . kind === SyntaxKind . SuperKeyword ) ;
654
+ }
655
+
656
+ function climbParentPropertyAccesses ( node : Node ) : Node {
657
+ if ( node . parent && isPropertyAccessExpression ( node . parent ) ) {
658
+ const { name } = node . parent ;
659
+ // Either the location is on the right of a property access, or on the left and the right is missing
660
+ if ( node === name || ( name && name . getFullWidth ( ) === 0 ) ) {
661
+ return node . parent ;
662
+ }
663
+ }
664
+ return node ;
665
+ }
654
666
}
0 commit comments