mol_wire_lib 1.0.104 → 1.0.105
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/README.md +9 -1
- package/node.d.ts +124 -0
- package/node.deps.json +1 -1
- package/node.esm.js +561 -0
- package/node.esm.js.map +1 -1
- package/node.js +561 -0
- package/node.js.map +1 -1
- package/node.test.js +1797 -1797
- package/node.test.js.map +1 -1
- package/package.json +17 -3
- package/web.d.ts +74 -0
- package/web.deps.json +1 -1
- package/web.esm.js +120 -0
- package/web.esm.js.map +1 -1
- package/web.js +120 -0
- package/web.js.map +1 -1
- package/web.test.js +0 -120
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
|
@@ -1429,109 +1429,36 @@ var $;
|
|
|
1429
1429
|
"use strict";
|
|
1430
1430
|
var $;
|
|
1431
1431
|
(function ($) {
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
$.$
|
|
1432
|
+
$.$mol_mem = $mol_wire_mem(0);
|
|
1433
|
+
$.$mol_mem_key = $mol_wire_mem(1);
|
|
1434
|
+
$.$mol_mem_key2 = $mol_wire_mem(2);
|
|
1435
|
+
$.$mol_mem_key3 = $mol_wire_mem(3);
|
|
1436
1436
|
})($ || ($ = {}));
|
|
1437
|
-
//mol/
|
|
1437
|
+
//mol/mem/mem.ts
|
|
1438
1438
|
;
|
|
1439
1439
|
"use strict";
|
|
1440
1440
|
var $;
|
|
1441
|
-
(function ($
|
|
1442
|
-
function $
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
$_1.$mol_test = $mol_test;
|
|
1451
|
-
$_1.$mol_test_mocks = [];
|
|
1452
|
-
$_1.$mol_test_all = [];
|
|
1453
|
-
async function $mol_test_run() {
|
|
1454
|
-
for (var test of $_1.$mol_test_all) {
|
|
1455
|
-
let context = Object.create($$);
|
|
1456
|
-
for (let mock of $_1.$mol_test_mocks)
|
|
1457
|
-
await mock(context);
|
|
1458
|
-
const res = test(context);
|
|
1459
|
-
if (res instanceof Promise) {
|
|
1460
|
-
await new Promise((done, fail) => {
|
|
1461
|
-
res.then(done, fail);
|
|
1462
|
-
setTimeout(() => fail(new Error('Test timeout: ' + test.name)), 1000);
|
|
1463
|
-
});
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
$$.$mol_log3_done({
|
|
1467
|
-
place: '$mol_test',
|
|
1468
|
-
message: 'All tests passed',
|
|
1469
|
-
count: $_1.$mol_test_all.length,
|
|
1441
|
+
(function ($) {
|
|
1442
|
+
function $mol_log3_area_lazy(event) {
|
|
1443
|
+
const self = this;
|
|
1444
|
+
const stack = self.$mol_log3_stack;
|
|
1445
|
+
const deep = stack.length;
|
|
1446
|
+
let logged = false;
|
|
1447
|
+
stack.push(() => {
|
|
1448
|
+
logged = true;
|
|
1449
|
+
self.$mol_log3_area.call(self, event);
|
|
1470
1450
|
});
|
|
1451
|
+
return () => {
|
|
1452
|
+
if (logged)
|
|
1453
|
+
self.console.groupEnd();
|
|
1454
|
+
if (stack.length > deep)
|
|
1455
|
+
stack.length = deep;
|
|
1456
|
+
};
|
|
1471
1457
|
}
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
function $mol_test_schedule() {
|
|
1475
|
-
if (scheduled)
|
|
1476
|
-
return;
|
|
1477
|
-
scheduled = true;
|
|
1478
|
-
setTimeout(async () => {
|
|
1479
|
-
scheduled = false;
|
|
1480
|
-
try {
|
|
1481
|
-
await $mol_test_run();
|
|
1482
|
-
}
|
|
1483
|
-
finally {
|
|
1484
|
-
$$.$mol_test_complete();
|
|
1485
|
-
}
|
|
1486
|
-
}, 0);
|
|
1487
|
-
}
|
|
1488
|
-
$_1.$mol_test_schedule = $mol_test_schedule;
|
|
1489
|
-
$_1.$mol_test_mocks.push(context => {
|
|
1490
|
-
let seed = 0;
|
|
1491
|
-
context.Math = Object.create(Math);
|
|
1492
|
-
context.Math.random = () => Math.sin(seed++);
|
|
1493
|
-
const forbidden = ['XMLHttpRequest', 'fetch'];
|
|
1494
|
-
for (let api of forbidden) {
|
|
1495
|
-
context[api] = new Proxy(function () { }, {
|
|
1496
|
-
get() {
|
|
1497
|
-
$mol_fail_hidden(new Error(`${api} is forbidden in tests`));
|
|
1498
|
-
},
|
|
1499
|
-
apply() {
|
|
1500
|
-
$mol_fail_hidden(new Error(`${api} is forbidden in tests`));
|
|
1501
|
-
},
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
});
|
|
1505
|
-
$mol_test({
|
|
1506
|
-
'mocked Math.random'($) {
|
|
1507
|
-
console.assert($.Math.random() === 0);
|
|
1508
|
-
console.assert($.Math.random() === Math.sin(1));
|
|
1509
|
-
},
|
|
1510
|
-
'forbidden XMLHttpRequest'($) {
|
|
1511
|
-
try {
|
|
1512
|
-
console.assert(void new $.XMLHttpRequest);
|
|
1513
|
-
}
|
|
1514
|
-
catch (error) {
|
|
1515
|
-
console.assert(error.message === 'XMLHttpRequest is forbidden in tests');
|
|
1516
|
-
}
|
|
1517
|
-
},
|
|
1518
|
-
'forbidden fetch'($) {
|
|
1519
|
-
try {
|
|
1520
|
-
console.assert(void $.fetch(''));
|
|
1521
|
-
}
|
|
1522
|
-
catch (error) {
|
|
1523
|
-
console.assert(error.message === 'fetch is forbidden in tests');
|
|
1524
|
-
}
|
|
1525
|
-
},
|
|
1526
|
-
});
|
|
1527
|
-
})($ || ($ = {}));
|
|
1528
|
-
//mol/test/test.test.ts
|
|
1529
|
-
;
|
|
1530
|
-
"use strict";
|
|
1531
|
-
var $;
|
|
1532
|
-
(function ($) {
|
|
1458
|
+
$.$mol_log3_area_lazy = $mol_log3_area_lazy;
|
|
1459
|
+
$.$mol_log3_stack = [];
|
|
1533
1460
|
})($ || ($ = {}));
|
|
1534
|
-
//mol/
|
|
1461
|
+
//mol/log3/log3.ts
|
|
1535
1462
|
;
|
|
1536
1463
|
"use strict";
|
|
1537
1464
|
//node/node.ts
|
|
@@ -1578,531 +1505,387 @@ require = (req => Object.assign(function require(name) {
|
|
|
1578
1505
|
"use strict";
|
|
1579
1506
|
var $;
|
|
1580
1507
|
(function ($) {
|
|
1581
|
-
|
|
1508
|
+
function $mol_deprecated(message) {
|
|
1509
|
+
return (host, field, descr) => {
|
|
1510
|
+
const value = descr.value;
|
|
1511
|
+
let warned = false;
|
|
1512
|
+
descr.value = function $mol_deprecated_wrapper(...args) {
|
|
1513
|
+
if (!warned) {
|
|
1514
|
+
$$.$mol_log3_warn({
|
|
1515
|
+
place: `${host.constructor.name}::${field}`,
|
|
1516
|
+
message: `Deprecated`,
|
|
1517
|
+
hint: message,
|
|
1518
|
+
});
|
|
1519
|
+
warned = true;
|
|
1520
|
+
}
|
|
1521
|
+
return value.call(this, ...args);
|
|
1522
|
+
};
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
1525
|
+
$.$mol_deprecated = $mol_deprecated;
|
|
1582
1526
|
})($ || ($ = {}));
|
|
1583
|
-
//mol/
|
|
1527
|
+
//mol/deprecated/deprecated.ts
|
|
1584
1528
|
;
|
|
1585
1529
|
"use strict";
|
|
1586
1530
|
var $;
|
|
1587
1531
|
(function ($) {
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
if (node_set.has(nextNode)) {
|
|
1606
|
-
el.insertBefore(view, nextNode);
|
|
1607
|
-
break;
|
|
1608
|
-
}
|
|
1609
|
-
else {
|
|
1610
|
-
const nn = nextNode.nextSibling;
|
|
1611
|
-
el.removeChild(nextNode);
|
|
1612
|
-
nextNode = nn;
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
else {
|
|
1618
|
-
if (nextNode && nextNode.nodeName === '#text') {
|
|
1619
|
-
const str = String(view);
|
|
1620
|
-
if (nextNode.nodeValue !== str)
|
|
1621
|
-
nextNode.nodeValue = str;
|
|
1622
|
-
nextNode = nextNode.nextSibling;
|
|
1532
|
+
$.$mol_tree_convert = Symbol('$mol_tree_convert');
|
|
1533
|
+
class $mol_tree extends $mol_object2 {
|
|
1534
|
+
type;
|
|
1535
|
+
data;
|
|
1536
|
+
sub;
|
|
1537
|
+
baseUri;
|
|
1538
|
+
row;
|
|
1539
|
+
col;
|
|
1540
|
+
length;
|
|
1541
|
+
constructor(config = {}) {
|
|
1542
|
+
super();
|
|
1543
|
+
this.type = config.type || '';
|
|
1544
|
+
if (config.value !== undefined) {
|
|
1545
|
+
var sub = $mol_tree.values(config.value);
|
|
1546
|
+
if (config.type || sub.length > 1) {
|
|
1547
|
+
this.sub = [...sub, ...(config.sub || [])];
|
|
1548
|
+
this.data = config.data || '';
|
|
1623
1549
|
}
|
|
1624
1550
|
else {
|
|
1625
|
-
|
|
1626
|
-
|
|
1551
|
+
this.data = sub[0].data;
|
|
1552
|
+
this.sub = config.sub || [];
|
|
1627
1553
|
}
|
|
1628
1554
|
}
|
|
1555
|
+
else {
|
|
1556
|
+
this.data = config.data || '';
|
|
1557
|
+
this.sub = config.sub || [];
|
|
1558
|
+
}
|
|
1559
|
+
this.baseUri = config.baseUri || '';
|
|
1560
|
+
this.row = config.row || 0;
|
|
1561
|
+
this.col = config.col || 0;
|
|
1562
|
+
this.length = config.length || 0;
|
|
1629
1563
|
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1564
|
+
static values(str, baseUri) {
|
|
1565
|
+
return str.split('\n').map((data, index) => new $mol_tree({
|
|
1566
|
+
data: data,
|
|
1567
|
+
baseUri: baseUri,
|
|
1568
|
+
row: index + 1,
|
|
1569
|
+
length: data.length,
|
|
1570
|
+
}));
|
|
1634
1571
|
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
;
|
|
1646
|
-
"use strict";
|
|
1647
|
-
//mol/type/assert/assert.ts
|
|
1648
|
-
;
|
|
1649
|
-
"use strict";
|
|
1650
|
-
//mol/type/equals/equals.test.ts
|
|
1651
|
-
;
|
|
1652
|
-
"use strict";
|
|
1653
|
-
//mol/type/equals/equals.ts
|
|
1654
|
-
;
|
|
1655
|
-
"use strict";
|
|
1656
|
-
//mol/type/partial/deep/deep.test.ts
|
|
1657
|
-
;
|
|
1658
|
-
"use strict";
|
|
1659
|
-
//mol/type/partial/deep/deep.ts
|
|
1660
|
-
;
|
|
1661
|
-
"use strict";
|
|
1662
|
-
var $;
|
|
1663
|
-
(function ($) {
|
|
1664
|
-
$mol_test({
|
|
1665
|
-
'Make empty div'() {
|
|
1666
|
-
$mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
|
|
1667
|
-
},
|
|
1668
|
-
'Define native field'() {
|
|
1669
|
-
const dom = $mol_jsx("input", { value: '123' });
|
|
1670
|
-
$mol_assert_equal(dom.outerHTML, '<input value="123">');
|
|
1671
|
-
$mol_assert_equal(dom.value, '123');
|
|
1672
|
-
},
|
|
1673
|
-
'Define classes'() {
|
|
1674
|
-
const dom = $mol_jsx("div", { class: 'foo bar' });
|
|
1675
|
-
$mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
|
|
1676
|
-
},
|
|
1677
|
-
'Define styles'() {
|
|
1678
|
-
const dom = $mol_jsx("div", { style: { color: 'red' } });
|
|
1679
|
-
$mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
|
|
1680
|
-
},
|
|
1681
|
-
'Define dataset'() {
|
|
1682
|
-
const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
|
|
1683
|
-
$mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
|
|
1684
|
-
},
|
|
1685
|
-
'Define attributes'() {
|
|
1686
|
-
const dom = $mol_jsx("div", { lang: "ru", hidden: true });
|
|
1687
|
-
$mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
|
|
1688
|
-
},
|
|
1689
|
-
'Define child nodes'() {
|
|
1690
|
-
const dom = $mol_jsx("div", null,
|
|
1691
|
-
"hello",
|
|
1692
|
-
$mol_jsx("strong", null, "world"),
|
|
1693
|
-
"!");
|
|
1694
|
-
$mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
|
|
1695
|
-
},
|
|
1696
|
-
'Function as component'() {
|
|
1697
|
-
const Button = ({ hint }, target) => {
|
|
1698
|
-
return $mol_jsx("button", { title: hint }, target());
|
|
1699
|
-
};
|
|
1700
|
-
const dom = $mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
|
|
1701
|
-
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
|
|
1702
|
-
},
|
|
1703
|
-
'Nested guid generation'() {
|
|
1704
|
-
const Foo = () => {
|
|
1705
|
-
return $mol_jsx("div", null,
|
|
1706
|
-
$mol_jsx(Bar, { id: "/bar" },
|
|
1707
|
-
$mol_jsx("img", { id: "/icon" })));
|
|
1708
|
-
};
|
|
1709
|
-
const Bar = (props, icon) => {
|
|
1710
|
-
return $mol_jsx("span", null, icon);
|
|
1711
|
-
};
|
|
1712
|
-
const dom = $mol_jsx(Foo, { id: "/foo" });
|
|
1713
|
-
$mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
|
|
1714
|
-
},
|
|
1715
|
-
'Fail on non unique ids'() {
|
|
1716
|
-
const App = () => {
|
|
1717
|
-
return $mol_jsx("div", null,
|
|
1718
|
-
$mol_jsx("span", { id: "/bar" }),
|
|
1719
|
-
$mol_jsx("span", { id: "/bar" }));
|
|
1720
|
-
};
|
|
1721
|
-
$mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
|
|
1722
|
-
},
|
|
1723
|
-
});
|
|
1724
|
-
})($ || ($ = {}));
|
|
1725
|
-
//mol/jsx/jsx.test.tsx
|
|
1726
|
-
;
|
|
1727
|
-
"use strict";
|
|
1728
|
-
var $;
|
|
1729
|
-
(function ($) {
|
|
1730
|
-
$.$mol_jsx_prefix = '';
|
|
1731
|
-
$.$mol_jsx_booked = null;
|
|
1732
|
-
$.$mol_jsx_document = {
|
|
1733
|
-
getElementById: () => null,
|
|
1734
|
-
createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
|
|
1735
|
-
createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
|
|
1736
|
-
};
|
|
1737
|
-
$.$mol_jsx_frag = '';
|
|
1738
|
-
function $mol_jsx(Elem, props, ...childNodes) {
|
|
1739
|
-
const id = props && props.id || '';
|
|
1740
|
-
if (Elem && $.$mol_jsx_booked) {
|
|
1741
|
-
if ($.$mol_jsx_booked.has(id)) {
|
|
1742
|
-
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
|
|
1743
|
-
}
|
|
1744
|
-
else {
|
|
1745
|
-
$.$mol_jsx_booked.add(id);
|
|
1746
|
-
}
|
|
1572
|
+
clone(config = {}) {
|
|
1573
|
+
return new $mol_tree({
|
|
1574
|
+
type: ('type' in config) ? config.type : this.type,
|
|
1575
|
+
data: ('data' in config) ? config.data : this.data,
|
|
1576
|
+
sub: ('sub' in config) ? config.sub : this.sub,
|
|
1577
|
+
baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
|
|
1578
|
+
row: ('row' in config) ? config.row : this.row,
|
|
1579
|
+
col: ('col' in config) ? config.col : this.col,
|
|
1580
|
+
length: ('length' in config) ? config.length : this.length,
|
|
1581
|
+
value: config.value
|
|
1582
|
+
});
|
|
1747
1583
|
}
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
}
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1584
|
+
make(config) {
|
|
1585
|
+
return new $mol_tree({
|
|
1586
|
+
baseUri: this.baseUri,
|
|
1587
|
+
row: this.row,
|
|
1588
|
+
col: this.col,
|
|
1589
|
+
length: this.length,
|
|
1590
|
+
...config,
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
make_data(value, sub) {
|
|
1594
|
+
return this.make({ value, sub });
|
|
1595
|
+
}
|
|
1596
|
+
make_struct(type, sub) {
|
|
1597
|
+
return this.make({ type, sub });
|
|
1598
|
+
}
|
|
1599
|
+
static fromString(str, baseUri) {
|
|
1600
|
+
var root = new $mol_tree({ baseUri: baseUri });
|
|
1601
|
+
var stack = [root];
|
|
1602
|
+
var row = 0;
|
|
1603
|
+
var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
|
|
1604
|
+
var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
|
|
1605
|
+
lines.forEach(line => {
|
|
1606
|
+
++row;
|
|
1607
|
+
var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
|
|
1608
|
+
if (!chunks || chunks[4])
|
|
1609
|
+
return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
|
|
1610
|
+
var indent = chunks[1];
|
|
1611
|
+
var path = chunks[2];
|
|
1612
|
+
var data = chunks[3];
|
|
1613
|
+
var deep = indent.length;
|
|
1614
|
+
var types = path ? path.replace(/ $/, '').split(/ +/) : [];
|
|
1615
|
+
if (stack.length <= deep)
|
|
1616
|
+
return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
|
|
1617
|
+
stack.length = deep + 1;
|
|
1618
|
+
var parent = stack[deep];
|
|
1619
|
+
let col = deep;
|
|
1620
|
+
types.forEach(type => {
|
|
1621
|
+
if (!type)
|
|
1622
|
+
return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
|
|
1623
|
+
var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
|
|
1624
|
+
const parent_sub = parent.sub;
|
|
1625
|
+
parent_sub.push(next);
|
|
1626
|
+
parent = next;
|
|
1627
|
+
col += type.length + 1;
|
|
1628
|
+
});
|
|
1629
|
+
if (data) {
|
|
1630
|
+
var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
|
|
1631
|
+
const parent_sub = parent.sub;
|
|
1632
|
+
parent_sub.push(next);
|
|
1633
|
+
parent = next;
|
|
1773
1634
|
}
|
|
1635
|
+
stack.push(parent);
|
|
1636
|
+
});
|
|
1637
|
+
return root;
|
|
1638
|
+
}
|
|
1639
|
+
static fromJSON(json, baseUri = '') {
|
|
1640
|
+
switch (true) {
|
|
1641
|
+
case typeof json === 'boolean':
|
|
1642
|
+
case typeof json === 'number':
|
|
1643
|
+
case json === null:
|
|
1644
|
+
return new $mol_tree({
|
|
1645
|
+
type: String(json),
|
|
1646
|
+
baseUri: baseUri
|
|
1647
|
+
});
|
|
1648
|
+
case typeof json === 'string':
|
|
1649
|
+
return new $mol_tree({
|
|
1650
|
+
value: json,
|
|
1651
|
+
baseUri: baseUri
|
|
1652
|
+
});
|
|
1653
|
+
case Array.isArray(json):
|
|
1654
|
+
return new $mol_tree({
|
|
1655
|
+
type: "/",
|
|
1656
|
+
sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
|
|
1657
|
+
});
|
|
1658
|
+
case json instanceof Date:
|
|
1659
|
+
return new $mol_tree({
|
|
1660
|
+
value: json.toISOString(),
|
|
1661
|
+
baseUri: baseUri
|
|
1662
|
+
});
|
|
1663
|
+
default:
|
|
1664
|
+
if (typeof json[$.$mol_tree_convert] === 'function') {
|
|
1665
|
+
return json[$.$mol_tree_convert]();
|
|
1666
|
+
}
|
|
1667
|
+
if (typeof json.toJSON === 'function') {
|
|
1668
|
+
return $mol_tree.fromJSON(json.toJSON());
|
|
1669
|
+
}
|
|
1670
|
+
if (json instanceof Error) {
|
|
1671
|
+
const { name, message, stack } = json;
|
|
1672
|
+
json = { ...json, name, message, stack };
|
|
1673
|
+
}
|
|
1674
|
+
var sub = [];
|
|
1675
|
+
for (var key in json) {
|
|
1676
|
+
if (json[key] === undefined)
|
|
1677
|
+
continue;
|
|
1678
|
+
const subsub = $mol_tree.fromJSON(json[key], baseUri);
|
|
1679
|
+
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
1680
|
+
var child = new $mol_tree({
|
|
1681
|
+
type: key,
|
|
1682
|
+
baseUri: baseUri,
|
|
1683
|
+
sub: [subsub],
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
else {
|
|
1687
|
+
var child = new $mol_tree({
|
|
1688
|
+
value: key,
|
|
1689
|
+
baseUri: baseUri,
|
|
1690
|
+
sub: [subsub],
|
|
1691
|
+
});
|
|
1692
|
+
}
|
|
1693
|
+
sub.push(child);
|
|
1694
|
+
}
|
|
1695
|
+
return new $mol_tree({
|
|
1696
|
+
type: "*",
|
|
1697
|
+
sub: sub,
|
|
1698
|
+
baseUri: baseUri
|
|
1699
|
+
});
|
|
1774
1700
|
}
|
|
1775
1701
|
}
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
|
|
1779
|
-
: $.$mol_jsx_document.createDocumentFragment();
|
|
1702
|
+
get uri() {
|
|
1703
|
+
return this.baseUri + '#' + this.row + ':' + this.col;
|
|
1780
1704
|
}
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
typeof props[key] === 'object' &&
|
|
1791
|
-
Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
|
|
1792
|
-
if (typeof node[key] === 'object') {
|
|
1793
|
-
Object.assign(node[key], props[key]);
|
|
1794
|
-
continue;
|
|
1705
|
+
toString(prefix = '') {
|
|
1706
|
+
var output = '';
|
|
1707
|
+
if (this.type.length) {
|
|
1708
|
+
if (!prefix.length) {
|
|
1709
|
+
prefix = "\t";
|
|
1710
|
+
}
|
|
1711
|
+
output += this.type;
|
|
1712
|
+
if (this.sub.length == 1) {
|
|
1713
|
+
return output + ' ' + this.sub[0].toString(prefix);
|
|
1795
1714
|
}
|
|
1715
|
+
output += "\n";
|
|
1796
1716
|
}
|
|
1797
|
-
else {
|
|
1798
|
-
|
|
1717
|
+
else if (this.data.length || prefix.length) {
|
|
1718
|
+
output += "\\" + this.data + "\n";
|
|
1799
1719
|
}
|
|
1720
|
+
for (var child of this.sub) {
|
|
1721
|
+
output += prefix;
|
|
1722
|
+
output += child.toString(prefix + "\t");
|
|
1723
|
+
}
|
|
1724
|
+
return output;
|
|
1725
|
+
}
|
|
1726
|
+
toJSON() {
|
|
1727
|
+
if (!this.type)
|
|
1728
|
+
return this.value;
|
|
1729
|
+
if (this.type === 'true')
|
|
1730
|
+
return true;
|
|
1731
|
+
if (this.type === 'false')
|
|
1732
|
+
return false;
|
|
1733
|
+
if (this.type === 'null')
|
|
1734
|
+
return null;
|
|
1735
|
+
if (this.type === '*') {
|
|
1736
|
+
var obj = {};
|
|
1737
|
+
for (var child of this.sub) {
|
|
1738
|
+
if (child.type === '-')
|
|
1739
|
+
continue;
|
|
1740
|
+
var key = child.type || child.clone({ sub: child.sub.slice(0, child.sub.length - 1) }).value;
|
|
1741
|
+
var val = child.sub[child.sub.length - 1].toJSON();
|
|
1742
|
+
if (val !== undefined)
|
|
1743
|
+
obj[key] = val;
|
|
1744
|
+
}
|
|
1745
|
+
return obj;
|
|
1746
|
+
}
|
|
1747
|
+
if (this.type === '/') {
|
|
1748
|
+
var res = [];
|
|
1749
|
+
this.sub.forEach(child => {
|
|
1750
|
+
if (child.type === '-')
|
|
1751
|
+
return;
|
|
1752
|
+
var val = child.toJSON();
|
|
1753
|
+
if (val !== undefined)
|
|
1754
|
+
res.push(val);
|
|
1755
|
+
});
|
|
1756
|
+
return res;
|
|
1757
|
+
}
|
|
1758
|
+
if (this.type === 'time') {
|
|
1759
|
+
return new Date(this.value);
|
|
1760
|
+
}
|
|
1761
|
+
const numb = Number(this.type);
|
|
1762
|
+
if (!Number.isNaN(numb) || this.type === 'NaN')
|
|
1763
|
+
return numb;
|
|
1764
|
+
throw new Error(`Unknown type (${this.type}) at ${this.uri}`);
|
|
1765
|
+
}
|
|
1766
|
+
get value() {
|
|
1767
|
+
var values = [];
|
|
1768
|
+
for (var child of this.sub) {
|
|
1769
|
+
if (child.type)
|
|
1770
|
+
continue;
|
|
1771
|
+
values.push(child.value);
|
|
1772
|
+
}
|
|
1773
|
+
return this.data + values.join("\n");
|
|
1774
|
+
}
|
|
1775
|
+
insert(value, ...path) {
|
|
1776
|
+
if (path.length === 0)
|
|
1777
|
+
return value;
|
|
1778
|
+
const type = path[0];
|
|
1779
|
+
if (typeof type === 'string') {
|
|
1780
|
+
let replaced = false;
|
|
1781
|
+
const sub = this.sub.map((item, index) => {
|
|
1782
|
+
if (item.type !== type)
|
|
1783
|
+
return item;
|
|
1784
|
+
replaced = true;
|
|
1785
|
+
return item.insert(value, ...path.slice(1));
|
|
1786
|
+
});
|
|
1787
|
+
if (!replaced)
|
|
1788
|
+
sub.push(new $mol_tree({ type }).insert(value, ...path.slice(1)));
|
|
1789
|
+
return this.clone({ sub });
|
|
1790
|
+
}
|
|
1791
|
+
else if (typeof type === 'number') {
|
|
1792
|
+
const sub = this.sub.slice();
|
|
1793
|
+
sub[type] = (sub[type] || new $mol_tree).insert(value, ...path.slice(1));
|
|
1794
|
+
return this.clone({ sub });
|
|
1795
|
+
}
|
|
1796
|
+
else {
|
|
1797
|
+
return this.clone({ sub: ((this.sub.length === 0) ? [new $mol_tree()] : this.sub).map(item => item.insert(value, ...path.slice(1))) });
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
select(...path) {
|
|
1801
|
+
var next = [this];
|
|
1802
|
+
for (var type of path) {
|
|
1803
|
+
if (!next.length)
|
|
1804
|
+
break;
|
|
1805
|
+
var prev = next;
|
|
1806
|
+
next = [];
|
|
1807
|
+
for (var item of prev) {
|
|
1808
|
+
switch (typeof (type)) {
|
|
1809
|
+
case 'string':
|
|
1810
|
+
for (var child of item.sub) {
|
|
1811
|
+
if (!type || (child.type == type)) {
|
|
1812
|
+
next.push(child);
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
break;
|
|
1816
|
+
case 'number':
|
|
1817
|
+
if (type < item.sub.length)
|
|
1818
|
+
next.push(item.sub[type]);
|
|
1819
|
+
break;
|
|
1820
|
+
default: next.push(...item.sub);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
return new $mol_tree({ sub: next });
|
|
1825
|
+
}
|
|
1826
|
+
filter(path, value) {
|
|
1827
|
+
var sub = this.sub.filter(function (item) {
|
|
1828
|
+
var found = item.select(...path);
|
|
1829
|
+
if (value == null) {
|
|
1830
|
+
return Boolean(found.sub.length);
|
|
1831
|
+
}
|
|
1832
|
+
else {
|
|
1833
|
+
return found.sub.some(child => child.value == value);
|
|
1834
|
+
}
|
|
1835
|
+
});
|
|
1836
|
+
return new $mol_tree({ sub: sub });
|
|
1837
|
+
}
|
|
1838
|
+
transform(visit, stack = []) {
|
|
1839
|
+
const sub_stack = [this, ...stack];
|
|
1840
|
+
return visit(sub_stack, () => this.sub.map(node => node.transform(visit, sub_stack)).filter(n => n));
|
|
1841
|
+
}
|
|
1842
|
+
hack(context) {
|
|
1843
|
+
const sub = [].concat(...this.sub.map(child => {
|
|
1844
|
+
const handle = context[child.type] || context[''];
|
|
1845
|
+
if (!handle)
|
|
1846
|
+
$mol_fail(child.error('Handler not defined'));
|
|
1847
|
+
return handle(child, context);
|
|
1848
|
+
}));
|
|
1849
|
+
return this.clone({ sub });
|
|
1850
|
+
}
|
|
1851
|
+
error(message) {
|
|
1852
|
+
return new Error(`${message}:\n${this} ${this.baseUri}:${this.row}:${this.col}`);
|
|
1800
1853
|
}
|
|
1801
|
-
if (guid)
|
|
1802
|
-
node.id = guid;
|
|
1803
|
-
return node;
|
|
1804
1854
|
}
|
|
1805
|
-
|
|
1855
|
+
__decorate([
|
|
1856
|
+
$mol_deprecated('Use $mol_tree:hack')
|
|
1857
|
+
], $mol_tree.prototype, "transform", null);
|
|
1858
|
+
$.$mol_tree = $mol_tree;
|
|
1806
1859
|
})($ || ($ = {}));
|
|
1807
|
-
//mol/
|
|
1860
|
+
//mol/tree/tree.ts
|
|
1808
1861
|
;
|
|
1809
1862
|
"use strict";
|
|
1810
1863
|
var $;
|
|
1811
1864
|
(function ($) {
|
|
1812
|
-
$
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
$mol_assert_ok($mol_compare_deep(1, 1));
|
|
1821
|
-
$mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
|
|
1822
|
-
$mol_assert_not($mol_compare_deep(1, 2));
|
|
1823
|
-
$mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
|
|
1824
|
-
$mol_assert_not($mol_compare_deep(Object(1), Object(2)));
|
|
1825
|
-
},
|
|
1826
|
-
'POJO'() {
|
|
1827
|
-
$mol_assert_ok($mol_compare_deep({}, {}));
|
|
1828
|
-
$mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
|
|
1829
|
-
$mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
|
|
1830
|
-
$mol_assert_not($mol_compare_deep({}, { a: undefined }));
|
|
1831
|
-
$mol_assert_ok($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
|
|
1832
|
-
$mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
|
|
1833
|
-
},
|
|
1834
|
-
'Array'() {
|
|
1835
|
-
$mol_assert_ok($mol_compare_deep([], []));
|
|
1836
|
-
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
|
|
1837
|
-
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
|
|
1838
|
-
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
|
|
1839
|
-
},
|
|
1840
|
-
'Non POJO are different'() {
|
|
1841
|
-
class Thing extends Object {
|
|
1842
|
-
}
|
|
1843
|
-
$mol_assert_not($mol_compare_deep(new Thing, new Thing));
|
|
1844
|
-
$mol_assert_not($mol_compare_deep(() => 1, () => 1));
|
|
1845
|
-
$mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
|
|
1846
|
-
},
|
|
1847
|
-
'same POJOs with cyclic reference'() {
|
|
1848
|
-
const a = { foo: {} };
|
|
1849
|
-
a['self'] = a;
|
|
1850
|
-
const b = { foo: {} };
|
|
1851
|
-
b['self'] = b;
|
|
1852
|
-
$mol_assert_ok($mol_compare_deep(a, b));
|
|
1853
|
-
},
|
|
1854
|
-
'Date'() {
|
|
1855
|
-
$mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
|
|
1856
|
-
$mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
|
|
1857
|
-
},
|
|
1858
|
-
'RegExp'() {
|
|
1859
|
-
$mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
|
|
1860
|
-
$mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
|
|
1861
|
-
$mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
|
|
1862
|
-
},
|
|
1863
|
-
'Error'() {
|
|
1864
|
-
$mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
|
|
1865
|
-
const fail = (message) => new Error(message);
|
|
1866
|
-
$mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
|
|
1867
|
-
$mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
|
|
1868
|
-
},
|
|
1869
|
-
'Map'() {
|
|
1870
|
-
$mol_assert_ok($mol_compare_deep(new Map, new Map));
|
|
1871
|
-
$mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
|
|
1872
|
-
$mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
|
|
1873
|
-
$mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
|
|
1874
|
-
},
|
|
1875
|
-
'Set'() {
|
|
1876
|
-
$mol_assert_ok($mol_compare_deep(new Set, new Set));
|
|
1877
|
-
$mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
|
|
1878
|
-
$mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
|
|
1879
|
-
},
|
|
1880
|
-
'Uint8Array'() {
|
|
1881
|
-
$mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
|
|
1882
|
-
$mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
|
|
1883
|
-
$mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
|
|
1884
|
-
},
|
|
1885
|
-
'Custom comparator'() {
|
|
1886
|
-
class User {
|
|
1887
|
-
name;
|
|
1888
|
-
rand;
|
|
1889
|
-
constructor(name, rand = Math.random()) {
|
|
1890
|
-
this.name = name;
|
|
1891
|
-
this.rand = rand;
|
|
1892
|
-
}
|
|
1893
|
-
[Symbol.toPrimitive](mode) {
|
|
1894
|
-
return this.name;
|
|
1895
|
-
}
|
|
1865
|
+
function $mol_log3_node_make(level, output, type, color) {
|
|
1866
|
+
return function $mol_log3_logger(event) {
|
|
1867
|
+
if (!event.time)
|
|
1868
|
+
event = { time: new Date().toISOString(), ...event };
|
|
1869
|
+
const tree = this.$mol_tree.fromJSON(event).clone({ type });
|
|
1870
|
+
let str = tree.toString();
|
|
1871
|
+
if (process[output].isTTY) {
|
|
1872
|
+
str = $node.colorette[color + 'Bright'](str);
|
|
1896
1873
|
}
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1874
|
+
;
|
|
1875
|
+
this.console[level](str);
|
|
1876
|
+
const self = this;
|
|
1877
|
+
return () => self.console.groupEnd();
|
|
1878
|
+
};
|
|
1879
|
+
}
|
|
1880
|
+
$.$mol_log3_node_make = $mol_log3_node_make;
|
|
1881
|
+
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
|
|
1882
|
+
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
|
|
1883
|
+
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
|
|
1884
|
+
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
|
|
1885
|
+
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
|
|
1886
|
+
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
|
|
1901
1887
|
})($ || ($ = {}));
|
|
1902
|
-
//mol/
|
|
1903
|
-
;
|
|
1904
|
-
"use strict";
|
|
1905
|
-
var $;
|
|
1906
|
-
(function ($) {
|
|
1907
|
-
function $mol_dom_serialize(node) {
|
|
1908
|
-
const serializer = new $mol_dom_context.XMLSerializer;
|
|
1909
|
-
return serializer.serializeToString(node);
|
|
1910
|
-
}
|
|
1911
|
-
$.$mol_dom_serialize = $mol_dom_serialize;
|
|
1912
|
-
})($ || ($ = {}));
|
|
1913
|
-
//mol/dom/serialize/serialize.ts
|
|
1914
|
-
;
|
|
1915
|
-
"use strict";
|
|
1916
|
-
var $;
|
|
1917
|
-
(function ($) {
|
|
1918
|
-
$mol_test({
|
|
1919
|
-
'must be false'() {
|
|
1920
|
-
$mol_assert_not(0);
|
|
1921
|
-
},
|
|
1922
|
-
'must be true'() {
|
|
1923
|
-
$mol_assert_ok(1);
|
|
1924
|
-
},
|
|
1925
|
-
'two must be equal'() {
|
|
1926
|
-
$mol_assert_equal(2, 2);
|
|
1927
|
-
},
|
|
1928
|
-
'three must be equal'() {
|
|
1929
|
-
$mol_assert_equal(2, 2, 2);
|
|
1930
|
-
},
|
|
1931
|
-
'two must be unique'() {
|
|
1932
|
-
$mol_assert_unique([3], [3]);
|
|
1933
|
-
},
|
|
1934
|
-
'three must be unique'() {
|
|
1935
|
-
$mol_assert_unique([3], [3], [3]);
|
|
1936
|
-
},
|
|
1937
|
-
'two must be alike'() {
|
|
1938
|
-
$mol_assert_like([3], [3]);
|
|
1939
|
-
},
|
|
1940
|
-
'three must be alike'() {
|
|
1941
|
-
$mol_assert_like([3], [3], [3]);
|
|
1942
|
-
},
|
|
1943
|
-
});
|
|
1944
|
-
})($ || ($ = {}));
|
|
1945
|
-
//mol/assert/assert.test.ts
|
|
1946
|
-
;
|
|
1947
|
-
"use strict";
|
|
1948
|
-
var $;
|
|
1949
|
-
(function ($) {
|
|
1950
|
-
function $mol_assert_ok(value) {
|
|
1951
|
-
if (value)
|
|
1952
|
-
return;
|
|
1953
|
-
$mol_fail(new Error(`${value} ≠ true`));
|
|
1954
|
-
}
|
|
1955
|
-
$.$mol_assert_ok = $mol_assert_ok;
|
|
1956
|
-
function $mol_assert_not(value) {
|
|
1957
|
-
if (!value)
|
|
1958
|
-
return;
|
|
1959
|
-
$mol_fail(new Error(`${value} ≠ false`));
|
|
1960
|
-
}
|
|
1961
|
-
$.$mol_assert_not = $mol_assert_not;
|
|
1962
|
-
function $mol_assert_fail(handler, ErrorRight) {
|
|
1963
|
-
const fail = $.$mol_fail;
|
|
1964
|
-
try {
|
|
1965
|
-
$.$mol_fail = $.$mol_fail_hidden;
|
|
1966
|
-
handler();
|
|
1967
|
-
}
|
|
1968
|
-
catch (error) {
|
|
1969
|
-
if (!ErrorRight)
|
|
1970
|
-
return error;
|
|
1971
|
-
$.$mol_fail = fail;
|
|
1972
|
-
if (typeof ErrorRight === 'string') {
|
|
1973
|
-
$mol_assert_equal(error.message, ErrorRight);
|
|
1974
|
-
}
|
|
1975
|
-
else {
|
|
1976
|
-
$mol_assert_ok(error instanceof ErrorRight);
|
|
1977
|
-
}
|
|
1978
|
-
return error;
|
|
1979
|
-
}
|
|
1980
|
-
finally {
|
|
1981
|
-
$.$mol_fail = fail;
|
|
1982
|
-
}
|
|
1983
|
-
$mol_fail(new Error('Not failed'));
|
|
1984
|
-
}
|
|
1985
|
-
$.$mol_assert_fail = $mol_assert_fail;
|
|
1986
|
-
function $mol_assert_equal(...args) {
|
|
1987
|
-
for (let i = 0; i < args.length; ++i) {
|
|
1988
|
-
for (let j = 0; j < args.length; ++j) {
|
|
1989
|
-
if (i === j)
|
|
1990
|
-
continue;
|
|
1991
|
-
if (Number.isNaN(args[i]) && Number.isNaN(args[j]))
|
|
1992
|
-
continue;
|
|
1993
|
-
if (args[i] !== args[j])
|
|
1994
|
-
$mol_fail(new Error(`Not equal (${i + 1}:${j + 1})\n${args[i]}\n${args[j]}`));
|
|
1995
|
-
}
|
|
1996
|
-
}
|
|
1997
|
-
}
|
|
1998
|
-
$.$mol_assert_equal = $mol_assert_equal;
|
|
1999
|
-
function $mol_assert_unique(...args) {
|
|
2000
|
-
for (let i = 0; i < args.length; ++i) {
|
|
2001
|
-
for (let j = 0; j < args.length; ++j) {
|
|
2002
|
-
if (i === j)
|
|
2003
|
-
continue;
|
|
2004
|
-
if (args[i] === args[j] || (Number.isNaN(args[i]) && Number.isNaN(args[j]))) {
|
|
2005
|
-
$mol_fail(new Error(`args[${i}] = args[${j}] = ${args[i]}`));
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
$.$mol_assert_unique = $mol_assert_unique;
|
|
2011
|
-
function $mol_assert_like(head, ...tail) {
|
|
2012
|
-
for (let [index, value] of Object.entries(tail)) {
|
|
2013
|
-
if (!$mol_compare_deep(value, head)) {
|
|
2014
|
-
const print = (val) => {
|
|
2015
|
-
if (!val)
|
|
2016
|
-
return val;
|
|
2017
|
-
if (typeof val !== 'object')
|
|
2018
|
-
return val;
|
|
2019
|
-
if ('outerHTML' in val)
|
|
2020
|
-
return val.outerHTML;
|
|
2021
|
-
try {
|
|
2022
|
-
return JSON.stringify(val);
|
|
2023
|
-
}
|
|
2024
|
-
catch (error) {
|
|
2025
|
-
console.error(error);
|
|
2026
|
-
return val;
|
|
2027
|
-
}
|
|
2028
|
-
};
|
|
2029
|
-
return $mol_fail(new Error(`Not like (1:${+index + 2})\n${print(head)}\n---\n${print(value)}`));
|
|
2030
|
-
}
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
|
-
$.$mol_assert_like = $mol_assert_like;
|
|
2034
|
-
function $mol_assert_dom(left, right) {
|
|
2035
|
-
$mol_assert_equal($mol_dom_serialize(left), $mol_dom_serialize(right));
|
|
2036
|
-
}
|
|
2037
|
-
$.$mol_assert_dom = $mol_assert_dom;
|
|
2038
|
-
})($ || ($ = {}));
|
|
2039
|
-
//mol/assert/assert.ts
|
|
2040
|
-
;
|
|
2041
|
-
"use strict";
|
|
2042
|
-
var $;
|
|
2043
|
-
(function ($) {
|
|
2044
|
-
function $mol_log3_area_lazy(event) {
|
|
2045
|
-
const self = this;
|
|
2046
|
-
const stack = self.$mol_log3_stack;
|
|
2047
|
-
const deep = stack.length;
|
|
2048
|
-
let logged = false;
|
|
2049
|
-
stack.push(() => {
|
|
2050
|
-
logged = true;
|
|
2051
|
-
self.$mol_log3_area.call(self, event);
|
|
2052
|
-
});
|
|
2053
|
-
return () => {
|
|
2054
|
-
if (logged)
|
|
2055
|
-
self.console.groupEnd();
|
|
2056
|
-
if (stack.length > deep)
|
|
2057
|
-
stack.length = deep;
|
|
2058
|
-
};
|
|
2059
|
-
}
|
|
2060
|
-
$.$mol_log3_area_lazy = $mol_log3_area_lazy;
|
|
2061
|
-
$.$mol_log3_stack = [];
|
|
2062
|
-
})($ || ($ = {}));
|
|
2063
|
-
//mol/log3/log3.ts
|
|
2064
|
-
;
|
|
2065
|
-
"use strict";
|
|
2066
|
-
var $;
|
|
2067
|
-
(function ($) {
|
|
2068
|
-
function $mol_log3_node_make(level, output, type, color) {
|
|
2069
|
-
return function $mol_log3_logger(event) {
|
|
2070
|
-
if (!event.time)
|
|
2071
|
-
event = { time: new Date().toISOString(), ...event };
|
|
2072
|
-
const tree = this.$mol_tree.fromJSON(event).clone({ type });
|
|
2073
|
-
let str = tree.toString();
|
|
2074
|
-
if (process[output].isTTY) {
|
|
2075
|
-
str = $node.colorette[color + 'Bright'](str);
|
|
2076
|
-
}
|
|
2077
|
-
;
|
|
2078
|
-
this.console[level](str);
|
|
2079
|
-
const self = this;
|
|
2080
|
-
return () => self.console.groupEnd();
|
|
2081
|
-
};
|
|
2082
|
-
}
|
|
2083
|
-
$.$mol_log3_node_make = $mol_log3_node_make;
|
|
2084
|
-
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
|
|
2085
|
-
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
|
|
2086
|
-
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
|
|
2087
|
-
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
|
|
2088
|
-
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
|
|
2089
|
-
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
|
|
2090
|
-
})($ || ($ = {}));
|
|
2091
|
-
//mol/log3/log3.node.ts
|
|
2092
|
-
;
|
|
2093
|
-
"use strict";
|
|
2094
|
-
var $;
|
|
2095
|
-
(function ($_1) {
|
|
2096
|
-
$mol_test_mocks.push($ => {
|
|
2097
|
-
$.$mol_log3_come = () => { };
|
|
2098
|
-
$.$mol_log3_done = () => { };
|
|
2099
|
-
$.$mol_log3_fail = () => { };
|
|
2100
|
-
$.$mol_log3_warn = () => { };
|
|
2101
|
-
$.$mol_log3_rise = () => { };
|
|
2102
|
-
$.$mol_log3_area = () => () => { };
|
|
2103
|
-
});
|
|
2104
|
-
})($ || ($ = {}));
|
|
2105
|
-
//mol/log3/log3.test.ts
|
|
1888
|
+
//mol/log3/log3.node.ts
|
|
2106
1889
|
;
|
|
2107
1890
|
"use strict";
|
|
2108
1891
|
var $;
|
|
@@ -2153,1356 +1936,1573 @@ var $;
|
|
|
2153
1936
|
"use strict";
|
|
2154
1937
|
var $;
|
|
2155
1938
|
(function ($) {
|
|
2156
|
-
$
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
'set'() {
|
|
2166
|
-
const target = { foo: 777 };
|
|
2167
|
-
const proxy = $mol_delegate({}, () => target);
|
|
2168
|
-
proxy.foo = 123;
|
|
2169
|
-
$mol_assert_equal(target.foo, 123);
|
|
2170
|
-
},
|
|
2171
|
-
'getOwnPropertyDescriptor'() {
|
|
2172
|
-
const proxy = $mol_delegate({}, () => ({ foo: 777 }));
|
|
2173
|
-
$mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
|
|
2174
|
-
value: 777,
|
|
2175
|
-
writable: true,
|
|
2176
|
-
enumerable: true,
|
|
2177
|
-
configurable: true,
|
|
2178
|
-
});
|
|
2179
|
-
},
|
|
2180
|
-
'ownKeys'() {
|
|
2181
|
-
const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
|
|
2182
|
-
$mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
|
|
2183
|
-
},
|
|
2184
|
-
'getPrototypeOf'() {
|
|
2185
|
-
class Foo {
|
|
1939
|
+
class $mol_wire_log extends $mol_object2 {
|
|
1940
|
+
static watch(task) {
|
|
1941
|
+
return task;
|
|
1942
|
+
}
|
|
1943
|
+
static track(fiber) {
|
|
1944
|
+
const prev = $mol_wire_probe(() => this.track(fiber));
|
|
1945
|
+
let next;
|
|
1946
|
+
try {
|
|
1947
|
+
next = fiber.sync();
|
|
2186
1948
|
}
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
1949
|
+
finally {
|
|
1950
|
+
for (const pub of fiber.pub_list) {
|
|
1951
|
+
if (pub instanceof $mol_wire_fiber) {
|
|
1952
|
+
this.track(pub);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
2192
1955
|
}
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
'instanceof'() {
|
|
2199
|
-
class Foo {
|
|
1956
|
+
if (prev !== undefined && !$mol_compare_deep(prev, next)) {
|
|
1957
|
+
this.$.$mol_log3_rise({
|
|
1958
|
+
message: 'Changed',
|
|
1959
|
+
place: fiber,
|
|
1960
|
+
});
|
|
2200
1961
|
}
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
class Foo {
|
|
1962
|
+
return next;
|
|
1963
|
+
}
|
|
1964
|
+
static active() {
|
|
1965
|
+
try {
|
|
1966
|
+
this.watch()?.();
|
|
2207
1967
|
}
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
1968
|
+
finally {
|
|
1969
|
+
for (const pub of $mol_wire_auto().pub_list) {
|
|
1970
|
+
if (pub instanceof $mol_wire_fiber) {
|
|
1971
|
+
this.track(pub);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
__decorate([
|
|
1978
|
+
$mol_mem
|
|
1979
|
+
], $mol_wire_log, "watch", null);
|
|
1980
|
+
__decorate([
|
|
1981
|
+
$mol_mem_key
|
|
1982
|
+
], $mol_wire_log, "track", null);
|
|
1983
|
+
__decorate([
|
|
1984
|
+
$mol_mem
|
|
1985
|
+
], $mol_wire_log, "active", null);
|
|
1986
|
+
$.$mol_wire_log = $mol_wire_log;
|
|
2213
1987
|
})($ || ($ = {}));
|
|
2214
|
-
//mol/
|
|
2215
|
-
;
|
|
2216
|
-
"use strict";
|
|
2217
|
-
//mol/type/writable/writable.test.ts
|
|
1988
|
+
//mol/wire/log/log.ts
|
|
2218
1989
|
;
|
|
2219
1990
|
"use strict";
|
|
2220
1991
|
var $;
|
|
2221
1992
|
(function ($) {
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
const queue = $.$mol_after_mock_queue.splice(0);
|
|
2225
|
-
for (const task of queue)
|
|
2226
|
-
task();
|
|
2227
|
-
}
|
|
2228
|
-
$.$mol_after_mock_warp = $mol_after_mock_warp;
|
|
2229
|
-
class $mol_after_mock_commmon extends $mol_object2 {
|
|
2230
|
-
task;
|
|
2231
|
-
promise = Promise.resolve();
|
|
2232
|
-
cancelled = false;
|
|
2233
|
-
id;
|
|
2234
|
-
constructor(task) {
|
|
2235
|
-
super();
|
|
2236
|
-
this.task = task;
|
|
2237
|
-
$.$mol_after_mock_queue.push(task);
|
|
2238
|
-
}
|
|
2239
|
-
destructor() {
|
|
2240
|
-
const index = $.$mol_after_mock_queue.indexOf(this.task);
|
|
2241
|
-
if (index >= 0)
|
|
2242
|
-
$.$mol_after_mock_queue.splice(index, 1);
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
$.$mol_after_mock_commmon = $mol_after_mock_commmon;
|
|
2246
|
-
class $mol_after_mock_timeout extends $mol_after_mock_commmon {
|
|
2247
|
-
delay;
|
|
2248
|
-
constructor(delay, task) {
|
|
2249
|
-
super(task);
|
|
2250
|
-
this.delay = delay;
|
|
2251
|
-
}
|
|
1993
|
+
function $mol_test_complete() {
|
|
1994
|
+
process.exit(0);
|
|
2252
1995
|
}
|
|
2253
|
-
$.$
|
|
1996
|
+
$.$mol_test_complete = $mol_test_complete;
|
|
2254
1997
|
})($ || ($ = {}));
|
|
2255
|
-
//mol/
|
|
1998
|
+
//mol/test/test.node.test.ts
|
|
2256
1999
|
;
|
|
2257
2000
|
"use strict";
|
|
2258
2001
|
var $;
|
|
2259
2002
|
(function ($_1) {
|
|
2260
|
-
$mol_test({
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2003
|
+
function $mol_test(set) {
|
|
2004
|
+
for (let name in set) {
|
|
2005
|
+
const code = set[name];
|
|
2006
|
+
const test = (typeof code === 'string') ? new Function('', code) : code;
|
|
2007
|
+
$_1.$mol_test_all.push(test);
|
|
2008
|
+
}
|
|
2009
|
+
$mol_test_schedule();
|
|
2010
|
+
}
|
|
2011
|
+
$_1.$mol_test = $mol_test;
|
|
2012
|
+
$_1.$mol_test_mocks = [];
|
|
2013
|
+
$_1.$mol_test_all = [];
|
|
2014
|
+
async function $mol_test_run() {
|
|
2015
|
+
for (var test of $_1.$mol_test_all) {
|
|
2016
|
+
let context = Object.create($$);
|
|
2017
|
+
for (let mock of $_1.$mol_test_mocks)
|
|
2018
|
+
await mock(context);
|
|
2019
|
+
const res = test(context);
|
|
2020
|
+
if (res instanceof Promise) {
|
|
2021
|
+
await new Promise((done, fail) => {
|
|
2022
|
+
res.then(done, fail);
|
|
2023
|
+
setTimeout(() => fail(new Error('Test timeout: ' + test.name)), 1000);
|
|
2024
|
+
});
|
|
2271
2025
|
}
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
;
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
$mol_test({
|
|
2288
|
-
'Collect deps'() {
|
|
2289
|
-
const pub1 = new $mol_wire_pub;
|
|
2290
|
-
const pub2 = new $mol_wire_pub;
|
|
2291
|
-
const sub = new $mol_wire_pub_sub;
|
|
2292
|
-
const bu1 = sub.track_on();
|
|
2026
|
+
}
|
|
2027
|
+
$$.$mol_log3_done({
|
|
2028
|
+
place: '$mol_test',
|
|
2029
|
+
message: 'All tests passed',
|
|
2030
|
+
count: $_1.$mol_test_all.length,
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
$_1.$mol_test_run = $mol_test_run;
|
|
2034
|
+
let scheduled = false;
|
|
2035
|
+
function $mol_test_schedule() {
|
|
2036
|
+
if (scheduled)
|
|
2037
|
+
return;
|
|
2038
|
+
scheduled = true;
|
|
2039
|
+
setTimeout(async () => {
|
|
2040
|
+
scheduled = false;
|
|
2293
2041
|
try {
|
|
2294
|
-
|
|
2295
|
-
pub2.promote();
|
|
2296
|
-
pub2.promote();
|
|
2042
|
+
await $mol_test_run();
|
|
2297
2043
|
}
|
|
2298
2044
|
finally {
|
|
2299
|
-
|
|
2300
|
-
sub.track_off(bu1);
|
|
2045
|
+
$$.$mol_test_complete();
|
|
2301
2046
|
}
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2047
|
+
}, 0);
|
|
2048
|
+
}
|
|
2049
|
+
$_1.$mol_test_schedule = $mol_test_schedule;
|
|
2050
|
+
$_1.$mol_test_mocks.push(context => {
|
|
2051
|
+
let seed = 0;
|
|
2052
|
+
context.Math = Object.create(Math);
|
|
2053
|
+
context.Math.random = () => Math.sin(seed++);
|
|
2054
|
+
const forbidden = ['XMLHttpRequest', 'fetch'];
|
|
2055
|
+
for (let api of forbidden) {
|
|
2056
|
+
context[api] = new Proxy(function () { }, {
|
|
2057
|
+
get() {
|
|
2058
|
+
$mol_fail_hidden(new Error(`${api} is forbidden in tests`));
|
|
2059
|
+
},
|
|
2060
|
+
apply() {
|
|
2061
|
+
$mol_fail_hidden(new Error(`${api} is forbidden in tests`));
|
|
2062
|
+
},
|
|
2063
|
+
});
|
|
2064
|
+
}
|
|
2065
|
+
});
|
|
2066
|
+
$mol_test({
|
|
2067
|
+
'mocked Math.random'($) {
|
|
2068
|
+
console.assert($.Math.random() === 0);
|
|
2069
|
+
console.assert($.Math.random() === Math.sin(1));
|
|
2070
|
+
},
|
|
2071
|
+
'forbidden XMLHttpRequest'($) {
|
|
2306
2072
|
try {
|
|
2307
|
-
|
|
2308
|
-
pub1.promote();
|
|
2309
|
-
pub2.promote();
|
|
2073
|
+
console.assert(void new $.XMLHttpRequest);
|
|
2310
2074
|
}
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
sub.track_off(bu2);
|
|
2075
|
+
catch (error) {
|
|
2076
|
+
console.assert(error.message === 'XMLHttpRequest is forbidden in tests');
|
|
2314
2077
|
}
|
|
2315
|
-
pub1.emit();
|
|
2316
|
-
pub2.emit();
|
|
2317
|
-
$mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
|
|
2318
2078
|
},
|
|
2319
|
-
'
|
|
2320
|
-
const sub1 = new $mol_wire_pub_sub;
|
|
2321
|
-
const sub2 = new $mol_wire_pub_sub;
|
|
2322
|
-
const bu1 = sub1.track_on();
|
|
2079
|
+
'forbidden fetch'($) {
|
|
2323
2080
|
try {
|
|
2324
|
-
|
|
2325
|
-
try {
|
|
2326
|
-
$mol_assert_fail(() => sub1.promote(), 'Circular subscription');
|
|
2327
|
-
}
|
|
2328
|
-
finally {
|
|
2329
|
-
sub2.track_cut();
|
|
2330
|
-
sub2.track_off(bu2);
|
|
2331
|
-
}
|
|
2081
|
+
console.assert(void $.fetch(''));
|
|
2332
2082
|
}
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
sub1.track_off(bu1);
|
|
2083
|
+
catch (error) {
|
|
2084
|
+
console.assert(error.message === 'fetch is forbidden in tests');
|
|
2336
2085
|
}
|
|
2337
2086
|
},
|
|
2338
2087
|
});
|
|
2339
2088
|
})($ || ($ = {}));
|
|
2340
|
-
//mol/
|
|
2089
|
+
//mol/test/test.test.ts
|
|
2341
2090
|
;
|
|
2342
2091
|
"use strict";
|
|
2343
2092
|
var $;
|
|
2344
|
-
(function ($
|
|
2345
|
-
$mol_test_mocks.push($ => {
|
|
2346
|
-
$.$mol_after_timeout = $mol_after_mock_timeout;
|
|
2347
|
-
});
|
|
2093
|
+
(function ($) {
|
|
2348
2094
|
})($ || ($ = {}));
|
|
2349
|
-
//mol/
|
|
2095
|
+
//mol/dom/context/context.ts
|
|
2350
2096
|
;
|
|
2351
2097
|
"use strict";
|
|
2352
2098
|
var $;
|
|
2353
|
-
(function ($
|
|
2354
|
-
$
|
|
2355
|
-
$.$mol_after_frame = $mol_after_mock_commmon;
|
|
2356
|
-
});
|
|
2099
|
+
(function ($) {
|
|
2100
|
+
$.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
|
|
2357
2101
|
})($ || ($ = {}));
|
|
2358
|
-
//mol/
|
|
2102
|
+
//mol/dom/context/context.node.ts
|
|
2359
2103
|
;
|
|
2360
2104
|
"use strict";
|
|
2361
2105
|
var $;
|
|
2362
2106
|
(function ($) {
|
|
2363
|
-
$
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
async 'Idempotence control'() {
|
|
2391
|
-
class Idempotence extends $mol_object2 {
|
|
2392
|
-
static logs_idemp = 0;
|
|
2393
|
-
static logs_unidemp = 0;
|
|
2394
|
-
static log_idemp() {
|
|
2395
|
-
this.logs_idemp += 1;
|
|
2396
|
-
}
|
|
2397
|
-
static log_unidemp() {
|
|
2398
|
-
this.logs_unidemp += 1;
|
|
2399
|
-
}
|
|
2400
|
-
static async val(a) {
|
|
2401
|
-
return a;
|
|
2402
|
-
}
|
|
2403
|
-
static sum(a, b) {
|
|
2404
|
-
this.log_idemp();
|
|
2405
|
-
this.log_unidemp();
|
|
2406
|
-
const syn = $mol_wire_sync(this);
|
|
2407
|
-
return syn.val(a) + syn.val(b);
|
|
2408
|
-
}
|
|
2409
|
-
static async calc(a, b) {
|
|
2410
|
-
return 5 + await $mol_wire_async(this).sum(a, b);
|
|
2107
|
+
function $mol_dom_render_children(el, childNodes) {
|
|
2108
|
+
const node_set = new Set(childNodes);
|
|
2109
|
+
let nextNode = el.firstChild;
|
|
2110
|
+
for (let view of childNodes) {
|
|
2111
|
+
if (view == null)
|
|
2112
|
+
continue;
|
|
2113
|
+
if (view instanceof $mol_dom_context.Node) {
|
|
2114
|
+
while (true) {
|
|
2115
|
+
if (!nextNode) {
|
|
2116
|
+
el.appendChild(view);
|
|
2117
|
+
break;
|
|
2118
|
+
}
|
|
2119
|
+
if (nextNode == view) {
|
|
2120
|
+
nextNode = nextNode.nextSibling;
|
|
2121
|
+
break;
|
|
2122
|
+
}
|
|
2123
|
+
else {
|
|
2124
|
+
if (node_set.has(nextNode)) {
|
|
2125
|
+
el.insertBefore(view, nextNode);
|
|
2126
|
+
break;
|
|
2127
|
+
}
|
|
2128
|
+
else {
|
|
2129
|
+
const nn = nextNode.nextSibling;
|
|
2130
|
+
el.removeChild(nextNode);
|
|
2131
|
+
nextNode = nn;
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2411
2134
|
}
|
|
2412
2135
|
}
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
},
|
|
2420
|
-
async 'Error handling'() {
|
|
2421
|
-
class Handle extends $mol_object2 {
|
|
2422
|
-
static async sum(a, b) {
|
|
2423
|
-
$mol_fail(new Error('test error ' + (a + b)));
|
|
2136
|
+
else {
|
|
2137
|
+
if (nextNode && nextNode.nodeName === '#text') {
|
|
2138
|
+
const str = String(view);
|
|
2139
|
+
if (nextNode.nodeValue !== str)
|
|
2140
|
+
nextNode.nodeValue = str;
|
|
2141
|
+
nextNode = nextNode.nextSibling;
|
|
2424
2142
|
}
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
}
|
|
2429
|
-
catch (error) {
|
|
2430
|
-
if (error instanceof Promise)
|
|
2431
|
-
$mol_fail_hidden(error);
|
|
2432
|
-
$mol_assert_equal(error.message, 'test error 3');
|
|
2433
|
-
}
|
|
2143
|
+
else {
|
|
2144
|
+
const textNode = $mol_dom_context.document.createTextNode(String(view));
|
|
2145
|
+
el.insertBefore(textNode, nextNode);
|
|
2434
2146
|
}
|
|
2435
2147
|
}
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2148
|
+
}
|
|
2149
|
+
while (nextNode) {
|
|
2150
|
+
const currNode = nextNode;
|
|
2151
|
+
nextNode = currNode.nextSibling;
|
|
2152
|
+
el.removeChild(currNode);
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
$.$mol_dom_render_children = $mol_dom_render_children;
|
|
2439
2156
|
})($ || ($ = {}));
|
|
2440
|
-
//mol/
|
|
2157
|
+
//mol/dom/render/children/children.ts
|
|
2158
|
+
;
|
|
2159
|
+
"use strict";
|
|
2160
|
+
//mol/type/error/error.ts
|
|
2161
|
+
;
|
|
2162
|
+
"use strict";
|
|
2163
|
+
//mol/type/assert/assert.test.ts
|
|
2164
|
+
;
|
|
2165
|
+
"use strict";
|
|
2166
|
+
//mol/type/assert/assert.ts
|
|
2167
|
+
;
|
|
2168
|
+
"use strict";
|
|
2169
|
+
//mol/type/equals/equals.test.ts
|
|
2170
|
+
;
|
|
2171
|
+
"use strict";
|
|
2172
|
+
//mol/type/equals/equals.ts
|
|
2173
|
+
;
|
|
2174
|
+
"use strict";
|
|
2175
|
+
//mol/type/partial/deep/deep.test.ts
|
|
2176
|
+
;
|
|
2177
|
+
"use strict";
|
|
2178
|
+
//mol/type/partial/deep/deep.ts
|
|
2441
2179
|
;
|
|
2442
2180
|
"use strict";
|
|
2443
2181
|
var $;
|
|
2444
2182
|
(function ($) {
|
|
2445
2183
|
$mol_test({
|
|
2446
|
-
'
|
|
2447
|
-
$mol_assert_equal($
|
|
2448
|
-
$mol_assert_equal($mol_key(false), 'false');
|
|
2449
|
-
$mol_assert_equal($mol_key(true), 'true');
|
|
2450
|
-
$mol_assert_equal($mol_key(0), '0');
|
|
2451
|
-
$mol_assert_equal($mol_key(''), '""');
|
|
2184
|
+
'Make empty div'() {
|
|
2185
|
+
$mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
|
|
2452
2186
|
},
|
|
2453
|
-
'
|
|
2454
|
-
$
|
|
2455
|
-
$mol_assert_equal(
|
|
2456
|
-
$mol_assert_equal(
|
|
2187
|
+
'Define native field'() {
|
|
2188
|
+
const dom = $mol_jsx("input", { value: '123' });
|
|
2189
|
+
$mol_assert_equal(dom.outerHTML, '<input value="123">');
|
|
2190
|
+
$mol_assert_equal(dom.value, '123');
|
|
2457
2191
|
},
|
|
2458
|
-
'
|
|
2459
|
-
const
|
|
2460
|
-
$mol_assert_equal(
|
|
2461
|
-
$mol_assert_unique($mol_key(func), $mol_key(() => { }));
|
|
2192
|
+
'Define classes'() {
|
|
2193
|
+
const dom = $mol_jsx("div", { class: 'foo bar' });
|
|
2194
|
+
$mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
|
|
2462
2195
|
},
|
|
2463
|
-
'
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
const jin = new User();
|
|
2467
|
-
$mol_assert_equal($mol_key(jin), $mol_key(jin));
|
|
2468
|
-
$mol_assert_unique($mol_key(jin), $mol_key(new User()));
|
|
2196
|
+
'Define styles'() {
|
|
2197
|
+
const dom = $mol_jsx("div", { style: { color: 'red' } });
|
|
2198
|
+
$mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
|
|
2469
2199
|
},
|
|
2470
|
-
'
|
|
2471
|
-
const
|
|
2472
|
-
$mol_assert_equal(
|
|
2473
|
-
$mol_assert_unique($mol_key(foo), $mol_key($mol_jsx("div", null, "bar")));
|
|
2200
|
+
'Define dataset'() {
|
|
2201
|
+
const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
|
|
2202
|
+
$mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
|
|
2474
2203
|
},
|
|
2475
|
-
'
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
age;
|
|
2479
|
-
constructor(name, age) {
|
|
2480
|
-
this.name = name;
|
|
2481
|
-
this.age = age;
|
|
2482
|
-
}
|
|
2483
|
-
toJSON() { return { name: this.name }; }
|
|
2484
|
-
}
|
|
2485
|
-
$mol_assert_equal($mol_key(new User('jin', 18)), '{"name":"jin"}');
|
|
2204
|
+
'Define attributes'() {
|
|
2205
|
+
const dom = $mol_jsx("div", { lang: "ru", hidden: true });
|
|
2206
|
+
$mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
|
|
2486
2207
|
},
|
|
2487
|
-
'
|
|
2488
|
-
$
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2208
|
+
'Define child nodes'() {
|
|
2209
|
+
const dom = $mol_jsx("div", null,
|
|
2210
|
+
"hello",
|
|
2211
|
+
$mol_jsx("strong", null, "world"),
|
|
2212
|
+
"!");
|
|
2213
|
+
$mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
|
|
2214
|
+
},
|
|
2215
|
+
'Function as component'() {
|
|
2216
|
+
const Button = ({ hint }, target) => {
|
|
2217
|
+
return $mol_jsx("button", { title: hint }, target());
|
|
2218
|
+
};
|
|
2219
|
+
const dom = $mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
|
|
2220
|
+
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
|
|
2221
|
+
},
|
|
2222
|
+
'Nested guid generation'() {
|
|
2223
|
+
const Foo = () => {
|
|
2224
|
+
return $mol_jsx("div", null,
|
|
2225
|
+
$mol_jsx(Bar, { id: "/bar" },
|
|
2226
|
+
$mol_jsx("img", { id: "/icon" })));
|
|
2227
|
+
};
|
|
2228
|
+
const Bar = (props, icon) => {
|
|
2229
|
+
return $mol_jsx("span", null, icon);
|
|
2230
|
+
};
|
|
2231
|
+
const dom = $mol_jsx(Foo, { id: "/foo" });
|
|
2232
|
+
$mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
|
|
2233
|
+
},
|
|
2234
|
+
'Fail on non unique ids'() {
|
|
2235
|
+
const App = () => {
|
|
2236
|
+
return $mol_jsx("div", null,
|
|
2237
|
+
$mol_jsx("span", { id: "/bar" }),
|
|
2238
|
+
$mol_jsx("span", { id: "/bar" }));
|
|
2239
|
+
};
|
|
2240
|
+
$mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
|
|
2492
2241
|
},
|
|
2493
2242
|
});
|
|
2494
2243
|
})($ || ($ = {}));
|
|
2495
|
-
//mol/
|
|
2244
|
+
//mol/jsx/jsx.test.tsx
|
|
2496
2245
|
;
|
|
2497
2246
|
"use strict";
|
|
2498
2247
|
var $;
|
|
2499
|
-
(function ($
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
$mol_assert_equal(App.value(), 3);
|
|
2514
|
-
},
|
|
2515
|
-
'Mem overrides mem'($) {
|
|
2516
|
-
class Base extends $mol_object2 {
|
|
2517
|
-
static $ = $;
|
|
2518
|
-
static value(next = 1) {
|
|
2519
|
-
return next + 1;
|
|
2520
|
-
}
|
|
2248
|
+
(function ($) {
|
|
2249
|
+
$.$mol_jsx_prefix = '';
|
|
2250
|
+
$.$mol_jsx_booked = null;
|
|
2251
|
+
$.$mol_jsx_document = {
|
|
2252
|
+
getElementById: () => null,
|
|
2253
|
+
createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
|
|
2254
|
+
createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
|
|
2255
|
+
};
|
|
2256
|
+
$.$mol_jsx_frag = '';
|
|
2257
|
+
function $mol_jsx(Elem, props, ...childNodes) {
|
|
2258
|
+
const id = props && props.id || '';
|
|
2259
|
+
if (Elem && $.$mol_jsx_booked) {
|
|
2260
|
+
if ($.$mol_jsx_booked.has(id)) {
|
|
2261
|
+
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
|
|
2521
2262
|
}
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
], Base, "value", null);
|
|
2525
|
-
class Middle extends Base {
|
|
2526
|
-
static value(next) {
|
|
2527
|
-
return super.value(next) + 1;
|
|
2528
|
-
}
|
|
2263
|
+
else {
|
|
2264
|
+
$.$mol_jsx_booked.add(id);
|
|
2529
2265
|
}
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2266
|
+
}
|
|
2267
|
+
const guid = $.$mol_jsx_prefix + id;
|
|
2268
|
+
let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
|
|
2269
|
+
if (typeof Elem !== 'string') {
|
|
2270
|
+
if ('prototype' in Elem) {
|
|
2271
|
+
const view = node && node[Elem] || new Elem;
|
|
2272
|
+
Object.assign(view, props);
|
|
2273
|
+
view[Symbol.toStringTag] = guid;
|
|
2274
|
+
view.childNodes = childNodes;
|
|
2275
|
+
if (!view.ownerDocument)
|
|
2276
|
+
view.ownerDocument = $.$mol_jsx_document;
|
|
2277
|
+
node = view.valueOf();
|
|
2278
|
+
node[Elem] = view;
|
|
2279
|
+
return node;
|
|
2537
2280
|
}
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
'Auto recalculation of cached values'($) {
|
|
2546
|
-
class App extends $mol_object2 {
|
|
2547
|
-
static $ = $;
|
|
2548
|
-
static xxx(next) {
|
|
2549
|
-
return next || 1;
|
|
2550
|
-
}
|
|
2551
|
-
static yyy() {
|
|
2552
|
-
return this.xxx() + 1;
|
|
2281
|
+
else {
|
|
2282
|
+
const prefix = $.$mol_jsx_prefix;
|
|
2283
|
+
const booked = $.$mol_jsx_booked;
|
|
2284
|
+
try {
|
|
2285
|
+
$.$mol_jsx_prefix = guid;
|
|
2286
|
+
$.$mol_jsx_booked = new Set;
|
|
2287
|
+
return Elem(props, ...childNodes);
|
|
2553
2288
|
}
|
|
2554
|
-
|
|
2555
|
-
|
|
2289
|
+
finally {
|
|
2290
|
+
$.$mol_jsx_prefix = prefix;
|
|
2291
|
+
$.$mol_jsx_booked = booked;
|
|
2556
2292
|
}
|
|
2557
2293
|
}
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
return next || 1;
|
|
2579
|
-
}
|
|
2580
|
-
static yyy() {
|
|
2581
|
-
log.push('yyy');
|
|
2582
|
-
return [Math.sign(this.xxx())];
|
|
2583
|
-
}
|
|
2584
|
-
static zzz() {
|
|
2585
|
-
log.push('zzz');
|
|
2586
|
-
return this.yyy()[0] + 1;
|
|
2294
|
+
}
|
|
2295
|
+
if (!node) {
|
|
2296
|
+
node = Elem
|
|
2297
|
+
? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
|
|
2298
|
+
: $.$mol_jsx_document.createDocumentFragment();
|
|
2299
|
+
}
|
|
2300
|
+
$mol_dom_render_children(node, [].concat(...childNodes));
|
|
2301
|
+
if (!Elem)
|
|
2302
|
+
return node;
|
|
2303
|
+
for (const key in props) {
|
|
2304
|
+
if (typeof props[key] === 'string') {
|
|
2305
|
+
;
|
|
2306
|
+
node.setAttribute(key, props[key]);
|
|
2307
|
+
}
|
|
2308
|
+
else if (props[key] &&
|
|
2309
|
+
typeof props[key] === 'object' &&
|
|
2310
|
+
Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
|
|
2311
|
+
if (typeof node[key] === 'object') {
|
|
2312
|
+
Object.assign(node[key], props[key]);
|
|
2313
|
+
continue;
|
|
2587
2314
|
}
|
|
2588
2315
|
}
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2316
|
+
else {
|
|
2317
|
+
node[key] = props[key];
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
if (guid)
|
|
2321
|
+
node.id = guid;
|
|
2322
|
+
return node;
|
|
2323
|
+
}
|
|
2324
|
+
$.$mol_jsx = $mol_jsx;
|
|
2325
|
+
})($ || ($ = {}));
|
|
2326
|
+
//mol/jsx/jsx.ts
|
|
2327
|
+
;
|
|
2328
|
+
"use strict";
|
|
2329
|
+
var $;
|
|
2330
|
+
(function ($) {
|
|
2331
|
+
$mol_test({
|
|
2332
|
+
'nulls & undefineds'() {
|
|
2333
|
+
$mol_assert_ok($mol_compare_deep(null, null));
|
|
2334
|
+
$mol_assert_ok($mol_compare_deep(undefined, undefined));
|
|
2335
|
+
$mol_assert_not($mol_compare_deep(undefined, null));
|
|
2336
|
+
$mol_assert_not($mol_compare_deep({}, null));
|
|
2604
2337
|
},
|
|
2605
|
-
'
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2338
|
+
'number'() {
|
|
2339
|
+
$mol_assert_ok($mol_compare_deep(1, 1));
|
|
2340
|
+
$mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
|
|
2341
|
+
$mol_assert_not($mol_compare_deep(1, 2));
|
|
2342
|
+
$mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
|
|
2343
|
+
$mol_assert_not($mol_compare_deep(Object(1), Object(2)));
|
|
2344
|
+
},
|
|
2345
|
+
'POJO'() {
|
|
2346
|
+
$mol_assert_ok($mol_compare_deep({}, {}));
|
|
2347
|
+
$mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
|
|
2348
|
+
$mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
|
|
2349
|
+
$mol_assert_not($mol_compare_deep({}, { a: undefined }));
|
|
2350
|
+
$mol_assert_ok($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
|
|
2351
|
+
$mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
|
|
2352
|
+
},
|
|
2353
|
+
'Array'() {
|
|
2354
|
+
$mol_assert_ok($mol_compare_deep([], []));
|
|
2355
|
+
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
|
|
2356
|
+
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
|
|
2357
|
+
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
|
|
2358
|
+
},
|
|
2359
|
+
'Non POJO are different'() {
|
|
2360
|
+
class Thing extends Object {
|
|
2616
2361
|
}
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
__decorate([
|
|
2621
|
-
$mol_wire_mem(0)
|
|
2622
|
-
], App, "second", null);
|
|
2623
|
-
__decorate([
|
|
2624
|
-
$mol_wire_mem(0)
|
|
2625
|
-
], App, "condition", null);
|
|
2626
|
-
__decorate([
|
|
2627
|
-
$mol_wire_mem(0)
|
|
2628
|
-
], App, "result", null);
|
|
2629
|
-
$mol_assert_equal(App.result(), 1);
|
|
2630
|
-
$mol_assert_equal(App.counter, 1);
|
|
2631
|
-
App.condition(false);
|
|
2632
|
-
$mol_assert_equal(App.result(), 3);
|
|
2633
|
-
$mol_assert_equal(App.counter, 2);
|
|
2634
|
-
App.first(10);
|
|
2635
|
-
$mol_assert_equal(App.result(), 3);
|
|
2636
|
-
$mol_assert_equal(App.counter, 2);
|
|
2362
|
+
$mol_assert_not($mol_compare_deep(new Thing, new Thing));
|
|
2363
|
+
$mol_assert_not($mol_compare_deep(() => 1, () => 1));
|
|
2364
|
+
$mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
|
|
2637
2365
|
},
|
|
2638
|
-
'
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2366
|
+
'same POJOs with cyclic reference'() {
|
|
2367
|
+
const a = { foo: {} };
|
|
2368
|
+
a['self'] = a;
|
|
2369
|
+
const b = { foo: {} };
|
|
2370
|
+
b['self'] = b;
|
|
2371
|
+
$mol_assert_ok($mol_compare_deep(a, b));
|
|
2372
|
+
},
|
|
2373
|
+
'Date'() {
|
|
2374
|
+
$mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
|
|
2375
|
+
$mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
|
|
2376
|
+
},
|
|
2377
|
+
'RegExp'() {
|
|
2378
|
+
$mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
|
|
2379
|
+
$mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
|
|
2380
|
+
$mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
|
|
2381
|
+
},
|
|
2382
|
+
'Error'() {
|
|
2383
|
+
$mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
|
|
2384
|
+
const fail = (message) => new Error(message);
|
|
2385
|
+
$mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
|
|
2386
|
+
$mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
|
|
2387
|
+
},
|
|
2388
|
+
'Map'() {
|
|
2389
|
+
$mol_assert_ok($mol_compare_deep(new Map, new Map));
|
|
2390
|
+
$mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
|
|
2391
|
+
$mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
|
|
2392
|
+
$mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
|
|
2393
|
+
},
|
|
2394
|
+
'Set'() {
|
|
2395
|
+
$mol_assert_ok($mol_compare_deep(new Set, new Set));
|
|
2396
|
+
$mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
|
|
2397
|
+
$mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
|
|
2398
|
+
},
|
|
2399
|
+
'Uint8Array'() {
|
|
2400
|
+
$mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
|
|
2401
|
+
$mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
|
|
2402
|
+
$mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
|
|
2403
|
+
},
|
|
2404
|
+
'Custom comparator'() {
|
|
2405
|
+
class User {
|
|
2406
|
+
name;
|
|
2407
|
+
rand;
|
|
2408
|
+
constructor(name, rand = Math.random()) {
|
|
2409
|
+
this.name = name;
|
|
2410
|
+
this.rand = rand;
|
|
2644
2411
|
}
|
|
2645
|
-
|
|
2646
|
-
return
|
|
2412
|
+
[Symbol.toPrimitive](mode) {
|
|
2413
|
+
return this.name;
|
|
2647
2414
|
}
|
|
2648
2415
|
}
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
], App, "foo", null);
|
|
2652
|
-
__decorate([
|
|
2653
|
-
$mol_wire_mem(0)
|
|
2654
|
-
], App, "bar", null);
|
|
2655
|
-
$mol_assert_like(App.bar(), { numbs: [1], count: 1 });
|
|
2656
|
-
App.foo({ numbs: [1] });
|
|
2657
|
-
$mol_assert_like(App.bar(), { numbs: [1], count: 1 });
|
|
2658
|
-
App.foo({ numbs: [2] });
|
|
2659
|
-
$mol_assert_like(App.bar(), { numbs: [2], count: 2 });
|
|
2416
|
+
$mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
|
|
2417
|
+
$mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
|
|
2660
2418
|
},
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
], App, "test", null);
|
|
2683
|
-
App.test();
|
|
2419
|
+
});
|
|
2420
|
+
})($ || ($ = {}));
|
|
2421
|
+
//mol/compare/deep/deep.test.tsx
|
|
2422
|
+
;
|
|
2423
|
+
"use strict";
|
|
2424
|
+
var $;
|
|
2425
|
+
(function ($) {
|
|
2426
|
+
function $mol_dom_serialize(node) {
|
|
2427
|
+
const serializer = new $mol_dom_context.XMLSerializer;
|
|
2428
|
+
return serializer.serializeToString(node);
|
|
2429
|
+
}
|
|
2430
|
+
$.$mol_dom_serialize = $mol_dom_serialize;
|
|
2431
|
+
})($ || ($ = {}));
|
|
2432
|
+
//mol/dom/serialize/serialize.ts
|
|
2433
|
+
;
|
|
2434
|
+
"use strict";
|
|
2435
|
+
var $;
|
|
2436
|
+
(function ($) {
|
|
2437
|
+
$mol_test({
|
|
2438
|
+
'must be false'() {
|
|
2439
|
+
$mol_assert_not(0);
|
|
2684
2440
|
},
|
|
2685
|
-
'
|
|
2686
|
-
|
|
2687
|
-
static $ = $;
|
|
2688
|
-
static store(next = 0) {
|
|
2689
|
-
return next;
|
|
2690
|
-
}
|
|
2691
|
-
static fast(next) {
|
|
2692
|
-
return this.store(next);
|
|
2693
|
-
}
|
|
2694
|
-
static slow(next) {
|
|
2695
|
-
return this.store(next);
|
|
2696
|
-
}
|
|
2697
|
-
}
|
|
2698
|
-
__decorate([
|
|
2699
|
-
$mol_wire_mem(0)
|
|
2700
|
-
], App, "store", null);
|
|
2701
|
-
__decorate([
|
|
2702
|
-
$mol_wire_mem(0)
|
|
2703
|
-
], App, "fast", null);
|
|
2704
|
-
__decorate([
|
|
2705
|
-
$mol_wire_mem(0)
|
|
2706
|
-
], App, "slow", null);
|
|
2707
|
-
App.fast();
|
|
2708
|
-
$mol_assert_equal(App.slow(666), 666);
|
|
2709
|
-
$mol_assert_equal(App.fast(), App.slow(), 666);
|
|
2710
|
-
App.store(777);
|
|
2711
|
-
$mol_assert_equal(App.fast(), App.slow(), 777);
|
|
2441
|
+
'must be true'() {
|
|
2442
|
+
$mol_assert_ok(1);
|
|
2712
2443
|
},
|
|
2713
|
-
'
|
|
2714
|
-
|
|
2715
|
-
static $ = $;
|
|
2716
|
-
static count(next = 0) {
|
|
2717
|
-
return next;
|
|
2718
|
-
}
|
|
2719
|
-
static count2() {
|
|
2720
|
-
return this.count();
|
|
2721
|
-
}
|
|
2722
|
-
static res() {
|
|
2723
|
-
const count = this.count2();
|
|
2724
|
-
if (!count)
|
|
2725
|
-
this.count(count + 1);
|
|
2726
|
-
return count + 1;
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
__decorate([
|
|
2730
|
-
$mol_wire_mem(0)
|
|
2731
|
-
], App, "count", null);
|
|
2732
|
-
__decorate([
|
|
2733
|
-
$mol_wire_mem(0)
|
|
2734
|
-
], App, "count2", null);
|
|
2735
|
-
__decorate([
|
|
2736
|
-
$mol_wire_mem(0)
|
|
2737
|
-
], App, "res", null);
|
|
2738
|
-
$mol_assert_like(App.res(), 1);
|
|
2739
|
-
App.count(5);
|
|
2740
|
-
$mol_assert_like(App.res(), 6);
|
|
2444
|
+
'two must be equal'() {
|
|
2445
|
+
$mol_assert_equal(2, 2);
|
|
2741
2446
|
},
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
static $ = $;
|
|
2745
|
-
static checked(next = false) {
|
|
2746
|
-
$$.$mol_wait_timeout(0);
|
|
2747
|
-
return next;
|
|
2748
|
-
}
|
|
2749
|
-
static toggle() {
|
|
2750
|
-
const prev = this.checked();
|
|
2751
|
-
$mol_assert_unique(this.checked(!prev), prev);
|
|
2752
|
-
}
|
|
2753
|
-
static res() {
|
|
2754
|
-
return this.checked();
|
|
2755
|
-
}
|
|
2756
|
-
static test() {
|
|
2757
|
-
$mol_assert_equal(App.res(), false);
|
|
2758
|
-
App.toggle();
|
|
2759
|
-
$mol_assert_equal(App.res(), true);
|
|
2760
|
-
}
|
|
2761
|
-
}
|
|
2762
|
-
__decorate([
|
|
2763
|
-
$mol_wire_mem(0)
|
|
2764
|
-
], App, "checked", null);
|
|
2765
|
-
__decorate([
|
|
2766
|
-
$mol_wire_method
|
|
2767
|
-
], App, "toggle", null);
|
|
2768
|
-
__decorate([
|
|
2769
|
-
$mol_wire_mem(0)
|
|
2770
|
-
], App, "res", null);
|
|
2771
|
-
__decorate([
|
|
2772
|
-
$mol_wire_method
|
|
2773
|
-
], App, "test", null);
|
|
2774
|
-
await $mol_wire_async(App).test();
|
|
2447
|
+
'three must be equal'() {
|
|
2448
|
+
$mol_assert_equal(2, 2, 2);
|
|
2775
2449
|
},
|
|
2776
|
-
'
|
|
2777
|
-
|
|
2778
|
-
static get $() { return $; }
|
|
2779
|
-
static condition(next = false) { return next; }
|
|
2780
|
-
static broken() {
|
|
2781
|
-
if (this.condition()) {
|
|
2782
|
-
$mol_fail(new Error('test error'));
|
|
2783
|
-
}
|
|
2784
|
-
return 1;
|
|
2785
|
-
}
|
|
2786
|
-
static result() {
|
|
2787
|
-
return this.broken();
|
|
2788
|
-
}
|
|
2789
|
-
}
|
|
2790
|
-
__decorate([
|
|
2791
|
-
$mol_wire_mem(0)
|
|
2792
|
-
], App, "condition", null);
|
|
2793
|
-
__decorate([
|
|
2794
|
-
$mol_wire_mem(0)
|
|
2795
|
-
], App, "broken", null);
|
|
2796
|
-
__decorate([
|
|
2797
|
-
$mol_wire_mem(0)
|
|
2798
|
-
], App, "result", null);
|
|
2799
|
-
$mol_assert_equal(App.result(), 1);
|
|
2800
|
-
App.condition(true);
|
|
2801
|
-
$mol_assert_fail(() => App.result());
|
|
2802
|
-
App.condition(false);
|
|
2803
|
-
$mol_assert_equal(App.result(), 1);
|
|
2450
|
+
'two must be unique'() {
|
|
2451
|
+
$mol_assert_unique([3], [3]);
|
|
2804
2452
|
},
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
static $ = $;
|
|
2808
|
-
static async source() {
|
|
2809
|
-
return 'Jin';
|
|
2810
|
-
}
|
|
2811
|
-
static middle() {
|
|
2812
|
-
return $mol_wire_sync(this).source();
|
|
2813
|
-
}
|
|
2814
|
-
static target() {
|
|
2815
|
-
return this.middle();
|
|
2816
|
-
}
|
|
2817
|
-
static test() {
|
|
2818
|
-
$mol_assert_equal(App.target(), 'Jin');
|
|
2819
|
-
}
|
|
2820
|
-
}
|
|
2821
|
-
__decorate([
|
|
2822
|
-
$mol_wire_mem(0)
|
|
2823
|
-
], App, "middle", null);
|
|
2824
|
-
__decorate([
|
|
2825
|
-
$mol_wire_mem(0)
|
|
2826
|
-
], App, "target", null);
|
|
2827
|
-
__decorate([
|
|
2828
|
-
$mol_wire_method
|
|
2829
|
-
], App, "test", null);
|
|
2830
|
-
await $mol_wire_async(App).test();
|
|
2453
|
+
'three must be unique'() {
|
|
2454
|
+
$mol_assert_unique([3], [3], [3]);
|
|
2831
2455
|
},
|
|
2832
|
-
'
|
|
2833
|
-
|
|
2834
|
-
class App extends $mol_object2 {
|
|
2835
|
-
static $ = $;
|
|
2836
|
-
static showing(next = true) {
|
|
2837
|
-
return next;
|
|
2838
|
-
}
|
|
2839
|
-
static details() {
|
|
2840
|
-
return {
|
|
2841
|
-
destructor() {
|
|
2842
|
-
destroyed = true;
|
|
2843
|
-
}
|
|
2844
|
-
};
|
|
2845
|
-
}
|
|
2846
|
-
static render() {
|
|
2847
|
-
return this.showing() ? this.details() : null;
|
|
2848
|
-
}
|
|
2849
|
-
}
|
|
2850
|
-
__decorate([
|
|
2851
|
-
$mol_wire_mem(0)
|
|
2852
|
-
], App, "showing", null);
|
|
2853
|
-
__decorate([
|
|
2854
|
-
$mol_wire_mem(0)
|
|
2855
|
-
], App, "details", null);
|
|
2856
|
-
__decorate([
|
|
2857
|
-
$mol_wire_mem(0)
|
|
2858
|
-
], App, "render", null);
|
|
2859
|
-
const details = App.render();
|
|
2860
|
-
$mol_assert_ok(details);
|
|
2861
|
-
App.showing(false);
|
|
2862
|
-
$mol_assert_not(App.render());
|
|
2863
|
-
App.showing(true);
|
|
2864
|
-
$mol_assert_equal(App.render(), details);
|
|
2865
|
-
$mol_wire_fiber.sync();
|
|
2866
|
-
$mol_assert_not(destroyed);
|
|
2867
|
-
App.showing(false);
|
|
2868
|
-
$mol_wire_fiber.sync();
|
|
2869
|
-
$mol_assert_ok(destroyed);
|
|
2870
|
-
App.showing(true);
|
|
2871
|
-
$mol_assert_unique(App.render(), details);
|
|
2456
|
+
'two must be alike'() {
|
|
2457
|
+
$mol_assert_like([3], [3]);
|
|
2872
2458
|
},
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
static $ = $;
|
|
2876
|
-
static counter = 0;
|
|
2877
|
-
static resets(next) {
|
|
2878
|
-
return ($mol_wire_probe(() => this.resets()) ?? -1) + 1;
|
|
2879
|
-
}
|
|
2880
|
-
static async wait() { }
|
|
2881
|
-
static value() {
|
|
2882
|
-
return ++this.counter;
|
|
2883
|
-
}
|
|
2884
|
-
static result() {
|
|
2885
|
-
if (this.resets())
|
|
2886
|
-
$mol_wire_sync(this).wait();
|
|
2887
|
-
return this.value();
|
|
2888
|
-
}
|
|
2889
|
-
static test() {
|
|
2890
|
-
}
|
|
2891
|
-
}
|
|
2892
|
-
__decorate([
|
|
2893
|
-
$mol_wire_mem(0)
|
|
2894
|
-
], App, "resets", null);
|
|
2895
|
-
__decorate([
|
|
2896
|
-
$mol_wire_mem(0)
|
|
2897
|
-
], App, "value", null);
|
|
2898
|
-
__decorate([
|
|
2899
|
-
$mol_wire_mem(0)
|
|
2900
|
-
], App, "result", null);
|
|
2901
|
-
__decorate([
|
|
2902
|
-
$mol_wire_method
|
|
2903
|
-
], App, "test", null);
|
|
2904
|
-
$mol_assert_equal(App.result(), 1);
|
|
2905
|
-
App.resets(null);
|
|
2906
|
-
$mol_wire_fiber.sync();
|
|
2907
|
-
$mol_assert_equal(await $mol_wire_async(App).result(), 1);
|
|
2459
|
+
'three must be alike'() {
|
|
2460
|
+
$mol_assert_like([3], [3], [3]);
|
|
2908
2461
|
},
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2462
|
+
});
|
|
2463
|
+
})($ || ($ = {}));
|
|
2464
|
+
//mol/assert/assert.test.ts
|
|
2465
|
+
;
|
|
2466
|
+
"use strict";
|
|
2467
|
+
var $;
|
|
2468
|
+
(function ($) {
|
|
2469
|
+
function $mol_assert_ok(value) {
|
|
2470
|
+
if (value)
|
|
2471
|
+
return;
|
|
2472
|
+
$mol_fail(new Error(`${value} ≠ true`));
|
|
2473
|
+
}
|
|
2474
|
+
$.$mol_assert_ok = $mol_assert_ok;
|
|
2475
|
+
function $mol_assert_not(value) {
|
|
2476
|
+
if (!value)
|
|
2477
|
+
return;
|
|
2478
|
+
$mol_fail(new Error(`${value} ≠ false`));
|
|
2479
|
+
}
|
|
2480
|
+
$.$mol_assert_not = $mol_assert_not;
|
|
2481
|
+
function $mol_assert_fail(handler, ErrorRight) {
|
|
2482
|
+
const fail = $.$mol_fail;
|
|
2483
|
+
try {
|
|
2484
|
+
$.$mol_fail = $.$mol_fail_hidden;
|
|
2485
|
+
handler();
|
|
2486
|
+
}
|
|
2487
|
+
catch (error) {
|
|
2488
|
+
if (!ErrorRight)
|
|
2489
|
+
return error;
|
|
2490
|
+
$.$mol_fail = fail;
|
|
2491
|
+
if (typeof ErrorRight === 'string') {
|
|
2492
|
+
$mol_assert_equal(error.message, ErrorRight);
|
|
2923
2493
|
}
|
|
2924
|
-
|
|
2925
|
-
$
|
|
2926
|
-
], Team, "user_name", null);
|
|
2927
|
-
__decorate([
|
|
2928
|
-
$mol_wire_mem(1)
|
|
2929
|
-
], Team, "user_names", null);
|
|
2930
|
-
__decorate([
|
|
2931
|
-
$mol_wire_method
|
|
2932
|
-
], Team, "test", null);
|
|
2933
|
-
$mol_assert_like(Team.user_names(), ['jin', 'john']);
|
|
2934
|
-
Team.user_name('jin', 'JIN');
|
|
2935
|
-
$mol_assert_like(Team.user_names(), ['JIN', 'john']);
|
|
2936
|
-
},
|
|
2937
|
-
'Memoize by single complex key'($) {
|
|
2938
|
-
class Map extends $mol_object2 {
|
|
2939
|
-
static $ = $;
|
|
2940
|
-
static tile(pos) {
|
|
2941
|
-
return new String(`/tile=${pos}`);
|
|
2942
|
-
}
|
|
2943
|
-
static test() {
|
|
2944
|
-
$mol_assert_like(this.tile([0, 1]), new String('/tile=0,1'));
|
|
2945
|
-
$mol_assert_equal(this.tile([0, 1]), this.tile([0, 1]));
|
|
2946
|
-
}
|
|
2494
|
+
else {
|
|
2495
|
+
$mol_assert_ok(error instanceof ErrorRight);
|
|
2947
2496
|
}
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
$
|
|
2965
|
-
}
|
|
2497
|
+
return error;
|
|
2498
|
+
}
|
|
2499
|
+
finally {
|
|
2500
|
+
$.$mol_fail = fail;
|
|
2501
|
+
}
|
|
2502
|
+
$mol_fail(new Error('Not failed'));
|
|
2503
|
+
}
|
|
2504
|
+
$.$mol_assert_fail = $mol_assert_fail;
|
|
2505
|
+
function $mol_assert_equal(...args) {
|
|
2506
|
+
for (let i = 0; i < args.length; ++i) {
|
|
2507
|
+
for (let j = 0; j < args.length; ++j) {
|
|
2508
|
+
if (i === j)
|
|
2509
|
+
continue;
|
|
2510
|
+
if (Number.isNaN(args[i]) && Number.isNaN(args[j]))
|
|
2511
|
+
continue;
|
|
2512
|
+
if (args[i] !== args[j])
|
|
2513
|
+
$mol_fail(new Error(`Not equal (${i + 1}:${j + 1})\n${args[i]}\n${args[j]}`));
|
|
2966
2514
|
}
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
static title() {
|
|
2978
|
-
return new $mol_object2;
|
|
2979
|
-
}
|
|
2980
|
-
static like(friend) {
|
|
2981
|
-
return new $mol_object2;
|
|
2982
|
-
}
|
|
2983
|
-
static relation(friend, props) {
|
|
2984
|
-
return new $mol_object2;
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
$.$mol_assert_equal = $mol_assert_equal;
|
|
2518
|
+
function $mol_assert_unique(...args) {
|
|
2519
|
+
for (let i = 0; i < args.length; ++i) {
|
|
2520
|
+
for (let j = 0; j < args.length; ++j) {
|
|
2521
|
+
if (i === j)
|
|
2522
|
+
continue;
|
|
2523
|
+
if (args[i] === args[j] || (Number.isNaN(args[i]) && Number.isNaN(args[j]))) {
|
|
2524
|
+
$mol_fail(new Error(`args[${i}] = args[${j}] = ${args[i]}`));
|
|
2985
2525
|
}
|
|
2986
2526
|
}
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
++this.sums;
|
|
3010
|
-
return this.value(index - 1) + this.value(index - 2);
|
|
3011
|
-
}
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
$.$mol_assert_unique = $mol_assert_unique;
|
|
2530
|
+
function $mol_assert_like(head, ...tail) {
|
|
2531
|
+
for (let [index, value] of Object.entries(tail)) {
|
|
2532
|
+
if (!$mol_compare_deep(value, head)) {
|
|
2533
|
+
const print = (val) => {
|
|
2534
|
+
if (!val)
|
|
2535
|
+
return val;
|
|
2536
|
+
if (typeof val !== 'object')
|
|
2537
|
+
return val;
|
|
2538
|
+
if ('outerHTML' in val)
|
|
2539
|
+
return val.outerHTML;
|
|
2540
|
+
try {
|
|
2541
|
+
return JSON.stringify(val);
|
|
2542
|
+
}
|
|
2543
|
+
catch (error) {
|
|
2544
|
+
console.error(error);
|
|
2545
|
+
return val;
|
|
2546
|
+
}
|
|
2547
|
+
};
|
|
2548
|
+
return $mol_fail(new Error(`Not like (1:${+index + 2})\n${print(head)}\n---\n${print(value)}`));
|
|
3012
2549
|
}
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
$mol_assert_equal(Fib.sums, 6);
|
|
3021
|
-
},
|
|
3022
|
-
});
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
$.$mol_assert_like = $mol_assert_like;
|
|
2553
|
+
function $mol_assert_dom(left, right) {
|
|
2554
|
+
$mol_assert_equal($mol_dom_serialize(left), $mol_dom_serialize(right));
|
|
2555
|
+
}
|
|
2556
|
+
$.$mol_assert_dom = $mol_assert_dom;
|
|
3023
2557
|
})($ || ($ = {}));
|
|
3024
|
-
//mol/
|
|
2558
|
+
//mol/assert/assert.ts
|
|
3025
2559
|
;
|
|
3026
2560
|
"use strict";
|
|
3027
2561
|
var $;
|
|
3028
|
-
(function ($) {
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
2562
|
+
(function ($_1) {
|
|
2563
|
+
$mol_test_mocks.push($ => {
|
|
2564
|
+
$.$mol_log3_come = () => { };
|
|
2565
|
+
$.$mol_log3_done = () => { };
|
|
2566
|
+
$.$mol_log3_fail = () => { };
|
|
2567
|
+
$.$mol_log3_warn = () => { };
|
|
2568
|
+
$.$mol_log3_rise = () => { };
|
|
2569
|
+
$.$mol_log3_area = () => () => { };
|
|
2570
|
+
});
|
|
3033
2571
|
})($ || ($ = {}));
|
|
3034
|
-
//mol/
|
|
2572
|
+
//mol/log3/log3.test.ts
|
|
3035
2573
|
;
|
|
3036
2574
|
"use strict";
|
|
3037
2575
|
var $;
|
|
3038
2576
|
(function ($) {
|
|
3039
|
-
function $mol_deprecated(message) {
|
|
3040
|
-
return (host, field, descr) => {
|
|
3041
|
-
const value = descr.value;
|
|
3042
|
-
let warned = false;
|
|
3043
|
-
descr.value = function $mol_deprecated_wrapper(...args) {
|
|
3044
|
-
if (!warned) {
|
|
3045
|
-
$$.$mol_log3_warn({
|
|
3046
|
-
place: `${host.constructor.name}::${field}`,
|
|
3047
|
-
message: `Deprecated`,
|
|
3048
|
-
hint: message,
|
|
3049
|
-
});
|
|
3050
|
-
warned = true;
|
|
3051
|
-
}
|
|
3052
|
-
return value.call(this, ...args);
|
|
3053
|
-
};
|
|
3054
|
-
};
|
|
3055
|
-
}
|
|
3056
|
-
$.$mol_deprecated = $mol_deprecated;
|
|
3057
|
-
})($ || ($ = {}));
|
|
3058
|
-
//mol/deprecated/deprecated.ts
|
|
3059
|
-
;
|
|
3060
|
-
"use strict";
|
|
3061
|
-
var $;
|
|
3062
|
-
(function ($_1) {
|
|
3063
2577
|
$mol_test({
|
|
3064
|
-
'
|
|
3065
|
-
$
|
|
3066
|
-
$mol_assert_equal(
|
|
3067
|
-
$mol_assert_equal($mol_tree.fromString("foo\n\n\n").sub.length, 1);
|
|
3068
|
-
$mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub.length, 2);
|
|
3069
|
-
$mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub[1].data, "bar");
|
|
3070
|
-
$mol_assert_equal($mol_tree.fromString("foo bar \\pol").sub[0].sub[0].sub[0].data, "pol");
|
|
3071
|
-
$mol_assert_equal($mol_tree.fromString("foo bar\n\t\\pol\n\t\\men").sub[0].sub[0].sub[1].data, "men");
|
|
3072
|
-
$mol_assert_equal($mol_tree.fromString('foo bar \\text\n').toString(), 'foo bar \\text\n');
|
|
3073
|
-
},
|
|
3074
|
-
'inserting'() {
|
|
3075
|
-
$mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 'a', 'b', 'c').toString(), 'a b \\\n');
|
|
3076
|
-
$mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 'a', 'b', 'c', 'd').toString(), 'a b c \\\n');
|
|
3077
|
-
$mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 0, 0, 0).toString(), 'a b \\\n');
|
|
3078
|
-
$mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 0, 0, 0, 0).toString(), 'a b \\\n\t\\\n');
|
|
3079
|
-
$mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, null, null, null).toString(), 'a b \\\n');
|
|
3080
|
-
$mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, null, null, null, null).toString(), 'a b \\\n\t\\\n');
|
|
2578
|
+
'get'() {
|
|
2579
|
+
const proxy = $mol_delegate({}, () => ({ foo: 777 }));
|
|
2580
|
+
$mol_assert_equal(proxy.foo, 777);
|
|
3081
2581
|
},
|
|
3082
|
-
'
|
|
3083
|
-
$
|
|
3084
|
-
$mol_assert_equal(
|
|
3085
|
-
$mol_assert_equal($mol_tree.fromJSON([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
|
|
3086
|
-
$mol_assert_equal($mol_tree.fromJSON(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
|
|
3087
|
-
$mol_assert_equal($mol_tree.fromJSON({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
|
|
2582
|
+
'has'() {
|
|
2583
|
+
const proxy = $mol_delegate({}, () => ({ foo: 777 }));
|
|
2584
|
+
$mol_assert_equal('foo' in proxy, true);
|
|
3088
2585
|
},
|
|
3089
|
-
'
|
|
3090
|
-
|
|
3091
|
-
$
|
|
3092
|
-
|
|
3093
|
-
$mol_assert_equal(
|
|
3094
|
-
$mol_assert_equal(JSON.stringify($mol_tree.fromString('*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n').sub[0]), '{"foo":false,"bar\\nbaz":"lol"}');
|
|
2586
|
+
'set'() {
|
|
2587
|
+
const target = { foo: 777 };
|
|
2588
|
+
const proxy = $mol_delegate({}, () => target);
|
|
2589
|
+
proxy.foo = 123;
|
|
2590
|
+
$mol_assert_equal(target.foo, 123);
|
|
3095
2591
|
},
|
|
3096
|
-
'
|
|
3097
|
-
const
|
|
3098
|
-
|
|
3099
|
-
|
|
2592
|
+
'getOwnPropertyDescriptor'() {
|
|
2593
|
+
const proxy = $mol_delegate({}, () => ({ foo: 777 }));
|
|
2594
|
+
$mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
|
|
2595
|
+
value: 777,
|
|
2596
|
+
writable: true,
|
|
2597
|
+
enumerable: true,
|
|
2598
|
+
configurable: true,
|
|
3100
2599
|
});
|
|
3101
|
-
$mol_assert_equal(res.toString(), new $mol_tree({ type: 'foo 777 xxx' }).toString());
|
|
3102
2600
|
},
|
|
3103
|
-
'
|
|
3104
|
-
const
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
2601
|
+
'ownKeys'() {
|
|
2602
|
+
const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
|
|
2603
|
+
$mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
|
|
2604
|
+
},
|
|
2605
|
+
'getPrototypeOf'() {
|
|
2606
|
+
class Foo {
|
|
3109
2607
|
}
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
2608
|
+
const proxy = $mol_delegate({}, () => new Foo);
|
|
2609
|
+
$mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
|
|
2610
|
+
},
|
|
2611
|
+
'setPrototypeOf'() {
|
|
2612
|
+
class Foo {
|
|
2613
|
+
}
|
|
2614
|
+
const target = {};
|
|
2615
|
+
const proxy = $mol_delegate({}, () => target);
|
|
2616
|
+
Object.setPrototypeOf(proxy, Foo.prototype);
|
|
2617
|
+
$mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
|
|
2618
|
+
},
|
|
2619
|
+
'instanceof'() {
|
|
2620
|
+
class Foo {
|
|
2621
|
+
}
|
|
2622
|
+
const proxy = $mol_delegate({}, () => new Foo);
|
|
2623
|
+
$mol_assert_ok(proxy instanceof Foo);
|
|
2624
|
+
$mol_assert_ok(proxy instanceof $mol_delegate);
|
|
2625
|
+
},
|
|
2626
|
+
'autobind'() {
|
|
2627
|
+
class Foo {
|
|
2628
|
+
}
|
|
2629
|
+
const proxy = $mol_delegate({}, () => new Foo);
|
|
2630
|
+
$mol_assert_ok(proxy instanceof Foo);
|
|
2631
|
+
$mol_assert_ok(proxy instanceof $mol_delegate);
|
|
3115
2632
|
},
|
|
3116
2633
|
});
|
|
3117
2634
|
})($ || ($ = {}));
|
|
3118
|
-
//mol/
|
|
2635
|
+
//mol/delegate/delegate.test.ts
|
|
2636
|
+
;
|
|
2637
|
+
"use strict";
|
|
2638
|
+
//mol/type/writable/writable.test.ts
|
|
3119
2639
|
;
|
|
3120
2640
|
"use strict";
|
|
3121
2641
|
var $;
|
|
3122
2642
|
(function ($) {
|
|
3123
|
-
$.$
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
2643
|
+
$.$mol_after_mock_queue = [];
|
|
2644
|
+
function $mol_after_mock_warp() {
|
|
2645
|
+
const queue = $.$mol_after_mock_queue.splice(0);
|
|
2646
|
+
for (const task of queue)
|
|
2647
|
+
task();
|
|
2648
|
+
}
|
|
2649
|
+
$.$mol_after_mock_warp = $mol_after_mock_warp;
|
|
2650
|
+
class $mol_after_mock_commmon extends $mol_object2 {
|
|
2651
|
+
task;
|
|
2652
|
+
promise = Promise.resolve();
|
|
2653
|
+
cancelled = false;
|
|
2654
|
+
id;
|
|
2655
|
+
constructor(task) {
|
|
3133
2656
|
super();
|
|
3134
|
-
this.
|
|
3135
|
-
|
|
3136
|
-
var sub = $mol_tree.values(config.value);
|
|
3137
|
-
if (config.type || sub.length > 1) {
|
|
3138
|
-
this.sub = [...sub, ...(config.sub || [])];
|
|
3139
|
-
this.data = config.data || '';
|
|
3140
|
-
}
|
|
3141
|
-
else {
|
|
3142
|
-
this.data = sub[0].data;
|
|
3143
|
-
this.sub = config.sub || [];
|
|
3144
|
-
}
|
|
3145
|
-
}
|
|
3146
|
-
else {
|
|
3147
|
-
this.data = config.data || '';
|
|
3148
|
-
this.sub = config.sub || [];
|
|
3149
|
-
}
|
|
3150
|
-
this.baseUri = config.baseUri || '';
|
|
3151
|
-
this.row = config.row || 0;
|
|
3152
|
-
this.col = config.col || 0;
|
|
3153
|
-
this.length = config.length || 0;
|
|
3154
|
-
}
|
|
3155
|
-
static values(str, baseUri) {
|
|
3156
|
-
return str.split('\n').map((data, index) => new $mol_tree({
|
|
3157
|
-
data: data,
|
|
3158
|
-
baseUri: baseUri,
|
|
3159
|
-
row: index + 1,
|
|
3160
|
-
length: data.length,
|
|
3161
|
-
}));
|
|
3162
|
-
}
|
|
3163
|
-
clone(config = {}) {
|
|
3164
|
-
return new $mol_tree({
|
|
3165
|
-
type: ('type' in config) ? config.type : this.type,
|
|
3166
|
-
data: ('data' in config) ? config.data : this.data,
|
|
3167
|
-
sub: ('sub' in config) ? config.sub : this.sub,
|
|
3168
|
-
baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
|
|
3169
|
-
row: ('row' in config) ? config.row : this.row,
|
|
3170
|
-
col: ('col' in config) ? config.col : this.col,
|
|
3171
|
-
length: ('length' in config) ? config.length : this.length,
|
|
3172
|
-
value: config.value
|
|
3173
|
-
});
|
|
3174
|
-
}
|
|
3175
|
-
make(config) {
|
|
3176
|
-
return new $mol_tree({
|
|
3177
|
-
baseUri: this.baseUri,
|
|
3178
|
-
row: this.row,
|
|
3179
|
-
col: this.col,
|
|
3180
|
-
length: this.length,
|
|
3181
|
-
...config,
|
|
3182
|
-
});
|
|
2657
|
+
this.task = task;
|
|
2658
|
+
$.$mol_after_mock_queue.push(task);
|
|
3183
2659
|
}
|
|
3184
|
-
|
|
3185
|
-
|
|
2660
|
+
destructor() {
|
|
2661
|
+
const index = $.$mol_after_mock_queue.indexOf(this.task);
|
|
2662
|
+
if (index >= 0)
|
|
2663
|
+
$.$mol_after_mock_queue.splice(index, 1);
|
|
3186
2664
|
}
|
|
3187
|
-
|
|
3188
|
-
|
|
2665
|
+
}
|
|
2666
|
+
$.$mol_after_mock_commmon = $mol_after_mock_commmon;
|
|
2667
|
+
class $mol_after_mock_timeout extends $mol_after_mock_commmon {
|
|
2668
|
+
delay;
|
|
2669
|
+
constructor(delay, task) {
|
|
2670
|
+
super(task);
|
|
2671
|
+
this.delay = delay;
|
|
3189
2672
|
}
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
stack.length = deep + 1;
|
|
3209
|
-
var parent = stack[deep];
|
|
3210
|
-
let col = deep;
|
|
3211
|
-
types.forEach(type => {
|
|
3212
|
-
if (!type)
|
|
3213
|
-
return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
|
|
3214
|
-
var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
|
|
3215
|
-
const parent_sub = parent.sub;
|
|
3216
|
-
parent_sub.push(next);
|
|
3217
|
-
parent = next;
|
|
3218
|
-
col += type.length + 1;
|
|
3219
|
-
});
|
|
3220
|
-
if (data) {
|
|
3221
|
-
var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
|
|
3222
|
-
const parent_sub = parent.sub;
|
|
3223
|
-
parent_sub.push(next);
|
|
3224
|
-
parent = next;
|
|
2673
|
+
}
|
|
2674
|
+
$.$mol_after_mock_timeout = $mol_after_mock_timeout;
|
|
2675
|
+
})($ || ($ = {}));
|
|
2676
|
+
//mol/after/mock/mock.test.ts
|
|
2677
|
+
;
|
|
2678
|
+
"use strict";
|
|
2679
|
+
var $;
|
|
2680
|
+
(function ($_1) {
|
|
2681
|
+
$mol_test({
|
|
2682
|
+
async 'Latest Calls Wins on Concurrency'($) {
|
|
2683
|
+
class NameLogger extends $mol_object2 {
|
|
2684
|
+
static $ = $;
|
|
2685
|
+
static first = [];
|
|
2686
|
+
static last = [];
|
|
2687
|
+
static send(next) {
|
|
2688
|
+
$mol_wire_sync(this.first).push(next);
|
|
2689
|
+
this.$.$mol_wait_timeout(0);
|
|
2690
|
+
this.last.push(next);
|
|
3225
2691
|
}
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
2692
|
+
}
|
|
2693
|
+
const name = $mol_wire_async(NameLogger).send;
|
|
2694
|
+
name('john');
|
|
2695
|
+
const promise = name('jin');
|
|
2696
|
+
$.$mol_after_mock_warp();
|
|
2697
|
+
await promise;
|
|
2698
|
+
$mol_assert_like(NameLogger.first, ['john', 'jin']);
|
|
2699
|
+
$mol_assert_like(NameLogger.last, ['jin']);
|
|
2700
|
+
},
|
|
2701
|
+
});
|
|
2702
|
+
})($ || ($ = {}));
|
|
2703
|
+
//mol/wire/async/async.test.ts
|
|
2704
|
+
;
|
|
2705
|
+
"use strict";
|
|
2706
|
+
var $;
|
|
2707
|
+
(function ($_1) {
|
|
2708
|
+
$mol_test({
|
|
2709
|
+
'Collect deps'() {
|
|
2710
|
+
const pub1 = new $mol_wire_pub;
|
|
2711
|
+
const pub2 = new $mol_wire_pub;
|
|
2712
|
+
const sub = new $mol_wire_pub_sub;
|
|
2713
|
+
const bu1 = sub.track_on();
|
|
2714
|
+
try {
|
|
2715
|
+
pub1.promote();
|
|
2716
|
+
pub2.promote();
|
|
2717
|
+
pub2.promote();
|
|
2718
|
+
}
|
|
2719
|
+
finally {
|
|
2720
|
+
sub.track_cut();
|
|
2721
|
+
sub.track_off(bu1);
|
|
2722
|
+
}
|
|
2723
|
+
pub1.emit();
|
|
2724
|
+
pub2.emit();
|
|
2725
|
+
$mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
|
|
2726
|
+
const bu2 = sub.track_on();
|
|
2727
|
+
try {
|
|
2728
|
+
pub1.promote();
|
|
2729
|
+
pub1.promote();
|
|
2730
|
+
pub2.promote();
|
|
2731
|
+
}
|
|
2732
|
+
finally {
|
|
2733
|
+
sub.track_cut();
|
|
2734
|
+
sub.track_off(bu2);
|
|
2735
|
+
}
|
|
2736
|
+
pub1.emit();
|
|
2737
|
+
pub2.emit();
|
|
2738
|
+
$mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
|
|
2739
|
+
},
|
|
2740
|
+
'cyclic detection'($) {
|
|
2741
|
+
const sub1 = new $mol_wire_pub_sub;
|
|
2742
|
+
const sub2 = new $mol_wire_pub_sub;
|
|
2743
|
+
const bu1 = sub1.track_on();
|
|
2744
|
+
try {
|
|
2745
|
+
const bu2 = sub2.track_on();
|
|
2746
|
+
try {
|
|
2747
|
+
$mol_assert_fail(() => sub1.promote(), 'Circular subscription');
|
|
2748
|
+
}
|
|
2749
|
+
finally {
|
|
2750
|
+
sub2.track_cut();
|
|
2751
|
+
sub2.track_off(bu2);
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
finally {
|
|
2755
|
+
sub1.track_cut();
|
|
2756
|
+
sub1.track_off(bu1);
|
|
2757
|
+
}
|
|
2758
|
+
},
|
|
2759
|
+
});
|
|
2760
|
+
})($ || ($ = {}));
|
|
2761
|
+
//mol/wire/pub/sub/sub.test.ts
|
|
2762
|
+
;
|
|
2763
|
+
"use strict";
|
|
2764
|
+
var $;
|
|
2765
|
+
(function ($_1) {
|
|
2766
|
+
$mol_test_mocks.push($ => {
|
|
2767
|
+
$.$mol_after_timeout = $mol_after_mock_timeout;
|
|
2768
|
+
});
|
|
2769
|
+
})($ || ($ = {}));
|
|
2770
|
+
//mol/after/timeout/timeout.test.ts
|
|
2771
|
+
;
|
|
2772
|
+
"use strict";
|
|
2773
|
+
var $;
|
|
2774
|
+
(function ($_1) {
|
|
2775
|
+
$mol_test_mocks.push($ => {
|
|
2776
|
+
$.$mol_after_frame = $mol_after_mock_commmon;
|
|
2777
|
+
});
|
|
2778
|
+
})($ || ($ = {}));
|
|
2779
|
+
//mol/after/frame/frame.test.ts
|
|
2780
|
+
;
|
|
2781
|
+
"use strict";
|
|
2782
|
+
var $;
|
|
2783
|
+
(function ($) {
|
|
2784
|
+
$mol_test({
|
|
2785
|
+
'Sync execution'() {
|
|
2786
|
+
class Sync extends $mol_object2 {
|
|
2787
|
+
static calc(a, b) {
|
|
2788
|
+
return a + b;
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
__decorate([
|
|
2792
|
+
$mol_wire_method
|
|
2793
|
+
], Sync, "calc", null);
|
|
2794
|
+
$mol_assert_equal(Sync.calc(1, 2), 3);
|
|
2795
|
+
},
|
|
2796
|
+
async 'async <=> sync'() {
|
|
2797
|
+
class SyncAsync extends $mol_object2 {
|
|
2798
|
+
static async val(a) {
|
|
2799
|
+
return a;
|
|
2800
|
+
}
|
|
2801
|
+
static sum(a, b) {
|
|
2802
|
+
const syn = $mol_wire_sync(this);
|
|
2803
|
+
return syn.val(a) + syn.val(b);
|
|
2804
|
+
}
|
|
2805
|
+
static async calc(a, b) {
|
|
2806
|
+
return 5 + await $mol_wire_async(this).sum(a, b);
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
$mol_assert_equal(await SyncAsync.calc(1, 2), 8);
|
|
2810
|
+
},
|
|
2811
|
+
async 'Idempotence control'() {
|
|
2812
|
+
class Idempotence extends $mol_object2 {
|
|
2813
|
+
static logs_idemp = 0;
|
|
2814
|
+
static logs_unidemp = 0;
|
|
2815
|
+
static log_idemp() {
|
|
2816
|
+
this.logs_idemp += 1;
|
|
2817
|
+
}
|
|
2818
|
+
static log_unidemp() {
|
|
2819
|
+
this.logs_unidemp += 1;
|
|
2820
|
+
}
|
|
2821
|
+
static async val(a) {
|
|
2822
|
+
return a;
|
|
2823
|
+
}
|
|
2824
|
+
static sum(a, b) {
|
|
2825
|
+
this.log_idemp();
|
|
2826
|
+
this.log_unidemp();
|
|
2827
|
+
const syn = $mol_wire_sync(this);
|
|
2828
|
+
return syn.val(a) + syn.val(b);
|
|
2829
|
+
}
|
|
2830
|
+
static async calc(a, b) {
|
|
2831
|
+
return 5 + await $mol_wire_async(this).sum(a, b);
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2834
|
+
__decorate([
|
|
2835
|
+
$mol_wire_method
|
|
2836
|
+
], Idempotence, "log_idemp", null);
|
|
2837
|
+
$mol_assert_equal(await Idempotence.calc(1, 2), 8);
|
|
2838
|
+
$mol_assert_equal(Idempotence.logs_idemp, 1);
|
|
2839
|
+
$mol_assert_equal(Idempotence.logs_unidemp, 3);
|
|
2840
|
+
},
|
|
2841
|
+
async 'Error handling'() {
|
|
2842
|
+
class Handle extends $mol_object2 {
|
|
2843
|
+
static async sum(a, b) {
|
|
2844
|
+
$mol_fail(new Error('test error ' + (a + b)));
|
|
2845
|
+
}
|
|
2846
|
+
static check() {
|
|
2847
|
+
try {
|
|
2848
|
+
return $mol_wire_sync(Handle).sum(1, 2);
|
|
3264
2849
|
}
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
const subsub = $mol_tree.fromJSON(json[key], baseUri);
|
|
3270
|
-
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
3271
|
-
var child = new $mol_tree({
|
|
3272
|
-
type: key,
|
|
3273
|
-
baseUri: baseUri,
|
|
3274
|
-
sub: [subsub],
|
|
3275
|
-
});
|
|
3276
|
-
}
|
|
3277
|
-
else {
|
|
3278
|
-
var child = new $mol_tree({
|
|
3279
|
-
value: key,
|
|
3280
|
-
baseUri: baseUri,
|
|
3281
|
-
sub: [subsub],
|
|
3282
|
-
});
|
|
3283
|
-
}
|
|
3284
|
-
sub.push(child);
|
|
2850
|
+
catch (error) {
|
|
2851
|
+
if (error instanceof Promise)
|
|
2852
|
+
$mol_fail_hidden(error);
|
|
2853
|
+
$mol_assert_equal(error.message, 'test error 3');
|
|
3285
2854
|
}
|
|
3286
|
-
|
|
3287
|
-
type: "*",
|
|
3288
|
-
sub: sub,
|
|
3289
|
-
baseUri: baseUri
|
|
3290
|
-
});
|
|
2855
|
+
}
|
|
3291
2856
|
}
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
2857
|
+
await $mol_wire_async(Handle).check();
|
|
2858
|
+
},
|
|
2859
|
+
});
|
|
2860
|
+
})($ || ($ = {}));
|
|
2861
|
+
//mol/wire/fiber/fiber.test.ts
|
|
2862
|
+
;
|
|
2863
|
+
"use strict";
|
|
2864
|
+
var $;
|
|
2865
|
+
(function ($) {
|
|
2866
|
+
$mol_test({
|
|
2867
|
+
'Primitives'() {
|
|
2868
|
+
$mol_assert_equal($mol_key(null), 'null');
|
|
2869
|
+
$mol_assert_equal($mol_key(false), 'false');
|
|
2870
|
+
$mol_assert_equal($mol_key(true), 'true');
|
|
2871
|
+
$mol_assert_equal($mol_key(0), '0');
|
|
2872
|
+
$mol_assert_equal($mol_key(''), '""');
|
|
2873
|
+
},
|
|
2874
|
+
'Array & POJO'() {
|
|
2875
|
+
$mol_assert_equal($mol_key([null]), '[null]');
|
|
2876
|
+
$mol_assert_equal($mol_key({ foo: 0 }), '{"foo":0}');
|
|
2877
|
+
$mol_assert_equal($mol_key({ foo: [false] }), '{"foo":[false]}');
|
|
2878
|
+
},
|
|
2879
|
+
'Function'() {
|
|
2880
|
+
const func = () => { };
|
|
2881
|
+
$mol_assert_equal($mol_key(func), $mol_key(func));
|
|
2882
|
+
$mol_assert_unique($mol_key(func), $mol_key(() => { }));
|
|
2883
|
+
},
|
|
2884
|
+
'Objects'() {
|
|
2885
|
+
class User {
|
|
2886
|
+
}
|
|
2887
|
+
const jin = new User();
|
|
2888
|
+
$mol_assert_equal($mol_key(jin), $mol_key(jin));
|
|
2889
|
+
$mol_assert_unique($mol_key(jin), $mol_key(new User()));
|
|
2890
|
+
},
|
|
2891
|
+
'Elements'() {
|
|
2892
|
+
const foo = $mol_jsx("div", null, "bar");
|
|
2893
|
+
$mol_assert_equal($mol_key(foo), $mol_key(foo));
|
|
2894
|
+
$mol_assert_unique($mol_key(foo), $mol_key($mol_jsx("div", null, "bar")));
|
|
2895
|
+
},
|
|
2896
|
+
'Custom JSON representation'() {
|
|
2897
|
+
class User {
|
|
2898
|
+
name;
|
|
2899
|
+
age;
|
|
2900
|
+
constructor(name, age) {
|
|
2901
|
+
this.name = name;
|
|
2902
|
+
this.age = age;
|
|
2903
|
+
}
|
|
2904
|
+
toJSON() { return { name: this.name }; }
|
|
2905
|
+
}
|
|
2906
|
+
$mol_assert_equal($mol_key(new User('jin', 18)), '{"name":"jin"}');
|
|
2907
|
+
},
|
|
2908
|
+
'Special native classes'() {
|
|
2909
|
+
$mol_assert_equal($mol_key(new Date('xyz')), 'null');
|
|
2910
|
+
$mol_assert_equal($mol_key(new Date('2001-01-02T03:04:05.678Z')), '"2001-01-02T03:04:05.678Z"');
|
|
2911
|
+
$mol_assert_equal($mol_key(/./), '"/./"');
|
|
2912
|
+
$mol_assert_equal($mol_key(/\./gimsu), '"/\\\\./gimsu"');
|
|
2913
|
+
},
|
|
2914
|
+
});
|
|
2915
|
+
})($ || ($ = {}));
|
|
2916
|
+
//mol/key/key.test.tsx
|
|
2917
|
+
;
|
|
2918
|
+
"use strict";
|
|
2919
|
+
var $;
|
|
2920
|
+
(function ($_1) {
|
|
2921
|
+
$mol_test({
|
|
2922
|
+
'Cached channel'($) {
|
|
2923
|
+
class App extends $mol_object2 {
|
|
2924
|
+
static $ = $;
|
|
2925
|
+
static value(next = 1) {
|
|
2926
|
+
return next + 1;
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
__decorate([
|
|
2930
|
+
$mol_wire_mem(0)
|
|
2931
|
+
], App, "value", null);
|
|
2932
|
+
$mol_assert_equal(App.value(), 2);
|
|
2933
|
+
App.value(2);
|
|
2934
|
+
$mol_assert_equal(App.value(), 3);
|
|
2935
|
+
},
|
|
2936
|
+
'Mem overrides mem'($) {
|
|
2937
|
+
class Base extends $mol_object2 {
|
|
2938
|
+
static $ = $;
|
|
2939
|
+
static value(next = 1) {
|
|
2940
|
+
return next + 1;
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
__decorate([
|
|
2944
|
+
$mol_wire_mem(0)
|
|
2945
|
+
], Base, "value", null);
|
|
2946
|
+
class Middle extends Base {
|
|
2947
|
+
static value(next) {
|
|
2948
|
+
return super.value(next) + 1;
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
__decorate([
|
|
2952
|
+
$mol_wire_mem(0)
|
|
2953
|
+
], Middle, "value", null);
|
|
2954
|
+
class App extends Middle {
|
|
2955
|
+
static value(next) {
|
|
2956
|
+
return super.value(next) * 3;
|
|
2957
|
+
}
|
|
2958
|
+
}
|
|
2959
|
+
__decorate([
|
|
2960
|
+
$mol_wire_mem(0)
|
|
2961
|
+
], App, "value", null);
|
|
2962
|
+
$mol_assert_equal(App.value(), 9);
|
|
2963
|
+
$mol_assert_equal(App.value(5), 21);
|
|
2964
|
+
$mol_assert_equal(App.value(), 21);
|
|
2965
|
+
},
|
|
2966
|
+
'Auto recalculation of cached values'($) {
|
|
2967
|
+
class App extends $mol_object2 {
|
|
2968
|
+
static $ = $;
|
|
2969
|
+
static xxx(next) {
|
|
2970
|
+
return next || 1;
|
|
2971
|
+
}
|
|
2972
|
+
static yyy() {
|
|
2973
|
+
return this.xxx() + 1;
|
|
2974
|
+
}
|
|
2975
|
+
static zzz() {
|
|
2976
|
+
return this.yyy() + 1;
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
__decorate([
|
|
2980
|
+
$mol_wire_mem(0)
|
|
2981
|
+
], App, "xxx", null);
|
|
2982
|
+
__decorate([
|
|
2983
|
+
$mol_wire_mem(0)
|
|
2984
|
+
], App, "yyy", null);
|
|
2985
|
+
__decorate([
|
|
2986
|
+
$mol_wire_mem(0)
|
|
2987
|
+
], App, "zzz", null);
|
|
2988
|
+
$mol_assert_equal(App.yyy(), 2);
|
|
2989
|
+
$mol_assert_equal(App.zzz(), 3);
|
|
2990
|
+
App.xxx(5);
|
|
2991
|
+
$mol_assert_equal(App.zzz(), 7);
|
|
2992
|
+
},
|
|
2993
|
+
'Skip recalculation when actually no dependency changes'($) {
|
|
2994
|
+
const log = [];
|
|
2995
|
+
class App extends $mol_object2 {
|
|
2996
|
+
static $ = $;
|
|
2997
|
+
static xxx(next) {
|
|
2998
|
+
log.push('xxx');
|
|
2999
|
+
return next || 1;
|
|
3000
|
+
}
|
|
3001
|
+
static yyy() {
|
|
3002
|
+
log.push('yyy');
|
|
3003
|
+
return [Math.sign(this.xxx())];
|
|
3004
|
+
}
|
|
3005
|
+
static zzz() {
|
|
3006
|
+
log.push('zzz');
|
|
3007
|
+
return this.yyy()[0] + 1;
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
__decorate([
|
|
3011
|
+
$mol_wire_mem(0)
|
|
3012
|
+
], App, "xxx", null);
|
|
3013
|
+
__decorate([
|
|
3014
|
+
$mol_wire_mem(0)
|
|
3015
|
+
], App, "yyy", null);
|
|
3016
|
+
__decorate([
|
|
3017
|
+
$mol_wire_mem(0)
|
|
3018
|
+
], App, "zzz", null);
|
|
3019
|
+
App.zzz();
|
|
3020
|
+
$mol_assert_like(log, ['zzz', 'yyy', 'xxx']);
|
|
3021
|
+
App.xxx(5);
|
|
3022
|
+
$mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx']);
|
|
3023
|
+
App.zzz();
|
|
3024
|
+
$mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx', 'yyy']);
|
|
3025
|
+
},
|
|
3026
|
+
'Flow: Auto'($) {
|
|
3027
|
+
class App extends $mol_object2 {
|
|
3028
|
+
static get $() { return $; }
|
|
3029
|
+
static first(next = 1) { return next; }
|
|
3030
|
+
static second(next = 2) { return next; }
|
|
3031
|
+
static condition(next = true) { return next; }
|
|
3032
|
+
static counter = 0;
|
|
3033
|
+
static result() {
|
|
3034
|
+
const res = this.condition() ? this.first() : this.second();
|
|
3035
|
+
return res + this.counter++;
|
|
3036
|
+
}
|
|
3037
|
+
}
|
|
3038
|
+
__decorate([
|
|
3039
|
+
$mol_wire_mem(0)
|
|
3040
|
+
], App, "first", null);
|
|
3041
|
+
__decorate([
|
|
3042
|
+
$mol_wire_mem(0)
|
|
3043
|
+
], App, "second", null);
|
|
3044
|
+
__decorate([
|
|
3045
|
+
$mol_wire_mem(0)
|
|
3046
|
+
], App, "condition", null);
|
|
3047
|
+
__decorate([
|
|
3048
|
+
$mol_wire_mem(0)
|
|
3049
|
+
], App, "result", null);
|
|
3050
|
+
$mol_assert_equal(App.result(), 1);
|
|
3051
|
+
$mol_assert_equal(App.counter, 1);
|
|
3052
|
+
App.condition(false);
|
|
3053
|
+
$mol_assert_equal(App.result(), 3);
|
|
3054
|
+
$mol_assert_equal(App.counter, 2);
|
|
3055
|
+
App.first(10);
|
|
3056
|
+
$mol_assert_equal(App.result(), 3);
|
|
3057
|
+
$mol_assert_equal(App.counter, 2);
|
|
3058
|
+
},
|
|
3059
|
+
'Dupes: Equality'($) {
|
|
3060
|
+
let counter = 0;
|
|
3061
|
+
class App extends $mol_object2 {
|
|
3062
|
+
static $ = $;
|
|
3063
|
+
static foo(next) {
|
|
3064
|
+
return next ?? { numbs: [1] };
|
|
3065
|
+
}
|
|
3066
|
+
static bar() {
|
|
3067
|
+
return { ...this.foo(), count: ++counter };
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
__decorate([
|
|
3071
|
+
$mol_wire_mem(0)
|
|
3072
|
+
], App, "foo", null);
|
|
3073
|
+
__decorate([
|
|
3074
|
+
$mol_wire_mem(0)
|
|
3075
|
+
], App, "bar", null);
|
|
3076
|
+
$mol_assert_like(App.bar(), { numbs: [1], count: 1 });
|
|
3077
|
+
App.foo({ numbs: [1] });
|
|
3078
|
+
$mol_assert_like(App.bar(), { numbs: [1], count: 1 });
|
|
3079
|
+
App.foo({ numbs: [2] });
|
|
3080
|
+
$mol_assert_like(App.bar(), { numbs: [2], count: 2 });
|
|
3081
|
+
},
|
|
3082
|
+
'Cycle: Fail'($) {
|
|
3083
|
+
class App extends $mol_object2 {
|
|
3084
|
+
static $ = $;
|
|
3085
|
+
static foo() {
|
|
3086
|
+
return this.bar() + 1;
|
|
3087
|
+
}
|
|
3088
|
+
static bar() {
|
|
3089
|
+
return this.foo() + 1;
|
|
3090
|
+
}
|
|
3091
|
+
static test() {
|
|
3092
|
+
$mol_assert_fail(() => App.foo(), 'Circular subscription');
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
__decorate([
|
|
3096
|
+
$mol_wire_mem(0)
|
|
3097
|
+
], App, "foo", null);
|
|
3098
|
+
__decorate([
|
|
3099
|
+
$mol_wire_mem(0)
|
|
3100
|
+
], App, "bar", null);
|
|
3101
|
+
__decorate([
|
|
3102
|
+
$mol_wire_method
|
|
3103
|
+
], App, "test", null);
|
|
3104
|
+
App.test();
|
|
3105
|
+
},
|
|
3106
|
+
'Different order of pull and push'($) {
|
|
3107
|
+
class App extends $mol_object2 {
|
|
3108
|
+
static $ = $;
|
|
3109
|
+
static store(next = 0) {
|
|
3110
|
+
return next;
|
|
3111
|
+
}
|
|
3112
|
+
static fast(next) {
|
|
3113
|
+
return this.store(next);
|
|
3114
|
+
}
|
|
3115
|
+
static slow(next) {
|
|
3116
|
+
return this.store(next);
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
__decorate([
|
|
3120
|
+
$mol_wire_mem(0)
|
|
3121
|
+
], App, "store", null);
|
|
3122
|
+
__decorate([
|
|
3123
|
+
$mol_wire_mem(0)
|
|
3124
|
+
], App, "fast", null);
|
|
3125
|
+
__decorate([
|
|
3126
|
+
$mol_wire_mem(0)
|
|
3127
|
+
], App, "slow", null);
|
|
3128
|
+
App.fast();
|
|
3129
|
+
$mol_assert_equal(App.slow(666), 666);
|
|
3130
|
+
$mol_assert_equal(App.fast(), App.slow(), 666);
|
|
3131
|
+
App.store(777);
|
|
3132
|
+
$mol_assert_equal(App.fast(), App.slow(), 777);
|
|
3133
|
+
},
|
|
3134
|
+
'Actions inside invariant'($) {
|
|
3135
|
+
class App extends $mol_object2 {
|
|
3136
|
+
static $ = $;
|
|
3137
|
+
static count(next = 0) {
|
|
3138
|
+
return next;
|
|
3139
|
+
}
|
|
3140
|
+
static count2() {
|
|
3141
|
+
return this.count();
|
|
3142
|
+
}
|
|
3143
|
+
static res() {
|
|
3144
|
+
const count = this.count2();
|
|
3145
|
+
if (!count)
|
|
3146
|
+
this.count(count + 1);
|
|
3147
|
+
return count + 1;
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
__decorate([
|
|
3151
|
+
$mol_wire_mem(0)
|
|
3152
|
+
], App, "count", null);
|
|
3153
|
+
__decorate([
|
|
3154
|
+
$mol_wire_mem(0)
|
|
3155
|
+
], App, "count2", null);
|
|
3156
|
+
__decorate([
|
|
3157
|
+
$mol_wire_mem(0)
|
|
3158
|
+
], App, "res", null);
|
|
3159
|
+
$mol_assert_like(App.res(), 1);
|
|
3160
|
+
App.count(5);
|
|
3161
|
+
$mol_assert_like(App.res(), 6);
|
|
3162
|
+
},
|
|
3163
|
+
async 'Toggle with async'($) {
|
|
3164
|
+
class App extends $mol_object2 {
|
|
3165
|
+
static $ = $;
|
|
3166
|
+
static checked(next = false) {
|
|
3167
|
+
$$.$mol_wait_timeout(0);
|
|
3168
|
+
return next;
|
|
3301
3169
|
}
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3170
|
+
static toggle() {
|
|
3171
|
+
const prev = this.checked();
|
|
3172
|
+
$mol_assert_unique(this.checked(!prev), prev);
|
|
3305
3173
|
}
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
output += child.toString(prefix + "\t");
|
|
3314
|
-
}
|
|
3315
|
-
return output;
|
|
3316
|
-
}
|
|
3317
|
-
toJSON() {
|
|
3318
|
-
if (!this.type)
|
|
3319
|
-
return this.value;
|
|
3320
|
-
if (this.type === 'true')
|
|
3321
|
-
return true;
|
|
3322
|
-
if (this.type === 'false')
|
|
3323
|
-
return false;
|
|
3324
|
-
if (this.type === 'null')
|
|
3325
|
-
return null;
|
|
3326
|
-
if (this.type === '*') {
|
|
3327
|
-
var obj = {};
|
|
3328
|
-
for (var child of this.sub) {
|
|
3329
|
-
if (child.type === '-')
|
|
3330
|
-
continue;
|
|
3331
|
-
var key = child.type || child.clone({ sub: child.sub.slice(0, child.sub.length - 1) }).value;
|
|
3332
|
-
var val = child.sub[child.sub.length - 1].toJSON();
|
|
3333
|
-
if (val !== undefined)
|
|
3334
|
-
obj[key] = val;
|
|
3174
|
+
static res() {
|
|
3175
|
+
return this.checked();
|
|
3176
|
+
}
|
|
3177
|
+
static test() {
|
|
3178
|
+
$mol_assert_equal(App.res(), false);
|
|
3179
|
+
App.toggle();
|
|
3180
|
+
$mol_assert_equal(App.res(), true);
|
|
3335
3181
|
}
|
|
3336
|
-
return obj;
|
|
3337
3182
|
}
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3183
|
+
__decorate([
|
|
3184
|
+
$mol_wire_mem(0)
|
|
3185
|
+
], App, "checked", null);
|
|
3186
|
+
__decorate([
|
|
3187
|
+
$mol_wire_method
|
|
3188
|
+
], App, "toggle", null);
|
|
3189
|
+
__decorate([
|
|
3190
|
+
$mol_wire_mem(0)
|
|
3191
|
+
], App, "res", null);
|
|
3192
|
+
__decorate([
|
|
3193
|
+
$mol_wire_method
|
|
3194
|
+
], App, "test", null);
|
|
3195
|
+
await $mol_wire_async(App).test();
|
|
3196
|
+
},
|
|
3197
|
+
'Restore after error'($) {
|
|
3198
|
+
class App extends $mol_object2 {
|
|
3199
|
+
static get $() { return $; }
|
|
3200
|
+
static condition(next = false) { return next; }
|
|
3201
|
+
static broken() {
|
|
3202
|
+
if (this.condition()) {
|
|
3203
|
+
$mol_fail(new Error('test error'));
|
|
3204
|
+
}
|
|
3205
|
+
return 1;
|
|
3206
|
+
}
|
|
3207
|
+
static result() {
|
|
3208
|
+
return this.broken();
|
|
3209
|
+
}
|
|
3348
3210
|
}
|
|
3349
|
-
|
|
3350
|
-
|
|
3211
|
+
__decorate([
|
|
3212
|
+
$mol_wire_mem(0)
|
|
3213
|
+
], App, "condition", null);
|
|
3214
|
+
__decorate([
|
|
3215
|
+
$mol_wire_mem(0)
|
|
3216
|
+
], App, "broken", null);
|
|
3217
|
+
__decorate([
|
|
3218
|
+
$mol_wire_mem(0)
|
|
3219
|
+
], App, "result", null);
|
|
3220
|
+
$mol_assert_equal(App.result(), 1);
|
|
3221
|
+
App.condition(true);
|
|
3222
|
+
$mol_assert_fail(() => App.result());
|
|
3223
|
+
App.condition(false);
|
|
3224
|
+
$mol_assert_equal(App.result(), 1);
|
|
3225
|
+
},
|
|
3226
|
+
async 'Wait for data'($) {
|
|
3227
|
+
class App extends $mol_object2 {
|
|
3228
|
+
static $ = $;
|
|
3229
|
+
static async source() {
|
|
3230
|
+
return 'Jin';
|
|
3231
|
+
}
|
|
3232
|
+
static middle() {
|
|
3233
|
+
return $mol_wire_sync(this).source();
|
|
3234
|
+
}
|
|
3235
|
+
static target() {
|
|
3236
|
+
return this.middle();
|
|
3237
|
+
}
|
|
3238
|
+
static test() {
|
|
3239
|
+
$mol_assert_equal(App.target(), 'Jin');
|
|
3240
|
+
}
|
|
3351
3241
|
}
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3242
|
+
__decorate([
|
|
3243
|
+
$mol_wire_mem(0)
|
|
3244
|
+
], App, "middle", null);
|
|
3245
|
+
__decorate([
|
|
3246
|
+
$mol_wire_mem(0)
|
|
3247
|
+
], App, "target", null);
|
|
3248
|
+
__decorate([
|
|
3249
|
+
$mol_wire_method
|
|
3250
|
+
], App, "test", null);
|
|
3251
|
+
await $mol_wire_async(App).test();
|
|
3252
|
+
},
|
|
3253
|
+
'Auto destroy on long alone'($) {
|
|
3254
|
+
let destroyed = false;
|
|
3255
|
+
class App extends $mol_object2 {
|
|
3256
|
+
static $ = $;
|
|
3257
|
+
static showing(next = true) {
|
|
3258
|
+
return next;
|
|
3259
|
+
}
|
|
3260
|
+
static details() {
|
|
3261
|
+
return {
|
|
3262
|
+
destructor() {
|
|
3263
|
+
destroyed = true;
|
|
3264
|
+
}
|
|
3265
|
+
};
|
|
3266
|
+
}
|
|
3267
|
+
static render() {
|
|
3268
|
+
return this.showing() ? this.details() : null;
|
|
3269
|
+
}
|
|
3363
3270
|
}
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3271
|
+
__decorate([
|
|
3272
|
+
$mol_wire_mem(0)
|
|
3273
|
+
], App, "showing", null);
|
|
3274
|
+
__decorate([
|
|
3275
|
+
$mol_wire_mem(0)
|
|
3276
|
+
], App, "details", null);
|
|
3277
|
+
__decorate([
|
|
3278
|
+
$mol_wire_mem(0)
|
|
3279
|
+
], App, "render", null);
|
|
3280
|
+
const details = App.render();
|
|
3281
|
+
$mol_assert_ok(details);
|
|
3282
|
+
App.showing(false);
|
|
3283
|
+
$mol_assert_not(App.render());
|
|
3284
|
+
App.showing(true);
|
|
3285
|
+
$mol_assert_equal(App.render(), details);
|
|
3286
|
+
$mol_wire_fiber.sync();
|
|
3287
|
+
$mol_assert_not(destroyed);
|
|
3288
|
+
App.showing(false);
|
|
3289
|
+
$mol_wire_fiber.sync();
|
|
3290
|
+
$mol_assert_ok(destroyed);
|
|
3291
|
+
App.showing(true);
|
|
3292
|
+
$mol_assert_unique(App.render(), details);
|
|
3293
|
+
},
|
|
3294
|
+
async 'Hold pubs while wait async task'($) {
|
|
3295
|
+
class App extends $mol_object2 {
|
|
3296
|
+
static $ = $;
|
|
3297
|
+
static counter = 0;
|
|
3298
|
+
static resets(next) {
|
|
3299
|
+
return ($mol_wire_probe(() => this.resets()) ?? -1) + 1;
|
|
3300
|
+
}
|
|
3301
|
+
static async wait() { }
|
|
3302
|
+
static value() {
|
|
3303
|
+
return ++this.counter;
|
|
3304
|
+
}
|
|
3305
|
+
static result() {
|
|
3306
|
+
if (this.resets())
|
|
3307
|
+
$mol_wire_sync(this).wait();
|
|
3308
|
+
return this.value();
|
|
3309
|
+
}
|
|
3310
|
+
static test() {
|
|
3311
|
+
}
|
|
3381
3312
|
}
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3313
|
+
__decorate([
|
|
3314
|
+
$mol_wire_mem(0)
|
|
3315
|
+
], App, "resets", null);
|
|
3316
|
+
__decorate([
|
|
3317
|
+
$mol_wire_mem(0)
|
|
3318
|
+
], App, "value", null);
|
|
3319
|
+
__decorate([
|
|
3320
|
+
$mol_wire_mem(0)
|
|
3321
|
+
], App, "result", null);
|
|
3322
|
+
__decorate([
|
|
3323
|
+
$mol_wire_method
|
|
3324
|
+
], App, "test", null);
|
|
3325
|
+
$mol_assert_equal(App.result(), 1);
|
|
3326
|
+
App.resets(null);
|
|
3327
|
+
$mol_wire_fiber.sync();
|
|
3328
|
+
$mol_assert_equal(await $mol_wire_async(App).result(), 1);
|
|
3329
|
+
},
|
|
3330
|
+
'Memoize by single simple key'($) {
|
|
3331
|
+
class Team extends $mol_object2 {
|
|
3332
|
+
static $ = $;
|
|
3333
|
+
static user_name(user, next) {
|
|
3334
|
+
return next ?? user;
|
|
3335
|
+
}
|
|
3336
|
+
static user_names() {
|
|
3337
|
+
return [
|
|
3338
|
+
this.user_name('jin'),
|
|
3339
|
+
this.user_name('john'),
|
|
3340
|
+
];
|
|
3341
|
+
}
|
|
3342
|
+
static test() {
|
|
3343
|
+
}
|
|
3386
3344
|
}
|
|
3387
|
-
|
|
3388
|
-
|
|
3345
|
+
__decorate([
|
|
3346
|
+
$mol_wire_mem(1)
|
|
3347
|
+
], Team, "user_name", null);
|
|
3348
|
+
__decorate([
|
|
3349
|
+
$mol_wire_mem(1)
|
|
3350
|
+
], Team, "user_names", null);
|
|
3351
|
+
__decorate([
|
|
3352
|
+
$mol_wire_method
|
|
3353
|
+
], Team, "test", null);
|
|
3354
|
+
$mol_assert_like(Team.user_names(), ['jin', 'john']);
|
|
3355
|
+
Team.user_name('jin', 'JIN');
|
|
3356
|
+
$mol_assert_like(Team.user_names(), ['JIN', 'john']);
|
|
3357
|
+
},
|
|
3358
|
+
'Memoize by single complex key'($) {
|
|
3359
|
+
class Map extends $mol_object2 {
|
|
3360
|
+
static $ = $;
|
|
3361
|
+
static tile(pos) {
|
|
3362
|
+
return new String(`/tile=${pos}`);
|
|
3363
|
+
}
|
|
3364
|
+
static test() {
|
|
3365
|
+
$mol_assert_like(this.tile([0, 1]), new String('/tile=0,1'));
|
|
3366
|
+
$mol_assert_equal(this.tile([0, 1]), this.tile([0, 1]));
|
|
3367
|
+
}
|
|
3389
3368
|
}
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
case 'number':
|
|
3408
|
-
if (type < item.sub.length)
|
|
3409
|
-
next.push(item.sub[type]);
|
|
3410
|
-
break;
|
|
3411
|
-
default: next.push(...item.sub);
|
|
3412
|
-
}
|
|
3369
|
+
__decorate([
|
|
3370
|
+
$mol_wire_mem(1)
|
|
3371
|
+
], Map, "tile", null);
|
|
3372
|
+
__decorate([
|
|
3373
|
+
$mol_wire_method
|
|
3374
|
+
], Map, "test", null);
|
|
3375
|
+
Map.test();
|
|
3376
|
+
},
|
|
3377
|
+
'Memoize by multiple keys'($) {
|
|
3378
|
+
class Map extends $mol_object2 {
|
|
3379
|
+
static $ = $;
|
|
3380
|
+
static tile(x, y) {
|
|
3381
|
+
return new String(`/tile=${x},${y}`);
|
|
3382
|
+
}
|
|
3383
|
+
static test() {
|
|
3384
|
+
$mol_assert_like(this.tile(0, 1), new String('/tile=0,1'));
|
|
3385
|
+
$mol_assert_equal(this.tile(0, 1), this.tile(0, 1));
|
|
3413
3386
|
}
|
|
3414
3387
|
}
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3388
|
+
__decorate([
|
|
3389
|
+
$mol_wire_mem(2)
|
|
3390
|
+
], Map, "tile", null);
|
|
3391
|
+
__decorate([
|
|
3392
|
+
$mol_wire_method
|
|
3393
|
+
], Map, "test", null);
|
|
3394
|
+
Map.test();
|
|
3395
|
+
},
|
|
3396
|
+
'Owned value has js-path name'() {
|
|
3397
|
+
class App extends $mol_object2 {
|
|
3398
|
+
static title() {
|
|
3399
|
+
return new $mol_object2;
|
|
3422
3400
|
}
|
|
3423
|
-
|
|
3424
|
-
return
|
|
3401
|
+
static like(friend) {
|
|
3402
|
+
return new $mol_object2;
|
|
3425
3403
|
}
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
}));
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3404
|
+
static relation(friend, props) {
|
|
3405
|
+
return new $mol_object2;
|
|
3406
|
+
}
|
|
3407
|
+
}
|
|
3408
|
+
__decorate([
|
|
3409
|
+
$mol_wire_mem(0)
|
|
3410
|
+
], App, "title", null);
|
|
3411
|
+
__decorate([
|
|
3412
|
+
$mol_wire_mem(1)
|
|
3413
|
+
], App, "like", null);
|
|
3414
|
+
__decorate([
|
|
3415
|
+
$mol_wire_mem(2)
|
|
3416
|
+
], App, "relation", null);
|
|
3417
|
+
$mol_assert_equal(`${App.title()}`, 'App.title()');
|
|
3418
|
+
$mol_assert_equal(`${App.like(123)}`, 'App.like(123)');
|
|
3419
|
+
$mol_assert_equal(`${App.relation(123, [456])}`, 'App.relation(123,[456])');
|
|
3420
|
+
},
|
|
3421
|
+
'Deep deps'($) {
|
|
3422
|
+
class Fib extends $mol_object2 {
|
|
3423
|
+
static $ = $;
|
|
3424
|
+
static sums = 0;
|
|
3425
|
+
static value(index, next) {
|
|
3426
|
+
if (next)
|
|
3427
|
+
return next;
|
|
3428
|
+
if (index < 2)
|
|
3429
|
+
return 1;
|
|
3430
|
+
++this.sums;
|
|
3431
|
+
return this.value(index - 1) + this.value(index - 2);
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
__decorate([
|
|
3435
|
+
$mol_wire_mem(1)
|
|
3436
|
+
], Fib, "value", null);
|
|
3437
|
+
$mol_assert_equal(Fib.value(4), 5);
|
|
3438
|
+
$mol_assert_equal(Fib.sums, 3);
|
|
3439
|
+
Fib.value(1, 2);
|
|
3440
|
+
$mol_assert_equal(Fib.value(4), 8);
|
|
3441
|
+
$mol_assert_equal(Fib.sums, 6);
|
|
3442
|
+
},
|
|
3443
|
+
});
|
|
3450
3444
|
})($ || ($ = {}));
|
|
3451
|
-
//mol/
|
|
3445
|
+
//mol/wire/mem/mem.test.ts
|
|
3452
3446
|
;
|
|
3453
3447
|
"use strict";
|
|
3454
3448
|
var $;
|
|
3455
|
-
(function ($) {
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3449
|
+
(function ($_1) {
|
|
3450
|
+
$mol_test({
|
|
3451
|
+
'tree parsing'() {
|
|
3452
|
+
$mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub.length, 2);
|
|
3453
|
+
$mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub[1].type, "bar");
|
|
3454
|
+
$mol_assert_equal($mol_tree.fromString("foo\n\n\n").sub.length, 1);
|
|
3455
|
+
$mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub.length, 2);
|
|
3456
|
+
$mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub[1].data, "bar");
|
|
3457
|
+
$mol_assert_equal($mol_tree.fromString("foo bar \\pol").sub[0].sub[0].sub[0].data, "pol");
|
|
3458
|
+
$mol_assert_equal($mol_tree.fromString("foo bar\n\t\\pol\n\t\\men").sub[0].sub[0].sub[1].data, "men");
|
|
3459
|
+
$mol_assert_equal($mol_tree.fromString('foo bar \\text\n').toString(), 'foo bar \\text\n');
|
|
3460
|
+
},
|
|
3461
|
+
'inserting'() {
|
|
3462
|
+
$mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 'a', 'b', 'c').toString(), 'a b \\\n');
|
|
3463
|
+
$mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 'a', 'b', 'c', 'd').toString(), 'a b c \\\n');
|
|
3464
|
+
$mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 0, 0, 0).toString(), 'a b \\\n');
|
|
3465
|
+
$mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 0, 0, 0, 0).toString(), 'a b \\\n\t\\\n');
|
|
3466
|
+
$mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, null, null, null).toString(), 'a b \\\n');
|
|
3467
|
+
$mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, null, null, null, null).toString(), 'a b \\\n\t\\\n');
|
|
3468
|
+
},
|
|
3469
|
+
'fromJSON'() {
|
|
3470
|
+
$mol_assert_equal($mol_tree.fromJSON([]).toString(), '/\n');
|
|
3471
|
+
$mol_assert_equal($mol_tree.fromJSON([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
|
|
3472
|
+
$mol_assert_equal($mol_tree.fromJSON([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
|
|
3473
|
+
$mol_assert_equal($mol_tree.fromJSON(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
|
|
3474
|
+
$mol_assert_equal($mol_tree.fromJSON({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
|
|
3475
|
+
},
|
|
3476
|
+
'toJSON'() {
|
|
3477
|
+
$mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n').sub[0]), '[]');
|
|
3478
|
+
$mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\tfalse\n\ttrue\n').sub[0]), '[false,true]');
|
|
3479
|
+
$mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t0\n\t1\n\t2.3\n').sub[0]), '[0,1,2.3]');
|
|
3480
|
+
$mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n').sub[0]), '["","foo","bar\\nbaz"]');
|
|
3481
|
+
$mol_assert_equal(JSON.stringify($mol_tree.fromString('*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n').sub[0]), '{"foo":false,"bar\\nbaz":"lol"}');
|
|
3482
|
+
},
|
|
3483
|
+
'hack'() {
|
|
3484
|
+
const res = $mol_tree.fromString(`foo bar xxx`).hack({
|
|
3485
|
+
'': (tree, context) => [tree.hack(context)],
|
|
3486
|
+
'bar': (tree, context) => [tree.hack(context).clone({ type: '777' })],
|
|
3487
|
+
});
|
|
3488
|
+
$mol_assert_equal(res.toString(), new $mol_tree({ type: 'foo 777 xxx' }).toString());
|
|
3489
|
+
},
|
|
3490
|
+
'errors handling'($) {
|
|
3491
|
+
const errors = [];
|
|
3492
|
+
class Tree extends $mol_tree {
|
|
3493
|
+
static $ = $.$mol_ambient({
|
|
3494
|
+
$mol_fail: error => errors.push(error.message)
|
|
3477
3495
|
});
|
|
3478
3496
|
}
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
for (const pub of $mol_wire_auto().pub_list) {
|
|
3487
|
-
if (pub instanceof $mol_wire_fiber) {
|
|
3488
|
-
this.track(pub);
|
|
3489
|
-
}
|
|
3490
|
-
}
|
|
3491
|
-
}
|
|
3492
|
-
}
|
|
3493
|
-
}
|
|
3494
|
-
__decorate([
|
|
3495
|
-
$mol_mem
|
|
3496
|
-
], $mol_wire_log, "watch", null);
|
|
3497
|
-
__decorate([
|
|
3498
|
-
$mol_mem_key
|
|
3499
|
-
], $mol_wire_log, "track", null);
|
|
3500
|
-
__decorate([
|
|
3501
|
-
$mol_mem
|
|
3502
|
-
], $mol_wire_log, "active", null);
|
|
3503
|
-
$.$mol_wire_log = $mol_wire_log;
|
|
3497
|
+
Tree.fromString(`
|
|
3498
|
+
\t \tfoo
|
|
3499
|
+
bar \\data
|
|
3500
|
+
`, 'test');
|
|
3501
|
+
$mol_assert_like(errors, ['Syntax error at test:2\n \tfoo']);
|
|
3502
|
+
},
|
|
3503
|
+
});
|
|
3504
3504
|
})($ || ($ = {}));
|
|
3505
|
-
//mol/
|
|
3505
|
+
//mol/tree/tree.test.ts
|
|
3506
3506
|
;
|
|
3507
3507
|
"use strict";
|
|
3508
3508
|
var $;
|