mol_compare_deep 0.0.57 → 0.0.60
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.deps.json +1 -1
- package/node.test.js +294 -294
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.deps.json +1 -1
- package/web.test.js +79 -79
- package/web.test.js.map +1 -1
package/node.deps.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"files":["LICENSE","README.md","lang.lang.tree","mam.jam.js","mam.ts","package.json","sandbox.config.json","tsconfig.json","tsfmt.json","yarn.lock","mol/CNAME","mol/CODE_OF_CONDUCT.md","mol/CONTRIBUTING.md","mol/LICENSE","mol/index.html","mol/mol.meta.tree","mol/readme.md","mol/compare/deep/README.md","mol/compare/deep/deep.ts"],"mods":{},"deps_in":{"mol/compare":{"mol/compare/deep":-9007199254740991},"mol":{"mol/compare":-9007199254740991},"":{"mol":-9007199254740991}},"deps_out":{"mol/compare/deep":{"mol/compare":-9007199254740991},"mol/compare":{"mol":-9007199254740991},"mol":{"":-9007199254740991}},"sloc":{"LICENSE":113,"md":
|
|
1
|
+
{"files":["LICENSE","README.md","lang.lang.tree","mam.jam.js","mam.ts","package.json","sandbox.config.json","tsconfig.json","tsfmt.json","yarn.lock","mol/CNAME","mol/CODE_OF_CONDUCT.md","mol/CONTRIBUTING.md","mol/LICENSE","mol/index.html","mol/mol.meta.tree","mol/readme.md","mol/compare/deep/README.md","mol/compare/deep/deep.ts"],"mods":{},"deps_in":{"mol/compare":{"mol/compare/deep":-9007199254740991},"mol":{"mol/compare":-9007199254740991},"":{"mol":-9007199254740991}},"deps_out":{"mol/compare/deep":{"mol/compare":-9007199254740991},"mol/compare":{"mol":-9007199254740991},"mol":{"":-9007199254740991}},"sloc":{"LICENSE":113,"md":529,"tree":31,"js":10,"ts":109,"json":87,"lock":939,"CNAME":1,"html":1},"deps":{"mol/compare/deep":{"..":-9007199254740991,"/mol/compare/deep/cache":-1,"/mol/compare/deep":-1,"/mol/compare/deep/cache/get":-2,"/mol/compare/deep/cache/set":-3},"mol/compare":{"..":-9007199254740991},"mol":{"..":-9007199254740991},"":{}}}
|
package/node.test.js
CHANGED
|
@@ -524,253 +524,16 @@ var $;
|
|
|
524
524
|
//mol/type/assert/assert.ts
|
|
525
525
|
;
|
|
526
526
|
"use strict";
|
|
527
|
-
//mol/type/
|
|
528
|
-
;
|
|
529
|
-
"use strict";
|
|
530
|
-
//mol/type/partial/deep/deep.ts
|
|
527
|
+
//mol/type/equals/equals.test.ts
|
|
531
528
|
;
|
|
532
529
|
"use strict";
|
|
533
|
-
|
|
534
|
-
(function ($) {
|
|
535
|
-
$mol_test({
|
|
536
|
-
'Make empty div'() {
|
|
537
|
-
$mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
|
|
538
|
-
},
|
|
539
|
-
'Define native field'() {
|
|
540
|
-
const dom = $mol_jsx("input", { value: '123' });
|
|
541
|
-
$mol_assert_equal(dom.outerHTML, '<input value="123">');
|
|
542
|
-
$mol_assert_equal(dom.value, '123');
|
|
543
|
-
},
|
|
544
|
-
'Define classes'() {
|
|
545
|
-
const dom = $mol_jsx("div", { class: 'foo bar' });
|
|
546
|
-
$mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
|
|
547
|
-
},
|
|
548
|
-
'Define styles'() {
|
|
549
|
-
const dom = $mol_jsx("div", { style: { color: 'red' } });
|
|
550
|
-
$mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
|
|
551
|
-
},
|
|
552
|
-
'Define dataset'() {
|
|
553
|
-
const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
|
|
554
|
-
$mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
|
|
555
|
-
},
|
|
556
|
-
'Define attributes'() {
|
|
557
|
-
const dom = $mol_jsx("div", { lang: "ru", hidden: true });
|
|
558
|
-
$mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
|
|
559
|
-
},
|
|
560
|
-
'Define child nodes'() {
|
|
561
|
-
const dom = $mol_jsx("div", null,
|
|
562
|
-
"hello",
|
|
563
|
-
$mol_jsx("strong", null, "world"),
|
|
564
|
-
"!");
|
|
565
|
-
$mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
|
|
566
|
-
},
|
|
567
|
-
'Function as component'() {
|
|
568
|
-
const Button = ({ hint }, target) => {
|
|
569
|
-
return $mol_jsx("button", { title: hint }, target());
|
|
570
|
-
};
|
|
571
|
-
const dom = $mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
|
|
572
|
-
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
|
|
573
|
-
},
|
|
574
|
-
'Nested guid generation'() {
|
|
575
|
-
const Foo = () => {
|
|
576
|
-
return $mol_jsx("div", null,
|
|
577
|
-
$mol_jsx(Bar, { id: "/bar" },
|
|
578
|
-
$mol_jsx("img", { id: "/icon" })));
|
|
579
|
-
};
|
|
580
|
-
const Bar = (props, icon) => {
|
|
581
|
-
return $mol_jsx("span", null, icon);
|
|
582
|
-
};
|
|
583
|
-
const dom = $mol_jsx(Foo, { id: "/foo" });
|
|
584
|
-
$mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
|
|
585
|
-
},
|
|
586
|
-
'Fail on non unique ids'() {
|
|
587
|
-
const App = () => {
|
|
588
|
-
return $mol_jsx("div", null,
|
|
589
|
-
$mol_jsx("span", { id: "/bar" }),
|
|
590
|
-
$mol_jsx("span", { id: "/bar" }));
|
|
591
|
-
};
|
|
592
|
-
$mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
|
|
593
|
-
},
|
|
594
|
-
});
|
|
595
|
-
})($ || ($ = {}));
|
|
596
|
-
//mol/jsx/jsx.test.tsx
|
|
530
|
+
//mol/type/equals/equals.ts
|
|
597
531
|
;
|
|
598
532
|
"use strict";
|
|
599
|
-
|
|
600
|
-
(function ($) {
|
|
601
|
-
$.$mol_jsx_prefix = '';
|
|
602
|
-
$.$mol_jsx_booked = null;
|
|
603
|
-
$.$mol_jsx_document = {
|
|
604
|
-
getElementById: () => null,
|
|
605
|
-
createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
|
|
606
|
-
createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
|
|
607
|
-
};
|
|
608
|
-
$.$mol_jsx_frag = '';
|
|
609
|
-
function $mol_jsx(Elem, props, ...childNodes) {
|
|
610
|
-
const id = props && props.id || '';
|
|
611
|
-
if (Elem && $.$mol_jsx_booked) {
|
|
612
|
-
if ($.$mol_jsx_booked.has(id)) {
|
|
613
|
-
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
|
|
614
|
-
}
|
|
615
|
-
else {
|
|
616
|
-
$.$mol_jsx_booked.add(id);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
const guid = $.$mol_jsx_prefix + id;
|
|
620
|
-
let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
|
|
621
|
-
if (typeof Elem !== 'string') {
|
|
622
|
-
if ('prototype' in Elem) {
|
|
623
|
-
const view = node && node[Elem] || new Elem;
|
|
624
|
-
Object.assign(view, props);
|
|
625
|
-
view[Symbol.toStringTag] = guid;
|
|
626
|
-
view.childNodes = childNodes;
|
|
627
|
-
if (!view.ownerDocument)
|
|
628
|
-
view.ownerDocument = $.$mol_jsx_document;
|
|
629
|
-
node = view.valueOf();
|
|
630
|
-
node[Elem] = view;
|
|
631
|
-
return node;
|
|
632
|
-
}
|
|
633
|
-
else {
|
|
634
|
-
const prefix = $.$mol_jsx_prefix;
|
|
635
|
-
const booked = $.$mol_jsx_booked;
|
|
636
|
-
try {
|
|
637
|
-
$.$mol_jsx_prefix = guid;
|
|
638
|
-
$.$mol_jsx_booked = new Set;
|
|
639
|
-
return Elem(props, ...childNodes);
|
|
640
|
-
}
|
|
641
|
-
finally {
|
|
642
|
-
$.$mol_jsx_prefix = prefix;
|
|
643
|
-
$.$mol_jsx_booked = booked;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
if (!node) {
|
|
648
|
-
node = Elem
|
|
649
|
-
? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
|
|
650
|
-
: $.$mol_jsx_document.createDocumentFragment();
|
|
651
|
-
}
|
|
652
|
-
$mol_dom_render_children(node, [].concat(...childNodes));
|
|
653
|
-
if (!Elem)
|
|
654
|
-
return node;
|
|
655
|
-
for (const key in props) {
|
|
656
|
-
if (typeof props[key] === 'string') {
|
|
657
|
-
;
|
|
658
|
-
node.setAttribute(key, props[key]);
|
|
659
|
-
}
|
|
660
|
-
else if (props[key] &&
|
|
661
|
-
typeof props[key] === 'object' &&
|
|
662
|
-
Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
|
|
663
|
-
if (typeof node[key] === 'object') {
|
|
664
|
-
Object.assign(node[key], props[key]);
|
|
665
|
-
continue;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
else {
|
|
669
|
-
node[key] = props[key];
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
if (guid)
|
|
673
|
-
node.id = guid;
|
|
674
|
-
return node;
|
|
675
|
-
}
|
|
676
|
-
$.$mol_jsx = $mol_jsx;
|
|
677
|
-
})($ || ($ = {}));
|
|
678
|
-
//mol/jsx/jsx.ts
|
|
533
|
+
//mol/type/partial/deep/deep.test.ts
|
|
679
534
|
;
|
|
680
535
|
"use strict";
|
|
681
|
-
|
|
682
|
-
(function ($) {
|
|
683
|
-
$mol_test({
|
|
684
|
-
'nulls & undefineds'() {
|
|
685
|
-
$mol_assert_ok($mol_compare_deep(null, null));
|
|
686
|
-
$mol_assert_ok($mol_compare_deep(undefined, undefined));
|
|
687
|
-
$mol_assert_not($mol_compare_deep(undefined, null));
|
|
688
|
-
$mol_assert_not($mol_compare_deep({}, null));
|
|
689
|
-
},
|
|
690
|
-
'number'() {
|
|
691
|
-
$mol_assert_ok($mol_compare_deep(1, 1));
|
|
692
|
-
$mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
|
|
693
|
-
$mol_assert_not($mol_compare_deep(1, 2));
|
|
694
|
-
$mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
|
|
695
|
-
$mol_assert_not($mol_compare_deep(Object(1), Object(2)));
|
|
696
|
-
},
|
|
697
|
-
'POJO'() {
|
|
698
|
-
$mol_assert_ok($mol_compare_deep({}, {}));
|
|
699
|
-
$mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
|
|
700
|
-
$mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
|
|
701
|
-
$mol_assert_not($mol_compare_deep({}, { a: undefined }));
|
|
702
|
-
$mol_assert_ok($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
|
|
703
|
-
$mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
|
|
704
|
-
},
|
|
705
|
-
'Array'() {
|
|
706
|
-
$mol_assert_ok($mol_compare_deep([], []));
|
|
707
|
-
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
|
|
708
|
-
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
|
|
709
|
-
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
|
|
710
|
-
},
|
|
711
|
-
'Non POJO are different'() {
|
|
712
|
-
class Thing extends Object {
|
|
713
|
-
}
|
|
714
|
-
$mol_assert_not($mol_compare_deep(new Thing, new Thing));
|
|
715
|
-
$mol_assert_not($mol_compare_deep(() => 1, () => 1));
|
|
716
|
-
$mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
|
|
717
|
-
},
|
|
718
|
-
'same POJOs with cyclic reference'() {
|
|
719
|
-
const a = { foo: {} };
|
|
720
|
-
a['self'] = a;
|
|
721
|
-
const b = { foo: {} };
|
|
722
|
-
b['self'] = b;
|
|
723
|
-
$mol_assert_ok($mol_compare_deep(a, b));
|
|
724
|
-
},
|
|
725
|
-
'Date'() {
|
|
726
|
-
$mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
|
|
727
|
-
$mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
|
|
728
|
-
},
|
|
729
|
-
'RegExp'() {
|
|
730
|
-
$mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
|
|
731
|
-
$mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
|
|
732
|
-
$mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
|
|
733
|
-
},
|
|
734
|
-
'Error'() {
|
|
735
|
-
$mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
|
|
736
|
-
const fail = (message) => new Error(message);
|
|
737
|
-
$mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
|
|
738
|
-
$mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
|
|
739
|
-
},
|
|
740
|
-
'Map'() {
|
|
741
|
-
$mol_assert_ok($mol_compare_deep(new Map, new Map));
|
|
742
|
-
$mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
|
|
743
|
-
$mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
|
|
744
|
-
$mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
|
|
745
|
-
},
|
|
746
|
-
'Set'() {
|
|
747
|
-
$mol_assert_ok($mol_compare_deep(new Set, new Set));
|
|
748
|
-
$mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
|
|
749
|
-
$mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
|
|
750
|
-
},
|
|
751
|
-
'Uint8Array'() {
|
|
752
|
-
$mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
|
|
753
|
-
$mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
|
|
754
|
-
$mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
|
|
755
|
-
},
|
|
756
|
-
'Custom comparator'() {
|
|
757
|
-
class User {
|
|
758
|
-
name;
|
|
759
|
-
rand;
|
|
760
|
-
constructor(name, rand = Math.random()) {
|
|
761
|
-
this.name = name;
|
|
762
|
-
this.rand = rand;
|
|
763
|
-
}
|
|
764
|
-
[Symbol.toPrimitive](mode) {
|
|
765
|
-
return this.name;
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
$mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
|
|
769
|
-
$mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
|
|
770
|
-
},
|
|
771
|
-
});
|
|
772
|
-
})($ || ($ = {}));
|
|
773
|
-
//mol/compare/deep/deep.test.tsx
|
|
536
|
+
//mol/type/partial/deep/deep.ts
|
|
774
537
|
;
|
|
775
538
|
"use strict";
|
|
776
539
|
var $;
|
|
@@ -841,59 +604,13 @@ var $;
|
|
|
841
604
|
"use strict";
|
|
842
605
|
var $;
|
|
843
606
|
(function ($) {
|
|
844
|
-
|
|
845
|
-
|
|
607
|
+
$.$mol_ambient_ref = Symbol('$mol_ambient_ref');
|
|
608
|
+
function $mol_ambient(overrides) {
|
|
609
|
+
return Object.setPrototypeOf(overrides, this || $);
|
|
846
610
|
}
|
|
847
|
-
$.$
|
|
611
|
+
$.$mol_ambient = $mol_ambient;
|
|
848
612
|
})($ || ($ = {}));
|
|
849
|
-
//mol/
|
|
850
|
-
;
|
|
851
|
-
"use strict";
|
|
852
|
-
var $;
|
|
853
|
-
(function ($) {
|
|
854
|
-
$.$mol_env = function $mol_env() {
|
|
855
|
-
return this.process.env;
|
|
856
|
-
};
|
|
857
|
-
})($ || ($ = {}));
|
|
858
|
-
//mol/env/env.node.ts
|
|
859
|
-
;
|
|
860
|
-
"use strict";
|
|
861
|
-
var $;
|
|
862
|
-
(function ($) {
|
|
863
|
-
function $mol_exec(dir, command, ...args) {
|
|
864
|
-
let [app, ...args0] = command.split(' ');
|
|
865
|
-
args = [...args0, ...args];
|
|
866
|
-
this.$mol_log3_come({
|
|
867
|
-
place: '$mol_exec',
|
|
868
|
-
dir: $node.path.relative('', dir),
|
|
869
|
-
message: 'Run',
|
|
870
|
-
command: `${app} ${args.join(' ')}`,
|
|
871
|
-
});
|
|
872
|
-
var res = $node['child_process'].spawnSync(app, args, {
|
|
873
|
-
cwd: $node.path.resolve(dir),
|
|
874
|
-
shell: true,
|
|
875
|
-
env: this.$mol_env(),
|
|
876
|
-
});
|
|
877
|
-
if (res.status || res.error)
|
|
878
|
-
return $mol_fail(res.error || new Error(res.stderr.toString()));
|
|
879
|
-
if (!res.stdout)
|
|
880
|
-
res.stdout = Buffer.from([]);
|
|
881
|
-
return res;
|
|
882
|
-
}
|
|
883
|
-
$.$mol_exec = $mol_exec;
|
|
884
|
-
})($ || ($ = {}));
|
|
885
|
-
//mol/exec/exec.node.ts
|
|
886
|
-
;
|
|
887
|
-
"use strict";
|
|
888
|
-
var $;
|
|
889
|
-
(function ($) {
|
|
890
|
-
$.$mol_ambient_ref = Symbol('$mol_ambient_ref');
|
|
891
|
-
function $mol_ambient(overrides) {
|
|
892
|
-
return Object.setPrototypeOf(overrides, this || $);
|
|
893
|
-
}
|
|
894
|
-
$.$mol_ambient = $mol_ambient;
|
|
895
|
-
})($ || ($ = {}));
|
|
896
|
-
//mol/ambient/ambient.ts
|
|
613
|
+
//mol/ambient/ambient.ts
|
|
897
614
|
;
|
|
898
615
|
"use strict";
|
|
899
616
|
var $;
|
|
@@ -1518,9 +1235,292 @@ var $;
|
|
|
1518
1235
|
//mol/tree/tree.ts
|
|
1519
1236
|
;
|
|
1520
1237
|
"use strict";
|
|
1521
|
-
|
|
1238
|
+
var $;
|
|
1239
|
+
(function ($) {
|
|
1240
|
+
function $mol_env() {
|
|
1241
|
+
return {};
|
|
1242
|
+
}
|
|
1243
|
+
$.$mol_env = $mol_env;
|
|
1244
|
+
})($ || ($ = {}));
|
|
1245
|
+
//mol/env/env.ts
|
|
1522
1246
|
;
|
|
1523
1247
|
"use strict";
|
|
1524
|
-
|
|
1248
|
+
var $;
|
|
1249
|
+
(function ($) {
|
|
1250
|
+
$.$mol_env = function $mol_env() {
|
|
1251
|
+
return this.process.env;
|
|
1252
|
+
};
|
|
1253
|
+
})($ || ($ = {}));
|
|
1254
|
+
//mol/env/env.node.ts
|
|
1255
|
+
;
|
|
1256
|
+
"use strict";
|
|
1257
|
+
var $;
|
|
1258
|
+
(function ($) {
|
|
1259
|
+
function $mol_exec(dir, command, ...args) {
|
|
1260
|
+
let [app, ...args0] = command.split(' ');
|
|
1261
|
+
args = [...args0, ...args];
|
|
1262
|
+
this.$mol_log3_come({
|
|
1263
|
+
place: '$mol_exec',
|
|
1264
|
+
dir: $node.path.relative('', dir),
|
|
1265
|
+
message: 'Run',
|
|
1266
|
+
command: `${app} ${args.join(' ')}`,
|
|
1267
|
+
});
|
|
1268
|
+
var res = $node['child_process'].spawnSync(app, args, {
|
|
1269
|
+
cwd: $node.path.resolve(dir),
|
|
1270
|
+
shell: true,
|
|
1271
|
+
env: this.$mol_env(),
|
|
1272
|
+
});
|
|
1273
|
+
if (res.status || res.error)
|
|
1274
|
+
return $mol_fail(res.error || new Error(res.stderr.toString()));
|
|
1275
|
+
if (!res.stdout)
|
|
1276
|
+
res.stdout = Buffer.from([]);
|
|
1277
|
+
return res;
|
|
1278
|
+
}
|
|
1279
|
+
$.$mol_exec = $mol_exec;
|
|
1280
|
+
})($ || ($ = {}));
|
|
1281
|
+
//mol/exec/exec.node.ts
|
|
1282
|
+
;
|
|
1283
|
+
"use strict";
|
|
1284
|
+
var $;
|
|
1285
|
+
(function ($) {
|
|
1286
|
+
$mol_test({
|
|
1287
|
+
'Make empty div'() {
|
|
1288
|
+
$mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
|
|
1289
|
+
},
|
|
1290
|
+
'Define native field'() {
|
|
1291
|
+
const dom = $mol_jsx("input", { value: '123' });
|
|
1292
|
+
$mol_assert_equal(dom.outerHTML, '<input value="123">');
|
|
1293
|
+
$mol_assert_equal(dom.value, '123');
|
|
1294
|
+
},
|
|
1295
|
+
'Define classes'() {
|
|
1296
|
+
const dom = $mol_jsx("div", { class: 'foo bar' });
|
|
1297
|
+
$mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
|
|
1298
|
+
},
|
|
1299
|
+
'Define styles'() {
|
|
1300
|
+
const dom = $mol_jsx("div", { style: { color: 'red' } });
|
|
1301
|
+
$mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
|
|
1302
|
+
},
|
|
1303
|
+
'Define dataset'() {
|
|
1304
|
+
const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
|
|
1305
|
+
$mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
|
|
1306
|
+
},
|
|
1307
|
+
'Define attributes'() {
|
|
1308
|
+
const dom = $mol_jsx("div", { lang: "ru", hidden: true });
|
|
1309
|
+
$mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
|
|
1310
|
+
},
|
|
1311
|
+
'Define child nodes'() {
|
|
1312
|
+
const dom = $mol_jsx("div", null,
|
|
1313
|
+
"hello",
|
|
1314
|
+
$mol_jsx("strong", null, "world"),
|
|
1315
|
+
"!");
|
|
1316
|
+
$mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
|
|
1317
|
+
},
|
|
1318
|
+
'Function as component'() {
|
|
1319
|
+
const Button = ({ hint }, target) => {
|
|
1320
|
+
return $mol_jsx("button", { title: hint }, target());
|
|
1321
|
+
};
|
|
1322
|
+
const dom = $mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
|
|
1323
|
+
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
|
|
1324
|
+
},
|
|
1325
|
+
'Nested guid generation'() {
|
|
1326
|
+
const Foo = () => {
|
|
1327
|
+
return $mol_jsx("div", null,
|
|
1328
|
+
$mol_jsx(Bar, { id: "/bar" },
|
|
1329
|
+
$mol_jsx("img", { id: "/icon" })));
|
|
1330
|
+
};
|
|
1331
|
+
const Bar = (props, icon) => {
|
|
1332
|
+
return $mol_jsx("span", null, icon);
|
|
1333
|
+
};
|
|
1334
|
+
const dom = $mol_jsx(Foo, { id: "/foo" });
|
|
1335
|
+
$mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
|
|
1336
|
+
},
|
|
1337
|
+
'Fail on non unique ids'() {
|
|
1338
|
+
const App = () => {
|
|
1339
|
+
return $mol_jsx("div", null,
|
|
1340
|
+
$mol_jsx("span", { id: "/bar" }),
|
|
1341
|
+
$mol_jsx("span", { id: "/bar" }));
|
|
1342
|
+
};
|
|
1343
|
+
$mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
|
|
1344
|
+
},
|
|
1345
|
+
});
|
|
1346
|
+
})($ || ($ = {}));
|
|
1347
|
+
//mol/jsx/jsx.test.tsx
|
|
1348
|
+
;
|
|
1349
|
+
"use strict";
|
|
1350
|
+
var $;
|
|
1351
|
+
(function ($) {
|
|
1352
|
+
$.$mol_jsx_prefix = '';
|
|
1353
|
+
$.$mol_jsx_booked = null;
|
|
1354
|
+
$.$mol_jsx_document = {
|
|
1355
|
+
getElementById: () => null,
|
|
1356
|
+
createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
|
|
1357
|
+
createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
|
|
1358
|
+
};
|
|
1359
|
+
$.$mol_jsx_frag = '';
|
|
1360
|
+
function $mol_jsx(Elem, props, ...childNodes) {
|
|
1361
|
+
const id = props && props.id || '';
|
|
1362
|
+
if (Elem && $.$mol_jsx_booked) {
|
|
1363
|
+
if ($.$mol_jsx_booked.has(id)) {
|
|
1364
|
+
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
|
|
1365
|
+
}
|
|
1366
|
+
else {
|
|
1367
|
+
$.$mol_jsx_booked.add(id);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
const guid = $.$mol_jsx_prefix + id;
|
|
1371
|
+
let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
|
|
1372
|
+
if (typeof Elem !== 'string') {
|
|
1373
|
+
if ('prototype' in Elem) {
|
|
1374
|
+
const view = node && node[Elem] || new Elem;
|
|
1375
|
+
Object.assign(view, props);
|
|
1376
|
+
view[Symbol.toStringTag] = guid;
|
|
1377
|
+
view.childNodes = childNodes;
|
|
1378
|
+
if (!view.ownerDocument)
|
|
1379
|
+
view.ownerDocument = $.$mol_jsx_document;
|
|
1380
|
+
node = view.valueOf();
|
|
1381
|
+
node[Elem] = view;
|
|
1382
|
+
return node;
|
|
1383
|
+
}
|
|
1384
|
+
else {
|
|
1385
|
+
const prefix = $.$mol_jsx_prefix;
|
|
1386
|
+
const booked = $.$mol_jsx_booked;
|
|
1387
|
+
try {
|
|
1388
|
+
$.$mol_jsx_prefix = guid;
|
|
1389
|
+
$.$mol_jsx_booked = new Set;
|
|
1390
|
+
return Elem(props, ...childNodes);
|
|
1391
|
+
}
|
|
1392
|
+
finally {
|
|
1393
|
+
$.$mol_jsx_prefix = prefix;
|
|
1394
|
+
$.$mol_jsx_booked = booked;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
if (!node) {
|
|
1399
|
+
node = Elem
|
|
1400
|
+
? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
|
|
1401
|
+
: $.$mol_jsx_document.createDocumentFragment();
|
|
1402
|
+
}
|
|
1403
|
+
$mol_dom_render_children(node, [].concat(...childNodes));
|
|
1404
|
+
if (!Elem)
|
|
1405
|
+
return node;
|
|
1406
|
+
for (const key in props) {
|
|
1407
|
+
if (typeof props[key] === 'string') {
|
|
1408
|
+
;
|
|
1409
|
+
node.setAttribute(key, props[key]);
|
|
1410
|
+
}
|
|
1411
|
+
else if (props[key] &&
|
|
1412
|
+
typeof props[key] === 'object' &&
|
|
1413
|
+
Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
|
|
1414
|
+
if (typeof node[key] === 'object') {
|
|
1415
|
+
Object.assign(node[key], props[key]);
|
|
1416
|
+
continue;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
else {
|
|
1420
|
+
node[key] = props[key];
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
if (guid)
|
|
1424
|
+
node.id = guid;
|
|
1425
|
+
return node;
|
|
1426
|
+
}
|
|
1427
|
+
$.$mol_jsx = $mol_jsx;
|
|
1428
|
+
})($ || ($ = {}));
|
|
1429
|
+
//mol/jsx/jsx.ts
|
|
1430
|
+
;
|
|
1431
|
+
"use strict";
|
|
1432
|
+
var $;
|
|
1433
|
+
(function ($) {
|
|
1434
|
+
$mol_test({
|
|
1435
|
+
'nulls & undefineds'() {
|
|
1436
|
+
$mol_assert_ok($mol_compare_deep(null, null));
|
|
1437
|
+
$mol_assert_ok($mol_compare_deep(undefined, undefined));
|
|
1438
|
+
$mol_assert_not($mol_compare_deep(undefined, null));
|
|
1439
|
+
$mol_assert_not($mol_compare_deep({}, null));
|
|
1440
|
+
},
|
|
1441
|
+
'number'() {
|
|
1442
|
+
$mol_assert_ok($mol_compare_deep(1, 1));
|
|
1443
|
+
$mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
|
|
1444
|
+
$mol_assert_not($mol_compare_deep(1, 2));
|
|
1445
|
+
$mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
|
|
1446
|
+
$mol_assert_not($mol_compare_deep(Object(1), Object(2)));
|
|
1447
|
+
},
|
|
1448
|
+
'POJO'() {
|
|
1449
|
+
$mol_assert_ok($mol_compare_deep({}, {}));
|
|
1450
|
+
$mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
|
|
1451
|
+
$mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
|
|
1452
|
+
$mol_assert_not($mol_compare_deep({}, { a: undefined }));
|
|
1453
|
+
$mol_assert_ok($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
|
|
1454
|
+
$mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
|
|
1455
|
+
},
|
|
1456
|
+
'Array'() {
|
|
1457
|
+
$mol_assert_ok($mol_compare_deep([], []));
|
|
1458
|
+
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
|
|
1459
|
+
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
|
|
1460
|
+
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
|
|
1461
|
+
},
|
|
1462
|
+
'Non POJO are different'() {
|
|
1463
|
+
class Thing extends Object {
|
|
1464
|
+
}
|
|
1465
|
+
$mol_assert_not($mol_compare_deep(new Thing, new Thing));
|
|
1466
|
+
$mol_assert_not($mol_compare_deep(() => 1, () => 1));
|
|
1467
|
+
$mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
|
|
1468
|
+
},
|
|
1469
|
+
'same POJOs with cyclic reference'() {
|
|
1470
|
+
const a = { foo: {} };
|
|
1471
|
+
a['self'] = a;
|
|
1472
|
+
const b = { foo: {} };
|
|
1473
|
+
b['self'] = b;
|
|
1474
|
+
$mol_assert_ok($mol_compare_deep(a, b));
|
|
1475
|
+
},
|
|
1476
|
+
'Date'() {
|
|
1477
|
+
$mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
|
|
1478
|
+
$mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
|
|
1479
|
+
},
|
|
1480
|
+
'RegExp'() {
|
|
1481
|
+
$mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
|
|
1482
|
+
$mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
|
|
1483
|
+
$mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
|
|
1484
|
+
},
|
|
1485
|
+
'Error'() {
|
|
1486
|
+
$mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
|
|
1487
|
+
const fail = (message) => new Error(message);
|
|
1488
|
+
$mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
|
|
1489
|
+
$mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
|
|
1490
|
+
},
|
|
1491
|
+
'Map'() {
|
|
1492
|
+
$mol_assert_ok($mol_compare_deep(new Map, new Map));
|
|
1493
|
+
$mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
|
|
1494
|
+
$mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
|
|
1495
|
+
$mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
|
|
1496
|
+
},
|
|
1497
|
+
'Set'() {
|
|
1498
|
+
$mol_assert_ok($mol_compare_deep(new Set, new Set));
|
|
1499
|
+
$mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
|
|
1500
|
+
$mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
|
|
1501
|
+
},
|
|
1502
|
+
'Uint8Array'() {
|
|
1503
|
+
$mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
|
|
1504
|
+
$mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
|
|
1505
|
+
$mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
|
|
1506
|
+
},
|
|
1507
|
+
'Custom comparator'() {
|
|
1508
|
+
class User {
|
|
1509
|
+
name;
|
|
1510
|
+
rand;
|
|
1511
|
+
constructor(name, rand = Math.random()) {
|
|
1512
|
+
this.name = name;
|
|
1513
|
+
this.rand = rand;
|
|
1514
|
+
}
|
|
1515
|
+
[Symbol.toPrimitive](mode) {
|
|
1516
|
+
return this.name;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
$mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
|
|
1520
|
+
$mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
|
|
1521
|
+
},
|
|
1522
|
+
});
|
|
1523
|
+
})($ || ($ = {}));
|
|
1524
|
+
//mol/compare/deep/deep.test.tsx
|
|
1525
1525
|
|
|
1526
1526
|
//# sourceMappingURL=node.test.js.map
|