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

That's pretty much what I did. There is a polymorphic method to_js_tail on AST nodes that asks the node to emit itself as a return statement. Nodes that are values just prepend "return", blocks forward the call to their last statement, control structures forward to each of their blocks and so on.

That just handles returns. I never implemented statements as expressions in general. I was planning to do that by wrapping non-expressions in anonymous functions but if you can do it by injecting temp variables, that's probably a lot more efficient.




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