motoko 3.11.6 → 3.12.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/src/file.ts CHANGED
@@ -14,6 +14,7 @@ function getValidPath(path: string): string {
14
14
  }
15
15
 
16
16
  export type MotokoFile = ReturnType<typeof file>;
17
+ export type Scope = unknown;
17
18
 
18
19
  export const file = (mo: Motoko, path: string) => {
19
20
  path = getValidPath(path);
@@ -66,9 +67,15 @@ export const file = (mo: Motoko, path: string) => {
66
67
  parseMotoko() {
67
68
  return mo.parseMotoko(result.read());
68
69
  },
70
+ parseMotokoWithDeps() {
71
+ return mo.parseMotokoWithDeps(path, result.read());
72
+ },
69
73
  parseMotokoTyped() {
70
74
  return mo.parseMotokoTyped(path);
71
75
  },
76
+ parseMotokoTypedWithScopeCache(scopeCache: Map<string, Scope>) {
77
+ return mo.parseMotokoTypedWithScopeCache(path, scopeCache);
78
+ },
72
79
  };
73
80
  return result;
74
81
  };
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CompilerNode, Node, simplifyAST } from './ast';
2
- import { file } from './file';
2
+ import { Scope, file } from './file';
3
3
  import {
4
4
  Package,
5
5
  PackageInfo,
@@ -91,6 +91,48 @@ export default function wrapMotoko(compiler: Compiler) {
91
91
  );
92
92
  }
93
93
 
94
+ // Function signatures for `mo.parseMotokoTypedWithScopeCache()`
95
+ type ParseMotokoTypedWithScopeCacheResult = {
96
+ ast: Node;
97
+ type: Node;
98
+ immediateImports: string[];
99
+ };
100
+ function parseMotokoTypedWithScopeCache(
101
+ paths: string,
102
+ scopeCache: Map<string, Scope>,
103
+ ): [ParseMotokoTypedWithScopeCacheResult, Map<string, Scope>];
104
+ function parseMotokoTypedWithScopeCache(
105
+ paths: string[],
106
+ scopeCache: Map<string, Scope>,
107
+ ): [ParseMotokoTypedWithScopeCacheResult[], Map<string, Scope>];
108
+ function parseMotokoTypedWithScopeCache(
109
+ paths: string | string[],
110
+ scopeCache: Map<string, Scope>,
111
+ ): [ParseMotokoTypedWithScopeCacheResult | ParseMotokoTypedWithScopeCacheResult[], Map<string, Scope>] {
112
+ if (typeof paths === 'string') {
113
+ const [progs, outCache] = mo.parseMotokoTypedWithScopeCache([paths], scopeCache);
114
+ return [progs[0], outCache];
115
+ }
116
+ const [progs, outCache] =
117
+ invoke('parseMotokoTypedWithScopeCache', true, [paths, scopeCache]);
118
+ return [
119
+ progs.map(
120
+ ({ ast, typ, immediateImports }: {
121
+ ast: CompilerNode;
122
+ typ: CompilerNode;
123
+ immediateImports: string[];
124
+ }) => {
125
+ return {
126
+ ast: simplifyAST(ast),
127
+ type: simplifyAST(typ),
128
+ immediateImports,
129
+ };
130
+ },
131
+ ),
132
+ outCache,
133
+ ];
134
+ }
135
+
94
136
  const mo = {
95
137
  version,
96
138
  compiler,
@@ -188,7 +230,16 @@ export default function wrapMotoko(compiler: Compiler) {
188
230
  const ast = invoke('parseMotoko', true, [content]);
189
231
  return simplifyAST(ast);
190
232
  },
233
+ parseMotokoWithDeps(
234
+ path: string,
235
+ content: string,
236
+ ): { ast: Node, immediateImports: string[] } {
237
+ const { ast, immediateImports } =
238
+ invoke('parseMotokoWithDeps', true, [path, content]);
239
+ return { ast: simplifyAST(ast), immediateImports };
240
+ },
191
241
  parseMotokoTyped,
242
+ parseMotokoTypedWithScopeCache,
192
243
  resolveMain(directory: string = ''): string | undefined {
193
244
  return resolveMain(mo, directory);
194
245
  },