-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[babel 8] Numeric literals must be finite and non-negative (#15802)
- Loading branch information
1 parent
1010563
commit 3d47fb6
Showing
6 changed files
with
92 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 18 additions & 8 deletions
26
packages/babel-plugin-transform-typescript/test/fixtures/regression/15768/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
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, | ||
const v3 = NaN; | ||
|
||
{ | ||
let Infinity = 1; | ||
let NaN = 2; | ||
|
||
enum StateEnum { | ||
okay = 0, | ||
neg = -Infinity, | ||
pos = Infinity, | ||
nan = NaN, | ||
negReal = -1 / 0, | ||
posReal = 1 / 0, | ||
nanReal = 0 / 0, | ||
ext = v, | ||
ext2 = v2, | ||
ext3 = v3, | ||
} | ||
} |
28 changes: 18 additions & 10 deletions
28
packages/babel-plugin-transform-typescript/test/fixtures/regression/15768/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
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 || {}); | ||
const v3 = NaN; | ||
{ | ||
let Infinity = 1; | ||
let NaN = 2; | ||
let 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["negReal"] = -Infinity] = "negReal"; | ||
StateEnum[StateEnum["posReal"] = Infinity] = "posReal"; | ||
StateEnum[StateEnum["nanReal"] = NaN] = "nanReal"; | ||
StateEnum[StateEnum["ext"] = 42] = "ext"; | ||
StateEnum[StateEnum["ext2"] = Infinity] = "ext2"; | ||
StateEnum[StateEnum["ext3"] = NaN] = "ext3"; | ||
return StateEnum; | ||
}({}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as t from "../../lib/index.js"; | ||
|
||
const itBabel8 = process.env.BABEL_8_BREAKING ? it : it.skip; | ||
|
||
describe("builders", function () { | ||
itBabel8("t.numericLiteral expexts a non-negative finite value", () => { | ||
expect(() => t.numericLiteral(-1)).toThrow(); | ||
expect(() => t.numericLiteral(-0)).toThrow(); | ||
expect(() => t.numericLiteral(-Infinity)).toThrow(); | ||
expect(() => t.numericLiteral(Infinity)).toThrow(); | ||
expect(() => t.numericLiteral(NaN)).toThrow(); | ||
}); | ||
}); |