json-as 0.9.29 → 1.0.0-alpha.1
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/.github/workflows/nodejs.yml +0 -3
- package/.prettierrc.json +3 -2
- package/CHANGELOG +13 -0
- package/LICENSE +1 -1
- package/README.md +22 -7
- package/as-test.config.json +1 -1
- package/asconfig.json +2 -2
- package/assembly/__benches__/misc.bench.ts +17 -32
- package/assembly/__tests__/bool.spec.ts +1 -1
- package/assembly/__tests__/simd/string.spec.ts +32 -0
- package/assembly/custom/memory.ts +25 -0
- package/assembly/custom/util.ts +14 -92
- package/assembly/deserialize/simd/string.ts +103 -0
- package/assembly/deserialize/simple/arbitrary.ts +17 -0
- package/assembly/deserialize/simple/array/arbitrary.ts +113 -0
- package/assembly/deserialize/simple/array/array.ts +18 -0
- package/assembly/deserialize/simple/array/bool.ts +17 -0
- package/assembly/deserialize/simple/array/float.ts +28 -0
- package/assembly/deserialize/simple/array/integer.ts +27 -0
- package/assembly/deserialize/simple/array/map.ts +18 -0
- package/assembly/deserialize/simple/array/object.ts +18 -0
- package/assembly/deserialize/simple/array/string.ts +22 -0
- package/assembly/deserialize/simple/array.ts +48 -0
- package/assembly/deserialize/simple/bool.ts +9 -0
- package/assembly/deserialize/simple/date.ts +11 -0
- package/assembly/deserialize/simple/float.ts +10 -0
- package/assembly/deserialize/simple/integer.ts +5 -0
- package/assembly/deserialize/simple/map.ts +154 -0
- package/assembly/deserialize/simple/object.ts +159 -0
- package/assembly/deserialize/simple/string.ts +48 -0
- package/assembly/globals/tables.ts +417 -0
- package/assembly/index.d.ts +9 -13
- package/assembly/index.ts +266 -146
- package/assembly/serialize/simd/string.ts +176 -0
- package/assembly/serialize/simple/arbitrary.ts +36 -0
- package/assembly/serialize/simple/array.ts +32 -0
- package/assembly/serialize/simple/bool.ts +19 -0
- package/assembly/serialize/simple/date.ts +13 -0
- package/assembly/serialize/simple/float.ts +7 -0
- package/assembly/serialize/simple/integer.ts +7 -0
- package/assembly/serialize/simple/map.ts +43 -0
- package/assembly/serialize/simple/object.ts +7 -0
- package/assembly/serialize/simple/string.ts +48 -0
- package/assembly/test.ts +41 -27
- package/assembly/tsconfig.json +2 -91
- package/assembly/types.ts +0 -0
- package/assembly/util/atoi.ts +35 -0
- package/assembly/util/bytes.ts +12 -0
- package/assembly/util/concat.ts +9 -0
- package/assembly/util/getArrayDepth.ts +17 -0
- package/assembly/util/index.ts +5 -0
- package/assembly/util/isSpace.ts +4 -0
- package/assembly/util/nextPowerOf2.ts +4 -0
- package/assembly/util/ptrToStr.ts +7 -0
- package/assembly/util/snp.ts +69 -0
- package/bench.js +5 -5
- package/modules/bs/index.ts +167 -0
- package/modules/tsconfig.json +8 -0
- package/package.json +42 -48
- package/transform/lib/builder.js +1353 -0
- package/transform/lib/builder.js.map +1 -0
- package/transform/lib/index.js +497 -332
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/index.old.js +404 -0
- package/transform/lib/index.old.js.map +1 -0
- package/transform/lib/linker.js +18 -0
- package/transform/lib/linker.js.map +1 -0
- package/transform/lib/types.js +25 -0
- package/transform/lib/types.js.map +1 -0
- package/transform/lib/util.js +47 -0
- package/transform/lib/util.js.map +1 -0
- package/transform/lib/visitor.js +529 -446
- package/transform/lib/visitor.js.map +1 -0
- package/transform/package.json +1 -34
- package/transform/src/builder.ts +1371 -0
- package/transform/src/index.ts +564 -341
- package/transform/src/linker.ts +21 -0
- package/transform/src/types.ts +27 -0
- package/transform/src/util.ts +56 -0
- package/transform/src/visitor.ts +531 -0
- package/transform/tsconfig.json +3 -1
- package/assembly/__benches__/as-tral.d.ts +0 -1
- package/assembly/__tests__/date.spec.ts +0 -12
- package/assembly/custom/bs.ts +0 -202
- package/assembly/deserialize/array/array.ts +0 -31
- package/assembly/deserialize/array/bool.ts +0 -19
- package/assembly/deserialize/array/float.ts +0 -24
- package/assembly/deserialize/array/integer.ts +0 -24
- package/assembly/deserialize/array/map.ts +0 -27
- package/assembly/deserialize/array/object.ts +0 -27
- package/assembly/deserialize/array/string.ts +0 -29
- package/assembly/deserialize/array.ts +0 -46
- package/assembly/deserialize/bool.ts +0 -34
- package/assembly/deserialize/date.ts +0 -19
- package/assembly/deserialize/float.ts +0 -21
- package/assembly/deserialize/integer.ts +0 -16
- package/assembly/deserialize/map.ts +0 -139
- package/assembly/deserialize/object.ts +0 -211
- package/assembly/deserialize/string.ts +0 -149
- package/assembly/serialize/array.ts +0 -44
- package/assembly/serialize/bool.ts +0 -10
- package/assembly/serialize/date.ts +0 -4
- package/assembly/serialize/float.ts +0 -4
- package/assembly/serialize/integer.ts +0 -5
- package/assembly/serialize/map.ts +0 -24
- package/assembly/serialize/object.ts +0 -13
- package/assembly/serialize/string.ts +0 -284
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ClassDeclaration, ImportStatement, NodeKind, Parser, Source } from "assemblyscript/dist/assemblyscript.js";
|
|
2
|
+
|
|
3
|
+
export function getImports(source: Source): ImportStatement[] {
|
|
4
|
+
return source.statements.filter((v) => v.kind === NodeKind.Import) as ImportStatement[];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getImportedClass(name: string, source: Source, parser: Parser): ClassDeclaration | null {
|
|
8
|
+
for (const stmt of getImports(source)) {
|
|
9
|
+
const externalSource = parser.sources.find((src) => src.internalPath === stmt.internalPath);
|
|
10
|
+
if (!externalSource) continue;
|
|
11
|
+
|
|
12
|
+
const classDeclaration = externalSource.statements.find((s) => s.kind === NodeKind.ClassDeclaration && (<ClassDeclaration>s).name.text === name) as ClassDeclaration | null;
|
|
13
|
+
|
|
14
|
+
if (classDeclaration) return classDeclaration;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getClasses(source: Source): ClassDeclaration[] {
|
|
20
|
+
return source.statements.filter((v) => v.kind === NodeKind.ClassDeclaration) as ClassDeclaration[];
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ClassDeclaration, Expression, FieldDeclaration } from "assemblyscript/dist/assemblyscript.js";
|
|
2
|
+
|
|
3
|
+
export enum PropertyFlags {
|
|
4
|
+
OmitNull,
|
|
5
|
+
OmitIf,
|
|
6
|
+
Raw,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class Property {
|
|
10
|
+
public name: string = "";
|
|
11
|
+
public alias: string | null = null;
|
|
12
|
+
public type: string = "";
|
|
13
|
+
public value: string | null = null;
|
|
14
|
+
public flags: Map<PropertyFlags, Expression | null> = new Map<PropertyFlags, Expression | null>();
|
|
15
|
+
public node!: FieldDeclaration;
|
|
16
|
+
public byteSize: number = 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class Schema {
|
|
20
|
+
public static: boolean = true;
|
|
21
|
+
public name: string = "";
|
|
22
|
+
public members: Property[] = [];
|
|
23
|
+
public parent: Schema | null = null;
|
|
24
|
+
public node!: ClassDeclaration;
|
|
25
|
+
public needsLink: string | null = null;
|
|
26
|
+
public byteSize: number = 0;
|
|
27
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Taken from https://github.com/as-pect/visitor-as/blob/master/src/simpleParser.ts
|
|
2
|
+
import { Parser, Tokenizer, Source, SourceKind, Expression, Statement, NamespaceDeclaration, ClassDeclaration, DeclarationStatement, Range, Node } from "assemblyscript/dist/assemblyscript.js";
|
|
3
|
+
import { ASTBuilder } from "./builder.js";
|
|
4
|
+
|
|
5
|
+
export class SimpleParser {
|
|
6
|
+
private static get parser(): Parser {
|
|
7
|
+
return new Parser();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
private static getTokenizer(s: string, file: string = "index.ts"): Tokenizer {
|
|
11
|
+
return new Tokenizer(new Source(SourceKind.User, file, s));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static parseExpression(s: string): Expression {
|
|
15
|
+
const res = this.parser.parseExpression(this.getTokenizer(s));
|
|
16
|
+
if (res == null) {
|
|
17
|
+
throw new Error("Failed to parse the expression: '" + s + "'");
|
|
18
|
+
}
|
|
19
|
+
return res;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static parseStatement(s: string, topLevel = false): Statement {
|
|
23
|
+
const res = this.parser.parseStatement(this.getTokenizer(s), topLevel);
|
|
24
|
+
if (res == null) {
|
|
25
|
+
throw new Error("Failed to parse the statement: '" + s + "'");
|
|
26
|
+
}
|
|
27
|
+
return res;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static parseTopLevelStatement(s: string, namespace?: NamespaceDeclaration | null): Statement {
|
|
31
|
+
const res = this.parser.parseTopLevelStatement(this.getTokenizer(s), namespace);
|
|
32
|
+
if (res == null) {
|
|
33
|
+
throw new Error("Failed to parse the top level statement: '" + s + "'");
|
|
34
|
+
}
|
|
35
|
+
return res;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static parseClassMember(s: string, _class: ClassDeclaration): DeclarationStatement {
|
|
39
|
+
let res = this.parser.parseClassMember(this.getTokenizer(s, _class.range.source.normalizedPath), _class);
|
|
40
|
+
if (res == null) {
|
|
41
|
+
throw new Error("Failed to parse the class member: '" + s + "'");
|
|
42
|
+
}
|
|
43
|
+
return <DeclarationStatement>res;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let isStdlibRegex = /\~lib\/(?:array|arraybuffer|atomics|builtins|crypto|console|compat|dataview|date|diagnostics|error|function|iterator|map|math|number|object|process|reference|regexp|set|staticarray|string|symbol|table|typedarray|vector|rt\/?|bindings\/|shared\/typeinfo)|util\/|uri|polyfills|memory/;
|
|
48
|
+
|
|
49
|
+
export function isStdlib(s: Source | { range: Range }): boolean {
|
|
50
|
+
let source = s instanceof Source ? s : s.range.source;
|
|
51
|
+
return isStdlibRegex.test(source.internalPath);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function toString(node: Node): string {
|
|
55
|
+
return ASTBuilder.build(node);
|
|
56
|
+
}
|
|
@@ -0,0 +1,531 @@
|
|
|
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, NodeKind, TypeNode, Expression, LiteralKind, UnaryExpression, SuperExpression, FalseExpression, TrueExpression, ThisExpression, NullExpression, ConstructorExpression, Statement, VoidStatement, CompiledExpression, CommentNode, Module, OmittedExpression, ForOfStatement, ModuleDeclaration } from "assemblyscript/dist/assemblyscript.js";
|
|
2
|
+
import { toString } from "./util.js";
|
|
3
|
+
|
|
4
|
+
export class Visitor {
|
|
5
|
+
public currentSource: Source | null = null;
|
|
6
|
+
visit(node: Node | Node[], ref: Node | null = null): void {
|
|
7
|
+
if (node == null) return;
|
|
8
|
+
if (node instanceof Array) {
|
|
9
|
+
for (const n of node) {
|
|
10
|
+
this._visit(n, ref);
|
|
11
|
+
}
|
|
12
|
+
} else {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
this._visit(node, ref);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
_visit(node: Node, ref: Node | null): void {
|
|
18
|
+
switch (node.kind) {
|
|
19
|
+
case NodeKind.Source:
|
|
20
|
+
this.visitSource(node as Source, ref);
|
|
21
|
+
break;
|
|
22
|
+
case NodeKind.NamedType:
|
|
23
|
+
this.visitNamedTypeNode(node as NamedTypeNode, ref);
|
|
24
|
+
break;
|
|
25
|
+
case NodeKind.FunctionType:
|
|
26
|
+
this.visitFunctionTypeNode(node as FunctionTypeNode, ref);
|
|
27
|
+
break;
|
|
28
|
+
case NodeKind.TypeName:
|
|
29
|
+
this.visitTypeName(node as TypeName, ref);
|
|
30
|
+
break;
|
|
31
|
+
case NodeKind.TypeParameter:
|
|
32
|
+
this.visitTypeParameter(node as TypeParameterNode, ref);
|
|
33
|
+
break;
|
|
34
|
+
case NodeKind.Identifier:
|
|
35
|
+
this.visitIdentifierExpression(node as IdentifierExpression, ref);
|
|
36
|
+
break;
|
|
37
|
+
case NodeKind.Assertion:
|
|
38
|
+
this.visitAssertionExpression(node as AssertionExpression, ref);
|
|
39
|
+
break;
|
|
40
|
+
case NodeKind.Binary:
|
|
41
|
+
this.visitBinaryExpression(node as BinaryExpression, ref);
|
|
42
|
+
break;
|
|
43
|
+
case NodeKind.Call:
|
|
44
|
+
this.visitCallExpression(node as CallExpression, ref);
|
|
45
|
+
break;
|
|
46
|
+
case NodeKind.Class:
|
|
47
|
+
this.visitClassExpression(node as ClassExpression, ref);
|
|
48
|
+
break;
|
|
49
|
+
case NodeKind.Comma:
|
|
50
|
+
this.visitCommaExpression(node as CommaExpression, ref);
|
|
51
|
+
break;
|
|
52
|
+
case NodeKind.ElementAccess:
|
|
53
|
+
this.visitElementAccessExpression(node as ElementAccessExpression, ref);
|
|
54
|
+
break;
|
|
55
|
+
case NodeKind.Function:
|
|
56
|
+
this.visitFunctionExpression(node as FunctionExpression, ref);
|
|
57
|
+
break;
|
|
58
|
+
case NodeKind.InstanceOf:
|
|
59
|
+
this.visitInstanceOfExpression(node as InstanceOfExpression, ref);
|
|
60
|
+
break;
|
|
61
|
+
case NodeKind.Literal:
|
|
62
|
+
this.visitLiteralExpression(node as LiteralExpression, ref);
|
|
63
|
+
break;
|
|
64
|
+
case NodeKind.New:
|
|
65
|
+
this.visitNewExpression(node as NewExpression, ref);
|
|
66
|
+
break;
|
|
67
|
+
case NodeKind.Parenthesized:
|
|
68
|
+
this.visitParenthesizedExpression(node as ParenthesizedExpression, ref);
|
|
69
|
+
break;
|
|
70
|
+
case NodeKind.PropertyAccess:
|
|
71
|
+
this.visitPropertyAccessExpression(node as PropertyAccessExpression, ref);
|
|
72
|
+
break;
|
|
73
|
+
case NodeKind.Ternary:
|
|
74
|
+
this.visitTernaryExpression(node as TernaryExpression, ref);
|
|
75
|
+
break;
|
|
76
|
+
case NodeKind.UnaryPostfix:
|
|
77
|
+
this.visitUnaryPostfixExpression(node as UnaryPostfixExpression, ref);
|
|
78
|
+
break;
|
|
79
|
+
case NodeKind.UnaryPrefix:
|
|
80
|
+
this.visitUnaryPrefixExpression(node as UnaryPrefixExpression, ref);
|
|
81
|
+
break;
|
|
82
|
+
case NodeKind.Block:
|
|
83
|
+
this.visitBlockStatement(node as BlockStatement, ref);
|
|
84
|
+
break;
|
|
85
|
+
case NodeKind.Break:
|
|
86
|
+
this.visitBreakStatement(node as BreakStatement, ref);
|
|
87
|
+
break;
|
|
88
|
+
case NodeKind.Continue:
|
|
89
|
+
this.visitContinueStatement(node as ContinueStatement, ref);
|
|
90
|
+
break;
|
|
91
|
+
case NodeKind.Do:
|
|
92
|
+
this.visitDoStatement(node as DoStatement, ref);
|
|
93
|
+
break;
|
|
94
|
+
case NodeKind.Empty:
|
|
95
|
+
this.visitEmptyStatement(node as EmptyStatement, ref);
|
|
96
|
+
break;
|
|
97
|
+
case NodeKind.Export:
|
|
98
|
+
this.visitExportStatement(node as ExportStatement, ref);
|
|
99
|
+
break;
|
|
100
|
+
case NodeKind.ExportDefault:
|
|
101
|
+
this.visitExportDefaultStatement(node as ExportDefaultStatement, ref);
|
|
102
|
+
break;
|
|
103
|
+
case NodeKind.ExportImport:
|
|
104
|
+
this.visitExportImportStatement(node as ExportImportStatement, ref);
|
|
105
|
+
break;
|
|
106
|
+
case NodeKind.Expression:
|
|
107
|
+
this.visitExpressionStatement(node as ExpressionStatement, ref);
|
|
108
|
+
break;
|
|
109
|
+
case NodeKind.For:
|
|
110
|
+
this.visitForStatement(node as ForStatement, ref);
|
|
111
|
+
break;
|
|
112
|
+
case NodeKind.If:
|
|
113
|
+
this.visitIfStatement(node as IfStatement, ref);
|
|
114
|
+
break;
|
|
115
|
+
case NodeKind.Import:
|
|
116
|
+
this.visitImportStatement(node as ImportStatement, ref);
|
|
117
|
+
break;
|
|
118
|
+
case NodeKind.Return:
|
|
119
|
+
this.visitReturnStatement(node as ReturnStatement, ref);
|
|
120
|
+
break;
|
|
121
|
+
case NodeKind.Switch:
|
|
122
|
+
this.visitSwitchStatement(node as SwitchStatement, ref);
|
|
123
|
+
break;
|
|
124
|
+
case NodeKind.Throw:
|
|
125
|
+
this.visitThrowStatement(node as ThrowStatement, ref);
|
|
126
|
+
break;
|
|
127
|
+
case NodeKind.Try:
|
|
128
|
+
this.visitTryStatement(node as TryStatement, ref);
|
|
129
|
+
break;
|
|
130
|
+
case NodeKind.Variable:
|
|
131
|
+
this.visitVariableStatement(node as VariableStatement, ref);
|
|
132
|
+
break;
|
|
133
|
+
case NodeKind.While:
|
|
134
|
+
this.visitWhileStatement(node as WhileStatement, ref);
|
|
135
|
+
break;
|
|
136
|
+
case NodeKind.ClassDeclaration:
|
|
137
|
+
this.visitClassDeclaration(node as ClassDeclaration, false, ref);
|
|
138
|
+
break;
|
|
139
|
+
case NodeKind.EnumDeclaration:
|
|
140
|
+
this.visitEnumDeclaration(node as EnumDeclaration, false, ref);
|
|
141
|
+
break;
|
|
142
|
+
case NodeKind.EnumValueDeclaration:
|
|
143
|
+
this.visitEnumValueDeclaration(node as EnumValueDeclaration, ref);
|
|
144
|
+
break;
|
|
145
|
+
case NodeKind.FieldDeclaration:
|
|
146
|
+
this.visitFieldDeclaration(node as FieldDeclaration, ref);
|
|
147
|
+
break;
|
|
148
|
+
case NodeKind.FunctionDeclaration:
|
|
149
|
+
this.visitFunctionDeclaration(node as FunctionDeclaration, false, ref);
|
|
150
|
+
break;
|
|
151
|
+
case NodeKind.ImportDeclaration:
|
|
152
|
+
this.visitImportDeclaration(node as ImportDeclaration, ref);
|
|
153
|
+
break;
|
|
154
|
+
case NodeKind.InterfaceDeclaration:
|
|
155
|
+
this.visitInterfaceDeclaration(node as InterfaceDeclaration, false, ref);
|
|
156
|
+
break;
|
|
157
|
+
case NodeKind.MethodDeclaration:
|
|
158
|
+
this.visitMethodDeclaration(node as MethodDeclaration, ref);
|
|
159
|
+
break;
|
|
160
|
+
case NodeKind.NamespaceDeclaration:
|
|
161
|
+
this.visitNamespaceDeclaration(node as NamespaceDeclaration, false, ref);
|
|
162
|
+
break;
|
|
163
|
+
case NodeKind.TypeDeclaration:
|
|
164
|
+
this.visitTypeDeclaration(node as TypeDeclaration, ref);
|
|
165
|
+
break;
|
|
166
|
+
case NodeKind.VariableDeclaration:
|
|
167
|
+
this.visitVariableDeclaration(node as VariableDeclaration, ref);
|
|
168
|
+
break;
|
|
169
|
+
case NodeKind.Decorator:
|
|
170
|
+
this.visitDecoratorNode(node as DecoratorNode, ref);
|
|
171
|
+
break;
|
|
172
|
+
case NodeKind.ExportMember:
|
|
173
|
+
this.visitExportMember(node as ExportMember, ref);
|
|
174
|
+
break;
|
|
175
|
+
case NodeKind.SwitchCase:
|
|
176
|
+
this.visitSwitchCase(node as SwitchCase, ref);
|
|
177
|
+
break;
|
|
178
|
+
case NodeKind.IndexSignature:
|
|
179
|
+
this.visitIndexSignature(node as IndexSignatureNode, ref);
|
|
180
|
+
break;
|
|
181
|
+
case NodeKind.Null:
|
|
182
|
+
this.visitNullExpression(node as NullExpression, ref);
|
|
183
|
+
break;
|
|
184
|
+
case NodeKind.True: {
|
|
185
|
+
this.visitTrueExpression(node as TrueExpression, ref);
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
case NodeKind.False: {
|
|
189
|
+
this.visitFalseExpression(node as FalseExpression, ref);
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case NodeKind.Compiled: {
|
|
193
|
+
this.visitCompiledExpression(node as CompiledExpression, ref);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case NodeKind.Constructor: {
|
|
197
|
+
this.visitConstructorExpression(node as ConstructorExpression, ref);
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
case NodeKind.Comment: {
|
|
201
|
+
this.visitComment(node as CommentNode, ref);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case NodeKind.ForOf: {
|
|
205
|
+
this.visitForOfStatement(node as ForOfStatement, ref);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
case NodeKind.Module: {
|
|
209
|
+
this.visitModuleDeclaration(node as ModuleDeclaration, ref);
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
case NodeKind.Omitted: {
|
|
213
|
+
this.visitOmittedExpression(node as OmittedExpression, ref);
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
case NodeKind.Parameter: {
|
|
217
|
+
this.visitParameter(node as ParameterNode, ref);
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
case NodeKind.Super: {
|
|
221
|
+
this.visitSuperExpression(node as SuperExpression, ref);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case NodeKind.This: {
|
|
225
|
+
this.visitThisExpression(node as ThisExpression, ref);
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
case NodeKind.Void: {
|
|
229
|
+
this.visitVoidStatement(node as VoidStatement, ref);
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
default:
|
|
233
|
+
throw new Error("Could not visit invalid type!");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
visitSource(node: Source, ref: Node | null = null): void {
|
|
237
|
+
this.currentSource = node;
|
|
238
|
+
this.visit(node.statements, node);
|
|
239
|
+
this.currentSource = null;
|
|
240
|
+
}
|
|
241
|
+
visitTypeNode(node: TypeNode, ref: Node | null = null): void {}
|
|
242
|
+
visitTypeName(node: TypeName, ref: Node | null = null): void {
|
|
243
|
+
this.visit(node.identifier, node);
|
|
244
|
+
this.visit(node.next, node);
|
|
245
|
+
}
|
|
246
|
+
visitNamedTypeNode(node: NamedTypeNode, ref: Node | null = null): void {
|
|
247
|
+
this.visit(node.name, node);
|
|
248
|
+
this.visit(node.typeArguments, node);
|
|
249
|
+
}
|
|
250
|
+
visitFunctionTypeNode(node: FunctionTypeNode, ref: Node | null = null): void {
|
|
251
|
+
this.visit(node.parameters, node);
|
|
252
|
+
this.visit(node.returnType, node);
|
|
253
|
+
this.visit(node.explicitThisType, node);
|
|
254
|
+
}
|
|
255
|
+
visitTypeParameter(node: TypeParameterNode, ref: Node | null = null): void {
|
|
256
|
+
this.visit(node.name, node);
|
|
257
|
+
this.visit(node.extendsType, node);
|
|
258
|
+
this.visit(node.defaultType, node);
|
|
259
|
+
}
|
|
260
|
+
visitIdentifierExpression(node: IdentifierExpression, ref: Node | null = null): void {}
|
|
261
|
+
visitArrayLiteralExpression(node: ArrayLiteralExpression, ref: Node | null = null): void {
|
|
262
|
+
this.visit(node.elementExpressions, node);
|
|
263
|
+
}
|
|
264
|
+
visitObjectLiteralExpression(node: ObjectLiteralExpression, ref: Node | null = null): void {
|
|
265
|
+
this.visit(node.names, node);
|
|
266
|
+
this.visit(node.values, node);
|
|
267
|
+
}
|
|
268
|
+
visitAssertionExpression(node: AssertionExpression, ref: Node | null = null): void {
|
|
269
|
+
this.visit(node.toType, node);
|
|
270
|
+
this.visit(node.expression, node);
|
|
271
|
+
}
|
|
272
|
+
visitBinaryExpression(node: BinaryExpression, ref: Node | null = null): void {
|
|
273
|
+
this.visit(node.left, node);
|
|
274
|
+
this.visit(node.right, node);
|
|
275
|
+
}
|
|
276
|
+
visitCallExpression(node: CallExpression, ref: Node | null = null): void {
|
|
277
|
+
this.visit(node.expression, node);
|
|
278
|
+
this.visit(node.typeArguments, node);
|
|
279
|
+
this.visit(node.args, node);
|
|
280
|
+
}
|
|
281
|
+
visitClassExpression(node: ClassExpression, ref: Node | null = null): void {
|
|
282
|
+
this.visit(node.declaration, node);
|
|
283
|
+
}
|
|
284
|
+
visitCommaExpression(node: CommaExpression, ref: Node | null = null): void {
|
|
285
|
+
this.visit(node.expressions, node);
|
|
286
|
+
}
|
|
287
|
+
visitElementAccessExpression(node: ElementAccessExpression, ref: Node | null = null): void {
|
|
288
|
+
this.visit(node.elementExpression, node);
|
|
289
|
+
this.visit(node.expression, node);
|
|
290
|
+
}
|
|
291
|
+
visitFunctionExpression(node: FunctionExpression, ref: Node | null = null): void {
|
|
292
|
+
this.visit(node.declaration, node);
|
|
293
|
+
}
|
|
294
|
+
visitLiteralExpression(node: LiteralExpression, ref: Node | null = null): void {
|
|
295
|
+
switch (node.literalKind) {
|
|
296
|
+
case LiteralKind.Float:
|
|
297
|
+
this.visitFloatLiteralExpression(node as FloatLiteralExpression);
|
|
298
|
+
break;
|
|
299
|
+
case LiteralKind.Integer:
|
|
300
|
+
this.visitIntegerLiteralExpression(node as IntegerLiteralExpression);
|
|
301
|
+
break;
|
|
302
|
+
case LiteralKind.String:
|
|
303
|
+
this.visitStringLiteralExpression(node as StringLiteralExpression);
|
|
304
|
+
break;
|
|
305
|
+
case LiteralKind.Template:
|
|
306
|
+
this.visitTemplateLiteralExpression(node as TemplateLiteralExpression);
|
|
307
|
+
break;
|
|
308
|
+
case LiteralKind.RegExp:
|
|
309
|
+
this.visitRegexpLiteralExpression(node as RegexpLiteralExpression);
|
|
310
|
+
break;
|
|
311
|
+
case LiteralKind.Array:
|
|
312
|
+
this.visitArrayLiteralExpression(node as ArrayLiteralExpression);
|
|
313
|
+
break;
|
|
314
|
+
case LiteralKind.Object:
|
|
315
|
+
this.visitObjectLiteralExpression(node as ObjectLiteralExpression);
|
|
316
|
+
break;
|
|
317
|
+
default:
|
|
318
|
+
throw new Error("Invalid LiteralKind at visitLiteralExpression(): " + node.literalKind);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
visitFloatLiteralExpression(node: FloatLiteralExpression, ref: Node | null = null): void {}
|
|
322
|
+
visitInstanceOfExpression(node: InstanceOfExpression, ref: Node | null = null): void {
|
|
323
|
+
this.visit(node.expression, node);
|
|
324
|
+
this.visit(node.isType, node);
|
|
325
|
+
}
|
|
326
|
+
visitIntegerLiteralExpression(node: IntegerLiteralExpression, ref: Node | null = null): void {}
|
|
327
|
+
visitStringLiteralExpression(node: StringLiteralExpression, ref: Node | null = null): void {}
|
|
328
|
+
visitTemplateLiteralExpression(node: TemplateLiteralExpression, ref: Node | null = null): void {}
|
|
329
|
+
visitRegexpLiteralExpression(node: RegexpLiteralExpression, ref: Node | null = null): void {}
|
|
330
|
+
visitNewExpression(node: NewExpression, ref: Node | null = null): void {
|
|
331
|
+
this.visit(node.typeName, node);
|
|
332
|
+
this.visit(node.typeArguments, node);
|
|
333
|
+
this.visit(node.args, node);
|
|
334
|
+
}
|
|
335
|
+
visitParenthesizedExpression(node: ParenthesizedExpression, ref: Node | null = null): void {
|
|
336
|
+
this.visit(node.expression, node);
|
|
337
|
+
}
|
|
338
|
+
visitPropertyAccessExpression(node: PropertyAccessExpression, ref: Node | null = null): void {
|
|
339
|
+
this.visit(node.property, node);
|
|
340
|
+
this.visit(node.expression, node);
|
|
341
|
+
}
|
|
342
|
+
visitTernaryExpression(node: TernaryExpression, ref: Node | null = null): void {
|
|
343
|
+
this.visit(node.condition, node);
|
|
344
|
+
this.visit(node.ifThen, node);
|
|
345
|
+
this.visit(node.ifElse, node);
|
|
346
|
+
}
|
|
347
|
+
visitUnaryExpression(node: UnaryExpression, ref: Node | null = null): void {
|
|
348
|
+
this.visit(node.operand, node);
|
|
349
|
+
}
|
|
350
|
+
visitUnaryPostfixExpression(node: UnaryPostfixExpression, ref: Node | null = null): void {
|
|
351
|
+
this.visit(node.operand, node);
|
|
352
|
+
}
|
|
353
|
+
visitUnaryPrefixExpression(node: UnaryPrefixExpression, ref: Node | null = null): void {
|
|
354
|
+
this.visit(node.operand, node);
|
|
355
|
+
}
|
|
356
|
+
visitSuperExpression(node: SuperExpression, ref: Node | null = null): void {}
|
|
357
|
+
visitFalseExpression(node: FalseExpression, ref: Node | null = null): void {}
|
|
358
|
+
visitTrueExpression(node: TrueExpression, ref: Node | null = null): void {}
|
|
359
|
+
visitThisExpression(node: ThisExpression, ref: Node | null = null): void {}
|
|
360
|
+
visitNullExpression(node: NullExpression, ref: Node | null = null): void {}
|
|
361
|
+
visitConstructorExpression(node: ConstructorExpression, ref: Node | null = null): void {}
|
|
362
|
+
visitNodeAndTerminate(statement: Statement, ref: Node | null = null): void {}
|
|
363
|
+
visitBlockStatement(node: BlockStatement, ref: Node | null = null): void {
|
|
364
|
+
this.visit(node.statements, node);
|
|
365
|
+
}
|
|
366
|
+
visitBreakStatement(node: BreakStatement, ref: Node | null = null): void {
|
|
367
|
+
this.visit(node.label, node);
|
|
368
|
+
}
|
|
369
|
+
visitContinueStatement(node: ContinueStatement, ref: Node | null = null): void {
|
|
370
|
+
this.visit(node.label, node);
|
|
371
|
+
}
|
|
372
|
+
visitClassDeclaration(node: ClassDeclaration, isDefault: boolean = false, ref: Node | null = null): void {
|
|
373
|
+
this.visit(node.name, node);
|
|
374
|
+
this.visit(node.decorators, node);
|
|
375
|
+
if (node.isGeneric ? node.typeParameters != null : node.typeParameters == null) {
|
|
376
|
+
this.visit(node.typeParameters, node);
|
|
377
|
+
this.visit(node.extendsType, node);
|
|
378
|
+
this.visit(node.implementsTypes, node);
|
|
379
|
+
this.visit(node.members, node);
|
|
380
|
+
} else {
|
|
381
|
+
throw new Error("Expected to type parameters to match class declaration, but found type mismatch instead!");
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
visitDoStatement(node: DoStatement, ref: Node | null = null): void {
|
|
385
|
+
this.visit(node.condition, node);
|
|
386
|
+
this.visit(node.body, node);
|
|
387
|
+
}
|
|
388
|
+
visitEmptyStatement(node: EmptyStatement, ref: Node | null = null): void {}
|
|
389
|
+
visitEnumDeclaration(node: EnumDeclaration, isDefault: boolean = false, ref: Node | null = null): void {
|
|
390
|
+
this.visit(node.name, node);
|
|
391
|
+
this.visit(node.decorators, node);
|
|
392
|
+
this.visit(node.values, node);
|
|
393
|
+
}
|
|
394
|
+
visitEnumValueDeclaration(node: EnumValueDeclaration, ref: Node | null = null): void {
|
|
395
|
+
this.visit(node.name, node);
|
|
396
|
+
this.visit(node.initializer, node);
|
|
397
|
+
}
|
|
398
|
+
visitExportImportStatement(node: ExportImportStatement, ref: Node | null = null): void {
|
|
399
|
+
this.visit(node.name, node);
|
|
400
|
+
this.visit(node.externalName, node);
|
|
401
|
+
}
|
|
402
|
+
visitExportMember(node: ExportMember, ref: Node | null = null): void {
|
|
403
|
+
this.visit(node.localName, node);
|
|
404
|
+
this.visit(node.exportedName, node);
|
|
405
|
+
}
|
|
406
|
+
visitExportStatement(node: ExportStatement, ref: Node | null = null): void {
|
|
407
|
+
this.visit(node.path, node);
|
|
408
|
+
this.visit(node.members, node);
|
|
409
|
+
}
|
|
410
|
+
visitExportDefaultStatement(node: ExportDefaultStatement, ref: Node | null = null): void {
|
|
411
|
+
this.visit(node.declaration, node);
|
|
412
|
+
}
|
|
413
|
+
visitExpressionStatement(node: ExpressionStatement, ref: Node | null = null): void {
|
|
414
|
+
this.visit(node.expression, ref);
|
|
415
|
+
}
|
|
416
|
+
visitFieldDeclaration(node: FieldDeclaration, ref: Node | null = null): void {
|
|
417
|
+
this.visit(node.name, node);
|
|
418
|
+
this.visit(node.type, node);
|
|
419
|
+
this.visit(node.initializer, node);
|
|
420
|
+
this.visit(node.decorators, node);
|
|
421
|
+
}
|
|
422
|
+
visitForStatement(node: ForStatement, ref: Node | null = null): void {
|
|
423
|
+
this.visit(node.initializer, node);
|
|
424
|
+
this.visit(node.condition, node);
|
|
425
|
+
this.visit(node.incrementor, node);
|
|
426
|
+
this.visit(node.body, node);
|
|
427
|
+
}
|
|
428
|
+
visitFunctionDeclaration(node: FunctionDeclaration, isDefault: boolean = false, ref: Node | null = null): void {
|
|
429
|
+
this.visit(node.name, node);
|
|
430
|
+
this.visit(node.decorators, node);
|
|
431
|
+
this.visit(node.typeParameters, node);
|
|
432
|
+
this.visit(node.signature, node);
|
|
433
|
+
this.visit(node.body, node);
|
|
434
|
+
}
|
|
435
|
+
visitIfStatement(node: IfStatement, ref: Node | null = null): void {
|
|
436
|
+
this.visit(node.condition, node);
|
|
437
|
+
this.visit(node.ifTrue, node);
|
|
438
|
+
this.visit(node.ifFalse, node);
|
|
439
|
+
}
|
|
440
|
+
visitImportDeclaration(node: ImportDeclaration, ref: Node | null = null): void {
|
|
441
|
+
this.visit(node.foreignName, node);
|
|
442
|
+
this.visit(node.name, node);
|
|
443
|
+
this.visit(node.decorators, node);
|
|
444
|
+
}
|
|
445
|
+
visitImportStatement(node: ImportStatement, ref: Node | null = null): void {
|
|
446
|
+
this.visit(node.namespaceName, node);
|
|
447
|
+
this.visit(node.declarations, node);
|
|
448
|
+
}
|
|
449
|
+
visitIndexSignature(node: IndexSignatureNode, ref: Node | null = null): void {
|
|
450
|
+
this.visit(node.keyType, node);
|
|
451
|
+
this.visit(node.valueType, node);
|
|
452
|
+
}
|
|
453
|
+
visitInterfaceDeclaration(node: InterfaceDeclaration, isDefault: boolean = false, ref: Node | null = null): void {
|
|
454
|
+
this.visit(node.name, node);
|
|
455
|
+
this.visit(node.typeParameters, node);
|
|
456
|
+
this.visit(node.implementsTypes, node);
|
|
457
|
+
this.visit(node.extendsType, node);
|
|
458
|
+
this.visit(node.members, node);
|
|
459
|
+
}
|
|
460
|
+
visitMethodDeclaration(node: MethodDeclaration, ref: Node | null = null): void {
|
|
461
|
+
this.visit(node.name, node);
|
|
462
|
+
this.visit(node.typeParameters, node);
|
|
463
|
+
this.visit(node.signature, node);
|
|
464
|
+
this.visit(node.decorators, node);
|
|
465
|
+
this.visit(node.body, node);
|
|
466
|
+
}
|
|
467
|
+
visitNamespaceDeclaration(node: NamespaceDeclaration, isDefault: boolean = false, ref: Node | null = null): void {
|
|
468
|
+
this.visit(node.name, node);
|
|
469
|
+
this.visit(node.decorators, node);
|
|
470
|
+
this.visit(node.members, node);
|
|
471
|
+
}
|
|
472
|
+
visitReturnStatement(node: ReturnStatement, ref: Node | null = null): void {
|
|
473
|
+
this.visit(node.value, node);
|
|
474
|
+
}
|
|
475
|
+
visitSwitchCase(node: SwitchCase, ref: Node | null = null): void {
|
|
476
|
+
this.visit(node.label, node);
|
|
477
|
+
this.visit(node.statements, node);
|
|
478
|
+
}
|
|
479
|
+
visitSwitchStatement(node: SwitchStatement, ref: Node | null = null): void {
|
|
480
|
+
this.visit(node.condition, node);
|
|
481
|
+
this.visit(node.cases, node);
|
|
482
|
+
}
|
|
483
|
+
visitThrowStatement(node: ThrowStatement, ref: Node | null = null): void {
|
|
484
|
+
this.visit(node.value, node);
|
|
485
|
+
}
|
|
486
|
+
visitTryStatement(node: TryStatement, ref: Node | null = null): void {
|
|
487
|
+
this.visit(node.bodyStatements, node);
|
|
488
|
+
this.visit(node.catchVariable, node);
|
|
489
|
+
this.visit(node.catchStatements, node);
|
|
490
|
+
this.visit(node.finallyStatements, node);
|
|
491
|
+
}
|
|
492
|
+
visitTypeDeclaration(node: TypeDeclaration, ref: Node | null = null): void {
|
|
493
|
+
this.visit(node.name, node);
|
|
494
|
+
this.visit(node.decorators, node);
|
|
495
|
+
this.visit(node.type, node);
|
|
496
|
+
this.visit(node.typeParameters, node);
|
|
497
|
+
}
|
|
498
|
+
visitVariableDeclaration(node: VariableDeclaration, ref: Node | null = null): void {
|
|
499
|
+
this.visit(node.name, node);
|
|
500
|
+
this.visit(node.type, node);
|
|
501
|
+
this.visit(node.initializer, node);
|
|
502
|
+
}
|
|
503
|
+
visitVariableStatement(node: VariableStatement, ref: Node | null = null): void {
|
|
504
|
+
this.visit(node.decorators, node);
|
|
505
|
+
this.visit(node.declarations, node);
|
|
506
|
+
}
|
|
507
|
+
visitWhileStatement(node: WhileStatement, ref: Node | null = null): void {
|
|
508
|
+
this.visit(node.condition, node);
|
|
509
|
+
this.visit(node.body, node);
|
|
510
|
+
}
|
|
511
|
+
visitVoidStatement(node: VoidStatement, ref: Node | null = null): void {}
|
|
512
|
+
visitComment(node: CommentNode, ref: Node | null = null): void {}
|
|
513
|
+
visitDecoratorNode(node: DecoratorNode, ref: Node | null = null): void {
|
|
514
|
+
this.visit(node.name, node);
|
|
515
|
+
this.visit(node.args, node);
|
|
516
|
+
}
|
|
517
|
+
visitParameter(node: ParameterNode, ref: Node | null = null): void {
|
|
518
|
+
this.visit(node.name, node);
|
|
519
|
+
this.visit(node.implicitFieldDeclaration, node);
|
|
520
|
+
this.visit(node.initializer, node);
|
|
521
|
+
this.visit(node.type, node);
|
|
522
|
+
}
|
|
523
|
+
visitCompiledExpression(node: CompiledExpression, ref: Node | null = null): void {}
|
|
524
|
+
visitForOfStatement(node: ForOfStatement, ref: Node | null = null): void {
|
|
525
|
+
this.visit(node.body, node);
|
|
526
|
+
this.visit(node.variable, node);
|
|
527
|
+
this.visit(node.iterable, node);
|
|
528
|
+
}
|
|
529
|
+
visitModuleDeclaration(node: ModuleDeclaration, ref: Node | null = null): void {}
|
|
530
|
+
visitOmittedExpression(node: OmittedExpression, ref: Node | null = null): void {}
|
|
531
|
+
}
|
package/transform/tsconfig.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="@as-tral/cli/as-tral" />
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { JSON } from "json-as";
|
|
2
|
-
import { describe, expect, run } from "as-test/assembly";
|
|
3
|
-
|
|
4
|
-
describe("Should serialize dates", () => {
|
|
5
|
-
expect(JSON.stringify(new Date(1767184496789))).toBe('"2025-12-31T12:34:56.789Z"');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
describe("Should deserialize dates", () => {
|
|
9
|
-
expect(JSON.parse<Date>('"2025-12-31T12:34:56.789Z"').getTime()).toBe(1767184496789);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
run();
|