@fable-org/fable-library-ts 2.0.0-beta.3 → 2.0.0-beta.5
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 +1385 -1378
- package/Async.ts +13 -12
- package/AsyncBuilder.ts +10 -11
- package/BigInt.ts +6 -6
- package/BitConverter.ts +3 -3
- package/Boolean.ts +3 -2
- package/CHANGELOG.md +12 -0
- package/Char.ts +38 -35
- package/Choice.ts +326 -301
- package/CollectionUtil.ts +4 -4
- package/Date.ts +67 -62
- package/DateOffset.ts +48 -57
- package/DateOnly.ts +8 -8
- package/Decimal.ts +9 -9
- package/Double.ts +3 -2
- package/Encoding.ts +1 -1
- package/Event.ts +3 -3
- package/FSharp.Collections.ts +53 -34
- package/FSharp.Core.CompilerServices.ts +38 -37
- package/FSharp.Core.ts +186 -185
- package/Global.ts +80 -37
- package/Guid.ts +7 -6
- package/Int32.ts +20 -17
- package/List.ts +1429 -1417
- package/Long.ts +6 -5
- package/MailboxProcessor.ts +8 -7
- package/Map.ts +1550 -1552
- package/MapUtil.ts +5 -5
- package/MutableMap.ts +358 -345
- package/MutableSet.ts +250 -249
- package/Native.ts +19 -11
- package/Numeric.ts +1 -1
- package/Observable.ts +3 -3
- package/Option.ts +10 -4
- package/Random.ts +196 -194
- package/Range.ts +57 -56
- package/Reflection.ts +73 -40
- package/RegExp.ts +5 -3
- package/Result.ts +201 -196
- package/Seq.ts +1517 -1525
- package/Seq2.ts +130 -129
- package/Set.ts +1955 -1955
- package/String.ts +41 -38
- package/System.Collections.Generic.ts +401 -380
- package/System.Text.ts +204 -203
- package/System.ts +366 -0
- package/TimeOnly.ts +10 -10
- package/TimeSpan.ts +11 -11
- package/Timer.ts +2 -2
- package/Types.ts +1 -19
- package/Uri.ts +13 -10
- package/Util.ts +77 -21
- package/package.json +22 -22
- package/tsconfig.json +18 -5
- package/SystemException.ts +0 -7
package/Reflection.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FSharpRef, Record, Union } from "./Types.
|
|
2
|
-
import { combineHashCodes, equalArraysWith, IEquatable, stringHash } from "./Util.
|
|
3
|
-
import Decimal from "./Decimal.
|
|
1
|
+
import { FSharpRef, Record, Union } from "./Types.ts";
|
|
2
|
+
import { Exception, MutableArray, combineHashCodes, equalArraysWith, IEquatable, stringHash } from "./Util.ts";
|
|
3
|
+
import Decimal from "./Decimal.ts";
|
|
4
4
|
|
|
5
5
|
export type FieldInfo = [string, TypeInfo];
|
|
6
6
|
export type PropertyInfo = FieldInfo;
|
|
@@ -9,34 +9,67 @@ export type ParameterInfo = FieldInfo;
|
|
|
9
9
|
export type Constructor = new (...args: any[]) => any;
|
|
10
10
|
|
|
11
11
|
export class CaseInfo {
|
|
12
|
+
public declaringType: TypeInfo;
|
|
13
|
+
public tag: number;
|
|
14
|
+
public name: string;
|
|
15
|
+
public fields?: FieldInfo[];
|
|
16
|
+
|
|
12
17
|
constructor(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
declaringType: TypeInfo,
|
|
19
|
+
tag: number,
|
|
20
|
+
name: string,
|
|
21
|
+
fields?: FieldInfo[]
|
|
22
|
+
) {
|
|
23
|
+
this.declaringType = declaringType;
|
|
24
|
+
this.tag = tag;
|
|
25
|
+
this.name = name;
|
|
26
|
+
this.fields = fields;
|
|
17
27
|
}
|
|
18
28
|
}
|
|
19
29
|
|
|
20
30
|
export type EnumCase = [string, number];
|
|
21
31
|
|
|
22
32
|
export class MethodInfo {
|
|
33
|
+
public name: string;
|
|
34
|
+
public parameters: ParameterInfo[];
|
|
35
|
+
public returnType: TypeInfo;
|
|
36
|
+
|
|
23
37
|
constructor(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
38
|
+
name: string,
|
|
39
|
+
parameters: ParameterInfo[],
|
|
40
|
+
returnType: TypeInfo,
|
|
27
41
|
) {
|
|
42
|
+
this.name = name;
|
|
43
|
+
this.parameters = parameters;
|
|
44
|
+
this.returnType = returnType;
|
|
28
45
|
}
|
|
29
46
|
}
|
|
30
47
|
|
|
31
48
|
export class TypeInfo implements IEquatable<TypeInfo> {
|
|
49
|
+
public fullname: string;
|
|
50
|
+
public generics?: TypeInfo[];
|
|
51
|
+
public construct?: Constructor;
|
|
52
|
+
public parent?: TypeInfo;
|
|
53
|
+
public fields?: () => FieldInfo[];
|
|
54
|
+
public cases?: () => CaseInfo[];
|
|
55
|
+
public enumCases?: EnumCase[];
|
|
56
|
+
|
|
32
57
|
constructor(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
58
|
+
fullname: string,
|
|
59
|
+
generics?: TypeInfo[],
|
|
60
|
+
construct?: Constructor,
|
|
61
|
+
parent?: TypeInfo,
|
|
62
|
+
fields?: () => FieldInfo[],
|
|
63
|
+
cases?: () => CaseInfo[],
|
|
64
|
+
enumCases?: EnumCase[]
|
|
65
|
+
) {
|
|
66
|
+
this.fullname = fullname;
|
|
67
|
+
this.generics = generics;
|
|
68
|
+
this.construct = construct;
|
|
69
|
+
this.parent = parent;
|
|
70
|
+
this.fields = fields;
|
|
71
|
+
this.cases = cases;
|
|
72
|
+
this.enumCases = enumCases;
|
|
40
73
|
}
|
|
41
74
|
public toString() {
|
|
42
75
|
return fullName(this);
|
|
@@ -50,9 +83,9 @@ export class TypeInfo implements IEquatable<TypeInfo> {
|
|
|
50
83
|
}
|
|
51
84
|
|
|
52
85
|
export class GenericParameter extends TypeInfo {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
86
|
+
constructor(name: string) {
|
|
87
|
+
super(name);
|
|
88
|
+
}
|
|
56
89
|
}
|
|
57
90
|
|
|
58
91
|
export function getGenerics(t: TypeInfo): TypeInfo[] {
|
|
@@ -177,7 +210,7 @@ export function name(info: FieldInfo | TypeInfo | CaseInfo | MethodInfo): string
|
|
|
177
210
|
return name(elemType) + "[]";
|
|
178
211
|
} else {
|
|
179
212
|
const i = info.fullname.lastIndexOf(".");
|
|
180
|
-
return i === -1 ? info.fullname : info.fullname.
|
|
213
|
+
return i === -1 ? info.fullname : info.fullname.slice(i + 1);
|
|
181
214
|
}
|
|
182
215
|
} else {
|
|
183
216
|
return info.name;
|
|
@@ -201,7 +234,7 @@ export function namespace(t: TypeInfo): string {
|
|
|
201
234
|
return namespace(elemType);
|
|
202
235
|
} else {
|
|
203
236
|
const i = t.fullname.lastIndexOf(".");
|
|
204
|
-
return i === -1 ? "" : t.fullname.
|
|
237
|
+
return i === -1 ? "" : t.fullname.slice(0, i);
|
|
205
238
|
}
|
|
206
239
|
}
|
|
207
240
|
|
|
@@ -290,7 +323,7 @@ export function getEnumValues(t: TypeInfo): number[] {
|
|
|
290
323
|
if (isEnum(t) && t.enumCases != null) {
|
|
291
324
|
return t.enumCases.map((kv) => kv[1]);
|
|
292
325
|
} else {
|
|
293
|
-
throw new
|
|
326
|
+
throw new Exception(`${t.fullname} is not an enum type`);
|
|
294
327
|
}
|
|
295
328
|
}
|
|
296
329
|
|
|
@@ -298,7 +331,7 @@ export function getEnumNames(t: TypeInfo): string[] {
|
|
|
298
331
|
if (isEnum(t) && t.enumCases != null) {
|
|
299
332
|
return t.enumCases.map((kv) => kv[0]);
|
|
300
333
|
} else {
|
|
301
|
-
throw new
|
|
334
|
+
throw new Exception(`${t.fullname} is not an enum type`);
|
|
302
335
|
}
|
|
303
336
|
}
|
|
304
337
|
|
|
@@ -310,7 +343,7 @@ function getEnumCase(t: TypeInfo, v: number | string): EnumCase {
|
|
|
310
343
|
return kv;
|
|
311
344
|
}
|
|
312
345
|
}
|
|
313
|
-
throw new
|
|
346
|
+
throw new Exception(`'${v}' was not found in ${t.fullname}`);
|
|
314
347
|
} else {
|
|
315
348
|
for (const kv of t.enumCases) {
|
|
316
349
|
if (kv[1] === v) {
|
|
@@ -321,7 +354,7 @@ function getEnumCase(t: TypeInfo, v: number | string): EnumCase {
|
|
|
321
354
|
return ["", v];
|
|
322
355
|
}
|
|
323
356
|
} else {
|
|
324
|
-
throw new
|
|
357
|
+
throw new Exception(`${t.fullname} is not an enum type`);
|
|
325
358
|
}
|
|
326
359
|
}
|
|
327
360
|
|
|
@@ -360,7 +393,7 @@ export function getUnionCases(t: TypeInfo): CaseInfo[] {
|
|
|
360
393
|
if (t.cases != null) {
|
|
361
394
|
return t.cases();
|
|
362
395
|
} else {
|
|
363
|
-
throw new
|
|
396
|
+
throw new Exception(`${t.fullname} is not an F# union type`);
|
|
364
397
|
}
|
|
365
398
|
}
|
|
366
399
|
|
|
@@ -368,7 +401,7 @@ export function getRecordElements(t: TypeInfo): FieldInfo[] {
|
|
|
368
401
|
if (t.fields != null) {
|
|
369
402
|
return t.fields();
|
|
370
403
|
} else {
|
|
371
|
-
throw new
|
|
404
|
+
throw new Exception(`${t.fullname} is not an F# record type`);
|
|
372
405
|
}
|
|
373
406
|
}
|
|
374
407
|
|
|
@@ -376,7 +409,7 @@ export function getTupleElements(t: TypeInfo): TypeInfo[] {
|
|
|
376
409
|
if (isTuple(t) && t.generics != null) {
|
|
377
410
|
return t.generics;
|
|
378
411
|
} else {
|
|
379
|
-
throw new
|
|
412
|
+
throw new Exception(`${t.fullname} is not a tuple type`);
|
|
380
413
|
}
|
|
381
414
|
}
|
|
382
415
|
|
|
@@ -385,7 +418,7 @@ export function getFunctionElements(t: TypeInfo): [TypeInfo, TypeInfo] {
|
|
|
385
418
|
const gen = t.generics;
|
|
386
419
|
return [gen[0], gen[1]];
|
|
387
420
|
} else {
|
|
388
|
-
throw new
|
|
421
|
+
throw new Exception(`${t.fullname} is not an F# function type`);
|
|
389
422
|
}
|
|
390
423
|
}
|
|
391
424
|
|
|
@@ -412,7 +445,7 @@ export function getUnionFields(v: any, t: TypeInfo): [CaseInfo, any[]] {
|
|
|
412
445
|
const cases = getUnionCases(t);
|
|
413
446
|
const case_ = cases[v.tag];
|
|
414
447
|
if (case_ == null) {
|
|
415
|
-
throw new
|
|
448
|
+
throw new Exception(`Cannot find case ${v.name} in union type`);
|
|
416
449
|
}
|
|
417
450
|
return [case_, v.fields];
|
|
418
451
|
}
|
|
@@ -424,7 +457,7 @@ export function getUnionCaseFields(uci: CaseInfo): FieldInfo[] {
|
|
|
424
457
|
// This is used as replacement of `FSharpValue.GetRecordFields`
|
|
425
458
|
// For `FSharpTypes.GetRecordFields` see `getRecordElements`
|
|
426
459
|
// Object.keys returns keys in the order they were added to the object
|
|
427
|
-
export function getRecordFields(v: any): any
|
|
460
|
+
export function getRecordFields(v: any): MutableArray<any> {
|
|
428
461
|
return Object.keys(v).map((k) => v[k]);
|
|
429
462
|
}
|
|
430
463
|
|
|
@@ -432,7 +465,7 @@ export function getRecordField(v: any, field: FieldInfo): any {
|
|
|
432
465
|
return v[field[0]];
|
|
433
466
|
}
|
|
434
467
|
|
|
435
|
-
export function getTupleFields(v: any): any
|
|
468
|
+
export function getTupleFields(v: any): MutableArray<any> {
|
|
436
469
|
return v;
|
|
437
470
|
}
|
|
438
471
|
|
|
@@ -440,10 +473,10 @@ export function getTupleField(v: any, i: number): any {
|
|
|
440
473
|
return v[i];
|
|
441
474
|
}
|
|
442
475
|
|
|
443
|
-
export function makeUnion(uci: CaseInfo, values: any
|
|
476
|
+
export function makeUnion(uci: CaseInfo, values: MutableArray<any>): any {
|
|
444
477
|
const expectedLength = (uci.fields || []).length;
|
|
445
478
|
if (values.length !== expectedLength) {
|
|
446
|
-
throw new
|
|
479
|
+
throw new Exception(`Expected an array of length ${expectedLength} but got ${values.length}`);
|
|
447
480
|
}
|
|
448
481
|
const construct = uci.declaringType.construct;
|
|
449
482
|
if (construct == null) {
|
|
@@ -458,10 +491,10 @@ export function makeUnion(uci: CaseInfo, values: any[]): any {
|
|
|
458
491
|
}
|
|
459
492
|
}
|
|
460
493
|
|
|
461
|
-
export function makeRecord(t: TypeInfo, values: any
|
|
494
|
+
export function makeRecord(t: TypeInfo, values: MutableArray<any>): any {
|
|
462
495
|
const fields = getRecordElements(t);
|
|
463
496
|
if (fields.length !== values.length) {
|
|
464
|
-
throw new
|
|
497
|
+
throw new Exception(`Expected an array of length ${fields.length} but got ${values.length}`);
|
|
465
498
|
}
|
|
466
499
|
return t.construct != null
|
|
467
500
|
? new t.construct(...values)
|
|
@@ -471,7 +504,7 @@ export function makeRecord(t: TypeInfo, values: any[]): any {
|
|
|
471
504
|
}, {} as any);
|
|
472
505
|
}
|
|
473
506
|
|
|
474
|
-
export function makeTuple(values: any
|
|
507
|
+
export function makeTuple(values: MutableArray<any>, _t: TypeInfo): any {
|
|
475
508
|
return values;
|
|
476
509
|
}
|
|
477
510
|
|
|
@@ -506,7 +539,7 @@ export function createInstance(t: TypeInfo, consArgs?: any[]): any {
|
|
|
506
539
|
// Even though char is a value type, it's erased to string, and Unchecked.defaultof<char> is null
|
|
507
540
|
return null;
|
|
508
541
|
default:
|
|
509
|
-
throw new
|
|
542
|
+
throw new Exception(`Cannot access constructor of ${t.fullname}`);
|
|
510
543
|
}
|
|
511
544
|
}
|
|
512
545
|
}
|
|
@@ -519,7 +552,7 @@ export function getValue(propertyInfo: PropertyInfo, v: any): any {
|
|
|
519
552
|
|
|
520
553
|
function assertUnion(x: any) {
|
|
521
554
|
if (!(x instanceof Union)) {
|
|
522
|
-
throw new
|
|
555
|
+
throw new Exception(`Value is not an F# union type`);
|
|
523
556
|
}
|
|
524
557
|
}
|
|
525
558
|
|
package/RegExp.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Exception } from "./Util.ts";
|
|
2
|
+
|
|
1
3
|
export type MatchEvaluator = (match: any) => string;
|
|
2
4
|
|
|
3
5
|
export function create(pattern: string, options = 0) {
|
|
@@ -8,7 +10,7 @@ export function create(pattern: string, options = 0) {
|
|
|
8
10
|
// * Singleline: 0x0010
|
|
9
11
|
// * ECMAScript: 0x0100 (ignored)
|
|
10
12
|
if ((options & ~(1 ^ 2 ^ 8 ^ 16 ^ 256)) !== 0) {
|
|
11
|
-
throw new
|
|
13
|
+
throw new Exception("RegexOptions only supports: IgnoreCase, Multiline, Compiled, Singleline and ECMAScript");
|
|
12
14
|
}
|
|
13
15
|
// Set always global and unicode flags for compatibility with dotnet, see #2925
|
|
14
16
|
let flags = "gu";
|
|
@@ -39,10 +41,10 @@ export function match(reg: RegExp, input: string, startAt = 0) {
|
|
|
39
41
|
|
|
40
42
|
export function matches(reg: RegExp, input: string, startAt = 0) {
|
|
41
43
|
if (input == null) {
|
|
42
|
-
throw new
|
|
44
|
+
throw new Exception("Input cannot ve null");
|
|
43
45
|
}
|
|
44
46
|
if (!reg.global) {
|
|
45
|
-
throw new
|
|
47
|
+
throw new Exception("Non-global RegExp"); // Prevent infinite loop
|
|
46
48
|
}
|
|
47
49
|
reg.lastIndex = startAt;
|
|
48
50
|
const matches: RegExpExecArray[] = [];
|