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 +114 -12
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.test.js +114 -12
- package/web.test.js.map +1 -1
package/package.json
CHANGED
package/web.test.js
CHANGED
|
@@ -235,28 +235,52 @@ var $;
|
|
|
235
235
|
const Button = (props, target) => {
|
|
236
236
|
return $mol_jsx("button", { title: props.hint }, target());
|
|
237
237
|
};
|
|
238
|
-
const dom = $mol_jsx(Button, { id: "
|
|
239
|
-
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="
|
|
238
|
+
const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
|
|
239
|
+
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="foo" class="Button">hey!</button>');
|
|
240
240
|
},
|
|
241
241
|
'Nested guid generation'() {
|
|
242
242
|
const Foo = () => {
|
|
243
243
|
return $mol_jsx("div", null,
|
|
244
|
-
$mol_jsx(Bar, { id: "
|
|
245
|
-
$mol_jsx("img", { id: "
|
|
244
|
+
$mol_jsx(Bar, { id: "bar" },
|
|
245
|
+
$mol_jsx("img", { id: "icon" })));
|
|
246
246
|
};
|
|
247
247
|
const Bar = (props, icon) => {
|
|
248
|
-
return $mol_jsx("span", null,
|
|
248
|
+
return $mol_jsx("span", null,
|
|
249
|
+
icon,
|
|
250
|
+
$mol_jsx("i", { id: "label" }));
|
|
249
251
|
};
|
|
250
|
-
const dom = $mol_jsx(Foo, { id: "
|
|
251
|
-
$mol_assert_equal(dom.outerHTML, '<div id="
|
|
252
|
+
const dom = $mol_jsx(Foo, { id: "foo" });
|
|
253
|
+
$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>');
|
|
252
254
|
},
|
|
253
255
|
'Fail on non unique ids'() {
|
|
254
256
|
const App = () => {
|
|
255
257
|
return $mol_jsx("div", null,
|
|
256
|
-
$mol_jsx("span", { id: "
|
|
257
|
-
$mol_jsx("span", { id: "
|
|
258
|
+
$mol_jsx("span", { id: "bar" }),
|
|
259
|
+
$mol_jsx("span", { id: "bar" }));
|
|
258
260
|
};
|
|
259
|
-
$mol_assert_fail(() => $mol_jsx(App, { id: "
|
|
261
|
+
$mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
|
|
262
|
+
},
|
|
263
|
+
'Owner based guid generationn'() {
|
|
264
|
+
const Foo = () => {
|
|
265
|
+
return $mol_jsx("div", null,
|
|
266
|
+
$mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
267
|
+
};
|
|
268
|
+
const Bar = (props) => {
|
|
269
|
+
return $mol_jsx("span", null, props.icon());
|
|
270
|
+
};
|
|
271
|
+
const dom = $mol_jsx(Foo, { id: "app" });
|
|
272
|
+
$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>');
|
|
273
|
+
},
|
|
274
|
+
'Fail on same ids from different caller'() {
|
|
275
|
+
const Foo = () => {
|
|
276
|
+
return $mol_jsx("div", null,
|
|
277
|
+
$mol_jsx("img", { id: "icon" }),
|
|
278
|
+
$mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
279
|
+
};
|
|
280
|
+
const Bar = (props) => {
|
|
281
|
+
return $mol_jsx("span", null, props.icon());
|
|
282
|
+
};
|
|
283
|
+
$mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
|
|
260
284
|
},
|
|
261
285
|
});
|
|
262
286
|
})($ || ($ = {}));
|
|
@@ -266,6 +290,7 @@ var $;
|
|
|
266
290
|
var $;
|
|
267
291
|
(function ($) {
|
|
268
292
|
$.$mol_jsx_prefix = '';
|
|
293
|
+
$.$mol_jsx_crumbs = '';
|
|
269
294
|
$.$mol_jsx_booked = null;
|
|
270
295
|
$.$mol_jsx_document = {
|
|
271
296
|
getElementById: () => null,
|
|
@@ -275,16 +300,45 @@ var $;
|
|
|
275
300
|
$.$mol_jsx_frag = '';
|
|
276
301
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
277
302
|
const id = props && props.id || '';
|
|
303
|
+
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
304
|
+
const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id}`) : $.$mol_jsx_crumbs;
|
|
278
305
|
if (Elem && $.$mol_jsx_booked) {
|
|
279
306
|
if ($.$mol_jsx_booked.has(id)) {
|
|
280
|
-
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(
|
|
307
|
+
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
|
|
281
308
|
}
|
|
282
309
|
else {
|
|
283
310
|
$.$mol_jsx_booked.add(id);
|
|
284
311
|
}
|
|
285
312
|
}
|
|
286
|
-
const guid = $.$mol_jsx_prefix + id;
|
|
287
313
|
let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
|
|
314
|
+
if ($.$mol_jsx_prefix) {
|
|
315
|
+
const prefix_ext = $.$mol_jsx_prefix;
|
|
316
|
+
const booked_ext = $.$mol_jsx_booked;
|
|
317
|
+
const crumbs_ext = $.$mol_jsx_crumbs;
|
|
318
|
+
for (const field in props) {
|
|
319
|
+
const func = props[field];
|
|
320
|
+
if (typeof func !== 'function')
|
|
321
|
+
continue;
|
|
322
|
+
const wrapper = function (...args) {
|
|
323
|
+
const prefix = $.$mol_jsx_prefix;
|
|
324
|
+
const booked = $.$mol_jsx_booked;
|
|
325
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
326
|
+
try {
|
|
327
|
+
$.$mol_jsx_prefix = prefix_ext;
|
|
328
|
+
$.$mol_jsx_booked = booked_ext;
|
|
329
|
+
$.$mol_jsx_crumbs = crumbs_ext;
|
|
330
|
+
return func.call(this, ...args);
|
|
331
|
+
}
|
|
332
|
+
finally {
|
|
333
|
+
$.$mol_jsx_prefix = prefix;
|
|
334
|
+
$.$mol_jsx_booked = booked;
|
|
335
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
$mol_func_name_from(wrapper, func);
|
|
339
|
+
props[field] = wrapper;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
288
342
|
if (typeof Elem !== 'string') {
|
|
289
343
|
if ('prototype' in Elem) {
|
|
290
344
|
const view = node && node[Elem] || new Elem;
|
|
@@ -293,6 +347,7 @@ var $;
|
|
|
293
347
|
view.childNodes = childNodes;
|
|
294
348
|
if (!view.ownerDocument)
|
|
295
349
|
view.ownerDocument = $.$mol_jsx_document;
|
|
350
|
+
view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
296
351
|
node = view.valueOf();
|
|
297
352
|
node[Elem] = view;
|
|
298
353
|
return node;
|
|
@@ -300,14 +355,17 @@ var $;
|
|
|
300
355
|
else {
|
|
301
356
|
const prefix = $.$mol_jsx_prefix;
|
|
302
357
|
const booked = $.$mol_jsx_booked;
|
|
358
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
303
359
|
try {
|
|
304
360
|
$.$mol_jsx_prefix = guid;
|
|
305
361
|
$.$mol_jsx_booked = new Set;
|
|
362
|
+
$.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
306
363
|
return Elem(props, ...childNodes);
|
|
307
364
|
}
|
|
308
365
|
finally {
|
|
309
366
|
$.$mol_jsx_prefix = prefix;
|
|
310
367
|
$.$mol_jsx_booked = booked;
|
|
368
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
311
369
|
}
|
|
312
370
|
}
|
|
313
371
|
}
|
|
@@ -338,6 +396,8 @@ var $;
|
|
|
338
396
|
}
|
|
339
397
|
if (guid)
|
|
340
398
|
node.id = guid;
|
|
399
|
+
if ($.$mol_jsx_crumbs)
|
|
400
|
+
node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
|
|
341
401
|
return node;
|
|
342
402
|
}
|
|
343
403
|
$.$mol_jsx = $mol_jsx;
|
|
@@ -782,6 +842,48 @@ var $;
|
|
|
782
842
|
;
|
|
783
843
|
"use strict";
|
|
784
844
|
var $;
|
|
845
|
+
(function ($_1) {
|
|
846
|
+
$mol_test({
|
|
847
|
+
'FQN of anon function'($) {
|
|
848
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
|
849
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
|
850
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
|
851
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
|
852
|
+
},
|
|
853
|
+
});
|
|
854
|
+
})($ || ($ = {}));
|
|
855
|
+
//mol/func/name/name.test.ts
|
|
856
|
+
;
|
|
857
|
+
"use strict";
|
|
858
|
+
var $;
|
|
859
|
+
(function ($) {
|
|
860
|
+
function $mol_func_name(func) {
|
|
861
|
+
let name = func.name;
|
|
862
|
+
if (name?.length > 1)
|
|
863
|
+
return name;
|
|
864
|
+
for (let key in this) {
|
|
865
|
+
try {
|
|
866
|
+
if (this[key] !== func)
|
|
867
|
+
continue;
|
|
868
|
+
name = key;
|
|
869
|
+
Object.defineProperty(func, 'name', { value: name });
|
|
870
|
+
break;
|
|
871
|
+
}
|
|
872
|
+
catch { }
|
|
873
|
+
}
|
|
874
|
+
return name;
|
|
875
|
+
}
|
|
876
|
+
$.$mol_func_name = $mol_func_name;
|
|
877
|
+
function $mol_func_name_from(target, source) {
|
|
878
|
+
Object.defineProperty(target, 'name', { value: source.name });
|
|
879
|
+
return target;
|
|
880
|
+
}
|
|
881
|
+
$.$mol_func_name_from = $mol_func_name_from;
|
|
882
|
+
})($ || ($ = {}));
|
|
883
|
+
//mol/func/name/name.ts
|
|
884
|
+
;
|
|
885
|
+
"use strict";
|
|
886
|
+
var $;
|
|
785
887
|
(function ($) {
|
|
786
888
|
$mol_test({
|
|
787
889
|
'escape'() {
|