Skip to content

Directly yielding comprehensions produces unnesesary yield* expresion. #938

@bartosz-m

Description

@bartosz-m

I was using co library when I discovered that yielding comprehensions produces yield* expression just after regular yield but only when comprehensions were yielded directly (without temp variable)

Thouse work as expected:
with temp variable

!->*
    temp = [i**2 for i til 10 ]
    yield temp
(function*(){
  var y, res$, i$, i;
  res$ = [];
  for (i$ = 0; i$ < 10; ++i$) {
    i = i$;
    res$.push(Math.pow(i, 2));
  }
  y = res$;
  (yield y);
});

with hidden temp varible using ..

!->* [i**2 for i til 10 ]
        yield ..
(function*(){
  var x$, res$, i$, i;
  res$ = [];
  for (i$ = 0; i$ < 10; ++i$) {
    i = i$;
    res$.push(Math.pow(i, 2));
  }
  x$ = res$;
  (yield x$);
});

And this doesn't:

!->* yield [i**2 for i til 10 ]
(function*(){
  var i;
  (yield (yield* (function*(){
    var i$, results$ = [];
    for (i$ = 0; i$ < 10; ++i$) {
      i = i$;
      results$.push(Math.pow(i, 2));
    }
    return results$;
  }())));
});

The same goes for object comprehensions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions