efront 4.3.11 → 4.3.15

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,13 @@
1
+ module.exports = function (p) {
2
+ var s = [];
3
+ while (p) {
4
+ var reg = /[\$\/\\]/g;
5
+ reg.lastIndex = 1;
6
+ var m = reg.exec(p);
7
+ var i = m ? m.index : p.length;
8
+ s.push(p.slice(0, i));
9
+ p = p.slice(i + 1);
10
+ }
11
+ if (m) s.push('');
12
+ return s;
13
+ }
@@ -153,7 +153,7 @@ class BigNumber {
153
153
  v = +v;
154
154
  }
155
155
  else v = vmap[v];
156
- if (Number.isNaN(v) || v >= system_scale || v !== +v) throw new Error("数据错误!");
156
+ if (v !== v || v >= system_scale || v !== +v) throw new Error("数据错误!");
157
157
 
158
158
  if (dotOccurs) {
159
159
  num = BigNumber.add(num, BigNumber.div(v, scale, BigNumber.DECIMAL_DIGIT))
@@ -1,5 +1,5 @@
1
1
  function isEmpty(value) {
2
- if (value === '' || value === null || value === undefined || Number.isNaN(value)) return true;
2
+ if (value === '' || value === null || value === undefined || value !== value) return true;
3
3
  if (value instanceof Array && value.length === 0 || value.constructor === Object || !value.constructor) {
4
4
  for (var k in value) return false;
5
5
  return true;
@@ -1,5 +1,5 @@
1
1
  function isHandled(value) {
2
- if (value === '' || value === null || value === undefined || Number.isNaN(value)) return false;
2
+ if (value === '' || value === null || value === undefined || value !== value) return false;
3
3
  return true;
4
4
  }
5
5
  module.exports = isHandled;
@@ -1,4 +1,3 @@
1
- var isNaN = Number.isNaN;
2
1
  function isSame(o1, o2) {
3
- return o1 === o2 || isNaN(o1) && isNaN(o2);
2
+ return o1 === o2 || o1 !== o1 && o2 !== o2;
4
3
  }
@@ -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,7 +384,7 @@ 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
389
  if (o.unary && /^(\+|\-)$/.test(o.text) && last && last.type === STAMP && /^(\+\+|\-\-)$/.test(last.text)) o.unary = !!last.unary;
390
390
  }
@@ -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];
@@ -13,7 +13,7 @@ var cloneNode = function (o) {
13
13
  c = Object.assign({}, c);
14
14
  }
15
15
  else switch (typeof c) {
16
- case "number": case "bigint": c = { type: VALUE, isdigit: !Number.isNaN(c), text: String(c) }; break;
16
+ case "number": case "bigint": c = { type: VALUE, isdigit: c === c, text: String(c) }; break;
17
17
  case "boolean": case "undefined": c = { type: VALUE, text: String(c) }; break;
18
18
  case "regexp": c = { type: QUOTED, text: String(c) }; break;
19
19
  case "string": c = scanner2(c); break;
@@ -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
  };
@@ -144,9 +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
+ test(`a[0]++ > 1`, "_ = a[0]++, _ > 1");
148
+ test(`a[0]-- > 1`, "_ = a[0]--, _ > 1");
147
149
  test(`c=b\r\n++a`, "c = b; ++a");
148
150
  test(`c=b+\r\n++a`, "_ =\r\n++a, c = b + _");
149
151
  test(`c=b+ ++a`, "_ = ++a, c = b + _");
150
152
  unstruct.debug = true; r++;
151
153
  test(`c=b+ +a`, "_ = +a, c = b + _");
152
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
+
@@ -1,5 +1,6 @@
1
1
  var path = require("path");
2
2
  var fs = require("fs").promises;
3
+ var $split = require("../basic/$split");
3
4
  var str2array = require("../basic/str2array");
4
5
  async function detectWithExtension(filenames, extensions = [""], folders = [""]) {
5
6
  if (typeof filenames === 'string') filenames = str2array(filenames);
@@ -10,7 +11,7 @@ async function detectWithExtension(filenames, extensions = [""], folders = [""])
10
11
  }
11
12
  if (folders === null) folders = [""];
12
13
  extensions = [].concat(extensions);
13
- filenames = filenames.map(f => efront$$split(f).join('/')).map(filename => {
14
+ filenames = filenames.map(f => $split(f).join('/')).map(filename => {
14
15
  var tempname = filename.replace(/[#\?][\s\S]*$/, '');
15
16
  var params = filename.slice(tempname.length);
16
17
  return [tempname, params];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "4.3.11",
3
+ "version": "4.3.15",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {