motoko 3.1.3 → 3.2.0
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/lib/ast.d.ts +4 -3
- package/lib/ast.d.ts.map +1 -1
- package/lib/ast.js +12 -7
- package/lib/ast.js.map +1 -1
- package/package.json +1 -1
- package/packages/latest/base.json +1 -1
- package/src/ast.ts +22 -11
- package/versions/latest/moc.min.js +1 -1
- package/versions/latest/moc_interpreter.min.js +1 -1
package/src/ast.ts
CHANGED
@@ -16,6 +16,7 @@ export interface Source {
|
|
16
16
|
}
|
17
17
|
|
18
18
|
export interface Node extends Partial<Source> {
|
19
|
+
parent?: Node | undefined;
|
19
20
|
name: string;
|
20
21
|
type?: string;
|
21
22
|
doc?: string;
|
@@ -23,13 +24,18 @@ export interface Node extends Partial<Source> {
|
|
23
24
|
args?: AST[];
|
24
25
|
}
|
25
26
|
|
26
|
-
export function simplifyAST(ast: CompilerNode): Node;
|
27
|
-
export function simplifyAST(
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
export function simplifyAST(ast: CompilerNode, parent?: Node | undefined): Node;
|
28
|
+
export function simplifyAST(
|
29
|
+
ast: CompilerAST[],
|
30
|
+
parent?: Node | undefined,
|
31
|
+
): AST[];
|
32
|
+
export function simplifyAST<T extends CompilerAST>(
|
33
|
+
ast: T,
|
34
|
+
parent?: Node | undefined,
|
35
|
+
): T;
|
36
|
+
export function simplifyAST(ast: CompilerAST, parent?: Node | undefined): AST {
|
31
37
|
if (Array.isArray(ast)) {
|
32
|
-
return ast.map((a) => simplifyAST(a));
|
38
|
+
return ast.map((a) => simplifyAST(a, parent));
|
33
39
|
}
|
34
40
|
if (typeof ast !== 'object') {
|
35
41
|
return ast;
|
@@ -43,7 +49,7 @@ export function simplifyAST(ast: CompilerAST): AST {
|
|
43
49
|
const node: Node = {
|
44
50
|
...(typeof subAst === 'string'
|
45
51
|
? { name: subAst }
|
46
|
-
: simplifyAST(subAst as any as CompilerNode)),
|
52
|
+
: simplifyAST(subAst as any as CompilerNode, parent)),
|
47
53
|
start: [+start.args[1], +start.args[2]],
|
48
54
|
end: [+end.args[1], +end.args[2]],
|
49
55
|
};
|
@@ -58,7 +64,7 @@ export function simplifyAST(ast: CompilerAST): AST {
|
|
58
64
|
return {
|
59
65
|
...(typeof typeAst === 'string'
|
60
66
|
? { name: typeAst }
|
61
|
-
: simplifyAST(typeAst)),
|
67
|
+
: simplifyAST(typeAst, parent)),
|
62
68
|
type,
|
63
69
|
};
|
64
70
|
}
|
@@ -67,12 +73,17 @@ export function simplifyAST(ast: CompilerAST): AST {
|
|
67
73
|
return {
|
68
74
|
...(typeof docAst === 'string'
|
69
75
|
? { name: docAst }
|
70
|
-
: simplifyAST(docAst)),
|
76
|
+
: simplifyAST(docAst, parent)),
|
71
77
|
doc,
|
72
78
|
};
|
73
79
|
}
|
74
|
-
|
80
|
+
const node: Node = {
|
75
81
|
name: ast.name,
|
76
|
-
args: simplifyAST(ast.args),
|
77
82
|
};
|
83
|
+
Object.defineProperty(node, 'parent', {
|
84
|
+
value: parent,
|
85
|
+
enumerable: false,
|
86
|
+
});
|
87
|
+
node.args = simplifyAST(ast.args, node);
|
88
|
+
return node;
|
78
89
|
}
|