motoko 3.2.1 → 3.3.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/lib/ast.d.ts +1 -0
- package/lib/ast.d.ts.map +1 -1
- package/lib/ast.js +18 -8
- package/lib/ast.js.map +1 -1
- package/lib/file.d.ts +1 -1
- package/lib/file.js +1 -1
- package/lib/file.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/versions/interpreter.d.ts +1 -1
- package/lib/versions/moc.d.ts +1 -1
- package/package.json +1 -1
- package/packages/latest/base.json +1 -1
- package/src/ast.ts +24 -18
- package/src/file.ts +1 -1
- package/versions/latest/moc.min.js +1 -1
- package/versions/latest/moc_interpreter.min.js +1 -1
package/src/ast.ts
CHANGED
@@ -24,6 +24,12 @@ export interface Node extends Partial<Source> {
|
|
24
24
|
args?: AST[];
|
25
25
|
}
|
26
26
|
|
27
|
+
export function asNode(ast: AST | undefined): Node | undefined {
|
28
|
+
if (ast && typeof ast === 'object' && !Array.isArray(ast)) {
|
29
|
+
return ast;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
27
33
|
export function simplifyAST(ast: CompilerNode, parent?: Node | undefined): Node;
|
28
34
|
export function simplifyAST(
|
29
35
|
ast: CompilerAST[],
|
@@ -44,12 +50,12 @@ export function simplifyAST(ast: CompilerAST, parent?: Node | undefined): AST {
|
|
44
50
|
const [start, end, subAst] = ast.args as [
|
45
51
|
CompilerSpan,
|
46
52
|
CompilerSpan,
|
47
|
-
|
53
|
+
CompilerNode,
|
48
54
|
];
|
49
|
-
const node
|
55
|
+
const node =
|
50
56
|
typeof subAst === 'string'
|
51
|
-
? { name: subAst }
|
52
|
-
: simplifyAST(subAst
|
57
|
+
? { name: subAst, parent }
|
58
|
+
: simplifyAST(subAst, parent);
|
53
59
|
node.start = [+start.args[1], +start.args[2]];
|
54
60
|
node.end = [+end.args[1], +end.args[2]];
|
55
61
|
const file = start.args[0];
|
@@ -59,22 +65,22 @@ export function simplifyAST(ast: CompilerAST, parent?: Node | undefined): AST {
|
|
59
65
|
return node;
|
60
66
|
}
|
61
67
|
if (ast.name === ':') {
|
62
|
-
const [typeAst, type] = ast.args as [
|
63
|
-
|
64
|
-
|
65
|
-
? { name: typeAst }
|
66
|
-
: simplifyAST(typeAst, parent)
|
67
|
-
|
68
|
-
|
68
|
+
const [typeAst, type] = ast.args as [CompilerNode, string];
|
69
|
+
const node =
|
70
|
+
typeof typeAst === 'string'
|
71
|
+
? { name: typeAst, parent }
|
72
|
+
: simplifyAST(typeAst, parent);
|
73
|
+
node.type = type;
|
74
|
+
return node;
|
69
75
|
}
|
70
76
|
if (ast.name === '*') {
|
71
|
-
const [doc, docAst] = ast.args as [string,
|
72
|
-
|
73
|
-
|
74
|
-
? { name: docAst }
|
75
|
-
: simplifyAST(docAst, parent)
|
76
|
-
|
77
|
-
|
77
|
+
const [doc, docAst] = ast.args as [string, CompilerNode];
|
78
|
+
const node =
|
79
|
+
typeof docAst === 'string'
|
80
|
+
? { name: docAst, parent }
|
81
|
+
: simplifyAST(docAst, parent);
|
82
|
+
node.doc = doc;
|
83
|
+
return node;
|
78
84
|
}
|
79
85
|
const node: Node = {
|
80
86
|
name: ast.name,
|