Skip to content

Commit ede6dfb

Browse files
authored
fix(typescript_indexer): emit correct vnames for static methods (kythe#6151)
According to https://github.com/kythe/kythe/blob/master/kythe/typescript/SCHEMA.md#class-declaration static methods should get different vnames from instance methods. But currently static methods are treated as instance methods and vnames overlap. This PR fixes that. Note that static properties already work correctly.
1 parent c9e7eeb commit ede6dfb

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

kythe/typescript/indexer.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function hasExpressionInitializer(node: ts.Node):
7171
* Determines if a node is a static member of a class.
7272
*/
7373
function isStaticMember(node: ts.Node, klass: ts.Declaration): boolean {
74-
return ts.isPropertyDeclaration(node) && node.parent === klass &&
74+
return (ts.isPropertyDeclaration(node) || ts.isMethodDeclaration(node)) && node.parent === klass &&
7575
((ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Static) > 0);
7676
}
7777

@@ -1655,11 +1655,8 @@ class Visitor {
16551655
todo(this.sourceRoot, decl, 'Emit variable delaration code');
16561656
}
16571657

1658-
if (ts.isPropertyDeclaration(decl)) {
1659-
const declNode = decl as ts.PropertyDeclaration;
1660-
if (isStaticMember(declNode, declNode.parent)) {
1661-
this.emitFact(vname, FactName.TAG_STATIC, '');
1662-
}
1658+
if (ts.isPropertyDeclaration(decl) && isStaticMember(decl, decl.parent)) {
1659+
this.emitFact(vname, FactName.TAG_STATIC, '');
16631660
}
16641661
if (ts.isPropertySignature(decl) ||
16651662
ts.isPropertyDeclaration(decl) ||
@@ -2157,6 +2154,9 @@ class Visitor {
21572154
this.emitFact(vname, FactName.COMPLETE, 'incomplete');
21582155
}
21592156
this.emitMarkedSourceForFunction(decl, vname);
2157+
if (ts.isMethodDeclaration(decl) && isStaticMember(decl, decl.parent)) {
2158+
this.emitFact(vname, FactName.TAG_STATIC, '');
2159+
}
21602160
}
21612161

21622162
/**

kythe/typescript/testdata/class.ts

+7
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class Class implements IFace {
7979
this.method();
8080
}
8181

82+
//- @method defines/binding StaticMethod
83+
//- StaticMethod.tag/static _
84+
//- !{ @method defines/binding Method }
85+
//- StaticMethod.node/kind function
86+
//- StaticMethod childof Class
87+
static method() {}
88+
8289
//- @"#privateMethod" defines/binding PrivateMethod
8390
//- PrivateMethod.node/kind function
8491
//- PrivateMethod childof Class

0 commit comments

Comments
 (0)