MCPcopy Create free account
hub / github.com/Make-md/makemd / generateCodeForProp

Function generateCodeForProp

src/core/utils/frames/executable.ts:7–25  ·  view source on GitHub ↗
(value: any, isClosure: boolean, type?: string)

Source from the content-addressed store, hash-verified

5import { isString } from "lodash";
6
7const 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: {}};

Callers 1

buildExecutableFunction · 0.85

Calls 2

objectIsConstFunction · 0.90
startsWithMethod · 0.80

Tested by

no test coverage detected