@magnusopera/fscript 0.86.1 → 0.86.3

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 (97) hide show
  1. package/dist/FScript.Language/Ast.js +2 -2
  2. package/dist/FScript.Language/BuiltinFunctions.js +106 -61
  3. package/dist/FScript.Language/BuiltinSignatures.js +6 -6
  4. package/dist/FScript.Language/BuiltinTypes.js +1 -1
  5. package/dist/FScript.Language/Error.js +2 -2
  6. package/dist/FScript.Language/Eval.js +52 -60
  7. package/dist/FScript.Language/Execution.js +6 -6
  8. package/dist/FScript.Language/ExportSignatures.js +5 -5
  9. package/dist/FScript.Language/HostInterop.js +8 -8
  10. package/dist/FScript.Language/IncludeResolver.js +10 -10
  11. package/dist/FScript.Language/Interactive.js +7 -7
  12. package/dist/FScript.Language/Lexer.js +19 -11
  13. package/dist/FScript.Language/Parser.js +16 -16
  14. package/dist/FScript.Language/Pretty.js +4 -4
  15. package/dist/FScript.Language/Span.js +2 -2
  16. package/dist/FScript.Language/TaskFunctions.js +2 -2
  17. package/dist/FScript.Language/TaskSharingAnalysis.js +207 -197
  18. package/dist/FScript.Language/Token.js +2 -2
  19. package/dist/FScript.Language/TypeInfer.js +188 -168
  20. package/dist/FScript.Language/Types.js +8 -8
  21. package/dist/FScript.Language/Value.js +2 -2
  22. package/dist/Library.js +13 -13
  23. package/dist/fable_modules/fable-library-js.5.24.0/Async.js +363 -0
  24. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/AsyncBuilder.js +70 -10
  25. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/CHANGELOG.md +90 -1
  26. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/CollectionUtil.js +10 -16
  27. package/dist/fable_modules/fable-library-js.5.24.0/DateOnlyTemporal.js +146 -0
  28. package/dist/fable_modules/fable-library-js.5.24.0/DateTimeFormat.js +523 -0
  29. package/dist/fable_modules/fable-library-js.5.24.0/DateTimeOffsetTemporal.js +283 -0
  30. package/dist/fable_modules/fable-library-js.5.24.0/DateTimeTemporal.js +243 -0
  31. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Decimal.js +100 -11
  32. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Encoding.js +23 -16
  33. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Guid.js +3 -1
  34. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/MailboxProcessor.js +23 -3
  35. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/MutableMap.js +5 -1
  36. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/MutableSet.js +5 -1
  37. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Numeric.js +38 -1
  38. package/dist/fable_modules/fable-library-js.5.24.0/Stopwatch.js +65 -0
  39. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/String.js +43 -9
  40. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/System.Text.js +9 -9
  41. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Task.js +22 -0
  42. package/dist/fable_modules/fable-library-js.5.24.0/TimeOnlyTemporal.js +142 -0
  43. package/dist/fable_modules/fable-library-js.5.24.0/TimeSpanTemporal.js +259 -0
  44. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Util.js +15 -3
  45. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/big.d.ts +1 -0
  46. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/lib/big.js +111 -64
  47. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/package.json +1 -1
  48. package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/quotation.js +47 -0
  49. package/dist/fable_modules/project_cracked.json +1 -1
  50. package/package.json +1 -1
  51. package/dist/fable_modules/fable-library-js.5.13.0/Async.js +0 -163
  52. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Array.js +0 -0
  53. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/BigInt.js +0 -0
  54. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/BitConverter.js +0 -0
  55. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Boolean.js +0 -0
  56. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Char.js +0 -0
  57. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Choice.js +0 -0
  58. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/ConditionalWeakTable.js +0 -0
  59. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Date.js +0 -0
  60. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/DateOffset.js +0 -0
  61. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/DateOnly.js +0 -0
  62. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Directory.js +0 -0
  63. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Double.js +0 -0
  64. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Environment.js +0 -0
  65. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Event.js +0 -0
  66. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/FSharp.Collections.js +0 -0
  67. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/FSharp.Core.CompilerServices.js +0 -0
  68. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/FSharp.Core.js +0 -0
  69. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/File.js +0 -0
  70. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Global.js +0 -0
  71. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Int32.js +0 -0
  72. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/List.js +0 -0
  73. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Long.js +0 -0
  74. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Map.js +0 -0
  75. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/MapUtil.js +0 -0
  76. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Native.js +0 -0
  77. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Observable.js +0 -0
  78. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Option.js +0 -0
  79. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Path.js +0 -0
  80. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/README.md +0 -0
  81. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Random.js +0 -0
  82. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Range.js +0 -0
  83. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Reflection.js +0 -0
  84. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/RegExp.js +0 -0
  85. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Result.js +0 -0
  86. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Seq.js +0 -0
  87. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Seq2.js +0 -0
  88. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Set.js +0 -0
  89. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/System.Collections.Generic.js +0 -0
  90. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/System.js +0 -0
  91. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/TaskBuilder.js +0 -0
  92. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/TimeOnly.js +0 -0
  93. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/TimeSpan.js +0 -0
  94. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Timer.js +0 -0
  95. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Types.js +0 -0
  96. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Unicode.13.0.0.js +0 -0
  97. /package/dist/fable_modules/{fable-library-js.5.13.0 → fable-library-js.5.24.0}/Uri.js +0 -0
@@ -1,12 +1,12 @@
1
1
 
2
- import { Record, Union } from "../fable_modules/fable-library-js.5.13.0/Types.js";
3
- import { record_type, union_type, bool_type, int32_type, option_type, class_type, string_type, list_type } from "../fable_modules/fable-library-js.5.13.0/Reflection.js";
4
- import { toList, isEmpty, ofList, difference, singleton, add, union, empty } from "../fable_modules/fable-library-js.5.13.0/Set.js";
5
- import { Exception, comparePrimitives } from "../fable_modules/fable-library-js.5.13.0/Util.js";
6
- import { empty as empty_1, fold, map } from "../fable_modules/fable-library-js.5.13.0/List.js";
7
- import { fold as fold_1, map as map_1 } from "../fable_modules/fable-library-js.5.13.0/Seq.js";
8
- import { toList as toList_1, values } from "../fable_modules/fable-library-js.5.13.0/Map.js";
9
- import { join, printf, toText } from "../fable_modules/fable-library-js.5.13.0/String.js";
2
+ import { Record, Union } from "../fable_modules/fable-library-js.5.24.0/Types.js";
3
+ import { record_type, union_type, bool_type, int32_type, option_type, class_type, string_type, list_type } from "../fable_modules/fable-library-js.5.24.0/Reflection.js";
4
+ import { toList, isEmpty, ofList, difference, singleton, add, union, empty } from "../fable_modules/fable-library-js.5.24.0/Set.js";
5
+ import { Exception, comparePrimitives } from "../fable_modules/fable-library-js.5.24.0/Util.js";
6
+ import { empty as empty_1, fold, map } from "../fable_modules/fable-library-js.5.24.0/List.js";
7
+ import { fold as fold_1, map as map_1 } from "../fable_modules/fable-library-js.5.24.0/Seq.js";
8
+ import { toList as toList_1, values } from "../fable_modules/fable-library-js.5.24.0/Map.js";
9
+ import { join, printf, toText } from "../fable_modules/fable-library-js.5.24.0/String.js";
10
10
 
11
11
  export class Type extends Union {
12
12
  constructor(tag, fields) {
@@ -1,6 +1,6 @@
1
1
 
2
- import { Record, FSharpRef, Union } from "../fable_modules/fable-library-js.5.13.0/Types.js";
3
- import { int32_type, lambda_type, unit_type, obj_type, record_type, option_type, class_type, list_type, float64_type, union_type, bool_type, int64_type, string_type } from "../fable_modules/fable-library-js.5.13.0/Reflection.js";
2
+ import { Record, FSharpRef, Union } from "../fable_modules/fable-library-js.5.24.0/Types.js";
3
+ import { int32_type, lambda_type, unit_type, obj_type, record_type, option_type, class_type, list_type, float64_type, union_type, bool_type, int64_type, string_type } from "../fable_modules/fable-library-js.5.24.0/Reflection.js";
4
4
  import { HostUnionDescriptor_$reflection, Scheme_$reflection, HostTypeDescriptor_$reflection, Type_$reflection } from "./Types.js";
5
5
  import { Expr_$reflection } from "./Ast.js";
6
6
  import { EvalError$_$reflection } from "./Error.js";
package/dist/Library.js CHANGED
@@ -1,26 +1,26 @@
1
1
 
2
- import { Record } from "./fable_modules/fable-library-js.5.13.0/Types.js";
3
- import { option_type, obj_type, class_type, record_type, list_type, string_type } from "./fable_modules/fable-library-js.5.13.0/Reflection.js";
2
+ import { Record } from "./fable_modules/fable-library-js.5.24.0/Types.js";
3
+ import { option_type, obj_type, class_type, record_type, list_type, string_type } from "./fable_modules/fable-library-js.5.24.0/Reflection.js";
4
4
  import { Stmt_$reflection } from "./FScript.Language/Ast.js";
5
5
  import { ExtensionRegistration, ExternalFunction, MapKey, Value, ExternalCallContext_$reflection, Value_$reflection, ExtensionRegistration_$reflection } from "./FScript.Language/Value.js";
6
6
  import { inferProgramWithRegistration, TypedStmt_$reflection } from "./FScript.Language/TypeInfer.js";
7
7
  import { HostUnionDescriptor, HostTypeDescriptor, Scheme, Type, Types_ftvType, Types_typeToString, Type_$reflection } from "./FScript.Language/Types.js";
8
8
  import { submit as submit_1, createWithRegistration, Session_$reflection } from "./FScript.Language/Interactive.js";
9
- import { foldBack, find, tryFind as tryFind_1, choose, filter, sort, exists, singleton, collect, append, iterate as iterate_1, tail, head, isEmpty as isEmpty_1, fold, zip, iterateIndexed, empty, ofArray, length, map, toArray } from "./fable_modules/fable-library-js.5.13.0/List.js";
10
- import { flatten, defaultArg, value as value_15, some } from "./fable_modules/fable-library-js.5.13.0/Option.js";
11
- import { stringHash, disposeSafe, getEnumerator, curry2, compare, comparePrimitives, Exception } from "./fable_modules/fable-library-js.5.13.0/Util.js";
12
- import { isNullOrWhiteSpace, concat } from "./fable_modules/fable-library-js.5.13.0/String.js";
9
+ import { foldBack, find, tryFind as tryFind_1, choose, filter, sort, exists, singleton, collect, append, iterate as iterate_1, tail, head, isEmpty as isEmpty_1, fold, zip, iterateIndexed, empty, ofArray, length, map, toArray } from "./fable_modules/fable-library-js.5.24.0/List.js";
10
+ import { flatten, defaultArg, value as value_15, some } from "./fable_modules/fable-library-js.5.24.0/Option.js";
11
+ import { stringHash, disposeSafe, getEnumerator, curry2, compare, comparePrimitives, Exception } from "./fable_modules/fable-library-js.5.24.0/Util.js";
12
+ import { isNullOrWhiteSpace, concat } from "./fable_modules/fable-library-js.5.24.0/String.js";
13
13
  import { EvalError$, EvalException, TypeException, ParseException } from "./FScript.Language/Error.js";
14
- import { toInt32_unchecked, fromFloat64, toInt64_unchecked } from "./fable_modules/fable-library-js.5.13.0/BigInt.js";
15
- import { parse as parse_1 } from "./fable_modules/fable-library-js.5.13.0/Long.js";
16
- import { parse as parse_2 } from "./fable_modules/fable-library-js.5.13.0/Int32.js";
17
- import { FSharpMap__get_Count, FSharpMap__get_Keys, empty as empty_3, FSharpMap__get_Item, FSharpMap__TryFind, FSharpMap__ContainsKey, tryFind, iterate, ofList, toList } from "./fable_modules/fable-library-js.5.13.0/Map.js";
18
- import { map as map_1, item } from "./fable_modules/fable-library-js.5.13.0/Array.js";
19
- import { ofSeq, ofList as ofList_1, isSubset, FSharpSet__Add, FSharpSet__Contains, empty as empty_1, isEmpty } from "./fable_modules/fable-library-js.5.13.0/Set.js";
14
+ import { toInt32_unchecked, fromFloat64, toInt64_unchecked } from "./fable_modules/fable-library-js.5.24.0/BigInt.js";
15
+ import { parse as parse_1 } from "./fable_modules/fable-library-js.5.24.0/Long.js";
16
+ import { parse as parse_2 } from "./fable_modules/fable-library-js.5.24.0/Int32.js";
17
+ import { FSharpMap__get_Count, FSharpMap__get_Keys, empty as empty_3, FSharpMap__get_Item, FSharpMap__TryFind, FSharpMap__ContainsKey, tryFind, iterate, ofList, toList } from "./fable_modules/fable-library-js.5.24.0/Map.js";
18
+ import { map as map_1, item } from "./fable_modules/fable-library-js.5.24.0/Array.js";
19
+ import { ofSeq, ofList as ofList_1, isSubset, FSharpSet__Add, FSharpSet__Contains, empty as empty_1, isEmpty } from "./fable_modules/fable-library-js.5.24.0/Set.js";
20
20
  import { $007CRecordFields$007C_$007C, create, empty as empty_2, typeDefinitions, validateCall } from "./FScript.Language/HostInterop.js";
21
21
  import { parseProgramFromSourceWithIncludesResolver } from "./FScript.Language/IncludeResolver.js";
22
22
  import { invokeValue, evalProgramWithRegistration, evalProgramWithRegistrationState } from "./FScript.Language/Eval.js";
23
- import { List_distinct } from "./fable_modules/fable-library-js.5.13.0/Seq2.js";
23
+ import { List_distinct } from "./fable_modules/fable-library-js.5.24.0/Seq2.js";
24
24
  import { valueToString } from "./FScript.Language/Pretty.js";
25
25
  import { Span, Position } from "./FScript.Language/Span.js";
26
26
 
@@ -0,0 +1,363 @@
1
+ import { OperationCanceledException, Trampoline } from "./AsyncBuilder.js";
2
+ import { CancellationToken } from "./AsyncBuilder.js";
3
+ import { protectedCont, protectedBind, protectedReturn } from "./AsyncBuilder.js";
4
+ import { Choice_makeChoice1Of2, Choice_makeChoice2Of2 } from "./Choice.js";
5
+ import { ArgumentException_$ctor_Z384F8060, InvalidOperationException_$ctor_Z721C83C5, TimeoutException_$ctor } from "./System.js";
6
+ import { Exception, ensureErrorOrException } from "./Util.js";
7
+ function emptyContinuation(_x) {
8
+ // NOP
9
+ }
10
+ // MakeAsync: body:(AsyncActivation<'T> -> AsyncReturn) -> Async<'T>
11
+ export function makeAsync(body) {
12
+ return body;
13
+ }
14
+ // Invoke: computation: Async<'T> -> ctxt:AsyncActivation<'T> -> AsyncReturn
15
+ export function invoke(computation, ctx) {
16
+ return computation(ctx);
17
+ }
18
+ // CallThenInvoke: ctxt:AsyncActivation<'T> -> result1:'U -> part2:('U -> Async<'T>) -> AsyncReturn
19
+ export function callThenInvoke(ctx, result1, part2) {
20
+ return part2(result1)(ctx);
21
+ }
22
+ // Bind: ctxt:AsyncActivation<'T> -> part1:Async<'U> -> part2:('U -> Async<'T>) -> AsyncReturn
23
+ export function bind(ctx, part1, part2) {
24
+ return protectedBind(part1, part2)(ctx);
25
+ }
26
+ export function createCancellationToken(arg) {
27
+ const token = new CancellationToken(typeof arg === "boolean" ? arg : false);
28
+ if (typeof arg === "number") {
29
+ setTimeout(() => { token.cancel(); }, arg);
30
+ }
31
+ return token;
32
+ }
33
+ export function cancel(token) {
34
+ token.cancel();
35
+ }
36
+ export function cancelAfter(token, ms) {
37
+ setTimeout(() => { token.cancel(); }, ms);
38
+ }
39
+ export function isCancellationRequested(token) {
40
+ return token != null && token.isCancelled;
41
+ }
42
+ export function throwIfCancellationRequested(token) {
43
+ if (token != null && token.isCancelled) {
44
+ throw new Exception("Operation is cancelled");
45
+ }
46
+ }
47
+ // The parent keeps the listener until unlink is called
48
+ function createLinkedToken(parent) {
49
+ const token = new CancellationToken();
50
+ const id = parent.addListener(() => token.cancel());
51
+ return [token, () => { parent.removeListener(id); }];
52
+ }
53
+ export function startChild(computation, ms) {
54
+ return protectedCont((ctx) => {
55
+ const timeout = ms == null || ms === -1 ? undefined : ms;
56
+ const [childToken, unlink] = timeout === undefined
57
+ ? [ctx.cancelToken, () => { }]
58
+ : createLinkedToken(ctx.cancelToken);
59
+ const promise = startAsPromise(computation, childToken);
60
+ let settled = false;
61
+ const onSettled = () => { settled = true; unlink(); };
62
+ // Without a rejection handler an unawaited child's failure is an unhandled rejection
63
+ promise.then(onSettled, onSettled);
64
+ // Like .NET, the timeout only runs while the result is awaited, not from the start of the child
65
+ const awaitResult = () => timeout === undefined || settled ? promise : new Promise((resolve, reject) => {
66
+ const timeoutId = setTimeout(() => {
67
+ // .NET doesn't cancel the child when the timeout is 0
68
+ if (timeout !== 0) {
69
+ try {
70
+ childToken.cancel();
71
+ }
72
+ catch (error) {
73
+ reject(error);
74
+ return;
75
+ }
76
+ }
77
+ reject(TimeoutException_$ctor());
78
+ }, timeout);
79
+ promise.then(value => { clearTimeout(timeoutId); resolve(value); }, error => { clearTimeout(timeoutId); reject(error); });
80
+ });
81
+ // JS Promises are hot, computation has already started
82
+ // but we delay returning the result
83
+ protectedReturn(protectedCont((awaitCtx) => awaitPromise(awaitResult())(awaitCtx)))(ctx);
84
+ });
85
+ }
86
+ export function awaitPromise(p) {
87
+ return fromContinuations((conts) => p.then(conts[0]).catch((err) => (err instanceof OperationCanceledException
88
+ ? conts[2] : conts[1])(err)));
89
+ }
90
+ export function awaitEvent(event, cancelAction) {
91
+ return protectedCont((ctx) => {
92
+ let tokenId;
93
+ const handler = ((_sender, arg) => {
94
+ ctx.cancelToken.removeListener(tokenId);
95
+ event.RemoveHandler(handler);
96
+ ctx.onSuccess(arg);
97
+ });
98
+ tokenId = ctx.cancelToken.addListener(() => {
99
+ event.RemoveHandler(handler);
100
+ if (cancelAction != null) {
101
+ cancelAction();
102
+ }
103
+ ctx.onCancel(new OperationCanceledException());
104
+ });
105
+ if (ctx.cancelToken.isCancelled) {
106
+ return;
107
+ }
108
+ event.AddHandler(handler);
109
+ });
110
+ }
111
+ export function cancellationToken() {
112
+ return protectedCont((ctx) => ctx.onSuccess(ctx.cancelToken));
113
+ }
114
+ export const defaultCancellationToken = new CancellationToken();
115
+ export function catchAsync(work) {
116
+ return protectedCont((ctx) => {
117
+ work({
118
+ onSuccess: (x) => ctx.onSuccess(Choice_makeChoice1Of2(x)),
119
+ onError: (ex) => ctx.onSuccess(Choice_makeChoice2Of2(ex)),
120
+ onCancel: ctx.onCancel,
121
+ cancelToken: ctx.cancelToken,
122
+ trampoline: ctx.trampoline,
123
+ });
124
+ });
125
+ }
126
+ export function tryCancelled(computation, compensation) {
127
+ return (ctx) => {
128
+ // invariant: install the handler without adding a cancellation checkpoint, including for nested handlers
129
+ computation({
130
+ ...ctx,
131
+ onCancel: (error) => {
132
+ // decision: preserve the original cancellation even when compensation throws, matching .NET
133
+ try {
134
+ compensation(error);
135
+ }
136
+ catch { /* Cancellation takes precedence. */ }
137
+ if (ctx.trampoline.incrementAndCheck()) {
138
+ ctx.trampoline.hijack(() => ctx.onCancel(error));
139
+ }
140
+ else {
141
+ ctx.onCancel(error);
142
+ }
143
+ },
144
+ });
145
+ };
146
+ }
147
+ export function fromContinuations(f) {
148
+ return (ctx) => {
149
+ let settled = false;
150
+ const claim = () => {
151
+ if (settled) {
152
+ throw InvalidOperationException_$ctor_Z721C83C5("A continuation was invoked more than once");
153
+ }
154
+ settled = true;
155
+ };
156
+ const success = (x) => { claim(); ctx.onSuccess(x); };
157
+ const error = (x) => { claim(); ctx.onError(x); };
158
+ const cancelled = (x) => { claim(); ctx.onCancel(x); };
159
+ protectedCont(() => f([success, error, cancelled]))({
160
+ onSuccess: success,
161
+ onError: (x) => { if (settled) {
162
+ throw x;
163
+ } error(x); },
164
+ onCancel: cancelled,
165
+ cancelToken: ctx.cancelToken,
166
+ trampoline: ctx.trampoline,
167
+ });
168
+ };
169
+ }
170
+ export function ignore(computation) {
171
+ return protectedBind(computation, (_x) => protectedReturn(void 0));
172
+ }
173
+ export function parallel(computations, maxDegreeOfParallelism) {
174
+ if (maxDegreeOfParallelism != null && maxDegreeOfParallelism < 1) {
175
+ throw ArgumentException_$ctor_Z384F8060(`maxDegreeOfParallelism must be positive, was ${maxDegreeOfParallelism}`, "maxDegreeOfParallelism");
176
+ }
177
+ return protectedCont((ctx) => awaitPromise(runParallel(Array.from(computations), maxDegreeOfParallelism, ctx.cancelToken))(ctx));
178
+ }
179
+ function runParallel(computations, limit, parentToken) {
180
+ return new Promise((resolve, reject) => {
181
+ const count = computations.length;
182
+ const results = new Array(count);
183
+ const [token, unlink] = createLinkedToken(parentToken);
184
+ let next = 0;
185
+ let running = 0;
186
+ let failed = false;
187
+ let failure;
188
+ const startNext = () => {
189
+ const i = next++;
190
+ running++;
191
+ startAsPromise(computations[i], token)
192
+ .then((x) => { results[i] = x; }, (err) => {
193
+ if (!failed) {
194
+ failed = true;
195
+ failure = err;
196
+ try {
197
+ token.cancel();
198
+ }
199
+ catch (error) {
200
+ failure = error;
201
+ }
202
+ }
203
+ })
204
+ .then(() => {
205
+ running--;
206
+ if (!failed && next < count) {
207
+ startNext();
208
+ }
209
+ else if (running === 0) {
210
+ unlink();
211
+ if (failed) {
212
+ reject(failure);
213
+ }
214
+ else {
215
+ resolve(results);
216
+ }
217
+ }
218
+ });
219
+ };
220
+ if (count === 0) {
221
+ unlink();
222
+ resolve(results);
223
+ }
224
+ const initial = Math.min(limit ?? count, count);
225
+ while (next < initial) {
226
+ startNext();
227
+ }
228
+ });
229
+ }
230
+ export function choice(computations) {
231
+ return protectedCont((ctx) => {
232
+ const works = Array.from(computations);
233
+ let remaining = works.length;
234
+ if (remaining === 0) {
235
+ ctx.onSuccess(undefined);
236
+ return;
237
+ }
238
+ const [token, unlink] = createLinkedToken(ctx.cancelToken);
239
+ let done = false;
240
+ const finish = (report) => {
241
+ if (done) {
242
+ return;
243
+ }
244
+ done = true;
245
+ unlink();
246
+ try {
247
+ token.cancel();
248
+ }
249
+ catch (error) {
250
+ ctx.onError(ensureErrorOrException(error));
251
+ return;
252
+ }
253
+ report();
254
+ };
255
+ for (const work of works) {
256
+ startWithContinuations(work, (x) => {
257
+ if (x != null) {
258
+ finish(() => ctx.onSuccess(x));
259
+ }
260
+ else if (--remaining === 0) {
261
+ finish(() => ctx.onSuccess(undefined));
262
+ }
263
+ }, (err) => finish(() => ctx.onError(err)), (err) => finish(() => ctx.onCancel(err)), token);
264
+ if (done) {
265
+ break;
266
+ }
267
+ }
268
+ });
269
+ }
270
+ export function onCancel(interruption) {
271
+ return protectedCont((ctx) => {
272
+ const token = ctx.cancelToken;
273
+ let interrupted = false;
274
+ const interrupt = () => {
275
+ if (!interrupted) {
276
+ interrupted = true;
277
+ try {
278
+ interruption();
279
+ }
280
+ catch { /* Ignored, like .NET Async.OnCancel */ }
281
+ }
282
+ };
283
+ const id = token.addListener(interrupt);
284
+ let disposed = false;
285
+ ctx.onSuccess({
286
+ Dispose() {
287
+ if (disposed) {
288
+ return;
289
+ }
290
+ disposed = true;
291
+ token.removeListener(id);
292
+ // With use! Dispose runs inside cancel() before this listener gets its turn
293
+ if (token.isCancelled) {
294
+ interrupt();
295
+ }
296
+ },
297
+ });
298
+ });
299
+ }
300
+ export function sequential(computations) {
301
+ function _sequential(computations, cancelToken) {
302
+ let pr = Promise.resolve([]);
303
+ for (const c of computations) {
304
+ pr = pr.then(results => startAsPromise(c, cancelToken).then(r => results.concat([r])));
305
+ }
306
+ return pr;
307
+ }
308
+ // Children share the parent's cancellation token, like .NET Async.Sequential
309
+ return protectedCont((ctx) => awaitPromise(_sequential(computations, ctx.cancelToken))(ctx));
310
+ }
311
+ export function sleep(millisecondsDueTime) {
312
+ return protectedCont((ctx) => {
313
+ let completed = false;
314
+ let tokenId;
315
+ const settle = (cancelled) => {
316
+ if (completed) {
317
+ return;
318
+ }
319
+ completed = true;
320
+ clearTimeout(timeoutId);
321
+ if (tokenId !== undefined) {
322
+ ctx.cancelToken.removeListener(tokenId);
323
+ }
324
+ if (cancelled) {
325
+ ctx.onCancel(new OperationCanceledException());
326
+ }
327
+ else {
328
+ ctx.onSuccess(void 0);
329
+ }
330
+ };
331
+ const timeoutId = setTimeout(() => settle(false), millisecondsDueTime);
332
+ tokenId = ctx.cancelToken.addListener(() => settle(true));
333
+ });
334
+ }
335
+ export function start(computation, cancellationToken) {
336
+ return startWithContinuations(computation, emptyContinuation, function (err) { throw err; }, emptyContinuation, cancellationToken);
337
+ }
338
+ export function startImmediate(computation, cancellationToken) {
339
+ return start(computation, cancellationToken);
340
+ }
341
+ export function startWithContinuations(computation, continuation, exceptionContinuation, cancellationContinuation, cancelToken) {
342
+ const trampoline = new Trampoline();
343
+ // Mark the computation completed as soon as a terminal continuation is entered
344
+ // so protectedCont lets exceptions from continuation code propagate instead of
345
+ // routing them to onError (see Trampoline.completed).
346
+ const done = (cont) => (x) => { trampoline.completed = true; return cont(x); };
347
+ computation({
348
+ onSuccess: done(continuation ? continuation : emptyContinuation),
349
+ onError: done(exceptionContinuation),
350
+ onCancel: done(cancellationContinuation),
351
+ cancelToken: cancelToken ? cancelToken : defaultCancellationToken,
352
+ trampoline,
353
+ });
354
+ }
355
+ export function startAsPromise(computation, cancellationToken) {
356
+ return new Promise((resolve, reject) => startWithContinuations(computation, resolve, reject, reject, cancellationToken ? cancellationToken : defaultCancellationToken));
357
+ }
358
+ export function startAsTask(computation, _taskCreationOptions, cancellationToken) {
359
+ return startAsPromise(computation, cancellationToken);
360
+ }
361
+ export function startImmediateAsTask(computation, cancellationToken) {
362
+ return startAsPromise(computation, cancellationToken);
363
+ }
@@ -1,4 +1,12 @@
1
1
  import { Exception, ensureErrorOrException } from "./Util.js";
2
+ // AggregateError requires ES2021; the runtime also supports ES2020 hosts.
3
+ export class CancellationCallbackError extends Exception {
4
+ constructor(errors) {
5
+ // invariant: F# InnerException exposes the first failure without discarding the remaining errors
6
+ super("Cancellation callbacks failed", errors[0]);
7
+ this.errors = errors;
8
+ }
9
+ }
2
10
  export class CancellationToken {
3
11
  constructor(cancelled = false) {
4
12
  this._id = 0;
@@ -11,14 +19,35 @@ export class CancellationToken {
11
19
  cancel() {
12
20
  if (!this._cancelled) {
13
21
  this._cancelled = true;
14
- for (const [, listener] of this._listeners) {
15
- listener();
22
+ // decision: visit newest registrations first, matching .NET; disposal can skip pending callbacks
23
+ const pending = Array.from(this._listeners.keys()).reverse();
24
+ const errors = [];
25
+ for (const id of pending) {
26
+ const listener = this._listeners.get(id);
27
+ this._listeners.delete(id);
28
+ if (listener) {
29
+ try {
30
+ listener();
31
+ }
32
+ catch (error) {
33
+ errors.push(error);
34
+ }
35
+ }
36
+ }
37
+ if (errors.length > 0) {
38
+ throw new CancellationCallbackError(errors);
16
39
  }
17
40
  }
18
41
  }
19
42
  addListener(f) {
20
43
  const id = this._id;
21
- this._listeners.set(this._id++, f);
44
+ this._id++;
45
+ if (this._cancelled) {
46
+ f();
47
+ }
48
+ else {
49
+ this._listeners.set(id, f);
50
+ }
22
51
  return id;
23
52
  }
24
53
  removeListener(id) {
@@ -145,24 +174,54 @@ export class AsyncBuilder {
145
174
  return computation;
146
175
  }
147
176
  TryFinally(computation, compensation) {
148
- return protectedCont((ctx) => {
149
- computation({
177
+ // The cancellation check in protectedCont must see the cleanup continuations
178
+ return (ctx) => {
179
+ let settled = false;
180
+ protectedCont(computation)({
150
181
  onSuccess: (x) => {
151
- compensation();
182
+ if (settled) {
183
+ return;
184
+ }
185
+ settled = true;
186
+ try {
187
+ compensation();
188
+ }
189
+ catch (error) {
190
+ ctx.onError(ensureErrorOrException(error));
191
+ return;
192
+ }
152
193
  ctx.onSuccess(x);
153
194
  },
154
195
  onError: (x) => {
155
- compensation();
196
+ if (settled) {
197
+ throw x;
198
+ }
199
+ settled = true;
200
+ try {
201
+ compensation();
202
+ }
203
+ catch (error) {
204
+ ctx.onError(ensureErrorOrException(error));
205
+ return;
206
+ }
156
207
  ctx.onError(x);
157
208
  },
158
209
  onCancel: (x) => {
159
- compensation();
210
+ if (settled) {
211
+ return;
212
+ }
213
+ settled = true;
214
+ // decision: cancellation remains terminal when compensation throws, matching .NET Async.TryFinally
215
+ try {
216
+ compensation();
217
+ }
218
+ catch { /* Cancellation takes precedence. */ }
160
219
  ctx.onCancel(x);
161
220
  },
162
221
  cancelToken: ctx.cancelToken,
163
222
  trampoline: ctx.trampoline,
164
223
  });
165
- });
224
+ };
166
225
  }
167
226
  TryWith(computation, catchHandler) {
168
227
  return protectedCont((ctx) => {
@@ -187,7 +246,8 @@ export class AsyncBuilder {
187
246
  });
188
247
  }
189
248
  Using(resource, binder) {
190
- return this.TryFinally(binder(resource), () => resource.Dispose());
249
+ // Without Delay the binder runs before TryFinally installs Dispose
250
+ return this.TryFinally(this.Delay(() => binder(resource)), () => resource.Dispose());
191
251
  }
192
252
  While(guard, computation) {
193
253
  if (guard()) {
@@ -1,5 +1,5 @@
1
1
  ---
2
- last_commit_released: 619d7afddbaf25108e819abaaa9d8a6503c457d6
2
+ last_commit_released: 2098f64a25e96385306ef19ed8c289f3b6c84db9
3
3
  updaters:
4
4
  - package.json:
5
5
  file: package.json
@@ -15,6 +15,95 @@ All notable changes to this project will be documented in this file.
15
15
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
16
16
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
17
17
 
18
+ ## 2.10.0 - 2026-10-22
19
+
20
+ ### 🚀 Features
21
+
22
+ * *(js/ts)* Support System.Diagnostics.Stopwatch (#5100) ([eb68225f](https://github.com/fable-compiler/Fable/commit/eb68225ff74d1b455765d99998faa6fd3be32383))
23
+
24
+ ### 🐞 Bug Fixes
25
+
26
+ * *(js/ts)* Round decimals below 0.1 correctly ([fca4c408](https://github.com/fable-compiler/Fable/commit/fca4c408a64e33c58293f12869975e5b61bcb96a))
27
+ * *(js/ts)* Keep decimal zero scale without leading zeros ([3076b45a](https://github.com/fable-compiler/Fable/commit/3076b45acacf39b8c99ec57025560ad355ab74db))
28
+ * *(js/ts)* Hash decimals by value in collections ([32a69e0d](https://github.com/fable-compiler/Fable/commit/32a69e0d00f567c9a838307e9ed51b3b1d519473))
29
+ * *(js/ts)* Keep .NET decimal scale through arithmetic (#5126) ([bdf0a6c8](https://github.com/fable-compiler/Fable/commit/bdf0a6c8cb56151a5431b5e3703f7ee165b26dba))
30
+ * *(js/ts)* Accept decimal integers up to 2^96 ([c9feb339](https://github.com/fable-compiler/Fable/commit/c9feb339fb8a4e98bebf17b3facdc42ecd22d628))
31
+ * *(js/ts)* Align decimal conversion, parsing and G format ([6430cdac](https://github.com/fable-compiler/Fable/commit/6430cdacec34e6327434af649eb0c9427d65608c))
32
+ * *(js/ts)* Add missing Async and Task members, cancel timed-out StartChild, bind Async in task { } (#5097) ([d063630d](https://github.com/fable-compiler/Fable/commit/d063630d58d62db21603d45a6bf54b172378c66e))
33
+ * *(js/ts)* Respect maxDegreeOfParallelism and cancel on failure in Async.Parallel (#5098) ([5de3271d](https://github.com/fable-compiler/Fable/commit/5de3271d8b47f1752c4e74c010e4314cf40bbcbe))
34
+
35
+ <strong><small>[View changes on Github](https://github.com/fable-compiler/Fable/compare/e33c57870454fea189a3eb33519f583a5003f8c3..2098f64a25e96385306ef19ed8c289f3b6c84db9)</small></strong>
36
+
37
+ ## 2.9.0 - 2026-10-16
38
+
39
+ ### 🚀 Features
40
+
41
+ * *(js/ts/python/beam)* Support Async.TryCancelled (#5083) ([1643297d](https://github.com/fable-compiler/Fable/commit/1643297d9297fef536c8d10091d5b0d1fad77af7))
42
+
43
+ ### 🐞 Bug Fixes
44
+
45
+ * *(js/ts)* Avoid full array copy in Encoding.GetString (#5069) ([e6b72ec7](https://github.com/fable-compiler/Fable/commit/e6b72ec73be454bd3b3233167542a65fc6553c8a))
46
+ * *(js/ts/python)* Preserve cancelled cleanup and generic unit callbacks (#5062) ([5dd6b497](https://github.com/fable-compiler/Fable/commit/5dd6b4979e79c8f7c4632cbfb5254d6cf0d2e8d2))
47
+
48
+ <strong><small>[View changes on Github](https://github.com/fable-compiler/Fable/compare/148f989e1b37b3f6560c3dda615b6a3a8efffcb8..e33c57870454fea189a3eb33519f583a5003f8c3)</small></strong>
49
+
50
+ ## 2.8.1 - 2026-10-12
51
+
52
+ ### 🐞 Bug Fixes
53
+
54
+ * *(js/ts/python)* Synchronize cancellation registrations (#5036) ([07db576c](https://github.com/fable-compiler/Fable/commit/07db576c4ae16dcef9d1773ac4d6c70b2a223f0a))
55
+ * *(js/ts/python)* Settle cancelled delays and finalizers once (#5038) ([a9802484](https://github.com/fable-compiler/Fable/commit/a9802484c8cdeadd5203123d76f42e375c1c3159))
56
+
57
+ <strong><small>[View changes on Github](https://github.com/fable-compiler/Fable/compare/2369fbd24fafe851544c1ed6eb54f0bfc2b75f36..148f989e1b37b3f6560c3dda615b6a3a8efffcb8)</small></strong>
58
+
59
+ ## 2.8.0 - 2026-09-25
60
+
61
+ ### 🐞 Bug Fixes
62
+
63
+ * *(js/ts)* Fix Dictionary.Remove and HashSet.Remove to remove empty buckets (#4985) ([aea61b56](https://github.com/fable-compiler/Fable/commit/aea61b562c461a9b383e805f06f68a3b21ed45c2))
64
+ * *(js/ts)* Clear custom System.Collections.IList implementations ([2369fbd2](https://github.com/fable-compiler/Fable/commit/2369fbd24fafe851544c1ed6eb54f0bfc2b75f36))
65
+
66
+ ### ⚡ Performance Improvements
67
+
68
+ * *(js/ts)* Faster `resizeArray.Clear()` in JS/TS ([32d85add](https://github.com/fable-compiler/Fable/commit/32d85add01422547dba03b15e0a0787d8afb031b))
69
+
70
+ <strong><small>[View changes on Github](https://github.com/fable-compiler/Fable/compare/4a441b1926387a42db6a3a4294acd97b02760ca3..2369fbd24fafe851544c1ed6eb54f0bfc2b75f36)</small></strong>
71
+
72
+ ## 2.7.1 - 2026-09-11
73
+
74
+ ### 🐞 Bug Fixes
75
+
76
+ * *(js/ts)* Keep the sign of negative decimals below 0.1 ([91d80f18](https://github.com/fable-compiler/Fable/commit/91d80f185fb38e4d23fd9e906037a14daab3e3b9))
77
+ * *(js/ts)* Respect the precision when formatting decimals below 0.1 ([1c02557e](https://github.com/fable-compiler/Fable/commit/1c02557efd113d8d30a922c74c3fc9d1e7168cfd))
78
+ * *(js/ts)* Omit the decimal sign when the rounded result is zero ([ef63087d](https://github.com/fable-compiler/Fable/commit/ef63087d97b61927763023c4b2e5bb16bcd64af2))
79
+
80
+ <strong><small>[View changes on Github](https://github.com/fable-compiler/Fable/compare/c49d1ec5d1a491bfff65fe4bd6c71014cac9b321..4a441b1926387a42db6a3a4294acd97b02760ca3)</small></strong>
81
+
82
+ ## 2.7.0 - 2026-09-08
83
+
84
+ ### 🚀 Features
85
+
86
+ * Add Temporal dates and times (opt-in) (#4759) ([3e8f56f7](https://github.com/fable-compiler/Fable/commit/3e8f56f78345fbee8a4394c5452eb212264701f9))
87
+
88
+ ### 🐞 Bug Fixes
89
+
90
+ * *(js/ts)* Match .NET for G, E and custom numeric formats ([6fb03090](https://github.com/fable-compiler/Fable/commit/6fb03090ce328b8c5d6a36422f120dd641aefe3a))
91
+ * *(js/ts)* Allow the E format specifier on Int64 and UInt64 ([c49d1ec5](https://github.com/fable-compiler/Fable/commit/c49d1ec5d1a491bfff65fe4bd6c71014cac9b321))
92
+
93
+ <strong><small>[View changes on Github](https://github.com/fable-compiler/Fable/compare/bf694309ae5dbc6bb546d9acc4d091f5e35fe330..c49d1ec5d1a491bfff65fe4bd6c71014cac9b321)</small></strong>
94
+
95
+ ## 2.6.0 - 2026-09-03
96
+
97
+ ### 🚀 Features
98
+
99
+ * *(all)* Quotations: DerivedPatterns, and captured locals as Value nodes (#4919) ([fae5093f](https://github.com/fable-compiler/Fable/commit/fae5093f2801195e865adf1acfaec63f38bbf973))
100
+
101
+ ### 🐞 Bug Fixes
102
+
103
+ * *(all)* Emit instance calls for virtual methods inherited from Object (#4926) ([2fb535a7](https://github.com/fable-compiler/Fable/commit/2fb535a7cd35cef501c56684f205e2dffa3c36e6))
104
+
105
+ <strong><small>[View changes on Github](https://github.com/fable-compiler/Fable/compare/619d7afddbaf25108e819abaaa9d8a6503c457d6..bf694309ae5dbc6bb546d9acc4d091f5e35fe330)</small></strong>
106
+
18
107
  ## 2.5.1 - 2026-07-24
19
108
 
20
109
  ### 🐞 Bug Fixes