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