gopi-suvanam / scribbler

Scribbler - JavaScript Notebook Tool for experimenting in JavaScript. Runs in the browser without a backend. Discord server: https://discord.gg/uxNSsWunwU
https://scribbler.live
MIT License
52 stars 7 forks source link

Top level await #18

Closed DH-ai closed 4 months ago

DH-ai commented 4 months ago

Resolved the error you were talking about and test different cases, also included one notebook with cases i find necessary or sufficient last case might have one problem where we can't call the async function from other cell, work around is checking if async is present then don't wrap the code in IIAFE. I will work on globalizing the variable and documentation tmw and bugs if found.

gopi-suvanam commented 4 months ago

hey there is still a bug you are testing /await/ .. this will run async code even when there is an async inside a function... so the code below will not run properly

cell 1:
var abc;
(async function(){

abc = await 1;
})();

cell 2:
scrib.show(abc);

you first appraoch of checking the error message was only correct..

try {

        return (0,eval)(code);
    }
    catch(err){

        if (err.message==='await is only valid in async functions, async generators and modules'){
            return(0,eval)('(async () => {'+code+'    })();')
        }else{
            throw(err);
        }

}