transpiling ES6 generator functions to ES5: what next?

Brendan Eich brendan at mozilla.com
Fri Jan 24 21:30:37 PST 2014


David Bruant wrote:
> Hi Ben,
>
> Sorry for the very late response.
> This is quite an interesting work, thanks for sharing!
> I'm particularly interested in your test suite [1] which is impressive.
>
> This is making me realize that generators are fully compilable 
> (efficiently from what I can see) into ES5 and makes me wonder if the 
> current generators specificities are worth it. Very specifically, do 
> we really need Generator.prototype [ @@toStringTag ] === "Generator" ?
> From an author point of view, I don't really see in which situation 
> this information could matter. As a comparison, functions generated 
> after the class syntax do not have an @@toStringTag to "Class".
> Generators would just be sugar to write iterators (+ .throw)

The answer is that class constructor is a Function instance, not a 
ClassFunction instance, because classes are mostly sugar for the 
prototypal pattern, whereas generators do *not* desugar in any 
translating-not-compiling sense.

Matthias Felleisen wrote a paper, "On the Expressive Power of 
Programming Languages", that gets at the difference between compilation 
in general and translation or desugaring. You say generators are sugar 
to write iterators (+ .throw), but my understanding per Felleisen is 
that's an abuse of "sugar". Regenerator is a compiler, not a translator 
of like-to-like-expressiveness languages.

/be


More information about the es-discuss mailing list