Bug Report
🔎 Search Terms
4.9, compiler regression, for-of, import(), commonJS
🕗 Version & Regression Information
Works fine in 4.8.4 & 4.9.1-beta.
First saw this in the 4.9.2-rc & 4.9.3 and still exists in the current nightly 5.0.0-dev.20221116.
Please keep and fill in the line that best applies:
-->
- This changed between versions 4.9.1-beta and 4.9.2-rc
⏯ Playground Link
v4.9.3 commonjs output with the issue
Properly working v4.8.4 commonjs output
💻 Code
Compiling the following while targeting es2022 w/ commonjs output.
for (const file of [1,2,3]) {
import(`./${file}.json`);
}
PS: The actual code I'm using is storing the resulting promises, but didn't include it in the minimum reproduction code since it didn't make any difference.
🙁 Actual behavior
It imports file 3.json three times, b/c of a new var a_ outside the for-of scope is created and re-used across iterations.
var _a; // <-- was not emitted before 4.9.2-rc
for (const model of [1, 2, 3]) {
_a = `./${model}.json`, Promise.resolve().then(() => __importStar(require(_a)));
}
🙂 Expected behavior
It should import files 1.json, 2.json & 3.json, just like up to 4.9.1-beta.