Skip to content

Commit

Permalink
feat(typescript): use unique vnames for anonymous functions (#5593)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbeloglazov committed Apr 21, 2023
1 parent eb169e6 commit 7ef0880
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions kythe/typescript/indexer.ts
Expand Up @@ -1270,8 +1270,7 @@ class Visitor {
const vname = this.host.getSymbolName(sym, TSNamespace.VALUE, context);
return {sym, vname};
} else {
// TODO: choose VName for anonymous functions and return symbol
return {vname: this.newVName('TODO', 'TODOPath')};
return {vname: this.host.scopedSignature(node)};
}
}

Expand Down Expand Up @@ -2666,6 +2665,7 @@ class Visitor {
case ts.SyntaxKind.ArrowFunction:
case ts.SyntaxKind.Constructor:
case ts.SyntaxKind.FunctionDeclaration:
case ts.SyntaxKind.FunctionExpression:
case ts.SyntaxKind.MethodDeclaration:
case ts.SyntaxKind.MethodSignature:
case ts.SyntaxKind.GetAccessor:
Expand Down
17 changes: 17 additions & 0 deletions kythe/typescript/testdata/anonymous.ts
@@ -0,0 +1,17 @@

function takeAnything(a: any) {}

takeAnything(
//- @"() => {}" defines vname("arrow0", _, _, _, _)
() => {}
);

takeAnything(
//- @"() => {}" defines vname("arrow1", _, _, _, _)
() => {}
);

takeAnything(
//- @"function() {}" defines vname("func2", _, _, _, _)
function() {}
)
3 changes: 2 additions & 1 deletion kythe/typescript/testdata/marked_source/function.ts
Expand Up @@ -53,4 +53,5 @@
//- ArgCodeDefaultValue.pre_text "'0'"
function myFunction(arg: string = '0'): number {
return 0;
}
}

0 comments on commit 7ef0880

Please sign in to comment.