for await...of loops transformation lost JS labels
Author: XinkaiCreated Sep 28, 2026Updated Sep 28, 2026
LabelsC-bug
Describe the bug
When SWC lowers
myLabel: for await (const i of stream) {
continue myLabel;
}
myLabel: myLabel2: for await (const i of stream) {
break myLabel2;
}to ES5, JS labels are lost in the output. When the output is executed, a SyntaxError gets thrown. This breaks continue or break in the body.
Input code
async function nestedLabels(stream) {
const visited = [];
outer: second: for await (const item of stream) {
if (item === 1) continue outer;
if (item === 2) break second;
visited.push(item);
}
return visited;
}Config
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
"target": "es5",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}Link to the code that reproduces this issue
SWC Info output
No response
Expected behavior
- JS labels are kept
- No runtime error, code semantics hold
Actual behavior
- JS labels are lost
- Runtime SyntaxError
Version
1.16.2
Additional context
No response
Source: swc-project/swc