{"version":3,"sources":["https://lively-kernel.org/lively4/swd21-pipes-and-filters/src/client/bound-eval.js"],"names":["uuid","workspaces","Preferences","rewriteSourceWithAsyncAwaitSupport","source","boundEval","thisReference","targetModule","lively4url","codeId","targetPath","replace","path","encodeURI","self","__pluginDoitThisRefs__","window","__global_this__","__topLevelVarRecorder_ModuleNames__","get","match","console","log","setCode","System","import","then","m","lively","unloadModule","value","__result__","err","Promise","resolve","isError"],"mappings":";;;;;;AAASA,U,UAAAA,I;;AACGC,gB;;AACLC,iB;;;;;;;;;;;AAIEC,6E;;;;;;;;;;;;;AANAH,+C;;;;;;;;;;;;;AACGC,qD;;;;;;;;;;;;;AACLC,sD;;;;;;;;;AAGP;AACA,eAASC,kCAAT,CAA4CC,MAA5C,EAAoD;AAClD,eAAQ;kCACwBA,MAAO;KADvC;AAGD;;yBAEc,eAAeC,SAAf,CAAyBD,MAAzB,EAAiCE,aAAjC,EAAgDC,YAAhD,EAA8D;AAC3E,YAAI;AACF,cAAI,CAACA,YAAL,EAAmBA,eAAeC,aAAa,GAA5B;;AAEnB,cAAIC,SAAST,SAAS,GAAtB,CAHE,CAG0B;;AAE5B,cAAIU,aAAaH,aAAaI,OAAb,CAAqB,aAArB,EAAmC,EAAnC,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;AACAU,iBAAOC,eAAP,GAAyBX,aAAzB,CAdE,CAcqC;;AAEvC,cAAI,CAACQ,KAAKI,mCAAV,EAA+C;AAC7CJ,iBAAKI,mCAAL,GAA2C,EAA3C;AACD;AACD;AACAJ,eAAKI,mCAAL,CAAyCT,MAAzC,IAAmDF,YAAnD;;AAGA,cAAIL,YAAYiB,GAAZ,CAAgB,mBAAhB,KAAwCf,OAAOgB,KAAP,CAAa,QAAb,CAAxC,IAAkE,CAAChB,OAAOgB,KAAP,CAAa,SAAb,CAAvE,EAAgG;AAC9FhB,qBAASD,mCAAmCC,MAAnC,CAAT;AACD;AACD,cAAIF,YAAYiB,GAAZ,CAAgB,mBAAhB,CAAJ,EAA0C;AACxCP,mBAAOA,KAAKD,OAAL,CAAa,YAAb,EAA2B,kBAA3B,CAA+C;AAA/C,aAAP;AACD,WAFD,MAEO,IAAIT,YAAYiB,GAAZ,CAAgB,sBAAhB,CAAJ,EAA6C;AAClDP,mBAAOA,KAAKD,OAAL,CAAa,YAAb,EAA2B,aAA3B,CAAP;AACD;;AAED;AACA;;AAEAU,kBAAQC,GAAR,CAAY,YAAYb,MAAZ,GAAqB,MAArB,GAA8BF,YAA1C;;AAEAN,qBAAWsB,OAAX,CAAmBX,IAAnB,EAAyBR,MAAzB;;AAGA,iBAAO,MAAMoB,OAAOC,MAAP,CAAcb,IAAd,EACVc,IADU,CACLC,KAAK;;AAET;AACAC,mBAAOC,YAAP,CAAoBjB,IAApB;;AAGA,mBAAQ,EAACkB,OAAOH,EAAEI,UAAV,EAAR;AAAgC,WAPvB,CAAb;AAQD,SAhDD,CAgDE,OAAMC,GAAN,EAAW;AACX,iBAAOC,QAAQC,OAAR,CAAgB,EAAEJ,OAAOE,GAAT,EAAcG,SAAS,IAAvB,EAAhB,CAAP;AACD,SAlDD,SAkDU;AACR;AACAP,iBAAOC,YAAP,CAAoBjB,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\n\n// #Hack maybe this we get support for rewriting this source in #Babel7 ? Please leave it here for a reminder...\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    window.__global_this__ = thisReference // #Hack... #TODO why is this still used?\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\") /// does not work yet #TODO \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        \n        // we unloaded it to prevent reevaluation of old workspaces if their dependencies change...\n        lively.unloadModule(path) \n        \n        \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"]}