json-as 0.5.2 → 0.5.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.
@@ -14,8 +14,9 @@ class AsJSONTransform extends ClassDecorator {
14
14
  public currentClass!: ClassDeclaration;
15
15
  public sources: Source[] = [];
16
16
  public encodeStmts: string[] = [];
17
- public decodeStmts: string[] = [];
18
- public checkDecodeStmts: string[] = [];
17
+ //public decodeStmts: string[] = [];
18
+ public setDataStmts: string[] = [];
19
+ //public checkDecodeStmts: string[] = [];
19
20
 
20
21
  visitMethodDeclaration(): void {}
21
22
  visitFieldDeclaration(node: FieldDeclaration): void {
@@ -33,12 +34,23 @@ class AsJSONTransform extends ClassDecorator {
33
34
  );
34
35
 
35
36
  // @ts-ignore
36
- this.decodeStmts.push(
37
- `${name}: JSON.parseObjectValue<${type}>(values.get("${name}")),\n`
37
+ //this.decodeStmts.push(
38
+ // `${name}: JSON.parseObjectValue<${type}>(values.get("${name}")),\n`
39
+ //);
40
+
41
+ // @ts-ignore
42
+ this.setDataStmts.push(
43
+ `if (key.length === ${name.length} && (memory.compare(changetype<usize>("${name}"), changetype<usize>(key), ${name.length}) == 0)) {
44
+ this.${name} = JSON.parseObjectValue<${type}>(value);
45
+ return;
46
+ }
47
+ `
38
48
  );
39
49
 
40
50
  // @ts-ignore
41
- this.checkDecodeStmts.push(' if (!values.has("${name}")) throw new Error("Key "${name}" was not found. Cannot instantiate object.");\n')
51
+ //this.checkDecodeStmts.push(
52
+ // ' if (!values.has("${name}")) throw new Error("Key "${name}" was not found. Cannot instantiate object.");\n'
53
+ //);
42
54
  }
43
55
  visitClassDeclaration(node: ClassDeclaration): void {
44
56
  if (!node.members) {
@@ -60,33 +72,46 @@ class AsJSONTransform extends ClassDecorator {
60
72
  stmt.length - 1
61
73
  );
62
74
  serializeFunc = `
63
- @inline
64
75
  __JSON_Serialize(): string {
65
76
  return \`{${this.encodeStmts.join("")}}\`;
66
77
  }
67
78
  `;
68
79
  } else {
69
80
  serializeFunc = `
70
- @inline
71
81
  __JSON_Serialize(): string {
72
82
  return "{}";
73
83
  }
74
84
  `;
75
85
  }
76
- const deserializeFunc = `
77
- @inline
86
+ /*const deserializeFunc = `
78
87
  __JSON_Deserialize<T>(values: Map<string, string>): T {
79
- ${process.argv.includes("--debugJSON") ? this.checkDecodeStmts.join("else") : ""}
88
+ ${
89
+ process.argv.includes("--debugJSON")
90
+ ? this.checkDecodeStmts.join("else")
91
+ : ""
92
+ }
80
93
  return {
81
94
  ${
82
- // @ts-ignore
83
- this.decodeStmts.join("")
95
+ // @ts-ignore
96
+ this.decodeStmts.join("")
84
97
  }
85
98
  }
86
99
  }
87
- `;
100
+ `;*/
101
+ const setKeyFunc = `
102
+ __JSON_Set_Key(key: string, value: string): void {
103
+ ${
104
+ // @ts-ignore
105
+ this.setDataStmts.join("")
106
+ }
107
+ throw new Error("Cannot find key: " + key);
108
+ }
109
+ `
110
+ //console.log(setKeyFunc, deserializeFunc, serializeFunc)
88
111
  this.encodeStmts = [];
89
- this.decodeStmts = [];
112
+ //this.decodeStmts = [];
113
+ this.setDataStmts = [];
114
+ //this.checkDecodeStmts = [];
90
115
  const serializedProperty = SimpleParser.parseClassMember(
91
116
  serializedProp,
92
117
  node
@@ -96,11 +121,16 @@ class AsJSONTransform extends ClassDecorator {
96
121
  const serializeMethod = SimpleParser.parseClassMember(serializeFunc, node);
97
122
  node.members.push(serializeMethod);
98
123
 
99
- const deserializeMethod = SimpleParser.parseClassMember(
100
- deserializeFunc,
124
+ //const deserializeMethod = SimpleParser.parseClassMember(
125
+ // deserializeFunc,
126
+ // node
127
+ //);
128
+ //node.members.push(deserializeMethod);
129
+ const setDataMethod = SimpleParser.parseClassMember(
130
+ setKeyFunc,
101
131
  node
102
132
  );
103
- node.members.push(deserializeMethod);
133
+ node.members.push(setDataMethod);
104
134
  }
105
135
  get name(): string {
106
136
  return "json";
package/assembly/type.ts DELETED
@@ -1,13 +0,0 @@
1
- export class Type<T> {
2
- // Edited by transform at compile-time
3
- public value: any;
4
- constructor(value: T) {
5
- this.value = value;
6
- }
7
- set(data: any) {
8
-
9
- }
10
- static from<T>(value: T): Type<T> {
11
- return new Type<T>(value);
12
- }
13
- }