Ben Newman (2014-01-25T17:34:54.000Z)
domenic at domenicdenicola.com (2014-01-27T15:57:12.227Z)
My experience implementing Regenerator is consistent with the nuance that Brendan is highlighting here, as I understand it. The state machines that Regenerator produces behave to the outside world almost exactly as generators are supposed to behave, but there are gaps: as an example, direct eval inside a generator would have access to state-machine specific state (i.e. the $ctx variable), because some of the machinery that V8 or SpiderMonkey are able to keep hidden simply has to operate in the realm of end-user source code when you don't have native support for generators. Now, I happen to think it's not that hard to keep those gaps from interfering with actual coding. The fact that https://github.com/facebook/regenerator/blob/master/test/tests.es6.jspasses without translation in Node v0.11.2+ is a testament to how close the semantics are. But in order for a transformation to be considered "desugaring," I agree with Brendan that there have to be no observable gaps in semantics. If you're building a library based on generators, I definitely recommend writing your code in the most agnostic way you can—for instance, accept any object that has a .next and .throw method as a generator, rather than requiring it to be instanceof Generator, since that's not a built-in constructor in ES5 environments.