Open Maxdamantus opened 2 years ago
I should probably have actually simplified it a bit further, since it's not dependent on any await
-based condition:
async function foo() {
tmp: {
for (let x = 0; x < 4; x++) {
break tmp;
await Promise.resolve();
}
console.log("Impossible");
throw 0;
}
console.log("Success");
}
foo();
The code above should be statically known to log Success
, since the await
never actually happens. The generated code instead jumps to the Impossible
branch.
Bug Report
When using the "ES5" target,
async
/await
code generation does not correctly handle breaking from labelled blocks.π Search Terms
break block label async
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
Compiler options:
--lib ES2015,dom --target ES5
π Actual behavior
"Impossible" is logged, because the
break
statement seems to short-circuit the inner loopπ Expected behavior
"Success" is logged, because the
break
statement should short-circuit the outer blockInterestingly, it does seem to handle breaking from outer loops (eg adding a superfluous loop,
tmp: for (let nvm = 0; nvm < 1; nvm++) ...
), but not plain blocks.