From 507aa8af935d12544f7bd8aa0d130f2e8ebb7825 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 31 Jan 2024 17:05:20 +0100 Subject: [PATCH] Simplify and remove magic strings --- packages/server/src/jsRunner.ts | 4 +--- packages/string-templates/src/helpers/javascript.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/server/src/jsRunner.ts b/packages/server/src/jsRunner.ts index 5b7bbf34ae..5e8aa2d1e1 100644 --- a/packages/server/src/jsRunner.ts +++ b/packages/server/src/jsRunner.ts @@ -107,10 +107,8 @@ export function init() { } } - // We need to warp up the actual run in a `cb` function to be able to extract its value from isolated-vm - js = js.replace(/run\(\);$/, "cb(run());") const script = jsIsolate.compileModuleSync( - `import helpers from "compiled_module";${js}`, + `import helpers from "compiled_module";const result=${js};cb(result)`, {} ) diff --git a/packages/string-templates/src/helpers/javascript.js b/packages/string-templates/src/helpers/javascript.js index eff125dd72..61a9ed21f1 100644 --- a/packages/string-templates/src/helpers/javascript.js +++ b/packages/string-templates/src/helpers/javascript.js @@ -42,7 +42,7 @@ module.exports.processJS = (handlebars, context) => { try { // Wrap JS in a function and immediately invoke it. // This is required to allow the final `return` statement to be valid. - const js = `function run(){${atob(handlebars)}};run();` + const js = `(function(){${atob(handlebars)}})();` // Our $ context function gets a value from context. // We clone the context to avoid mutation in the binding affecting real