@fable-org/fable-library-js 2.0.0-rc.3 → 2.0.0-rc.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/CHANGELOG.md CHANGED
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## 2.0.0-rc.5 - 2026-03-31
11
+
12
+ ### Fixed
13
+
14
+ * [JS/TS] Improve `Regex.Escape` and `Regex.Unescape` handling (by @MangelMaxime)
15
+ * [JS/TS] Fixed quotation for union string cases (by @MangelMaxime)
16
+
17
+ ## 2.0.0-rc.4 - 2026-03-19
18
+
19
+ ### Fixed
20
+
21
+ * [JS/TS] Fix `Unchecked.defaultof<char>` being emitted as `null` instead of `'\0'` (by @MangelMaxime)
22
+
10
23
  ## 2.0.0-rc.3 - 2026-03-10
11
24
 
12
25
  ### Fixed
package/Map.js CHANGED
@@ -806,6 +806,9 @@ export function MapTreeModule_ofSeq(comparer, c) {
806
806
  }
807
807
  }
808
808
  }
809
+ /**
810
+ * Imperative left-to-right iterators.
811
+ */
809
812
  export class MapTreeModule_MapIterator$2 extends Record {
810
813
  constructor(stack, started) {
811
814
  super();
package/MutableMap.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { disposeSafe, defaultOf, equals, toIterator, getEnumerator } from "./Util.js";
2
2
  import { iterate, map, delay, toArray, iterateIndexed, concat } from "./Seq.js";
3
3
  import { value as value_1 } from "./Option.js";
4
- import { setItem } from "./Array.js";
4
+ import { item as item_1, setItem } from "./Array.js";
5
5
  import { FSharpRef } from "./Types.js";
6
6
  import { class_type } from "./Reflection.js";
7
7
  import { getItemFromDict, tryGetValue } from "./MapUtil.js";
@@ -231,7 +231,7 @@ export function Dictionary__TryFind_2B595(this$, k) {
231
231
  }
232
232
  switch (matchResult) {
233
233
  case 0:
234
- return getItemFromDict(this$.hashMap, matchValue[1])[matchValue[2]];
234
+ return item_1(matchValue[2], getItemFromDict(this$.hashMap, matchValue[1]));
235
235
  default:
236
236
  return undefined;
237
237
  }
@@ -269,7 +269,7 @@ export function Dictionary__set_Item_5BDDA1(this$, k, v) {
269
269
  const matchValue = Dictionary__TryFindIndex_2B595(this$, k);
270
270
  if (matchValue[0]) {
271
271
  if (matchValue[2] > -1) {
272
- getItemFromDict(this$.hashMap, matchValue[1])[matchValue[2]] = [k, v];
272
+ setItem(getItemFromDict(this$.hashMap, matchValue[1]), matchValue[2], [k, v]);
273
273
  }
274
274
  else {
275
275
  const value = void (getItemFromDict(this$.hashMap, matchValue[1]).push([k, v]));
package/MutableSet.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { disposeSafe, defaultOf, toIterator, getEnumerator } from "./Util.js";
2
2
  import { iterate, map, iterateIndexed, concat } from "./Seq.js";
3
- import { setItem } from "./Array.js";
3
+ import { item as item_1, setItem } from "./Array.js";
4
4
  import { some } from "./Option.js";
5
5
  import { FSharpRef } from "./Types.js";
6
6
  import { class_type } from "./Reflection.js";
@@ -146,7 +146,7 @@ function HashSet__TryFind_2B595(this$, k) {
146
146
  }
147
147
  switch (matchResult) {
148
148
  case 0:
149
- return some(getItemFromDict(this$.hashMap, matchValue[1])[matchValue[2]]);
149
+ return some(item_1(matchValue[2], getItemFromDict(this$.hashMap, matchValue[1])));
150
150
  default:
151
151
  return undefined;
152
152
  }
package/Reflection.js CHANGED
@@ -431,8 +431,7 @@ export function createInstance(t, consArgs) {
431
431
  case decimal_type.fullname:
432
432
  return new Decimal(0);
433
433
  case char_type.fullname:
434
- // Even though char is a value type, it's erased to string, and Unchecked.defaultof<char> is null
435
- return null;
434
+ return "\0";
436
435
  default:
437
436
  throw new Exception(`Cannot access constructor of ${t.fullname}`);
438
437
  }
package/RegExp.js CHANGED
@@ -18,10 +18,19 @@ export function create(pattern, options = 0) {
18
18
  }
19
19
  // From http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
20
20
  export function escape(str) {
21
- return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
21
+ // Matches the characters escaped by .NET's Regex.Escape.
22
+ // Note:
23
+ //
24
+ // .NET also escapes space and # (relevant for IgnorePatternWhitespace mode),
25
+ // but JS unicode-mode regex rejects \ and \# as invalid escapes, and we don't
26
+ // support IgnorePatternWhitespace, so we omit them.
27
+ //
28
+ // .NET does not escape ] and } but JS unicode-mode regex rejects bare ] and }
29
+ // as invalid, so we escape them too for compatibility.
30
+ return str.replace(/[$()*+.?[\\\^{|}\]]/g, "\\$&");
22
31
  }
23
32
  export function unescape(str) {
24
- return str.replace(/\\([\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|])/g, "$1");
33
+ return str.replace(/\\([$()*+.?[\\\^{|}\]])/g, "$1");
25
34
  }
26
35
  export function isMatch(reg, input, startAt = 0) {
27
36
  reg.lastIndex = startAt;
package/Seq.js CHANGED
@@ -5,7 +5,7 @@ import { class_type } from "./Reflection.js";
5
5
  import { some, value as value_1 } from "./Option.js";
6
6
  import { KeyNotFoundException_$ctor_Z721C83C5 } from "./System.Collections.Generic.js";
7
7
  import { Operators_Lock, Operators_NullArgCheck } from "./FSharp.Core.js";
8
- import { chunkBySize as chunkBySize_1, permute as permute_1, transpose as transpose_1, map as map_1, windowed as windowed_1, splitInto as splitInto_1, pairwise as pairwise_1, scanBack as scanBack_1, reverse as reverse_1, mapFoldBack as mapFoldBack_1, mapFold as mapFold_1, tryItem as tryItem_1, tryHead as tryHead_1, foldBack2 as foldBack2_1, foldBack as foldBack_1, tryFindIndexBack as tryFindIndexBack_1, tryFindBack as tryFindBack_1, singleton as singleton_1 } from "./Array.js";
8
+ import { chunkBySize as chunkBySize_1, permute as permute_1, transpose as transpose_1, map as map_1, windowed as windowed_1, splitInto as splitInto_1, pairwise as pairwise_1, scanBack as scanBack_1, reverse as reverse_1, mapFoldBack as mapFoldBack_1, mapFold as mapFold_1, item as item_1, tryItem as tryItem_1, tryHead as tryHead_1, foldBack2 as foldBack2_1, foldBack as foldBack_1, tryFindIndexBack as tryFindIndexBack_1, tryFindBack as tryFindBack_1, singleton as singleton_1 } from "./Array.js";
9
9
  import { length as length_1, tryItem as tryItem_2, isEmpty as isEmpty_1, tryHead as tryHead_2, ofSeq as ofSeq_1, ofArray as ofArray_1, toArray as toArray_1, FSharpList } from "./List.js";
10
10
  import { SR_indexOutOfBounds } from "./Global.js";
11
11
  export const SR_enumerationAlreadyFinished = "Enumeration already finished.";
@@ -954,7 +954,7 @@ export function cache(source) {
954
954
  });
955
955
  }, unfold((i_1) => Operators_Lock(prefix, () => {
956
956
  if (i_1 < prefix.length) {
957
- return [prefix[i_1], i_1 + 1];
957
+ return [item_1(i_1, prefix), i_1 + 1];
958
958
  }
959
959
  else {
960
960
  if (i_1 >= prefix.length) {
@@ -981,7 +981,7 @@ export function cache(source) {
981
981
  }
982
982
  }
983
983
  if (i_1 < prefix.length) {
984
- return [prefix[i_1], i_1 + 1];
984
+ return [item_1(i_1, prefix), i_1 + 1];
985
985
  }
986
986
  else {
987
987
  return undefined;
package/String.js CHANGED
@@ -331,7 +331,12 @@ export function format(str, ...args) {
331
331
  precision = precision == null ? 2 : precision;
332
332
  rep = toFixed(rep, precision);
333
333
  parts = splitIntAndDecimalPart(rep);
334
- rep = "¤" + thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
334
+ if (precision > 0) {
335
+ rep = "¤" + thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
336
+ }
337
+ else {
338
+ rep = "¤" + thousandSeparate(parts.integral);
339
+ }
335
340
  if (isNegative) {
336
341
  rep = "(" + rep + ")";
337
342
  }
@@ -375,14 +380,24 @@ export function format(str, ...args) {
375
380
  precision = precision != null ? precision : 2;
376
381
  rep = toFixed(rep, precision);
377
382
  parts = splitIntAndDecimalPart(rep);
378
- rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
383
+ if (precision > 0) {
384
+ rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
385
+ }
386
+ else {
387
+ rep = thousandSeparate(parts.integral);
388
+ }
379
389
  break;
380
390
  case "p":
381
391
  case "P":
382
392
  precision = precision != null ? precision : 2;
383
393
  rep = toFixed(multiply(rep, 100), precision);
384
394
  parts = splitIntAndDecimalPart(rep);
385
- rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0") + " %";
395
+ if (precision > 0) {
396
+ rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0") + " %";
397
+ }
398
+ else {
399
+ rep = thousandSeparate(parts.integral) + " %";
400
+ }
386
401
  break;
387
402
  case "r":
388
403
  case "R":
package/System.Text.js CHANGED
@@ -2,6 +2,7 @@ import { replace, format, replicate, substring, isNullOrEmpty, join } from "./St
2
2
  import { class_type } from "./Reflection.js";
3
3
  import { toString } from "./Types.js";
4
4
  import { Exception, clear, int32ToString } from "./Util.js";
5
+ import { setItem, item } from "./Array.js";
5
6
  export class StringBuilder {
6
7
  constructor(value, capacity) {
7
8
  this.buf = [];
@@ -118,8 +119,8 @@ export function StringBuilder__Clear(x) {
118
119
  export function StringBuilder__get_Chars_Z524259A4(x, index) {
119
120
  let len = 0;
120
121
  let i = 0;
121
- while ((i < x.buf.length) && ((len + x.buf[i].length) <= index)) {
122
- len = ((len + x.buf[i].length) | 0);
122
+ while ((i < x.buf.length) && ((len + item(i, x.buf).length) <= index)) {
123
+ len = ((len + item(i, x.buf).length) | 0);
123
124
  i = ((i + 1) | 0);
124
125
  }
125
126
  if ((index < 0) ? true : (i >= x.buf.length)) {
@@ -127,14 +128,14 @@ export function StringBuilder__get_Chars_Z524259A4(x, index) {
127
128
  }
128
129
  else {
129
130
  const pos = (index - len) | 0;
130
- return x.buf[i][pos];
131
+ return item(i, x.buf)[pos];
131
132
  }
132
133
  }
133
134
  export function StringBuilder__set_Chars_413E0D0A(x, index, value) {
134
135
  let len = 0;
135
136
  let i = 0;
136
- while ((i < x.buf.length) && ((len + x.buf[i].length) <= index)) {
137
- len = ((len + x.buf[i].length) | 0);
137
+ while ((i < x.buf.length) && ((len + item(i, x.buf).length) <= index)) {
138
+ len = ((len + item(i, x.buf).length) | 0);
138
139
  i = ((i + 1) | 0);
139
140
  }
140
141
  if ((index < 0) ? true : (i >= x.buf.length)) {
@@ -142,12 +143,12 @@ export function StringBuilder__set_Chars_413E0D0A(x, index, value) {
142
143
  }
143
144
  else {
144
145
  const pos = (index - len) | 0;
145
- x.buf[i] = ((x.buf[i].slice(0, (pos - 1) + 1) + value) + x.buf[i].slice(pos + 1, x.buf[i].length));
146
+ setItem(x.buf, i, (item(i, x.buf).slice(0, (pos - 1) + 1) + value) + item(i, x.buf).slice(pos + 1, item(i, x.buf).length));
146
147
  }
147
148
  }
148
149
  export function StringBuilder__Replace_Z766F94C0(x, oldValue, newValue) {
149
150
  for (let i = x.buf.length - 1; i >= 0; i--) {
150
- x.buf[i] = replace(x.buf[i], oldValue, newValue);
151
+ setItem(x.buf, i, replace(item(i, x.buf), oldValue, newValue));
151
152
  }
152
153
  return x;
153
154
  }
@@ -158,7 +159,7 @@ export function StringBuilder__Replace_Z384F8060(x, oldValue, newValue) {
158
159
  export function StringBuilder__get_Length(x) {
159
160
  let len = 0;
160
161
  for (let i = x.buf.length - 1; i >= 0; i--) {
161
- len = ((len + x.buf[i].length) | 0);
162
+ len = ((len + item(i, x.buf).length) | 0);
162
163
  }
163
164
  return len | 0;
164
165
  }
package/Types.js CHANGED
@@ -36,6 +36,12 @@ export function toString(x, callStack = 0) {
36
36
  return String(x);
37
37
  }
38
38
  export function unionToString(name, fields) {
39
+ function unionFieldToString(x) {
40
+ if (typeof x === "string") {
41
+ return '"' + x + '"';
42
+ }
43
+ return toString(x);
44
+ }
39
45
  if (fields.length === 0) {
40
46
  return name;
41
47
  }
@@ -43,11 +49,11 @@ export function unionToString(name, fields) {
43
49
  let fieldStr;
44
50
  let withParens = true;
45
51
  if (fields.length === 1) {
46
- fieldStr = toString(fields[0]);
52
+ fieldStr = unionFieldToString(fields[0]);
47
53
  withParens = fieldStr.indexOf(" ") >= 0;
48
54
  }
49
55
  else {
50
- fieldStr = fields.map((x) => toString(x)).join(", ");
56
+ fieldStr = fields.map((x) => unionFieldToString(x)).join(", ");
51
57
  }
52
58
  return name + (withParens ? " (" : " ") + fieldStr + (withParens ? ")" : "");
53
59
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "private": false,
4
4
  "type": "module",
5
5
  "name": "@fable-org/fable-library-js",
6
- "version": "2.0.0-rc.3",
6
+ "version": "2.0.0-rc.5",
7
7
  "description": "Core library used by F# projects compiled with fable.io",
8
8
  "author": "Fable Contributors",
9
9
  "license": "MIT",