mol_crypto_lib 0.1.1695 → 0.1.1697

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node.test.js CHANGED
@@ -250,6 +250,20 @@ var $;
250
250
  ;
251
251
  "use strict";
252
252
 
253
+ ;
254
+ "use strict";
255
+ var $;
256
+ (function ($) {
257
+ const mod = require('module');
258
+ const internals = mod.builtinModules;
259
+ function $node_internal_check(name) {
260
+ if (name.startsWith('node:'))
261
+ return true;
262
+ return internals.includes(name);
263
+ }
264
+ $.$node_internal_check = $node_internal_check;
265
+ })($ || ($ = {}));
266
+
253
267
  ;
254
268
  "use strict";
255
269
  var $;
@@ -329,39 +343,44 @@ var $node = new Proxy({ require }, {
329
343
  get(target, name, wrapper) {
330
344
  if (target[name])
331
345
  return target[name];
332
- if (name.startsWith('node:'))
346
+ const $$ = $;
347
+ if ($$.$node_internal_check(name, target))
333
348
  return target.require(name);
334
349
  if (name[0] === '.')
335
350
  return target.require(name);
336
- const mod = target.require('module');
337
- if (mod.builtinModules.indexOf(name) >= 0)
338
- return target.require(name);
339
351
  try {
340
352
  target.require.resolve(name);
341
353
  }
342
354
  catch {
343
- const $$ = $;
344
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
355
+ try {
356
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
357
+ }
358
+ catch (e) {
359
+ if ($$.$mol_promise_like(e))
360
+ $$.$mol_fail_hidden(e);
361
+ }
345
362
  try {
346
363
  $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
347
364
  }
348
365
  catch (e) {
349
- if ($$.$mol_fail_catch(e)) {
350
- $$.$mol_fail_log(e);
351
- }
366
+ if ($$.$mol_promise_like(e))
367
+ $$.$mol_fail_hidden(e);
368
+ $$.$mol_fail_log(e);
352
369
  }
353
370
  }
354
371
  try {
355
372
  return target.require(name);
356
373
  }
357
374
  catch (error) {
358
- if ($.$mol_fail_catch(error) && error.code === 'ERR_REQUIRE_ESM') {
375
+ if ($$.$mol_promise_like(error))
376
+ $$.$mol_fail_hidden(error);
377
+ if (error && typeof error === 'object' && error.code === 'ERR_REQUIRE_ESM') {
359
378
  const module = cache.get(name);
360
379
  if (module)
361
380
  return module;
362
381
  throw Object.assign(import(name).then(module => cache.set(name, module)), { cause: error });
363
382
  }
364
- $.$mol_fail_log(error);
383
+ $$.$mol_fail_log(error);
365
384
  return null;
366
385
  }
367
386
  },
@@ -2993,51 +3012,59 @@ var $;
2993
3012
  $mol_test_mocks.push($ => $.$mol_fail_log = () => false);
2994
3013
  })($ || ($ = {}));
2995
3014
 
2996
- ;
2997
- "use strict";
2998
- var $;
2999
- (function ($_1) {
3000
- $mol_test({
3001
- 'FQN of anon function'($) {
3002
- const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
3003
- $mol_assert_equal($$.$mol_func_name_test.name, '');
3004
- $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
3005
- $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
3006
- },
3007
- });
3008
- })($ || ($ = {}));
3009
-
3010
3015
  ;
3011
3016
  "use strict";
3012
3017
  var $;
3013
3018
  (function ($) {
3014
- $mol_test({
3015
- 'auto name'() {
3016
- class Invalid extends $mol_error_mix {
3017
- }
3018
- const mix = new Invalid('foo');
3019
- $mol_assert_equal(mix.name, 'Invalid_Error');
3020
- },
3021
- 'simpe mix'() {
3022
- const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
3023
- $mol_assert_equal(mix.message, 'foo');
3024
- $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
3025
- },
3026
- 'provide additional info'() {
3027
- class Invalid extends $mol_error_mix {
3028
- }
3029
- const mix = new $mol_error_mix('Wrong password', {}, new Invalid('Too short', { value: 'p@ssw0rd', hint: '> 8 letters' }), new Invalid('Too simple', { value: 'p@ssw0rd', hint: 'need capital letter' }));
3030
- const hints = [];
3031
- if (mix instanceof $mol_error_mix) {
3032
- for (const er of mix.errors) {
3033
- if (er instanceof Invalid) {
3034
- hints.push(er.cause?.hint ?? '');
3019
+ function $mol_dom_render_children(el, childNodes) {
3020
+ const node_set = new Set(childNodes);
3021
+ let nextNode = el.firstChild;
3022
+ for (let view of childNodes) {
3023
+ if (view == null)
3024
+ continue;
3025
+ if (view instanceof $mol_dom_context.Node) {
3026
+ while (true) {
3027
+ if (!nextNode) {
3028
+ el.appendChild(view);
3029
+ break;
3030
+ }
3031
+ if (nextNode == view) {
3032
+ nextNode = nextNode.nextSibling;
3033
+ break;
3034
+ }
3035
+ else {
3036
+ if (node_set.has(nextNode)) {
3037
+ el.insertBefore(view, nextNode);
3038
+ break;
3039
+ }
3040
+ else {
3041
+ const nn = nextNode.nextSibling;
3042
+ el.removeChild(nextNode);
3043
+ nextNode = nn;
3044
+ }
3035
3045
  }
3036
3046
  }
3037
3047
  }
3038
- $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
3039
- },
3040
- });
3048
+ else {
3049
+ if (nextNode && nextNode.nodeName === '#text') {
3050
+ const str = String(view);
3051
+ if (nextNode.nodeValue !== str)
3052
+ nextNode.nodeValue = str;
3053
+ nextNode = nextNode.nextSibling;
3054
+ }
3055
+ else {
3056
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
3057
+ el.insertBefore(textNode, nextNode);
3058
+ }
3059
+ }
3060
+ }
3061
+ while (nextNode) {
3062
+ const currNode = nextNode;
3063
+ nextNode = currNode.nextSibling;
3064
+ el.removeChild(currNode);
3065
+ }
3066
+ }
3067
+ $.$mol_dom_render_children = $mol_dom_render_children;
3041
3068
  })($ || ($ = {}));
3042
3069
 
3043
3070
  ;
@@ -3055,138 +3082,136 @@ var $;
3055
3082
  ;
3056
3083
  "use strict";
3057
3084
 
3058
- ;
3059
- "use strict";
3060
-
3061
3085
  ;
3062
3086
  "use strict";
3063
3087
  var $;
3064
- (function ($_1) {
3065
- $mol_test({
3066
- 'init with overload'() {
3067
- class X extends $mol_object {
3068
- foo() {
3069
- return 1;
3070
- }
3071
- }
3072
- var x = X.make({
3073
- foo: () => 2,
3074
- });
3075
- $mol_assert_equal(x.foo(), 2);
3076
- },
3077
- 'Context in instance inherits from class'($) {
3078
- const custom = $.$mol_ambient({});
3079
- class X extends $.$mol_object {
3080
- static $ = custom;
3081
- }
3082
- $mol_assert_equal(new X().$, custom);
3083
- },
3084
- });
3088
+ (function ($) {
3089
+ function $mol_dom_serialize(node) {
3090
+ const serializer = new $mol_dom_context.XMLSerializer;
3091
+ return serializer.serializeToString(node);
3092
+ }
3093
+ $.$mol_dom_serialize = $mol_dom_serialize;
3085
3094
  })($ || ($ = {}));
3086
3095
 
3087
3096
  ;
3088
3097
  "use strict";
3089
3098
  var $;
3090
- (function ($_1) {
3091
- $mol_test({
3092
- 'Collect deps'() {
3093
- const pub1 = new $mol_wire_pub;
3094
- const pub2 = new $mol_wire_pub;
3095
- const sub = new $mol_wire_pub_sub;
3096
- const bu1 = sub.track_on();
3097
- try {
3098
- pub1.promote();
3099
- pub2.promote();
3100
- pub2.promote();
3099
+ (function ($) {
3100
+ $.$mol_jsx_prefix = '';
3101
+ $.$mol_jsx_crumbs = '';
3102
+ $.$mol_jsx_booked = null;
3103
+ $.$mol_jsx_document = {
3104
+ getElementById: () => null,
3105
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
3106
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
3107
+ };
3108
+ $.$mol_jsx_frag = '';
3109
+ function $mol_jsx(Elem, props, ...childNodes) {
3110
+ const id = props && props.id || '';
3111
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
3112
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
3113
+ if (Elem && $.$mol_jsx_booked) {
3114
+ if ($.$mol_jsx_booked.has(id)) {
3115
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
3101
3116
  }
3102
- finally {
3103
- sub.track_cut();
3104
- sub.track_off(bu1);
3117
+ else {
3118
+ $.$mol_jsx_booked.add(id);
3105
3119
  }
3106
- pub1.emit();
3107
- pub2.emit();
3108
- $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
3109
- const bu2 = sub.track_on();
3110
- try {
3111
- pub1.promote();
3112
- pub1.promote();
3113
- pub2.promote();
3120
+ }
3121
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
3122
+ if ($.$mol_jsx_prefix) {
3123
+ const prefix_ext = $.$mol_jsx_prefix;
3124
+ const booked_ext = $.$mol_jsx_booked;
3125
+ const crumbs_ext = $.$mol_jsx_crumbs;
3126
+ for (const field in props) {
3127
+ const func = props[field];
3128
+ if (typeof func !== 'function')
3129
+ continue;
3130
+ const wrapper = function (...args) {
3131
+ const prefix = $.$mol_jsx_prefix;
3132
+ const booked = $.$mol_jsx_booked;
3133
+ const crumbs = $.$mol_jsx_crumbs;
3134
+ try {
3135
+ $.$mol_jsx_prefix = prefix_ext;
3136
+ $.$mol_jsx_booked = booked_ext;
3137
+ $.$mol_jsx_crumbs = crumbs_ext;
3138
+ return func.call(this, ...args);
3139
+ }
3140
+ finally {
3141
+ $.$mol_jsx_prefix = prefix;
3142
+ $.$mol_jsx_booked = booked;
3143
+ $.$mol_jsx_crumbs = crumbs;
3144
+ }
3145
+ };
3146
+ $mol_func_name_from(wrapper, func);
3147
+ props[field] = wrapper;
3114
3148
  }
3115
- finally {
3116
- sub.track_cut();
3117
- sub.track_off(bu2);
3149
+ }
3150
+ if (typeof Elem !== 'string') {
3151
+ if ('prototype' in Elem) {
3152
+ const view = node && node[String(Elem)] || new Elem;
3153
+ Object.assign(view, props);
3154
+ view[Symbol.toStringTag] = guid;
3155
+ view.childNodes = childNodes;
3156
+ if (!view.ownerDocument)
3157
+ view.ownerDocument = $.$mol_jsx_document;
3158
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
3159
+ node = view.valueOf();
3160
+ node[String(Elem)] = view;
3161
+ return node;
3118
3162
  }
3119
- pub1.emit();
3120
- pub2.emit();
3121
- $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
3122
- },
3123
- 'cyclic detection'($) {
3124
- const sub1 = new $mol_wire_pub_sub;
3125
- const sub2 = new $mol_wire_pub_sub;
3126
- const bu1 = sub1.track_on();
3127
- try {
3128
- const bu2 = sub2.track_on();
3163
+ else {
3164
+ const prefix = $.$mol_jsx_prefix;
3165
+ const booked = $.$mol_jsx_booked;
3166
+ const crumbs = $.$mol_jsx_crumbs;
3129
3167
  try {
3130
- $mol_assert_fail(() => sub1.promote(), 'Circular subscription');
3168
+ $.$mol_jsx_prefix = guid;
3169
+ $.$mol_jsx_booked = new Set;
3170
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
3171
+ return Elem(props, ...childNodes);
3131
3172
  }
3132
3173
  finally {
3133
- sub2.track_cut();
3134
- sub2.track_off(bu2);
3174
+ $.$mol_jsx_prefix = prefix;
3175
+ $.$mol_jsx_booked = booked;
3176
+ $.$mol_jsx_crumbs = crumbs;
3135
3177
  }
3136
3178
  }
3137
- finally {
3138
- sub1.track_cut();
3139
- sub1.track_off(bu1);
3140
- }
3141
- },
3142
- });
3143
- })($ || ($ = {}));
3144
-
3145
- ;
3146
- "use strict";
3147
- var $;
3148
- (function ($) {
3149
- $.$mol_after_mock_queue = [];
3150
- function $mol_after_mock_warp() {
3151
- const queue = $.$mol_after_mock_queue.splice(0);
3152
- for (const task of queue)
3153
- task();
3154
- }
3155
- $.$mol_after_mock_warp = $mol_after_mock_warp;
3156
- class $mol_after_mock_commmon extends $mol_object2 {
3157
- task;
3158
- promise = Promise.resolve();
3159
- cancelled = false;
3160
- id;
3161
- constructor(task) {
3162
- super();
3163
- this.task = task;
3164
- $.$mol_after_mock_queue.push(task);
3165
3179
  }
3166
- destructor() {
3167
- const index = $.$mol_after_mock_queue.indexOf(this.task);
3168
- if (index >= 0)
3169
- $.$mol_after_mock_queue.splice(index, 1);
3180
+ if (!node) {
3181
+ node = Elem
3182
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
3183
+ : $.$mol_jsx_document.createDocumentFragment();
3170
3184
  }
3171
- }
3172
- $.$mol_after_mock_commmon = $mol_after_mock_commmon;
3173
- class $mol_after_mock_timeout extends $mol_after_mock_commmon {
3174
- delay;
3175
- constructor(delay, task) {
3176
- super(task);
3177
- this.delay = delay;
3185
+ $mol_dom_render_children(node, [].concat(...childNodes));
3186
+ if (!Elem)
3187
+ return node;
3188
+ if (guid)
3189
+ node.id = guid;
3190
+ for (const key in props) {
3191
+ if (key === 'id')
3192
+ continue;
3193
+ if (typeof props[key] === 'string') {
3194
+ if (typeof node[key] === 'string')
3195
+ node[key] = props[key];
3196
+ node.setAttribute(key, props[key]);
3197
+ }
3198
+ else if (props[key] &&
3199
+ typeof props[key] === 'object' &&
3200
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
3201
+ if (typeof node[key] === 'object') {
3202
+ Object.assign(node[key], props[key]);
3203
+ continue;
3204
+ }
3205
+ }
3206
+ else {
3207
+ node[key] = props[key];
3208
+ }
3178
3209
  }
3210
+ if ($.$mol_jsx_crumbs)
3211
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
3212
+ return node;
3179
3213
  }
3180
- $.$mol_after_mock_timeout = $mol_after_mock_timeout;
3181
- })($ || ($ = {}));
3182
-
3183
- ;
3184
- "use strict";
3185
- var $;
3186
- (function ($_1) {
3187
- $mol_test_mocks.push($ => {
3188
- $.$mol_after_tick = $mol_after_mock_commmon;
3189
- });
3214
+ $.$mol_jsx = $mol_jsx;
3190
3215
  })($ || ($ = {}));
3191
3216
 
3192
3217
  ;
@@ -3194,94 +3219,101 @@ var $;
3194
3219
  var $;
3195
3220
  (function ($) {
3196
3221
  $mol_test({
3197
- 'Sync execution'() {
3198
- class Sync extends $mol_object2 {
3199
- static calc(a, b) {
3200
- return a + b;
3201
- }
3202
- }
3203
- __decorate([
3204
- $mol_wire_method
3205
- ], Sync, "calc", null);
3206
- $mol_assert_equal(Sync.calc(1, 2), 3);
3222
+ 'Make empty div'() {
3223
+ $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
3207
3224
  },
3208
- async 'async <=> sync'() {
3209
- class SyncAsync extends $mol_object2 {
3210
- static async val(a) {
3211
- return a;
3212
- }
3213
- static sum(a, b) {
3214
- const syn = $mol_wire_sync(this);
3215
- return syn.val(a) + syn.val(b);
3216
- }
3217
- static async calc(a, b) {
3218
- return 5 + await $mol_wire_async(this).sum(a, b);
3219
- }
3220
- }
3221
- $mol_assert_equal(await SyncAsync.calc(1, 2), 8);
3225
+ 'Define native field'() {
3226
+ const dom = $mol_jsx("input", { value: '123' });
3227
+ $mol_assert_equal(dom.outerHTML, '<input value="123">');
3228
+ $mol_assert_equal(dom.value, '123');
3222
3229
  },
3223
- async 'Idempotence control'() {
3224
- class Idempotence extends $mol_object2 {
3225
- static logs_idemp = 0;
3226
- static logs_unidemp = 0;
3227
- static log_idemp() {
3228
- this.logs_idemp += 1;
3229
- }
3230
- static log_unidemp() {
3231
- this.logs_unidemp += 1;
3232
- }
3233
- static async val(a) {
3234
- return a;
3235
- }
3236
- static sum(a, b) {
3237
- this.log_idemp();
3238
- this.log_unidemp();
3239
- const syn = $mol_wire_sync(this);
3240
- return syn.val(a) + syn.val(b);
3241
- }
3242
- static async calc(a, b) {
3243
- return 5 + await $mol_wire_async(this).sum(a, b);
3244
- }
3245
- }
3246
- __decorate([
3247
- $mol_wire_method
3248
- ], Idempotence, "log_idemp", null);
3249
- $mol_assert_equal(await Idempotence.calc(1, 2), 8);
3250
- $mol_assert_equal(Idempotence.logs_idemp, 1);
3251
- $mol_assert_equal(Idempotence.logs_unidemp, 3);
3230
+ 'Define classes'() {
3231
+ const dom = $mol_jsx("div", { class: 'foo bar' });
3232
+ $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
3252
3233
  },
3253
- async 'Error handling'() {
3254
- class Handle extends $mol_object2 {
3255
- static async sum(a, b) {
3256
- $mol_fail(new Error('test error ' + (a + b)));
3257
- }
3258
- static check() {
3259
- try {
3260
- return $mol_wire_sync(Handle).sum(1, 2);
3261
- }
3262
- catch (error) {
3263
- if ($mol_promise_like(error))
3264
- $mol_fail_hidden(error);
3265
- $mol_assert_equal(error.message, 'test error 3');
3266
- }
3267
- }
3268
- }
3269
- await $mol_wire_async(Handle).check();
3234
+ 'Define styles'() {
3235
+ const dom = $mol_jsx("div", { style: { color: 'red' } });
3236
+ $mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
3237
+ },
3238
+ 'Define dataset'() {
3239
+ const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
3240
+ $mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
3241
+ },
3242
+ 'Define attributes'() {
3243
+ const dom = $mol_jsx("div", { lang: "ru", hidden: true });
3244
+ $mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
3245
+ },
3246
+ 'Define child nodes'() {
3247
+ const dom = $mol_jsx("div", null,
3248
+ "hello",
3249
+ $mol_jsx("strong", null, "world"),
3250
+ "!");
3251
+ $mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
3252
+ },
3253
+ 'Make fragment'() {
3254
+ const dom = $mol_jsx($mol_jsx_frag, null,
3255
+ $mol_jsx("br", null),
3256
+ $mol_jsx("hr", null));
3257
+ $mol_assert_equal($mol_dom_serialize(dom), '<br xmlns="http://www.w3.org/1999/xhtml" /><hr xmlns="http://www.w3.org/1999/xhtml" />');
3258
+ },
3259
+ 'Spread fragment'() {
3260
+ const dom = $mol_jsx("div", null,
3261
+ $mol_jsx($mol_jsx_frag, null,
3262
+ $mol_jsx("br", null),
3263
+ $mol_jsx("hr", null)));
3264
+ $mol_assert_equal(dom.outerHTML, '<div><br><hr></div>');
3265
+ },
3266
+ 'Function as component'() {
3267
+ const Button = (props, target) => {
3268
+ return $mol_jsx("button", { title: props.hint }, target());
3269
+ };
3270
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
3271
+ $mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
3272
+ },
3273
+ 'Nested guid generation'() {
3274
+ const Foo = () => {
3275
+ return $mol_jsx("div", null,
3276
+ $mol_jsx(Bar, { id: "bar" },
3277
+ $mol_jsx("img", { id: "icon" })));
3278
+ };
3279
+ const Bar = (props, icon) => {
3280
+ return $mol_jsx("span", null,
3281
+ icon,
3282
+ $mol_jsx("i", { id: "label" }));
3283
+ };
3284
+ const dom = $mol_jsx(Foo, { id: "foo" });
3285
+ $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>');
3286
+ },
3287
+ 'Fail on non unique ids'() {
3288
+ const App = () => {
3289
+ return $mol_jsx("div", null,
3290
+ $mol_jsx("span", { id: "bar" }),
3291
+ $mol_jsx("span", { id: "bar" }));
3292
+ };
3293
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
3294
+ },
3295
+ 'Owner based guid generationn'() {
3296
+ const Foo = () => {
3297
+ return $mol_jsx("div", null,
3298
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
3299
+ };
3300
+ const Bar = (props) => {
3301
+ return $mol_jsx("span", null, props.icon());
3302
+ };
3303
+ const dom = $mol_jsx(Foo, { id: "app" });
3304
+ $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>');
3305
+ },
3306
+ 'Fail on same ids from different caller'() {
3307
+ const Foo = () => {
3308
+ return $mol_jsx("div", null,
3309
+ $mol_jsx("img", { id: "icon" }),
3310
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
3311
+ };
3312
+ const Bar = (props) => {
3313
+ return $mol_jsx("span", null, props.icon());
3314
+ };
3315
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
3270
3316
  },
3271
- });
3272
- })($ || ($ = {}));
3273
-
3274
- ;
3275
- "use strict";
3276
- var $;
3277
- (function ($_1) {
3278
- $mol_test_mocks.push($ => {
3279
- $.$mol_log3_come = () => { };
3280
- $.$mol_log3_done = () => { };
3281
- $.$mol_log3_fail = () => { };
3282
- $.$mol_log3_warn = () => { };
3283
- $.$mol_log3_rise = () => { };
3284
- $.$mol_log3_area = () => () => { };
3285
3317
  });
3286
3318
  })($ || ($ = {}));
3287
3319
 
@@ -3289,213 +3321,415 @@ var $;
3289
3321
  "use strict";
3290
3322
  var $;
3291
3323
  (function ($) {
3292
- function $mol_wire_method(host, field, descr) {
3293
- if (!descr)
3294
- descr = Reflect.getOwnPropertyDescriptor(host, field);
3295
- const orig = descr?.value ?? host[field];
3296
- const sup = Reflect.getPrototypeOf(host);
3297
- if (typeof sup[field] === 'function') {
3298
- Object.defineProperty(orig, 'name', { value: sup[field].name });
3324
+ function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
3325
+ const source = typeof item === 'function' ? new $mol_range2_array() : item;
3326
+ if (typeof item !== 'function') {
3327
+ item = index => source[index];
3328
+ size = () => source.length;
3299
3329
  }
3300
- const temp = $mol_wire_task.getter(orig);
3301
- const value = function (...args) {
3302
- const fiber = temp(this ?? null, args);
3303
- return fiber.sync();
3304
- };
3305
- Object.defineProperty(value, 'name', { value: orig.name + ' ' });
3306
- Object.assign(value, { orig });
3307
- const descr2 = { ...descr, value };
3308
- Reflect.defineProperty(host, field, descr2);
3309
- return descr2;
3310
- }
3311
- $.$mol_wire_method = $mol_wire_method;
3312
- })($ || ($ = {}));
3313
-
3314
- ;
3315
- "use strict";
3316
- var $;
3317
- (function ($) {
3318
- function $mol_wire_async(obj) {
3319
- let fiber;
3320
- const temp = $mol_wire_task.getter(obj);
3321
- return new Proxy(obj, {
3322
- get(obj, field) {
3323
- const val = obj[field];
3324
- if (typeof val !== 'function')
3325
- return val;
3326
- let fiber;
3327
- const temp = $mol_wire_task.getter(val);
3328
- return function $mol_wire_async(...args) {
3329
- fiber?.destructor();
3330
- fiber = temp(obj, args);
3331
- return fiber.async();
3332
- };
3330
+ return new Proxy(source, {
3331
+ get(target, field) {
3332
+ if (typeof field === 'string') {
3333
+ if (field === 'length')
3334
+ return size();
3335
+ const index = Number(field);
3336
+ if (index < 0)
3337
+ return undefined;
3338
+ if (index >= size())
3339
+ return undefined;
3340
+ if (index === Math.trunc(index))
3341
+ return item(index);
3342
+ }
3343
+ return $mol_range2_array.prototype[field];
3333
3344
  },
3334
- apply(obj, self, args) {
3335
- fiber?.destructor();
3336
- fiber = temp(self, args);
3337
- return fiber.async();
3345
+ set(target, field) {
3346
+ return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
3338
3347
  },
3348
+ ownKeys(target) {
3349
+ return [...Array(size())].map((v, i) => String(i)).concat('length');
3350
+ },
3351
+ getOwnPropertyDescriptor(target, field) {
3352
+ if (field === "length")
3353
+ return {
3354
+ value: size(),
3355
+ writable: true,
3356
+ enumerable: false,
3357
+ configurable: false,
3358
+ };
3359
+ const index = Number(field);
3360
+ if (index === Math.trunc(index))
3361
+ return {
3362
+ get: () => this.get(target, field, this),
3363
+ enumerable: true,
3364
+ configurable: true,
3365
+ };
3366
+ return Object.getOwnPropertyDescriptor(target, field);
3367
+ }
3339
3368
  });
3340
3369
  }
3341
- $.$mol_wire_async = $mol_wire_async;
3342
- })($ || ($ = {}));
3343
-
3344
- ;
3345
- "use strict";
3346
- var $;
3347
- (function ($_1) {
3348
- $mol_test({
3349
- 'test types'($) {
3350
- class A {
3351
- static a() {
3352
- return '';
3353
- }
3354
- static b() {
3355
- return $mol_wire_async(this).a();
3356
- }
3357
- }
3358
- },
3359
- async 'Latest method calls wins'($) {
3360
- class NameLogger extends $mol_object2 {
3361
- static $ = $;
3362
- static first = [];
3363
- static last = [];
3364
- static send(next) {
3365
- $mol_wire_sync(this.first).push(next);
3366
- $$.$mol_wait_timeout(0);
3367
- this.last.push(next);
3368
- }
3369
- }
3370
- const name = $mol_wire_async(NameLogger).send;
3371
- name('john');
3372
- const promise = name('jin');
3373
- $.$mol_after_mock_warp();
3374
- await promise;
3375
- $mol_assert_equal(NameLogger.first, ['john', 'jin']);
3376
- $mol_assert_equal(NameLogger.last, ['jin']);
3377
- },
3378
- async 'Latest function calls wins'($) {
3379
- const first = [];
3380
- const last = [];
3381
- function send_name(next) {
3382
- $mol_wire_sync(first).push(next);
3383
- $$.$mol_wait_timeout(0);
3384
- last.push(next);
3370
+ $.$mol_range2 = $mol_range2;
3371
+ class $mol_range2_array extends Array {
3372
+ concat(...tail) {
3373
+ if (tail.length === 0)
3374
+ return this;
3375
+ if (tail.length > 1) {
3376
+ let list = this;
3377
+ for (let item of tail)
3378
+ list = list.concat(item);
3379
+ return list;
3385
3380
  }
3386
- const name = $mol_wire_async(send_name);
3387
- name('john');
3388
- const promise = name('jin');
3389
- $.$mol_after_mock_warp();
3390
- await promise;
3391
- $mol_assert_equal(first, ['john', 'jin']);
3392
- $mol_assert_equal(last, ['jin']);
3393
- },
3394
- });
3395
- })($ || ($ = {}));
3396
-
3397
- ;
3398
- "use strict";
3399
- var $;
3400
- (function ($_1) {
3401
- $mol_test({
3402
- 'test types'($) {
3403
- class A {
3404
- static a() {
3405
- return Promise.resolve('');
3406
- }
3407
- static b() {
3408
- return $mol_wire_sync(this).a();
3381
+ return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
3382
+ }
3383
+ filter(check, context) {
3384
+ const filtered = [];
3385
+ let cursor = -1;
3386
+ return $mol_range2(index => {
3387
+ while (cursor < this.length && index >= filtered.length - 1) {
3388
+ const val = this[++cursor];
3389
+ if (check(val, cursor, this))
3390
+ filtered.push(val);
3409
3391
  }
3392
+ return filtered[index];
3393
+ }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
3394
+ }
3395
+ forEach(proceed, context) {
3396
+ for (let [key, value] of this.entries())
3397
+ proceed.call(context, value, key, this);
3398
+ }
3399
+ map(proceed, context) {
3400
+ return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
3401
+ }
3402
+ reduce(merge, result) {
3403
+ let index = 0;
3404
+ if (arguments.length === 1) {
3405
+ result = this[index++];
3410
3406
  }
3411
- },
3412
- async 'test method from host'($) {
3413
- let count = 0;
3414
- class A {
3415
- static a() {
3416
- return $mol_wire_sync(this).b();
3417
- }
3418
- static b() { return Promise.resolve(++count); }
3407
+ for (; index < this.length; ++index) {
3408
+ result = merge(result, this[index], index, this);
3419
3409
  }
3420
- $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
3421
- },
3422
- async 'test function'($) {
3423
- let count = 0;
3424
- class A {
3425
- static a() {
3426
- return $mol_wire_sync(this.b)();
3427
- }
3428
- static b() { return Promise.resolve(++count); }
3410
+ return result;
3411
+ }
3412
+ toReversed() {
3413
+ return $mol_range2(index => this[this.length - 1 - index], () => this.length);
3414
+ }
3415
+ slice(from = 0, to = this.length) {
3416
+ return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
3417
+ }
3418
+ some(check, context) {
3419
+ for (let index = 0; index < this.length; ++index) {
3420
+ if (check.call(context, this[index], index, this))
3421
+ return true;
3429
3422
  }
3430
- $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
3431
- },
3432
- async 'test construct itself'($) {
3433
- class A {
3434
- static instances = [];
3435
- static a() {
3436
- const a = new ($mol_wire_sync(A))();
3437
- this.instances.push(a);
3438
- $mol_wire_sync(this).b();
3439
- }
3440
- static b() { return Promise.resolve(); }
3423
+ return false;
3424
+ }
3425
+ every(check, context) {
3426
+ for (let index = 0; index < this.length; ++index) {
3427
+ if (!check.call(context, this[index], index, this))
3428
+ return false;
3441
3429
  }
3442
- await $mol_wire_async(A).a();
3443
- $mol_assert_equal(A.instances.length, 2);
3444
- $mol_assert_equal(A.instances[0] instanceof A, true);
3445
- $mol_assert_equal(A.instances[0], A.instances[1]);
3430
+ return true;
3446
3431
  }
3447
- });
3448
- })($ || ($ = {}));
3449
-
3450
- ;
3451
- "use strict";
3452
- var $;
3453
- (function ($) {
3454
- class $mol_promise extends Promise {
3455
- done;
3456
- fail;
3457
- constructor(executor) {
3458
- let done;
3459
- let fail;
3460
- super((d, f) => {
3461
- done = d;
3462
- fail = f;
3463
- executor?.(d, f);
3464
- });
3465
- this.done = done;
3466
- this.fail = fail;
3432
+ reverse() {
3433
+ return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
3434
+ }
3435
+ sort() {
3436
+ return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
3437
+ }
3438
+ indexOf(needle) {
3439
+ return this.findIndex(item => item === needle);
3440
+ }
3441
+ [Symbol.toPrimitive]() {
3442
+ return $mol_guid();
3467
3443
  }
3468
3444
  }
3469
- $.$mol_promise = $mol_promise;
3445
+ $.$mol_range2_array = $mol_range2_array;
3470
3446
  })($ || ($ = {}));
3471
3447
 
3472
3448
  ;
3473
3449
  "use strict";
3474
3450
  var $;
3475
3451
  (function ($) {
3476
- class $mol_after_timeout extends $mol_object2 {
3477
- delay;
3478
- task;
3479
- id;
3480
- constructor(delay, task) {
3481
- super();
3482
- this.delay = delay;
3483
- this.task = task;
3484
- this.id = setTimeout(task, delay);
3485
- }
3486
- destructor() {
3487
- clearTimeout(this.id);
3452
+ $mol_test({
3453
+ 'lazy calls'() {
3454
+ let calls = 0;
3455
+ const list = $mol_range2(index => (++calls, index), () => 10);
3456
+ $mol_assert_equal(true, list instanceof Array);
3457
+ $mol_assert_equal(list.length, 10);
3458
+ $mol_assert_equal(list[-1], undefined);
3459
+ $mol_assert_equal(list[0], 0);
3460
+ $mol_assert_equal(list[9], 9);
3461
+ $mol_assert_equal(list[9.5], undefined);
3462
+ $mol_assert_equal(list[10], undefined);
3463
+ $mol_assert_equal(calls, 2);
3464
+ },
3465
+ 'infinity list'() {
3466
+ let calls = 0;
3467
+ const list = $mol_range2(index => (++calls, index));
3468
+ $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
3469
+ $mol_assert_equal(list[0], 0);
3470
+ $mol_assert_equal(list[4], 4);
3471
+ $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
3472
+ $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
3473
+ $mol_assert_equal(calls, 3);
3474
+ },
3475
+ 'stringify'() {
3476
+ const list = $mol_range2(i => i, () => 5);
3477
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
3478
+ $mol_assert_equal(list.join(';'), '0;1;2;3;4');
3479
+ },
3480
+ 'for-of'() {
3481
+ let log = '';
3482
+ for (let i of $mol_range2(i => i + 1, () => 5)) {
3483
+ log += i;
3484
+ }
3485
+ $mol_assert_equal(log, '12345');
3486
+ },
3487
+ 'for-in'() {
3488
+ let log = '';
3489
+ for (let i in $mol_range2(i => i, () => 5)) {
3490
+ log += i;
3491
+ }
3492
+ $mol_assert_equal(log, '01234');
3493
+ },
3494
+ 'forEach'() {
3495
+ let log = '';
3496
+ $mol_range2(i => i, () => 5).forEach(i => log += i);
3497
+ $mol_assert_equal(log, '01234');
3498
+ },
3499
+ 'reduce'() {
3500
+ let calls = 0;
3501
+ const list = $mol_range2().slice(1, 6);
3502
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
3503
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
3504
+ },
3505
+ 'lazy concat'() {
3506
+ let calls1 = 0;
3507
+ let calls2 = 0;
3508
+ const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
3509
+ $mol_assert_equal(true, list instanceof Array);
3510
+ $mol_assert_equal(list.length, 15);
3511
+ $mol_assert_equal(list[0], 0);
3512
+ $mol_assert_equal(list[4], 4);
3513
+ $mol_assert_equal(list[5], 0);
3514
+ $mol_assert_equal(list[9], 4);
3515
+ $mol_assert_equal(list[10], 0);
3516
+ $mol_assert_equal(list[14], 4);
3517
+ $mol_assert_equal(list[15], undefined);
3518
+ $mol_assert_equal(calls1, 2);
3519
+ $mol_assert_equal(calls2, 2);
3520
+ },
3521
+ 'lazy filter'() {
3522
+ let calls = 0;
3523
+ const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
3524
+ $mol_assert_equal(true, list instanceof Array);
3525
+ $mol_assert_equal(list.length, 3);
3526
+ $mol_assert_equal(list[0], 1);
3527
+ $mol_assert_equal(list[2], 5);
3528
+ $mol_assert_equal(list[3], undefined);
3529
+ $mol_assert_equal(calls, 8);
3530
+ },
3531
+ 'lazy reverse'() {
3532
+ let calls = 0;
3533
+ const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
3534
+ $mol_assert_equal(true, list instanceof Array);
3535
+ $mol_assert_equal(list.length, 3);
3536
+ $mol_assert_equal(list[0], 9);
3537
+ $mol_assert_equal(list[2], 7);
3538
+ $mol_assert_equal(list[3], undefined);
3539
+ $mol_assert_equal(calls, 2);
3540
+ },
3541
+ 'lazy map'() {
3542
+ let calls1 = 0;
3543
+ let calls2 = 0;
3544
+ const source = $mol_range2(index => (++calls1, index), () => 5);
3545
+ const target = source.map((item, index, self) => {
3546
+ ++calls2;
3547
+ $mol_assert_equal(source, self);
3548
+ return index + 10;
3549
+ }, () => 5);
3550
+ $mol_assert_equal(true, target instanceof Array);
3551
+ $mol_assert_equal(target.length, 5);
3552
+ $mol_assert_equal(target[0], 10);
3553
+ $mol_assert_equal(target[4], 14);
3554
+ $mol_assert_equal(target[5], undefined);
3555
+ $mol_assert_equal(calls1, 2);
3556
+ $mol_assert_equal(calls2, 2);
3557
+ },
3558
+ 'lazy slice'() {
3559
+ let calls = 0;
3560
+ const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
3561
+ $mol_assert_equal(true, list instanceof Array);
3562
+ $mol_assert_equal(list.length, 4);
3563
+ $mol_assert_equal(list[0], 3);
3564
+ $mol_assert_equal(list[3], 6);
3565
+ $mol_assert_equal(list[4], undefined);
3566
+ $mol_assert_equal(calls, 2);
3567
+ },
3568
+ 'lazy some'() {
3569
+ let calls = 0;
3570
+ $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
3571
+ $mol_assert_equal(calls, 3);
3572
+ $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
3573
+ $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
3574
+ },
3575
+ 'lazy every'() {
3576
+ let calls = 0;
3577
+ $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
3578
+ $mol_assert_equal(calls, 3);
3579
+ $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
3580
+ $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
3581
+ },
3582
+ 'lazyfy'() {
3583
+ let calls = 0;
3584
+ const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
3585
+ $mol_assert_equal(true, list instanceof Array);
3586
+ $mol_assert_equal(list.length, 4);
3587
+ $mol_assert_equal(calls, 0);
3588
+ $mol_assert_equal(list[0], 12);
3589
+ $mol_assert_equal(list[3], 15);
3590
+ $mol_assert_equal(list[4], undefined);
3591
+ $mol_assert_equal(calls, 2);
3592
+ },
3593
+ 'prevent modification'() {
3594
+ const list = $mol_range2(i => i, () => 5);
3595
+ $mol_assert_fail(() => list.push(4), TypeError);
3596
+ $mol_assert_fail(() => list.pop(), TypeError);
3597
+ $mol_assert_fail(() => list.unshift(4), TypeError);
3598
+ $mol_assert_fail(() => list.shift(), TypeError);
3599
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
3600
+ $mol_assert_fail(() => list[1] = 2, TypeError);
3601
+ $mol_assert_fail(() => list.reverse(), TypeError);
3602
+ $mol_assert_fail(() => list.sort(), TypeError);
3603
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
3488
3604
  }
3489
- }
3490
- $.$mol_after_timeout = $mol_after_timeout;
3605
+ });
3491
3606
  })($ || ($ = {}));
3492
3607
 
3493
3608
  ;
3494
3609
  "use strict";
3495
3610
  var $;
3496
- (function ($_1) {
3497
- $mol_test_mocks.push($ => {
3498
- $.$mol_after_timeout = $mol_after_mock_timeout;
3611
+ (function ($) {
3612
+ $mol_test({
3613
+ 'nulls & undefineds'() {
3614
+ $mol_assert_ok($mol_compare_deep(null, null));
3615
+ $mol_assert_ok($mol_compare_deep(undefined, undefined));
3616
+ $mol_assert_not($mol_compare_deep(undefined, null));
3617
+ $mol_assert_not($mol_compare_deep({}, null));
3618
+ },
3619
+ 'number'() {
3620
+ $mol_assert_ok($mol_compare_deep(1, 1));
3621
+ $mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
3622
+ $mol_assert_not($mol_compare_deep(1, 2));
3623
+ $mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
3624
+ $mol_assert_not($mol_compare_deep(Object(1), Object(2)));
3625
+ },
3626
+ 'POJO'() {
3627
+ $mol_assert_ok($mol_compare_deep({}, {}));
3628
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
3629
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
3630
+ $mol_assert_not($mol_compare_deep({}, { a: undefined }));
3631
+ $mol_assert_not($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
3632
+ $mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
3633
+ $mol_assert_ok($mol_compare_deep(Object.create(null), Object.create(null)));
3634
+ },
3635
+ 'Array'() {
3636
+ $mol_assert_ok($mol_compare_deep([], []));
3637
+ $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
3638
+ $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
3639
+ $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
3640
+ $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
3641
+ $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
3642
+ },
3643
+ 'Non POJO are different'() {
3644
+ class Thing extends Object {
3645
+ }
3646
+ $mol_assert_not($mol_compare_deep(new Thing, new Thing));
3647
+ $mol_assert_not($mol_compare_deep(() => 1, () => 1));
3648
+ $mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
3649
+ },
3650
+ 'POJO with symbols'() {
3651
+ const sym = Symbol();
3652
+ $mol_assert_ok($mol_compare_deep({ [sym]: true }, { [sym]: true }));
3653
+ $mol_assert_not($mol_compare_deep({ [Symbol()]: true }, { [Symbol()]: true }));
3654
+ },
3655
+ 'same POJOs with cyclic reference'() {
3656
+ const a = { foo: {} };
3657
+ a['self'] = a;
3658
+ const b = { foo: {} };
3659
+ b['self'] = b;
3660
+ $mol_assert_ok($mol_compare_deep(a, b));
3661
+ },
3662
+ 'same POJOs with cyclic reference with cache warmup'() {
3663
+ const obj1 = { test: 1, obj3: null };
3664
+ const obj1_copy = { test: 1, obj3: null };
3665
+ const obj2 = { test: 2, obj1 };
3666
+ const obj2_copy = { test: 2, obj1: obj1_copy };
3667
+ const obj3 = { test: 3, obj2 };
3668
+ const obj3_copy = { test: 3, obj2: obj2_copy };
3669
+ obj1.obj3 = obj3;
3670
+ obj1_copy.obj3 = obj3_copy;
3671
+ $mol_assert_not($mol_compare_deep(obj1, {}));
3672
+ $mol_assert_not($mol_compare_deep(obj2, {}));
3673
+ $mol_assert_not($mol_compare_deep(obj3, {}));
3674
+ $mol_assert_ok($mol_compare_deep(obj3, obj3_copy));
3675
+ },
3676
+ 'Date'() {
3677
+ $mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
3678
+ $mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
3679
+ },
3680
+ 'RegExp'() {
3681
+ $mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
3682
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
3683
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
3684
+ },
3685
+ 'Error'() {
3686
+ $mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
3687
+ const fail = (message) => new Error(message);
3688
+ $mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
3689
+ $mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
3690
+ },
3691
+ 'Map'() {
3692
+ $mol_assert_ok($mol_compare_deep(new Map, new Map));
3693
+ $mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
3694
+ $mol_assert_ok($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
3695
+ $mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
3696
+ $mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[3], 2]])));
3697
+ },
3698
+ 'Set'() {
3699
+ $mol_assert_ok($mol_compare_deep(new Set, new Set));
3700
+ $mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
3701
+ $mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
3702
+ },
3703
+ 'Uint8Array'() {
3704
+ $mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
3705
+ $mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
3706
+ $mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
3707
+ },
3708
+ 'DataView'() {
3709
+ $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array().buffer), new DataView(new Uint8Array().buffer)));
3710
+ $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([0]).buffer)));
3711
+ $mol_assert_not($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([1]).buffer)));
3712
+ },
3713
+ 'Serializale'() {
3714
+ class User {
3715
+ name;
3716
+ rand;
3717
+ constructor(name, rand = Math.random()) {
3718
+ this.name = name;
3719
+ this.rand = rand;
3720
+ }
3721
+ [Symbol.toPrimitive](mode) {
3722
+ return this.name;
3723
+ }
3724
+ }
3725
+ $mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
3726
+ $mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
3727
+ },
3728
+ 'Iterable'() {
3729
+ $mol_assert_ok($mol_compare_deep(new URLSearchParams({ foo: 'bar' }), new URLSearchParams({ foo: 'bar' })));
3730
+ $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx' }), new URLSearchParams({ foo: 'yyy' })));
3731
+ $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx', bar: 'yyy' }), new URLSearchParams({ bar: 'yyy', foo: 'xxx' })));
3732
+ },
3499
3733
  });
3500
3734
  })($ || ($ = {}));
3501
3735
 
@@ -3503,202 +3737,142 @@ var $;
3503
3737
  "use strict";
3504
3738
  var $;
3505
3739
  (function ($) {
3506
- class $mol_after_work extends $mol_object2 {
3507
- delay;
3508
- task;
3509
- id;
3510
- constructor(delay, task) {
3511
- super();
3512
- this.delay = delay;
3513
- this.task = task;
3514
- this.id = requestIdleCallback(task, { timeout: delay });
3740
+ function $mol_assert_ok(value) {
3741
+ if (value)
3742
+ return;
3743
+ $mol_fail(new Error(`${value} ≠ true`));
3744
+ }
3745
+ $.$mol_assert_ok = $mol_assert_ok;
3746
+ function $mol_assert_not(value) {
3747
+ if (!value)
3748
+ return;
3749
+ $mol_fail(new Error(`${value} ≠ false`));
3750
+ }
3751
+ $.$mol_assert_not = $mol_assert_not;
3752
+ function $mol_assert_fail(handler, ErrorRight) {
3753
+ const fail = $.$mol_fail;
3754
+ try {
3755
+ $.$mol_fail = $.$mol_fail_hidden;
3756
+ handler();
3515
3757
  }
3516
- destructor() {
3517
- cancelIdleCallback(this.id);
3758
+ catch (error) {
3759
+ $.$mol_fail = fail;
3760
+ if (typeof ErrorRight === 'string') {
3761
+ $mol_assert_equal(error.message ?? error, ErrorRight);
3762
+ }
3763
+ else {
3764
+ $mol_assert_equal(error instanceof ErrorRight, true);
3765
+ }
3766
+ return error;
3518
3767
  }
3768
+ finally {
3769
+ $.$mol_fail = fail;
3770
+ }
3771
+ $mol_fail(new Error('Not failed'));
3519
3772
  }
3520
- $.$mol_after_work = $mol_after_work;
3521
- if (typeof requestIdleCallback !== 'function') {
3522
- $.$mol_after_work = $mol_after_timeout;
3773
+ $.$mol_assert_fail = $mol_assert_fail;
3774
+ function $mol_assert_like(...args) {
3775
+ $mol_assert_equal(...args);
3523
3776
  }
3524
- })($ || ($ = {}));
3525
-
3526
- ;
3527
- "use strict";
3528
- var $;
3529
- (function ($_1) {
3530
- $mol_test_mocks.push($ => {
3531
- $.$mol_after_work = $mol_after_mock_timeout;
3532
- });
3533
- })($ || ($ = {}));
3534
-
3535
- ;
3536
- "use strict";
3537
- var $;
3538
- (function ($) {
3539
- function $mol_wait_rest_async() {
3540
- return new Promise(done => {
3541
- new this.$mol_after_work(16, () => done(null));
3542
- });
3777
+ $.$mol_assert_like = $mol_assert_like;
3778
+ function $mol_assert_unique(...args) {
3779
+ for (let i = 0; i < args.length; ++i) {
3780
+ for (let j = 0; j < args.length; ++j) {
3781
+ if (i === j)
3782
+ continue;
3783
+ if (!$mol_compare_deep(args[i], args[j]))
3784
+ continue;
3785
+ return $mol_fail(new Error(`Uniquesess assertion failure`, { cause: { [i]: args[i], [i]: args[i] } }));
3786
+ }
3787
+ }
3543
3788
  }
3544
- $.$mol_wait_rest_async = $mol_wait_rest_async;
3545
- function $mol_wait_rest() {
3546
- return this.$mol_wire_sync(this).$mol_wait_rest_async();
3789
+ $.$mol_assert_unique = $mol_assert_unique;
3790
+ function $mol_assert_equal(...args) {
3791
+ for (let i = 1; i < args.length; ++i) {
3792
+ if ($mol_compare_deep(args[0], args[i]))
3793
+ continue;
3794
+ return $mol_fail(new Error(`Equality assertion failure`, { cause: { 0: args[0], [i]: args[i] } }));
3795
+ }
3547
3796
  }
3548
- $.$mol_wait_rest = $mol_wait_rest;
3549
- })($ || ($ = {}));
3550
-
3551
- ;
3552
- "use strict";
3553
- var $;
3554
- (function ($_1) {
3555
- var $$;
3556
- (function ($$) {
3557
- $mol_test_mocks.push($ => {
3558
- $.$mol_wait_timeout = function $mol_wait_timeout_mock(timeout) { };
3559
- $.$mol_wait_timeout_async = async function $mol_wait_timeout_async_mock(timeout) { };
3560
- });
3561
- })($$ = $_1.$$ || ($_1.$$ = {}));
3797
+ $.$mol_assert_equal = $mol_assert_equal;
3562
3798
  })($ || ($ = {}));
3563
3799
 
3564
3800
  ;
3565
3801
  "use strict";
3566
3802
  var $;
3567
3803
  (function ($) {
3568
- function $mol_wait_timeout_async(timeout) {
3569
- const promise = new $mol_promise();
3570
- const task = new this.$mol_after_timeout(timeout, () => promise.done());
3571
- return Object.assign(promise, {
3572
- destructor: () => task.destructor()
3573
- });
3574
- }
3575
- $.$mol_wait_timeout_async = $mol_wait_timeout_async;
3576
- function $mol_wait_timeout(timeout) {
3577
- return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
3578
- }
3579
- $.$mol_wait_timeout = $mol_wait_timeout;
3580
- })($ || ($ = {}));
3581
-
3582
- ;
3583
- "use strict";
3584
- var $;
3585
- (function ($_1) {
3586
- var $$;
3587
- (function ($$) {
3588
- $mol_test_mocks.push($ => {
3589
- $.$mol_wait_rest = function $mol_wait_rest_mock() { };
3590
- $.$mol_wait_rest_async = async function $mol_wait_rest_async_mock() { };
3591
- });
3592
- })($$ = $_1.$$ || ($_1.$$ = {}));
3804
+ $mol_test({
3805
+ 'must be false'() {
3806
+ $mol_assert_not(0);
3807
+ },
3808
+ 'must be true'() {
3809
+ $mol_assert_ok(1);
3810
+ },
3811
+ 'two must be equal'() {
3812
+ $mol_assert_equal(2, 2);
3813
+ },
3814
+ 'three must be equal'() {
3815
+ $mol_assert_equal(2, 2, 2);
3816
+ },
3817
+ 'two must be unique'() {
3818
+ $mol_assert_unique([2], [3]);
3819
+ },
3820
+ 'three must be unique'() {
3821
+ $mol_assert_unique([1], [2], [3]);
3822
+ },
3823
+ 'two must be alike'() {
3824
+ $mol_assert_equal([3], [3]);
3825
+ },
3826
+ 'three must be alike'() {
3827
+ $mol_assert_equal([3], [3], [3]);
3828
+ },
3829
+ 'two object must be alike'() {
3830
+ $mol_assert_equal({ a: 1 }, { a: 1 });
3831
+ },
3832
+ 'three object must be alike'() {
3833
+ $mol_assert_equal({ a: 1 }, { a: 1 }, { a: 1 });
3834
+ },
3835
+ });
3593
3836
  })($ || ($ = {}));
3594
3837
 
3595
3838
  ;
3596
3839
  "use strict";
3597
3840
  var $;
3598
- (function ($_1) {
3841
+ (function ($) {
3599
3842
  $mol_test({
3600
- async 'exec timeout auto kill child process'($) {
3601
- let close_mock = () => { };
3602
- const error_message = 'Run error, timeout';
3603
- function mol_run_spawn_sync_mock() {
3604
- return {
3605
- output: [],
3606
- stdout: error_message,
3607
- stderr: '',
3608
- status: 0,
3609
- signal: null,
3610
- pid: 123,
3611
- };
3612
- }
3613
- function mol_run_spawn_mock() {
3614
- return {
3615
- on(name, cb) {
3616
- if (name === 'exit')
3617
- close_mock = cb;
3618
- },
3619
- kill() { close_mock(); }
3620
- };
3621
- }
3622
- const context_mock = $.$mol_ambient({
3623
- $mol_run_spawn_sync: mol_run_spawn_sync_mock,
3624
- $mol_run_spawn: mol_run_spawn_mock
3625
- });
3626
- class $mol_run_mock extends $mol_run {
3627
- static get $() { return context_mock; }
3628
- static async_enabled() {
3629
- return true;
3630
- }
3631
- }
3632
- let message = '';
3633
- try {
3634
- const res = await $mol_wire_async($mol_run_mock).spawn({
3635
- command: 'sleep 10',
3636
- dir: '.',
3637
- timeout: 10,
3638
- env: { 'MOL_RUN_ASYNC': '1' }
3639
- });
3640
- }
3641
- catch (e) {
3642
- message = e.message;
3643
- }
3644
- $mol_assert_equal(message, error_message);
3645
- }
3843
+ 'encode empty'() {
3844
+ $mol_assert_equal($mol_charset_encode(''), new Uint8Array([]));
3845
+ },
3846
+ 'encode 1 octet'() {
3847
+ $mol_assert_equal($mol_charset_encode('F'), new Uint8Array([0x46]));
3848
+ },
3849
+ 'encode 2 octet'() {
3850
+ $mol_assert_equal($mol_charset_encode('Б'), new Uint8Array([0xd0, 0x91]));
3851
+ },
3852
+ 'encode 3 octet'() {
3853
+ $mol_assert_equal($mol_charset_encode('ह'), new Uint8Array([0xe0, 0xa4, 0xb9]));
3854
+ },
3855
+ 'encode 4 octet'() {
3856
+ $mol_assert_equal($mol_charset_encode('𐍈'), new Uint8Array([0xf0, 0x90, 0x8d, 0x88]));
3857
+ },
3858
+ 'encode surrogate pair'() {
3859
+ $mol_assert_equal($mol_charset_encode('😀'), new Uint8Array([0xf0, 0x9f, 0x98, 0x80]));
3860
+ },
3646
3861
  });
3647
3862
  })($ || ($ = {}));
3648
3863
 
3649
3864
  ;
3650
3865
  "use strict";
3651
3866
  var $;
3652
- (function ($) {
3653
- function $mol_dom_render_children(el, childNodes) {
3654
- const node_set = new Set(childNodes);
3655
- let nextNode = el.firstChild;
3656
- for (let view of childNodes) {
3657
- if (view == null)
3658
- continue;
3659
- if (view instanceof $mol_dom_context.Node) {
3660
- while (true) {
3661
- if (!nextNode) {
3662
- el.appendChild(view);
3663
- break;
3664
- }
3665
- if (nextNode == view) {
3666
- nextNode = nextNode.nextSibling;
3667
- break;
3668
- }
3669
- else {
3670
- if (node_set.has(nextNode)) {
3671
- el.insertBefore(view, nextNode);
3672
- break;
3673
- }
3674
- else {
3675
- const nn = nextNode.nextSibling;
3676
- el.removeChild(nextNode);
3677
- nextNode = nn;
3678
- }
3679
- }
3680
- }
3681
- }
3682
- else {
3683
- if (nextNode && nextNode.nodeName === '#text') {
3684
- const str = String(view);
3685
- if (nextNode.nodeValue !== str)
3686
- nextNode.nodeValue = str;
3687
- nextNode = nextNode.nextSibling;
3688
- }
3689
- else {
3690
- const textNode = $mol_dom_context.document.createTextNode(String(view));
3691
- el.insertBefore(textNode, nextNode);
3692
- }
3693
- }
3694
- }
3695
- while (nextNode) {
3696
- const currNode = nextNode;
3697
- nextNode = currNode.nextSibling;
3698
- el.removeChild(currNode);
3699
- }
3700
- }
3701
- $.$mol_dom_render_children = $mol_dom_render_children;
3867
+ (function ($_1) {
3868
+ $mol_test_mocks.push($ => {
3869
+ $.$mol_log3_come = () => { };
3870
+ $.$mol_log3_done = () => { };
3871
+ $.$mol_log3_fail = () => { };
3872
+ $.$mol_log3_warn = () => { };
3873
+ $.$mol_log3_rise = () => { };
3874
+ $.$mol_log3_area = () => () => { };
3875
+ });
3702
3876
  })($ || ($ = {}));
3703
3877
 
3704
3878
  ;
@@ -3707,238 +3881,135 @@ var $;
3707
3881
  ;
3708
3882
  "use strict";
3709
3883
 
3884
+ ;
3885
+ "use strict";
3886
+
3710
3887
  ;
3711
3888
  "use strict";
3712
3889
  var $;
3713
- (function ($) {
3714
- function $mol_dom_serialize(node) {
3715
- const serializer = new $mol_dom_context.XMLSerializer;
3716
- return serializer.serializeToString(node);
3717
- }
3718
- $.$mol_dom_serialize = $mol_dom_serialize;
3890
+ (function ($_1) {
3891
+ $mol_test({
3892
+ 'FQN of anon function'($) {
3893
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
3894
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
3895
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
3896
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
3897
+ },
3898
+ });
3719
3899
  })($ || ($ = {}));
3720
3900
 
3721
3901
  ;
3722
3902
  "use strict";
3723
3903
  var $;
3724
3904
  (function ($) {
3725
- $.$mol_jsx_prefix = '';
3726
- $.$mol_jsx_crumbs = '';
3727
- $.$mol_jsx_booked = null;
3728
- $.$mol_jsx_document = {
3729
- getElementById: () => null,
3730
- createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
3731
- createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
3732
- };
3733
- $.$mol_jsx_frag = '';
3734
- function $mol_jsx(Elem, props, ...childNodes) {
3735
- const id = props && props.id || '';
3736
- const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
3737
- const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
3738
- if (Elem && $.$mol_jsx_booked) {
3739
- if ($.$mol_jsx_booked.has(id)) {
3740
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
3741
- }
3742
- else {
3743
- $.$mol_jsx_booked.add(id);
3744
- }
3745
- }
3746
- let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
3747
- if ($.$mol_jsx_prefix) {
3748
- const prefix_ext = $.$mol_jsx_prefix;
3749
- const booked_ext = $.$mol_jsx_booked;
3750
- const crumbs_ext = $.$mol_jsx_crumbs;
3751
- for (const field in props) {
3752
- const func = props[field];
3753
- if (typeof func !== 'function')
3754
- continue;
3755
- const wrapper = function (...args) {
3756
- const prefix = $.$mol_jsx_prefix;
3757
- const booked = $.$mol_jsx_booked;
3758
- const crumbs = $.$mol_jsx_crumbs;
3759
- try {
3760
- $.$mol_jsx_prefix = prefix_ext;
3761
- $.$mol_jsx_booked = booked_ext;
3762
- $.$mol_jsx_crumbs = crumbs_ext;
3763
- return func.call(this, ...args);
3764
- }
3765
- finally {
3766
- $.$mol_jsx_prefix = prefix;
3767
- $.$mol_jsx_booked = booked;
3768
- $.$mol_jsx_crumbs = crumbs;
3769
- }
3770
- };
3771
- $mol_func_name_from(wrapper, func);
3772
- props[field] = wrapper;
3773
- }
3774
- }
3775
- if (typeof Elem !== 'string') {
3776
- if ('prototype' in Elem) {
3777
- const view = node && node[String(Elem)] || new Elem;
3778
- Object.assign(view, props);
3779
- view[Symbol.toStringTag] = guid;
3780
- view.childNodes = childNodes;
3781
- if (!view.ownerDocument)
3782
- view.ownerDocument = $.$mol_jsx_document;
3783
- view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
3784
- node = view.valueOf();
3785
- node[String(Elem)] = view;
3786
- return node;
3787
- }
3788
- else {
3789
- const prefix = $.$mol_jsx_prefix;
3790
- const booked = $.$mol_jsx_booked;
3791
- const crumbs = $.$mol_jsx_crumbs;
3792
- try {
3793
- $.$mol_jsx_prefix = guid;
3794
- $.$mol_jsx_booked = new Set;
3795
- $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
3796
- return Elem(props, ...childNodes);
3797
- }
3798
- finally {
3799
- $.$mol_jsx_prefix = prefix;
3800
- $.$mol_jsx_booked = booked;
3801
- $.$mol_jsx_crumbs = crumbs;
3802
- }
3905
+ $mol_test({
3906
+ 'get'() {
3907
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
3908
+ $mol_assert_equal(proxy.foo, 777);
3909
+ },
3910
+ 'has'() {
3911
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
3912
+ $mol_assert_equal('foo' in proxy, true);
3913
+ },
3914
+ 'set'() {
3915
+ const target = { foo: 777 };
3916
+ const proxy = $mol_delegate({}, () => target);
3917
+ proxy.foo = 123;
3918
+ $mol_assert_equal(target.foo, 123);
3919
+ },
3920
+ 'getOwnPropertyDescriptor'() {
3921
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
3922
+ $mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
3923
+ value: 777,
3924
+ writable: true,
3925
+ enumerable: true,
3926
+ configurable: true,
3927
+ });
3928
+ },
3929
+ 'ownKeys'() {
3930
+ const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
3931
+ $mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
3932
+ },
3933
+ 'getPrototypeOf'() {
3934
+ class Foo {
3803
3935
  }
3804
- }
3805
- if (!node) {
3806
- node = Elem
3807
- ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
3808
- : $.$mol_jsx_document.createDocumentFragment();
3809
- }
3810
- $mol_dom_render_children(node, [].concat(...childNodes));
3811
- if (!Elem)
3812
- return node;
3813
- if (guid)
3814
- node.id = guid;
3815
- for (const key in props) {
3816
- if (key === 'id')
3817
- continue;
3818
- if (typeof props[key] === 'string') {
3819
- if (typeof node[key] === 'string')
3820
- node[key] = props[key];
3821
- node.setAttribute(key, props[key]);
3936
+ const proxy = $mol_delegate({}, () => new Foo);
3937
+ $mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
3938
+ },
3939
+ 'setPrototypeOf'() {
3940
+ class Foo {
3822
3941
  }
3823
- else if (props[key] &&
3824
- typeof props[key] === 'object' &&
3825
- Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
3826
- if (typeof node[key] === 'object') {
3827
- Object.assign(node[key], props[key]);
3828
- continue;
3829
- }
3942
+ const target = {};
3943
+ const proxy = $mol_delegate({}, () => target);
3944
+ Object.setPrototypeOf(proxy, Foo.prototype);
3945
+ $mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
3946
+ },
3947
+ 'instanceof'() {
3948
+ class Foo {
3830
3949
  }
3831
- else {
3832
- node[key] = props[key];
3950
+ const proxy = $mol_delegate({}, () => new Foo);
3951
+ $mol_assert_ok(proxy instanceof Foo);
3952
+ $mol_assert_ok(proxy instanceof $mol_delegate);
3953
+ },
3954
+ 'autobind'() {
3955
+ class Foo {
3833
3956
  }
3834
- }
3835
- if ($.$mol_jsx_crumbs)
3836
- node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
3837
- return node;
3838
- }
3839
- $.$mol_jsx = $mol_jsx;
3957
+ const proxy = $mol_delegate({}, () => new Foo);
3958
+ $mol_assert_ok(proxy instanceof Foo);
3959
+ $mol_assert_ok(proxy instanceof $mol_delegate);
3960
+ },
3961
+ });
3840
3962
  })($ || ($ = {}));
3841
3963
 
3842
3964
  ;
3843
3965
  "use strict";
3844
3966
  var $;
3845
- (function ($) {
3967
+ (function ($_1) {
3846
3968
  $mol_test({
3847
- 'Make empty div'() {
3848
- $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
3849
- },
3850
- 'Define native field'() {
3851
- const dom = $mol_jsx("input", { value: '123' });
3852
- $mol_assert_equal(dom.outerHTML, '<input value="123">');
3853
- $mol_assert_equal(dom.value, '123');
3854
- },
3855
- 'Define classes'() {
3856
- const dom = $mol_jsx("div", { class: 'foo bar' });
3857
- $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
3858
- },
3859
- 'Define styles'() {
3860
- const dom = $mol_jsx("div", { style: { color: 'red' } });
3861
- $mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
3862
- },
3863
- 'Define dataset'() {
3864
- const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
3865
- $mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
3866
- },
3867
- 'Define attributes'() {
3868
- const dom = $mol_jsx("div", { lang: "ru", hidden: true });
3869
- $mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
3870
- },
3871
- 'Define child nodes'() {
3872
- const dom = $mol_jsx("div", null,
3873
- "hello",
3874
- $mol_jsx("strong", null, "world"),
3875
- "!");
3876
- $mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
3877
- },
3878
- 'Make fragment'() {
3879
- const dom = $mol_jsx($mol_jsx_frag, null,
3880
- $mol_jsx("br", null),
3881
- $mol_jsx("hr", null));
3882
- $mol_assert_equal($mol_dom_serialize(dom), '<br xmlns="http://www.w3.org/1999/xhtml" /><hr xmlns="http://www.w3.org/1999/xhtml" />');
3883
- },
3884
- 'Spread fragment'() {
3885
- const dom = $mol_jsx("div", null,
3886
- $mol_jsx($mol_jsx_frag, null,
3887
- $mol_jsx("br", null),
3888
- $mol_jsx("hr", null)));
3889
- $mol_assert_equal(dom.outerHTML, '<div><br><hr></div>');
3890
- },
3891
- 'Function as component'() {
3892
- const Button = (props, target) => {
3893
- return $mol_jsx("button", { title: props.hint }, target());
3894
- };
3895
- const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
3896
- $mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
3969
+ 'span for same uri'($) {
3970
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
3971
+ const child = span.span(4, 5, 8);
3972
+ $mol_assert_equal(child.uri, 'test.ts');
3973
+ $mol_assert_equal(child.row, 4);
3974
+ $mol_assert_equal(child.col, 5);
3975
+ $mol_assert_equal(child.length, 8);
3897
3976
  },
3898
- 'Nested guid generation'() {
3899
- const Foo = () => {
3900
- return $mol_jsx("div", null,
3901
- $mol_jsx(Bar, { id: "bar" },
3902
- $mol_jsx("img", { id: "icon" })));
3903
- };
3904
- const Bar = (props, icon) => {
3905
- return $mol_jsx("span", null,
3906
- icon,
3907
- $mol_jsx("i", { id: "label" }));
3908
- };
3909
- const dom = $mol_jsx(Foo, { id: "foo" });
3910
- $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>');
3977
+ 'span after of given position'($) {
3978
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
3979
+ const child = span.after(11);
3980
+ $mol_assert_equal(child.uri, 'test.ts');
3981
+ $mol_assert_equal(child.row, 1);
3982
+ $mol_assert_equal(child.col, 7);
3983
+ $mol_assert_equal(child.length, 11);
3911
3984
  },
3912
- 'Fail on non unique ids'() {
3913
- const App = () => {
3914
- return $mol_jsx("div", null,
3915
- $mol_jsx("span", { id: "bar" }),
3916
- $mol_jsx("span", { id: "bar" }));
3917
- };
3918
- $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
3985
+ 'slice span - regular'($) {
3986
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
3987
+ const child = span.slice(1, 4);
3988
+ $mol_assert_equal(child.row, 1);
3989
+ $mol_assert_equal(child.col, 4);
3990
+ $mol_assert_equal(child.length, 3);
3991
+ const child2 = span.slice(2, 2);
3992
+ $mol_assert_equal(child2.col, 5);
3993
+ $mol_assert_equal(child2.length, 0);
3919
3994
  },
3920
- 'Owner based guid generationn'() {
3921
- const Foo = () => {
3922
- return $mol_jsx("div", null,
3923
- $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
3924
- };
3925
- const Bar = (props) => {
3926
- return $mol_jsx("span", null, props.icon());
3927
- };
3928
- const dom = $mol_jsx(Foo, { id: "app" });
3929
- $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>');
3995
+ 'slice span - negative'($) {
3996
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
3997
+ const child = span.slice(-3, -1);
3998
+ $mol_assert_equal(child.row, 1);
3999
+ $mol_assert_equal(child.col, 5);
4000
+ $mol_assert_equal(child.length, 2);
3930
4001
  },
3931
- 'Fail on same ids from different caller'() {
3932
- const Foo = () => {
3933
- return $mol_jsx("div", null,
3934
- $mol_jsx("img", { id: "icon" }),
3935
- $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
3936
- };
3937
- const Bar = (props) => {
3938
- return $mol_jsx("span", null, props.icon());
3939
- };
3940
- $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
4002
+ 'slice span - out of range'($) {
4003
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
4004
+ $mol_assert_fail(() => span.slice(-1, 3), `End value '3' can't be less than begin value (test.ts#1:3/5)`);
4005
+ $mol_assert_fail(() => span.slice(1, 6), `End value '6' out of range (test.ts#1:3/5)`);
4006
+ $mol_assert_fail(() => span.slice(1, 10), `End value '10' out of range (test.ts#1:3/5)`);
3941
4007
  },
4008
+ 'error handling'($) {
4009
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
4010
+ const error = span.error('Some error');
4011
+ $mol_assert_equal(error.message, 'Some error (test.ts#1:3/4)');
4012
+ }
3942
4013
  });
3943
4014
  })($ || ($ = {}));
3944
4015
 
@@ -3946,287 +4017,176 @@ var $;
3946
4017
  "use strict";
3947
4018
  var $;
3948
4019
  (function ($) {
3949
- function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
3950
- const source = typeof item === 'function' ? new $mol_range2_array() : item;
3951
- if (typeof item !== 'function') {
3952
- item = index => source[index];
3953
- size = () => source.length;
3954
- }
3955
- return new Proxy(source, {
3956
- get(target, field) {
3957
- if (typeof field === 'string') {
3958
- if (field === 'length')
3959
- return size();
3960
- const index = Number(field);
3961
- if (index < 0)
3962
- return undefined;
3963
- if (index >= size())
3964
- return undefined;
3965
- if (index === Math.trunc(index))
3966
- return item(index);
3967
- }
3968
- return $mol_range2_array.prototype[field];
3969
- },
3970
- set(target, field) {
3971
- return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
3972
- },
3973
- ownKeys(target) {
3974
- return [...Array(size())].map((v, i) => String(i)).concat('length');
3975
- },
3976
- getOwnPropertyDescriptor(target, field) {
3977
- if (field === "length")
3978
- return {
3979
- value: size(),
3980
- writable: true,
3981
- enumerable: false,
3982
- configurable: false,
3983
- };
3984
- const index = Number(field);
3985
- if (index === Math.trunc(index))
3986
- return {
3987
- get: () => this.get(target, field, this),
3988
- enumerable: true,
3989
- configurable: true,
3990
- };
3991
- return Object.getOwnPropertyDescriptor(target, field);
3992
- }
3993
- });
3994
- }
3995
- $.$mol_range2 = $mol_range2;
3996
- class $mol_range2_array extends Array {
3997
- concat(...tail) {
3998
- if (tail.length === 0)
3999
- return this;
4000
- if (tail.length > 1) {
4001
- let list = this;
4002
- for (let item of tail)
4003
- list = list.concat(item);
4004
- return list;
4005
- }
4006
- return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
4007
- }
4008
- filter(check, context) {
4009
- const filtered = [];
4010
- let cursor = -1;
4011
- return $mol_range2(index => {
4012
- while (cursor < this.length && index >= filtered.length - 1) {
4013
- const val = this[++cursor];
4014
- if (check(val, cursor, this))
4015
- filtered.push(val);
4016
- }
4017
- return filtered[index];
4018
- }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
4019
- }
4020
- forEach(proceed, context) {
4021
- for (let [key, value] of this.entries())
4022
- proceed.call(context, value, key, this);
4023
- }
4024
- map(proceed, context) {
4025
- return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
4026
- }
4027
- reduce(merge, result) {
4028
- let index = 0;
4029
- if (arguments.length === 1) {
4030
- result = this[index++];
4031
- }
4032
- for (; index < this.length; ++index) {
4033
- result = merge(result, this[index], index, this);
4034
- }
4035
- return result;
4036
- }
4037
- toReversed() {
4038
- return $mol_range2(index => this[this.length - 1 - index], () => this.length);
4039
- }
4040
- slice(from = 0, to = this.length) {
4041
- return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
4042
- }
4043
- some(check, context) {
4044
- for (let index = 0; index < this.length; ++index) {
4045
- if (check.call(context, this[index], index, this))
4046
- return true;
4047
- }
4048
- return false;
4049
- }
4050
- every(check, context) {
4051
- for (let index = 0; index < this.length; ++index) {
4052
- if (!check.call(context, this[index], index, this))
4053
- return false;
4054
- }
4055
- return true;
4056
- }
4057
- reverse() {
4058
- return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
4059
- }
4060
- sort() {
4061
- return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
4062
- }
4063
- indexOf(needle) {
4064
- return this.findIndex(item => item === needle);
4065
- }
4066
- [Symbol.toPrimitive]() {
4067
- return $mol_guid();
4068
- }
4069
- }
4070
- $.$mol_range2_array = $mol_range2_array;
4020
+ $mol_test({
4021
+ 'all cases of using maybe'() {
4022
+ $mol_assert_equal($mol_maybe(0)[0], 0);
4023
+ $mol_assert_equal($mol_maybe(false)[0], false);
4024
+ $mol_assert_equal($mol_maybe(null)[0], void 0);
4025
+ $mol_assert_equal($mol_maybe(void 0)[0], void 0);
4026
+ $mol_assert_equal($mol_maybe(void 0).map(v => v.toString())[0], void 0);
4027
+ $mol_assert_equal($mol_maybe(0).map(v => v.toString())[0], '0');
4028
+ },
4029
+ });
4071
4030
  })($ || ($ = {}));
4072
4031
 
4073
4032
  ;
4074
4033
  "use strict";
4075
4034
  var $;
4076
- (function ($) {
4035
+ (function ($_1) {
4036
+ function check(tree, ideal) {
4037
+ $mol_assert_equal(tree.toString(), $$.$mol_tree2_from_string(ideal).toString());
4038
+ }
4077
4039
  $mol_test({
4078
- 'lazy calls'() {
4079
- let calls = 0;
4080
- const list = $mol_range2(index => (++calls, index), () => 10);
4081
- $mol_assert_equal(true, list instanceof Array);
4082
- $mol_assert_equal(list.length, 10);
4083
- $mol_assert_equal(list[-1], undefined);
4084
- $mol_assert_equal(list[0], 0);
4085
- $mol_assert_equal(list[9], 9);
4086
- $mol_assert_equal(list[9.5], undefined);
4087
- $mol_assert_equal(list[10], undefined);
4088
- $mol_assert_equal(calls, 2);
4089
- },
4090
- 'infinity list'() {
4091
- let calls = 0;
4092
- const list = $mol_range2(index => (++calls, index));
4093
- $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
4094
- $mol_assert_equal(list[0], 0);
4095
- $mol_assert_equal(list[4], 4);
4096
- $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
4097
- $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
4098
- $mol_assert_equal(calls, 3);
4099
- },
4100
- 'stringify'() {
4101
- const list = $mol_range2(i => i, () => 5);
4102
- $mol_assert_equal(list.toString(), '0,1,2,3,4');
4103
- $mol_assert_equal(list.join(';'), '0;1;2;3;4');
4104
- },
4105
- 'for-of'() {
4106
- let log = '';
4107
- for (let i of $mol_range2(i => i + 1, () => 5)) {
4108
- log += i;
4109
- }
4110
- $mol_assert_equal(log, '12345');
4111
- },
4112
- 'for-in'() {
4113
- let log = '';
4114
- for (let i in $mol_range2(i => i, () => 5)) {
4115
- log += i;
4116
- }
4117
- $mol_assert_equal(log, '01234');
4040
+ 'inserting'($) {
4041
+ check($.$mol_tree2_from_string(`
4042
+ a b c d
4043
+ `).insert($mol_tree2.struct('x'), 'a', 'b', 'c'), `
4044
+ a b x
4045
+ `);
4046
+ check($.$mol_tree2_from_string(`
4047
+ a b
4048
+ `).insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd'), `
4049
+ a b c x
4050
+ `);
4051
+ check($.$mol_tree2_from_string(`
4052
+ a b c d
4053
+ `)
4054
+ .insert($mol_tree2.struct('x'), 0, 0, 0), `
4055
+ a b x
4056
+ `);
4057
+ check($.$mol_tree2_from_string(`
4058
+ a b
4059
+ `)
4060
+ .insert($mol_tree2.struct('x'), 0, 0, 0, 0), `
4061
+ a b \\
4062
+ x
4063
+ `);
4064
+ check($.$mol_tree2_from_string(`
4065
+ a b c d
4066
+ `)
4067
+ .insert($mol_tree2.struct('x'), null, null, null), `
4068
+ a b x
4069
+ `);
4070
+ check($.$mol_tree2_from_string(`
4071
+ a b
4072
+ `)
4073
+ .insert($mol_tree2.struct('x'), null, null, null, null), `
4074
+ a b \\
4075
+ x
4076
+ `);
4118
4077
  },
4119
- 'forEach'() {
4120
- let log = '';
4121
- $mol_range2(i => i, () => 5).forEach(i => log += i);
4122
- $mol_assert_equal(log, '01234');
4078
+ 'updating'($) {
4079
+ check($.$mol_tree2_from_string(`
4080
+ a b c d
4081
+ `).update([], 'a', 'b', 'c')[0], `
4082
+ a b
4083
+ `);
4084
+ check($.$mol_tree2_from_string(`
4085
+ a b c d
4086
+ `).update([$mol_tree2.struct('x')])[0], `
4087
+ x
4088
+ `);
4089
+ check($.$mol_tree2_from_string(`
4090
+ a b c d
4091
+ `).update([$mol_tree2.struct('x'), $mol_tree2.struct('y')], 'a', 'b', 'c')[0], `
4092
+ a b
4093
+ x
4094
+ y
4095
+ `);
4123
4096
  },
4124
- 'reduce'() {
4125
- let calls = 0;
4126
- const list = $mol_range2().slice(1, 6);
4127
- $mol_assert_equal(list.reduce((s, v) => s + v), 15);
4128
- $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
4097
+ 'deleting'($) {
4098
+ const base = $.$mol_tree2_from_string(`
4099
+ a b c d
4100
+ `);
4101
+ check(base.insert(null, 'a', 'b', 'c'), `
4102
+ a b
4103
+ `);
4104
+ check(base.update(base.select('a', 'b', 'c', null).kids, 'a', 'b', 'c')[0], `
4105
+ a b d
4106
+ `);
4107
+ check(base.insert(null, 0, 0, 0), `
4108
+ a b
4109
+ `);
4129
4110
  },
4130
- 'lazy concat'() {
4131
- let calls1 = 0;
4132
- let calls2 = 0;
4133
- const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
4134
- $mol_assert_equal(true, list instanceof Array);
4135
- $mol_assert_equal(list.length, 15);
4136
- $mol_assert_equal(list[0], 0);
4137
- $mol_assert_equal(list[4], 4);
4138
- $mol_assert_equal(list[5], 0);
4139
- $mol_assert_equal(list[9], 4);
4140
- $mol_assert_equal(list[10], 0);
4141
- $mol_assert_equal(list[14], 4);
4142
- $mol_assert_equal(list[15], undefined);
4143
- $mol_assert_equal(calls1, 2);
4144
- $mol_assert_equal(calls2, 2);
4111
+ 'hack'($) {
4112
+ const res = $.$mol_tree2_from_string(`
4113
+ foo bar xxx
4114
+ `)
4115
+ .hack({
4116
+ 'bar': (input, belt) => [input.struct('777', input.hack(belt))],
4117
+ });
4118
+ $mol_assert_equal(res.map(String), ['foo 777 xxx\n']);
4145
4119
  },
4146
- 'lazy filter'() {
4147
- let calls = 0;
4148
- const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
4149
- $mol_assert_equal(true, list instanceof Array);
4150
- $mol_assert_equal(list.length, 3);
4151
- $mol_assert_equal(list[0], 1);
4152
- $mol_assert_equal(list[2], 5);
4153
- $mol_assert_equal(list[3], undefined);
4154
- $mol_assert_equal(calls, 8);
4120
+ });
4121
+ })($ || ($ = {}));
4122
+
4123
+ ;
4124
+ "use strict";
4125
+ var $;
4126
+ (function ($_1) {
4127
+ $mol_test({
4128
+ 'tree parsing'($) {
4129
+ $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
4130
+ $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
4131
+ $mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
4132
+ $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
4133
+ $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
4134
+ $mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
4135
+ $mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
4136
+ $mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
4155
4137
  },
4156
- 'lazy reverse'() {
4157
- let calls = 0;
4158
- const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
4159
- $mol_assert_equal(true, list instanceof Array);
4160
- $mol_assert_equal(list.length, 3);
4161
- $mol_assert_equal(list[0], 9);
4162
- $mol_assert_equal(list[2], 7);
4163
- $mol_assert_equal(list[3], undefined);
4164
- $mol_assert_equal(calls, 2);
4138
+ 'Too many tabs'($) {
4139
+ const tree = `
4140
+ foo
4141
+ bar
4142
+ `;
4143
+ $mol_assert_fail(() => {
4144
+ $.$mol_tree2_from_string(tree, 'test');
4145
+ }, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
4165
4146
  },
4166
- 'lazy map'() {
4167
- let calls1 = 0;
4168
- let calls2 = 0;
4169
- const source = $mol_range2(index => (++calls1, index), () => 5);
4170
- const target = source.map((item, index, self) => {
4171
- ++calls2;
4172
- $mol_assert_equal(source, self);
4173
- return index + 10;
4174
- }, () => 5);
4175
- $mol_assert_equal(true, target instanceof Array);
4176
- $mol_assert_equal(target.length, 5);
4177
- $mol_assert_equal(target[0], 10);
4178
- $mol_assert_equal(target[4], 14);
4179
- $mol_assert_equal(target[5], undefined);
4180
- $mol_assert_equal(calls1, 2);
4181
- $mol_assert_equal(calls2, 2);
4147
+ 'Too few tabs'($) {
4148
+ const tree = `
4149
+ foo
4150
+ bar
4151
+ `;
4152
+ $mol_assert_fail(() => {
4153
+ $.$mol_tree2_from_string(tree, 'test');
4154
+ }, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
4182
4155
  },
4183
- 'lazy slice'() {
4184
- let calls = 0;
4185
- const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
4186
- $mol_assert_equal(true, list instanceof Array);
4187
- $mol_assert_equal(list.length, 4);
4188
- $mol_assert_equal(list[0], 3);
4189
- $mol_assert_equal(list[3], 6);
4190
- $mol_assert_equal(list[4], undefined);
4191
- $mol_assert_equal(calls, 2);
4156
+ 'Wrong nodes separator at start'($) {
4157
+ const tree = `foo\n \tbar\n`;
4158
+ $mol_assert_fail(() => {
4159
+ $.$mol_tree2_from_string(tree, 'test');
4160
+ }, 'Wrong nodes separator\ntest#2:1/2\n!!\n \tbar');
4192
4161
  },
4193
- 'lazy some'() {
4194
- let calls = 0;
4195
- $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
4196
- $mol_assert_equal(calls, 3);
4197
- $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
4198
- $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
4162
+ 'Wrong nodes separator in the middle'($) {
4163
+ const tree = `foo bar\n`;
4164
+ $mol_assert_fail(() => {
4165
+ $.$mol_tree2_from_string(tree, 'test');
4166
+ }, 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar');
4199
4167
  },
4200
- 'lazy every'() {
4201
- let calls = 0;
4202
- $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
4203
- $mol_assert_equal(calls, 3);
4204
- $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
4205
- $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
4168
+ 'Unexpected EOF, LF required'($) {
4169
+ const tree = ` foo`;
4170
+ $mol_assert_fail(() => {
4171
+ $.$mol_tree2_from_string(tree, 'test');
4172
+ }, 'Unexpected EOF, LF required\ntest#1:5/1\n !\n foo');
4206
4173
  },
4207
- 'lazyfy'() {
4208
- let calls = 0;
4209
- const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
4210
- $mol_assert_equal(true, list instanceof Array);
4211
- $mol_assert_equal(list.length, 4);
4212
- $mol_assert_equal(calls, 0);
4213
- $mol_assert_equal(list[0], 12);
4214
- $mol_assert_equal(list[3], 15);
4215
- $mol_assert_equal(list[4], undefined);
4216
- $mol_assert_equal(calls, 2);
4174
+ 'Errors skip and collect'($) {
4175
+ const tree = `foo bar`;
4176
+ const errors = [];
4177
+ const $$ = $.$mol_ambient({
4178
+ $mol_fail: (error) => {
4179
+ errors.push(error.message);
4180
+ return null;
4181
+ }
4182
+ });
4183
+ const res = $$.$mol_tree2_from_string(tree, 'test');
4184
+ $mol_assert_like(errors, [
4185
+ 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar',
4186
+ 'Unexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
4187
+ ]);
4188
+ $mol_assert_equal(res.toString(), 'foo bar\n');
4217
4189
  },
4218
- 'prevent modification'() {
4219
- const list = $mol_range2(i => i, () => 5);
4220
- $mol_assert_fail(() => list.push(4), TypeError);
4221
- $mol_assert_fail(() => list.pop(), TypeError);
4222
- $mol_assert_fail(() => list.unshift(4), TypeError);
4223
- $mol_assert_fail(() => list.shift(), TypeError);
4224
- $mol_assert_fail(() => list.splice(1, 2), TypeError);
4225
- $mol_assert_fail(() => list[1] = 2, TypeError);
4226
- $mol_assert_fail(() => list.reverse(), TypeError);
4227
- $mol_assert_fail(() => list.sort(), TypeError);
4228
- $mol_assert_equal(list.toString(), '0,1,2,3,4');
4229
- }
4230
4190
  });
4231
4191
  })($ || ($ = {}));
4232
4192
 
@@ -4235,125 +4195,130 @@ var $;
4235
4195
  var $;
4236
4196
  (function ($) {
4237
4197
  $mol_test({
4238
- 'nulls & undefineds'() {
4239
- $mol_assert_ok($mol_compare_deep(null, null));
4240
- $mol_assert_ok($mol_compare_deep(undefined, undefined));
4241
- $mol_assert_not($mol_compare_deep(undefined, null));
4242
- $mol_assert_not($mol_compare_deep({}, null));
4243
- },
4244
- 'number'() {
4245
- $mol_assert_ok($mol_compare_deep(1, 1));
4246
- $mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
4247
- $mol_assert_not($mol_compare_deep(1, 2));
4248
- $mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
4249
- $mol_assert_not($mol_compare_deep(Object(1), Object(2)));
4250
- },
4251
- 'POJO'() {
4252
- $mol_assert_ok($mol_compare_deep({}, {}));
4253
- $mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
4254
- $mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
4255
- $mol_assert_not($mol_compare_deep({}, { a: undefined }));
4256
- $mol_assert_not($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
4257
- $mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
4258
- $mol_assert_ok($mol_compare_deep(Object.create(null), Object.create(null)));
4259
- },
4260
- 'Array'() {
4261
- $mol_assert_ok($mol_compare_deep([], []));
4262
- $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
4263
- $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
4264
- $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
4265
- $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
4266
- $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
4198
+ 'fromJSON'() {
4199
+ $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
4200
+ $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
4201
+ $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
4202
+ $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
4203
+ $mol_assert_equal($mol_tree2_from_json(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
4204
+ $mol_assert_equal($mol_tree2_from_json({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
4267
4205
  },
4268
- 'Non POJO are different'() {
4269
- class Thing extends Object {
4206
+ });
4207
+ })($ || ($ = {}));
4208
+
4209
+ ;
4210
+ "use strict";
4211
+ var $;
4212
+ (function ($) {
4213
+ $mol_test({
4214
+ 'auto name'() {
4215
+ class Invalid extends $mol_error_mix {
4270
4216
  }
4271
- $mol_assert_not($mol_compare_deep(new Thing, new Thing));
4272
- $mol_assert_not($mol_compare_deep(() => 1, () => 1));
4273
- $mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
4274
- },
4275
- 'POJO with symbols'() {
4276
- const sym = Symbol();
4277
- $mol_assert_ok($mol_compare_deep({ [sym]: true }, { [sym]: true }));
4278
- $mol_assert_not($mol_compare_deep({ [Symbol()]: true }, { [Symbol()]: true }));
4279
- },
4280
- 'same POJOs with cyclic reference'() {
4281
- const a = { foo: {} };
4282
- a['self'] = a;
4283
- const b = { foo: {} };
4284
- b['self'] = b;
4285
- $mol_assert_ok($mol_compare_deep(a, b));
4286
- },
4287
- 'same POJOs with cyclic reference with cache warmup'() {
4288
- const obj1 = { test: 1, obj3: null };
4289
- const obj1_copy = { test: 1, obj3: null };
4290
- const obj2 = { test: 2, obj1 };
4291
- const obj2_copy = { test: 2, obj1: obj1_copy };
4292
- const obj3 = { test: 3, obj2 };
4293
- const obj3_copy = { test: 3, obj2: obj2_copy };
4294
- obj1.obj3 = obj3;
4295
- obj1_copy.obj3 = obj3_copy;
4296
- $mol_assert_not($mol_compare_deep(obj1, {}));
4297
- $mol_assert_not($mol_compare_deep(obj2, {}));
4298
- $mol_assert_not($mol_compare_deep(obj3, {}));
4299
- $mol_assert_ok($mol_compare_deep(obj3, obj3_copy));
4300
- },
4301
- 'Date'() {
4302
- $mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
4303
- $mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
4304
- },
4305
- 'RegExp'() {
4306
- $mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
4307
- $mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
4308
- $mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
4217
+ const mix = new Invalid('foo');
4218
+ $mol_assert_equal(mix.name, 'Invalid_Error');
4309
4219
  },
4310
- 'Error'() {
4311
- $mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
4312
- const fail = (message) => new Error(message);
4313
- $mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
4314
- $mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
4220
+ 'simpe mix'() {
4221
+ const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
4222
+ $mol_assert_equal(mix.message, 'foo');
4223
+ $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
4315
4224
  },
4316
- 'Map'() {
4317
- $mol_assert_ok($mol_compare_deep(new Map, new Map));
4318
- $mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
4319
- $mol_assert_ok($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
4320
- $mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
4321
- $mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[3], 2]])));
4225
+ 'provide additional info'() {
4226
+ class Invalid extends $mol_error_mix {
4227
+ }
4228
+ const mix = new $mol_error_mix('Wrong password', {}, new Invalid('Too short', { value: 'p@ssw0rd', hint: '> 8 letters' }), new Invalid('Too simple', { value: 'p@ssw0rd', hint: 'need capital letter' }));
4229
+ const hints = [];
4230
+ if (mix instanceof $mol_error_mix) {
4231
+ for (const er of mix.errors) {
4232
+ if (er instanceof Invalid) {
4233
+ hints.push(er.cause?.hint ?? '');
4234
+ }
4235
+ }
4236
+ }
4237
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
4322
4238
  },
4323
- 'Set'() {
4324
- $mol_assert_ok($mol_compare_deep(new Set, new Set));
4325
- $mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
4326
- $mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
4239
+ });
4240
+ })($ || ($ = {}));
4241
+
4242
+ ;
4243
+ "use strict";
4244
+ var $;
4245
+ (function ($_1) {
4246
+ $mol_test({
4247
+ 'init with overload'() {
4248
+ class X extends $mol_object {
4249
+ foo() {
4250
+ return 1;
4251
+ }
4252
+ }
4253
+ var x = X.make({
4254
+ foo: () => 2,
4255
+ });
4256
+ $mol_assert_equal(x.foo(), 2);
4327
4257
  },
4328
- 'Uint8Array'() {
4329
- $mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
4330
- $mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
4331
- $mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
4258
+ 'Context in instance inherits from class'($) {
4259
+ const custom = $.$mol_ambient({});
4260
+ class X extends $.$mol_object {
4261
+ static $ = custom;
4262
+ }
4263
+ $mol_assert_equal(new X().$, custom);
4332
4264
  },
4333
- 'DataView'() {
4334
- $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array().buffer), new DataView(new Uint8Array().buffer)));
4335
- $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([0]).buffer)));
4336
- $mol_assert_not($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([1]).buffer)));
4265
+ });
4266
+ })($ || ($ = {}));
4267
+
4268
+ ;
4269
+ "use strict";
4270
+ var $;
4271
+ (function ($_1) {
4272
+ $mol_test({
4273
+ 'Collect deps'() {
4274
+ const pub1 = new $mol_wire_pub;
4275
+ const pub2 = new $mol_wire_pub;
4276
+ const sub = new $mol_wire_pub_sub;
4277
+ const bu1 = sub.track_on();
4278
+ try {
4279
+ pub1.promote();
4280
+ pub2.promote();
4281
+ pub2.promote();
4282
+ }
4283
+ finally {
4284
+ sub.track_cut();
4285
+ sub.track_off(bu1);
4286
+ }
4287
+ pub1.emit();
4288
+ pub2.emit();
4289
+ $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
4290
+ const bu2 = sub.track_on();
4291
+ try {
4292
+ pub1.promote();
4293
+ pub1.promote();
4294
+ pub2.promote();
4295
+ }
4296
+ finally {
4297
+ sub.track_cut();
4298
+ sub.track_off(bu2);
4299
+ }
4300
+ pub1.emit();
4301
+ pub2.emit();
4302
+ $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
4337
4303
  },
4338
- 'Serializale'() {
4339
- class User {
4340
- name;
4341
- rand;
4342
- constructor(name, rand = Math.random()) {
4343
- this.name = name;
4344
- this.rand = rand;
4304
+ 'cyclic detection'($) {
4305
+ const sub1 = new $mol_wire_pub_sub;
4306
+ const sub2 = new $mol_wire_pub_sub;
4307
+ const bu1 = sub1.track_on();
4308
+ try {
4309
+ const bu2 = sub2.track_on();
4310
+ try {
4311
+ $mol_assert_fail(() => sub1.promote(), 'Circular subscription');
4345
4312
  }
4346
- [Symbol.toPrimitive](mode) {
4347
- return this.name;
4313
+ finally {
4314
+ sub2.track_cut();
4315
+ sub2.track_off(bu2);
4348
4316
  }
4349
4317
  }
4350
- $mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
4351
- $mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
4352
- },
4353
- 'Iterable'() {
4354
- $mol_assert_ok($mol_compare_deep(new URLSearchParams({ foo: 'bar' }), new URLSearchParams({ foo: 'bar' })));
4355
- $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx' }), new URLSearchParams({ foo: 'yyy' })));
4356
- $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx', bar: 'yyy' }), new URLSearchParams({ bar: 'yyy', foo: 'xxx' })));
4318
+ finally {
4319
+ sub1.track_cut();
4320
+ sub1.track_off(bu1);
4321
+ }
4357
4322
  },
4358
4323
  });
4359
4324
  })($ || ($ = {}));
@@ -4362,66 +4327,47 @@ var $;
4362
4327
  "use strict";
4363
4328
  var $;
4364
4329
  (function ($) {
4365
- function $mol_assert_ok(value) {
4366
- if (value)
4367
- return;
4368
- $mol_fail(new Error(`${value} true`));
4369
- }
4370
- $.$mol_assert_ok = $mol_assert_ok;
4371
- function $mol_assert_not(value) {
4372
- if (!value)
4373
- return;
4374
- $mol_fail(new Error(`${value} ≠ false`));
4330
+ $.$mol_after_mock_queue = [];
4331
+ function $mol_after_mock_warp() {
4332
+ const queue = $.$mol_after_mock_queue.splice(0);
4333
+ for (const task of queue)
4334
+ task();
4375
4335
  }
4376
- $.$mol_assert_not = $mol_assert_not;
4377
- function $mol_assert_fail(handler, ErrorRight) {
4378
- const fail = $.$mol_fail;
4379
- try {
4380
- $.$mol_fail = $.$mol_fail_hidden;
4381
- handler();
4382
- }
4383
- catch (error) {
4384
- $.$mol_fail = fail;
4385
- if (typeof ErrorRight === 'string') {
4386
- $mol_assert_equal(error.message ?? error, ErrorRight);
4387
- }
4388
- else {
4389
- $mol_assert_equal(error instanceof ErrorRight, true);
4390
- }
4391
- return error;
4392
- }
4393
- finally {
4394
- $.$mol_fail = fail;
4336
+ $.$mol_after_mock_warp = $mol_after_mock_warp;
4337
+ class $mol_after_mock_commmon extends $mol_object2 {
4338
+ task;
4339
+ promise = Promise.resolve();
4340
+ cancelled = false;
4341
+ id;
4342
+ constructor(task) {
4343
+ super();
4344
+ this.task = task;
4345
+ $.$mol_after_mock_queue.push(task);
4395
4346
  }
4396
- $mol_fail(new Error('Not failed'));
4397
- }
4398
- $.$mol_assert_fail = $mol_assert_fail;
4399
- function $mol_assert_like(...args) {
4400
- $mol_assert_equal(...args);
4401
- }
4402
- $.$mol_assert_like = $mol_assert_like;
4403
- function $mol_assert_unique(...args) {
4404
- for (let i = 0; i < args.length; ++i) {
4405
- for (let j = 0; j < args.length; ++j) {
4406
- if (i === j)
4407
- continue;
4408
- if (!$mol_compare_deep(args[i], args[j]))
4409
- continue;
4410
- return $mol_fail(new Error(`Uniquesess assertion failure`, { cause: { [i]: args[i], [i]: args[i] } }));
4411
- }
4347
+ destructor() {
4348
+ const index = $.$mol_after_mock_queue.indexOf(this.task);
4349
+ if (index >= 0)
4350
+ $.$mol_after_mock_queue.splice(index, 1);
4412
4351
  }
4413
4352
  }
4414
- $.$mol_assert_unique = $mol_assert_unique;
4415
- function $mol_assert_equal(...args) {
4416
- for (let i = 1; i < args.length; ++i) {
4417
- if ($mol_compare_deep(args[0], args[i]))
4418
- continue;
4419
- if (args[0] instanceof $mol_dom_context.Element && args[i] instanceof $mol_dom_context.Element && args[0].outerHTML === args[i].outerHTML)
4420
- continue;
4421
- return $mol_fail(new Error(`Equality assertion failure`, { cause: { 0: args[0], [i]: args[i] } }));
4353
+ $.$mol_after_mock_commmon = $mol_after_mock_commmon;
4354
+ class $mol_after_mock_timeout extends $mol_after_mock_commmon {
4355
+ delay;
4356
+ constructor(delay, task) {
4357
+ super(task);
4358
+ this.delay = delay;
4422
4359
  }
4423
4360
  }
4424
- $.$mol_assert_equal = $mol_assert_equal;
4361
+ $.$mol_after_mock_timeout = $mol_after_mock_timeout;
4362
+ })($ || ($ = {}));
4363
+
4364
+ ;
4365
+ "use strict";
4366
+ var $;
4367
+ (function ($_1) {
4368
+ $mol_test_mocks.push($ => {
4369
+ $.$mol_after_tick = $mol_after_mock_commmon;
4370
+ });
4425
4371
  })($ || ($ = {}));
4426
4372
 
4427
4373
  ;
@@ -4429,35 +4375,162 @@ var $;
4429
4375
  var $;
4430
4376
  (function ($) {
4431
4377
  $mol_test({
4432
- 'must be false'() {
4433
- $mol_assert_not(0);
4434
- },
4435
- 'must be true'() {
4436
- $mol_assert_ok(1);
4437
- },
4438
- 'two must be equal'() {
4439
- $mol_assert_equal(2, 2);
4440
- },
4441
- 'three must be equal'() {
4442
- $mol_assert_equal(2, 2, 2);
4378
+ 'Sync execution'() {
4379
+ class Sync extends $mol_object2 {
4380
+ static calc(a, b) {
4381
+ return a + b;
4382
+ }
4383
+ }
4384
+ __decorate([
4385
+ $mol_wire_method
4386
+ ], Sync, "calc", null);
4387
+ $mol_assert_equal(Sync.calc(1, 2), 3);
4443
4388
  },
4444
- 'two must be unique'() {
4445
- $mol_assert_unique([2], [3]);
4389
+ async 'async <=> sync'() {
4390
+ class SyncAsync extends $mol_object2 {
4391
+ static async val(a) {
4392
+ return a;
4393
+ }
4394
+ static sum(a, b) {
4395
+ const syn = $mol_wire_sync(this);
4396
+ return syn.val(a) + syn.val(b);
4397
+ }
4398
+ static async calc(a, b) {
4399
+ return 5 + await $mol_wire_async(this).sum(a, b);
4400
+ }
4401
+ }
4402
+ $mol_assert_equal(await SyncAsync.calc(1, 2), 8);
4446
4403
  },
4447
- 'three must be unique'() {
4448
- $mol_assert_unique([1], [2], [3]);
4404
+ async 'Idempotence control'() {
4405
+ class Idempotence extends $mol_object2 {
4406
+ static logs_idemp = 0;
4407
+ static logs_unidemp = 0;
4408
+ static log_idemp() {
4409
+ this.logs_idemp += 1;
4410
+ }
4411
+ static log_unidemp() {
4412
+ this.logs_unidemp += 1;
4413
+ }
4414
+ static async val(a) {
4415
+ return a;
4416
+ }
4417
+ static sum(a, b) {
4418
+ this.log_idemp();
4419
+ this.log_unidemp();
4420
+ const syn = $mol_wire_sync(this);
4421
+ return syn.val(a) + syn.val(b);
4422
+ }
4423
+ static async calc(a, b) {
4424
+ return 5 + await $mol_wire_async(this).sum(a, b);
4425
+ }
4426
+ }
4427
+ __decorate([
4428
+ $mol_wire_method
4429
+ ], Idempotence, "log_idemp", null);
4430
+ $mol_assert_equal(await Idempotence.calc(1, 2), 8);
4431
+ $mol_assert_equal(Idempotence.logs_idemp, 1);
4432
+ $mol_assert_equal(Idempotence.logs_unidemp, 3);
4449
4433
  },
4450
- 'two must be alike'() {
4451
- $mol_assert_equal([3], [3]);
4434
+ async 'Error handling'() {
4435
+ class Handle extends $mol_object2 {
4436
+ static async sum(a, b) {
4437
+ $mol_fail(new Error('test error ' + (a + b)));
4438
+ }
4439
+ static check() {
4440
+ try {
4441
+ return $mol_wire_sync(Handle).sum(1, 2);
4442
+ }
4443
+ catch (error) {
4444
+ if ($mol_promise_like(error))
4445
+ $mol_fail_hidden(error);
4446
+ $mol_assert_equal(error.message, 'test error 3');
4447
+ }
4448
+ }
4449
+ }
4450
+ await $mol_wire_async(Handle).check();
4452
4451
  },
4453
- 'three must be alike'() {
4454
- $mol_assert_equal([3], [3], [3]);
4452
+ });
4453
+ })($ || ($ = {}));
4454
+
4455
+ ;
4456
+ "use strict";
4457
+ var $;
4458
+ (function ($) {
4459
+ function $mol_wire_async(obj) {
4460
+ let fiber;
4461
+ const temp = $mol_wire_task.getter(obj);
4462
+ return new Proxy(obj, {
4463
+ get(obj, field) {
4464
+ const val = obj[field];
4465
+ if (typeof val !== 'function')
4466
+ return val;
4467
+ let fiber;
4468
+ const temp = $mol_wire_task.getter(val);
4469
+ return function $mol_wire_async(...args) {
4470
+ fiber?.destructor();
4471
+ fiber = temp(obj, args);
4472
+ return fiber.async();
4473
+ };
4474
+ },
4475
+ apply(obj, self, args) {
4476
+ fiber?.destructor();
4477
+ fiber = temp(self, args);
4478
+ return fiber.async();
4479
+ },
4480
+ });
4481
+ }
4482
+ $.$mol_wire_async = $mol_wire_async;
4483
+ })($ || ($ = {}));
4484
+
4485
+ ;
4486
+ "use strict";
4487
+ var $;
4488
+ (function ($_1) {
4489
+ $mol_test({
4490
+ 'test types'($) {
4491
+ class A {
4492
+ static a() {
4493
+ return '';
4494
+ }
4495
+ static b() {
4496
+ return $mol_wire_async(this).a();
4497
+ }
4498
+ }
4455
4499
  },
4456
- 'two object must be alike'() {
4457
- $mol_assert_equal({ a: 1 }, { a: 1 });
4500
+ async 'Latest method calls wins'($) {
4501
+ class NameLogger extends $mol_object2 {
4502
+ static $ = $;
4503
+ static first = [];
4504
+ static last = [];
4505
+ static send(next) {
4506
+ $mol_wire_sync(this.first).push(next);
4507
+ $$.$mol_wait_timeout(0);
4508
+ this.last.push(next);
4509
+ }
4510
+ }
4511
+ const name = $mol_wire_async(NameLogger).send;
4512
+ name('john');
4513
+ const promise = name('jin');
4514
+ $.$mol_after_mock_warp();
4515
+ await promise;
4516
+ $mol_assert_equal(NameLogger.first, ['john', 'jin']);
4517
+ $mol_assert_equal(NameLogger.last, ['jin']);
4458
4518
  },
4459
- 'three object must be alike'() {
4460
- $mol_assert_equal({ a: 1 }, { a: 1 }, { a: 1 });
4519
+ async 'Latest function calls wins'($) {
4520
+ const first = [];
4521
+ const last = [];
4522
+ function send_name(next) {
4523
+ $mol_wire_sync(first).push(next);
4524
+ $$.$mol_wait_timeout(0);
4525
+ last.push(next);
4526
+ }
4527
+ const name = $mol_wire_async(send_name);
4528
+ name('john');
4529
+ const promise = name('jin');
4530
+ $.$mol_after_mock_warp();
4531
+ await promise;
4532
+ $mol_assert_equal(first, ['john', 'jin']);
4533
+ $mol_assert_equal(last, ['jin']);
4461
4534
  },
4462
4535
  });
4463
4536
  })($ || ($ = {}));
@@ -4466,140 +4539,163 @@ var $;
4466
4539
  "use strict";
4467
4540
  var $;
4468
4541
  (function ($) {
4469
- $mol_test({
4470
- 'encode empty'() {
4471
- $mol_assert_equal($mol_charset_encode(''), new Uint8Array([]));
4472
- },
4473
- 'encode 1 octet'() {
4474
- $mol_assert_equal($mol_charset_encode('F'), new Uint8Array([0x46]));
4475
- },
4476
- 'encode 2 octet'() {
4477
- $mol_assert_equal($mol_charset_encode('Б'), new Uint8Array([0xd0, 0x91]));
4478
- },
4479
- 'encode 3 octet'() {
4480
- $mol_assert_equal($mol_charset_encode('ह'), new Uint8Array([0xe0, 0xa4, 0xb9]));
4481
- },
4482
- 'encode 4 octet'() {
4483
- $mol_assert_equal($mol_charset_encode('𐍈'), new Uint8Array([0xf0, 0x90, 0x8d, 0x88]));
4484
- },
4485
- 'encode surrogate pair'() {
4486
- $mol_assert_equal($mol_charset_encode('😀'), new Uint8Array([0xf0, 0x9f, 0x98, 0x80]));
4487
- },
4488
- });
4542
+ function $mol_wire_method(host, field, descr) {
4543
+ if (!descr)
4544
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
4545
+ const orig = descr?.value ?? host[field];
4546
+ const sup = Reflect.getPrototypeOf(host);
4547
+ if (typeof sup[field] === 'function') {
4548
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
4549
+ }
4550
+ const temp = $mol_wire_task.getter(orig);
4551
+ const value = function (...args) {
4552
+ const fiber = temp(this ?? null, args);
4553
+ return fiber.sync();
4554
+ };
4555
+ Object.defineProperty(value, 'name', { value: orig.name + ' ' });
4556
+ Object.assign(value, { orig });
4557
+ const descr2 = { ...descr, value };
4558
+ Reflect.defineProperty(host, field, descr2);
4559
+ return descr2;
4560
+ }
4561
+ $.$mol_wire_method = $mol_wire_method;
4489
4562
  })($ || ($ = {}));
4490
4563
 
4491
4564
  ;
4492
4565
  "use strict";
4493
4566
  var $;
4494
- (function ($) {
4567
+ (function ($_1) {
4495
4568
  $mol_test({
4496
- 'get'() {
4497
- const proxy = $mol_delegate({}, () => ({ foo: 777 }));
4498
- $mol_assert_equal(proxy.foo, 777);
4499
- },
4500
- 'has'() {
4501
- const proxy = $mol_delegate({}, () => ({ foo: 777 }));
4502
- $mol_assert_equal('foo' in proxy, true);
4503
- },
4504
- 'set'() {
4505
- const target = { foo: 777 };
4506
- const proxy = $mol_delegate({}, () => target);
4507
- proxy.foo = 123;
4508
- $mol_assert_equal(target.foo, 123);
4509
- },
4510
- 'getOwnPropertyDescriptor'() {
4511
- const proxy = $mol_delegate({}, () => ({ foo: 777 }));
4512
- $mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
4513
- value: 777,
4514
- writable: true,
4515
- enumerable: true,
4516
- configurable: true,
4517
- });
4518
- },
4519
- 'ownKeys'() {
4520
- const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
4521
- $mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
4522
- },
4523
- 'getPrototypeOf'() {
4524
- class Foo {
4569
+ 'test types'($) {
4570
+ class A {
4571
+ static a() {
4572
+ return Promise.resolve('');
4573
+ }
4574
+ static b() {
4575
+ return $mol_wire_sync(this).a();
4576
+ }
4525
4577
  }
4526
- const proxy = $mol_delegate({}, () => new Foo);
4527
- $mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
4528
4578
  },
4529
- 'setPrototypeOf'() {
4530
- class Foo {
4579
+ async 'test method from host'($) {
4580
+ let count = 0;
4581
+ class A {
4582
+ static a() {
4583
+ return $mol_wire_sync(this).b();
4584
+ }
4585
+ static b() { return Promise.resolve(++count); }
4531
4586
  }
4532
- const target = {};
4533
- const proxy = $mol_delegate({}, () => target);
4534
- Object.setPrototypeOf(proxy, Foo.prototype);
4535
- $mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
4587
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
4536
4588
  },
4537
- 'instanceof'() {
4538
- class Foo {
4589
+ async 'test function'($) {
4590
+ let count = 0;
4591
+ class A {
4592
+ static a() {
4593
+ return $mol_wire_sync(this.b)();
4594
+ }
4595
+ static b() { return Promise.resolve(++count); }
4539
4596
  }
4540
- const proxy = $mol_delegate({}, () => new Foo);
4541
- $mol_assert_ok(proxy instanceof Foo);
4542
- $mol_assert_ok(proxy instanceof $mol_delegate);
4597
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
4543
4598
  },
4544
- 'autobind'() {
4545
- class Foo {
4599
+ async 'test construct itself'($) {
4600
+ class A {
4601
+ static instances = [];
4602
+ static a() {
4603
+ const a = new ($mol_wire_sync(A))();
4604
+ this.instances.push(a);
4605
+ $mol_wire_sync(this).b();
4606
+ }
4607
+ static b() { return Promise.resolve(); }
4546
4608
  }
4547
- const proxy = $mol_delegate({}, () => new Foo);
4548
- $mol_assert_ok(proxy instanceof Foo);
4549
- $mol_assert_ok(proxy instanceof $mol_delegate);
4550
- },
4609
+ await $mol_wire_async(A).a();
4610
+ $mol_assert_equal(A.instances.length, 2);
4611
+ $mol_assert_equal(A.instances[0] instanceof A, true);
4612
+ $mol_assert_equal(A.instances[0], A.instances[1]);
4613
+ }
4551
4614
  });
4552
4615
  })($ || ($ = {}));
4553
4616
 
4617
+ ;
4618
+ "use strict";
4619
+ var $;
4620
+ (function ($) {
4621
+ class $mol_promise extends Promise {
4622
+ done;
4623
+ fail;
4624
+ constructor(executor) {
4625
+ let done;
4626
+ let fail;
4627
+ super((d, f) => {
4628
+ done = d;
4629
+ fail = f;
4630
+ executor?.(d, f);
4631
+ });
4632
+ this.done = done;
4633
+ this.fail = fail;
4634
+ }
4635
+ }
4636
+ $.$mol_promise = $mol_promise;
4637
+ })($ || ($ = {}));
4638
+
4639
+ ;
4640
+ "use strict";
4641
+ var $;
4642
+ (function ($) {
4643
+ class $mol_after_timeout extends $mol_object2 {
4644
+ delay;
4645
+ task;
4646
+ id;
4647
+ constructor(delay, task) {
4648
+ super();
4649
+ this.delay = delay;
4650
+ this.task = task;
4651
+ this.id = setTimeout(task, delay);
4652
+ }
4653
+ destructor() {
4654
+ clearTimeout(this.id);
4655
+ }
4656
+ }
4657
+ $.$mol_after_timeout = $mol_after_timeout;
4658
+ })($ || ($ = {}));
4659
+
4554
4660
  ;
4555
4661
  "use strict";
4556
4662
  var $;
4557
4663
  (function ($_1) {
4558
- $mol_test({
4559
- 'span for same uri'($) {
4560
- const span = new $mol_span('test.ts', '', 1, 3, 4);
4561
- const child = span.span(4, 5, 8);
4562
- $mol_assert_equal(child.uri, 'test.ts');
4563
- $mol_assert_equal(child.row, 4);
4564
- $mol_assert_equal(child.col, 5);
4565
- $mol_assert_equal(child.length, 8);
4566
- },
4567
- 'span after of given position'($) {
4568
- const span = new $mol_span('test.ts', '', 1, 3, 4);
4569
- const child = span.after(11);
4570
- $mol_assert_equal(child.uri, 'test.ts');
4571
- $mol_assert_equal(child.row, 1);
4572
- $mol_assert_equal(child.col, 7);
4573
- $mol_assert_equal(child.length, 11);
4574
- },
4575
- 'slice span - regular'($) {
4576
- const span = new $mol_span('test.ts', '', 1, 3, 5);
4577
- const child = span.slice(1, 4);
4578
- $mol_assert_equal(child.row, 1);
4579
- $mol_assert_equal(child.col, 4);
4580
- $mol_assert_equal(child.length, 3);
4581
- const child2 = span.slice(2, 2);
4582
- $mol_assert_equal(child2.col, 5);
4583
- $mol_assert_equal(child2.length, 0);
4584
- },
4585
- 'slice span - negative'($) {
4586
- const span = new $mol_span('test.ts', '', 1, 3, 5);
4587
- const child = span.slice(-3, -1);
4588
- $mol_assert_equal(child.row, 1);
4589
- $mol_assert_equal(child.col, 5);
4590
- $mol_assert_equal(child.length, 2);
4591
- },
4592
- 'slice span - out of range'($) {
4593
- const span = new $mol_span('test.ts', '', 1, 3, 5);
4594
- $mol_assert_fail(() => span.slice(-1, 3), `End value '3' can't be less than begin value (test.ts#1:3/5)`);
4595
- $mol_assert_fail(() => span.slice(1, 6), `End value '6' out of range (test.ts#1:3/5)`);
4596
- $mol_assert_fail(() => span.slice(1, 10), `End value '10' out of range (test.ts#1:3/5)`);
4597
- },
4598
- 'error handling'($) {
4599
- const span = new $mol_span('test.ts', '', 1, 3, 4);
4600
- const error = span.error('Some error');
4601
- $mol_assert_equal(error.message, 'Some error (test.ts#1:3/4)');
4664
+ $mol_test_mocks.push($ => {
4665
+ $.$mol_after_timeout = $mol_after_mock_timeout;
4666
+ });
4667
+ })($ || ($ = {}));
4668
+
4669
+ ;
4670
+ "use strict";
4671
+ var $;
4672
+ (function ($) {
4673
+ class $mol_after_work extends $mol_object2 {
4674
+ delay;
4675
+ task;
4676
+ id;
4677
+ constructor(delay, task) {
4678
+ super();
4679
+ this.delay = delay;
4680
+ this.task = task;
4681
+ this.id = requestIdleCallback(task, { timeout: delay });
4682
+ }
4683
+ destructor() {
4684
+ cancelIdleCallback(this.id);
4602
4685
  }
4686
+ }
4687
+ $.$mol_after_work = $mol_after_work;
4688
+ if (typeof requestIdleCallback !== 'function') {
4689
+ $.$mol_after_work = $mol_after_timeout;
4690
+ }
4691
+ })($ || ($ = {}));
4692
+
4693
+ ;
4694
+ "use strict";
4695
+ var $;
4696
+ (function ($_1) {
4697
+ $mol_test_mocks.push($ => {
4698
+ $.$mol_after_work = $mol_after_mock_timeout;
4603
4699
  });
4604
4700
  })($ || ($ = {}));
4605
4701
 
@@ -4607,192 +4703,113 @@ var $;
4607
4703
  "use strict";
4608
4704
  var $;
4609
4705
  (function ($) {
4610
- $mol_test({
4611
- 'all cases of using maybe'() {
4612
- $mol_assert_equal($mol_maybe(0)[0], 0);
4613
- $mol_assert_equal($mol_maybe(false)[0], false);
4614
- $mol_assert_equal($mol_maybe(null)[0], void 0);
4615
- $mol_assert_equal($mol_maybe(void 0)[0], void 0);
4616
- $mol_assert_equal($mol_maybe(void 0).map(v => v.toString())[0], void 0);
4617
- $mol_assert_equal($mol_maybe(0).map(v => v.toString())[0], '0');
4618
- },
4619
- });
4706
+ function $mol_wait_rest_async() {
4707
+ return new Promise(done => {
4708
+ new this.$mol_after_work(16, () => done(null));
4709
+ });
4710
+ }
4711
+ $.$mol_wait_rest_async = $mol_wait_rest_async;
4712
+ function $mol_wait_rest() {
4713
+ return this.$mol_wire_sync(this).$mol_wait_rest_async();
4714
+ }
4715
+ $.$mol_wait_rest = $mol_wait_rest;
4620
4716
  })($ || ($ = {}));
4621
4717
 
4622
4718
  ;
4623
4719
  "use strict";
4624
4720
  var $;
4625
4721
  (function ($_1) {
4626
- function check(tree, ideal) {
4627
- $mol_assert_equal(tree.toString(), $$.$mol_tree2_from_string(ideal).toString());
4722
+ var $$;
4723
+ (function ($$) {
4724
+ $mol_test_mocks.push($ => {
4725
+ $.$mol_wait_timeout = function $mol_wait_timeout_mock(timeout) { };
4726
+ $.$mol_wait_timeout_async = async function $mol_wait_timeout_async_mock(timeout) { };
4727
+ });
4728
+ })($$ = $_1.$$ || ($_1.$$ = {}));
4729
+ })($ || ($ = {}));
4730
+
4731
+ ;
4732
+ "use strict";
4733
+ var $;
4734
+ (function ($) {
4735
+ function $mol_wait_timeout_async(timeout) {
4736
+ const promise = new $mol_promise();
4737
+ const task = new this.$mol_after_timeout(timeout, () => promise.done());
4738
+ return Object.assign(promise, {
4739
+ destructor: () => task.destructor()
4740
+ });
4628
4741
  }
4629
- $mol_test({
4630
- 'inserting'($) {
4631
- check($.$mol_tree2_from_string(`
4632
- a b c d
4633
- `).insert($mol_tree2.struct('x'), 'a', 'b', 'c'), `
4634
- a b x
4635
- `);
4636
- check($.$mol_tree2_from_string(`
4637
- a b
4638
- `).insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd'), `
4639
- a b c x
4640
- `);
4641
- check($.$mol_tree2_from_string(`
4642
- a b c d
4643
- `)
4644
- .insert($mol_tree2.struct('x'), 0, 0, 0), `
4645
- a b x
4646
- `);
4647
- check($.$mol_tree2_from_string(`
4648
- a b
4649
- `)
4650
- .insert($mol_tree2.struct('x'), 0, 0, 0, 0), `
4651
- a b \\
4652
- x
4653
- `);
4654
- check($.$mol_tree2_from_string(`
4655
- a b c d
4656
- `)
4657
- .insert($mol_tree2.struct('x'), null, null, null), `
4658
- a b x
4659
- `);
4660
- check($.$mol_tree2_from_string(`
4661
- a b
4662
- `)
4663
- .insert($mol_tree2.struct('x'), null, null, null, null), `
4664
- a b \\
4665
- x
4666
- `);
4667
- },
4668
- 'updating'($) {
4669
- check($.$mol_tree2_from_string(`
4670
- a b c d
4671
- `).update([], 'a', 'b', 'c')[0], `
4672
- a b
4673
- `);
4674
- check($.$mol_tree2_from_string(`
4675
- a b c d
4676
- `).update([$mol_tree2.struct('x')])[0], `
4677
- x
4678
- `);
4679
- check($.$mol_tree2_from_string(`
4680
- a b c d
4681
- `).update([$mol_tree2.struct('x'), $mol_tree2.struct('y')], 'a', 'b', 'c')[0], `
4682
- a b
4683
- x
4684
- y
4685
- `);
4686
- },
4687
- 'deleting'($) {
4688
- const base = $.$mol_tree2_from_string(`
4689
- a b c d
4690
- `);
4691
- check(base.insert(null, 'a', 'b', 'c'), `
4692
- a b
4693
- `);
4694
- check(base.update(base.select('a', 'b', 'c', null).kids, 'a', 'b', 'c')[0], `
4695
- a b d
4696
- `);
4697
- check(base.insert(null, 0, 0, 0), `
4698
- a b
4699
- `);
4700
- },
4701
- 'hack'($) {
4702
- const res = $.$mol_tree2_from_string(`
4703
- foo bar xxx
4704
- `)
4705
- .hack({
4706
- 'bar': (input, belt) => [input.struct('777', input.hack(belt))],
4707
- });
4708
- $mol_assert_equal(res.map(String), ['foo 777 xxx\n']);
4709
- },
4710
- });
4742
+ $.$mol_wait_timeout_async = $mol_wait_timeout_async;
4743
+ function $mol_wait_timeout(timeout) {
4744
+ return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
4745
+ }
4746
+ $.$mol_wait_timeout = $mol_wait_timeout;
4711
4747
  })($ || ($ = {}));
4712
4748
 
4713
4749
  ;
4714
4750
  "use strict";
4715
4751
  var $;
4716
4752
  (function ($_1) {
4717
- $mol_test({
4718
- 'tree parsing'($) {
4719
- $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
4720
- $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
4721
- $mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
4722
- $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
4723
- $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
4724
- $mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
4725
- $mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
4726
- $mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
4727
- },
4728
- 'Too many tabs'($) {
4729
- const tree = `
4730
- foo
4731
- bar
4732
- `;
4733
- $mol_assert_fail(() => {
4734
- $.$mol_tree2_from_string(tree, 'test');
4735
- }, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
4736
- },
4737
- 'Too few tabs'($) {
4738
- const tree = `
4739
- foo
4740
- bar
4741
- `;
4742
- $mol_assert_fail(() => {
4743
- $.$mol_tree2_from_string(tree, 'test');
4744
- }, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
4745
- },
4746
- 'Wrong nodes separator at start'($) {
4747
- const tree = `foo\n \tbar\n`;
4748
- $mol_assert_fail(() => {
4749
- $.$mol_tree2_from_string(tree, 'test');
4750
- }, 'Wrong nodes separator\ntest#2:1/2\n!!\n \tbar');
4751
- },
4752
- 'Wrong nodes separator in the middle'($) {
4753
- const tree = `foo bar\n`;
4754
- $mol_assert_fail(() => {
4755
- $.$mol_tree2_from_string(tree, 'test');
4756
- }, 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar');
4757
- },
4758
- 'Unexpected EOF, LF required'($) {
4759
- const tree = ` foo`;
4760
- $mol_assert_fail(() => {
4761
- $.$mol_tree2_from_string(tree, 'test');
4762
- }, 'Unexpected EOF, LF required\ntest#1:5/1\n !\n foo');
4763
- },
4764
- 'Errors skip and collect'($) {
4765
- const tree = `foo bar`;
4766
- const errors = [];
4767
- const $$ = $.$mol_ambient({
4768
- $mol_fail: (error) => {
4769
- errors.push(error.message);
4770
- return null;
4771
- }
4772
- });
4773
- const res = $$.$mol_tree2_from_string(tree, 'test');
4774
- $mol_assert_like(errors, [
4775
- 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar',
4776
- 'Unexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
4777
- ]);
4778
- $mol_assert_equal(res.toString(), 'foo bar\n');
4779
- },
4780
- });
4753
+ var $$;
4754
+ (function ($$) {
4755
+ $mol_test_mocks.push($ => {
4756
+ $.$mol_wait_rest = function $mol_wait_rest_mock() { };
4757
+ $.$mol_wait_rest_async = async function $mol_wait_rest_async_mock() { };
4758
+ });
4759
+ })($$ = $_1.$$ || ($_1.$$ = {}));
4781
4760
  })($ || ($ = {}));
4782
4761
 
4783
4762
  ;
4784
4763
  "use strict";
4785
4764
  var $;
4786
- (function ($) {
4765
+ (function ($_1) {
4787
4766
  $mol_test({
4788
- 'fromJSON'() {
4789
- $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
4790
- $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
4791
- $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
4792
- $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
4793
- $mol_assert_equal($mol_tree2_from_json(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
4794
- $mol_assert_equal($mol_tree2_from_json({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
4795
- },
4767
+ async 'exec timeout auto kill child process'($) {
4768
+ let close_mock = () => { };
4769
+ const error_message = 'Run error, timeout';
4770
+ function mol_run_spawn_sync_mock() {
4771
+ return {
4772
+ output: [],
4773
+ stdout: error_message,
4774
+ stderr: '',
4775
+ status: 0,
4776
+ signal: null,
4777
+ pid: 123,
4778
+ };
4779
+ }
4780
+ function mol_run_spawn_mock() {
4781
+ return {
4782
+ on(name, cb) {
4783
+ if (name === 'exit')
4784
+ close_mock = cb;
4785
+ },
4786
+ kill() { close_mock(); }
4787
+ };
4788
+ }
4789
+ const context_mock = $.$mol_ambient({
4790
+ $mol_run_spawn_sync: mol_run_spawn_sync_mock,
4791
+ $mol_run_spawn: mol_run_spawn_mock
4792
+ });
4793
+ class $mol_run_mock extends $mol_run {
4794
+ static get $() { return context_mock; }
4795
+ static async_enabled() {
4796
+ return true;
4797
+ }
4798
+ }
4799
+ let message = '';
4800
+ try {
4801
+ const res = await $mol_wire_async($mol_run_mock).spawn({
4802
+ command: 'sleep 10',
4803
+ dir: '.',
4804
+ timeout: 10,
4805
+ env: { 'MOL_RUN_ASYNC': '1' }
4806
+ });
4807
+ }
4808
+ catch (e) {
4809
+ message = e.message;
4810
+ }
4811
+ $mol_assert_equal(message, error_message);
4812
+ }
4796
4813
  });
4797
4814
  })($ || ($ = {}));
4798
4815