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