json-as 0.5.31 → 0.5.32

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  ![AssemblyScript](https://img.shields.io/badge/AssemblyScript-blue)
3
3
  ![WebAssembly](https://img.shields.io/badge/WebAssemby-purple)
4
4
 
5
- Probably the fastest JSON implementation for AssemblyScript with many more optimizations coming down the pipeline.
5
+ JSON for AssemblyScript focused on performance, low-overhead, and ease-of-use.
6
6
  ## Installation
7
7
 
8
8
  ```bash
@@ -18,13 +18,13 @@ For arbitrary-length numbers, use
18
18
  npm install as-bignum
19
19
  ```
20
20
 
21
- Add the transform to your `asc` command
21
+ Add the transform to your `asc` command (e.g. in package.json)
22
22
 
23
23
  ```bash
24
24
  --transform json-as/transform
25
25
  ```
26
26
 
27
- Or, add it to `asconfig.json`
27
+ Alternatively, add it to your `asconfig.json`
28
28
 
29
29
  ```
30
30
  {
@@ -75,10 +75,6 @@ const stringified = JSON.stringify<Player>(player);
75
75
  const parsed = JSON.parse<Player>(stringified);
76
76
  ```
77
77
 
78
- ## Notes
79
-
80
- Performance exceeds JavaScript JSON implementation by an average of 230% but this decreases with larger data packets.
81
-
82
78
  ## Planned Features
83
79
 
84
80
  - [x] Serialize
@@ -101,17 +97,25 @@ Performance exceeds JavaScript JSON implementation by an average of 230% but thi
101
97
  - [ ] Arrays
102
98
  ## Performance
103
99
 
104
- **Serialize Object (Vec3):** ~11.1m ops/s
100
+ Number parsing speed has doubled over the last 5 versions due to the use of a `atoi_fast` function found in `assembly/util.ts`. This can be further optimized with SIMD.
101
+
102
+ String serialization has more than tripled in performance (+360%). The algorithm was rewritten for less if statements and more traps.
103
+
104
+ String deserialization was quadrupled from 3.4m ops to 14.8 ops (435%). It went from using `.replaceAll` to a specialized algorithm.
105
+
106
+ Schema (object) parsing is being optimized on GitHub and should be at least doubled if not tripled. (Current speed of barely-optimized version is 6.9m ops) This is due to taking advantage of the types with a type map and eliminating extra checking.
107
+
108
+ **Serialize Object (Vec3):** 6.7m ops/5s
105
109
 
106
- **Deserialize Object (Vec3):** ~3.2m ops/s
110
+ **Deserialize Object (Vec3):** 3.8m ops/5s
107
111
 
108
- **Serialize Array (int[]):** ~1.4m ops/s
112
+ **Serialize Array (int[]):** 6.6m ops/5s
109
113
 
110
- **Deserialize Array (int[]):** ~2.8m ops/s
114
+ **Deserialize Array (int[]):** 8.6m ops/5s
111
115
 
112
- **Serialize String (5):** ~4.2m ops/s
116
+ **Serialize String (5):** 5.9m ops/5s
113
117
 
114
- **Deserialize String (5):** ~12m ops/s
118
+ **Deserialize String (5):** 16.3m ops/5s
115
119
 
116
120
  ## Issues
117
121
 
package/asconfig.json CHANGED
@@ -12,8 +12,6 @@
12
12
  "options": {
13
13
  "transform": [
14
14
  "./transform"
15
- ],
16
- "bindings": "esm"
17
- },
18
- "extends": "./node_modules/@assemblyscript/wasi-shim/asconfig.json"
15
+ ]
16
+ }
19
17
  }
@@ -1,51 +1,91 @@
1
1
  import { JSON } from "..";
2
+ import { backSlashCode, quoteCode } from "../src/chars";
3
+ import { atoi_fast, unsafeCharCodeAt } from "../src/util";
2
4
 
3
5
  @json
4
6
  class Vec3 {
5
7
  x: i32;
6
8
  y: i32;
7
9
  z: i32;
10
+
11
+ /*@inline __JSON_Serialize(data: Vec3): string {
12
+ return `{"x":${data.x.toString()},"y":${data.y.toString()},"z":${data.z.toString()}}`;
13
+ }*/
14
+
15
+ @inline __JSON_Deserialize(data: string, to: Vec3): Vec3 {
16
+ let last = 1;
17
+ let char = 0;
18
+ let inStr = false;
19
+ let key: string | null = null;
20
+ let pos = 0;
21
+ for (; pos < data.length - 1; pos++) {
22
+ char = unsafeCharCodeAt(data, pos);
23
+ if (inStr === false && char === quoteCode) {
24
+ if (key != null) {
25
+ if (unsafeCharCodeAt(key, 0) == 120) {
26
+ to.x = atoi_fast<i32>(data.slice(last, pos - 1))
27
+ } else if (unsafeCharCodeAt(key, 0) == 121) {
28
+ to.y = atoi_fast<i32>(data.slice(last, pos - 1))
29
+ } else if (unsafeCharCodeAt(key, 0) == 122) {
30
+ to.z = atoi_fast<i32>(data.slice(last, pos - 1))
31
+ }
32
+ }
33
+ last = ++pos;
34
+ inStr = true;
35
+ } else if (char === quoteCode && unsafeCharCodeAt(data, pos - 1) != backSlashCode) {
36
+ inStr = false;
37
+ key = data.slice(last, pos);
38
+ last = pos += 2;
39
+ }
40
+ }
41
+ if (key != null) {
42
+ if (unsafeCharCodeAt(key, 0) == 120) {
43
+ to.x = atoi_fast<i32>(data.slice(last, pos - 1))
44
+ } else if (unsafeCharCodeAt(key, 0) == 121) {
45
+ to.y = atoi_fast<i32>(data.slice(last, pos - 1))
46
+ } else if (unsafeCharCodeAt(key, 0) == 122) {
47
+ to.z = atoi_fast<i32>(data.slice(last, pos - 1))
48
+ }
49
+ }
50
+ return to;
51
+ }
8
52
  }
9
53
 
10
- const vec: Vec3 = blackbox<Vec3>({
11
- x: 0,
12
- y: 0,
13
- z: 0
14
- });
54
+ const vec: Vec3 = {
55
+ x: 3,
56
+ y: 1,
57
+ z: 8
58
+ };
59
+
60
+ const vecOut = new Vec3();
15
61
 
62
+ const i32Max = blackbox("429496729");
63
+ /*
16
64
  bench("Stringify Object (Vec3)", () => {
17
- blackbox(JSON.stringify(vec));
18
- });
65
+ blackbox<string>(vec.__JSON_Serialize(vec));
66
+ });*/
19
67
 
68
+ // TODO: Make this allocate without crashing
20
69
  bench("Parse Object (Vec3)", () => {
21
- blackbox(JSON.parse<Vec3>(blackbox('{"x":0,"y":0,"z":0}')));
22
- });/*
23
-
24
- bench("Stringify Array", () => {
25
- blackbox(JSON.stringify(blackbox([1, 2, 3, 4, 5])));
70
+ blackbox<Vec3>(vec.__JSON_Deserialize('{"x":0,"y":0,"z":0}', vec));
26
71
  });
27
- bench("Stringify String Array", () => {
28
- blackbox(JSON.stringify(blackbox(["a", "b", "c", "d", "e"])));
72
+
73
+ bench("Stringify Number Array", () => {
74
+ blackbox(JSON.stringify<i32[]>([1, 2, 3]));
29
75
  });
30
- /*
76
+
31
77
  bench("Parse Array", () => {
32
- blackbox(JSON.parse<i32[]>(blackbox("[1,2,3,4]")));
78
+ blackbox(JSON.parse<i32[]>(blackbox("[1,2,3]")));
33
79
  });
34
80
 
35
- bench("Stringify Nested Array", () => {
36
- blackbox(
37
- JSON.stringify<string[][]>(
38
- blackbox([
39
- ["a", "b", "c"]
40
- ])
41
- )
42
- );
81
+ bench("Stringify Boolean Array", () => {
82
+ blackbox(JSON.stringify<boolean[]>([true, false, true]));
43
83
  });
44
84
 
45
- bench("Parse Nested Array", () => {
46
- blackbox(JSON.parse<string[][]>(blackbox('[["a","b","c"]]')));
85
+ bench("Stringify String Array", () => {
86
+ blackbox(JSON.stringify<string[]>(["a", "b", "c"]));
47
87
  });
48
- */
88
+
49
89
  bench("Stringify String", () => {
50
90
  blackbox(JSON.stringify(blackbox("Hello \"World!")));
51
91
  });
@@ -53,7 +93,7 @@ bench("Stringify String", () => {
53
93
  bench("Parse String", () => {
54
94
  blackbox(JSON.parse<string>(blackbox('"Hello \"World!"')));
55
95
  });
56
- /*
96
+
57
97
  bench("Stringify Boolean", () => {
58
98
  blackbox(JSON.stringify(blackbox(true)));
59
99
  });
@@ -76,4 +116,4 @@ bench("Stringify Float", () => {
76
116
 
77
117
  bench("Parse Float", () => {
78
118
  blackbox(JSON.parse<f32>(blackbox("3.14")));
79
- });*/
119
+ });
@@ -23,7 +23,7 @@ import {
23
23
  uCode,
24
24
  emptyArrayWord
25
25
  } from "./chars";
26
- import { escapeChar, isBigNum, unsafeCharCodeAt } from "./util";
26
+ import { atoi_fast, escapeChar, isBigNum, unsafeCharCodeAt } from "./util";
27
27
 
28
28
  /**
29
29
  * JSON Encoder/Decoder for AssemblyScript
@@ -42,34 +42,21 @@ export namespace JSON {
42
42
  if (isString<T>() && data != null) {
43
43
  // @ts-ignore
44
44
  return serializeString(data);
45
- }
46
- // Boolean
47
- else if (isBoolean<T>()) {
45
+ } else if (isBoolean<T>()) {
48
46
  return data ? "true" : "false";
49
- }
50
- // Nullable
51
- else if (isNullable<T>() && data == null) {
47
+ } else if (isNullable<T>() && data == null) {
52
48
  return "null";
53
- }
54
- // Integers/Floats
55
- // @ts-ignore
56
- else if ((isInteger<T>() || isFloat<T>()) && isFinite(data)) {
49
+ // @ts-ignore
50
+ } else if ((isInteger<T>() || isFloat<T>()) && isFinite(data)) {
57
51
  // @ts-ignore
58
52
  return data.toString();
59
- }
60
- // Class-Based serialization
61
- // @ts-ignore
62
- else if (isDefined(data.__JSON_Serialize)) {
63
53
  // @ts-ignore
64
- //if (isNullable<T>()) return "null";
54
+ } else if (isDefined(data.__JSON_Serialize)) {
65
55
  // @ts-ignore
66
56
  return data.__JSON_Serialize();
67
- }
68
- else if (data instanceof Date) {
57
+ } else if (data instanceof Date) {
69
58
  return data.toISOString();
70
- }
71
- // ArrayLike
72
- else if (isArrayLike<T>()) {
59
+ } else if (isArrayLike<T>()) {
73
60
  // @ts-ignore
74
61
  if (data.length == 0) {
75
62
  return emptyArrayWord;
@@ -87,18 +74,13 @@ export namespace JSON {
87
74
  result += rightBracketWord;
88
75
  return result;
89
76
  // @ts-ignore
90
- } else if (isFloat<valueof<T>>() || isInteger<valueof<T>>()) {
91
- let result = new StringSink(leftBracketWord);
77
+ } else if (isBoolean<valueof<T>>()) {
92
78
  // @ts-ignore
93
- for (let i = 0; i < data.length - 1; i++) {
94
- // @ts-ignore
95
- result.write(JSON.stringify(unchecked(data[i])));
96
- result.write(commaWord);
97
- }
79
+ return leftBracketWord + data.join(commaWord) + rightBracketWord;
98
80
  // @ts-ignore
99
- result.write(JSON.stringify(unchecked(data[data.length - 1])));
100
- result.write(rightBracketWord);
101
- return result.toString();
81
+ } else if (isFloat<valueof<T>>() || isInteger<valueof<T>>()) {
82
+ // @ts-ignore
83
+ return leftBracketWord + data.join(commaWord) + rightBracketWord;
102
84
  } else {
103
85
  let result = new StringSink(leftBracketWord);
104
86
  // @ts-ignore
@@ -164,7 +146,48 @@ export namespace JSON {
164
146
  let type: T;
165
147
  if (isString<T>()) {
166
148
  // @ts-ignore
167
- return data.replaceAll('\\"', '"');
149
+ let result = "";
150
+ let last = 0;
151
+ let char = 0;
152
+ for (let i = 0; i < data.length; i++) {
153
+ // \\"
154
+ if (unsafeCharCodeAt(data, i) === backSlashCode) {
155
+ char = unsafeCharCodeAt(data, ++i);
156
+ result += data.slice(last, i - 1)
157
+ if (char === 34) {
158
+ result += "\"";
159
+ last = ++i;
160
+ } else if (char === 110) {
161
+ result += "\n";
162
+ last = ++i;
163
+ // 92 98 114 116 102 117
164
+ } else if (char >= 92 && char <= 117) {
165
+ if (char === 92) {
166
+ result += "\\";
167
+ last = ++i;
168
+ } else if (char === 98) {
169
+ result += "\b";
170
+ last = ++i;
171
+ } else if (char === 102) {
172
+ result += "\f";
173
+ last = ++i;
174
+ } else if (char === 114) {
175
+ result += "\r";
176
+ last = ++i;
177
+ } else if (char === 116) {
178
+ result += "\t";
179
+ last = ++i;
180
+ } else if (char === 117 && load<u64>(changetype<usize>(data) + <usize>((i + 1) << 1)) === 27584753879220272) {
181
+ result += "\u000b";
182
+ i += 4;
183
+ last = ++i;
184
+ }
185
+ }
186
+ }
187
+ }
188
+ result += data.slice(last);
189
+ // @ts-ignore
190
+ return result;
168
191
  } else if (isBoolean<T>()) {
169
192
  // @ts-ignore
170
193
  return parseBoolean<T>(data);
@@ -193,16 +216,16 @@ export namespace JSON {
193
216
  }
194
217
  }
195
218
 
219
+
196
220
  // @ts-ignore
197
221
  @inline
198
- // @ts-ignore
199
222
  function serializeString(data: string): string {
200
223
  // @ts-ignore
201
224
  if (data.length === 0) return "\"\"";
202
225
  // Fast path for Vectors (3)
203
226
  let char: i32 = 0;
204
227
  if (data.length === 1) {
205
- char === unsafeCharCodeAt(data, 0);
228
+ char = unsafeCharCodeAt(data, 0);
206
229
  if (char === 34) {
207
230
  return "\\\"";
208
231
  } else if (char === 92) {
@@ -359,28 +382,16 @@ function parseBoolean<T extends boolean>(data: string): T {
359
382
  @inline
360
383
  // @ts-ignore
361
384
  export function parseNumber<T>(data: string): T {
385
+ if (isInteger<T>()) {
386
+ // @ts-ignore
387
+ return atoi_fast<T>(data);
388
+ }
362
389
  // @ts-ignore
363
390
  const type: T = 0;
364
391
  // @ts-ignore
365
392
  if (type instanceof f64) return f64.parse(data);
366
393
  // @ts-ignore
367
394
  else if (type instanceof f32) return f32.parse(data);
368
- // @ts-ignore
369
- else if (type instanceof u64) return u64.parse(data);
370
- // @ts-ignore
371
- else if (type instanceof u32) return u32.parse(data);
372
- // @ts-ignore
373
- else if (type instanceof u8) return u8.parse(data);
374
- // @ts-ignore
375
- else if (type instanceof u16) return u16.parse(data);
376
- // @ts-ignore
377
- else if (type instanceof i64) return i64.parse(data);
378
- // @ts-ignore
379
- else if (type instanceof i32) return i32.parse(data);
380
- // @ts-ignore
381
- else if (type instanceof i16) return i16.parse(data);
382
- // @ts-ignore
383
- else if (type instanceof i8) return i8.parse(data);
384
395
  }
385
396
 
386
397
  // @ts-ignore
@@ -1,5 +1,5 @@
1
1
  import { StringSink } from "as-string-sink/assembly";
2
- import { isSpace } from "util/string";
2
+ import { CharCode, isSpace } from "util/string";
3
3
  import { backSlashCode, quoteCode } from "./chars";
4
4
  import { u128, u128Safe, u256, u256Safe, i128, i128Safe, i256Safe } from "as-bignum/assembly";
5
5
 
@@ -78,3 +78,24 @@ export function getArrayDepth<T>(depth: i32 = 1): i32 {
78
78
  return depth;
79
79
  }
80
80
  }
81
+
82
+ /**
83
+ * Implementation of ATOI. Can be much much faster with SIMD.
84
+ * Its pretty fast. (173m ops (atoi_fast) vs 89 ops (parseInt))
85
+ */
86
+ @unsafe
87
+ @inline
88
+ export function atoi_fast<T extends number>(str: string): T {
89
+ // @ts-ignore
90
+ let val: T = 0;
91
+ for (let pos = 0; pos < str.length; pos += 2) {
92
+ // @ts-ignore
93
+ val = (val << 1) + (val << 3) + (load<u16>(changetype<usize>(str) + <usize>pos) - 48);
94
+ // We use load because in this case, there is no need to have bounds-checking
95
+ }
96
+ return val;
97
+ }
98
+
99
+ /**
100
+ *
101
+ */
package/assembly/test.ts CHANGED
@@ -1,4 +1,6 @@
1
+ import { backSlashCode, quoteCode } from "./src/chars";
1
2
  import { JSON } from "./src/json";
3
+ import { atoi_fast, unsafeCharCodeAt } from "./src/util";
2
4
 
3
5
  // @json or @serializable work here
4
6
  @json
@@ -6,33 +8,64 @@ class Vec3 {
6
8
  x!: f32;
7
9
  y!: f32;
8
10
  z!: f32;
11
+
12
+ @inline
13
+ __JSON_Serialize(): string {
14
+ return `{"x":${this.x.toString()},"y":${this.y.toString()},"z":${this.z.toString()}}`;
15
+ }
16
+
17
+ @inline
18
+ __JSON_Deserialize(data: string, to: Vec3): Vec3 {
19
+ let last = 1;
20
+ let char = 0;
21
+ let inStr = false;
22
+ let key: string | null = null;
23
+ let pos = 0;
24
+ for (; pos < data.length - 1; pos++) {
25
+ char = unsafeCharCodeAt(data, pos);
26
+ if (inStr === false && char === quoteCode) {
27
+ if (key != null) {
28
+ if (key == "x") {
29
+ to.x = f32.parse(data.slice(last, pos - 1))
30
+ } else if (key == "y") {
31
+ to.y = f32.parse(data.slice(last, pos - 1))
32
+ } else if (key == "z") {
33
+ to.z = f32.parse(data.slice(last, pos - 1))
34
+ }
35
+ }
36
+ last = ++pos;
37
+ inStr = true;
38
+ } else if (char === quoteCode && unsafeCharCodeAt(data, pos - 1) != backSlashCode) {
39
+ inStr = false;
40
+ key = data.slice(last, pos);
41
+ last = pos += 2;
42
+ }
43
+ }
44
+ if (key != null) {
45
+ if (key == "x") {
46
+ to.x = f32.parse(data.slice(last, pos - 1))
47
+ } else if (key == "y") {
48
+ to.y = f32.parse(data.slice(last, pos - 1))
49
+ } else if (key == "z") {
50
+ to.z = f32.parse(data.slice(last, pos - 1))
51
+ }
52
+ }
53
+ return to;
54
+ }
9
55
  }
10
56
 
11
- @json
12
- class Player {
13
- firstName!: string;
14
- lastName!: string;
15
- lastActive!: i32[];
16
- age!: i32;
17
- pos!: Vec3 | null;
18
- isVerified!: boolean;
57
+ const vec: Vec3 = {
58
+ x: 3.4,
59
+ y: 1.2,
60
+ z: 8.3
19
61
  }
20
62
 
21
- const player: Player = {
22
- firstName: "Emmet",
23
- lastName: "West",
24
- lastActive: [8, 27, 2022],
25
- age: 23,
26
- pos: {
27
- x: 3.4,
28
- y: 1.2,
29
- z: 8.3
30
- },
31
- isVerified: true
32
- };
33
-
34
- const stringified = JSON.stringify<Player>(player);
35
- console.log(stringified);
36
-
37
- const parsed = JSON.parse<Player>(stringified);
38
- console.log(JSON.stringify(parsed));
63
+ const serializedVec3 = vec.__JSON_Serialize();
64
+ console.log(serializedVec3);
65
+
66
+ const parsedVec3 = vec.__JSON_Deserialize(serializedVec3, new Vec3());
67
+ console.log(parsedVec3.__JSON_Serialize());
68
+
69
+ console.log(`atoi_fast("429496729"): ${atoi_fast<i32>("429496729")}`);
70
+
71
+ console.log(`strtol("429496729"): ${i32.parse("429496729")}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-as",
3
- "version": "0.5.31",
3
+ "version": "0.5.32",
4
4
  "description": "JSON encoder/decoder for AssemblyScript",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
@@ -12,7 +12,7 @@
12
12
  "license": "MIT",
13
13
  "scripts": {
14
14
  "aspect": "asp",
15
- "bench:astral": "astral",
15
+ "bench:astral": "astral -Ospeed --noAssert --uncheckedBehavior always",
16
16
  "build:test": "asc assembly/test.ts --target test --runtime stub",
17
17
  "build:transform": "tsc -p ./transform",
18
18
  "test:wasmtime": "wasmtime ./build/test.wasm",
@@ -23,9 +23,9 @@
23
23
  "devDependencies": {
24
24
  "@as-pect/cli": "^8.0.1",
25
25
  "@as-tral/cli": "^2.0.0",
26
- "@assemblyscript/loader": "^0.27.0",
26
+ "@assemblyscript/loader": "^0.27.1",
27
27
  "@assemblyscript/wasi-shim": "^0.1.0",
28
- "assemblyscript": "^0.27.0",
28
+ "assemblyscript": "^0.27.1",
29
29
  "assemblyscript-prettier": "^1.0.7",
30
30
  "prettier": "^2.8.4",
31
31
  "typescript": "^4.9.5",
@@ -37,6 +37,8 @@ class AsJSONTransform extends BaseVisitor {
37
37
  else {
38
38
  this.currentClass.encodeStmts.push(`"${name}":\${JSON.stringify<${type}>(this.${name})},`);
39
39
  }
40
+ this.currentClass.keys.push(name);
41
+ this.currentClass.types.push(type);
40
42
  // @ts-ignore
41
43
  //this.decodeStmts.push(
42
44
  // `${name}: JSON.parseObjectValue<${type}>(values.get("${name}")),\n`
@@ -125,8 +127,6 @@ class AsJSONTransform extends BaseVisitor {
125
127
  const setDataMethod = SimpleParser.parseClassMember(setKeyFunc, node);
126
128
  node.members.push(setDataMethod);
127
129
  this.schemasList.push(this.currentClass);
128
- //console.log(serializeFunc);
129
- //console.log(setKeyFunc);
130
130
  }
131
131
  visitSource(node) {
132
132
  super.visitSource(node);
@@ -0,0 +1,15 @@
1
+ export var Types;
2
+ (function (Types) {
3
+ Types[Types["String"] = 0] = "String";
4
+ Types[Types["u8"] = 1] = "u8";
5
+ Types[Types["i8"] = 2] = "i8";
6
+ Types[Types["u16"] = 3] = "u16";
7
+ Types[Types["i16"] = 4] = "i16";
8
+ Types[Types["u32"] = 5] = "u32";
9
+ Types[Types["i32"] = 6] = "i32";
10
+ Types[Types["u64"] = 7] = "u64";
11
+ Types[Types["i64"] = 8] = "i64";
12
+ Types[Types["f32"] = 9] = "f32";
13
+ Types[Types["f64"] = 10] = "f64";
14
+ Types[Types["boolean"] = 11] = "boolean";
15
+ })(Types || (Types = {}));
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@json-as/transform",
3
- "version": "0.5.31",
3
+ "version": "0.5.32",
4
4
  "description": "JSON encoder/decoder for AssemblyScript",
5
5
  "main": "./lib/index.js",
6
6
  "author": "Jairus Tanaka",
@@ -44,7 +44,9 @@ class AsJSONTransform extends BaseVisitor {
44
44
  `"${name}":\${JSON.stringify<${type}>(this.${name})},`
45
45
  );
46
46
  }
47
-
47
+
48
+ this.currentClass.keys.push(name);
49
+ this.currentClass.types.push(type);
48
50
  // @ts-ignore
49
51
  //this.decodeStmts.push(
50
52
  // `${name}: JSON.parseObjectValue<${type}>(values.get("${name}")),\n`
@@ -136,7 +138,7 @@ class AsJSONTransform extends BaseVisitor {
136
138
  }
137
139
  }
138
140
  `
139
-
141
+
140
142
  const serializeMethod = SimpleParser.parseClassMember(serializeFunc, node);
141
143
  node.members.push(serializeMethod);
142
144
 
@@ -147,9 +149,6 @@ class AsJSONTransform extends BaseVisitor {
147
149
  node.members.push(setDataMethod);
148
150
 
149
151
  this.schemasList.push(this.currentClass);
150
-
151
- //console.log(serializeFunc);
152
- //console.log(setKeyFunc);
153
152
  }
154
153
  visitSource(node: Source): void {
155
154
  super.visitSource(node);