@magnusopera/fscript 0.75.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.
Files changed (79) hide show
  1. package/README.md +5 -0
  2. package/dist/FScript.Language/Ast.js +234 -0
  3. package/dist/FScript.Language/BuiltinFunctions.js +2039 -0
  4. package/dist/FScript.Language/BuiltinSignatures.js +24 -0
  5. package/dist/FScript.Language/BuiltinTypes.js +13 -0
  6. package/dist/FScript.Language/Error.js +74 -0
  7. package/dist/FScript.Language/Eval.js +2404 -0
  8. package/dist/FScript.Language/IncludeResolver.js +806 -0
  9. package/dist/FScript.Language/Lexer.js +1067 -0
  10. package/dist/FScript.Language/Library.js +28 -0
  11. package/dist/FScript.Language/Parser.js +2368 -0
  12. package/dist/FScript.Language/Pretty.js +115 -0
  13. package/dist/FScript.Language/Span.js +33 -0
  14. package/dist/FScript.Language/Token.js +32 -0
  15. package/dist/FScript.Language/TypeInfer.js +2561 -0
  16. package/dist/FScript.Language/Types.js +205 -0
  17. package/dist/FScript.Language/Value.js +91 -0
  18. package/dist/Library.js +732 -0
  19. package/dist/fable_modules/fable-library-js.5.2.0/Array.js +1347 -0
  20. package/dist/fable_modules/fable-library-js.5.2.0/Async.js +134 -0
  21. package/dist/fable_modules/fable-library-js.5.2.0/AsyncBuilder.js +183 -0
  22. package/dist/fable_modules/fable-library-js.5.2.0/BigInt.js +306 -0
  23. package/dist/fable_modules/fable-library-js.5.2.0/BitConverter.js +138 -0
  24. package/dist/fable_modules/fable-library-js.5.2.0/Boolean.js +22 -0
  25. package/dist/fable_modules/fable-library-js.5.2.0/CHANGELOG.md +234 -0
  26. package/dist/fable_modules/fable-library-js.5.2.0/Char.js +202 -0
  27. package/dist/fable_modules/fable-library-js.5.2.0/Choice.js +184 -0
  28. package/dist/fable_modules/fable-library-js.5.2.0/CollectionUtil.js +182 -0
  29. package/dist/fable_modules/fable-library-js.5.2.0/ConditionalWeakTable.js +21 -0
  30. package/dist/fable_modules/fable-library-js.5.2.0/Date.js +841 -0
  31. package/dist/fable_modules/fable-library-js.5.2.0/DateOffset.js +261 -0
  32. package/dist/fable_modules/fable-library-js.5.2.0/DateOnly.js +124 -0
  33. package/dist/fable_modules/fable-library-js.5.2.0/Decimal.js +238 -0
  34. package/dist/fable_modules/fable-library-js.5.2.0/Double.js +47 -0
  35. package/dist/fable_modules/fable-library-js.5.2.0/Encoding.js +185 -0
  36. package/dist/fable_modules/fable-library-js.5.2.0/Event.js +93 -0
  37. package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Collections.js +45 -0
  38. package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Core.CompilerServices.js +27 -0
  39. package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Core.js +156 -0
  40. package/dist/fable_modules/fable-library-js.5.2.0/Global.js +29 -0
  41. package/dist/fable_modules/fable-library-js.5.2.0/Guid.js +161 -0
  42. package/dist/fable_modules/fable-library-js.5.2.0/Int32.js +135 -0
  43. package/dist/fable_modules/fable-library-js.5.2.0/List.js +1323 -0
  44. package/dist/fable_modules/fable-library-js.5.2.0/Long.js +47 -0
  45. package/dist/fable_modules/fable-library-js.5.2.0/MailboxProcessor.js +94 -0
  46. package/dist/fable_modules/fable-library-js.5.2.0/Map.js +1396 -0
  47. package/dist/fable_modules/fable-library-js.5.2.0/MapUtil.js +130 -0
  48. package/dist/fable_modules/fable-library-js.5.2.0/MutableMap.js +339 -0
  49. package/dist/fable_modules/fable-library-js.5.2.0/MutableSet.js +233 -0
  50. package/dist/fable_modules/fable-library-js.5.2.0/Native.js +14 -0
  51. package/dist/fable_modules/fable-library-js.5.2.0/Numeric.js +75 -0
  52. package/dist/fable_modules/fable-library-js.5.2.0/Observable.js +113 -0
  53. package/dist/fable_modules/fable-library-js.5.2.0/Option.js +104 -0
  54. package/dist/fable_modules/fable-library-js.5.2.0/README.md +3 -0
  55. package/dist/fable_modules/fable-library-js.5.2.0/Random.js +172 -0
  56. package/dist/fable_modules/fable-library-js.5.2.0/Range.js +45 -0
  57. package/dist/fable_modules/fable-library-js.5.2.0/Reflection.js +479 -0
  58. package/dist/fable_modules/fable-library-js.5.2.0/RegExp.js +141 -0
  59. package/dist/fable_modules/fable-library-js.5.2.0/Result.js +165 -0
  60. package/dist/fable_modules/fable-library-js.5.2.0/Seq.js +1417 -0
  61. package/dist/fable_modules/fable-library-js.5.2.0/Seq2.js +111 -0
  62. package/dist/fable_modules/fable-library-js.5.2.0/Set.js +1816 -0
  63. package/dist/fable_modules/fable-library-js.5.2.0/String.js +674 -0
  64. package/dist/fable_modules/fable-library-js.5.2.0/System.Collections.Generic.js +333 -0
  65. package/dist/fable_modules/fable-library-js.5.2.0/System.Text.js +200 -0
  66. package/dist/fable_modules/fable-library-js.5.2.0/System.js +283 -0
  67. package/dist/fable_modules/fable-library-js.5.2.0/TimeOnly.js +122 -0
  68. package/dist/fable_modules/fable-library-js.5.2.0/TimeSpan.js +180 -0
  69. package/dist/fable_modules/fable-library-js.5.2.0/Timer.js +67 -0
  70. package/dist/fable_modules/fable-library-js.5.2.0/Types.js +198 -0
  71. package/dist/fable_modules/fable-library-js.5.2.0/Unicode.13.0.0.js +4 -0
  72. package/dist/fable_modules/fable-library-js.5.2.0/Uri.js +165 -0
  73. package/dist/fable_modules/fable-library-js.5.2.0/Util.js +795 -0
  74. package/dist/fable_modules/fable-library-js.5.2.0/big.d.ts +338 -0
  75. package/dist/fable_modules/fable-library-js.5.2.0/lib/big.js +825 -0
  76. package/dist/fable_modules/fable-library-js.5.2.0/package.json +24 -0
  77. package/dist/fable_modules/fable-library-js.5.2.0/quotation.js +618 -0
  78. package/dist/fable_modules/project_cracked.json +1 -0
  79. package/package.json +36 -0
@@ -0,0 +1,806 @@
1
+
2
+ import { printf, toText, isNullOrWhiteSpace, concat, endsWith, substring, split, join, trimEnd, startsWith, replace, isNullOrEmpty, compare } from "../fable_modules/fable-library-js.5.2.0/String.js";
3
+ import { exists, choose, collect, append, map, ofArray, fold as fold_1, singleton, empty, tail as tail_2, cons, head as head_1, isEmpty, reverse } from "../fable_modules/fable-library-js.5.2.0/List.js";
4
+ import { fold } from "../fable_modules/fable-library-js.5.2.0/Array.js";
5
+ import { ParseException, ParseError } from "./Error.js";
6
+ import { isLetterOrDigit, isLetter } from "../fable_modules/fable-library-js.5.2.0/Char.js";
7
+ import { toList as toList_1, fold as fold_2, forAll } from "../fable_modules/fable-library-js.5.2.0/Seq.js";
8
+ import { union, toList, ofList, FSharpSet__Contains, empty as empty_1, add } from "../fable_modules/fable-library-js.5.2.0/Set.js";
9
+ import { curry4, defaultOf, disposeSafe, getEnumerator, Exception, curry2, comparePrimitives } from "../fable_modules/fable-library-js.5.2.0/Util.js";
10
+ import { empty as empty_2, add as add_1, FSharpMap__ContainsKey, FSharpMap__get_Item } from "../fable_modules/fable-library-js.5.2.0/Map.js";
11
+ import { TypeDef, Stmt, InterpolatedPart, MapEntry, Param, Expr, Pattern, TypeRef } from "./Ast.js";
12
+ import { map as map_1 } from "../fable_modules/fable-library-js.5.2.0/Option.js";
13
+ import { parseProgramWithSourceName } from "./Parser.js";
14
+ import { FSharpRef } from "../fable_modules/fable-library-js.5.2.0/Types.js";
15
+ import { Span, Position } from "./Span.js";
16
+ import { addToSet, tryGetValue } from "../fable_modules/fable-library-js.5.2.0/MapUtil.js";
17
+
18
+ const pathComparison = 4;
19
+
20
+ function pathsEqual(left, right) {
21
+ return compare(left, right, pathComparison) === 0;
22
+ }
23
+
24
+ function makeStringDictionary() {
25
+ return new Map([]);
26
+ }
27
+
28
+ function makeStringHashSet() {
29
+ return new Set([]);
30
+ }
31
+
32
+ function normalizeSeparators(path) {
33
+ if (isNullOrEmpty(path)) {
34
+ return "";
35
+ }
36
+ else {
37
+ return replace(path, "\\", "/");
38
+ }
39
+ }
40
+
41
+ function isPathRooted(path) {
42
+ return startsWith(normalizeSeparators(path), "/", 4);
43
+ }
44
+
45
+ function trimTrailingDirectorySeparators(path) {
46
+ const normalized = normalizeSeparators(path);
47
+ if (isNullOrEmpty(normalized) ? true : (normalized === "/")) {
48
+ return normalized;
49
+ }
50
+ else {
51
+ return trimEnd(normalized, "/");
52
+ }
53
+ }
54
+
55
+ function normalizePath(path) {
56
+ const normalized = normalizeSeparators(path);
57
+ const isRooted = startsWith(normalized, "/", 4);
58
+ const body = join("/", reverse(fold((acc, part) => {
59
+ switch (part) {
60
+ case ".":
61
+ return acc;
62
+ case "..":
63
+ if (!isEmpty(acc)) {
64
+ if (head_1(acc) === "..") {
65
+ return cons(part, acc);
66
+ }
67
+ else {
68
+ return tail_2(acc);
69
+ }
70
+ }
71
+ else if (isRooted) {
72
+ return empty();
73
+ }
74
+ else {
75
+ return singleton("..");
76
+ }
77
+ default:
78
+ return cons(part, acc);
79
+ }
80
+ }, empty(), split(normalized, ["/"], undefined, 1))));
81
+ if (isRooted) {
82
+ if (isNullOrEmpty(body)) {
83
+ return "/";
84
+ }
85
+ else {
86
+ return "/" + body;
87
+ }
88
+ }
89
+ else if (isNullOrEmpty(body)) {
90
+ return ".";
91
+ }
92
+ else {
93
+ return body;
94
+ }
95
+ }
96
+
97
+ function normalizeFilePath(path) {
98
+ return normalizePath(path);
99
+ }
100
+
101
+ function getDirectoryName(path) {
102
+ const normalized = trimTrailingDirectorySeparators(path);
103
+ if (isNullOrEmpty(normalized) ? true : (normalized === "/")) {
104
+ return "";
105
+ }
106
+ else {
107
+ const matchValue = normalized.lastIndexOf("/") | 0;
108
+ switch (matchValue) {
109
+ case -1:
110
+ return "";
111
+ case 0:
112
+ return "/";
113
+ default:
114
+ return substring(normalized, 0, matchValue);
115
+ }
116
+ }
117
+ }
118
+
119
+ function combinePath(directory, path) {
120
+ if (isNullOrEmpty(directory)) {
121
+ return path;
122
+ }
123
+ else if (isPathRooted(path)) {
124
+ return path;
125
+ }
126
+ else if (endsWith(directory, "/", 4)) {
127
+ return directory + path;
128
+ }
129
+ else {
130
+ return (directory + "/") + path;
131
+ }
132
+ }
133
+
134
+ function normalizeDirectoryPath(path) {
135
+ const full = normalizePath(path);
136
+ if (endsWith(full, "/", 4)) {
137
+ return full;
138
+ }
139
+ else {
140
+ return full + "/";
141
+ }
142
+ }
143
+
144
+ function ensureFssPath(path, span) {
145
+ if (!endsWith(path, ".fss", 5)) {
146
+ throw new ParseException(new ParseError("Only \'.fss\' files can be used with \'import\'", span));
147
+ }
148
+ }
149
+
150
+ function ensureWithinRoot(rootDirectoryWithSeparator, path, span) {
151
+ const fullPath = normalizePath(path);
152
+ const fullRoot = trimTrailingDirectorySeparators(rootDirectoryWithSeparator);
153
+ const rootWithSeparator = endsWith(fullRoot, "/", 4) ? fullRoot : (fullRoot + "/");
154
+ if (!((compare(fullPath, fullRoot, pathComparison) === 0) ? true : startsWith(fullPath, rootWithSeparator, pathComparison))) {
155
+ throw new ParseException(new ParseError(concat("Imported file \'", fullPath, "\' is outside of sandbox root"), span));
156
+ }
157
+ return fullPath;
158
+ }
159
+
160
+ function getFileNameWithoutExtension(sourceName) {
161
+ const normalized = trimTrailingDirectorySeparators(sourceName);
162
+ let fileName;
163
+ const matchValue = normalized.lastIndexOf("/") | 0;
164
+ fileName = ((matchValue === -1) ? normalized : substring(normalized, matchValue + 1));
165
+ const matchValue_1 = fileName.lastIndexOf(".") | 0;
166
+ if (matchValue_1 > 0) {
167
+ return substring(fileName, 0, matchValue_1);
168
+ }
169
+ else {
170
+ return fileName;
171
+ }
172
+ }
173
+
174
+ function resolveImportPath(currentFile, importPath, rootDirectoryWithSeparator, span) {
175
+ if (isNullOrWhiteSpace(importPath)) {
176
+ throw new ParseException(new ParseError("Import path cannot be empty", span));
177
+ }
178
+ ensureFssPath(importPath, span);
179
+ const currentDirectory = getDirectoryName(currentFile);
180
+ return ensureWithinRoot(rootDirectoryWithSeparator, isPathRooted(importPath) ? importPath : (isNullOrEmpty(currentDirectory) ? importPath : combinePath(currentDirectory, importPath)), span);
181
+ }
182
+
183
+ function isValidAliasName(name) {
184
+ let c;
185
+ if (!isNullOrWhiteSpace(name) && ((c = name[0], isLetter(c) ? true : (c === "_")))) {
186
+ return forAll((c_1) => {
187
+ if (isLetterOrDigit(c_1)) {
188
+ return true;
189
+ }
190
+ else {
191
+ return c_1 === "_";
192
+ }
193
+ }, name.split(""));
194
+ }
195
+ else {
196
+ return false;
197
+ }
198
+ }
199
+
200
+ function tryGetSourceModulePrefix(sourceName) {
201
+ let stem;
202
+ try {
203
+ stem = getFileNameWithoutExtension(sourceName);
204
+ }
205
+ catch (matchValue) {
206
+ stem = sourceName;
207
+ }
208
+ if (isValidAliasName(stem)) {
209
+ return stem;
210
+ }
211
+ else {
212
+ return undefined;
213
+ }
214
+ }
215
+
216
+ function collectPatternBindings(pattern) {
217
+ const loop = (acc_mut, pat_mut) => {
218
+ loop:
219
+ while (true) {
220
+ const acc = acc_mut, pat = pat_mut;
221
+ switch (pat.tag) {
222
+ case 1:
223
+ return add(pat.fields[0], acc);
224
+ case 4: {
225
+ acc_mut = loop(acc, pat.fields[0]);
226
+ pat_mut = pat.fields[1];
227
+ continue loop;
228
+ }
229
+ case 5:
230
+ return fold_1(loop, acc, pat.fields[0]);
231
+ case 6:
232
+ return fold_1((s, tupledArg) => loop(s, tupledArg[1]), acc, pat.fields[0]);
233
+ case 7: {
234
+ const tailPattern = pat.fields[1];
235
+ const withClauses = fold_1((s_1, tupledArg_1) => loop(loop(s_1, tupledArg_1[0]), tupledArg_1[1]), acc, pat.fields[0]);
236
+ if (tailPattern == null) {
237
+ return withClauses;
238
+ }
239
+ else {
240
+ acc_mut = withClauses;
241
+ pat_mut = tailPattern;
242
+ continue loop;
243
+ }
244
+ }
245
+ case 8: {
246
+ acc_mut = acc;
247
+ pat_mut = pat.fields[0];
248
+ continue loop;
249
+ }
250
+ case 10: {
251
+ const payload = pat.fields[2];
252
+ if (payload == null) {
253
+ return acc;
254
+ }
255
+ else {
256
+ acc_mut = acc;
257
+ pat_mut = payload;
258
+ continue loop;
259
+ }
260
+ }
261
+ case 11:
262
+ return acc;
263
+ default:
264
+ return acc;
265
+ }
266
+ break;
267
+ }
268
+ };
269
+ return loop(empty_1({
270
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
271
+ }), pattern);
272
+ }
273
+
274
+ function parseDotted(name) {
275
+ return ofArray(split(name, ["."], undefined, 0));
276
+ }
277
+
278
+ function joinDotted(parts) {
279
+ return join(".", parts);
280
+ }
281
+
282
+ function rewriteNameWithAliases(aliases, name) {
283
+ const matchValue = parseDotted(name);
284
+ let matchResult, first_1, rest_1;
285
+ if (!isEmpty(matchValue)) {
286
+ if (FSharpMap__ContainsKey(aliases, head_1(matchValue)) && !isEmpty(tail_2(matchValue))) {
287
+ matchResult = 0;
288
+ first_1 = head_1(matchValue);
289
+ rest_1 = tail_2(matchValue);
290
+ }
291
+ else {
292
+ matchResult = 1;
293
+ }
294
+ }
295
+ else {
296
+ matchResult = 1;
297
+ }
298
+ switch (matchResult) {
299
+ case 0:
300
+ return (FSharpMap__get_Item(aliases, first_1) + ".") + joinDotted(rest_1);
301
+ default:
302
+ return name;
303
+ }
304
+ }
305
+
306
+ function rewriteNameWithSelfPrefix(selfPrefix, selfNames, boundNames, name) {
307
+ let prefix;
308
+ let matchResult, prefix_1;
309
+ if (selfPrefix != null) {
310
+ if ((prefix = selfPrefix, FSharpSet__Contains(selfNames, name) && !FSharpSet__Contains(boundNames, name))) {
311
+ matchResult = 0;
312
+ prefix_1 = selfPrefix;
313
+ }
314
+ else {
315
+ matchResult = 1;
316
+ }
317
+ }
318
+ else {
319
+ matchResult = 1;
320
+ }
321
+ switch (matchResult) {
322
+ case 0:
323
+ return concat(prefix_1, ".", name);
324
+ default:
325
+ return name;
326
+ }
327
+ }
328
+
329
+ function rewriteTypeName(aliases, selfPrefix, selfTypeNames, name) {
330
+ let prefix;
331
+ const aliasRewritten = rewriteNameWithAliases(aliases, name);
332
+ if (aliasRewritten !== name) {
333
+ return aliasRewritten;
334
+ }
335
+ else {
336
+ let matchResult, prefix_1;
337
+ if (selfPrefix != null) {
338
+ if ((prefix = selfPrefix, FSharpSet__Contains(selfTypeNames, name))) {
339
+ matchResult = 0;
340
+ prefix_1 = selfPrefix;
341
+ }
342
+ else {
343
+ matchResult = 1;
344
+ }
345
+ }
346
+ else {
347
+ matchResult = 1;
348
+ }
349
+ switch (matchResult) {
350
+ case 0:
351
+ return concat(prefix_1, ".", name);
352
+ default:
353
+ return name;
354
+ }
355
+ }
356
+ }
357
+
358
+ function rewriteTypeQualifier(aliases, selfPrefix, selfTypeNames, qualifier) {
359
+ if (qualifier != null) {
360
+ return rewriteTypeName(aliases, selfPrefix, selfTypeNames, qualifier);
361
+ }
362
+ else {
363
+ return undefined;
364
+ }
365
+ }
366
+
367
+ function rewriteTypeRef(aliases, selfPrefix, selfTypeNames, tref) {
368
+ switch (tref.tag) {
369
+ case 1:
370
+ return new TypeRef(1, [map((tref_1) => rewriteTypeRef(aliases, selfPrefix, selfTypeNames, tref_1), tref.fields[0])]);
371
+ case 2:
372
+ return new TypeRef(2, [rewriteTypeRef(aliases, selfPrefix, selfTypeNames, tref.fields[0]), rewriteTypeRef(aliases, selfPrefix, selfTypeNames, tref.fields[1])]);
373
+ case 3:
374
+ return new TypeRef(3, [rewriteTypeRef(aliases, selfPrefix, selfTypeNames, tref.fields[0]), tref.fields[1]]);
375
+ case 4:
376
+ return new TypeRef(4, [map((tupledArg) => [tupledArg[0], rewriteTypeRef(aliases, selfPrefix, selfTypeNames, tupledArg[1])], tref.fields[0])]);
377
+ case 5:
378
+ return new TypeRef(5, [map((tupledArg_1) => [tupledArg_1[0], rewriteTypeRef(aliases, selfPrefix, selfTypeNames, tupledArg_1[1])], tref.fields[0])]);
379
+ default:
380
+ return new TypeRef(0, [rewriteTypeName(aliases, selfPrefix, selfTypeNames, tref.fields[0])]);
381
+ }
382
+ }
383
+
384
+ function rewritePattern(aliases, selfPrefix, selfTypeNames, pat) {
385
+ switch (pat.tag) {
386
+ case 4:
387
+ return new Pattern(4, [rewritePattern(aliases, selfPrefix, selfTypeNames, pat.fields[0]), rewritePattern(aliases, selfPrefix, selfTypeNames, pat.fields[1]), pat.fields[2]]);
388
+ case 5:
389
+ return new Pattern(5, [map((pat_1) => rewritePattern(aliases, selfPrefix, selfTypeNames, pat_1), pat.fields[0]), pat.fields[1]]);
390
+ case 6:
391
+ return new Pattern(6, [map((tupledArg) => [tupledArg[0], rewritePattern(aliases, selfPrefix, selfTypeNames, tupledArg[1])], pat.fields[0]), pat.fields[1]]);
392
+ case 7:
393
+ return new Pattern(7, [map((tupledArg_1) => [rewritePattern(aliases, selfPrefix, selfTypeNames, tupledArg_1[0]), rewritePattern(aliases, selfPrefix, selfTypeNames, tupledArg_1[1])], pat.fields[0]), map_1((pat_2) => rewritePattern(aliases, selfPrefix, selfTypeNames, pat_2), pat.fields[1]), pat.fields[2]]);
394
+ case 8:
395
+ return new Pattern(8, [rewritePattern(aliases, selfPrefix, selfTypeNames, pat.fields[0]), pat.fields[1]]);
396
+ case 10:
397
+ return new Pattern(10, [rewriteTypeQualifier(aliases, selfPrefix, selfTypeNames, pat.fields[0]), pat.fields[1], map_1((pat_3) => rewritePattern(aliases, selfPrefix, selfTypeNames, pat_3), pat.fields[2]), pat.fields[3]]);
398
+ case 11:
399
+ return new Pattern(11, [rewriteTypeRef(aliases, selfPrefix, selfTypeNames, pat.fields[0]), pat.fields[1]]);
400
+ default:
401
+ return pat;
402
+ }
403
+ }
404
+
405
+ function tryFlattenExprPath(expr) {
406
+ const loop = (acc_mut, current_mut) => {
407
+ loop:
408
+ while (true) {
409
+ const acc = acc_mut, current = current_mut;
410
+ switch (current.tag) {
411
+ case 2:
412
+ return append(parseDotted(current.fields[0]), acc);
413
+ case 21: {
414
+ acc_mut = cons(current.fields[1], acc);
415
+ current_mut = current.fields[0];
416
+ continue loop;
417
+ }
418
+ default:
419
+ return undefined;
420
+ }
421
+ break;
422
+ }
423
+ };
424
+ return loop(empty(), expr);
425
+ }
426
+
427
+ function rewriteModuleScopedStatements(selfPrefix, aliases, statements) {
428
+ const topLevelValueNames = ofList(collect((_arg) => {
429
+ switch (_arg.tag) {
430
+ case 2:
431
+ return singleton(_arg.fields[0]);
432
+ case 3:
433
+ return toList(collectPatternBindings(_arg.fields[0]));
434
+ case 4:
435
+ return map((tupledArg) => tupledArg[0], _arg.fields[0]);
436
+ default:
437
+ return empty();
438
+ }
439
+ }, statements), {
440
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
441
+ });
442
+ const topLevelTypeNames = ofList(choose((_arg_5) => {
443
+ if (_arg_5.tag === 0) {
444
+ return _arg_5.fields[0].Name;
445
+ }
446
+ else {
447
+ return undefined;
448
+ }
449
+ }, statements), {
450
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
451
+ });
452
+ const rewriteValueName = (boundNames, name_2) => {
453
+ const aliasRewritten = rewriteNameWithAliases(aliases, name_2);
454
+ if (aliasRewritten !== name_2) {
455
+ return aliasRewritten;
456
+ }
457
+ else {
458
+ return rewriteNameWithSelfPrefix(selfPrefix, topLevelValueNames, boundNames, name_2);
459
+ }
460
+ };
461
+ const rewriteExpr = (boundNames_1, expr) => {
462
+ let rest;
463
+ switch (expr.tag) {
464
+ case 2:
465
+ return new Expr(2, [rewriteValueName(boundNames_1, expr.fields[0]), expr.fields[1]]);
466
+ case 29:
467
+ return new Expr(29, [rewriteValueName(boundNames_1, expr.fields[0]), expr.fields[1]]);
468
+ case 28:
469
+ return new Expr(28, [rewriteTypeName(aliases, selfPrefix, topLevelTypeNames, expr.fields[0]), expr.fields[1]]);
470
+ case 3:
471
+ return new Expr(3, [rewriteExpr(boundNames_1, expr.fields[0]), expr.fields[1]]);
472
+ case 4: {
473
+ const param = expr.fields[0];
474
+ return new Expr(4, [new Param(param.Name, map_1((tref) => rewriteTypeRef(aliases, selfPrefix, topLevelTypeNames, tref), param.Annotation), param.Span), rewriteExpr(add(param.Name, boundNames_1), expr.fields[1]), expr.fields[2]]);
475
+ }
476
+ case 5:
477
+ return new Expr(5, [rewriteExpr(boundNames_1, expr.fields[0]), rewriteExpr(boundNames_1, expr.fields[1]), expr.fields[2]]);
478
+ case 6:
479
+ return new Expr(6, [rewriteExpr(boundNames_1, expr.fields[0]), rewriteExpr(boundNames_1, expr.fields[1]), rewriteExpr(boundNames_1, expr.fields[2]), expr.fields[3]]);
480
+ case 7:
481
+ return new Expr(7, [rewriteExpr(boundNames_1, expr.fields[0]), expr.fields[1]]);
482
+ case 8: {
483
+ const name_6 = expr.fields[0];
484
+ return new Expr(8, [name_6, rewriteExpr(boundNames_1, expr.fields[1]), rewriteExpr(add(name_6, boundNames_1), expr.fields[2]), expr.fields[3]]);
485
+ }
486
+ case 9: {
487
+ const rewrittenCases = map((tupledArg_1) => {
488
+ const rewrittenPattern = rewritePattern(aliases, selfPrefix, topLevelTypeNames, tupledArg_1[0]);
489
+ const boundWithPattern = union(boundNames_1, collectPatternBindings(rewrittenPattern));
490
+ return [rewrittenPattern, map_1(curry2(rewriteExpr)(boundWithPattern), tupledArg_1[1]), rewriteExpr(boundWithPattern, tupledArg_1[2]), tupledArg_1[3]];
491
+ }, expr.fields[1]);
492
+ return new Expr(9, [rewriteExpr(boundNames_1, expr.fields[0]), rewrittenCases, expr.fields[2]]);
493
+ }
494
+ case 10: {
495
+ const valueExpr_1 = expr.fields[1];
496
+ const span_10 = expr.fields[5];
497
+ const name_7 = expr.fields[0];
498
+ const bodyExpr = expr.fields[2];
499
+ const rewrittenReturnAnnotation = map_1((tref_1) => rewriteTypeRef(aliases, selfPrefix, topLevelTypeNames, tref_1), expr.fields[4]);
500
+ if (expr.fields[3]) {
501
+ const boundWithName = add(name_7, boundNames_1);
502
+ return new Expr(10, [name_7, rewriteExpr(boundWithName, valueExpr_1), rewriteExpr(boundWithName, bodyExpr), true, rewrittenReturnAnnotation, span_10]);
503
+ }
504
+ else {
505
+ return new Expr(10, [name_7, rewriteExpr(boundNames_1, valueExpr_1), rewriteExpr(add(name_7, boundNames_1), bodyExpr), false, rewrittenReturnAnnotation, span_10]);
506
+ }
507
+ }
508
+ case 11: {
509
+ const rewrittenPattern_1 = rewritePattern(aliases, selfPrefix, topLevelTypeNames, expr.fields[0]);
510
+ const boundWithPattern_1 = union(boundNames_1, collectPatternBindings(rewrittenPattern_1));
511
+ return new Expr(11, [rewrittenPattern_1, rewriteExpr(boundNames_1, expr.fields[1]), rewriteExpr(boundWithPattern_1, expr.fields[2]), expr.fields[3]]);
512
+ }
513
+ case 12: {
514
+ const bindings_1 = expr.fields[0];
515
+ const recursiveBound = union(boundNames_1, ofList(map((tupledArg_2) => tupledArg_2[0], bindings_1), {
516
+ Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
517
+ }));
518
+ return new Expr(12, [map((tupledArg_3) => {
519
+ const rewrittenArgs = map((p) => (new Param(p.Name, map_1((tref_2) => rewriteTypeRef(aliases, selfPrefix, topLevelTypeNames, tref_2), p.Annotation), p.Span)), tupledArg_3[1]);
520
+ return [tupledArg_3[0], rewrittenArgs, map_1((tref_3) => rewriteTypeRef(aliases, selfPrefix, topLevelTypeNames, tref_3), tupledArg_3[2]), rewriteExpr(fold_1((s, p_1) => add(p_1.Name, s), recursiveBound, rewrittenArgs), tupledArg_3[3]), tupledArg_3[4]];
521
+ }, bindings_1), rewriteExpr(recursiveBound, expr.fields[1]), expr.fields[2]]);
522
+ }
523
+ case 13:
524
+ return new Expr(13, [map(curry2(rewriteExpr)(boundNames_1), expr.fields[0]), expr.fields[1]]);
525
+ case 14:
526
+ return new Expr(14, [rewriteExpr(boundNames_1, expr.fields[0]), rewriteExpr(boundNames_1, expr.fields[1]), expr.fields[2]]);
527
+ case 15:
528
+ return new Expr(15, [map(curry2(rewriteExpr)(boundNames_1), expr.fields[0]), expr.fields[1]]);
529
+ case 16:
530
+ return new Expr(16, [map((tupledArg_4) => [tupledArg_4[0], rewriteExpr(boundNames_1, tupledArg_4[1])], expr.fields[0]), expr.fields[1]]);
531
+ case 17:
532
+ return new Expr(17, [map((tupledArg_5) => [tupledArg_5[0], rewriteExpr(boundNames_1, tupledArg_5[1])], expr.fields[0]), expr.fields[1]]);
533
+ case 18:
534
+ return new Expr(18, [map((_arg_10) => {
535
+ if (_arg_10.tag === 1) {
536
+ return new MapEntry(1, [rewriteExpr(boundNames_1, _arg_10.fields[0])]);
537
+ }
538
+ else {
539
+ return new MapEntry(0, [rewriteExpr(boundNames_1, _arg_10.fields[0]), rewriteExpr(boundNames_1, _arg_10.fields[1])]);
540
+ }
541
+ }, expr.fields[0]), expr.fields[1]]);
542
+ case 19:
543
+ return new Expr(19, [rewriteExpr(boundNames_1, expr.fields[0]), map((tupledArg_6) => [tupledArg_6[0], rewriteExpr(boundNames_1, tupledArg_6[1])], expr.fields[1]), expr.fields[2]]);
544
+ case 20:
545
+ return new Expr(20, [rewriteExpr(boundNames_1, expr.fields[0]), map((tupledArg_7) => [tupledArg_7[0], rewriteExpr(boundNames_1, tupledArg_7[1])], expr.fields[1]), expr.fields[2]]);
546
+ case 21: {
547
+ const target_2 = expr.fields[0];
548
+ const span_21 = expr.fields[2];
549
+ const fieldName = expr.fields[1];
550
+ const matchValue = tryFlattenExprPath(target_2);
551
+ let matchResult, rest_1, root_1;
552
+ if (matchValue != null) {
553
+ if (!isEmpty(matchValue)) {
554
+ if ((rest = tail_2(matchValue), FSharpMap__ContainsKey(aliases, head_1(matchValue)))) {
555
+ matchResult = 0;
556
+ rest_1 = tail_2(matchValue);
557
+ root_1 = head_1(matchValue);
558
+ }
559
+ else {
560
+ matchResult = 1;
561
+ }
562
+ }
563
+ else {
564
+ matchResult = 1;
565
+ }
566
+ }
567
+ else {
568
+ matchResult = 1;
569
+ }
570
+ switch (matchResult) {
571
+ case 0:
572
+ return new Expr(2, [(FSharpMap__get_Item(aliases, root_1) + ".") + joinDotted(append(rest_1, singleton(fieldName))), span_21]);
573
+ default:
574
+ return new Expr(21, [rewriteExpr(boundNames_1, target_2), fieldName, span_21]);
575
+ }
576
+ }
577
+ case 22:
578
+ return new Expr(22, [rewriteExpr(boundNames_1, expr.fields[0]), rewriteExpr(boundNames_1, expr.fields[1]), expr.fields[2]]);
579
+ case 23:
580
+ return new Expr(23, [rewriteExpr(boundNames_1, expr.fields[0]), rewriteExpr(boundNames_1, expr.fields[1]), expr.fields[2]]);
581
+ case 24:
582
+ return new Expr(24, [rewriteExpr(boundNames_1, expr.fields[0]), rewriteExpr(boundNames_1, expr.fields[1]), expr.fields[2]]);
583
+ case 25:
584
+ return new Expr(25, [expr.fields[0], rewriteExpr(boundNames_1, expr.fields[1]), rewriteExpr(boundNames_1, expr.fields[2]), expr.fields[3]]);
585
+ case 26:
586
+ return new Expr(26, [rewriteExpr(boundNames_1, expr.fields[0]), expr.fields[1]]);
587
+ case 30:
588
+ return new Expr(30, [map((_arg_11) => {
589
+ if (_arg_11.tag === 1) {
590
+ return new InterpolatedPart(1, [rewriteExpr(boundNames_1, _arg_11.fields[0])]);
591
+ }
592
+ else {
593
+ return new InterpolatedPart(0, [_arg_11.fields[0]]);
594
+ }
595
+ }, expr.fields[0]), expr.fields[1]]);
596
+ default:
597
+ return expr;
598
+ }
599
+ };
600
+ const qualifySelfName = (name_14) => {
601
+ if (selfPrefix == null) {
602
+ return name_14;
603
+ }
604
+ else {
605
+ return `${selfPrefix}.${name_14}`;
606
+ }
607
+ };
608
+ const rewriteParam = (param_1) => (new Param(param_1.Name, map_1((tref_4) => rewriteTypeRef(aliases, selfPrefix, topLevelTypeNames, tref_4), param_1.Annotation), param_1.Span));
609
+ return map((_arg_12) => {
610
+ let def_1;
611
+ switch (_arg_12.tag) {
612
+ case 2: {
613
+ const isRec_1 = _arg_12.fields[4];
614
+ const rewrittenName = qualifySelfName(_arg_12.fields[0]);
615
+ const rewrittenArgs_1 = map(rewriteParam, _arg_12.fields[1]);
616
+ const rewrittenReturnAnnotation_2 = map_1((tref_6) => rewriteTypeRef(aliases, selfPrefix, topLevelTypeNames, tref_6), _arg_12.fields[2]);
617
+ const bound = fold_1((s_1, p_2) => add(p_2.Name, s_1), empty_1({
618
+ Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
619
+ }), rewrittenArgs_1);
620
+ return new Stmt(2, [rewrittenName, rewrittenArgs_1, rewrittenReturnAnnotation_2, rewriteExpr(isRec_1 ? add(rewrittenName, bound) : bound, _arg_12.fields[3]), isRec_1, _arg_12.fields[5], _arg_12.fields[6]]);
621
+ }
622
+ case 3:
623
+ return new Stmt(3, [rewritePattern(aliases, selfPrefix, topLevelTypeNames, _arg_12.fields[0]), rewriteExpr(empty_1({
624
+ Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
625
+ }), _arg_12.fields[1]), _arg_12.fields[2], _arg_12.fields[3]]);
626
+ case 4: {
627
+ const bindings_2 = _arg_12.fields[0];
628
+ const names_1 = ofList(map((tupledArg_10) => qualifySelfName(tupledArg_10[0]), bindings_2), {
629
+ Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
630
+ });
631
+ return new Stmt(4, [map((tupledArg_11) => {
632
+ const rewrittenName_1 = qualifySelfName(tupledArg_11[0]);
633
+ const rewrittenArgs_2 = map(rewriteParam, tupledArg_11[1]);
634
+ return [rewrittenName_1, rewrittenArgs_2, map_1((tref_7) => rewriteTypeRef(aliases, selfPrefix, topLevelTypeNames, tref_7), tupledArg_11[2]), rewriteExpr(fold_1((s_2, p_3) => add(p_3.Name, s_2), names_1, rewrittenArgs_2), tupledArg_11[3]), tupledArg_11[4]];
635
+ }, bindings_2), _arg_12.fields[1], _arg_12.fields[2]]);
636
+ }
637
+ case 5:
638
+ return new Stmt(5, [rewriteExpr(empty_1({
639
+ Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
640
+ }), _arg_12.fields[0])]);
641
+ case 1:
642
+ throw new Exception("Unexpected unresolved import directive");
643
+ default:
644
+ return new Stmt(0, [(def_1 = _arg_12.fields[0], new TypeDef(qualifySelfName(def_1.Name), def_1.IsRecursive, map((tupledArg_8) => [tupledArg_8[0], rewriteTypeRef(aliases, selfPrefix, topLevelTypeNames, tupledArg_8[1])], def_1.Fields), map((tupledArg_9) => [tupledArg_9[0], map_1((tref_5) => rewriteTypeRef(aliases, selfPrefix, topLevelTypeNames, tref_5), tupledArg_9[1])], def_1.Cases), def_1.Span))]);
645
+ }
646
+ }, statements);
647
+ }
648
+
649
+ function expandProgram(rootDirectoryWithSeparator, fileSpan, getOrCreatePrefix, loadFileRef, stack, isMainFile, currentFile, currentPrefix, program) {
650
+ let seenCode = false;
651
+ const imports = [];
652
+ const localCode = [];
653
+ const enumerator = getEnumerator(program);
654
+ try {
655
+ while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
656
+ const stmt = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
657
+ if (stmt.tag === 1) {
658
+ const span = stmt.fields[2];
659
+ if (seenCode) {
660
+ throw new ParseException(new ParseError("\'import\' directives must appear before code", span));
661
+ }
662
+ void (imports.push([stmt.fields[0], stmt.fields[1], span]));
663
+ }
664
+ else {
665
+ seenCode = true;
666
+ void (localCode.push(stmt));
667
+ }
668
+ }
669
+ }
670
+ finally {
671
+ disposeSafe(enumerator);
672
+ }
673
+ const aliasMappings = fold_2((acc, tupledArg) => {
674
+ const alias_1 = tupledArg[0];
675
+ const span_1 = tupledArg[2];
676
+ if (!isValidAliasName(alias_1)) {
677
+ throw new ParseException(new ParseError(concat("Invalid import alias \'", alias_1, "\'"), span_1));
678
+ }
679
+ if (FSharpMap__ContainsKey(acc, alias_1)) {
680
+ throw new ParseException(new ParseError(concat("Duplicate import alias \'", alias_1, "\'"), span_1));
681
+ }
682
+ return add_1(alias_1, getOrCreatePrefix(resolveImportPath(currentFile, tupledArg[1], rootDirectoryWithSeparator, span_1)), acc);
683
+ }, empty_2({
684
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
685
+ }), imports);
686
+ return append(collect((tupledArg_1) => {
687
+ const resolvedPath_1 = resolveImportPath(currentFile, tupledArg_1[1], rootDirectoryWithSeparator, tupledArg_1[2]);
688
+ const childPrefix = FSharpMap__get_Item(aliasMappings, tupledArg_1[0]);
689
+ return loadFileRef.contents(stack)(false)(resolvedPath_1)(childPrefix);
690
+ }, toList_1(imports)), rewriteModuleScopedStatements(isMainFile ? undefined : currentPrefix, aliasMappings, toList_1(localCode)));
691
+ }
692
+
693
+ export function parseIncludedSource(sourceName, source) {
694
+ const program = parseProgramWithSourceName(sourceName, source);
695
+ const dummyRoot = normalizeDirectoryPath(".");
696
+ let counter = 0;
697
+ const pathPrefixes = makeStringDictionary();
698
+ const loadRef = new FSharpRef((_arg) => ((_arg_1) => ((_arg_2) => ((_arg_3) => empty()))));
699
+ if (exists((_arg_4) => {
700
+ if (_arg_4.tag === 1) {
701
+ return true;
702
+ }
703
+ else {
704
+ return false;
705
+ }
706
+ }, program)) {
707
+ throw new ParseException(new ParseError("Embedded source does not support \'import\'", head_1(choose((_arg_5) => {
708
+ if (_arg_5.tag === 1) {
709
+ return _arg_5.fields[2];
710
+ }
711
+ else {
712
+ return undefined;
713
+ }
714
+ }, program))));
715
+ }
716
+ return expandProgram(dummyRoot, (path) => {
717
+ const p = new Position(path, 1, 1);
718
+ return new Span(p, p);
719
+ }, (path_1) => {
720
+ let matchValue;
721
+ let outArg = defaultOf();
722
+ matchValue = [tryGetValue(pathPrefixes, path_1, new FSharpRef(() => outArg, (v) => {
723
+ outArg = v;
724
+ })), outArg];
725
+ if (matchValue[0]) {
726
+ return matchValue[1];
727
+ }
728
+ else {
729
+ let prefix_1;
730
+ counter = ((counter + 1) | 0);
731
+ prefix_1 = (`__imp${counter}`);
732
+ pathPrefixes.set(path_1, prefix_1);
733
+ return prefix_1;
734
+ }
735
+ }, loadRef, empty(), false, sourceName, tryGetSourceModulePrefix(sourceName), program);
736
+ }
737
+
738
+ export function parseProgramFromFile(rootDirectory, entryFile) {
739
+ const p = new Position(entryFile, 1, 1);
740
+ throw new ParseException(new ParseError("File-backed imports are not supported in Fable builds; use resolver-backed source imports", new Span(p, p)));
741
+ }
742
+
743
+ function parseProgramFromSourceWithIncludesCore(rootDirectory, entryFile, entrySource, resolveImportedSource) {
744
+ const rootDirectoryWithSeparator = normalizeDirectoryPath(rootDirectory);
745
+ const fileSpan = (path) => {
746
+ const p = new Position(path, 1, 1);
747
+ return new Span(p, p);
748
+ };
749
+ let counter = 0;
750
+ const pathPrefixes = makeStringDictionary();
751
+ const emittedFiles = makeStringHashSet();
752
+ const entryFullPath = normalizeFilePath(entryFile);
753
+ const entrySpan = fileSpan(entryFullPath);
754
+ ensureFssPath(entryFullPath, entrySpan);
755
+ const entrySandboxedPath = ensureWithinRoot(rootDirectoryWithSeparator, entryFullPath, entrySpan);
756
+ const loadFile = (stack, isMainFile, filePath, prefix_2) => {
757
+ let arg, matchValue_1;
758
+ const fullFilePath = normalizeFilePath(filePath);
759
+ const initialSpan = fileSpan(fullFilePath);
760
+ ensureFssPath(fullFilePath, initialSpan);
761
+ const sandboxedPath = ensureWithinRoot(rootDirectoryWithSeparator, fullFilePath, initialSpan);
762
+ if (exists((p_1) => pathsEqual(p_1, sandboxedPath), stack)) {
763
+ throw new ParseException(new ParseError((arg = join(" -> ", append(reverse(cons(sandboxedPath, stack)), singleton(sandboxedPath))), toText(printf("Import cycle detected: %s"))(arg)), fileSpan(sandboxedPath)));
764
+ }
765
+ else if (!isMainFile && emittedFiles.has(sandboxedPath)) {
766
+ return empty();
767
+ }
768
+ else {
769
+ if (!isMainFile) {
770
+ addToSet(sandboxedPath, emittedFiles);
771
+ }
772
+ const program = parseProgramWithSourceName(sandboxedPath, pathsEqual(sandboxedPath, entrySandboxedPath) ? entrySource : ((resolveImportedSource == null) ? (() => {
773
+ throw new ParseException(new ParseError(concat("Imported file \'", sandboxedPath, "\' could not be resolved; Fable hosts must provide a resolver"), fileSpan(sandboxedPath)));
774
+ })() : ((matchValue_1 = resolveImportedSource(sandboxedPath), (matchValue_1 == null) ? (() => {
775
+ throw new ParseException(new ParseError(concat("Imported file \'", sandboxedPath, "\' could not be resolved"), fileSpan(sandboxedPath)));
776
+ })() : matchValue_1))));
777
+ return expandProgram(rootDirectoryWithSeparator, fileSpan, (path_1) => {
778
+ let matchValue;
779
+ let outArg = defaultOf();
780
+ matchValue = [tryGetValue(pathPrefixes, path_1, new FSharpRef(() => outArg, (v) => {
781
+ outArg = v;
782
+ })), outArg];
783
+ if (matchValue[0]) {
784
+ return matchValue[1];
785
+ }
786
+ else {
787
+ let prefix_1;
788
+ counter = ((counter + 1) | 0);
789
+ prefix_1 = (`__imp${counter}`);
790
+ pathPrefixes.set(path_1, prefix_1);
791
+ return prefix_1;
792
+ }
793
+ }, new FSharpRef(curry4(loadFile)), cons(sandboxedPath, stack), isMainFile, sandboxedPath, prefix_2, program);
794
+ }
795
+ };
796
+ return loadFile(empty(), true, entrySandboxedPath, undefined);
797
+ }
798
+
799
+ export function parseProgramFromSourceWithIncludes(rootDirectory, entryFile, entrySource) {
800
+ return parseProgramFromSourceWithIncludesCore(rootDirectory, entryFile, entrySource, undefined);
801
+ }
802
+
803
+ export function parseProgramFromSourceWithIncludesResolver(rootDirectory, entryFile, entrySource, resolveImportedSource) {
804
+ return parseProgramFromSourceWithIncludesCore(rootDirectory, entryFile, entrySource, resolveImportedSource);
805
+ }
806
+