@fable-org/fable-library-ts 2.1.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Array.ts +33 -33
- package/Async.ts +18 -0
- package/CHANGELOG.md +25 -1
- package/List.ts +16 -16
- package/Reflection.ts +21 -4
- package/Seq.ts +20 -20
- package/String.ts +26 -0
- package/System.ts +17 -9
- package/Task.ts +37 -0
- package/TaskBuilder.ts +85 -0
- package/Util.ts +7 -1
- package/package.json +1 -1
package/Array.ts
CHANGED
|
@@ -47,7 +47,7 @@ export function getSubArray<T>(array: MutableArray<T>, start: int32, count: int3
|
|
|
47
47
|
|
|
48
48
|
export function last<T>(array: MutableArray<T>): T {
|
|
49
49
|
if (array.length === 0) {
|
|
50
|
-
throw new Exception("The input array was empty
|
|
50
|
+
throw new Exception("The input array was empty (Parameter \'array\')");
|
|
51
51
|
}
|
|
52
52
|
return item_2(array.length - 1, array);
|
|
53
53
|
}
|
|
@@ -246,7 +246,7 @@ export function singleton<T>(value: T, cons?: any): MutableArray<T> {
|
|
|
246
246
|
|
|
247
247
|
export function initialize<T>(count: int32, initializer: ((arg0: int32) => T), cons?: any): MutableArray<T> {
|
|
248
248
|
if (count < 0) {
|
|
249
|
-
throw new Exception("The input must be non-negative
|
|
249
|
+
throw new Exception("The input must be non-negative (Parameter \'count\')");
|
|
250
250
|
}
|
|
251
251
|
const result: MutableArray<T> = Helpers_allocateArrayFromCons<T>(cons, count);
|
|
252
252
|
for (let i = 0; i <= (count - 1); i++) {
|
|
@@ -271,7 +271,7 @@ export function pairwise<T>(array: MutableArray<T>): MutableArray<[T, T]> {
|
|
|
271
271
|
|
|
272
272
|
export function replicate<T>(count: int32, initial: T, cons?: any): MutableArray<T> {
|
|
273
273
|
if (count < 0) {
|
|
274
|
-
throw new Exception("The input must be non-negative
|
|
274
|
+
throw new Exception("The input must be non-negative (Parameter \'count\')");
|
|
275
275
|
}
|
|
276
276
|
const result: MutableArray<T> = Helpers_allocateArrayFromCons<T>(cons, count);
|
|
277
277
|
for (let i = 0; i <= (result.length - 1); i++) {
|
|
@@ -313,7 +313,7 @@ export function scanBack<T, State>(folder: ((arg0: T, arg1: State) => State), ar
|
|
|
313
313
|
|
|
314
314
|
export function skip<T>(count: int32, array: MutableArray<T>, cons?: any): MutableArray<T> {
|
|
315
315
|
if (count > array.length) {
|
|
316
|
-
throw new Exception("count is greater than array length
|
|
316
|
+
throw new Exception("count is greater than array length (Parameter \'count\')");
|
|
317
317
|
}
|
|
318
318
|
if (count === array.length) {
|
|
319
319
|
return Helpers_allocateArrayFromCons<T>(cons, 0);
|
|
@@ -340,10 +340,10 @@ export function skipWhile<T>(predicate: ((arg0: T) => boolean), array: MutableAr
|
|
|
340
340
|
|
|
341
341
|
export function take<T>(count: int32, array: MutableArray<T>, cons?: any): MutableArray<T> {
|
|
342
342
|
if (count < 0) {
|
|
343
|
-
throw new Exception("The input must be non-negative
|
|
343
|
+
throw new Exception("The input must be non-negative (Parameter \'count\')");
|
|
344
344
|
}
|
|
345
345
|
if (count > array.length) {
|
|
346
|
-
throw new Exception("count is greater than array length
|
|
346
|
+
throw new Exception("count is greater than array length (Parameter \'count\')");
|
|
347
347
|
}
|
|
348
348
|
if (count === 0) {
|
|
349
349
|
return Helpers_allocateArrayFromCons<T>(cons, 0);
|
|
@@ -854,7 +854,7 @@ export function zip3<T, U, V>(array1: MutableArray<T>, array2: MutableArray<U>,
|
|
|
854
854
|
|
|
855
855
|
export function chunkBySize<T>(chunkSize: int32, array: MutableArray<T>): MutableArray<MutableArray<T>> {
|
|
856
856
|
if (chunkSize < 1) {
|
|
857
|
-
throw new Exception("The input must be positive
|
|
857
|
+
throw new Exception("The input must be positive. (Parameter \'size\')");
|
|
858
858
|
}
|
|
859
859
|
const result: MutableArray<T>[] = [];
|
|
860
860
|
if (array.length > 0) {
|
|
@@ -871,7 +871,7 @@ export function chunkBySize<T>(chunkSize: int32, array: MutableArray<T>): Mutabl
|
|
|
871
871
|
|
|
872
872
|
export function splitAt<T>(index: int32, array: MutableArray<T>): [MutableArray<T>, MutableArray<T>] {
|
|
873
873
|
if ((index < 0) ? true : (index > array.length)) {
|
|
874
|
-
throw new Exception(
|
|
874
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
875
875
|
}
|
|
876
876
|
return [array.slice(0, (0 + index)), array.slice(index)] as [MutableArray<T>, MutableArray<T>];
|
|
877
877
|
}
|
|
@@ -984,9 +984,9 @@ export function exactlyOne<T>(array: MutableArray<T>): T {
|
|
|
984
984
|
case 1:
|
|
985
985
|
return item_2(0, array);
|
|
986
986
|
case 0:
|
|
987
|
-
throw new Exception("The input sequence was empty
|
|
987
|
+
throw new Exception("The input sequence was empty (Parameter \'array\')");
|
|
988
988
|
default:
|
|
989
|
-
throw new Exception("Input array too long
|
|
989
|
+
throw new Exception("Input array too long (Parameter \'array\')");
|
|
990
990
|
}
|
|
991
991
|
}
|
|
992
992
|
|
|
@@ -1001,7 +1001,7 @@ export function tryExactlyOne<T>(array: MutableArray<T>): Option<T> {
|
|
|
1001
1001
|
|
|
1002
1002
|
export function head<T>(array: MutableArray<T>): T {
|
|
1003
1003
|
if (array.length === 0) {
|
|
1004
|
-
throw new Exception("The input array was empty
|
|
1004
|
+
throw new Exception("The input array was empty (Parameter \'array\')");
|
|
1005
1005
|
}
|
|
1006
1006
|
else {
|
|
1007
1007
|
return item_2(0, array);
|
|
@@ -1019,14 +1019,14 @@ export function tryHead<T>(array: MutableArray<T>): Option<T> {
|
|
|
1019
1019
|
|
|
1020
1020
|
export function tail<T>(array: MutableArray<T>): MutableArray<T> {
|
|
1021
1021
|
if (array.length === 0) {
|
|
1022
|
-
throw new Exception("Not enough elements
|
|
1022
|
+
throw new Exception("Not enough elements (Parameter \'array\')");
|
|
1023
1023
|
}
|
|
1024
1024
|
return array.slice(1);
|
|
1025
1025
|
}
|
|
1026
1026
|
|
|
1027
1027
|
export function item<T>(index: int32, array: MutableArray<T>): T {
|
|
1028
1028
|
if ((index < 0) ? true : (index >= array.length)) {
|
|
1029
|
-
throw new Exception("Index was outside the bounds of the array
|
|
1029
|
+
throw new Exception("Index was outside the bounds of the array. (Parameter \'index\')");
|
|
1030
1030
|
}
|
|
1031
1031
|
else {
|
|
1032
1032
|
return array[index];
|
|
@@ -1035,7 +1035,7 @@ export function item<T>(index: int32, array: MutableArray<T>): T {
|
|
|
1035
1035
|
|
|
1036
1036
|
export function setItem<T>(array: MutableArray<T>, index: int32, value: T): void {
|
|
1037
1037
|
if ((index < 0) ? true : (index >= array.length)) {
|
|
1038
|
-
throw new Exception("Index was outside the bounds of the array
|
|
1038
|
+
throw new Exception("Index was outside the bounds of the array. (Parameter \'index\')");
|
|
1039
1039
|
}
|
|
1040
1040
|
else {
|
|
1041
1041
|
array[index] = value;
|
|
@@ -1196,7 +1196,7 @@ export function min<a>(xs: MutableArray<a>, comparer: IComparer<a>): a {
|
|
|
1196
1196
|
|
|
1197
1197
|
export function average<T>(array: MutableArray<T>, averager: any): T {
|
|
1198
1198
|
if (array.length === 0) {
|
|
1199
|
-
throw new Exception("The input array was empty
|
|
1199
|
+
throw new Exception("The input array was empty (Parameter \'array\')");
|
|
1200
1200
|
}
|
|
1201
1201
|
let total: T = averager.GetZero();
|
|
1202
1202
|
for (let i = 0; i <= (array.length - 1); i++) {
|
|
@@ -1207,7 +1207,7 @@ export function average<T>(array: MutableArray<T>, averager: any): T {
|
|
|
1207
1207
|
|
|
1208
1208
|
export function averageBy<T, T2>(projection: ((arg0: T) => T2), array: MutableArray<T>, averager: any): T2 {
|
|
1209
1209
|
if (array.length === 0) {
|
|
1210
|
-
throw new Exception("The input array was empty
|
|
1210
|
+
throw new Exception("The input array was empty (Parameter \'array\')");
|
|
1211
1211
|
}
|
|
1212
1212
|
let total: T2 = averager.GetZero();
|
|
1213
1213
|
for (let i = 0; i <= (array.length - 1); i++) {
|
|
@@ -1231,7 +1231,7 @@ export function windowed<T>(windowSize: int32, source: MutableArray<T>): Mutable
|
|
|
1231
1231
|
|
|
1232
1232
|
export function splitInto<T>(chunks: int32, array: MutableArray<T>): MutableArray<MutableArray<T>> {
|
|
1233
1233
|
if (chunks < 1) {
|
|
1234
|
-
throw new Exception("The input must be positive
|
|
1234
|
+
throw new Exception("The input must be positive. (Parameter \'chunks\')");
|
|
1235
1235
|
}
|
|
1236
1236
|
const result: MutableArray<T>[] = [];
|
|
1237
1237
|
if (array.length > 0) {
|
|
@@ -1275,7 +1275,7 @@ export function transpose<T>(arrays: Iterable<MutableArray<T>>, cons?: any): Mut
|
|
|
1275
1275
|
export function insertAt<T>(index: int32, y: T, xs: MutableArray<T>, cons?: any): MutableArray<T> {
|
|
1276
1276
|
const len: int32 = xs.length | 0;
|
|
1277
1277
|
if ((index < 0) ? true : (index > len)) {
|
|
1278
|
-
throw new Exception(
|
|
1278
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1279
1279
|
}
|
|
1280
1280
|
const target: MutableArray<T> = Helpers_allocateArrayFromCons<T>(cons, len + 1);
|
|
1281
1281
|
for (let i = 0; i <= (index - 1); i++) {
|
|
@@ -1291,7 +1291,7 @@ export function insertAt<T>(index: int32, y: T, xs: MutableArray<T>, cons?: any)
|
|
|
1291
1291
|
export function insertManyAt<T>(index: int32, ys: Iterable<T>, xs: MutableArray<T>, cons?: any): MutableArray<T> {
|
|
1292
1292
|
const len: int32 = xs.length | 0;
|
|
1293
1293
|
if ((index < 0) ? true : (index > len)) {
|
|
1294
|
-
throw new Exception(
|
|
1294
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1295
1295
|
}
|
|
1296
1296
|
const ys_1: MutableArray<T> = Array.from(ys);
|
|
1297
1297
|
const len2: int32 = ys_1.length | 0;
|
|
@@ -1313,7 +1313,7 @@ export function randomShuffleInPlaceBy<T>(randomizer: (() => float64), xs: Mutab
|
|
|
1313
1313
|
for (let i: int32 = len - 1; i >= 1; i--) {
|
|
1314
1314
|
const r: float64 = randomizer();
|
|
1315
1315
|
if ((r < 0) ? true : (r >= 1)) {
|
|
1316
|
-
throw new Exception(
|
|
1316
|
+
throw new Exception(SR_Arg_ArgumentOutOfRangeException + " (Parameter \'randomizer\')");
|
|
1317
1317
|
}
|
|
1318
1318
|
const j: int32 = ~~(r * (i + 1)) | 0;
|
|
1319
1319
|
const tmp: T = item_2(i, xs);
|
|
@@ -1346,12 +1346,12 @@ export function randomShuffle<T>(xs: MutableArray<T>): MutableArray<T> {
|
|
|
1346
1346
|
|
|
1347
1347
|
export function randomChoiceBy<T>(randomizer: (() => float64), xs: MutableArray<T>): T {
|
|
1348
1348
|
if (isEmpty<T>(xs)) {
|
|
1349
|
-
throw new Exception(
|
|
1349
|
+
throw new Exception(SR_inputSequenceEmpty + " (Parameter \'source\')");
|
|
1350
1350
|
}
|
|
1351
1351
|
const len: int32 = xs.length | 0;
|
|
1352
1352
|
const r: float64 = randomizer();
|
|
1353
1353
|
if ((r < 0) ? true : (r >= 1)) {
|
|
1354
|
-
throw new Exception(
|
|
1354
|
+
throw new Exception(SR_Arg_ArgumentOutOfRangeException + " (Parameter \'randomizer\')");
|
|
1355
1355
|
}
|
|
1356
1356
|
return item_2(~~(r * len), xs);
|
|
1357
1357
|
}
|
|
@@ -1366,16 +1366,16 @@ export function randomChoice<T>(xs: MutableArray<T>): T {
|
|
|
1366
1366
|
|
|
1367
1367
|
export function randomChoicesBy<T>(randomizer: (() => float64), count: int32, xs: MutableArray<T>, cons?: any): MutableArray<T> {
|
|
1368
1368
|
if (count < 0) {
|
|
1369
|
-
throw new Exception(
|
|
1369
|
+
throw new Exception(SR_inputMustBeNonNegative + " (Parameter \'count\')");
|
|
1370
1370
|
}
|
|
1371
1371
|
if ((count > 0) && isEmpty<T>(xs)) {
|
|
1372
|
-
throw new Exception(
|
|
1372
|
+
throw new Exception(SR_inputSequenceEmpty + " (Parameter \'source\')");
|
|
1373
1373
|
}
|
|
1374
1374
|
const len: int32 = xs.length | 0;
|
|
1375
1375
|
return initialize<T>(count, (_arg: int32): T => {
|
|
1376
1376
|
const r: float64 = randomizer();
|
|
1377
1377
|
if ((r < 0) ? true : (r >= 1)) {
|
|
1378
|
-
throw new Exception(
|
|
1378
|
+
throw new Exception(SR_Arg_ArgumentOutOfRangeException + " (Parameter \'randomizer\')");
|
|
1379
1379
|
}
|
|
1380
1380
|
return item_2(~~(r * len), xs);
|
|
1381
1381
|
}, cons);
|
|
@@ -1391,20 +1391,20 @@ export function randomChoices<T>(count: int32, xs: MutableArray<T>, cons?: any):
|
|
|
1391
1391
|
|
|
1392
1392
|
export function randomSampleBy<T>(randomizer: (() => float64), count: int32, xs: MutableArray<T>): MutableArray<T> {
|
|
1393
1393
|
if (count < 0) {
|
|
1394
|
-
throw new Exception(
|
|
1394
|
+
throw new Exception(SR_inputMustBeNonNegative + " (Parameter \'count\')");
|
|
1395
1395
|
}
|
|
1396
1396
|
const arr: MutableArray<T> = copy<T>(xs);
|
|
1397
1397
|
const len: int32 = arr.length | 0;
|
|
1398
1398
|
if ((len === 0) && (count > 0)) {
|
|
1399
|
-
throw new Exception(
|
|
1399
|
+
throw new Exception(SR_inputSequenceEmpty + " (Parameter \'source\')");
|
|
1400
1400
|
}
|
|
1401
1401
|
if (count > len) {
|
|
1402
|
-
throw new Exception(
|
|
1402
|
+
throw new Exception(SR_notEnoughElements + " (Parameter \'count\')");
|
|
1403
1403
|
}
|
|
1404
1404
|
for (let i = 0; i <= (count - 1); i++) {
|
|
1405
1405
|
const r: float64 = randomizer();
|
|
1406
1406
|
if ((r < 0) ? true : (r >= 1)) {
|
|
1407
|
-
throw new Exception(
|
|
1407
|
+
throw new Exception(SR_Arg_ArgumentOutOfRangeException + " (Parameter \'randomizer\')");
|
|
1408
1408
|
}
|
|
1409
1409
|
const j: int32 = (i + ~~(r * (len - i))) | 0;
|
|
1410
1410
|
const tmp: T = item_2(i, arr);
|
|
@@ -1424,7 +1424,7 @@ export function randomSample<T>(count: int32, xs: MutableArray<T>): MutableArray
|
|
|
1424
1424
|
|
|
1425
1425
|
export function removeAt<T>(index: int32, xs: MutableArray<T>): MutableArray<T> {
|
|
1426
1426
|
if ((index < 0) ? true : (index >= xs.length)) {
|
|
1427
|
-
throw new Exception(
|
|
1427
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1428
1428
|
}
|
|
1429
1429
|
let i = -1;
|
|
1430
1430
|
return filter<T>((_arg: T): boolean => {
|
|
@@ -1457,7 +1457,7 @@ export function removeManyAt<T>(index: int32, count: int32, xs: MutableArray<T>)
|
|
|
1457
1457
|
}, xs);
|
|
1458
1458
|
const status_1: int32 = (((status === 0) && ((i + 1) === (index + count))) ? 1 : status) | 0;
|
|
1459
1459
|
if (status_1 < 1) {
|
|
1460
|
-
throw new Exception(
|
|
1460
|
+
throw new Exception(SR_indexOutOfBounds + ((" (Parameter \'" + ((status_1 < 0) ? "index" : "count")) + "\')"));
|
|
1461
1461
|
}
|
|
1462
1462
|
return ys;
|
|
1463
1463
|
}
|
|
@@ -1465,7 +1465,7 @@ export function removeManyAt<T>(index: int32, count: int32, xs: MutableArray<T>)
|
|
|
1465
1465
|
export function updateAt<T>(index: int32, y: T, xs: MutableArray<T>, cons?: any): MutableArray<T> {
|
|
1466
1466
|
const len: int32 = xs.length | 0;
|
|
1467
1467
|
if ((index < 0) ? true : (index >= len)) {
|
|
1468
|
-
throw new Exception(
|
|
1468
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1469
1469
|
}
|
|
1470
1470
|
const target: MutableArray<T> = Helpers_allocateArrayFromCons<T>(cons, len);
|
|
1471
1471
|
for (let i = 0; i <= (len - 1); i++) {
|
|
@@ -1477,7 +1477,7 @@ export function updateAt<T>(index: int32, y: T, xs: MutableArray<T>, cons?: any)
|
|
|
1477
1477
|
export function resize<T>(xs: FSharpRef<MutableArray<T>>, newSize: int32, zero?: Option<T>, cons?: any): void {
|
|
1478
1478
|
let array: MutableArray<T> = (undefined as any), array_1: MutableArray<T> = (undefined as any), start_2: int32 = (undefined as any), count_2: int32 = (undefined as any);
|
|
1479
1479
|
if (newSize < 0) {
|
|
1480
|
-
throw new Exception("The input must be non-negative
|
|
1480
|
+
throw new Exception("The input must be non-negative. (Parameter \'newSize\')");
|
|
1481
1481
|
}
|
|
1482
1482
|
const zero_1: T = defaultArg<T>(zero, defaultOf());
|
|
1483
1483
|
if (Operators_IsNull<any>(xs.contents)) {
|
package/Async.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { OperationCanceledException, Trampoline } from "./AsyncBuilder.ts";
|
|
|
2
2
|
import { Continuation, Continuations } from "./AsyncBuilder.ts";
|
|
3
3
|
import { Async, IAsyncContext, CancellationToken } from "./AsyncBuilder.ts";
|
|
4
4
|
import { protectedCont, protectedBind, protectedReturn } from "./AsyncBuilder.ts";
|
|
5
|
+
import type { IEvent$2 } from "./Event.ts";
|
|
5
6
|
import { FSharpChoice$2_$union, Choice_makeChoice1Of2, Choice_makeChoice2Of2 } from "./Choice.ts";
|
|
6
7
|
import { TimeoutException_$ctor } from "./System.ts";
|
|
7
8
|
import { Exception } from "./Util.ts";
|
|
@@ -86,6 +87,23 @@ export function awaitPromise<T>(p: Promise<T>) {
|
|
|
86
87
|
? conts[2] : conts[1])(err)));
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
export function awaitEvent<Del extends Function, T>(event: IEvent$2<Del, T>, cancelAction?: () => void): Async<T> {
|
|
91
|
+
return protectedCont((ctx: IAsyncContext<T>) => {
|
|
92
|
+
let tokenId: number;
|
|
93
|
+
const handler = ((_sender: unknown, arg: T) => {
|
|
94
|
+
ctx.cancelToken.removeListener(tokenId);
|
|
95
|
+
event.RemoveHandler(handler as unknown as Del);
|
|
96
|
+
ctx.onSuccess(arg);
|
|
97
|
+
}) as unknown as Del;
|
|
98
|
+
tokenId = ctx.cancelToken.addListener(() => {
|
|
99
|
+
event.RemoveHandler(handler);
|
|
100
|
+
if (cancelAction != null) { cancelAction(); }
|
|
101
|
+
ctx.onCancel(new OperationCanceledException());
|
|
102
|
+
});
|
|
103
|
+
event.AddHandler(handler);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
89
107
|
export function cancellationToken() {
|
|
90
108
|
return protectedCont((ctx: IAsyncContext<CancellationToken>) => ctx.onSuccess(ctx.cancelToken));
|
|
91
109
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
last_commit_released:
|
|
2
|
+
last_commit_released: c977d78b39225a51c7bd051a1fe363ed0ccbe201
|
|
3
3
|
updaters:
|
|
4
4
|
- package.json:
|
|
5
5
|
file: package.json
|
|
@@ -15,6 +15,30 @@ 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.3.0 - 2026-06-30
|
|
19
|
+
|
|
20
|
+
### 🚀 Features
|
|
21
|
+
|
|
22
|
+
* *(js/ts)* Map task { } to Promise<T> ([97f54d36](https://github.com/fable-compiler/Fable/commit/97f54d3692e5ba881c249b289c20b4fad5ac27e2))
|
|
23
|
+
* *(js/ts/python/beam)* Add support for `Async.AwaitEvent` (#4693) ([71c98179](https://github.com/fable-compiler/Fable/commit/71c981792b6ff99cd417bb2e70a13a9d55ed72cf))
|
|
24
|
+
|
|
25
|
+
### 🐞 Bug Fixes
|
|
26
|
+
|
|
27
|
+
* *(js)* Respect StringComparison in String.IndexOf/LastIndexOf (#4681) ([7cb92d52](https://github.com/fable-compiler/Fable/commit/7cb92d522e5dc8dfe51351565504c59a94c2f408))
|
|
28
|
+
* *(js/ts)* Int list is not a union type (#4698) ([ecbecbe7](https://github.com/fable-compiler/Fable/commit/ecbecbe756610fd83a621c005e97eda92bbc332a))
|
|
29
|
+
* *(js/ts)* Pass TypeInfo to getRecordFields to handle None fields in anonymous records (#4704) ([c977d78b](https://github.com/fable-compiler/Fable/commit/c977d78b39225a51c7bd051a1fe363ed0ccbe201))
|
|
30
|
+
* *(ts)* Widen isEnumDefined value parameter to accept any value (#4690) ([0d6498dd](https://github.com/fable-compiler/Fable/commit/0d6498ddf65e0e18918690633da23b04b78479f6))
|
|
31
|
+
|
|
32
|
+
<strong><small>[View changes on Github](https://github.com/fable-compiler/Fable/compare/c9b3ee2429a4688946c1936e27df730837428070..c977d78b39225a51c7bd051a1fe363ed0ccbe201)</small></strong>
|
|
33
|
+
|
|
34
|
+
## 2.2.0 - 2026-06-24
|
|
35
|
+
|
|
36
|
+
### 🚀 Features
|
|
37
|
+
|
|
38
|
+
* *(all)* Support Exception.InnerException across all targets (#4677) ([c9b3ee24](https://github.com/fable-compiler/Fable/commit/c9b3ee2429a4688946c1936e27df730837428070))
|
|
39
|
+
|
|
40
|
+
<strong><small>[View changes on Github](https://github.com/fable-compiler/Fable/compare/15eb83ed36657f75073fb0e1b4cac677e24fc9bb..c9b3ee2429a4688946c1936e27df730837428070)</small></strong>
|
|
41
|
+
|
|
18
42
|
## 2.1.1 - 2026-06-10
|
|
19
43
|
|
|
20
44
|
### 🐞 Bug Fixes
|
package/List.ts
CHANGED
|
@@ -243,7 +243,7 @@ export function FSharpList__get_Head<T>(xs: FSharpList<T>): T {
|
|
|
243
243
|
return xs.head;
|
|
244
244
|
}
|
|
245
245
|
else {
|
|
246
|
-
throw new Exception(
|
|
246
|
+
throw new Exception(SR_inputWasEmpty + " (Parameter \'list\')");
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
|
@@ -253,7 +253,7 @@ export function FSharpList__get_Tail<T>(xs: FSharpList<T>): FSharpList<T> {
|
|
|
253
253
|
return value_1(matchValue);
|
|
254
254
|
}
|
|
255
255
|
else {
|
|
256
|
-
throw new Exception(
|
|
256
|
+
throw new Exception(SR_inputWasEmpty + " (Parameter \'list\')");
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
|
|
@@ -274,7 +274,7 @@ export function FSharpList__get_Item_Z524259A4<T>(xs: FSharpList<T>, index: int3
|
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
else {
|
|
277
|
-
throw new Exception(
|
|
277
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
278
278
|
}
|
|
279
279
|
break;
|
|
280
280
|
}
|
|
@@ -1026,7 +1026,7 @@ export function exists2<T1, T2>(f_mut: ((arg0: T1, arg1: T2) => boolean), xs_mut
|
|
|
1026
1026
|
continue exists2;
|
|
1027
1027
|
}
|
|
1028
1028
|
default:
|
|
1029
|
-
throw new Exception(
|
|
1029
|
+
throw new Exception(SR_differentLengths + " (Parameter \'list2\')");
|
|
1030
1030
|
}
|
|
1031
1031
|
break;
|
|
1032
1032
|
}
|
|
@@ -1143,7 +1143,7 @@ export function skip<T>(count_mut: int32, xs_mut: FSharpList<T>): FSharpList<T>
|
|
|
1143
1143
|
return xs;
|
|
1144
1144
|
}
|
|
1145
1145
|
else if (FSharpList__get_IsEmpty<T>(xs)) {
|
|
1146
|
-
throw new Exception(
|
|
1146
|
+
throw new Exception(SR_notEnoughElements + " (Parameter \'list\')");
|
|
1147
1147
|
}
|
|
1148
1148
|
else {
|
|
1149
1149
|
count_mut = (count - 1);
|
|
@@ -1175,7 +1175,7 @@ export function skipWhile<T>(predicate_mut: ((arg0: T) => boolean), xs_mut: FSha
|
|
|
1175
1175
|
|
|
1176
1176
|
export function take<T>(count: int32, xs: FSharpList<T>): FSharpList<T> {
|
|
1177
1177
|
if (count < 0) {
|
|
1178
|
-
throw new Exception(
|
|
1178
|
+
throw new Exception(SR_inputMustBeNonNegative + " (Parameter \'count\')");
|
|
1179
1179
|
}
|
|
1180
1180
|
const loop = (i_mut: int32, acc_mut: FSharpList<T>, xs_1_mut: FSharpList<T>): FSharpList<T> => {
|
|
1181
1181
|
loop:
|
|
@@ -1186,7 +1186,7 @@ export function take<T>(count: int32, xs: FSharpList<T>): FSharpList<T> {
|
|
|
1186
1186
|
return acc;
|
|
1187
1187
|
}
|
|
1188
1188
|
else if (FSharpList__get_IsEmpty<T>(xs_1)) {
|
|
1189
|
-
throw new Exception(
|
|
1189
|
+
throw new Exception(SR_notEnoughElements + " (Parameter \'list\')");
|
|
1190
1190
|
}
|
|
1191
1191
|
else {
|
|
1192
1192
|
i_mut = (i - 1);
|
|
@@ -1277,23 +1277,23 @@ export function getSlice<T>(startIndex: Option<int32>, endIndex: Option<int32>,
|
|
|
1277
1277
|
|
|
1278
1278
|
export function splitAt<T>(index: int32, xs: FSharpList<T>): [FSharpList<T>, FSharpList<T>] {
|
|
1279
1279
|
if (index < 0) {
|
|
1280
|
-
throw new Exception(
|
|
1280
|
+
throw new Exception(SR_inputMustBeNonNegative + " (Parameter \'index\')");
|
|
1281
1281
|
}
|
|
1282
1282
|
if (index > FSharpList__get_Length<T>(xs)) {
|
|
1283
|
-
throw new Exception(
|
|
1283
|
+
throw new Exception(SR_notEnoughElements + " (Parameter \'index\')");
|
|
1284
1284
|
}
|
|
1285
1285
|
return [take<T>(index, xs), skip<T>(index, xs)] as [FSharpList<T>, FSharpList<T>];
|
|
1286
1286
|
}
|
|
1287
1287
|
|
|
1288
1288
|
export function exactlyOne<T>(xs: FSharpList<T>): T {
|
|
1289
1289
|
if (FSharpList__get_IsEmpty<T>(xs)) {
|
|
1290
|
-
throw new Exception(
|
|
1290
|
+
throw new Exception(SR_inputSequenceEmpty + " (Parameter \'list\')");
|
|
1291
1291
|
}
|
|
1292
1292
|
else if (FSharpList__get_IsEmpty<T>(FSharpList__get_Tail<T>(xs))) {
|
|
1293
1293
|
return FSharpList__get_Head<T>(xs);
|
|
1294
1294
|
}
|
|
1295
1295
|
else {
|
|
1296
|
-
throw new Exception(
|
|
1296
|
+
throw new Exception(SR_inputSequenceTooLong + " (Parameter \'list\')");
|
|
1297
1297
|
}
|
|
1298
1298
|
}
|
|
1299
1299
|
|
|
@@ -1340,7 +1340,7 @@ export function insertAt<T>(index: int32, y: T, xs: FSharpList<T>): FSharpList<T
|
|
|
1340
1340
|
}
|
|
1341
1341
|
}, FSharpList_get_Empty<T>(), xs);
|
|
1342
1342
|
return reverse<T>(isDone ? result : (((i + 1) === index) ? FSharpList_Cons_305B8EAC<T>(y, result) : (() => {
|
|
1343
|
-
throw new Exception(
|
|
1343
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1344
1344
|
})()));
|
|
1345
1345
|
}
|
|
1346
1346
|
|
|
@@ -1359,7 +1359,7 @@ export function insertManyAt<T>(index: int32, ys: Iterable<T>, xs: FSharpList<T>
|
|
|
1359
1359
|
}
|
|
1360
1360
|
}, FSharpList_get_Empty<T>(), xs);
|
|
1361
1361
|
return reverse<T>(isDone ? result : (((i + 1) === index) ? append<T>(ys_1, result) : (() => {
|
|
1362
|
-
throw new Exception(
|
|
1362
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1363
1363
|
})()));
|
|
1364
1364
|
}
|
|
1365
1365
|
|
|
@@ -1377,7 +1377,7 @@ export function removeAt<T>(index: int32, xs: FSharpList<T>): FSharpList<T> {
|
|
|
1377
1377
|
}
|
|
1378
1378
|
}, xs);
|
|
1379
1379
|
if (!isDone) {
|
|
1380
|
-
throw new Exception(
|
|
1380
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1381
1381
|
}
|
|
1382
1382
|
return ys;
|
|
1383
1383
|
}
|
|
@@ -1406,7 +1406,7 @@ export function removeManyAt<T>(index: int32, count: int32, xs: FSharpList<T>):
|
|
|
1406
1406
|
}, xs);
|
|
1407
1407
|
const status_1: int32 = (((status === 0) && ((i + 1) === (index + count))) ? 1 : status) | 0;
|
|
1408
1408
|
if (status_1 < 1) {
|
|
1409
|
-
throw new Exception(
|
|
1409
|
+
throw new Exception(SR_indexOutOfBounds + ((" (Parameter \'" + ((status_1 < 0) ? "index" : "count")) + "\')"));
|
|
1410
1410
|
}
|
|
1411
1411
|
return ys;
|
|
1412
1412
|
}
|
|
@@ -1423,7 +1423,7 @@ export function updateAt<T>(index: int32, y: T, xs: FSharpList<T>): FSharpList<T
|
|
|
1423
1423
|
}
|
|
1424
1424
|
}, xs);
|
|
1425
1425
|
if (!isDone) {
|
|
1426
|
-
throw new Exception(
|
|
1426
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1427
1427
|
}
|
|
1428
1428
|
return ys;
|
|
1429
1429
|
}
|
package/Reflection.ts
CHANGED
|
@@ -171,7 +171,18 @@ export function option_type(generic: TypeInfo): TypeInfo {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
export function list_type(generic: TypeInfo): TypeInfo {
|
|
174
|
-
|
|
174
|
+
const t: TypeInfo = new TypeInfo(
|
|
175
|
+
"Microsoft.FSharp.Collections.FSharpList`1",
|
|
176
|
+
[generic],
|
|
177
|
+
undefined,
|
|
178
|
+
undefined,
|
|
179
|
+
undefined,
|
|
180
|
+
() => [
|
|
181
|
+
new CaseInfo(t, 0, "Empty"),
|
|
182
|
+
new CaseInfo(t, 1, "Cons", [["Head", generic], ["Tail", t]])
|
|
183
|
+
]
|
|
184
|
+
);
|
|
185
|
+
return t;
|
|
175
186
|
}
|
|
176
187
|
|
|
177
188
|
export function array_type(generic: TypeInfo): TypeInfo {
|
|
@@ -389,7 +400,7 @@ export function getEnumName(t: TypeInfo, v: number): string {
|
|
|
389
400
|
return getEnumCase(t, v)[0];
|
|
390
401
|
}
|
|
391
402
|
|
|
392
|
-
export function isEnumDefined(t: TypeInfo, v:
|
|
403
|
+
export function isEnumDefined(t: TypeInfo, v: any): boolean {
|
|
393
404
|
try {
|
|
394
405
|
const kv = getEnumCase(t, v);
|
|
395
406
|
return kv[0] != null && kv[0] !== "";
|
|
@@ -477,8 +488,14 @@ export function getUnionCaseFields(uci: CaseInfo): FieldInfo[] {
|
|
|
477
488
|
|
|
478
489
|
// This is used as replacement of `FSharpValue.GetRecordFields`
|
|
479
490
|
// For `FSharpTypes.GetRecordFields` see `getRecordElements`
|
|
480
|
-
//
|
|
481
|
-
|
|
491
|
+
// TypeInfo is used when available to enumerate fields by name: anonymous record None fields
|
|
492
|
+
// are omitted from the JS object, so Object.keys alone would miss them.
|
|
493
|
+
// Boxed anonymous record would are still not covered but this is the best we can do for now
|
|
494
|
+
// without adding a __fields__ to every anonymous record being created
|
|
495
|
+
export function getRecordFields(v: any, t: TypeInfo): MutableArray<any> {
|
|
496
|
+
if (t.fields != null) {
|
|
497
|
+
return t.fields().map(([key, _]) => v[key]);
|
|
498
|
+
}
|
|
482
499
|
return Object.keys(v).map((k) => v[k]);
|
|
483
500
|
}
|
|
484
501
|
|
package/Seq.ts
CHANGED
|
@@ -559,14 +559,14 @@ export function exactlyOne<T>(xs: Iterable<T>): T {
|
|
|
559
559
|
if (e["System.Collections.IEnumerator.MoveNext"]()) {
|
|
560
560
|
const v: T = e["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
561
561
|
if (e["System.Collections.IEnumerator.MoveNext"]()) {
|
|
562
|
-
throw new Exception(
|
|
562
|
+
throw new Exception(SR_inputSequenceTooLong + " (Parameter \'source\')");
|
|
563
563
|
}
|
|
564
564
|
else {
|
|
565
565
|
return v;
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
568
|
else {
|
|
569
|
-
throw new Exception(
|
|
569
|
+
throw new Exception(SR_inputSequenceEmpty + " (Parameter \'source\')");
|
|
570
570
|
}
|
|
571
571
|
}
|
|
572
572
|
finally {
|
|
@@ -764,7 +764,7 @@ export function tryHead<T>(xs: Iterable<T>): Option<T> {
|
|
|
764
764
|
export function head<T>(xs: Iterable<T>): T {
|
|
765
765
|
const matchValue: Option<T> = tryHead<T>(xs);
|
|
766
766
|
if (matchValue == null) {
|
|
767
|
-
throw new Exception(
|
|
767
|
+
throw new Exception(SR_inputSequenceEmpty + " (Parameter \'source\')");
|
|
768
768
|
}
|
|
769
769
|
else {
|
|
770
770
|
return value_1(matchValue);
|
|
@@ -836,7 +836,7 @@ export function tryItem<T>(index: int32, xs: Iterable<T>): Option<T> {
|
|
|
836
836
|
export function item<T>(index: int32, xs: Iterable<T>): T {
|
|
837
837
|
const matchValue: Option<T> = tryItem<T>(index, xs);
|
|
838
838
|
if (matchValue == null) {
|
|
839
|
-
throw new Exception(
|
|
839
|
+
throw new Exception(SR_notEnoughElements + " (Parameter \'index\')");
|
|
840
840
|
}
|
|
841
841
|
else {
|
|
842
842
|
return value_1(matchValue);
|
|
@@ -896,7 +896,7 @@ export function tryLast<T>(xs: Iterable<T>): Option<T> {
|
|
|
896
896
|
export function last<T>(xs: Iterable<T>): T {
|
|
897
897
|
const matchValue: Option<T> = tryLast<T>(xs);
|
|
898
898
|
if (matchValue == null) {
|
|
899
|
-
throw new Exception(
|
|
899
|
+
throw new Exception(SR_notEnoughElements + " (Parameter \'source\')");
|
|
900
900
|
}
|
|
901
901
|
else {
|
|
902
902
|
return value_1(matchValue);
|
|
@@ -1205,7 +1205,7 @@ export function skip<T>(count: int32, source: Iterable<T>): Iterable<T> {
|
|
|
1205
1205
|
try {
|
|
1206
1206
|
for (let _ = 1; _ <= count; _++) {
|
|
1207
1207
|
if (!e["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1208
|
-
throw new Exception(
|
|
1208
|
+
throw new Exception(SR_notEnoughElements + " (Parameter \'source\')");
|
|
1209
1209
|
}
|
|
1210
1210
|
}
|
|
1211
1211
|
return Enumerator_enumerateThenFinally<T>((): void => {
|
|
@@ -1241,7 +1241,7 @@ export function take<T>(count: int32, xs: Iterable<T>): Iterable<T> {
|
|
|
1241
1241
|
return some(e["System.Collections.Generic.IEnumerator`1.get_Current"]());
|
|
1242
1242
|
}
|
|
1243
1243
|
else {
|
|
1244
|
-
throw new Exception(
|
|
1244
|
+
throw new Exception(SR_notEnoughElements + " (Parameter \'source\')");
|
|
1245
1245
|
}
|
|
1246
1246
|
}
|
|
1247
1247
|
else {
|
|
@@ -1351,7 +1351,7 @@ export function average<T>(xs: Iterable<T>, averager: any): T {
|
|
|
1351
1351
|
return averager.Add(acc, x);
|
|
1352
1352
|
}, averager.GetZero(), xs);
|
|
1353
1353
|
if (count === 0) {
|
|
1354
|
-
throw new Exception(
|
|
1354
|
+
throw new Exception(SR_inputSequenceEmpty + " (Parameter \'source\')");
|
|
1355
1355
|
}
|
|
1356
1356
|
else {
|
|
1357
1357
|
return averager.DivideByInt(total, count);
|
|
@@ -1365,7 +1365,7 @@ export function averageBy<T, U>(f: ((arg0: T) => U), xs: Iterable<T>, averager:
|
|
|
1365
1365
|
return averager.Add(acc, f(x));
|
|
1366
1366
|
}, averager.GetZero(), xs);
|
|
1367
1367
|
if (count === 0) {
|
|
1368
|
-
throw new Exception(
|
|
1368
|
+
throw new Exception(SR_inputSequenceEmpty + " (Parameter \'source\')");
|
|
1369
1369
|
}
|
|
1370
1370
|
else {
|
|
1371
1371
|
return averager.DivideByInt(total, count);
|
|
@@ -1383,7 +1383,7 @@ export function chunkBySize<T>(chunkSize: int32, xs: Iterable<T>): Iterable<Muta
|
|
|
1383
1383
|
export function insertAt<T>(index: int32, y: T, xs: Iterable<T>): Iterable<T> {
|
|
1384
1384
|
let isDone = false;
|
|
1385
1385
|
if (index < 0) {
|
|
1386
|
-
throw new Exception(
|
|
1386
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1387
1387
|
}
|
|
1388
1388
|
return generateIndexed<IEnumerator<T>, T>((): IEnumerator<T> => ofSeq<T>(xs), (i: int32, e: IEnumerator<T>): Option<T> => {
|
|
1389
1389
|
if ((isDone ? true : (i < index)) && e["System.Collections.IEnumerator.MoveNext"]()) {
|
|
@@ -1395,7 +1395,7 @@ export function insertAt<T>(index: int32, y: T, xs: Iterable<T>): Iterable<T> {
|
|
|
1395
1395
|
}
|
|
1396
1396
|
else {
|
|
1397
1397
|
if (!isDone) {
|
|
1398
|
-
throw new Exception(
|
|
1398
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1399
1399
|
}
|
|
1400
1400
|
return undefined;
|
|
1401
1401
|
}
|
|
@@ -1407,7 +1407,7 @@ export function insertAt<T>(index: int32, y: T, xs: Iterable<T>): Iterable<T> {
|
|
|
1407
1407
|
export function insertManyAt<T>(index: int32, ys: Iterable<T>, xs: Iterable<T>): Iterable<T> {
|
|
1408
1408
|
let status = -1;
|
|
1409
1409
|
if (index < 0) {
|
|
1410
|
-
throw new Exception(
|
|
1410
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1411
1411
|
}
|
|
1412
1412
|
return generateIndexed<[IEnumerator<T>, IEnumerator<T>], T>((): [IEnumerator<T>, IEnumerator<T>] => ([ofSeq<T>(xs), ofSeq<T>(ys)] as [IEnumerator<T>, IEnumerator<T>]), (i: int32, tupledArg: [IEnumerator<T>, IEnumerator<T>]): Option<T> => {
|
|
1413
1413
|
const e1: IEnumerator<T> = tupledArg[0];
|
|
@@ -1434,7 +1434,7 @@ export function insertManyAt<T>(index: int32, ys: Iterable<T>, xs: Iterable<T>):
|
|
|
1434
1434
|
}
|
|
1435
1435
|
else {
|
|
1436
1436
|
if (status < 1) {
|
|
1437
|
-
throw new Exception(
|
|
1437
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1438
1438
|
}
|
|
1439
1439
|
return undefined;
|
|
1440
1440
|
}
|
|
@@ -1451,7 +1451,7 @@ export function insertManyAt<T>(index: int32, ys: Iterable<T>, xs: Iterable<T>):
|
|
|
1451
1451
|
export function removeAt<T>(index: int32, xs: Iterable<T>): Iterable<T> {
|
|
1452
1452
|
let isDone = false;
|
|
1453
1453
|
if (index < 0) {
|
|
1454
|
-
throw new Exception(
|
|
1454
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1455
1455
|
}
|
|
1456
1456
|
return generateIndexed<IEnumerator<T>, T>((): IEnumerator<T> => ofSeq<T>(xs), (i: int32, e: IEnumerator<T>): Option<T> => {
|
|
1457
1457
|
if ((isDone ? true : (i < index)) && e["System.Collections.IEnumerator.MoveNext"]()) {
|
|
@@ -1463,7 +1463,7 @@ export function removeAt<T>(index: int32, xs: Iterable<T>): Iterable<T> {
|
|
|
1463
1463
|
}
|
|
1464
1464
|
else {
|
|
1465
1465
|
if (!isDone) {
|
|
1466
|
-
throw new Exception(
|
|
1466
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1467
1467
|
}
|
|
1468
1468
|
return undefined;
|
|
1469
1469
|
}
|
|
@@ -1474,7 +1474,7 @@ export function removeAt<T>(index: int32, xs: Iterable<T>): Iterable<T> {
|
|
|
1474
1474
|
|
|
1475
1475
|
export function removeManyAt<T>(index: int32, count: int32, xs: Iterable<T>): Iterable<T> {
|
|
1476
1476
|
if (index < 0) {
|
|
1477
|
-
throw new Exception(
|
|
1477
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1478
1478
|
}
|
|
1479
1479
|
return generateIndexed<IEnumerator<T>, T>((): IEnumerator<T> => ofSeq<T>(xs), (i: int32, e: IEnumerator<T>): Option<T> => {
|
|
1480
1480
|
if (i < index) {
|
|
@@ -1482,14 +1482,14 @@ export function removeManyAt<T>(index: int32, count: int32, xs: Iterable<T>): It
|
|
|
1482
1482
|
return some(e["System.Collections.Generic.IEnumerator`1.get_Current"]());
|
|
1483
1483
|
}
|
|
1484
1484
|
else {
|
|
1485
|
-
throw new Exception(
|
|
1485
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1486
1486
|
}
|
|
1487
1487
|
}
|
|
1488
1488
|
else {
|
|
1489
1489
|
if (i === index) {
|
|
1490
1490
|
for (let _ = 1; _ <= count; _++) {
|
|
1491
1491
|
if (!e["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1492
|
-
throw new Exception(
|
|
1492
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'count\')");
|
|
1493
1493
|
}
|
|
1494
1494
|
}
|
|
1495
1495
|
}
|
|
@@ -1503,7 +1503,7 @@ export function removeManyAt<T>(index: int32, count: int32, xs: Iterable<T>): It
|
|
|
1503
1503
|
export function updateAt<T>(index: int32, y: T, xs: Iterable<T>): Iterable<T> {
|
|
1504
1504
|
let isDone = false;
|
|
1505
1505
|
if (index < 0) {
|
|
1506
|
-
throw new Exception(
|
|
1506
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1507
1507
|
}
|
|
1508
1508
|
return generateIndexed<IEnumerator<T>, T>((): IEnumerator<T> => ofSeq<T>(xs), (i: int32, e: IEnumerator<T>): Option<T> => {
|
|
1509
1509
|
if ((isDone ? true : (i < index)) && e["System.Collections.IEnumerator.MoveNext"]()) {
|
|
@@ -1515,7 +1515,7 @@ export function updateAt<T>(index: int32, y: T, xs: Iterable<T>): Iterable<T> {
|
|
|
1515
1515
|
}
|
|
1516
1516
|
else {
|
|
1517
1517
|
if (!isDone) {
|
|
1518
|
-
throw new Exception(
|
|
1518
|
+
throw new Exception(SR_indexOutOfBounds + " (Parameter \'index\')");
|
|
1519
1519
|
}
|
|
1520
1520
|
return undefined;
|
|
1521
1521
|
}
|
package/String.ts
CHANGED
|
@@ -99,6 +99,32 @@ export function contains(str: string, pattern: string, ic: boolean | StringCompa
|
|
|
99
99
|
return false;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
export function indexOf(str: string, searchValue: string, comparison: StringComparison, startIndex: number = 0): number {
|
|
103
|
+
if (comparison === StringComparison.Ordinal) { // fast path
|
|
104
|
+
return str.indexOf(searchValue, startIndex);
|
|
105
|
+
}
|
|
106
|
+
const len = searchValue.length;
|
|
107
|
+
for (let i = Math.max(startIndex, 0); i <= str.length - len; i++) {
|
|
108
|
+
if (cmp(str.slice(i, i + len), searchValue, comparison) === 0) {
|
|
109
|
+
return i;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return -1;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function lastIndexOf(str: string, searchValue: string, comparison: StringComparison, startIndex: number = str.length - 1): number {
|
|
116
|
+
if (comparison === StringComparison.Ordinal) { // fast path
|
|
117
|
+
return str.lastIndexOf(searchValue, startIndex);
|
|
118
|
+
}
|
|
119
|
+
const len = searchValue.length;
|
|
120
|
+
for (let i = Math.min(startIndex, str.length - len); i >= 0; i--) {
|
|
121
|
+
if (cmp(str.slice(i, i + len), searchValue, comparison) === 0) {
|
|
122
|
+
return i;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return -1;
|
|
126
|
+
}
|
|
127
|
+
|
|
102
128
|
export function indexOfAny(str: string, anyOf: string[], ...args: number[]) {
|
|
103
129
|
if (str == null || str === "") {
|
|
104
130
|
return -1;
|
package/System.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { Exception } from "./Util.ts";
|
|
2
|
+
import { defaultOf, Exception } from "./Util.ts";
|
|
3
3
|
import { class_type, TypeInfo } from "./Reflection.ts";
|
|
4
4
|
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.ts";
|
|
5
5
|
import { isNullOrEmpty } from "./String.ts";
|
|
@@ -294,8 +294,8 @@ export function TimeoutException_$ctor(): TimeoutException {
|
|
|
294
294
|
|
|
295
295
|
export class ArgumentException extends Exception {
|
|
296
296
|
readonly paramName: string;
|
|
297
|
-
constructor(message: string, paramName: string) {
|
|
298
|
-
super(isNullOrEmpty(paramName) ? message : (((message + SR_Arg_ParamName_Name) + paramName) + "\')"));
|
|
297
|
+
constructor(message: string, paramName: string, innerException: Exception) {
|
|
298
|
+
super(isNullOrEmpty(paramName) ? message : (((message + SR_Arg_ParamName_Name) + paramName) + "\')"), innerException);
|
|
299
299
|
this.paramName = paramName;
|
|
300
300
|
}
|
|
301
301
|
}
|
|
@@ -304,16 +304,24 @@ export function ArgumentException_$reflection(): TypeInfo {
|
|
|
304
304
|
return class_type("System.ArgumentException", undefined, ArgumentException, class_type("System.Exception"));
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
-
export function ArgumentException_$
|
|
308
|
-
return new ArgumentException(message, paramName);
|
|
307
|
+
export function ArgumentException_$ctor_Z60A2B367(message: string, paramName: string, innerException: Exception): ArgumentException {
|
|
308
|
+
return new ArgumentException(message, paramName, innerException);
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
export function ArgumentException_$ctor(): ArgumentException {
|
|
312
|
-
return ArgumentException_$
|
|
312
|
+
return ArgumentException_$ctor_Z60A2B367(SR_Arg_ArgumentException, "", defaultOf());
|
|
313
313
|
}
|
|
314
314
|
|
|
315
315
|
export function ArgumentException_$ctor_Z721C83C5(message: string): ArgumentException {
|
|
316
|
-
return ArgumentException_$
|
|
316
|
+
return ArgumentException_$ctor_Z60A2B367(message, "", defaultOf());
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export function ArgumentException_$ctor_Z384F8060(message: string, paramName: string): ArgumentException {
|
|
320
|
+
return ArgumentException_$ctor_Z60A2B367(message, paramName, defaultOf());
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export function ArgumentException_$ctor_68CE3CA2(message: string, innerException: Exception): ArgumentException {
|
|
324
|
+
return ArgumentException_$ctor_Z60A2B367(message, "", innerException);
|
|
317
325
|
}
|
|
318
326
|
|
|
319
327
|
export function ArgumentException__get_ParamName(_: ArgumentException): string {
|
|
@@ -322,7 +330,7 @@ export function ArgumentException__get_ParamName(_: ArgumentException): string {
|
|
|
322
330
|
|
|
323
331
|
export class ArgumentNullException extends ArgumentException {
|
|
324
332
|
constructor(paramName: string, message: string) {
|
|
325
|
-
super(message, paramName);
|
|
333
|
+
super(message, paramName, defaultOf());
|
|
326
334
|
}
|
|
327
335
|
}
|
|
328
336
|
|
|
@@ -344,7 +352,7 @@ export function ArgumentNullException_$ctor(): ArgumentNullException {
|
|
|
344
352
|
|
|
345
353
|
export class ArgumentOutOfRangeException extends ArgumentException {
|
|
346
354
|
constructor(paramName: string, message: string) {
|
|
347
|
-
super(message, paramName);
|
|
355
|
+
super(message, paramName, defaultOf());
|
|
348
356
|
}
|
|
349
357
|
}
|
|
350
358
|
|
package/Task.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { OperationCanceledException } from "./AsyncBuilder.ts";
|
|
2
|
+
|
|
3
|
+
export class TaskCompletionSource<T> {
|
|
4
|
+
private _resolve!: (value: T) => void;
|
|
5
|
+
private _reject!: (reason?: unknown) => void;
|
|
6
|
+
public task: Promise<T>;
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
this.task = new Promise<T>((resolve, reject) => {
|
|
10
|
+
this._resolve = resolve;
|
|
11
|
+
this._reject = reject;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
SetResult(value: T): void { this._resolve(value); }
|
|
16
|
+
SetException(error: unknown): void { this._reject(error); }
|
|
17
|
+
SetCancelled(): void { this._reject(new OperationCanceledException()); }
|
|
18
|
+
get_Task(): Promise<T> { return this.task; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function fromResult<T>(value: T): Promise<T> {
|
|
22
|
+
return Promise.resolve(value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function zero(): Promise<void> {
|
|
26
|
+
return Promise.resolve();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Task<T> = Promise<T> in JS/TS. GetAwaiter/GetResult return the Promise itself;
|
|
30
|
+
// callers should use Async.AwaitTask to extract the value in an async context.
|
|
31
|
+
export function getAwaiter<T>(t: Promise<T>): Promise<T> {
|
|
32
|
+
return t;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getResult<T>(t: Promise<T>): Promise<T> {
|
|
36
|
+
return t;
|
|
37
|
+
}
|
package/TaskBuilder.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { IDisposable } from "./Util.ts";
|
|
2
|
+
import { zero } from "./Task.ts";
|
|
3
|
+
|
|
4
|
+
export class TaskBuilder {
|
|
5
|
+
public Bind<T, U>(computation: Promise<T>, binder: (x: T) => Promise<U>): Promise<U> {
|
|
6
|
+
return computation.then(binder);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public Combine<T>(computation1: Promise<void>, computation2: () => Promise<T>): Promise<T> {
|
|
10
|
+
return computation1.then(computation2);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public Delay<T>(generator: () => Promise<T>): () => Promise<T> {
|
|
14
|
+
return generator;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public For<T>(sequence: Iterable<T>, body: (x: T) => Promise<void>): Promise<void> {
|
|
18
|
+
const iter = sequence[Symbol.iterator]();
|
|
19
|
+
let cur = iter.next();
|
|
20
|
+
return this.While(
|
|
21
|
+
() => !cur.done,
|
|
22
|
+
this.Delay(() => {
|
|
23
|
+
const res = body(cur.value!);
|
|
24
|
+
cur = iter.next();
|
|
25
|
+
return res;
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public Return<T>(value?: T): Promise<T | undefined> {
|
|
31
|
+
return Promise.resolve(value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public ReturnFrom<T>(computation: Promise<T>): Promise<T> {
|
|
35
|
+
return computation;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public TryFinally<T>(computation: () => Promise<T>, compensation: () => void): Promise<T> {
|
|
39
|
+
try {
|
|
40
|
+
return computation().finally(compensation);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
compensation();
|
|
43
|
+
return Promise.reject(e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public TryWith<T>(computation: () => Promise<T>, catchHandler: (e: unknown) => Promise<T>): Promise<T> {
|
|
48
|
+
try {
|
|
49
|
+
return computation().catch(catchHandler);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
try {
|
|
52
|
+
return catchHandler(e);
|
|
53
|
+
} catch (e2) {
|
|
54
|
+
return Promise.reject(e2);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public Using<T extends IDisposable, U>(resource: T, binder: (x: T) => Promise<U>): Promise<U> {
|
|
60
|
+
return this.TryFinally(() => binder(resource), () => resource.Dispose());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public While(guard: () => boolean, computation: () => Promise<void>): Promise<void> {
|
|
64
|
+
return (async () => {
|
|
65
|
+
while (guard()) {
|
|
66
|
+
await computation();
|
|
67
|
+
}
|
|
68
|
+
})();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public Zero(): Promise<void> {
|
|
72
|
+
return zero();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public Run<T>(computation: () => Promise<T>): Promise<T> {
|
|
76
|
+
try {
|
|
77
|
+
return computation();
|
|
78
|
+
} catch (e) {
|
|
79
|
+
return Promise.reject(e);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const singleton = new TaskBuilder();
|
|
85
|
+
export function task(): TaskBuilder { return singleton; }
|
package/Util.ts
CHANGED
|
@@ -80,9 +80,15 @@ export interface ICollection<T> extends IEnumerable<T> {
|
|
|
80
80
|
export class Exception {
|
|
81
81
|
public message: string;
|
|
82
82
|
public stack?: string;
|
|
83
|
+
// Typed non-nullable to match how Fable models .NET reference types: nullability
|
|
84
|
+
// annotations are erased, so consumers (and `get_InnerException`) see `Exception`.
|
|
85
|
+
// At runtime this is `undefined` when no inner exception was provided, just like
|
|
86
|
+
// a `defaultOf()` value, which is fine for code that reads `.InnerException`.
|
|
87
|
+
public innerException!: Exception;
|
|
83
88
|
|
|
84
|
-
constructor(msg?: string) {
|
|
89
|
+
constructor(msg?: string, innerException?: Exception) {
|
|
85
90
|
this.message = msg ?? "";
|
|
91
|
+
this.innerException = innerException as Exception;
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
toString() {
|
package/package.json
CHANGED