Closed wrapperup closed 8 months ago
I guess the one question I have is do we want to still support CJS modules? estree-walker
doesn't have a CJS version. There isn't a deno alternative for any of these unfortunately.
Thanks for this! Please, let me some time to test it.
I think we can remove CJS support.
Motivation
The
with
statement comes with a lot of caveats, the main one (for me) is the huge performance penalty. JavaScript runtimes will de-optimize value accesses inside ofwith
statements. I like the convenience of accessing state properties with just{{ prop }}
, but since it has a huge perf penalty, I usually opt to disableuseWith
, which forces me to write templates withit
.Additionally, the generated code can't be used in strict mode.
Solution
Remove the
with
statement, and rewrite the generated JavaScript to insert the template state access.Currently, it happens in a (~200 LoC) transform step that analyzes the AST of the generated code, and rewrites any unbound and non-global values to access from the template state. Accessing globals like
Deno
,Promise
,JSON
and other globals should still work to try and keep the "write real JavaScript" promise, and it should also respect variable bindings and their scopes.Benchmarks
Quick benchmark to guage the improvement, it varies a bit (mostly on accesses inside the
with
statement)With the code transform step, Vento now performs within error of disabling
useWith
. The real-world improvements can be pretty huge for SSR use-cases, especially in larger templates (though this varies on accesses!).Todo
var
)Replaceestree-walker
so we can still build CJS modules (maybe?)