fix(es/compat): Visit children of while statement in the generator pass (#7624)

**Related issue:**

 - Closes #7622.
This commit is contained in:
Donny/강동윤 2023-07-06 12:27:49 +09:00 committed by GitHub
parent 2e7b05e588
commit d2ac2c16a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,19 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false
},
"target": "es5",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}

View File

@ -0,0 +1,11 @@
async function asyncWhile() {
while (true) {
return {};
}
}
function* generatorWhile() {
while (true) {
return {};
}
}

View File

@ -0,0 +1,34 @@
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
function asyncWhile() {
return _asyncWhile.apply(this, arguments);
}
function _asyncWhile() {
_asyncWhile = _async_to_generator(function() {
return _ts_generator(this, function(_state) {
while(true){
return [
2,
{}
];
}
return [
2
];
});
});
return _asyncWhile.apply(this, arguments);
}
function generatorWhile() {
return _ts_generator(this, function(_state) {
while(true){
return [
2,
{}
];
}
return [
2
];
});
}

View File

@ -1646,6 +1646,8 @@ impl Generator {
self.emit_break(loop_label, None);
self.end_loop_block();
} else {
node.visit_mut_children_with(self);
self.emit_stmt(Stmt::While(node));
}
}