json-as 0.5.22 → 0.5.24
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/src/json.ts +3 -4
- package/assembly/src/util.ts +2 -2
- package/package.json +1 -1
- package/transform/lib/index.js +17 -3
- package/transform/package.json +1 -1
package/assembly/src/json.ts
CHANGED
|
@@ -128,7 +128,7 @@ export namespace JSON {
|
|
|
128
128
|
// @ts-ignore
|
|
129
129
|
return data.toString();
|
|
130
130
|
} else {
|
|
131
|
-
throw new Error(`Could not serialize data of type ${nameof<T>()}.
|
|
131
|
+
throw new Error(`Could not serialize data of type ${nameof<T>()}. Make sure to add the correct decorators to classes.`);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
@@ -165,7 +165,7 @@ export namespace JSON {
|
|
|
165
165
|
return parseBigNum<T>(data);
|
|
166
166
|
} else {
|
|
167
167
|
// @ts-ignore
|
|
168
|
-
throw new Error(`Could not deserialize data ${data} to type ${nameof<T>()}.
|
|
168
|
+
throw new Error(`Could not deserialize data ${data} to type ${nameof<T>()}. Make sure to add the correct decorators to classes.`);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
// @ts-ignore
|
|
@@ -194,8 +194,7 @@ export namespace JSON {
|
|
|
194
194
|
return parseBigNum<T>(data);
|
|
195
195
|
} else {
|
|
196
196
|
// @ts-ignore
|
|
197
|
-
|
|
198
|
-
throw new Error(`Could not deserialize data ${data} to type ${nameof<T>()}. Invalide data provided.`)
|
|
197
|
+
throw new Error(`Could not deserialize data ${data} to type ${nameof<T>()}. Make sure to add the correct decorators to classes.`)
|
|
199
198
|
}
|
|
200
199
|
}
|
|
201
200
|
}
|
package/assembly/src/util.ts
CHANGED
|
@@ -67,7 +67,7 @@ export function escapeChar(char: string): string {
|
|
|
67
67
|
*/
|
|
68
68
|
export function getArrayDepth<T>(depth: i32 = 1): i32 {
|
|
69
69
|
// @ts-ignore
|
|
70
|
-
if (isArray<T>()) {
|
|
70
|
+
if (!isArray<T>()) {
|
|
71
71
|
return 0;
|
|
72
72
|
// @ts-ignore
|
|
73
73
|
} else if (isArray<valueof<T>>()) {
|
|
@@ -77,4 +77,4 @@ export function getArrayDepth<T>(depth: i32 = 1): i32 {
|
|
|
77
77
|
} else {
|
|
78
78
|
return depth;
|
|
79
79
|
}
|
|
80
|
-
}
|
|
80
|
+
}
|
package/package.json
CHANGED
package/transform/lib/index.js
CHANGED
|
@@ -48,9 +48,9 @@ class AsJSONTransform extends BaseVisitor {
|
|
|
48
48
|
//);
|
|
49
49
|
}
|
|
50
50
|
visitClassDeclaration(node) {
|
|
51
|
-
var
|
|
51
|
+
var _c;
|
|
52
52
|
const className = node.name.text;
|
|
53
|
-
if (!((
|
|
53
|
+
if (!((_c = node.decorators) === null || _c === void 0 ? void 0 : _c.length))
|
|
54
54
|
return;
|
|
55
55
|
let foundDecorator = false;
|
|
56
56
|
for (const decorator of node.decorators) {
|
|
@@ -127,8 +127,22 @@ export default class Transformer extends Transform {
|
|
|
127
127
|
afterParse(parser) {
|
|
128
128
|
// Create new transform
|
|
129
129
|
const transformer = new AsJSONTransform();
|
|
130
|
+
// Sort the sources so that user scripts are visited last
|
|
131
|
+
const sources = parser.sources.filter(source => !isStdlib(source)).sort((_a, _b) => {
|
|
132
|
+
const a = _a.internalPath;
|
|
133
|
+
const b = _b.internalPath;
|
|
134
|
+
if (a[0] === "~" && b[0] !== "~") {
|
|
135
|
+
return -1;
|
|
136
|
+
}
|
|
137
|
+
else if (a[0] !== "~" && b[0] === "~") {
|
|
138
|
+
return 1;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
130
144
|
// Loop over every source
|
|
131
|
-
for (const source of
|
|
145
|
+
for (const source of sources) {
|
|
132
146
|
// Ignore all lib and std. Visit everything else.
|
|
133
147
|
if (!isStdlib(source)) {
|
|
134
148
|
transformer.visit(source);
|