Microsoft/TypeScript

async code generator does not correctly handle labelled blocks

Open

#50,332 建立於 2022年8月17日

在 GitHub 查看
 (1 留言) (2 反應) (0 負責人)TypeScript (6,726 fork)batch import
BugDomain: JS EmitHelp Wanted

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

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

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about everything

⏯ Playground Link

Playground link with relevant code

💻 Code

Compiler options: --lib ES2015,dom --target ES5

async function foo() {
    tmp: {
        for (let x = 0; x < 4; x++)
            if (await Promise.resolve(true))
                break tmp;
        console.log("Impossible");
        throw 0;
    }
    console.log("Success");
}

foo();

🙁 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 block

Interestingly, 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.

貢獻者指南