3 ms·
Great stuff. The one really interesting overlap between the two -- from taking a quick glance at your readme, is that we're both trying to convert things that o
by jashkenas 17y ago
Great stuff. The one really interesting overlap between the two -- from taking a quick glance at your readme, is that we're both trying to convert things that otherwise would be statements in JavaScript into expressions.
CoffeeScript does this by using the AST to recursively push down returns and assignments requested from outside a block to the final line of each possible branch of execution:
http://jashkenas.github.com/coffee-script/#expressions http://jashkenas.github.com/coffee-script/#expressions
How are you doing it? Did you find any particularly tricky cases?
- extension 17y agoThat'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.