Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Jul 11, 2023
1 parent 6f71686 commit 96ac676
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/babel-plugin-transform-typescript/src/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["transform-typescript"]
}
Original file line number Diff line number Diff line change
@@ -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 || {});

0 comments on commit 96ac676

Please sign in to comment.