mol_tree2 1.0.213 → 1.0.214

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
@@ -1673,25 +1673,25 @@ var $;
1673
1673
  //mol/dom/render/children/children.ts
1674
1674
  ;
1675
1675
  "use strict";
1676
- //mol/type/partial/deep/deep.ts
1676
+ //mol/type/error/error.ts
1677
1677
  ;
1678
1678
  "use strict";
1679
- //mol/type/error/error.ts
1679
+ //mol/type/assert/assert.test.ts
1680
1680
  ;
1681
1681
  "use strict";
1682
1682
  //mol/type/assert/assert.ts
1683
1683
  ;
1684
1684
  "use strict";
1685
- //mol/type/assert/assert.test.ts
1685
+ //mol/type/equals/equals.test.ts
1686
1686
  ;
1687
1687
  "use strict";
1688
1688
  //mol/type/equals/equals.ts
1689
1689
  ;
1690
1690
  "use strict";
1691
- //mol/type/equals/equals.test.ts
1691
+ //mol/type/partial/deep/deep.test.ts
1692
1692
  ;
1693
1693
  "use strict";
1694
- //mol/type/partial/deep/deep.test.ts
1694
+ //mol/type/partial/deep/deep.ts
1695
1695
  ;
1696
1696
  "use strict";
1697
1697
  var $;
@@ -2138,6 +2138,38 @@ var $;
2138
2138
  ;
2139
2139
  "use strict";
2140
2140
  var $;
2141
+ (function ($) {
2142
+ $mol_test({
2143
+ 'must be false'() {
2144
+ $mol_assert_not(0);
2145
+ },
2146
+ 'must be true'() {
2147
+ $mol_assert_ok(1);
2148
+ },
2149
+ 'two must be equal'() {
2150
+ $mol_assert_equal(2, 2);
2151
+ },
2152
+ 'three must be equal'() {
2153
+ $mol_assert_equal(2, 2, 2);
2154
+ },
2155
+ 'two must be unique'() {
2156
+ $mol_assert_unique([3], [3]);
2157
+ },
2158
+ 'three must be unique'() {
2159
+ $mol_assert_unique([3], [3], [3]);
2160
+ },
2161
+ 'two must be alike'() {
2162
+ $mol_assert_like([3], [3]);
2163
+ },
2164
+ 'three must be alike'() {
2165
+ $mol_assert_like([3], [3], [3]);
2166
+ },
2167
+ });
2168
+ })($ || ($ = {}));
2169
+ //mol/assert/assert.test.ts
2170
+ ;
2171
+ "use strict";
2172
+ var $;
2141
2173
  (function ($) {
2142
2174
  function $mol_assert_ok(value) {
2143
2175
  if (value)
@@ -2232,84 +2264,6 @@ var $;
2232
2264
  ;
2233
2265
  "use strict";
2234
2266
  var $;
2235
- (function ($) {
2236
- $mol_test({
2237
- 'must be false'() {
2238
- $mol_assert_not(0);
2239
- },
2240
- 'must be true'() {
2241
- $mol_assert_ok(1);
2242
- },
2243
- 'two must be equal'() {
2244
- $mol_assert_equal(2, 2);
2245
- },
2246
- 'three must be equal'() {
2247
- $mol_assert_equal(2, 2, 2);
2248
- },
2249
- 'two must be unique'() {
2250
- $mol_assert_unique([3], [3]);
2251
- },
2252
- 'three must be unique'() {
2253
- $mol_assert_unique([3], [3], [3]);
2254
- },
2255
- 'two must be alike'() {
2256
- $mol_assert_like([3], [3]);
2257
- },
2258
- 'three must be alike'() {
2259
- $mol_assert_like([3], [3], [3]);
2260
- },
2261
- });
2262
- })($ || ($ = {}));
2263
- //mol/assert/assert.test.ts
2264
- ;
2265
- "use strict";
2266
- var $;
2267
- (function ($) {
2268
- const named = new WeakSet();
2269
- function $mol_func_name(func) {
2270
- let name = func.name;
2271
- if (name?.length > 1)
2272
- return name;
2273
- if (named.has(func))
2274
- return name;
2275
- for (let key in this) {
2276
- try {
2277
- if (this[key] !== func)
2278
- continue;
2279
- name = key;
2280
- Object.defineProperty(func, 'name', { value: name });
2281
- break;
2282
- }
2283
- catch { }
2284
- }
2285
- named.add(func);
2286
- return name;
2287
- }
2288
- $.$mol_func_name = $mol_func_name;
2289
- function $mol_func_name_from(target, source) {
2290
- Object.defineProperty(target, 'name', { value: source.name });
2291
- return target;
2292
- }
2293
- $.$mol_func_name_from = $mol_func_name_from;
2294
- })($ || ($ = {}));
2295
- //mol/func/name/name.ts
2296
- ;
2297
- "use strict";
2298
- var $;
2299
- (function ($_1) {
2300
- $mol_test({
2301
- 'FQN of anon function'($) {
2302
- const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
2303
- $mol_assert_equal($$.$mol_func_name_test.name, '');
2304
- $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
2305
- $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
2306
- },
2307
- });
2308
- })($ || ($ = {}));
2309
- //mol/func/name/name.test.ts
2310
- ;
2311
- "use strict";
2312
- var $;
2313
2267
  (function ($) {
2314
2268
  $mol_test({
2315
2269
  'get'() {
@@ -2376,98 +2330,274 @@ var $;
2376
2330
  ;
2377
2331
  "use strict";
2378
2332
  var $;
2379
- (function ($) {
2380
- $.$mol_tree_convert = Symbol('$mol_tree_convert');
2381
- class $mol_tree extends $mol_object2 {
2382
- type;
2383
- data;
2384
- sub;
2385
- baseUri;
2386
- row;
2387
- col;
2388
- length;
2389
- constructor(config = {}) {
2390
- super();
2391
- this.type = config.type || '';
2392
- if (config.value !== undefined) {
2393
- var sub = $mol_tree.values(config.value);
2394
- if (config.type || sub.length > 1) {
2395
- this.sub = [...sub, ...(config.sub || [])];
2396
- this.data = config.data || '';
2397
- }
2398
- else {
2399
- this.data = sub[0].data;
2400
- this.sub = config.sub || [];
2401
- }
2402
- }
2403
- else {
2404
- this.data = config.data || '';
2405
- this.sub = config.sub || [];
2406
- }
2407
- this.baseUri = config.baseUri || '';
2408
- this.row = config.row || 0;
2409
- this.col = config.col || 0;
2410
- this.length = config.length || 0;
2411
- }
2412
- static values(str, baseUri) {
2413
- return str.split('\n').map((data, index) => new $mol_tree({
2414
- data: data,
2415
- baseUri: baseUri,
2416
- row: index + 1,
2417
- length: data.length,
2418
- }));
2419
- }
2420
- clone(config = {}) {
2421
- return new $mol_tree({
2422
- type: ('type' in config) ? config.type : this.type,
2423
- data: ('data' in config) ? config.data : this.data,
2424
- sub: ('sub' in config) ? config.sub : this.sub,
2425
- baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
2426
- row: ('row' in config) ? config.row : this.row,
2427
- col: ('col' in config) ? config.col : this.col,
2428
- length: ('length' in config) ? config.length : this.length,
2429
- value: config.value
2430
- });
2431
- }
2432
- make(config) {
2433
- return new $mol_tree({
2434
- baseUri: this.baseUri,
2435
- row: this.row,
2436
- col: this.col,
2437
- length: this.length,
2438
- ...config,
2439
- });
2440
- }
2441
- make_data(value, sub) {
2442
- return this.make({ value, sub });
2443
- }
2444
- make_struct(type, sub) {
2445
- return this.make({ type, sub });
2333
+ (function ($_1) {
2334
+ $mol_test({
2335
+ 'span for same uri'($) {
2336
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
2337
+ const child = span.span(4, 5, 8);
2338
+ $mol_assert_equal(child.uri, 'test.ts');
2339
+ $mol_assert_equal(child.row, 4);
2340
+ $mol_assert_equal(child.col, 5);
2341
+ $mol_assert_equal(child.length, 8);
2342
+ },
2343
+ 'span after of given position'($) {
2344
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
2345
+ const child = span.after(11);
2346
+ $mol_assert_equal(child.uri, 'test.ts');
2347
+ $mol_assert_equal(child.row, 1);
2348
+ $mol_assert_equal(child.col, 7);
2349
+ $mol_assert_equal(child.length, 11);
2350
+ },
2351
+ 'slice span - regular'($) {
2352
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
2353
+ const child = span.slice(1, 4);
2354
+ $mol_assert_equal(child.row, 1);
2355
+ $mol_assert_equal(child.col, 4);
2356
+ $mol_assert_equal(child.length, 3);
2357
+ const child2 = span.slice(2, 2);
2358
+ $mol_assert_equal(child2.col, 5);
2359
+ $mol_assert_equal(child2.length, 0);
2360
+ },
2361
+ 'slice span - negative'($) {
2362
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
2363
+ const child = span.slice(-3, -1);
2364
+ $mol_assert_equal(child.row, 1);
2365
+ $mol_assert_equal(child.col, 5);
2366
+ $mol_assert_equal(child.length, 2);
2367
+ },
2368
+ 'slice span - out of range'($) {
2369
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
2370
+ $mol_assert_fail(() => span.slice(-1, 3));
2371
+ $mol_assert_fail(() => span.slice(1, 6));
2372
+ $mol_assert_fail(() => span.slice(1, 10));
2373
+ },
2374
+ 'error handling'($) {
2375
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
2376
+ const error = span.error('Some error\n');
2377
+ $mol_assert_equal(error.message, 'Some error\ntest.ts#1:3/4');
2446
2378
  }
2447
- static fromString(str, baseUri) {
2448
- var root = new $mol_tree({ baseUri: baseUri });
2449
- var stack = [root];
2450
- var row = 0;
2451
- var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
2452
- var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
2453
- lines.forEach(line => {
2454
- ++row;
2455
- var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
2456
- if (!chunks || chunks[4])
2457
- return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
2458
- var indent = chunks[1];
2459
- var path = chunks[2];
2460
- var data = chunks[3];
2461
- var deep = indent.length;
2462
- var types = path ? path.replace(/ $/, '').split(/ +/) : [];
2463
- if (stack.length <= deep)
2464
- return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
2465
- stack.length = deep + 1;
2466
- var parent = stack[deep];
2467
- let col = deep;
2468
- types.forEach(type => {
2469
- if (!type)
2470
- return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
2379
+ });
2380
+ })($ || ($ = {}));
2381
+ //mol/span/span.test.ts
2382
+ ;
2383
+ "use strict";
2384
+ var $;
2385
+ (function ($_1) {
2386
+ $mol_test({
2387
+ 'tree parsing'($) {
2388
+ $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
2389
+ $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
2390
+ $mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
2391
+ $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
2392
+ $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
2393
+ $mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
2394
+ $mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
2395
+ $mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
2396
+ },
2397
+ 'Too many tabs'($) {
2398
+ const tree = `
2399
+ foo
2400
+ bar
2401
+ `;
2402
+ $mol_assert_fail(() => {
2403
+ $.$mol_tree2_from_string(tree, 'test');
2404
+ }, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
2405
+ },
2406
+ 'Too few tabs'($) {
2407
+ const tree = `
2408
+ foo
2409
+ bar
2410
+ `;
2411
+ $mol_assert_fail(() => {
2412
+ $.$mol_tree2_from_string(tree, 'test');
2413
+ }, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
2414
+ },
2415
+ 'Wrong nodes separator'($) {
2416
+ const tree = `foo bar\n`;
2417
+ $mol_assert_fail(() => {
2418
+ $.$mol_tree2_from_string(tree, 'test');
2419
+ }, 'Wrong nodes separator\ntest#1:4/2\n !!\nfoo bar');
2420
+ },
2421
+ 'Undexpected EOF, LF required'($) {
2422
+ const tree = ` foo`;
2423
+ $mol_assert_fail(() => {
2424
+ $.$mol_tree2_from_string(tree, 'test');
2425
+ }, 'Undexpected EOF, LF required\ntest#1:5/1\n !\n foo');
2426
+ },
2427
+ 'Errors skip and collect'($) {
2428
+ const tree = `foo bar`;
2429
+ const errors = [];
2430
+ const $$ = $.$mol_ambient({
2431
+ $mol_fail: (error) => {
2432
+ errors.push(error.message);
2433
+ return null;
2434
+ }
2435
+ });
2436
+ const res = $$.$mol_tree2_from_string(tree, 'test');
2437
+ $mol_assert_like(errors, [
2438
+ 'Wrong nodes separator\ntest#1:4/2\n !!\nfoo bar',
2439
+ 'Undexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
2440
+ ]);
2441
+ $mol_assert_equal(res.toString(), 'foo bar\n');
2442
+ },
2443
+ });
2444
+ })($ || ($ = {}));
2445
+ //mol/tree2/from/string/string.test.ts
2446
+ ;
2447
+ "use strict";
2448
+ var $;
2449
+ (function ($_1) {
2450
+ $mol_test({
2451
+ 'tree parsing'() {
2452
+ $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub.length, 2);
2453
+ $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub[1].type, "bar");
2454
+ $mol_assert_equal($mol_tree.fromString("foo\n\n\n").sub.length, 1);
2455
+ $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub.length, 2);
2456
+ $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub[1].data, "bar");
2457
+ $mol_assert_equal($mol_tree.fromString("foo bar \\pol").sub[0].sub[0].sub[0].data, "pol");
2458
+ $mol_assert_equal($mol_tree.fromString("foo bar\n\t\\pol\n\t\\men").sub[0].sub[0].sub[1].data, "men");
2459
+ $mol_assert_equal($mol_tree.fromString('foo bar \\text\n').toString(), 'foo bar \\text\n');
2460
+ },
2461
+ 'inserting'() {
2462
+ $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 'a', 'b', 'c').toString(), 'a b \\\n');
2463
+ $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 'a', 'b', 'c', 'd').toString(), 'a b c \\\n');
2464
+ $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 0, 0, 0).toString(), 'a b \\\n');
2465
+ $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 0, 0, 0, 0).toString(), 'a b \\\n\t\\\n');
2466
+ $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, null, null, null).toString(), 'a b \\\n');
2467
+ $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, null, null, null, null).toString(), 'a b \\\n\t\\\n');
2468
+ },
2469
+ 'fromJSON'() {
2470
+ $mol_assert_equal($mol_tree.fromJSON([]).toString(), '/\n');
2471
+ $mol_assert_equal($mol_tree.fromJSON([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
2472
+ $mol_assert_equal($mol_tree.fromJSON([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
2473
+ $mol_assert_equal($mol_tree.fromJSON(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
2474
+ $mol_assert_equal($mol_tree.fromJSON({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
2475
+ },
2476
+ 'toJSON'() {
2477
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n').sub[0]), '[]');
2478
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\tfalse\n\ttrue\n').sub[0]), '[false,true]');
2479
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t0\n\t1\n\t2.3\n').sub[0]), '[0,1,2.3]');
2480
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n').sub[0]), '["","foo","bar\\nbaz"]');
2481
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n').sub[0]), '{"foo":false,"bar\\nbaz":"lol"}');
2482
+ },
2483
+ 'hack'() {
2484
+ const res = $mol_tree.fromString(`foo bar xxx`).hack({
2485
+ '': (tree, context) => [tree.hack(context)],
2486
+ 'bar': (tree, context) => [tree.hack(context).clone({ type: '777' })],
2487
+ });
2488
+ $mol_assert_equal(res.toString(), new $mol_tree({ type: 'foo 777 xxx' }).toString());
2489
+ },
2490
+ 'errors handling'($) {
2491
+ const errors = [];
2492
+ class Tree extends $mol_tree {
2493
+ static $ = $.$mol_ambient({
2494
+ $mol_fail: error => errors.push(error.message)
2495
+ });
2496
+ }
2497
+ Tree.fromString(`
2498
+ \t \tfoo
2499
+ bar \\data
2500
+ `, 'test');
2501
+ $mol_assert_like(errors, ['Syntax error at test:2\n \tfoo']);
2502
+ },
2503
+ });
2504
+ })($ || ($ = {}));
2505
+ //mol/tree/tree.test.ts
2506
+ ;
2507
+ "use strict";
2508
+ var $;
2509
+ (function ($) {
2510
+ $.$mol_tree_convert = Symbol('$mol_tree_convert');
2511
+ class $mol_tree extends $mol_object2 {
2512
+ type;
2513
+ data;
2514
+ sub;
2515
+ baseUri;
2516
+ row;
2517
+ col;
2518
+ length;
2519
+ constructor(config = {}) {
2520
+ super();
2521
+ this.type = config.type || '';
2522
+ if (config.value !== undefined) {
2523
+ var sub = $mol_tree.values(config.value);
2524
+ if (config.type || sub.length > 1) {
2525
+ this.sub = [...sub, ...(config.sub || [])];
2526
+ this.data = config.data || '';
2527
+ }
2528
+ else {
2529
+ this.data = sub[0].data;
2530
+ this.sub = config.sub || [];
2531
+ }
2532
+ }
2533
+ else {
2534
+ this.data = config.data || '';
2535
+ this.sub = config.sub || [];
2536
+ }
2537
+ this.baseUri = config.baseUri || '';
2538
+ this.row = config.row || 0;
2539
+ this.col = config.col || 0;
2540
+ this.length = config.length || 0;
2541
+ }
2542
+ static values(str, baseUri) {
2543
+ return str.split('\n').map((data, index) => new $mol_tree({
2544
+ data: data,
2545
+ baseUri: baseUri,
2546
+ row: index + 1,
2547
+ length: data.length,
2548
+ }));
2549
+ }
2550
+ clone(config = {}) {
2551
+ return new $mol_tree({
2552
+ type: ('type' in config) ? config.type : this.type,
2553
+ data: ('data' in config) ? config.data : this.data,
2554
+ sub: ('sub' in config) ? config.sub : this.sub,
2555
+ baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
2556
+ row: ('row' in config) ? config.row : this.row,
2557
+ col: ('col' in config) ? config.col : this.col,
2558
+ length: ('length' in config) ? config.length : this.length,
2559
+ value: config.value
2560
+ });
2561
+ }
2562
+ make(config) {
2563
+ return new $mol_tree({
2564
+ baseUri: this.baseUri,
2565
+ row: this.row,
2566
+ col: this.col,
2567
+ length: this.length,
2568
+ ...config,
2569
+ });
2570
+ }
2571
+ make_data(value, sub) {
2572
+ return this.make({ value, sub });
2573
+ }
2574
+ make_struct(type, sub) {
2575
+ return this.make({ type, sub });
2576
+ }
2577
+ static fromString(str, baseUri) {
2578
+ var root = new $mol_tree({ baseUri: baseUri });
2579
+ var stack = [root];
2580
+ var row = 0;
2581
+ var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
2582
+ var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
2583
+ lines.forEach(line => {
2584
+ ++row;
2585
+ var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
2586
+ if (!chunks || chunks[4])
2587
+ return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
2588
+ var indent = chunks[1];
2589
+ var path = chunks[2];
2590
+ var data = chunks[3];
2591
+ var deep = indent.length;
2592
+ var types = path ? path.replace(/ $/, '').split(/ +/) : [];
2593
+ if (stack.length <= deep)
2594
+ return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
2595
+ stack.length = deep + 1;
2596
+ var parent = stack[deep];
2597
+ let col = deep;
2598
+ types.forEach(type => {
2599
+ if (!type)
2600
+ return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
2471
2601
  var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
2472
2602
  const parent_sub = parent.sub;
2473
2603
  parent_sub.push(next);
@@ -2708,113 +2838,47 @@ var $;
2708
2838
  var $;
2709
2839
  (function ($_1) {
2710
2840
  $mol_test({
2711
- 'tree parsing'() {
2712
- $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub.length, 2);
2713
- $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub[1].type, "bar");
2714
- $mol_assert_equal($mol_tree.fromString("foo\n\n\n").sub.length, 1);
2715
- $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub.length, 2);
2716
- $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub[1].data, "bar");
2717
- $mol_assert_equal($mol_tree.fromString("foo bar \\pol").sub[0].sub[0].sub[0].data, "pol");
2718
- $mol_assert_equal($mol_tree.fromString("foo bar\n\t\\pol\n\t\\men").sub[0].sub[0].sub[1].data, "men");
2719
- $mol_assert_equal($mol_tree.fromString('foo bar \\text\n').toString(), 'foo bar \\text\n');
2720
- },
2721
- 'inserting'() {
2722
- $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 'a', 'b', 'c').toString(), 'a b \\\n');
2723
- $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 'a', 'b', 'c', 'd').toString(), 'a b c \\\n');
2724
- $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 0, 0, 0).toString(), 'a b \\\n');
2725
- $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 0, 0, 0, 0).toString(), 'a b \\\n\t\\\n');
2726
- $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, null, null, null).toString(), 'a b \\\n');
2727
- $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, null, null, null, null).toString(), 'a b \\\n\t\\\n');
2728
- },
2729
- 'fromJSON'() {
2730
- $mol_assert_equal($mol_tree.fromJSON([]).toString(), '/\n');
2731
- $mol_assert_equal($mol_tree.fromJSON([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
2732
- $mol_assert_equal($mol_tree.fromJSON([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
2733
- $mol_assert_equal($mol_tree.fromJSON(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
2734
- $mol_assert_equal($mol_tree.fromJSON({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
2735
- },
2736
- 'toJSON'() {
2737
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n').sub[0]), '[]');
2738
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\tfalse\n\ttrue\n').sub[0]), '[false,true]');
2739
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t0\n\t1\n\t2.3\n').sub[0]), '[0,1,2.3]');
2740
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n').sub[0]), '["","foo","bar\\nbaz"]');
2741
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n').sub[0]), '{"foo":false,"bar\\nbaz":"lol"}');
2742
- },
2743
- 'hack'() {
2744
- const res = $mol_tree.fromString(`foo bar xxx`).hack({
2745
- '': (tree, context) => [tree.hack(context)],
2746
- 'bar': (tree, context) => [tree.hack(context).clone({ type: '777' })],
2747
- });
2748
- $mol_assert_equal(res.toString(), new $mol_tree({ type: 'foo 777 xxx' }).toString());
2749
- },
2750
- 'errors handling'($) {
2751
- const errors = [];
2752
- class Tree extends $mol_tree {
2753
- static $ = $.$mol_ambient({
2754
- $mol_fail: error => errors.push(error.message)
2755
- });
2756
- }
2757
- Tree.fromString(`
2758
- \t \tfoo
2759
- bar \\data
2760
- `, 'test');
2761
- $mol_assert_like(errors, ['Syntax error at test:2\n \tfoo']);
2841
+ 'FQN of anon function'($) {
2842
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
2843
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
2844
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
2845
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
2762
2846
  },
2763
2847
  });
2764
2848
  })($ || ($ = {}));
2765
- //mol/tree/tree.test.ts
2849
+ //mol/func/name/name.test.ts
2766
2850
  ;
2767
2851
  "use strict";
2768
2852
  var $;
2769
- (function ($_1) {
2770
- $mol_test({
2771
- 'span for same uri'($) {
2772
- const span = new $mol_span('test.ts', '', 1, 3, 4);
2773
- const child = span.span(4, 5, 8);
2774
- $mol_assert_equal(child.uri, 'test.ts');
2775
- $mol_assert_equal(child.row, 4);
2776
- $mol_assert_equal(child.col, 5);
2777
- $mol_assert_equal(child.length, 8);
2778
- },
2779
- 'span after of given position'($) {
2780
- const span = new $mol_span('test.ts', '', 1, 3, 4);
2781
- const child = span.after(11);
2782
- $mol_assert_equal(child.uri, 'test.ts');
2783
- $mol_assert_equal(child.row, 1);
2784
- $mol_assert_equal(child.col, 7);
2785
- $mol_assert_equal(child.length, 11);
2786
- },
2787
- 'slice span - regular'($) {
2788
- const span = new $mol_span('test.ts', '', 1, 3, 5);
2789
- const child = span.slice(1, 4);
2790
- $mol_assert_equal(child.row, 1);
2791
- $mol_assert_equal(child.col, 4);
2792
- $mol_assert_equal(child.length, 3);
2793
- const child2 = span.slice(2, 2);
2794
- $mol_assert_equal(child2.col, 5);
2795
- $mol_assert_equal(child2.length, 0);
2796
- },
2797
- 'slice span - negative'($) {
2798
- const span = new $mol_span('test.ts', '', 1, 3, 5);
2799
- const child = span.slice(-3, -1);
2800
- $mol_assert_equal(child.row, 1);
2801
- $mol_assert_equal(child.col, 5);
2802
- $mol_assert_equal(child.length, 2);
2803
- },
2804
- 'slice span - out of range'($) {
2805
- const span = new $mol_span('test.ts', '', 1, 3, 5);
2806
- $mol_assert_fail(() => span.slice(-1, 3));
2807
- $mol_assert_fail(() => span.slice(1, 6));
2808
- $mol_assert_fail(() => span.slice(1, 10));
2809
- },
2810
- 'error handling'($) {
2811
- const span = new $mol_span('test.ts', '', 1, 3, 4);
2812
- const error = span.error('Some error\n');
2813
- $mol_assert_equal(error.message, 'Some error\ntest.ts#1:3/4');
2853
+ (function ($) {
2854
+ const named = new WeakSet();
2855
+ function $mol_func_name(func) {
2856
+ let name = func.name;
2857
+ if (name?.length > 1)
2858
+ return name;
2859
+ if (named.has(func))
2860
+ return name;
2861
+ for (let key in this) {
2862
+ try {
2863
+ if (this[key] !== func)
2864
+ continue;
2865
+ name = key;
2866
+ Object.defineProperty(func, 'name', { value: name });
2867
+ break;
2868
+ }
2869
+ catch { }
2814
2870
  }
2815
- });
2871
+ named.add(func);
2872
+ return name;
2873
+ }
2874
+ $.$mol_func_name = $mol_func_name;
2875
+ function $mol_func_name_from(target, source) {
2876
+ Object.defineProperty(target, 'name', { value: source.name });
2877
+ return target;
2878
+ }
2879
+ $.$mol_func_name_from = $mol_func_name_from;
2816
2880
  })($ || ($ = {}));
2817
- //mol/span/span.test.ts
2881
+ //mol/func/name/name.ts
2818
2882
  ;
2819
2883
  "use strict";
2820
2884
  var $;
@@ -2875,99 +2939,22 @@ var $;
2875
2939
  //mol/tree2/from/json/json.test.ts
2876
2940
  ;
2877
2941
  "use strict";
2878
- var $;
2879
- (function ($_1) {
2880
- $mol_test({
2881
- 'tree parsing'($) {
2882
- $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
2883
- $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
2884
- $mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
2885
- $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
2886
- $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
2887
- $mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
2888
- $mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
2889
- $mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
2890
- },
2891
- 'Too many tabs'($) {
2892
- const tree = `
2893
- foo
2894
- bar
2895
- `;
2896
- $mol_assert_fail(() => {
2897
- $.$mol_tree2_from_string(tree, 'test');
2898
- }, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
2899
- },
2900
- 'Too few tabs'($) {
2901
- const tree = `
2902
- foo
2903
- bar
2904
- `;
2905
- $mol_assert_fail(() => {
2906
- $.$mol_tree2_from_string(tree, 'test');
2907
- }, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
2908
- },
2909
- 'Wrong nodes separator'($) {
2910
- const tree = `foo bar\n`;
2911
- $mol_assert_fail(() => {
2912
- $.$mol_tree2_from_string(tree, 'test');
2913
- }, 'Wrong nodes separator\ntest#1:4/2\n !!\nfoo bar');
2914
- },
2915
- 'Undexpected EOF, LF required'($) {
2916
- const tree = ` foo`;
2917
- $mol_assert_fail(() => {
2918
- $.$mol_tree2_from_string(tree, 'test');
2919
- }, 'Undexpected EOF, LF required\ntest#1:5/1\n !\n foo');
2920
- },
2921
- 'Errors skip and collect'($) {
2922
- const tree = `foo bar`;
2923
- const errors = [];
2924
- const $$ = $.$mol_ambient({
2925
- $mol_fail: (error) => {
2926
- errors.push(error.message);
2927
- return null;
2928
- }
2929
- });
2930
- const res = $$.$mol_tree2_from_string(tree, 'test');
2931
- $mol_assert_like(errors, [
2932
- 'Wrong nodes separator\ntest#1:4/2\n !!\nfoo bar',
2933
- 'Undexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
2934
- ]);
2935
- $mol_assert_equal(res.toString(), 'foo bar\n');
2936
- },
2937
- });
2938
- })($ || ($ = {}));
2939
- //mol/tree2/from/string/string.test.ts
2940
- ;
2941
- "use strict";
2942
2942
  //mol/type/unary/unary.ts
2943
2943
  ;
2944
2944
  "use strict";
2945
- //mol/type/param/param.ts
2946
- ;
2947
- "use strict";
2948
2945
  //mol/type/param/param.test.ts
2949
2946
  ;
2950
2947
  "use strict";
2951
- //mol/type/tail/tail.ts
2948
+ //mol/type/param/param.ts
2952
2949
  ;
2953
2950
  "use strict";
2954
2951
  //mol/type/tail/tail.test.ts
2955
2952
  ;
2956
2953
  "use strict";
2957
- //mol/data/value/value.ts
2954
+ //mol/type/tail/tail.ts
2958
2955
  ;
2959
2956
  "use strict";
2960
- var $;
2961
- (function ($) {
2962
- function $mol_data_setup(value, config) {
2963
- return Object.assign(value, {
2964
- config,
2965
- Value: null
2966
- });
2967
- }
2968
- $.$mol_data_setup = $mol_data_setup;
2969
- })($ || ($ = {}));
2970
- //mol/data/setup/setup.ts
2957
+ //mol/data/value/value.ts
2971
2958
  ;
2972
2959
  "use strict";
2973
2960
  var $;
@@ -2984,12 +2971,15 @@ var $;
2984
2971
  "use strict";
2985
2972
  var $;
2986
2973
  (function ($) {
2987
- function $mol_func_is_class(func) {
2988
- return Object.getOwnPropertyDescriptor(func, 'prototype')?.writable === false;
2974
+ function $mol_data_setup(value, config) {
2975
+ return Object.assign(value, {
2976
+ config,
2977
+ Value: null
2978
+ });
2989
2979
  }
2990
- $.$mol_func_is_class = $mol_func_is_class;
2980
+ $.$mol_data_setup = $mol_data_setup;
2991
2981
  })($ || ($ = {}));
2992
- //mol/func/is/class/class.ts
2982
+ //mol/data/setup/setup.ts
2993
2983
  ;
2994
2984
  "use strict";
2995
2985
  var $;
@@ -3020,31 +3010,26 @@ var $;
3020
3010
  //mol/func/is/class/class.test.ts
3021
3011
  ;
3022
3012
  "use strict";
3023
- //mol/type/result/result.ts
3013
+ var $;
3014
+ (function ($) {
3015
+ function $mol_func_is_class(func) {
3016
+ return Object.getOwnPropertyDescriptor(func, 'prototype')?.writable === false;
3017
+ }
3018
+ $.$mol_func_is_class = $mol_func_is_class;
3019
+ })($ || ($ = {}));
3020
+ //mol/func/is/class/class.ts
3024
3021
  ;
3025
3022
  "use strict";
3026
3023
  //mol/type/result/result.test.ts
3027
3024
  ;
3028
3025
  "use strict";
3029
- //mol/type/foot/foot.ts
3026
+ //mol/type/result/result.ts
3030
3027
  ;
3031
3028
  "use strict";
3032
3029
  //mol/type/foot/foot.test.ts
3033
3030
  ;
3034
3031
  "use strict";
3035
- var $;
3036
- (function ($) {
3037
- function $mol_data_pipe(...funcs) {
3038
- return $mol_data_setup(function (input) {
3039
- let value = input;
3040
- for (const func of funcs)
3041
- value = $mol_func_is_class(func) ? new func(value) : func.call(this, value);
3042
- return value;
3043
- }, { funcs });
3044
- }
3045
- $.$mol_data_pipe = $mol_data_pipe;
3046
- })($ || ($ = {}));
3047
- //mol/data/pipe/pipe.ts
3032
+ //mol/type/foot/foot.ts
3048
3033
  ;
3049
3034
  "use strict";
3050
3035
  var $;
@@ -3080,6 +3065,21 @@ var $;
3080
3065
  ;
3081
3066
  "use strict";
3082
3067
  var $;
3068
+ (function ($) {
3069
+ function $mol_data_pipe(...funcs) {
3070
+ return $mol_data_setup(function (input) {
3071
+ let value = input;
3072
+ for (const func of funcs)
3073
+ value = $mol_func_is_class(func) ? new func(value) : func.call(this, value);
3074
+ return value;
3075
+ }, { funcs });
3076
+ }
3077
+ $.$mol_data_pipe = $mol_data_pipe;
3078
+ })($ || ($ = {}));
3079
+ //mol/data/pipe/pipe.ts
3080
+ ;
3081
+ "use strict";
3082
+ var $;
3083
3083
  (function ($) {
3084
3084
  const convert = $mol_data_pipe($mol_tree2_from_string, $mol_tree2_js_to_text, $mol_tree2_text_to_string);
3085
3085
  $mol_test({