Repository: babel/babel (TypeScript)

Issue:
[Bug]: TypeScript Enums With Global Properties Like `Infinity` or `NaN` Are Transpiled as Members
### How are you using Babel?

REPL

### Input code

```ts
const v = 42;

enum StateEnum {
	okay = 0,
	neg = -Infinity,
	pos = Infinity,
	nan = NaN,
	ext = v,
}
```
[REPL v7.22.8](https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=MYewdgzgLgBAbjAvDALAJgNwCgsFMwCuAtjAMpQCGUuAooSQN5YCQIA1hQJ5IwAMANCzC4A5jwC0ASTAAzAJZg5UToOYAHEBB7T5i5arAUwPAHIUTq3AA9YyOIIC-QA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=typescript&prettier=false&targets=&version=7.22.8&externalPlugins=&assumptions=%7B%7D) - Buggy
[REPL v7.20.15](https://babel.dev/repl#?browsers=&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=MYewdgzgLgBAbjAvDALAJgNwCgsFMwCuAtjAMpQCGUuAooSQN5YCQIA1hQJ5IwAMANCzC4A5jwC0ASTAAzAJZg5UToOYAHEBB7T5i5arAUwPAHIUTq3AA9YyOIIC-QA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=typescript&prettier=false&targets=&version=7.20.15&externalPlugins=&assumptions=%7B%7D) - Okay


### Configuration file name

_No response_

### Configuration

see REPL

### Current and expected behavior

Input:
```ts
const v = 42;

enum StateEnum {
	okay = 0,
	neg = -Infinity,
	pos = Infinity,
	nan = NaN,
	ext = v,
}
```

Buggy Result (7.22.8):
```js
const v = 42;
var StateEnum = function (StateEnum) {
  StateEnum[StateEnum["okay"] = 0] = "okay";
  StateEnum[StateEnum["neg"] = -StateEnum.Infinity] = "neg";
  StateEnum[StateEnum["pos"] = StateEnum.Infinity] = "pos";
  StateEnum[StateEnum["nan"] = StateEnum.NaN] = "nan";
  StateEnum[StateEnum["ext"] = 42] = "ext";
  return StateEnum;
}(StateEnum || {});
```
Correct old Result (7.20.15):
```js
const v = 42;
var StateEnum;
(function (StateEnum) {
  StateEnum[StateEnum["okay"] = 0] = "okay";
  StateEnum[StateEnum["neg"] = -Infinity] = "neg";
  StateEnum[StateEnum["pos"] = Infinity] = "pos";
  StateEnum[StateEnum["nan"] = NaN] = "nan";
  StateEnum[StateEnum["ext"] = v] = "ext";
})(StateEnum || (StateEnum = {}));
```

In the buggy version not `Infinity` is used, but `StateEnum.infinity` - which is `undefined`

### Environment

- REPL 7.22.8

### Possible solution

_No response_

### Additional context

_No response_


Hints:
Hey @htho! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant [Slack community](https://babeljs.slack.com) that typically always has someone willing to help. You can sign-up [here](https://slack.babeljs.io/) for an invite.

Patch:
diff --git a/packages/babel-plugin-transform-typescript/src/enum.ts b/packages/babel-plugin-transform-typescript/src/enum.ts
--- a/packages/babel-plugin-transform-typescript/src/enum.ts
+++ b/packages/babel-plugin-transform-typescript/src/enum.ts
@@ -301,6 +301,10 @@ function computeConstantValue(
     } else if (path.isIdentifier()) {
       const name = path.node.name;
 
+      if (["Infinity", "NaN"].includes(name)) {
+        return Number(name);
+      }
+
       let value = prevMembers?.get(name);
       if (value !== undefined) {
         return value;


Test patch:
diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/regression/15768/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/regression/15768/input.ts
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-typescript/test/fixtures/regression/15768/input.ts
@@ -0,0 +1,11 @@
+const v = 42;
+const v2 = Infinity;
+var Infinity = 1; // Known inconsistencies
+enum StateEnum {
+	okay = 0,
+	neg = -Infinity,
+	pos = Infinity,
+	nan = NaN,
+	ext = v,
+  ext2 = v2,
+}
diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/regression/15768/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/regression/15768/options.json
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-typescript/test/fixtures/regression/15768/options.json
@@ -0,0 +1,3 @@
+{
+  "plugins": ["transform-typescript"]
+}
diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/regression/15768/output.js b/packages/babel-plugin-transform-typescript/test/fixtures/regression/15768/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-typescript/test/fixtures/regression/15768/output.js
@@ -0,0 +1,12 @@
+const v = 42;
+const v2 = Infinity;
+var Infinity = 1; // Known inconsistencies
+var StateEnum = /*#__PURE__*/function (StateEnum) {
+  StateEnum[StateEnum["okay"] = 0] = "okay";
+  StateEnum[StateEnum["neg"] = -Infinity] = "neg";
+  StateEnum[StateEnum["pos"] = Infinity] = "pos";
+  StateEnum[StateEnum["nan"] = NaN] = "nan";
+  StateEnum[StateEnum["ext"] = 42] = "ext";
+  StateEnum[StateEnum["ext2"] = 1] = "ext2";
+  return StateEnum;
+}(StateEnum || {});