Closed Bug 1251882 Opened 9 years ago Closed 9 years ago

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

Categories

(Firefox :: Untriaged, defect)

44 Branch
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: blindwanderer, Unassigned)

References

Details

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
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
Closed: 9 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.