efront 4.10.2 → 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
  ```
@@ -383,6 +383,14 @@ Javascript.prototype.setType = function (o) {
383
383
  var queue = o.queue;
384
384
 
385
385
  if (last) {
386
+ if (last.type === STAMP && last.text === "?") {
387
+ if (o.type === EXPRESS && /^\.[^\.]|^\.$/.test(o.text)) {
388
+ last.type = EXPRESS;
389
+ var q = o.queue;
390
+ q.question--;
391
+ return false;
392
+ }
393
+ }
386
394
  if (o.type === STRAP && o.text === "function") {
387
395
  if (last.text === 'async' && !last.isend) last.type = STRAP;
388
396
  }
@@ -528,6 +536,28 @@ Javascript.prototype.detour = function (body, ie) {
528
536
  return envs;
529
537
  }
530
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
+ }
531
561
  function detour(o, ie) {
532
562
  while (o) {
533
563
  switch (o.type) {
@@ -536,23 +566,7 @@ function detour(o, ie) {
536
566
  break;
537
567
  case STAMP:
538
568
  if (o.text === "?.") {
539
- var h = snapExpressHead(o);
540
- var f = snapExpressFoot(o);
541
- o = h;
542
- var rest = [o];
543
- while (o !== f) {
544
- o = o.next;
545
- rest.push(o);
546
- }
547
- text = createString(rest);
548
- remove(h, f.prev);
549
- text = renderExpress(text, false);
550
- if (hasdot) text = "..." + text;
551
- var o1 = scan(text);
552
- detour(o1.first, ie);
553
- patchArrawScope(o1, o);
554
- replace(o, ...o1);
555
- o = o1.last;
569
+ o = detourNullishSeek(o, ie);
556
570
  continue;
557
571
  }
558
572
  else if (o.text === '.') {
@@ -566,6 +580,10 @@ function detour(o, ie) {
566
580
  }
567
581
  break;
568
582
  case EXPRESS:
583
+ if (/^\?\./.test(o.text)) {
584
+ o = detourNullishSeek(o, ie);
585
+ continue;
586
+ }
569
587
  var text = o.text.replace(/^\.\.\./, '');
570
588
  var hasdot = o.text.length !== text.length;
571
589
  if (context.avoidMap) {
@@ -721,14 +739,21 @@ var removeImport = function (c, i, code) {
721
739
  var t = null;
722
740
  if (n && n.type === EXPRESS) {
723
741
  t = Object.create(null);
724
- var ts = n.text.split(".")
725
- for (var e of ts) {
726
- t[e] = true;
727
- }
728
- var ni = code.indexOf(n, i);
729
- removeFromList(used[ts[0]], n);
730
- splice(code, ni, 1);
731
- n = n.next;
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);
756
+ }
732
757
  }
733
758
  if (!n || n.type !== QUOTED) throw new Error(i18n`缺少导入路径!`);
734
759
  var ns = skipAssignment(n);
@@ -111,4 +111,14 @@ while (++i < 2) {}
111
111
  a ? function () {} : function () {}
112
112
  declare module 'buffer' {}
113
113
  a <= 1;
114
- `)
114
+ `)
115
+
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{}`)
@@ -102,7 +102,7 @@ class Program {
102
102
  ["[", "]"],
103
103
  ["{", "}"],
104
104
  ]
105
- stamps = "/=+;|:?<>-!~%^&*,.".split("")
105
+ stamps = "/=+;|:?<>-!~%^&*,".split("")
106
106
  value_reg = /^(false|true|null)$/
107
107
  number_reg = number_reg;
108
108
  Code = Array;
@@ -726,7 +726,7 @@ class Program {
726
726
  save(SPACE);
727
727
  }
728
728
  else {
729
- if (this.keepspace) save(SPACE);
729
+ if (this.keepspace || start === 0) save(SPACE);
730
730
  }
731
731
  lasttype = SPACE;
732
732
  continue;
@@ -999,8 +999,10 @@ class Program {
999
999
  this.space_reg = new RegExp(`^[${spaces}]+$`, flagUnicode);
1000
1000
  this.space_exp = new RegExp(`[${spaces}]+`, flagUnicode);
1001
1001
  var quotes_entries = this.createRegExp(this.comments.concat(this.quotes).map(q => q[0]), true).source;
1002
- var powers = Object.keys(this.powermap).filter(k => this.stamp_reg.test(k));
1002
+ var powers = Object.keys(this.powermap).filter(k => k.length > 1 && this.stamp_reg.test(k));
1003
1003
  var powers_entries = this.createRegExp(this.tags.map(t => t[0]).concat(powers), true).source;
1004
+ var entries_reg = new RegExp(`^(${powers_entries}|${quotes_entries}|${scopes})$`, this.nocase ? 'iu' : '');
1005
+ stamps = this.compile(this.stamps.filter(s => !entries_reg.test(s)).join(''));
1004
1006
  this.entry_reg = new RegExp([`[${spaces}]+|${quotes_entries}|[${scopes}]|${number_reg.source.replace(/^\^|\$$/g, "")}[^${tokens}]*|${express}|${powers_entries}|[${stamps}]`], "gi" + flagUnicode);
1005
1007
  }
1006
1008
  }
@@ -17,7 +17,7 @@ const [
17
17
  var number_reg = /^(?:(?:0x[0-9a-f]+|0b[01]+|0o?[0-7]+)(?:_[0-9a-f]+)*|(?:(?:(?:\d+_)*\d+|\d*)\.\d+(?:_\d+)*|(?:\d+_)*\d+\.?))(?:e[\+\-]?\d+(?:_\d+)*|[hijklmnu]+)?/i;
18
18
  var equal_reg = /^(?:[\+\-\*\/~\^&\|%]|\*\*|>>>?|<<)?\=$|^(?:\+\+|\-\-)$/;
19
19
  var needhead_reg = /^\?|^\.(?:[^\.]|$)|^\[/;
20
- var needfoot_reg = /(\:\:|([^\.]|^)\.)$/;
20
+ var needfoot_reg = /(\:\:|\.)$/;
21
21
  var skipAssignment = function (o, cx) {
22
22
  if (!o) return;
23
23
  var next = arguments.length === 1 ? function () {
@@ -115,6 +115,10 @@ var skipAssignment = function (o, cx) {
115
115
  next();
116
116
  break;
117
117
  }
118
+ if (needfoot_reg.test(o.text)) {
119
+ next();
120
+ break;
121
+ }
118
122
  var prev = o.prev;
119
123
  if (prev?.type === EXPRESS && needfoot_reg.test(prev.text)) {
120
124
  next();
@@ -1356,7 +1360,7 @@ var createString = function (parsed) {
1356
1360
  }
1357
1361
  case SCOPED:
1358
1362
  var prev = o.prev;
1359
- if (patchspace && prev && o.type !== QUOTED && (lasttype === STAMP && !prev.unary && !prev.needle
1363
+ if (patchspace && !intag && prev && o.type !== QUOTED && (lasttype === STAMP && !prev.unary && !prev.needle
1360
1364
  || lasttype & ~(SPACE | STAMP | COMMENT) && o.brace
1361
1365
  || lasttype === STRAP && !/^(this|arguments|import)$/.test(prev.text)
1362
1366
  )) result.push(" ");
@@ -30,7 +30,7 @@ var unslice = function (arr) {
30
30
  continue;
31
31
  }
32
32
  var p = o.prev;
33
- if (p && is3dots(p)) {
33
+ if (p?.type && (STAMP | EXPRESS) && p.text === '...') {
34
34
  var px = arr.lastIndexOf(p, cx);
35
35
  splice(arr, px, cx - px + 1, ...o);
36
36
  cx += o.length - 1;
@@ -857,7 +857,7 @@ var killspr = function (body, i, _getobjname, killobj) {
857
857
  splice(body, i++, 0, ...scanner2('["apply"]'));
858
858
  var m1 = skipAssignment(m);
859
859
  if (index > 0 || m1 && m1.next) {
860
- var h = splice(o, 2, o.length);
860
+ var h = splice(o, 2, o.length - 2);
861
861
  var c = scanner2(`[]`);
862
862
  splice(c[0], 0, 0, ...h);
863
863
  killobj(c);
@@ -940,9 +940,7 @@ var killobj = function (body, getobjname, getletname, getname_, letname_, deep =
940
940
  var name = getname_("_");
941
941
  var y = scanner2(`for await(var ${name} of)yield ${name}`, innerJs);
942
942
  splice(y[2], y[2].length, 0, ...splice(body, i, n - i));
943
- splice.debug = true;
944
943
  splice(body, i - 1, 1, ...y);
945
- splice.debug = false;
946
944
  innerJs.setType(y[1]);
947
945
  if (y[1].type === EXPRESS) splice(body, i, 1);
948
946
  unforof(y[0], getname_.bind(null, '_'), y.used, deepkill);
@@ -160,7 +160,7 @@ textSpan: highlightSpan.textSpan,
160
160
  isWriteAccess: highlightSpan.kind === "writtenReference" /* writtenReference */ }, highlightSpan.isInString && { isInString: true }, highlightSpan.contextSpan && { contextSpan: highlightSpan.contextSpan })) }`);
161
161
  assert(downLevel(`async()=>({ [argitem.sort ? argitem.sort : 'date']: "desc" })`), `function () { return async_(
162
162
  function () {
163
- _ = {}; _1 = argitem.sort; if (!_1) return [1, 0]; _1 = argitem.sort; return [2, 0]
163
+ _ = {}; if (!argitem.sort) return [1, 0]; _1 = argitem.sort; return [2, 0]
164
164
  },
165
165
  function () {
166
166
  _1 = 'date'; return [1, 0]
@@ -430,15 +430,16 @@ function () {
430
430
  _0 = a; return [_0, 1]
431
431
  })
432
432
  var a, _0 }`)
433
-
434
433
  assert(downLevel(`function(a=b=>b,c){c}`), 'function (a, c) { if (a === undefined) a = function (b) { return b }; c }')
435
434
  assert(downLevel(`Object.defineProperty(dis, f.key, {get() {}, set(v) {}})`), `Object.defineProperty(dis, f.key, (_ = {},
436
435
  _.get = function () {},
437
436
  _.set = function (v) {}, _))
438
437
  var _`);
439
- common.debug = true;
438
+ downLevel.debug = true; i++;
439
+ assert(downLevel(`var restq = splice(queue, i, i2 - i, ...a[1], { type: STAMP, text: "=" });`), `var slice_ = Array["prototype"]["slice"];
440
+ var restq = splice["apply"](null, [queue, i, i2 - i]["concat"](slice_["call"](a[1]), [{ type: STAMP, text: "=" }]));`)
440
441
  var c = scanner2(`\r\n if (search.length) return null;\r\n return path.join(...pathlist);\r\n`);
441
442
  c.fix();
442
443
  c.break();
443
444
  assert(c.toString(), `\r\n if (search["length"]) return null;\r\n return path["join"](...pathlist);\r\n`)
444
- assert(downLevel.code(c).toString(), `\r\n if (search["length"]) return null;\r\n return (_ = path)["join"]["apply"](_, pathlist);\r\n\r\nvar _`);
445
+ assert(downLevel.code(c).toString(), `\r\n if (search["length"]) return null;\r\n return path["join"]["apply"](path, pathlist);\r\n`);
@@ -24,10 +24,12 @@ function rescan(strs, ...args) {
24
24
  var dist = [];
25
25
  var i = 0;
26
26
  for (var s of strs) {
27
- dist.push(s, '#\\' + i++);
27
+ if (s) dist.push(s, ' ');
28
+ dist.push('#\\' + i++, " ");
28
29
  }
30
+ dist.pop();
29
31
  if (i > args.length) dist.pop();
30
- dist = scanner2(dist.join(' '));
32
+ dist = scanner2(dist.join(''));
31
33
  patchObject(dist, args);
32
34
  return dist;
33
35
  }
@@ -126,7 +126,7 @@ test(`switch(a){default: a;case 1:b;}`, 'if (a === 1) return [2, 0]; return [1,
126
126
  test("loop:{a=b;if(a) continue loop}", "a = b; if (a) return [0, 0]", true);
127
127
  test("if(a)try{}finally{}else a;", 'if (!a) return [4, 0]; return [1, 8];\r\n return [0, 9];\r\n return [1, 9];\r\n return [2, 0];\r\n a; return [1, 0]')
128
128
  test("b:while(t){switch(a){case c:break b;}}", 'if (!t) return [1, 0]; if (a === c) return [1, 0]; return [0, 0]');
129
- test("predef[key[1]](r.slice(key[0].length).trim())", '_ = key[1]; _0 = key[0]; _0 = _0.length; _0 = r.slice(_0); _0 = _0.trim(); predef[_](_0)');
129
+ test("predef[key[1]](r.slice(key[0].length).trim())", '_ = key[1]; _0 = key[0].length; _0 = r.slice(_0); _0 = _0.trim(); predef[_](_0)');
130
130
  test("predef[key[1]](r.slice())(r.slice())", '_ = key[1]; _0 = r.slice(); _ = predef[_](_0); _0 = r.slice(); _(_0)');
131
131
  test("predef[key[1]][key[2]][key[3]]", '_ = key[1]; _ = predef[_]; _0 = key[2]; _ = _[_0]; _0 = key[3]; _[_0]');
132
132
  test("[key[1]][key[2]][key[3]]", '_ = key[1]; _ = [_]; _0 = key[2]; _ = _[_0]; _0 = key[3]; _[_0]');
@@ -281,14 +281,18 @@
281
281
  }
282
282
  else text = encode(text);
283
283
  var codes = text.split(/\r\n|\r|\n/);
284
- var minSpace = 0;
284
+ var minSpace = Infinity;
285
285
  for (var c of codes) {
286
- var m = /^\s*/.exec(c);
287
- if (m && m[0].length < minSpace) {
286
+ var m = /^\s+/.exec(c);
287
+ if (!m) {
288
+ minSpace = 0;
289
+ break;
290
+ }
291
+ if (m[0].length < minSpace) {
288
292
  minSpace = m[0].length;
289
293
  }
290
294
  }
291
- if (minSpace > 0) codes = codes.map(c => /^\s+/.test(c) ? c.slice(minSpace) : c);
295
+ if (minSpace > 0 && minSpace < Infinity) codes = codes.map(c => /^\s+/.test(c) ? c.slice(minSpace) : c);
292
296
  return codes;
293
297
  }
294
298
  function codetext(type, text, blink) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "4.10.2",
3
+ "version": "4.11.0",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {