@builder.io/react 3.0.13-0 → 3.0.13-2
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.
- package/dist/builder-react-lite.cjs.js +1 -1
- package/dist/builder-react-lite.cjs.js.map +1 -1
- package/dist/builder-react-lite.esm.js +1 -1
- package/dist/builder-react-lite.esm.js.map +1 -1
- package/dist/builder-react.browser.js +2 -2
- package/dist/builder-react.browser.js.map +1 -1
- package/dist/builder-react.cjs.js +1 -1
- package/dist/builder-react.cjs.js.map +1 -1
- package/dist/builder-react.es5.js +1 -1
- package/dist/builder-react.es5.js.map +1 -1
- package/dist/builder-react.unpkg.js +2 -2
- package/dist/builder-react.unpkg.js.map +1 -1
- package/dist/lib/package.json +1 -1
- package/dist/lib/src/builder-react.js.map +1 -1
- package/dist/lib/src/components/builder-component.component.js +1 -1
- package/dist/lib/src/components/builder-component.component.js.map +1 -1
- package/dist/lib/src/functions/string-to-function.js +37 -25
- package/dist/lib/src/functions/string-to-function.js.map +1 -1
- package/dist/lib/src/functions/try-eval.js +12 -18
- package/dist/lib/src/functions/try-eval.js.map +1 -1
- package/dist/types/src/builder-react.d.ts +2 -2
- package/dist/types/src/components/builder-component.component.d.ts +3 -3
- package/dist/types/src/functions/string-to-function.d.ts +2 -0
- package/package.json +2 -2
- package/src/builder-react.ts +6 -2
- package/src/components/builder-component.component.tsx +5 -5
- package/src/functions/string-to-function.ts +30 -21
- package/src/functions/try-eval.tsx +11 -10
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Builder } from '@builder.io/sdk';
|
|
3
3
|
import { safeDynamicRequire } from './safe-dynamic-require';
|
|
4
4
|
import { isDebug } from './is-debug';
|
|
5
|
+
import { getIsolateContext, makeFn } from './string-to-function';
|
|
5
6
|
|
|
6
7
|
export const tryEval = (str?: string, data: any = {}, errors?: Error[]): any => {
|
|
7
8
|
const value = str;
|
|
@@ -52,16 +53,16 @@ export const tryEval = (str?: string, data: any = {}, errors?: Error[]): any =>
|
|
|
52
53
|
// Below is a hack to get certain code to *only* load in the server build, to not screw with
|
|
53
54
|
// browser bundler's like rollup and webpack. Our rollup plugin strips these comments only
|
|
54
55
|
// for the server build
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
const ivm = safeDynamicRequire('isolated-vm');
|
|
57
|
+
const context = getIsolateContext();
|
|
58
|
+
const fnString = makeFn(str!, useReturn, ['state']);
|
|
59
|
+
const resultStr = context.evalClosureSync(fnString, [new ivm.Reference(data || {})]);
|
|
60
|
+
try {
|
|
61
|
+
// returning objects throw errors in isolated vm, so we stringify it and parse it back
|
|
62
|
+
return JSON.parse(resultStr);
|
|
63
|
+
} catch (_error: any) {
|
|
64
|
+
return resultStr;
|
|
65
|
+
}
|
|
65
66
|
}
|
|
66
67
|
} catch (error: any) {
|
|
67
68
|
if (errors) {
|