Skip to content

Commit 79e9bb1

Browse files
author
Josh Goldberg
committed
Added explicit check for scientific notation
1 parent 99f9719 commit 79e9bb1

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33689,9 +33689,10 @@ namespace ts {
3368933689
}
3369033690

3369133691
function checkNumericLiteralValueSize(node: NumericLiteral) {
33692+
// Scientific notation (e.g. 2e54 and 1e00000000010) can't be converted to bigint
3369233693
// Literals with 15 or fewer characters aren't long enough to reach past 2^53 - 1
3369333694
// Fractional numbers (e.g. 9000000000000000.001) are inherently imprecise anyway
33694-
if (node.text.length <= 15 || node.text.indexOf(".") !== -1) {
33695+
if (node.numericLiteralFlags & TokenFlags.Scientific || node.text.length <= 15 || node.text.indexOf(".") !== -1) {
3369533696
return;
3369633697
}
3369733698

tests/cases/fourslash/codeFixUseBigIntLiteral.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
////2e52;
1919
////2e53;
2020
////2e54;
21+
////1e00000000010;
2122

2223
verify.codeFix({
2324
description: ts.Diagnostics.Convert_to_a_bigint_numeric_literal.message,
@@ -41,7 +42,8 @@ verify.codeFix({
4142
-0x20000000000001;
4243
2e52;
4344
2e53;
44-
2e54;`
45+
2e54;
46+
1e00000000010;`
4547
});
4648

4749
verify.codeFixAll({
@@ -66,5 +68,6 @@ verify.codeFixAll({
6668
-0x20000000000001n;
6769
2e52;
6870
2e53;
69-
2e54;`
71+
2e54;
72+
1e00000000010;`
7073
});

0 commit comments

Comments
 (0)