rhendric · GitHub

Could be more tests from generators.ls.

For example:

# yield from in let
first = ->>*
  i = 0
  loop => yield await Promise.resolve i++
second = ->>*
  let
    await Promise.resolve 1
    yield from first!
list = second!
for let i to 3
  {value} <- list.next!then
  eq value, i

(a modified test from generators.ls with an addition of a let block)
This passes, but only due to recent changes.

However this one doesn't:

# in switch
f7 = (x) ->*
    y = switch x
    | true => yield await Promise.resolve 1
    | _    => yield await Promise.resolve 2
    y
g7 = f7 true
g7.next!then -> eq 1 it.value

(a modified test from generators.ls)

Speaking of which, what do you think about my idea from #1060 (comment) to rewrite Node::compile-closure to use Call.let? That way we would avoid duplicating a similar behavior. Moreover, Call.let produces more optimized code, because the wrapper doesn't have to be a (async) generator function, if the body doesn't have await or yield.


Edit: Pardon my foolishness, I forgot to change the arrow ^_^' The test passes.

Read the original on github.com ↗