fix(es/codegen): Fix numeric literals (#4733)

This commit is contained in:
magic-akari 2022-05-21 22:14:33 +08:00 committed by GitHub
parent 5ad70cd6d4
commit ea46eb41e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 79 additions and 68 deletions

View File

@ -0,0 +1 @@
expect(9_007_199_254_740_993n).toBe(9007199254740993n);

View File

@ -0,0 +1 @@
9_007_199_254_740_993n;

View File

@ -0,0 +1 @@
9007199254740993n;

View File

@ -0,0 +1,4 @@
expect(1_000).toBe(1000);
expect(0xae_be_ce).toBe(0xaebece);
expect(0b1010_0001_1000_0101).toBe(0b1010000110000101);
expect(0o0_6_6_6).toBe(0o0666);

View File

@ -1,4 +1,4 @@
3;
1;
195;
53;
0b0011;
0B01;
0b11000011;
0B0110101;

View File

@ -1,4 +1,4 @@
3;
1;
195;
53;
0b0011;
0B01;
0b11000011;
0B0110101;

View File

@ -1,14 +1,14 @@
1000000000;
1.10001;
10000000000;
10000000000;
0.0000000001;
11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011;
1e10;
1e+10;
1e-10;
1.1e100;
1.1e+100;
1.1e-100;
123456;
122333;
12.34;
1234000000000000000000000000000000000000000000000000000000;
1234000000000000000000000000000000000000000000000000000000;
0.0000000000000000000000000000000000000000000000000000001234;
12.34e56;
12.34e+56;
12.34e-56;

View File

@ -1,14 +1,14 @@
1000000000;
1.10001;
10000000000;
10000000000;
0.0000000001;
11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011;
1e10;
1e+10;
1e-10;
1.1e100;
1.1e+100;
1.1e-100;
123456;
122333;
12.34;
1234000000000000000000000000000000000000000000000000000000;
1234000000000000000000000000000000000000000000000000000000;
0.0000000000000000000000000000000000000000000000000000001234;
12.34e56;
12.34e+56;
12.34e-56;

View File

@ -1,4 +1,4 @@
17;
1;
285212689;
1114369;
0x0011;
0X01;
0x11000011;
0X0110101;

View File

@ -1,4 +1,4 @@
17;
1;
285212689;
1114369;
0x0011;
0X01;
0x11000011;
0X0110101;

View File

@ -1,4 +1,4 @@
9;
1;
2359305;
36929;
0o0011;
0O01;
0o11000011;
0O0110101;

View File

@ -1,4 +1,4 @@
9;
1;
2359305;
36929;
0o0011;
0O01;
0o11000011;
0O0110101;

View File

@ -577,8 +577,8 @@ where
} else {
match &num.raw {
Some(raw) => {
if raw.contains('_') {
self.wr.write_str_lit(num.span, &num.value.to_string())?;
if self.cfg.target < EsVersion::Es2021 && raw.contains('_') {
self.wr.write_str_lit(num.span, &raw.replace('_', ""))?;
} else {
self.wr.write_str_lit(num.span, raw)?;
}
@ -600,7 +600,11 @@ where
} else {
match &v.raw {
Some(raw) => {
self.wr.write_lit(v.span, raw)?;
if self.cfg.target < EsVersion::Es2021 && raw.contains('_') {
self.wr.write_str_lit(v.span, &raw.replace('_', ""))?;
} else {
self.wr.write_str_lit(v.span, raw)?;
}
}
_ => {
self.wr.write_lit(v.span, &v.value.to_string())?;

View File

@ -4,14 +4,14 @@ const negativeExp = 0.00000001;
const huge = 1000000000001;
const big = 100000000001;
const fractional = 100.2300200;
const numeric_separators = 1000000000000;
const one = 1000;
const two = 1000000;
const three = -1000000;
const bin = 85;
const oct = 342391;
const hex = 3735928559;
const fractional2 = 1000.0001;
const numeric_separators = 1_000_000_000_000;
const one = 1_000;
const two = 1_000_000;
const three = -1_000_000;
const bin = 0b0101_0101;
const oct = 0o0123_4567;
const hex = 0xDEAD_BEEF;
const fractional2 = 1_000.000_100;
const identifier = _1000;
const negate_identifier = -_1000;
const foo = 0.1;
@ -63,20 +63,20 @@ const foo43 = -1000000003242;
const foo43 = 0.0;
const foo44 = -0.0;
const foo45 = +0.0;
const foo46 = 1000000000;
const foo47 = 1.10001;
const foo48 = 10000000000;
const foo49 = 10000000000;
const foo50 = 0.0000000001;
const foo51 = 11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
const foo52 = 11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
const foo53 = 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011;
const foo54 = 123456;
const foo55 = 122333;
const foo56 = 12.34;
const foo57 = 1234000000000000000000000000000000000000000000000000000000;
const foo58 = 1234000000000000000000000000000000000000000000000000000000;
const foo59 = 0.0000000000000000000000000000000000000000000000000000001234;
const foo46 = 1_000_000_000;
const foo47 = 1.1_00_01;
const foo48 = 1e1_0;
const foo49 = 1e+1_0;
const foo50 = 1e-1_0;
const foo51 = 1.1e10_0;
const foo52 = 1.1e+10_0;
const foo53 = 1.1e-10_0;
const foo54 = 12_34_56;
const foo55 = 1_22_333;
const foo56 = 1_2.3_4;
const foo57 = 1_2.3_4e5_6;
const foo58 = 1_2.3_4e+5_6;
const foo59 = 1_2.3_4e-5_6;
const foo60 = 0.100;
const foo61 = 1E1;
const foo62 = 5e+9;
@ -105,7 +105,7 @@ const foo71 = 0XfF;
77.0.toExponential();
const hugefoo = 1000000000001..test();
const hugefoo1 = 0xEE.test();
1234.toString();
1_2_3_4..toString();
const foo72 = 86400000;
const foo73 = 65535;
const foo74 = 0xffff;