mol_regexp 0.0.406 → 0.0.409

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 CHANGED
@@ -744,28 +744,52 @@ var $;
744
744
  const Button = (props, target) => {
745
745
  return $mol_jsx("button", { title: props.hint }, target());
746
746
  };
747
- const dom = $mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
748
- $mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
747
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
748
+ $mol_assert_equal(dom.outerHTML, '<button title="click me" id="foo" class="Button">hey!</button>');
749
749
  },
750
750
  'Nested guid generation'() {
751
751
  const Foo = () => {
752
752
  return $mol_jsx("div", null,
753
- $mol_jsx(Bar, { id: "/bar" },
754
- $mol_jsx("img", { id: "/icon" })));
753
+ $mol_jsx(Bar, { id: "bar" },
754
+ $mol_jsx("img", { id: "icon" })));
755
755
  };
756
756
  const Bar = (props, icon) => {
757
- return $mol_jsx("span", null, icon);
757
+ return $mol_jsx("span", null,
758
+ icon,
759
+ $mol_jsx("i", { id: "label" }));
758
760
  };
759
- const dom = $mol_jsx(Foo, { id: "/foo" });
760
- $mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
761
+ const dom = $mol_jsx(Foo, { id: "foo" });
762
+ $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>');
761
763
  },
762
764
  'Fail on non unique ids'() {
763
765
  const App = () => {
764
766
  return $mol_jsx("div", null,
765
- $mol_jsx("span", { id: "/bar" }),
766
- $mol_jsx("span", { id: "/bar" }));
767
+ $mol_jsx("span", { id: "bar" }),
768
+ $mol_jsx("span", { id: "bar" }));
767
769
  };
768
- $mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
770
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
771
+ },
772
+ 'Owner based guid generationn'() {
773
+ const Foo = () => {
774
+ return $mol_jsx("div", null,
775
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
776
+ };
777
+ const Bar = (props) => {
778
+ return $mol_jsx("span", null, props.icon());
779
+ };
780
+ const dom = $mol_jsx(Foo, { id: "app" });
781
+ $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>');
782
+ },
783
+ 'Fail on same ids from different caller'() {
784
+ const Foo = () => {
785
+ return $mol_jsx("div", null,
786
+ $mol_jsx("img", { id: "icon" }),
787
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
788
+ };
789
+ const Bar = (props) => {
790
+ return $mol_jsx("span", null, props.icon());
791
+ };
792
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
769
793
  },
770
794
  });
771
795
  })($ || ($ = {}));
@@ -775,6 +799,7 @@ var $;
775
799
  var $;
776
800
  (function ($) {
777
801
  $.$mol_jsx_prefix = '';
802
+ $.$mol_jsx_crumbs = '';
778
803
  $.$mol_jsx_booked = null;
779
804
  $.$mol_jsx_document = {
780
805
  getElementById: () => null,
@@ -784,16 +809,45 @@ var $;
784
809
  $.$mol_jsx_frag = '';
785
810
  function $mol_jsx(Elem, props, ...childNodes) {
786
811
  const id = props && props.id || '';
812
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
813
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id}`) : $.$mol_jsx_crumbs;
787
814
  if (Elem && $.$mol_jsx_booked) {
788
815
  if ($.$mol_jsx_booked.has(id)) {
789
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
816
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
790
817
  }
791
818
  else {
792
819
  $.$mol_jsx_booked.add(id);
793
820
  }
794
821
  }
795
- const guid = $.$mol_jsx_prefix + id;
796
822
  let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
823
+ if ($.$mol_jsx_prefix) {
824
+ const prefix_ext = $.$mol_jsx_prefix;
825
+ const booked_ext = $.$mol_jsx_booked;
826
+ const crumbs_ext = $.$mol_jsx_crumbs;
827
+ for (const field in props) {
828
+ const func = props[field];
829
+ if (typeof func !== 'function')
830
+ continue;
831
+ const wrapper = function (...args) {
832
+ const prefix = $.$mol_jsx_prefix;
833
+ const booked = $.$mol_jsx_booked;
834
+ const crumbs = $.$mol_jsx_crumbs;
835
+ try {
836
+ $.$mol_jsx_prefix = prefix_ext;
837
+ $.$mol_jsx_booked = booked_ext;
838
+ $.$mol_jsx_crumbs = crumbs_ext;
839
+ return func.call(this, ...args);
840
+ }
841
+ finally {
842
+ $.$mol_jsx_prefix = prefix;
843
+ $.$mol_jsx_booked = booked;
844
+ $.$mol_jsx_crumbs = crumbs;
845
+ }
846
+ };
847
+ $mol_func_name_from(wrapper, func);
848
+ props[field] = wrapper;
849
+ }
850
+ }
797
851
  if (typeof Elem !== 'string') {
798
852
  if ('prototype' in Elem) {
799
853
  const view = node && node[Elem] || new Elem;
@@ -802,6 +856,7 @@ var $;
802
856
  view.childNodes = childNodes;
803
857
  if (!view.ownerDocument)
804
858
  view.ownerDocument = $.$mol_jsx_document;
859
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
805
860
  node = view.valueOf();
806
861
  node[Elem] = view;
807
862
  return node;
@@ -809,14 +864,17 @@ var $;
809
864
  else {
810
865
  const prefix = $.$mol_jsx_prefix;
811
866
  const booked = $.$mol_jsx_booked;
867
+ const crumbs = $.$mol_jsx_crumbs;
812
868
  try {
813
869
  $.$mol_jsx_prefix = guid;
814
870
  $.$mol_jsx_booked = new Set;
871
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
815
872
  return Elem(props, ...childNodes);
816
873
  }
817
874
  finally {
818
875
  $.$mol_jsx_prefix = prefix;
819
876
  $.$mol_jsx_booked = booked;
877
+ $.$mol_jsx_crumbs = crumbs;
820
878
  }
821
879
  }
822
880
  }
@@ -847,6 +905,8 @@ var $;
847
905
  }
848
906
  if (guid)
849
907
  node.id = guid;
908
+ if ($.$mol_jsx_crumbs)
909
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
850
910
  return node;
851
911
  }
852
912
  $.$mol_jsx = $mol_jsx;
@@ -1824,6 +1884,48 @@ var $;
1824
1884
  ;
1825
1885
  "use strict";
1826
1886
  var $;
1887
+ (function ($_1) {
1888
+ $mol_test({
1889
+ 'FQN of anon function'($) {
1890
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
1891
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
1892
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
1893
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
1894
+ },
1895
+ });
1896
+ })($ || ($ = {}));
1897
+ //mol/func/name/name.test.ts
1898
+ ;
1899
+ "use strict";
1900
+ var $;
1901
+ (function ($) {
1902
+ function $mol_func_name(func) {
1903
+ let name = func.name;
1904
+ if (name?.length > 1)
1905
+ return name;
1906
+ for (let key in this) {
1907
+ try {
1908
+ if (this[key] !== func)
1909
+ continue;
1910
+ name = key;
1911
+ Object.defineProperty(func, 'name', { value: name });
1912
+ break;
1913
+ }
1914
+ catch { }
1915
+ }
1916
+ return name;
1917
+ }
1918
+ $.$mol_func_name = $mol_func_name;
1919
+ function $mol_func_name_from(target, source) {
1920
+ Object.defineProperty(target, 'name', { value: source.name });
1921
+ return target;
1922
+ }
1923
+ $.$mol_func_name_from = $mol_func_name_from;
1924
+ })($ || ($ = {}));
1925
+ //mol/func/name/name.ts
1926
+ ;
1927
+ "use strict";
1928
+ var $;
1827
1929
  (function ($) {
1828
1930
  $mol_test({
1829
1931
  'escape'() {