json-as 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/assembly/test.ts CHANGED
@@ -1,173 +1,173 @@
1
1
  import { JSON } from ".";
2
2
  import { bytes } from "./util";
3
3
 
4
- // @json
5
- // class Obj {
6
- // public a: string = "hello";
7
- // public b: string = "world";
8
- // public c: string = '"\t\f\u0000\u0001';
9
- // }
10
-
11
- // @json
12
- // class Vec3 {
13
- // x: f32 = 0.0;
14
- // y: f32 = 0.0;
15
- // z: f32 = 0.0;
16
- // }
17
-
18
- // @json
19
- // class Player {
20
- // @alias("first name")
21
- // firstName!: string;
22
- // lastName!: string;
23
- // lastActive!: i32[];
24
- // // Drop in a code block, function, or expression that evaluates to a boolean
25
- // @omitif((self: Player) => self.age < 18)
26
- // age!: i32;
27
-
28
- // @omitnull()
29
- // pos!: Vec3 | null;
30
- // isVerified!: boolean;
31
- // }
32
-
33
- // @json
34
- // class Point {}
35
-
36
- // @json
37
- // class NewPoint {
38
- // x: f64 = 0.0;
39
- // y: f64 = 0.0;
40
- // constructor(x: f64, y: f64) {
41
- // this.x = x;
42
- // this.y = y;
43
- // }
4
+ @json
5
+ class Obj {
6
+ public a: string = "hello";
7
+ public b: string = "world";
8
+ public c: string = '"\t\f\u0000\u0001';
9
+ }
44
10
 
45
- // @serializer
46
- // serializer(self: NewPoint): string {
47
- // return `x=${self.x},y=${self.y}`;
48
- // }
11
+ @json
12
+ class Vec3 {
13
+ x: f32 = 0.0;
14
+ y: f32 = 0.0;
15
+ z: f32 = 0.0;
16
+ }
49
17
 
50
- // @deserializer
51
- // deserializer(data: string): NewPoint {
52
- // const dataSize = bytes(data);
18
+ @json
19
+ class Player {
20
+ @alias("first name")
21
+ firstName!: string;
22
+ lastName!: string;
23
+ lastActive!: i32[];
24
+ // Drop in a code block, function, or expression that evaluates to a boolean
25
+ @omitif((self: Player) => self.age < 18)
26
+ age!: i32;
27
+
28
+ @omitnull()
29
+ pos!: Vec3 | null;
30
+ isVerified!: boolean;
31
+ }
53
32
 
54
- // const c = data.indexOf(",");
55
- // const x = data.slice(2, c);
56
- // const y = data.slice(c + 3);
33
+ @json
34
+ class Point {}
57
35
 
58
- // return new NewPoint(f64.parse(x), f64.parse(y));
59
- // }
60
- // }
36
+ @json
37
+ class NewPoint {
38
+ x: f64 = 0.0;
39
+ y: f64 = 0.0;
40
+ constructor(x: f64, y: f64) {
41
+ this.x = x;
42
+ this.y = y;
43
+ }
44
+
45
+ @serializer
46
+ serializer(self: NewPoint): string {
47
+ return `x=${self.x},y=${self.y}`;
48
+ }
49
+
50
+ @deserializer
51
+ deserializer(data: string): NewPoint {
52
+ const dataSize = bytes(data);
53
+
54
+ const c = data.indexOf(",");
55
+ const x = data.slice(2, c);
56
+ const y = data.slice(c + 3);
57
+
58
+ return new NewPoint(f64.parse(x), f64.parse(y));
59
+ }
60
+ }
61
61
 
62
- // @json
63
- // class InnerObj<T> {
64
- // obj: T = instantiate<T>();
65
- // }
62
+ @json
63
+ class InnerObj<T> {
64
+ obj: T = instantiate<T>();
65
+ }
66
66
 
67
- // @json
68
- // class ObjWithBracketString {
69
- // data: string = "";
70
- // }
67
+ @json
68
+ class ObjWithBracketString {
69
+ data: string = "";
70
+ }
71
71
 
72
- // const player: Player = {
73
- // firstName: "Jairus",
74
- // lastName: "Tanaka",
75
- // lastActive: [2, 7, 2025],
76
- // age: 18,
77
- // pos: {
78
- // x: 3.4,
79
- // y: 1.2,
80
- // z: 8.3,
81
- // },
82
- // isVerified: true,
83
- // };
72
+ const player: Player = {
73
+ firstName: "Jairus",
74
+ lastName: "Tanaka",
75
+ lastActive: [2, 7, 2025],
76
+ age: 18,
77
+ pos: {
78
+ x: 3.4,
79
+ y: 1.2,
80
+ z: 8.3,
81
+ },
82
+ isVerified: true,
83
+ };
84
84
 
85
- // const a1 = JSON.stringify("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000a\u000b\u000c\u000d\u000e\u000f\u000f\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f");
86
- // // console.log("Bytes " + bytes(a1).toString());
87
- // console.log("a1: " + a1);
85
+ const a1 = JSON.stringify("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000a\u000b\u000c\u000d\u000e\u000f\u000f\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f");
86
+ // console.log("Bytes " + bytes(a1).toString());
87
+ console.log("a1: " + a1);
88
88
 
89
- // const obj = new Obj();
90
- // const a2 = JSON.stringify(obj);
91
- // // console.log("Bytes " + bytes(a2).toString());
92
- // console.log("a2: " + a2);
89
+ const obj = new Obj();
90
+ const a2 = JSON.stringify(obj);
91
+ // console.log("Bytes " + bytes(a2).toString());
92
+ console.log("a2: " + a2);
93
93
 
94
- // const a3 = JSON.stringify(player);
95
- // // console.log("Bytes " + bytes(a3).toString());
96
- // console.log("a3: " + a3);
94
+ const a3 = JSON.stringify(player);
95
+ // console.log("Bytes " + bytes(a3).toString());
96
+ console.log("a3: " + a3);
97
97
 
98
- // const a4 = new JSON.Obj();
98
+ const a4 = new JSON.Obj();
99
99
 
100
- // a4.set("x", 1.5);
101
- // a4.set("y", 5.4);
102
- // a4.set("z", 9.8);
103
- // a4.set("obj", obj);
104
- // a4.set<boolean>("bool", false);
100
+ a4.set("x", 1.5);
101
+ a4.set("y", 5.4);
102
+ a4.set("z", 9.8);
103
+ a4.set("obj", obj);
104
+ a4.set<boolean>("bool", false);
105
105
 
106
- // console.log("a4: " + JSON.stringify(a4));
106
+ console.log("a4: " + JSON.stringify(a4));
107
107
 
108
- // const a5 = JSON.parse<JSON.Obj>('{"foo":"bar"}');
108
+ const a5 = JSON.parse<JSON.Obj>('{"foo":"bar"}');
109
109
 
110
- // console.log("a5: " + JSON.stringify(a5));
110
+ console.log("a5: " + JSON.stringify(a5));
111
111
 
112
- // const a6 = JSON.parse<JSON.Obj>('{"x":1.5,"y":5.4,"z":9.8,"obj":{"foo":"bar"}}');
112
+ const a6 = JSON.parse<JSON.Obj>('{"x":1.5,"y":5.4,"z":9.8,"obj":{"foo":"bar"}}');
113
113
 
114
- // console.log("a6: " + JSON.stringify(a6));
114
+ console.log("a6: " + JSON.stringify(a6));
115
115
 
116
- // const a7 = JSON.parse<JSON.Value[]>('["string",true,3.14,{"x":1.0,"y":2.0,"z":3.0},[1,2,3,true]]');
116
+ const a7 = JSON.parse<JSON.Value[]>('["string",true,3.14,{"x":1.0,"y":2.0,"z":3.0},[1,2,3,true]]');
117
117
 
118
- // console.log("a7: " + JSON.stringify(a7));
118
+ console.log("a7: " + JSON.stringify(a7));
119
119
 
120
- // const a8 = JSON.stringify(["hello", JSON.stringify("world"), "working?"]);
120
+ const a8 = JSON.stringify(["hello", JSON.stringify("world"), "working?"]);
121
121
 
122
- // console.log("a8: " + a8);
122
+ console.log("a8: " + a8);
123
123
 
124
- // const a9 = JSON.stringify<JSON.Raw>(JSON.Raw.from('"hello world"'));
124
+ const a9 = JSON.stringify<JSON.Raw>(JSON.Raw.from('"hello world"'));
125
125
 
126
- // console.log("a9: " + a9);
126
+ console.log("a9: " + a9);
127
127
 
128
- // const m10 = new Map<string, JSON.Raw>();
129
- // m10.set("hello", new JSON.Raw('"world"'));
130
- // m10.set("pos", new JSON.Raw('{"x":1.0,"y":2.0,"z":3.0}'));
128
+ const m10 = new Map<string, JSON.Raw>();
129
+ m10.set("hello", new JSON.Raw('"world"'));
130
+ m10.set("pos", new JSON.Raw('{"x":1.0,"y":2.0,"z":3.0}'));
131
131
 
132
- // const a10 = JSON.stringify(m10);
132
+ const a10 = JSON.stringify(m10);
133
133
 
134
- // console.log("a10: " + a10);
134
+ console.log("a10: " + a10);
135
135
 
136
- // const a11 = JSON.parse<JSON.Obj>(' { "x" : 3.4 , "y" : 1.2 , "z" : 8.3 } ');
136
+ const a11 = JSON.parse<JSON.Obj>(' { "x" : 3.4 , "y" : 1.2 , "z" : 8.3 } ');
137
137
 
138
- // console.log("a11: " + JSON.stringify(a11));
138
+ console.log("a11: " + JSON.stringify(a11));
139
139
 
140
- // const a12 = JSON.parse<InnerObj<ObjWithBracketString>>('{"obj":{"data":"hello} world"}}');
140
+ const a12 = JSON.parse<InnerObj<ObjWithBracketString>>('{"obj":{"data":"hello} world"}}');
141
141
 
142
- // console.log("a12: " + JSON.stringify(a12));
142
+ console.log("a12: " + JSON.stringify(a12));
143
143
 
144
- // const a13 = JSON.stringify<JSON.Obj>(new JSON.Obj());
144
+ const a13 = JSON.stringify<JSON.Obj>(new JSON.Obj());
145
145
 
146
- // console.log("a13: " + a13);
146
+ console.log("a13: " + a13);
147
147
 
148
- // const a14 = JSON.stringify(new Point());
149
- // console.log("a14: " + a14);
148
+ const a14 = JSON.stringify(new Point());
149
+ console.log("a14: " + a14);
150
150
 
151
- // const a15 = JSON.parse<Point>(a14);
152
- // console.log("a15: " + JSON.stringify(a15));
151
+ const a15 = JSON.parse<Point>(a14);
152
+ console.log("a15: " + JSON.stringify(a15));
153
153
 
154
- // const a16 = JSON.stringify(new NewPoint(1.0, 2.0));
155
- // console.log("a16: " + a16);
154
+ const a16 = JSON.stringify(new NewPoint(1.0, 2.0));
155
+ console.log("a16: " + a16);
156
156
 
157
- // const a17 = JSON.parse<NewPoint>(a16);
158
- // console.log("a17: " + JSON.stringify(a17));
157
+ const a17 = JSON.parse<NewPoint>(a16);
158
+ console.log("a17: " + JSON.stringify(a17));
159
159
 
160
- // const a18 = JSON.parse<JSON.Obj[]>('[{"x":1.0,"y":2.0,"z":3.0},{"x":4.0,"y":5.0,"z":6.0},{"x":7.0,"y":8.0,"z":9.0}]');
161
- // console.log("a18: " + JSON.stringify(a18));
160
+ const a18 = JSON.parse<JSON.Obj[]>('[{"x":1.0,"y":2.0,"z":3.0},{"x":4.0,"y":5.0,"z":6.0},{"x":7.0,"y":8.0,"z":9.0}]');
161
+ console.log("a18: " + JSON.stringify(a18));
162
162
 
163
- // const a19 = JSON.stringify<JSON.Obj[]>(a18);
164
- // console.log("a19: " + a19);
163
+ const a19 = JSON.stringify<JSON.Obj[]>(a18);
164
+ console.log("a19: " + a19);
165
165
 
166
- // const a20 = JSON.parse<JSON.Box<f64>[]>("[1.3,4.7,9.5]");
167
- // console.log("a20: " + JSON.stringify(a20));
166
+ const a20 = JSON.parse<JSON.Box<f64>[]>("[1.3,4.7,9.5]");
167
+ console.log("a20: " + JSON.stringify(a20));
168
168
 
169
- // const a21 = JSON.stringify<JSON.Box<f64>[]>(a20);
170
- // console.log("a21: " + a21);
169
+ const a21 = JSON.stringify<JSON.Box<f64>[]>(a20);
170
+ console.log("a21: " + a21);
171
171
 
172
172
  const a22 = JSON.parse<Foo>('{"id":"0xb8","firstName":"Jairus","lastName":"Tanaka"}');
173
173
  console.log("a22: " + JSON.stringify(a22));
@@ -179,3 +179,40 @@ class Foo {
179
179
  firstName: string = "";
180
180
  lastName: string = "";
181
181
  }
182
+
183
+ @json
184
+ class SrvInfo {
185
+ accessUrl: string = "https://example.com";
186
+ cardTypes: i32[] = [1, 2, 3];
187
+ customService: string = "Contact us at support@example.com";
188
+ invoiceApplicationStatus: i32 = 1;
189
+ isCertification: bool = true;
190
+ isOnlineRecharge: bool = false;
191
+ loginTypes: i32[] = [0, 1]; // e.g. 0 = password, 1 = OTP
192
+ record: string = "ICP 12345678";
193
+ regCompanyAudit: i32 = 2;
194
+ regCompanyPipeline: i32[] = [101, 102, 103];
195
+ regPwdLimit: i32 = 8; // min password length
196
+ serverTime: i64 = 1650000000000; // dummy timestamp
197
+ srvDescription: string = "A demo service for handling customer operations.";
198
+ srvHiddenMenu: string[] = ["admin", "beta"];
199
+ srvHost: string = "srv.example.com";
200
+ srvId: i32 = 999;
201
+ srvKeywords: string[] = ["finance", "payments", "online"];
202
+ srvLogoImgUrl: string = "https://example.com/logo.png";
203
+ srvName: string = "ExampleService";
204
+ srvPageId: i32 = 5;
205
+ thirdAuthUrl: string = "https://auth.example.com";
206
+ userCenterStyle: i32 = 1; // e.g. 1 = modern, 0 = legacy
207
+ }
208
+
209
+ const a23 = JSON.stringify(new SrvInfo());
210
+ console.log("a23: " + a23);
211
+
212
+ const a24 = '{"accessUrl":"https://example.com","cardTypes":[1,2,3],"customService":"Contact us at support@example.com","invoiceApplicationStatus":1,"isCertification":true,"isOnlineRecharge":false,"loginTypes":[0,1],"record":"ICP 12345678","regCompanyAudit":2,"regCompanyPipeline":[101,102,103],"regPwdLimit":8,"serverTime":1650000000000,"srvDescription":"A demo service for handling customer operations.","srvHiddenMenu":["admin","beta"],"srvHost":"srv.example.com","srvId":999,"srvKeywords":["finance","payments","online"],"srvLogoImgUrl":"https://example.com/logo.png","srvName":"ExampleService","srvPageId":5,"thirdAuthUrl":"https://auth.example.com","userCenterStyle":1}';
213
+ console.log("a25: " + (a24 == a23).toString());
214
+
215
+ const a26 = JSON.parse<SrvInfo>(a23);
216
+ console.log("a26: " + JSON.stringify(a26));
217
+
218
+ console.log("a27: " + (JSON.stringify(a26) == a23).toString())
package/index.ts CHANGED
@@ -1 +1,26 @@
1
- export { JSON } from "./assembly/index";
1
+ class SrvInfo {
2
+ accessUrl: string = "https://example.com";
3
+ cardTypes: number[] = [1, 2, 3];
4
+ customService: string = "Contact us at support@example.com";
5
+ invoiceApplicationStatus: number = 1;
6
+ isCertification: bool = true;
7
+ isOnlineRecharge: bool = false;
8
+ loginTypes: number[] = [0, 1]; // e.g. 0 = password, 1 = OTP
9
+ record: string = "ICP 12345678";
10
+ regCompanyAudit: number = 2;
11
+ regCompanyPipeline: number[] = [101, 102, 103];
12
+ regPwdLimit: number = 8; // min password length
13
+ serverTime: i64 = 1650000000000; // dummy timestamp
14
+ srvDescription: string = "A demo service for handling customer operations.";
15
+ srvHiddenMenu: string[] = ["admin", "beta"];
16
+ srvHost: string = "srv.example.com";
17
+ srvId: number = 999;
18
+ srvKeywords: string[] = ["finance", "payments", "online"];
19
+ srvLogoImgUrl: string = "https://example.com/logo.png";
20
+ srvName: string = "ExampleService";
21
+ srvPageId: number = 5;
22
+ thirdAuthUrl: string = "https://auth.example.com";
23
+ userCenterStyle: number = 1; // e.g. 1 = modern, 0 = legacy
24
+ }
25
+
26
+ console.log(JSON.stringify(new SrvInfo()))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-as",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "author": "Jairus Tanaka",
5
5
  "description": "The only JSON library you'll need for AssemblyScript. SIMD enabled",
6
6
  "types": "assembly/index.ts",
@@ -15,6 +15,7 @@
15
15
  "url": "https://github.com/JairusSW/json-as/issues"
16
16
  },
17
17
  "scripts": {
18
+ "ci": "act",
18
19
  "test": "bash ./run-tests.sh",
19
20
  "bench:as": "bash ./run-bench.as.sh",
20
21
  "bench:js": "bash ./run-bench.js.sh",
package/run-tests.sh CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  mkdir -p ./build
4
4
 
5
+ npm run build:test
6
+ npm run test:wasmtime
7
+
5
8
  for file in ./assembly/__tests__/*.spec.ts; do
6
9
  filename=$(basename -- "$file")
7
10
  output="./build/${filename%.ts}.wasm"
@@ -8,7 +8,7 @@ import { Property, PropertyFlags, Schema } from "./types.js";
8
8
  import { getClasses, getImportedClass } from "./linker.js";
9
9
  let indent = " ";
10
10
  const DEBUG = process.env["JSON_DEBUG"];
11
- const STRICT = process.env["JSON_STRICT"] && process.env["JSON_STRICT"] == "false";
11
+ const STRICT = !(process.env["JSON_STRICT"] && process.env["JSON_STRICT"] == "false");
12
12
  class JSONTransform extends Visitor {
13
13
  static SN = new JSONTransform();
14
14
  program;
@@ -300,10 +300,8 @@ class JSONTransform extends Visitor {
300
300
  sortedMembers.object.push(member);
301
301
  }
302
302
  indent = "";
303
- let shouldGroup = false;
304
303
  DESERIALIZE += indent + " let keyStart: usize = 0;\n";
305
- if (shouldGroup || DEBUG)
306
- DESERIALIZE += indent + " let keyEnd: usize = 0;\n";
304
+ DESERIALIZE += indent + " let keyEnd: usize = 0;\n";
307
305
  DESERIALIZE += indent + " let isKey = false;\n";
308
306
  if (sortedMembers.object.length || sortedMembers.array.length)
309
307
  DESERIALIZE += indent + " let depth: i32 = 0;\n";
@@ -321,8 +319,7 @@ class JSONTransform extends Visitor {
321
319
  DESERIALIZE += indent + " if (code == 34 && load<u16>(srcStart - 2) !== 92) {\n";
322
320
  DESERIALIZE += indent + " if (isKey) {\n";
323
321
  DESERIALIZE += indent + " keyStart = lastIndex;\n";
324
- if (shouldGroup || DEBUG)
325
- DESERIALIZE += indent + " keyEnd = srcStart;\n";
322
+ DESERIALIZE += indent + " keyEnd = srcStart;\n";
326
323
  DESERIALIZE += indent + " while (JSON.Util.isSpace((code = load<u16>((srcStart += 2))))) {}\n";
327
324
  DESERIALIZE += indent + " if (code !== 58) throw new Error(\"Expected ':' after key at position \" + (srcEnd - srcStart).toString());\n";
328
325
  DESERIALIZE += indent + " isKey = false;\n";
@@ -334,23 +331,34 @@ class JSONTransform extends Visitor {
334
331
  DESERIALIZE += indent + " srcStart += 2;\n";
335
332
  DESERIALIZE += indent + " } else {\n";
336
333
  const groupMembers = (members) => {
337
- let sorted = [];
338
- let len = -1;
339
- members
340
- .slice()
341
- .sort((a, b) => (a.alias?.length || a.name.length) - (b.alias?.length || b.name.length))
342
- .forEach((member) => {
343
- const _nameLength = member.alias?.length || member.name.length;
344
- if (_nameLength === len) {
345
- sorted[sorted.length - 1].push(member);
334
+ const groups = new Map();
335
+ for (const member of members) {
336
+ const name = member.alias || member.name;
337
+ const length = name.length;
338
+ if (!groups.has(length)) {
339
+ groups.set(length, []);
346
340
  }
347
- else {
348
- sorted.push([member]);
349
- len = _nameLength;
350
- }
351
- });
352
- sorted = sorted.sort((a, b) => b.length - a.length);
353
- return sorted;
341
+ groups.get(length).push(member);
342
+ }
343
+ return [...groups.values()]
344
+ .map(group => group.sort((a, b) => {
345
+ const aLen = (a.alias || a.name).length;
346
+ const bLen = (b.alias || b.name).length;
347
+ return aLen - bLen;
348
+ }))
349
+ .sort((a, b) => b.length - a.length);
350
+ };
351
+ const generateGroups = (members, cb) => {
352
+ const groups = groupMembers(members);
353
+ DESERIALIZE += " switch (<u32>keyEnd - <u32>keyStart) {\n";
354
+ for (const group of groups) {
355
+ const groupLen = (group[0].alias || group[0].name).length << 1;
356
+ DESERIALIZE += " case " + groupLen + ": {\n";
357
+ cb(group);
358
+ DESERIALIZE += "\n }\n";
359
+ }
360
+ DESERIALIZE += " }\n";
361
+ DESERIALIZE += " break;\n";
354
362
  };
355
363
  const generateComparisions = (members) => {
356
364
  if (members.some((m) => (m.alias || m.name).length << 1 == 2)) {
@@ -365,13 +373,10 @@ class JSONTransform extends Visitor {
365
373
  if (members.some((m) => (m.alias || m.name).length << 1 == 8)) {
366
374
  DESERIALIZE += " const code64 = load<u64>(keyStart);\n";
367
375
  }
368
- if (members.some((m) => (m.alias || m.name).length << 1 > 8)) {
369
- DESERIALIZE += toMemCDecl(Math.max(...members.map((m) => (m.alias || m.name).length << 1)), " ");
370
- }
371
376
  const complex = isStruct(members[0].type) || members[0].type != "JSON.Obj" || isArray(members[0].type);
372
377
  const firstMemberName = members[0].alias || members[0].name;
373
378
  DESERIALIZE += indent + " if (" + getComparision(firstMemberName) + ") { // " + firstMemberName + "\n";
374
- DESERIALIZE += indent + " store<" + members[0].type + ">(changetype<usize>(out), JSON.__deserialize<" + members[0].type + ">(lastIndex, srcStart" + (isString(members[0].type) ? " + 2" : "") + "), offsetof<this>(" + JSON.stringify(firstMemberName) + "));\n";
379
+ DESERIALIZE += indent + " store<" + members[0].type + ">(changetype<usize>(out), JSON.__deserialize<" + members[0].type + ">(lastIndex, srcStart" + (isString(members[0].type) ? " + 2" : "") + "), offsetof<this>(" + JSON.stringify(members[0].name) + "));\n";
375
380
  if (isString(members[0].type))
376
381
  DESERIALIZE += indent + " srcStart += 4;\n";
377
382
  else if (!complex)
@@ -383,8 +388,8 @@ class JSONTransform extends Visitor {
383
388
  const member = members[i];
384
389
  const memberName = member.alias || member.name;
385
390
  DESERIALIZE += indent + " else if (" + getComparision(memberName) + ") { // " + memberName + "\n";
386
- DESERIALIZE += indent + " store<" + members[0].type + ">(changetype<usize>(out), JSON.__deserialize<" + members[0].type + ">(lastIndex, srcStart" + (isString(members[0].type) ? " + 2" : "") + "), offsetof<this>(" + JSON.stringify(memberName) + "));\n";
387
- if (isString(members[0].type))
391
+ DESERIALIZE += indent + " store<" + member.type + ">(changetype<usize>(out), JSON.__deserialize<" + member.type + ">(lastIndex, srcStart" + (isString(member.type) ? " + 2" : "") + "), offsetof<this>(" + JSON.stringify(member.name) + "));\n";
392
+ if (isString(member.type))
388
393
  DESERIALIZE += indent + " srcStart += 4;\n";
389
394
  else if (!complex)
390
395
  DESERIALIZE += indent + " srcStart += 2;\n";
@@ -489,9 +494,6 @@ class JSONTransform extends Visitor {
489
494
  if (sortedMembers.boolean.some((m) => (m.alias || m.name).length << 1 == 8)) {
490
495
  DESERIALIZE += " const code64 = load<u64>(keyStart);\n";
491
496
  }
492
- if (sortedMembers.boolean.some((m) => (m.alias || m.name).length << 1 > 8)) {
493
- DESERIALIZE += toMemCDecl(Math.max(...sortedMembers.boolean.map((m) => (m.alias || m.name).length << 1)), " ");
494
- }
495
497
  const firstMemberName = sortedMembers.boolean[0].alias || sortedMembers.boolean[0].name;
496
498
  DESERIALIZE += indent + " if (" + getComparision(firstMemberName) + ") { // " + firstMemberName + "\n";
497
499
  DESERIALIZE += indent + " store<" + sortedMembers.boolean[0].type + ">(changetype<usize>(out), true, offsetof<this>(" + JSON.stringify(sortedMembers.boolean[0].name) + "));\n";
@@ -503,7 +505,7 @@ class JSONTransform extends Visitor {
503
505
  const member = sortedMembers.boolean[i];
504
506
  const memberName = member.alias || member.name;
505
507
  DESERIALIZE += indent + " else if (" + getComparision(memberName) + ") { // " + memberName + "\n";
506
- DESERIALIZE += indent + " store<" + sortedMembers.boolean[0].type + ">(changetype<usize>(out), true, offsetof<this>(" + JSON.stringify(sortedMembers.boolean[0].name) + "));\n";
508
+ DESERIALIZE += indent + " store<" + member.type + ">(changetype<usize>(out), true, offsetof<this>(" + JSON.stringify(member.name) + "));\n";
507
509
  DESERIALIZE += indent + " srcStart += 2;\n";
508
510
  DESERIALIZE += indent + " keyStart = 0;\n";
509
511
  DESERIALIZE += indent + " break;\n";
@@ -528,7 +530,7 @@ class JSONTransform extends Visitor {
528
530
  const member = sortedMembers.boolean[i];
529
531
  const memberName = member.alias || member.name;
530
532
  DESERIALIZE += indent + " else if (" + getComparision(memberName) + ") { // " + memberName + "\n";
531
- DESERIALIZE += indent + " store<" + sortedMembers.boolean[0].type + ">(changetype<usize>(out), false, offsetof<this>(" + JSON.stringify(sortedMembers.boolean[0].name) + "));\n";
533
+ DESERIALIZE += indent + " store<" + member.type + ">(changetype<usize>(out), false, offsetof<this>(" + JSON.stringify(member.name) + "));\n";
532
534
  DESERIALIZE += indent + " srcStart += 2;\n";
533
535
  DESERIALIZE += indent + " keyStart = 0;\n";
534
536
  DESERIALIZE += indent + " break;\n";
@@ -558,9 +560,6 @@ class JSONTransform extends Visitor {
558
560
  if (sortedMembers.null.some((m) => (m.alias || m.name).length << 1 == 8)) {
559
561
  DESERIALIZE += " const code64 = load<u64>(keyStart);\n";
560
562
  }
561
- if (sortedMembers.null.some((m) => (m.alias || m.name).length << 1 > 8)) {
562
- DESERIALIZE += toMemCDecl(Math.max(...sortedMembers.null.map((m) => (m.alias || m.name).length << 1)), " ");
563
- }
564
563
  const firstMemberName = sortedMembers.null[0].alias || sortedMembers.null[0].name;
565
564
  DESERIALIZE += indent + " if (" + getComparision(firstMemberName) + ") { // " + firstMemberName + "\n";
566
565
  DESERIALIZE += indent + " store<" + sortedMembers.null[0].type + ">(changetype<usize>(out), null, offsetof<this>(" + JSON.stringify(sortedMembers.null[0].name) + "));\n";
@@ -572,7 +571,7 @@ class JSONTransform extends Visitor {
572
571
  const member = sortedMembers.null[i];
573
572
  const memberName = member.alias || member.name;
574
573
  DESERIALIZE += indent + " else if (" + getComparision(memberName) + ") { // " + memberName + "\n";
575
- DESERIALIZE += indent + " store<" + sortedMembers.null[0].type + ">(changetype<usize>(out), null, offsetof<this>(" + JSON.stringify(sortedMembers.null[0].name) + "));\n";
574
+ DESERIALIZE += indent + " store<" + member.type + ">(changetype<usize>(out), null, offsetof<this>(" + JSON.stringify(member.name) + "));\n";
576
575
  DESERIALIZE += indent + " srcStart += 2;\n";
577
576
  DESERIALIZE += indent + " keyStart = 0;\n";
578
577
  DESERIALIZE += indent + " break;\n";
@@ -937,7 +936,7 @@ function getComparision(data) {
937
936
  return "code64 == " + toU64(data);
938
937
  }
939
938
  default: {
940
- return toMemCCheck(data);
939
+ return "memory.compare(keyStart, changetype<usize>(" + JSON.stringify(data) + "), keyEnd - keyStart) == 0";
941
940
  }
942
941
  }
943
942
  }