json-as 0.5.18 → 0.5.19
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/Candle.ts +18 -0
- package/assembly/test.ts +2 -26
- package/package.json +1 -1
- package/transform/lib/index.js +11 -19
- package/transform/package.json +1 -1
- package/transform/src/index.ts +11 -25
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JSON
|
|
3
|
+
} from ".";
|
|
4
|
+
@json
|
|
5
|
+
export class Candle {
|
|
6
|
+
timestamp!: i64;
|
|
7
|
+
high!: f64;
|
|
8
|
+
low!: f64;
|
|
9
|
+
open!: f64;
|
|
10
|
+
close!: f64;
|
|
11
|
+
constructor(timestamp: i64, high: f64, low: f64, open: f64, close: f64) {
|
|
12
|
+
this.timestamp = timestamp;
|
|
13
|
+
this.high = high;
|
|
14
|
+
this.low = low;
|
|
15
|
+
this.open = open;
|
|
16
|
+
this.close = close;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/assembly/test.ts
CHANGED
|
@@ -1,33 +1,9 @@
|
|
|
1
1
|
import { u128 } from "as-bignum/assembly";
|
|
2
|
+
import { Candle } from "./Candle";
|
|
2
3
|
import {
|
|
3
4
|
JSON
|
|
4
5
|
} from ".";
|
|
5
6
|
|
|
6
|
-
@json
|
|
7
|
-
class Candle {
|
|
8
|
-
timestamp!: i64;
|
|
9
|
-
high!: f64;
|
|
10
|
-
low!: f64;
|
|
11
|
-
open!: f64;
|
|
12
|
-
close!: f64;
|
|
13
|
-
constructor(timestamp: i64, high: f64, low: f64, open: f64, close: f64) {
|
|
14
|
-
this.timestamp = timestamp;
|
|
15
|
-
this.high = high;
|
|
16
|
-
this.low = low;
|
|
17
|
-
this.open = open;
|
|
18
|
-
this.close = close;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//console.log(JSON.stringify(candle));
|
|
23
|
-
|
|
24
|
-
const parsedCandleArray: Candle[] = JSON.parse<Candle[]>(`[{"timestamp":1620248400000,"high":573.3476371851107,"low":572.7653897862947,"close":572.7653897862947,"open":573.3476371851107},{"timestamp":1620249300000,"high":572.4966600947654,"low":572.3690847959957,"close":572.3690847959957,"open":572.4966600947654},{"timestamp":1620250200000,"high":572.2886600465616,"low":571.757999416375,"close":571.757999416375,"open":572.2886600465616},{"timestamp":1620251100000,"high":571.745549588537,"low":571.4831524457645,"close":571.4831524457645,"open":571.745549588537},{"timestamp":1620252000000,"high":571.4291070205617,"low":571.423771655803,"close":571.423771655803,"open":571.4291070205617},{"timestamp":1620252900000,"high":571.2682040427187,"low":570.0124454515138,"close":571.2543224050862,"open":571.2682040427187},{"timestamp":1620253800000,"high":571.950687856295,"low":571.950687856295,"close":571.950687856295,"open":571.950687856295},{"timestamp":1620254700000,"high":574.32247048919,"low":572.229619806987,"close":574.32247048919,"open":572.229619806987},{"timestamp":1620255600000,"high":573.7949788294341,"low":573.7949788294341,"close":573.7949788294341,"open":573.7949788294341},{"timestamp":1620256500000,"high":573.6703031128156,"low":573.6703031128156,"close":573.6703031128156,"open":573.6703031128156},{"timestamp":1620261000000,"high":573.4922654231464,"low":573.4922654231464,"close":573.4922654231464,"open":573.4922654231464},{"timestamp":1620261900000,"high":573.2630790607755,"low":572.1510958054668,"close":572.1510958054668,"open":573.2630790607755},{"timestamp":1620262800000,"high":570.381489136757,"low":570.381489136757,"close":570.381489136757,"open":570.381489136757},{"timestamp":1620264600000,"high":570.2742985701099,"low":570.0803689046074,"close":570.0803689046074,"open":570.2742985701099},{"timestamp":1620265500000,"high":570.1422401263446,"low":570.1422401263446,"close":570.1422401263446,"open":570.1422401263446},{"timestamp":1620266400000,"high":572.8052512272116,"low":572.8052201233321,"close":572.8052512272116,"open":572.8052201233321},{"timestamp":1620267300000,"high":572.7730922927839,"low":572.7447581107978,"close":572.7447581107978,"open":572.7730922927839},{"timestamp":1620268200000,"high":572.7272428903487,"low":572.7258230151764,"close":572.7258230151764,"open":572.7272428903487},{"timestamp":1620270900000,"high":572.2594215468664,"low":571.8195591664584,"close":571.8195591664584,"open":572.2578671930029},{"timestamp":1620271800000,"high":571.2809499888094,"low":571.2808568072832,"close":571.2808568072832,"open":571.2809499888094},{"timestamp":1620272700000,"high":571.1742152842157,"low":571.1742152842157,"close":571.1742152842157,"open":571.1742152842157},{"timestamp":1620273600000,"high":571.1716102454611,"low":571.0288842515337,"close":571.0288842515337,"open":571.0642228722581},{"timestamp":1620275400000,"high":571.0203010949516,"low":571.0203010949516,"close":571.0203010949516,"open":571.0203010949516},{"timestamp":1620277200000,"high":570.261632018576,"low":570.261632018576,"close":570.261632018576,"open":570.261632018576},{"timestamp":1620279000000,"high":570.1348876529629,"low":570.1348876529629,"close":570.1348876529629,"open":570.1348876529629},{"timestamp":1620279900000,"high":570.199730991694,"low":570.199730991694,"close":570.199730991694,"open":570.199730991694},{"timestamp":1620282600000,"high":568.4408310147167,"low":568.4408310147167,"close":568.4408310147167,"open":568.4408310147167},{"timestamp":1620284400000,"high":567.8217236373331,"low":567.5896453383704,"close":567.5896453383704,"open":567.8217236373331},{"timestamp":1620288000000,"high":568.652510360092,"low":568.652510360092,"close":568.652510360092,"open":568.652510360092},{"timestamp":1620288900000,"high":569.0169039594798,"low":569.0169039594798,"close":569.0169039594798,"open":569.0169039594798},{"timestamp":1620289800000,"high":569.1372681718557,"low":569.1372681718557,"close":569.1372681718557,"open":569.1372681718557},{"timestamp":1620293400000,"high":569.1425890413165,"low":569.1425890413165,"close":569.1425890413165,"open":569.1425890413165},{"timestamp":1620294300000,"high":571.4603226652566,"low":569.668539984208,"close":571.3510882379371,"open":569.668539984208},{"timestamp":1620295200000,"high":575.0297756308146,"low":565.6188600247405,"close":575.0297756308146,"open":571.2768914562338},{"timestamp":1620296100000,"high":579.5414875855951,"low":578.0875180733055,"close":579.5414875855951,"open":578.0875180733055},{"timestamp":1620297000000,"high":580.4591998073045,"low":580.4591998073045,"close":580.4591998073045,"open":580.4591998073045},{"timestamp":1620299700000,"high":580.462401844569,"low":580.462401844569,"close":580.462401844569,"open":580.462401844569},{"timestamp":1620303300000,"high":580.450191330308,"low":580.450191330308,"close":580.450191330308,"open":580.450191330308},{"timestamp":1620305100000,"high":580.4060918534583,"low":580.4060918534583,"close":580.4060918534583,"open":580.4060918534583},{"timestamp":1620306000000,"high":580.2988479516713,"low":580.2988479516713,"close":580.2988479516713,"open":580.2988479516713},{"timestamp":1620306900000,"high":578.5227831917862,"low":578.5121109550881,"close":578.5121109550881,"open":578.5227831917862},{"timestamp":1620307800000,"high":578.3521310367136,"low":578.224208690017,"close":578.224208690017,"open":578.3521310367136},{"timestamp":1620308700000,"high":578.1781390176766,"low":578.1781390176766,"close":578.1781390176766,"open":578.1781390176766},{"timestamp":1620309600000,"high":574.5402154361069,"low":574.2966785397088,"close":574.5402154361069,"open":574.2966785397088},{"timestamp":1620310500000,"high":574.6374782052543,"low":574.3595582585991,"close":574.6374782052543,"open":574.3595582585991},{"timestamp":1620311400000,"high":575.0993626799352,"low":575.0993626799352,"close":575.0993626799352,"open":575.0993626799352},{"timestamp":1620313200000,"high":573.7701312728145,"low":573.7701312728145,"close":573.7701312728145,"open":573.7701312728145},{"timestamp":1620314100000,"high":573.3906631152785,"low":573.3906631152785,"close":573.3906631152785,"open":573.3906631152785},{"timestamp":1620315000000,"high":573.4334610811361,"low":573.4334610811361,"close":573.4334610811361,"open":573.4334610811361},{"timestamp":1620315900000,"high":571.6595888644223,"low":571.6595888644223,"close":571.6595888644223,"open":571.6595888644223},{"timestamp":1620316800000,"high":571.7534533028926,"low":571.7534533028926,"close":571.7534533028926,"open":571.7534533028926},{"timestamp":1620317700000,"high":577.9623648979384,"low":574.8537177533384,"close":576.1674529591473,"open":574.8537177533384},{"timestamp":1620318600000,"high":576.1563193117207,"low":576.0620257439493,"close":576.0620257439493,"open":576.1563193117207},{"timestamp":1620319500000,"high":574.275952158709,"low":571.177013121888,"close":571.177013121888,"open":574.275952158709},{"timestamp":1620321300000,"high":571.2079586608608,"low":571.2079586608608,"close":571.2079586608608,"open":571.2079586608608},{"timestamp":1620323100000,"high":571.324057673865,"low":571.324057673865,"close":571.324057673865,"open":571.324057673865},{"timestamp":1620324000000,"high":571.1253547573914,"low":570.0875973567182,"close":570.0875973567182,"open":571.1253547573914},{"timestamp":1620324900000,"high":570.0805475832676,"low":570.0805475832676,"close":570.0805475832676,"open":570.0805475832676},{"timestamp":1620325800000,"high":570.0257972684403,"low":559.1035539331212,"close":559.1035539331212,"open":570.0257972684403},{"timestamp":1620328500000,"high":557.5649037694549,"low":556.0279702412793,"close":556.0279702412793,"open":557.5649037694549},{"timestamp":1620329400000,"high":556.6968218685071,"low":556.6968218685071,"close":556.6968218685071,"open":556.6968218685071},{"timestamp":1620330300000,"high":560.7228138291837,"low":558.2216468935494,"close":560.7228138291837,"open":558.2216468935494},{"timestamp":1620332100000,"high":560.5876666979001,"low":560.5876666979001,"close":560.5876666979001,"open":560.5876666979001},{"timestamp":1620333000000,"high":560.5186489036859,"low":559.9302964393763,"close":559.9302964393763,"open":560.5186489036859},{"timestamp":1620335700000,"high":560.8859962694225,"low":560.8859962694225,"close":560.8859962694225,"open":560.8859962694225},{"timestamp":1620337500000,"high":562.6549059693484,"low":561.1228262312293,"close":562.6549059693484,"open":561.1228262312293},{"timestamp":1620338400000,"high":562.5749239504988,"low":562.5749239504988,"close":562.5749239504988,"open":562.5749239504988},{"timestamp":1620340200000,"high":564.1086094674863,"low":564.1086094674863,"close":564.1086094674863,"open":564.1086094674863},{"timestamp":1620341100000,"high":564.1156752788603,"low":564.1156752788603,"close":564.1156752788603,"open":564.1156752788603},{"timestamp":1620342000000,"high":563.8686326269438,"low":563.8686326269438,"close":563.8686326269438,"open":563.8686326269438},{"timestamp":1620343800000,"high":565.4032072056408,"low":565.4032072056408,"close":565.4032072056408,"open":565.4032072056408},{"timestamp":1620344700000,"high":564.9161906724804,"low":564.846451581273,"close":564.846451581273,"open":564.9161906724804},{"timestamp":1620345600000,"high":565.3129449522828,"low":563.3005556458523,"close":565.3129449522828,"open":563.3005556458523},{"timestamp":1620346500000,"high":566.8491299730733,"low":566.7792504378252,"close":566.7792504378252,"open":566.8491299730733},{"timestamp":1620347400000,"high":567.6311377719769,"low":566.8226586070456,"close":567.6311377719769,"open":566.8226586070456},{"timestamp":1620349200000,"high":568.393145669603,"low":562.3084190409248,"close":562.3084190409248,"open":568.393145669603},{"timestamp":1620350100000,"high":563.0673266288399,"low":563.0673266288399,"close":563.0673266288399,"open":563.0673266288399},{"timestamp":1620351000000,"high":563.0460469915702,"low":563.0460469915702,"close":563.0460469915702,"open":563.0460469915702},{"timestamp":1620351900000,"high":562.6940165863563,"low":562.6940165863563,"close":562.6940165863563,"open":562.6940165863563},{"timestamp":1620352800000,"high":562.2290121119479,"low":562.2290121119479,"close":562.2290121119479,"open":562.2290121119479},{"timestamp":1620354600000,"high":560.6865799646575,"low":559.1464640169283,"close":559.1464640169283,"open":560.6865799646575},{"timestamp":1620356400000,"high":558.6737643409452,"low":558.5032601234623,"close":558.5032601234623,"open":558.6737643409452},{"timestamp":1620358200000,"high":557.7252518300813,"low":557.7252518300813,"close":557.7252518300813,"open":557.7252518300813},{"timestamp":1620359100000,"high":559.452591197762,"low":559.452591197762,"close":559.452591197762,"open":559.452591197762},{"timestamp":1620360000000,"high":557.9238732313372,"low":551.1413593852167,"close":554.1625302396624,"open":557.9238732313372},{"timestamp":1620360900000,"high":555.7240520136215,"low":555.674531175535,"close":555.7240520136215,"open":555.674531175535},{"timestamp":1620361800000,"high":554.0781517227211,"low":554.0781517227211,"close":554.0781517227211,"open":554.0781517227211},{"timestamp":1620362700000,"high":555.9093975255644,"low":554.0935763098537,"close":555.9093975255644,"open":554.0935763098537},{"timestamp":1620363600000,"high":556.7596063111193,"low":556.0023730597429,"close":556.7596063111193,"open":556.0023730597429},{"timestamp":1620365400000,"high":558.3270073972132,"low":556.8114287909416,"close":558.3270073972132,"open":556.8114287909416},{"timestamp":1620367200000,"high":558.7824867555943,"low":558.7824867555943,"close":558.7824867555943,"open":558.7824867555943},{"timestamp":1620369000000,"high":562.0179021454524,"low":560.3025781550792,"close":562.0179021454524,"open":560.3025781550792},{"timestamp":1620369900000,"high":562.0080817771758,"low":562.0080817771758,"close":562.0080817771758,"open":562.0080817771758},{"timestamp":1620373500000,"high":560.4783187009747,"low":560.4783187009747,"close":560.4783187009747,"open":560.4783187009747},{"timestamp":1620374400000,"high":558.9505059072079,"low":558.9505059072079,"close":558.9505059072079,"open":558.9505059072079},{"timestamp":1620375300000,"high":558.7316785819487,"low":558.7315744378288,"close":558.7315744378288,"open":558.7316785819487},{"timestamp":1620376200000,"high":559.2700965276954,"low":558.7201382932576,"close":558.7201382932576,"open":559.2700965276954},{"timestamp":1620377100000,"high":559.7884860040957,"low":558.2725955125745,"close":559.7884860040957,"open":558.3870242987017},{"timestamp":1620378000000,"high":561.2454700974902,"low":559.7277145674427,"close":561.0931142383333,"open":559.7780560002528},{"timestamp":1620379800000,"high":562.5589149792357,"low":561.0392143359311,"close":562.5589149792357,"open":561.0392143359311},{"timestamp":1620381600000,"high":564.825992475405,"low":564.0806119374416,"close":564.825992475405,"open":564.0806119374416},{"timestamp":1620382500000,"high":564.8106789982139,"low":564.8003967441988,"close":564.8003967441988,"open":564.8106789982139},{"timestamp":1620383400000,"high":565.0122815398387,"low":565.0122815398387,"close":565.0122815398387,"open":565.0122815398387},{"timestamp":1620384300000,"high":565.0122384439766,"low":565.0122384439766,"close":565.0122384439766,"open":565.0122384439766},{"timestamp":1620385200000,"high":564.9947583554654,"low":564.9947583554654,"close":564.9947583554654,"open":564.9947583554654},{"timestamp":1620386100000,"high":564.7315180958523,"low":564.726251367374,"close":564.726251367374,"open":564.7315180958523},{"timestamp":1620387000000,"high":566.1025337740446,"low":564.5781421341958,"close":566.1025337740446,"open":564.5781421341958}]`);
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < parsedCandleArray.length; i++) {
|
|
27
|
-
const chunk = parsedCandleArray[i];
|
|
28
|
-
console.log(JSON.stringify(chunk));
|
|
29
|
-
}
|
|
30
|
-
/*
|
|
31
7
|
// @ts-ignore
|
|
32
8
|
@JSON
|
|
33
9
|
class Vec3 {
|
|
@@ -73,4 +49,4 @@ const player: Player = {
|
|
|
73
49
|
const serializedPlayer = JSON.stringify<Player>(player);
|
|
74
50
|
console.log("Serialized Player: " + serializedPlayer);
|
|
75
51
|
const deserializedPlayer = JSON.parse<Player>(serializedPlayer);
|
|
76
|
-
console.log("Deserialized Player: " + JSON.stringify(deserializedPlayer))
|
|
52
|
+
console.log("Deserialized Player: " + JSON.stringify(deserializedPlayer));
|
package/package.json
CHANGED
package/transform/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getName, toString } from "visitor-as/dist/utils.js";
|
|
1
|
+
import { getName, toString, isStdlib } from "visitor-as/dist/utils.js";
|
|
2
2
|
import { BaseVisitor, SimpleParser } from "visitor-as/dist/index.js";
|
|
3
3
|
import { Transform } from "assemblyscript/dist/transform.js";
|
|
4
4
|
class SchemaData {
|
|
@@ -48,7 +48,8 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
48
48
|
//);
|
|
49
49
|
}
|
|
50
50
|
visitClassDeclaration(node) {
|
|
51
|
-
var _a
|
|
51
|
+
var _a;
|
|
52
|
+
const className = node.name.text;
|
|
52
53
|
if (!((_a = node.decorators) === null || _a === void 0 ? void 0 : _a.length))
|
|
53
54
|
return;
|
|
54
55
|
let foundDecorator = false;
|
|
@@ -59,16 +60,13 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
59
60
|
}
|
|
60
61
|
if (!foundDecorator)
|
|
61
62
|
return;
|
|
62
|
-
if (!node.members) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
63
|
// Prevent from being triggered twice
|
|
66
64
|
for (const member of node.members) {
|
|
67
65
|
if (member.name.text == "__JSON_Serialize")
|
|
68
66
|
return;
|
|
69
67
|
}
|
|
70
68
|
this.currentClass = {
|
|
71
|
-
name:
|
|
69
|
+
name: className,
|
|
72
70
|
keys: [],
|
|
73
71
|
values: [],
|
|
74
72
|
types: [],
|
|
@@ -78,21 +76,16 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
78
76
|
setDataStmts: []
|
|
79
77
|
};
|
|
80
78
|
if (this.currentClass.parent.length > 0) {
|
|
81
|
-
const parentSchema = this.schemasList.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
if (parentSchema.length > 0 && ((_b = parentSchema[0]) === null || _b === void 0 ? void 0 : _b.encodeStmts)) {
|
|
87
|
-
(_c = parentSchema[0]) === null || _c === void 0 ? void 0 : _c.encodeStmts.push(((_d = parentSchema[0]) === null || _d === void 0 ? void 0 : _d.encodeStmts.pop()) + ",");
|
|
88
|
-
this.currentClass.encodeStmts.push(...(_e = parentSchema[0]) === null || _e === void 0 ? void 0 : _e.encodeStmts);
|
|
79
|
+
const parentSchema = this.schemasList.find((v) => v.name == this.currentClass.parent);
|
|
80
|
+
if (parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.encodeStmts) {
|
|
81
|
+
parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.encodeStmts.push((parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.encodeStmts.pop()) + ",");
|
|
82
|
+
this.currentClass.encodeStmts.push(...parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.encodeStmts);
|
|
89
83
|
}
|
|
90
84
|
else {
|
|
91
|
-
|
|
85
|
+
console.error("Class extends " + this.currentClass.parent + ", but parent class not found. Maybe add the @json decorator over parent class?");
|
|
92
86
|
}
|
|
93
87
|
}
|
|
94
88
|
this.visit(node.members);
|
|
95
|
-
// const serializedProp = '__JSON_Serialized: string = "";';
|
|
96
89
|
let serializeFunc = "";
|
|
97
90
|
if (this.currentClass.encodeStmts.length > 0) {
|
|
98
91
|
const stmt = this.currentClass.encodeStmts[this.currentClass.encodeStmts.length - 1];
|
|
@@ -117,7 +110,6 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
117
110
|
this.currentClass.setDataStmts.join("")}
|
|
118
111
|
}
|
|
119
112
|
`;
|
|
120
|
-
//console.log(serializeFunc, setKeyFunc)
|
|
121
113
|
const serializeMethod = SimpleParser.parseClassMember(serializeFunc, node);
|
|
122
114
|
node.members.push(serializeMethod);
|
|
123
115
|
const setDataMethod = SimpleParser.parseClassMember(setKeyFunc, node);
|
|
@@ -135,8 +127,8 @@ export default class Transformer extends Transform {
|
|
|
135
127
|
const transformer = new AsJSONTransform();
|
|
136
128
|
// Loop over every source
|
|
137
129
|
for (const source of parser.sources) {
|
|
138
|
-
// Ignore all lib
|
|
139
|
-
if (!source
|
|
130
|
+
// Ignore all lib and std. Visit everything else.
|
|
131
|
+
if (!isStdlib(source)) {
|
|
140
132
|
transformer.visit(source);
|
|
141
133
|
}
|
|
142
134
|
}
|
package/transform/package.json
CHANGED
package/transform/src/index.ts
CHANGED
|
@@ -4,11 +4,7 @@ import {
|
|
|
4
4
|
Source,
|
|
5
5
|
Parser
|
|
6
6
|
} from "assemblyscript/dist/assemblyscript";
|
|
7
|
-
import {
|
|
8
|
-
ClassDecorator,
|
|
9
|
-
registerDecorator,
|
|
10
|
-
} from "visitor-as/dist/decorator.js";
|
|
11
|
-
import { getName, toString } from "visitor-as/dist/utils.js";
|
|
7
|
+
import { getName, toString, isStdlib } from "visitor-as/dist/utils.js";
|
|
12
8
|
import { BaseVisitor, SimpleParser } from "visitor-as/dist/index.js";
|
|
13
9
|
import { Transform } from "assemblyscript/dist/transform.js";
|
|
14
10
|
|
|
@@ -63,6 +59,7 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
63
59
|
//);
|
|
64
60
|
}
|
|
65
61
|
visitClassDeclaration(node: ClassDeclaration): void {
|
|
62
|
+
const className = node.name.text;
|
|
66
63
|
if (!node.decorators?.length) return;
|
|
67
64
|
let foundDecorator = false;
|
|
68
65
|
for (const decorator of node.decorators!) {
|
|
@@ -70,9 +67,6 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
70
67
|
if (decorator.name.text.toLowerCase() == "json" || decorator.name.text.toLowerCase() == "serializable") foundDecorator = true;
|
|
71
68
|
}
|
|
72
69
|
if (!foundDecorator) return;
|
|
73
|
-
if (!node.members) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
70
|
|
|
77
71
|
// Prevent from being triggered twice
|
|
78
72
|
for (const member of node.members) {
|
|
@@ -80,7 +74,7 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
80
74
|
}
|
|
81
75
|
|
|
82
76
|
this.currentClass = {
|
|
83
|
-
name:
|
|
77
|
+
name: className,
|
|
84
78
|
keys: [],
|
|
85
79
|
values: [],
|
|
86
80
|
types: [],
|
|
@@ -89,25 +83,19 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
89
83
|
encodeStmts: [],
|
|
90
84
|
setDataStmts: []
|
|
91
85
|
}
|
|
92
|
-
|
|
86
|
+
|
|
93
87
|
if (this.currentClass.parent.length > 0) {
|
|
94
|
-
const parentSchema = this.schemasList.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
if (parentSchema.length > 0 && parentSchema[0]?.encodeStmts) {
|
|
100
|
-
parentSchema[0]?.encodeStmts.push(parentSchema[0]?.encodeStmts.pop() + ",")
|
|
101
|
-
this.currentClass.encodeStmts.push(...parentSchema[0]?.encodeStmts)
|
|
88
|
+
const parentSchema = this.schemasList.find((v) => v.name == this.currentClass.parent);
|
|
89
|
+
if (parentSchema?.encodeStmts) {
|
|
90
|
+
parentSchema?.encodeStmts.push(parentSchema?.encodeStmts.pop() + ",");
|
|
91
|
+
this.currentClass.encodeStmts.push(...parentSchema?.encodeStmts);
|
|
102
92
|
} else {
|
|
103
|
-
|
|
93
|
+
console.error("Class extends " + this.currentClass.parent + ", but parent class not found. Maybe add the @json decorator over parent class?");
|
|
104
94
|
}
|
|
105
95
|
}
|
|
106
96
|
|
|
107
97
|
this.visit(node.members);
|
|
108
98
|
|
|
109
|
-
// const serializedProp = '__JSON_Serialized: string = "";';
|
|
110
|
-
|
|
111
99
|
let serializeFunc = "";
|
|
112
100
|
|
|
113
101
|
if (this.currentClass.encodeStmts.length > 0) {
|
|
@@ -138,8 +126,6 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
138
126
|
}
|
|
139
127
|
`
|
|
140
128
|
|
|
141
|
-
//console.log(serializeFunc, setKeyFunc)
|
|
142
|
-
|
|
143
129
|
const serializeMethod = SimpleParser.parseClassMember(serializeFunc, node);
|
|
144
130
|
node.members.push(serializeMethod);
|
|
145
131
|
|
|
@@ -163,8 +149,8 @@ export default class Transformer extends Transform {
|
|
|
163
149
|
const transformer = new AsJSONTransform();
|
|
164
150
|
// Loop over every source
|
|
165
151
|
for (const source of parser.sources) {
|
|
166
|
-
// Ignore all lib
|
|
167
|
-
if (!source
|
|
152
|
+
// Ignore all lib and std. Visit everything else.
|
|
153
|
+
if (!isStdlib(source)) {
|
|
168
154
|
transformer.visit(source);
|
|
169
155
|
}
|
|
170
156
|
}
|