Hacker News new | past | comments | ask | show | jobs | submit login

If 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.




Let 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`.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: