Skip to content

Commit

Permalink
Name anonymous functions with more details (#355)
Browse files Browse the repository at this point in the history
* name anonymous functions more detailed

* Update src/closure.ts

Co-Authored-By: Open O. Close <3646725+openorclose@users.noreply.github.com>

* anonyomous functions identified by their parameters

* single parameter prettier now

* single parameter prettier now
  • Loading branch information
podocarp authored and openorclose committed Oct 4, 2019
1 parent 3d3fc4c commit 5be548c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/closure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ export default class Closure extends Callable {
return closure
}

/** Keep track how many lambdas are created */
private static lambdaCtr = 0

/** Unique ID defined for anonymous closure */
public functionName: string

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

0 comments on commit 5be548c

Please sign in to comment.