Microsoft/TypeScript

`using` transform throws when a for body binding shadows the for head binding

开放

#61,714 创建于 2025年5月16日

 (6 条评论) (1 个反应) (1 位负责人)TypeScript (13,395 个派生)batch import
BugDomain: API: TransformsHelp Wanted

仓库指标

星标
 (108,860 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

🔎 Search Terms

explicit resource management, using, await using, loop initializer, Symbol.dispose, Symbol.asyncDispose, iteration, shadows

🕗 Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250516#code/MYGwhgzhAEBiD29oG8C+BYAUAM3gJ2gAoBXCASwDsBzaXJebaAbQF0BKFLaaYeCiAC61E0ALzQKAUwDucRITYBuLKiA

💻 Code

class Foo {}
for (using foo of []) {
  const foo = new Foo();
}

🙁 Actual behavior

The transformed output throws "redeclaration of const foo "

🙂 Expected behavior

The transformed output should not throw.

Additional information about the issue

Babel is also affected by this issue: https://github.com/babel/babel/issues/17318. We plan to wrap the for body within a new block when it contains shadowed binding.

贡献者指南