efront 4.34.1 → 4.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/coms/basic/Matrix.js +3 -1
  2. package/coms/basic/color.js +258 -78
  3. package/coms/basic/color_test.js +23 -2
  4. package/coms/basic/crc.js +6 -2
  5. package/coms/basic/data.js +3 -3
  6. package/coms/basic/decodeASN1.js +2 -2
  7. package/coms/basic/math.js +321 -0
  8. package/coms/basic/math.md +265 -0
  9. package/coms/basic/math_test.xht +56 -0
  10. package/coms/basic/pinyin.js +40 -0
  11. package/coms/basic/pinyin_test.js +40 -0
  12. package/coms/basic/wait.js +1 -1
  13. package/coms/basic_/JSON.js +24 -4
  14. package/coms/compile/Html.js +1 -0
  15. package/coms/compile/Javascript.js +14 -0
  16. package/coms/compile/Javascript_test.js +4 -3
  17. package/coms/compile/Program.js +82 -45
  18. package/coms/compile/autoenum.js +498 -138
  19. package/coms/compile/autoenum_test.js +70 -4
  20. package/coms/compile/autoeval.js +616 -18
  21. package/coms/compile/autoeval_test.js +55 -2
  22. package/coms/compile/common.js +27 -15
  23. package/coms/compile/common_test.js +12 -2
  24. package/coms/compile/downLevel.js +60 -7
  25. package/coms/compile/downLevel_test.js +22 -8
  26. package/coms/compile/powermap.js +2 -2
  27. package/coms/compile/rescan.js +2 -2
  28. package/coms/compile/scanner2.js +25 -1
  29. package/coms/compile/translate.js +18 -7
  30. package/coms/compile/unstruct.js +44 -2
  31. package/coms/compile/unstruct_test.js +14 -9
  32. package/coms/compile//347/256/227/345/274/217.js +276 -0
  33. package/coms/compile//347/256/227/345/274/217_test.js +26 -0
  34. package/coms/compile//347/264/240/351/246/250.js +60 -23
  35. package/coms/compile//347/264/240/351/246/250_test.js +8 -3
  36. package/coms/docs/markdown.js +4 -0
  37. package/coms/frame/ChatRTC.js +60 -18
  38. package/coms/frame/chat-rtc.xht +20 -18
  39. package/coms/frame/chat.js +38 -21
  40. package/coms/frame/chat.less +8 -3
  41. package/coms/reptile/colors.js +1 -0
  42. package/coms/zimoli/prompt.js +12 -2
  43. package/coms/zimoli/render.js +0 -1
  44. package/coms//350/214/250/350/217/260//344/270/212/350/211/262.xht +4 -0
  45. package/coms//350/214/250/350/217/260//346/240/207/347/255/276/345/214/226.js +14 -4
  46. package/package.json +1 -1
  47. package/public/efront.js +1 -1
  48. package/public//346/226/207/344/273/266/347/263/273/347/273/237//344/270/273/351/241/265.jsp +2 -2
@@ -1,5 +1,46 @@
1
- var { skipAssignment, snapSentenceHead, snapExpressFoot, pickAssignment, EXPRESS, SPACE, SCOPED, QUOTED, VALUE, STRAP, STAMP, number_reg, createString } = require("./common");
1
+ var {
2
+ skipAssignment,
3
+ snapSentenceHead,
4
+ snapAssignmentHead,
5
+ skipSentenceQueue,
6
+ snapExpressFoot,
7
+ pickArgument,
8
+ EXPRESS,
9
+ PROPERTY,
10
+ SPACE,
11
+ SCOPED,
12
+ QUOTED,
13
+ VALUE,
14
+ STRAP,
15
+ STAMP,
16
+ LABEL,
17
+ number_reg,
18
+ createString
19
+ } = require("./common");
2
20
  var strings = require("../basic/strings");
21
+ var getSimpleQuotedKey = function (t) {
22
+ if (!t.length) if (/[\.\[\]]|^#/.test(t.text)) {
23
+ return `[${t.text}]`;
24
+ }
25
+ else {
26
+ return "." + strings.decode(t.text);
27
+ }
28
+ return "[*]";
29
+ }
30
+ var getSimpleProperty = function (o) {
31
+ var t = o.last;
32
+ if (!t) throw new Error(i18n`代码结构错误`);
33
+ var p = t.prev;
34
+ if (p && (p.type !== STAMP || p.text !== ",")) return ["[*]"];
35
+ switch (t.type) {
36
+ case QUOTED: return getSimpleQuotedKey(t);
37
+ case VALUE:
38
+ if (t.isdigit) return `[${t.text}]`;
39
+ return "[*]";
40
+ }
41
+ return "[*]";
42
+ }
43
+
3
44
 
4
45
  var createRefId = function (o) {
5
46
  var ids = [], refs = [];
@@ -8,22 +49,7 @@ var createRefId = function (o) {
8
49
  while (o) {
9
50
  if (o.type === SCOPED) {
10
51
  if (o.entry !== '[') break;
11
- var t = o.last;
12
- if (!t) throw new Error(i18n`格式错误`);
13
- if (t.type === QUOTED) {
14
- if (!t.length) {
15
- if (/\.|^#/.test(t.text)) {
16
- ids.push(`[${t.text}]`);
17
- }
18
- else {
19
- ids.push(strings.decode(t.text));
20
- }
21
- }
22
- else {
23
- ids.push("[*]");
24
- break;
25
- }
26
- }
52
+ ids.push(getSimpleProperty(o))
27
53
  }
28
54
  else if (o.type === EXPRESS) {
29
55
  var t = o.text.replace(/^\.\.\.|\.\.\.$/g, "").replace(/^[^\.\[]+/, '');
@@ -57,19 +83,64 @@ var createRefId = function (o) {
57
83
  }
58
84
  var ignore = Symbol("ignore");
59
85
  var mapkey = null;
60
- var maplist = function (u) {
86
+ var patchFnFromProperty = function (o) {
87
+ var kpath = [];
88
+ var origin = o;
89
+ if (!o.queue.isObject) return;
90
+ while (o?.queue?.kind) {
91
+ if (o.type & (EXPRESS | PROPERTY)) {
92
+ if (o.short) {
93
+ kpath.push(o.text);
94
+ o = o.queue;
95
+ continue;
96
+ }
97
+ }
98
+ var p = o.prev;
99
+ if (!p) return;
100
+ if (p.type & (STAMP | STRAP)) {
101
+ if (/^(\:|as)$/.test(p.text)) p = p.prev;
102
+ else return;
103
+ }
104
+ if (!p) return;
105
+ if (p.type === PROPERTY) {//不处理字符串属性
106
+ kpath.push(o.text);
107
+ o = o.queue;
108
+ if (o.entry !== '{') return;
109
+ continue;
110
+ }
111
+ return;
112
+ }
113
+ if (!o || !o.equal || o.next !== o.equal) return;
114
+ var next = skipAssignment(o.equal);
115
+ var obj = o.equal.next;
116
+ if (obj.next !== next) return;
117
+ obj = outObjects[obj.text];
118
+ if (!obj) return;
119
+ var next = o.euqal;
120
+ while (kpath.length) {
121
+ var k = kpath.pop();
122
+ if (k in obj) obj = obj[k];
123
+ if (obj == null) return;
124
+ }
125
+ origin.fnq = o;
126
+ origin.fn = obj;
127
+ }
128
+ var maplist = function (oused) {
61
129
  var map = Object.create(null);
62
- for (var o of u) {
130
+ for (var o of oused) {
131
+
63
132
  if (o[mapkey]) continue;
64
133
  o[mapkey] = true;
65
134
  var r = createRefId(o);
135
+ if (/\[\*\]/.test(r)) continue;
66
136
  if (!map[r]) {
67
137
  map[r] = [];
68
138
  map[r].wcount = 0;
69
- map[r].ccount = 0;
70
139
  }
71
140
  var m = map[r];
72
- if (!o.equal && o.kind) m.unshift(o);
141
+ if (enumtype & REFTYPE && o.kind) {
142
+ m.unshift(o);
143
+ }
73
144
  else m.push(o);
74
145
  if (o.equal || o.kind) {
75
146
  if (enumtype & REFTYPE) {
@@ -79,20 +150,24 @@ var maplist = function (u) {
79
150
  o.typeref = typeref;
80
151
  }
81
152
  if (typeref) {
82
- if (m.typeref !== typeref) {
83
- m.typeref = typeref;
84
- m.wcount++;
85
- }
153
+ m.typeref = typeref;
154
+ m.wcount++;
86
155
  }
87
- else if (m.typeref) {
88
- var n = o.next;
89
- o[ignore] = true;
90
- if (n.type === STAMP && /^(\+\+|\-\-)$/.test(n.text)) continue;
156
+ else {
157
+ var n = o.equal;
158
+ if (n?.type !== STAMP) continue;
159
+ if (n?.type === STAMP && /^(\+\+|\-\-)$/.test(n.text)) {
160
+ o[ignore] = true;
161
+ continue;
162
+ }
91
163
  if (/^[\+\-]\=$/.test(n.text)) {
92
164
  var nn = n.next;
93
- if (nn && snapExpressFoot(nn) == nn && nn.isdigit && (nn.text & 0x1ff) === +nn.text) continue;
165
+ if (nn && snapExpressFoot(nn) == nn && nn.isdigit && (nn.text & 0x1ff) === +nn.text) {
166
+ if (m.typeref === 'uint') o[ignore] = true;
167
+ continue;
168
+ }
94
169
  }
95
- else if (!n || !/[^=!]?=$/.test(n.text)) continue;
170
+ else if (!/[^=!]?=$/.test(n.text)) continue;
96
171
  o[ignore] = false;
97
172
  m.wcount++;
98
173
  }
@@ -106,7 +181,10 @@ var maplist = function (u) {
106
181
  }
107
182
  else if (enumtype & REFMOVE) m.wcount++;
108
183
  }
109
- else if (enumtype & REFMOVE) m.wcount++;
184
+ else if (enumtype & REFMOVE) {
185
+ m.wcount++;
186
+ if (o.kind !== 'argument') patchFnFromProperty(o);
187
+ }
110
188
  }
111
189
  else {
112
190
  if (o.equal) m.wcount++;
@@ -115,7 +193,6 @@ var maplist = function (u) {
115
193
  else if (enumtype & REFSTRC) {
116
194
  if (o.enumref && o.enumref !== m.enumref) m.wcount++, m.enumref = o.enumref;
117
195
  }
118
- if (o.called) m.ccount++;
119
196
  }
120
197
  return map;
121
198
  }
@@ -136,14 +213,101 @@ function removeRefs(o) {
136
213
  o.next = r.next;
137
214
  if (o.next) o.next.prev = o;
138
215
  }
139
-
140
- function inCondition(o) {
216
+ function getFirstBreak(o, labels = []) {
217
+ while (o.type === LABEL) {
218
+ labels.push(o.text.replace(/\:$/, ''));
219
+ o = o.next;
220
+ }
221
+ if (o.type === STRAP && /^(for|while|do|switch)$/.test(o.text)) {
222
+ labels.push("break");
223
+ o = o.next;
224
+ }
225
+ if (o.type === STRAP) o = o.next;
226
+ if (o.type === SCOPED && o.entry === '(') o = o.next;
227
+ while (o.type === LABEL) {
228
+ labels.push(o.text.replace(/\:$/, ''));
229
+ o = o.next;
230
+ }
231
+ if (o.type !== SCOPED || o.entry !== "{") return;
232
+ var m = o.first;
233
+ while (m) switch (m.type) {
234
+ case SCOPED:
235
+ var h = snapSentenceHead(m);
236
+ var fb = getFirstBreak(h, labels.concat("{"));
237
+ if (fb) return fb;
238
+ m = m.next;
239
+ continue;
240
+ case STRAP:
241
+ if (m.type === STRAP && m.text === 'break') {
242
+ if (!m.isend) m = m.next;
243
+ var n = m.text;
244
+ var i = labels.lastIndexOf(n);
245
+ if (i >= 0) {
246
+ i = labels.lastIndexOf("{", i);
247
+ }
248
+ if (i < 0) {
249
+ return m.start;
250
+ }
251
+ }
252
+ m = m.next;
253
+ continue;
254
+ default: m = m.next;
255
+ }
256
+ }
257
+ function getConditionBlock(q, s) {
258
+ do {
259
+ var o = snapSentenceHead(q);
260
+ var p = o.prev;
261
+ if (p) {
262
+ if (p.type === SCOPED && p.entry === '(') {
263
+ p = p.prev;
264
+ if (p.type === STRAP && /^(if|while|with|for|switch)$/.test(p.text)) {
265
+ return [q, q.end];
266
+ }
267
+ }
268
+ if (p.type === STRAP && p.text === 'else') {
269
+ return [q, q.end];
270
+ }
271
+ }
272
+ if (o.type === STRAP) {
273
+ if (/^(if|while|with|for)$/.test(o.text)) return [q, q.end];
274
+ if (o.text === 'switch') {
275
+ var m = s;
276
+ while (o) {
277
+ if (m.type === STRAP) {
278
+ if (/^(case|default)$/.test(m.text)) {
279
+ return [q, m.start];
280
+ }
281
+ }
282
+ }
283
+ return [q, q.end];
284
+ }
285
+ }
286
+ if (o.type === LABEL) a: {
287
+ var fb = getFirstBreak(o);
288
+ var m = q.first;
289
+ while (m) {
290
+ if (m.start > fb) return [q, q.end];
291
+ if (m === s) break a;
292
+ m = m.next;
293
+ }
294
+ }
295
+ s = q;
296
+ q = q.queue;
297
+ } while (q);
298
+ return [o, o.end];
299
+ }
300
+ function preCondition(o) {
141
301
  // 只检查一级
142
302
  var incondition = false;
143
303
  while (o && o.prev) {
144
304
  o = snapSentenceHead(o);
145
305
  var p = o.prev;
146
306
  if (!p) break;
307
+ if (p.type === STRAP) {
308
+ incondition = p.text === 'else';
309
+ break;
310
+ }
147
311
  if (p.type === SCOPED) {
148
312
  if (p.entry !== "(") break;
149
313
  if (!p.prev) break;
@@ -155,11 +319,12 @@ function inCondition(o) {
155
319
  }
156
320
  if (/^(?:while)$/.test(pp.text)) {
157
321
  var ppp = pp.prev;
158
- if (!ppp || !ppp.prev) {
322
+ if (!ppp || !ppp.prev || ppp.type !== SCOPED || ppp.entry !== '{') {
159
323
  incondition = true;
160
324
  break;
161
325
  }
162
326
  var pppp = ppp.prev;
327
+ while (pppp?.type === LABEL) pppp = pppp.prev;
163
328
  if (pppp.type === STRAP && pppp.text === "do") break;
164
329
  incondition = true;
165
330
  break;
@@ -167,132 +332,283 @@ function inCondition(o) {
167
332
  }
168
333
  break;
169
334
  }
170
- if (p.type === STAMP) {
171
- if (p.text === ";") break;
172
- if (/^[\?\:]$/i.test(p.text)) {
173
- incondition = true;
335
+ if (p.type === STAMP) switch (p.text) {
336
+ case ";": break;
337
+ case "?": incondition = true; break;
338
+ case ":":
339
+ if (p.isExpress) incondition = true;
340
+ else incondition = ":";
174
341
  break;
175
- }
176
- o = p.prev;
177
- continue;
342
+ case "=>": incondition = true; break;
343
+ default:
344
+ o = p.prev;
345
+ continue;
178
346
  }
179
347
  break;
180
348
  }
181
349
  return incondition;
350
+ }
182
351
 
352
+ function inOperatorLeft(q) {
353
+ if (!q.isObject) return false;
354
+ do {
355
+ if (q.kind) return true;
356
+ var n = q.next;
357
+ if (n?.type === STAMP && !/[,;]/.test(n.text)) {
358
+ return true;
359
+ }
360
+ q = q.queue;
361
+ } while (q);
362
+ return false;
183
363
  }
184
- var noVarOutOfFor = function (os, qq, sb, su) {
185
- if (qq === sb) return true;
186
- if (enumtype & REFMOVE) return false;
187
- var [o] = os;
188
- var us = su[o.tack];
189
- if (!us) return false;
190
- var otext = o.text;
191
- var c = 0;
192
- for (var u of us) {
193
- if (u.text === otext) {
194
- c++;
364
+ function getEnumRange(o, scoped) {
365
+ var q = o.queue, oe = Infinity;
366
+ if (inOperatorLeft(q)) return;
367
+ if (q !== scoped.body) {
368
+ if (q.entry === '(') {
369
+ var qp = q.prev;
370
+ if (qp?.type === EXPRESS) qp = qp.prev;
371
+ if (qp && qp.type === STRAP && qp.text === "await") qp = qp.prev;
372
+ if (qp && qp.type === STRAP && qp.text === 'for') {
373
+ var f = q.first;
374
+ var fc = 0;
375
+ while (f && f !== o) {
376
+ if (f.type === STAMP && f.text === ";") {
377
+ fc++;
378
+ if (fc > 1) return;
379
+ }
380
+ f = f.next;
381
+ }
382
+ [q, oe] = getConditionBlock(q.queue, q);
383
+ }
384
+ else if (q === scoped.head) return;
385
+ else[q, oe] = getConditionBlock(q, o);
195
386
  }
387
+ else[q, oe] = getConditionBlock(q, o);
196
388
  }
197
- return c === os.length;
198
- };
199
- function enumref(refitem, scoped) {
200
- if (enumtype === REFMOVE) {
201
- var c = 0;
202
- for (var rk in refitem) {
203
- c++;
204
- var a = refitem[rk];
205
- if (a.ccount > 0) return;
206
- }
207
- var a = refitem[""];
208
- if (a && c > 1) {
209
- if (a.wcount < a.length) return;
389
+ var pc = preCondition(o);
390
+ if (pc) {
391
+ var e = o;
392
+ if (pc === ':') while (e) {
393
+ if (e.type === STRAP && /^(case|default)$/.test(e.text)) break;
394
+ e = e.next;
210
395
  }
396
+ else e = skipSentenceQueue(o);
397
+ q = o.queue;
398
+ if (e) oe = e.end;
399
+ else oe = q.end;
211
400
  }
401
+ return [q, oe];
402
+ }
403
+ function enumequal(refitem, scoped) {
212
404
  for (var rk in refitem) {
213
405
  var os = refitem[rk];
214
- if (os.wcount !== 1 || os.length < 2) continue;
215
- var eq = null, em = null, tp = null;
406
+ var wcount = os.wcount;
407
+ if (wcount < 1 || os.length <= wcount) continue;
408
+ var eq = null;
409
+ var cq = null, oe = Infinity;
216
410
  loop: for (var o of os) {
217
- if (o.equal && !o[ignore]) {
218
- if (o.equal.text !== '=') break;
219
- if (o.queue.kind) break;
220
- var q = o.queue;
221
- if (q !== scoped.body) {
222
- if (q.entry === '(' && noVarOutOfFor(os, q.queue, scoped.body, scoped.used)) {
223
- var qp = q.prev;
224
- if (qp?.type === EXPRESS) qp = qp.prev;
225
- if (qp && qp.type === STRAP && qp.text === "await") qp = qp.prev;
226
- if (qp && qp.type === STRAP && qp.text === 'for') {
227
- var f = q.first;
228
- var fc = 0;
229
- while (f && f !== o) {
230
- if (f.type === STAMP && f.text === ";") {
231
- fc++;
232
- if (fc > 1) break loop;
233
- }
234
- f = f.next;
235
- }
236
- }
237
- }
238
- else break;
411
+ if (o[ignore]) {
412
+ if (REFTYPE & enumtype) {
413
+ o.typeref = eq;
239
414
  }
240
- if (inCondition(o)) break;
241
- if (enumtype & REFTYPE) {
242
- if (o.typeref) {
243
- tp = o.typeref;
244
- if (isObject(tp)) tp = tp.typeref;
245
- continue;
246
- }
415
+ continue;
416
+ }
417
+ if (
418
+ eq === null || o.equal || o.fn !== undefined
419
+ ) {
420
+ if (!o.equal && o.fn === undefined) continue;
421
+ eq = null;
422
+ oe = Infinity;
423
+ cq = null;
424
+ if (!wcount) break;
425
+ if (o.fn === undefined && o.equal.text !== "=") {
426
+ continue;
247
427
  }
248
- if (enumtype & REFSTRC) {
249
- if (o.enumref) {
250
- em = o.enumref;
251
- continue;
252
- }
428
+ wcount--;
429
+ if (wcount > 0) continue;
430
+ if (o.fn !== undefined) {
431
+ var range = getEnumRange(o.fnq, scoped);
432
+ if (!range) continue;
433
+ [cq, oe] = range;
434
+ eq = o;
435
+ continue;
436
+ }
437
+ var range = getEnumRange(o, scoped);
438
+ if (!range) continue;
439
+ [cq, oe] = range;
440
+ o = o.equal.next;
441
+ var n = skipAssignment(o);
442
+ if (!o || n !== o.next) break loop;
443
+ if (o.type === VALUE && o.isdigit) {
444
+ eq = o;
445
+ }
446
+ else if (o.type === EXPRESS && o.tack in outObjects) {
447
+ eq = o;
448
+ var k = o.text.slice(o.tack.length + 1);
449
+ o.fn = outObjects[o.tack][k];
253
450
  }
254
- if (enumtype & REFMOVE) {
255
- o = o.equal.next;
256
- var n = skipAssignment(o);
257
- if (!o || n !== o.next) break loop;
258
- if (o.type === VALUE && o.isdigit) eq = o;
451
+ continue;
452
+ }
453
+ if (o.queue !== cq) {
454
+ var oq = o.queue;
455
+ while (oq && oq !== cq) oq = oq.queue;
456
+ if (!oq) {
457
+ eq = null;
458
+ continue;
259
459
  }
260
460
  }
261
- else if (o.kind) {
262
- if (enumtype & REFTYPE) {
263
- if (o.typeref) {
264
- tp = o.typeref;
265
- if (isObject(tp)) tp = tp.typeref;
266
- continue;
461
+ if (o.start > oe) {
462
+ eq = null;
463
+ continue;
464
+ }
465
+ if (!eq) continue;
466
+ if (o.short) continue;
467
+ // var 替换前 = createString(pickAssignment(o));
468
+ if (eq.isdigit) {
469
+ o.type = eq.type;
470
+ o.isdigit = true;
471
+ o.text = eq.text;
472
+ }
473
+ else if (eq.fn !== undefined) {
474
+ o.fn = eq.fn;
475
+ }
476
+ // var 替换后 = createString(pickAssignment(o));
477
+ removeRefs(o);
478
+ }
479
+ }
480
+ }
481
+ function enummark(refitem, scoped) {
482
+ var rest = [];
483
+ for (var rk in refitem) {
484
+ var os = refitem[rk];
485
+ var wcount = os.wcount;
486
+ if (wcount < 1 || os.length <= wcount) return;
487
+ var eq = null;
488
+ var cq = null, oe = Infinity;
489
+ loop: for (var o of os) {
490
+ if (o[ignore]) {
491
+ o.typeref = eq;
492
+ continue;
493
+ }
494
+ if (eq === null || o.equal) {
495
+ if (!o.equal && !o.kind) continue;
496
+ if (!wcount) break;
497
+ var _eq = o.typeref;
498
+ if (!_eq && o.equal && o.equal === o.next) {
499
+ var n = o.equal.next;
500
+ if (n.type === STAMP && /^(\+\+|\-\-)$/.test(n.text)) {
501
+ n = n.next;
267
502
  }
503
+ if (skipAssignment(n) === n.next) {
504
+ _eq = n;
505
+ }
506
+ }
507
+ if (isObject(_eq)) {
508
+ if (_eq.typeref) _eq = _eq.typeref;
268
509
  }
510
+ if (eq === _eq) {
511
+ var oq = o.queue;
512
+ while (oq && oq !== cq) oq = oq.queue;
513
+ if (oq) continue;
514
+ }
515
+ eq = null;
516
+ oe = Infinity;
517
+ cq = null;
518
+ if (o.equal && o.equal.text !== "=") {
519
+ continue;
520
+ }
521
+ wcount--;
522
+
523
+ var range = getEnumRange(o, scoped);
524
+ if (!range) {
525
+ eq = null;
526
+ continue;
527
+ }
528
+ [cq, oe] = range;
529
+ eq = _eq;
530
+ continue;
269
531
  }
270
- else if (o.enumref) {
271
- if (enumtype & REFSTRC) {
272
- em = o.enumref;
532
+ if (o.queue !== cq) {
533
+ var oq = o.queue;
534
+ while (oq && oq !== cq) oq = oq.queue;
535
+ if (!oq) {
536
+ eq = null;
273
537
  continue;
274
538
  }
275
539
  }
540
+ if (o.start > oe) {
541
+ eq = null;
542
+ continue;
543
+ }
544
+
545
+ if (o.kind) {
546
+ if (o.typeref) {
547
+ eq = o.typeref;
548
+ if (isObject(eq)) eq = eq.typeref;
549
+ }
550
+ }
276
551
  else {
277
- if (enumtype & REFTYPE) {
278
- if (tp) {
279
- o.typeref = tp;
280
- continue;
281
- }
552
+ if (eq) o.typeref = eq;
553
+ }
554
+ }
555
+ }
556
+ }
557
+ function enumstruct(refitem, scoped) {
558
+ for (var rk in refitem) {
559
+ var os = refitem[rk];
560
+ var eq = null;
561
+ var qs = [], cq = null, oe = Infinity;
562
+ loop: for (var o of os) {
563
+ if (eq === null || o.equal || o.kind) a: {
564
+ if (o.enumref) {
565
+ eq = o.enumref;
566
+ cq = o.queue;
567
+ qs.push([cq, eq, Infinity]);
568
+ continue;
282
569
  }
283
- if (enumtype & REFSTRC) {
284
- if (em) {
285
- o.enumref = em;
286
- continue;
570
+ if (!o.equal) break a;
571
+ if (o.equal.text !== "=") break a;
572
+ var range = getEnumRange(o, scoped);
573
+ if (!range) break a;
574
+ var o1 = o.equal.next;
575
+ var n = skipAssignment(o1);
576
+ if (!o1 || n !== o1.next) break a;
577
+ if (o1.enumref) {
578
+ [cq, oe] = range;
579
+ eq = o1.enumref;
580
+ qs.push([cq, eq, oe]);
581
+ continue;
582
+ }
583
+ }
584
+ if (o.queue !== cq) {
585
+ do {
586
+ var oq = o.queue;
587
+ while (oq && oq !== cq) oq = oq.queue;
588
+ if (oq) break;
589
+ if (!oq) {
590
+ if (qs.length) [cq, eq, oe] = qs.pop();
591
+ else cq = null, oe = Infinity;
287
592
  }
593
+ } while (cq);
594
+ if (!cq) {
595
+ eq = null;
596
+ continue;
288
597
  }
289
- if (enumtype & REFMOVE) {
290
- if (!eq) break;
291
- if (o.short) continue;
292
- o.type = eq.type;
293
- o.isdigit = true;
294
- o.text = eq.text;
295
- removeRefs(o);
598
+ }
599
+ if (o.start > oe) {
600
+ eq = null;
601
+ continue;
602
+ }
603
+
604
+ if (o.enumref) {
605
+ eq = o.enumref;
606
+ continue;
607
+ }
608
+ else {
609
+ if (eq) {
610
+ o.enumref = eq;
611
+ continue;
296
612
  }
297
613
  }
298
614
  }
@@ -302,8 +618,21 @@ function atuoenum(scoped) {
302
618
  var { used, caps } = scoped;
303
619
  mapkey = Symbol('enumed');
304
620
  for (var k in caps) {
305
- var rs = maplist(used[k]);
306
- enumref(rs, scoped);
621
+ var rs = null;
622
+ var os = used[k];
623
+ if (enumtype & REFSTRC) {
624
+ rs = maplist(os);
625
+ enumstruct(rs, scoped);
626
+ }
627
+ if (enumtype & REFTYPE) {
628
+ if (!rs) rs = maplist(os);
629
+ enummark(rs, scoped);
630
+ }
631
+ if (enumtype & REFMOVE) {
632
+ if (os.ignore) continue;
633
+ if (!rs) rs = maplist(used[k]);
634
+ enumequal(rs, scoped);
635
+ }
307
636
  }
308
637
  for (var k in caps) {
309
638
  for (var o of used[k]) {
@@ -311,15 +640,46 @@ function atuoenum(scoped) {
311
640
  }
312
641
  }
313
642
  }
643
+ var setStalk = function (scoped) {
644
+ for (var s of scoped) setStalk(s);
645
+ if (!scoped.isfunc) return;
646
+ var used = scoped.used;
647
+ for (var k in scoped.envs) {
648
+ var os = used[k];
649
+ for (var o of os) if (o.equal) {
650
+ if (!o.stalk) o.stalk = scoped;
651
+ }
652
+ }
653
+ loop: for (var k in used) {
654
+ var os = used[k];
655
+ if (os) for (var o of os) if (o.stalk) {
656
+ if (o.stalk !== scoped) {
657
+ os.ignore = true;
658
+ continue loop;
659
+ }
660
+ }
661
+ }
662
+ }
314
663
  var enumtype = 0;
664
+ var outObjects = null;
315
665
  var exports = module.exports = function main(code, type = REFMOVE) {
316
- var rest = [code.scoped];
666
+ var scoped = code.scoped;
667
+ outObjects = Object.create(null);
668
+ if (scoped.envs.Math) outObjects.Math = Math;
669
+ if (scoped.envs.Number) outObjects.Number = Number;
670
+ setStalk(scoped);
671
+ var rest = [scoped];
672
+ var backq = [];
317
673
  enumtype = type;
318
674
  while (rest.length) {
319
675
  var s = rest.pop();
320
- if (s.length) rest.push(...s);
321
- atuoenum(s);
676
+ backq.push(s);
677
+ if (s.length) rest.push(...s), backq.push(...s);
678
+ }
679
+ while (backq.length) {
680
+ atuoenum(backq.pop());
322
681
  }
682
+ outObjects = null;
323
683
  return code;
324
684
  }
325
685
  var REFMOVE = exports.REFMOVE = 1;