efront 4.10.1 → 4.10.2

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.
@@ -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,34 +369,46 @@ 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) {
391
- if (last.type === STAMP && last.text === "?") {
392
- if (o.type === EXPRESS && /^\.[^\.]|^\.$/.test(o.text)) {
393
- last.type = EXPRESS;
394
- var q = o.queue;
395
- q.question--;
396
- return false;
397
- }
398
- }
399
386
  if (o.type === STRAP && o.text === "function") {
400
387
  if (last.text === 'async' && !last.isend) last.type = STRAP;
401
388
  }
402
- if ((o.type & (EXPRESS | STRAP) && last.type === STAMP || o.type === STAMP && /^([\|\&]|\=\>)$/.test(o.text)) && (last.istype || queue.istype)) {
389
+ if ((o.type & (EXPRESS | STRAP) && last.type === STAMP || o.type === STAMP && /^([\|\&]|\=\>)$/.test(o.text)) && (last.istype || last.isargl)) {
403
390
  o.istype = true;
404
391
  }
392
+ if (queue.isargl) {
393
+ if (last.type === STAMP && /^[,;]$/.test(last.text)) {
394
+ o.isarg = true;
395
+ };
396
+ }
397
+ if (o.type === STAMP && o.needle) {
398
+ // o.type = EXPRESS;
399
+ }
405
400
  }
406
401
  else {
407
- if (queue.istype) {
402
+ if (queue.isargl) {
403
+ o.isarg = true;
404
+ }
405
+ else if (queue.istype) {
408
406
  o.istype = true;
409
407
  }
410
408
  }
409
+ if (o.isarg && o.type === STRAP) {
410
+ o.type = EXPRESS;
411
+ }
411
412
 
412
413
  fixType(o);
413
414
  if (queue.isObject || queue.isClass) {
@@ -434,12 +435,17 @@ Javascript.prototype.setType = function (o) {
434
435
  if (last && last.type === PROPERTY && propresolve_reg.test(last.text) && (o.type !== SCOPED || o.entry === "[")) {
435
436
  last.type = STRAP;
436
437
  }
437
- if (queue.isClass) o.isend = false;
438
438
  }
439
439
  }
440
440
  if (o.isprop);
441
441
  else if (o.type === STRAP) {
442
- if (this.type_reg.test(o.text)) o.istype = true;
442
+ if (this.type_reg.test(o.text) && !this.funcstrap_reg.test(o.text)) {
443
+ if (last) {
444
+ if (last.type === STRAP && last.transive && !last.isend || last.type === STAMP && queue.inExpress) {
445
+ o.type = EXPRESS;
446
+ }
447
+ }
448
+ }
443
449
  if (propresolve_reg.test(o.text)) o.type = EXPRESS;
444
450
  }
445
451
  if (last) {
@@ -450,22 +456,6 @@ Javascript.prototype.setType = function (o) {
450
456
  }
451
457
  }
452
458
  }
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
459
  };
470
460
 
471
461
  var js = new Javascript;
@@ -544,23 +534,18 @@ function detour(o, ie) {
544
534
  case SCOPED:
545
535
  detour(o.first, ie);
546
536
  break;
547
- case EXPRESS:
548
- var text = o.text.replace(/^\.\.\./, '');
549
- var hasdot = o.text.length !== text.length;
550
- if (context.avoidMap) {
551
- var m = /^[^\.\[\]]+/.exec(o.text);
552
- if (m) { context.avoidMap[m[0]] = true; }
553
- }
554
- if (/\?\.|\?\?/.test(text)) {
555
- o = snapExpressHead(o);
537
+ case STAMP:
538
+ if (o.text === "?.") {
539
+ var h = snapExpressHead(o);
556
540
  var f = snapExpressFoot(o);
541
+ o = h;
557
542
  var rest = [o];
558
- remove(o, f.prev);
559
543
  while (o !== f) {
560
544
  o = o.next;
561
545
  rest.push(o);
562
546
  }
563
547
  text = createString(rest);
548
+ remove(h, f.prev);
564
549
  text = renderExpress(text, false);
565
550
  if (hasdot) text = "..." + text;
566
551
  var o1 = scan(text);
@@ -570,6 +555,23 @@ function detour(o, ie) {
570
555
  o = o1.last;
571
556
  continue;
572
557
  }
558
+ else if (o.text === '.') {
559
+ var n = o.next;
560
+ remove(o);
561
+ if (n.type === EXPRESS) {
562
+ n.text = `[${strings.recode(n.text)}]`;
563
+ }
564
+ o = n;
565
+ continue;
566
+ }
567
+ break;
568
+ case EXPRESS:
569
+ var text = o.text.replace(/^\.\.\./, '');
570
+ var hasdot = o.text.length !== text.length;
571
+ if (context.avoidMap) {
572
+ var m = /^[^\.\[\]]+/.exec(o.text);
573
+ if (m) { context.avoidMap[m[0]] = true; }
574
+ }
573
575
  text = text.replace(/\.([^\.\[\!\=\:]+)/g, (_, a) => ie === undefined || context.strap_reg.test(a) || /#/.test(a) ? `[${strings.recode(a)}]` : _);
574
576
  if (hasdot) text = "..." + text;
575
577
  o.text = text;
@@ -906,6 +908,17 @@ Javascript.prototype.fix = function (code) {
906
908
  }
907
909
  var requires = code.used.require;
908
910
  imports = imports.filter(m => {
911
+ if (m.next?.text === '.') {
912
+ var o = m;
913
+ var s = snapExpressFoot(o);
914
+ var a = [o];
915
+ while (o !== s) {
916
+ o = o.next;
917
+ a.push(o);
918
+ }
919
+ m.text = createString(a);
920
+ remove(m.next, s);
921
+ }
909
922
  if (/^import\.meta($|\.)/.test(m.text)) {
910
923
  m.text = m.text.replace(/\./, '_');
911
924
  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,10 @@ 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' {}
111
-
113
+ a <= 1;
112
114
  `)