json-as 1.1.20 → 1.1.22
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/CHANGELOG.md +9 -0
- package/README.md +42 -50
- package/assembly/__tests__/arbitrary.spec.ts +16 -0
- package/assembly/__tests__/enum.spec.ts +35 -0
- package/assembly/deserialize/simd/string.ts +18 -19
- package/assembly/deserialize/simple/object.ts +15 -8
- package/assembly/index.ts +15 -9
- package/assembly/serialize/simd/string.ts +2 -3
- package/assembly/serialize/simple/arbitrary.ts +1 -0
- package/assembly/serialize/simple/array.ts +1 -1
- package/assembly/serialize/simple/bool.ts +1 -1
- package/assembly/serialize/simple/float.ts +3 -1
- package/assembly/serialize/simple/integer.ts +1 -1
- package/assembly/serialize/simple/map.ts +2 -2
- package/assembly/serialize/simple/object.ts +28 -26
- package/assembly/test.tmp.ts +91 -402
- package/assembly/test.ts +20 -37
- package/lib/as-bs.ts +13 -12
- package/package.json +7 -7
- package/run-bench.as.sh +3 -3
- package/run-bench.js.sh +1 -1
- package/run-tests.sh +1 -1
- package/transform/lib/index.js +52 -18
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/types.js +22 -1
- package/transform/lib/types.js.map +1 -1
- package/transform/src/index.ts +61 -19
- package/transform/src/types.ts +36 -2
package/transform/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClassDeclaration, Expression, FieldDeclaration, Source, NodeKind, Node, NamespaceDeclaration, DeclarationStatement, TypeName, Parser, ImportStatement, CommonFlags } from "assemblyscript/dist/assemblyscript.js";
|
|
1
|
+
import { ClassDeclaration, Expression, FieldDeclaration, Source, NodeKind, Node, NamespaceDeclaration, DeclarationStatement, TypeName, Parser, ImportStatement, CommonFlags, EnumDeclaration } from "assemblyscript/dist/assemblyscript.js";
|
|
2
2
|
import { TypeAlias } from "./linkers/alias.js";
|
|
3
3
|
import { stripNull } from "./index.js";
|
|
4
4
|
|
|
@@ -100,9 +100,10 @@ export class Src {
|
|
|
100
100
|
public schemas: Schema[];
|
|
101
101
|
public aliases: TypeAlias[];
|
|
102
102
|
public exports: Schema[];
|
|
103
|
+
public imports: ImportStatement[] = [];
|
|
103
104
|
private nodeMap: Map<Node, NamespaceDeclaration[]> = new Map<Node, NamespaceDeclaration[]>();
|
|
104
105
|
private classes: Record<string, ClassDeclaration> = {};
|
|
105
|
-
private
|
|
106
|
+
private enums: Record<string, EnumDeclaration> = {};
|
|
106
107
|
|
|
107
108
|
constructor(
|
|
108
109
|
source: Source,
|
|
@@ -130,6 +131,10 @@ export class Src {
|
|
|
130
131
|
const classDeclaration = node as ClassDeclaration;
|
|
131
132
|
this.classes[this.qualifiedName(classDeclaration, path)] = classDeclaration;
|
|
132
133
|
break;
|
|
134
|
+
case NodeKind.EnumDeclaration:
|
|
135
|
+
const enumDeclaration = node as EnumDeclaration;
|
|
136
|
+
this.enums[this.qualifiedName(enumDeclaration, path)] = enumDeclaration;
|
|
137
|
+
break;
|
|
133
138
|
case NodeKind.Import:
|
|
134
139
|
const importStatement = node as ImportStatement;
|
|
135
140
|
this.imports.push(importStatement);
|
|
@@ -157,6 +162,15 @@ export class Src {
|
|
|
157
162
|
return this.classes[qualifiedName] || null;
|
|
158
163
|
}
|
|
159
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Get an enum declaration by its qualified name.
|
|
167
|
+
* @param qualifiedName Qualified name (eg. "Namespace.MyEnum")
|
|
168
|
+
* @returns Enum declaration or null if not found.
|
|
169
|
+
*/
|
|
170
|
+
getEnum(qualifiedName: string): EnumDeclaration | null {
|
|
171
|
+
return this.enums[qualifiedName] || null;
|
|
172
|
+
}
|
|
173
|
+
|
|
160
174
|
/**
|
|
161
175
|
* Get imported class from other sources in the parser.
|
|
162
176
|
* @param qualifiedName Qualified name of class.
|
|
@@ -177,6 +191,26 @@ export class Src {
|
|
|
177
191
|
return null;
|
|
178
192
|
}
|
|
179
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Get imported enum from other sources in the parser.
|
|
196
|
+
* @param qualifiedName Qualified name of enum.
|
|
197
|
+
* @param parser AssemblyScript parser.
|
|
198
|
+
* @returns Enum declaration or null if not found.
|
|
199
|
+
*/
|
|
200
|
+
getImportedEnum(qualifiedName: string, parser: Parser): EnumDeclaration | null {
|
|
201
|
+
for (const stmt of this.imports) {
|
|
202
|
+
const externalSource = parser.sources.filter((src) => src.internalPath != this.internalPath).find((src) => src.internalPath == stmt.internalPath);
|
|
203
|
+
if (!externalSource) continue;
|
|
204
|
+
|
|
205
|
+
const source = this.sourceSet.get(externalSource);
|
|
206
|
+
const enumDeclaration = source.getEnum(qualifiedName);
|
|
207
|
+
if (enumDeclaration && enumDeclaration.flags & CommonFlags.Export) {
|
|
208
|
+
return enumDeclaration;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
|
|
180
214
|
/**
|
|
181
215
|
* Gets a unique path string to the node by combining the internalPath with
|
|
182
216
|
* the qualified name of the node.
|