mol_conform 0.0.262 → 0.0.264

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/node.test.js CHANGED
@@ -145,7 +145,7 @@ var $;
145
145
  var $;
146
146
  (function ($) {
147
147
  function $mol_fail_hidden(error) {
148
- throw error;
148
+ throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
149
149
  }
150
150
  $.$mol_fail_hidden = $mol_fail_hidden;
151
151
  })($ || ($ = {}));
@@ -260,7 +260,7 @@ var $;
260
260
  "use strict";
261
261
  var $;
262
262
  (function ($) {
263
- const mod = require('module');
263
+ const mod = require /****/('module');
264
264
  const internals = mod.builtinModules;
265
265
  function $node_internal_check(name) {
266
266
  if (name.startsWith('node:'))
@@ -274,8 +274,8 @@ var $;
274
274
  "use strict";
275
275
  var $;
276
276
  (function ($) {
277
- const path = require('path');
278
- const mod = require('module');
277
+ const path = require /****/('path');
278
+ const mod = require /****/('module');
279
279
  const localRequire = mod.createRequire(path.join(process.cwd(), 'package.json'));
280
280
  function $node_autoinstall(name) {
281
281
  try {
@@ -396,6 +396,7 @@ var $;
396
396
  ])
397
397
  ].map(frame_normalize).join('\n')
398
398
  });
399
+ // в nodejs, что б не дублировалось cause в консоли
399
400
  Object.defineProperty(this, 'cause', {
400
401
  get: () => cause
401
402
  });
@@ -586,6 +587,9 @@ var $;
586
587
  [Symbol.dispose]() {
587
588
  this.destructor();
588
589
  }
590
+ //[ Symbol.toPrimitive ]( hint: string ) {
591
+ // return hint === 'number' ? this.valueOf() : this.toString()
592
+ //}
589
593
  toString() {
590
594
  return this[Symbol.toStringTag] || this.constructor.name + '<>';
591
595
  }
@@ -662,6 +666,7 @@ var $;
662
666
  "use strict";
663
667
  var $;
664
668
  (function ($) {
669
+ /** Generates unique identifier. */
665
670
  function $mol_guid(length = 8, exists = () => false) {
666
671
  for (;;) {
667
672
  let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
@@ -677,11 +682,16 @@ var $;
677
682
  "use strict";
678
683
  var $;
679
684
  (function ($) {
685
+ /** Special status statuses. */
680
686
  let $mol_wire_cursor;
681
687
  (function ($mol_wire_cursor) {
688
+ /** Update required. */
682
689
  $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
690
+ /** Some of (transitive) pub update required. */
683
691
  $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
692
+ /** Actual state but may be dropped. */
684
693
  $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
694
+ /** State will never be changed. */
685
695
  $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
686
696
  })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
687
697
  })($ || ($ = {}));
@@ -690,6 +700,9 @@ var $;
690
700
  "use strict";
691
701
  var $;
692
702
  (function ($) {
703
+ /**
704
+ * Collects subscribers in compact array. 28B
705
+ */
693
706
  class $mol_wire_pub extends Object {
694
707
  constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
695
708
  super();
@@ -697,10 +710,17 @@ var $;
697
710
  }
698
711
  [Symbol.toStringTag];
699
712
  data = [];
713
+ // Derived objects should be Arrays.
700
714
  static get [Symbol.species]() {
701
715
  return Array;
702
716
  }
703
- sub_from = 0;
717
+ /**
718
+ * Index of first subscriber.
719
+ */
720
+ sub_from = 0; // 4B
721
+ /**
722
+ * All current subscribers.
723
+ */
704
724
  get sub_list() {
705
725
  const res = [];
706
726
  for (let i = this.sub_from; i < this.data.length; i += 2) {
@@ -708,14 +728,23 @@ var $;
708
728
  }
709
729
  return res;
710
730
  }
731
+ /**
732
+ * Has any subscribers or not.
733
+ */
711
734
  get sub_empty() {
712
735
  return this.sub_from === this.data.length;
713
736
  }
737
+ /**
738
+ * Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
739
+ */
714
740
  sub_on(sub, pub_pos) {
715
741
  const pos = this.data.length;
716
742
  this.data.push(sub, pub_pos);
717
743
  return pos;
718
744
  }
745
+ /**
746
+ * Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
747
+ */
719
748
  sub_off(sub_pos) {
720
749
  if (!(sub_pos < this.data.length)) {
721
750
  $mol_fail(new Error(`Wrong pos ${sub_pos}`));
@@ -728,21 +757,39 @@ var $;
728
757
  if (end === this.sub_from)
729
758
  this.reap();
730
759
  }
760
+ /**
761
+ * Called when last sub was unsubscribed.
762
+ **/
731
763
  reap() { }
764
+ /**
765
+ * Autowire this publisher with current subscriber.
766
+ **/
732
767
  promote() {
733
768
  $mol_wire_auto()?.track_next(this);
734
769
  }
770
+ /**
771
+ * Enforce actualization. Should not throw errors.
772
+ */
735
773
  fresh() { }
774
+ /**
775
+ * Allow to put data to caches in the subtree.
776
+ */
736
777
  complete() { }
737
778
  get incompleted() {
738
779
  return false;
739
780
  }
781
+ /**
782
+ * Notify subscribers about self changes.
783
+ */
740
784
  emit(quant = $mol_wire_cursor.stale) {
741
785
  for (let i = this.sub_from; i < this.data.length; i += 2) {
742
786
  ;
743
787
  this.data[i].absorb(quant, this.data[i + 1]);
744
788
  }
745
789
  }
790
+ /**
791
+ * Moves peer from one position to another. Doesn't clear data at old position!
792
+ */
746
793
  peer_move(from_pos, to_pos) {
747
794
  const peer = this.data[from_pos];
748
795
  const self_pos = this.data[from_pos + 1];
@@ -750,6 +797,9 @@ var $;
750
797
  this.data[to_pos + 1] = self_pos;
751
798
  peer.peer_repos(self_pos, to_pos);
752
799
  }
800
+ /**
801
+ * Updates self position in the peer.
802
+ */
753
803
  peer_repos(peer_pos, self_pos) {
754
804
  this.data[peer_pos + 1] = self_pos;
755
805
  }
@@ -765,10 +815,16 @@ var $;
765
815
  var $;
766
816
  (function ($) {
767
817
  $.$mol_wire_auto_sub = null;
818
+ /**
819
+ * When fulfilled, all publishers are promoted to this subscriber on access to its.
820
+ */
768
821
  function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
769
822
  return $.$mol_wire_auto_sub = next;
770
823
  }
771
824
  $.$mol_wire_auto = $mol_wire_auto;
825
+ /**
826
+ * Affection queue. Used to prevent accidental stack overflow on emit.
827
+ */
772
828
  $.$mol_wire_affected = [];
773
829
  })($ || ($ = {}));
774
830
 
@@ -776,6 +832,7 @@ var $;
776
832
  "use strict";
777
833
  var $;
778
834
  (function ($) {
835
+ // https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
779
836
  $['devtoolsFormatters'] ||= [];
780
837
  function $mol_dev_format_register(config) {
781
838
  $['devtoolsFormatters'].push(config);
@@ -827,6 +884,7 @@ var $;
827
884
  return false;
828
885
  if (!val)
829
886
  return false;
887
+ // if( Error.isError( val ) ) true
830
888
  if (val[$.$mol_dev_format_body])
831
889
  return true;
832
890
  return false;
@@ -844,12 +902,16 @@ var $;
844
902
  return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
845
903
  }
846
904
  }
905
+ // if( Error.isError( val ) ) {
906
+ // return $mol_dev_format_native( val )
907
+ // }
847
908
  return null;
848
909
  },
849
910
  });
850
911
  function $mol_dev_format_native(obj) {
851
912
  if (typeof obj === 'undefined')
852
913
  return $.$mol_dev_format_shade('undefined');
914
+ // if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
853
915
  return [
854
916
  'object',
855
917
  {
@@ -907,6 +969,9 @@ var $;
907
969
  'margin-left': '13px'
908
970
  });
909
971
  class Stack extends Array {
972
+ // [ Symbol.toPrimitive ]() {
973
+ // return this.toString()
974
+ // }
910
975
  toString() {
911
976
  return this.join('\n');
912
977
  }
@@ -929,6 +994,7 @@ var $;
929
994
  this.method = call.getMethodName() ?? '';
930
995
  if (this.method === this.function)
931
996
  this.method = '';
997
+ // const func = c.getFunction()
932
998
  this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
933
999
  this.eval = call.getEvalOrigin() ?? '';
934
1000
  this.source = call.getScriptNameOrSourceURL() ?? '';
@@ -975,9 +1041,16 @@ var $;
975
1041
  "use strict";
976
1042
  var $;
977
1043
  (function ($) {
1044
+ /**
1045
+ * Publisher that can auto collect other publishers. 32B
1046
+ *
1047
+ * P1 P2 P3 P4 S1 S2 S3
1048
+ * ^ ^
1049
+ * pubs_from subs_from
1050
+ */
978
1051
  class $mol_wire_pub_sub extends $mol_wire_pub {
979
- pub_from = 0;
980
- cursor = $mol_wire_cursor.stale;
1052
+ pub_from = 0; // 4B
1053
+ cursor = $mol_wire_cursor.stale; // 4B
981
1054
  get temp() {
982
1055
  return false;
983
1056
  }
@@ -1095,10 +1168,27 @@ var $;
1095
1168
  return;
1096
1169
  this.cursor = quant;
1097
1170
  this.emit($mol_wire_cursor.doubt);
1171
+ // if( pos >= 0 && pos < this.sub_from - 2 ) {
1172
+ // const pub = this.data[ pos ] as $mol_wire_pub
1173
+ // if( pub instanceof $mol_wire_task ) return
1174
+ // for(
1175
+ // let cursor = this.pub_from;
1176
+ // cursor < this.sub_from;
1177
+ // cursor += 2
1178
+ // ) {
1179
+ // const pub = this.data[ cursor ] as $mol_wire_pub
1180
+ // if( pub instanceof $mol_wire_task ) {
1181
+ // pub.destructor()
1182
+ // }
1183
+ // }
1184
+ // }
1098
1185
  }
1099
1186
  [$mol_dev_format_head]() {
1100
1187
  return $mol_dev_format_native(this);
1101
1188
  }
1189
+ /**
1190
+ * Is subscribed to any publisher or not.
1191
+ */
1102
1192
  get pub_empty() {
1103
1193
  return this.sub_from === this.pub_from;
1104
1194
  }
@@ -1168,6 +1258,7 @@ var $;
1168
1258
  "use strict";
1169
1259
  var $;
1170
1260
  (function ($) {
1261
+ /// @todo right orderinng
1171
1262
  $.$mol_after_mock_queue = [];
1172
1263
  function $mol_after_mock_warp() {
1173
1264
  const queue = $.$mol_after_mock_queue.splice(0);
@@ -1244,6 +1335,13 @@ var $;
1244
1335
  var $;
1245
1336
  (function ($) {
1246
1337
  const wrappers = new WeakMap();
1338
+ /**
1339
+ * Suspendable task with support both sync/async api.
1340
+ *
1341
+ * A1 A2 A3 A4 P1 P2 P3 P4 S1 S2 S3
1342
+ * ^ ^ ^
1343
+ * args_from pubs_from subs_from
1344
+ **/
1247
1345
  class $mol_wire_fiber extends $mol_wire_pub_sub {
1248
1346
  task;
1249
1347
  host;
@@ -1264,6 +1362,7 @@ var $;
1264
1362
  });
1265
1363
  }
1266
1364
  static sync() {
1365
+ // Sync whole fiber graph
1267
1366
  while (this.planning.size) {
1268
1367
  for (const fiber of this.planning) {
1269
1368
  this.planning.delete(fiber);
@@ -1274,6 +1373,7 @@ var $;
1274
1373
  fiber.fresh();
1275
1374
  }
1276
1375
  }
1376
+ // Collect garbage
1277
1377
  while (this.reaping.size) {
1278
1378
  const fibers = this.reaping;
1279
1379
  this.reaping = new Set;
@@ -1425,6 +1525,10 @@ var $;
1425
1525
  this.cursor = $mol_wire_cursor.stale;
1426
1526
  this.fresh();
1427
1527
  }
1528
+ /**
1529
+ * Synchronous execution. Throws Promise when waits async task (SuspenseAPI provider).
1530
+ * Should be called inside SuspenseAPI consumer (ie fiber).
1531
+ */
1428
1532
  sync() {
1429
1533
  if (!$mol_wire_fiber.warm) {
1430
1534
  return this.result();
@@ -1439,6 +1543,10 @@ var $;
1439
1543
  }
1440
1544
  return this.cache;
1441
1545
  }
1546
+ /**
1547
+ * Asynchronous execution.
1548
+ * It's SuspenseAPI consumer. So SuspenseAPI providers can be called inside.
1549
+ */
1442
1550
  async async_raw() {
1443
1551
  while (true) {
1444
1552
  this.fresh();
@@ -1451,6 +1559,7 @@ var $;
1451
1559
  if (!$mol_promise_like(this.cache))
1452
1560
  return this.cache;
1453
1561
  if (this.cursor === $mol_wire_cursor.final) {
1562
+ // never ends on destructed fiber
1454
1563
  await new Promise(() => { });
1455
1564
  }
1456
1565
  }
@@ -1579,6 +1688,7 @@ var $;
1579
1688
  "use strict";
1580
1689
  var $;
1581
1690
  (function ($) {
1691
+ /** Log begin of collapsed group only when some logged inside, returns func to close group */
1582
1692
  function $mol_log3_area_lazy(event) {
1583
1693
  const self = this.$;
1584
1694
  const stack = self.$mol_log3_stack;
@@ -1603,6 +1713,7 @@ var $;
1603
1713
  "use strict";
1604
1714
  var $;
1605
1715
  (function ($) {
1716
+ /** Module for working with terminal. Text coloring when output in terminal */
1606
1717
  class $mol_term_color {
1607
1718
  static reset = this.ansi(0, 0);
1608
1719
  static bold = this.ansi(1, 22);
@@ -1688,6 +1799,7 @@ var $;
1688
1799
  "use strict";
1689
1800
  var $;
1690
1801
  (function ($) {
1802
+ /** One-shot fiber */
1691
1803
  class $mol_wire_task extends $mol_wire_fiber {
1692
1804
  static getter(task) {
1693
1805
  return function $mol_wire_task_get(host, args) {
@@ -1713,6 +1825,7 @@ var $;
1713
1825
  }
1714
1826
  const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
1715
1827
  const next = new $mol_wire_task(key, task, host, args);
1828
+ // Disabled because non-idempotency is required for try-catch
1716
1829
  if (existen?.temp) {
1717
1830
  $$.$mol_log3_warn({
1718
1831
  place: '$mol_wire_task',
@@ -1745,7 +1858,7 @@ var $;
1745
1858
  try {
1746
1859
  next[Symbol.toStringTag] = this[Symbol.toStringTag];
1747
1860
  }
1748
- catch {
1861
+ catch { // Promises throw in strict mode
1749
1862
  Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1750
1863
  }
1751
1864
  }
@@ -1770,6 +1883,9 @@ var $;
1770
1883
  "use strict";
1771
1884
  var $;
1772
1885
  (function ($) {
1886
+ /**
1887
+ * Decorates method to fiber to ensure it is executed only once inside other fiber.
1888
+ */
1773
1889
  function $mol_wire_method(host, field, descr) {
1774
1890
  if (!descr)
1775
1891
  descr = Reflect.getOwnPropertyDescriptor(host, field);
@@ -1796,6 +1912,7 @@ var $;
1796
1912
  "use strict";
1797
1913
  var $;
1798
1914
  (function ($) {
1915
+ /** Convert a pseudo-synchronous (Suspense API) API to an explicit asynchronous one (for integrating with external systems). */
1799
1916
  function $mol_wire_async(obj) {
1800
1917
  let fiber;
1801
1918
  const temp = $mol_wire_task.getter(obj);
@@ -1907,6 +2024,10 @@ var $;
1907
2024
  props[field] = get_val;
1908
2025
  return get_val;
1909
2026
  }
2027
+ /**
2028
+ * Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
2029
+ * @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
2030
+ */
1910
2031
  function $mol_wire_sync(obj) {
1911
2032
  return new Proxy(obj, {
1912
2033
  get(obj, field) {
@@ -2408,6 +2529,12 @@ var $;
2408
2529
  createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
2409
2530
  };
2410
2531
  $.$mol_jsx_frag = '';
2532
+ /**
2533
+ * JSX adapter that makes DOM tree.
2534
+ * Generates global unique ids for every DOM-element by components tree with ids.
2535
+ * Ensures all local ids are unique.
2536
+ * Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
2537
+ */
2411
2538
  function $mol_jsx(Elem, props, ...childNodes) {
2412
2539
  const id = props && props.id || '';
2413
2540
  const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
@@ -2518,6 +2645,8 @@ var $;
2518
2645
 
2519
2646
  ;
2520
2647
  "use strict";
2648
+ /** @jsx $mol_jsx */
2649
+ /** @jsxFrag $mol_jsx_frag */
2521
2650
  var $;
2522
2651
  (function ($) {
2523
2652
  $mol_test({
@@ -2623,6 +2752,7 @@ var $;
2623
2752
  "use strict";
2624
2753
  var $;
2625
2754
  (function ($) {
2755
+ /** Lazy computed lists with native Array interface. $mol_range2_array is mutable but all derived ranges are immutable. */
2626
2756
  function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
2627
2757
  const source = typeof item === 'function' ? new $mol_range2_array() : item;
2628
2758
  if (typeof item !== 'function') {
@@ -2671,6 +2801,7 @@ var $;
2671
2801
  }
2672
2802
  $.$mol_range2 = $mol_range2;
2673
2803
  class $mol_range2_array extends Array {
2804
+ // Lazy
2674
2805
  concat(...tail) {
2675
2806
  if (tail.length === 0)
2676
2807
  return this;
@@ -2682,6 +2813,7 @@ var $;
2682
2813
  }
2683
2814
  return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
2684
2815
  }
2816
+ // Lazy
2685
2817
  filter(check, context) {
2686
2818
  const filtered = [];
2687
2819
  let cursor = -1;
@@ -2694,13 +2826,16 @@ var $;
2694
2826
  return filtered[index];
2695
2827
  }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
2696
2828
  }
2829
+ // Diligent
2697
2830
  forEach(proceed, context) {
2698
2831
  for (let [key, value] of this.entries())
2699
2832
  proceed.call(context, value, key, this);
2700
2833
  }
2834
+ // Lazy
2701
2835
  map(proceed, context) {
2702
2836
  return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
2703
2837
  }
2838
+ // Diligent
2704
2839
  reduce(merge, result) {
2705
2840
  let index = 0;
2706
2841
  if (arguments.length === 1) {
@@ -2711,12 +2846,15 @@ var $;
2711
2846
  }
2712
2847
  return result;
2713
2848
  }
2849
+ // Lazy
2714
2850
  toReversed() {
2715
2851
  return $mol_range2(index => this[this.length - 1 - index], () => this.length);
2716
2852
  }
2853
+ // Lazy
2717
2854
  slice(from = 0, to = this.length) {
2718
2855
  return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
2719
2856
  }
2857
+ // Lazy
2720
2858
  some(check, context) {
2721
2859
  for (let index = 0; index < this.length; ++index) {
2722
2860
  if (check.call(context, this[index], index, this))
@@ -2912,6 +3050,10 @@ var $;
2912
3050
  var $;
2913
3051
  (function ($) {
2914
3052
  $.$mol_compare_deep_cache = new WeakMap();
3053
+ /**
3054
+ * Deeply compares two values. Returns true if equal.
3055
+ * Define `Symbol.toPrimitive` to customize.
3056
+ */
2915
3057
  function $mol_compare_deep(left, right) {
2916
3058
  if (Object.is(left, right))
2917
3059
  return true;
@@ -3049,6 +3191,7 @@ var $;
3049
3191
 
3050
3192
  ;
3051
3193
  "use strict";
3194
+ /** @jsx $mol_jsx */
3052
3195
  var $;
3053
3196
  (function ($) {
3054
3197
  $mol_test({
@@ -3110,6 +3253,7 @@ var $;
3110
3253
  const obj3_copy = { test: 3, obj2: obj2_copy };
3111
3254
  obj1.obj3 = obj3;
3112
3255
  obj1_copy.obj3 = obj3_copy;
3256
+ // warmup cache
3113
3257
  $mol_assert_not($mol_compare_deep(obj1, {}));
3114
3258
  $mol_assert_not($mol_compare_deep(obj2, {}));
3115
3259
  $mol_assert_not($mol_compare_deep(obj3, {}));
@@ -3179,18 +3323,34 @@ var $;
3179
3323
  "use strict";
3180
3324
  var $;
3181
3325
  (function ($) {
3326
+ /**
3327
+ * Argument must be Truthy
3328
+ * @deprecated use $mol_assert_equal instead
3329
+ */
3182
3330
  function $mol_assert_ok(value) {
3183
3331
  if (value)
3184
3332
  return;
3185
3333
  $mol_fail(new Error(`${value} ≠ true`));
3186
3334
  }
3187
3335
  $.$mol_assert_ok = $mol_assert_ok;
3336
+ /**
3337
+ * Argument must be Falsy
3338
+ * @deprecated use $mol_assert_equal instead
3339
+ */
3188
3340
  function $mol_assert_not(value) {
3189
3341
  if (!value)
3190
3342
  return;
3191
3343
  $mol_fail(new Error(`${value} ≠ false`));
3192
3344
  }
3193
3345
  $.$mol_assert_not = $mol_assert_not;
3346
+ /**
3347
+ * Handler must throw an error.
3348
+ * @example
3349
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } ) // Passes because throws error
3350
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , 'Parse error' ) // Passes because throws right message
3351
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
3352
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
3353
+ */
3194
3354
  function $mol_assert_fail(handler, ErrorRight) {
3195
3355
  const fail = $.$mol_fail;
3196
3356
  try {
@@ -3213,10 +3373,18 @@ var $;
3213
3373
  $mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
3214
3374
  }
3215
3375
  $.$mol_assert_fail = $mol_assert_fail;
3376
+ /** @deprecated Use $mol_assert_equal */
3216
3377
  function $mol_assert_like(...args) {
3217
3378
  $mol_assert_equal(...args);
3218
3379
  }
3219
3380
  $.$mol_assert_like = $mol_assert_like;
3381
+ /**
3382
+ * All arguments must not be structural equal to each other.
3383
+ * @example
3384
+ * $mol_assert_unique( 1 , 2 , 3 ) // Passes
3385
+ * $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
3386
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
3387
+ */
3220
3388
  function $mol_assert_unique(...args) {
3221
3389
  for (let i = 0; i < args.length; ++i) {
3222
3390
  for (let j = 0; j < args.length; ++j) {
@@ -3229,6 +3397,13 @@ var $;
3229
3397
  }
3230
3398
  }
3231
3399
  $.$mol_assert_unique = $mol_assert_unique;
3400
+ /**
3401
+ * All arguments must be structural equal each other.
3402
+ * @example
3403
+ * $mol_assert_like( [1] , [1] , [1] ) // Passes
3404
+ * $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
3405
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
3406
+ */
3232
3407
  function $mol_assert_equal(...args) {
3233
3408
  for (let i = 1; i < args.length; ++i) {
3234
3409
  if ($mol_compare_deep(args[0], args[i]))
@@ -3282,6 +3457,11 @@ var $;
3282
3457
  var $;
3283
3458
  (function ($) {
3284
3459
  const instances = new WeakSet();
3460
+ /**
3461
+ * Proxy that delegates all to lazy returned target.
3462
+ *
3463
+ * $mol_delegate( Array.prototype , ()=> fetch_array() )
3464
+ */
3285
3465
  function $mol_delegate(proto, target) {
3286
3466
  const proxy = new Proxy(proto, {
3287
3467
  get: (_, field) => {
@@ -3381,6 +3561,7 @@ var $;
3381
3561
  "use strict";
3382
3562
  var $;
3383
3563
  (function ($) {
3564
+ /** Position in any resource. */
3384
3565
  class $mol_span extends $mol_object2 {
3385
3566
  uri;
3386
3567
  source;
@@ -3396,13 +3577,17 @@ var $;
3396
3577
  this.length = length;
3397
3578
  this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
3398
3579
  }
3580
+ /** Span for begin of unknown resource */
3399
3581
  static unknown = $mol_span.begin('?');
3582
+ /** Makes new span for begin of resource. */
3400
3583
  static begin(uri, source = '') {
3401
3584
  return new $mol_span(uri, source, 1, 1, 0);
3402
3585
  }
3586
+ /** Makes new span for end of resource. */
3403
3587
  static end(uri, source) {
3404
3588
  return new $mol_span(uri, source, 1, source.length + 1, 0);
3405
3589
  }
3590
+ /** Makes new span for entire resource. */
3406
3591
  static entire(uri, source) {
3407
3592
  return new $mol_span(uri, source, 1, 1, source.length);
3408
3593
  }
@@ -3417,15 +3602,19 @@ var $;
3417
3602
  length: this.length
3418
3603
  };
3419
3604
  }
3605
+ /** Makes new error for this span. */
3420
3606
  error(message, Class = Error) {
3421
3607
  return new Class(`${message} (${this})`);
3422
3608
  }
3609
+ /** Makes new span for same uri. */
3423
3610
  span(row, col, length) {
3424
3611
  return new $mol_span(this.uri, this.source, row, col, length);
3425
3612
  }
3613
+ /** Makes new span after end of this. */
3426
3614
  after(length = 0) {
3427
3615
  return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
3428
3616
  }
3617
+ /** Makes new span between begin and end. */
3429
3618
  slice(begin, end = -1) {
3430
3619
  let len = this.length;
3431
3620
  if (begin < 0)
@@ -3500,6 +3689,7 @@ var $;
3500
3689
  "use strict";
3501
3690
  var $;
3502
3691
  (function ($) {
3692
+ /** Serializes tree to string in tree format. */
3503
3693
  function $mol_tree2_to_string(tree) {
3504
3694
  let output = [];
3505
3695
  function dump(tree, prefix = '') {
@@ -3559,12 +3749,25 @@ var $;
3559
3749
  "use strict";
3560
3750
  var $;
3561
3751
  (function ($) {
3752
+ /**
3753
+ * Abstract Syntax Tree with human readable serialization.
3754
+ * Avoid direct instantiation. Use static factories instead.
3755
+ * @see https://github.com/nin-jin/tree.d
3756
+ */
3562
3757
  class $mol_tree2 extends Object {
3563
3758
  type;
3564
3759
  value;
3565
3760
  kids;
3566
3761
  span;
3567
- constructor(type, value, kids, span) {
3762
+ constructor(
3763
+ /** Type of structural node, `value` should be empty */
3764
+ type,
3765
+ /** Content of data node, `type` should be empty */
3766
+ value,
3767
+ /** Child nodes */
3768
+ kids,
3769
+ /** Position in most far source resource */
3770
+ span) {
3568
3771
  super();
3569
3772
  this.type = type;
3570
3773
  this.value = value;
@@ -3572,12 +3775,15 @@ var $;
3572
3775
  this.span = span;
3573
3776
  this[Symbol.toStringTag] = type || '\\' + value;
3574
3777
  }
3778
+ /** Makes collection node. */
3575
3779
  static list(kids, span = $mol_span.unknown) {
3576
3780
  return new $mol_tree2('', '', kids, span);
3577
3781
  }
3782
+ /** Makes new derived collection node. */
3578
3783
  list(kids) {
3579
3784
  return $mol_tree2.list(kids, this.span);
3580
3785
  }
3786
+ /** Makes data node for any string. */
3581
3787
  static data(value, kids = [], span = $mol_span.unknown) {
3582
3788
  const chunks = value.split('\n');
3583
3789
  if (chunks.length > 1) {
@@ -3591,21 +3797,26 @@ var $;
3591
3797
  }
3592
3798
  return new $mol_tree2('', value, kids, span);
3593
3799
  }
3800
+ /** Makes new derived data node. */
3594
3801
  data(value, kids = []) {
3595
3802
  return $mol_tree2.data(value, kids, this.span);
3596
3803
  }
3804
+ /** Makes struct node. */
3597
3805
  static struct(type, kids = [], span = $mol_span.unknown) {
3598
3806
  if (/[ \n\t\\]/.test(type)) {
3599
3807
  $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
3600
3808
  }
3601
3809
  return new $mol_tree2(type, '', kids, span);
3602
3810
  }
3811
+ /** Makes new derived structural node. */
3603
3812
  struct(type, kids = []) {
3604
3813
  return $mol_tree2.struct(type, kids, this.span);
3605
3814
  }
3815
+ /** Makes new derived node with different kids id defined. */
3606
3816
  clone(kids, span = this.span) {
3607
3817
  return new $mol_tree2(this.type, this.value, kids, span);
3608
3818
  }
3819
+ /** Returns multiline text content. */
3609
3820
  text() {
3610
3821
  var values = [];
3611
3822
  for (var kid of this.kids) {
@@ -3615,15 +3826,20 @@ var $;
3615
3826
  }
3616
3827
  return this.value + values.join('\n');
3617
3828
  }
3829
+ /** Parses tree format. */
3830
+ /** @deprecated Use $mol_tree2_from_string */
3618
3831
  static fromString(str, uri = 'unknown') {
3619
3832
  return $$.$mol_tree2_from_string(str, uri);
3620
3833
  }
3834
+ /** Serializes to tree format. */
3621
3835
  toString() {
3622
3836
  return $$.$mol_tree2_to_string(this);
3623
3837
  }
3838
+ /** Makes new tree with node overrided by path. */
3624
3839
  insert(value, ...path) {
3625
3840
  return this.update($mol_maybe(value), ...path)[0];
3626
3841
  }
3842
+ /** Makes new tree with node overrided by path. */
3627
3843
  update(value, ...path) {
3628
3844
  if (path.length === 0)
3629
3845
  return value;
@@ -3656,6 +3872,7 @@ var $;
3656
3872
  return [this.clone(kids)];
3657
3873
  }
3658
3874
  }
3875
+ /** Query nodes by path. */
3659
3876
  select(...path) {
3660
3877
  let next = [this];
3661
3878
  for (const type of path) {
@@ -3682,6 +3899,7 @@ var $;
3682
3899
  }
3683
3900
  return this.list(next);
3684
3901
  }
3902
+ /** Filter kids by path or value. */
3685
3903
  filter(path, value) {
3686
3904
  const sub = this.kids.filter(item => {
3687
3905
  var found = item.select(...path);
@@ -3709,9 +3927,11 @@ var $;
3709
3927
  $mol_fail_hidden(error);
3710
3928
  }
3711
3929
  }
3930
+ /** Transform tree through context with transformers */
3712
3931
  hack(belt, context = {}) {
3713
3932
  return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
3714
3933
  }
3934
+ /** Makes Error with node coordinates. */
3715
3935
  error(message, Class = Error) {
3716
3936
  return this.span.error(`${message}\n${this.clone([])}`, Class);
3717
3937
  }
@@ -3867,6 +4087,7 @@ var $;
3867
4087
  "use strict";
3868
4088
  var $;
3869
4089
  (function ($) {
4090
+ /** Syntax error with cordinates and source line snippet. */
3870
4091
  class $mol_error_syntax extends SyntaxError {
3871
4092
  reason;
3872
4093
  line;
@@ -3885,6 +4106,7 @@ var $;
3885
4106
  "use strict";
3886
4107
  var $;
3887
4108
  (function ($) {
4109
+ /** Parses tree format from string. */
3888
4110
  function $mol_tree2_from_string(str, uri = '?') {
3889
4111
  const span = $mol_span.entire(uri, str);
3890
4112
  var root = $mol_tree2.list([], span);
@@ -3894,6 +4116,7 @@ var $;
3894
4116
  var indent = 0;
3895
4117
  var line_start = pos;
3896
4118
  row++;
4119
+ // read indent
3897
4120
  while (str.length > pos && str[pos] == '\t') {
3898
4121
  indent++;
3899
4122
  pos++;
@@ -3902,8 +4125,10 @@ var $;
3902
4125
  min_indent = indent;
3903
4126
  }
3904
4127
  indent -= min_indent;
4128
+ // invalid tab size
3905
4129
  if (indent < 0 || indent >= stack.length) {
3906
4130
  const sp = span.span(row, 1, pos - line_start);
4131
+ // skip error line
3907
4132
  while (str.length > pos && str[pos] != '\n') {
3908
4133
  pos++;
3909
4134
  }
@@ -3918,7 +4143,9 @@ var $;
3918
4143
  }
3919
4144
  stack.length = indent + 1;
3920
4145
  var parent = stack[indent];
4146
+ // parse types
3921
4147
  while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
4148
+ // type can not contain space and tab
3922
4149
  var error_start = pos;
3923
4150
  while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
3924
4151
  pos++;
@@ -3930,6 +4157,7 @@ var $;
3930
4157
  const sp = span.span(row, error_start - line_start + 1, pos - error_start);
3931
4158
  this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
3932
4159
  }
4160
+ // read type
3933
4161
  var type_start = pos;
3934
4162
  while (str.length > pos &&
3935
4163
  str[pos] != '\\' &&
@@ -3944,10 +4172,12 @@ var $;
3944
4172
  parent_kids.push(next);
3945
4173
  parent = next;
3946
4174
  }
4175
+ // read one space if exists
3947
4176
  if (str.length > pos && str[pos] == ' ') {
3948
4177
  pos++;
3949
4178
  }
3950
4179
  }
4180
+ // read data
3951
4181
  if (str.length > pos && str[pos] == '\\') {
3952
4182
  var data_start = pos;
3953
4183
  while (str.length > pos && str[pos] != '\n') {
@@ -3958,6 +4188,7 @@ var $;
3958
4188
  parent_kids.push(next);
3959
4189
  parent = next;
3960
4190
  }
4191
+ // now must be end of text
3961
4192
  if (str.length === pos && stack.length > 0) {
3962
4193
  const sp = span.span(row, pos - line_start + 1, 1);
3963
4194
  this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
@@ -4150,6 +4381,12 @@ var $;
4150
4381
  'return result without errors'() {
4151
4382
  $mol_assert_equal($mol_try(() => false), false);
4152
4383
  },
4384
+ //'return error if thrown'() {
4385
+ //
4386
+ // const error = new Error( '$mol_try test error' )
4387
+ // $mol_assert_equal( $mol_try( ()=> { throw error } ) , error )
4388
+ //
4389
+ //} ,
4153
4390
  });
4154
4391
  })($ || ($ = {}));
4155
4392