json-as 0.6.4 → 0.6.6
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,7 +1,7 @@
|
|
|
1
1
|
import { JSON } from "./src/json";
|
|
2
2
|
|
|
3
3
|
// @ts-ignore
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
class Vec3 {
|
|
6
6
|
x: f64 = 3.4;
|
|
7
7
|
y: f64 = 1.2;
|
|
@@ -10,7 +10,7 @@ class Vec3 {
|
|
|
10
10
|
|
|
11
11
|
// @ts-ignore
|
|
12
12
|
@json
|
|
13
|
-
class Player {
|
|
13
|
+
class Player extends Vec3 {
|
|
14
14
|
firstName: string;
|
|
15
15
|
lastName: string;
|
|
16
16
|
lastActive: Date;
|
|
@@ -32,6 +32,9 @@ const player: Player = {
|
|
|
32
32
|
z: 8.3,
|
|
33
33
|
},
|
|
34
34
|
isVerified: true,
|
|
35
|
+
x: 1,
|
|
36
|
+
y: 3,
|
|
37
|
+
z: 3
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
let out = "";
|
|
@@ -44,7 +47,7 @@ console.log("Implemented: " + JSON.stringify(JSON.parse<Vec3>('{}', true)));
|
|
|
44
47
|
|
|
45
48
|
console.log("Original: " + JSON.stringify(player));
|
|
46
49
|
//console.log("Revised: " + vec.__JSON_Deserialize('{"x":3,"y":1,"z":8}').__JSON_Serialize());
|
|
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}')));
|
|
50
|
+
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,"x":5","y":4","z":3}')));
|
|
48
51
|
|
|
49
52
|
@serializable
|
|
50
53
|
class Wrapper<T> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-as",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "JSON encoder/decoder for AssemblyScript",
|
|
5
5
|
"types": "assembly/index.ts",
|
|
6
6
|
"author": "Jairus Tanaka",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"scripts": {
|
|
17
|
-
"test
|
|
17
|
+
"test": "asp",
|
|
18
18
|
"bench:astral": "astral --optimizeLevel 3 --shrinkLevel 0 --converge --noAssert --uncheckedBehavior never --runtime stub",
|
|
19
19
|
"build:test": "asc assembly/test.ts -o build/test.wasm --transform ./transform --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json --optimizeLevel 0 --shrinkLevel 0 --noAssert --uncheckedBehavior always --runtime stub",
|
|
20
20
|
"build:bench": "asc bench/benchmark.ts -o bench/benchmark.wasm --transform ./transform --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json --optimizeLevel 3 --shrinkLevel 0 --converge --noAssert --uncheckedBehavior always --runtime stub",
|
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 = [
|
|
@@ -217,5 +212,14 @@ export default class Transformer extends Transform {
|
|
|
217
212
|
transformer.visit(source);
|
|
218
213
|
}
|
|
219
214
|
}
|
|
215
|
+
// Check that every parent and child class is hooked up correctly
|
|
216
|
+
const schemas = transformer.schemasList;
|
|
217
|
+
for (const schema of schemas) {
|
|
218
|
+
if (schema.parent) {
|
|
219
|
+
const parent = schemas.find((v) => v.name === schema.parent);
|
|
220
|
+
if (!parent)
|
|
221
|
+
throw new Error(`Class ${schema.name} extends its parent class ${schema.parent}, but ${schema.parent} does not include a @json or @serializable decorator! Add the decorator and rebuild.`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
220
224
|
}
|
|
221
225
|
}
|
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
|
|
|
@@ -261,5 +255,13 @@ export default class Transformer extends Transform {
|
|
|
261
255
|
transformer.visit(source);
|
|
262
256
|
}
|
|
263
257
|
}
|
|
258
|
+
// Check that every parent and child class is hooked up correctly
|
|
259
|
+
const schemas = transformer.schemasList;
|
|
260
|
+
for (const schema of schemas) {
|
|
261
|
+
if (schema.parent) {
|
|
262
|
+
const parent = schemas.find((v) => v.name === schema.parent);
|
|
263
|
+
if (!parent) throw new Error(`Class ${schema.name} extends its parent class ${schema.parent}, but ${schema.parent} does not include a @json or @serializable decorator! Add the decorator and rebuild.`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
264
266
|
}
|
|
265
267
|
}
|