mol_vary 0.0.81 → 0.0.83

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