From cf6da4743efe59fa9ec39532712cbf2a82e8b877 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Sat, 26 Sep 2020 17:30:18 -0500 Subject: [PATCH] js: use more descriptive script names --- src/compiler/jsgen.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/compiler/jsgen.js b/src/compiler/jsgen.js index b5a3e6dc..744e71c0 100644 --- a/src/compiler/jsgen.js +++ b/src/compiler/jsgen.js @@ -968,6 +968,22 @@ class JSGenerator { return result; } + getScriptFactoryName () { + return factoryNameVariablePool.next(); + } + + getScriptName (yields) { + let name = yields ? generatorNameVariablePool.next() : functionNameVariablePool.next(); + if (this.isProcedure) { + const simplifiedProcedureCode = this.script.procedureCode + .replace(/%[\w]/g, '') // remove arguments + .replace(/[^a-zA-Z0-9]/g, '_') // remove unsafe + .substring(0, 20); // keep length reasonable + name += `_${simplifiedProcedureCode}`; + } + return name; + } + /** * Generate the JS to pass into eval() based on the current state of the compiler. * @returns {string} JS to pass into eval() @@ -976,7 +992,7 @@ class JSGenerator { let script = ''; // Setup the factory - script += `(function ${factoryNameVariablePool.next()}(target) { `; + script += `(function ${this.getScriptFactoryName()}(target) { `; script += 'const runtime = target.runtime; '; script += 'const stage = runtime.getTargetForStage();\n'; for (const varValue of Object.keys(this._setupVariables)) { @@ -987,11 +1003,12 @@ class JSGenerator { // Generated script script += 'return '; if (this.script.yields) { - script += `function* ${generatorNameVariablePool.next()} `; + script += `function* `; } else { - script += `function ${functionNameVariablePool.next()} `; + script += `function `; } - script += '('; + script += this.getScriptName(this.script.yields); + script += ' ('; if (this.script.arguments.length) { const args = []; for (let i = 0; i < this.script.arguments.length; i++) {