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

Function pY

main.js:54–54  ·  view source on GitHub ↗
(e,t)

Source from the content-addressed store, hash-verified

52`):!1,a=r?.startsWith("object")&&NP(n,r),o;try{o=i&&!t&&!n.startsWith("(")&&!a?new Function(`with(this) { ${n} }`):new Function(`with(this) { return ${n}; }`)}catch(s){console.log(s,n)}return o},u0=e=>{let t={...e,execActions:{},execProps:{},execStyles:{},execPropsOptions:{}},{sortedKeys:r,dependencies:n}=spe(t.node.props,`${t.id}.props`),{sortedKeys:i,dependencies:a}=spe(t.node.styles,`${t.id}.styles`);t.execPropsOptions.props=r.map(s=>({name:s,isConst:ou(t.node.props[s]),deps:n.get(s)||[]})),t.execProps=DP(t.node.props,(s,l)=>dY(s,!1,t.node.types?.[l])),t.execStyles=DP(t.node.styles,s=>dY(s,!1)),t.execActions=DP(t.node.actions,s=>dY(s,!0)),t.children=t.children.map(s=>u0(s)),t.execPropsOptions.children=[...t.children.flatMap(s=>s.execPropsOptions.children),...t.children.map(s=>s.id)];let o=[...t.children.flatMap(s=>s.execPropsOptions.deps),...t.execPropsOptions.props.flatMap(s=>s.deps),...[...a.values()].flat()];return t.execPropsOptions.deps=o.filter(s=>s[0]!=t.id),t.node.type=="list"&&(t.execPropsOptions.template=t.children),t};function rJe(e){let t=[];function r(i,a=[]){if(i.type==="Identifier")return a.push(i.name),a;if(i.type==="MemberExpression"){let o=r(i.object,a);if(o&&i.computed)return i.property.type==="Literal"?(o.push(String(i.property.value)),o):i.property.type==="Identifier"?(o.push(i.property.name),o):i.property.type==="MemberExpression"?(n(i.property),o):null;if(o)return r(i.property,o)}else{if(i.type==="Literal")return a.push(String(i.value)),a;if(i.type==="ChainExpression"||i.type=="ExpressionStatement"){n(i.expression);return}else if(i.type==="CallExpression"){n(i);return}}return null}function n(i){if(i.type==="MemberExpression"){let a=r(i);a&&t.push(a);return}for(let a in i)if(typeof i[a]=="object"&&i[a]!==null)n(i[a]);else if(Array.isArray(i[a]))for(let o of i[a])typeof o=="object"&&o!==null&&n(o)}try{let i=nx(e.replace("return ",""),{ecmaVersion:2020});n(i)}catch{return[]}return t}function spe(e,t){let r=new Map,n=new Map,i=new Map;for(let u in e){let c=e[u],f=rJe(c),d=f.filter(p=>p.slice(0,-1).join(".")===t);n.set(u,d),i.set(u,f),r.has(u)||r.set(u,new Set);for(let p of d){let h=p[p.length-1];h!==u&&r.get(u).add(h)}}let a=new Set,o=[],s=new Set,l=u=>{if(s.has(u))throw new Error("Circular dependency detected");if(!a.has(u)){s.add(u);let c=r.get(u)||new Set;for(let f of c)l(f);a.add(u),s.delete(u),o.push(u)}};for(let u in e)a.has(u)||l(u);return{sortedKeys:o,dependencies:i}}var{stringify:nJe}=JSON;if(!String.prototype.repeat)throw new Error("String.prototype.repeat is undefined, see https://github.com/davidbonnet/astring#installation");if(!String.prototype.endsWith)throw new Error("String.prototype.endsWith is undefined, see https://github.com/davidbonnet/astring#installation");var MP={"||":2,"??":3,"&&":4,"|":5,"^":6,"&":7,"==":8,"!=":8,"===":8,"!==":8,"<":9,">":9,"<=":9,">=":9,in:9,instanceof:9,"<<":10,">>":10,">>>":10,"+":11,"-":11,"*":12,"%":12,"/":12,"**":13},zm=17,iJe={ArrayExpression:20,TaggedTemplateExpression:20,ThisExpression:20,Identifier:20,PrivateIdentifier:20,Literal:18,TemplateLiteral:20,Super:20,SequenceExpression:20,MemberExpression:19,ChainExpression:19,CallExpression:19,NewExpression:19,ArrowFunctionExpression:zm,ClassExpression:zm,FunctionExpression:zm,ObjectExpression:zm,UpdateExpression:16,UnaryExpression:15,AwaitExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,YieldExpression:2,RestElement:1};function iE(e,t){let{generator:r}=e;if(e.write("("),t!=null&&t.length>0){r[t[0].type](t[0],e);let{length:n}=t;for(let i=1;i<n;i++){let a=t[i];e.write(", "),r[a.type](a,e)}}e.write(")")}function hpe(e,t,r,n){let i=e.expressionsPrecedence[t.type];if(i===zm)return!0;let a=e.expressionsPrecedence[r.type];return i!==a?!n&&i===15&&a===14&&r.operator==="**"||i<a:i!==13&&i!==14?!1:t.operator==="**"&&r.operator==="**"?!n:i===13&&a===13&&(t.operator==="??"||r.operator==="??")?!0:n?MP[t.operator]<=MP[r.operator]:MP[t.operator]<MP[r.operator]}function OP(e,t,r,n){let{generator:i}=e;hpe(e,t,r,n)?(e.write("("),i[t.type](t,e),e.write(")")):i[t.type](t,e)}function aJe(e,t,r,n){let i=t.split(`
53`),a=i.length-1;if(e.write(i[0].trim()),a>0){e.write(n);for(let o=1;o<a;o++)e.write(r+i[o].trim()+n);e.write(r+i[a].trim())}}function $c(e,t,r,n){let{length:i}=t;for(let a=0;a<i;a++){let o=t[a];e.write(r),o.type[0]==="L"?e.write("// "+o.value.trim()+`
54`,o):(e.write("/*"),aJe(e,o.value,r,n),e.write("*/"+n))}}function oJe(e){let t=e;for(;t!=null;){let{type:r}=t;if(r[0]==="C"&&r[1]==="a")return!0;if(r[0]==="M"&&r[1]==="e"&&r[2]==="m")t=t.object;else return!1}}function pY(e,t){let{generator:r}=e,{declarations:n}=t;e.write(t.kind+" ");let{length:i}=n;if(i>0){r.VariableDeclarator(n[0],e);for(let a=1;a<i;a++)e.write(", "),r.VariableDeclarator(n[a],e)}}var upe,cpe,fpe,dpe,ppe,mpe,sJe={Program(e,t){let r=t.indent.repeat(t.indentLevel),{lineEnd:n,writeComments:i}=t;i&&e.comments!=null&&$c(t,e.comments,r,n);let a=e.body,{length:o}=a;for(let s=0;s<o;s++){let l=a[s];i&&l.comments!=null&&$c(t,l.comments,r,n),t.write(r),this[l.type](l,t),t.write(n)}i&&e.trailingComments!=null&&$c(t,e.trailingComments,r,n)},BlockStatement:mpe=function(e,t){let r=t.indent.repeat(t.indentLevel++),{lineEnd:n,writeComments:i}=t,a=r+t.indent;t.write("{");let o=e.body;if(o!=null&&o.length>0){t.write(n),i&&e.comments!=null&&$c(t,e.comments,a,n);let{length:s}=o;for(let l=0;l<s;l++){let u=o[l];i&&u.comments!=null&&$c(t,u.comments,a,n),t.write(a),this[u.type](u,t),t.write(n)}t.write(r)}else i&&e.comments!=null&&(t.write(n),$c(t,e.comments,a,n),t.write(r));i&&e.trailingComments!=null&&$c(t,e.trailingComments,a,n),t.write("}"),t.indentLevel--},ClassBody:mpe,StaticBlock(e,t){t.write("static "),this.BlockStatement(e,t)},EmptyStatement(e,t){t.write(";")},ExpressionStatement(e,t){let r=t.expressionsPrecedence[e.expression.type];r===zm||r===3&&e.expression.left.type[0]==="O"?(t.write("("),this[e.expression.type](e.expression,t),t.write(")")):this[e.expression.type](e.expression,t),t.write(";")},IfStatement(e,t){t.write("if ("),this[e.test.type](e.test,t),t.write(") "),this[e.consequent.type](e.consequent,t),e.alternate!=null&&(t.write(" else "),this[e.alternate.type](e.alternate,t))},LabeledStatement(e,t){this[e.label.type](e.label,t),t.write(": "),this[e.body.type](e.body,t)},BreakStatement(e,t){t.write("break"),e.label!=null&&(t.write(" "),this[e.label.type](e.label,t)),t.write(";")},ContinueStatement(e,t){t.write("continue"),e.label!=null&&(t.write(" "),this[e.label.type](e.label,t)),t.write(";")},WithStatement(e,t){t.write("with ("),this[e.object.type](e.object,t),t.write(") "),this[e.body.type](e.body,t)},SwitchStatement(e,t){let r=t.indent.repeat(t.indentLevel++),{lineEnd:n,writeComments:i}=t;t.indentLevel++;let a=r+t.indent,o=a+t.indent;t.write("switch ("),this[e.discriminant.type](e.discriminant,t),t.write(") {"+n);let{cases:s}=e,{length:l}=s;for(let u=0;u<l;u++){let c=s[u];i&&c.comments!=null&&$c(t,c.comments,a,n),c.test?(t.write(a+"case "),this[c.test.type](c.test,t),t.write(":"+n)):t.write(a+"default:"+n);let{consequent:f}=c,{length:d}=f;for(let p=0;p<d;p++){let h=f[p];i&&h.comments!=null&&$c(t,h.comments,o,n),t.write(o),this[h.type](h,t),t.write(n)}}t.indentLevel-=2,t.write(r+"}")},ReturnStatement(e,t){t.write("return"),e.argument&&(t.write(" "),this[e.argument.type](e.argument,t)),t.write(";")},ThrowStatement(e,t){t.write("throw "),this[e.argument.type](e.argument,t),t.write(";")},TryStatement(e,t){if(t.write("try "),this[e.block.type](e.block,t),e.handler){let{handler:r}=e;r.param==null?t.write(" catch "):(t.write(" catch ("),this[r.param.type](r.param,t),t.write(") ")),this[r.body.type](r.body,t)}e.finalizer&&(t.write(" finally "),this[e.finalizer.type](e.finalizer,t))},WhileStatement(e,t){t.write("while ("),this[e.test.type](e.test,t),t.write(") "),this[e.body.type](e.body,t)},DoWhileStatement(e,t){t.write("do "),this[e.body.type](e.body,t),t.write(" while ("),this[e.test.type](e.test,t),t.write(");")},ForStatement(e,t){if(t.write("for ("),e.init!=null){let{init:r}=e;r.type[0]==="V"?pY(t,r):this[r.type](r,t)}t.write("; "),e.test&&this[e.test.type](e.test,t),t.write("; "),e.update&&this[e.update.type](e.update,t),t.write(") "),this[e.body.type](e.body,t)},ForInStatement:upe=function(e,t){t.write(`for ${e.await?"await ":""}(`);let{left:r}=e;r.type[0]==="V"?pY(t,r):this[r.type](r,t),t.write(e.type[3]==="I"?" in ":" of "),this[e.right.type](e.right,t),t.write(") "),this[e.body.type](e.body,t)},ForOfStatement:upe,DebuggerStatement(e,t){t.write("debugger;",e)},FunctionDeclaration:cpe=function(e,t){t.write((e.async?"async ":"")+(e.generator?"function* ":"function ")+(e.id?e.id.name:""),e),iE(t,e.params),t.write(" "),this[e.body.type](e.body,t)},FunctionExpression:cpe,VariableDeclaration(e,t){pY(t,e),t.write(";")},VariableDeclarator(e,t){this[e.id.type](e.id,t),e.init!=null&&(t.write(" = "),this[e.init.type](e.init,t))},ClassDeclaration(e,t){if(t.write("class "+(e.id?`${e.id.name} `:""),e),e.superClass){t.write("extends ");let{superClass:r}=e,{type:n}=r,i=t.expressionsPrecedence[n];(n[0]!=="C"||n[1]!=="l"||n[5]!=="E")&&(i===zm||i<t.expressionsPrecedence.ClassExpression)?(t.write("("),this[e.superClass.type](r,t),t.write(")")):this[r.type](r,t),t.write(" ")}this.ClassBody(e.body,t)},ImportDeclaration(e,t){t.write("import ");let{specifiers:r,attributes:n}=e,{length:i}=r,a=0;if(i>0){for(;a<i;){a>0&&t.write(", ");let o=r[a],s=o.type[6];if(s==="D")t.write(o.local.name,o),a++;else if(s==="N")t.write("* as "+o.local.name,o),a++;else break}if(a<i){for(t.write("{");;){let o=r[a],{name:s}=o.imported;if(t.write(s,o),s!==o.local.name&&t.write(" as "+o.local.name),++a<i)t.write(", ");else break}t.write("}")}t.write(" from ")}if(this.Literal(e.source,t),n&&n.length>0){t.write(" with { ");for(let o=0;o<n.length;o++)this.ImportAttribute(n[o],t),o<n.length-1&&t.write(", ");t.write(" }")}t.write(";")},ImportAttribute(e,t){this.Identifier(e.key,t),t.write(": "),this.Literal(e.value,t)},ImportExpression(e,t){t.write("import("),this[e.source.type](e.source,t),t.write(")")},ExportDefaultDeclaration(e,t){t.write("export default "),this[e.declaration.type](e.declaration,t),t.expressionsPrecedence[e.declaration.type]!=null&&e.declaration.type[0]!=="F"&&t.write(";")},ExportNamedDeclaration(e,t){if(t.write("export "),e.declaration)this[e.declaration.type](e.declaration,t);else{t.write("{");let{specifiers:r}=e,{length:n}=r;if(n>0)for(let i=0;;){let a=r[i],{name:o}=a.local;if(t.write(o,a),o!==a.exported.name&&t.write(" as "+a.exported.name),++i<n)t.write(", ");else break}if(t.write("}"),e.source&&(t.write(" from "),this.Literal(e.source,t)),e.attributes&&e.attributes.length>0){t.write(" with { ");for(let i=0;i<e.attributes.length;i++)this.ImportAttribute(e.attributes[i],t),i<e.attributes.length-1&&t.write(", ");t.write(" }")}t.write(";")}},ExportAllDeclaration(e,t){if(e.exported!=null?t.write("export * as "+e.exported.name+" from "):t.write("export * from "),this.Literal(e.source,t),e.attributes&&e.attributes.length>0){t.write(" with { ");for(let r=0;r<e.attributes.length;r++)this.ImportAttribute(e.attributes[r],t),r<e.attributes.length-1&&t.write(", ");t.write(" }")}t.write(";")},MethodDefinition(e,t){e.static&&t.write("static ");let r=e.kind[0];(r==="g"||r==="s")&&t.write(e.kind+" "),e.value.async&&t.write("async "),e.value.generator&&t.write("*"),e.computed?(t.write("["),this[e.key.type](e.key,t),t.write("]")):this[e.key.type](e.key,t),iE(t,e.value.params),t.write(" "),this[e.value.body.type](e.value.body,t)},ClassExpression(e,t){this.ClassDeclaration(e,t)},ArrowFunctionExpression(e,t){t.write(e.async?"async ":"",e);let{params:r}=e;r!=null&&(r.length===1&&r[0].type[0]==="I"?t.write(r[0].name,r[0]):iE(t,e.params)),t.write(" => "),e.body.type[0]==="O"?(t.write("("),this.ObjectExpression(e.body,t),t.write(")")):this[e.body.type](e.body,t)},ThisExpression(e,t){t.write("this",e)},Super(e,t){t.write("super",e)},RestElement:fpe=function(e,t){t.write("..."),this[e.argument.type](e.argument,t)},SpreadElement:fpe,YieldExpression(e,t){t.write(e.delegate?"yield*":"yield"),e.argument&&(t.write(" "),this[e.argument.type](e.argument,t))},AwaitExpression(e,t){t.write("await ",e),OP(t,e.argument,e)},TemplateLiteral(e,t){let{quasis:r,expressions:n}=e;t.write("`");let{length:i}=n;for(let o=0;o<i;o++){let s=n[o],l=r[o];t.write(l.value.raw,l),t.write("${"),this[s.type](s,t),t.write("}")}let a=r[r.length-1];t.write(a.value.raw,a),t.write("`")},TemplateElement(e,t){t.write(e.value.raw,e)},TaggedTemplateExpression(e,t){OP(t,e.tag,e),this[e.quasi.type](e.quasi,t)},ArrayExpression:ppe=function(e,t){if(t.write("["),e.elements.length>0){let{elements:r}=e,{length:n}=r;for(let i=0;;){let a=r[i];if(a!=null&&this[a.type](a,t),++i<n)t.write(", ");else{a==null&&t.write(", ");break}}}t.write("]")},ArrayPattern:ppe,ObjectExpression(e,t){let r=t.indent.repeat(t.indentLevel++),{lineEnd:n,writeComments:i}=t,a=r+t.indent;if(t.write("{"),e.properties.length>0){t.write(n),i&&e.comments!=null&&$c(t,e.comments,a,n);let o=","+n,{properties:s}=e,{length:l}=s;for(let u=0;;){let c=s[u];if(i&&c.comments!=null&&$c(t,c.comments,a,n),t.write(a),this[c.type](c,t),++u<l)t.write(o);else break}t.write(n),i&&e.trailingComments!=null&&$c(t,e.trailingComments,a,n),t.write(r+"}")}else i?e.comments!=null?(t.write(n),$c(t,e.comments,a,n),e.trailingComments!=null&&$c(t,e.trailingComments,a,n),t.write(r+"}")):e.trailingComments!=null?(t.write(n),$c(t,e.trailingComments,a,n),t.write(r+"}")):t.write("}"):t.write("}");t.indentLevel--},Property(e,t){e.method||e.kind[0]!=="i"?this.MethodDefinition(e,t):(e.shorthand||(e.computed?(t.write("["),this[e.key.type](e.key,t),t.write("]")):this[e.key.type](e.key,t),t.write(": ")),this[e.value.type](e.value,t))},PropertyDefinition(e,t){if(e.static&&t.write("static "),e.computed&&t.write("["),this[e.key.type](e.key,t),e.computed&&t.write("]"),e.value==null){e.key.type[0]!=="F"&&t.write(";");return}t.write(" = "),this[e.value.type](e.value,t),t.write(";")},ObjectPattern(e,t){if(t.write("{"),e.properties.length>0){let{properties:r}=e,{length:n}=r;for(let i=0;this[r[i].type](r[i],t),++i<n;)t.write(", ")}t.write("}")},SequenceExpression(e,t){iE(t,e.expressions)},UnaryExpression(e,t){if(e.prefix){let{operator:r,argument:n,argument:{type:i}}=e;t.write(r);let a=hpe(t,n,e);!a&&(r.length>1||i[0]==="U"&&(i[1]==="n"||i[1]==="p")&&n.prefix&&n.operator[0]===r&&(r==="+"||r==="-"))&&t.write(" "),a?(t.write(r.length>1?" (":"("),this[i](n,t),t.write(")")):this[i](n,t)}else this[e.argument.type](e.argument,t),t.write(e.operator)},UpdateExpression(e,t){e.prefix?(t.write(e.operator),this[e.argument.type](e.argument,t)):(this[e.argument.type](e.argument,t),t.write(e.operator))},AssignmentExpression(e,t){this[e.left.type](e.left,t),t.write(" "+e.operator+" "),this[e.right.type](e.right,t)},AssignmentPattern(e,t){this[e.left.type](e.left,t),t.write(" = "),this[e.right.type](e.right,t)},BinaryExpression:dpe=function(e,t){let r=e.operator==="in";r&&t.write("("),OP(t,e.left,e,!1),t.write(" "+e.operator+" "),OP(t,e.right,e,!0),r&&t.write(")")},LogicalExpression:dpe,ConditionalExpression(e,t){let{test:r}=e,n=t.expressionsPrecedence[r.type];n===zm||n<=t.expressionsPrecedence.ConditionalExpression?(t.write("("),this[r.type](r,t),t.write(")")):this[r.type](r,t),t.write(" ? "),this[e.consequent.type](e.consequent,t),t.write(" : "),this[e.alternate.type](e.alternate,t)},NewExpression(e,t){t.write("new ");let r=t.expressionsPrecedence[e.callee.type];r===zm||r<t.expressionsPrecedence.CallExpression||oJe(e.callee)?(t.write("("),this[e.callee.type](e.callee,t),t.write(")")):this[e.callee.type](e.callee,t),iE(t,e.arguments)},CallExpression(e,t){let r=t.expressionsPrecedence[e.callee.type];r===zm||r<t.expressionsPrecedence.CallExpression?(t.write("("),this[e.callee.type](e.callee,t),t.write(")")):this[e.callee.type](e.callee,t),e.optional&&t.write("?."),iE(t,e.arguments)},ChainExpression(e,t){this[e.expression.type](e.expression,t)},MemberExpression(e,t){let r=t.expressionsPrecedence[e.object.type];r===zm||r<t.expressionsPrecedence.MemberExpression?(t.write("("),this[e.object.type](e.object,t),t.write(")")):this[e.object.type](e.object,t),e.computed?(e.optional&&t.write("?."),t.write("["),this[e.property.type](e.property,t),t.write("]")):(e.optional?t.write("?."):t.write("."),this[e.property.type](e.property,t))},MetaProperty(e,t){t.write(e.meta.name+"."+e.property.name,e)},Identifier(e,t){t.write(e.name,e)},PrivateIdentifier(e,t){t.write(`#${e.name}`,e)},Literal(e,t){e.raw!=null?t.write(e.raw,e):e.regex!=null?this.RegExpLiteral(e,t):e.bigint!=null?t.write(e.bigint+"n",e):t.write(nJe(e.value),e)},RegExpLiteral(e,t){let{regex:r}=e;t.write(`/${r.pattern}/${r.flags}`,e)}},lJe={};var mY=class{constructor(t){let r=t??lJe;this.output="",r.output!=null?(this.output=r.output,this.write=this.writeToStream):this.output="",this.generator=r.generator!=null?r.generator:sJe,this.expressionsPrecedence=r.expressionsPrecedence!=null?r.expressionsPrecedence:iJe,this.indent=r.indent!=null?r.indent:" ",this.lineEnd=r.lineEnd!=null?r.lineEnd:`
55`,this.indentLevel=r.startingIndentLevel!=null?r.startingIndentLevel:0,this.writeComments=r.comments?r.comments:!1,r.sourceMap!=null&&(this.write=r.output==null?this.writeAndMap:this.writeToStreamAndMap,this.sourceMap=r.sourceMap,this.line=1,this.column=0,this.lineEndSize=this.lineEnd.split(`
56`).length-1,this.mapping={original:null,generated:this,name:void 0,source:r.sourceMap.file||r.sourceMap._file})}write(t){this.output+=t}writeToStream(t){this.output.write(t)}writeAndMap(t,r){this.output+=t,this.map(t,r)}writeToStreamAndMap(t,r){this.output.write(t),this.map(t,r)}map(t,r){if(r!=null){let{type:a}=r;if(a[0]==="L"&&a[2]==="n"){this.column=0,this.line++;return}if(r.loc!=null){let{mapping:o}=this;o.original=r.loc.start,o.name=r.name,this.sourceMap.addMapping(o)}if(a[0]==="T"&&a[8]==="E"||a[0]==="L"&&a[1]==="i"&&typeof r.value=="string"){let{length:o}=t,{column:s,line:l}=this;for(let u=0;u<o;u++)t[u]===`
57`?(s=0,l++):s++;this.column=s,this.line=l;return}}let{length:n}=t,{lineEnd:i}=this;n>0&&(this.lineEndSize>0&&(i.length===1?t[n-1]===i:t.endsWith(i))?(this.line+=this.lineEndSize,this.column=0):this.column+=n)}toString(){return this.output}};function gpe(e,t){let r=new mY(t);return r.generator[e.type](e,r),r.output}var og=(e,t,r)=>{let n,i=uo(e),a=i.includes(`

Callers 3

ForStatementFunction · 0.85
main.jsFile · 0.85
VariableDeclarationFunction · 0.85

Calls 1

writeMethod · 0.80

Tested by

no test coverage detected