If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

yield from an anonymous non generator into a generator yields a surprise

RESOLVED INVALID

Status

()

Firefox
Untriaged
RESOLVED INVALID
2 years ago
2 years ago

People

(Reporter: blindwanderer, Unassigned)

Tracking

(Depends on: 1 bug)

44 Branch
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

2 years ago
User Agent: Mozilla/5.0 (Windows NT 5.1; rv:44.0) Gecko/20100101 Firefox/44.0
Build ID: 20160210153822

Steps to reproduce:

function *weird(){
  [1,2,3,4,5].forEach(function(i){
    yield i;
  });
}


Actual results:

console.log([...weird()]) //-> []

yields nothing because the legacy generator syntax gets invoked.


Expected results:

console.log([...weird()]) //-> [1,2,3,4,5]

Implementing this is blocked by Bug 1083482
(Reporter)

Updated

2 years ago
Depends on: 1083482
There cannot be an yield expression in non-generator function, in term of standard.
When the legacy generator syntax gets removed, the code should just throw an syntax error after `yield`, because 'yield' is just an identifier in non-generator.

if you want to iterate over an array and yield each element, you need to do something like following:

function *weird(){
  for (let i of [1,2,3,4,5]) {
    yield i;
  }
}

console.log([...weird()]);
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.