jhusain / asyncgenerator

Asynchronous Generators for ES7
391 stars 22 forks source link

Transpiler #7

Open blakelapierre opened 9 years ago

blakelapierre commented 9 years ago

Is there a transpiler for this yet (preferably for Traceur)?

mnieper commented 9 years ago

I've been working on it. The for-on loop is already implemented in the master branch of Traceur behind the --for-on experimental flag.

Please try it out.

The async generators themselves will follow soon.

blakelapierre commented 9 years ago

I'll try it out soon.

I've been using 6to5 lately as it has better feature coverage at the moment and integrates a bit better with my tooling. Any chance of getting it in over there?

mnieper commented 9 years ago

I have been doing it in my spare time, so I'd rather like to implement more features to one tool (in this case, Traceur) than to learn a new transpiler's internals and implement the same things there. However, maybe there is another volunteer to do this.

In any case, the last time I tried out 6to5 I wasn't convinced. They promise more than what they can fulfiill. For example, 6to5 promises to have proper tail call support. But apparently they can only do it for self-recursive functions (which is definitely a very boring use case for PTCs). On the other hand, this code

function f(n, m) {
  if (n === 0) {
    return m;
  }
  return g(n - 1, n * m); 
}

function g(a, b) {
  return f(a, b);
}

is left untouched by the transpiler.

P.S.: Has been addressed here: http://6to5.org/docs/learn-es6/#tail-calls

blakelapierre commented 9 years ago

It's very understandable to implement the features in a single tool. I've briefly looked at Traceur's code and haven't looked at 6to5's at all. I've been primarily focused on applications and tools at the moment, and have mostly been concerned with just getting something that "works". Which, by far, the most important to me has been the syntax improvements.

I was working on a generator library both as an exercise and for use in some applications and tried (hoped!) to combine async functions and generators, which is how I found this project.

I have some experience in compilers so I may soon try to get into some of the internals and see what's going on and contribute where needed, if I can.

mnieper commented 9 years ago

Check out this branch:

https://github.com/mnieper/traceur-compiler/tree/async-generators

mnieper commented 9 years ago

My work has now been merged into the master branch of Traceur. It now includes async generators as well as the for-on loop. Examples can be found under test/feature/AsyncGenerators. Documentation will follow soon.

blakelapierre commented 9 years ago

Very cool, I'll have to find the code I was working on and try it out soon!