4 ms·
I wasn't aware that the benchmark comparison was about micro-templating, it includes libraries like handlebars. I am sure you realize you can just walk the AST
by esailija 13y ago
I wasn't aware that the benchmark comparison was about micro-templating, it includes libraries like handlebars.
I am sure you realize you can just walk the AST for what identifiers are being used in the template code and forward declare them in the generated code so that reference errors are not caused.
- jashkenas 13y agoIf you allow arbitrary JavaScript, then I'm sure you realize that you can't "just walk the AST" ;) At compile time, you have no idea which identifiers are incoming data values — to be supplied by the caller of the template function — and which identifiers already exist in scope.
- esailija 13y agoLet me put it in code terms. In the following template script: <div>@hello</div> The generated code can be like (not including runtime lib): var ___html = ""; var hello = hasown.call(data, "hello") ? data.hello : ""; ___html += '<div>' + safeString(hello, HTML_GENERIC) + '</div>'; return ___html; Which gives same effect as `with`.