json-as 0.6.3 → 0.6.5
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 +23 -0
- package/package.json +1 -1
- package/transform/lib/index.js +1 -6
- package/transform/package.json +1 -1
- package/transform/src/index.ts +1 -7
package/assembly/test.ts
CHANGED
|
@@ -45,6 +45,29 @@ console.log("Implemented: " + JSON.stringify(JSON.parse<Vec3>('{}', true)));
|
|
|
45
45
|
console.log("Original: " + JSON.stringify(player));
|
|
46
46
|
//console.log("Revised: " + vec.__JSON_Deserialize('{"x":3,"y":1,"z":8}').__JSON_Serialize());
|
|
47
47
|
console.log("Implemented: " + JSON.stringify(JSON.parse<Player>('{"firstName":"Emmet","lastName":"West","lastActive":"2023-11-16T04:06:35.108285303Z","age":23,"pos":{"x":3.4,"y":1.2,"z":8.3},"isVerified":true}')));
|
|
48
|
+
|
|
49
|
+
@serializable
|
|
50
|
+
class Wrapper<T> {
|
|
51
|
+
data!: T;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@serializable
|
|
55
|
+
class Foo {
|
|
56
|
+
foo!: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@serializable
|
|
60
|
+
class Bar {
|
|
61
|
+
bar!: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const foo: Wrapper<Foo> = {
|
|
65
|
+
data: new Foo()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
foo.data.foo = "ha";
|
|
69
|
+
console.log(JSON.stringify(foo));
|
|
70
|
+
console.log(JSON.stringify(JSON.parse<Wrapper<Foo>>("{\"data\":{\"foo\":\"ha\"}}")))
|
|
48
71
|
/*
|
|
49
72
|
// 9,325,755
|
|
50
73
|
bench("Stringify Object (Vec3)", () => {
|
package/package.json
CHANGED
package/transform/lib/index.js
CHANGED
|
@@ -58,11 +58,6 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
58
58
|
parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.encodeStmts.push((parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.encodeStmts.pop()) + ",");
|
|
59
59
|
this.currentClass.encodeStmts.push(...parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.encodeStmts);
|
|
60
60
|
}
|
|
61
|
-
else {
|
|
62
|
-
console.error("Class extends " +
|
|
63
|
-
this.currentClass.parent +
|
|
64
|
-
", but parent class not found. Maybe add the @json decorator over parent class?");
|
|
65
|
-
}
|
|
66
61
|
}
|
|
67
62
|
const parentSchema = this.schemasList.find((v) => v.name == this.currentClass.parent);
|
|
68
63
|
const members = [
|
|
@@ -157,7 +152,7 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
157
152
|
// Odd behavior here... When pairing this transform with asyncify, having @inline on __JSON_Set_Key<T> with a generic will cause it to freeze.
|
|
158
153
|
// Binaryen cannot predict and add/mangle code when it is genericed.
|
|
159
154
|
const setKeyFunc = `
|
|
160
|
-
__JSON_Set_Key<
|
|
155
|
+
__JSON_Set_Key<__JSON_Key_Type>(key: __JSON_Key_Type, data: string, val_start: i32, val_end: i32, initializeDefaultValues: boolean): void {
|
|
161
156
|
${
|
|
162
157
|
// @ts-ignore
|
|
163
158
|
this.currentClass.setDataStmts.join("")}
|
package/transform/package.json
CHANGED
package/transform/src/index.ts
CHANGED
|
@@ -65,12 +65,6 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
65
65
|
if (parentSchema?.encodeStmts) {
|
|
66
66
|
parentSchema?.encodeStmts.push(parentSchema?.encodeStmts.pop() + ",");
|
|
67
67
|
this.currentClass.encodeStmts.push(...parentSchema?.encodeStmts);
|
|
68
|
-
} else {
|
|
69
|
-
console.error(
|
|
70
|
-
"Class extends " +
|
|
71
|
-
this.currentClass.parent +
|
|
72
|
-
", but parent class not found. Maybe add the @json decorator over parent class?"
|
|
73
|
-
);
|
|
74
68
|
}
|
|
75
69
|
}
|
|
76
70
|
|
|
@@ -195,7 +189,7 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
195
189
|
// Odd behavior here... When pairing this transform with asyncify, having @inline on __JSON_Set_Key<T> with a generic will cause it to freeze.
|
|
196
190
|
// Binaryen cannot predict and add/mangle code when it is genericed.
|
|
197
191
|
const setKeyFunc = `
|
|
198
|
-
__JSON_Set_Key<
|
|
192
|
+
__JSON_Set_Key<__JSON_Key_Type>(key: __JSON_Key_Type, data: string, val_start: i32, val_end: i32, initializeDefaultValues: boolean): void {
|
|
199
193
|
${
|
|
200
194
|
// @ts-ignore
|
|
201
195
|
this.currentClass.setDataStmts.join("")
|