efront 4.3.10 → 4.3.14

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,7 +1,14 @@
1
1
  var mark = require("./mark");
2
- var gray = console.format('<gray>;</gray>').split(';');
3
- var green = console.format('<green>;</green>').split(';');
4
- var crack = console.format('<red2>;</red2>').split(';');
2
+ if (console.format) {
3
+ var gray = console.format('<gray>;</gray>').split(';');
4
+ var green = console.format('<green>;</green>').split(';');
5
+ var crack = console.format('<red2>;</red2>').split(';');
6
+ }
7
+ else {
8
+ var gray = [, ,];
9
+ var green = [, ,];
10
+ var crack = [, ,];
11
+ }
5
12
  var dump = function (a, msg) {
6
13
  if (a instanceof Object) console.error('属性错误'), console.log(msg ? msg + " " : " {\r\n", Object.keys(a).map(k => ` ${k}${gray.join(':')}\r\n ${a[k]}`).join('\r\n') + "\r\n }");
7
14
  else if (msg) console.log(msg + ":", a);
@@ -1,24 +1,26 @@
1
1
  var tick = Promise.resolve();
2
2
  var exec_ = function (args, ok, oh, int) {
3
- var p = null, index = 0, r, e, finished = false, t = this;
3
+ var p = null, index = 0, r, e, finished = false;
4
4
  var next = function (arg) {
5
5
  p = arg;
6
6
  run();
7
7
  };
8
- var catches = [], catch_, throwed;
8
+ var catches = [], catch_, throwed = false;
9
9
  var thro = function (err) {
10
+ e = err;
10
11
  if (catch_) {
12
+ throwed = true;
11
13
  fina();
12
14
  }
13
15
  else if (catches.length) {
14
- catch_ = catches[catches.length - 1];
15
- [index, p, throwed] = catch_;
16
+ catch_ = catches.pop();
17
+ [index, p] = catch_;
18
+ throwed = false;
16
19
  index += p & 0xffff;
17
20
  if (p >>> 16) {
18
21
  next(err);
19
22
  }
20
23
  else {
21
- e = err;
22
24
  catches.pop();
23
25
  fina();
24
26
  }
@@ -42,27 +44,26 @@ var exec_ = function (args, ok, oh, int) {
42
44
  next();
43
45
  };
44
46
  var fine = function () {
45
- index++;
46
- next();
47
+ catches.pop();
48
+ if (throwed) thro(e);
49
+ else if (finished) retn(r);
50
+ else {
51
+ index++;
52
+ next();
53
+ }
47
54
  }
48
55
  var run = function () {
49
56
  var args_length = args.length, i;
50
- if (!catch_ || index >= args_length) {
51
- if (throwed) {
52
- return oh(e);
53
- }
54
- if (finished) return ok(r);
55
- }
56
57
  while (index < args_length) {
57
58
  try {
58
- var a = args[index].call(t, p) || [1, 0];
59
+ var a = args[index](p) || [1, 0];
59
60
  catch_ = null;
60
61
  p = a[0];
61
62
  i = a[1];
62
63
  } catch (e) {
63
64
  p = null;
64
65
  thro(e);
65
- break;
66
+ return;
66
67
  }
67
68
  switch (i) {
68
69
  case 0: index += p; break; // reflow
@@ -0,0 +1,48 @@
1
+ var a = async function () {
2
+ console.log(1);
3
+ for (var a = 0; a < 10; a++) {
4
+ await new Promise(ok => setTimeout(ok, 20));
5
+ }
6
+ console.log(2);
7
+ await new Promise(ok => setTimeout(ok, 20));
8
+ await new Promise(ok => setTimeout(ok, 20));
9
+ };
10
+ var b = async function () {
11
+ console.log(3, process.uptime())
12
+ try {
13
+ console.log(4, 'try');
14
+ throw 5
15
+ } catch (e) {
16
+ console.log(e, 'catched')
17
+ throw 7;
18
+ }
19
+ finally {
20
+ console.log(6, 'finally')
21
+ }
22
+ console.fail('<red>这一行不应出现!</red>');
23
+ };
24
+ var c = async function () {
25
+
26
+ try {
27
+
28
+ await b();
29
+ } catch (e) {
30
+ console.log(e)
31
+ return 9;
32
+ }
33
+ finally {
34
+ console.log(8)
35
+ }
36
+ };
37
+ var d = async function () {
38
+ try {
39
+ throw new Error(10);
40
+ }
41
+ catch (e) {
42
+ throw e;
43
+ }
44
+ }
45
+ console.log(0, process.uptime())
46
+ await a();
47
+ console.log(await c());
48
+ await d();
@@ -384,9 +384,9 @@ Javascript.prototype.setType = function (o) {
384
384
  }
385
385
  }
386
386
  if (o.type === STAMP) {
387
- if (!last || last.type & (STAMP | STRAP) || last.type === SCOPED && /^[\{\[]$/.test(last.entry) && !last.isExpress) {
387
+ if (!last || last.type & (STAMP | STRAP) && !/^(\+\+|\-\-)$/.test(last.text) || last.type === SCOPED && /^[\{\[]$/.test(last.entry) && !last.isExpress) {
388
388
  o.unary = /^[^=;,\*]$|.[^\=\>\<\|\&\^]$/.test(o.text);
389
- if (o.unary && last && last.type === STAMP && /^(\+\+|\-\-)$/.test(last.text)) o.unary = !/^[\+\-]$/.test(o.text);
389
+ if (o.unary && /^(\+|\-)$/.test(o.text) && last && last.type === STAMP && /^(\+\+|\-\-)$/.test(last.text)) o.unary = !!last.unary;
390
390
  }
391
391
  if (last && /^(\+\+|\-\-)$/.test(o.text)) {
392
392
  var i = 1;
@@ -658,7 +658,7 @@ var removeImport = function (c, i, code) {
658
658
  var next = c.next;
659
659
  var { used, envs, vars } = code;
660
660
  if (next && next.type !== QUOTED) {
661
- var [dec, map, o] = getDeclared(c.next);
661
+ var [dec, map, o] = getDeclared(c.next, 'remove');
662
662
  if (!o) throw new Error(i18n`代码结构异常!`);
663
663
  if (o.type !== STRAP || o.text !== 'from') throw new Error(i18n`缺少from语句`);
664
664
  var oi = code.indexOf(o, i);
@@ -730,7 +730,7 @@ var removeImport = function (c, i, code) {
730
730
  if (used[dn]) used[dn].forEach(u => {
731
731
  if (used[name].indexOf(u) >= 0) return;
732
732
  patchname(name, u, da);
733
- used[name].push(u);
733
+ if (u.kind !== 'remove') used[name].push(u);
734
734
  });
735
735
  delete used[dn];
736
736
  delete vars[dn];
@@ -1722,6 +1722,7 @@ var down = function (scoped) {
1722
1722
  var argname = _letname("_");
1723
1723
  unstruct.debug = downLevel.debug;
1724
1724
  var body = scanner2(`return ${funcMark}()`);
1725
+ var body3 = body[body.length - 1];
1725
1726
  var code = unawait(scoped.body, _getname, argname);
1726
1727
  code.forEach(function (c) {
1727
1728
  revar(c);
@@ -1729,8 +1730,8 @@ var down = function (scoped) {
1729
1730
  if (!c.length) f[2].push(...scanner2('return [1,0]'));
1730
1731
  else f[2].push(...c);
1731
1732
  f[2].push({ type: SPACE, text: "\r\n" });
1732
- if (body[2].length) body[2].push({ type: STAMP, text: "," });
1733
- body[2].push({ type: SPACE, text: '\r\n' }, ...f);
1733
+ if (body3.length) body3.push({ type: STAMP, text: "," });
1734
+ body3.push({ type: SPACE, text: '\r\n' }, ...f);
1734
1735
  });
1735
1736
  splice(scoped.body, 0, scoped.body.length);
1736
1737
  if (markcodes.length || argcodes.length) {
@@ -435,6 +435,7 @@ var _do = function (body, cx, unblock, result) {
435
435
  if (label.continue) ifpatch(result), label.contat = result.length;
436
436
  var b = rescan`if (${getCondition(o, unblock)}) return [${i - result.length}, 0]`;
437
437
  pushstep(result, b);
438
+ b[b.length - 1][0].text = String(i - result.length + 1);
438
439
  while (body[cx] !== o) cx++;
439
440
  return cx + 1;
440
441
  };
@@ -938,7 +939,6 @@ var _express = function (body, getname, ret) {
938
939
  }
939
940
  var result = [];
940
941
  var q = [];
941
- var needpunc = false;
942
942
  var bx = 0;
943
943
  var cache = [];
944
944
  var n = null;
@@ -966,10 +966,8 @@ var _express = function (body, getname, ret) {
966
966
  }
967
967
  if (o.type & (STRAP | STAMP)) {
968
968
  var p = 0;
969
- if (/^([!~]|\+\-|\-\+)*$/.test(o.text)) p = powermap["!"];
970
- if (!p && /^[\+\-]$/.test(o.text)) p = needpunc ? powermap["+"] : powermap["!"];
971
- if (!p) p = powermap[o.text];
972
- if (o.unary) needpunc = false;
969
+ if (o.unary) p = powermap["!"];
970
+ else p = powermap[o.text];
973
971
  var b = body.slice(bx, cx + 1);
974
972
  bx = cx + 1;
975
973
  b.index = nameindex;
@@ -1021,7 +1019,6 @@ var _express = function (body, getname, ret) {
1021
1019
  }
1022
1020
  }
1023
1021
  else {
1024
- needpunc = true;
1025
1022
  if (o.type === EXPRESS) {
1026
1023
  exps.push(o);
1027
1024
  }
@@ -144,7 +144,12 @@ test(`a[0]-- + 1`, "_ = a[0]--, _ + 1");
144
144
  test(`a[0]-- +1`, "_ = a[0]--, _ + 1");
145
145
  test(`a[0]--+1`, "_ = a[0]--, _ + 1");
146
146
  test(`a[0]+++1`, "_ = a[0]++, _ + 1");
147
- unstruct.debug = true; r++;
147
+ test(`a[0]++ > 1`, "_ = a[0]++, _ > 1");
148
+ test(`a[0]-- > 1`, "_ = a[0]--, _ > 1");
148
149
  test(`c=b\r\n++a`, "c = b; ++a");
149
150
  test(`c=b+\r\n++a`, "_ =\r\n++a, c = b + _");
150
151
  test(`c=b+ ++a`, "_ = ++a, c = b + _");
152
+ unstruct.debug = true; r++;
153
+ test(`c=b+ +a`, "_ = +a, c = b + _");
154
+ test(`c=b+ !a`, "_ = !a, c = b + _");
155
+ test(`do {var loadcount = 0;} while (loadcount !== 0);`, `loadcount = 0; _ = loadcount !== 0; if (_) return [0, 0]`);
@@ -11,14 +11,72 @@ var updatePrime = function (m) {
11
11
  prime.push(n);
12
12
  }
13
13
  }
14
- var isPrime = function (s) {
14
+ var isPrime = function (s, int) {
15
+ return 最小素约数(s, int) === s;
16
+ };
17
+
18
+ var 分解因数 = function (s) {
19
+ var r = [];
20
+ do {
21
+ var d = 最小素约数(s);
22
+ r.push(d);
23
+ s = s / d;
24
+ } while (s >= d);
25
+ return r;
26
+ };
27
+ var 公约数 = function (a, b) {
28
+ var r1 = 分解因数(a);
29
+ var r2 = 分解因数(b);
30
+ var i1 = 0, i2 = 0;
31
+ var s = [];
32
+ while (i1 < r1.length && i2 < r2.length) {
33
+ var a1 = r1[i1], a2 = r2[i2];
34
+ if (a1 === a2) {
35
+ i1++, i2++;
36
+ s.push(a1);
37
+ continue;
38
+ }
39
+ if (a1 < a2) {
40
+ i1++;
41
+ }
42
+ else {
43
+ i2++;
44
+ }
45
+ }
46
+ return s;
47
+ };
48
+
49
+ var 最小素约数 = function (s, int = typeof s === 'bigint' ? BigInt : Number) {
15
50
  var n = Math.sqrt(Number(s));
16
- s = BigInt(s);
51
+ var = int(0);
17
52
  if (n > prime[prime.length - 1]) updatePrime(n);
18
- for (var cx = 0; prime[cx] < n; cx++)if (s % BigInt(prime[cx]) === 0n) return false;
19
- return true;
53
+ for (var cx = 0; prime[cx] <= n; cx++)if (s % int(prime[cx]) === ) return int(prime[cx]);
54
+ return s;
55
+ };
56
+
57
+ var 测试梅森素数 = function (p) {
58
+ // 仅bigint;
59
+ if (!isPrime(p)) return false;
60
+ if (typeof p !== 'bigint') p = BigInt(p);
61
+ var 二 = BigInt(2);
62
+ var 一 = BigInt(1);
63
+ var 零 = BigInt(0);
64
+ var Mp = 二 ** p - 一;
65
+ var 四 = BigInt(4);
66
+ var L0 = 四;
67
+ var Lm = n => (n * n - 二) % Mp;
68
+ var Ln = L0;
69
+ for (var cx = 一, dx = p - 一; cx < dx; cx++) {
70
+ Ln = Lm(Ln);
71
+ }
72
+ return Ln === 零;
20
73
  };
21
74
  prime.isPrime = isPrime;
75
+ prime.mtest = 测试梅森素数;
76
+ prime.minFactor = 最小素约数;
77
+ prime.factorize = 分解因数;
78
+ prime.cd = 公约数;
79
+
22
80
  prime.find = function (start, delta, end) {
23
81
  var isBigInt = typeof start === 'bigint' || typeof end === 'bigint';
24
82
  var n = [0, 1, 2];
@@ -1,10 +1,37 @@
1
1
  var test = function (a, b, c) {
2
2
  var start = new Date;
3
- prime.find(a, b, c)
3
+ var r = prime.find(a, b, c)
4
4
  var end = new Date;
5
- console.log(a, b, c, '用时', end - start);
6
- }
5
+ var n = console.format("<yellow>;</yellow>").split(';');
6
+ var p = console.format("<green>;</green>").split(';');
7
+
8
+ if (r && r.length) console.log(console.format(`从${n.join(a)}每次加${n.join(b)}到${n.join(c)},用时${n.join(end - start)}毫秒,共找到${n.join(r.length)}个素数,最后一个是${p.join(r[r.length - 1])}`));
9
+ else console.log(`从${n.join(a)}每次加${n.join(b)}到${n.join(c)},用时${n.join(end - start)}毫秒,没找到素数`);
10
+ };
11
+ var testFactorize = function (s) {
12
+ var is = prime.factorize(s);
13
+ console.log(s, "因数分解为:", is);
14
+ };
15
+ testFactorize(2n * 3n * 5n * 7n * 11n * 13n + 1n);
16
+ testFactorize(2n * 3n * 5n * 7n * 11n * 13n);
17
+ testFactorize(2n ** 4n * 3n * 5n * 7n ** 2n * 11n * 13n);
18
+ testFactorize(2n * 3n * 5n * 7n * 11n * 13n - 1n);
19
+ testFactorize(2n * 3n * 5n * 7n * 11n * 13n * 17n * 19n * 23n * 29n * 31n - 1n);
20
+ testFactorize(2n * 3n * 5n * 7n * 11n * 13n * 17n * 19n * 23n * 29n * 31n + 1n);
21
+ testFactorize(2n * 3n * 5n * 7n * 11n * 13n * 17n * 19n * 23n * 29n * 31n * 37n * 41n - 1n);
22
+ testFactorize(2n * 3n * 5n * 7n * 11n * 13n * 17n * 19n * 23n * 29n * 31n * 37n * 41n + 1n);
23
+ console.log(prime.cd(9, 9))
24
+ console.log(prime.cd(9, 27))
25
+ console.log(prime.cd(9, 12))
26
+ console.log(prime.cd(2024, 1992))
7
27
  test(19000000n, 1, 21000000n);
8
28
  test(19000000, 1, 21000000);
9
- test(19000000, 1, 21000000);
10
- test(19000000n, 1, 21000000n);
29
+ test(0x1ffffffffff0ff, 2, 0x1fffffffffffff);
30
+ test(0x1f202403050355n, 2, 0x1f2024030503f5n);
31
+ console.log("已缓存的素数的个数", prime.length);
32
+ for (var p of prime) {
33
+ console.test("正在测试:", console.format(`<yellow>M(<gray>${p}</gray>)</yellow>`));
34
+ var a = prime.mtest(p);
35
+ if (a) console.pass("发现梅森素数:", console.format(`<yellow>M(<green>${p}</green>)</yellow>`));
36
+ }
37
+
@@ -21,7 +21,6 @@ var touch = {
21
21
  */
22
22
  var t = this;
23
23
  var start = () => {
24
- if (onclick.preventClick) return;
25
24
  var a = t.$scope.toActive(e);
26
25
  touchitems = t.querySelectorAll("fileitem");
27
26
  if (a && t.$scope.selected.indexOf(a.$scope.d) >= 0) {
@@ -38,7 +37,10 @@ var touch = {
38
37
  css(rect, { left: e.clientX - pos.left - t.clientLeft, top: e.clientY - t.clientTop, width: 0, height: 0 })
39
38
  };
40
39
  if (/^touch/.test(e.type)) {
41
- touch.ing = setTimeout(start, 600);
40
+ touch.ing = setTimeout(function () {
41
+ if (onclick.preventClick) return;
42
+ start();
43
+ }, 600);
42
44
  }
43
45
  else {
44
46
  start();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "4.3.10",
3
+ "version": "4.3.14",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {