@fable-org/fable-library-ts 2.0.0-beta.4 → 2.0.0-beta.6
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 +253 -247
- 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 +14 -0
- package/Char.ts +38 -35
- package/Choice.ts +36 -12
- package/CollectionUtil.ts +4 -4
- package/Date.ts +67 -62
- package/DateOffset.ts +47 -56
- 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 +31 -13
- package/FSharp.Core.CompilerServices.ts +4 -4
- package/FSharp.Core.ts +34 -34
- package/Global.ts +44 -2
- package/Guid.ts +7 -6
- package/Int32.ts +20 -17
- package/List.ts +57 -56
- package/Long.ts +6 -5
- package/MailboxProcessor.ts +8 -7
- package/Map.ts +67 -65
- package/MapUtil.ts +5 -5
- package/MutableMap.ts +32 -20
- package/MutableSet.ts +12 -12
- package/Native.ts +3 -3
- package/Numeric.ts +1 -1
- package/Observable.ts +3 -3
- package/Option.ts +3 -3
- package/Random.ts +34 -34
- package/Range.ts +7 -7
- package/Reflection.ts +73 -40
- package/RegExp.ts +5 -3
- package/Result.ts +31 -27
- package/Seq.ts +56 -54
- package/Seq2.ts +14 -14
- package/Set.ts +81 -80
- package/String.ts +41 -38
- package/System.Collections.Generic.ts +45 -25
- package/System.Text.ts +12 -12
- 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 +74 -26
- package/package.json +1 -1
- package/tsconfig.json +18 -5
- package/SystemException.ts +0 -7
package/MutableSet.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
import { IMap, IEqualityComparer, IDisposable, disposeSafe, defaultOf, ISet, toIterator, IEnumerator, getEnumerator } from "./Util.
|
|
3
|
-
import { iterate, map, iterateIndexed, concat } from "./Seq.
|
|
4
|
-
import { setItem } from "./Array.
|
|
5
|
-
import { int32 } from "./Int32.
|
|
6
|
-
import { some, Option } from "./Option.
|
|
7
|
-
import { FSharpRef } from "./Types.
|
|
8
|
-
import { class_type, TypeInfo } from "./Reflection.
|
|
9
|
-
import { getItemFromDict, tryGetValue } from "./MapUtil.
|
|
2
|
+
import { IMap, IEqualityComparer, IDisposable, disposeSafe, defaultOf, ISet, MutableArray, toIterator, IEnumerator, getEnumerator } from "./Util.ts";
|
|
3
|
+
import { iterate, map, iterateIndexed, concat } from "./Seq.ts";
|
|
4
|
+
import { setItem } from "./Array.ts";
|
|
5
|
+
import { int32 } from "./Int32.ts";
|
|
6
|
+
import { some, Option } from "./Option.ts";
|
|
7
|
+
import { FSharpRef } from "./Types.ts";
|
|
8
|
+
import { class_type, TypeInfo } from "./Reflection.ts";
|
|
9
|
+
import { getItemFromDict, tryGetValue } from "./MapUtil.ts";
|
|
10
10
|
|
|
11
11
|
export class HashSet<T> implements ISet<T>, Iterable<T>, Iterable<T> {
|
|
12
12
|
readonly comparer: IEqualityComparer<T>;
|
|
@@ -59,7 +59,7 @@ export class HashSet<T> implements ISet<T>, Iterable<T>, Iterable<T> {
|
|
|
59
59
|
const this$: HashSet<T> = this;
|
|
60
60
|
return HashSet__Contains_2B595<T>(this$, item);
|
|
61
61
|
}
|
|
62
|
-
"System.Collections.Generic.ICollection`1.CopyToZ3B4C077E"(array: T
|
|
62
|
+
"System.Collections.Generic.ICollection`1.CopyToZ3B4C077E"(array: MutableArray<T>, arrayIndex: int32): void {
|
|
63
63
|
const this$: HashSet<T> = this;
|
|
64
64
|
iterateIndexed<T>((i: int32, e: T): void => {
|
|
65
65
|
setItem(array, arrayIndex + i, e);
|
|
@@ -142,7 +142,7 @@ function HashSet__TryFindIndex_2B595<T>(this$: HashSet<T>, k: T): [boolean, int3
|
|
|
142
142
|
|
|
143
143
|
function HashSet__TryFind_2B595<T>(this$: HashSet<T>, k: T): Option<T> {
|
|
144
144
|
const matchValue: [boolean, int32, int32] = HashSet__TryFindIndex_2B595<T>(this$, k);
|
|
145
|
-
let matchResult: int32;
|
|
145
|
+
let matchResult: int32 = undefined as any;
|
|
146
146
|
if (matchValue[0]) {
|
|
147
147
|
if (matchValue[2] > -1) {
|
|
148
148
|
matchResult = 0;
|
|
@@ -204,7 +204,7 @@ export function HashSet__Add_2B595<T>(this$: HashSet<T>, k: T): boolean {
|
|
|
204
204
|
|
|
205
205
|
export function HashSet__Contains_2B595<T>(this$: HashSet<T>, k: T): boolean {
|
|
206
206
|
const matchValue: [boolean, int32, int32] = HashSet__TryFindIndex_2B595<T>(this$, k);
|
|
207
|
-
let matchResult: int32;
|
|
207
|
+
let matchResult: int32 = undefined as any;
|
|
208
208
|
if (matchValue[0]) {
|
|
209
209
|
if (matchValue[2] > -1) {
|
|
210
210
|
matchResult = 0;
|
|
@@ -226,7 +226,7 @@ export function HashSet__Contains_2B595<T>(this$: HashSet<T>, k: T): boolean {
|
|
|
226
226
|
|
|
227
227
|
export function HashSet__Remove_2B595<T>(this$: HashSet<T>, k: T): boolean {
|
|
228
228
|
const matchValue: [boolean, int32, int32] = HashSet__TryFindIndex_2B595<T>(this$, k);
|
|
229
|
-
let matchResult: int32;
|
|
229
|
+
let matchResult: int32 = undefined as any;
|
|
230
230
|
if (matchValue[0]) {
|
|
231
231
|
if (matchValue[2] > -1) {
|
|
232
232
|
matchResult = 0;
|
package/Native.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { int32 } from "./Int32.ts";
|
|
3
|
+
import { MutableArray } from "./Util.ts";
|
|
4
4
|
|
|
5
|
-
export function Helpers_allocateArrayFromCons<T>(cons:
|
|
5
|
+
export function Helpers_allocateArrayFromCons<T>(cons: any, len: int32): MutableArray<T> {
|
|
6
6
|
if (cons == null) {
|
|
7
7
|
return new Array(len);
|
|
8
8
|
}
|
package/Numeric.ts
CHANGED
package/Observable.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
import { FSharpChoice$2_$union, Choice_tryValueIfChoice1Of2, Choice_tryValueIfChoice2Of2 } from "./Choice.
|
|
3
|
-
import { Option, value } from "./Option.
|
|
4
|
-
import { IDisposable } from "./Util.
|
|
2
|
+
import { FSharpChoice$2_$union, Choice_tryValueIfChoice1Of2, Choice_tryValueIfChoice2Of2 } from "./Choice.ts";
|
|
3
|
+
import { Option, value } from "./Option.ts";
|
|
4
|
+
import { IDisposable } from "./Util.ts";
|
|
5
5
|
|
|
6
6
|
export interface IObserver<T> {
|
|
7
7
|
OnNext: (x: T) => void;
|
package/Option.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Nullable, structuralHash, equals, compare } from "./Util.
|
|
1
|
+
import { Exception, Nullable, structuralHash, equals, compare } from "./Util.ts";
|
|
2
2
|
|
|
3
3
|
// Options are erased in runtime by Fable, but we have
|
|
4
4
|
// the `Some` type below to wrap values that would evaluate
|
|
@@ -54,7 +54,7 @@ export class Some<T> {
|
|
|
54
54
|
|
|
55
55
|
export function nonNullValue<T>(x: Nullable<T>): T {
|
|
56
56
|
if (x == null) {
|
|
57
|
-
throw new
|
|
57
|
+
throw new Exception("Nullable has no value");
|
|
58
58
|
} else {
|
|
59
59
|
return x;
|
|
60
60
|
}
|
|
@@ -62,7 +62,7 @@ export function nonNullValue<T>(x: Nullable<T>): T {
|
|
|
62
62
|
|
|
63
63
|
export function value<T>(x: Option<T>) {
|
|
64
64
|
if (x == null) {
|
|
65
|
-
throw new
|
|
65
|
+
throw new Exception("Option has no value");
|
|
66
66
|
} else {
|
|
67
67
|
return x instanceof Some ? x.value : x;
|
|
68
68
|
}
|
package/Random.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
|
|
2
|
-
import { uint8, int32, float64 } from "./Int32.
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
2
|
+
import { uint8, int32, float64 } from "./Int32.ts";
|
|
3
|
+
import { ArgumentNullException_$ctor_Z721C83C5, ArgumentOutOfRangeException_$ctor_Z721C83C5 } from "./System.ts";
|
|
4
|
+
import { Operators_IsNull, Operators_NonNull } from "./FSharp.Core.ts";
|
|
5
|
+
import { MutableArray } from "./Util.ts";
|
|
6
|
+
import { class_type, TypeInfo } from "./Reflection.ts";
|
|
7
|
+
import { fromFloat64, op_Addition, toInt32_unchecked, toFloat64, compare, int64, fromInt32, toInt64_unchecked } from "./BigInt.ts";
|
|
8
|
+
import { item, setItem } from "./Array.ts";
|
|
8
9
|
|
|
9
10
|
function Native_random(): float64 {
|
|
10
11
|
return Math.random();
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
function Native_randomNext(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
;
|
|
14
|
+
function Native_randomNext(minValue: int32, maxValue: int32): int32 {
|
|
15
|
+
if (maxValue < minValue) {
|
|
16
|
+
throw ArgumentOutOfRangeException_$ctor_Z721C83C5("minValue must be less than maxValue");
|
|
17
|
+
}
|
|
18
|
+
return Math.floor(Math.random() * (maxValue - minValue)) + minValue;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function Native_randomBytes(buffer: uint8
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
function Native_randomBytes(buffer: MutableArray<uint8>): void {
|
|
22
|
+
if (Operators_IsNull<any>(buffer)) {
|
|
23
|
+
throw ArgumentNullException_$ctor_Z721C83C5("buffer");
|
|
24
|
+
}
|
|
25
|
+
for (let i = 0; i < buffer.length; i += 6) {
|
|
26
|
+
// Pick random 48-bit number. Fill buffer in 2 24-bit chunks to avoid bitwise truncation.
|
|
27
|
+
let r = Math.floor(Math.random() * 281474976710656); // Low 24 bits = chunk 1.
|
|
28
|
+
const rhi = Math.floor(r / 16777216); // High 24 bits shifted via division = chunk 2.
|
|
29
|
+
for (let j = 0; j < 6 && i + j < buffer.length; j++) {
|
|
30
|
+
if (j === 3) { r = rhi; }
|
|
31
|
+
buffer[i + j] = r & 255;
|
|
32
|
+
r >>>= 8;
|
|
24
33
|
}
|
|
25
|
-
|
|
26
|
-
// Pick random 48-bit number. Fill buffer in 2 24-bit chunks to avoid bitwise truncation.
|
|
27
|
-
let r = Math.floor(Math.random() * 281474976710656); // Low 24 bits = chunk 1.
|
|
28
|
-
const rhi = Math.floor(r / 16777216); // High 24 bits shifted via division = chunk 2.
|
|
29
|
-
for (let j = 0; j < 6 && i + j < buffer.length; j++) {
|
|
30
|
-
if (j === 3) { r = rhi; }
|
|
31
|
-
buffer[i + j] = r & 255;
|
|
32
|
-
r >>>= 8;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
34
|
+
};
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export interface IRandom {
|
|
38
38
|
Next0(): int32,
|
|
39
39
|
Next1(maxValue: int32): int32,
|
|
40
40
|
Next2(minValue: int32, maxValue: int32): int32,
|
|
41
|
-
NextBytes(buffer: uint8
|
|
41
|
+
NextBytes(buffer: MutableArray<uint8>): void,
|
|
42
42
|
NextDouble(): float64
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -57,7 +57,7 @@ export class NonSeeded implements IRandom {
|
|
|
57
57
|
NextDouble(): float64 {
|
|
58
58
|
return Native_random();
|
|
59
59
|
}
|
|
60
|
-
NextBytes(buffer: uint8
|
|
60
|
+
NextBytes(buffer: MutableArray<uint8>): void {
|
|
61
61
|
Native_randomBytes(buffer);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -74,12 +74,12 @@ export class Seeded implements IRandom {
|
|
|
74
74
|
readonly MBIG: int32;
|
|
75
75
|
inext: int32;
|
|
76
76
|
inextp: int32;
|
|
77
|
-
seedArray: int32
|
|
77
|
+
seedArray: MutableArray<int32>;
|
|
78
78
|
constructor(seed: int32) {
|
|
79
79
|
this.MBIG = 2147483647;
|
|
80
80
|
this.inext = 0;
|
|
81
81
|
this.inextp = 0;
|
|
82
|
-
this.seedArray =
|
|
82
|
+
this.seedArray = (new Int32Array(56));
|
|
83
83
|
let ii = 0;
|
|
84
84
|
let mj = 0;
|
|
85
85
|
let mk = 0;
|
|
@@ -114,14 +114,14 @@ export class Seeded implements IRandom {
|
|
|
114
114
|
Next1(maxValue: int32): int32 {
|
|
115
115
|
const this$: Seeded = this;
|
|
116
116
|
if (maxValue < 0) {
|
|
117
|
-
throw
|
|
117
|
+
throw ArgumentOutOfRangeException_$ctor_Z721C83C5("maxValue must be positive");
|
|
118
118
|
}
|
|
119
119
|
return ~~(Seeded__Sample(this$) * maxValue) | 0;
|
|
120
120
|
}
|
|
121
121
|
Next2(minValue: int32, maxValue: int32): int32 {
|
|
122
122
|
const this$: Seeded = this;
|
|
123
123
|
if (minValue > maxValue) {
|
|
124
|
-
throw
|
|
124
|
+
throw ArgumentOutOfRangeException_$ctor_Z721C83C5("minValue must be less than maxValue");
|
|
125
125
|
}
|
|
126
126
|
const range: int64 = toInt64_unchecked(fromInt32(maxValue - minValue));
|
|
127
127
|
return ((compare(range, toInt64_unchecked(fromInt32(2147483647))) <= 0) ? (~~(Seeded__Sample(this$) * toFloat64(range)) + minValue) : ~~toInt32_unchecked(toInt64_unchecked(op_Addition(toInt64_unchecked(fromFloat64(Seeded__GetSampleForLargeRange(this$) * toFloat64(range))), toInt64_unchecked(fromInt32(minValue)))))) | 0;
|
|
@@ -130,10 +130,10 @@ export class Seeded implements IRandom {
|
|
|
130
130
|
const this$: Seeded = this;
|
|
131
131
|
return Seeded__Sample(this$);
|
|
132
132
|
}
|
|
133
|
-
NextBytes(buffer: uint8
|
|
133
|
+
NextBytes(buffer: MutableArray<uint8>): void {
|
|
134
134
|
const this$: Seeded = this;
|
|
135
|
-
if (Operators_IsNull<
|
|
136
|
-
throw
|
|
135
|
+
if (Operators_IsNull<any>(buffer)) {
|
|
136
|
+
throw ArgumentNullException_$ctor_Z721C83C5("buffer");
|
|
137
137
|
}
|
|
138
138
|
for (let i = 0; i <= (buffer.length - 1); i++) {
|
|
139
139
|
setItem(buffer, i, (Seeded__InternalSample(this$) % (~~255 + 1)) & 0xFF);
|
package/Range.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
|
|
2
|
-
import { compare } from "./Util.
|
|
3
|
-
import { float64, int32 } from "./Int32.
|
|
4
|
-
import { Option } from "./Option.
|
|
5
|
-
import { unfold, delay } from "./Seq.
|
|
6
|
-
import { uint64, toUInt64_unchecked, int64, toInt64_unchecked, op_Addition, fromZero } from "./BigInt.
|
|
7
|
-
import { decimal, op_Addition as op_Addition_1, fromParts } from "./Decimal.
|
|
2
|
+
import { Exception, compare } from "./Util.ts";
|
|
3
|
+
import { float64, int32 } from "./Int32.ts";
|
|
4
|
+
import { Option } from "./Option.ts";
|
|
5
|
+
import { unfold, delay } from "./Seq.ts";
|
|
6
|
+
import { uint64, toUInt64_unchecked, int64, toInt64_unchecked, op_Addition, fromZero } from "./BigInt.ts";
|
|
7
|
+
import { decimal, op_Addition as op_Addition_1, fromParts } from "./Decimal.ts";
|
|
8
8
|
|
|
9
9
|
export function makeRangeStepFunction<T>(step: T, stop: T, zero: T, add: ((arg0: T, arg1: T) => T)): ((arg0: T) => Option<[T, T]>) {
|
|
10
10
|
const stepComparedWithZero: int32 = compare(step, zero) | 0;
|
|
11
11
|
if (stepComparedWithZero === 0) {
|
|
12
|
-
throw new
|
|
12
|
+
throw new Exception("The step of a range cannot be zero");
|
|
13
13
|
}
|
|
14
14
|
const stepGreaterThanZero: boolean = stepComparedWithZero > 0;
|
|
15
15
|
return (x: T): Option<[T, T]> => {
|
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[] = [];
|