as-test 0.4.0 → 0.4.2
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 +10 -1
- package/README.md +12 -12
- package/as-test.config.json +1 -1
- package/assembly/__tests__/array.spec.ts +3 -3
- package/assembly/src/expectation.ts +29 -16
- package/assembly/src/suite.ts +2 -0
- package/assembly/src/tests.ts +1 -0
- package/bin/build.js +65 -77
- package/bin/index.js +130 -160
- package/bin/init.js +96 -109
- package/bin/reporter.js +1 -1
- package/bin/run.js +210 -236
- package/bin/types.js +25 -25
- package/bin/util.js +35 -42
- package/cli/run.ts +13 -15
- package/cli/tsconfig.json +2 -1
- package/package.json +12 -9
- package/transform/lib/builder.js +1361 -0
- package/transform/lib/builder.js.map +1 -0
- package/transform/lib/coverage.js +6 -6
- package/transform/lib/coverage.js.map +1 -1
- package/transform/lib/index.js +1 -1
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/linker.js +19 -0
- package/transform/lib/linker.js.map +1 -0
- package/transform/lib/mock.js +9 -9
- package/transform/lib/mock.js.map +1 -1
- package/transform/lib/range.js +13 -0
- package/transform/lib/range.js.map +1 -0
- package/transform/lib/types.js +26 -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 +532 -0
- package/transform/lib/visitor.js.map +1 -0
- package/transform/src/builder.ts +1474 -0
- package/transform/src/coverage.ts +6 -7
- package/transform/src/index.ts +1 -2
- package/transform/src/linker.ts +41 -0
- package/transform/src/mock.ts +9 -10
- package/transform/src/range.ts +12 -0
- package/transform/src/types.ts +35 -0
- package/transform/src/util.ts +81 -0
- package/transform/src/visitor.ts +744 -0
- package/.trunk/configs/.markdownlint.yaml +0 -2
- package/.trunk/configs/.yamllint.yaml +0 -7
- package/.trunk/trunk.yaml +0 -34
- package/bin/about.js +0 -135
- package/bin/package.json +0 -3
|
@@ -18,10 +18,9 @@ import {
|
|
|
18
18
|
ArrowKind,
|
|
19
19
|
Node,
|
|
20
20
|
} from "assemblyscript/dist/assemblyscript.js";
|
|
21
|
-
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import { isStdlib } from "visitor-as/dist/utils.js";
|
|
21
|
+
import { RangeTransform } from "./range.js";
|
|
22
|
+
import { isStdlib, SimpleParser } from "./util.js";
|
|
23
|
+
import { Visitor } from "./visitor.js";
|
|
25
24
|
|
|
26
25
|
enum CoverType {
|
|
27
26
|
Function,
|
|
@@ -38,7 +37,7 @@ class CoverPoint {
|
|
|
38
37
|
public executed: boolean = false;
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
export class CoverageTransform extends
|
|
40
|
+
export class CoverageTransform extends Visitor {
|
|
42
41
|
public mustImport: boolean = false;
|
|
43
42
|
public points: Map<string, CoverPoint> = new Map<string, CoverPoint>();
|
|
44
43
|
public globalStatements: Statement[] = [];
|
|
@@ -359,14 +358,14 @@ export class CoverageTransform extends BaseVisitor {
|
|
|
359
358
|
if (ifTrue.visited) return;
|
|
360
359
|
// @ts-ignore
|
|
361
360
|
ifTrue.visited = true;
|
|
362
|
-
this.
|
|
361
|
+
this.visit(ifTrue);
|
|
363
362
|
}
|
|
364
363
|
if (visitIfFalse) {
|
|
365
364
|
// @ts-ignore
|
|
366
365
|
if (ifFalse.visited) return;
|
|
367
366
|
// @ts-ignore
|
|
368
367
|
ifFalse.visited = true;
|
|
369
|
-
this.
|
|
368
|
+
this.visit(ifFalse!);
|
|
370
369
|
}
|
|
371
370
|
} else {
|
|
372
371
|
super.visitIfStatement(node);
|
package/transform/src/index.ts
CHANGED
|
@@ -7,10 +7,9 @@ import {
|
|
|
7
7
|
Source,
|
|
8
8
|
Tokenizer,
|
|
9
9
|
} from "assemblyscript/dist/assemblyscript.js";
|
|
10
|
-
|
|
11
|
-
import { isStdlib } from "visitor-as/dist/utils.js";
|
|
12
10
|
import { CoverageTransform } from "./coverage.js";
|
|
13
11
|
import { MockTransform } from "./mock.js";
|
|
12
|
+
import { isStdlib } from "./util.js";
|
|
14
13
|
|
|
15
14
|
export default class Transformer extends Transform {
|
|
16
15
|
// Trigger the transform after parse.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClassDeclaration,
|
|
3
|
+
ImportStatement,
|
|
4
|
+
NodeKind,
|
|
5
|
+
Parser,
|
|
6
|
+
Source,
|
|
7
|
+
} from "assemblyscript/dist/assemblyscript.js";
|
|
8
|
+
|
|
9
|
+
export function getImports(source: Source): ImportStatement[] {
|
|
10
|
+
return source.statements.filter(
|
|
11
|
+
(v) => v.kind === NodeKind.Import,
|
|
12
|
+
) as ImportStatement[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getImportedClass(
|
|
16
|
+
name: string,
|
|
17
|
+
source: Source,
|
|
18
|
+
parser: Parser,
|
|
19
|
+
): ClassDeclaration | null {
|
|
20
|
+
for (const stmt of getImports(source)) {
|
|
21
|
+
const externalSource = parser.sources.find(
|
|
22
|
+
(src) => src.internalPath === stmt.internalPath,
|
|
23
|
+
);
|
|
24
|
+
if (!externalSource) continue;
|
|
25
|
+
|
|
26
|
+
const classDeclaration = externalSource.statements.find(
|
|
27
|
+
(s) =>
|
|
28
|
+
s.kind === NodeKind.ClassDeclaration &&
|
|
29
|
+
(<ClassDeclaration>s).name.text === name,
|
|
30
|
+
) as ClassDeclaration | null;
|
|
31
|
+
|
|
32
|
+
if (classDeclaration) return classDeclaration;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getClasses(source: Source): ClassDeclaration[] {
|
|
38
|
+
return source.statements.filter(
|
|
39
|
+
(v) => v.kind === NodeKind.ClassDeclaration,
|
|
40
|
+
) as ClassDeclaration[];
|
|
41
|
+
}
|
package/transform/src/mock.ts
CHANGED
|
@@ -11,11 +11,10 @@ import {
|
|
|
11
11
|
Expression,
|
|
12
12
|
FunctionDeclaration,
|
|
13
13
|
} from "assemblyscript/dist/assemblyscript.js";
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
public currentSource: Source;
|
|
14
|
+
import { Visitor } from "./visitor.js";
|
|
15
|
+
import { toString } from "./util.js";
|
|
16
|
+
export class MockTransform extends Visitor {
|
|
17
|
+
public srcCurrent: Source | null = null;
|
|
19
18
|
public globalStatements: Statement[] = [];
|
|
20
19
|
public mocked = new Set<string>();
|
|
21
20
|
public importFns: FunctionDeclaration[] = [];
|
|
@@ -58,7 +57,7 @@ export class MockTransform extends BaseVisitor {
|
|
|
58
57
|
cb.range,
|
|
59
58
|
);
|
|
60
59
|
|
|
61
|
-
const stmts = this.
|
|
60
|
+
const stmts = this.srcCurrent.statements;
|
|
62
61
|
let index = -1;
|
|
63
62
|
for (let i = 0; i < stmts.length; i++) {
|
|
64
63
|
const stmt = stmts[i];
|
|
@@ -79,7 +78,7 @@ export class MockTransform extends BaseVisitor {
|
|
|
79
78
|
}
|
|
80
79
|
visitSource(node: Source): void {
|
|
81
80
|
this.mocked = new Set<string>();
|
|
82
|
-
this.
|
|
81
|
+
this.srcCurrent = node;
|
|
83
82
|
this.importFns = [];
|
|
84
83
|
super.visitSource(node);
|
|
85
84
|
|
|
@@ -96,10 +95,10 @@ export class MockTransform extends BaseVisitor {
|
|
|
96
95
|
.join(".");
|
|
97
96
|
else if (dec.args[0])
|
|
98
97
|
path =
|
|
99
|
-
this.
|
|
98
|
+
this.srcCurrent.simplePath +
|
|
100
99
|
"." +
|
|
101
100
|
(dec.args[0] as StringLiteralExpression).value;
|
|
102
|
-
else path = this.
|
|
101
|
+
else path = this.srcCurrent.simplePath + "." + node.name.text;
|
|
103
102
|
if (!this.importMocked.has(path)) return;
|
|
104
103
|
|
|
105
104
|
let args: Expression[] = [
|
|
@@ -145,7 +144,7 @@ export class MockTransform extends BaseVisitor {
|
|
|
145
144
|
node.range,
|
|
146
145
|
);
|
|
147
146
|
|
|
148
|
-
const stmts = this.
|
|
147
|
+
const stmts = this.srcCurrent.statements;
|
|
149
148
|
let index = -1;
|
|
150
149
|
for (let i = 0; i < stmts.length; i++) {
|
|
151
150
|
const stmt = stmts[i];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Node } from "assemblyscript/dist/assemblyscript.js";
|
|
2
|
+
import { Visitor } from "./visitor.js";
|
|
3
|
+
|
|
4
|
+
export class RangeTransform extends Visitor {
|
|
5
|
+
constructor(private node: Node) {
|
|
6
|
+
super();
|
|
7
|
+
}
|
|
8
|
+
_visit(node: Node, ref: Node | null): void {
|
|
9
|
+
node.range = this.node.range;
|
|
10
|
+
return super._visit(node, ref);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClassDeclaration,
|
|
3
|
+
Expression,
|
|
4
|
+
FieldDeclaration,
|
|
5
|
+
} from "assemblyscript/dist/assemblyscript.js";
|
|
6
|
+
|
|
7
|
+
export enum PropertyFlags {
|
|
8
|
+
OmitNull,
|
|
9
|
+
OmitIf,
|
|
10
|
+
Raw,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class Property {
|
|
14
|
+
public name: string = "";
|
|
15
|
+
public alias: string | null = null;
|
|
16
|
+
public type: string = "";
|
|
17
|
+
public value: string | null = null;
|
|
18
|
+
public flags: Map<PropertyFlags, Expression | null> = new Map<
|
|
19
|
+
PropertyFlags,
|
|
20
|
+
Expression | null
|
|
21
|
+
>();
|
|
22
|
+
public node!: FieldDeclaration;
|
|
23
|
+
public byteSize: number = 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class Schema {
|
|
27
|
+
public static: boolean = true;
|
|
28
|
+
public name: string = "";
|
|
29
|
+
public members: Property[] = [];
|
|
30
|
+
public parent: Schema | null = null;
|
|
31
|
+
public node!: ClassDeclaration;
|
|
32
|
+
public needsLink: string | null = null;
|
|
33
|
+
public byteSize: number = 0;
|
|
34
|
+
public deps: Schema[] = [];
|
|
35
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Taken from https://github.com/as-pect/visitor-as/blob/master/src/simpleParser.ts
|
|
2
|
+
import {
|
|
3
|
+
Parser,
|
|
4
|
+
Tokenizer,
|
|
5
|
+
Source,
|
|
6
|
+
SourceKind,
|
|
7
|
+
Expression,
|
|
8
|
+
Statement,
|
|
9
|
+
NamespaceDeclaration,
|
|
10
|
+
ClassDeclaration,
|
|
11
|
+
DeclarationStatement,
|
|
12
|
+
Range,
|
|
13
|
+
Node,
|
|
14
|
+
} from "assemblyscript/dist/assemblyscript.js";
|
|
15
|
+
import { ASTBuilder } from "./builder.js";
|
|
16
|
+
|
|
17
|
+
export class SimpleParser {
|
|
18
|
+
private static get parser(): Parser {
|
|
19
|
+
return new Parser();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private static getTokenizer(s: string, file: string = "index.ts"): Tokenizer {
|
|
23
|
+
return new Tokenizer(new Source(SourceKind.User, file, s));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static parseExpression(s: string): Expression {
|
|
27
|
+
const res = this.parser.parseExpression(this.getTokenizer(s));
|
|
28
|
+
if (res == null) {
|
|
29
|
+
throw new Error("Failed to parse the expression: '" + s + "'");
|
|
30
|
+
}
|
|
31
|
+
return res;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static parseStatement(s: string, topLevel = false): Statement {
|
|
35
|
+
const res = this.parser.parseStatement(this.getTokenizer(s), topLevel);
|
|
36
|
+
if (res == null) {
|
|
37
|
+
throw new Error("Failed to parse the statement: '" + s + "'");
|
|
38
|
+
}
|
|
39
|
+
return res;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static parseTopLevelStatement(
|
|
43
|
+
s: string,
|
|
44
|
+
namespace?: NamespaceDeclaration | null,
|
|
45
|
+
): Statement {
|
|
46
|
+
const res = this.parser.parseTopLevelStatement(
|
|
47
|
+
this.getTokenizer(s),
|
|
48
|
+
namespace,
|
|
49
|
+
);
|
|
50
|
+
if (res == null) {
|
|
51
|
+
throw new Error("Failed to parse the top level statement: '" + s + "'");
|
|
52
|
+
}
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static parseClassMember(
|
|
57
|
+
s: string,
|
|
58
|
+
_class: ClassDeclaration,
|
|
59
|
+
): DeclarationStatement {
|
|
60
|
+
let res = this.parser.parseClassMember(
|
|
61
|
+
this.getTokenizer(s, _class.range.source.normalizedPath),
|
|
62
|
+
_class,
|
|
63
|
+
);
|
|
64
|
+
if (res == null) {
|
|
65
|
+
throw new Error("Failed to parse the class member: '" + s + "'");
|
|
66
|
+
}
|
|
67
|
+
return <DeclarationStatement>res;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let isStdlibRegex =
|
|
72
|
+
/\~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/;
|
|
73
|
+
|
|
74
|
+
export function isStdlib(s: Source | { range: Range }): boolean {
|
|
75
|
+
let source = s instanceof Source ? s : s.range.source;
|
|
76
|
+
return isStdlibRegex.test(source.internalPath);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function toString(node: Node): string {
|
|
80
|
+
return ASTBuilder.build(node);
|
|
81
|
+
}
|