@builder.io/react 2.0.2-0 → 2.0.2-1

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.
@@ -1,80 +0,0 @@
1
- import { Builder } from '@builder.io/sdk';
2
- import { safeDynamicRequire } from './safe-dynamic-require';
3
-
4
- export const tryEval = (str?: string, data: any = {}, errors?: Error[]): any => {
5
- const value = str;
6
- if (!(typeof value === 'string' && value.trim())) {
7
- return;
8
- }
9
- const useReturn = !(value.includes(';') || value.includes(' return '));
10
- let fn: Function = () => {
11
- /* Intentionally empty */
12
- };
13
- try {
14
- if (Builder.isBrowser) {
15
- // tslint:disable-next-line:no-function-constructor-with-string-args
16
- // TODO: VM in node......
17
- fn = new Function(
18
- 'state',
19
- // TODO: remove the with () {} - make a page v3 that doesn't use this
20
- `var rootState = state;
21
- if (typeof Proxy !== 'undefined') {
22
- rootState = new Proxy(rootState, {
23
- set: function () {
24
- return false;
25
- },
26
- get: function (target, key) {
27
- if (key === 'state') {
28
- return state;
29
- }
30
- return target[key]
31
- }
32
- });
33
- }
34
- with (rootState) {
35
- ${useReturn ? `return (${str});` : str};
36
- }`
37
- );
38
- }
39
- } catch (error) {
40
- if (Builder.isBrowser) {
41
- console.warn('Could not compile javascript', error);
42
- } else {
43
- // Add to req.options.errors to return to client
44
- }
45
- }
46
- try {
47
- if (Builder.isBrowser) {
48
- return fn(data || {});
49
- } else {
50
- // Below is a hack to get certain code to *only* load in the server build, to not screw with
51
- // browser bundler's like rollup and webpack. Our rollup plugin strips these comments only
52
- // for the server build
53
- // tslint:disable:comment-format
54
- const { VM } = safeDynamicRequire('vm2');
55
- return new VM({
56
- sandbox: {
57
- ...data,
58
- ...{ state: data },
59
- },
60
- // TODO: convert reutrn to module.exports on server
61
- }).run(value.replace(/(^|;)return /, '$1'));
62
- // tslint:enable:comment-format
63
- }
64
- } catch (error: any) {
65
- if (errors) {
66
- errors.push(error);
67
- }
68
-
69
- if (Builder.isBrowser) {
70
- console.warn('Builder custom code error:', error.message, 'in', str, error.stack);
71
- } else {
72
- if (process.env.DEBUG) {
73
- console.debug('Builder custom code error:', error.message, 'in', str, error.stack);
74
- }
75
- // Add to req.options.errors to return to client
76
- }
77
- }
78
-
79
- return;
80
- };