Skip to content

Commit 5be548c

Browse files
podocarpopenorclose
authored andcommitted
Name anonymous functions with more details (#355)
* name anonymous functions more detailed * Update src/closure.ts Co-Authored-By: Open O. Close <[email protected]> * anonyomous functions identified by their parameters * single parameter prettier now * single parameter prettier now
1 parent 3d3fc4c commit 5be548c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/closure.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ export default class Closure extends Callable {
6767
return closure
6868
}
6969

70-
/** Keep track how many lambdas are created */
71-
private static lambdaCtr = 0
72-
7370
/** Unique ID defined for anonymous closure */
7471
public functionName: string
7572

@@ -88,7 +85,11 @@ export default class Closure extends Callable {
8885
if (this.node.type === 'FunctionDeclaration' && this.node.id !== null) {
8986
this.functionName = this.node.id.name
9087
} else {
91-
this.functionName = `Anonymous${++Closure.lambdaCtr}`
88+
this.functionName =
89+
(this.node.params.length === 1 ? '' : '(') +
90+
this.node.params.map((o: es.Identifier) => o.name).join(', ') +
91+
(this.node.params.length === 1 ? '' : ')') +
92+
' => ...'
9293
}
9394
// TODO: Investigate how relevant this really is.
9495
// .fun seems to only be used in interpreter's NewExpression handler, which uses .fun.prototype.

0 commit comments

Comments
 (0)