(value: any, isClosure: boolean, type?: string)
| 5 | import { isString } from "lodash"; |
| 6 | |
| 7 | const generateCodeForProp = (value: any, isClosure: boolean, type?: string) => { |
| 8 | let codeBlock : string = value || ''; |
| 9 | if (!isString(codeBlock)) codeBlock = JSON.stringify(codeBlock); |
| 10 | if (codeBlock.startsWith('{') && codeBlock.endsWith('}')) codeBlock = `(${codeBlock})` |
| 11 | codeBlock = (isClosure && !codeBlock.startsWith('(')) ? `($event, $value, $state, $saveState, $api) => { ${codeBlock} }` : codeBlock; |
| 12 | const isMultiLine = (typeof codeBlock === 'string') ? codeBlock.includes('\n') : false; |
| 13 | const isObject = type?.startsWith('object') && objectIsConst(codeBlock, type) |
| 14 | |
| 15 | let func |
| 16 | try { |
| 17 | func = isMultiLine && !(isClosure) && !codeBlock.startsWith('(') && !isObject |
| 18 | ? new Function(`with(this) { ${codeBlock} }`) |
| 19 | : new Function(`with(this) { return ${codeBlock}; }`); |
| 20 | |
| 21 | } catch (e) { |
| 22 | console.log(e, codeBlock) |
| 23 | } |
| 24 | return func; |
| 25 | } |
| 26 | |
| 27 | export const buildExecutable = (root: FrameTreeNode) => { |
| 28 | const treeNode : FrameExecutable = {...root, execActions: {}, execProps: {}, execStyles: {}, execPropsOptions: {}}; |
no test coverage detected