Skip to content

Commit 511c955

Browse files
committed
Add go-to-definition support on 'instanceof' keyword
1 parent 6a83254 commit 511c955

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-1
lines changed

src/compiler/checker.ts

+15
Original file line numberDiff line numberDiff line change
@@ -45992,6 +45992,21 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4599245992
case SyntaxKind.ImportKeyword:
4599345993
case SyntaxKind.NewKeyword:
4599445994
return isMetaProperty(node.parent) ? checkMetaPropertyKeyword(node.parent).symbol : undefined;
45995+
case SyntaxKind.InstanceOfKeyword:
45996+
if (isBinaryExpression(node.parent)) {
45997+
const type = getTypeOfExpression(node.parent.right);
45998+
const hasInstanceMethodType = getSymbolHasInstanceMethodOfObjectType(type);
45999+
// const hasInstancePropertyName = getPropertyNameForKnownSymbolName("hasInstance");
46000+
// const hasInstanceProperty = getPropertyOfObjectType(type, hasInstancePropertyName);
46001+
// if (hasInstanceProperty) {
46002+
// const hasInstancePropertyType = getTypeOfSymbol(hasInstanceProperty);
46003+
// if (hasInstancePropertyType && getSignaturesOfType(hasInstancePropertyType, SignatureKind.Call).length !== 0) {
46004+
// return hasInstanceProperty;
46005+
// }
46006+
// }
46007+
return hasInstanceMethodType?.symbol ?? type.symbol;
46008+
}
46009+
return undefined;
4599546010
case SyntaxKind.MetaProperty:
4599646011
return checkExpression(node as Expression).symbol;
4599746012
case SyntaxKind.JsxNamespacedName:

src/services/goToDefinition.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ import {
101101
TypeChecker,
102102
TypeFlags,
103103
TypeReference,
104-
unescapeLeadingUnderscores,
104+
unescapeLeadingUnderscores
105105
} from "./_namespaces/ts";
106106

107107
/** @internal */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// === goToDefinition ===
2+
// === /tests/cases/fourslash/goToDefinitionInstanceof1.ts ===
3+
// <|class [|C|] {
4+
// }|>
5+
// declare var obj: any;
6+
// obj /*GOTO DEF*/instanceof C;
7+
8+
// === Details ===
9+
[
10+
{
11+
"kind": "class",
12+
"name": "C",
13+
"containerName": "",
14+
"isLocal": false,
15+
"isAmbient": false,
16+
"unverified": false,
17+
"failedAliasResolution": false
18+
}
19+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// === goToDefinition ===
2+
// === /main.ts ===
3+
// class C {
4+
// <|static [|[Symbol.hasInstance]|](value: unknown): boolean { return true; }|>
5+
// }
6+
// declare var obj: any;
7+
// obj /*GOTO DEF*/instanceof C;
8+
9+
// === Details ===
10+
[
11+
{
12+
"kind": "method",
13+
"name": "[Symbol.hasInstance]",
14+
"containerName": "C",
15+
"isLocal": false,
16+
"isAmbient": false,
17+
"unverified": false,
18+
"failedAliasResolution": false
19+
}
20+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// class /*end*/ C {
4+
//// }
5+
//// declare var obj: any;
6+
//// obj [|/*start*/instanceof|] C;
7+
8+
verify.baselineGoToDefinition("start");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @lib: esnext
4+
// @filename: /main.ts
5+
//// class C {
6+
//// static /*end*/[Symbol.hasInstance](value: unknown): boolean { return true; }
7+
//// }
8+
//// declare var obj: any;
9+
//// obj [|/*start*/instanceof|] C;
10+
11+
verify.baselineGoToDefinition("start");

0 commit comments

Comments
 (0)