Skip to content

Commit ae9c675

Browse files
authored
fix: correctly serialize negative numbers (#2790)
This commit fixes a bug where negative numbers were not correctly serialized, because the value parser confused "references" (which is where special negative tokens for special values exist), and "values" (where negative numbers are just negative numbers). The parser now correctly distinguishes between the two.
1 parent 03847e9 commit ae9c675

File tree

8 files changed

+208
-325
lines changed

8 files changed

+208
-325
lines changed

deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"@marvinh-test/fresh-island": "jsr:@marvinh-test/fresh-island@^0.0.1",
6666
"linkedom": "npm:linkedom@^0.16.11",
6767
"@std/async": "jsr:@std/async@1",
68-
"@std/expect": "jsr:@std/expect@1"
68+
"@std/expect": "jsr:@std/expect@1",
69+
"@std/testing": "jsr:@std/testing@1"
6970
},
7071
"compilerOptions": {
7172
"lib": ["dom", "dom.asynciterable", "deno.ns", "deno.unstable"],

deno.lock

Lines changed: 60 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
export const snapshot = {};
2+
3+
snapshot[`round trip - undefined 1`] = `"-1"`;
4+
5+
snapshot[`round trip - null 1`] = `"-2"`;
6+
7+
snapshot[`round trip - 1 1`] = `"[1]"`;
8+
9+
snapshot[`round trip - 2 1`] = `"[2]"`;
10+
11+
snapshot[`round trip - -2 1`] = `"[-2]"`;
12+
13+
snapshot[`round trip - Infinity 1`] = `"-4"`;
14+
15+
snapshot[`round trip - -Infinity 1`] = `"-5"`;
16+
17+
snapshot[`round trip - 0 1`] = `"[0]"`;
18+
19+
snapshot[`round trip - -0 1`] = `"-6"`;
20+
21+
snapshot[`round trip - NaN 1`] = `"-3"`;
22+
23+
snapshot[`round trip - 0 2`] = `"[0]"`;
24+
25+
snapshot[`round trip - true 1`] = `"[true]"`;
26+
27+
snapshot[`round trip - false 1`] = `"[false]"`;
28+
29+
snapshot[`round trip - 'abc' 1`] = `'["abc"]'`;
30+
31+
snapshot[`round trip - 1n 1`] = `'[["BigInt","1"]]'`;
32+
33+
snapshot[`round trip - -1n 1`] = `'[["BigInt","-1"]]'`;
34+
35+
snapshot[`round trip - [ 1, 2, 3 ] 1`] = `"[[1,2,3],1,2,3]"`;
36+
37+
snapshot[`round trip - [ null, undefined, -2 ] 1`] = `"[[-2,-1,1],-2]"`;
38+
39+
snapshot[`round trip - { a: 1, b: null, c: -2 } 1`] = `'[{"a":1,"b":-2,"c":2},1,-2]'`;
40+
41+
snapshot[`round trip - Uint8Array(3) [ 1, 2, 3 ] 1`] = `'[["Uint8Array","AQID"]]'`;
42+
43+
snapshot[`round trip - 1990-05-31T00:00:00.000Z 1`] = `'[["Date","1990-05-31T00:00:00.000Z"]]'`;
44+
45+
snapshot[`round trip - Map(2) { 1 => null, undefined => -2 } 1`] = `'[["Map",[1,-2,-1,2]],1,-2]'`;
46+
47+
snapshot[`round trip - Set(5) { 1, 2, null, -2, NaN } 1`] = `'[["Set",[1,2,-2,3,-3]],1,2,-2]'`;
48+
49+
snapshot[`round trip - [ 1, <1 empty item>, 3 ] 1`] = `"[[1,-7,2],1,3]"`;
50+
51+
snapshot[`round trip - /foo["]/ 1`] = `'[["RegExp","foo[\\\\"]", ""]]'`;
52+
53+
snapshot[`round trip - { a: { foo: 123 }, b: [ { foo: 123 }, { foo: 123 } ] } 1`] = `'[{"a":1,"b":3},{"foo":2},123,[1,1]]'`;
54+
55+
snapshot[`round trip - <ref *1> { a: 1, b: [Circular *1] } 1`] = `'[{"a":1,"b":0},1]'`;

0 commit comments

Comments
 (0)