motoko 3.2.1 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
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
- CompilerAST,
53
+ CompilerNode,
48
54
  ];
49
- const node: Node =
55
+ const node =
50
56
  typeof subAst === 'string'
51
- ? { name: subAst }
52
- : simplifyAST(subAst as any as CompilerNode, parent);
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 [CompilerAST, string];
63
- return {
64
- ...(typeof typeAst === 'string'
65
- ? { name: typeAst }
66
- : simplifyAST(typeAst, parent)),
67
- type,
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, CompilerAST];
72
- return {
73
- ...(typeof docAst === 'string'
74
- ? { name: docAst }
75
- : simplifyAST(docAst, parent)),
76
- doc,
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,
package/src/file.ts CHANGED
@@ -67,7 +67,7 @@ export const file = (mo: Motoko, path: string) => {
67
67
  return mo.parseMotoko(result.read());
68
68
  },
69
69
  parseMotokoTyped() {
70
- return mo.parseMotokoTyped([path]);
70
+ return mo.parseMotokoTyped(path);
71
71
  },
72
72
  };
73
73
  return result;