mol_charset_ucf_lib 0.0.1 → 0.0.3

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
@@ -19,5 +19,4156 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
19
19
  var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
20
20
  $.$$ = $
21
21
 
22
+ ;
23
+ "use strict";
24
+ var $;
25
+ (function ($) {
26
+ let buf = new Uint8Array(2 ** 12);
27
+ function $mol_charset_buffer(size) {
28
+ if (buf.byteLength < size)
29
+ buf = new Uint8Array(size);
30
+ return buf;
31
+ }
32
+ $.$mol_charset_buffer = $mol_charset_buffer;
33
+ })($ || ($ = {}));
34
+
35
+ ;
36
+ "use strict";
37
+ var $;
38
+ (function ($) {
39
+ let buf = new Uint8Array(2 ** 12);
40
+ function $mol_charset_ucf_encode(str) {
41
+ const buf = $mol_charset_buffer(str.length * 3);
42
+ return buf.slice(0, $mol_charset_ucf_encode_to(str, buf));
43
+ }
44
+ $.$mol_charset_ucf_encode = $mol_charset_ucf_encode;
45
+ function $mol_charset_ucf_encode_to(str, buf, from = 0) {
46
+ let pos = from;
47
+ let mode = 0xF;
48
+ for (let i = 0; i < str.length; i++) {
49
+ let code = str.charCodeAt(i);
50
+ if (code >= 0xd800 && code < 0xe000)
51
+ code = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
52
+ if (code < 0x20) {
53
+ if (code > 0x08 && code < 0x0E) {
54
+ buf[pos++] = code;
55
+ }
56
+ else {
57
+ if (mode !== 0x0E)
58
+ buf[pos++] = mode = 0x0E;
59
+ buf[pos++] = code | 0x80;
60
+ }
61
+ }
62
+ else {
63
+ if (code < 0xFF) {
64
+ buf[pos++] = code;
65
+ }
66
+ else if (code < 0x09_00) {
67
+ const page = (code >> 7) + 0x0E;
68
+ if (mode !== page)
69
+ buf[pos++] = mode = page;
70
+ buf[pos++] = (code & 0x7F) | 0x80;
71
+ }
72
+ else if (code < 0x04_00_00) {
73
+ const page = code >> 15;
74
+ if (mode !== page)
75
+ buf[pos++] = mode = page;
76
+ buf[pos++] = (code & 0x7F) | 0x80;
77
+ buf[pos++] = code >> 7;
78
+ }
79
+ else {
80
+ if (mode !== 0x08)
81
+ buf[pos++] = mode = 0x08;
82
+ buf[pos++] = (code & 0x7F) | 0x80;
83
+ buf[pos++] = code >> 7;
84
+ buf[pos++] = code >> 15;
85
+ }
86
+ }
87
+ }
88
+ return pos - from;
89
+ }
90
+ })($ || ($ = {}));
91
+
92
+ ;
93
+ "use strict";
94
+ var $;
95
+ (function ($) {
96
+ function $mol_charset_ucf_decode(buffer, mode = 0x0F) {
97
+ let text = '';
98
+ let pos = 0;
99
+ let page_offset = 0;
100
+ while (pos < buffer.length) {
101
+ let code = buffer[pos++];
102
+ if (code < 0x20) {
103
+ if (code >= 0x0E) {
104
+ mode = code;
105
+ page_offset = (mode - 0x0E) << 7;
106
+ }
107
+ else if (code > 0x08) {
108
+ text += String.fromCodePoint(code);
109
+ }
110
+ else if (code === 0x08) {
111
+ mode = 0x08;
112
+ page_offset = 0;
113
+ }
114
+ else {
115
+ mode = code;
116
+ page_offset = mode << 15;
117
+ }
118
+ }
119
+ else if (code < 0x80) {
120
+ text += String.fromCodePoint(code);
121
+ }
122
+ else {
123
+ code &= 0x7F;
124
+ if (mode <= 0x08)
125
+ code |= buffer[pos++] << 7;
126
+ if (mode === 0x08)
127
+ code |= buffer[pos++] << 15;
128
+ text += String.fromCodePoint(page_offset | code);
129
+ }
130
+ }
131
+ return text;
132
+ }
133
+ $.$mol_charset_ucf_decode = $mol_charset_ucf_decode;
134
+ })($ || ($ = {}));
135
+
136
+ ;
137
+ "use strict";
138
+ var $;
139
+ (function ($) {
140
+ function $mol_promise_like(val) {
141
+ try {
142
+ return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
143
+ }
144
+ catch {
145
+ return false;
146
+ }
147
+ }
148
+ $.$mol_promise_like = $mol_promise_like;
149
+ })($ || ($ = {}));
150
+
151
+ ;
152
+ "use strict";
153
+ var $;
154
+ (function ($) {
155
+ function $mol_fail(error) {
156
+ throw error;
157
+ }
158
+ $.$mol_fail = $mol_fail;
159
+ })($ || ($ = {}));
160
+
161
+ ;
162
+ "use strict";
163
+ var $;
164
+ (function ($) {
165
+ function $mol_fail_hidden(error) {
166
+ throw error;
167
+ }
168
+ $.$mol_fail_hidden = $mol_fail_hidden;
169
+ })($ || ($ = {}));
170
+
171
+ ;
172
+ "use strict";
173
+ var $;
174
+ (function ($_1) {
175
+ function $mol_test(set) {
176
+ for (let name in set) {
177
+ const code = set[name];
178
+ const test = (typeof code === 'string') ? new Function('', code) : code;
179
+ $_1.$mol_test_all.push(test);
180
+ }
181
+ $mol_test_schedule();
182
+ }
183
+ $_1.$mol_test = $mol_test;
184
+ $_1.$mol_test_mocks = [];
185
+ $_1.$mol_test_all = [];
186
+ async function $mol_test_run() {
187
+ for (var test of $_1.$mol_test_all) {
188
+ let context = Object.create($$);
189
+ for (let mock of $_1.$mol_test_mocks)
190
+ await mock(context);
191
+ const res = test(context);
192
+ if ($mol_promise_like(res)) {
193
+ await new Promise((done, fail) => {
194
+ res.then(done, fail);
195
+ setTimeout(() => fail(new Error('Test timeout: ' + test.name)), 1000);
196
+ });
197
+ }
198
+ }
199
+ $$.$mol_log3_done({
200
+ place: '$mol_test',
201
+ message: 'All tests passed',
202
+ count: $_1.$mol_test_all.length,
203
+ });
204
+ }
205
+ $_1.$mol_test_run = $mol_test_run;
206
+ let scheduled = false;
207
+ function $mol_test_schedule() {
208
+ if (scheduled)
209
+ return;
210
+ scheduled = true;
211
+ setTimeout(async () => {
212
+ scheduled = false;
213
+ await $mol_test_run();
214
+ $$.$mol_test_complete();
215
+ }, 1000);
216
+ }
217
+ $_1.$mol_test_schedule = $mol_test_schedule;
218
+ $_1.$mol_test_mocks.push(context => {
219
+ let seed = 0;
220
+ context.Math = Object.create(Math);
221
+ context.Math.random = () => Math.sin(seed++);
222
+ const forbidden = ['XMLHttpRequest', 'fetch'];
223
+ for (let api of forbidden) {
224
+ context[api] = new Proxy(function () { }, {
225
+ get() {
226
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
227
+ },
228
+ apply() {
229
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
230
+ },
231
+ });
232
+ }
233
+ });
234
+ $mol_test({
235
+ 'mocked Math.random'($) {
236
+ console.assert($.Math.random() === 0);
237
+ console.assert($.Math.random() === Math.sin(1));
238
+ },
239
+ 'forbidden XMLHttpRequest'($) {
240
+ try {
241
+ console.assert(void new $.XMLHttpRequest);
242
+ }
243
+ catch (error) {
244
+ console.assert(error.message === 'XMLHttpRequest is forbidden in tests');
245
+ }
246
+ },
247
+ 'forbidden fetch'($) {
248
+ try {
249
+ console.assert(void $.fetch(''));
250
+ }
251
+ catch (error) {
252
+ console.assert(error.message === 'fetch is forbidden in tests');
253
+ }
254
+ },
255
+ });
256
+ })($ || ($ = {}));
257
+
258
+ ;
259
+ "use strict";
260
+ var $;
261
+ (function ($) {
262
+ function $mol_test_complete() {
263
+ process.exit(0);
264
+ }
265
+ $.$mol_test_complete = $mol_test_complete;
266
+ })($ || ($ = {}));
267
+
268
+ ;
269
+ "use strict";
270
+ var $;
271
+ (function ($) {
272
+ })($ || ($ = {}));
273
+
274
+ ;
275
+ "use strict";
276
+
277
+ ;
278
+ "use strict";
279
+ var $;
280
+ (function ($) {
281
+ const mod = require('module');
282
+ const internals = mod.builtinModules;
283
+ function $node_internal_check(name) {
284
+ if (name.startsWith('node:'))
285
+ return true;
286
+ return internals.includes(name);
287
+ }
288
+ $.$node_internal_check = $node_internal_check;
289
+ })($ || ($ = {}));
290
+
291
+ ;
292
+ "use strict";
293
+ var $;
294
+ (function ($) {
295
+ const path = require('path');
296
+ const mod = require('module');
297
+ const localRequire = mod.createRequire(path.join(process.cwd(), 'package.json'));
298
+ function $node_autoinstall(name) {
299
+ try {
300
+ localRequire.resolve(name);
301
+ }
302
+ catch {
303
+ this.$mol_run.spawn({ command: ['npm', 'install', '--omit=dev', name], dir: '.' });
304
+ try {
305
+ this.$mol_run.spawn({ command: ['npm', 'install', '--omit=dev', '@types/' + name], dir: '.' });
306
+ }
307
+ catch (e) {
308
+ if (this.$mol_promise_like(e))
309
+ this.$mol_fail_hidden(e);
310
+ this.$mol_fail_log(e);
311
+ }
312
+ }
313
+ }
314
+ $.$node_autoinstall = $node_autoinstall;
315
+ })($ || ($ = {}));
316
+
317
+ ;
318
+ "use strict";
319
+ var $node = new Proxy({ require }, {
320
+ get(target, name, wrapper) {
321
+ if (target[name])
322
+ return target[name];
323
+ if ($.$node_internal_check(name))
324
+ return target.require(name);
325
+ if (name[0] === '.')
326
+ return target.require(name);
327
+ $.$node_autoinstall(name);
328
+ return target.require(name);
329
+ },
330
+ set(target, name, value) {
331
+ target[name] = value;
332
+ return true;
333
+ },
334
+ });
335
+ require = (req => Object.assign(function require(name) {
336
+ return $node[name];
337
+ }, req))(require);
338
+
339
+ ;
340
+ "use strict";
341
+ var $;
342
+ (function ($) {
343
+ const named = new WeakSet();
344
+ function $mol_func_name(func) {
345
+ let name = func.name;
346
+ if (name?.length > 1)
347
+ return name;
348
+ if (named.has(func))
349
+ return name;
350
+ for (let key in this) {
351
+ try {
352
+ if (this[key] !== func)
353
+ continue;
354
+ name = key;
355
+ Object.defineProperty(func, 'name', { value: name });
356
+ break;
357
+ }
358
+ catch { }
359
+ }
360
+ named.add(func);
361
+ return name;
362
+ }
363
+ $.$mol_func_name = $mol_func_name;
364
+ function $mol_func_name_from(target, source) {
365
+ Object.defineProperty(target, 'name', { value: source.name });
366
+ return target;
367
+ }
368
+ $.$mol_func_name_from = $mol_func_name_from;
369
+ })($ || ($ = {}));
370
+
371
+ ;
372
+ "use strict";
373
+ var $;
374
+ (function ($_1) {
375
+ $mol_test({
376
+ 'FQN of anon function'($) {
377
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
378
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
379
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
380
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
381
+ },
382
+ });
383
+ })($ || ($ = {}));
384
+
385
+ ;
386
+ "use strict";
387
+ var $;
388
+ (function ($) {
389
+ function cause_serialize(cause) {
390
+ return JSON.stringify(cause, null, ' ')
391
+ .replace(/\(/, '<')
392
+ .replace(/\)/, ' >');
393
+ }
394
+ function frame_normalize(frame) {
395
+ return (typeof frame === 'string' ? frame : cause_serialize(frame))
396
+ .trim()
397
+ .replace(/at /gm, ' at ')
398
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)');
399
+ }
400
+ class $mol_error_mix extends AggregateError {
401
+ cause;
402
+ name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
403
+ constructor(message, cause = {}, ...errors) {
404
+ super(errors, message, { cause });
405
+ this.cause = cause;
406
+ const desc = Object.getOwnPropertyDescriptor(this, 'stack');
407
+ const stack_get = () => desc?.get?.() ?? super.stack ?? desc?.value ?? this.message;
408
+ Object.defineProperty(this, 'stack', {
409
+ get: () => stack_get() + '\n' + [
410
+ this.cause ?? 'no cause',
411
+ ...this.errors.flatMap(e => [
412
+ String(e.stack),
413
+ ...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
414
+ ])
415
+ ].map(frame_normalize).join('\n')
416
+ });
417
+ Object.defineProperty(this, 'cause', {
418
+ get: () => cause
419
+ });
420
+ }
421
+ static [Symbol.toPrimitive]() {
422
+ return this.toString();
423
+ }
424
+ static toString() {
425
+ return $$.$mol_func_name(this);
426
+ }
427
+ static make(...params) {
428
+ return new this(...params);
429
+ }
430
+ }
431
+ $.$mol_error_mix = $mol_error_mix;
432
+ })($ || ($ = {}));
433
+
434
+ ;
435
+ "use strict";
436
+ var $;
437
+ (function ($) {
438
+ $mol_test({
439
+ 'auto name'() {
440
+ class Invalid extends $mol_error_mix {
441
+ }
442
+ const mix = new Invalid('foo');
443
+ $mol_assert_equal(mix.name, 'Invalid_Error');
444
+ },
445
+ 'simpe mix'() {
446
+ const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
447
+ $mol_assert_equal(mix.message, 'foo');
448
+ $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
449
+ },
450
+ 'provide additional info'() {
451
+ class Invalid extends $mol_error_mix {
452
+ }
453
+ const mix = new $mol_error_mix('Wrong password', {}, new Invalid('Too short', { value: 'p@ssw0rd', hint: '> 8 letters' }), new Invalid('Too simple', { value: 'p@ssw0rd', hint: 'need capital letter' }));
454
+ const hints = [];
455
+ if (mix instanceof $mol_error_mix) {
456
+ for (const er of mix.errors) {
457
+ if (er instanceof Invalid) {
458
+ hints.push(er.cause?.hint ?? '');
459
+ }
460
+ }
461
+ }
462
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
463
+ },
464
+ });
465
+ })($ || ($ = {}));
466
+
467
+ ;
468
+ "use strict";
469
+ var $;
470
+ (function ($) {
471
+ $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
472
+ function $mol_ambient(overrides) {
473
+ return Object.setPrototypeOf(overrides, this || $);
474
+ }
475
+ $.$mol_ambient = $mol_ambient;
476
+ })($ || ($ = {}));
477
+
478
+ ;
479
+ "use strict";
480
+ var $;
481
+ (function ($) {
482
+ $.$mol_owning_map = new WeakMap();
483
+ function $mol_owning_allow(having) {
484
+ try {
485
+ if (!having)
486
+ return false;
487
+ if (typeof having !== 'object' && typeof having !== 'function')
488
+ return false;
489
+ if (having instanceof $mol_delegate)
490
+ return false;
491
+ if (typeof having['destructor'] !== 'function')
492
+ return false;
493
+ return true;
494
+ }
495
+ catch {
496
+ return false;
497
+ }
498
+ }
499
+ $.$mol_owning_allow = $mol_owning_allow;
500
+ function $mol_owning_get(having, Owner) {
501
+ if (!$mol_owning_allow(having))
502
+ return null;
503
+ while (true) {
504
+ const owner = $.$mol_owning_map.get(having);
505
+ if (!owner)
506
+ return owner;
507
+ if (!Owner)
508
+ return owner;
509
+ if (owner instanceof Owner)
510
+ return owner;
511
+ having = owner;
512
+ }
513
+ }
514
+ $.$mol_owning_get = $mol_owning_get;
515
+ function $mol_owning_check(owner, having) {
516
+ if (!$mol_owning_allow(having))
517
+ return false;
518
+ if ($.$mol_owning_map.get(having) !== owner)
519
+ return false;
520
+ return true;
521
+ }
522
+ $.$mol_owning_check = $mol_owning_check;
523
+ function $mol_owning_catch(owner, having) {
524
+ if (!$mol_owning_allow(having))
525
+ return false;
526
+ if ($.$mol_owning_map.get(having))
527
+ return false;
528
+ $.$mol_owning_map.set(having, owner);
529
+ return true;
530
+ }
531
+ $.$mol_owning_catch = $mol_owning_catch;
532
+ })($ || ($ = {}));
533
+
534
+ ;
535
+ "use strict";
536
+
537
+ ;
538
+ "use strict";
539
+
540
+ ;
541
+ "use strict";
542
+
543
+ ;
544
+ "use strict";
545
+
546
+ ;
547
+ "use strict";
548
+
549
+ ;
550
+ "use strict";
551
+
552
+ ;
553
+ "use strict";
554
+
555
+ ;
556
+ "use strict";
557
+ var $;
558
+ (function ($) {
559
+ if (!Symbol.dispose)
560
+ Symbol.dispose = Symbol('Symbol.dispose');
561
+ class $mol_object2 {
562
+ static $ = $;
563
+ [Symbol.toStringTag];
564
+ [$mol_ambient_ref] = null;
565
+ get $() {
566
+ if (this[$mol_ambient_ref])
567
+ return this[$mol_ambient_ref];
568
+ const owner = $mol_owning_get(this);
569
+ return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
570
+ }
571
+ set $(next) {
572
+ if (this[$mol_ambient_ref])
573
+ $mol_fail_hidden(new Error('Context already defined'));
574
+ this[$mol_ambient_ref] = next;
575
+ }
576
+ static create(init) {
577
+ const obj = new this;
578
+ if (init)
579
+ init(obj);
580
+ return obj;
581
+ }
582
+ static [Symbol.toPrimitive]() {
583
+ return this.toString();
584
+ }
585
+ static toString() {
586
+ return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
587
+ }
588
+ static toJSON() {
589
+ return this.toString();
590
+ }
591
+ destructor() { }
592
+ static destructor() { }
593
+ [Symbol.dispose]() {
594
+ this.destructor();
595
+ }
596
+ toString() {
597
+ return this[Symbol.toStringTag] || this.constructor.name + '<>';
598
+ }
599
+ }
600
+ $.$mol_object2 = $mol_object2;
601
+ })($ || ($ = {}));
602
+
603
+ ;
604
+ "use strict";
605
+ var $;
606
+ (function ($_1) {
607
+ let $$;
608
+ (function ($$) {
609
+ let $;
610
+ })($$ = $_1.$$ || ($_1.$$ = {}));
611
+ $_1.$mol_object_field = Symbol('$mol_object_field');
612
+ class $mol_object extends $mol_object2 {
613
+ static make(config) {
614
+ return super.create(obj => {
615
+ for (let key in config)
616
+ obj[key] = config[key];
617
+ });
618
+ }
619
+ }
620
+ $_1.$mol_object = $mol_object;
621
+ })($ || ($ = {}));
622
+
623
+ ;
624
+ "use strict";
625
+ var $;
626
+ (function ($_1) {
627
+ $mol_test({
628
+ 'init with overload'() {
629
+ class X extends $mol_object {
630
+ foo() {
631
+ return 1;
632
+ }
633
+ }
634
+ var x = X.make({
635
+ foo: () => 2,
636
+ });
637
+ $mol_assert_equal(x.foo(), 2);
638
+ },
639
+ 'Context in instance inherits from class'($) {
640
+ const custom = $.$mol_ambient({});
641
+ class X extends $.$mol_object {
642
+ static $ = custom;
643
+ }
644
+ $mol_assert_equal(new X().$, custom);
645
+ },
646
+ });
647
+ })($ || ($ = {}));
648
+
649
+ ;
650
+ "use strict";
651
+ var $;
652
+ (function ($) {
653
+ function $mol_env() {
654
+ return {};
655
+ }
656
+ $.$mol_env = $mol_env;
657
+ })($ || ($ = {}));
658
+
659
+ ;
660
+ "use strict";
661
+ var $;
662
+ (function ($) {
663
+ $.$mol_env = function $mol_env() {
664
+ return this.process.env;
665
+ };
666
+ })($ || ($ = {}));
667
+
668
+ ;
669
+ "use strict";
670
+ var $;
671
+ (function ($) {
672
+ function $mol_guid(length = 8, exists = () => false) {
673
+ for (;;) {
674
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
675
+ if (exists(id))
676
+ continue;
677
+ return id;
678
+ }
679
+ }
680
+ $.$mol_guid = $mol_guid;
681
+ })($ || ($ = {}));
682
+
683
+ ;
684
+ "use strict";
685
+ var $;
686
+ (function ($) {
687
+ let $mol_wire_cursor;
688
+ (function ($mol_wire_cursor) {
689
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
690
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
691
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
692
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
693
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
694
+ })($ || ($ = {}));
695
+
696
+ ;
697
+ "use strict";
698
+ var $;
699
+ (function ($) {
700
+ class $mol_wire_pub extends Object {
701
+ constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
702
+ super();
703
+ this[Symbol.toStringTag] = id;
704
+ }
705
+ [Symbol.toStringTag];
706
+ data = [];
707
+ static get [Symbol.species]() {
708
+ return Array;
709
+ }
710
+ sub_from = 0;
711
+ get sub_list() {
712
+ const res = [];
713
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
714
+ res.push(this.data[i]);
715
+ }
716
+ return res;
717
+ }
718
+ get sub_empty() {
719
+ return this.sub_from === this.data.length;
720
+ }
721
+ sub_on(sub, pub_pos) {
722
+ const pos = this.data.length;
723
+ this.data.push(sub, pub_pos);
724
+ return pos;
725
+ }
726
+ sub_off(sub_pos) {
727
+ if (!(sub_pos < this.data.length)) {
728
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
729
+ }
730
+ const end = this.data.length - 2;
731
+ if (sub_pos !== end) {
732
+ this.peer_move(end, sub_pos);
733
+ }
734
+ this.data.length = end;
735
+ if (end === this.sub_from)
736
+ this.reap();
737
+ }
738
+ reap() { }
739
+ promote() {
740
+ $mol_wire_auto()?.track_next(this);
741
+ }
742
+ fresh() { }
743
+ complete() { }
744
+ get incompleted() {
745
+ return false;
746
+ }
747
+ emit(quant = $mol_wire_cursor.stale) {
748
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
749
+ ;
750
+ this.data[i].absorb(quant, this.data[i + 1]);
751
+ }
752
+ }
753
+ peer_move(from_pos, to_pos) {
754
+ const peer = this.data[from_pos];
755
+ const self_pos = this.data[from_pos + 1];
756
+ this.data[to_pos] = peer;
757
+ this.data[to_pos + 1] = self_pos;
758
+ peer.peer_repos(self_pos, to_pos);
759
+ }
760
+ peer_repos(peer_pos, self_pos) {
761
+ this.data[peer_pos + 1] = self_pos;
762
+ }
763
+ }
764
+ $.$mol_wire_pub = $mol_wire_pub;
765
+ })($ || ($ = {}));
766
+
767
+ ;
768
+ "use strict";
769
+
770
+ ;
771
+ "use strict";
772
+ var $;
773
+ (function ($) {
774
+ $.$mol_wire_auto_sub = null;
775
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
776
+ return $.$mol_wire_auto_sub = next;
777
+ }
778
+ $.$mol_wire_auto = $mol_wire_auto;
779
+ $.$mol_wire_affected = [];
780
+ })($ || ($ = {}));
781
+
782
+ ;
783
+ "use strict";
784
+ var $;
785
+ (function ($) {
786
+ $['devtoolsFormatters'] ||= [];
787
+ function $mol_dev_format_register(config) {
788
+ $['devtoolsFormatters'].push(config);
789
+ }
790
+ $.$mol_dev_format_register = $mol_dev_format_register;
791
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
792
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
793
+ function $mol_dev_format_button(label, click) {
794
+ return $mol_dev_format_auto({
795
+ [$.$mol_dev_format_head]() {
796
+ return $.$mol_dev_format_span({ color: 'cornflowerblue' }, label);
797
+ },
798
+ [$.$mol_dev_format_body]() {
799
+ Promise.resolve().then(click);
800
+ return $.$mol_dev_format_span({});
801
+ }
802
+ });
803
+ }
804
+ $mol_dev_format_register({
805
+ header: (val, config = false) => {
806
+ if (config)
807
+ return null;
808
+ if (!val)
809
+ return null;
810
+ if ($.$mol_dev_format_head in val) {
811
+ try {
812
+ return val[$.$mol_dev_format_head]();
813
+ }
814
+ catch (error) {
815
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
816
+ }
817
+ }
818
+ if (typeof val === 'function') {
819
+ return $mol_dev_format_native(val);
820
+ }
821
+ if (val instanceof Error) {
822
+ return $.$mol_dev_format_span({}, $mol_dev_format_native(val), ' ', $mol_dev_format_button('throw', () => $mol_fail_hidden(val)));
823
+ }
824
+ if (val instanceof Promise) {
825
+ return $.$mol_dev_format_shade($mol_dev_format_native(val), ' ', val[Symbol.toStringTag] ?? '');
826
+ }
827
+ if (Symbol.toStringTag in val) {
828
+ return $mol_dev_format_native(val);
829
+ }
830
+ return null;
831
+ },
832
+ hasBody: (val, config = false) => {
833
+ if (config)
834
+ return false;
835
+ if (!val)
836
+ return false;
837
+ if (val[$.$mol_dev_format_body])
838
+ return true;
839
+ return false;
840
+ },
841
+ body: (val, config = false) => {
842
+ if (config)
843
+ return null;
844
+ if (!val)
845
+ return null;
846
+ if ($.$mol_dev_format_body in val) {
847
+ try {
848
+ return val[$.$mol_dev_format_body]();
849
+ }
850
+ catch (error) {
851
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
852
+ }
853
+ }
854
+ return null;
855
+ },
856
+ });
857
+ function $mol_dev_format_native(obj) {
858
+ if (typeof obj === 'undefined')
859
+ return $.$mol_dev_format_shade('undefined');
860
+ return [
861
+ 'object',
862
+ {
863
+ object: obj,
864
+ config: true,
865
+ },
866
+ ];
867
+ }
868
+ $.$mol_dev_format_native = $mol_dev_format_native;
869
+ function $mol_dev_format_auto(obj) {
870
+ if (obj == null)
871
+ return $.$mol_dev_format_shade(String(obj));
872
+ return [
873
+ 'object',
874
+ {
875
+ object: obj,
876
+ config: false,
877
+ },
878
+ ];
879
+ }
880
+ $.$mol_dev_format_auto = $mol_dev_format_auto;
881
+ function $mol_dev_format_element(element, style, ...content) {
882
+ const styles = [];
883
+ for (let key in style)
884
+ styles.push(`${key} : ${style[key]}`);
885
+ return [
886
+ element,
887
+ {
888
+ style: styles.join(' ; '),
889
+ },
890
+ ...content,
891
+ ];
892
+ }
893
+ $.$mol_dev_format_element = $mol_dev_format_element;
894
+ $.$mol_dev_format_span = $mol_dev_format_element.bind(null, 'span');
895
+ $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
896
+ $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
897
+ $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
898
+ $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
899
+ $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
900
+ $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
901
+ $.$mol_dev_format_accent = $.$mol_dev_format_span.bind(null, {
902
+ 'color': 'magenta',
903
+ });
904
+ $.$mol_dev_format_strong = $.$mol_dev_format_span.bind(null, {
905
+ 'font-weight': 'bold',
906
+ });
907
+ $.$mol_dev_format_string = $.$mol_dev_format_span.bind(null, {
908
+ 'color': 'green',
909
+ });
910
+ $.$mol_dev_format_shade = $.$mol_dev_format_span.bind(null, {
911
+ 'color': 'gray',
912
+ });
913
+ $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
914
+ 'margin-left': '13px'
915
+ });
916
+ class Stack extends Array {
917
+ toString() {
918
+ return this.join('\n');
919
+ }
920
+ }
921
+ class Call extends Object {
922
+ type;
923
+ function;
924
+ method;
925
+ eval;
926
+ source;
927
+ offset;
928
+ pos;
929
+ object;
930
+ flags;
931
+ [Symbol.toStringTag];
932
+ constructor(call) {
933
+ super();
934
+ this.type = call.getTypeName() ?? '';
935
+ this.function = call.getFunctionName() ?? '';
936
+ this.method = call.getMethodName() ?? '';
937
+ if (this.method === this.function)
938
+ this.method = '';
939
+ this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
940
+ this.eval = call.getEvalOrigin() ?? '';
941
+ this.source = call.getScriptNameOrSourceURL() ?? '';
942
+ this.object = call.getThis();
943
+ this.offset = call.getPosition();
944
+ const flags = [];
945
+ if (call.isAsync())
946
+ flags.push('async');
947
+ if (call.isConstructor())
948
+ flags.push('constructor');
949
+ if (call.isEval())
950
+ flags.push('eval');
951
+ if (call.isNative())
952
+ flags.push('native');
953
+ if (call.isPromiseAll())
954
+ flags.push('PromiseAll');
955
+ if (call.isToplevel())
956
+ flags.push('top');
957
+ this.flags = flags;
958
+ const type = this.type ? this.type + '.' : '';
959
+ const func = this.function || '<anon>';
960
+ const method = this.method ? ' [' + this.method + '] ' : '';
961
+ this[Symbol.toStringTag] = `${type}${func}${method}`;
962
+ }
963
+ [Symbol.toPrimitive]() {
964
+ return this.toString();
965
+ }
966
+ toString() {
967
+ const object = this.object || '';
968
+ const label = this[Symbol.toStringTag];
969
+ const source = `${this.source}:${this.pos.join(':')} #${this.offset}`;
970
+ return `\tat ${object}${label} (${source})`;
971
+ }
972
+ [$.$mol_dev_format_head]() {
973
+ return $.$mol_dev_format_div({}, $mol_dev_format_native(this), $.$mol_dev_format_shade(' '), ...this.object ? [
974
+ $mol_dev_format_native(this.object),
975
+ ] : [], ...this.method ? [$.$mol_dev_format_shade(' ', ' [', this.method, ']')] : [], $.$mol_dev_format_shade(' ', this.flags.join(', ')));
976
+ }
977
+ }
978
+ Error.prepareStackTrace ??= (error, stack) => new Stack(...stack.map(call => new Call(call)));
979
+ })($ || ($ = {}));
980
+
981
+ ;
982
+ "use strict";
983
+ var $;
984
+ (function ($) {
985
+ class $mol_wire_pub_sub extends $mol_wire_pub {
986
+ pub_from = 0;
987
+ cursor = $mol_wire_cursor.stale;
988
+ get temp() {
989
+ return false;
990
+ }
991
+ get pub_list() {
992
+ const res = [];
993
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
994
+ for (let i = this.pub_from; i < max; i += 2) {
995
+ if (this.data[i])
996
+ res.push(this.data[i]);
997
+ }
998
+ return res;
999
+ }
1000
+ track_on() {
1001
+ this.cursor = this.pub_from;
1002
+ const sub = $mol_wire_auto();
1003
+ $mol_wire_auto(this);
1004
+ return sub;
1005
+ }
1006
+ promote() {
1007
+ if (this.cursor >= this.pub_from) {
1008
+ $mol_fail(new Error('Circular subscription'));
1009
+ }
1010
+ super.promote();
1011
+ }
1012
+ track_next(pub) {
1013
+ if (this.cursor < 0)
1014
+ $mol_fail(new Error('Promo to non begun sub'));
1015
+ if (this.cursor < this.sub_from) {
1016
+ const next = this.data[this.cursor];
1017
+ if (pub === undefined)
1018
+ return next ?? null;
1019
+ if (next === pub) {
1020
+ this.cursor += 2;
1021
+ return next;
1022
+ }
1023
+ if (next) {
1024
+ if (this.sub_from < this.data.length) {
1025
+ this.peer_move(this.sub_from, this.data.length);
1026
+ }
1027
+ this.peer_move(this.cursor, this.sub_from);
1028
+ this.sub_from += 2;
1029
+ }
1030
+ }
1031
+ else {
1032
+ if (pub === undefined)
1033
+ return null;
1034
+ if (this.sub_from < this.data.length) {
1035
+ this.peer_move(this.sub_from, this.data.length);
1036
+ }
1037
+ this.sub_from += 2;
1038
+ }
1039
+ this.data[this.cursor] = pub;
1040
+ this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
1041
+ this.cursor += 2;
1042
+ return pub;
1043
+ }
1044
+ track_off(sub) {
1045
+ $mol_wire_auto(sub);
1046
+ if (this.cursor < 0) {
1047
+ $mol_fail(new Error('End of non begun sub'));
1048
+ }
1049
+ for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
1050
+ const pub = this.data[cursor];
1051
+ pub.fresh();
1052
+ }
1053
+ this.cursor = $mol_wire_cursor.fresh;
1054
+ }
1055
+ pub_off(sub_pos) {
1056
+ this.data[sub_pos] = undefined;
1057
+ this.data[sub_pos + 1] = undefined;
1058
+ }
1059
+ destructor() {
1060
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
1061
+ const sub = this.data[cursor];
1062
+ const pos = this.data[cursor + 1];
1063
+ sub.pub_off(pos);
1064
+ }
1065
+ this.data.length = this.sub_from;
1066
+ this.cursor = this.pub_from;
1067
+ this.track_cut();
1068
+ this.cursor = $mol_wire_cursor.stale;
1069
+ }
1070
+ track_cut() {
1071
+ if (this.cursor < this.pub_from) {
1072
+ $mol_fail(new Error('Cut of non begun sub'));
1073
+ }
1074
+ let end = this.data.length;
1075
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
1076
+ const pub = this.data[cursor];
1077
+ pub?.sub_off(this.data[cursor + 1]);
1078
+ end -= 2;
1079
+ if (this.sub_from <= end)
1080
+ this.peer_move(end, cursor);
1081
+ }
1082
+ this.data.length = end;
1083
+ this.sub_from = this.cursor;
1084
+ }
1085
+ complete() { }
1086
+ complete_pubs() {
1087
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
1088
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1089
+ const pub = this.data[cursor];
1090
+ if (pub?.incompleted)
1091
+ return;
1092
+ }
1093
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1094
+ const pub = this.data[cursor];
1095
+ pub?.complete();
1096
+ }
1097
+ }
1098
+ absorb(quant = $mol_wire_cursor.stale, pos = -1) {
1099
+ if (this.cursor === $mol_wire_cursor.final)
1100
+ return;
1101
+ if (this.cursor >= quant)
1102
+ return;
1103
+ this.cursor = quant;
1104
+ this.emit($mol_wire_cursor.doubt);
1105
+ }
1106
+ [$mol_dev_format_head]() {
1107
+ return $mol_dev_format_native(this);
1108
+ }
1109
+ get pub_empty() {
1110
+ return this.sub_from === this.pub_from;
1111
+ }
1112
+ }
1113
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
1114
+ })($ || ($ = {}));
1115
+
1116
+ ;
1117
+ "use strict";
1118
+ var $;
1119
+ (function ($_1) {
1120
+ $mol_test({
1121
+ 'Collect deps'() {
1122
+ const pub1 = new $mol_wire_pub;
1123
+ const pub2 = new $mol_wire_pub;
1124
+ const sub = new $mol_wire_pub_sub;
1125
+ const bu1 = sub.track_on();
1126
+ try {
1127
+ pub1.promote();
1128
+ pub2.promote();
1129
+ pub2.promote();
1130
+ }
1131
+ finally {
1132
+ sub.track_cut();
1133
+ sub.track_off(bu1);
1134
+ }
1135
+ pub1.emit();
1136
+ pub2.emit();
1137
+ $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
1138
+ const bu2 = sub.track_on();
1139
+ try {
1140
+ pub1.promote();
1141
+ pub1.promote();
1142
+ pub2.promote();
1143
+ }
1144
+ finally {
1145
+ sub.track_cut();
1146
+ sub.track_off(bu2);
1147
+ }
1148
+ pub1.emit();
1149
+ pub2.emit();
1150
+ $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
1151
+ },
1152
+ 'cyclic detection'($) {
1153
+ const sub1 = new $mol_wire_pub_sub;
1154
+ const sub2 = new $mol_wire_pub_sub;
1155
+ const bu1 = sub1.track_on();
1156
+ try {
1157
+ const bu2 = sub2.track_on();
1158
+ try {
1159
+ $mol_assert_fail(() => sub1.promote(), 'Circular subscription');
1160
+ }
1161
+ finally {
1162
+ sub2.track_cut();
1163
+ sub2.track_off(bu2);
1164
+ }
1165
+ }
1166
+ finally {
1167
+ sub1.track_cut();
1168
+ sub1.track_off(bu1);
1169
+ }
1170
+ },
1171
+ });
1172
+ })($ || ($ = {}));
1173
+
1174
+ ;
1175
+ "use strict";
1176
+ var $;
1177
+ (function ($) {
1178
+ $.$mol_after_mock_queue = [];
1179
+ function $mol_after_mock_warp() {
1180
+ const queue = $.$mol_after_mock_queue.splice(0);
1181
+ for (const task of queue)
1182
+ task();
1183
+ }
1184
+ $.$mol_after_mock_warp = $mol_after_mock_warp;
1185
+ class $mol_after_mock_commmon extends $mol_object2 {
1186
+ task;
1187
+ promise = Promise.resolve();
1188
+ cancelled = false;
1189
+ id;
1190
+ constructor(task) {
1191
+ super();
1192
+ this.task = task;
1193
+ $.$mol_after_mock_queue.push(task);
1194
+ }
1195
+ destructor() {
1196
+ const index = $.$mol_after_mock_queue.indexOf(this.task);
1197
+ if (index >= 0)
1198
+ $.$mol_after_mock_queue.splice(index, 1);
1199
+ }
1200
+ }
1201
+ $.$mol_after_mock_commmon = $mol_after_mock_commmon;
1202
+ class $mol_after_mock_timeout extends $mol_after_mock_commmon {
1203
+ delay;
1204
+ constructor(delay, task) {
1205
+ super(task);
1206
+ this.delay = delay;
1207
+ }
1208
+ }
1209
+ $.$mol_after_mock_timeout = $mol_after_mock_timeout;
1210
+ })($ || ($ = {}));
1211
+
1212
+ ;
1213
+ "use strict";
1214
+ var $;
1215
+ (function ($) {
1216
+ class $mol_after_tick extends $mol_object2 {
1217
+ task;
1218
+ static promise = null;
1219
+ cancelled = false;
1220
+ constructor(task) {
1221
+ super();
1222
+ this.task = task;
1223
+ if (!$mol_after_tick.promise)
1224
+ $mol_after_tick.promise = Promise.resolve().then(() => {
1225
+ $mol_after_tick.promise = null;
1226
+ });
1227
+ $mol_after_tick.promise.then(() => {
1228
+ if (this.cancelled)
1229
+ return;
1230
+ task();
1231
+ });
1232
+ }
1233
+ destructor() {
1234
+ this.cancelled = true;
1235
+ }
1236
+ }
1237
+ $.$mol_after_tick = $mol_after_tick;
1238
+ })($ || ($ = {}));
1239
+
1240
+ ;
1241
+ "use strict";
1242
+ var $;
1243
+ (function ($_1) {
1244
+ $mol_test_mocks.push($ => {
1245
+ $.$mol_after_tick = $mol_after_mock_commmon;
1246
+ });
1247
+ })($ || ($ = {}));
1248
+
1249
+ ;
1250
+ "use strict";
1251
+ var $;
1252
+ (function ($) {
1253
+ const wrappers = new WeakMap();
1254
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
1255
+ task;
1256
+ host;
1257
+ static warm = true;
1258
+ static planning = new Set();
1259
+ static reaping = new Set();
1260
+ static plan_task = null;
1261
+ static plan() {
1262
+ if (this.plan_task)
1263
+ return;
1264
+ this.plan_task = new $mol_after_tick(() => {
1265
+ try {
1266
+ this.sync();
1267
+ }
1268
+ finally {
1269
+ $mol_wire_fiber.plan_task = null;
1270
+ }
1271
+ });
1272
+ }
1273
+ static sync() {
1274
+ while (this.planning.size) {
1275
+ for (const fiber of this.planning) {
1276
+ this.planning.delete(fiber);
1277
+ if (fiber.cursor >= 0)
1278
+ continue;
1279
+ if (fiber.cursor === $mol_wire_cursor.final)
1280
+ continue;
1281
+ fiber.fresh();
1282
+ }
1283
+ }
1284
+ while (this.reaping.size) {
1285
+ const fibers = this.reaping;
1286
+ this.reaping = new Set;
1287
+ for (const fiber of fibers) {
1288
+ if (!fiber.sub_empty)
1289
+ continue;
1290
+ fiber.destructor();
1291
+ }
1292
+ }
1293
+ }
1294
+ cache = undefined;
1295
+ get args() {
1296
+ return this.data.slice(0, this.pub_from);
1297
+ }
1298
+ result() {
1299
+ if ($mol_promise_like(this.cache))
1300
+ return;
1301
+ if (this.cache instanceof Error)
1302
+ return;
1303
+ return this.cache;
1304
+ }
1305
+ get incompleted() {
1306
+ return $mol_promise_like(this.cache);
1307
+ }
1308
+ field() {
1309
+ return this.task.name + '()';
1310
+ }
1311
+ constructor(id, task, host, args) {
1312
+ super(id);
1313
+ this.task = task;
1314
+ this.host = host;
1315
+ if (args)
1316
+ this.data.push(...args);
1317
+ this.pub_from = this.sub_from = args?.length ?? 0;
1318
+ }
1319
+ plan() {
1320
+ $mol_wire_fiber.planning.add(this);
1321
+ $mol_wire_fiber.plan();
1322
+ return this;
1323
+ }
1324
+ reap() {
1325
+ $mol_wire_fiber.reaping.add(this);
1326
+ $mol_wire_fiber.plan();
1327
+ }
1328
+ toString() {
1329
+ return this[Symbol.toStringTag];
1330
+ }
1331
+ toJSON() {
1332
+ return this[Symbol.toStringTag];
1333
+ }
1334
+ [$mol_dev_format_head]() {
1335
+ const cursor = {
1336
+ [$mol_wire_cursor.stale]: '🔴',
1337
+ [$mol_wire_cursor.doubt]: '🟡',
1338
+ [$mol_wire_cursor.fresh]: '🟢',
1339
+ [$mol_wire_cursor.final]: '🔵',
1340
+ }[this.cursor] ?? this.cursor.toString();
1341
+ return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1342
+ ? $mol_dev_format_shade(cursor)
1343
+ : $mol_dev_format_shade(this[Symbol.toStringTag], cursor), $mol_dev_format_auto(this.cache));
1344
+ }
1345
+ [$mol_dev_format_body]() { return null; }
1346
+ get $() {
1347
+ return (this.host ?? this.task)['$'];
1348
+ }
1349
+ emit(quant = $mol_wire_cursor.stale) {
1350
+ if (this.sub_empty)
1351
+ this.plan();
1352
+ else
1353
+ super.emit(quant);
1354
+ }
1355
+ fresh() {
1356
+ if (this.cursor === $mol_wire_cursor.fresh)
1357
+ return;
1358
+ if (this.cursor === $mol_wire_cursor.final)
1359
+ return;
1360
+ check: if (this.cursor === $mol_wire_cursor.doubt) {
1361
+ for (let i = this.pub_from; i < this.sub_from; i += 2) {
1362
+ ;
1363
+ this.data[i]?.fresh();
1364
+ if (this.cursor !== $mol_wire_cursor.doubt)
1365
+ break check;
1366
+ }
1367
+ this.cursor = $mol_wire_cursor.fresh;
1368
+ return;
1369
+ }
1370
+ const bu = this.track_on();
1371
+ let result;
1372
+ try {
1373
+ switch (this.pub_from) {
1374
+ case 0:
1375
+ result = this.task.call(this.host);
1376
+ break;
1377
+ case 1:
1378
+ result = this.task.call(this.host, this.data[0]);
1379
+ break;
1380
+ default:
1381
+ result = this.task.call(this.host, ...this.args);
1382
+ break;
1383
+ }
1384
+ if ($mol_promise_like(result)) {
1385
+ if (wrappers.has(result)) {
1386
+ result = wrappers.get(result).then(a => a);
1387
+ }
1388
+ else {
1389
+ const put = (res) => {
1390
+ if (this.cache === result)
1391
+ this.put(res);
1392
+ return res;
1393
+ };
1394
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1395
+ wrappers.set(result, result);
1396
+ const error = new Error(`Promise in ${this}`);
1397
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1398
+ }
1399
+ }
1400
+ }
1401
+ catch (error) {
1402
+ if (error instanceof Error || $mol_promise_like(error)) {
1403
+ result = error;
1404
+ }
1405
+ else {
1406
+ result = new Error(String(error), { cause: error });
1407
+ }
1408
+ if ($mol_promise_like(result)) {
1409
+ if (wrappers.has(result)) {
1410
+ result = wrappers.get(result);
1411
+ }
1412
+ else {
1413
+ const put = (v) => {
1414
+ if (this.cache === result)
1415
+ this.absorb();
1416
+ return v;
1417
+ };
1418
+ wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
1419
+ const error = new Error(`Promise in ${this}`);
1420
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1421
+ }
1422
+ }
1423
+ }
1424
+ if (!$mol_promise_like(result)) {
1425
+ this.track_cut();
1426
+ }
1427
+ this.track_off(bu);
1428
+ this.put(result);
1429
+ return this;
1430
+ }
1431
+ refresh() {
1432
+ this.cursor = $mol_wire_cursor.stale;
1433
+ this.fresh();
1434
+ }
1435
+ sync() {
1436
+ if (!$mol_wire_fiber.warm) {
1437
+ return this.result();
1438
+ }
1439
+ this.promote();
1440
+ this.fresh();
1441
+ if (this.cache instanceof Error) {
1442
+ return $mol_fail_hidden(this.cache);
1443
+ }
1444
+ if ($mol_promise_like(this.cache)) {
1445
+ return $mol_fail_hidden(this.cache);
1446
+ }
1447
+ return this.cache;
1448
+ }
1449
+ async async_raw() {
1450
+ while (true) {
1451
+ this.fresh();
1452
+ if (this.cache instanceof Error) {
1453
+ $mol_fail_hidden(this.cache);
1454
+ }
1455
+ if (!$mol_promise_like(this.cache))
1456
+ return this.cache;
1457
+ await Promise.race([this.cache, this.step()]);
1458
+ if (!$mol_promise_like(this.cache))
1459
+ return this.cache;
1460
+ if (this.cursor === $mol_wire_cursor.final) {
1461
+ await new Promise(() => { });
1462
+ }
1463
+ }
1464
+ }
1465
+ async() {
1466
+ const promise = this.async_raw();
1467
+ if (!promise.destructor)
1468
+ promise.destructor = () => this.destructor();
1469
+ return promise;
1470
+ }
1471
+ step() {
1472
+ return new Promise(done => {
1473
+ const sub = new $mol_wire_pub_sub;
1474
+ const prev = sub.track_on();
1475
+ sub.track_next(this);
1476
+ sub.track_off(prev);
1477
+ sub.absorb = () => {
1478
+ done(null);
1479
+ setTimeout(() => sub.destructor());
1480
+ };
1481
+ });
1482
+ }
1483
+ destructor() {
1484
+ super.destructor();
1485
+ $mol_wire_fiber.planning.delete(this);
1486
+ if (!$mol_owning_check(this, this.cache))
1487
+ return;
1488
+ try {
1489
+ this.cache.destructor();
1490
+ }
1491
+ catch (result) {
1492
+ if ($mol_promise_like(result)) {
1493
+ const error = new Error(`Promise in ${this}.destructor()`);
1494
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1495
+ }
1496
+ $mol_fail_hidden(result);
1497
+ }
1498
+ }
1499
+ }
1500
+ $.$mol_wire_fiber = $mol_wire_fiber;
1501
+ })($ || ($ = {}));
1502
+
1503
+ ;
1504
+ "use strict";
1505
+ var $;
1506
+ (function ($) {
1507
+ $mol_test({
1508
+ 'Sync execution'() {
1509
+ class Sync extends $mol_object2 {
1510
+ static calc(a, b) {
1511
+ return a + b;
1512
+ }
1513
+ }
1514
+ __decorate([
1515
+ $mol_wire_method
1516
+ ], Sync, "calc", null);
1517
+ $mol_assert_equal(Sync.calc(1, 2), 3);
1518
+ },
1519
+ async 'async <=> sync'() {
1520
+ class SyncAsync extends $mol_object2 {
1521
+ static async val(a) {
1522
+ return a;
1523
+ }
1524
+ static sum(a, b) {
1525
+ const syn = $mol_wire_sync(this);
1526
+ return syn.val(a) + syn.val(b);
1527
+ }
1528
+ static async calc(a, b) {
1529
+ return 5 + await $mol_wire_async(this).sum(a, b);
1530
+ }
1531
+ }
1532
+ $mol_assert_equal(await SyncAsync.calc(1, 2), 8);
1533
+ },
1534
+ async 'Idempotence control'() {
1535
+ class Idempotence extends $mol_object2 {
1536
+ static logs_idemp = 0;
1537
+ static logs_unidemp = 0;
1538
+ static log_idemp() {
1539
+ this.logs_idemp += 1;
1540
+ }
1541
+ static log_unidemp() {
1542
+ this.logs_unidemp += 1;
1543
+ }
1544
+ static async val(a) {
1545
+ return a;
1546
+ }
1547
+ static sum(a, b) {
1548
+ this.log_idemp();
1549
+ this.log_unidemp();
1550
+ const syn = $mol_wire_sync(this);
1551
+ return syn.val(a) + syn.val(b);
1552
+ }
1553
+ static async calc(a, b) {
1554
+ return 5 + await $mol_wire_async(this).sum(a, b);
1555
+ }
1556
+ }
1557
+ __decorate([
1558
+ $mol_wire_method
1559
+ ], Idempotence, "log_idemp", null);
1560
+ $mol_assert_equal(await Idempotence.calc(1, 2), 8);
1561
+ $mol_assert_equal(Idempotence.logs_idemp, 1);
1562
+ $mol_assert_equal(Idempotence.logs_unidemp, 3);
1563
+ },
1564
+ async 'Error handling'() {
1565
+ class Handle extends $mol_object2 {
1566
+ static async sum(a, b) {
1567
+ $mol_fail(new Error('test error ' + (a + b)));
1568
+ }
1569
+ static check() {
1570
+ try {
1571
+ return $mol_wire_sync(Handle).sum(1, 2);
1572
+ }
1573
+ catch (error) {
1574
+ if ($mol_promise_like(error))
1575
+ $mol_fail_hidden(error);
1576
+ $mol_assert_equal(error.message, 'test error 3');
1577
+ }
1578
+ }
1579
+ }
1580
+ await $mol_wire_async(Handle).check();
1581
+ },
1582
+ });
1583
+ })($ || ($ = {}));
1584
+
1585
+ ;
1586
+ "use strict";
1587
+ var $;
1588
+ (function ($) {
1589
+ function $mol_log3_area_lazy(event) {
1590
+ const self = this.$;
1591
+ const stack = self.$mol_log3_stack;
1592
+ const deep = stack.length;
1593
+ let logged = false;
1594
+ stack.push(() => {
1595
+ logged = true;
1596
+ self.$mol_log3_area.call(self, event);
1597
+ });
1598
+ return () => {
1599
+ if (logged)
1600
+ self.console.groupEnd();
1601
+ if (stack.length > deep)
1602
+ stack.length = deep;
1603
+ };
1604
+ }
1605
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1606
+ $.$mol_log3_stack = [];
1607
+ })($ || ($ = {}));
1608
+
1609
+ ;
1610
+ "use strict";
1611
+ var $;
1612
+ (function ($) {
1613
+ class $mol_term_color {
1614
+ static reset = this.ansi(0, 0);
1615
+ static bold = this.ansi(1, 22);
1616
+ static italic = this.ansi(3, 23);
1617
+ static underline = this.ansi(4, 24);
1618
+ static inverse = this.ansi(7, 27);
1619
+ static hidden = this.ansi(8, 28);
1620
+ static strike = this.ansi(9, 29);
1621
+ static gray = this.ansi(90, 39);
1622
+ static red = this.ansi(91, 39);
1623
+ static green = this.ansi(92, 39);
1624
+ static yellow = this.ansi(93, 39);
1625
+ static blue = this.ansi(94, 39);
1626
+ static magenta = this.ansi(95, 39);
1627
+ static cyan = this.ansi(96, 39);
1628
+ static Gray = (str) => this.inverse(this.gray(str));
1629
+ static Red = (str) => this.inverse(this.red(str));
1630
+ static Green = (str) => this.inverse(this.green(str));
1631
+ static Yellow = (str) => this.inverse(this.yellow(str));
1632
+ static Blue = (str) => this.inverse(this.blue(str));
1633
+ static Magenta = (str) => this.inverse(this.magenta(str));
1634
+ static Cyan = (str) => this.inverse(this.cyan(str));
1635
+ static ansi(open, close) {
1636
+ if (typeof process === 'undefined')
1637
+ return String;
1638
+ if (!process.stdout.isTTY)
1639
+ return String;
1640
+ const prefix = `\x1b[${open}m`;
1641
+ const postfix = `\x1b[${close}m`;
1642
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1643
+ return function colorer(str) {
1644
+ str = String(str);
1645
+ if (str === '')
1646
+ return str;
1647
+ const suffix = str.replace(suffix_regexp, prefix);
1648
+ return prefix + suffix + postfix;
1649
+ };
1650
+ }
1651
+ }
1652
+ $.$mol_term_color = $mol_term_color;
1653
+ })($ || ($ = {}));
1654
+
1655
+ ;
1656
+ "use strict";
1657
+ var $;
1658
+ (function ($) {
1659
+ function $mol_log3_node_make(level, output, type, color) {
1660
+ return function $mol_log3_logger(event) {
1661
+ if (!event.time)
1662
+ event = { time: new Date().toISOString(), ...event };
1663
+ let tree = this.$mol_tree2_from_json(event);
1664
+ tree = tree.struct(type, tree.kids);
1665
+ let str = color(tree.toString());
1666
+ this.console[level](str);
1667
+ const self = this;
1668
+ return () => self.console.groupEnd();
1669
+ };
1670
+ }
1671
+ $.$mol_log3_node_make = $mol_log3_node_make;
1672
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1673
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1674
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1675
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1676
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1677
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1678
+ })($ || ($ = {}));
1679
+
1680
+ ;
1681
+ "use strict";
1682
+ var $;
1683
+ (function ($_1) {
1684
+ $mol_test_mocks.push($ => {
1685
+ $.$mol_log3_come = () => { };
1686
+ $.$mol_log3_done = () => { };
1687
+ $.$mol_log3_fail = () => { };
1688
+ $.$mol_log3_warn = () => { };
1689
+ $.$mol_log3_rise = () => { };
1690
+ $.$mol_log3_area = () => () => { };
1691
+ });
1692
+ })($ || ($ = {}));
1693
+
1694
+ ;
1695
+ "use strict";
1696
+ var $;
1697
+ (function ($) {
1698
+ class $mol_wire_task extends $mol_wire_fiber {
1699
+ static getter(task) {
1700
+ return function $mol_wire_task_get(host, args) {
1701
+ const sub = $mol_wire_auto();
1702
+ const existen = sub?.track_next();
1703
+ let cause = '';
1704
+ reuse: if (existen) {
1705
+ if (!existen.temp)
1706
+ break reuse;
1707
+ if (existen.task !== task) {
1708
+ cause = 'task';
1709
+ break reuse;
1710
+ }
1711
+ if (existen.host !== host) {
1712
+ cause = 'host';
1713
+ break reuse;
1714
+ }
1715
+ if (!$mol_compare_deep(existen.args, args)) {
1716
+ cause = 'args';
1717
+ break reuse;
1718
+ }
1719
+ return existen;
1720
+ }
1721
+ const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
1722
+ const next = new $mol_wire_task(key, task, host, args);
1723
+ if (existen?.temp) {
1724
+ $$.$mol_log3_warn({
1725
+ place: '$mol_wire_task',
1726
+ message: `Different ${cause} on restart`,
1727
+ sub,
1728
+ prev: existen,
1729
+ next,
1730
+ hint: 'Maybe required additional memoization',
1731
+ });
1732
+ }
1733
+ return next;
1734
+ };
1735
+ }
1736
+ get temp() {
1737
+ return true;
1738
+ }
1739
+ complete() {
1740
+ if ($mol_promise_like(this.cache))
1741
+ return;
1742
+ this.destructor();
1743
+ }
1744
+ put(next) {
1745
+ const prev = this.cache;
1746
+ this.cache = next;
1747
+ if ($mol_promise_like(next)) {
1748
+ this.cursor = $mol_wire_cursor.fresh;
1749
+ if (next !== prev)
1750
+ this.emit();
1751
+ if ($mol_owning_catch(this, next)) {
1752
+ try {
1753
+ next[Symbol.toStringTag] = this[Symbol.toStringTag];
1754
+ }
1755
+ catch {
1756
+ Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1757
+ }
1758
+ }
1759
+ return next;
1760
+ }
1761
+ this.cursor = $mol_wire_cursor.final;
1762
+ if (this.sub_empty)
1763
+ this.destructor();
1764
+ else if (next !== prev)
1765
+ this.emit();
1766
+ return next;
1767
+ }
1768
+ destructor() {
1769
+ super.destructor();
1770
+ this.cursor = $mol_wire_cursor.final;
1771
+ }
1772
+ }
1773
+ $.$mol_wire_task = $mol_wire_task;
1774
+ })($ || ($ = {}));
1775
+
1776
+ ;
1777
+ "use strict";
1778
+ var $;
1779
+ (function ($) {
1780
+ function $mol_wire_method(host, field, descr) {
1781
+ if (!descr)
1782
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1783
+ const orig = descr?.value ?? host[field];
1784
+ const sup = Reflect.getPrototypeOf(host);
1785
+ if (typeof sup[field] === 'function') {
1786
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1787
+ }
1788
+ const temp = $mol_wire_task.getter(orig);
1789
+ const value = function (...args) {
1790
+ const fiber = temp(this ?? null, args);
1791
+ return fiber.sync();
1792
+ };
1793
+ Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1794
+ Object.assign(value, { orig });
1795
+ const descr2 = { ...descr, value };
1796
+ Reflect.defineProperty(host, field, descr2);
1797
+ return descr2;
1798
+ }
1799
+ $.$mol_wire_method = $mol_wire_method;
1800
+ })($ || ($ = {}));
1801
+
1802
+ ;
1803
+ "use strict";
1804
+ var $;
1805
+ (function ($) {
1806
+ function $mol_wire_async(obj) {
1807
+ let fiber;
1808
+ const temp = $mol_wire_task.getter(obj);
1809
+ return new Proxy(obj, {
1810
+ get(obj, field) {
1811
+ const val = obj[field];
1812
+ if (typeof val !== 'function')
1813
+ return val;
1814
+ let fiber;
1815
+ const temp = $mol_wire_task.getter(val);
1816
+ return function $mol_wire_async(...args) {
1817
+ fiber?.destructor();
1818
+ fiber = temp(obj, args);
1819
+ return fiber.async();
1820
+ };
1821
+ },
1822
+ apply(obj, self, args) {
1823
+ fiber?.destructor();
1824
+ fiber = temp(self, args);
1825
+ return fiber.async();
1826
+ },
1827
+ });
1828
+ }
1829
+ $.$mol_wire_async = $mol_wire_async;
1830
+ })($ || ($ = {}));
1831
+
1832
+ ;
1833
+ "use strict";
1834
+ var $;
1835
+ (function ($_1) {
1836
+ $mol_test({
1837
+ 'test types'($) {
1838
+ class A {
1839
+ static a() {
1840
+ return '';
1841
+ }
1842
+ static b() {
1843
+ return $mol_wire_async(this).a();
1844
+ }
1845
+ }
1846
+ },
1847
+ async 'Latest method calls wins'($) {
1848
+ class NameLogger extends $mol_object2 {
1849
+ static $ = $;
1850
+ static first = [];
1851
+ static last = [];
1852
+ static send(next) {
1853
+ $mol_wire_sync(this.first).push(next);
1854
+ $$.$mol_wait_timeout(0);
1855
+ this.last.push(next);
1856
+ }
1857
+ }
1858
+ const name = $mol_wire_async(NameLogger).send;
1859
+ name('john');
1860
+ const promise = name('jin');
1861
+ $.$mol_after_mock_warp();
1862
+ await promise;
1863
+ $mol_assert_equal(NameLogger.first, ['john', 'jin']);
1864
+ $mol_assert_equal(NameLogger.last, ['jin']);
1865
+ },
1866
+ async 'Latest function calls wins'($) {
1867
+ const first = [];
1868
+ const last = [];
1869
+ function send_name(next) {
1870
+ $mol_wire_sync(first).push(next);
1871
+ $$.$mol_wait_timeout(0);
1872
+ last.push(next);
1873
+ }
1874
+ const name = $mol_wire_async(send_name);
1875
+ name('john');
1876
+ const promise = name('jin');
1877
+ $.$mol_after_mock_warp();
1878
+ await promise;
1879
+ $mol_assert_equal(first, ['john', 'jin']);
1880
+ $mol_assert_equal(last, ['jin']);
1881
+ },
1882
+ });
1883
+ })($ || ($ = {}));
1884
+
1885
+ ;
1886
+ "use strict";
1887
+ var $;
1888
+ (function ($) {
1889
+ const factories = new WeakMap();
1890
+ function factory(val) {
1891
+ let make = factories.get(val);
1892
+ if (make)
1893
+ return make;
1894
+ make = $mol_func_name_from((...args) => new val(...args), val);
1895
+ factories.set(val, make);
1896
+ return make;
1897
+ }
1898
+ const getters = new WeakMap();
1899
+ function get_prop(host, field) {
1900
+ let props = getters.get(host);
1901
+ let get_val = props?.[field];
1902
+ if (get_val)
1903
+ return get_val;
1904
+ get_val = (next) => {
1905
+ if (next !== undefined)
1906
+ host[field] = next;
1907
+ return host[field];
1908
+ };
1909
+ Object.defineProperty(get_val, 'name', { value: field });
1910
+ if (!props) {
1911
+ props = {};
1912
+ getters.set(host, props);
1913
+ }
1914
+ props[field] = get_val;
1915
+ return get_val;
1916
+ }
1917
+ function $mol_wire_sync(obj) {
1918
+ return new Proxy(obj, {
1919
+ get(obj, field) {
1920
+ let val = obj[field];
1921
+ const temp = $mol_wire_task.getter(typeof val === 'function' ? val : get_prop(obj, field));
1922
+ if (typeof val !== 'function')
1923
+ return temp(obj, []).sync();
1924
+ return function $mol_wire_sync(...args) {
1925
+ const fiber = temp(obj, args);
1926
+ return fiber.sync();
1927
+ };
1928
+ },
1929
+ set(obj, field, next) {
1930
+ const temp = $mol_wire_task.getter(get_prop(obj, field));
1931
+ temp(obj, [next]).sync();
1932
+ return true;
1933
+ },
1934
+ construct(obj, args) {
1935
+ const temp = $mol_wire_task.getter(factory(obj));
1936
+ return temp(obj, args).sync();
1937
+ },
1938
+ apply(obj, self, args) {
1939
+ const temp = $mol_wire_task.getter(obj);
1940
+ return temp(self, args).sync();
1941
+ },
1942
+ });
1943
+ }
1944
+ $.$mol_wire_sync = $mol_wire_sync;
1945
+ })($ || ($ = {}));
1946
+
1947
+ ;
1948
+ "use strict";
1949
+ var $;
1950
+ (function ($_1) {
1951
+ $mol_test({
1952
+ 'test types'($) {
1953
+ class A {
1954
+ static a() {
1955
+ return Promise.resolve('');
1956
+ }
1957
+ static b() {
1958
+ return $mol_wire_sync(this).a();
1959
+ }
1960
+ }
1961
+ },
1962
+ async 'test method from host'($) {
1963
+ let count = 0;
1964
+ class A {
1965
+ static a() {
1966
+ return $mol_wire_sync(this).b();
1967
+ }
1968
+ static b() { return Promise.resolve(++count); }
1969
+ }
1970
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
1971
+ },
1972
+ async 'test function'($) {
1973
+ let count = 0;
1974
+ class A {
1975
+ static a() {
1976
+ return $mol_wire_sync(this.b)();
1977
+ }
1978
+ static b() { return Promise.resolve(++count); }
1979
+ }
1980
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
1981
+ },
1982
+ async 'test construct itself'($) {
1983
+ class A {
1984
+ static instances = [];
1985
+ static a() {
1986
+ const a = new ($mol_wire_sync(A))();
1987
+ this.instances.push(a);
1988
+ $mol_wire_sync(this).b();
1989
+ }
1990
+ static b() { return Promise.resolve(); }
1991
+ }
1992
+ await $mol_wire_async(A).a();
1993
+ $mol_assert_equal(A.instances.length, 2);
1994
+ $mol_assert_equal(A.instances[0] instanceof A, true);
1995
+ $mol_assert_equal(A.instances[0], A.instances[1]);
1996
+ }
1997
+ });
1998
+ })($ || ($ = {}));
1999
+
2000
+ ;
2001
+ "use strict";
2002
+ var $;
2003
+ (function ($) {
2004
+ class $mol_promise extends Promise {
2005
+ done;
2006
+ fail;
2007
+ constructor(executor) {
2008
+ let done;
2009
+ let fail;
2010
+ super((d, f) => {
2011
+ done = d;
2012
+ fail = f;
2013
+ executor?.(d, f);
2014
+ });
2015
+ this.done = done;
2016
+ this.fail = fail;
2017
+ }
2018
+ }
2019
+ $.$mol_promise = $mol_promise;
2020
+ })($ || ($ = {}));
2021
+
2022
+ ;
2023
+ "use strict";
2024
+ var $;
2025
+ (function ($) {
2026
+ class $mol_after_timeout extends $mol_object2 {
2027
+ delay;
2028
+ task;
2029
+ id;
2030
+ constructor(delay, task) {
2031
+ super();
2032
+ this.delay = delay;
2033
+ this.task = task;
2034
+ this.id = setTimeout(task, delay);
2035
+ }
2036
+ destructor() {
2037
+ clearTimeout(this.id);
2038
+ }
2039
+ }
2040
+ $.$mol_after_timeout = $mol_after_timeout;
2041
+ })($ || ($ = {}));
2042
+
2043
+ ;
2044
+ "use strict";
2045
+ var $;
2046
+ (function ($_1) {
2047
+ $mol_test_mocks.push($ => {
2048
+ $.$mol_after_timeout = $mol_after_mock_timeout;
2049
+ });
2050
+ })($ || ($ = {}));
2051
+
2052
+ ;
2053
+ "use strict";
2054
+ var $;
2055
+ (function ($) {
2056
+ class $mol_after_work extends $mol_object2 {
2057
+ delay;
2058
+ task;
2059
+ id;
2060
+ constructor(delay, task) {
2061
+ super();
2062
+ this.delay = delay;
2063
+ this.task = task;
2064
+ this.id = requestIdleCallback(task, { timeout: delay });
2065
+ }
2066
+ destructor() {
2067
+ cancelIdleCallback(this.id);
2068
+ }
2069
+ }
2070
+ $.$mol_after_work = $mol_after_work;
2071
+ if (typeof requestIdleCallback !== 'function') {
2072
+ $.$mol_after_work = $mol_after_timeout;
2073
+ }
2074
+ })($ || ($ = {}));
2075
+
2076
+ ;
2077
+ "use strict";
2078
+ var $;
2079
+ (function ($_1) {
2080
+ $mol_test_mocks.push($ => {
2081
+ $.$mol_after_work = $mol_after_mock_timeout;
2082
+ });
2083
+ })($ || ($ = {}));
2084
+
2085
+ ;
2086
+ "use strict";
2087
+ var $;
2088
+ (function ($) {
2089
+ function $mol_wait_rest_async() {
2090
+ return new Promise(done => {
2091
+ new this.$mol_after_work(16, () => done(null));
2092
+ });
2093
+ }
2094
+ $.$mol_wait_rest_async = $mol_wait_rest_async;
2095
+ function $mol_wait_rest() {
2096
+ return this.$mol_wire_sync(this).$mol_wait_rest_async();
2097
+ }
2098
+ $.$mol_wait_rest = $mol_wait_rest;
2099
+ })($ || ($ = {}));
2100
+
2101
+ ;
2102
+ "use strict";
2103
+ var $;
2104
+ (function ($_1) {
2105
+ var $$;
2106
+ (function ($$) {
2107
+ $mol_test_mocks.push($ => {
2108
+ $.$mol_wait_timeout = function $mol_wait_timeout_mock(timeout) { };
2109
+ $.$mol_wait_timeout_async = async function $mol_wait_timeout_async_mock(timeout) { };
2110
+ });
2111
+ })($$ = $_1.$$ || ($_1.$$ = {}));
2112
+ })($ || ($ = {}));
2113
+
2114
+ ;
2115
+ "use strict";
2116
+ var $;
2117
+ (function ($) {
2118
+ function $mol_wait_timeout_async(timeout) {
2119
+ const promise = new $mol_promise();
2120
+ const task = new this.$mol_after_timeout(timeout, () => promise.done());
2121
+ return Object.assign(promise, {
2122
+ destructor: () => task.destructor()
2123
+ });
2124
+ }
2125
+ $.$mol_wait_timeout_async = $mol_wait_timeout_async;
2126
+ function $mol_wait_timeout(timeout) {
2127
+ return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
2128
+ }
2129
+ $.$mol_wait_timeout = $mol_wait_timeout;
2130
+ })($ || ($ = {}));
2131
+
2132
+ ;
2133
+ "use strict";
2134
+ var $;
2135
+ (function ($_1) {
2136
+ var $$;
2137
+ (function ($$) {
2138
+ $mol_test_mocks.push($ => {
2139
+ $.$mol_wait_rest = function $mol_wait_rest_mock() { };
2140
+ $.$mol_wait_rest_async = async function $mol_wait_rest_async_mock() { };
2141
+ });
2142
+ })($$ = $_1.$$ || ($_1.$$ = {}));
2143
+ })($ || ($ = {}));
2144
+
2145
+ ;
2146
+ "use strict";
2147
+ var $;
2148
+ (function ($) {
2149
+ class $mol_run_error extends $mol_error_mix {
2150
+ }
2151
+ $.$mol_run_error = $mol_run_error;
2152
+ $.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
2153
+ $.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
2154
+ class $mol_run extends $mol_object {
2155
+ static async_enabled() {
2156
+ return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
2157
+ }
2158
+ static spawn(options) {
2159
+ const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
2160
+ const env = options.env ?? this.$.$mol_env();
2161
+ return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
2162
+ }
2163
+ static spawn_async({ dir, sync, timeout, command, env }) {
2164
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
2165
+ const [app, ...args] = args_raw;
2166
+ const opts = { shell: true, cwd: dir, env };
2167
+ const log_object = {
2168
+ place: `${this}.spawn()`,
2169
+ message: 'Run',
2170
+ command: args_raw.join(' '),
2171
+ dir: $node.path.relative('', dir),
2172
+ };
2173
+ if (sync) {
2174
+ this.$.$mol_log3_come({
2175
+ hint: 'Run inside fiber',
2176
+ ...log_object
2177
+ });
2178
+ let error;
2179
+ let res;
2180
+ try {
2181
+ res = this.$.$mol_run_spawn_sync(app, args, opts);
2182
+ error = res.error;
2183
+ }
2184
+ catch (err) {
2185
+ error = err;
2186
+ }
2187
+ if (!res || error || res.status) {
2188
+ throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
2189
+ }
2190
+ return res;
2191
+ }
2192
+ let sub;
2193
+ try {
2194
+ sub = this.$.$mol_run_spawn(app, args, {
2195
+ ...opts,
2196
+ stdio: ['pipe', 'inherit', 'inherit'],
2197
+ });
2198
+ }
2199
+ catch (error) {
2200
+ throw new $mol_run_error(this.error_message(undefined), log_object, error);
2201
+ }
2202
+ const pid = sub.pid ?? 0;
2203
+ this.$.$mol_log3_come({
2204
+ ...log_object,
2205
+ pid,
2206
+ });
2207
+ let timeout_kill = false;
2208
+ let timer;
2209
+ const std_data = [];
2210
+ const error_data = [];
2211
+ const add = (std_chunk, error_chunk) => {
2212
+ if (std_chunk)
2213
+ std_data.push(std_chunk);
2214
+ if (error_chunk)
2215
+ error_data.push(error_chunk);
2216
+ if (!timeout)
2217
+ return;
2218
+ clearTimeout(timer);
2219
+ timer = setTimeout(() => {
2220
+ const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
2221
+ timeout_kill = true;
2222
+ add();
2223
+ sub.kill(signal);
2224
+ }, timeout);
2225
+ };
2226
+ add();
2227
+ sub.stdout?.on('data', data => add(data));
2228
+ sub.stderr?.on('data', data => add(undefined, data));
2229
+ const result_promise = new Promise((done, fail) => {
2230
+ const close = (error, status = null, signal = null) => {
2231
+ if (!timer && timeout)
2232
+ return;
2233
+ clearTimeout(timer);
2234
+ timer = undefined;
2235
+ const res = {
2236
+ pid,
2237
+ signal,
2238
+ get stdout() { return Buffer.concat(std_data); },
2239
+ get stderr() { return Buffer.concat(error_data); }
2240
+ };
2241
+ if (error || status || timeout_kill)
2242
+ return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
2243
+ this.$.$mol_log3_done({
2244
+ ...log_object,
2245
+ pid,
2246
+ });
2247
+ done(res);
2248
+ };
2249
+ sub.on('disconnect', () => close(new Error('Disconnected')));
2250
+ sub.on('error', err => close(err));
2251
+ sub.on('exit', (status, signal) => close(null, status, signal));
2252
+ });
2253
+ return Object.assign(result_promise, { destructor: () => {
2254
+ clearTimeout(timer);
2255
+ sub.kill('SIGKILL');
2256
+ } });
2257
+ }
2258
+ static error_message(res) {
2259
+ return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
2260
+ }
2261
+ }
2262
+ $.$mol_run = $mol_run;
2263
+ })($ || ($ = {}));
2264
+
2265
+ ;
2266
+ "use strict";
2267
+ var $;
2268
+ (function ($_1) {
2269
+ $mol_test({
2270
+ async 'exec timeout auto kill child process'($) {
2271
+ let close_mock = () => { };
2272
+ const error_message = 'Run error, timeout';
2273
+ function mol_run_spawn_sync_mock() {
2274
+ return {
2275
+ output: [],
2276
+ stdout: error_message,
2277
+ stderr: '',
2278
+ status: 0,
2279
+ signal: null,
2280
+ pid: 123,
2281
+ };
2282
+ }
2283
+ function mol_run_spawn_mock() {
2284
+ return {
2285
+ on(name, cb) {
2286
+ if (name === 'exit')
2287
+ close_mock = cb;
2288
+ },
2289
+ kill() { close_mock(); }
2290
+ };
2291
+ }
2292
+ const context_mock = $.$mol_ambient({
2293
+ $mol_run_spawn_sync: mol_run_spawn_sync_mock,
2294
+ $mol_run_spawn: mol_run_spawn_mock
2295
+ });
2296
+ class $mol_run_mock extends $mol_run {
2297
+ static get $() { return context_mock; }
2298
+ static async_enabled() {
2299
+ return true;
2300
+ }
2301
+ }
2302
+ let message = '';
2303
+ try {
2304
+ const res = await $mol_wire_async($mol_run_mock).spawn({
2305
+ command: 'sleep 10',
2306
+ dir: '.',
2307
+ timeout: 10,
2308
+ env: { 'MOL_RUN_ASYNC': '1' }
2309
+ });
2310
+ }
2311
+ catch (e) {
2312
+ message = e.message;
2313
+ }
2314
+ $mol_assert_equal(message, error_message);
2315
+ }
2316
+ });
2317
+ })($ || ($ = {}));
2318
+
2319
+ ;
2320
+ "use strict";
2321
+ var $;
2322
+ (function ($) {
2323
+ $.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
2324
+ })($ || ($ = {}));
2325
+
2326
+ ;
2327
+ "use strict";
2328
+ var $;
2329
+ (function ($) {
2330
+ $.$mol_dom = $mol_dom_context;
2331
+ })($ || ($ = {}));
2332
+
2333
+ ;
2334
+ "use strict";
2335
+ var $;
2336
+ (function ($) {
2337
+ function $mol_dom_render_children(el, childNodes) {
2338
+ const node_set = new Set(childNodes);
2339
+ let nextNode = el.firstChild;
2340
+ for (let view of childNodes) {
2341
+ if (view == null)
2342
+ continue;
2343
+ if (view instanceof $mol_dom_context.Node) {
2344
+ while (true) {
2345
+ if (!nextNode) {
2346
+ el.appendChild(view);
2347
+ break;
2348
+ }
2349
+ if (nextNode == view) {
2350
+ nextNode = nextNode.nextSibling;
2351
+ break;
2352
+ }
2353
+ else {
2354
+ if (node_set.has(nextNode)) {
2355
+ el.insertBefore(view, nextNode);
2356
+ break;
2357
+ }
2358
+ else {
2359
+ const nn = nextNode.nextSibling;
2360
+ el.removeChild(nextNode);
2361
+ nextNode = nn;
2362
+ }
2363
+ }
2364
+ }
2365
+ }
2366
+ else {
2367
+ if (nextNode && nextNode.nodeName === '#text') {
2368
+ const str = String(view);
2369
+ if (nextNode.nodeValue !== str)
2370
+ nextNode.nodeValue = str;
2371
+ nextNode = nextNode.nextSibling;
2372
+ }
2373
+ else {
2374
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
2375
+ el.insertBefore(textNode, nextNode);
2376
+ }
2377
+ }
2378
+ }
2379
+ while (nextNode) {
2380
+ const currNode = nextNode;
2381
+ nextNode = currNode.nextSibling;
2382
+ el.removeChild(currNode);
2383
+ }
2384
+ }
2385
+ $.$mol_dom_render_children = $mol_dom_render_children;
2386
+ })($ || ($ = {}));
2387
+
2388
+ ;
2389
+ "use strict";
2390
+
2391
+ ;
2392
+ "use strict";
2393
+
2394
+ ;
2395
+ "use strict";
2396
+ var $;
2397
+ (function ($) {
2398
+ function $mol_dom_serialize(node) {
2399
+ const serializer = new $mol_dom_context.XMLSerializer;
2400
+ return serializer.serializeToString(node);
2401
+ }
2402
+ $.$mol_dom_serialize = $mol_dom_serialize;
2403
+ })($ || ($ = {}));
2404
+
2405
+ ;
2406
+ "use strict";
2407
+ var $;
2408
+ (function ($) {
2409
+ $.$mol_jsx_prefix = '';
2410
+ $.$mol_jsx_crumbs = '';
2411
+ $.$mol_jsx_booked = null;
2412
+ $.$mol_jsx_document = {
2413
+ getElementById: () => null,
2414
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
2415
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
2416
+ };
2417
+ $.$mol_jsx_frag = '';
2418
+ function $mol_jsx(Elem, props, ...childNodes) {
2419
+ const id = props && props.id || '';
2420
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
2421
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
2422
+ if (Elem && $.$mol_jsx_booked) {
2423
+ if ($.$mol_jsx_booked.has(id)) {
2424
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
2425
+ }
2426
+ else {
2427
+ $.$mol_jsx_booked.add(id);
2428
+ }
2429
+ }
2430
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
2431
+ if ($.$mol_jsx_prefix) {
2432
+ const prefix_ext = $.$mol_jsx_prefix;
2433
+ const booked_ext = $.$mol_jsx_booked;
2434
+ const crumbs_ext = $.$mol_jsx_crumbs;
2435
+ for (const field in props) {
2436
+ const func = props[field];
2437
+ if (typeof func !== 'function')
2438
+ continue;
2439
+ const wrapper = function (...args) {
2440
+ const prefix = $.$mol_jsx_prefix;
2441
+ const booked = $.$mol_jsx_booked;
2442
+ const crumbs = $.$mol_jsx_crumbs;
2443
+ try {
2444
+ $.$mol_jsx_prefix = prefix_ext;
2445
+ $.$mol_jsx_booked = booked_ext;
2446
+ $.$mol_jsx_crumbs = crumbs_ext;
2447
+ return func.call(this, ...args);
2448
+ }
2449
+ finally {
2450
+ $.$mol_jsx_prefix = prefix;
2451
+ $.$mol_jsx_booked = booked;
2452
+ $.$mol_jsx_crumbs = crumbs;
2453
+ }
2454
+ };
2455
+ $mol_func_name_from(wrapper, func);
2456
+ props[field] = wrapper;
2457
+ }
2458
+ }
2459
+ if (typeof Elem !== 'string') {
2460
+ if ('prototype' in Elem) {
2461
+ const view = node && node[String(Elem)] || new Elem;
2462
+ Object.assign(view, props);
2463
+ view[Symbol.toStringTag] = guid;
2464
+ view.childNodes = childNodes;
2465
+ if (!view.ownerDocument)
2466
+ view.ownerDocument = $.$mol_jsx_document;
2467
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
2468
+ node = view.valueOf();
2469
+ node[String(Elem)] = view;
2470
+ return node;
2471
+ }
2472
+ else {
2473
+ const prefix = $.$mol_jsx_prefix;
2474
+ const booked = $.$mol_jsx_booked;
2475
+ const crumbs = $.$mol_jsx_crumbs;
2476
+ try {
2477
+ $.$mol_jsx_prefix = guid;
2478
+ $.$mol_jsx_booked = new Set;
2479
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
2480
+ return Elem(props, ...childNodes);
2481
+ }
2482
+ finally {
2483
+ $.$mol_jsx_prefix = prefix;
2484
+ $.$mol_jsx_booked = booked;
2485
+ $.$mol_jsx_crumbs = crumbs;
2486
+ }
2487
+ }
2488
+ }
2489
+ if (!node) {
2490
+ node = Elem
2491
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
2492
+ : $.$mol_jsx_document.createDocumentFragment();
2493
+ }
2494
+ $mol_dom_render_children(node, [].concat(...childNodes));
2495
+ if (!Elem)
2496
+ return node;
2497
+ if (guid)
2498
+ node.id = guid;
2499
+ for (const key in props) {
2500
+ if (key === 'id')
2501
+ continue;
2502
+ if (typeof props[key] === 'string') {
2503
+ if (typeof node[key] === 'string')
2504
+ node[key] = props[key];
2505
+ node.setAttribute(key, props[key]);
2506
+ }
2507
+ else if (props[key] &&
2508
+ typeof props[key] === 'object' &&
2509
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
2510
+ if (typeof node[key] === 'object') {
2511
+ Object.assign(node[key], props[key]);
2512
+ continue;
2513
+ }
2514
+ }
2515
+ else {
2516
+ node[key] = props[key];
2517
+ }
2518
+ }
2519
+ if ($.$mol_jsx_crumbs)
2520
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
2521
+ return node;
2522
+ }
2523
+ $.$mol_jsx = $mol_jsx;
2524
+ })($ || ($ = {}));
2525
+
2526
+ ;
2527
+ "use strict";
2528
+ var $;
2529
+ (function ($) {
2530
+ $mol_test({
2531
+ 'Make empty div'() {
2532
+ $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
2533
+ },
2534
+ 'Define native field'() {
2535
+ const dom = $mol_jsx("input", { value: '123' });
2536
+ $mol_assert_equal(dom.outerHTML, '<input value="123">');
2537
+ $mol_assert_equal(dom.value, '123');
2538
+ },
2539
+ 'Define classes'() {
2540
+ const dom = $mol_jsx("div", { class: 'foo bar' });
2541
+ $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
2542
+ },
2543
+ 'Define styles'() {
2544
+ const dom = $mol_jsx("div", { style: { color: 'red' } });
2545
+ $mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
2546
+ },
2547
+ 'Define dataset'() {
2548
+ const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
2549
+ $mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
2550
+ },
2551
+ 'Define attributes'() {
2552
+ const dom = $mol_jsx("div", { lang: "ru", hidden: true });
2553
+ $mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
2554
+ },
2555
+ 'Define child nodes'() {
2556
+ const dom = $mol_jsx("div", null,
2557
+ "hello",
2558
+ $mol_jsx("strong", null, "world"),
2559
+ "!");
2560
+ $mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
2561
+ },
2562
+ 'Make fragment'() {
2563
+ const dom = $mol_jsx($mol_jsx_frag, null,
2564
+ $mol_jsx("br", null),
2565
+ $mol_jsx("hr", null));
2566
+ $mol_assert_equal($mol_dom_serialize(dom), '<br xmlns="http://www.w3.org/1999/xhtml" /><hr xmlns="http://www.w3.org/1999/xhtml" />');
2567
+ },
2568
+ 'Spread fragment'() {
2569
+ const dom = $mol_jsx("div", null,
2570
+ $mol_jsx($mol_jsx_frag, null,
2571
+ $mol_jsx("br", null),
2572
+ $mol_jsx("hr", null)));
2573
+ $mol_assert_equal(dom.outerHTML, '<div><br><hr></div>');
2574
+ },
2575
+ 'Function as component'() {
2576
+ const Button = (props, target) => {
2577
+ return $mol_jsx("button", { title: props.hint }, target());
2578
+ };
2579
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
2580
+ $mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
2581
+ },
2582
+ 'Nested guid generation'() {
2583
+ const Foo = () => {
2584
+ return $mol_jsx("div", null,
2585
+ $mol_jsx(Bar, { id: "bar" },
2586
+ $mol_jsx("img", { id: "icon" })));
2587
+ };
2588
+ const Bar = (props, icon) => {
2589
+ return $mol_jsx("span", null,
2590
+ icon,
2591
+ $mol_jsx("i", { id: "label" }));
2592
+ };
2593
+ const dom = $mol_jsx(Foo, { id: "foo" });
2594
+ $mol_assert_equal(dom.outerHTML, '<div id="foo" class="Foo"><span id="foo/bar" class="Foo_bar Bar"><img id="foo/icon" class="Foo_icon"><i id="foo/bar/label" class="Foo_bar_label Bar_label"></i></span></div>');
2595
+ },
2596
+ 'Fail on non unique ids'() {
2597
+ const App = () => {
2598
+ return $mol_jsx("div", null,
2599
+ $mol_jsx("span", { id: "bar" }),
2600
+ $mol_jsx("span", { id: "bar" }));
2601
+ };
2602
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
2603
+ },
2604
+ 'Owner based guid generationn'() {
2605
+ const Foo = () => {
2606
+ return $mol_jsx("div", null,
2607
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
2608
+ };
2609
+ const Bar = (props) => {
2610
+ return $mol_jsx("span", null, props.icon());
2611
+ };
2612
+ const dom = $mol_jsx(Foo, { id: "app" });
2613
+ $mol_assert_equal(dom.outerHTML, '<div id="app" class="Foo"><span id="app/middle" class="Foo_middle Bar"><img id="app/icon" class="Foo_icon"></span></div>');
2614
+ },
2615
+ 'Fail on same ids from different caller'() {
2616
+ const Foo = () => {
2617
+ return $mol_jsx("div", null,
2618
+ $mol_jsx("img", { id: "icon" }),
2619
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
2620
+ };
2621
+ const Bar = (props) => {
2622
+ return $mol_jsx("span", null, props.icon());
2623
+ };
2624
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
2625
+ },
2626
+ });
2627
+ })($ || ($ = {}));
2628
+
2629
+ ;
2630
+ "use strict";
2631
+ var $;
2632
+ (function ($) {
2633
+ function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
2634
+ const source = typeof item === 'function' ? new $mol_range2_array() : item;
2635
+ if (typeof item !== 'function') {
2636
+ item = index => source[index];
2637
+ size = () => source.length;
2638
+ }
2639
+ return new Proxy(source, {
2640
+ get(target, field) {
2641
+ if (typeof field === 'string') {
2642
+ if (field === 'length')
2643
+ return size();
2644
+ const index = Number(field);
2645
+ if (index < 0)
2646
+ return undefined;
2647
+ if (index >= size())
2648
+ return undefined;
2649
+ if (index === Math.trunc(index))
2650
+ return item(index);
2651
+ }
2652
+ return $mol_range2_array.prototype[field];
2653
+ },
2654
+ set(target, field) {
2655
+ return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
2656
+ },
2657
+ ownKeys(target) {
2658
+ return [...Array(size())].map((v, i) => String(i)).concat('length');
2659
+ },
2660
+ getOwnPropertyDescriptor(target, field) {
2661
+ if (field === "length")
2662
+ return {
2663
+ value: size(),
2664
+ writable: true,
2665
+ enumerable: false,
2666
+ configurable: false,
2667
+ };
2668
+ const index = Number(field);
2669
+ if (index === Math.trunc(index))
2670
+ return {
2671
+ get: () => this.get(target, field, this),
2672
+ enumerable: true,
2673
+ configurable: true,
2674
+ };
2675
+ return Object.getOwnPropertyDescriptor(target, field);
2676
+ }
2677
+ });
2678
+ }
2679
+ $.$mol_range2 = $mol_range2;
2680
+ class $mol_range2_array extends Array {
2681
+ concat(...tail) {
2682
+ if (tail.length === 0)
2683
+ return this;
2684
+ if (tail.length > 1) {
2685
+ let list = this;
2686
+ for (let item of tail)
2687
+ list = list.concat(item);
2688
+ return list;
2689
+ }
2690
+ return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
2691
+ }
2692
+ filter(check, context) {
2693
+ const filtered = [];
2694
+ let cursor = -1;
2695
+ return $mol_range2(index => {
2696
+ while (cursor < this.length && index >= filtered.length - 1) {
2697
+ const val = this[++cursor];
2698
+ if (check(val, cursor, this))
2699
+ filtered.push(val);
2700
+ }
2701
+ return filtered[index];
2702
+ }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
2703
+ }
2704
+ forEach(proceed, context) {
2705
+ for (let [key, value] of this.entries())
2706
+ proceed.call(context, value, key, this);
2707
+ }
2708
+ map(proceed, context) {
2709
+ return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
2710
+ }
2711
+ reduce(merge, result) {
2712
+ let index = 0;
2713
+ if (arguments.length === 1) {
2714
+ result = this[index++];
2715
+ }
2716
+ for (; index < this.length; ++index) {
2717
+ result = merge(result, this[index], index, this);
2718
+ }
2719
+ return result;
2720
+ }
2721
+ toReversed() {
2722
+ return $mol_range2(index => this[this.length - 1 - index], () => this.length);
2723
+ }
2724
+ slice(from = 0, to = this.length) {
2725
+ return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
2726
+ }
2727
+ some(check, context) {
2728
+ for (let index = 0; index < this.length; ++index) {
2729
+ if (check.call(context, this[index], index, this))
2730
+ return true;
2731
+ }
2732
+ return false;
2733
+ }
2734
+ every(check, context) {
2735
+ for (let index = 0; index < this.length; ++index) {
2736
+ if (!check.call(context, this[index], index, this))
2737
+ return false;
2738
+ }
2739
+ return true;
2740
+ }
2741
+ reverse() {
2742
+ return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
2743
+ }
2744
+ sort() {
2745
+ return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
2746
+ }
2747
+ indexOf(needle) {
2748
+ return this.findIndex(item => item === needle);
2749
+ }
2750
+ [Symbol.toPrimitive]() {
2751
+ return $mol_guid();
2752
+ }
2753
+ }
2754
+ $.$mol_range2_array = $mol_range2_array;
2755
+ })($ || ($ = {}));
2756
+
2757
+ ;
2758
+ "use strict";
2759
+ var $;
2760
+ (function ($) {
2761
+ $mol_test({
2762
+ 'lazy calls'() {
2763
+ let calls = 0;
2764
+ const list = $mol_range2(index => (++calls, index), () => 10);
2765
+ $mol_assert_equal(true, list instanceof Array);
2766
+ $mol_assert_equal(list.length, 10);
2767
+ $mol_assert_equal(list[-1], undefined);
2768
+ $mol_assert_equal(list[0], 0);
2769
+ $mol_assert_equal(list[9], 9);
2770
+ $mol_assert_equal(list[9.5], undefined);
2771
+ $mol_assert_equal(list[10], undefined);
2772
+ $mol_assert_equal(calls, 2);
2773
+ },
2774
+ 'infinity list'() {
2775
+ let calls = 0;
2776
+ const list = $mol_range2(index => (++calls, index));
2777
+ $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
2778
+ $mol_assert_equal(list[0], 0);
2779
+ $mol_assert_equal(list[4], 4);
2780
+ $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
2781
+ $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
2782
+ $mol_assert_equal(calls, 3);
2783
+ },
2784
+ 'stringify'() {
2785
+ const list = $mol_range2(i => i, () => 5);
2786
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
2787
+ $mol_assert_equal(list.join(';'), '0;1;2;3;4');
2788
+ },
2789
+ 'for-of'() {
2790
+ let log = '';
2791
+ for (let i of $mol_range2(i => i + 1, () => 5)) {
2792
+ log += i;
2793
+ }
2794
+ $mol_assert_equal(log, '12345');
2795
+ },
2796
+ 'for-in'() {
2797
+ let log = '';
2798
+ for (let i in $mol_range2(i => i, () => 5)) {
2799
+ log += i;
2800
+ }
2801
+ $mol_assert_equal(log, '01234');
2802
+ },
2803
+ 'forEach'() {
2804
+ let log = '';
2805
+ $mol_range2(i => i, () => 5).forEach(i => log += i);
2806
+ $mol_assert_equal(log, '01234');
2807
+ },
2808
+ 'reduce'() {
2809
+ let calls = 0;
2810
+ const list = $mol_range2().slice(1, 6);
2811
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
2812
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
2813
+ },
2814
+ 'lazy concat'() {
2815
+ let calls1 = 0;
2816
+ let calls2 = 0;
2817
+ const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
2818
+ $mol_assert_equal(true, list instanceof Array);
2819
+ $mol_assert_equal(list.length, 15);
2820
+ $mol_assert_equal(list[0], 0);
2821
+ $mol_assert_equal(list[4], 4);
2822
+ $mol_assert_equal(list[5], 0);
2823
+ $mol_assert_equal(list[9], 4);
2824
+ $mol_assert_equal(list[10], 0);
2825
+ $mol_assert_equal(list[14], 4);
2826
+ $mol_assert_equal(list[15], undefined);
2827
+ $mol_assert_equal(calls1, 2);
2828
+ $mol_assert_equal(calls2, 2);
2829
+ },
2830
+ 'lazy filter'() {
2831
+ let calls = 0;
2832
+ const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
2833
+ $mol_assert_equal(true, list instanceof Array);
2834
+ $mol_assert_equal(list.length, 3);
2835
+ $mol_assert_equal(list[0], 1);
2836
+ $mol_assert_equal(list[2], 5);
2837
+ $mol_assert_equal(list[3], undefined);
2838
+ $mol_assert_equal(calls, 8);
2839
+ },
2840
+ 'lazy reverse'() {
2841
+ let calls = 0;
2842
+ const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
2843
+ $mol_assert_equal(true, list instanceof Array);
2844
+ $mol_assert_equal(list.length, 3);
2845
+ $mol_assert_equal(list[0], 9);
2846
+ $mol_assert_equal(list[2], 7);
2847
+ $mol_assert_equal(list[3], undefined);
2848
+ $mol_assert_equal(calls, 2);
2849
+ },
2850
+ 'lazy map'() {
2851
+ let calls1 = 0;
2852
+ let calls2 = 0;
2853
+ const source = $mol_range2(index => (++calls1, index), () => 5);
2854
+ const target = source.map((item, index, self) => {
2855
+ ++calls2;
2856
+ $mol_assert_equal(source, self);
2857
+ return index + 10;
2858
+ }, () => 5);
2859
+ $mol_assert_equal(true, target instanceof Array);
2860
+ $mol_assert_equal(target.length, 5);
2861
+ $mol_assert_equal(target[0], 10);
2862
+ $mol_assert_equal(target[4], 14);
2863
+ $mol_assert_equal(target[5], undefined);
2864
+ $mol_assert_equal(calls1, 2);
2865
+ $mol_assert_equal(calls2, 2);
2866
+ },
2867
+ 'lazy slice'() {
2868
+ let calls = 0;
2869
+ const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
2870
+ $mol_assert_equal(true, list instanceof Array);
2871
+ $mol_assert_equal(list.length, 4);
2872
+ $mol_assert_equal(list[0], 3);
2873
+ $mol_assert_equal(list[3], 6);
2874
+ $mol_assert_equal(list[4], undefined);
2875
+ $mol_assert_equal(calls, 2);
2876
+ },
2877
+ 'lazy some'() {
2878
+ let calls = 0;
2879
+ $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
2880
+ $mol_assert_equal(calls, 3);
2881
+ $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
2882
+ $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
2883
+ },
2884
+ 'lazy every'() {
2885
+ let calls = 0;
2886
+ $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
2887
+ $mol_assert_equal(calls, 3);
2888
+ $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
2889
+ $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
2890
+ },
2891
+ 'lazyfy'() {
2892
+ let calls = 0;
2893
+ const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
2894
+ $mol_assert_equal(true, list instanceof Array);
2895
+ $mol_assert_equal(list.length, 4);
2896
+ $mol_assert_equal(calls, 0);
2897
+ $mol_assert_equal(list[0], 12);
2898
+ $mol_assert_equal(list[3], 15);
2899
+ $mol_assert_equal(list[4], undefined);
2900
+ $mol_assert_equal(calls, 2);
2901
+ },
2902
+ 'prevent modification'() {
2903
+ const list = $mol_range2(i => i, () => 5);
2904
+ $mol_assert_fail(() => list.push(4), TypeError);
2905
+ $mol_assert_fail(() => list.pop(), TypeError);
2906
+ $mol_assert_fail(() => list.unshift(4), TypeError);
2907
+ $mol_assert_fail(() => list.shift(), TypeError);
2908
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
2909
+ $mol_assert_fail(() => list[1] = 2, TypeError);
2910
+ $mol_assert_fail(() => list.reverse(), TypeError);
2911
+ $mol_assert_fail(() => list.sort(), TypeError);
2912
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
2913
+ }
2914
+ });
2915
+ })($ || ($ = {}));
2916
+
2917
+ ;
2918
+ "use strict";
2919
+ var $;
2920
+ (function ($) {
2921
+ $.$mol_compare_deep_cache = new WeakMap();
2922
+ function $mol_compare_deep(left, right) {
2923
+ if (Object.is(left, right))
2924
+ return true;
2925
+ if (left === null)
2926
+ return false;
2927
+ if (right === null)
2928
+ return false;
2929
+ if (typeof left !== 'object')
2930
+ return false;
2931
+ if (typeof right !== 'object')
2932
+ return false;
2933
+ const left_proto = Reflect.getPrototypeOf(left);
2934
+ const right_proto = Reflect.getPrototypeOf(right);
2935
+ if (left_proto !== right_proto)
2936
+ return false;
2937
+ if (left instanceof Boolean)
2938
+ return Object.is(left.valueOf(), right['valueOf']());
2939
+ if (left instanceof Number)
2940
+ return Object.is(left.valueOf(), right['valueOf']());
2941
+ if (left instanceof String)
2942
+ return Object.is(left.valueOf(), right['valueOf']());
2943
+ if (left instanceof Date)
2944
+ return Object.is(left.valueOf(), right['valueOf']());
2945
+ if (left instanceof RegExp)
2946
+ return left.source === right.source && left.flags === right.flags;
2947
+ if (left instanceof Error)
2948
+ return left.message === right.message && $mol_compare_deep(left.stack, right.stack);
2949
+ let left_cache = $.$mol_compare_deep_cache.get(left);
2950
+ if (left_cache) {
2951
+ const right_cache = left_cache.get(right);
2952
+ if (typeof right_cache === 'boolean')
2953
+ return right_cache;
2954
+ }
2955
+ else {
2956
+ left_cache = new WeakMap();
2957
+ $.$mol_compare_deep_cache.set(left, left_cache);
2958
+ }
2959
+ left_cache.set(right, true);
2960
+ let result;
2961
+ try {
2962
+ if (!left_proto)
2963
+ result = compare_pojo(left, right);
2964
+ else if (!Reflect.getPrototypeOf(left_proto))
2965
+ result = compare_pojo(left, right);
2966
+ else if (Symbol.toPrimitive in left)
2967
+ result = compare_primitive(left, right);
2968
+ else if (Array.isArray(left))
2969
+ result = compare_array(left, right);
2970
+ else if (left instanceof Set)
2971
+ result = compare_set(left, right);
2972
+ else if (left instanceof Map)
2973
+ result = compare_map(left, right);
2974
+ else if (ArrayBuffer.isView(left))
2975
+ result = compare_buffer(left, right);
2976
+ else if (Symbol.iterator in left)
2977
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
2978
+ else
2979
+ result = false;
2980
+ }
2981
+ finally {
2982
+ left_cache.set(right, result);
2983
+ }
2984
+ return result;
2985
+ }
2986
+ $.$mol_compare_deep = $mol_compare_deep;
2987
+ function compare_array(left, right) {
2988
+ const len = left.length;
2989
+ if (len !== right.length)
2990
+ return false;
2991
+ for (let i = 0; i < len; ++i) {
2992
+ if (!$mol_compare_deep(left[i], right[i]))
2993
+ return false;
2994
+ }
2995
+ return true;
2996
+ }
2997
+ function compare_buffer(left, right) {
2998
+ const len = left.byteLength;
2999
+ if (len !== right.byteLength)
3000
+ return false;
3001
+ if (left instanceof DataView)
3002
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, right.byteOffset, right.byteLength));
3003
+ for (let i = 0; i < len; ++i) {
3004
+ if (left[i] !== right[i])
3005
+ return false;
3006
+ }
3007
+ return true;
3008
+ }
3009
+ function compare_iterator(left, right) {
3010
+ while (true) {
3011
+ const left_next = left.next();
3012
+ const right_next = right.next();
3013
+ if (left_next.done !== right_next.done)
3014
+ return false;
3015
+ if (left_next.done)
3016
+ break;
3017
+ if (!$mol_compare_deep(left_next.value, right_next.value))
3018
+ return false;
3019
+ }
3020
+ return true;
3021
+ }
3022
+ function compare_set(left, right) {
3023
+ if (left.size !== right.size)
3024
+ return false;
3025
+ return compare_iterator(left.values(), right.values());
3026
+ }
3027
+ function compare_map(left, right) {
3028
+ if (left.size !== right.size)
3029
+ return false;
3030
+ return compare_iterator(left.keys(), right.keys())
3031
+ && compare_iterator(left.values(), right.values());
3032
+ }
3033
+ function compare_pojo(left, right) {
3034
+ const left_keys = Object.getOwnPropertyNames(left);
3035
+ const right_keys = Object.getOwnPropertyNames(right);
3036
+ if (!compare_array(left_keys, right_keys))
3037
+ return false;
3038
+ for (let key of left_keys) {
3039
+ if (!$mol_compare_deep(left[key], right[key]))
3040
+ return false;
3041
+ }
3042
+ const left_syms = Object.getOwnPropertySymbols(left);
3043
+ const right_syms = Object.getOwnPropertySymbols(right);
3044
+ if (!compare_array(left_syms, right_syms))
3045
+ return false;
3046
+ for (let key of left_syms) {
3047
+ if (!$mol_compare_deep(left[key], right[key]))
3048
+ return false;
3049
+ }
3050
+ return true;
3051
+ }
3052
+ function compare_primitive(left, right) {
3053
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
3054
+ }
3055
+ })($ || ($ = {}));
3056
+
3057
+ ;
3058
+ "use strict";
3059
+ var $;
3060
+ (function ($) {
3061
+ $mol_test({
3062
+ 'nulls & undefineds'() {
3063
+ $mol_assert_ok($mol_compare_deep(null, null));
3064
+ $mol_assert_ok($mol_compare_deep(undefined, undefined));
3065
+ $mol_assert_not($mol_compare_deep(undefined, null));
3066
+ $mol_assert_not($mol_compare_deep({}, null));
3067
+ },
3068
+ 'number'() {
3069
+ $mol_assert_ok($mol_compare_deep(1, 1));
3070
+ $mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
3071
+ $mol_assert_not($mol_compare_deep(1, 2));
3072
+ $mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
3073
+ $mol_assert_not($mol_compare_deep(Object(1), Object(2)));
3074
+ },
3075
+ 'POJO'() {
3076
+ $mol_assert_ok($mol_compare_deep({}, {}));
3077
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
3078
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
3079
+ $mol_assert_not($mol_compare_deep({}, { a: undefined }));
3080
+ $mol_assert_not($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
3081
+ $mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
3082
+ $mol_assert_ok($mol_compare_deep(Object.create(null), Object.create(null)));
3083
+ },
3084
+ 'Array'() {
3085
+ $mol_assert_ok($mol_compare_deep([], []));
3086
+ $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
3087
+ $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
3088
+ $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
3089
+ $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
3090
+ $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
3091
+ },
3092
+ 'Non POJO are different'() {
3093
+ class Thing extends Object {
3094
+ }
3095
+ $mol_assert_not($mol_compare_deep(new Thing, new Thing));
3096
+ $mol_assert_not($mol_compare_deep(() => 1, () => 1));
3097
+ $mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
3098
+ },
3099
+ 'POJO with symbols'() {
3100
+ const sym = Symbol();
3101
+ $mol_assert_ok($mol_compare_deep({ [sym]: true }, { [sym]: true }));
3102
+ $mol_assert_not($mol_compare_deep({ [Symbol()]: true }, { [Symbol()]: true }));
3103
+ },
3104
+ 'same POJOs with cyclic reference'() {
3105
+ const a = { foo: {} };
3106
+ a['self'] = a;
3107
+ const b = { foo: {} };
3108
+ b['self'] = b;
3109
+ $mol_assert_ok($mol_compare_deep(a, b));
3110
+ },
3111
+ 'same POJOs with cyclic reference with cache warmup'() {
3112
+ const obj1 = { test: 1, obj3: null };
3113
+ const obj1_copy = { test: 1, obj3: null };
3114
+ const obj2 = { test: 2, obj1 };
3115
+ const obj2_copy = { test: 2, obj1: obj1_copy };
3116
+ const obj3 = { test: 3, obj2 };
3117
+ const obj3_copy = { test: 3, obj2: obj2_copy };
3118
+ obj1.obj3 = obj3;
3119
+ obj1_copy.obj3 = obj3_copy;
3120
+ $mol_assert_not($mol_compare_deep(obj1, {}));
3121
+ $mol_assert_not($mol_compare_deep(obj2, {}));
3122
+ $mol_assert_not($mol_compare_deep(obj3, {}));
3123
+ $mol_assert_ok($mol_compare_deep(obj3, obj3_copy));
3124
+ },
3125
+ 'Date'() {
3126
+ $mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
3127
+ $mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
3128
+ },
3129
+ 'RegExp'() {
3130
+ $mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
3131
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
3132
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
3133
+ },
3134
+ 'Error'() {
3135
+ $mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
3136
+ const fail = (message) => new Error(message);
3137
+ $mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
3138
+ $mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
3139
+ },
3140
+ 'Map'() {
3141
+ $mol_assert_ok($mol_compare_deep(new Map, new Map));
3142
+ $mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
3143
+ $mol_assert_ok($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
3144
+ $mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
3145
+ $mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[3], 2]])));
3146
+ },
3147
+ 'Set'() {
3148
+ $mol_assert_ok($mol_compare_deep(new Set, new Set));
3149
+ $mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
3150
+ $mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
3151
+ },
3152
+ 'Uint8Array'() {
3153
+ $mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
3154
+ $mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
3155
+ $mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
3156
+ },
3157
+ 'DataView'() {
3158
+ $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array().buffer), new DataView(new Uint8Array().buffer)));
3159
+ $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([0]).buffer)));
3160
+ $mol_assert_not($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([1]).buffer)));
3161
+ },
3162
+ 'Serializale'() {
3163
+ class User {
3164
+ name;
3165
+ rand;
3166
+ constructor(name, rand = Math.random()) {
3167
+ this.name = name;
3168
+ this.rand = rand;
3169
+ }
3170
+ [Symbol.toPrimitive](mode) {
3171
+ return this.name;
3172
+ }
3173
+ }
3174
+ $mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
3175
+ $mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
3176
+ },
3177
+ 'Iterable'() {
3178
+ $mol_assert_ok($mol_compare_deep(new URLSearchParams({ foo: 'bar' }), new URLSearchParams({ foo: 'bar' })));
3179
+ $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx' }), new URLSearchParams({ foo: 'yyy' })));
3180
+ $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx', bar: 'yyy' }), new URLSearchParams({ bar: 'yyy', foo: 'xxx' })));
3181
+ },
3182
+ });
3183
+ })($ || ($ = {}));
3184
+
3185
+ ;
3186
+ "use strict";
3187
+ var $;
3188
+ (function ($) {
3189
+ function $mol_assert_ok(value) {
3190
+ if (value)
3191
+ return;
3192
+ $mol_fail(new Error(`${value} ≠ true`));
3193
+ }
3194
+ $.$mol_assert_ok = $mol_assert_ok;
3195
+ function $mol_assert_not(value) {
3196
+ if (!value)
3197
+ return;
3198
+ $mol_fail(new Error(`${value} ≠ false`));
3199
+ }
3200
+ $.$mol_assert_not = $mol_assert_not;
3201
+ function $mol_assert_fail(handler, ErrorRight) {
3202
+ const fail = $.$mol_fail;
3203
+ try {
3204
+ $.$mol_fail = $.$mol_fail_hidden;
3205
+ handler();
3206
+ }
3207
+ catch (error) {
3208
+ $.$mol_fail = fail;
3209
+ if (typeof ErrorRight === 'string') {
3210
+ $mol_assert_equal(error.message ?? error, ErrorRight);
3211
+ }
3212
+ else {
3213
+ $mol_assert_equal(error instanceof ErrorRight, true);
3214
+ }
3215
+ return error;
3216
+ }
3217
+ finally {
3218
+ $.$mol_fail = fail;
3219
+ }
3220
+ $mol_fail(new Error('Not failed'));
3221
+ }
3222
+ $.$mol_assert_fail = $mol_assert_fail;
3223
+ function $mol_assert_like(...args) {
3224
+ $mol_assert_equal(...args);
3225
+ }
3226
+ $.$mol_assert_like = $mol_assert_like;
3227
+ function $mol_assert_unique(...args) {
3228
+ for (let i = 0; i < args.length; ++i) {
3229
+ for (let j = 0; j < args.length; ++j) {
3230
+ if (i === j)
3231
+ continue;
3232
+ if (!$mol_compare_deep(args[i], args[j]))
3233
+ continue;
3234
+ return $mol_fail(new Error(`Uniquesess assertion failure`, { cause: { [i]: args[i], [i]: args[i] } }));
3235
+ }
3236
+ }
3237
+ }
3238
+ $.$mol_assert_unique = $mol_assert_unique;
3239
+ function $mol_assert_equal(...args) {
3240
+ for (let i = 1; i < args.length; ++i) {
3241
+ if ($mol_compare_deep(args[0], args[i]))
3242
+ continue;
3243
+ return $mol_fail(new Error(`Equality assertion failure`, { cause: { 0: args[0], [i]: args[i] } }));
3244
+ }
3245
+ }
3246
+ $.$mol_assert_equal = $mol_assert_equal;
3247
+ })($ || ($ = {}));
3248
+
3249
+ ;
3250
+ "use strict";
3251
+ var $;
3252
+ (function ($) {
3253
+ $mol_test({
3254
+ 'must be false'() {
3255
+ $mol_assert_not(0);
3256
+ },
3257
+ 'must be true'() {
3258
+ $mol_assert_ok(1);
3259
+ },
3260
+ 'two must be equal'() {
3261
+ $mol_assert_equal(2, 2);
3262
+ },
3263
+ 'three must be equal'() {
3264
+ $mol_assert_equal(2, 2, 2);
3265
+ },
3266
+ 'two must be unique'() {
3267
+ $mol_assert_unique([2], [3]);
3268
+ },
3269
+ 'three must be unique'() {
3270
+ $mol_assert_unique([1], [2], [3]);
3271
+ },
3272
+ 'two must be alike'() {
3273
+ $mol_assert_equal([3], [3]);
3274
+ },
3275
+ 'three must be alike'() {
3276
+ $mol_assert_equal([3], [3], [3]);
3277
+ },
3278
+ 'two object must be alike'() {
3279
+ $mol_assert_equal({ a: 1 }, { a: 1 });
3280
+ },
3281
+ 'three object must be alike'() {
3282
+ $mol_assert_equal({ a: 1 }, { a: 1 }, { a: 1 });
3283
+ },
3284
+ });
3285
+ })($ || ($ = {}));
3286
+
3287
+ ;
3288
+ "use strict";
3289
+ var $;
3290
+ (function ($) {
3291
+ const instances = new WeakSet();
3292
+ function $mol_delegate(proto, target) {
3293
+ const proxy = new Proxy(proto, {
3294
+ get: (_, field) => {
3295
+ const obj = target();
3296
+ let val = Reflect.get(obj, field);
3297
+ if (typeof val === 'function') {
3298
+ val = val.bind(obj);
3299
+ }
3300
+ return val;
3301
+ },
3302
+ has: (_, field) => Reflect.has(target(), field),
3303
+ set: (_, field, value) => Reflect.set(target(), field, value),
3304
+ getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
3305
+ ownKeys: () => Reflect.ownKeys(target()),
3306
+ getPrototypeOf: () => Reflect.getPrototypeOf(target()),
3307
+ setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
3308
+ isExtensible: () => Reflect.isExtensible(target()),
3309
+ preventExtensions: () => Reflect.preventExtensions(target()),
3310
+ apply: (_, self, args) => Reflect.apply(target(), self, args),
3311
+ construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
3312
+ defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
3313
+ deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
3314
+ });
3315
+ instances.add(proxy);
3316
+ return proxy;
3317
+ }
3318
+ $.$mol_delegate = $mol_delegate;
3319
+ Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
3320
+ value: (obj) => instances.has(obj),
3321
+ });
3322
+ })($ || ($ = {}));
3323
+
3324
+ ;
3325
+ "use strict";
3326
+ var $;
3327
+ (function ($) {
3328
+ $mol_test({
3329
+ 'get'() {
3330
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
3331
+ $mol_assert_equal(proxy.foo, 777);
3332
+ },
3333
+ 'has'() {
3334
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
3335
+ $mol_assert_equal('foo' in proxy, true);
3336
+ },
3337
+ 'set'() {
3338
+ const target = { foo: 777 };
3339
+ const proxy = $mol_delegate({}, () => target);
3340
+ proxy.foo = 123;
3341
+ $mol_assert_equal(target.foo, 123);
3342
+ },
3343
+ 'getOwnPropertyDescriptor'() {
3344
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
3345
+ $mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
3346
+ value: 777,
3347
+ writable: true,
3348
+ enumerable: true,
3349
+ configurable: true,
3350
+ });
3351
+ },
3352
+ 'ownKeys'() {
3353
+ const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
3354
+ $mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
3355
+ },
3356
+ 'getPrototypeOf'() {
3357
+ class Foo {
3358
+ }
3359
+ const proxy = $mol_delegate({}, () => new Foo);
3360
+ $mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
3361
+ },
3362
+ 'setPrototypeOf'() {
3363
+ class Foo {
3364
+ }
3365
+ const target = {};
3366
+ const proxy = $mol_delegate({}, () => target);
3367
+ Object.setPrototypeOf(proxy, Foo.prototype);
3368
+ $mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
3369
+ },
3370
+ 'instanceof'() {
3371
+ class Foo {
3372
+ }
3373
+ const proxy = $mol_delegate({}, () => new Foo);
3374
+ $mol_assert_ok(proxy instanceof Foo);
3375
+ $mol_assert_ok(proxy instanceof $mol_delegate);
3376
+ },
3377
+ 'autobind'() {
3378
+ class Foo {
3379
+ }
3380
+ const proxy = $mol_delegate({}, () => new Foo);
3381
+ $mol_assert_ok(proxy instanceof Foo);
3382
+ $mol_assert_ok(proxy instanceof $mol_delegate);
3383
+ },
3384
+ });
3385
+ })($ || ($ = {}));
3386
+
3387
+ ;
3388
+ "use strict";
3389
+ var $;
3390
+ (function ($) {
3391
+ class $mol_span extends $mol_object2 {
3392
+ uri;
3393
+ source;
3394
+ row;
3395
+ col;
3396
+ length;
3397
+ constructor(uri, source, row, col, length) {
3398
+ super();
3399
+ this.uri = uri;
3400
+ this.source = source;
3401
+ this.row = row;
3402
+ this.col = col;
3403
+ this.length = length;
3404
+ this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
3405
+ }
3406
+ static unknown = $mol_span.begin('?');
3407
+ static begin(uri, source = '') {
3408
+ return new $mol_span(uri, source, 1, 1, 0);
3409
+ }
3410
+ static end(uri, source) {
3411
+ return new $mol_span(uri, source, 1, source.length + 1, 0);
3412
+ }
3413
+ static entire(uri, source) {
3414
+ return new $mol_span(uri, source, 1, 1, source.length);
3415
+ }
3416
+ toString() {
3417
+ return this[Symbol.toStringTag];
3418
+ }
3419
+ toJSON() {
3420
+ return {
3421
+ uri: this.uri,
3422
+ row: this.row,
3423
+ col: this.col,
3424
+ length: this.length
3425
+ };
3426
+ }
3427
+ error(message, Class = Error) {
3428
+ return new Class(`${message} (${this})`);
3429
+ }
3430
+ span(row, col, length) {
3431
+ return new $mol_span(this.uri, this.source, row, col, length);
3432
+ }
3433
+ after(length = 0) {
3434
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
3435
+ }
3436
+ slice(begin, end = -1) {
3437
+ let len = this.length;
3438
+ if (begin < 0)
3439
+ begin += len;
3440
+ if (end < 0)
3441
+ end += len;
3442
+ if (begin < 0 || begin > len)
3443
+ this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
3444
+ if (end < 0 || end > len)
3445
+ this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
3446
+ if (end < begin)
3447
+ this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
3448
+ return this.span(this.row, this.col + begin, end - begin);
3449
+ }
3450
+ }
3451
+ $.$mol_span = $mol_span;
3452
+ })($ || ($ = {}));
3453
+
3454
+ ;
3455
+ "use strict";
3456
+ var $;
3457
+ (function ($_1) {
3458
+ $mol_test({
3459
+ 'span for same uri'($) {
3460
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
3461
+ const child = span.span(4, 5, 8);
3462
+ $mol_assert_equal(child.uri, 'test.ts');
3463
+ $mol_assert_equal(child.row, 4);
3464
+ $mol_assert_equal(child.col, 5);
3465
+ $mol_assert_equal(child.length, 8);
3466
+ },
3467
+ 'span after of given position'($) {
3468
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
3469
+ const child = span.after(11);
3470
+ $mol_assert_equal(child.uri, 'test.ts');
3471
+ $mol_assert_equal(child.row, 1);
3472
+ $mol_assert_equal(child.col, 7);
3473
+ $mol_assert_equal(child.length, 11);
3474
+ },
3475
+ 'slice span - regular'($) {
3476
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
3477
+ const child = span.slice(1, 4);
3478
+ $mol_assert_equal(child.row, 1);
3479
+ $mol_assert_equal(child.col, 4);
3480
+ $mol_assert_equal(child.length, 3);
3481
+ const child2 = span.slice(2, 2);
3482
+ $mol_assert_equal(child2.col, 5);
3483
+ $mol_assert_equal(child2.length, 0);
3484
+ },
3485
+ 'slice span - negative'($) {
3486
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
3487
+ const child = span.slice(-3, -1);
3488
+ $mol_assert_equal(child.row, 1);
3489
+ $mol_assert_equal(child.col, 5);
3490
+ $mol_assert_equal(child.length, 2);
3491
+ },
3492
+ 'slice span - out of range'($) {
3493
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
3494
+ $mol_assert_fail(() => span.slice(-1, 3), `End value '3' can't be less than begin value (test.ts#1:3/5)`);
3495
+ $mol_assert_fail(() => span.slice(1, 6), `End value '6' out of range (test.ts#1:3/5)`);
3496
+ $mol_assert_fail(() => span.slice(1, 10), `End value '10' out of range (test.ts#1:3/5)`);
3497
+ },
3498
+ 'error handling'($) {
3499
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
3500
+ const error = span.error('Some error');
3501
+ $mol_assert_equal(error.message, 'Some error (test.ts#1:3/4)');
3502
+ }
3503
+ });
3504
+ })($ || ($ = {}));
3505
+
3506
+ ;
3507
+ "use strict";
3508
+ var $;
3509
+ (function ($) {
3510
+ function $mol_tree2_to_string(tree) {
3511
+ let output = [];
3512
+ function dump(tree, prefix = '') {
3513
+ if (tree.type.length) {
3514
+ if (!prefix.length) {
3515
+ prefix = "\t";
3516
+ }
3517
+ output.push(tree.type);
3518
+ if (tree.kids.length == 1) {
3519
+ output.push(' ');
3520
+ dump(tree.kids[0], prefix);
3521
+ return;
3522
+ }
3523
+ output.push("\n");
3524
+ }
3525
+ else if (tree.value.length || prefix.length) {
3526
+ output.push("\\" + tree.value + "\n");
3527
+ }
3528
+ for (const kid of tree.kids) {
3529
+ output.push(prefix);
3530
+ dump(kid, prefix + "\t");
3531
+ }
3532
+ }
3533
+ dump(tree);
3534
+ return output.join('');
3535
+ }
3536
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
3537
+ })($ || ($ = {}));
3538
+
3539
+ ;
3540
+ "use strict";
3541
+ var $;
3542
+ (function ($) {
3543
+ function $mol_maybe(value) {
3544
+ return (value == null) ? [] : [value];
3545
+ }
3546
+ $.$mol_maybe = $mol_maybe;
3547
+ })($ || ($ = {}));
3548
+
3549
+ ;
3550
+ "use strict";
3551
+ var $;
3552
+ (function ($) {
3553
+ $mol_test({
3554
+ 'all cases of using maybe'() {
3555
+ $mol_assert_equal($mol_maybe(0)[0], 0);
3556
+ $mol_assert_equal($mol_maybe(false)[0], false);
3557
+ $mol_assert_equal($mol_maybe(null)[0], void 0);
3558
+ $mol_assert_equal($mol_maybe(void 0)[0], void 0);
3559
+ $mol_assert_equal($mol_maybe(void 0).map(v => v.toString())[0], void 0);
3560
+ $mol_assert_equal($mol_maybe(0).map(v => v.toString())[0], '0');
3561
+ },
3562
+ });
3563
+ })($ || ($ = {}));
3564
+
3565
+ ;
3566
+ "use strict";
3567
+ var $;
3568
+ (function ($) {
3569
+ class $mol_tree2 extends Object {
3570
+ type;
3571
+ value;
3572
+ kids;
3573
+ span;
3574
+ constructor(type, value, kids, span) {
3575
+ super();
3576
+ this.type = type;
3577
+ this.value = value;
3578
+ this.kids = kids;
3579
+ this.span = span;
3580
+ this[Symbol.toStringTag] = type || '\\' + value;
3581
+ }
3582
+ static list(kids, span = $mol_span.unknown) {
3583
+ return new $mol_tree2('', '', kids, span);
3584
+ }
3585
+ list(kids) {
3586
+ return $mol_tree2.list(kids, this.span);
3587
+ }
3588
+ static data(value, kids = [], span = $mol_span.unknown) {
3589
+ const chunks = value.split('\n');
3590
+ if (chunks.length > 1) {
3591
+ let kid_span = span.span(span.row, span.col, 0);
3592
+ const data = chunks.map(chunk => {
3593
+ kid_span = kid_span.after(chunk.length);
3594
+ return new $mol_tree2('', chunk, [], kid_span);
3595
+ });
3596
+ kids = [...data, ...kids];
3597
+ value = '';
3598
+ }
3599
+ return new $mol_tree2('', value, kids, span);
3600
+ }
3601
+ data(value, kids = []) {
3602
+ return $mol_tree2.data(value, kids, this.span);
3603
+ }
3604
+ static struct(type, kids = [], span = $mol_span.unknown) {
3605
+ if (/[ \n\t\\]/.test(type)) {
3606
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
3607
+ }
3608
+ return new $mol_tree2(type, '', kids, span);
3609
+ }
3610
+ struct(type, kids = []) {
3611
+ return $mol_tree2.struct(type, kids, this.span);
3612
+ }
3613
+ clone(kids, span = this.span) {
3614
+ return new $mol_tree2(this.type, this.value, kids, span);
3615
+ }
3616
+ text() {
3617
+ var values = [];
3618
+ for (var kid of this.kids) {
3619
+ if (kid.type)
3620
+ continue;
3621
+ values.push(kid.value);
3622
+ }
3623
+ return this.value + values.join('\n');
3624
+ }
3625
+ static fromString(str, uri = 'unknown') {
3626
+ return $$.$mol_tree2_from_string(str, uri);
3627
+ }
3628
+ toString() {
3629
+ return $$.$mol_tree2_to_string(this);
3630
+ }
3631
+ insert(value, ...path) {
3632
+ return this.update($mol_maybe(value), ...path)[0];
3633
+ }
3634
+ update(value, ...path) {
3635
+ if (path.length === 0)
3636
+ return value;
3637
+ const type = path[0];
3638
+ if (typeof type === 'string') {
3639
+ let replaced = false;
3640
+ const sub = this.kids.flatMap((item, index) => {
3641
+ if (item.type !== type)
3642
+ return item;
3643
+ replaced = true;
3644
+ return item.update(value, ...path.slice(1));
3645
+ }).filter(Boolean);
3646
+ if (!replaced && value) {
3647
+ sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
3648
+ }
3649
+ return [this.clone(sub)];
3650
+ }
3651
+ else if (typeof type === 'number') {
3652
+ const ins = (this.kids[type] || this.list([]))
3653
+ .update(value, ...path.slice(1));
3654
+ return [this.clone([
3655
+ ...this.kids.slice(0, type),
3656
+ ...ins,
3657
+ ...this.kids.slice(type + 1),
3658
+ ])];
3659
+ }
3660
+ else {
3661
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
3662
+ .flatMap(item => item.update(value, ...path.slice(1)));
3663
+ return [this.clone(kids)];
3664
+ }
3665
+ }
3666
+ select(...path) {
3667
+ let next = [this];
3668
+ for (const type of path) {
3669
+ if (!next.length)
3670
+ break;
3671
+ const prev = next;
3672
+ next = [];
3673
+ for (var item of prev) {
3674
+ switch (typeof (type)) {
3675
+ case 'string':
3676
+ for (var child of item.kids) {
3677
+ if (child.type == type) {
3678
+ next.push(child);
3679
+ }
3680
+ }
3681
+ break;
3682
+ case 'number':
3683
+ if (type < item.kids.length)
3684
+ next.push(item.kids[type]);
3685
+ break;
3686
+ default: next.push(...item.kids);
3687
+ }
3688
+ }
3689
+ }
3690
+ return this.list(next);
3691
+ }
3692
+ filter(path, value) {
3693
+ const sub = this.kids.filter(item => {
3694
+ var found = item.select(...path);
3695
+ if (value === undefined) {
3696
+ return Boolean(found.kids.length);
3697
+ }
3698
+ else {
3699
+ return found.kids.some(child => child.value == value);
3700
+ }
3701
+ });
3702
+ return this.clone(sub);
3703
+ }
3704
+ hack_self(belt, context = {}) {
3705
+ let handle = belt[this.type] || belt[''];
3706
+ if (!handle || handle === Object.prototype[this.type]) {
3707
+ handle = (input, belt, context) => [
3708
+ input.clone(input.hack(belt, context), context.span)
3709
+ ];
3710
+ }
3711
+ try {
3712
+ return handle(this, belt, context);
3713
+ }
3714
+ catch (error) {
3715
+ error.message += `\n${this.clone([])}${this.span}`;
3716
+ $mol_fail_hidden(error);
3717
+ }
3718
+ }
3719
+ hack(belt, context = {}) {
3720
+ return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
3721
+ }
3722
+ error(message, Class = Error) {
3723
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
3724
+ }
3725
+ }
3726
+ $.$mol_tree2 = $mol_tree2;
3727
+ class $mol_tree2_empty extends $mol_tree2 {
3728
+ constructor() {
3729
+ super('', '', [], $mol_span.unknown);
3730
+ }
3731
+ }
3732
+ $.$mol_tree2_empty = $mol_tree2_empty;
3733
+ })($ || ($ = {}));
3734
+
3735
+ ;
3736
+ "use strict";
3737
+ var $;
3738
+ (function ($_1) {
3739
+ function check(tree, ideal) {
3740
+ $mol_assert_equal(tree.toString(), $$.$mol_tree2_from_string(ideal).toString());
3741
+ }
3742
+ $mol_test({
3743
+ 'inserting'($) {
3744
+ check($.$mol_tree2_from_string(`
3745
+ a b c d
3746
+ `).insert($mol_tree2.struct('x'), 'a', 'b', 'c'), `
3747
+ a b x
3748
+ `);
3749
+ check($.$mol_tree2_from_string(`
3750
+ a b
3751
+ `).insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd'), `
3752
+ a b c x
3753
+ `);
3754
+ check($.$mol_tree2_from_string(`
3755
+ a b c d
3756
+ `)
3757
+ .insert($mol_tree2.struct('x'), 0, 0, 0), `
3758
+ a b x
3759
+ `);
3760
+ check($.$mol_tree2_from_string(`
3761
+ a b
3762
+ `)
3763
+ .insert($mol_tree2.struct('x'), 0, 0, 0, 0), `
3764
+ a b \\
3765
+ x
3766
+ `);
3767
+ check($.$mol_tree2_from_string(`
3768
+ a b c d
3769
+ `)
3770
+ .insert($mol_tree2.struct('x'), null, null, null), `
3771
+ a b x
3772
+ `);
3773
+ check($.$mol_tree2_from_string(`
3774
+ a b
3775
+ `)
3776
+ .insert($mol_tree2.struct('x'), null, null, null, null), `
3777
+ a b \\
3778
+ x
3779
+ `);
3780
+ },
3781
+ 'updating'($) {
3782
+ check($.$mol_tree2_from_string(`
3783
+ a b c d
3784
+ `).update([], 'a', 'b', 'c')[0], `
3785
+ a b
3786
+ `);
3787
+ check($.$mol_tree2_from_string(`
3788
+ a b c d
3789
+ `).update([$mol_tree2.struct('x')])[0], `
3790
+ x
3791
+ `);
3792
+ check($.$mol_tree2_from_string(`
3793
+ a b c d
3794
+ `).update([$mol_tree2.struct('x'), $mol_tree2.struct('y')], 'a', 'b', 'c')[0], `
3795
+ a b
3796
+ x
3797
+ y
3798
+ `);
3799
+ },
3800
+ 'deleting'($) {
3801
+ const base = $.$mol_tree2_from_string(`
3802
+ a b c d
3803
+ `);
3804
+ check(base.insert(null, 'a', 'b', 'c'), `
3805
+ a b
3806
+ `);
3807
+ check(base.update(base.select('a', 'b', 'c', null).kids, 'a', 'b', 'c')[0], `
3808
+ a b d
3809
+ `);
3810
+ check(base.insert(null, 0, 0, 0), `
3811
+ a b
3812
+ `);
3813
+ },
3814
+ 'hack'($) {
3815
+ const res = $.$mol_tree2_from_string(`
3816
+ foo bar xxx
3817
+ `)
3818
+ .hack({
3819
+ 'bar': (input, belt) => [input.struct('777', input.hack(belt))],
3820
+ });
3821
+ $mol_assert_equal(res.map(String), ['foo 777 xxx\n']);
3822
+ },
3823
+ });
3824
+ })($ || ($ = {}));
3825
+
3826
+ ;
3827
+ "use strict";
3828
+ var $;
3829
+ (function ($) {
3830
+ class $mol_error_syntax extends SyntaxError {
3831
+ reason;
3832
+ line;
3833
+ span;
3834
+ constructor(reason, line, span) {
3835
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
3836
+ this.reason = reason;
3837
+ this.line = line;
3838
+ this.span = span;
3839
+ }
3840
+ }
3841
+ $.$mol_error_syntax = $mol_error_syntax;
3842
+ })($ || ($ = {}));
3843
+
3844
+ ;
3845
+ "use strict";
3846
+ var $;
3847
+ (function ($) {
3848
+ function $mol_tree2_from_string(str, uri = '?') {
3849
+ const span = $mol_span.entire(uri, str);
3850
+ var root = $mol_tree2.list([], span);
3851
+ var stack = [root];
3852
+ var pos = 0, row = 0, min_indent = 0;
3853
+ while (str.length > pos) {
3854
+ var indent = 0;
3855
+ var line_start = pos;
3856
+ row++;
3857
+ while (str.length > pos && str[pos] == '\t') {
3858
+ indent++;
3859
+ pos++;
3860
+ }
3861
+ if (!root.kids.length) {
3862
+ min_indent = indent;
3863
+ }
3864
+ indent -= min_indent;
3865
+ if (indent < 0 || indent >= stack.length) {
3866
+ const sp = span.span(row, 1, pos - line_start);
3867
+ while (str.length > pos && str[pos] != '\n') {
3868
+ pos++;
3869
+ }
3870
+ if (indent < 0) {
3871
+ if (str.length > pos) {
3872
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
3873
+ }
3874
+ }
3875
+ else {
3876
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
3877
+ }
3878
+ }
3879
+ stack.length = indent + 1;
3880
+ var parent = stack[indent];
3881
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
3882
+ var error_start = pos;
3883
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
3884
+ pos++;
3885
+ }
3886
+ if (pos > error_start) {
3887
+ let line_end = str.indexOf('\n', pos);
3888
+ if (line_end === -1)
3889
+ line_end = str.length;
3890
+ const sp = span.span(row, error_start - line_start + 1, pos - error_start);
3891
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
3892
+ }
3893
+ var type_start = pos;
3894
+ while (str.length > pos &&
3895
+ str[pos] != '\\' &&
3896
+ str[pos] != ' ' &&
3897
+ str[pos] != '\t' &&
3898
+ str[pos] != '\n') {
3899
+ pos++;
3900
+ }
3901
+ if (pos > type_start) {
3902
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
3903
+ const parent_kids = parent.kids;
3904
+ parent_kids.push(next);
3905
+ parent = next;
3906
+ }
3907
+ if (str.length > pos && str[pos] == ' ') {
3908
+ pos++;
3909
+ }
3910
+ }
3911
+ if (str.length > pos && str[pos] == '\\') {
3912
+ var data_start = pos;
3913
+ while (str.length > pos && str[pos] != '\n') {
3914
+ pos++;
3915
+ }
3916
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
3917
+ const parent_kids = parent.kids;
3918
+ parent_kids.push(next);
3919
+ parent = next;
3920
+ }
3921
+ if (str.length === pos && stack.length > 0) {
3922
+ const sp = span.span(row, pos - line_start + 1, 1);
3923
+ this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
3924
+ }
3925
+ stack.push(parent);
3926
+ pos++;
3927
+ }
3928
+ return root;
3929
+ }
3930
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
3931
+ })($ || ($ = {}));
3932
+
3933
+ ;
3934
+ "use strict";
3935
+ var $;
3936
+ (function ($_1) {
3937
+ $mol_test({
3938
+ 'tree parsing'($) {
3939
+ $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
3940
+ $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
3941
+ $mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
3942
+ $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
3943
+ $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
3944
+ $mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
3945
+ $mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
3946
+ $mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
3947
+ },
3948
+ 'Too many tabs'($) {
3949
+ const tree = `
3950
+ foo
3951
+ bar
3952
+ `;
3953
+ $mol_assert_fail(() => {
3954
+ $.$mol_tree2_from_string(tree, 'test');
3955
+ }, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
3956
+ },
3957
+ 'Too few tabs'($) {
3958
+ const tree = `
3959
+ foo
3960
+ bar
3961
+ `;
3962
+ $mol_assert_fail(() => {
3963
+ $.$mol_tree2_from_string(tree, 'test');
3964
+ }, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
3965
+ },
3966
+ 'Wrong nodes separator at start'($) {
3967
+ const tree = `foo\n \tbar\n`;
3968
+ $mol_assert_fail(() => {
3969
+ $.$mol_tree2_from_string(tree, 'test');
3970
+ }, 'Wrong nodes separator\ntest#2:1/2\n!!\n \tbar');
3971
+ },
3972
+ 'Wrong nodes separator in the middle'($) {
3973
+ const tree = `foo bar\n`;
3974
+ $mol_assert_fail(() => {
3975
+ $.$mol_tree2_from_string(tree, 'test');
3976
+ }, 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar');
3977
+ },
3978
+ 'Unexpected EOF, LF required'($) {
3979
+ const tree = ` foo`;
3980
+ $mol_assert_fail(() => {
3981
+ $.$mol_tree2_from_string(tree, 'test');
3982
+ }, 'Unexpected EOF, LF required\ntest#1:5/1\n !\n foo');
3983
+ },
3984
+ 'Errors skip and collect'($) {
3985
+ const tree = `foo bar`;
3986
+ const errors = [];
3987
+ const $$ = $.$mol_ambient({
3988
+ $mol_fail: (error) => {
3989
+ errors.push(error.message);
3990
+ return null;
3991
+ }
3992
+ });
3993
+ const res = $$.$mol_tree2_from_string(tree, 'test');
3994
+ $mol_assert_like(errors, [
3995
+ 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar',
3996
+ 'Unexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
3997
+ ]);
3998
+ $mol_assert_equal(res.toString(), 'foo bar\n');
3999
+ },
4000
+ });
4001
+ })($ || ($ = {}));
4002
+
4003
+ ;
4004
+ "use strict";
4005
+ var $;
4006
+ (function ($) {
4007
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
4008
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
4009
+ return new $mol_tree2(String(json), '', [], span);
4010
+ }
4011
+ if (typeof json === 'string') {
4012
+ return $mol_tree2.data(json, [], span);
4013
+ }
4014
+ if (typeof json.toJSON === 'function') {
4015
+ return $mol_tree2_from_json(json.toJSON());
4016
+ }
4017
+ if (Array.isArray(json)) {
4018
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
4019
+ return new $mol_tree2('/', '', sub, span);
4020
+ }
4021
+ if (ArrayBuffer.isView(json)) {
4022
+ const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
4023
+ return $mol_tree2.data(String.fromCharCode(...buf), [], span);
4024
+ }
4025
+ if (json instanceof Date) {
4026
+ return new $mol_tree2('', json.toISOString(), [], span);
4027
+ }
4028
+ if (json.toString !== Object.prototype.toString) {
4029
+ return $mol_tree2.data(json.toString(), [], span);
4030
+ }
4031
+ if (json instanceof Error) {
4032
+ const { name, message, stack } = json;
4033
+ json = { ...json, name, message, stack };
4034
+ }
4035
+ const sub = [];
4036
+ for (var key in json) {
4037
+ const val = json[key];
4038
+ if (val === undefined)
4039
+ continue;
4040
+ const subsub = $mol_tree2_from_json(val, span);
4041
+ if (/^[^\n\t\\ ]+$/.test(key)) {
4042
+ sub.push(new $mol_tree2(key, '', [subsub], span));
4043
+ }
4044
+ else {
4045
+ sub.push($mol_tree2.data(key, [subsub], span));
4046
+ }
4047
+ }
4048
+ return new $mol_tree2('*', '', sub, span);
4049
+ }
4050
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
4051
+ })($ || ($ = {}));
4052
+
4053
+ ;
4054
+ "use strict";
4055
+ var $;
4056
+ (function ($) {
4057
+ $mol_test({
4058
+ 'fromJSON'() {
4059
+ $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
4060
+ $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
4061
+ $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
4062
+ $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
4063
+ $mol_assert_equal($mol_tree2_from_json(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
4064
+ $mol_assert_equal($mol_tree2_from_json({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
4065
+ },
4066
+ });
4067
+ })($ || ($ = {}));
4068
+
4069
+ ;
4070
+ "use strict";
4071
+ var $;
4072
+ (function ($) {
4073
+ const catched = new WeakSet();
4074
+ function $mol_fail_catch(error) {
4075
+ if (typeof error !== 'object')
4076
+ return false;
4077
+ if ($mol_promise_like(error))
4078
+ $mol_fail_hidden(error);
4079
+ if (catched.has(error))
4080
+ return false;
4081
+ catched.add(error);
4082
+ return true;
4083
+ }
4084
+ $.$mol_fail_catch = $mol_fail_catch;
4085
+ })($ || ($ = {}));
4086
+
4087
+ ;
4088
+ "use strict";
4089
+ var $;
4090
+ (function ($) {
4091
+ function $mol_try(handler) {
4092
+ try {
4093
+ return handler();
4094
+ }
4095
+ catch (error) {
4096
+ return error;
4097
+ }
4098
+ }
4099
+ $.$mol_try = $mol_try;
4100
+ })($ || ($ = {}));
4101
+
4102
+ ;
4103
+ "use strict";
4104
+ var $;
4105
+ (function ($) {
4106
+ $mol_test({
4107
+ 'return result without errors'() {
4108
+ $mol_assert_equal($mol_try(() => false), false);
4109
+ },
4110
+ });
4111
+ })($ || ($ = {}));
4112
+
4113
+ ;
4114
+ "use strict";
4115
+ var $;
4116
+ (function ($) {
4117
+ function $mol_fail_log(error) {
4118
+ if ($mol_promise_like(error))
4119
+ return false;
4120
+ if (!$mol_fail_catch(error))
4121
+ return false;
4122
+ $mol_try(() => { $mol_fail_hidden(error); });
4123
+ return true;
4124
+ }
4125
+ $.$mol_fail_log = $mol_fail_log;
4126
+ })($ || ($ = {}));
4127
+
4128
+ ;
4129
+ "use strict";
4130
+ var $;
4131
+ (function ($_1) {
4132
+ $mol_test_mocks.push($ => $.$mol_fail_log = () => false);
4133
+ })($ || ($ = {}));
4134
+
4135
+ ;
4136
+ "use strict";
4137
+ var $;
4138
+ (function ($_1) {
4139
+ var $$;
4140
+ (function ($$) {
4141
+ $mol_test({
4142
+ "Complex UCF encoding"($) {
4143
+ $mol_assert_equal($mol_charset_ucf_encode('hi мир, 你好 世界 🏴‍☠\t\n'), new Uint8Array([
4144
+ 0x68, 0x69, 0x20,
4145
+ 0x16, 0xBC, 0xB8, 0xC0, 0x2C, 0x20,
4146
+ 0x00, 0xE0, 0x9E, 0xFD, 0xB2, 0x20, 0x96, 0x9C, 0xCC, 0xEA, 0x20,
4147
+ 0x03, 0xF4, 0xE7, 0x00, 0x8D, 0x40, 0xA0, 0x4C, 0x09, 0x0A,
4148
+ ]));
4149
+ },
4150
+ });
4151
+ })($$ = $_1.$$ || ($_1.$$ = {}));
4152
+ })($ || ($ = {}));
4153
+
4154
+ ;
4155
+ "use strict";
4156
+ var $;
4157
+ (function ($_1) {
4158
+ var $$;
4159
+ (function ($$) {
4160
+ $mol_test({
4161
+ "Complex UCF eecoding"($) {
4162
+ $mol_assert_equal('hi мир, 你好 世界 🏴‍☠\t\n', $mol_charset_ucf_decode(new Uint8Array([
4163
+ 0x68, 0x69, 0x20,
4164
+ 0x16, 0xBC, 0xB8, 0xC0, 0x2C, 0x20,
4165
+ 0x00, 0xE0, 0x9E, 0xFD, 0xB2, 0x20, 0x96, 0x9C, 0xCC, 0xEA, 0x20,
4166
+ 0x03, 0xF4, 0xE7, 0x00, 0x8D, 0x40, 0xA0, 0x4C, 0x09, 0x0A,
4167
+ ])));
4168
+ },
4169
+ });
4170
+ })($$ = $_1.$$ || ($_1.$$ = {}));
4171
+ })($ || ($ = {}));
4172
+
22
4173
 
23
4174
  //# sourceMappingURL=node.test.js.map