mol_mutable 0.0.1
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/.nojekyll +0 -0
- package/README.md +514 -0
- package/node.audit.js +1 -0
- package/node.d.ts +25 -0
- package/node.deps.json +1 -0
- package/node.esm.js +63 -0
- package/node.esm.js.map +1 -0
- package/node.js +62 -0
- package/node.js.map +1 -0
- package/node.test.js +1708 -0
- package/node.test.js.map +1 -0
- package/package.json +13 -0
- package/test.html +11 -0
- package/web.audit.js +1 -0
- package/web.css +1 -0
- package/web.css.map +1 -0
- package/web.d.ts +25 -0
- package/web.deps.json +1 -0
- package/web.esm.js +63 -0
- package/web.esm.js.map +1 -0
- package/web.js +62 -0
- package/web.js.map +1 -0
- package/web.test.js +925 -0
- package/web.test.js.map +1 -0
package/node.test.js
ADDED
|
@@ -0,0 +1,1708 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use strict"
|
|
3
|
+
|
|
4
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
|
|
12
|
+
$.$$ = $
|
|
13
|
+
|
|
14
|
+
;
|
|
15
|
+
"use strict";
|
|
16
|
+
Error.stackTraceLimit = 50;
|
|
17
|
+
var $;
|
|
18
|
+
(function ($) {
|
|
19
|
+
})($ || ($ = {}));
|
|
20
|
+
module.exports = $;
|
|
21
|
+
//mam.ts
|
|
22
|
+
;
|
|
23
|
+
"use strict";
|
|
24
|
+
var $;
|
|
25
|
+
(function ($) {
|
|
26
|
+
function $mol_mutable(value, update = next => value = next) {
|
|
27
|
+
return new Proxy($mol_mutable, {
|
|
28
|
+
get: (mutable, field) => mutable(value[field], next => {
|
|
29
|
+
const next2 = Array.isArray(value) && typeof field === 'string'
|
|
30
|
+
? [
|
|
31
|
+
...value.slice(0, Number(field)),
|
|
32
|
+
next,
|
|
33
|
+
...value.slice(Number(field) + 1),
|
|
34
|
+
]
|
|
35
|
+
: { ...value, [field]: next };
|
|
36
|
+
value = update(next2);
|
|
37
|
+
return value[field];
|
|
38
|
+
}),
|
|
39
|
+
set: (mutable, field, next) => {
|
|
40
|
+
value = update(next);
|
|
41
|
+
return true;
|
|
42
|
+
},
|
|
43
|
+
apply: (mutable, self, [patch]) => {
|
|
44
|
+
if (!patch)
|
|
45
|
+
return value;
|
|
46
|
+
return value = update(patch(value));
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
$.$mol_mutable = $mol_mutable;
|
|
51
|
+
})($ || ($ = {}));
|
|
52
|
+
//mol/mutable/mutable.ts
|
|
53
|
+
;
|
|
54
|
+
"use strict";
|
|
55
|
+
var $;
|
|
56
|
+
(function ($) {
|
|
57
|
+
function $mol_fail(error) {
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
$.$mol_fail = $mol_fail;
|
|
61
|
+
})($ || ($ = {}));
|
|
62
|
+
//mol/fail/fail.ts
|
|
63
|
+
;
|
|
64
|
+
"use strict";
|
|
65
|
+
var $;
|
|
66
|
+
(function ($) {
|
|
67
|
+
function $mol_fail_hidden(error) {
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
$.$mol_fail_hidden = $mol_fail_hidden;
|
|
71
|
+
})($ || ($ = {}));
|
|
72
|
+
//mol/fail/hidden/hidden.ts
|
|
73
|
+
;
|
|
74
|
+
"use strict";
|
|
75
|
+
var $;
|
|
76
|
+
(function ($) {
|
|
77
|
+
function $mol_test_complete() {
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
$.$mol_test_complete = $mol_test_complete;
|
|
81
|
+
})($ || ($ = {}));
|
|
82
|
+
//mol/test/test.node.test.ts
|
|
83
|
+
;
|
|
84
|
+
"use strict";
|
|
85
|
+
var $;
|
|
86
|
+
(function ($_1) {
|
|
87
|
+
function $mol_test(set) {
|
|
88
|
+
for (let name in set) {
|
|
89
|
+
const code = set[name];
|
|
90
|
+
const test = (typeof code === 'string') ? new Function('', code) : code;
|
|
91
|
+
$_1.$mol_test_all.push(test);
|
|
92
|
+
}
|
|
93
|
+
$mol_test_schedule();
|
|
94
|
+
}
|
|
95
|
+
$_1.$mol_test = $mol_test;
|
|
96
|
+
$_1.$mol_test_mocks = [];
|
|
97
|
+
$_1.$mol_test_all = [];
|
|
98
|
+
async function $mol_test_run() {
|
|
99
|
+
for (var test of $_1.$mol_test_all) {
|
|
100
|
+
let context = Object.create($$);
|
|
101
|
+
for (let mock of $_1.$mol_test_mocks)
|
|
102
|
+
await mock(context);
|
|
103
|
+
const res = test(context);
|
|
104
|
+
if (res instanceof Promise) {
|
|
105
|
+
await new Promise((done, fail) => {
|
|
106
|
+
res.then(done, fail);
|
|
107
|
+
setTimeout(() => fail(new Error('Test timeout: ' + test.name)), 1000);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
$$.$mol_log3_done({
|
|
112
|
+
place: '$mol_test',
|
|
113
|
+
message: 'All tests passed',
|
|
114
|
+
count: $_1.$mol_test_all.length,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
$_1.$mol_test_run = $mol_test_run;
|
|
118
|
+
let scheduled = false;
|
|
119
|
+
function $mol_test_schedule() {
|
|
120
|
+
if (scheduled)
|
|
121
|
+
return;
|
|
122
|
+
scheduled = true;
|
|
123
|
+
setTimeout(async () => {
|
|
124
|
+
scheduled = false;
|
|
125
|
+
await $mol_test_run();
|
|
126
|
+
$$.$mol_test_complete();
|
|
127
|
+
}, 1000);
|
|
128
|
+
}
|
|
129
|
+
$_1.$mol_test_schedule = $mol_test_schedule;
|
|
130
|
+
$_1.$mol_test_mocks.push(context => {
|
|
131
|
+
let seed = 0;
|
|
132
|
+
context.Math = Object.create(Math);
|
|
133
|
+
context.Math.random = () => Math.sin(seed++);
|
|
134
|
+
const forbidden = ['XMLHttpRequest', 'fetch'];
|
|
135
|
+
for (let api of forbidden) {
|
|
136
|
+
context[api] = new Proxy(function () { }, {
|
|
137
|
+
get() {
|
|
138
|
+
$mol_fail_hidden(new Error(`${api} is forbidden in tests`));
|
|
139
|
+
},
|
|
140
|
+
apply() {
|
|
141
|
+
$mol_fail_hidden(new Error(`${api} is forbidden in tests`));
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
$mol_test({
|
|
147
|
+
'mocked Math.random'($) {
|
|
148
|
+
console.assert($.Math.random() === 0);
|
|
149
|
+
console.assert($.Math.random() === Math.sin(1));
|
|
150
|
+
},
|
|
151
|
+
'forbidden XMLHttpRequest'($) {
|
|
152
|
+
try {
|
|
153
|
+
console.assert(void new $.XMLHttpRequest);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
console.assert(error.message === 'XMLHttpRequest is forbidden in tests');
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
'forbidden fetch'($) {
|
|
160
|
+
try {
|
|
161
|
+
console.assert(void $.fetch(''));
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.assert(error.message === 'fetch is forbidden in tests');
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
})($ || ($ = {}));
|
|
169
|
+
//mol/test/test.test.ts
|
|
170
|
+
;
|
|
171
|
+
"use strict";
|
|
172
|
+
var $;
|
|
173
|
+
(function ($) {
|
|
174
|
+
})($ || ($ = {}));
|
|
175
|
+
//mol/dom/context/context.ts
|
|
176
|
+
;
|
|
177
|
+
"use strict";
|
|
178
|
+
//node/node.ts
|
|
179
|
+
;
|
|
180
|
+
"use strict";
|
|
181
|
+
var $node = new Proxy({ require }, {
|
|
182
|
+
get(target, name, wrapper) {
|
|
183
|
+
if (target[name])
|
|
184
|
+
return target[name];
|
|
185
|
+
const mod = target.require('module');
|
|
186
|
+
if (mod.builtinModules.indexOf(name) >= 0)
|
|
187
|
+
return target.require(name);
|
|
188
|
+
if (name[0] === '.')
|
|
189
|
+
return target.require(name);
|
|
190
|
+
const path = target.require('path');
|
|
191
|
+
const fs = target.require('fs');
|
|
192
|
+
let dir = path.resolve('.');
|
|
193
|
+
const suffix = `./node_modules/${name}`;
|
|
194
|
+
const $$ = $;
|
|
195
|
+
while (!fs.existsSync(path.join(dir, suffix))) {
|
|
196
|
+
const parent = path.resolve(dir, '..');
|
|
197
|
+
if (parent === dir) {
|
|
198
|
+
$$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
|
|
199
|
+
try {
|
|
200
|
+
$$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
|
|
201
|
+
}
|
|
202
|
+
catch { }
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
dir = parent;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return target.require(name);
|
|
210
|
+
},
|
|
211
|
+
set(target, name, value) {
|
|
212
|
+
target[name] = value;
|
|
213
|
+
return true;
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
require = (req => Object.assign(function require(name) {
|
|
217
|
+
return $node[name];
|
|
218
|
+
}, req))(require);
|
|
219
|
+
//node/node.node.ts
|
|
220
|
+
;
|
|
221
|
+
"use strict";
|
|
222
|
+
var $;
|
|
223
|
+
(function ($) {
|
|
224
|
+
function $mol_log3_area_lazy(event) {
|
|
225
|
+
const self = this;
|
|
226
|
+
const stack = self.$mol_log3_stack;
|
|
227
|
+
const deep = stack.length;
|
|
228
|
+
let logged = false;
|
|
229
|
+
stack.push(() => {
|
|
230
|
+
logged = true;
|
|
231
|
+
self.$mol_log3_area.call(self, event);
|
|
232
|
+
});
|
|
233
|
+
return () => {
|
|
234
|
+
if (logged)
|
|
235
|
+
self.console.groupEnd();
|
|
236
|
+
if (stack.length > deep)
|
|
237
|
+
stack.length = deep;
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
$.$mol_log3_area_lazy = $mol_log3_area_lazy;
|
|
241
|
+
$.$mol_log3_stack = [];
|
|
242
|
+
})($ || ($ = {}));
|
|
243
|
+
//mol/log3/log3.ts
|
|
244
|
+
;
|
|
245
|
+
"use strict";
|
|
246
|
+
var $;
|
|
247
|
+
(function ($) {
|
|
248
|
+
class $mol_term_color {
|
|
249
|
+
static reset = this.ansi(0, 0);
|
|
250
|
+
static bold = this.ansi(1, 22);
|
|
251
|
+
static italic = this.ansi(3, 23);
|
|
252
|
+
static underline = this.ansi(4, 24);
|
|
253
|
+
static inverse = this.ansi(7, 27);
|
|
254
|
+
static hidden = this.ansi(8, 28);
|
|
255
|
+
static strike = this.ansi(9, 29);
|
|
256
|
+
static gray = this.ansi(90, 39);
|
|
257
|
+
static red = this.ansi(91, 39);
|
|
258
|
+
static green = this.ansi(92, 39);
|
|
259
|
+
static yellow = this.ansi(93, 39);
|
|
260
|
+
static blue = this.ansi(94, 39);
|
|
261
|
+
static magenta = this.ansi(95, 39);
|
|
262
|
+
static cyan = this.ansi(96, 39);
|
|
263
|
+
static Gray = (str) => this.inverse(this.gray(str));
|
|
264
|
+
static Red = (str) => this.inverse(this.red(str));
|
|
265
|
+
static Green = (str) => this.inverse(this.green(str));
|
|
266
|
+
static Yellow = (str) => this.inverse(this.yellow(str));
|
|
267
|
+
static Blue = (str) => this.inverse(this.blue(str));
|
|
268
|
+
static Magenta = (str) => this.inverse(this.magenta(str));
|
|
269
|
+
static Cyan = (str) => this.inverse(this.cyan(str));
|
|
270
|
+
static ansi(open, close) {
|
|
271
|
+
if (typeof process === 'undefined')
|
|
272
|
+
return String;
|
|
273
|
+
if (!process.stdout.isTTY)
|
|
274
|
+
return String;
|
|
275
|
+
const prefix = `\x1b[${open}m`;
|
|
276
|
+
const postfix = `\x1b[${close}m`;
|
|
277
|
+
const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
|
|
278
|
+
return function colorer(str) {
|
|
279
|
+
str = String(str);
|
|
280
|
+
if (str === '')
|
|
281
|
+
return str;
|
|
282
|
+
const suffix = str.replace(suffix_regexp, prefix);
|
|
283
|
+
return prefix + suffix + postfix;
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
$.$mol_term_color = $mol_term_color;
|
|
288
|
+
})($ || ($ = {}));
|
|
289
|
+
//mol/term/color/color.ts
|
|
290
|
+
;
|
|
291
|
+
"use strict";
|
|
292
|
+
var $;
|
|
293
|
+
(function ($) {
|
|
294
|
+
function $mol_log3_node_make(level, output, type, color) {
|
|
295
|
+
return function $mol_log3_logger(event) {
|
|
296
|
+
if (!event.time)
|
|
297
|
+
event = { time: new Date().toISOString(), ...event };
|
|
298
|
+
const tree = this.$mol_tree.fromJSON(event).clone({ type });
|
|
299
|
+
let str = color(tree.toString());
|
|
300
|
+
this.console[level](str);
|
|
301
|
+
const self = this;
|
|
302
|
+
return () => self.console.groupEnd();
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
$.$mol_log3_node_make = $mol_log3_node_make;
|
|
306
|
+
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
|
|
307
|
+
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
|
|
308
|
+
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
|
|
309
|
+
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
|
|
310
|
+
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
|
|
311
|
+
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
|
|
312
|
+
})($ || ($ = {}));
|
|
313
|
+
//mol/log3/log3.node.ts
|
|
314
|
+
;
|
|
315
|
+
"use strict";
|
|
316
|
+
var $;
|
|
317
|
+
(function ($_1) {
|
|
318
|
+
$mol_test_mocks.push($ => {
|
|
319
|
+
$.$mol_log3_come = () => { };
|
|
320
|
+
$.$mol_log3_done = () => { };
|
|
321
|
+
$.$mol_log3_fail = () => { };
|
|
322
|
+
$.$mol_log3_warn = () => { };
|
|
323
|
+
$.$mol_log3_rise = () => { };
|
|
324
|
+
$.$mol_log3_area = () => () => { };
|
|
325
|
+
});
|
|
326
|
+
})($ || ($ = {}));
|
|
327
|
+
//mol/log3/log3.test.ts
|
|
328
|
+
;
|
|
329
|
+
"use strict";
|
|
330
|
+
var $;
|
|
331
|
+
(function ($) {
|
|
332
|
+
function $mol_env() {
|
|
333
|
+
return {};
|
|
334
|
+
}
|
|
335
|
+
$.$mol_env = $mol_env;
|
|
336
|
+
})($ || ($ = {}));
|
|
337
|
+
//mol/env/env.ts
|
|
338
|
+
;
|
|
339
|
+
"use strict";
|
|
340
|
+
var $;
|
|
341
|
+
(function ($) {
|
|
342
|
+
$.$mol_env = function $mol_env() {
|
|
343
|
+
return this.process.env;
|
|
344
|
+
};
|
|
345
|
+
})($ || ($ = {}));
|
|
346
|
+
//mol/env/env.node.ts
|
|
347
|
+
;
|
|
348
|
+
"use strict";
|
|
349
|
+
var $;
|
|
350
|
+
(function ($) {
|
|
351
|
+
function $mol_exec(dir, command, ...args) {
|
|
352
|
+
let [app, ...args0] = command.split(' ');
|
|
353
|
+
args = [...args0, ...args];
|
|
354
|
+
this.$mol_log3_come({
|
|
355
|
+
place: '$mol_exec',
|
|
356
|
+
dir: $node.path.relative('', dir),
|
|
357
|
+
message: 'Run',
|
|
358
|
+
command: `${app} ${args.join(' ')}`,
|
|
359
|
+
});
|
|
360
|
+
var res = $node['child_process'].spawnSync(app, args, {
|
|
361
|
+
cwd: $node.path.resolve(dir),
|
|
362
|
+
shell: true,
|
|
363
|
+
env: this.$mol_env(),
|
|
364
|
+
});
|
|
365
|
+
if (res.status || res.error)
|
|
366
|
+
return $mol_fail(res.error || new Error(res.stderr.toString()));
|
|
367
|
+
if (!res.stdout)
|
|
368
|
+
res.stdout = Buffer.from([]);
|
|
369
|
+
return res;
|
|
370
|
+
}
|
|
371
|
+
$.$mol_exec = $mol_exec;
|
|
372
|
+
})($ || ($ = {}));
|
|
373
|
+
//mol/exec/exec.node.ts
|
|
374
|
+
;
|
|
375
|
+
"use strict";
|
|
376
|
+
var $;
|
|
377
|
+
(function ($) {
|
|
378
|
+
$.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
|
|
379
|
+
})($ || ($ = {}));
|
|
380
|
+
//mol/dom/context/context.node.ts
|
|
381
|
+
;
|
|
382
|
+
"use strict";
|
|
383
|
+
var $;
|
|
384
|
+
(function ($) {
|
|
385
|
+
function $mol_dom_render_children(el, childNodes) {
|
|
386
|
+
const node_set = new Set(childNodes);
|
|
387
|
+
let nextNode = el.firstChild;
|
|
388
|
+
for (let view of childNodes) {
|
|
389
|
+
if (view == null)
|
|
390
|
+
continue;
|
|
391
|
+
if (view instanceof $mol_dom_context.Node) {
|
|
392
|
+
while (true) {
|
|
393
|
+
if (!nextNode) {
|
|
394
|
+
el.appendChild(view);
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
if (nextNode == view) {
|
|
398
|
+
nextNode = nextNode.nextSibling;
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
if (node_set.has(nextNode)) {
|
|
403
|
+
el.insertBefore(view, nextNode);
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
const nn = nextNode.nextSibling;
|
|
408
|
+
el.removeChild(nextNode);
|
|
409
|
+
nextNode = nn;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
if (nextNode && nextNode.nodeName === '#text') {
|
|
416
|
+
const str = String(view);
|
|
417
|
+
if (nextNode.nodeValue !== str)
|
|
418
|
+
nextNode.nodeValue = str;
|
|
419
|
+
nextNode = nextNode.nextSibling;
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
const textNode = $mol_dom_context.document.createTextNode(String(view));
|
|
423
|
+
el.insertBefore(textNode, nextNode);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
while (nextNode) {
|
|
428
|
+
const currNode = nextNode;
|
|
429
|
+
nextNode = currNode.nextSibling;
|
|
430
|
+
el.removeChild(currNode);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
$.$mol_dom_render_children = $mol_dom_render_children;
|
|
434
|
+
})($ || ($ = {}));
|
|
435
|
+
//mol/dom/render/children/children.ts
|
|
436
|
+
;
|
|
437
|
+
"use strict";
|
|
438
|
+
//mol/type/error/error.ts
|
|
439
|
+
;
|
|
440
|
+
"use strict";
|
|
441
|
+
//mol/type/assert/assert.test.ts
|
|
442
|
+
;
|
|
443
|
+
"use strict";
|
|
444
|
+
//mol/type/assert/assert.ts
|
|
445
|
+
;
|
|
446
|
+
"use strict";
|
|
447
|
+
//mol/type/equals/equals.test.ts
|
|
448
|
+
;
|
|
449
|
+
"use strict";
|
|
450
|
+
//mol/type/equals/equals.ts
|
|
451
|
+
;
|
|
452
|
+
"use strict";
|
|
453
|
+
//mol/type/partial/deep/deep.test.ts
|
|
454
|
+
;
|
|
455
|
+
"use strict";
|
|
456
|
+
//mol/type/partial/deep/deep.ts
|
|
457
|
+
;
|
|
458
|
+
"use strict";
|
|
459
|
+
var $;
|
|
460
|
+
(function ($) {
|
|
461
|
+
$mol_test({
|
|
462
|
+
'Make empty div'() {
|
|
463
|
+
$mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
|
|
464
|
+
},
|
|
465
|
+
'Define native field'() {
|
|
466
|
+
const dom = $mol_jsx("input", { value: '123' });
|
|
467
|
+
$mol_assert_equal(dom.outerHTML, '<input value="123">');
|
|
468
|
+
$mol_assert_equal(dom.value, '123');
|
|
469
|
+
},
|
|
470
|
+
'Define classes'() {
|
|
471
|
+
const dom = $mol_jsx("div", { class: 'foo bar' });
|
|
472
|
+
$mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
|
|
473
|
+
},
|
|
474
|
+
'Define styles'() {
|
|
475
|
+
const dom = $mol_jsx("div", { style: { color: 'red' } });
|
|
476
|
+
$mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
|
|
477
|
+
},
|
|
478
|
+
'Define dataset'() {
|
|
479
|
+
const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
|
|
480
|
+
$mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
|
|
481
|
+
},
|
|
482
|
+
'Define attributes'() {
|
|
483
|
+
const dom = $mol_jsx("div", { lang: "ru", hidden: true });
|
|
484
|
+
$mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
|
|
485
|
+
},
|
|
486
|
+
'Define child nodes'() {
|
|
487
|
+
const dom = $mol_jsx("div", null,
|
|
488
|
+
"hello",
|
|
489
|
+
$mol_jsx("strong", null, "world"),
|
|
490
|
+
"!");
|
|
491
|
+
$mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
|
|
492
|
+
},
|
|
493
|
+
'Function as component'() {
|
|
494
|
+
const Button = (props, target) => {
|
|
495
|
+
return $mol_jsx("button", { title: props.hint }, target());
|
|
496
|
+
};
|
|
497
|
+
const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
|
|
498
|
+
$mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
|
|
499
|
+
},
|
|
500
|
+
'Nested guid generation'() {
|
|
501
|
+
const Foo = () => {
|
|
502
|
+
return $mol_jsx("div", null,
|
|
503
|
+
$mol_jsx(Bar, { id: "bar" },
|
|
504
|
+
$mol_jsx("img", { id: "icon" })));
|
|
505
|
+
};
|
|
506
|
+
const Bar = (props, icon) => {
|
|
507
|
+
return $mol_jsx("span", null,
|
|
508
|
+
icon,
|
|
509
|
+
$mol_jsx("i", { id: "label" }));
|
|
510
|
+
};
|
|
511
|
+
const dom = $mol_jsx(Foo, { id: "foo" });
|
|
512
|
+
$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>');
|
|
513
|
+
},
|
|
514
|
+
'Fail on non unique ids'() {
|
|
515
|
+
const App = () => {
|
|
516
|
+
return $mol_jsx("div", null,
|
|
517
|
+
$mol_jsx("span", { id: "bar" }),
|
|
518
|
+
$mol_jsx("span", { id: "bar" }));
|
|
519
|
+
};
|
|
520
|
+
$mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
|
|
521
|
+
},
|
|
522
|
+
'Owner based guid generationn'() {
|
|
523
|
+
const Foo = () => {
|
|
524
|
+
return $mol_jsx("div", null,
|
|
525
|
+
$mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
526
|
+
};
|
|
527
|
+
const Bar = (props) => {
|
|
528
|
+
return $mol_jsx("span", null, props.icon());
|
|
529
|
+
};
|
|
530
|
+
const dom = $mol_jsx(Foo, { id: "app" });
|
|
531
|
+
$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>');
|
|
532
|
+
},
|
|
533
|
+
'Fail on same ids from different caller'() {
|
|
534
|
+
const Foo = () => {
|
|
535
|
+
return $mol_jsx("div", null,
|
|
536
|
+
$mol_jsx("img", { id: "icon" }),
|
|
537
|
+
$mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
538
|
+
};
|
|
539
|
+
const Bar = (props) => {
|
|
540
|
+
return $mol_jsx("span", null, props.icon());
|
|
541
|
+
};
|
|
542
|
+
$mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
|
|
543
|
+
},
|
|
544
|
+
});
|
|
545
|
+
})($ || ($ = {}));
|
|
546
|
+
//mol/jsx/jsx.test.tsx
|
|
547
|
+
;
|
|
548
|
+
"use strict";
|
|
549
|
+
var $;
|
|
550
|
+
(function ($) {
|
|
551
|
+
$.$mol_jsx_prefix = '';
|
|
552
|
+
$.$mol_jsx_crumbs = '';
|
|
553
|
+
$.$mol_jsx_booked = null;
|
|
554
|
+
$.$mol_jsx_document = {
|
|
555
|
+
getElementById: () => null,
|
|
556
|
+
createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
|
|
557
|
+
createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
|
|
558
|
+
};
|
|
559
|
+
$.$mol_jsx_frag = '';
|
|
560
|
+
function $mol_jsx(Elem, props, ...childNodes) {
|
|
561
|
+
const id = props && props.id || '';
|
|
562
|
+
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
563
|
+
const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
|
|
564
|
+
if (Elem && $.$mol_jsx_booked) {
|
|
565
|
+
if ($.$mol_jsx_booked.has(id)) {
|
|
566
|
+
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
|
|
567
|
+
}
|
|
568
|
+
else {
|
|
569
|
+
$.$mol_jsx_booked.add(id);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
|
|
573
|
+
if ($.$mol_jsx_prefix) {
|
|
574
|
+
const prefix_ext = $.$mol_jsx_prefix;
|
|
575
|
+
const booked_ext = $.$mol_jsx_booked;
|
|
576
|
+
const crumbs_ext = $.$mol_jsx_crumbs;
|
|
577
|
+
for (const field in props) {
|
|
578
|
+
const func = props[field];
|
|
579
|
+
if (typeof func !== 'function')
|
|
580
|
+
continue;
|
|
581
|
+
const wrapper = function (...args) {
|
|
582
|
+
const prefix = $.$mol_jsx_prefix;
|
|
583
|
+
const booked = $.$mol_jsx_booked;
|
|
584
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
585
|
+
try {
|
|
586
|
+
$.$mol_jsx_prefix = prefix_ext;
|
|
587
|
+
$.$mol_jsx_booked = booked_ext;
|
|
588
|
+
$.$mol_jsx_crumbs = crumbs_ext;
|
|
589
|
+
return func.call(this, ...args);
|
|
590
|
+
}
|
|
591
|
+
finally {
|
|
592
|
+
$.$mol_jsx_prefix = prefix;
|
|
593
|
+
$.$mol_jsx_booked = booked;
|
|
594
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
$mol_func_name_from(wrapper, func);
|
|
598
|
+
props[field] = wrapper;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
if (typeof Elem !== 'string') {
|
|
602
|
+
if ('prototype' in Elem) {
|
|
603
|
+
const view = node && node[Elem] || new Elem;
|
|
604
|
+
Object.assign(view, props);
|
|
605
|
+
view[Symbol.toStringTag] = guid;
|
|
606
|
+
view.childNodes = childNodes;
|
|
607
|
+
if (!view.ownerDocument)
|
|
608
|
+
view.ownerDocument = $.$mol_jsx_document;
|
|
609
|
+
view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
610
|
+
node = view.valueOf();
|
|
611
|
+
node[Elem] = view;
|
|
612
|
+
return node;
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
const prefix = $.$mol_jsx_prefix;
|
|
616
|
+
const booked = $.$mol_jsx_booked;
|
|
617
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
618
|
+
try {
|
|
619
|
+
$.$mol_jsx_prefix = guid;
|
|
620
|
+
$.$mol_jsx_booked = new Set;
|
|
621
|
+
$.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
622
|
+
return Elem(props, ...childNodes);
|
|
623
|
+
}
|
|
624
|
+
finally {
|
|
625
|
+
$.$mol_jsx_prefix = prefix;
|
|
626
|
+
$.$mol_jsx_booked = booked;
|
|
627
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
if (!node) {
|
|
632
|
+
node = Elem
|
|
633
|
+
? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
|
|
634
|
+
: $.$mol_jsx_document.createDocumentFragment();
|
|
635
|
+
}
|
|
636
|
+
$mol_dom_render_children(node, [].concat(...childNodes));
|
|
637
|
+
if (!Elem)
|
|
638
|
+
return node;
|
|
639
|
+
if (guid)
|
|
640
|
+
node.id = guid;
|
|
641
|
+
for (const key in props) {
|
|
642
|
+
if (key === 'id')
|
|
643
|
+
continue;
|
|
644
|
+
if (typeof props[key] === 'string') {
|
|
645
|
+
if (typeof node[key] === 'string')
|
|
646
|
+
node[key] = props[key];
|
|
647
|
+
node.setAttribute(key, props[key]);
|
|
648
|
+
}
|
|
649
|
+
else if (props[key] &&
|
|
650
|
+
typeof props[key] === 'object' &&
|
|
651
|
+
Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
|
|
652
|
+
if (typeof node[key] === 'object') {
|
|
653
|
+
Object.assign(node[key], props[key]);
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
else {
|
|
658
|
+
node[key] = props[key];
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
if ($.$mol_jsx_crumbs)
|
|
662
|
+
node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
|
|
663
|
+
return node;
|
|
664
|
+
}
|
|
665
|
+
$.$mol_jsx = $mol_jsx;
|
|
666
|
+
})($ || ($ = {}));
|
|
667
|
+
//mol/jsx/jsx.ts
|
|
668
|
+
;
|
|
669
|
+
"use strict";
|
|
670
|
+
var $;
|
|
671
|
+
(function ($) {
|
|
672
|
+
$mol_test({
|
|
673
|
+
'nulls & undefineds'() {
|
|
674
|
+
$mol_assert_ok($mol_compare_deep(null, null));
|
|
675
|
+
$mol_assert_ok($mol_compare_deep(undefined, undefined));
|
|
676
|
+
$mol_assert_not($mol_compare_deep(undefined, null));
|
|
677
|
+
$mol_assert_not($mol_compare_deep({}, null));
|
|
678
|
+
},
|
|
679
|
+
'number'() {
|
|
680
|
+
$mol_assert_ok($mol_compare_deep(1, 1));
|
|
681
|
+
$mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
|
|
682
|
+
$mol_assert_not($mol_compare_deep(1, 2));
|
|
683
|
+
$mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
|
|
684
|
+
$mol_assert_not($mol_compare_deep(Object(1), Object(2)));
|
|
685
|
+
},
|
|
686
|
+
'POJO'() {
|
|
687
|
+
$mol_assert_ok($mol_compare_deep({}, {}));
|
|
688
|
+
$mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
|
|
689
|
+
$mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
|
|
690
|
+
$mol_assert_not($mol_compare_deep({}, { a: undefined }));
|
|
691
|
+
$mol_assert_ok($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
|
|
692
|
+
$mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
|
|
693
|
+
},
|
|
694
|
+
'Array'() {
|
|
695
|
+
$mol_assert_ok($mol_compare_deep([], []));
|
|
696
|
+
$mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
|
|
697
|
+
$mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
|
|
698
|
+
$mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
|
|
699
|
+
},
|
|
700
|
+
'Non POJO are different'() {
|
|
701
|
+
class Thing extends Object {
|
|
702
|
+
}
|
|
703
|
+
$mol_assert_not($mol_compare_deep(new Thing, new Thing));
|
|
704
|
+
$mol_assert_not($mol_compare_deep(() => 1, () => 1));
|
|
705
|
+
$mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
|
|
706
|
+
},
|
|
707
|
+
'same POJOs with cyclic reference'() {
|
|
708
|
+
const a = { foo: {} };
|
|
709
|
+
a['self'] = a;
|
|
710
|
+
const b = { foo: {} };
|
|
711
|
+
b['self'] = b;
|
|
712
|
+
$mol_assert_ok($mol_compare_deep(a, b));
|
|
713
|
+
},
|
|
714
|
+
'Date'() {
|
|
715
|
+
$mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
|
|
716
|
+
$mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
|
|
717
|
+
},
|
|
718
|
+
'RegExp'() {
|
|
719
|
+
$mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
|
|
720
|
+
$mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
|
|
721
|
+
$mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
|
|
722
|
+
},
|
|
723
|
+
'Error'() {
|
|
724
|
+
$mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
|
|
725
|
+
const fail = (message) => new Error(message);
|
|
726
|
+
$mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
|
|
727
|
+
$mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
|
|
728
|
+
},
|
|
729
|
+
'Map'() {
|
|
730
|
+
$mol_assert_ok($mol_compare_deep(new Map, new Map));
|
|
731
|
+
$mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
|
|
732
|
+
$mol_assert_ok($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
|
|
733
|
+
$mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
|
|
734
|
+
$mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[3], 2]])));
|
|
735
|
+
},
|
|
736
|
+
'Set'() {
|
|
737
|
+
$mol_assert_ok($mol_compare_deep(new Set, new Set));
|
|
738
|
+
$mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
|
|
739
|
+
$mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
|
|
740
|
+
},
|
|
741
|
+
'Uint8Array'() {
|
|
742
|
+
$mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
|
|
743
|
+
$mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
|
|
744
|
+
$mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
|
|
745
|
+
},
|
|
746
|
+
'Custom comparator'() {
|
|
747
|
+
class User {
|
|
748
|
+
name;
|
|
749
|
+
rand;
|
|
750
|
+
constructor(name, rand = Math.random()) {
|
|
751
|
+
this.name = name;
|
|
752
|
+
this.rand = rand;
|
|
753
|
+
}
|
|
754
|
+
[Symbol.toPrimitive](mode) {
|
|
755
|
+
return this.name;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
$mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
|
|
759
|
+
$mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
|
|
760
|
+
},
|
|
761
|
+
});
|
|
762
|
+
})($ || ($ = {}));
|
|
763
|
+
//mol/compare/deep/deep.test.tsx
|
|
764
|
+
;
|
|
765
|
+
"use strict";
|
|
766
|
+
var $;
|
|
767
|
+
(function ($) {
|
|
768
|
+
$.$mol_compare_deep_cache = new WeakMap();
|
|
769
|
+
function $mol_compare_deep(left, right) {
|
|
770
|
+
if (Object.is(left, right))
|
|
771
|
+
return true;
|
|
772
|
+
if (left === null)
|
|
773
|
+
return false;
|
|
774
|
+
if (right === null)
|
|
775
|
+
return false;
|
|
776
|
+
if (typeof left !== 'object')
|
|
777
|
+
return false;
|
|
778
|
+
if (typeof right !== 'object')
|
|
779
|
+
return false;
|
|
780
|
+
const left_proto = Reflect.getPrototypeOf(left);
|
|
781
|
+
const right_proto = Reflect.getPrototypeOf(right);
|
|
782
|
+
if (left_proto !== right_proto)
|
|
783
|
+
return false;
|
|
784
|
+
if (left instanceof Boolean)
|
|
785
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
786
|
+
if (left instanceof Number)
|
|
787
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
788
|
+
if (left instanceof String)
|
|
789
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
790
|
+
if (left instanceof Date)
|
|
791
|
+
return Object.is(left.valueOf(), right['valueOf']());
|
|
792
|
+
if (left instanceof RegExp)
|
|
793
|
+
return left.source === right['source'] && left.flags === right['flags'];
|
|
794
|
+
if (left instanceof Error)
|
|
795
|
+
return left.message === right['message'] && left.stack === right['stack'];
|
|
796
|
+
let left_cache = $.$mol_compare_deep_cache.get(left);
|
|
797
|
+
if (left_cache) {
|
|
798
|
+
const right_cache = left_cache.get(right);
|
|
799
|
+
if (typeof right_cache === 'boolean')
|
|
800
|
+
return right_cache;
|
|
801
|
+
}
|
|
802
|
+
else {
|
|
803
|
+
left_cache = new WeakMap([[right, true]]);
|
|
804
|
+
$.$mol_compare_deep_cache.set(left, left_cache);
|
|
805
|
+
}
|
|
806
|
+
let result;
|
|
807
|
+
try {
|
|
808
|
+
if (left_proto && !Reflect.getPrototypeOf(left_proto))
|
|
809
|
+
result = compare_pojo(left, right);
|
|
810
|
+
else if (Array.isArray(left))
|
|
811
|
+
result = compare_array(left, right);
|
|
812
|
+
else if (left instanceof Set)
|
|
813
|
+
result = compare_set(left, right);
|
|
814
|
+
else if (left instanceof Map)
|
|
815
|
+
result = compare_map(left, right);
|
|
816
|
+
else if (ArrayBuffer.isView(left))
|
|
817
|
+
result = compare_buffer(left, right);
|
|
818
|
+
else if (Symbol.toPrimitive in left)
|
|
819
|
+
result = compare_primitive(left, right);
|
|
820
|
+
else
|
|
821
|
+
result = false;
|
|
822
|
+
}
|
|
823
|
+
finally {
|
|
824
|
+
left_cache.set(right, result);
|
|
825
|
+
}
|
|
826
|
+
return result;
|
|
827
|
+
}
|
|
828
|
+
$.$mol_compare_deep = $mol_compare_deep;
|
|
829
|
+
function compare_array(left, right) {
|
|
830
|
+
const len = left.length;
|
|
831
|
+
if (len !== right.length)
|
|
832
|
+
return false;
|
|
833
|
+
for (let i = 0; i < len; ++i) {
|
|
834
|
+
if (!$mol_compare_deep(left[i], right[i]))
|
|
835
|
+
return false;
|
|
836
|
+
}
|
|
837
|
+
return true;
|
|
838
|
+
}
|
|
839
|
+
function compare_buffer(left, right) {
|
|
840
|
+
const len = left.byteLength;
|
|
841
|
+
if (len !== right.byteLength)
|
|
842
|
+
return false;
|
|
843
|
+
for (let i = 0; i < len; ++i) {
|
|
844
|
+
if (left[i] !== right[i])
|
|
845
|
+
return false;
|
|
846
|
+
}
|
|
847
|
+
return true;
|
|
848
|
+
}
|
|
849
|
+
function compare_iterator(left, right) {
|
|
850
|
+
while (true) {
|
|
851
|
+
const left_next = left.next();
|
|
852
|
+
const right_next = right.next();
|
|
853
|
+
if (left_next.done !== right_next.done)
|
|
854
|
+
return false;
|
|
855
|
+
if (left_next.done)
|
|
856
|
+
break;
|
|
857
|
+
if (!$mol_compare_deep(left_next.value, right_next.value))
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
860
|
+
return true;
|
|
861
|
+
}
|
|
862
|
+
function compare_set(left, right) {
|
|
863
|
+
if (left.size !== right.size)
|
|
864
|
+
return false;
|
|
865
|
+
return compare_iterator(left.values(), right.values());
|
|
866
|
+
}
|
|
867
|
+
function compare_map(left, right) {
|
|
868
|
+
if (left.size !== right.size)
|
|
869
|
+
return false;
|
|
870
|
+
return compare_iterator(left.keys(), right.keys())
|
|
871
|
+
&& compare_iterator(left.values(), right.values());
|
|
872
|
+
}
|
|
873
|
+
function compare_pojo(left, right) {
|
|
874
|
+
const left_keys = Object.getOwnPropertyNames(left);
|
|
875
|
+
const right_keys = Object.getOwnPropertyNames(right);
|
|
876
|
+
if (left_keys.length !== right_keys.length)
|
|
877
|
+
return false;
|
|
878
|
+
for (let key of left_keys) {
|
|
879
|
+
if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
|
|
880
|
+
return false;
|
|
881
|
+
}
|
|
882
|
+
return true;
|
|
883
|
+
}
|
|
884
|
+
function compare_primitive(left, right) {
|
|
885
|
+
return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
|
|
886
|
+
}
|
|
887
|
+
})($ || ($ = {}));
|
|
888
|
+
//mol/compare/deep/deep.ts
|
|
889
|
+
;
|
|
890
|
+
"use strict";
|
|
891
|
+
var $;
|
|
892
|
+
(function ($) {
|
|
893
|
+
function $mol_dom_serialize(node) {
|
|
894
|
+
const serializer = new $mol_dom_context.XMLSerializer;
|
|
895
|
+
return serializer.serializeToString(node);
|
|
896
|
+
}
|
|
897
|
+
$.$mol_dom_serialize = $mol_dom_serialize;
|
|
898
|
+
})($ || ($ = {}));
|
|
899
|
+
//mol/dom/serialize/serialize.ts
|
|
900
|
+
;
|
|
901
|
+
"use strict";
|
|
902
|
+
var $;
|
|
903
|
+
(function ($) {
|
|
904
|
+
$mol_test({
|
|
905
|
+
'must be false'() {
|
|
906
|
+
$mol_assert_not(0);
|
|
907
|
+
},
|
|
908
|
+
'must be true'() {
|
|
909
|
+
$mol_assert_ok(1);
|
|
910
|
+
},
|
|
911
|
+
'two must be equal'() {
|
|
912
|
+
$mol_assert_equal(2, 2);
|
|
913
|
+
},
|
|
914
|
+
'three must be equal'() {
|
|
915
|
+
$mol_assert_equal(2, 2, 2);
|
|
916
|
+
},
|
|
917
|
+
'two must be unique'() {
|
|
918
|
+
$mol_assert_unique([3], [3]);
|
|
919
|
+
},
|
|
920
|
+
'three must be unique'() {
|
|
921
|
+
$mol_assert_unique([3], [3], [3]);
|
|
922
|
+
},
|
|
923
|
+
'two must be alike'() {
|
|
924
|
+
$mol_assert_like([3], [3]);
|
|
925
|
+
},
|
|
926
|
+
'three must be alike'() {
|
|
927
|
+
$mol_assert_like([3], [3], [3]);
|
|
928
|
+
},
|
|
929
|
+
});
|
|
930
|
+
})($ || ($ = {}));
|
|
931
|
+
//mol/assert/assert.test.ts
|
|
932
|
+
;
|
|
933
|
+
"use strict";
|
|
934
|
+
var $;
|
|
935
|
+
(function ($) {
|
|
936
|
+
function $mol_assert_ok(value) {
|
|
937
|
+
if (value)
|
|
938
|
+
return;
|
|
939
|
+
$mol_fail(new Error(`${value} ≠ true`));
|
|
940
|
+
}
|
|
941
|
+
$.$mol_assert_ok = $mol_assert_ok;
|
|
942
|
+
function $mol_assert_not(value) {
|
|
943
|
+
if (!value)
|
|
944
|
+
return;
|
|
945
|
+
$mol_fail(new Error(`${value} ≠ false`));
|
|
946
|
+
}
|
|
947
|
+
$.$mol_assert_not = $mol_assert_not;
|
|
948
|
+
function $mol_assert_fail(handler, ErrorRight) {
|
|
949
|
+
const fail = $.$mol_fail;
|
|
950
|
+
try {
|
|
951
|
+
$.$mol_fail = $.$mol_fail_hidden;
|
|
952
|
+
handler();
|
|
953
|
+
}
|
|
954
|
+
catch (error) {
|
|
955
|
+
if (!ErrorRight)
|
|
956
|
+
return error;
|
|
957
|
+
$.$mol_fail = fail;
|
|
958
|
+
if (typeof ErrorRight === 'string') {
|
|
959
|
+
$mol_assert_equal(error.message, ErrorRight);
|
|
960
|
+
}
|
|
961
|
+
else {
|
|
962
|
+
$mol_assert_ok(error instanceof ErrorRight);
|
|
963
|
+
}
|
|
964
|
+
return error;
|
|
965
|
+
}
|
|
966
|
+
finally {
|
|
967
|
+
$.$mol_fail = fail;
|
|
968
|
+
}
|
|
969
|
+
$mol_fail(new Error('Not failed'));
|
|
970
|
+
}
|
|
971
|
+
$.$mol_assert_fail = $mol_assert_fail;
|
|
972
|
+
function $mol_assert_equal(...args) {
|
|
973
|
+
for (let i = 0; i < args.length; ++i) {
|
|
974
|
+
for (let j = 0; j < args.length; ++j) {
|
|
975
|
+
if (i === j)
|
|
976
|
+
continue;
|
|
977
|
+
if (Number.isNaN(args[i]) && Number.isNaN(args[j]))
|
|
978
|
+
continue;
|
|
979
|
+
if (args[i] !== args[j])
|
|
980
|
+
$mol_fail(new Error(`Not equal (${i + 1}:${j + 1})\n${args[i]}\n${args[j]}`));
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
$.$mol_assert_equal = $mol_assert_equal;
|
|
985
|
+
function $mol_assert_unique(...args) {
|
|
986
|
+
for (let i = 0; i < args.length; ++i) {
|
|
987
|
+
for (let j = 0; j < args.length; ++j) {
|
|
988
|
+
if (i === j)
|
|
989
|
+
continue;
|
|
990
|
+
if (args[i] === args[j] || (Number.isNaN(args[i]) && Number.isNaN(args[j]))) {
|
|
991
|
+
$mol_fail(new Error(`args[${i}] = args[${j}] = ${args[i]}`));
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
$.$mol_assert_unique = $mol_assert_unique;
|
|
997
|
+
function $mol_assert_like(head, ...tail) {
|
|
998
|
+
for (let [index, value] of Object.entries(tail)) {
|
|
999
|
+
if (!$mol_compare_deep(value, head)) {
|
|
1000
|
+
const print = (val) => {
|
|
1001
|
+
if (!val)
|
|
1002
|
+
return val;
|
|
1003
|
+
if (typeof val !== 'object')
|
|
1004
|
+
return val;
|
|
1005
|
+
if ('outerHTML' in val)
|
|
1006
|
+
return val.outerHTML;
|
|
1007
|
+
try {
|
|
1008
|
+
return JSON.stringify(val);
|
|
1009
|
+
}
|
|
1010
|
+
catch (error) {
|
|
1011
|
+
console.error(error);
|
|
1012
|
+
return val;
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
return $mol_fail(new Error(`Not like (1:${+index + 2})\n${print(head)}\n---\n${print(value)}`));
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
$.$mol_assert_like = $mol_assert_like;
|
|
1020
|
+
function $mol_assert_dom(left, right) {
|
|
1021
|
+
$mol_assert_equal($mol_dom_serialize(left), $mol_dom_serialize(right));
|
|
1022
|
+
}
|
|
1023
|
+
$.$mol_assert_dom = $mol_assert_dom;
|
|
1024
|
+
})($ || ($ = {}));
|
|
1025
|
+
//mol/assert/assert.ts
|
|
1026
|
+
;
|
|
1027
|
+
"use strict";
|
|
1028
|
+
var $;
|
|
1029
|
+
(function ($) {
|
|
1030
|
+
$.$mol_ambient_ref = Symbol('$mol_ambient_ref');
|
|
1031
|
+
function $mol_ambient(overrides) {
|
|
1032
|
+
return Object.setPrototypeOf(overrides, this || $);
|
|
1033
|
+
}
|
|
1034
|
+
$.$mol_ambient = $mol_ambient;
|
|
1035
|
+
})($ || ($ = {}));
|
|
1036
|
+
//mol/ambient/ambient.ts
|
|
1037
|
+
;
|
|
1038
|
+
"use strict";
|
|
1039
|
+
var $;
|
|
1040
|
+
(function ($) {
|
|
1041
|
+
$mol_test({
|
|
1042
|
+
'get'() {
|
|
1043
|
+
const proxy = $mol_delegate({}, () => ({ foo: 777 }));
|
|
1044
|
+
$mol_assert_equal(proxy.foo, 777);
|
|
1045
|
+
},
|
|
1046
|
+
'has'() {
|
|
1047
|
+
const proxy = $mol_delegate({}, () => ({ foo: 777 }));
|
|
1048
|
+
$mol_assert_equal('foo' in proxy, true);
|
|
1049
|
+
},
|
|
1050
|
+
'set'() {
|
|
1051
|
+
const target = { foo: 777 };
|
|
1052
|
+
const proxy = $mol_delegate({}, () => target);
|
|
1053
|
+
proxy.foo = 123;
|
|
1054
|
+
$mol_assert_equal(target.foo, 123);
|
|
1055
|
+
},
|
|
1056
|
+
'getOwnPropertyDescriptor'() {
|
|
1057
|
+
const proxy = $mol_delegate({}, () => ({ foo: 777 }));
|
|
1058
|
+
$mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
|
|
1059
|
+
value: 777,
|
|
1060
|
+
writable: true,
|
|
1061
|
+
enumerable: true,
|
|
1062
|
+
configurable: true,
|
|
1063
|
+
});
|
|
1064
|
+
},
|
|
1065
|
+
'ownKeys'() {
|
|
1066
|
+
const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
|
|
1067
|
+
$mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
|
|
1068
|
+
},
|
|
1069
|
+
'getPrototypeOf'() {
|
|
1070
|
+
class Foo {
|
|
1071
|
+
}
|
|
1072
|
+
const proxy = $mol_delegate({}, () => new Foo);
|
|
1073
|
+
$mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
|
|
1074
|
+
},
|
|
1075
|
+
'setPrototypeOf'() {
|
|
1076
|
+
class Foo {
|
|
1077
|
+
}
|
|
1078
|
+
const target = {};
|
|
1079
|
+
const proxy = $mol_delegate({}, () => target);
|
|
1080
|
+
Object.setPrototypeOf(proxy, Foo.prototype);
|
|
1081
|
+
$mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
|
|
1082
|
+
},
|
|
1083
|
+
'instanceof'() {
|
|
1084
|
+
class Foo {
|
|
1085
|
+
}
|
|
1086
|
+
const proxy = $mol_delegate({}, () => new Foo);
|
|
1087
|
+
$mol_assert_ok(proxy instanceof Foo);
|
|
1088
|
+
$mol_assert_ok(proxy instanceof $mol_delegate);
|
|
1089
|
+
},
|
|
1090
|
+
'autobind'() {
|
|
1091
|
+
class Foo {
|
|
1092
|
+
}
|
|
1093
|
+
const proxy = $mol_delegate({}, () => new Foo);
|
|
1094
|
+
$mol_assert_ok(proxy instanceof Foo);
|
|
1095
|
+
$mol_assert_ok(proxy instanceof $mol_delegate);
|
|
1096
|
+
},
|
|
1097
|
+
});
|
|
1098
|
+
})($ || ($ = {}));
|
|
1099
|
+
//mol/delegate/delegate.test.ts
|
|
1100
|
+
;
|
|
1101
|
+
"use strict";
|
|
1102
|
+
var $;
|
|
1103
|
+
(function ($) {
|
|
1104
|
+
const instances = new WeakSet();
|
|
1105
|
+
function $mol_delegate(proto, target) {
|
|
1106
|
+
const proxy = new Proxy(proto, {
|
|
1107
|
+
get: (_, field) => {
|
|
1108
|
+
const obj = target();
|
|
1109
|
+
let val = Reflect.get(obj, field);
|
|
1110
|
+
if (typeof val === 'function') {
|
|
1111
|
+
val = val.bind(obj);
|
|
1112
|
+
}
|
|
1113
|
+
return val;
|
|
1114
|
+
},
|
|
1115
|
+
has: (_, field) => Reflect.has(target(), field),
|
|
1116
|
+
set: (_, field, value) => Reflect.set(target(), field, value),
|
|
1117
|
+
getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
|
|
1118
|
+
ownKeys: () => Reflect.ownKeys(target()),
|
|
1119
|
+
getPrototypeOf: () => Reflect.getPrototypeOf(target()),
|
|
1120
|
+
setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
|
|
1121
|
+
isExtensible: () => Reflect.isExtensible(target()),
|
|
1122
|
+
preventExtensions: () => Reflect.preventExtensions(target()),
|
|
1123
|
+
apply: (_, self, args) => Reflect.apply(target(), self, args),
|
|
1124
|
+
construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
|
|
1125
|
+
defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
|
|
1126
|
+
deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
|
|
1127
|
+
});
|
|
1128
|
+
instances.add(proxy);
|
|
1129
|
+
return proxy;
|
|
1130
|
+
}
|
|
1131
|
+
$.$mol_delegate = $mol_delegate;
|
|
1132
|
+
Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
|
|
1133
|
+
value: (obj) => instances.has(obj),
|
|
1134
|
+
});
|
|
1135
|
+
})($ || ($ = {}));
|
|
1136
|
+
//mol/delegate/delegate.ts
|
|
1137
|
+
;
|
|
1138
|
+
"use strict";
|
|
1139
|
+
var $;
|
|
1140
|
+
(function ($) {
|
|
1141
|
+
$.$mol_owning_map = new WeakMap();
|
|
1142
|
+
function $mol_owning_allow(having) {
|
|
1143
|
+
try {
|
|
1144
|
+
if (!having)
|
|
1145
|
+
return false;
|
|
1146
|
+
if (typeof having !== 'object')
|
|
1147
|
+
return false;
|
|
1148
|
+
if (having instanceof $mol_delegate)
|
|
1149
|
+
return false;
|
|
1150
|
+
if (typeof having['destructor'] !== 'function')
|
|
1151
|
+
return false;
|
|
1152
|
+
return true;
|
|
1153
|
+
}
|
|
1154
|
+
catch {
|
|
1155
|
+
return false;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
$.$mol_owning_allow = $mol_owning_allow;
|
|
1159
|
+
function $mol_owning_get(having, Owner) {
|
|
1160
|
+
if (!$mol_owning_allow(having))
|
|
1161
|
+
return null;
|
|
1162
|
+
while (true) {
|
|
1163
|
+
const owner = $.$mol_owning_map.get(having);
|
|
1164
|
+
if (!owner)
|
|
1165
|
+
return owner;
|
|
1166
|
+
if (!Owner)
|
|
1167
|
+
return owner;
|
|
1168
|
+
if (owner instanceof Owner)
|
|
1169
|
+
return owner;
|
|
1170
|
+
having = owner;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
$.$mol_owning_get = $mol_owning_get;
|
|
1174
|
+
function $mol_owning_check(owner, having) {
|
|
1175
|
+
if (!$mol_owning_allow(having))
|
|
1176
|
+
return false;
|
|
1177
|
+
if ($.$mol_owning_map.get(having) !== owner)
|
|
1178
|
+
return false;
|
|
1179
|
+
return true;
|
|
1180
|
+
}
|
|
1181
|
+
$.$mol_owning_check = $mol_owning_check;
|
|
1182
|
+
function $mol_owning_catch(owner, having) {
|
|
1183
|
+
if (!$mol_owning_allow(having))
|
|
1184
|
+
return false;
|
|
1185
|
+
if ($.$mol_owning_map.get(having))
|
|
1186
|
+
return false;
|
|
1187
|
+
$.$mol_owning_map.set(having, owner);
|
|
1188
|
+
return true;
|
|
1189
|
+
}
|
|
1190
|
+
$.$mol_owning_catch = $mol_owning_catch;
|
|
1191
|
+
})($ || ($ = {}));
|
|
1192
|
+
//mol/owning/owning.ts
|
|
1193
|
+
;
|
|
1194
|
+
"use strict";
|
|
1195
|
+
//mol/type/writable/writable.test.ts
|
|
1196
|
+
;
|
|
1197
|
+
"use strict";
|
|
1198
|
+
//mol/type/writable/writable.ts
|
|
1199
|
+
;
|
|
1200
|
+
"use strict";
|
|
1201
|
+
var $;
|
|
1202
|
+
(function ($) {
|
|
1203
|
+
class $mol_object2 {
|
|
1204
|
+
static $ = $;
|
|
1205
|
+
[$mol_ambient_ref] = null;
|
|
1206
|
+
get $() {
|
|
1207
|
+
if (this[$mol_ambient_ref])
|
|
1208
|
+
return this[$mol_ambient_ref];
|
|
1209
|
+
const owner = $mol_owning_get(this);
|
|
1210
|
+
return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
|
|
1211
|
+
}
|
|
1212
|
+
set $(next) {
|
|
1213
|
+
if (this[$mol_ambient_ref])
|
|
1214
|
+
$mol_fail_hidden(new Error('Context already defined'));
|
|
1215
|
+
this[$mol_ambient_ref] = next;
|
|
1216
|
+
}
|
|
1217
|
+
static create(init) {
|
|
1218
|
+
const obj = new this;
|
|
1219
|
+
if (init)
|
|
1220
|
+
init(obj);
|
|
1221
|
+
return obj;
|
|
1222
|
+
}
|
|
1223
|
+
static [Symbol.toPrimitive]() {
|
|
1224
|
+
return this.toString();
|
|
1225
|
+
}
|
|
1226
|
+
static toString() {
|
|
1227
|
+
if (Symbol.toStringTag in this)
|
|
1228
|
+
return this[Symbol.toStringTag];
|
|
1229
|
+
return this.name;
|
|
1230
|
+
}
|
|
1231
|
+
destructor() { }
|
|
1232
|
+
toString() {
|
|
1233
|
+
return this[Symbol.toStringTag] || this.constructor.name + '()';
|
|
1234
|
+
}
|
|
1235
|
+
toJSON() {
|
|
1236
|
+
return this.toString();
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
$.$mol_object2 = $mol_object2;
|
|
1240
|
+
})($ || ($ = {}));
|
|
1241
|
+
//mol/object2/object2.ts
|
|
1242
|
+
;
|
|
1243
|
+
"use strict";
|
|
1244
|
+
var $;
|
|
1245
|
+
(function ($_1) {
|
|
1246
|
+
$mol_test({
|
|
1247
|
+
'tree parsing'() {
|
|
1248
|
+
$mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub.length, 2);
|
|
1249
|
+
$mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub[1].type, "bar");
|
|
1250
|
+
$mol_assert_equal($mol_tree.fromString("foo\n\n\n").sub.length, 1);
|
|
1251
|
+
$mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub.length, 2);
|
|
1252
|
+
$mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub[1].data, "bar");
|
|
1253
|
+
$mol_assert_equal($mol_tree.fromString("foo bar \\pol").sub[0].sub[0].sub[0].data, "pol");
|
|
1254
|
+
$mol_assert_equal($mol_tree.fromString("foo bar\n\t\\pol\n\t\\men").sub[0].sub[0].sub[1].data, "men");
|
|
1255
|
+
$mol_assert_equal($mol_tree.fromString('foo bar \\text\n').toString(), 'foo bar \\text\n');
|
|
1256
|
+
},
|
|
1257
|
+
'inserting'() {
|
|
1258
|
+
$mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 'a', 'b', 'c').toString(), 'a b \\\n');
|
|
1259
|
+
$mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 'a', 'b', 'c', 'd').toString(), 'a b c \\\n');
|
|
1260
|
+
$mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 0, 0, 0).toString(), 'a b \\\n');
|
|
1261
|
+
$mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 0, 0, 0, 0).toString(), 'a b \\\n\t\\\n');
|
|
1262
|
+
$mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, null, null, null).toString(), 'a b \\\n');
|
|
1263
|
+
$mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, null, null, null, null).toString(), 'a b \\\n\t\\\n');
|
|
1264
|
+
},
|
|
1265
|
+
'fromJSON'() {
|
|
1266
|
+
$mol_assert_equal($mol_tree.fromJSON([]).toString(), '/\n');
|
|
1267
|
+
$mol_assert_equal($mol_tree.fromJSON([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
|
|
1268
|
+
$mol_assert_equal($mol_tree.fromJSON([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
|
|
1269
|
+
$mol_assert_equal($mol_tree.fromJSON(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
|
|
1270
|
+
$mol_assert_equal($mol_tree.fromJSON({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
|
|
1271
|
+
},
|
|
1272
|
+
'toJSON'() {
|
|
1273
|
+
$mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n').sub[0]), '[]');
|
|
1274
|
+
$mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\tfalse\n\ttrue\n').sub[0]), '[false,true]');
|
|
1275
|
+
$mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t0\n\t1\n\t2.3\n').sub[0]), '[0,1,2.3]');
|
|
1276
|
+
$mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n').sub[0]), '["","foo","bar\\nbaz"]');
|
|
1277
|
+
$mol_assert_equal(JSON.stringify($mol_tree.fromString('*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n').sub[0]), '{"foo":false,"bar\\nbaz":"lol"}');
|
|
1278
|
+
},
|
|
1279
|
+
'hack'() {
|
|
1280
|
+
const res = $mol_tree.fromString(`foo bar xxx`).hack({
|
|
1281
|
+
'': (tree, context) => [tree.hack(context)],
|
|
1282
|
+
'bar': (tree, context) => [tree.hack(context).clone({ type: '777' })],
|
|
1283
|
+
});
|
|
1284
|
+
$mol_assert_equal(res.toString(), new $mol_tree({ type: 'foo 777 xxx' }).toString());
|
|
1285
|
+
},
|
|
1286
|
+
'errors handling'($) {
|
|
1287
|
+
const errors = [];
|
|
1288
|
+
class Tree extends $mol_tree {
|
|
1289
|
+
static $ = $.$mol_ambient({
|
|
1290
|
+
$mol_fail: error => errors.push(error.message)
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
Tree.fromString(`
|
|
1294
|
+
\t \tfoo
|
|
1295
|
+
bar \\data
|
|
1296
|
+
`, 'test');
|
|
1297
|
+
$mol_assert_like(errors, ['Syntax error at test:2\n \tfoo']);
|
|
1298
|
+
},
|
|
1299
|
+
});
|
|
1300
|
+
})($ || ($ = {}));
|
|
1301
|
+
//mol/tree/tree.test.ts
|
|
1302
|
+
;
|
|
1303
|
+
"use strict";
|
|
1304
|
+
var $;
|
|
1305
|
+
(function ($) {
|
|
1306
|
+
$.$mol_tree_convert = Symbol('$mol_tree_convert');
|
|
1307
|
+
class $mol_tree extends $mol_object2 {
|
|
1308
|
+
type;
|
|
1309
|
+
data;
|
|
1310
|
+
sub;
|
|
1311
|
+
baseUri;
|
|
1312
|
+
row;
|
|
1313
|
+
col;
|
|
1314
|
+
length;
|
|
1315
|
+
constructor(config = {}) {
|
|
1316
|
+
super();
|
|
1317
|
+
this.type = config.type || '';
|
|
1318
|
+
if (config.value !== undefined) {
|
|
1319
|
+
var sub = $mol_tree.values(config.value);
|
|
1320
|
+
if (config.type || sub.length > 1) {
|
|
1321
|
+
this.sub = [...sub, ...(config.sub || [])];
|
|
1322
|
+
this.data = config.data || '';
|
|
1323
|
+
}
|
|
1324
|
+
else {
|
|
1325
|
+
this.data = sub[0].data;
|
|
1326
|
+
this.sub = config.sub || [];
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
else {
|
|
1330
|
+
this.data = config.data || '';
|
|
1331
|
+
this.sub = config.sub || [];
|
|
1332
|
+
}
|
|
1333
|
+
this.baseUri = config.baseUri || '';
|
|
1334
|
+
this.row = config.row || 0;
|
|
1335
|
+
this.col = config.col || 0;
|
|
1336
|
+
this.length = config.length || 0;
|
|
1337
|
+
}
|
|
1338
|
+
static values(str, baseUri) {
|
|
1339
|
+
return str.split('\n').map((data, index) => new $mol_tree({
|
|
1340
|
+
data: data,
|
|
1341
|
+
baseUri: baseUri,
|
|
1342
|
+
row: index + 1,
|
|
1343
|
+
length: data.length,
|
|
1344
|
+
}));
|
|
1345
|
+
}
|
|
1346
|
+
clone(config = {}) {
|
|
1347
|
+
return new $mol_tree({
|
|
1348
|
+
type: ('type' in config) ? config.type : this.type,
|
|
1349
|
+
data: ('data' in config) ? config.data : this.data,
|
|
1350
|
+
sub: ('sub' in config) ? config.sub : this.sub,
|
|
1351
|
+
baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
|
|
1352
|
+
row: ('row' in config) ? config.row : this.row,
|
|
1353
|
+
col: ('col' in config) ? config.col : this.col,
|
|
1354
|
+
length: ('length' in config) ? config.length : this.length,
|
|
1355
|
+
value: config.value
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
make(config) {
|
|
1359
|
+
return new $mol_tree({
|
|
1360
|
+
baseUri: this.baseUri,
|
|
1361
|
+
row: this.row,
|
|
1362
|
+
col: this.col,
|
|
1363
|
+
length: this.length,
|
|
1364
|
+
...config,
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
make_data(value, sub) {
|
|
1368
|
+
return this.make({ value, sub });
|
|
1369
|
+
}
|
|
1370
|
+
make_struct(type, sub) {
|
|
1371
|
+
return this.make({ type, sub });
|
|
1372
|
+
}
|
|
1373
|
+
static fromString(str, baseUri) {
|
|
1374
|
+
var root = new $mol_tree({ baseUri: baseUri });
|
|
1375
|
+
var stack = [root];
|
|
1376
|
+
var row = 0;
|
|
1377
|
+
var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
|
|
1378
|
+
var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
|
|
1379
|
+
lines.forEach(line => {
|
|
1380
|
+
++row;
|
|
1381
|
+
var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
|
|
1382
|
+
if (!chunks || chunks[4])
|
|
1383
|
+
return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
|
|
1384
|
+
var indent = chunks[1];
|
|
1385
|
+
var path = chunks[2];
|
|
1386
|
+
var data = chunks[3];
|
|
1387
|
+
var deep = indent.length;
|
|
1388
|
+
var types = path ? path.replace(/ $/, '').split(/ +/) : [];
|
|
1389
|
+
if (stack.length <= deep)
|
|
1390
|
+
return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
|
|
1391
|
+
stack.length = deep + 1;
|
|
1392
|
+
var parent = stack[deep];
|
|
1393
|
+
let col = deep;
|
|
1394
|
+
types.forEach(type => {
|
|
1395
|
+
if (!type)
|
|
1396
|
+
return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
|
|
1397
|
+
var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
|
|
1398
|
+
const parent_sub = parent.sub;
|
|
1399
|
+
parent_sub.push(next);
|
|
1400
|
+
parent = next;
|
|
1401
|
+
col += type.length + 1;
|
|
1402
|
+
});
|
|
1403
|
+
if (data) {
|
|
1404
|
+
var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
|
|
1405
|
+
const parent_sub = parent.sub;
|
|
1406
|
+
parent_sub.push(next);
|
|
1407
|
+
parent = next;
|
|
1408
|
+
}
|
|
1409
|
+
stack.push(parent);
|
|
1410
|
+
});
|
|
1411
|
+
return root;
|
|
1412
|
+
}
|
|
1413
|
+
static fromJSON(json, baseUri = '') {
|
|
1414
|
+
switch (true) {
|
|
1415
|
+
case typeof json === 'boolean':
|
|
1416
|
+
case typeof json === 'number':
|
|
1417
|
+
case json === null:
|
|
1418
|
+
return new $mol_tree({
|
|
1419
|
+
type: String(json),
|
|
1420
|
+
baseUri: baseUri
|
|
1421
|
+
});
|
|
1422
|
+
case typeof json === 'string':
|
|
1423
|
+
return new $mol_tree({
|
|
1424
|
+
value: json,
|
|
1425
|
+
baseUri: baseUri
|
|
1426
|
+
});
|
|
1427
|
+
case Array.isArray(json):
|
|
1428
|
+
return new $mol_tree({
|
|
1429
|
+
type: "/",
|
|
1430
|
+
sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
|
|
1431
|
+
});
|
|
1432
|
+
case json instanceof Date:
|
|
1433
|
+
return new $mol_tree({
|
|
1434
|
+
value: json.toISOString(),
|
|
1435
|
+
baseUri: baseUri
|
|
1436
|
+
});
|
|
1437
|
+
default:
|
|
1438
|
+
if (typeof json[$.$mol_tree_convert] === 'function') {
|
|
1439
|
+
return json[$.$mol_tree_convert]();
|
|
1440
|
+
}
|
|
1441
|
+
if (typeof json.toJSON === 'function') {
|
|
1442
|
+
return $mol_tree.fromJSON(json.toJSON());
|
|
1443
|
+
}
|
|
1444
|
+
if (json instanceof Error) {
|
|
1445
|
+
const { name, message, stack } = json;
|
|
1446
|
+
json = { ...json, name, message, stack };
|
|
1447
|
+
}
|
|
1448
|
+
var sub = [];
|
|
1449
|
+
for (var key in json) {
|
|
1450
|
+
if (json[key] === undefined)
|
|
1451
|
+
continue;
|
|
1452
|
+
const subsub = $mol_tree.fromJSON(json[key], baseUri);
|
|
1453
|
+
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
1454
|
+
var child = new $mol_tree({
|
|
1455
|
+
type: key,
|
|
1456
|
+
baseUri: baseUri,
|
|
1457
|
+
sub: [subsub],
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
else {
|
|
1461
|
+
var child = new $mol_tree({
|
|
1462
|
+
value: key,
|
|
1463
|
+
baseUri: baseUri,
|
|
1464
|
+
sub: [subsub],
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
sub.push(child);
|
|
1468
|
+
}
|
|
1469
|
+
return new $mol_tree({
|
|
1470
|
+
type: "*",
|
|
1471
|
+
sub: sub,
|
|
1472
|
+
baseUri: baseUri
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
get uri() {
|
|
1477
|
+
return this.baseUri + '#' + this.row + ':' + this.col;
|
|
1478
|
+
}
|
|
1479
|
+
toString(prefix = '') {
|
|
1480
|
+
var output = '';
|
|
1481
|
+
if (this.type.length) {
|
|
1482
|
+
if (!prefix.length) {
|
|
1483
|
+
prefix = "\t";
|
|
1484
|
+
}
|
|
1485
|
+
output += this.type;
|
|
1486
|
+
if (this.sub.length == 1) {
|
|
1487
|
+
return output + ' ' + this.sub[0].toString(prefix);
|
|
1488
|
+
}
|
|
1489
|
+
output += "\n";
|
|
1490
|
+
}
|
|
1491
|
+
else if (this.data.length || prefix.length) {
|
|
1492
|
+
output += "\\" + this.data + "\n";
|
|
1493
|
+
}
|
|
1494
|
+
for (var child of this.sub) {
|
|
1495
|
+
output += prefix;
|
|
1496
|
+
output += child.toString(prefix + "\t");
|
|
1497
|
+
}
|
|
1498
|
+
return output;
|
|
1499
|
+
}
|
|
1500
|
+
toJSON() {
|
|
1501
|
+
if (!this.type)
|
|
1502
|
+
return this.value;
|
|
1503
|
+
if (this.type === 'true')
|
|
1504
|
+
return true;
|
|
1505
|
+
if (this.type === 'false')
|
|
1506
|
+
return false;
|
|
1507
|
+
if (this.type === 'null')
|
|
1508
|
+
return null;
|
|
1509
|
+
if (this.type === '*') {
|
|
1510
|
+
var obj = {};
|
|
1511
|
+
for (var child of this.sub) {
|
|
1512
|
+
if (child.type === '-')
|
|
1513
|
+
continue;
|
|
1514
|
+
var key = child.type || child.clone({ sub: child.sub.slice(0, child.sub.length - 1) }).value;
|
|
1515
|
+
var val = child.sub[child.sub.length - 1].toJSON();
|
|
1516
|
+
if (val !== undefined)
|
|
1517
|
+
obj[key] = val;
|
|
1518
|
+
}
|
|
1519
|
+
return obj;
|
|
1520
|
+
}
|
|
1521
|
+
if (this.type === '/') {
|
|
1522
|
+
var res = [];
|
|
1523
|
+
this.sub.forEach(child => {
|
|
1524
|
+
if (child.type === '-')
|
|
1525
|
+
return;
|
|
1526
|
+
var val = child.toJSON();
|
|
1527
|
+
if (val !== undefined)
|
|
1528
|
+
res.push(val);
|
|
1529
|
+
});
|
|
1530
|
+
return res;
|
|
1531
|
+
}
|
|
1532
|
+
if (this.type === 'time') {
|
|
1533
|
+
return new Date(this.value);
|
|
1534
|
+
}
|
|
1535
|
+
const numb = Number(this.type);
|
|
1536
|
+
if (!Number.isNaN(numb) || this.type === 'NaN')
|
|
1537
|
+
return numb;
|
|
1538
|
+
throw new Error(`Unknown type (${this.type}) at ${this.uri}`);
|
|
1539
|
+
}
|
|
1540
|
+
get value() {
|
|
1541
|
+
var values = [];
|
|
1542
|
+
for (var child of this.sub) {
|
|
1543
|
+
if (child.type)
|
|
1544
|
+
continue;
|
|
1545
|
+
values.push(child.value);
|
|
1546
|
+
}
|
|
1547
|
+
return this.data + values.join("\n");
|
|
1548
|
+
}
|
|
1549
|
+
insert(value, ...path) {
|
|
1550
|
+
if (path.length === 0)
|
|
1551
|
+
return value;
|
|
1552
|
+
const type = path[0];
|
|
1553
|
+
if (typeof type === 'string') {
|
|
1554
|
+
let replaced = false;
|
|
1555
|
+
const sub = this.sub.map((item, index) => {
|
|
1556
|
+
if (item.type !== type)
|
|
1557
|
+
return item;
|
|
1558
|
+
replaced = true;
|
|
1559
|
+
return item.insert(value, ...path.slice(1));
|
|
1560
|
+
});
|
|
1561
|
+
if (!replaced)
|
|
1562
|
+
sub.push(new $mol_tree({ type }).insert(value, ...path.slice(1)));
|
|
1563
|
+
return this.clone({ sub });
|
|
1564
|
+
}
|
|
1565
|
+
else if (typeof type === 'number') {
|
|
1566
|
+
const sub = this.sub.slice();
|
|
1567
|
+
sub[type] = (sub[type] || new $mol_tree).insert(value, ...path.slice(1));
|
|
1568
|
+
return this.clone({ sub });
|
|
1569
|
+
}
|
|
1570
|
+
else {
|
|
1571
|
+
return this.clone({ sub: ((this.sub.length === 0) ? [new $mol_tree()] : this.sub).map(item => item.insert(value, ...path.slice(1))) });
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
select(...path) {
|
|
1575
|
+
var next = [this];
|
|
1576
|
+
for (var type of path) {
|
|
1577
|
+
if (!next.length)
|
|
1578
|
+
break;
|
|
1579
|
+
var prev = next;
|
|
1580
|
+
next = [];
|
|
1581
|
+
for (var item of prev) {
|
|
1582
|
+
switch (typeof (type)) {
|
|
1583
|
+
case 'string':
|
|
1584
|
+
for (var child of item.sub) {
|
|
1585
|
+
if (!type || (child.type == type)) {
|
|
1586
|
+
next.push(child);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
break;
|
|
1590
|
+
case 'number':
|
|
1591
|
+
if (type < item.sub.length)
|
|
1592
|
+
next.push(item.sub[type]);
|
|
1593
|
+
break;
|
|
1594
|
+
default: next.push(...item.sub);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
return new $mol_tree({ sub: next });
|
|
1599
|
+
}
|
|
1600
|
+
filter(path, value) {
|
|
1601
|
+
var sub = this.sub.filter(function (item) {
|
|
1602
|
+
var found = item.select(...path);
|
|
1603
|
+
if (value == null) {
|
|
1604
|
+
return Boolean(found.sub.length);
|
|
1605
|
+
}
|
|
1606
|
+
else {
|
|
1607
|
+
return found.sub.some(child => child.value == value);
|
|
1608
|
+
}
|
|
1609
|
+
});
|
|
1610
|
+
return new $mol_tree({ sub: sub });
|
|
1611
|
+
}
|
|
1612
|
+
transform(visit, stack = []) {
|
|
1613
|
+
const sub_stack = [this, ...stack];
|
|
1614
|
+
return visit(sub_stack, () => this.sub.map(node => node.transform(visit, sub_stack)).filter(n => n));
|
|
1615
|
+
}
|
|
1616
|
+
hack(context) {
|
|
1617
|
+
const sub = [].concat(...this.sub.map(child => {
|
|
1618
|
+
const handle = context[child.type] || context[''];
|
|
1619
|
+
if (!handle)
|
|
1620
|
+
$mol_fail(child.error('Handler not defined'));
|
|
1621
|
+
return handle(child, context);
|
|
1622
|
+
}));
|
|
1623
|
+
return this.clone({ sub });
|
|
1624
|
+
}
|
|
1625
|
+
error(message) {
|
|
1626
|
+
return new Error(`${message}:\n${this} ${this.baseUri}:${this.row}:${this.col}`);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
$.$mol_tree = $mol_tree;
|
|
1630
|
+
})($ || ($ = {}));
|
|
1631
|
+
//mol/tree/tree.ts
|
|
1632
|
+
;
|
|
1633
|
+
"use strict";
|
|
1634
|
+
var $;
|
|
1635
|
+
(function ($_1) {
|
|
1636
|
+
$mol_test({
|
|
1637
|
+
'FQN of anon function'($) {
|
|
1638
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
|
1639
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
|
1640
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
|
1641
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
|
1642
|
+
},
|
|
1643
|
+
});
|
|
1644
|
+
})($ || ($ = {}));
|
|
1645
|
+
//mol/func/name/name.test.ts
|
|
1646
|
+
;
|
|
1647
|
+
"use strict";
|
|
1648
|
+
var $;
|
|
1649
|
+
(function ($) {
|
|
1650
|
+
function $mol_func_name(func) {
|
|
1651
|
+
let name = func.name;
|
|
1652
|
+
if (name?.length > 1)
|
|
1653
|
+
return name;
|
|
1654
|
+
for (let key in this) {
|
|
1655
|
+
try {
|
|
1656
|
+
if (this[key] !== func)
|
|
1657
|
+
continue;
|
|
1658
|
+
name = key;
|
|
1659
|
+
Object.defineProperty(func, 'name', { value: name });
|
|
1660
|
+
break;
|
|
1661
|
+
}
|
|
1662
|
+
catch { }
|
|
1663
|
+
}
|
|
1664
|
+
return name;
|
|
1665
|
+
}
|
|
1666
|
+
$.$mol_func_name = $mol_func_name;
|
|
1667
|
+
function $mol_func_name_from(target, source) {
|
|
1668
|
+
Object.defineProperty(target, 'name', { value: source.name });
|
|
1669
|
+
return target;
|
|
1670
|
+
}
|
|
1671
|
+
$.$mol_func_name_from = $mol_func_name_from;
|
|
1672
|
+
})($ || ($ = {}));
|
|
1673
|
+
//mol/func/name/name.ts
|
|
1674
|
+
;
|
|
1675
|
+
"use strict";
|
|
1676
|
+
var $;
|
|
1677
|
+
(function ($) {
|
|
1678
|
+
$mol_test({
|
|
1679
|
+
'Wrap & unwrap'() {
|
|
1680
|
+
const val = [1];
|
|
1681
|
+
const mut = $mol_mutable(val);
|
|
1682
|
+
$mol_assert_equal(val, mut());
|
|
1683
|
+
},
|
|
1684
|
+
'Deep array'() {
|
|
1685
|
+
const val = [[1], [2], [3]];
|
|
1686
|
+
const mut = $mol_mutable(val);
|
|
1687
|
+
$mol_assert_equal(mut[1][0](v => -v), -2);
|
|
1688
|
+
$mol_assert_unique(val, mut());
|
|
1689
|
+
$mol_assert_equal(val[0], mut()[0]);
|
|
1690
|
+
$mol_assert_equal(val[2], mut()[2]);
|
|
1691
|
+
$mol_assert_unique(val[1], mut()[1]);
|
|
1692
|
+
$mol_assert_like(mut()[1], [-2]);
|
|
1693
|
+
},
|
|
1694
|
+
'Deep objects'() {
|
|
1695
|
+
const val = { a: { x: 1 }, b: { y: 2 }, c: { z: 3 } };
|
|
1696
|
+
const mut = $mol_mutable(val);
|
|
1697
|
+
$mol_assert_equal(mut.b.y(v => -v), -2);
|
|
1698
|
+
$mol_assert_unique(val, mut());
|
|
1699
|
+
$mol_assert_equal(val.a, mut().a);
|
|
1700
|
+
$mol_assert_equal(val.c, mut().c);
|
|
1701
|
+
$mol_assert_unique(val.b, mut().b);
|
|
1702
|
+
$mol_assert_like(mut().b, { y: -2 });
|
|
1703
|
+
},
|
|
1704
|
+
});
|
|
1705
|
+
})($ || ($ = {}));
|
|
1706
|
+
//mol/mutable/mutable.test.ts
|
|
1707
|
+
|
|
1708
|
+
//# sourceMappingURL=node.test.js.map
|