Civet icon indicating copy to clipboard operation
Civet copied to clipboard

yield in do

Open edemaine opened this issue 1 year ago • 2 comments
trafficstars

What should yield mean inside a do expression/block? The TC39 proposal says that it should yield in the containing function. We already support this with await but don't for yield.

For comparison, the Babel plugin for this proposal (main source code) supports this feature, and suggests a transpilation: just add yield* before the IIFE.

edemaine avatar Dec 22 '23 15:12 edemaine

We should match TC39 on this.

f = (x) ->
  y := do
    await x

A better transpilation for us would be something like:

f = async function (x) {
  let ref;
  {
    ref = await x
  }
  const y = ref;
  return y;
};

Similarly for yield:

f = (x) ->
  y := do
    yield x
f = function* (x) {
  let ref;
  {
    ref = yield x
  }
  const y = ref;
  return y;
};

This ties in with removing IIFEs as much as possible as mentioned in some other issues.

STRd6 avatar Dec 22 '23 17:12 STRd6

I agree that we should do that long term. (#202 and #381 are two of the relevant issues. I've added yield to the title of #202.) But in the short term we can fix this case easily via yield*, so we should do that.

edemaine avatar Dec 22 '23 18:12 edemaine