{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-drawio/src/client/bound-eval.js"],"names":["rewriteSourceWithAsyncAwaitSupport","source","uuid","workspaces","Preferences","boundEval","thisReference","targetModule","lively4url","codeId","targetPath","replace","path","encodeURI","self","__pluginDoitThisRefs__","__topLevelVarRecorder_ModuleNames__","get","match","setCode","System","import","then","m","lively","unloadModule","value","__result__","err","Promise","resolve","isError"],"mappings":";;;;;;AAIA,WAASA,kCAAT,CAA4CC,MAA5C,EAAoD;AAClD,WAAQ;kCACwBA,MAAO;KADvC;AAGD;;;;AARQC,U,UAAAA,I;;AACGC,gB;;AACLC,iB;;;;;;;;;yBAQQ,eAAeC,SAAf,CAAyBJ,MAAzB,EAAiCK,aAAjC,EAAgDC,YAAhD,EAA8D;AAC3E,YAAI;AACF,cAAI,CAACA,YAAL,EAAmBA,eAAeC,aAAa,GAA5B;;AAEnB,cAAIC,SAAS,8CAAS,GAAtB,CAHE,CAG0B;;AAE5B,cAAIC,aAAaH,aAAaI,OAAb,CAAqB,YAArB,EAAkC,EAAlC,CAAjB;AACA,cAAIC,OAAO,eAAeC,UAAUJ,SAAUC,UAApB,CAAiC;;;AAG3D;AAH0B,WAA1B,CAIA,IAAI,CAACI,KAAKC,sBAAV,EAAkC;AAChCD,iBAAKC,sBAAL,GAA8B,EAA9B;AACD;AACDD,eAAKC,sBAAL,CAA4BN,MAA5B,IAAsCH,aAAtC;;AAGA,cAAI,CAACQ,KAAKE,mCAAV,EAA+C;AAC7CF,iBAAKE,mCAAL,GAA2C,EAA3C;AACD;AACD;AACAF,eAAKE,mCAAL,CAAyCP,MAAzC,IAAmDF,YAAnD;;AAGA,cAAI,iDAAYU,GAAZ,CAAgB,mBAAhB,KAAwChB,OAAOiB,KAAP,CAAa,QAAb,CAAxC,IAAkE,CAACjB,OAAOiB,KAAP,CAAa,SAAb,CAAvE,EAAgG;AAC9FjB,qBAAS,wEAAmCA,MAAnC,CAAT;AACD;AACD,cAAI,iDAAYgB,GAAZ,CAAgB,mBAAhB,CAAJ,EAA0C;AACxCL,mBAAOA,KAAKD,OAAL,CAAa,YAAb,EAA2B,kBAA3B,CAAP;AACD,WAFD,MAEO,IAAI,iDAAYM,GAAZ,CAAgB,sBAAhB,CAAJ,EAA6C;AAClDL,mBAAOA,KAAKD,OAAL,CAAa,YAAb,EAA2B,aAA3B,CAAP;AACD;;AAED;AACA;;AAEA;;AAEA,0DAAWQ,OAAX,CAAmBP,IAAnB,EAAyBX,MAAzB;;AAGA,iBAAO,MAAMmB,OAAOC,MAAP,CAAcT,IAAd,EACVU,IADU,CACLC,KAAK;AACTC,mBAAOC,YAAP,CAAoBb,IAApB;AACA,mBAAQ,EAACc,OAAOH,EAAEI,UAAV,EAAR;AAAgC,WAHvB,CAAb;AAID,SA5CD,CA4CE,OAAMC,GAAN,EAAW;AACX,iBAAOC,QAAQC,OAAR,CAAgB,EAAEJ,OAAOE,GAAT,EAAcG,SAAS,IAAvB,EAAhB,CAAP;AACD,SA9CD,SA8CU;AACR;AACAP,iBAAOC,YAAP,CAAoBb,IAApB;AACD;AACF,O","file":"bound-eval.js","sourcesContent":["import { uuid } from 'utils';\nimport * as workspaces from './workspaces.js';\nimport Preferences from \"./preferences.js\";\n\nfunction rewriteSourceWithAsyncAwaitSupport(source) {\n  return `(async secretAsyncLabel => {\n  return { __asyncresult__: do {${source}}}\n})()`;\n}\n\nexport default async function boundEval(source, thisReference, targetModule) {\n  try {\n    if (!targetModule) targetModule = lively4url + \"/\"\n    \n    let codeId = uuid() + \"/\" ; // that way we can have a shared context for relative urls\n    \n    var targetPath = targetModule.replace(/https:\\/\\//,\"\")\n    var path = 'workspace:' + encodeURI(codeId  + targetPath)  // \"... and the resolve relative path morks\n\n    \n    // 'this' reference\n    if (!self.__pluginDoitThisRefs__) {\n      self.__pluginDoitThisRefs__ = {};\n    } \n    self.__pluginDoitThisRefs__[codeId] = thisReference;\n    \n    \n    if (!self.__topLevelVarRecorder_ModuleNames__) {\n      self.__topLevelVarRecorder_ModuleNames__ = {};\n    } \n    // console.log(\"boundEval register \" + codeId + \" -> \" +targetModule)\n    self.__topLevelVarRecorder_ModuleNames__[codeId] = targetModule;\n    \n    \n    if (Preferences.get('UseAsyncWorkspace') && source.match(/await /) && !source.match(/import /)) {\n      source = rewriteSourceWithAsyncAwaitSupport(source);\n    }  \n    if (Preferences.get('UseAsyncWorkspace')) {\n      path = path.replace(/^workspace/, \"workspaceasyncjs\")\n    } else if (Preferences.get('DisableAExpWorkspace')) {\n      path = path.replace(/^workspace/, \"workspacejs\")\n    }\n\n    // source\n    // TODO: we currently use a newly generated UUID on each evaluation to trick SystemJS into actually loading it (therefore, we use codeId):\n    \n    // console.log(\"setURL \" + codeId + \" -> \" + targetModule)\n    \n    workspaces.setCode(path, source);\n    \n    \n    return await System.import(path)\n      .then(m => {\n        lively.unloadModule(path)\n        return ({value: m.__result__ })});\n  } catch(err) {\n    return Promise.resolve({ value: err, isError: true });\n  } finally {\n    // console.log(\"BOUND EVAL UNLOAD \" + path)\n    lively.unloadModule(path)\n  }\n}\n"]}