efront 3.34.12 → 3.35.0

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 (75) hide show
  1. package/apps/moue/content//344/275/240/345/245/275/344/270/226/347/225/214.vue +21 -0
  2. package/apps/moue/content//344/275/240/345/245/275/345/274/200/345/217/221/350/200/205.html +1 -0
  3. package/apps/moue/{home/index.js → content//344/275/240/345/245/275/345/274/200/345/217/221/350/200/205.js} +4 -2
  4. package/apps/moue/content//344/275/240/345/245/275/345/274/200/345/217/221/350/200/205.less +4 -0
  5. package/apps/moue/home/index2.vue +97 -18
  6. package/apps/moue/index.html +1 -1
  7. package/coms/basic/ArrayFill.md +9 -0
  8. package/coms/basic/awaitable.md +10 -0
  9. package/coms/basic/backEach.md +7 -0
  10. package/coms/basic/combine.md +23 -0
  11. package/coms/basic/renderExpress.js +1 -1
  12. package/coms/basic/wait.js +5 -0
  13. package/coms/basic_/readme.md +5 -4
  14. package/coms/compile/#/350/257/264/346/230/216.md +1 -0
  15. package/coms/compile/Html.js +263 -0
  16. package/coms/compile/Html_test.js +5 -0
  17. package/coms/compile/Javascript.js +594 -0
  18. package/coms/compile/Program.js +664 -0
  19. package/coms/compile/autoenum.js +179 -0
  20. package/coms/compile/autoenum_test.js +17 -0
  21. package/coms/compile/autoeval.js +50 -0
  22. package/coms/compile/autoeval_test.js +28 -0
  23. package/coms/compile/autoiota.js +121 -0
  24. package/coms/compile/breakcode.js +83 -0
  25. package/coms/compile/common.js +1063 -0
  26. package/coms/compile/downLevel.js +901 -0
  27. package/coms/compile/downLevel_test.js +111 -0
  28. package/coms/compile/formatcode.js +57 -0
  29. package/coms/compile/iso8859.js +9 -0
  30. package/coms/compile/iso8859_test.js +2 -0
  31. package/coms/compile/keywords.js +6 -0
  32. package/coms/compile/namelist.js +154 -0
  33. package/coms/compile/namelist_test.js +7 -0
  34. package/coms/compile/polyfill.js +31 -0
  35. package/coms/compile/required.js +20 -0
  36. package/coms/compile/richcss.js +237 -0
  37. package/coms/compile/richcss_test.js +7 -0
  38. package/coms/compile/scanner.js +653 -0
  39. package/coms/compile/scanner2.js +202 -0
  40. package/coms/compile/scanner2_test.js +110 -0
  41. package/coms/compile/scanner_test.js +10 -0
  42. package/coms/compile/unstruct.js +712 -0
  43. package/coms/compile/unstruct_test.js +54 -0
  44. package/coms/compile/washcode.js +237 -0
  45. package/coms/compile/washcode_test.js +17 -0
  46. package/coms/docs/helps.js +71 -0
  47. package/coms/docs/markdown.js +248 -0
  48. package/coms/frame/route.js +1 -1
  49. package/coms/reptile/colored_console.js +2 -1
  50. package/coms/zimoli/cless.js +1 -0
  51. package/coms/zimoli/css.js +1 -9
  52. package/coms/zimoli/html.js +1 -1
  53. package/coms/zimoli/menu.js +1 -1
  54. package/coms/zimoli/menuItem.html +1 -1
  55. package/coms/zimoli/menuItem.js +1 -1
  56. package/coms/zimoli/render.js +14 -3
  57. package/coms/zimoli/text.js +1 -1
  58. package/coms/zimoli/tree.js +2 -4
  59. package/coms/zimoli/zimoli.js +39 -12
  60. package/docs/compare.md +5 -5
  61. package/docs/components.jsp +17 -0
  62. package/docs/index.html +16 -26
  63. package/docs/main.xht +182 -0
  64. package/docs/mark.xht +166 -0
  65. package/docs/welcome.jsp +7 -0
  66. package/docs//345/221/275/344/273/244.xht +100 -0
  67. package/docs//347/211/210/346/234/254/350/257/264/346/230/216.md +9 -0
  68. package/docs//347/273/204/344/273/266.xht +87 -0
  69. package/package.json +1 -1
  70. package/public/efront.js +1 -1
  71. package/readme.md +6 -11
  72. package/apis/docs/getAllComponents.js +0 -69
  73. package/apps/moue/home/index.html +0 -1
  74. package/apps/moue/home/index.less +0 -0
  75. package/docs/main.js +0 -17
@@ -0,0 +1,1063 @@
1
+ "use strict";
2
+ const [
3
+ /* 1 */COMMENT,
4
+ /* 2 */SPACE,
5
+ /* 4 */STRAP,
6
+ /* 8 */STAMP,
7
+ /* 16 */VALUE,
8
+ /* 32 */QUOTED,
9
+ /* 64 */PIECE,
10
+ /* 128 */EXPRESS,
11
+ /* 256 */SCOPED,
12
+ /* 512 */LABEL,
13
+ /*1024 */PROPERTY,
14
+ ] = new Array(20).fill(0).map((_, a) => 1 << a);
15
+ var number_reg = /^(0x[0-9a-f]+|0b\d+|0o\d+|(\d*\.\d+|\d+\.?)(e[\+\-]?\d+|[mn])?)$/i;
16
+ var equal_reg = /^(?:[\+\-\*\/~\^&\|%]|\*\*|>>>?|<<)?\=$|^(?:\+\+|\-\-)$/;
17
+ var skipAssignment = function (o, cx) {
18
+ var next = arguments.length === 1 ? function () {
19
+ o = o.next;
20
+ } : function () {
21
+ o = body[++ox];
22
+ cx = ox;
23
+ while (o && o.type & (SPACE | COMMENT)) o = body[++ox];
24
+ };
25
+ if (arguments.length !== 1) {
26
+ var body = o;
27
+ var ox = cx;
28
+ o = body[ox];
29
+ while (o && o.type & (SPACE | COMMENT)) o = body[++ox];
30
+ cx = ox + 1;
31
+ }
32
+ var needpunc = false;
33
+ var qcount = 0;
34
+ var ifdeep = 0;
35
+ loop: while (o) switch (o.type) {
36
+ case STAMP:
37
+ switch (o.text) {
38
+ case ";":
39
+ if (!ifdeep) break loop;
40
+ var n = o.next;
41
+ if (!n || n.type !== STRAP || n.text !== 'else') break loop;
42
+ next();
43
+ break;
44
+ case ",":
45
+ if (!ifdeep) break loop;
46
+ needpunc = false;
47
+ next();
48
+ break;
49
+ case "++":
50
+ case "--":
51
+ next();
52
+ break;
53
+ case "!":
54
+ case "~":
55
+ case "+":
56
+ case "-":
57
+ next();
58
+ needpunc = false;
59
+ break;
60
+ case "?":
61
+ qcount++;
62
+ needpunc = false;
63
+ next();
64
+ break;
65
+ case ":":
66
+ if (qcount === 0) {
67
+ var p = o.prev;
68
+ if (p && p.type === LABEL) {
69
+ next();
70
+ break;
71
+ }
72
+ break loop;
73
+ }
74
+ qcount--;
75
+ next();
76
+ needpunc = false;
77
+ break;
78
+ default:
79
+ if (/^[!~\+\-]+$/.test(o.text)) {
80
+ needpunc = false;
81
+ next();
82
+ break;
83
+ }
84
+ if (!needpunc) break loop;
85
+ needpunc = false;
86
+ next();
87
+ }
88
+ break;
89
+ case SCOPED:
90
+ if (needpunc && o.entry === "{") break loop;
91
+ next();
92
+ needpunc = true;
93
+ break;
94
+ case EXPRESS:
95
+ if (/^\.|\.$/.test(o.text)) {
96
+ next();
97
+ break;
98
+ }
99
+ else if (/^\[/.test(o.text)) {
100
+ needpunc = true;
101
+ next();
102
+ break;
103
+ }
104
+ case VALUE:
105
+ case QUOTED:
106
+ if (needpunc) break loop;
107
+ needpunc = true;
108
+ next();
109
+ break;
110
+ case STRAP:
111
+ if (needpunc) {
112
+ if (/^catch$/.test(o.text)) {
113
+ next();
114
+ next();
115
+ needpunc = false;
116
+ break;
117
+ }
118
+ if (!/^(in|instanceof|of|else|as|finally)$/.test(o.text)) break loop;
119
+ if (o.text === 'else') {
120
+ if (!ifdeep) break loop;
121
+ ifdeep--;
122
+ }
123
+
124
+ next();
125
+ needpunc = false;
126
+ }
127
+ else if (/^(do|if|while|for|switch|with)/.test(o.text)) {
128
+ if (o.text === 'if') ifdeep++;
129
+ next();
130
+ next();
131
+ break;
132
+ }
133
+ else if (o.text === "class") {
134
+ next();
135
+ while (o && !o.isClass) next();
136
+ while (o && o.isClass) next();
137
+ needpunc = true;
138
+ break;
139
+ }
140
+ else if (o.text === "function") {
141
+ next();
142
+ if (o && o.type === STAMP) next();
143
+ if (o && o.type === EXPRESS) next();
144
+ if (o) next();
145
+ if (o) next();
146
+ needpunc = true;
147
+ break;
148
+ }
149
+ else {
150
+ next();
151
+ needpunc = false;
152
+ }
153
+ break;
154
+ default:
155
+ // console.log(o);
156
+ // throw new Error('代码结构异常!');
157
+ next();
158
+ break loop;
159
+ }
160
+ return body ? cx : o;
161
+ };
162
+ function skipSentenceQueue(o) {
163
+ do {
164
+ o = skipAssignment(o)
165
+ } while (o && o.type === STAMP && o.text === ',' ? o = o.next : false);
166
+ return o;
167
+ }
168
+ function snapSentenceHead(o) {
169
+ // 只检查一级
170
+ while (o && o.prev) {
171
+ var p = o.prev;
172
+ if (o.entry === '(' && !(p.type & (STAMP | STRAP))) {
173
+ o = p;
174
+ p = o.prev;
175
+ if (!p) break;
176
+ }
177
+ var maybeprop = o.type === SCOPED && o.entry !== "{" || o.type === EXPRESS && /^\./.test(o.text);
178
+ if (p.type === EXPRESS) {
179
+ if (maybeprop || /\.$/.test(p.text)) {
180
+ o = p;
181
+ continue;
182
+ }
183
+ break;
184
+ }
185
+ if (p.type & (VALUE | QUOTED)) {
186
+ if (maybeprop) {
187
+ o = p;
188
+ if (p.entry === '`' && p.prev && !(p.prev.type & (STAMP | STRAP))) o = p.prev;
189
+ continue;
190
+ }
191
+ break;
192
+ }
193
+ if (p.type === SCOPED) {
194
+ if (maybeprop) {
195
+ o = p;
196
+ continue;
197
+ }
198
+ if (p.entry === "(" && o.type === SCOPED) {
199
+ var pp = p.prev;
200
+ if (pp && pp.type === EXPRESS) pp = pp.prev;
201
+ if (pp && pp.type === STRAP && pp.text === 'function') {
202
+ o = pp;
203
+ continue;
204
+ }
205
+ }
206
+ break;
207
+ }
208
+ if (p.type === STRAP) {
209
+ if (/^(?:new|void|typeof|delete|await|var|let|const|class|function)$/.test(p.text)) {
210
+ o = p;
211
+ continue;
212
+ }
213
+ if (/^(in|instanceof)/.test(p.text)) {
214
+ o = p.prev;
215
+ continue;
216
+ }
217
+ break;
218
+ }
219
+ if (p.type === STAMP) {
220
+ if (/=>|[,;]/.test(p.text) || equal_reg.test(p.text)) {
221
+ break;
222
+ }
223
+ if (/^(?:[!~]|\+\+|\-\-)$/.test(p.text)) {
224
+ o = p;
225
+ continue;
226
+ }
227
+ o = p.prev;
228
+ continue;
229
+ }
230
+ break;
231
+ }
232
+ return o;
233
+ }
234
+
235
+ var snapExpressHead = function (o) {
236
+ if (!o || o.type !== EXPRESS) return;
237
+ while (o && o.prev) {
238
+ var p = o.prev;
239
+ if (p.type & (EXPRESS | VALUE)) {
240
+ if (o.type === SCOPED && o.entry === '[' || o.type === EXPRESS && /^\./.test(o.text) || /\.$/.test(p.text) && !p.isdigit) {
241
+ o = p;
242
+ continue;
243
+ }
244
+ }
245
+ break;
246
+ }
247
+ return o;
248
+ };
249
+ var snapExpressFoot = function (o) {
250
+ if (!o || !(o.type & (EXPRESS | VALUE))) return;
251
+ while (o && o.next) {
252
+ var n = o.next;
253
+ if (n.type === SCOPED && o.entry === '[' || /\.$/.test(o.text) && !o.isdigit || n.type === EXPRESS && /^\./.test(n.text)) {
254
+ if (n.type & (EXPRESS | SCOPED)) {
255
+ o = n;
256
+ continue;
257
+ }
258
+ }
259
+ break;
260
+ }
261
+ return o;
262
+ };
263
+ var createScoped = function (parsed, wash) {
264
+ var used = Object.create(null); var vars = Object.create(null), lets = vars;
265
+ var scoped = [], funcbody = scoped;
266
+ scoped.body = parsed;
267
+ scoped.isfunc = true;
268
+ var run = function (o, id, body) {
269
+ loop: while (o) {
270
+ var isCatch = false;
271
+ var isFunction = false;
272
+ var isScope = false;
273
+ var isArrow = false;
274
+ var isClass = false;
275
+ var isAsync = false;
276
+ var isAster = false;
277
+ if (o.type === STAMP && equal_reg.test(o.text)) {
278
+ var p = snapExpressHead(o.prev);
279
+ if (!p) {
280
+ let n = o.next;
281
+ if (n && n.type & (EXPRESS | VALUE)) {
282
+ n.equal = o;
283
+ }
284
+ }
285
+ else if (p.type & (EXPRESS | VALUE)) {
286
+ p.equal = o;
287
+ }
288
+ else if (o.text === '=' && p.type === SCOPED) {
289
+ if (!p.kind) {
290
+ var pp = p.prev;
291
+ if (!pp || pp.type === STAMP || pp.type === STRAP) {
292
+ getDeclared(p, 'assign');
293
+ }
294
+ }
295
+ }
296
+ }
297
+ switch (o.type) {
298
+ case QUOTED:
299
+ if (o.length) {
300
+ run(o.first);
301
+ }
302
+ break;
303
+ case STAMP:
304
+ break;
305
+ case PROPERTY:
306
+ if (o.next) {
307
+ if (o.next.type !== STAMP || o.next.text !== ",") break;
308
+ }
309
+ if (o.prev && o.prev.type === STRAP && o.prev.text === 'as') {
310
+ break;
311
+ }
312
+ case VALUE:
313
+ if (o.isdigit) break;
314
+ case EXPRESS:
315
+ if (o.prev && o.prev.type === EXPRESS) {
316
+ if (/\.$/.test(o.prev.text)) break;
317
+ }
318
+ var u = o.text;
319
+ if (/^\.\.\./.test(u)) u = u.slice(3);
320
+ var u = u.replace(/^([^\.\[]*)[\s\S]*$/, '$1');
321
+ if (!u) break;
322
+ if (u === 'await' && funcbody.async !== false) {
323
+ o.type = STRAP;
324
+ funcbody.async = true;
325
+ continue;
326
+ }
327
+ if (u === 'yield' && funcbody.aster === true) {
328
+ o.type = STRAP;
329
+ continue;
330
+ }
331
+ if (o.next && o.next.type === STAMP && o.next.text === "=>") {
332
+ isScope = true;
333
+ isArrow = true;
334
+ }
335
+ else {
336
+ var prev = o.prev;
337
+ if (prev && prev.type === STAMP && /^(?:\+\+|\-\-)$/.test(prev.text)) {
338
+ var pp = prev.prev;
339
+ if (!pp || pp.type === STAMP) {
340
+ o.equal = o.prev;
341
+ }
342
+ }
343
+ saveTo(used, u, o);
344
+ }
345
+ break;
346
+ case LABEL:
347
+ var name = o.text;
348
+ name = name.slice(0, name.length - 1);
349
+ vars[name] = true;
350
+ o.kind = "label";
351
+ saveTo(used, name, o);
352
+ break;
353
+
354
+ case STRAP:
355
+ var s = o.text;
356
+ switch (s) {
357
+ case "return":
358
+ if (!funcbody.return) funcbody.return = [];
359
+ funcbody.return.push(o);
360
+ break;
361
+ case "await":
362
+ if (funcbody.async === false) {
363
+ o.type = EXPRESS;
364
+ continue;
365
+ }
366
+ funcbody.async = funcbody.await = true;
367
+ break;
368
+ case "yield":
369
+ if (!funcbody.aster) {
370
+ var mustyield = undefined;
371
+ var tmp = id;
372
+ if (body) while (body[++tmp] !== o.next) {
373
+ if (body[tmp].type === SPACE) {
374
+ mustyield = false;
375
+ break;
376
+ };
377
+ }
378
+ if (mustyield !== false && o.next) {
379
+ if (o.next.type === STRAP && !/^(?:instanceof|in|of|from|as)$/.test(o.next.text)
380
+ || o.next.type === STAMP && /[!~]/.test(o.next.text)
381
+ || o.next.type === EXPRESS && /^\./.test(o.next.text)
382
+ || o.next.type & (VALUE | QUOTED | SCOPED)
383
+ ) {
384
+ mustyield = true;
385
+ }
386
+ }
387
+ if (mustyield) funcbody.aster = true;
388
+ else o.type = EXPRESS;
389
+ continue;
390
+ }
391
+ funcbody.yield = true;
392
+ break;
393
+ case "as":
394
+ case "from":
395
+ break;
396
+ case "var":
397
+ case "import":
398
+ var m = vars;
399
+ case "let":
400
+ case "const":
401
+ m = m || lets;
402
+ var [declared, used0, o0, skiped] = getDeclared(o.next, s);
403
+ while (skiped.length) {
404
+ var o1 = run(skiped[0], 0);
405
+ let sindex = skiped.indexOf(o1);
406
+ if (sindex < 0) break;
407
+ skiped.splice(0, sindex + 1);
408
+ }
409
+ o = o0;
410
+ mergeTo(used, used0);
411
+ mapDeclared(m, declared);
412
+ continue loop;
413
+ case "function":
414
+ isFunction = true;
415
+
416
+ if (o.prev && o.prev.text === 'async') {
417
+ isAsync = true;
418
+ }
419
+ if (o.next.type === STAMP) {
420
+ isAster = true;
421
+ o = o.next;
422
+ }
423
+ case "catch":
424
+ if (s === 'catch') isCatch = true;
425
+ case "class":
426
+ if (s === 'class') isClass = true;
427
+ if (!o.isExpress) {
428
+ o = o.next;
429
+
430
+ if (o.type === EXPRESS) {
431
+ vars[o.text] = true;
432
+ o.kind = isFunction ? 'function' : 'class';
433
+ saveTo(used, o.text, o);
434
+ o = o.next;
435
+ }
436
+ }
437
+
438
+ isScope = true;
439
+ break;
440
+ case "for":
441
+ o = o.next;
442
+ isScope = true;
443
+ break;
444
+
445
+ }
446
+ break;
447
+ case SCOPED:
448
+ if (o.entry === "(") {
449
+ if (o.next && o.next.type === STAMP && o.next.text === "=>") {
450
+ isArrow = true;
451
+ isScope = true;
452
+ if (o.prev && o.prev.text === 'async') {
453
+ isAsync = true;
454
+ }
455
+ }
456
+ else if (o.prev && (o.prev.type === PROPERTY || o.prev.isprop)) {
457
+ isFunction = true;
458
+ isScope = true;
459
+ var pp = o.prev.prev;
460
+ if (pp && pp.type === STAMP && pp.isprop) {
461
+ isAster = true;
462
+ }
463
+ if (pp && pp.text === 'async') {
464
+ isAsync = true;
465
+ }
466
+ }
467
+ else {
468
+ run(o.first);
469
+ }
470
+ }
471
+ else if (o.entry === "{" && !o.isObject) {
472
+ isScope = true;
473
+ }
474
+ else {
475
+ run(o.first);
476
+ }
477
+ break;
478
+ }
479
+ if (isScope) {
480
+ var _used = used;
481
+ var _lets = lets;
482
+ var _vars = vars;
483
+ var _scoped = scoped;
484
+ var _funcbody = funcbody;
485
+ used = Object.create(null);
486
+ lets = Object.create(null);
487
+ vars = Object.create(null);
488
+ scoped = [];
489
+ var isExpress = o.isExpress;
490
+
491
+ if (isFunction || isArrow) {
492
+ scoped.used = used;
493
+ scoped.vars = vars;
494
+ lets = vars;
495
+ if (isFunction) {
496
+ vars.this = true, vars.arguments = true;
497
+ scoped.aster = isAster;
498
+ }
499
+ scoped.async = isAsync;
500
+ scoped.isfunc = true;
501
+ isFunction = true;
502
+ funcbody = scoped;
503
+ } else {
504
+ vars = _vars;
505
+ scoped.lets = lets;
506
+ scoped.used = used;
507
+ if (isClass) {
508
+ lets.super = true;
509
+ }
510
+ }
511
+ if (isArrow);
512
+ else while (o && o.isExpress && o.type !== SCOPED) {
513
+ o = o.next;
514
+ if (o && o.type === EXPRESS) {
515
+ saveTo(used, o.text, o);
516
+ if (o.prev && o.prev.type === STRAP && o.prev.text === 'extends') continue;
517
+ lets[o.text] = true;
518
+ o.kind = isFunction ? 'function' : 'class';
519
+ o = o.next;
520
+ }
521
+ if (isFunction) break;
522
+ }
523
+ if (!isFunction) while (o.type !== SCOPED) {
524
+ // if (o.next && o.next.type === STAMP && o.next.text === "=>") break;
525
+ o = run(o, 0);
526
+ o = o.next;
527
+ if (!o) break;
528
+ }
529
+ if (!o);
530
+ else if (o.entry === "(") {
531
+ scoped.head = o;
532
+ o.isExpress = isExpress;
533
+ if (isFunction || isCatch) {
534
+ var [declared, used0, o0, skiped] = getDeclared(o.first, 'argument');
535
+ scoped.args = declared;
536
+ mergeTo(used, used0);
537
+ while (skiped.length) {
538
+ var o1 = run(skiped[0], 0);
539
+ var sindex = skiped.indexOf(o1);
540
+ if (sindex < 0) break;
541
+ skiped.splice(0, sindex + 1);
542
+ }
543
+ mapDeclared(isCatch ? lets : vars, declared);
544
+ }
545
+ else {
546
+ run(o.first);
547
+ }
548
+ o = o.next;
549
+ if (!o);
550
+ else if (o.type === STAMP && o.text === "=>") o = o.next;
551
+ }
552
+ else if (isArrow) {
553
+ vars[o.text] = true;
554
+ o.kind = 'argument';
555
+ saveTo(used, o.text, o);
556
+ o = o.next.next;
557
+ }
558
+ if (!o);
559
+ else if (o.type === SCOPED && o.entry === "{") {
560
+ scoped.body = o;
561
+ o.isExpress = isExpress;
562
+ run(o.first);
563
+ if (wash && isFunction) {
564
+ var e = o.next;
565
+ if (e && e.type === EXPRESS && /^[\.\[]/.test(e.text) || e && e.type === SCOPED && e.entry === "[") {
566
+ scoped.target = true;
567
+ e = e.next;
568
+ }
569
+ if (e && e.type === SCOPED && e.entry === '(') {
570
+ if (e.first) {
571
+ scoped.pass = getDeclared(e.first)[0];
572
+ }
573
+ if (scoped.target) scoped.target = scoped.pass.shift();
574
+ }
575
+ }
576
+ }
577
+ else if (isArrow) {
578
+ var next = skipAssignment(o);
579
+ var u = o;
580
+ while (o !== next) {
581
+ var n = run(o, 0);
582
+ if (o === n) o = n.next;
583
+ else o = n;
584
+ }
585
+ }
586
+ else {
587
+ do {
588
+ if (o.type === STAMP && o.text === ";") break;
589
+ o = run(o, 0);
590
+ if (!o) break;
591
+ var next = o.next;
592
+ if (!next) break;
593
+ var e = o;
594
+ if (o.type === STAMP && /^(\+\+|\-\-)$/.test(o.text) && o.prev && o.prev.type === EXPRESS
595
+ || (VALUE | QUOTED | SCOPED) & o.type
596
+ || EXPRESS === o.type && !/\.$/.test(o.text)) {
597
+ if ((VALUE | QUOTED | PROPERTY | LABEL) & next.type) break;
598
+ if (EXPRESS === next.type && !/^\./.test(next.text)) break;
599
+ if (next.type === SCOPED && next.entry === "{") break;
600
+ if (next.type === STRAP && !next.isExpress) break;
601
+ }
602
+ o = next;
603
+ } while (o);
604
+ }
605
+ var map = isFunction ? vars : lets;
606
+ var keepscope = !!scoped.body || !!scoped.head;
607
+ if (!keepscope) for (var k in map) {
608
+ keepscope = true;
609
+ break;
610
+ }
611
+ if (keepscope) {
612
+ var envs = Object.create(null);
613
+ for (var k in used) {
614
+ if (!(k in map)) {
615
+ envs[k] = true;
616
+ for (var u of used[k]) {
617
+ saveTo(_used, k, u);
618
+ }
619
+ }
620
+ }
621
+ scoped.envs = envs;
622
+ _scoped.push(scoped);
623
+ }
624
+ else {
625
+ mergeTo(_used, used);
626
+ if (scoped.length) _scoped.push(scoped);
627
+ }
628
+ if (isFunction && vars.this) {
629
+ delete vars.this;
630
+ delete vars.arguments;
631
+ }
632
+ if (isClass) delete lets.super;
633
+ if (scoped.isfunc) {
634
+ if (used.yield) _scoped.yield = false;
635
+ funcbody = _funcbody;
636
+ }
637
+ used = _used;
638
+ lets = _lets;
639
+ vars = _vars;
640
+ scoped = _scoped;
641
+ }
642
+ if (id >= 0) break;
643
+ if (o) o = o.next;
644
+ }
645
+ return o;
646
+ };
647
+ run(parsed.first);
648
+ scoped.used = used;
649
+ scoped.vars = vars;
650
+ var envs = Object.create(null);
651
+ for (var u in used) {
652
+ if (!(u in vars)) {
653
+ if (!/^(true|false|null|this|arguments)$/.test(u)) envs[u] = true;
654
+ }
655
+ }
656
+ if (vars.yield) scoped.yield = false;
657
+ if (scoped.yield !== false && envs.yield) {
658
+ scoped.yield = true;
659
+ delete envs.yield;
660
+ delete used.yield;
661
+ }
662
+ scoped.envs = envs;
663
+ return scoped;
664
+ };
665
+ var getDeclared = function (o, kind, queue) {
666
+ var declared = [], used = Object.create(null); var skiped = [];
667
+ var prop = null;
668
+ var attributes = [];
669
+ var index = 0;
670
+ loop: while (o) {
671
+ while (o && o.type === STAMP && o.text === ',') o = o.next, index++;
672
+ if (!o) {
673
+ index--;
674
+ break;
675
+ }
676
+ if (o.isprop) {
677
+ prop = createString([o]).trim();
678
+ if (/^(['"`])[\s\S]*\1$/.test(prop)) {
679
+ prop = `[${prop}]`;
680
+ }
681
+ else if (o.isdigit) prop = `[${prop}]`;
682
+ else if (!/^\[[\s\S]*\]$/.test(prop)) prop = "." + prop;
683
+ skiped.push(o);
684
+ if (o.next && o.next.type === STAMP && o.next.text === ":") {
685
+ o = o.next;
686
+ o = o.next;
687
+ }
688
+ }
689
+ switch (o.type) {
690
+ case STAMP:
691
+ if (o.text === "*" && o.next) {
692
+ if (o.next.type === STRAP && o.next.text === 'as') {
693
+ o = o.next.next;
694
+ prop = "*";
695
+ continue;
696
+ }
697
+ }
698
+ case PROPERTY:
699
+ if (o.next) {
700
+ if (o.next.type === STAMP && o.next.text === ":" || o.next.type === STRAP && o.next.text === "as") {
701
+ prop = "." + o.text;
702
+ o = o.next.next;
703
+ continue;
704
+ }
705
+ }
706
+ case STRAP:
707
+ case VALUE:
708
+ case EXPRESS:
709
+ var n = o.text.replace(/^\.\.\.|\.\.\.$/g, '');
710
+ declared.push(n);
711
+ if (!prop) prop = declared["..."] ? declared["..."][1] - index : `[${index}]`;
712
+ if (n !== o.text) declared["..."] = [n, index];
713
+ else attributes.push([prop, n]);
714
+ o.kind = kind;
715
+ saveTo(used, n, o);
716
+ o = o.next;
717
+ break;
718
+ case SCOPED:
719
+ var [d, u, _, s] = getDeclared(o.first, kind, o);
720
+ while (s.length) skiped.push.apply(skiped, s.splice(0, 1024));
721
+ mergeTo(used, u);
722
+ declared.push(d);
723
+ if (!prop) prop = declared["..."] ? declared["..."][1] - index : `[${index}]`;
724
+ d.entry = o.entry;
725
+ o.kind = kind;
726
+ attributes.push([prop, d]);
727
+ o = o.next;
728
+ break;
729
+ default:
730
+ console.log(o);
731
+ throw new Error("代码结构异常");
732
+ }
733
+ if (!o) break;
734
+ switch (o.type) {
735
+ case STRAP:
736
+ if (/^(in|of)$/.test(o.text)) {
737
+ o = o.next;
738
+ var o0 = skipAssignment(o);
739
+ do {
740
+ skiped.push(o);
741
+ o = o.next;
742
+ } while (o !== o0);
743
+ o = o0;
744
+ break;
745
+ }
746
+ break loop;
747
+ case STAMP:
748
+ if (o.text === "=") {
749
+ o.prev.equal = o;
750
+ o = o.next;
751
+ var o0 = skipAssignment(o);
752
+ attributes[attributes.length - 1].push(queue, o, o0);
753
+ while (o !== o0) {
754
+ skiped.push(o);
755
+ o = o.next;
756
+ }
757
+ o = o0;
758
+ break;
759
+ }
760
+ break;
761
+ }
762
+ if (!o) break;
763
+ if (o.type !== STAMP) break;
764
+ if (o.text !== ',') break;
765
+ prop = null;
766
+ }
767
+ declared.attributes = attributes;
768
+ if (declared["..."]) declared["..."].push(index);
769
+ return [declared, used, o, skiped];
770
+ };
771
+ var mapDeclared = function (map, declared) {
772
+ var rest = [declared];
773
+ while (rest.length) {
774
+ var r = rest.pop();
775
+ for (var d of r) {
776
+ if (d instanceof Array) rest.push(d);
777
+ else map[d] = true;
778
+ }
779
+ }
780
+ return map;
781
+ };
782
+ var saveTo = function (used, k, o) {
783
+ if (!(used[k] instanceof Array)) used[k] = [];
784
+ used[k].push(o);
785
+ };
786
+
787
+ var mergeTo = function (used, used0) {
788
+ for (var k in used0) {
789
+ var v = used0[k];
790
+ for (var s of v) saveTo(used, k, s);
791
+ }
792
+ };
793
+ var breakSpace = function (o) {
794
+ var { prev, next } = o;
795
+ if (hasBreakBetween(prev, next)) return;
796
+ if (prev.type === STRAP && prev.isend) return ';';
797
+ return getSemicolonBetween(prev, next);
798
+ };
799
+ var hasBreakBetween = function (prev, next) {
800
+ if (!prev || !next) return true;
801
+ if (prev.type === STAMP && /^[,;]$/.test(prev.text)) return true;
802
+ if (next.type === STAMP && /^[,;]$/.test(next.text)) return true;
803
+ if (prev.type === EXPRESS && /\.$/.test(prev.text)) return true;
804
+ if (next.type === EXPRESS && /^[\.\[]/.test(next.text)) return true;
805
+ };
806
+ var getSemicolonBetween = function (prev, next) {
807
+ if (next.type === PROPERTY) return ";";
808
+ if (next.type === STAMP && next.text === "*") return ";";
809
+ if (
810
+ (EXPRESS | VALUE | QUOTED) & prev.type
811
+ || prev.type === STAMP && /^(\+\+|\-\-)$/.test(prev.text)
812
+ || prev.type === SCOPED && (prev.isExpress || prev.isObject)
813
+ ) {
814
+ if ((EXPRESS | VALUE | QUOTED | LABEL) & next.type) return ";";
815
+ if (next.type === STRAP) {
816
+ if (!/^(in|of|extends|instanceof|as)$/.test(next.text)) return ";";
817
+ return " ";
818
+ }
819
+ if (next.type === SCOPED && next.entry === '{') {
820
+ if (!next.isExpress) return ";";
821
+ }
822
+ return;
823
+ }
824
+ if (prev.type === STRAP) {
825
+ if ((STRAP | EXPRESS | VALUE | QUOTED) & next.type) return " ";
826
+ if (next.type === LABEL) return ";";
827
+ }
828
+ }
829
+ var needBreakBetween = function (prev, next) {
830
+ if (hasBreakBetween(prev, next)) return;
831
+ return getSemicolonBetween(prev, next);
832
+ };
833
+ var relink = function (list) {
834
+ var pi = 0, p = null;
835
+ for (var cx = 0, dx = list.length; cx < dx; cx++) {
836
+ var o = list[cx];
837
+ o.prev = p;
838
+ if (o.type === COMMENT || o.type === SPACE) continue;
839
+ if (!p) list.first = o;
840
+ while (pi < cx) list[pi++].next = o;
841
+ p = o;
842
+ }
843
+ while (pi < cx) list[pi++].next = null;
844
+ list.last = p;
845
+ return list;
846
+ }
847
+
848
+ var createString = function (parsed) {
849
+ var keepspace = parsed.keepspace !== false;
850
+ var helpcode = parsed.helpcode;
851
+ var lasttype = SPACE;
852
+ var result = [], cacheresult, finalresult = result;
853
+ var helpcolor = parsed.keepcolor === false;
854
+ var run = (o, i, a) => {
855
+ var prev = o.prev;
856
+ if (!((SPACE | COMMENT | STAMP | PIECE | SCOPED) & o.type) && prev && lasttype !== SPACE && keepspace) {
857
+ if ((QUOTED | SCOPED | STRAP | LABEL | COMMENT) & lasttype
858
+ || prev.type === STAMP && !prev.unary
859
+ ) {
860
+ if (o.type !== EXPRESS || !/^\.[^\.]/.test(o.text) && !prev.tag && !o.tag) {
861
+ result.push(" ");
862
+ lasttype = SPACE
863
+ }
864
+ }
865
+ }
866
+ switch (o.type) {
867
+ case COMMENT:
868
+ // 每一次要远行,我都不得不对自己的物品去粗取精。取舍之间,什么重要,什么不是那么重要,都有了一道明显的分界线。
869
+ var tmp = o.text, opentmp = false;
870
+ if (!keepspace || helpcode) {
871
+ if (/^\/[\/\*]\s*\<\!--/.test(tmp)) {
872
+ opentmp = true;
873
+ if (/^\/\*/.test(tmp)) opentmp = 2;
874
+ tmp = tmp.replace(/^\/[\/\*]\s*\<\!--\s*/, '');
875
+ cacheresult = [];
876
+ result = cacheresult;
877
+ result.push("/* <!-- 开发辅助代码: */");
878
+ }
879
+ if (/--\!?\>\s*(?:\*\/)?$/.test(tmp) && result !== finalresult) {
880
+ if (!opentmp) tmp = tmp.replace(/^\/[\/\*]\s*/, '');
881
+ tmp = tmp.replace(/\s*--\!?\>\s*(?:\*\/)?$/, "");
882
+ if (tmp) {
883
+ result.push(tmp);
884
+ }
885
+ result.push("/* --> */");
886
+ opentmp = true;
887
+ if (helpcode && cacheresult) finalresult = finalresult.concat(cacheresult), cacheresult = [];
888
+ result = finalresult;
889
+ }
890
+ else if (opentmp) {
891
+ if (opentmp === 2) tmp = tmp.replace(/\s*\*\/$/, '');
892
+ if (tmp) result.push("\r\n", tmp);
893
+ }
894
+ }
895
+ if (keepspace && !opentmp) {
896
+ if (lasttype !== SPACE && lasttype !== EXPRESS) result.push(" ");
897
+ result.push(tmp);
898
+ }
899
+ break;
900
+ case SPACE:
901
+ if (keepspace) {
902
+ result.push(o.text);
903
+ lasttype = SPACE;
904
+ break;
905
+ }
906
+ var b = breakSpace(o);
907
+ if (b) result.push(b);
908
+ break;
909
+ case QUOTED:
910
+ if (!o.length) {
911
+ if (helpcolor) o.text = color.transform(o.text);
912
+ result.push(o.text);
913
+ break;
914
+ }
915
+ case SCOPED:
916
+ if (keepspace && o.type !== QUOTED && (lasttype & (STRAP | COMMENT | STAMP)
917
+ && (!o.prev || !/[\+\-\~\!]$/.test(o.prev.text) || /[\+\-]$/.test(o.prev.text) && (!o.prev.prev || !((STAMP | STRAP) & o.prev.prev.type)))
918
+ || lasttype === SCOPED && o.entry === "{"
919
+ )) result.push(" ");
920
+ result.push(o.entry);
921
+ if (o.length > 0) {
922
+ if (o.entry === "{" && o[0].type !== SPACE) {
923
+ if (keepspace && lasttype !== PIECE) {
924
+ result.push(" ");
925
+ }
926
+ }
927
+ lasttype = SPACE;
928
+ o.forEach(run);
929
+ if (o.prev && o.prev.type === STRAP && /^for$/.test(o.prev.text));
930
+ else if (/^[,;]$/.test(result[result.length - 1]) && !keepspace) {
931
+ var last = o.last;
932
+ var lp = last && last.prev;
933
+ if (!lp) result.pop();
934
+ else {
935
+ var lpp = lp.prev;
936
+ if (lp.type === STRAP && lp.text === 'else' || lp.type === SCOPED && lpp && lpp.type === STRAP && /^(while|if|with|for)/.test(lpp.text));
937
+ else result.pop();
938
+ }
939
+ }
940
+ if (o.leave === "}" && (!o.next || o.next.type !== PIECE) && o[o.length - 1].type !== SPACE) {
941
+ if (keepspace) result.push(" ");
942
+ }
943
+ }
944
+ result.push(o.leave);
945
+ break;
946
+ default:
947
+ if (o instanceof Object) {
948
+ if (o.prev && o.prev.type === EXPRESS && o.type === EXPRESS && (/^\./.test(o.text) || /\.$/.test(o.prev.text)));
949
+ else if ((STRAP | EXPRESS | PROPERTY | COMMENT | VALUE) & lasttype && (STRAP | EXPRESS | PROPERTY | VALUE) & o.type) {
950
+ result.push(" ");
951
+ }
952
+ else if (o.prev && o.type === STAMP && !/^([,;])$/.test(o.text)) {
953
+ if (result[result.length - 1] === " " || (lasttype === PROPERTY || !o.isExpress && o.prev && o.prev.type !== LABEL) && o.text === ':') { }
954
+ else if (lasttype === STAMP) {
955
+ result.push(" ");
956
+ }
957
+ else if (/^(\+\+|\-\-)$/.test(o.prev.text) && o.prev.prev) {
958
+ var prev_prev = o.prev.prev;
959
+ if (
960
+ prev_prev.type === STRAP && !prev_prev.isExpress
961
+ || prev_prev.type & (EXPRESS | VALUE)
962
+ ) result.push(";");
963
+ }
964
+ else if (o.text === '*') {
965
+ if (keepspace && lasttype !== SPACE && (lasttype !== STRAP || o.prev && o.prev.text !== 'function')) result.push(" ");
966
+ }
967
+ else if (!/^(\+\+|\-\-)$/.test(o.text)) {
968
+ if (keepspace && lasttype !== SPACE) result.push(" ");
969
+ }
970
+ }
971
+ if (o.type === VALUE) {
972
+ if (/^0[0-7]+$/.test(o.text)) {
973
+ o.text = '0o' + o.text.slice(1);
974
+ }
975
+ }
976
+ result.push(o.text);
977
+ }
978
+ else {
979
+ result.push(o);
980
+ }
981
+ }
982
+ lasttype = o.type;
983
+ if (o.isprop) lasttype = PROPERTY;
984
+ };
985
+ parsed.forEach(run);
986
+ return finalresult.join("");
987
+ }
988
+ var rename = function (used, from, to) {
989
+ if (from === to) return;
990
+ var list = used[from];
991
+ if (list) for (var u of list) {
992
+ if (!u) continue;
993
+ var text = u.text;
994
+ var doted = /^\.\.\./.test(text);
995
+ if (doted) text = text.slice(3);
996
+ text = to + text.replace(/^[^\.\:\[]+/i, "");
997
+ if (doted) text = "..." + text;
998
+ if (u.type === PROPERTY) {
999
+ if (u.short) {
1000
+ var q = u.queue;
1001
+ q.splice(q.indexOf(u), 0, { type: PROPERTY, text: u.text }, { type: STAMP, text: ":" });
1002
+ u.short = false;
1003
+ u.type = EXPRESS;
1004
+ u.text = text;
1005
+ relink(q);
1006
+ }
1007
+ continue;
1008
+ }
1009
+ u.text = text;
1010
+ }
1011
+ };
1012
+
1013
+ /**
1014
+ * 按语句分割代码
1015
+ */
1016
+ var createExpressList = function (code) {
1017
+ var list = [];
1018
+ for (var cx = 0, dx = code.length; cx < dx;) {
1019
+ var o = code[cx];
1020
+ var ex = skipAssignment(code, cx);
1021
+ if (code[ex] && code[ex].type === STAMP && /[,;]/.test(code[ex].text)) {
1022
+ ex++;
1023
+ }
1024
+ if (ex > dx) ex = dx;
1025
+ var exp = [];
1026
+ do {
1027
+ exp.push(o);
1028
+ o = code[++cx];
1029
+ } while (cx < ex);
1030
+ relink(exp);
1031
+ list.push(exp);
1032
+ }
1033
+ return list;
1034
+ };
1035
+ module.exports = {
1036
+ /* 1 */COMMENT,
1037
+ /* 2 */SPACE,
1038
+ /* 4 */STRAP,
1039
+ /* 8 */STAMP,
1040
+ /* 16 */VALUE,
1041
+ /* 32 */QUOTED,
1042
+ /* 64 */PIECE,
1043
+ /* 128 */EXPRESS,
1044
+ /* 256 */SCOPED,
1045
+ /* 512 */LABEL,
1046
+ /*1024 */PROPERTY,
1047
+ number_reg,
1048
+ equal_reg,
1049
+ skipAssignment,
1050
+ getDeclared,
1051
+ createString,
1052
+ createScoped,
1053
+ createExpressList,
1054
+ snapSentenceHead,
1055
+ snapExpressHead,
1056
+ snapExpressFoot,
1057
+ skipSentenceQueue,
1058
+ needBreakBetween,
1059
+ saveTo,
1060
+ rename,
1061
+ relink,
1062
+ mergeTo
1063
+ };