mol_compare_deep 0.0.138 → 0.0.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node.test.js +118 -14
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.test.js +118 -14
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
|
@@ -618,6 +618,48 @@ var $;
|
|
|
618
618
|
;
|
|
619
619
|
"use strict";
|
|
620
620
|
var $;
|
|
621
|
+
(function ($_1) {
|
|
622
|
+
$mol_test({
|
|
623
|
+
'FQN of anon function'($) {
|
|
624
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
|
625
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
|
626
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
|
627
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
|
628
|
+
},
|
|
629
|
+
});
|
|
630
|
+
})($ || ($ = {}));
|
|
631
|
+
//mol/func/name/name.test.ts
|
|
632
|
+
;
|
|
633
|
+
"use strict";
|
|
634
|
+
var $;
|
|
635
|
+
(function ($) {
|
|
636
|
+
function $mol_func_name(func) {
|
|
637
|
+
let name = func.name;
|
|
638
|
+
if (name?.length > 1)
|
|
639
|
+
return name;
|
|
640
|
+
for (let key in this) {
|
|
641
|
+
try {
|
|
642
|
+
if (this[key] !== func)
|
|
643
|
+
continue;
|
|
644
|
+
name = key;
|
|
645
|
+
Object.defineProperty(func, 'name', { value: name });
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
catch { }
|
|
649
|
+
}
|
|
650
|
+
return name;
|
|
651
|
+
}
|
|
652
|
+
$.$mol_func_name = $mol_func_name;
|
|
653
|
+
function $mol_func_name_from(target, source) {
|
|
654
|
+
Object.defineProperty(target, 'name', { value: source.name });
|
|
655
|
+
return target;
|
|
656
|
+
}
|
|
657
|
+
$.$mol_func_name_from = $mol_func_name_from;
|
|
658
|
+
})($ || ($ = {}));
|
|
659
|
+
//mol/func/name/name.ts
|
|
660
|
+
;
|
|
661
|
+
"use strict";
|
|
662
|
+
var $;
|
|
621
663
|
(function ($) {
|
|
622
664
|
function $mol_dom_render_children(el, childNodes) {
|
|
623
665
|
const node_set = new Set(childNodes);
|
|
@@ -1337,28 +1379,52 @@ var $;
|
|
|
1337
1379
|
const Button = (props, target) => {
|
|
1338
1380
|
return $mol_jsx("button", { title: props.hint }, target());
|
|
1339
1381
|
};
|
|
1340
|
-
const dom = $mol_jsx(Button, { id: "
|
|
1341
|
-
$mol_assert_equal(dom.outerHTML, '<button title="click me"
|
|
1382
|
+
const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
|
|
1383
|
+
$mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
|
|
1342
1384
|
},
|
|
1343
1385
|
'Nested guid generation'() {
|
|
1344
1386
|
const Foo = () => {
|
|
1345
1387
|
return $mol_jsx("div", null,
|
|
1346
|
-
$mol_jsx(Bar, { id: "
|
|
1347
|
-
$mol_jsx("img", { id: "
|
|
1388
|
+
$mol_jsx(Bar, { id: "bar" },
|
|
1389
|
+
$mol_jsx("img", { id: "icon" })));
|
|
1348
1390
|
};
|
|
1349
1391
|
const Bar = (props, icon) => {
|
|
1350
|
-
return $mol_jsx("span", null,
|
|
1392
|
+
return $mol_jsx("span", null,
|
|
1393
|
+
icon,
|
|
1394
|
+
$mol_jsx("i", { id: "label" }));
|
|
1351
1395
|
};
|
|
1352
|
-
const dom = $mol_jsx(Foo, { id: "
|
|
1353
|
-
$mol_assert_equal(dom.outerHTML, '<div id="
|
|
1396
|
+
const dom = $mol_jsx(Foo, { id: "foo" });
|
|
1397
|
+
$mol_assert_equal(dom.outerHTML, '<div id="foo" class="Foo"><span id="foo/bar" class="Foo_bar Bar"><img id="foo/icon" class="Foo_icon"><i id="foo/bar/label" class="Foo_bar_label Bar_label"></i></span></div>');
|
|
1354
1398
|
},
|
|
1355
1399
|
'Fail on non unique ids'() {
|
|
1356
1400
|
const App = () => {
|
|
1357
1401
|
return $mol_jsx("div", null,
|
|
1358
|
-
$mol_jsx("span", { id: "
|
|
1359
|
-
$mol_jsx("span", { id: "
|
|
1402
|
+
$mol_jsx("span", { id: "bar" }),
|
|
1403
|
+
$mol_jsx("span", { id: "bar" }));
|
|
1404
|
+
};
|
|
1405
|
+
$mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
|
|
1406
|
+
},
|
|
1407
|
+
'Owner based guid generationn'() {
|
|
1408
|
+
const Foo = () => {
|
|
1409
|
+
return $mol_jsx("div", null,
|
|
1410
|
+
$mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
1360
1411
|
};
|
|
1361
|
-
|
|
1412
|
+
const Bar = (props) => {
|
|
1413
|
+
return $mol_jsx("span", null, props.icon());
|
|
1414
|
+
};
|
|
1415
|
+
const dom = $mol_jsx(Foo, { id: "app" });
|
|
1416
|
+
$mol_assert_equal(dom.outerHTML, '<div id="app" class="Foo"><span id="app/middle" class="Foo_middle Bar"><img id="app/icon" class="Foo_icon"></span></div>');
|
|
1417
|
+
},
|
|
1418
|
+
'Fail on same ids from different caller'() {
|
|
1419
|
+
const Foo = () => {
|
|
1420
|
+
return $mol_jsx("div", null,
|
|
1421
|
+
$mol_jsx("img", { id: "icon" }),
|
|
1422
|
+
$mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
1423
|
+
};
|
|
1424
|
+
const Bar = (props) => {
|
|
1425
|
+
return $mol_jsx("span", null, props.icon());
|
|
1426
|
+
};
|
|
1427
|
+
$mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
|
|
1362
1428
|
},
|
|
1363
1429
|
});
|
|
1364
1430
|
})($ || ($ = {}));
|
|
@@ -1368,6 +1434,7 @@ var $;
|
|
|
1368
1434
|
var $;
|
|
1369
1435
|
(function ($) {
|
|
1370
1436
|
$.$mol_jsx_prefix = '';
|
|
1437
|
+
$.$mol_jsx_crumbs = '';
|
|
1371
1438
|
$.$mol_jsx_booked = null;
|
|
1372
1439
|
$.$mol_jsx_document = {
|
|
1373
1440
|
getElementById: () => null,
|
|
@@ -1377,16 +1444,45 @@ var $;
|
|
|
1377
1444
|
$.$mol_jsx_frag = '';
|
|
1378
1445
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
1379
1446
|
const id = props && props.id || '';
|
|
1447
|
+
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
1448
|
+
const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
|
|
1380
1449
|
if (Elem && $.$mol_jsx_booked) {
|
|
1381
1450
|
if ($.$mol_jsx_booked.has(id)) {
|
|
1382
|
-
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(
|
|
1451
|
+
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
|
|
1383
1452
|
}
|
|
1384
1453
|
else {
|
|
1385
1454
|
$.$mol_jsx_booked.add(id);
|
|
1386
1455
|
}
|
|
1387
1456
|
}
|
|
1388
|
-
const guid = $.$mol_jsx_prefix + id;
|
|
1389
1457
|
let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
|
|
1458
|
+
if ($.$mol_jsx_prefix) {
|
|
1459
|
+
const prefix_ext = $.$mol_jsx_prefix;
|
|
1460
|
+
const booked_ext = $.$mol_jsx_booked;
|
|
1461
|
+
const crumbs_ext = $.$mol_jsx_crumbs;
|
|
1462
|
+
for (const field in props) {
|
|
1463
|
+
const func = props[field];
|
|
1464
|
+
if (typeof func !== 'function')
|
|
1465
|
+
continue;
|
|
1466
|
+
const wrapper = function (...args) {
|
|
1467
|
+
const prefix = $.$mol_jsx_prefix;
|
|
1468
|
+
const booked = $.$mol_jsx_booked;
|
|
1469
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
1470
|
+
try {
|
|
1471
|
+
$.$mol_jsx_prefix = prefix_ext;
|
|
1472
|
+
$.$mol_jsx_booked = booked_ext;
|
|
1473
|
+
$.$mol_jsx_crumbs = crumbs_ext;
|
|
1474
|
+
return func.call(this, ...args);
|
|
1475
|
+
}
|
|
1476
|
+
finally {
|
|
1477
|
+
$.$mol_jsx_prefix = prefix;
|
|
1478
|
+
$.$mol_jsx_booked = booked;
|
|
1479
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
$mol_func_name_from(wrapper, func);
|
|
1483
|
+
props[field] = wrapper;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1390
1486
|
if (typeof Elem !== 'string') {
|
|
1391
1487
|
if ('prototype' in Elem) {
|
|
1392
1488
|
const view = node && node[Elem] || new Elem;
|
|
@@ -1395,6 +1491,7 @@ var $;
|
|
|
1395
1491
|
view.childNodes = childNodes;
|
|
1396
1492
|
if (!view.ownerDocument)
|
|
1397
1493
|
view.ownerDocument = $.$mol_jsx_document;
|
|
1494
|
+
view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
1398
1495
|
node = view.valueOf();
|
|
1399
1496
|
node[Elem] = view;
|
|
1400
1497
|
return node;
|
|
@@ -1402,14 +1499,17 @@ var $;
|
|
|
1402
1499
|
else {
|
|
1403
1500
|
const prefix = $.$mol_jsx_prefix;
|
|
1404
1501
|
const booked = $.$mol_jsx_booked;
|
|
1502
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
1405
1503
|
try {
|
|
1406
1504
|
$.$mol_jsx_prefix = guid;
|
|
1407
1505
|
$.$mol_jsx_booked = new Set;
|
|
1506
|
+
$.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
1408
1507
|
return Elem(props, ...childNodes);
|
|
1409
1508
|
}
|
|
1410
1509
|
finally {
|
|
1411
1510
|
$.$mol_jsx_prefix = prefix;
|
|
1412
1511
|
$.$mol_jsx_booked = booked;
|
|
1512
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
1413
1513
|
}
|
|
1414
1514
|
}
|
|
1415
1515
|
}
|
|
@@ -1421,7 +1521,11 @@ var $;
|
|
|
1421
1521
|
$mol_dom_render_children(node, [].concat(...childNodes));
|
|
1422
1522
|
if (!Elem)
|
|
1423
1523
|
return node;
|
|
1524
|
+
if (guid)
|
|
1525
|
+
node.id = guid;
|
|
1424
1526
|
for (const key in props) {
|
|
1527
|
+
if (key === 'id')
|
|
1528
|
+
continue;
|
|
1425
1529
|
if (typeof props[key] === 'string') {
|
|
1426
1530
|
;
|
|
1427
1531
|
node.setAttribute(key, props[key]);
|
|
@@ -1438,8 +1542,8 @@ var $;
|
|
|
1438
1542
|
node[key] = props[key];
|
|
1439
1543
|
}
|
|
1440
1544
|
}
|
|
1441
|
-
if (
|
|
1442
|
-
node.
|
|
1545
|
+
if ($.$mol_jsx_crumbs)
|
|
1546
|
+
node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
|
|
1443
1547
|
return node;
|
|
1444
1548
|
}
|
|
1445
1549
|
$.$mol_jsx = $mol_jsx;
|