Microsoft/TypeScript

Enum value `1 / 0` incorrectly transformed if there is `Infinity` declared in scope

开放

#55,091 创建于 2023年7月20日

 (3 条评论) (2 个反应) (0 位负责人)TypeScript (13,395 个派生)batch import
BugDomain: enumHelp Wanted

仓库指标

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

描述

Bug Report

🔎 Search Terms

infinity enum variable let shadow

🕗 Version & Regression Information

Every version I tested

⏯ Playground Link

Playground link with relevant code

💻 Code

{
  let Infinity = 3;

  enum A {
    X = 1 / 0
  }

  console.log(A.X)
}

🙁 Actual behavior

{
    let Infinity = 3;
    let A;
    (function (A) {
        A[A["X"] = Infinity] = "X";
    })(A || (A = {}));
    console.log(A.X);
}

and logs 3

🙂 Expected behavior

It should log the result of 1 / 0, which is Infinity.

Somewhat related to https://github.com/microsoft/TypeScript/issues/54981.

贡献者指南