-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
Description
Describe the bug
When transpiling generator functions with recursion to ES5, SWC emits additional function values in the iteration result. Node.js and Babel correctly yield only the primitive values, but SWC’s output incorrectly includes anonymous functions.
Input code
function* traverse(obj) {
for (let key of Object.keys(obj)) {
if (typeof obj[key] === 'object') yield* traverse(obj[key]);
else yield obj[key];
}
}
const obj = {
data: [1, 2, 3],
nested: {
fieldName: 'Nested',
fieldData: 'Data'
},
get dataGenerator() {
return traverse(this);
}
};
function func1() {
const generator = (function() {
return obj.dataGenerator;
})();
const res = [];
for (let value of generator) {
res.push(value);
}
return res;
}
function main() {
const res = func1();
console.log(res);
}
main();
Config
Link to the code that reproduces this issue
SWC Info output
No response
Expected behavior
SWC's ES5 should print: [ 1, 2, 3, 'Nested', 'Data' ]
Actual behavior
It prints: [ 1, 2, 3, 'Nested', 'Data', [Function (anonymous)], [Function (anonymous)], [Function (anonymous)] ]
Version
1.13.5
Additional context
No response