gustwindevaluate.ts at develop · gustwi...

what's a worker safe way to evaluate simple expression? I have Function style code at https://github.com/gustwindjs/gustwind/blob/develop/utils/evaluate.ts but it seems to be disallowed for security reasons (totally understandable)
GitHub
gustwind/evaluate.ts at develop · gustwindjs/gustwind
🐳💨 – Deno powered JSON oriented site generator. Contribute to gustwindjs/gustwind development by creating an account on GitHub.
1 Reply
bebraw
bebraw3y ago
i guess what i'm looking for is some kind of a sandbox where to eval cool, thanks. i'm just looking at what it would take to remove the whole evaluation dependency from my work. it feels doable somehow 🙂 it's probably not a bad thing to do anyway as it's enforcing good development practices so i'll go this way i had a look at the expressions and it's mainly simple lookups and some && kind of things. i'll do a simple JSON based syntax to cover my use cases and of course more complexity can be added on top as needed if you know something pre-existing, that might potentially save a bit of effort but at the same time it's not going to take a lot of time to get the basic spec done at least this will live inside my templating library and i have a feeling the new solution will be faster than the old eval based one. the engine is fast already but making it faster is a nice side benefit it also means i have to push some work out of template compilation (i.e. run async things etc. earlier) but that's not too bad i think i might have to expose some spot where you can put your little custom logic for more complex evaluations but that's not a big deal overall everything will be better 💪 it's a bit exciting for me as this means i'll be able to run my ssg on the edge where i want so it will be actually a hybrid solution which is somehow cool i guess there are some new patterns this will enable since i could push some work to islands where an island is actually an edge worker and so on i managed to get the thing done at a basic level. here's the code: https://github.com/jsterlibs/website-v2/pull/14 and here's the template engine (look at the tests): https://github.com/gustwindjs/gustwind/tree/develop/breezewind . it's all very simple for now but it's enough to prove the point and i'll do much more on top of this. i ended up replacing the expressions with a recursive JSON based application syntax that looks something like this:
{
"utility": "concat",
"parameters", ["testing", { "utility": "get", "parameters": ["context", "demo"] }]
}
{
"utility": "concat",
"parameters", ["testing", { "utility": "get", "parameters": ["context", "demo"] }]
}
each utility is then defined on user side (apart from a couple of defaults that are shipped out of the box) doing this avoids the problem with eval while giving you more than enough power to program in templates with JSON the change made the system far more expressive than before and there are some interesting side effects to all this since applications run async i think it wouldn't be too hard to build some interpreter on top of the structure but i've skipped the problem for now as this is good enough for my purposes apart from adding the functionality i wanted to add to the service, i have to do a benchmark (related to my PhD work) to see how the approach compares against a completely static build
Want results from more Discord servers?
Add your server