@magnusopera/fscript 0.77.0 → 0.78.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.
Files changed (85) hide show
  1. package/dist/FScript.Language/Ast.js +2 -2
  2. package/dist/FScript.Language/BuiltinFunctions.js +68 -67
  3. package/dist/FScript.Language/BuiltinSignatures.js +7 -7
  4. package/dist/FScript.Language/BuiltinTypes.js +3 -3
  5. package/dist/FScript.Language/Error.js +2 -2
  6. package/dist/FScript.Language/Eval.js +305 -213
  7. package/dist/FScript.Language/IncludeResolver.js +97 -79
  8. package/dist/FScript.Language/Interactive.js +149 -0
  9. package/dist/FScript.Language/Lexer.js +77 -77
  10. package/dist/FScript.Language/Parser.js +274 -272
  11. package/dist/FScript.Language/Pretty.js +4 -4
  12. package/dist/FScript.Language/Span.js +2 -2
  13. package/dist/FScript.Language/Token.js +59 -2
  14. package/dist/FScript.Language/TypeInfer.js +452 -348
  15. package/dist/FScript.Language/Types.js +22 -10
  16. package/dist/FScript.Language/Value.js +3 -2
  17. package/dist/Library.js +91 -79
  18. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Array.js +36 -35
  19. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Async.js +52 -23
  20. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/AsyncBuilder.js +23 -2
  21. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/BigInt.js +33 -32
  22. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/BitConverter.js +2 -2
  23. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/CHANGELOG.md +80 -1
  24. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Date.js +8 -15
  25. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/DateOffset.js +8 -17
  26. package/dist/fable_modules/fable-library-js.5.13.0/Directory.js +11 -0
  27. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Double.js +8 -2
  28. package/dist/fable_modules/fable-library-js.5.13.0/Environment.js +3 -0
  29. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Event.js +10 -1
  30. package/dist/fable_modules/fable-library-js.5.13.0/File.js +27 -0
  31. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/List.js +35 -21
  32. package/dist/fable_modules/fable-library-js.5.13.0/Long.js +38 -0
  33. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/MailboxProcessor.js +11 -5
  34. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Map.js +8 -4
  35. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/MutableMap.js +2 -2
  36. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/MutableSet.js +1 -1
  37. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Observable.js +5 -3
  38. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Option.js +1 -18
  39. package/dist/fable_modules/fable-library-js.5.13.0/Path.js +31 -0
  40. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Reflection.js +13 -3
  41. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/RegExp.js +53 -24
  42. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Seq.js +109 -22
  43. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Set.js +16 -3
  44. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/String.js +28 -1
  45. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/System.js +15 -9
  46. package/dist/fable_modules/fable-library-js.5.13.0/Task.js +27 -0
  47. package/dist/fable_modules/fable-library-js.5.13.0/TaskBuilder.js +72 -0
  48. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Types.js +12 -12
  49. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Util.js +15 -3
  50. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/package.json +1 -1
  51. package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/quotation.js +25 -8
  52. package/dist/fable_modules/project_cracked.json +1 -1
  53. package/package.json +1 -1
  54. package/dist/fable_modules/fable-library-js.5.2.0/Long.js +0 -47
  55. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Boolean.js +0 -0
  56. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Char.js +0 -0
  57. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Choice.js +0 -0
  58. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/CollectionUtil.js +0 -0
  59. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/ConditionalWeakTable.js +0 -0
  60. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/DateOnly.js +0 -0
  61. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Decimal.js +0 -0
  62. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Encoding.js +0 -0
  63. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/FSharp.Collections.js +0 -0
  64. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/FSharp.Core.CompilerServices.js +0 -0
  65. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/FSharp.Core.js +0 -0
  66. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Global.js +0 -0
  67. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Guid.js +0 -0
  68. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Int32.js +0 -0
  69. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/MapUtil.js +0 -0
  70. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Native.js +0 -0
  71. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Numeric.js +0 -0
  72. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/README.md +0 -0
  73. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Random.js +0 -0
  74. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Range.js +0 -0
  75. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Result.js +0 -0
  76. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Seq2.js +0 -0
  77. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/System.Collections.Generic.js +0 -0
  78. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/System.Text.js +0 -0
  79. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/TimeOnly.js +0 -0
  80. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/TimeSpan.js +0 -0
  81. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Timer.js +0 -0
  82. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Unicode.13.0.0.js +0 -0
  83. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/Uri.js +0 -0
  84. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/big.d.ts +0 -0
  85. /package/dist/fable_modules/{fable-library-js.5.2.0 → fable-library-js.5.13.0}/lib/big.js +0 -0
@@ -0,0 +1,31 @@
1
+ // This library doesn't depend on @types/node (to stay browser-compatible),
2
+ // so these Node.js built-in imports can't be type-checked; the exported
3
+ // functions below still declare their own types for callers to rely on.
4
+ // @ts-ignore
5
+ import { basename, extname, join } from "node:path";
6
+ // @ts-ignore
7
+ import { tmpdir } from "node:os";
8
+ // @ts-ignore
9
+ import { writeFileSync } from "node:fs";
10
+ // Mirrors the format of .NET's Path.GetRandomFileName(): 8 random hex chars,
11
+ // a dot, then 3 more random hex chars.
12
+ export function getRandomFileName() {
13
+ const nameBytes = new Uint8Array(4);
14
+ crypto.getRandomValues(nameBytes);
15
+ const name = Array.from(nameBytes, (b) => b.toString(16).padStart(2, "0")).join("");
16
+ const extBytes = new Uint8Array(2);
17
+ crypto.getRandomValues(extBytes);
18
+ const ext = Array.from(extBytes, (b) => b.toString(16).padStart(2, "0")).join("").slice(0, 3);
19
+ return `${name}.${ext}`;
20
+ }
21
+ export function getFileNameWithoutExtension(path) {
22
+ return basename(path, extname(path));
23
+ }
24
+ export function hasExtension(path) {
25
+ return extname(path) !== "";
26
+ }
27
+ export function getTempFileName() {
28
+ const path = join(tmpdir(), getRandomFileName());
29
+ writeFileSync(path, "");
30
+ return path;
31
+ }
@@ -93,7 +93,11 @@ export function option_type(generic) {
93
93
  return t;
94
94
  }
95
95
  export function list_type(generic) {
96
- return new TypeInfo("Microsoft.FSharp.Collections.FSharpList`1", [generic]);
96
+ const t = new TypeInfo("Microsoft.FSharp.Collections.FSharpList`1", [generic], undefined, undefined, undefined, () => [
97
+ new CaseInfo(t, 0, "Empty"),
98
+ new CaseInfo(t, 1, "Cons", [["Head", generic], ["Tail", t]])
99
+ ]);
100
+ return t;
97
101
  }
98
102
  export function array_type(generic) {
99
103
  return new TypeInfo("[]", [generic]);
@@ -377,8 +381,14 @@ export function getUnionCaseFields(uci) {
377
381
  }
378
382
  // This is used as replacement of `FSharpValue.GetRecordFields`
379
383
  // For `FSharpTypes.GetRecordFields` see `getRecordElements`
380
- // Object.keys returns keys in the order they were added to the object
381
- export function getRecordFields(v) {
384
+ // TypeInfo is used when available to enumerate fields by name: anonymous record None fields
385
+ // are omitted from the JS object, so Object.keys alone would miss them.
386
+ // Boxed anonymous record would are still not covered but this is the best we can do for now
387
+ // without adding a __fields__ to every anonymous record being created
388
+ export function getRecordFields(v, t) {
389
+ if (t.fields != null) {
390
+ return t.fields().map(([key, _]) => v[key]);
391
+ }
382
392
  return Object.keys(v).map((k) => v[k]);
383
393
  }
384
394
  export function getRecordField(v, field) {
@@ -105,29 +105,38 @@ export function replace(reg, input, replacement, limit, offset = 0) {
105
105
  input = tmp;
106
106
  limit = undefined;
107
107
  }
108
- if (typeof replacement === "function") {
109
- limit = limit == null ? -1 : limit;
110
- return input.substring(0, offset) + input.substring(offset).replace(reg, replacer);
111
- }
112
- else {
113
- replacement =
114
- replacement
115
- // $0 doesn't work with JS regex, see #1155
116
- .replace(/\$0/g, (_s) => "$&")
117
- // named groups in replacement are `${name}` in .Net, but `$<name>` in JS (in regex: groups are `(?<name>...)` in both)
118
- .replace(/\${([^}]+)}/g, "\$<$1>");
119
- if (limit != null) {
120
- let m;
121
- const sub1 = input.substring(offset);
122
- const _matches = matches(reg, sub1);
123
- const sub2 = matches.length > limit ? (m = _matches[limit - 1], sub1.substring(0, m.index + m[0].length)) : sub1;
124
- return input.substring(0, offset) + sub2.replace(reg, replacement)
125
- + input.substring(offset + sub2.length);
126
- }
127
- else {
128
- return input.replace(reg, replacement);
129
- }
108
+ if (typeof replacement === "string") {
109
+ const rep = replacement;
110
+ // .NET replacement patterns cannot be rewritten as JS replacement strings unambiguously
111
+ // (e.g. `$$0` must stay literal "$0", `$0` doesn't work with JS regex (see #1155), and
112
+ // `${1}` followed by a digit must not become `$1` + digit), so interpret them with an
113
+ // evaluator instead, honoring the `$$` escape left-to-right
114
+ replacement = (match) => rep.replace(/\$(?:(\$)|(&)|(`)|(')|(\d+)|\{(\d+)\}|\{([^}]+)\})/g, (s, dollar, and, before, after, num, numBraced, name) => {
115
+ if (dollar != null) {
116
+ return "$";
117
+ }
118
+ if (and != null) {
119
+ return match[0];
120
+ }
121
+ if (before != null) {
122
+ return match.input.substring(0, match.index);
123
+ }
124
+ if (after != null) {
125
+ return match.input.substring(match.index + match[0].length);
126
+ }
127
+ const n = num ?? numBraced;
128
+ if (n != null) {
129
+ const i = parseInt(n, 10);
130
+ // Same as .NET: an unmatched group is replaced by an empty string,
131
+ // a nonexistent group number keeps the substitution pattern literally
132
+ return i < match.length ? (match[i] ?? "") : s;
133
+ }
134
+ // Named groups are `${name}` in .NET (in regex: groups are `(?<name>...)` in both)
135
+ return match.groups != null && name in match.groups ? (match.groups[name] ?? "") : s;
136
+ });
130
137
  }
138
+ limit = limit == null ? -1 : limit;
139
+ return input.substring(0, offset) + input.substring(offset).replace(reg, replacer);
131
140
  }
132
141
  export function split(reg, input, limit, offset = 0) {
133
142
  if (typeof reg === "string") {
@@ -136,6 +145,26 @@ export function split(reg, input, limit, offset = 0) {
136
145
  input = tmp;
137
146
  limit = undefined;
138
147
  }
139
- input = input.substring(offset);
140
- return input.split(reg, limit);
148
+ // JS String.split(regex, limit) truncates the result and discards the remainder,
149
+ // whereas .NET keeps it in the last element (`limit` is the max number of elements),
150
+ // keeps the text before `offset` in the first element and includes the values of
151
+ // matched capture groups, so iterate the matches manually like .NET Regex.Split does
152
+ const result = [];
153
+ let prev = 0;
154
+ let count = limit == null ? -1 : limit - 1;
155
+ for (const m of matches(reg, input, offset)) {
156
+ if (count === 0) {
157
+ break;
158
+ }
159
+ result.push(input.substring(prev, m.index));
160
+ prev = m.index + m[0].length;
161
+ for (let i = 1; i < m.length; i++) {
162
+ if (m[i] !== undefined) {
163
+ result.push(m[i]);
164
+ }
165
+ }
166
+ count--;
167
+ }
168
+ result.push(input.substring(prev));
169
+ return result;
141
170
  }
@@ -277,7 +277,7 @@ export function Enumerator_unfold(f, state) {
277
277
  return Enumerator_FromFunctions$1_$ctor_58C54629(() => {
278
278
  if (curr != null) {
279
279
  const x = value_1(curr)[0];
280
- const st = value_1(curr)[1];
280
+ value_1(curr)[1];
281
281
  return x;
282
282
  }
283
283
  else {
@@ -286,7 +286,7 @@ export function Enumerator_unfold(f, state) {
286
286
  }, () => {
287
287
  curr = f(acc);
288
288
  if (curr != null) {
289
- const x_1 = value_1(curr)[0];
289
+ value_1(curr)[0];
290
290
  const st_1 = value_1(curr)[1];
291
291
  acc = st_1;
292
292
  return true;
@@ -457,6 +457,93 @@ export function enumerateUsing(resource, source) {
457
457
  export function enumerateWhile(guard, xs) {
458
458
  return concat(unfold((i) => (guard() ? [xs, i + 1] : undefined), 0));
459
459
  }
460
+ export function enumerateTryWith(source, catchFilter, catchHandler) {
461
+ return mkSeq(() => {
462
+ let e = undefined;
463
+ let caught = false;
464
+ let started = false;
465
+ let finished = false;
466
+ let curr = undefined;
467
+ const tryNext = () => {
468
+ try {
469
+ let en_2;
470
+ if (e == null) {
471
+ const en_1 = getEnumerator(source);
472
+ e = en_1;
473
+ en_2 = en_1;
474
+ }
475
+ else {
476
+ en_2 = value_1(e);
477
+ }
478
+ if (en_2["System.Collections.IEnumerator.MoveNext"]()) {
479
+ curr = some(en_2["System.Collections.Generic.IEnumerator`1.get_Current"]());
480
+ return true;
481
+ }
482
+ else {
483
+ finished = true;
484
+ return false;
485
+ }
486
+ }
487
+ catch (matchValue) {
488
+ if (!caught) {
489
+ const ex_1 = matchValue;
490
+ if (catchFilter(ex_1) !== 0) {
491
+ caught = true;
492
+ if (e == null) {
493
+ }
494
+ else {
495
+ const en_3 = value_1(e);
496
+ try {
497
+ disposeSafe(en_3);
498
+ }
499
+ catch (matchValue_1) {
500
+ }
501
+ e = undefined;
502
+ }
503
+ e = getEnumerator(catchHandler(ex_1));
504
+ return tryNext();
505
+ }
506
+ else {
507
+ throw matchValue;
508
+ }
509
+ }
510
+ else {
511
+ throw matchValue;
512
+ }
513
+ }
514
+ };
515
+ return Enumerator_FromFunctions$1_$ctor_58C54629(() => {
516
+ if (!started) {
517
+ Enumerator_notStarted();
518
+ }
519
+ else if (finished) {
520
+ Enumerator_alreadyFinished();
521
+ }
522
+ if (curr != null) {
523
+ return value_1(curr);
524
+ }
525
+ else {
526
+ return Enumerator_alreadyFinished();
527
+ }
528
+ }, () => {
529
+ if (!started) {
530
+ started = true;
531
+ }
532
+ if (finished) {
533
+ return false;
534
+ }
535
+ else {
536
+ return tryNext();
537
+ }
538
+ }, () => {
539
+ if (e == null) {
540
+ }
541
+ else {
542
+ disposeSafe(value_1(e));
543
+ }
544
+ });
545
+ });
546
+ }
460
547
  export function filter(f, xs) {
461
548
  return choose((x) => {
462
549
  if (f(x)) {
@@ -505,14 +592,14 @@ export function exactlyOne(xs) {
505
592
  if (e["System.Collections.IEnumerator.MoveNext"]()) {
506
593
  const v = e["System.Collections.Generic.IEnumerator`1.get_Current"]();
507
594
  if (e["System.Collections.IEnumerator.MoveNext"]()) {
508
- throw new Exception((SR_inputSequenceTooLong + "\\nParameter name: ") + "source");
595
+ throw new Exception(SR_inputSequenceTooLong + " (Parameter \'source\')");
509
596
  }
510
597
  else {
511
598
  return v;
512
599
  }
513
600
  }
514
601
  else {
515
- throw new Exception((SR_inputSequenceEmpty + "\\nParameter name: ") + "source");
602
+ throw new Exception(SR_inputSequenceEmpty + " (Parameter \'source\')");
516
603
  }
517
604
  }
518
605
  finally {
@@ -692,7 +779,7 @@ export function tryHead(xs) {
692
779
  export function head(xs) {
693
780
  const matchValue = tryHead(xs);
694
781
  if (matchValue == null) {
695
- throw new Exception((SR_inputSequenceEmpty + "\\nParameter name: ") + "source");
782
+ throw new Exception(SR_inputSequenceEmpty + " (Parameter \'source\')");
696
783
  }
697
784
  else {
698
785
  return value_1(matchValue);
@@ -758,7 +845,7 @@ export function tryItem(index, xs) {
758
845
  export function item(index, xs) {
759
846
  const matchValue = tryItem(index, xs);
760
847
  if (matchValue == null) {
761
- throw new Exception((SR_notEnoughElements + "\\nParameter name: ") + "index");
848
+ throw new Exception(SR_notEnoughElements + " (Parameter \'index\')");
762
849
  }
763
850
  else {
764
851
  return value_1(matchValue);
@@ -811,7 +898,7 @@ export function tryLast(xs) {
811
898
  export function last(xs) {
812
899
  const matchValue = tryLast(xs);
813
900
  if (matchValue == null) {
814
- throw new Exception((SR_notEnoughElements + "\\nParameter name: ") + "source");
901
+ throw new Exception(SR_notEnoughElements + " (Parameter \'source\')");
815
902
  }
816
903
  else {
817
904
  return value_1(matchValue);
@@ -1092,7 +1179,7 @@ export function skip(count, source) {
1092
1179
  try {
1093
1180
  for (let _ = 1; _ <= count; _++) {
1094
1181
  if (!e["System.Collections.IEnumerator.MoveNext"]()) {
1095
- throw new Exception((SR_notEnoughElements + "\\nParameter name: ") + "source");
1182
+ throw new Exception(SR_notEnoughElements + " (Parameter \'source\')");
1096
1183
  }
1097
1184
  }
1098
1185
  return Enumerator_enumerateThenFinally(() => {
@@ -1125,7 +1212,7 @@ export function take(count, xs) {
1125
1212
  return some(e["System.Collections.Generic.IEnumerator`1.get_Current"]());
1126
1213
  }
1127
1214
  else {
1128
- throw new Exception((SR_notEnoughElements + "\\nParameter name: ") + "source");
1215
+ throw new Exception(SR_notEnoughElements + " (Parameter \'source\')");
1129
1216
  }
1130
1217
  }
1131
1218
  else {
@@ -1213,7 +1300,7 @@ export function average(xs, averager) {
1213
1300
  return averager.Add(acc, x);
1214
1301
  }, averager.GetZero(), xs);
1215
1302
  if (count === 0) {
1216
- throw new Exception((SR_inputSequenceEmpty + "\\nParameter name: ") + "source");
1303
+ throw new Exception(SR_inputSequenceEmpty + " (Parameter \'source\')");
1217
1304
  }
1218
1305
  else {
1219
1306
  return averager.DivideByInt(total, count);
@@ -1226,7 +1313,7 @@ export function averageBy(f, xs, averager) {
1226
1313
  return averager.Add(acc, f(x));
1227
1314
  }, averager.GetZero(), xs);
1228
1315
  if (count === 0) {
1229
- throw new Exception((SR_inputSequenceEmpty + "\\nParameter name: ") + "source");
1316
+ throw new Exception(SR_inputSequenceEmpty + " (Parameter \'source\')");
1230
1317
  }
1231
1318
  else {
1232
1319
  return averager.DivideByInt(total, count);
@@ -1241,7 +1328,7 @@ export function chunkBySize(chunkSize, xs) {
1241
1328
  export function insertAt(index, y, xs) {
1242
1329
  let isDone = false;
1243
1330
  if (index < 0) {
1244
- throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index");
1331
+ throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
1245
1332
  }
1246
1333
  return generateIndexed(() => ofSeq(xs), (i, e) => {
1247
1334
  if ((isDone ? true : (i < index)) && e["System.Collections.IEnumerator.MoveNext"]()) {
@@ -1253,7 +1340,7 @@ export function insertAt(index, y, xs) {
1253
1340
  }
1254
1341
  else {
1255
1342
  if (!isDone) {
1256
- throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index");
1343
+ throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
1257
1344
  }
1258
1345
  return undefined;
1259
1346
  }
@@ -1264,7 +1351,7 @@ export function insertAt(index, y, xs) {
1264
1351
  export function insertManyAt(index, ys, xs) {
1265
1352
  let status = -1;
1266
1353
  if (index < 0) {
1267
- throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index");
1354
+ throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
1268
1355
  }
1269
1356
  return generateIndexed(() => [ofSeq(xs), ofSeq(ys)], (i, tupledArg) => {
1270
1357
  const e1 = tupledArg[0];
@@ -1291,7 +1378,7 @@ export function insertManyAt(index, ys, xs) {
1291
1378
  }
1292
1379
  else {
1293
1380
  if (status < 1) {
1294
- throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index");
1381
+ throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
1295
1382
  }
1296
1383
  return undefined;
1297
1384
  }
@@ -1307,7 +1394,7 @@ export function insertManyAt(index, ys, xs) {
1307
1394
  export function removeAt(index, xs) {
1308
1395
  let isDone = false;
1309
1396
  if (index < 0) {
1310
- throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index");
1397
+ throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
1311
1398
  }
1312
1399
  return generateIndexed(() => ofSeq(xs), (i, e) => {
1313
1400
  if ((isDone ? true : (i < index)) && e["System.Collections.IEnumerator.MoveNext"]()) {
@@ -1319,7 +1406,7 @@ export function removeAt(index, xs) {
1319
1406
  }
1320
1407
  else {
1321
1408
  if (!isDone) {
1322
- throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index");
1409
+ throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
1323
1410
  }
1324
1411
  return undefined;
1325
1412
  }
@@ -1329,7 +1416,7 @@ export function removeAt(index, xs) {
1329
1416
  }
1330
1417
  export function removeManyAt(index, count, xs) {
1331
1418
  if (index < 0) {
1332
- throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index");
1419
+ throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
1333
1420
  }
1334
1421
  return generateIndexed(() => ofSeq(xs), (i, e) => {
1335
1422
  if (i < index) {
@@ -1337,14 +1424,14 @@ export function removeManyAt(index, count, xs) {
1337
1424
  return some(e["System.Collections.Generic.IEnumerator`1.get_Current"]());
1338
1425
  }
1339
1426
  else {
1340
- throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index");
1427
+ throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
1341
1428
  }
1342
1429
  }
1343
1430
  else {
1344
1431
  if (i === index) {
1345
1432
  for (let _ = 1; _ <= count; _++) {
1346
1433
  if (!e["System.Collections.IEnumerator.MoveNext"]()) {
1347
- throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "count");
1434
+ throw new Exception(SR_indexOutOfBounds + " (Parameter \'count\')");
1348
1435
  }
1349
1436
  }
1350
1437
  }
@@ -1357,7 +1444,7 @@ export function removeManyAt(index, count, xs) {
1357
1444
  export function updateAt(index, y, xs) {
1358
1445
  let isDone = false;
1359
1446
  if (index < 0) {
1360
- throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index");
1447
+ throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
1361
1448
  }
1362
1449
  return generateIndexed(() => ofSeq(xs), (i, e) => {
1363
1450
  if ((isDone ? true : (i < index)) && e["System.Collections.IEnumerator.MoveNext"]()) {
@@ -1369,7 +1456,7 @@ export function updateAt(index, y, xs) {
1369
1456
  }
1370
1457
  else {
1371
1458
  if (!isDone) {
1372
- throw new Exception((SR_indexOutOfBounds + "\\nParameter name: ") + "index");
1459
+ throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
1373
1460
  }
1374
1461
  return undefined;
1375
1462
  }
@@ -1,10 +1,9 @@
1
1
  import { record_type, bool_type, list_type, option_type, class_type } from "./Reflection.js";
2
2
  import { some, value as value_2 } from "./Option.js";
3
3
  import { structuralHash, toIterator, disposeSafe, getEnumerator, isArrayLike, Exception } from "./Util.js";
4
- import { Record } from "./Types.js";
4
+ import { toString, Record } from "./Types.js";
5
5
  import { fold as fold_2, cons, singleton as singleton_1, empty as empty_1, ofArrayWithTail, tail, head, isEmpty as isEmpty_1, FSharpList } from "./List.js";
6
6
  import { fold as fold_1, fill, setItem } from "./Array.js";
7
- import { join } from "./String.js";
8
7
  import { NotSupportedException_$ctor_Z721C83C5 } from "./System.js";
9
8
  import { skip, truncate, iterateIndexed, exists as exists_1, forAll as forAll_1, fold as fold_3, reduce, iterate as iterate_1, map as map_1 } from "./Seq.js";
10
9
  import { HashSet__get_Comparer, HashSet_$ctor_Z6150332D, HashSet } from "./MutableSet.js";
@@ -1402,7 +1401,21 @@ export class FSharpSet {
1402
1401
  }
1403
1402
  toString() {
1404
1403
  const this$ = this;
1405
- return ("set [" + join("; ", this$)) + "]";
1404
+ let result = "set [";
1405
+ let first = true;
1406
+ const enumerator = getEnumerator(this$);
1407
+ try {
1408
+ while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
1409
+ let x = undefined, matchValue = undefined, s = undefined;
1410
+ const x_1 = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
1411
+ result = ((first ? result : (result + "; ")) + ((x = x_1, (matchValue = x, (typeof matchValue === "string") ? ((s = matchValue, ("\"" + s) + "\"")) : toString(x)))));
1412
+ first = false;
1413
+ }
1414
+ }
1415
+ finally {
1416
+ disposeSafe(enumerator);
1417
+ }
1418
+ return result + "]";
1406
1419
  }
1407
1420
  get [Symbol.toStringTag]() {
1408
1421
  return "FSharpSet";
@@ -80,7 +80,7 @@ export function endsWith(str, pattern, ic) {
80
80
  return str.endsWith(pattern);
81
81
  }
82
82
  if (str.length >= pattern.length) {
83
- return cmp(str.slice(-pattern.length), pattern, ic) === 0;
83
+ return cmp(str.slice(str.length - pattern.length), pattern, ic) === 0;
84
84
  }
85
85
  return false;
86
86
  }
@@ -96,6 +96,30 @@ export function contains(str, pattern, ic) {
96
96
  }
97
97
  return false;
98
98
  }
99
+ export function indexOf(str, searchValue, comparison, startIndex = 0) {
100
+ if (comparison === StringComparison.Ordinal) { // fast path
101
+ return str.indexOf(searchValue, startIndex);
102
+ }
103
+ const len = searchValue.length;
104
+ for (let i = Math.max(startIndex, 0); i <= str.length - len; i++) {
105
+ if (cmp(str.slice(i, i + len), searchValue, comparison) === 0) {
106
+ return i;
107
+ }
108
+ }
109
+ return -1;
110
+ }
111
+ export function lastIndexOf(str, searchValue, comparison, startIndex = str.length - 1) {
112
+ if (comparison === StringComparison.Ordinal) { // fast path
113
+ return str.lastIndexOf(searchValue, startIndex);
114
+ }
115
+ const len = searchValue.length;
116
+ for (let i = Math.min(startIndex, str.length - len); i >= 0; i--) {
117
+ if (cmp(str.slice(i, i + len), searchValue, comparison) === 0) {
118
+ return i;
119
+ }
120
+ }
121
+ return -1;
122
+ }
99
123
  export function indexOfAny(str, anyOf, ...args) {
100
124
  if (str == null || str === "") {
101
125
  return -1;
@@ -215,6 +239,9 @@ function formatReplacement(rep, flags, padLength, precision, format) {
215
239
  else if (rep instanceof Date) {
216
240
  rep = dateToString(rep);
217
241
  }
242
+ else if (format === "A" && typeof rep === "string") {
243
+ rep = "\"" + rep + "\"";
244
+ }
218
245
  else {
219
246
  rep = toString(rep);
220
247
  }
@@ -1,4 +1,4 @@
1
- import { Exception } from "./Util.js";
1
+ import { defaultOf, Exception } from "./Util.js";
2
2
  import { class_type } from "./Reflection.js";
3
3
  import { SR_Arg_ArgumentOutOfRangeException, SR_ArgumentNull_Generic, SR_Arg_ArgumentException, SR_Arg_ParamName_Name, SR_Arg_TimeoutException, SR_Arg_StackOverflowException, SR_Arg_RankException, SR_Arg_OverflowException, SR_Arg_OutOfMemoryException, SR_Arg_NullReferenceException, SR_Arg_NotSupportedException, SR_Arg_NotImplementedException, SR_Arg_NotFiniteNumberException, SR_Arg_InvalidOperationException, SR_Arg_IndexOutOfRangeException, SR_Arg_FormatException, SR_Arg_DivideByZero, SR_Arg_ArithmeticException, SR_Arg_ApplicationException, SR_Arg_SystemException } from "./Global.js";
4
4
  import { isNullOrEmpty } from "./String.js";
@@ -227,29 +227,35 @@ export function TimeoutException_$ctor() {
227
227
  return TimeoutException_$ctor_Z721C83C5(SR_Arg_TimeoutException);
228
228
  }
229
229
  export class ArgumentException extends Exception {
230
- constructor(message, paramName) {
231
- super(isNullOrEmpty(paramName) ? message : (((message + SR_Arg_ParamName_Name) + paramName) + "\')"));
230
+ constructor(message, paramName, innerException) {
231
+ super(isNullOrEmpty(paramName) ? message : (((message + SR_Arg_ParamName_Name) + paramName) + "\')"), innerException);
232
232
  this.paramName = paramName;
233
233
  }
234
234
  }
235
235
  export function ArgumentException_$reflection() {
236
236
  return class_type("System.ArgumentException", undefined, ArgumentException, class_type("System.Exception"));
237
237
  }
238
- export function ArgumentException_$ctor_Z384F8060(message, paramName) {
239
- return new ArgumentException(message, paramName);
238
+ export function ArgumentException_$ctor_Z60A2B367(message, paramName, innerException) {
239
+ return new ArgumentException(message, paramName, innerException);
240
240
  }
241
241
  export function ArgumentException_$ctor() {
242
- return ArgumentException_$ctor_Z384F8060(SR_Arg_ArgumentException, "");
242
+ return ArgumentException_$ctor_Z60A2B367(SR_Arg_ArgumentException, "", defaultOf());
243
243
  }
244
244
  export function ArgumentException_$ctor_Z721C83C5(message) {
245
- return ArgumentException_$ctor_Z384F8060(message, "");
245
+ return ArgumentException_$ctor_Z60A2B367(message, "", defaultOf());
246
+ }
247
+ export function ArgumentException_$ctor_Z384F8060(message, paramName) {
248
+ return ArgumentException_$ctor_Z60A2B367(message, paramName, defaultOf());
249
+ }
250
+ export function ArgumentException_$ctor_68CE3CA2(message, innerException) {
251
+ return ArgumentException_$ctor_Z60A2B367(message, "", innerException);
246
252
  }
247
253
  export function ArgumentException__get_ParamName(_) {
248
254
  return _.paramName;
249
255
  }
250
256
  export class ArgumentNullException extends ArgumentException {
251
257
  constructor(paramName, message) {
252
- super(message, paramName);
258
+ super(message, paramName, defaultOf());
253
259
  }
254
260
  }
255
261
  export function ArgumentNullException_$reflection() {
@@ -266,7 +272,7 @@ export function ArgumentNullException_$ctor() {
266
272
  }
267
273
  export class ArgumentOutOfRangeException extends ArgumentException {
268
274
  constructor(paramName, message) {
269
- super(message, paramName);
275
+ super(message, paramName, defaultOf());
270
276
  }
271
277
  }
272
278
  export function ArgumentOutOfRangeException_$reflection() {
@@ -0,0 +1,27 @@
1
+ import { OperationCanceledException } from "./AsyncBuilder.js";
2
+ export class TaskCompletionSource {
3
+ constructor() {
4
+ this.task = new Promise((resolve, reject) => {
5
+ this._resolve = resolve;
6
+ this._reject = reject;
7
+ });
8
+ }
9
+ SetResult(value) { this._resolve(value); }
10
+ SetException(error) { this._reject(error); }
11
+ SetCancelled() { this._reject(new OperationCanceledException()); }
12
+ get_Task() { return this.task; }
13
+ }
14
+ export function fromResult(value) {
15
+ return Promise.resolve(value);
16
+ }
17
+ export function zero() {
18
+ return Promise.resolve();
19
+ }
20
+ // Task<T> = Promise<T> in JS/TS. GetAwaiter/GetResult return the Promise itself;
21
+ // callers should use Async.AwaitTask to extract the value in an async context.
22
+ export function getAwaiter(t) {
23
+ return t;
24
+ }
25
+ export function getResult(t) {
26
+ return t;
27
+ }