mam 1.11.607 → 1.11.608
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
|
@@ -1123,6 +1123,16 @@ var $;
|
|
|
1123
1123
|
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
|
1124
1124
|
})($ || ($ = {}));
|
|
1125
1125
|
|
|
1126
|
+
;
|
|
1127
|
+
"use strict";
|
|
1128
|
+
var $;
|
|
1129
|
+
(function ($) {
|
|
1130
|
+
function $mol_maybe(value) {
|
|
1131
|
+
return (value == null) ? [] : [value];
|
|
1132
|
+
}
|
|
1133
|
+
$.$mol_maybe = $mol_maybe;
|
|
1134
|
+
})($ || ($ = {}));
|
|
1135
|
+
|
|
1126
1136
|
;
|
|
1127
1137
|
"use strict";
|
|
1128
1138
|
var $;
|
|
@@ -1190,33 +1200,38 @@ var $;
|
|
|
1190
1200
|
return $$.$mol_tree2_to_string(this);
|
|
1191
1201
|
}
|
|
1192
1202
|
insert(value, ...path) {
|
|
1203
|
+
return this.update($mol_maybe(value), ...path)[0];
|
|
1204
|
+
}
|
|
1205
|
+
update(value, ...path) {
|
|
1193
1206
|
if (path.length === 0)
|
|
1194
1207
|
return value;
|
|
1195
1208
|
const type = path[0];
|
|
1196
1209
|
if (typeof type === 'string') {
|
|
1197
1210
|
let replaced = false;
|
|
1198
|
-
const sub = this.kids.
|
|
1211
|
+
const sub = this.kids.flatMap((item, index) => {
|
|
1199
1212
|
if (item.type !== type)
|
|
1200
1213
|
return item;
|
|
1201
1214
|
replaced = true;
|
|
1202
|
-
return item.
|
|
1215
|
+
return item.update(value, ...path.slice(1));
|
|
1203
1216
|
}).filter(Boolean);
|
|
1204
1217
|
if (!replaced && value) {
|
|
1205
|
-
sub.push(this.struct(type, []).
|
|
1218
|
+
sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
|
|
1206
1219
|
}
|
|
1207
|
-
return this.clone(sub);
|
|
1220
|
+
return [this.clone(sub)];
|
|
1208
1221
|
}
|
|
1209
1222
|
else if (typeof type === 'number') {
|
|
1210
|
-
const
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1223
|
+
const ins = (this.kids[type] || this.list([]))
|
|
1224
|
+
.update(value, ...path.slice(1));
|
|
1225
|
+
return [this.clone([
|
|
1226
|
+
...this.kids.slice(0, type),
|
|
1227
|
+
...ins,
|
|
1228
|
+
...this.kids.slice(type + 1),
|
|
1229
|
+
])];
|
|
1214
1230
|
}
|
|
1215
1231
|
else {
|
|
1216
1232
|
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
1217
|
-
.
|
|
1218
|
-
|
|
1219
|
-
return this.clone(kids);
|
|
1233
|
+
.flatMap(item => item.update(value, ...path.slice(1)));
|
|
1234
|
+
return [this.clone(kids)];
|
|
1220
1235
|
}
|
|
1221
1236
|
}
|
|
1222
1237
|
select(...path) {
|
package/node.test.js
CHANGED
|
@@ -1114,6 +1114,16 @@ var $;
|
|
|
1114
1114
|
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
|
1115
1115
|
})($ || ($ = {}));
|
|
1116
1116
|
|
|
1117
|
+
;
|
|
1118
|
+
"use strict";
|
|
1119
|
+
var $;
|
|
1120
|
+
(function ($) {
|
|
1121
|
+
function $mol_maybe(value) {
|
|
1122
|
+
return (value == null) ? [] : [value];
|
|
1123
|
+
}
|
|
1124
|
+
$.$mol_maybe = $mol_maybe;
|
|
1125
|
+
})($ || ($ = {}));
|
|
1126
|
+
|
|
1117
1127
|
;
|
|
1118
1128
|
"use strict";
|
|
1119
1129
|
var $;
|
|
@@ -1181,33 +1191,38 @@ var $;
|
|
|
1181
1191
|
return $$.$mol_tree2_to_string(this);
|
|
1182
1192
|
}
|
|
1183
1193
|
insert(value, ...path) {
|
|
1194
|
+
return this.update($mol_maybe(value), ...path)[0];
|
|
1195
|
+
}
|
|
1196
|
+
update(value, ...path) {
|
|
1184
1197
|
if (path.length === 0)
|
|
1185
1198
|
return value;
|
|
1186
1199
|
const type = path[0];
|
|
1187
1200
|
if (typeof type === 'string') {
|
|
1188
1201
|
let replaced = false;
|
|
1189
|
-
const sub = this.kids.
|
|
1202
|
+
const sub = this.kids.flatMap((item, index) => {
|
|
1190
1203
|
if (item.type !== type)
|
|
1191
1204
|
return item;
|
|
1192
1205
|
replaced = true;
|
|
1193
|
-
return item.
|
|
1206
|
+
return item.update(value, ...path.slice(1));
|
|
1194
1207
|
}).filter(Boolean);
|
|
1195
1208
|
if (!replaced && value) {
|
|
1196
|
-
sub.push(this.struct(type, []).
|
|
1209
|
+
sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
|
|
1197
1210
|
}
|
|
1198
|
-
return this.clone(sub);
|
|
1211
|
+
return [this.clone(sub)];
|
|
1199
1212
|
}
|
|
1200
1213
|
else if (typeof type === 'number') {
|
|
1201
|
-
const
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1214
|
+
const ins = (this.kids[type] || this.list([]))
|
|
1215
|
+
.update(value, ...path.slice(1));
|
|
1216
|
+
return [this.clone([
|
|
1217
|
+
...this.kids.slice(0, type),
|
|
1218
|
+
...ins,
|
|
1219
|
+
...this.kids.slice(type + 1),
|
|
1220
|
+
])];
|
|
1205
1221
|
}
|
|
1206
1222
|
else {
|
|
1207
1223
|
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
1208
|
-
.
|
|
1209
|
-
|
|
1210
|
-
return this.clone(kids);
|
|
1224
|
+
.flatMap(item => item.update(value, ...path.slice(1)));
|
|
1225
|
+
return [this.clone(kids)];
|
|
1211
1226
|
}
|
|
1212
1227
|
}
|
|
1213
1228
|
select(...path) {
|
|
@@ -8894,41 +8909,105 @@ var $;
|
|
|
8894
8909
|
});
|
|
8895
8910
|
})($ || ($ = {}));
|
|
8896
8911
|
|
|
8912
|
+
;
|
|
8913
|
+
"use strict";
|
|
8914
|
+
var $;
|
|
8915
|
+
(function ($) {
|
|
8916
|
+
$mol_test({
|
|
8917
|
+
'all cases of using maybe'() {
|
|
8918
|
+
$mol_assert_equal($mol_maybe(0)[0], 0);
|
|
8919
|
+
$mol_assert_equal($mol_maybe(false)[0], false);
|
|
8920
|
+
$mol_assert_equal($mol_maybe(null)[0], void 0);
|
|
8921
|
+
$mol_assert_equal($mol_maybe(void 0)[0], void 0);
|
|
8922
|
+
$mol_assert_equal($mol_maybe(void 0).map(v => v.toString())[0], void 0);
|
|
8923
|
+
$mol_assert_equal($mol_maybe(0).map(v => v.toString())[0], '0');
|
|
8924
|
+
},
|
|
8925
|
+
});
|
|
8926
|
+
})($ || ($ = {}));
|
|
8927
|
+
|
|
8897
8928
|
;
|
|
8898
8929
|
"use strict";
|
|
8899
8930
|
var $;
|
|
8900
8931
|
(function ($_1) {
|
|
8932
|
+
function check(tree, ideal) {
|
|
8933
|
+
$mol_assert_equal(tree.toString(), $$.$mol_tree2_from_string(ideal).toString());
|
|
8934
|
+
}
|
|
8901
8935
|
$mol_test({
|
|
8902
8936
|
'inserting'($) {
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
|
|
8916
|
-
.insert($mol_tree2.struct('x'),
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8937
|
+
check($.$mol_tree2_from_string(`
|
|
8938
|
+
a b c d
|
|
8939
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c'), `
|
|
8940
|
+
a b x
|
|
8941
|
+
`);
|
|
8942
|
+
check($.$mol_tree2_from_string(`
|
|
8943
|
+
a b
|
|
8944
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd'), `
|
|
8945
|
+
a b c x
|
|
8946
|
+
`);
|
|
8947
|
+
check($.$mol_tree2_from_string(`
|
|
8948
|
+
a b c d
|
|
8949
|
+
`)
|
|
8950
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0), `
|
|
8951
|
+
a b x
|
|
8952
|
+
`);
|
|
8953
|
+
check($.$mol_tree2_from_string(`
|
|
8954
|
+
a b
|
|
8955
|
+
`)
|
|
8956
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0, 0), `
|
|
8957
|
+
a b \\
|
|
8958
|
+
x
|
|
8959
|
+
`);
|
|
8960
|
+
check($.$mol_tree2_from_string(`
|
|
8961
|
+
a b c d
|
|
8962
|
+
`)
|
|
8963
|
+
.insert($mol_tree2.struct('x'), null, null, null), `
|
|
8964
|
+
a b x
|
|
8965
|
+
`);
|
|
8966
|
+
check($.$mol_tree2_from_string(`
|
|
8967
|
+
a b
|
|
8968
|
+
`)
|
|
8969
|
+
.insert($mol_tree2.struct('x'), null, null, null, null), `
|
|
8970
|
+
a b \\
|
|
8971
|
+
x
|
|
8972
|
+
`);
|
|
8973
|
+
},
|
|
8974
|
+
'updating'($) {
|
|
8975
|
+
check($.$mol_tree2_from_string(`
|
|
8976
|
+
a b c d
|
|
8977
|
+
`).update([], 'a', 'b', 'c')[0], `
|
|
8978
|
+
a b
|
|
8979
|
+
`);
|
|
8980
|
+
check($.$mol_tree2_from_string(`
|
|
8981
|
+
a b c d
|
|
8982
|
+
`).update([$mol_tree2.struct('x')])[0], `
|
|
8983
|
+
x
|
|
8984
|
+
`);
|
|
8985
|
+
check($.$mol_tree2_from_string(`
|
|
8986
|
+
a b c d
|
|
8987
|
+
`).update([$mol_tree2.struct('x'), $mol_tree2.struct('y')], 'a', 'b', 'c')[0], `
|
|
8988
|
+
a b
|
|
8989
|
+
x
|
|
8990
|
+
y
|
|
8991
|
+
`);
|
|
8921
8992
|
},
|
|
8922
8993
|
'deleting'($) {
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8994
|
+
const base = $.$mol_tree2_from_string(`
|
|
8995
|
+
a b c d
|
|
8996
|
+
`);
|
|
8997
|
+
check(base.insert(null, 'a', 'b', 'c'), `
|
|
8998
|
+
a b
|
|
8999
|
+
`);
|
|
9000
|
+
check(base.update(base.select('a', 'b', 'c', null).kids, 'a', 'b', 'c')[0], `
|
|
9001
|
+
a b d
|
|
9002
|
+
`);
|
|
9003
|
+
check(base.insert(null, 0, 0, 0), `
|
|
9004
|
+
a b
|
|
9005
|
+
`);
|
|
8929
9006
|
},
|
|
8930
9007
|
'hack'($) {
|
|
8931
|
-
const res = $.$mol_tree2_from_string(`
|
|
9008
|
+
const res = $.$mol_tree2_from_string(`
|
|
9009
|
+
foo bar xxx
|
|
9010
|
+
`)
|
|
8932
9011
|
.hack({
|
|
8933
9012
|
'bar': (input, belt) => [input.struct('777', input.hack(belt))],
|
|
8934
9013
|
});
|