@win2win/shared 1.0.129 → 1.0.130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,9 +8,10 @@ function deserialize(stringFn, options) {
|
|
|
8
8
|
const { context = {}, run = false, useInvisibleContext = false, } = options || {};
|
|
9
9
|
if (!stringFn || typeof stringFn !== "string")
|
|
10
10
|
return run ? null : () => null;
|
|
11
|
+
const isEmpty = (obj) => JSON.stringify(obj || {}) === "{}";
|
|
11
12
|
try {
|
|
12
13
|
const cleanedStringFn = stringFn.replace(/\/\/.*$/gm, "").trim();
|
|
13
|
-
const fn = new Function("context", `return (...args) => { with (context) { return (${cleanedStringFn})(${useInvisibleContext ? "" : "context,"} ...args) } }`);
|
|
14
|
+
const fn = new Function("context", `return (...args) => { with (context) { return (${cleanedStringFn})(${(useInvisibleContext || isEmpty(context)) ? "" : "context,"} ...args) } }`);
|
|
14
15
|
const runableFn = fn(context);
|
|
15
16
|
return run ? runableFn() : runableFn;
|
|
16
17
|
}
|
package/package.json
CHANGED