Skip to content

Commit 986532d

Browse files
author
Andy
authored
Fix bug: In findAllReferences, don't crash on static method missing body (microsoft#24814)
1 parent 3f8661b commit 986532d

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/services/findAllReferences.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,14 +1035,16 @@ namespace ts.FindAllReferences.Core {
10351035
if (!(isMethodOrAccessor(member) && hasModifier(member, ModifierFlags.Static))) {
10361036
continue;
10371037
}
1038-
member.body!.forEachChild(function cb(node) {
1039-
if (node.kind === SyntaxKind.ThisKeyword) {
1040-
addRef(node);
1041-
}
1042-
else if (!isFunctionLike(node)) {
1043-
node.forEachChild(cb);
1044-
}
1045-
});
1038+
if (member.body) {
1039+
member.body.forEachChild(function cb(node) {
1040+
if (node.kind === SyntaxKind.ThisKeyword) {
1041+
addRef(node);
1042+
}
1043+
else if (!isFunctionLike(node)) {
1044+
node.forEachChild(cb);
1045+
}
1046+
});
1047+
}
10461048
}
10471049
}
10481050

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////declare class [|{| "isWriteAccess": true, "isDefinition": true |}C|] {
4+
//// static m(): void;
5+
////}
6+
7+
verify.singleReferenceGroup("class C");

0 commit comments

Comments
 (0)