efront 4.10.1 → 4.11.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.
@@ -1,4 +1,4 @@
1
- 国际化工具的时的语法如下:
1
+ 国际化工具的使用时的语法如下:
2
2
  ```javascript
3
3
  i18n`中文内容${参数}`
4
4
  ```
@@ -0,0 +1,16 @@
1
+ var sortRegister = function (list) {
2
+ var found = 0;
3
+ a: for (var cx = 0, dx = list.length; cx < dx; cx++) {
4
+ for (var cy = found + 1, dy = dx; cy < dy; cy++) {
5
+ if (cy !== cx && list[cy].indexOf(list[cx]) >= 0) continue a;
6
+ }
7
+ if (found !== cx) {
8
+ var temp = list[found];
9
+ list[found] = list[cx];
10
+ list[cx] = temp;
11
+ }
12
+ cx = found++;
13
+ }
14
+ return list;
15
+ }
16
+ module.exports = sortRegister;
@@ -1,3 +1,3 @@
1
1
  function nullish_(a, b) {
2
- return a === null || a === undefined ? b : a;
2
+ return a == null ? b : a;
3
3
  }
@@ -83,7 +83,7 @@ class Html extends Javascript {
83
83
  }
84
84
  var property = new Program;
85
85
  property.stamps = "=".split('');
86
- var p = new Program;
86
+ var p = new Javascript;
87
87
  var replaceISO8859 = function (data) {
88
88
  return String(data).replace(/<\!--([\s\S]*)--\>$/g, '$1').replace(/&\w+;/g, a => iso8859[a] || a).replace(/&#(\d+);/g, (_, a) => String.fromCodePoint(a))
89
89
  };
@@ -109,6 +109,7 @@ Html.prototype.createScoped = function (code) {
109
109
  var inScript = false;
110
110
  var noTag = true;
111
111
  var run = function (c) {
112
+
112
113
  switch (c.type) {
113
114
  case ELEMENT:
114
115
  var v = toCamelCase(c.tag);
@@ -155,6 +156,7 @@ Html.prototype.createScoped = function (code) {
155
156
  break;
156
157
  case QUOTED:
157
158
  case PIECE:
159
+
158
160
  if (c.length) {
159
161
  c.forEach(run);
160
162
  break;
@@ -181,6 +183,7 @@ Html.prototype.createScoped = function (code) {
181
183
  break;
182
184
  }
183
185
  };
186
+
184
187
  code.forEach(run);
185
188
  var envs = Object.create(null);
186
189
  for (var k in used) {
@@ -227,6 +230,7 @@ Html.prototype.createScoped = function (code) {
227
230
  scoped.envs = envs;
228
231
  scoped.vars = vars;
229
232
  scoped.used = used;
233
+
230
234
  return scoped;
231
235
  };
232
236
  Html.prototype.createString = common.createString;
@@ -47,10 +47,9 @@ class Javascript extends Program {
47
47
  transive_reg = /^(new|var|let|const|yield|void|in|of|typeof|delete|case|return|await|default|instanceof|throw|extends|import|from)$/
48
48
  strapexp_reg = /^(new|void|typeof|delete|class|function|await)/;
49
49
  forceend_reg = /^(return|yield|break|continue|debugger|async)$/;
50
- type_reg = /^(var|let|const|function|class|interface|type)$/;
51
50
  defaultType = EXPRESS;
52
51
  }
53
- var propresolve_reg = /^(static|get|set|async|readonly|private)$/;
52
+ var propresolve_reg = /^(static|get|set|async|readonly|private|pub)$/;
54
53
 
55
54
  var isProperty = function (o) {
56
55
  var queue = o.queue;
@@ -83,13 +82,7 @@ var isProperty = function (o) {
83
82
  return false;
84
83
  };
85
84
  var setStrapExpress = function (mark_type, mark_text, prop, o, default_type) {
86
- var prev = o.prev;
87
- if (prev && prev.type === STRAP && /^(?:function|class|let|const|var)$/.test(prev.text)) {
88
- o.type = EXPRESS;
89
- return;
90
- }
91
85
  var type = o.type;
92
- if (type !== STRAP) return;
93
86
  var h = snapExpressHead(o);
94
87
  var isfunc = h?.prev?.type === STAMP && h.prev.text === '=>';
95
88
  var q = o.queue;
@@ -218,12 +211,6 @@ var fixType = function (o) {
218
211
  }
219
212
  break;
220
213
  }
221
- if (type === STRAP && /^(class|interface)$/.test(m) && !queue.classed) {
222
- queue.classed = [m];
223
- }
224
- else if (queue.classed) {
225
- if (type === STRAP && /^(class|function|interface)$/.test(m)) queue.classed.push(m);
226
- }
227
214
  if (type === PROPERTY) o.isprop = true;
228
215
  o.type = type;
229
216
 
@@ -322,11 +309,13 @@ var detectLabel = function (o) {
322
309
  inExpress = true;
323
310
  break;
324
311
  case ":":
312
+
325
313
  if (queue.question) {
326
314
  queue.question--;
327
315
  if (last.type === STAMP && last.text === '?') {
328
316
  inExpress = false;
329
317
  o.istype = true;
318
+ last.istype = true;
330
319
  last.type = EXPRESS;
331
320
  }
332
321
  else {
@@ -354,7 +343,7 @@ var detectLabel = function (o) {
354
343
  if (!temp.isExpress) break;
355
344
  temp = temp.prev;
356
345
  }
357
- if (last.type & (EXPRESS | STRAP | VALUE | QUOTED)) {
346
+ if (!queue.isargl && last.type & (EXPRESS | STRAP | VALUE | QUOTED)) {
358
347
  // label
359
348
  var lp = last.prev;
360
349
  if (!lp || lp.type !== STRAP || lp.isend) {
@@ -380,11 +369,17 @@ var detectLabel = function (o) {
380
369
 
381
370
  Javascript.prototype.setType = function (o) {
382
371
  if (detectLabel(o)) return false;
383
- switch (o.text) {
372
+ var last = o.prev;
373
+ if (last?.type === STRAP && o.type === STRAP && this.type_reg.test(last.text)) {
374
+ if (/^(yield|await|async)$/.test(o.text)) o.type = EXPRESS;
375
+ }
376
+ if (o.type === STRAP) switch (o.text) {
384
377
  case "yield": setYieldExpress(o, this.defaultType); break;
385
378
  case "await": setAwaitExpress(o, this.defaultType); break;
386
379
  }
387
- var last = o.prev;
380
+ if (o.type === EXPRESS && last?.type === EXPRESS && !last.isend && /^(async|await|yield)$/.test(last.text)) {
381
+ last.type = STRAP;
382
+ }
388
383
  var queue = o.queue;
389
384
 
390
385
  if (last) {
@@ -399,15 +394,29 @@ Javascript.prototype.setType = function (o) {
399
394
  if (o.type === STRAP && o.text === "function") {
400
395
  if (last.text === 'async' && !last.isend) last.type = STRAP;
401
396
  }
402
- if ((o.type & (EXPRESS | STRAP) && last.type === STAMP || o.type === STAMP && /^([\|\&]|\=\>)$/.test(o.text)) && (last.istype || queue.istype)) {
397
+ if ((o.type & (EXPRESS | STRAP) && last.type === STAMP || o.type === STAMP && /^([\|\&]|\=\>)$/.test(o.text)) && (last.istype || last.isargl)) {
403
398
  o.istype = true;
404
399
  }
400
+ if (queue.isargl) {
401
+ if (last.type === STAMP && /^[,;]$/.test(last.text)) {
402
+ o.isarg = true;
403
+ };
404
+ }
405
+ if (o.type === STAMP && o.needle) {
406
+ // o.type = EXPRESS;
407
+ }
405
408
  }
406
409
  else {
407
- if (queue.istype) {
410
+ if (queue.isargl) {
411
+ o.isarg = true;
412
+ }
413
+ else if (queue.istype) {
408
414
  o.istype = true;
409
415
  }
410
416
  }
417
+ if (o.isarg && o.type === STRAP) {
418
+ o.type = EXPRESS;
419
+ }
411
420
 
412
421
  fixType(o);
413
422
  if (queue.isObject || queue.isClass) {
@@ -434,12 +443,17 @@ Javascript.prototype.setType = function (o) {
434
443
  if (last && last.type === PROPERTY && propresolve_reg.test(last.text) && (o.type !== SCOPED || o.entry === "[")) {
435
444
  last.type = STRAP;
436
445
  }
437
- if (queue.isClass) o.isend = false;
438
446
  }
439
447
  }
440
448
  if (o.isprop);
441
449
  else if (o.type === STRAP) {
442
- if (this.type_reg.test(o.text)) o.istype = true;
450
+ if (this.type_reg.test(o.text) && !this.funcstrap_reg.test(o.text)) {
451
+ if (last) {
452
+ if (last.type === STRAP && last.transive && !last.isend || last.type === STAMP && queue.inExpress) {
453
+ o.type = EXPRESS;
454
+ }
455
+ }
456
+ }
443
457
  if (propresolve_reg.test(o.text)) o.type = EXPRESS;
444
458
  }
445
459
  if (last) {
@@ -450,22 +464,6 @@ Javascript.prototype.setType = function (o) {
450
464
  }
451
465
  }
452
466
  }
453
- if (o.type === STAMP) {
454
- if (!last || last.type & (STAMP | STRAP) && !/^(\+\+|\-\-)$/.test(last.text) && !last.istype || last.type === SCOPED && /^[\{\[]$/.test(last.entry) && !last.isExpress) {
455
- o.unary = /^[^=;,\*]$|.[^\=\>\<\|\&\^]$/.test(o.text);
456
- if (o.unary && /^(\+|\-)$/.test(o.text) && last && last.type === STAMP && /^(\+\+|\-\-)$/.test(last.text)) o.unary = !!last.unary;
457
- }
458
- if (last && /^(\+\+|\-\-)$/.test(o.text)) {
459
- var i = 1;
460
- var p = queue[queue.length - i];
461
- if (p === o) p = queue[queue.length - ++i];
462
- while (p && p.type & (SPACE | COMMENT)) {
463
- if (p.type === SPACE && /[\r\n\u2028\u2029]/.test(p.text)) break;
464
- p = queue[queue.length - ++i];
465
- }
466
- o.unary = !p || p.type & (SPACE | STAMP | STRAP) || p.type === EXPRESS && p.prev && p.prev.type === STAMP && /^(\+\+|\-\-)$/.test(p.prev.text) && p.prev.unary;
467
- }
468
- }
469
467
  };
470
468
 
471
469
  var js = new Javascript;
@@ -538,38 +536,60 @@ Javascript.prototype.detour = function (body, ie) {
538
536
  return envs;
539
537
  }
540
538
  var context = null, rootenvs = null;
539
+ var detourNullishSeek = function (o, ie) {
540
+ var h = snapExpressHead(o);
541
+ var f = snapExpressFoot(o);
542
+ o = h;
543
+ var rest = [o];
544
+ while (o !== f) {
545
+ o = o.next;
546
+ rest.push(o);
547
+ }
548
+ var text = createString(rest);
549
+ var text1 = text.replace(/^\.\.\./, '');
550
+ var hasdot = text1.length !== text.length;
551
+ remove(h, f.prev);
552
+ text = renderExpress(text1, false);
553
+ if (hasdot) text = "..." + text;
554
+ var o1 = scan(text);
555
+ detour(o1.first, ie);
556
+ patchArrawScope(o1, o);
557
+ replace(o, ...o1);
558
+ o = o1.last;
559
+ return o;
560
+ }
541
561
  function detour(o, ie) {
542
562
  while (o) {
543
563
  switch (o.type) {
544
564
  case SCOPED:
545
565
  detour(o.first, ie);
546
566
  break;
567
+ case STAMP:
568
+ if (o.text === "?.") {
569
+ o = detourNullishSeek(o, ie);
570
+ continue;
571
+ }
572
+ else if (o.text === '.') {
573
+ var n = o.next;
574
+ remove(o);
575
+ if (n.type === EXPRESS) {
576
+ n.text = `[${strings.recode(n.text)}]`;
577
+ }
578
+ o = n;
579
+ continue;
580
+ }
581
+ break;
547
582
  case EXPRESS:
583
+ if (/^\?\./.test(o.text)) {
584
+ o = detourNullishSeek(o, ie);
585
+ continue;
586
+ }
548
587
  var text = o.text.replace(/^\.\.\./, '');
549
588
  var hasdot = o.text.length !== text.length;
550
589
  if (context.avoidMap) {
551
590
  var m = /^[^\.\[\]]+/.exec(o.text);
552
591
  if (m) { context.avoidMap[m[0]] = true; }
553
592
  }
554
- if (/\?\.|\?\?/.test(text)) {
555
- o = snapExpressHead(o);
556
- var f = snapExpressFoot(o);
557
- var rest = [o];
558
- remove(o, f.prev);
559
- while (o !== f) {
560
- o = o.next;
561
- rest.push(o);
562
- }
563
- text = createString(rest);
564
- text = renderExpress(text, false);
565
- if (hasdot) text = "..." + text;
566
- var o1 = scan(text);
567
- detour(o1.first, ie);
568
- patchArrawScope(o1, o);
569
- replace(o, ...o1);
570
- o = o1.last;
571
- continue;
572
- }
573
593
  text = text.replace(/\.([^\.\[\!\=\:]+)/g, (_, a) => ie === undefined || context.strap_reg.test(a) || /#/.test(a) ? `[${strings.recode(a)}]` : _);
574
594
  if (hasdot) text = "..." + text;
575
595
  o.text = text;
@@ -719,14 +739,21 @@ var removeImport = function (c, i, code) {
719
739
  var t = null;
720
740
  if (n && n.type === EXPRESS) {
721
741
  t = Object.create(null);
722
- var ts = n.text.split(".")
723
- for (var e of ts) {
724
- t[e] = true;
742
+ removeFromList(used[n.tack], n);
743
+ while (n?.type === EXPRESS) {
744
+ var ts = n.text.split(".")
745
+ for (var e of ts) {
746
+ t[e] = true;
747
+ }
748
+ var ni = code.indexOf(n, i);
749
+ n = n.next;
750
+ if (n?.needle) {
751
+ n = n.next;
752
+ var ne = code.indexOf(n, ni);
753
+ splice(code, ni, ne - ni);
754
+ }
755
+ else splice(code, ni, 1);
725
756
  }
726
- var ni = code.indexOf(n, i);
727
- removeFromList(used[ts[0]], n);
728
- splice(code, ni, 1);
729
- n = n.next;
730
757
  }
731
758
  if (!n || n.type !== QUOTED) throw new Error(i18n`缺少导入路径!`);
732
759
  var ns = skipAssignment(n);
@@ -906,6 +933,17 @@ Javascript.prototype.fix = function (code) {
906
933
  }
907
934
  var requires = code.used.require;
908
935
  imports = imports.filter(m => {
936
+ if (m.next?.text === '.') {
937
+ var o = m;
938
+ var s = snapExpressFoot(o);
939
+ var a = [o];
940
+ while (o !== s) {
941
+ o = o.next;
942
+ a.push(o);
943
+ }
944
+ m.text = createString(a);
945
+ remove(m.next, s);
946
+ }
909
947
  if (/^import\.meta($|\.)/.test(m.text)) {
910
948
  m.text = m.text.replace(/\./, '_');
911
949
  return true;
@@ -1,9 +1,11 @@
1
1
  // 导入
2
+ var js = new Javascript;
2
3
  var testFix = function (a, e) {
3
- var c = scanner2(a);
4
+ var c = scanner2(a, js);
4
5
  c.fix();
5
6
  assert(c.toString(), e);
6
7
  }
8
+ js.debug = true;
7
9
  testFix(`import a from "a";console.log(a)`, 'var a = require("a"); console.log(a.default)');
8
10
  testFix(`import {a} from "a";console.log(a)`, 'var a1 = require("a"); console.log(a1.a)');
9
11
  testFix(`import a,{a as b} from "a";console.log(a,b)`, 'var a = require("a"); console.log(a.default, a.a)');
@@ -103,10 +105,20 @@ interface WritableOptions extends StreamOptions<Writable> {
103
105
  ): void;
104
106
  final?(this: Writable, callback: (error?: Error | null) => void): void;
105
107
  }`);
106
- common.debug=true;
108
+ common.debug = true;
107
109
  testTypescript(`
108
- while(++i < 2) {}
109
- a ? function() {} : function() {}
110
+ while (++i < 2) {}
111
+ a ? function () {} : function () {}
110
112
  declare module 'buffer' {}
113
+ a <= 1;
114
+ `)
111
115
 
112
- `)
116
+ var testPress = function (text, expect) {
117
+ var code = scanner2(text);
118
+ code.press(false);
119
+ assert(code.toString(), expect);
120
+ };
121
+ testPress(`if(){}\r\nelse {}`, `if(){}else{}`)
122
+ testPress(`if(a)a={}\r\nelse{}`, `if(a)a={};else{}`)
123
+ testPress(`if()a=function(){}\r\nelse {}`,`if()a=function(){};else{}`)
124
+ testPress(`if()function a(){}\r\nelse {}`,`if()function a(){}else{}`)