mol_jsx_lib 0.0.1287 → 0.0.1289
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.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +26 -11
- package/node.js.map +1 -1
- package/node.mjs +26 -11
- package/node.test.js +115 -36
- package/node.test.js.map +1 -1
- package/package.json +2 -1
package/node.mjs
CHANGED
|
@@ -1305,6 +1305,16 @@ var $;
|
|
|
1305
1305
|
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
|
1306
1306
|
})($ || ($ = {}));
|
|
1307
1307
|
|
|
1308
|
+
;
|
|
1309
|
+
"use strict";
|
|
1310
|
+
var $;
|
|
1311
|
+
(function ($) {
|
|
1312
|
+
function $mol_maybe(value) {
|
|
1313
|
+
return (value == null) ? [] : [value];
|
|
1314
|
+
}
|
|
1315
|
+
$.$mol_maybe = $mol_maybe;
|
|
1316
|
+
})($ || ($ = {}));
|
|
1317
|
+
|
|
1308
1318
|
;
|
|
1309
1319
|
"use strict";
|
|
1310
1320
|
var $;
|
|
@@ -1372,33 +1382,38 @@ var $;
|
|
|
1372
1382
|
return $$.$mol_tree2_to_string(this);
|
|
1373
1383
|
}
|
|
1374
1384
|
insert(value, ...path) {
|
|
1385
|
+
return this.update($mol_maybe(value), ...path)[0];
|
|
1386
|
+
}
|
|
1387
|
+
update(value, ...path) {
|
|
1375
1388
|
if (path.length === 0)
|
|
1376
1389
|
return value;
|
|
1377
1390
|
const type = path[0];
|
|
1378
1391
|
if (typeof type === 'string') {
|
|
1379
1392
|
let replaced = false;
|
|
1380
|
-
const sub = this.kids.
|
|
1393
|
+
const sub = this.kids.flatMap((item, index) => {
|
|
1381
1394
|
if (item.type !== type)
|
|
1382
1395
|
return item;
|
|
1383
1396
|
replaced = true;
|
|
1384
|
-
return item.
|
|
1397
|
+
return item.update(value, ...path.slice(1));
|
|
1385
1398
|
}).filter(Boolean);
|
|
1386
1399
|
if (!replaced && value) {
|
|
1387
|
-
sub.push(this.struct(type, []).
|
|
1400
|
+
sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
|
|
1388
1401
|
}
|
|
1389
|
-
return this.clone(sub);
|
|
1402
|
+
return [this.clone(sub)];
|
|
1390
1403
|
}
|
|
1391
1404
|
else if (typeof type === 'number') {
|
|
1392
|
-
const
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1405
|
+
const ins = (this.kids[type] || this.list([]))
|
|
1406
|
+
.update(value, ...path.slice(1));
|
|
1407
|
+
return [this.clone([
|
|
1408
|
+
...this.kids.slice(0, type),
|
|
1409
|
+
...ins,
|
|
1410
|
+
...this.kids.slice(type + 1),
|
|
1411
|
+
])];
|
|
1396
1412
|
}
|
|
1397
1413
|
else {
|
|
1398
1414
|
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
1399
|
-
.
|
|
1400
|
-
|
|
1401
|
-
return this.clone(kids);
|
|
1415
|
+
.flatMap(item => item.update(value, ...path.slice(1)));
|
|
1416
|
+
return [this.clone(kids)];
|
|
1402
1417
|
}
|
|
1403
1418
|
}
|
|
1404
1419
|
select(...path) {
|
package/node.test.js
CHANGED
|
@@ -1296,6 +1296,16 @@ var $;
|
|
|
1296
1296
|
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
|
1297
1297
|
})($ || ($ = {}));
|
|
1298
1298
|
|
|
1299
|
+
;
|
|
1300
|
+
"use strict";
|
|
1301
|
+
var $;
|
|
1302
|
+
(function ($) {
|
|
1303
|
+
function $mol_maybe(value) {
|
|
1304
|
+
return (value == null) ? [] : [value];
|
|
1305
|
+
}
|
|
1306
|
+
$.$mol_maybe = $mol_maybe;
|
|
1307
|
+
})($ || ($ = {}));
|
|
1308
|
+
|
|
1299
1309
|
;
|
|
1300
1310
|
"use strict";
|
|
1301
1311
|
var $;
|
|
@@ -1363,33 +1373,38 @@ var $;
|
|
|
1363
1373
|
return $$.$mol_tree2_to_string(this);
|
|
1364
1374
|
}
|
|
1365
1375
|
insert(value, ...path) {
|
|
1376
|
+
return this.update($mol_maybe(value), ...path)[0];
|
|
1377
|
+
}
|
|
1378
|
+
update(value, ...path) {
|
|
1366
1379
|
if (path.length === 0)
|
|
1367
1380
|
return value;
|
|
1368
1381
|
const type = path[0];
|
|
1369
1382
|
if (typeof type === 'string') {
|
|
1370
1383
|
let replaced = false;
|
|
1371
|
-
const sub = this.kids.
|
|
1384
|
+
const sub = this.kids.flatMap((item, index) => {
|
|
1372
1385
|
if (item.type !== type)
|
|
1373
1386
|
return item;
|
|
1374
1387
|
replaced = true;
|
|
1375
|
-
return item.
|
|
1388
|
+
return item.update(value, ...path.slice(1));
|
|
1376
1389
|
}).filter(Boolean);
|
|
1377
1390
|
if (!replaced && value) {
|
|
1378
|
-
sub.push(this.struct(type, []).
|
|
1391
|
+
sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
|
|
1379
1392
|
}
|
|
1380
|
-
return this.clone(sub);
|
|
1393
|
+
return [this.clone(sub)];
|
|
1381
1394
|
}
|
|
1382
1395
|
else if (typeof type === 'number') {
|
|
1383
|
-
const
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1396
|
+
const ins = (this.kids[type] || this.list([]))
|
|
1397
|
+
.update(value, ...path.slice(1));
|
|
1398
|
+
return [this.clone([
|
|
1399
|
+
...this.kids.slice(0, type),
|
|
1400
|
+
...ins,
|
|
1401
|
+
...this.kids.slice(type + 1),
|
|
1402
|
+
])];
|
|
1387
1403
|
}
|
|
1388
1404
|
else {
|
|
1389
1405
|
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
1390
|
-
.
|
|
1391
|
-
|
|
1392
|
-
return this.clone(kids);
|
|
1406
|
+
.flatMap(item => item.update(value, ...path.slice(1)));
|
|
1407
|
+
return [this.clone(kids)];
|
|
1393
1408
|
}
|
|
1394
1409
|
}
|
|
1395
1410
|
select(...path) {
|
|
@@ -3412,41 +3427,105 @@ var $;
|
|
|
3412
3427
|
});
|
|
3413
3428
|
})($ || ($ = {}));
|
|
3414
3429
|
|
|
3430
|
+
;
|
|
3431
|
+
"use strict";
|
|
3432
|
+
var $;
|
|
3433
|
+
(function ($) {
|
|
3434
|
+
$mol_test({
|
|
3435
|
+
'all cases of using maybe'() {
|
|
3436
|
+
$mol_assert_equal($mol_maybe(0)[0], 0);
|
|
3437
|
+
$mol_assert_equal($mol_maybe(false)[0], false);
|
|
3438
|
+
$mol_assert_equal($mol_maybe(null)[0], void 0);
|
|
3439
|
+
$mol_assert_equal($mol_maybe(void 0)[0], void 0);
|
|
3440
|
+
$mol_assert_equal($mol_maybe(void 0).map(v => v.toString())[0], void 0);
|
|
3441
|
+
$mol_assert_equal($mol_maybe(0).map(v => v.toString())[0], '0');
|
|
3442
|
+
},
|
|
3443
|
+
});
|
|
3444
|
+
})($ || ($ = {}));
|
|
3445
|
+
|
|
3415
3446
|
;
|
|
3416
3447
|
"use strict";
|
|
3417
3448
|
var $;
|
|
3418
3449
|
(function ($_1) {
|
|
3450
|
+
function check(tree, ideal) {
|
|
3451
|
+
$mol_assert_equal(tree.toString(), $$.$mol_tree2_from_string(ideal).toString());
|
|
3452
|
+
}
|
|
3419
3453
|
$mol_test({
|
|
3420
3454
|
'inserting'($) {
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
.insert($mol_tree2.struct('x'),
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3455
|
+
check($.$mol_tree2_from_string(`
|
|
3456
|
+
a b c d
|
|
3457
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c'), `
|
|
3458
|
+
a b x
|
|
3459
|
+
`);
|
|
3460
|
+
check($.$mol_tree2_from_string(`
|
|
3461
|
+
a b
|
|
3462
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd'), `
|
|
3463
|
+
a b c x
|
|
3464
|
+
`);
|
|
3465
|
+
check($.$mol_tree2_from_string(`
|
|
3466
|
+
a b c d
|
|
3467
|
+
`)
|
|
3468
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0), `
|
|
3469
|
+
a b x
|
|
3470
|
+
`);
|
|
3471
|
+
check($.$mol_tree2_from_string(`
|
|
3472
|
+
a b
|
|
3473
|
+
`)
|
|
3474
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0, 0), `
|
|
3475
|
+
a b \\
|
|
3476
|
+
x
|
|
3477
|
+
`);
|
|
3478
|
+
check($.$mol_tree2_from_string(`
|
|
3479
|
+
a b c d
|
|
3480
|
+
`)
|
|
3481
|
+
.insert($mol_tree2.struct('x'), null, null, null), `
|
|
3482
|
+
a b x
|
|
3483
|
+
`);
|
|
3484
|
+
check($.$mol_tree2_from_string(`
|
|
3485
|
+
a b
|
|
3486
|
+
`)
|
|
3487
|
+
.insert($mol_tree2.struct('x'), null, null, null, null), `
|
|
3488
|
+
a b \\
|
|
3489
|
+
x
|
|
3490
|
+
`);
|
|
3491
|
+
},
|
|
3492
|
+
'updating'($) {
|
|
3493
|
+
check($.$mol_tree2_from_string(`
|
|
3494
|
+
a b c d
|
|
3495
|
+
`).update([], 'a', 'b', 'c')[0], `
|
|
3496
|
+
a b
|
|
3497
|
+
`);
|
|
3498
|
+
check($.$mol_tree2_from_string(`
|
|
3499
|
+
a b c d
|
|
3500
|
+
`).update([$mol_tree2.struct('x')])[0], `
|
|
3501
|
+
x
|
|
3502
|
+
`);
|
|
3503
|
+
check($.$mol_tree2_from_string(`
|
|
3504
|
+
a b c d
|
|
3505
|
+
`).update([$mol_tree2.struct('x'), $mol_tree2.struct('y')], 'a', 'b', 'c')[0], `
|
|
3506
|
+
a b
|
|
3507
|
+
x
|
|
3508
|
+
y
|
|
3509
|
+
`);
|
|
3439
3510
|
},
|
|
3440
3511
|
'deleting'($) {
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3512
|
+
const base = $.$mol_tree2_from_string(`
|
|
3513
|
+
a b c d
|
|
3514
|
+
`);
|
|
3515
|
+
check(base.insert(null, 'a', 'b', 'c'), `
|
|
3516
|
+
a b
|
|
3517
|
+
`);
|
|
3518
|
+
check(base.update(base.select('a', 'b', 'c', null).kids, 'a', 'b', 'c')[0], `
|
|
3519
|
+
a b d
|
|
3520
|
+
`);
|
|
3521
|
+
check(base.insert(null, 0, 0, 0), `
|
|
3522
|
+
a b
|
|
3523
|
+
`);
|
|
3447
3524
|
},
|
|
3448
3525
|
'hack'($) {
|
|
3449
|
-
const res = $.$mol_tree2_from_string(`
|
|
3526
|
+
const res = $.$mol_tree2_from_string(`
|
|
3527
|
+
foo bar xxx
|
|
3528
|
+
`)
|
|
3450
3529
|
.hack({
|
|
3451
3530
|
'bar': (input, belt) => [input.struct('777', input.hack(belt))],
|
|
3452
3531
|
});
|