json-as 0.9.8 → 0.9.9

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.
Files changed (63) hide show
  1. package/.github/workflows/nodejs.yml +9 -10
  2. package/CHANGELOG +10 -2
  3. package/README.md +55 -8
  4. package/asconfig.json +24 -3
  5. package/assembly/__tests__/test.spec.ts +564 -0
  6. package/assembly/__tests__/types.ts +82 -0
  7. package/assembly/{src/chars.ts → chars.ts} +36 -36
  8. package/assembly/deserialize/array/array.ts +4 -4
  9. package/assembly/deserialize/array/bool.ts +4 -4
  10. package/assembly/deserialize/array/float.ts +4 -4
  11. package/assembly/deserialize/array/integer.ts +4 -4
  12. package/assembly/deserialize/array/map.ts +4 -4
  13. package/assembly/deserialize/array/object.ts +4 -4
  14. package/assembly/deserialize/array/string.ts +4 -4
  15. package/assembly/deserialize/array.ts +5 -4
  16. package/assembly/deserialize/bool.ts +4 -4
  17. package/assembly/deserialize/date.ts +2 -2
  18. package/assembly/deserialize/float.ts +2 -2
  19. package/assembly/deserialize/integer.ts +3 -3
  20. package/assembly/deserialize/map.ts +4 -4
  21. package/assembly/deserialize/mpz.ts +12 -0
  22. package/assembly/deserialize/object.ts +4 -4
  23. package/assembly/deserialize/string.ts +5 -5
  24. package/assembly/index.ts +25 -23
  25. package/assembly/serialize/array.ts +6 -5
  26. package/assembly/serialize/bool.ts +2 -2
  27. package/assembly/serialize/date.ts +2 -2
  28. package/assembly/serialize/float.ts +2 -2
  29. package/assembly/serialize/integer.ts +2 -2
  30. package/assembly/serialize/map.ts +8 -7
  31. package/assembly/serialize/mpz.ts +6 -0
  32. package/assembly/serialize/object.ts +2 -2
  33. package/assembly/serialize/string.ts +5 -5
  34. package/assembly/serialize/unknown.ts +5 -5
  35. package/assembly/test.ts +30 -40
  36. package/assembly/types.ts +4 -0
  37. package/assembly/{src/util.ts → util.ts} +3 -3
  38. package/bench/benchmark.ts +1 -1
  39. package/build/test.spec.wasm +0 -0
  40. package/build/test.spec.wasm.map +1 -0
  41. package/build/test.spec.wat +112683 -0
  42. package/build/test.wasm +0 -0
  43. package/build/test.wasm.map +1 -0
  44. package/build/test.wat +24968 -0
  45. package/package.json +11 -12
  46. package/transform/lib/index.js +12 -0
  47. package/transform/lib/visitor.js +516 -0
  48. package/transform/package.json +1 -1
  49. package/transform/src/index.ts +8 -0
  50. package/transform/src/visitor.ts +543 -0
  51. package/transform/tsconfig.json +23 -63
  52. package/tsconfig.json +13 -13
  53. package/as-pect.asconfig.json +0 -24
  54. package/as-pect.config.js +0 -30
  55. package/assembly/__tests__/deserialize.spec.ts +0 -301
  56. package/assembly/__tests__/serialize.spec.ts +0 -398
  57. package/assembly/deserialize/box.ts +0 -17
  58. package/assembly/serialize/box.ts +0 -11
  59. package/develop/assembly/serialize/unknown.ts +0 -46
  60. package/transform/lib/index.old.js +0 -257
  61. package/transform/lib/types.js +0 -17
  62. package/transform/src/index.old.ts +0 -312
  63. /package/assembly/{src/sink.ts → sink.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-as",
3
- "version": "0.9.8",
3
+ "version": "0.9.9",
4
4
  "description": "JSON encoder/decoder for AssemblyScript",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
@@ -15,12 +15,10 @@
15
15
  ],
16
16
  "license": "MIT",
17
17
  "scripts": {
18
- "test": "npm run test:serialize && npm run test:deserialize",
19
- "test:serialize": "wasmtime build/serialize.spec.wasm",
20
- "test:deserialize": "wasmtime build/deserialize.spec.wasm",
21
- "tests:build": "asc assembly/__tests__/serialize.spec.ts -o build/serialize.spec.wasm --transform ./transform --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json --optimizeLevel 0 --shrinkLevel 0 --noAssert --uncheckedBehavior always & asc assembly/__tests__/deserialize.spec.ts -o build/deserialize.spec.wasm --transform ./transform --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json --optimizeLevel 0 --shrinkLevel 0 --noAssert --uncheckedBehavior always",
22
- "build:test": "JSON_DEBUG=true 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",
23
- "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",
18
+ "test": "wasmtime build/test.spec.wasm",
19
+ "pretest": "asc assembly/__tests__/test.spec.ts --target test",
20
+ "build:test": "JSON_DEBUG=true asc assembly/test.ts --target debug",
21
+ "build:bench": "asc bench/benchmark.ts -o bench/benchmark.wasm --transform ./transform --optimizeLevel 3 --shrinkLevel 0 --converge --noAssert --uncheckedBehavior always --runtime stub",
24
22
  "bench:wasmtime": "wasmtime ./bench/benchmark.wasm",
25
23
  "bench:wasmer": "wasmer --llvm ./bench/benchmark.wasm",
26
24
  "build:transform": "tsc -p ./transform",
@@ -33,20 +31,21 @@
33
31
  "devDependencies": {
34
32
  "@assemblyscript/wasi-shim": "^0.1.0",
35
33
  "as-bench": "^0.0.0-alpha",
36
- "assemblyscript": "^0.27.27",
34
+ "as-console": "^7.0.0",
35
+ "assemblyscript": "^0.27.28",
37
36
  "assemblyscript-prettier": "^3.0.1",
38
37
  "benchmark": "^2.1.4",
38
+ "json-as": "link:json-as",
39
39
  "microtime": "^3.1.1",
40
40
  "prettier": "^3.3.2",
41
41
  "tinybench": "^2.8.0",
42
- "typescript": "^5.4.5",
42
+ "typescript": "^5.5.3",
43
43
  "visitor-as": "^0.11.4"
44
44
  },
45
45
  "dependencies": {
46
- "as-container": "^0.8.0",
46
+ "@hypercubed/as-mpz": "^2.2.0",
47
47
  "as-string-sink": "^0.5.3",
48
- "as-test": "^0.0.3",
49
- "as-variant": "^0.4.1",
48
+ "as-test": "^0.1.4",
50
49
  "as-virtual": "^0.2.0"
51
50
  },
52
51
  "overrides": {
@@ -150,6 +150,18 @@ class JSONTransform extends BaseVisitor {
150
150
  else if (mem.value) {
151
151
  mem.initialize = "this." + name.text + " = " + mem.value;
152
152
  }
153
+ else if (t === "Map") {
154
+ mem.initialize = "this." + name.text + " = new " + mem.type + "()";
155
+ }
156
+ else if (t === "string") {
157
+ mem.initialize = "this." + name.text + " = \"\"";
158
+ }
159
+ else if (t === "Array") {
160
+ mem.initialize = "this." + name.text + " = instantiate<" + mem.type + ">()";
161
+ }
162
+ else {
163
+ console.log(t);
164
+ }
153
165
  schema.members.push(mem);
154
166
  }
155
167
  let SERIALIZE_RAW = "__SERIALIZE(): string {\n let out = `{";
@@ -0,0 +1,516 @@
1
+ import { ArrayLiteralExpression, AssertionExpression, BinaryExpression, CallExpression, ElementAccessExpression, FloatLiteralExpression, FunctionTypeNode, IdentifierExpression, NamedTypeNode, Node, ObjectLiteralExpression, Source, TypeParameterNode, BlockStatement, BreakStatement, ClassDeclaration, ClassExpression, CommaExpression, ContinueStatement, DecoratorNode, DoStatement, EmptyStatement, EnumDeclaration, EnumValueDeclaration, ExportDefaultStatement, ExportImportStatement, ExportMember, ExportStatement, ExpressionStatement, FieldDeclaration, ForStatement, FunctionDeclaration, FunctionExpression, IfStatement, ImportDeclaration, ImportStatement, IndexSignatureNode, InstanceOfExpression, IntegerLiteralExpression, InterfaceDeclaration, LiteralExpression, MethodDeclaration, NamespaceDeclaration, NewExpression, ParameterNode, ParenthesizedExpression, PropertyAccessExpression, RegexpLiteralExpression, ReturnStatement, StringLiteralExpression, SwitchCase, SwitchStatement, TemplateLiteralExpression, TernaryExpression, ThrowStatement, TryStatement, TypeDeclaration, TypeName, UnaryPostfixExpression, UnaryPrefixExpression, VariableDeclaration, VariableStatement, WhileStatement, } from "assemblyscript/dist/assemblyscript.js";
2
+ export class Visitor {
3
+ constructor() {
4
+ this.currentSource = null;
5
+ this.depth = 0;
6
+ }
7
+ visit(node) {
8
+ if (node == null) {
9
+ return;
10
+ }
11
+ else if (node instanceof Array) {
12
+ for (const element of node) {
13
+ this.visit(element);
14
+ }
15
+ }
16
+ else if (node instanceof Map) {
17
+ for (const element of node.values()) {
18
+ this.visit(element);
19
+ }
20
+ // @ts-ignore
21
+ }
22
+ else if (typeof node[Symbol.iterator] === "function") {
23
+ // @ts-ignore
24
+ for (const element of node) {
25
+ this.visit(element);
26
+ }
27
+ }
28
+ else if (node instanceof Node) {
29
+ this._visit(node);
30
+ }
31
+ else {
32
+ throw new Error("Could not visit invalid type!");
33
+ }
34
+ }
35
+ _visit(node) {
36
+ if (node instanceof Source) {
37
+ this.visitSource(node);
38
+ }
39
+ else if (node instanceof NamedTypeNode) {
40
+ this.visitNamedTypeNode(node);
41
+ }
42
+ else if (node instanceof FunctionTypeNode) {
43
+ this.visitFunctionTypeNode(node);
44
+ }
45
+ else if (node instanceof TypeName) {
46
+ this.visitTypeName(node);
47
+ }
48
+ else if (node instanceof TypeParameterNode) {
49
+ this.visitTypeParameter(node);
50
+ }
51
+ else if (node instanceof IdentifierExpression) {
52
+ this.visitIdentifierExpression(node);
53
+ }
54
+ else if (node instanceof AssertionExpression) {
55
+ this.visitAssertionExpression(node);
56
+ }
57
+ else if (node instanceof BinaryExpression) {
58
+ this.visitBinaryExpression(node);
59
+ }
60
+ else if (node instanceof CallExpression) {
61
+ this.visitCallExpression(node);
62
+ }
63
+ else if (node instanceof ClassExpression) {
64
+ this.visitClassExpression(node);
65
+ }
66
+ else if (node instanceof CommaExpression) {
67
+ this.visitCommaExpression(node);
68
+ }
69
+ else if (node instanceof ElementAccessExpression) {
70
+ this.visitElementAccessExpression(node);
71
+ }
72
+ else if (node instanceof FunctionExpression) {
73
+ this.visitFunctionExpression(node);
74
+ }
75
+ else if (node instanceof InstanceOfExpression) {
76
+ this.visitInstanceOfExpression(node);
77
+ }
78
+ else if (node instanceof LiteralExpression) {
79
+ this.visitLiteralExpression(node);
80
+ }
81
+ else if (node instanceof NewExpression) {
82
+ this.visitNewExpression(node);
83
+ }
84
+ else if (node instanceof ParenthesizedExpression) {
85
+ this.visitParenthesizedExpression(node);
86
+ }
87
+ else if (node instanceof PropertyAccessExpression) {
88
+ this.visitPropertyAccessExpression(node);
89
+ }
90
+ else if (node instanceof TernaryExpression) {
91
+ this.visitTernaryExpression(node);
92
+ }
93
+ else if (node instanceof UnaryPostfixExpression) {
94
+ this.visitUnaryPostfixExpression(node);
95
+ }
96
+ else if (node instanceof UnaryPrefixExpression) {
97
+ this.visitUnaryPrefixExpression(node);
98
+ }
99
+ else if (node instanceof BlockStatement) {
100
+ this.visitBlockStatement(node);
101
+ }
102
+ else if (node instanceof BreakStatement) {
103
+ this.visitBreakStatement(node);
104
+ }
105
+ else if (node instanceof ContinueStatement) {
106
+ this.visitContinueStatement(node);
107
+ }
108
+ else if (node instanceof DoStatement) {
109
+ this.visitDoStatement(node);
110
+ }
111
+ else if (node instanceof EmptyStatement) {
112
+ this.visitEmptyStatement(node);
113
+ }
114
+ else if (node instanceof ExportStatement) {
115
+ this.visitExportStatement(node);
116
+ }
117
+ else if (node instanceof ExportDefaultStatement) {
118
+ this.visitExportDefaultStatement(node);
119
+ }
120
+ else if (node instanceof ExportImportStatement) {
121
+ this.visitExportImportStatement(node);
122
+ }
123
+ else if (node instanceof ExpressionStatement) {
124
+ this.visitExpressionStatement(node);
125
+ }
126
+ else if (node instanceof ForStatement) {
127
+ this.visitForStatement(node);
128
+ }
129
+ else if (node instanceof IfStatement) {
130
+ this.visitIfStatement(node);
131
+ }
132
+ else if (node instanceof ImportStatement) {
133
+ this.visitImportStatement(node);
134
+ }
135
+ else if (node instanceof ReturnStatement) {
136
+ this.visitReturnStatement(node);
137
+ }
138
+ else if (node instanceof SwitchStatement) {
139
+ this.visitSwitchStatement(node);
140
+ }
141
+ else if (node instanceof ThrowStatement) {
142
+ this.visitThrowStatement(node);
143
+ }
144
+ else if (node instanceof TryStatement) {
145
+ this.visitTryStatement(node);
146
+ }
147
+ else if (node instanceof VariableStatement) {
148
+ this.visitVariableStatement(node);
149
+ }
150
+ else if (node instanceof WhileStatement) {
151
+ this.visitWhileStatement(node);
152
+ }
153
+ else if (node instanceof ClassDeclaration) {
154
+ this.visitClassDeclaration(node);
155
+ }
156
+ else if (node instanceof EnumDeclaration) {
157
+ this.visitEnumDeclaration(node);
158
+ }
159
+ else if (node instanceof EnumValueDeclaration) {
160
+ this.visitEnumValueDeclaration(node);
161
+ }
162
+ else if (node instanceof FieldDeclaration) {
163
+ this.visitFieldDeclaration(node);
164
+ }
165
+ else if (node instanceof FunctionDeclaration) {
166
+ this.visitFunctionDeclaration(node);
167
+ }
168
+ else if (node instanceof ImportDeclaration) {
169
+ this.visitImportDeclaration(node);
170
+ }
171
+ else if (node instanceof InterfaceDeclaration) {
172
+ this.visitInterfaceDeclaration(node);
173
+ }
174
+ else if (node instanceof MethodDeclaration) {
175
+ this.visitMethodDeclaration(node);
176
+ }
177
+ else if (node instanceof NamespaceDeclaration) {
178
+ this.visitNamespaceDeclaration(node);
179
+ }
180
+ else if (node instanceof TypeDeclaration) {
181
+ this.visitTypeDeclaration(node);
182
+ }
183
+ else if (node instanceof VariableDeclaration) {
184
+ this.visitVariableDeclaration(node);
185
+ }
186
+ else if (node instanceof DecoratorNode) {
187
+ this.visitDecoratorNode(node);
188
+ }
189
+ else if (node instanceof ExportMember) {
190
+ this.visitExportMember(node);
191
+ }
192
+ else if (node instanceof ParameterNode) {
193
+ this.visitParameter(node);
194
+ }
195
+ else if (node instanceof SwitchCase) {
196
+ this.visitSwitchCase(node);
197
+ }
198
+ else if (node instanceof IndexSignatureNode) {
199
+ this.visitIndexSignature(node);
200
+ }
201
+ else {
202
+ throw new Error("Could not visit invalid type!");
203
+ }
204
+ }
205
+ visitSource(node) {
206
+ this.currentSource = node;
207
+ for (const stmt of node.statements) {
208
+ this.depth++;
209
+ this._visit(stmt);
210
+ this.depth--;
211
+ }
212
+ this.currentSource = null;
213
+ }
214
+ visitTypeNode(node) { }
215
+ visitTypeName(node) {
216
+ this.visit(node.identifier);
217
+ this.visit(node.next);
218
+ }
219
+ visitNamedTypeNode(node) {
220
+ this.visit(node.name);
221
+ this.visit(node.typeArguments);
222
+ }
223
+ visitFunctionTypeNode(node) {
224
+ this.visit(node.parameters);
225
+ this.visit(node.returnType);
226
+ this.visit(node.explicitThisType);
227
+ }
228
+ visitTypeParameter(node) {
229
+ this.visit(node.name);
230
+ this.visit(node.extendsType);
231
+ this.visit(node.defaultType);
232
+ }
233
+ visitIdentifierExpression(node) { }
234
+ visitArrayLiteralExpression(node) {
235
+ this.visit(node.elementExpressions);
236
+ }
237
+ visitObjectLiteralExpression(node) {
238
+ this.visit(node.names);
239
+ this.visit(node.values);
240
+ }
241
+ visitAssertionExpression(node) {
242
+ this.visit(node.toType);
243
+ this.visit(node.expression);
244
+ }
245
+ visitBinaryExpression(node) {
246
+ this.visit(node.left);
247
+ this.visit(node.right);
248
+ }
249
+ visitCallExpression(node) {
250
+ this.visit(node.expression);
251
+ this.visitArguments(node.typeArguments, node.args);
252
+ }
253
+ visitArguments(typeArguments, args) {
254
+ this.visit(typeArguments);
255
+ this.visit(args);
256
+ }
257
+ visitClassExpression(node) {
258
+ this.visit(node.declaration);
259
+ }
260
+ visitCommaExpression(node) {
261
+ this.visit(node.expressions);
262
+ }
263
+ visitElementAccessExpression(node) {
264
+ this.visit(node.elementExpression);
265
+ this.visit(node.expression);
266
+ }
267
+ visitFunctionExpression(node) {
268
+ this.visit(node.declaration);
269
+ }
270
+ visitLiteralExpression(node) {
271
+ if (node instanceof FloatLiteralExpression) {
272
+ this.visitFloatLiteralExpression(node);
273
+ }
274
+ else if (node instanceof IntegerLiteralExpression) {
275
+ this.visitIntegerLiteralExpression(node);
276
+ }
277
+ else if (node instanceof StringLiteralExpression) {
278
+ this.visitStringLiteralExpression(node);
279
+ }
280
+ else if (node instanceof TemplateLiteralExpression) {
281
+ this.visitTemplateLiteralExpression(node);
282
+ }
283
+ else if (node instanceof RegexpLiteralExpression) {
284
+ this.visitRegexpLiteralExpression(node);
285
+ }
286
+ else if (node instanceof ArrayLiteralExpression) {
287
+ this.visitArrayLiteralExpression(node);
288
+ }
289
+ else if (node instanceof ObjectLiteralExpression) {
290
+ this.visitObjectLiteralExpression(node);
291
+ }
292
+ else {
293
+ throw new Error("Invalid LiteralKind at visitLiteralExpression(): " + node.literalKind);
294
+ }
295
+ }
296
+ visitFloatLiteralExpression(node) { }
297
+ visitInstanceOfExpression(node) {
298
+ this.visit(node.expression);
299
+ this.visit(node.isType);
300
+ }
301
+ visitIntegerLiteralExpression(node) { }
302
+ visitStringLiteral(str, singleQuoted = false) { }
303
+ visitStringLiteralExpression(node) {
304
+ this.visitStringLiteral(node.value);
305
+ }
306
+ visitTemplateLiteralExpression(node) { }
307
+ visitRegexpLiteralExpression(node) { }
308
+ visitNewExpression(node) {
309
+ this.visit(node.typeArguments);
310
+ this.visitArguments(node.typeArguments, node.args);
311
+ this.visit(node.args);
312
+ }
313
+ visitParenthesizedExpression(node) {
314
+ this.visit(node.expression);
315
+ }
316
+ visitPropertyAccessExpression(node) {
317
+ this.visit(node.property);
318
+ this.visit(node.expression);
319
+ }
320
+ visitTernaryExpression(node) {
321
+ this.visit(node.condition);
322
+ this.visit(node.ifThen);
323
+ this.visit(node.ifElse);
324
+ }
325
+ visitUnaryExpression(node) {
326
+ this.visit(node.operand);
327
+ }
328
+ visitUnaryPostfixExpression(node) {
329
+ this.visit(node.operand);
330
+ }
331
+ visitUnaryPrefixExpression(node) {
332
+ this.visit(node.operand);
333
+ }
334
+ visitSuperExpression(node) { }
335
+ visitFalseExpression(node) { }
336
+ visitTrueExpression(node) { }
337
+ visitThisExpression(node) { }
338
+ visitNullExperssion(node) { }
339
+ visitConstructorExpression(node) { }
340
+ visitNodeAndTerminate(statement) { }
341
+ visitBlockStatement(node) {
342
+ this.depth++;
343
+ this.visit(node.statements);
344
+ this.depth--;
345
+ }
346
+ visitBreakStatement(node) {
347
+ this.visit(node.label);
348
+ }
349
+ visitContinueStatement(node) {
350
+ this.visit(node.label);
351
+ }
352
+ visitClassDeclaration(node, isDefault = false) {
353
+ this.visit(node.name);
354
+ this.depth++;
355
+ this.visit(node.decorators);
356
+ if (node.isGeneric ? node.typeParameters != null : node.typeParameters == null) {
357
+ this.visit(node.typeParameters);
358
+ this.visit(node.extendsType);
359
+ this.visit(node.implementsTypes);
360
+ this.visit(node.members);
361
+ this.depth--;
362
+ }
363
+ else {
364
+ throw new Error("Expected to type parameters to match class declaration, but found type mismatch instead!");
365
+ }
366
+ }
367
+ visitDoStatement(node) {
368
+ this.visit(node.condition);
369
+ this.visit(node.body);
370
+ }
371
+ visitEmptyStatement(node) { }
372
+ visitEnumDeclaration(node, isDefault = false) {
373
+ this.visit(node.name);
374
+ this.visit(node.decorators);
375
+ this.visit(node.values);
376
+ }
377
+ visitEnumValueDeclaration(node) {
378
+ this.visit(node.name);
379
+ this.visit(node.initializer);
380
+ }
381
+ visitExportImportStatement(node) {
382
+ this.visit(node.name);
383
+ this.visit(node.externalName);
384
+ }
385
+ visitExportMember(node) {
386
+ this.visit(node.localName);
387
+ this.visit(node.exportedName);
388
+ }
389
+ visitExportStatement(node) {
390
+ this.visit(node.path);
391
+ this.visit(node.members);
392
+ }
393
+ visitExportDefaultStatement(node) {
394
+ this.visit(node.declaration);
395
+ }
396
+ visitExpressionStatement(node) {
397
+ this.visit(node.expression);
398
+ }
399
+ visitFieldDeclaration(node) {
400
+ this.visit(node.name);
401
+ this.visit(node.type);
402
+ this.visit(node.initializer);
403
+ this.visit(node.decorators);
404
+ }
405
+ visitForStatement(node) {
406
+ this.visit(node.initializer);
407
+ this.visit(node.condition);
408
+ this.visit(node.incrementor);
409
+ this.visit(node.body);
410
+ }
411
+ visitFunctionDeclaration(node, isDefault = false) {
412
+ this.visit(node.name);
413
+ this.visit(node.decorators);
414
+ this.visit(node.typeParameters);
415
+ this.visit(node.signature);
416
+ this.depth++;
417
+ this.visit(node.body);
418
+ this.depth--;
419
+ }
420
+ visitIfStatement(node) {
421
+ this.visit(node.condition);
422
+ this.visit(node.ifTrue);
423
+ this.visit(node.ifFalse);
424
+ }
425
+ visitImportDeclaration(node) {
426
+ this.visit(node.foreignName);
427
+ this.visit(node.name);
428
+ this.visit(node.decorators);
429
+ }
430
+ visitImportStatement(node) {
431
+ this.visit(node.namespaceName);
432
+ this.visit(node.declarations);
433
+ }
434
+ visitIndexSignature(node) {
435
+ this.visit(node.keyType);
436
+ this.visit(node.valueType);
437
+ }
438
+ visitInterfaceDeclaration(node, isDefault = false) {
439
+ this.visit(node.name);
440
+ this.visit(node.typeParameters);
441
+ this.visit(node.implementsTypes);
442
+ this.visit(node.extendsType);
443
+ this.depth++;
444
+ this.visit(node.members);
445
+ this.depth--;
446
+ }
447
+ visitMethodDeclaration(node) {
448
+ this.visit(node.name);
449
+ this.visit(node.typeParameters);
450
+ this.visit(node.signature);
451
+ this.visit(node.decorators);
452
+ this.depth++;
453
+ this.visit(node.body);
454
+ this.depth--;
455
+ }
456
+ visitNamespaceDeclaration(node, isDefault = false) {
457
+ this.visit(node.name);
458
+ this.visit(node.decorators);
459
+ this.visit(node.members);
460
+ }
461
+ visitReturnStatement(node) {
462
+ this.visit(node.value);
463
+ }
464
+ visitSwitchCase(node) {
465
+ this.visit(node.label);
466
+ this.visit(node.statements);
467
+ }
468
+ visitSwitchStatement(node) {
469
+ this.visit(node.condition);
470
+ this.depth++;
471
+ this.visit(node.cases);
472
+ this.depth--;
473
+ }
474
+ visitThrowStatement(node) {
475
+ this.visit(node.value);
476
+ }
477
+ visitTryStatement(node) {
478
+ this.visit(node.bodyStatements);
479
+ this.visit(node.catchVariable);
480
+ this.visit(node.catchStatements);
481
+ this.visit(node.finallyStatements);
482
+ }
483
+ visitTypeDeclaration(node) {
484
+ this.visit(node.name);
485
+ this.visit(node.decorators);
486
+ this.visit(node.type);
487
+ this.visit(node.typeParameters);
488
+ }
489
+ visitVariableDeclaration(node) {
490
+ this.visit(node.name);
491
+ this.visit(node.type);
492
+ this.visit(node.initializer);
493
+ }
494
+ visitVariableStatement(node) {
495
+ this.visit(node.decorators);
496
+ this.visit(node.declarations);
497
+ }
498
+ visitWhileStatement(node) {
499
+ this.visit(node.condition);
500
+ this.depth++;
501
+ this.visit(node.body);
502
+ this.depth--;
503
+ }
504
+ visitVoidStatement(node) { }
505
+ visitComment(node) { }
506
+ visitDecoratorNode(node) {
507
+ this.visit(node.name);
508
+ this.visit(node.args);
509
+ }
510
+ visitParameter(node) {
511
+ this.visit(node.name);
512
+ this.visit(node.implicitFieldDeclaration);
513
+ this.visit(node.initializer);
514
+ this.visit(node.type);
515
+ }
516
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@json-as/transform",
3
- "version": "0.9.8",
3
+ "version": "0.9.9",
4
4
  "description": "JSON encoder/decoder for AssemblyScript",
5
5
  "main": "./lib/index.js",
6
6
  "author": "Jairus Tanaka",
@@ -164,6 +164,14 @@ class JSONTransform extends BaseVisitor {
164
164
  mem.initialize = "this." + name.text + " = changetype<nonnull<" + mem.type + ">>(__new(offsetof<nonnull<" + mem.type + ">>(), idof<nonnull<" + mem.type + ">>()));\n changetype<nonnull<" + mem.type + ">>(this." + name.text + ").__INITIALIZE()";
165
165
  } else if (mem.value) {
166
166
  mem.initialize = "this." + name.text + " = " + mem.value;
167
+ } else if (t === "Map") {
168
+ mem.initialize = "this." + name.text + " = new " + mem.type + "()"
169
+ } else if (t === "string") {
170
+ mem.initialize = "this." + name.text + " = \"\"";
171
+ } else if (t === "Array") {
172
+ mem.initialize = "this." + name.text + " = instantiate<" + mem.type + ">()";
173
+ } else {
174
+ console.log(t)
167
175
  }
168
176
 
169
177
  schema.members.push(mem);