mol_tree2 0.0.4 → 1.0.7

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.js CHANGED
@@ -5,1044 +5,1216 @@ var exports = void 0;
5
5
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
6
6
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7
7
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
8
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
+ else for (var i = decorators.length - 1; i >= 0; i--) if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
9
9
  return c > 3 && r && Object.defineProperty(target, key, r), r;
10
10
  };
11
11
 
12
- var globalThis = globalThis || ( typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this )
13
- var $ = ( typeof module === 'object' ) ? Object.setPrototypeOf( module['export'+'s'] , globalThis ) : globalThis
12
+ var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
14
13
  $.$$ = $
15
- $.$mol = $ // deprecated
16
14
 
17
15
  ;
18
16
 
19
17
  var $node = $node || {}
20
- void function( module ) { var exports = module.exports = this; function require( id ) { return $node[ id.replace( /^.\// , "../mol/" ) ] };
18
+ void function( module ) { var exports = module.exports = this; function require( id ) { return $node[ id.replace( /^.\// , "../" ) ] };
21
19
  ;
22
- "use strict";
23
- Error.stackTraceLimit = Infinity;
24
- var $;
25
- (function ($) {
26
- })($ || ($ = {}));
27
- module.exports = $;
28
- //mol.js.map
20
+ "use strict";
21
+ Error.stackTraceLimit = 50;
22
+ var $;
23
+ (function ($) {
24
+ })($ || ($ = {}));
25
+ module.exports = $;
26
+ //mam.ts
29
27
  ;
30
28
 
31
- $node[ "../mol/mol" ] = $node[ "../mol/mol.js" ] = module.exports }.call( {} , {} )
29
+ $node[ "../mam.ts" ] = $node[ "../mam.ts" ] = module.exports }.call( {} , {} )
32
30
  ;
33
- "use strict";
34
- var $;
35
- (function ($) {
36
- $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
37
- function $mol_ambient(overrides) {
38
- return Object.setPrototypeOf(overrides, this || $);
39
- }
40
- $.$mol_ambient = $mol_ambient;
41
- })($ || ($ = {}));
42
- //ambient.js.map
31
+ "use strict";
32
+ var $;
33
+ (function ($) {
34
+ $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
35
+ function $mol_ambient(overrides) {
36
+ return Object.setPrototypeOf(overrides, this || $);
37
+ }
38
+ $.$mol_ambient = $mol_ambient;
39
+ })($ || ($ = {}));
40
+ //mol/ambient/ambient.ts
43
41
  ;
44
- "use strict";
45
- var $;
46
- (function ($) {
47
- const instances = new WeakSet();
48
- function $mol_delegate(proto, target) {
49
- const proxy = new Proxy(proto, {
50
- get: (_, field) => {
51
- const obj = target();
52
- let val = Reflect.get(obj, field);
53
- if (typeof val === 'function') {
54
- val = val.bind(obj);
55
- }
56
- return val;
57
- },
58
- has: (_, field) => Reflect.has(target(), field),
59
- set: (_, field, value) => Reflect.set(target(), field, value),
60
- getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
61
- ownKeys: () => Reflect.ownKeys(target()),
62
- getPrototypeOf: () => Reflect.getPrototypeOf(target()),
63
- setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
64
- isExtensible: () => Reflect.isExtensible(target()),
65
- preventExtensions: () => Reflect.preventExtensions(target()),
66
- apply: (_, self, args) => Reflect.apply(target(), self, args),
67
- construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
68
- defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
69
- deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
70
- });
71
- instances.add(proxy);
72
- return proxy;
73
- }
74
- $.$mol_delegate = $mol_delegate;
75
- Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
76
- value: (obj) => instances.has(obj),
77
- });
78
- })($ || ($ = {}));
79
- //delegate.js.map
42
+ "use strict";
43
+ var $;
44
+ (function ($) {
45
+ const instances = new WeakSet();
46
+ function $mol_delegate(proto, target) {
47
+ const proxy = new Proxy(proto, {
48
+ get: (_, field) => {
49
+ const obj = target();
50
+ let val = Reflect.get(obj, field);
51
+ if (typeof val === 'function') {
52
+ val = val.bind(obj);
53
+ }
54
+ return val;
55
+ },
56
+ has: (_, field) => Reflect.has(target(), field),
57
+ set: (_, field, value) => Reflect.set(target(), field, value),
58
+ getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
59
+ ownKeys: () => Reflect.ownKeys(target()),
60
+ getPrototypeOf: () => Reflect.getPrototypeOf(target()),
61
+ setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
62
+ isExtensible: () => Reflect.isExtensible(target()),
63
+ preventExtensions: () => Reflect.preventExtensions(target()),
64
+ apply: (_, self, args) => Reflect.apply(target(), self, args),
65
+ construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
66
+ defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
67
+ deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
68
+ });
69
+ instances.add(proxy);
70
+ return proxy;
71
+ }
72
+ $.$mol_delegate = $mol_delegate;
73
+ Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
74
+ value: (obj) => instances.has(obj),
75
+ });
76
+ })($ || ($ = {}));
77
+ //mol/delegate/delegate.ts
80
78
  ;
81
- "use strict";
82
- var $;
83
- (function ($) {
84
- $.$mol_owning_map = new WeakMap();
85
- function $mol_owning_allow(having) {
86
- try {
87
- if (!having)
88
- return false;
89
- if (typeof having !== 'object')
90
- return false;
91
- if (having instanceof $.$mol_delegate)
92
- return false;
93
- if (typeof having['destructor'] !== 'function')
94
- return false;
95
- return true;
96
- }
97
- catch (_a) {
98
- return false;
99
- }
100
- }
101
- $.$mol_owning_allow = $mol_owning_allow;
102
- function $mol_owning_get(having, Owner) {
103
- if (!$mol_owning_allow(having))
104
- return null;
105
- while (true) {
106
- const owner = $.$mol_owning_map.get(having);
107
- if (!owner)
108
- return owner;
109
- if (!Owner)
110
- return owner;
111
- if (owner instanceof Owner)
112
- return owner;
113
- having = owner;
114
- }
115
- }
116
- $.$mol_owning_get = $mol_owning_get;
117
- function $mol_owning_check(owner, having) {
118
- if (!$mol_owning_allow(having))
119
- return false;
120
- if ($.$mol_owning_map.get(having) !== owner)
121
- return false;
122
- return true;
123
- }
124
- $.$mol_owning_check = $mol_owning_check;
125
- function $mol_owning_catch(owner, having) {
126
- if (!$mol_owning_allow(having))
127
- return false;
128
- if ($.$mol_owning_map.get(having))
129
- return false;
130
- $.$mol_owning_map.set(having, owner);
131
- return true;
132
- }
133
- $.$mol_owning_catch = $mol_owning_catch;
134
- })($ || ($ = {}));
135
- //owning.js.map
79
+ "use strict";
80
+ var $;
81
+ (function ($) {
82
+ $.$mol_owning_map = new WeakMap();
83
+ function $mol_owning_allow(having) {
84
+ try {
85
+ if (!having)
86
+ return false;
87
+ if (typeof having !== 'object')
88
+ return false;
89
+ if (having instanceof $mol_delegate)
90
+ return false;
91
+ if (typeof having['destructor'] !== 'function')
92
+ return false;
93
+ return true;
94
+ }
95
+ catch {
96
+ return false;
97
+ }
98
+ }
99
+ $.$mol_owning_allow = $mol_owning_allow;
100
+ function $mol_owning_get(having, Owner) {
101
+ if (!$mol_owning_allow(having))
102
+ return null;
103
+ while (true) {
104
+ const owner = $.$mol_owning_map.get(having);
105
+ if (!owner)
106
+ return owner;
107
+ if (!Owner)
108
+ return owner;
109
+ if (owner instanceof Owner)
110
+ return owner;
111
+ having = owner;
112
+ }
113
+ }
114
+ $.$mol_owning_get = $mol_owning_get;
115
+ function $mol_owning_check(owner, having) {
116
+ if (!$mol_owning_allow(having))
117
+ return false;
118
+ if ($.$mol_owning_map.get(having) !== owner)
119
+ return false;
120
+ return true;
121
+ }
122
+ $.$mol_owning_check = $mol_owning_check;
123
+ function $mol_owning_catch(owner, having) {
124
+ if (!$mol_owning_allow(having))
125
+ return false;
126
+ if ($.$mol_owning_map.get(having))
127
+ return false;
128
+ $.$mol_owning_map.set(having, owner);
129
+ return true;
130
+ }
131
+ $.$mol_owning_catch = $mol_owning_catch;
132
+ })($ || ($ = {}));
133
+ //mol/owning/owning.ts
136
134
  ;
137
- "use strict";
138
- var $;
139
- (function ($) {
140
- function $mol_fail(error) {
141
- throw error;
142
- }
143
- $.$mol_fail = $mol_fail;
144
- })($ || ($ = {}));
145
- //fail.js.map
135
+ "use strict";
136
+ var $;
137
+ (function ($) {
138
+ function $mol_fail(error) {
139
+ throw error;
140
+ }
141
+ $.$mol_fail = $mol_fail;
142
+ })($ || ($ = {}));
143
+ //mol/fail/fail.ts
146
144
  ;
147
- "use strict";
148
- var $;
149
- (function ($) {
150
- function $mol_fail_hidden(error) {
151
- throw error;
152
- }
153
- $.$mol_fail_hidden = $mol_fail_hidden;
154
- })($ || ($ = {}));
155
- //hidden.js.map
145
+ "use strict";
146
+ var $;
147
+ (function ($) {
148
+ function $mol_fail_hidden(error) {
149
+ throw error;
150
+ }
151
+ $.$mol_fail_hidden = $mol_fail_hidden;
152
+ })($ || ($ = {}));
153
+ //mol/fail/hidden/hidden.ts
156
154
  ;
157
- "use strict";
158
- //writable.js.map
155
+ "use strict";
156
+ //mol/type/writable/writable.ts
159
157
  ;
160
- "use strict";
161
- var $;
162
- (function ($) {
163
- var _a;
164
- class $mol_object2 {
165
- constructor(init) {
166
- this[_a] = null;
167
- if (init)
168
- init(this);
169
- }
170
- get $() {
171
- if (this[$.$mol_ambient_ref])
172
- return this[$.$mol_ambient_ref];
173
- const owner = $.$mol_owning_get(this);
174
- return this[$.$mol_ambient_ref] = (owner === null || owner === void 0 ? void 0 : owner.$) || $mol_object2.$;
175
- }
176
- set $(next) {
177
- if (this[$.$mol_ambient_ref])
178
- $.$mol_fail_hidden(new Error('Context already defined'));
179
- this[$.$mol_ambient_ref] = next;
180
- }
181
- static create(init) {
182
- return new this(init);
183
- }
184
- static [(_a = $.$mol_ambient_ref, Symbol.toPrimitive)]() {
185
- return this.toString();
186
- }
187
- static toString() {
188
- if (Symbol.toStringTag in this)
189
- return this[Symbol.toStringTag];
190
- return this.name;
191
- }
192
- destructor() { }
193
- [Symbol.toPrimitive](hint) {
194
- return hint === 'number' ? this.valueOf() : this.toString();
195
- }
196
- toString() {
197
- return this[Symbol.toStringTag] || this.constructor.name + '()';
198
- }
199
- toJSON() {
200
- return this.toString();
201
- }
202
- }
203
- $mol_object2.$ = $;
204
- $.$mol_object2 = $mol_object2;
205
- })($ || ($ = {}));
206
- //object2.js.map
158
+ "use strict";
159
+ var $;
160
+ (function ($) {
161
+ class $mol_object2 {
162
+ static $ = $;
163
+ [$mol_ambient_ref] = null;
164
+ get $() {
165
+ if (this[$mol_ambient_ref])
166
+ return this[$mol_ambient_ref];
167
+ const owner = $mol_owning_get(this);
168
+ return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
169
+ }
170
+ set $(next) {
171
+ if (this[$mol_ambient_ref])
172
+ $mol_fail_hidden(new Error('Context already defined'));
173
+ this[$mol_ambient_ref] = next;
174
+ }
175
+ static create(init) {
176
+ const obj = new this;
177
+ if (init)
178
+ init(obj);
179
+ return obj;
180
+ }
181
+ static [Symbol.toPrimitive]() {
182
+ return this.toString();
183
+ }
184
+ static toString() {
185
+ if (Symbol.toStringTag in this)
186
+ return this[Symbol.toStringTag];
187
+ return this.name;
188
+ }
189
+ destructor() { }
190
+ toString() {
191
+ return this[Symbol.toStringTag] || this.constructor.name + '()';
192
+ }
193
+ toJSON() {
194
+ return this.toString();
195
+ }
196
+ }
197
+ $.$mol_object2 = $mol_object2;
198
+ })($ || ($ = {}));
199
+ //mol/object2/object2.ts
207
200
  ;
208
- "use strict";
209
- var $;
210
- (function ($) {
211
- class $mol_span extends $.$mol_object2 {
212
- constructor(uri, source, row, col, length) {
213
- super();
214
- this.uri = uri;
215
- this.source = source;
216
- this.row = row;
217
- this.col = col;
218
- this.length = length;
219
- this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
220
- }
221
- static begin(uri, source = '') {
222
- return new $mol_span(uri, source, 1, 1, 0);
223
- }
224
- static end(uri, source) {
225
- return new $mol_span(uri, source, 1, source.length + 1, length);
226
- }
227
- static entire(uri, source) {
228
- return new $mol_span(uri, source, 1, 1, source.length);
229
- }
230
- toString() {
231
- return this[Symbol.toStringTag];
232
- }
233
- toJSON() {
234
- return {
235
- uri: this.uri,
236
- row: this.row,
237
- col: this.col,
238
- length: this.length
239
- };
240
- }
241
- error(message, Class = Error) {
242
- return new Class(`${message}${this}`);
243
- }
244
- span(row, col, length) {
245
- return new $mol_span(this.uri, this.source, row, col, length);
246
- }
247
- after(length = 0) {
248
- return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
249
- }
250
- slice(begin, end = -1) {
251
- let len = this.length;
252
- if (begin < 0)
253
- begin += len;
254
- if (end < 0)
255
- end += len;
256
- if (begin < 0 || begin > len)
257
- this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
258
- if (end < 0 || end > len)
259
- this.$.$mol_fail(`End value '${end}' out of range ${this}`);
260
- if (end < begin)
261
- this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
262
- return this.span(this.row, this.col + begin, end - begin);
263
- }
264
- }
265
- $mol_span.unknown = $mol_span.begin('unknown');
266
- $.$mol_span = $mol_span;
267
- })($ || ($ = {}));
268
- //span.js.map
201
+ "use strict";
202
+ var $;
203
+ (function ($) {
204
+ class $mol_span extends $mol_object2 {
205
+ uri;
206
+ source;
207
+ row;
208
+ col;
209
+ length;
210
+ constructor(uri, source, row, col, length) {
211
+ super();
212
+ this.uri = uri;
213
+ this.source = source;
214
+ this.row = row;
215
+ this.col = col;
216
+ this.length = length;
217
+ this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
218
+ }
219
+ static unknown = $mol_span.begin('unknown');
220
+ static begin(uri, source = '') {
221
+ return new $mol_span(uri, source, 1, 1, 0);
222
+ }
223
+ static end(uri, source) {
224
+ return new $mol_span(uri, source, 1, source.length + 1, length);
225
+ }
226
+ static entire(uri, source) {
227
+ return new $mol_span(uri, source, 1, 1, source.length);
228
+ }
229
+ toString() {
230
+ return this[Symbol.toStringTag];
231
+ }
232
+ toJSON() {
233
+ return {
234
+ uri: this.uri,
235
+ row: this.row,
236
+ col: this.col,
237
+ length: this.length
238
+ };
239
+ }
240
+ error(message, Class = Error) {
241
+ return new Class(`${message}${this}`);
242
+ }
243
+ span(row, col, length) {
244
+ return new $mol_span(this.uri, this.source, row, col, length);
245
+ }
246
+ after(length = 0) {
247
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
248
+ }
249
+ slice(begin, end = -1) {
250
+ let len = this.length;
251
+ if (begin < 0)
252
+ begin += len;
253
+ if (end < 0)
254
+ end += len;
255
+ if (begin < 0 || begin > len)
256
+ this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
257
+ if (end < 0 || end > len)
258
+ this.$.$mol_fail(`End value '${end}' out of range ${this}`);
259
+ if (end < begin)
260
+ this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
261
+ return this.span(this.row, this.col + begin, end - begin);
262
+ }
263
+ }
264
+ $.$mol_span = $mol_span;
265
+ })($ || ($ = {}));
266
+ //mol/span/span.ts
269
267
  ;
270
- "use strict";
271
- var $;
272
- (function ($) {
273
- function $mol_deprecated(message) {
274
- return (host, field, descr) => {
275
- const value = descr.value;
276
- let warned = false;
277
- descr.value = function $mol_deprecated_wrapper(...args) {
278
- if (!warned) {
279
- this.$.$mol_log3_warn({
280
- place: `${host.constructor.name}::${field}`,
281
- message: `Deprecated`,
282
- hint: message,
283
- });
284
- warned = true;
285
- }
286
- return value.call(this, ...args);
287
- };
288
- };
289
- }
290
- $.$mol_deprecated = $mol_deprecated;
291
- })($ || ($ = {}));
292
- //deprecated.js.map
268
+ "use strict";
269
+ var $;
270
+ (function ($) {
271
+ class $mol_error_syntax extends SyntaxError {
272
+ reason;
273
+ line;
274
+ span;
275
+ constructor(reason, line, span) {
276
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
277
+ this.reason = reason;
278
+ this.line = line;
279
+ this.span = span;
280
+ }
281
+ }
282
+ $.$mol_error_syntax = $mol_error_syntax;
283
+ })($ || ($ = {}));
284
+ //mol/error/syntax/syntax.ts
293
285
  ;
294
- "use strict";
295
- var $;
296
- (function ($) {
297
- class $mol_tree2 extends $.$mol_object2 {
298
- constructor(type, value, kids, span) {
299
- super();
300
- this.type = type;
301
- this.value = value;
302
- this.kids = kids;
303
- this.span = span;
304
- this[Symbol.toStringTag] = type || '\\' + value;
305
- }
306
- static list(kids, span = $.$mol_span.unknown) {
307
- return new $mol_tree2('', '', kids, span);
308
- }
309
- list(kids) {
310
- return $mol_tree2.list(kids, this.span);
311
- }
312
- static data(value, kids = [], span = $.$mol_span.unknown) {
313
- const chunks = value.split('\n');
314
- if (chunks.length > 1) {
315
- let kid_span = span.span(span.row, span.col, 0);
316
- const data = chunks.map(chunk => {
317
- kid_span = kid_span.after(chunk.length);
318
- return new $mol_tree2('', chunk, [], kid_span);
319
- });
320
- kids = [...data, ...kids];
321
- value = '';
322
- }
323
- return new $mol_tree2('', value, kids, span);
324
- }
325
- data(value, kids = []) {
326
- return $mol_tree2.data(value, kids, this.span);
327
- }
328
- static struct(type, kids = [], span = $.$mol_span.unknown) {
329
- if (/[ \n\t\\]/.test(type)) {
330
- this.$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
331
- }
332
- return new $mol_tree2(type, '', kids, span);
333
- }
334
- struct(type, kids = []) {
335
- return $mol_tree2.struct(type, kids, this.span);
336
- }
337
- clone(kids, span = this.span) {
338
- return new $mol_tree2(this.type, this.value, kids, span);
339
- }
340
- text() {
341
- var values = [];
342
- for (var kid of this.kids) {
343
- if (kid.type)
344
- continue;
345
- values.push(kid.value);
346
- }
347
- return this.value + values.join('\n');
348
- }
349
- static fromString(str, uri = 'unknown') {
350
- return this.$.$mol_tree2_from_string(str, uri);
351
- }
352
- toString() {
353
- return this.$.$mol_tree2_to_string(this);
354
- }
355
- insert(value, ...path) {
356
- if (path.length === 0)
357
- return value;
358
- const type = path[0];
359
- if (typeof type === 'string') {
360
- let replaced = false;
361
- const sub = this.kids.map((item, index) => {
362
- if (item.type !== type)
363
- return item;
364
- replaced = true;
365
- return item.insert(value, ...path.slice(1));
366
- });
367
- if (!replaced) {
368
- sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
369
- }
370
- return this.clone(sub);
371
- }
372
- else if (typeof type === 'number') {
373
- const sub = this.kids.slice();
374
- sub[type] = (sub[type] || this.list([])).insert(value, ...path.slice(1));
375
- return this.clone(sub);
376
- }
377
- else {
378
- const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
379
- .map(item => item.insert(value, ...path.slice(1)));
380
- return this.clone(kids);
381
- }
382
- }
383
- select(...path) {
384
- let next = [this];
385
- for (const type of path) {
386
- if (!next.length)
387
- break;
388
- const prev = next;
389
- next = [];
390
- for (var item of prev) {
391
- switch (typeof (type)) {
392
- case 'string':
393
- for (var child of item.kids) {
394
- if (!type || (child.type == type)) {
395
- next.push(child);
396
- }
397
- }
398
- break;
399
- case 'number':
400
- if (type < item.kids.length)
401
- next.push(item.kids[type]);
402
- break;
403
- default: next.push(...item.kids);
404
- }
405
- }
406
- }
407
- return this.list(next);
408
- }
409
- filter(path, value) {
410
- const sub = this.kids.filter(item => {
411
- var found = item.select(...path);
412
- if (value === undefined) {
413
- return Boolean(found.kids.length);
414
- }
415
- else {
416
- return found.kids.some(child => child.value == value);
417
- }
418
- });
419
- return this.clone(sub);
420
- }
421
- hack(belt, context = {}) {
422
- return [].concat(...this.kids.map(child => {
423
- let handle = belt[child.type] || belt[''];
424
- if (!handle || handle === Object.prototype[child.type]) {
425
- handle = (input, belt, context) => [
426
- input.clone(input.hack(belt, context), context.span)
427
- ];
428
- }
429
- try {
430
- return handle(child, belt, context);
431
- }
432
- catch (error) {
433
- error.message += `\n${child.clone([])}${child.span}`;
434
- $.$mol_fail_hidden(error);
435
- }
436
- }));
437
- }
438
- error(message, Class = Error) {
439
- return this.span.error(`${message}\n${this.clone([])}`, Class);
440
- }
441
- }
442
- __decorate([
443
- $.$mol_deprecated('Use $mol_tree2_from_string')
444
- ], $mol_tree2, "fromString", null);
445
- $.$mol_tree2 = $mol_tree2;
446
- class $mol_tree2_empty extends $mol_tree2 {
447
- constructor() {
448
- super('', '', [], $.$mol_span.unknown);
449
- }
450
- }
451
- $.$mol_tree2_empty = $mol_tree2_empty;
452
- })($ || ($ = {}));
453
- //tree2.js.map
286
+ "use strict";
287
+ var $;
288
+ (function ($) {
289
+ function $mol_tree2_from_string(str, uri = 'unknown') {
290
+ const span = $mol_span.entire(uri, str);
291
+ var root = $mol_tree2.list([], span);
292
+ var stack = [root];
293
+ var pos = 0, row = 0, min_indent = 0;
294
+ while (str.length > pos) {
295
+ var indent = 0;
296
+ var line_start = pos;
297
+ row++;
298
+ while (str.length > pos && str[pos] == '\t') {
299
+ indent++;
300
+ pos++;
301
+ }
302
+ if (!root.kids.length) {
303
+ min_indent = indent;
304
+ }
305
+ indent -= min_indent;
306
+ if (indent < 0 || indent >= stack.length) {
307
+ const sp = span.span(row, 1, pos - line_start);
308
+ while (str.length > pos && str[pos] != '\n') {
309
+ pos++;
310
+ }
311
+ if (indent < 0) {
312
+ if (str.length > pos) {
313
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
314
+ }
315
+ }
316
+ else {
317
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
318
+ }
319
+ }
320
+ stack.length = indent + 1;
321
+ var parent = stack[indent];
322
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
323
+ var error_start = pos;
324
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
325
+ pos++;
326
+ }
327
+ if (pos > error_start) {
328
+ let line_end = str.indexOf('\n', pos);
329
+ if (line_end === -1)
330
+ line_end = str.length;
331
+ const sp = span.span(row, error_start - line_start, pos - error_start + 1);
332
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
333
+ }
334
+ var type_start = pos;
335
+ while (str.length > pos &&
336
+ str[pos] != '\\' &&
337
+ str[pos] != ' ' &&
338
+ str[pos] != '\t' &&
339
+ str[pos] != '\n') {
340
+ pos++;
341
+ }
342
+ if (pos > type_start) {
343
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
344
+ const parent_kids = parent.kids;
345
+ parent_kids.push(next);
346
+ parent = next;
347
+ }
348
+ if (str.length > pos && str[pos] == ' ') {
349
+ pos++;
350
+ }
351
+ }
352
+ if (str.length > pos && str[pos] == '\\') {
353
+ var data_start = pos;
354
+ while (str.length > pos && str[pos] != '\n') {
355
+ pos++;
356
+ }
357
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
358
+ const parent_kids = parent.kids;
359
+ parent_kids.push(next);
360
+ parent = next;
361
+ }
362
+ if (str.length === pos && stack.length > 0) {
363
+ const sp = span.span(row, pos - line_start + 1, 1);
364
+ this.$mol_fail(new this.$mol_error_syntax(`Undexpected EOF, LF required`, str.substring(line_start, str.length), sp));
365
+ }
366
+ stack.push(parent);
367
+ pos++;
368
+ }
369
+ return root;
370
+ }
371
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
372
+ })($ || ($ = {}));
373
+ //mol/tree2/from/string/string.ts
454
374
  ;
455
- "use strict";
456
- var $;
457
- (function ($) {
458
- function $mol_log3_area_lazy(event) {
459
- const self = this;
460
- const stack = self.$mol_log3_stack;
461
- const deep = stack.length;
462
- let logged = false;
463
- stack.push(() => {
464
- logged = true;
465
- self.$mol_log3_area.call(self, event);
466
- });
467
- return () => {
468
- if (logged)
469
- self.console.groupEnd();
470
- if (stack.length > deep)
471
- stack.length = deep;
472
- };
473
- }
474
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
475
- $.$mol_log3_stack = [];
476
- })($ || ($ = {}));
477
- //log3.js.map
375
+ "use strict";
376
+ var $;
377
+ (function ($) {
378
+ function $mol_tree2_to_string(tree) {
379
+ let output = [];
380
+ function dump(tree, prefix = '') {
381
+ if (tree.type.length) {
382
+ if (!prefix.length) {
383
+ prefix = "\t";
384
+ }
385
+ output.push(tree.type);
386
+ if (tree.kids.length == 1) {
387
+ output.push(' ');
388
+ dump(tree.kids[0], prefix);
389
+ return;
390
+ }
391
+ output.push("\n");
392
+ }
393
+ else if (tree.value.length || prefix.length) {
394
+ output.push("\\" + tree.value + "\n");
395
+ }
396
+ for (const kid of tree.kids) {
397
+ output.push(prefix);
398
+ dump(kid, prefix + "\t");
399
+ }
400
+ }
401
+ dump(tree);
402
+ return output.join('');
403
+ }
404
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
405
+ })($ || ($ = {}));
406
+ //mol/tree2/to/string/string.ts
478
407
  ;
479
- "use strict";
480
- var $node = new Proxy({ require }, {
481
- get(target, name, wrapper) {
482
- if (target[name])
483
- return target[name];
484
- const mod = target.require('module');
485
- if (mod.builtinModules.indexOf(name) >= 0)
486
- return target.require(name);
487
- const path = target.require('path');
488
- const fs = target.require('fs');
489
- let dir = path.resolve('.');
490
- const suffix = `./node_modules/${name}`;
491
- const $$ = $;
492
- while (!fs.existsSync(path.join(dir, suffix))) {
493
- const parent = path.resolve(dir, '..');
494
- if (parent === dir) {
495
- $$.$mol_exec('.', 'npm', 'install', name);
496
- try {
497
- $$.$mol_exec('.', 'npm', 'install', '@types/' + name);
498
- }
499
- catch (_a) { }
500
- break;
501
- }
502
- else {
503
- dir = parent;
504
- }
505
- }
506
- return target.require(name);
507
- },
508
- set(target, name, value) {
509
- target[name] = value;
510
- return true;
511
- },
512
- });
513
- require = (req => Object.assign(function require(name) {
514
- return $node[name];
515
- }, req))(require);
516
- //node.node.js.map
408
+ "use strict";
409
+ var $;
410
+ (function ($) {
411
+ class $mol_tree2 extends Object {
412
+ type;
413
+ value;
414
+ kids;
415
+ span;
416
+ constructor(type, value, kids, span) {
417
+ super();
418
+ this.type = type;
419
+ this.value = value;
420
+ this.kids = kids;
421
+ this.span = span;
422
+ this[Symbol.toStringTag] = type || '\\' + value;
423
+ }
424
+ static list(kids, span = $mol_span.unknown) {
425
+ return new $mol_tree2('', '', kids, span);
426
+ }
427
+ list(kids) {
428
+ return $mol_tree2.list(kids, this.span);
429
+ }
430
+ static data(value, kids = [], span = $mol_span.unknown) {
431
+ const chunks = value.split('\n');
432
+ if (chunks.length > 1) {
433
+ let kid_span = span.span(span.row, span.col, 0);
434
+ const data = chunks.map(chunk => {
435
+ kid_span = kid_span.after(chunk.length);
436
+ return new $mol_tree2('', chunk, [], kid_span);
437
+ });
438
+ kids = [...data, ...kids];
439
+ value = '';
440
+ }
441
+ return new $mol_tree2('', value, kids, span);
442
+ }
443
+ data(value, kids = []) {
444
+ return $mol_tree2.data(value, kids, this.span);
445
+ }
446
+ static struct(type, kids = [], span = $mol_span.unknown) {
447
+ if (/[ \n\t\\]/.test(type)) {
448
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
449
+ }
450
+ return new $mol_tree2(type, '', kids, span);
451
+ }
452
+ struct(type, kids = []) {
453
+ return $mol_tree2.struct(type, kids, this.span);
454
+ }
455
+ clone(kids, span = this.span) {
456
+ return new $mol_tree2(this.type, this.value, kids, span);
457
+ }
458
+ text() {
459
+ var values = [];
460
+ for (var kid of this.kids) {
461
+ if (kid.type)
462
+ continue;
463
+ values.push(kid.value);
464
+ }
465
+ return this.value + values.join('\n');
466
+ }
467
+ static fromString(str, uri = 'unknown') {
468
+ return $$.$mol_tree2_from_string(str, uri);
469
+ }
470
+ toString() {
471
+ return $$.$mol_tree2_to_string(this);
472
+ }
473
+ insert(value, ...path) {
474
+ if (path.length === 0)
475
+ return value;
476
+ const type = path[0];
477
+ if (typeof type === 'string') {
478
+ let replaced = false;
479
+ const sub = this.kids.map((item, index) => {
480
+ if (item.type !== type)
481
+ return item;
482
+ replaced = true;
483
+ return item.insert(value, ...path.slice(1));
484
+ }).filter(Boolean);
485
+ if (!replaced && value) {
486
+ sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
487
+ }
488
+ return this.clone(sub);
489
+ }
490
+ else if (typeof type === 'number') {
491
+ const sub = this.kids.slice();
492
+ sub[type] = (sub[type] || this.list([]))
493
+ .insert(value, ...path.slice(1));
494
+ return this.clone(sub.filter(Boolean));
495
+ }
496
+ else {
497
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
498
+ .map(item => item.insert(value, ...path.slice(1)))
499
+ .filter(Boolean);
500
+ return this.clone(kids);
501
+ }
502
+ }
503
+ select(...path) {
504
+ let next = [this];
505
+ for (const type of path) {
506
+ if (!next.length)
507
+ break;
508
+ const prev = next;
509
+ next = [];
510
+ for (var item of prev) {
511
+ switch (typeof (type)) {
512
+ case 'string':
513
+ for (var child of item.kids) {
514
+ if (child.type == type) {
515
+ next.push(child);
516
+ }
517
+ }
518
+ break;
519
+ case 'number':
520
+ if (type < item.kids.length)
521
+ next.push(item.kids[type]);
522
+ break;
523
+ default: next.push(...item.kids);
524
+ }
525
+ }
526
+ }
527
+ return this.list(next);
528
+ }
529
+ filter(path, value) {
530
+ const sub = this.kids.filter(item => {
531
+ var found = item.select(...path);
532
+ if (value === undefined) {
533
+ return Boolean(found.kids.length);
534
+ }
535
+ else {
536
+ return found.kids.some(child => child.value == value);
537
+ }
538
+ });
539
+ return this.clone(sub);
540
+ }
541
+ hack(belt, context = {}) {
542
+ return [].concat(...this.kids.map(child => {
543
+ let handle = belt[child.type] || belt[''];
544
+ if (!handle || handle === Object.prototype[child.type]) {
545
+ handle = (input, belt, context) => [
546
+ input.clone(input.hack(belt, context), context.span)
547
+ ];
548
+ }
549
+ try {
550
+ return handle(child, belt, context);
551
+ }
552
+ catch (error) {
553
+ error.message += `\n${child.clone([])}${child.span}`;
554
+ $mol_fail_hidden(error);
555
+ }
556
+ }));
557
+ }
558
+ error(message, Class = Error) {
559
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
560
+ }
561
+ }
562
+ $.$mol_tree2 = $mol_tree2;
563
+ class $mol_tree2_empty extends $mol_tree2 {
564
+ constructor() {
565
+ super('', '', [], $mol_span.unknown);
566
+ }
567
+ }
568
+ $.$mol_tree2_empty = $mol_tree2_empty;
569
+ })($ || ($ = {}));
570
+ //mol/tree2/tree2.ts
517
571
  ;
518
- "use strict";
519
- var $;
520
- (function ($) {
521
- $.$mol_tree_convert = Symbol('$mol_tree_convert');
522
- class $mol_tree extends $.$mol_object2 {
523
- constructor(config = {}) {
524
- super();
525
- this.type = config.type || '';
526
- if (config.value !== undefined) {
527
- var sub = $mol_tree.values(config.value);
528
- if (config.type || sub.length > 1) {
529
- this.sub = [...sub, ...(config.sub || [])];
530
- this.data = config.data || '';
531
- }
532
- else {
533
- this.data = sub[0].data;
534
- this.sub = config.sub || [];
535
- }
536
- }
537
- else {
538
- this.data = config.data || '';
539
- this.sub = config.sub || [];
540
- }
541
- this.baseUri = config.baseUri || '';
542
- this.row = config.row || 0;
543
- this.col = config.col || 0;
544
- this.length = config.length || 0;
545
- }
546
- static values(str, baseUri) {
547
- return str.split('\n').map((data, index) => new $mol_tree({
548
- data: data,
549
- baseUri: baseUri,
550
- row: index + 1,
551
- length: data.length,
552
- }));
553
- }
554
- clone(config = {}) {
555
- return new $mol_tree({
556
- type: ('type' in config) ? config.type : this.type,
557
- data: ('data' in config) ? config.data : this.data,
558
- sub: ('sub' in config) ? config.sub : this.sub,
559
- baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
560
- row: ('row' in config) ? config.row : this.row,
561
- col: ('col' in config) ? config.col : this.col,
562
- length: ('length' in config) ? config.length : this.length,
563
- value: config.value
564
- });
565
- }
566
- make(config) {
567
- return new $mol_tree(Object.assign({ baseUri: this.baseUri, row: this.row, col: this.col, length: this.length }, config));
568
- }
569
- make_data(value, sub) {
570
- return this.make({ value, sub });
571
- }
572
- make_struct(type, sub) {
573
- return this.make({ type, sub });
574
- }
575
- static fromString(str, baseUri) {
576
- var root = new $mol_tree({ baseUri: baseUri });
577
- var stack = [root];
578
- var row = 0;
579
- var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
580
- var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
581
- lines.forEach(line => {
582
- ++row;
583
- var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
584
- if (!chunks || chunks[4])
585
- return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
586
- var indent = chunks[1];
587
- var path = chunks[2];
588
- var data = chunks[3];
589
- var deep = indent.length;
590
- var types = path ? path.replace(/ $/, '').split(/ +/) : [];
591
- if (stack.length <= deep)
592
- return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
593
- stack.length = deep + 1;
594
- var parent = stack[deep];
595
- let col = deep;
596
- types.forEach(type => {
597
- if (!type)
598
- return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
599
- var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
600
- const parent_sub = parent.sub;
601
- parent_sub.push(next);
602
- parent = next;
603
- col += type.length + 1;
604
- });
605
- if (data) {
606
- var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
607
- const parent_sub = parent.sub;
608
- parent_sub.push(next);
609
- parent = next;
610
- }
611
- stack.push(parent);
612
- });
613
- return root;
614
- }
615
- static fromJSON(json, baseUri = '') {
616
- switch (true) {
617
- case typeof json === 'boolean':
618
- case typeof json === 'number':
619
- case json === null:
620
- return new $mol_tree({
621
- type: String(json),
622
- baseUri: baseUri
623
- });
624
- case typeof json === 'string':
625
- return new $mol_tree({
626
- value: json,
627
- baseUri: baseUri
628
- });
629
- case Array.isArray(json):
630
- return new $mol_tree({
631
- type: "/",
632
- sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
633
- });
634
- case json instanceof Date:
635
- return new $mol_tree({
636
- value: json.toISOString(),
637
- baseUri: baseUri
638
- });
639
- default:
640
- if (typeof json[$.$mol_tree_convert] === 'function') {
641
- return json[$.$mol_tree_convert]();
642
- }
643
- if (typeof json.toJSON === 'function') {
644
- return $mol_tree.fromJSON(json.toJSON());
645
- }
646
- if (json instanceof Error) {
647
- const { name, message, stack } = json;
648
- json = Object.assign(Object.assign({}, json), { name, message, stack });
649
- }
650
- var sub = [];
651
- for (var key in json) {
652
- if (json[key] === undefined)
653
- continue;
654
- const subsub = $mol_tree.fromJSON(json[key], baseUri);
655
- if (/^[^\n\t\\ ]+$/.test(key)) {
656
- var child = new $mol_tree({
657
- type: key,
658
- baseUri: baseUri,
659
- sub: [subsub],
660
- });
661
- }
662
- else {
663
- var child = new $mol_tree({
664
- value: key,
665
- baseUri: baseUri,
666
- sub: [subsub],
667
- });
668
- }
669
- sub.push(child);
670
- }
671
- return new $mol_tree({
672
- type: "*",
673
- sub: sub,
674
- baseUri: baseUri
675
- });
676
- }
677
- }
678
- get uri() {
679
- return this.baseUri + '#' + this.row + ':' + this.col;
680
- }
681
- toString(prefix = '') {
682
- var output = '';
683
- if (this.type.length) {
684
- if (!prefix.length) {
685
- prefix = "\t";
686
- }
687
- output += this.type;
688
- if (this.sub.length == 1) {
689
- return output + ' ' + this.sub[0].toString(prefix);
690
- }
691
- output += "\n";
692
- }
693
- else if (this.data.length || prefix.length) {
694
- output += "\\" + this.data + "\n";
695
- }
696
- for (var child of this.sub) {
697
- output += prefix;
698
- output += child.toString(prefix + "\t");
699
- }
700
- return output;
701
- }
702
- toJSON() {
703
- if (!this.type)
704
- return this.value;
705
- if (this.type === 'true')
706
- return true;
707
- if (this.type === 'false')
708
- return false;
709
- if (this.type === 'null')
710
- return null;
711
- if (this.type === '*') {
712
- var obj = {};
713
- for (var child of this.sub) {
714
- if (child.type === '-')
715
- continue;
716
- var key = child.type || child.clone({ sub: child.sub.slice(0, child.sub.length - 1) }).value;
717
- var val = child.sub[child.sub.length - 1].toJSON();
718
- if (val !== undefined)
719
- obj[key] = val;
720
- }
721
- return obj;
722
- }
723
- if (this.type === '/') {
724
- var res = [];
725
- this.sub.forEach(child => {
726
- if (child.type === '-')
727
- return;
728
- var val = child.toJSON();
729
- if (val !== undefined)
730
- res.push(val);
731
- });
732
- return res;
733
- }
734
- if (this.type === 'time') {
735
- return new Date(this.value);
736
- }
737
- const numb = Number(this.type);
738
- if (!Number.isNaN(numb) || this.type === 'NaN')
739
- return numb;
740
- throw new Error(`Unknown type (${this.type}) at ${this.uri}`);
741
- }
742
- get value() {
743
- var values = [];
744
- for (var child of this.sub) {
745
- if (child.type)
746
- continue;
747
- values.push(child.value);
748
- }
749
- return this.data + values.join("\n");
750
- }
751
- insert(value, ...path) {
752
- if (path.length === 0)
753
- return value;
754
- const type = path[0];
755
- if (typeof type === 'string') {
756
- let replaced = false;
757
- const sub = this.sub.map((item, index) => {
758
- if (item.type !== type)
759
- return item;
760
- replaced = true;
761
- return item.insert(value, ...path.slice(1));
762
- });
763
- if (!replaced)
764
- sub.push(new $mol_tree({ type }).insert(value, ...path.slice(1)));
765
- return this.clone({ sub });
766
- }
767
- else if (typeof type === 'number') {
768
- const sub = this.sub.slice();
769
- sub[type] = (sub[type] || new $mol_tree).insert(value, ...path.slice(1));
770
- return this.clone({ sub });
771
- }
772
- else {
773
- return this.clone({ sub: ((this.sub.length === 0) ? [new $mol_tree()] : this.sub).map(item => item.insert(value, ...path.slice(1))) });
774
- }
775
- }
776
- select(...path) {
777
- var next = [this];
778
- for (var type of path) {
779
- if (!next.length)
780
- break;
781
- var prev = next;
782
- next = [];
783
- for (var item of prev) {
784
- switch (typeof (type)) {
785
- case 'string':
786
- for (var child of item.sub) {
787
- if (!type || (child.type == type)) {
788
- next.push(child);
789
- }
790
- }
791
- break;
792
- case 'number':
793
- if (type < item.sub.length)
794
- next.push(item.sub[type]);
795
- break;
796
- default: next.push(...item.sub);
797
- }
798
- }
799
- }
800
- return new $mol_tree({ sub: next });
801
- }
802
- filter(path, value) {
803
- var sub = this.sub.filter(function (item) {
804
- var found = item.select(...path);
805
- if (value == null) {
806
- return Boolean(found.sub.length);
807
- }
808
- else {
809
- return found.sub.some(child => child.value == value);
810
- }
811
- });
812
- return new $mol_tree({ sub: sub });
813
- }
814
- transform(visit, stack = []) {
815
- const sub_stack = [this, ...stack];
816
- return visit(sub_stack, () => this.sub.map(node => node.transform(visit, sub_stack)).filter(n => n));
817
- }
818
- hack(context) {
819
- const sub = [].concat(...this.sub.map(child => {
820
- const handle = context[child.type] || context[''];
821
- if (!handle)
822
- $.$mol_fail(child.error('Handler not defined'));
823
- return handle(child, context);
824
- }));
825
- return this.clone({ sub });
826
- }
827
- error(message) {
828
- return new Error(`${message}:\n${this} ${this.baseUri}:${this.row}:${this.col}`);
829
- }
830
- }
831
- __decorate([
832
- $.$mol_deprecated('Use $mol_tree:hack')
833
- ], $mol_tree.prototype, "transform", null);
834
- $.$mol_tree = $mol_tree;
835
- })($ || ($ = {}));
836
- //tree.js.map
572
+ "use strict";
573
+ var $;
574
+ (function ($) {
575
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
576
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
577
+ return new $mol_tree2(String(json), '', [], span);
578
+ }
579
+ if (typeof json === 'string') {
580
+ return $mol_tree2.data(json, [], span);
581
+ }
582
+ if (Array.isArray(json)) {
583
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
584
+ return new $mol_tree2('/', '', sub, span);
585
+ }
586
+ if (json instanceof Date) {
587
+ return new $mol_tree2('', json.toISOString(), [], span);
588
+ }
589
+ if (typeof json.toJSON === 'function') {
590
+ return $mol_tree2_from_json(json.toJSON());
591
+ }
592
+ if (json instanceof Error) {
593
+ const { name, message, stack } = json;
594
+ json = { ...json, name, message, stack };
595
+ }
596
+ const sub = [];
597
+ for (var key in json) {
598
+ const val = json[key];
599
+ if (val === undefined)
600
+ continue;
601
+ const subsub = $mol_tree2_from_json(val, span);
602
+ if (/^[^\n\t\\ ]+$/.test(key)) {
603
+ sub.push(new $mol_tree2(key, '', [subsub], span));
604
+ }
605
+ else {
606
+ sub.push($mol_tree2.data(key, [subsub], span));
607
+ }
608
+ }
609
+ return new $mol_tree2('*', '', sub, span);
610
+ }
611
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
612
+ })($ || ($ = {}));
613
+ //mol/tree2/from/json/json.ts
837
614
  ;
838
- "use strict";
839
- var $;
840
- (function ($) {
841
- function $mol_log3_node_make(level, output, type, color) {
842
- return function $mol_log3_logger(event) {
843
- if (!event.time)
844
- event = Object.assign({ time: new Date().toISOString() }, event);
845
- const tree = this.$mol_tree.fromJSON(event).clone({ type });
846
- let str = tree.toString();
847
- if (process[output].isTTY) {
848
- str = $node.colorette[color + 'Bright'](str);
849
- }
850
- this.console[level](str);
851
- const self = this;
852
- return () => self.console.groupEnd();
853
- };
854
- }
855
- $.$mol_log3_node_make = $mol_log3_node_make;
856
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
857
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
858
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
859
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
860
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
861
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
862
- })($ || ($ = {}));
863
- //log3.node.js.map
615
+ "use strict";
616
+ var $;
617
+ (function ($) {
618
+ function $mol_tree2_js_to_text(js) {
619
+ function sequence(open, separator, close) {
620
+ return (input, belt) => [
621
+ ...open ? [input.data(open)] : [],
622
+ input.struct(separator && input.kids.length > 2 ? 'indent' : 'line', [].concat(...input.kids.map((kid, index) => [
623
+ kid.struct('line', [
624
+ ...kid.list([kid]).hack(belt),
625
+ ...(separator && index < input.kids.length - 1) ? [input.data(separator)] : [],
626
+ ]),
627
+ ]))),
628
+ ...close ? [input.data(close)] : [],
629
+ ];
630
+ }
631
+ function duplet(open, separator, close) {
632
+ return (input, belt) => [
633
+ ...open ? [input.data(open)] : [],
634
+ ...input.list(input.kids.slice(0, 1)).hack(belt),
635
+ ...(separator && input.kids.length > 1) ? [input.data(separator)] : [],
636
+ ...input.list(input.kids.slice(1, 2)).hack(belt),
637
+ ...close ? [input.data(close)] : [],
638
+ ];
639
+ }
640
+ function triplet(open, separator12, separator23, close) {
641
+ return (input, belt) => [
642
+ ...open ? [input.data(open)] : [],
643
+ ...input.list(input.kids.slice(0, 1)).hack(belt),
644
+ ...(separator12 && input.kids.length > 1) ? [input.data(separator12)] : [],
645
+ ...input.list(input.kids.slice(1, 2)).hack(belt),
646
+ ...(separator23 && input.kids.length > 2) ? [input.data(separator23)] : [],
647
+ ...input.list(input.kids.slice(2, 3)).hack(belt),
648
+ ...close ? [input.data(close)] : [],
649
+ ];
650
+ }
651
+ return js.list([js.struct('line', js.hack({
652
+ '+': sequence('+'),
653
+ '-': sequence('-'),
654
+ '!': sequence('!'),
655
+ '~': sequence('~'),
656
+ 'return': sequence('return '),
657
+ 'break': sequence('break '),
658
+ 'continue': sequence('continue '),
659
+ 'yield': sequence('yield '),
660
+ 'yield*': sequence('yield* '),
661
+ 'await': sequence('await '),
662
+ 'void': sequence('void '),
663
+ 'delete': sequence('delete '),
664
+ 'typeof': sequence('typeof '),
665
+ 'new': sequence('new '),
666
+ '...': sequence('...'),
667
+ '@++': sequence('', '', '++'),
668
+ '@--': sequence('', '', '--'),
669
+ '(in)': sequence('(', ' in ', ')'),
670
+ '(instanceof)': sequence('(', ' instanceof ', ')'),
671
+ '(+)': sequence('(', ' + ', ')'),
672
+ '(-)': sequence('(', ' - ', ')'),
673
+ '(*)': sequence('(', ' * ', ')'),
674
+ '(/)': sequence('(', ' / ', ')'),
675
+ '(%)': sequence('(', ' % ', ')'),
676
+ '(**)': sequence('(', ' ** ', ')'),
677
+ '(<)': sequence('(', ' < ', ')'),
678
+ '(<=)': sequence('(', ' <= ', ')'),
679
+ '(>)': sequence('(', ' > ', ')'),
680
+ '(>=)': sequence('(', ' >= ', ')'),
681
+ '(==)': sequence('(', ' == ', ')'),
682
+ '(!=)': sequence('(', ' != ', ')'),
683
+ '(===)': sequence('(', ' === ', ')'),
684
+ '(!==)': sequence('(', ' !== ', ')'),
685
+ '(<<)': sequence('(', ' << ', ')'),
686
+ '(>>)': sequence('(', ' >> ', ')'),
687
+ '(>>>)': sequence('(', ' >>> ', ')'),
688
+ '(&)': sequence('(', ' & ', ')'),
689
+ '(|)': sequence('(', ' | ', ')'),
690
+ '(^)': sequence('(', ' ^ ', ')'),
691
+ '(&&)': sequence('(', ' && ', ')'),
692
+ '(||)': sequence('(', ' || ', ')'),
693
+ '(,)': sequence('(', ', ', ')'),
694
+ '{;}': sequence('{', '; ', '}'),
695
+ ';': sequence('', ';', ''),
696
+ '[,]': sequence('[', ', ', ']'),
697
+ '{,}': sequence('{', ', ', '}'),
698
+ '()': sequence('(', '', ')'),
699
+ '{}': sequence('{', '', '}'),
700
+ '[]': (input, belt) => {
701
+ const first = input.kids[0];
702
+ if (first.type)
703
+ return sequence('[', '', ']')(input, belt);
704
+ else
705
+ return [input.data('.' + first.text())];
706
+ },
707
+ ':': (input, belt) => {
708
+ const first = input.kids[0];
709
+ if (first.type)
710
+ return duplet('[', ']: ')(input, belt);
711
+ else
712
+ return duplet('', ': ')(input, belt);
713
+ },
714
+ 'let': duplet('let ', ' = '),
715
+ 'const': duplet('const ', ' = '),
716
+ 'var': duplet('var ', ' = '),
717
+ '=': duplet('', ' = '),
718
+ '+=': duplet('', ' += '),
719
+ '-=': duplet('', ' -= '),
720
+ '*=': duplet('', ' *= '),
721
+ '/=': duplet('', ' /= '),
722
+ '%=': duplet('', ' %= '),
723
+ '**=': duplet('', ' **= '),
724
+ '<<=': duplet('', ' <<= '),
725
+ '>>=': duplet('', ' >>= '),
726
+ '>>>=': duplet('', ' >>>= '),
727
+ '&=': duplet('', ' &= '),
728
+ '|=': duplet('', ' |= '),
729
+ '^=': duplet('', ' ^= '),
730
+ '&&=': duplet('', ' &&= '),
731
+ '||=': duplet('', ' ||= '),
732
+ '=>': duplet('', ' => '),
733
+ 'async=>': duplet('async ', ' => '),
734
+ 'function': triplet('function '),
735
+ 'function*': triplet('function* '),
736
+ 'async': triplet('async function '),
737
+ 'async*': triplet('async function* '),
738
+ 'class': triplet('class ', ' '),
739
+ 'extends': sequence('extends ', '', ' '),
740
+ 'if': triplet('if', ' ', 'else'),
741
+ '?:': triplet('', ' ? ', ' : '),
742
+ '.': (input, belt) => {
743
+ const first = input.kids[0];
744
+ if (first.type)
745
+ return triplet('[', ']')(input, belt);
746
+ else
747
+ return [
748
+ input.data(first.text()),
749
+ ...input.list(input.kids.slice(1)).hack(belt),
750
+ ];
751
+ },
752
+ 'get': triplet('get [', ']'),
753
+ 'set': triplet('set [', ']'),
754
+ 'static': triplet('static [', ']'),
755
+ '/./': sequence(),
756
+ '.global': sequence('g'),
757
+ '.multiline': sequence('m'),
758
+ '.ignoreCase': sequence('i'),
759
+ '.source': (input, belt) => [
760
+ input.data('/'),
761
+ input.data(JSON.stringify(input.text()).slice(1, -1)),
762
+ input.data('/'),
763
+ ],
764
+ '``': (input, belt) => {
765
+ return [
766
+ input.data('`'),
767
+ ...[].concat(...input.kids.map(kid => {
768
+ if (kid.type) {
769
+ return [
770
+ kid.data('${'),
771
+ ...kid.list([kid]).hack(belt),
772
+ kid.data('}'),
773
+ ];
774
+ }
775
+ else {
776
+ return [
777
+ input.data(JSON.stringify(kid.text()).slice(1, -1)),
778
+ ];
779
+ }
780
+ })),
781
+ input.data('`'),
782
+ ];
783
+ },
784
+ '': (input, belt) => {
785
+ if (!input.type)
786
+ return [
787
+ input.data(JSON.stringify(input.text())),
788
+ ];
789
+ if (/^[\w$#][\w0-9$]*$/i.test(input.type))
790
+ return [
791
+ input.data(input.type),
792
+ ];
793
+ if (input.type === 'NaN' || !Number.isNaN(Number(input.type)))
794
+ return [
795
+ input.data(input.type)
796
+ ];
797
+ $mol_fail(new SyntaxError(`Wrong node type`));
798
+ },
799
+ }))]);
800
+ }
801
+ $.$mol_tree2_js_to_text = $mol_tree2_js_to_text;
802
+ })($ || ($ = {}));
803
+ //mol/tree2/js/to/text/text.ts
864
804
  ;
865
- "use strict";
866
- var $;
867
- (function ($) {
868
- function $mol_env() {
869
- return {};
870
- }
871
- $.$mol_env = $mol_env;
872
- })($ || ($ = {}));
873
- //env.js.map
805
+ "use strict";
806
+ var $;
807
+ (function ($) {
808
+ function $mol_tree2_span_imprint(tree) {
809
+ const sources = new Map();
810
+ const res = tree.clone(tree.hack({
811
+ '': (input, belt) => {
812
+ if (!sources.has(input.span.uri)) {
813
+ sources.set(input.span.uri, tree.struct(input.span.uri, [
814
+ tree.data(input.span.source)
815
+ ]));
816
+ }
817
+ return [
818
+ input.clone([
819
+ input.data(input.span.toString()),
820
+ ...input.hack(belt),
821
+ ]),
822
+ ];
823
+ },
824
+ }));
825
+ return tree.clone([
826
+ ...sources.values(),
827
+ res,
828
+ ]);
829
+ }
830
+ $.$mol_tree2_span_imprint = $mol_tree2_span_imprint;
831
+ })($ || ($ = {}));
832
+ //mol/tree2/span/imprint/imprint.ts
833
+ ;
834
+ "use strict";
835
+ var $;
836
+ (function ($) {
837
+ function $mol_tree2_span_reuse(tree) {
838
+ const sources = new Map();
839
+ return tree.clone(tree.hack({
840
+ '': (input, belt) => {
841
+ if (input.type) {
842
+ sources.set(input.type, input.kids[0].text());
843
+ return [];
844
+ }
845
+ return input.hack({
846
+ '': (input, belt) => {
847
+ const kids = input.list(input.kids.slice(1)).hack(belt);
848
+ const [_, uri, row, col, length] = /^(.*)#(\d+):(\d+)\/(\d+)$/.exec(input.kids[0].text());
849
+ const span = new $mol_span(uri, sources.get(uri), Number(row), Number(col), Number(length));
850
+ return [
851
+ new $mol_tree2(input.type, input.value, kids, span),
852
+ ];
853
+ },
854
+ });
855
+ },
856
+ }));
857
+ }
858
+ $.$mol_tree2_span_reuse = $mol_tree2_span_reuse;
859
+ })($ || ($ = {}));
860
+ //mol/tree2/span/reuse/reuse.ts
861
+ ;
862
+ "use strict";
863
+ var $;
864
+ (function ($) {
865
+ function $mol_tree2_text_to_string(text) {
866
+ let res = '';
867
+ function visit(text, prefix, inline) {
868
+ if (text.type === 'indent') {
869
+ if (inline)
870
+ res += '\n';
871
+ for (let kid of text.kids) {
872
+ visit(kid, prefix + '\t', false);
873
+ }
874
+ if (inline)
875
+ res += prefix;
876
+ }
877
+ else if (text.type === 'line') {
878
+ if (!inline)
879
+ res += prefix;
880
+ for (let kid of text.kids) {
881
+ visit(kid, prefix, true);
882
+ }
883
+ if (!inline)
884
+ res += '\n';
885
+ }
886
+ else {
887
+ if (!inline)
888
+ res += prefix;
889
+ res += text.text();
890
+ if (!inline)
891
+ res += '\n';
892
+ }
893
+ }
894
+ for (let kid of text.kids) {
895
+ visit(kid, '', false);
896
+ }
897
+ return res;
898
+ }
899
+ $.$mol_tree2_text_to_string = $mol_tree2_text_to_string;
900
+ })($ || ($ = {}));
901
+ //mol/tree2/text/to/string/string.ts
902
+ ;
903
+ "use strict";
904
+ var $;
905
+ (function ($) {
906
+ const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
907
+ function $mol_vlq_encode(val) {
908
+ const sign = val < 0 ? 1 : 0;
909
+ if (sign)
910
+ val = -val;
911
+ let index = sign | ((val & 0b1111) << 1);
912
+ val >>>= 4;
913
+ let res = '';
914
+ while (val) {
915
+ index |= 1 << 5;
916
+ res += alphabet[index];
917
+ if (!val)
918
+ break;
919
+ index = val & 0b11111;
920
+ val >>>= 5;
921
+ }
922
+ res += alphabet[index];
923
+ return res;
924
+ }
925
+ $.$mol_vlq_encode = $mol_vlq_encode;
926
+ })($ || ($ = {}));
927
+ //mol/vlq/vlq.ts
874
928
  ;
875
- "use strict";
876
- var $;
877
- (function ($) {
878
- $.$mol_env = function $mol_env() {
879
- return this.process.env;
880
- };
881
- })($ || ($ = {}));
882
- //env.node.js.map
929
+ "use strict";
930
+ var $;
931
+ (function ($) {
932
+ function $mol_tree2_text_to_sourcemap(tree) {
933
+ let col = 1;
934
+ let prev_span;
935
+ let prev_index = 0;
936
+ let prev_col = 1;
937
+ let mappings = '';
938
+ let line = [];
939
+ const file_indexes = new Map();
940
+ const file_sources = new Map();
941
+ function span2index(span) {
942
+ if (file_indexes.has(span.uri))
943
+ return file_indexes.get(span.uri);
944
+ const index = file_indexes.size;
945
+ file_indexes.set(span.uri, index);
946
+ file_sources.set(span.uri, span.source);
947
+ return index;
948
+ }
949
+ function next_line() {
950
+ if (!line.length)
951
+ return;
952
+ mappings += line.join(',') + ';';
953
+ line = [];
954
+ col = 1;
955
+ prev_col = 1;
956
+ }
957
+ function visit(text, prefix, inline) {
958
+ function indent() {
959
+ col += prefix;
960
+ }
961
+ if (inline && text.type === 'indent')
962
+ next_line();
963
+ if (prev_span !== text.span || col === 1) {
964
+ const index = span2index(text.span);
965
+ line.push($mol_vlq_encode(col - prev_col) +
966
+ $mol_vlq_encode(index - prev_index) +
967
+ $mol_vlq_encode(text.span.row - (prev_span?.row ?? 1)) +
968
+ $mol_vlq_encode(text.span.col - (prev_span?.col ?? 1)));
969
+ prev_col = col;
970
+ prev_span = text.span;
971
+ prev_index = index;
972
+ }
973
+ if (text.type === 'indent') {
974
+ for (let kid of text.kids) {
975
+ visit(kid, prefix + 1, false);
976
+ }
977
+ if (inline)
978
+ indent();
979
+ }
980
+ else if (text.type === 'line') {
981
+ if (!inline)
982
+ indent();
983
+ for (let kid of text.kids) {
984
+ visit(kid, prefix, true);
985
+ }
986
+ if (!inline)
987
+ next_line();
988
+ }
989
+ else {
990
+ if (!inline)
991
+ indent();
992
+ col += text.text().length;
993
+ if (!inline)
994
+ next_line();
995
+ }
996
+ }
997
+ for (let kid of tree.kids) {
998
+ visit(kid, 0, false);
999
+ }
1000
+ next_line();
1001
+ const map = {
1002
+ version: 3,
1003
+ sources: [...file_sources.keys()],
1004
+ sourcesContent: [...file_sources.values()],
1005
+ mappings,
1006
+ };
1007
+ return map;
1008
+ }
1009
+ $.$mol_tree2_text_to_sourcemap = $mol_tree2_text_to_sourcemap;
1010
+ })($ || ($ = {}));
1011
+ //mol/tree2/text/to/sourcemap/sourcemap.ts
883
1012
  ;
884
- "use strict";
885
- var $;
886
- (function ($) {
887
- function $mol_exec(dir, command, ...args) {
888
- let [app, ...args0] = command.split(' ');
889
- args = [...args0, ...args];
890
- this.$mol_log3_come({
891
- place: '$mol_exec',
892
- dir: $node.path.relative('', dir),
893
- message: 'Run',
894
- command: `${app} ${args.join(' ')}`,
895
- });
896
- var res = $node['child_process'].spawnSync(app, args, {
897
- cwd: $node.path.resolve(dir),
898
- shell: true,
899
- env: this.$mol_env(),
900
- });
901
- if (res.status || res.error)
902
- return $.$mol_fail(res.error || new Error(res.stderr.toString()));
903
- if (!res.stdout)
904
- res.stdout = Buffer.from([]);
905
- return res;
906
- }
907
- $.$mol_exec = $mol_exec;
908
- })($ || ($ = {}));
909
- //exec.node.js.map
1013
+ "use strict";
1014
+ var $;
1015
+ (function ($) {
1016
+ function $mol_tree2_text_to_string_mapped(text, type) {
1017
+ const code = this.$mol_tree2_text_to_string(text);
1018
+ const map = this.$mol_tree2_text_to_sourcemap(text);
1019
+ map.mappings = ';;' + map.mappings;
1020
+ let res = code;
1021
+ const map_uri = `data:application/json,${this.encodeURIComponent(JSON.stringify(map))}`;
1022
+ if (type === 'js')
1023
+ res += `\n//# sourceMappingURL=${map_uri}`;
1024
+ else
1025
+ res += `\n/*# sourceMappingURL=${map_uri} */`;
1026
+ return res;
1027
+ }
1028
+ $.$mol_tree2_text_to_string_mapped = $mol_tree2_text_to_string_mapped;
1029
+ function $mol_tree2_text_to_string_mapped_js(text) {
1030
+ return this.$mol_tree2_text_to_string_mapped(text, 'js');
1031
+ }
1032
+ $.$mol_tree2_text_to_string_mapped_js = $mol_tree2_text_to_string_mapped_js;
1033
+ function $mol_tree2_text_to_string_mapped_css(text) {
1034
+ return this.$mol_tree2_text_to_string_mapped(text, 'css');
1035
+ }
1036
+ $.$mol_tree2_text_to_string_mapped_css = $mol_tree2_text_to_string_mapped_css;
1037
+ })($ || ($ = {}));
1038
+ //mol/tree2/text/to/string/mapped/mapped.ts
910
1039
  ;
911
- "use strict";
912
- var $;
913
- (function ($) {
914
- class $mol_error_syntax extends SyntaxError {
915
- constructor(reason, line, span) {
916
- super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
917
- this.reason = reason;
918
- this.line = line;
919
- this.span = span;
920
- }
921
- }
922
- $.$mol_error_syntax = $mol_error_syntax;
923
- })($ || ($ = {}));
924
- //syntax.js.map
1040
+ "use strict";
1041
+ var $;
1042
+ (function ($) {
1043
+ function $mol_tree2_text_to_sourcemap_vis(text) {
1044
+ const code = this.$mol_tree2_text_to_string(text);
1045
+ const map = this.$mol_tree2_text_to_sourcemap(text);
1046
+ const uri = [
1047
+ 'https://sokra.github.io/source-map-visualization/#base64',
1048
+ btoa(code),
1049
+ btoa(JSON.stringify(map)),
1050
+ ...map.sourcesContent.map(btoa),
1051
+ ].join(',');
1052
+ return uri;
1053
+ }
1054
+ $.$mol_tree2_text_to_sourcemap_vis = $mol_tree2_text_to_sourcemap_vis;
1055
+ })($ || ($ = {}));
1056
+ //mol/tree2/text/to/sourcemap/vis/vis.ts
925
1057
  ;
926
- "use strict";
927
- var $;
928
- (function ($) {
929
- function $mol_tree2_from_string(str, uri = 'unknown') {
930
- const span = $.$mol_span.entire(uri, str);
931
- var root = $.$mol_tree2.list([], span);
932
- var stack = [root];
933
- var pos = 0, row = 0, min_indent = 0;
934
- while (str.length > pos) {
935
- var indent = 0;
936
- var line_start = pos;
937
- row++;
938
- while (str.length > pos && str[pos] == '\t') {
939
- indent++;
940
- pos++;
941
- }
942
- if (!root.kids.length) {
943
- min_indent = indent;
944
- }
945
- indent -= min_indent;
946
- if (indent < 0 || indent >= stack.length) {
947
- const sp = span.span(row, 1, pos - line_start);
948
- while (str.length > pos && str[pos] != '\n') {
949
- pos++;
950
- }
951
- if (indent < 0) {
952
- if (str.length > pos) {
953
- this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
954
- }
955
- }
956
- else {
957
- this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
958
- }
959
- }
960
- stack.length = indent + 1;
961
- var parent = stack[indent];
962
- while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
963
- var error_start = pos;
964
- while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
965
- pos++;
966
- }
967
- if (pos > error_start) {
968
- let line_end = str.indexOf('\n', pos);
969
- if (line_end === -1)
970
- line_end = str.length;
971
- const sp = span.span(row, error_start - line_start, pos - error_start + 1);
972
- this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
973
- }
974
- var type_start = pos;
975
- while (str.length > pos &&
976
- str[pos] != '\\' &&
977
- str[pos] != ' ' &&
978
- str[pos] != '\t' &&
979
- str[pos] != '\n') {
980
- pos++;
981
- }
982
- if (pos > type_start) {
983
- let next = new $.$mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
984
- const parent_kids = parent.kids;
985
- parent_kids.push(next);
986
- parent = next;
987
- }
988
- if (str.length > pos && str[pos] == ' ') {
989
- pos++;
990
- }
991
- }
992
- if (str.length > pos && str[pos] == '\\') {
993
- var data_start = pos;
994
- while (str.length > pos && str[pos] != '\n') {
995
- pos++;
996
- }
997
- let next = new $.$mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
998
- const parent_kids = parent.kids;
999
- parent_kids.push(next);
1000
- parent = next;
1001
- }
1002
- if (str.length === pos && stack.length > 0) {
1003
- const sp = span.span(row, pos - line_start + 1, 1);
1004
- this.$mol_fail(new this.$mol_error_syntax(`Undexpected EOF, LF required`, str.substring(line_start, str.length), sp));
1005
- }
1006
- stack.push(parent);
1007
- pos++;
1008
- }
1009
- return root;
1010
- }
1011
- $.$mol_tree2_from_string = $mol_tree2_from_string;
1012
- })($ || ($ = {}));
1013
- //string.js.map
1058
+ "use strict";
1059
+ var $;
1060
+ (function ($) {
1061
+ function $mol_tree2_xml_from_dom(dom) {
1062
+ switch (dom.nodeType) {
1063
+ case dom.DOCUMENT_NODE: {
1064
+ let kids = [];
1065
+ for (const kid of dom.childNodes) {
1066
+ kids.push($mol_tree2_xml_from_dom(kid));
1067
+ }
1068
+ return $mol_tree2.list(kids);
1069
+ }
1070
+ case dom.PROCESSING_INSTRUCTION_NODE: {
1071
+ return $mol_tree2.struct('?', [
1072
+ $mol_tree2.struct(dom.nodeName, dom.nodeValue.split(' ').map(chunk => {
1073
+ const [, name, value] = /^(.*?)(?:="(.*?)")?$/.exec(chunk);
1074
+ const kids = value ? [$mol_tree2.data(value)] : [];
1075
+ return $mol_tree2.struct(name, kids);
1076
+ }))
1077
+ ]);
1078
+ }
1079
+ case dom.DOCUMENT_TYPE_NODE: {
1080
+ const dom2 = dom;
1081
+ return $mol_tree2.struct('!', [
1082
+ $mol_tree2.struct('DOCTYPE', [
1083
+ $mol_tree2.struct(dom2.name)
1084
+ ])
1085
+ ]);
1086
+ }
1087
+ case dom.ELEMENT_NODE: {
1088
+ let kids = [];
1089
+ for (const attr of dom.attributes) {
1090
+ kids.push($mol_tree2.struct('@', [
1091
+ $mol_tree2.struct(attr.nodeName, [
1092
+ $mol_tree2.data(attr.nodeValue)
1093
+ ])
1094
+ ]));
1095
+ }
1096
+ for (const kid of dom.childNodes) {
1097
+ const k = $mol_tree2_xml_from_dom(kid);
1098
+ if (k.type || k.value)
1099
+ kids.push(k);
1100
+ }
1101
+ return $mol_tree2.struct(dom.nodeName, kids);
1102
+ }
1103
+ case dom.COMMENT_NODE: {
1104
+ return $mol_tree2.struct('--', [
1105
+ $mol_tree2.data(dom.nodeValue)
1106
+ ]);
1107
+ }
1108
+ case dom.TEXT_NODE: {
1109
+ if (!dom.nodeValue.trim())
1110
+ return $mol_tree2.list([]);
1111
+ return $mol_tree2.data(dom.nodeValue.replace(/\s+/g, ' '));
1112
+ }
1113
+ }
1114
+ return $mol_fail(new Error(`Unsupported node ${dom.nodeName}`));
1115
+ }
1116
+ $.$mol_tree2_xml_from_dom = $mol_tree2_xml_from_dom;
1117
+ })($ || ($ = {}));
1118
+ //mol/tree2/xml/from/dom/dom.ts
1014
1119
  ;
1015
- "use strict";
1016
- var $;
1017
- (function ($) {
1018
- function $mol_tree2_to_string(tree) {
1019
- let output = [];
1020
- function dump(tree, prefix = '') {
1021
- if (tree.type.length) {
1022
- if (!prefix.length) {
1023
- prefix = "\t";
1024
- }
1025
- output.push(tree.type);
1026
- if (tree.kids.length == 1) {
1027
- output.push(' ');
1028
- dump(tree.kids[0], prefix);
1029
- return;
1030
- }
1031
- output.push("\n");
1032
- }
1033
- else if (tree.value.length || prefix.length) {
1034
- output.push("\\" + tree.value + "\n");
1035
- }
1036
- for (const kid of tree.kids) {
1037
- output.push(prefix);
1038
- dump(kid, prefix + "\t");
1039
- }
1040
- }
1041
- dump(tree);
1042
- return output.join('');
1043
- }
1044
- $.$mol_tree2_to_string = $mol_tree2_to_string;
1045
- })($ || ($ = {}));
1046
- //string.js.map
1120
+ "use strict";
1121
+ var $;
1122
+ (function ($) {
1123
+ const mapping = {
1124
+ '<': '&lt;',
1125
+ '>': '&gt;',
1126
+ '"': '&quot;',
1127
+ '&': '&amp;',
1128
+ };
1129
+ function $mol_html_encode(text) {
1130
+ return text.replace(/[&<">]/gi, str => mapping[str]);
1131
+ }
1132
+ $.$mol_html_encode = $mol_html_encode;
1133
+ })($ || ($ = {}));
1134
+ //mol/html/encode/encode.ts
1135
+ ;
1136
+ "use strict";
1137
+ var $;
1138
+ (function ($) {
1139
+ function attrs_belt(separator) {
1140
+ return {
1141
+ '': (input) => [
1142
+ input.data(' '),
1143
+ input.data($mol_html_encode(input.type)),
1144
+ ...input.value ? [
1145
+ input.data('"'),
1146
+ input.data($mol_html_encode(input.value)),
1147
+ input.data('"'),
1148
+ ] : [],
1149
+ ...input.hack({
1150
+ '': (input) => {
1151
+ if (!input.type)
1152
+ return [
1153
+ input.data(separator),
1154
+ input.data('"'),
1155
+ input.data($mol_html_encode(input.text())),
1156
+ input.data('"'),
1157
+ ];
1158
+ $mol_fail(new SyntaxError('Wrong attribute value'));
1159
+ },
1160
+ }),
1161
+ ],
1162
+ };
1163
+ }
1164
+ function $mol_tree2_xml_to_text(xml) {
1165
+ return xml.list(xml.hack({
1166
+ '@': (input, belt) => [],
1167
+ '--': (input, belt) => [
1168
+ xml.struct('line', [
1169
+ input.data('<!-- '),
1170
+ ...input.hack(belt),
1171
+ input.data(' -->'),
1172
+ ]),
1173
+ ],
1174
+ '?': (input, belt) => [
1175
+ xml.struct('line', [
1176
+ input.data('<?'),
1177
+ input.kids[0].data(input.kids[0].type),
1178
+ ...input.kids[0].hack(attrs_belt('=')),
1179
+ input.data('?>'),
1180
+ ]),
1181
+ ],
1182
+ '!': (input, belt) => [
1183
+ xml.struct('line', [
1184
+ input.data('<!'),
1185
+ input.kids[0].data(input.kids[0].type),
1186
+ ...input.kids[0].hack(attrs_belt(' ')),
1187
+ input.data('>'),
1188
+ ]),
1189
+ ],
1190
+ '': (input, belt) => {
1191
+ if (!input.type)
1192
+ return [
1193
+ input.data($mol_html_encode(input.text())),
1194
+ ];
1195
+ const attrs = input.select('@', null).hack(attrs_belt('='));
1196
+ const content = input.hack(belt);
1197
+ return [
1198
+ input.struct('line', [
1199
+ input.data(`<`),
1200
+ input.data(input.type),
1201
+ ...attrs,
1202
+ ...content.length ? [
1203
+ input.data(`>`),
1204
+ input.struct('indent', content),
1205
+ input.data(`</`),
1206
+ input.data(input.type),
1207
+ input.data(`>`),
1208
+ ] : [
1209
+ input.data(` />`),
1210
+ ]
1211
+ ]),
1212
+ ];
1213
+ },
1214
+ }));
1215
+ }
1216
+ $.$mol_tree2_xml_to_text = $mol_tree2_xml_to_text;
1217
+ })($ || ($ = {}));
1218
+ //mol/tree2/xml/to/text/text.ts
1047
1219
 
1048
1220
  //# sourceMappingURL=node.js.map