efront 2.41.8 → 2.42.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.
@@ -14,6 +14,9 @@
14
14
  <script deleteoncompile efrontloader>
15
15
  // 若要在开发环境使用内置组件,请保留此script标签中的代码,在编译发布时时,这里的代码会自动删除
16
16
  </script>
17
+ <script>
18
+ cross_host = 'efront.cc';
19
+ </script>
17
20
  <style>
18
21
  *,
19
22
  ::before,
@@ -25,8 +25,9 @@ var mergeTo = function (used, used0) {
25
25
  for (var s of v) saveTo(used, k, s);
26
26
  }
27
27
  };
28
-
29
28
  var skipAssignment = function (o) {
29
+ var needpunc = false;
30
+ var o0 = o;
30
31
  loop: while (o) switch (o.type) {
31
32
  case STAMP:
32
33
  switch (o.text) {
@@ -36,61 +37,72 @@ var skipAssignment = function (o) {
36
37
  case "++":
37
38
  case "--":
38
39
  o = o.next;
39
- if (!o) break loop;
40
- if (o.type !== STAMP) {
41
- o = o.next;
42
- break loop;
43
- }
40
+ break;
41
+ case "!":
42
+ case "~":
43
+ case "+":
44
+ case "-":
45
+ o = o.next;
46
+ needpunc = false;
44
47
  break;
45
48
  default:
49
+ if (/^[!~\+\-]+$/.test(o.text)) {
50
+ needpunc = false;
51
+ o = o.next;
52
+ break;
53
+ }
54
+ if (!needpunc) break loop;
55
+ needpunc = false;
46
56
  o = o.next;
47
57
  }
48
58
  break;
49
59
  case SCOPED:
50
- if (!o.isObject && o.entry === "{") break loop;
60
+ if (needpunc && o.entry === "{") break loop;
51
61
  o = o.next;
62
+ needpunc = true;
52
63
  break;
53
64
  case EXPRESS:
54
- if (/\.$/.test(o.text)) {
65
+ if (/^\.|\.$/.test(o.text)) {
55
66
  o = o.next;
56
67
  break;
57
68
  }
58
69
  case VALUE:
59
70
  case QUOTED:
71
+ if (needpunc) break loop;
72
+ needpunc = true;
60
73
  o = o.next;
61
- if (!o) break loop;
62
- if (o.type === SCOPED && o.entry !== "{") break;
63
- if (o.type === EXPRESS) {
64
- if (/^\./.test(o.text)) break;
65
- break loop;
66
- }
67
- if (o.type === STRAP) {
68
- if (/^(in|of|as|instanceof|extends)$/i.test(o.text)) break;
69
- break loop;
70
- }
71
- if (o.type !== STAMP) break loop;
72
-
73
74
  break;
74
75
  case STRAP:
75
- if (!o.isExpress) break loop;
76
- if (o.text === "class") {
76
+ if (needpunc) {
77
+ if (!/^(in|instanceof)$/.test(o.text)) break loop;
78
+ o = o.next;
79
+ needpunc = false;
80
+ }
81
+ else if (o.text === "class") {
77
82
  o = o.next;
78
83
  while (o && !o.isClass) o = o.next;
79
84
  while (o && o.isClass) o = o.next;
85
+ needpunc = true;
80
86
  break;
81
87
  }
82
- if (o.text === "function") {
88
+ else if (o.text === "function") {
83
89
  o = o.next;
84
90
  if (o && o.type === EXPRESS) o = o.next;
85
91
  if (o) o = o.next;
86
92
  if (o) o = o.next;
93
+ needpunc = true;
87
94
  break;
88
95
  }
89
- o = o.next;
96
+ else {
97
+ o = o.next;
98
+ needpunc = false;
99
+ }
90
100
  break;
91
101
  default:
102
+ throw new Error('代码结构异常!');
92
103
  o = o.next;
93
104
  }
105
+ if (o === o0) throw new Error("代码结构异常!");
94
106
  return o;
95
107
  };
96
108
 
@@ -122,37 +134,58 @@ var needBreak = function (prev, next) {
122
134
  }
123
135
  };
124
136
 
125
- var getDeclared = function (o) {
137
+ var getDeclared = function (o, kind) {
138
+
126
139
  var declared = Object.create(null), used = Object.create(null); var skiped = [];
127
140
  loop: while (o) {
141
+ while (o && o.type === STAMP && o.text === ',') o = o.next;
142
+ if (!o) break;
143
+ if (o.isprop) {
144
+ if (o.next && o.next.type === STAMP && o.next.text === ":") {
145
+ o = o.next;
146
+ o = o.next;
147
+ }
148
+ }
128
149
  switch (o.type) {
129
- case STRAP:
130
- if (/^(in|of)$/.test(o.text)) {
131
- o = o.next;
132
- var o0 = skipAssignment(o);
133
- do {
134
- skiped.push(o);
135
- o = o.next;
136
- } while (o !== o0);
137
- o = o0;
138
- break;
150
+ case PROPERTY:
151
+ if (o.next && o.next.type === STAMP && o.next.text === ":") {
152
+ o = o.next.next;
153
+ continue;
139
154
  }
155
+ case STRAP:
140
156
  case VALUE:
141
- o = o.next;
142
- break;
143
157
  case EXPRESS:
144
158
  declared[o.text] = true;
159
+ o.kind = kind;
145
160
  saveTo(used, o.text, o);
146
161
  o = o.next;
147
162
  break;
148
163
  case SCOPED:
149
- var [d, u, _, s] = getDeclared(o.first);
150
- if (o.findIndex(a => a.text === "areTypesComparable") >= 0) console.log(o.prev.prev.prev);
164
+ var [d, u, _, s] = getDeclared(o.first, kind);
151
165
  while (s.length) skiped.push.apply(skiped, s.splice(0, 1024));
152
166
  mergeTo(used, u);
153
167
  Object.assign(declared, d);
154
168
  o = o.next;
155
169
  break;
170
+
171
+ default:
172
+ console.log(o);
173
+ throw new Error("代码结构异常");
174
+ }
175
+ if (!o) break;
176
+ switch (o.type) {
177
+ case STRAP:
178
+ if (/^(in|of)$/.test(o.text)) {
179
+ o = o.next;
180
+ var o0 = skipAssignment(o);
181
+ do {
182
+ skiped.push(o);
183
+ o = o.next;
184
+ } while (o !== o0);
185
+ o = o0;
186
+ break;
187
+ }
188
+ break loop;
156
189
  case STAMP:
157
190
  if (o.text === "=") {
158
191
  o = o.next;
@@ -164,13 +197,11 @@ var getDeclared = function (o) {
164
197
  o = o0;
165
198
  break;
166
199
  }
167
- if (o.text === ";") break loop;
168
- if (o.text !== ",") break loop;
169
- o = o.next;
170
200
  break;
171
- default:
172
- break loop;
173
201
  }
202
+ if (!o) break;
203
+ if (o.type !== STAMP) break;
204
+ if (o.text !== ',') break;
174
205
  }
175
206
  return [declared, used, o, skiped];
176
207
  }
@@ -198,6 +229,7 @@ var compress = function (scoped, maped) {
198
229
  for (var cx = 0, dx = keys.length; cx < dx; cx++) {
199
230
  var k = keys[cx];
200
231
  var name = names[cx];
232
+ map[k] = name;
201
233
  var list = used[k];
202
234
  if (list) for (var u of list) {
203
235
  if (!u) continue;
@@ -214,6 +246,7 @@ var compress = function (scoped, maped) {
214
246
  }
215
247
  };
216
248
 
249
+
217
250
  class Program extends Array {
218
251
  COMMENT = COMMENT
219
252
  SPACE = SPACE
@@ -227,6 +260,21 @@ class Program extends Array {
227
260
  LABEL = LABEL
228
261
  PROPERTY = PROPERTY
229
262
  pressed = false
263
+ _scoped = null;
264
+ isExpress() {
265
+ if (!this.first) return false;
266
+ var first = this.first;
267
+ if (first.type === SCOPED) {
268
+ if (first.entry === '{') return false;
269
+ }
270
+ else if (first.type === STRAP) {
271
+ if (!/^(new|void|typeof|delete|class|function|await)/.test(first.text)) return false;
272
+ }
273
+ else if (!~[EXPRESS, STAMP, QUOTED, SCOPED, VALUE].indexOf(first.type)) return false;
274
+ var last = skipAssignment(this.first);
275
+ return this.lastUncomment === last || !last;
276
+ }
277
+
230
278
  toString() {
231
279
  var lasttype;
232
280
  var result = [];
@@ -267,7 +315,7 @@ class Program extends Array {
267
315
  result.push(o.leave);
268
316
  break;
269
317
  default:
270
- if ([STRAP, EXPRESS, VALUE].indexOf(lasttype) >= 0 && [STRAP, EXPRESS, VALUE].indexOf(o.type) >= 0) result.push(" ");
318
+ if ([STRAP, EXPRESS, PROPERTY, VALUE].indexOf(lasttype) >= 0 && [STRAP, EXPRESS, PROPERTY, VALUE].indexOf(o.type) >= 0) result.push(" ");
271
319
  if (o instanceof Object) {
272
320
  // var broker = needBreak(o.prev, o);
273
321
  // if (broker) result.push(broker);
@@ -301,12 +349,26 @@ class Program extends Array {
301
349
  this.forEach(run);
302
350
  return result.join("");
303
351
  }
304
- toScoped() {
305
- var used = Object.create(null); var vars = Object.create(null), lets = Object.create(null); var scoped = [];
352
+ get envs() {
353
+ return this.scoped.envs;
354
+ }
355
+ get vars() {
356
+ return this.scoped.vars;
357
+ }
358
+ get used() {
359
+ return this.scoped.used;
360
+ }
361
+ get scoped() {
362
+ if (this._scoped) return this._scoped;
363
+ var used = Object.create(null); var vars = Object.create(null), lets = vars;
364
+ var scoped = this._scoped = [];
365
+ scoped.code = this;
306
366
  var run = function (o, id) {
307
367
  loop: while (o) {
368
+ var isCatch = false;
308
369
  var isFunction = false;
309
370
  var isScope = false;
371
+ var isArrow = false;
310
372
  switch (o.type) {
311
373
  case QUOTED:
312
374
  if (o.length) {
@@ -315,15 +377,21 @@ class Program extends Array {
315
377
  break;
316
378
  case STAMP:
317
379
  break;
380
+ case PROPERTY:
381
+ if (o.next) {
382
+ if (o.next.type !== STAMP || o.next.text !== ",") break;
383
+ }
384
+ case VALUE:
385
+ if (program.number_reg.test(o.text)) break;
318
386
  case EXPRESS:
319
387
  if (o.prev && o.prev.type === EXPRESS) {
320
388
  if (/\.$/.test(o.prev.text)) break;
321
389
  }
322
390
  var u = o.text.split(".")[0];
323
- if (!u || program.value_reg.test(u)) break;
391
+ if (!u) break;
324
392
  if (o.next && o.next.type === STAMP && o.next.text === "=>") {
325
393
  isScope = true;
326
- isFunction = true;
394
+ isArrow = true;
327
395
  }
328
396
  else {
329
397
  saveTo(used, u, o);
@@ -333,6 +401,7 @@ class Program extends Array {
333
401
  var name = o.text;
334
402
  name = name.slice(0, name.length - 1);
335
403
  vars[name] = true;
404
+ o.kind = "label";
336
405
  saveTo(used, name, o);
337
406
  break;
338
407
 
@@ -345,7 +414,7 @@ class Program extends Array {
345
414
  case "let":
346
415
  case "const":
347
416
  m = m || lets;
348
- var [declared, used0, o0, skiped] = getDeclared(o.next);
417
+ var [declared, used0, o0, skiped] = getDeclared(o.next, s);
349
418
  while (skiped.length) {
350
419
  var o1 = run(skiped[0], 0);
351
420
  let sindex = skiped.indexOf(o1);
@@ -358,12 +427,15 @@ class Program extends Array {
358
427
  continue loop;
359
428
  case "function":
360
429
  isFunction = true;
430
+ case "catch":
431
+ isCatch = true;
361
432
  case "class":
362
433
  if (!o.isExpress) {
363
434
  o = o.next;
364
435
 
365
436
  if (o.type === EXPRESS) {
366
437
  vars[o.text] = true;
438
+ o.kind = isFunction ? 'function' : 'class';
367
439
  saveTo(used, o.text, o);
368
440
 
369
441
  o = o.next;
@@ -377,8 +449,8 @@ class Program extends Array {
377
449
  case SCOPED:
378
450
  if (o.entry === "(") {
379
451
  if (o.next && o.next.type === STAMP && o.next.text === "=>"
380
- || o.prev && o.prev.type === PROPERTY) {
381
- isFunction = true;
452
+ || o.prev && (o.prev.type === PROPERTY || o.prev.isprop)) {
453
+ isArrow = true;
382
454
  isScope = true;
383
455
  }
384
456
  else {
@@ -405,26 +477,29 @@ class Program extends Array {
405
477
  _scoped.push(scoped);
406
478
  var isExpress = o.isExpress;
407
479
 
408
- if (isFunction) {
480
+ if (isFunction || isArrow) {
409
481
  scoped.used = used;
410
482
  scoped.vars = vars;
411
483
  lets = vars;
484
+ if (isFunction) vars.this = true, vars.arguments = true;
485
+ isFunction = true;
412
486
  } else {
413
487
  vars = _vars;
414
488
  scoped.lets = lets;
415
489
  scoped.used = used;
416
490
  }
417
- if (o.next && o.next.type === STAMP && o.next.text === "=>");
491
+ if (isArrow);
418
492
  else if (o.isExpress && o.type !== SCOPED) {
419
493
  o = o.next;
420
494
  if (o.type === EXPRESS) {
421
495
  vars[o.text] = true;
496
+ o.kind = isFunction ? 'function' : 'class';
422
497
  saveTo(used, o.text, o);
423
498
  o = o.next;
424
499
  }
425
500
  }
426
- while (o.type !== SCOPED) {
427
- if (o.next && o.next.type === STAMP && o.next.text === "=>") break;
501
+ if (!isFunction) while (o.type !== SCOPED) {
502
+ // if (o.next && o.next.type === STAMP && o.next.text === "=>") break;
428
503
  o = run(o, 0);
429
504
  o = o.next;
430
505
  if (!o) break loop;
@@ -432,8 +507,8 @@ class Program extends Array {
432
507
 
433
508
  if (o.entry === "(") {
434
509
  o.isExpress = isExpress;
435
- if (isFunction) {
436
- var [declared, used0, o0, skiped] = getDeclared(o.first);
510
+ if (isFunction || isCatch) {
511
+ var [declared, used0, o0, skiped] = getDeclared(o.first, 'argument');
437
512
  mergeTo(used, used0);
438
513
  while (skiped.length) {
439
514
  var o1 = run(skiped[0], 0);
@@ -441,7 +516,7 @@ class Program extends Array {
441
516
  if (sindex < 0) break;
442
517
  skiped.splice(0, sindex + 1);
443
518
  }
444
- Object.assign(vars, declared);
519
+ Object.assign(isCatch ? lets : vars, declared);
445
520
  }
446
521
  else {
447
522
  run(o.first);
@@ -450,13 +525,14 @@ class Program extends Array {
450
525
  if (!o) break;
451
526
  if (o.type === STAMP && o.text === "=>") o = o.next;
452
527
  }
453
- else if (o.next && o.next.type === STAMP && o.next.text === "=>") {
528
+ else if (isArrow) {
454
529
  vars[o.text] = true;
530
+ o.kind = 'argument';
455
531
  saveTo(used, o.text, o);
456
532
  o = o.next.next;
457
533
  }
458
534
  if (!o) break;
459
- if (o.type === SCOPED) {
535
+ if (o.type === SCOPED && o.entry === "{") {
460
536
  o.isExpress = isExpress;
461
537
  run(o.first);
462
538
  }
@@ -466,8 +542,10 @@ class Program extends Array {
466
542
  o = run(o, 0);
467
543
  var next = o.next;
468
544
  if (!next) break;
469
- if (o.type === STAMP && /^(\+\+|\-\-)$/.test(o.text) || ~[EXPRESS, VALUE, QUOTED, SCOPED].indexOf(o.type)) {
470
- if (~[EXPRESS, VALUE, QUOTED, PROPERTY, LABEL].indexOf(next.type)) break;
545
+ var e = o;
546
+ if (o.type === STAMP && /^(\+\+|\-\-)$/.test(o.text) || ~[VALUE, QUOTED, SCOPED].indexOf(o.type) || EXPRESS === o.type && !/\.$/.test(o.text)) {
547
+ if (~[VALUE, QUOTED, PROPERTY, LABEL].indexOf(next.type)) break;
548
+ if (EXPRESS === next.type && !/^\./.test(next.text)) break;
471
549
  if (next.type === SCOPED && next.entry === "{") break;
472
550
  }
473
551
  o = next;
@@ -475,13 +553,16 @@ class Program extends Array {
475
553
  }
476
554
  var map = isFunction ? vars : lets;
477
555
  for (var k in used) {
478
- // if (k === 'areTypesComparable') console.log(vars, lets, isFunction);
479
556
  if (!(k in map)) {
480
557
  for (var u of used[k]) {
481
558
  saveTo(_used, k, u);
482
559
  }
483
560
  }
484
561
  }
562
+ if (vars.this) {
563
+ delete vars.this;
564
+ delete vars.arguments;
565
+ }
485
566
  used = _used;
486
567
  lets = _lets;
487
568
  vars = _vars;
@@ -495,13 +576,30 @@ class Program extends Array {
495
576
  run(this.first);
496
577
  scoped.used = used;
497
578
  scoped.vars = vars;
498
- scoped.lets = lets;
499
- return scoped;
579
+ var envs = Object.create(null);
580
+ for (var u in used) {
581
+ if (!(u in vars)) {
582
+ if (!/^(true|false|null|this|arguments)$/.test(u)) envs[u] = true;
583
+ }
584
+ }
585
+ scoped.envs = envs;
586
+ return this._scoped;
587
+ }
588
+ getUndecleared() {
589
+ return this.envs;
590
+ }
591
+ // 绕开低版本ie的异常属性
592
+ detour() {
593
+ }
594
+ // 标记要保留的代码
595
+ ahchor() { }
596
+ // 清理无效的代码
597
+ clean() {
500
598
  }
599
+ // 压缩
501
600
  press() {
502
601
  this.pressed = true;
503
- var scoped = this.toScoped();
504
- compress(scoped);
602
+ compress(this.scoped);
505
603
  return this;
506
604
  }
507
605
  }
@@ -525,7 +623,7 @@ class Javascript {
525
623
  stamps = "/=+;|:?<>-!~@#%^&*,".split("")
526
624
  value_reg = /^(false|true|null|Infinity|NaN|undefined|arguments|this)$/
527
625
  number_reg = /^[\+\-]?(0x[0-9a-f]+|0b\d+|0o\d+|(\d*\.\d+|\d+\.?)(e[\+\-]?\d+|[mn])?)$/i;
528
- transive = /^(new|void|in|of|typeof|delete|case|return|await|export|default|instanceof|throw|extends|import|from)$/
626
+ transive = /^(new|var|let|const|yield|void|in|of|typeof|delete|case|return|await|export|default|instanceof|throw|extends|import|from)$/
529
627
  straps = `if,in,do,as,of
530
628
  var,for,new,try,let
531
629
  else,case,void,with,enum,from
@@ -563,6 +661,9 @@ class Javascript {
563
661
  queue.__proto__ = Program.prototype;
564
662
  var origin = queue;
565
663
  var queue_push = function (scope) {
664
+ if (~[VALUE, QUOTED, SCOPED, EXPRESS, PROPERTY].indexOf(scope.type)) {
665
+ scope.isprop = isProperty();
666
+ }
566
667
  var last = queue.lastUncomment;
567
668
  if (scope.type !== COMMENT && scope.type !== SPACE) {
568
669
  if (last) {
@@ -585,10 +686,13 @@ class Javascript {
585
686
  var save = (type) => {
586
687
  if (lasttype === STAMP && type === STAMP && !/[,;\:\?]/.test(m)) {
587
688
  var scope = queue[queue.length - 1];
588
- scope.end = end;
589
- scope.text = text.slice(scope.start, scope.end);
590
- queue.inExpress = true;
591
- return;
689
+ if (/=>$/i.test(scope.text) || /=$/.test(scope.text) && /[^>=]/.test(m)) {
690
+ } else {
691
+ scope.end = end;
692
+ scope.text = text.slice(scope.start, scope.end);
693
+ queue.inExpress = true;
694
+ return;
695
+ }
592
696
  }
593
697
  var last = queue.lastUncomment;
594
698
  switch (type) {
@@ -605,12 +709,33 @@ class Javascript {
605
709
  type = EXPRESS;
606
710
  }
607
711
  else if (isProperty()) type = PROPERTY;
608
- else if (m === "as") {
609
- if (!last || last.type === STAMP) {
712
+ else if (m === 'from') {
713
+ if (!last || last.type === STRAP && last.text !== 'import') {
610
714
  type = EXPRESS;
611
715
  break;
612
716
  }
613
- if (~[EXPRESS, VALUE].indexOf(last.type)) last.type = PROPERTY;
717
+ var temp = last;
718
+ while (temp.type === EXPRESS || temp.type === VALUE || temp.type === SCOPED) {
719
+ var prev = last.prev;
720
+ if (!prev) break;
721
+ if (prev.type !== STAMP || prev.text !== ',') break;
722
+ temp = prev.prev;
723
+ if (!temp) break;
724
+ }
725
+ if (temp.type !== STRAP || temp.text !== 'import') {
726
+ type = EXPRESS;
727
+ }
728
+ }
729
+ else if (m === 'as') {
730
+ if (!last) {
731
+ type = EXPRESS;
732
+ break;
733
+ }
734
+ if (~[EXPRESS, VALUE].indexOf(last.type)) {
735
+ last.type = PROPERTY;
736
+ } else {
737
+ type = EXPRESS;
738
+ }
614
739
  }
615
740
  break;
616
741
  case STAMP:
@@ -658,6 +783,7 @@ class Javascript {
658
783
  queue.inExpress = false;
659
784
  break check;
660
785
  }
786
+ if (!temp.isExpress) break;
661
787
  temp = temp.prev;
662
788
  }
663
789
  queue.inExpress = false;
@@ -769,6 +895,7 @@ class Javascript {
769
895
  parents.push(queue);
770
896
  queue = scope;
771
897
  lasttype = scope.type;
898
+ var m0 = m;
772
899
  while (index < text.length) {
773
900
  var reg = quote.reg;
774
901
  reg.lastIndex = index;
@@ -777,7 +904,6 @@ class Javascript {
777
904
  index = text.length;
778
905
  break;
779
906
  }
780
- var m1 = m;
781
907
  var m = match[0];
782
908
  index = this.lastIndex = match.index + m.length;
783
909
  if (quote.length === 2) {
@@ -790,8 +916,8 @@ class Javascript {
790
916
  continue;
791
917
  }
792
918
  if (quote.length >= 4 && m in quote.entry) {
793
- queue.entry = m1;
794
- start += m1.length;
919
+ queue.entry = m0;
920
+ start += m0.length;
795
921
  push_quote();
796
922
  continue loop;
797
923
  }
@@ -849,14 +975,20 @@ class Javascript {
849
975
  scope.inExpress = false;
850
976
  }
851
977
  }
852
- else if (!queue.lastUncomment || ~[STAMP, STRAP].indexOf(queue.lastUncomment.type)) {
853
- scope.inExpress = queue.inExpress;
854
- if (queue.inExpress) scope.isObject = true;
855
- else if (queue.lastUncomment && queue.lastUncomment.text !== "=>") scope.isObject = scope.inExpress;
978
+ else if (!queue.lastUncomment) {
979
+ scope.isObject = queue.inExpress;
856
980
  }
857
- else {
858
- scope.inExpress = false;
981
+ else if (queue.lastUncomment.type === STAMP) {
982
+ if (queue.lastUncomment.text === ':') {
983
+ scope.isObject = queue.inExpress;
984
+ }
985
+ else scope.isObject = !/^(;|\+\+|\-\-|=>)$/.test(queue.lastUncomment.text);
986
+ }
987
+ else if (STRAP === queue.lastUncomment.type) {
988
+ if (queue[queue.length - 1].type === SPACE && queue.lastUncomment.text === 'return');
989
+ else scope.isObject = queue.inExpress;
859
990
  }
991
+ queue.inExpress = scope.isObject;
860
992
  }
861
993
  else {
862
994
  scope.isExpress = queue.inExpress;