From 5be548c0f568528a19cb8803f0bedf041477ac51 Mon Sep 17 00:00:00 2001 From: Jia Xiaodong Date: Fri, 4 Oct 2019 10:12:12 +0800 Subject: [PATCH] Name anonymous functions with more details (#355) * 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 --- src/closure.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/closure.ts b/src/closure.ts index 51d401dbc..f84fe0df3 100644 --- a/src/closure.ts +++ b/src/closure.ts @@ -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 @@ -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.