mol_jsx_lib 0.0.56 → 0.0.57
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.d.ts +5 -0
- package/node.deps.json +1 -1
- package/node.esm.js +54 -2
- package/node.esm.js.map +1 -1
- package/node.js +54 -2
- package/node.js.map +1 -1
- package/node.test.js +91 -3
- package/node.test.js.map +1 -1
- package/package.json +3 -1
- package/web.d.ts +5 -0
- package/web.deps.json +1 -1
- package/web.esm.js +54 -2
- package/web.esm.js.map +1 -1
- package/web.js +54 -2
- package/web.js.map +1 -1
- package/web.test.js +37 -1
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
|
@@ -721,6 +721,34 @@ var $;
|
|
|
721
721
|
;
|
|
722
722
|
"use strict";
|
|
723
723
|
var $;
|
|
724
|
+
(function ($) {
|
|
725
|
+
function $mol_func_name(func) {
|
|
726
|
+
let name = func.name;
|
|
727
|
+
if (name?.length > 1)
|
|
728
|
+
return name;
|
|
729
|
+
for (let key in this) {
|
|
730
|
+
try {
|
|
731
|
+
if (this[key] !== func)
|
|
732
|
+
continue;
|
|
733
|
+
name = key;
|
|
734
|
+
Object.defineProperty(func, 'name', { value: name });
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
737
|
+
catch { }
|
|
738
|
+
}
|
|
739
|
+
return name;
|
|
740
|
+
}
|
|
741
|
+
$.$mol_func_name = $mol_func_name;
|
|
742
|
+
function $mol_func_name_from(target, source) {
|
|
743
|
+
Object.defineProperty(target, 'name', { value: source.name });
|
|
744
|
+
return target;
|
|
745
|
+
}
|
|
746
|
+
$.$mol_func_name_from = $mol_func_name_from;
|
|
747
|
+
})($ || ($ = {}));
|
|
748
|
+
//mol/func/name/name.ts
|
|
749
|
+
;
|
|
750
|
+
"use strict";
|
|
751
|
+
var $;
|
|
724
752
|
(function ($) {
|
|
725
753
|
function $mol_dom_render_children(el, childNodes) {
|
|
726
754
|
const node_set = new Set(childNodes);
|
|
@@ -790,16 +818,40 @@ var $;
|
|
|
790
818
|
$.$mol_jsx_frag = '';
|
|
791
819
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
792
820
|
const id = props && props.id || '';
|
|
821
|
+
const guid = $.$mol_jsx_prefix + id;
|
|
793
822
|
if (Elem && $.$mol_jsx_booked) {
|
|
794
823
|
if ($.$mol_jsx_booked.has(id)) {
|
|
795
|
-
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(
|
|
824
|
+
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
|
|
796
825
|
}
|
|
797
826
|
else {
|
|
798
827
|
$.$mol_jsx_booked.add(id);
|
|
799
828
|
}
|
|
800
829
|
}
|
|
801
|
-
const guid = $.$mol_jsx_prefix + id;
|
|
802
830
|
let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
|
|
831
|
+
if ($.$mol_jsx_prefix) {
|
|
832
|
+
const prefix_ext = $.$mol_jsx_prefix;
|
|
833
|
+
const booked_ext = $.$mol_jsx_booked;
|
|
834
|
+
for (const field in props) {
|
|
835
|
+
const func = props[field];
|
|
836
|
+
if (typeof func !== 'function')
|
|
837
|
+
continue;
|
|
838
|
+
const wrapper = function (...args) {
|
|
839
|
+
const prefix = $.$mol_jsx_prefix;
|
|
840
|
+
const booked = $.$mol_jsx_booked;
|
|
841
|
+
try {
|
|
842
|
+
$.$mol_jsx_prefix = prefix_ext;
|
|
843
|
+
$.$mol_jsx_booked = booked_ext;
|
|
844
|
+
return func.call(this, ...args);
|
|
845
|
+
}
|
|
846
|
+
finally {
|
|
847
|
+
$.$mol_jsx_prefix = prefix;
|
|
848
|
+
$.$mol_jsx_booked = booked;
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
$mol_func_name_from(wrapper, func);
|
|
852
|
+
props[field] = wrapper;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
803
855
|
if (typeof Elem !== 'string') {
|
|
804
856
|
if ('prototype' in Elem) {
|
|
805
857
|
const view = node && node[Elem] || new Elem;
|
|
@@ -2560,6 +2612,20 @@ var $;
|
|
|
2560
2612
|
//mol/assert/assert.ts
|
|
2561
2613
|
;
|
|
2562
2614
|
"use strict";
|
|
2615
|
+
var $;
|
|
2616
|
+
(function ($_1) {
|
|
2617
|
+
$mol_test({
|
|
2618
|
+
'FQN of anon function'($) {
|
|
2619
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
|
2620
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
|
2621
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
|
2622
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
|
2623
|
+
},
|
|
2624
|
+
});
|
|
2625
|
+
})($ || ($ = {}));
|
|
2626
|
+
//mol/func/name/name.test.ts
|
|
2627
|
+
;
|
|
2628
|
+
"use strict";
|
|
2563
2629
|
//mol/type/error/error.ts
|
|
2564
2630
|
;
|
|
2565
2631
|
"use strict";
|
|
@@ -2763,7 +2829,29 @@ var $;
|
|
|
2763
2829
|
$mol_jsx("span", { id: "/bar" }),
|
|
2764
2830
|
$mol_jsx("span", { id: "/bar" }));
|
|
2765
2831
|
};
|
|
2766
|
-
$mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
|
|
2832
|
+
$mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/foo/bar"');
|
|
2833
|
+
},
|
|
2834
|
+
'Owner based guid generationn'() {
|
|
2835
|
+
const Foo = () => {
|
|
2836
|
+
return $mol_jsx("div", null,
|
|
2837
|
+
$mol_jsx(Bar, { id: "/bar", icon: () => $mol_jsx("img", { id: "/icon" }) }));
|
|
2838
|
+
};
|
|
2839
|
+
const Bar = (props) => {
|
|
2840
|
+
return $mol_jsx("span", null, props.icon());
|
|
2841
|
+
};
|
|
2842
|
+
const dom = $mol_jsx(Foo, { id: "/foo" });
|
|
2843
|
+
$mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
|
|
2844
|
+
},
|
|
2845
|
+
'Fail on same ids from different caller'() {
|
|
2846
|
+
const Foo = () => {
|
|
2847
|
+
return $mol_jsx("div", null,
|
|
2848
|
+
$mol_jsx("img", { id: "/icon" }),
|
|
2849
|
+
$mol_jsx(Bar, { id: "/bar", icon: () => $mol_jsx("img", { id: "/icon" }) }));
|
|
2850
|
+
};
|
|
2851
|
+
const Bar = (props) => {
|
|
2852
|
+
return $mol_jsx("span", null, props.icon());
|
|
2853
|
+
};
|
|
2854
|
+
$mol_assert_fail(() => $mol_jsx(Foo, { id: "/foo" }), 'JSX already has tag with id "/foo/icon"');
|
|
2767
2855
|
},
|
|
2768
2856
|
});
|
|
2769
2857
|
})($ || ($ = {}));
|