efront 3.37.0 → 3.38.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.
@@ -1,13 +1,14 @@
1
1
  var unstruct = require('./unstruct');
2
2
  var scanner2 = require("./scanner2");
3
3
  var { createString } = require("./common");
4
+ var r = 10;
4
5
  function test(codetext, expect, ret = false) {
5
- var code = scanner2(codetext);
6
- var i = -2;
7
- code = unstruct(code, () => ++i >= 0 ? "_" + i : '_', ret && "@");
8
- assert(code.map(createString).join("; "), expect);
6
+ var code = scanner2(codetext), i = -2;
7
+ try { code = unstruct(code, () => ++i >= 0 ? "_" + i : '_', ret && "@"); } catch (e) { console.log(r); throw e }
8
+ assert(code.map(createString).join(";\r\n "), expect, r++);
9
9
  }
10
10
  test('a+b', "a + b");
11
+ test('var a = b', "a = b");
11
12
  test('a + !c', "_ = !c, a + _");
12
13
  test('a + b * c', "_ = b * c, a + _");
13
14
  test('a + b * !c', "_ = !c, _ = b * _, a + _");
@@ -16,49 +17,74 @@ test('a * a + b * c', "_ = a * a, _0 = b * c, _ + _0");
16
17
  test('a * a + b * c * c ** d', "_ = a * a, _0 = b * c, _1 = c ** d, _0 = _0 * _1, _ + _0");
17
18
  test('a * a || b * c * c ** d', "_ = a * a @re _ = b * c, _0 = c ** d, _ * _0");
18
19
  test('a * a || b * c || c * d', "_ = a * a @re _ = b * c @re c * d");
19
- test('a?b:c', "if (a) return [1, 0]; _ = b; return [2, 0]; _ = c");
20
+ test('a || b || c', "_ = a; if (_) return [1, 0]; _ = b; if (_) return [1, 0]; c", true);
21
+ test('a?b:c', "if (!a) return [1, 0]; _ = b; return [2, 0];\r\n _ = c; return [1, 0]");
20
22
  test('a * a && b * c * c ** d', "_ = a * a @rz _ = b * c, _0 = c ** d, _ * _0");
21
- test('a = 1 + 2', "_ = 1 + 2, a = _", true);
23
+ test('a = 1 + 2', "_ = 1 + 2; a = _", true);
22
24
  test('a = b', "a = b", true);
23
- test('a = b = c', "_ = c, b = _, a = _", true);
24
- test('a = b = c + d', "_ = c + d, b = _, a = _", true);
25
- test('a = b = c + d * 1', "_ = d * 1, _ = c + _, b = _, a = _", true);
26
- test('return a = b', "a = b; return [a, 2]", true);
25
+ test('a.a = b', "a.a = b", true);
26
+ test('loaded[f.name] = a', "_ = f.name; loaded[_] = a", true);
27
+ test('a = b = c', "b = c; a = c", true);
28
+ test('a = b = c + d', "_ = c + d; b = _; a = _", true);
29
+ test('a = b = c + d * 1', "_ = d * 1, _ = c + _; b = _; a = _", true);
30
+ test('return a = b', "a = b; return [b, 2]", true);
27
31
  test('a*a', "a * a", true);
28
32
  test('a * a && b * c * c ** d', "_ = a * a; if (!_) return [1, 0]; _ = b * c, _0 = c ** d, _ * _0", true);
29
33
  test('a * a || b * c * c ** d', "_ = a * a; if (_) return [1, 0]; _ = b * c, _0 = c ** d, _ * _0", true);
30
34
  test('a * a ?? b * c * c ** d', "_ = a * a; if (_ !== null && _ !== undefined) return [1, 0]; _ = b * c, _0 = c ** d, _ * _0", true);
31
- test('a * a && await b*c', "_ = a * a; if (!_) return [2, 0]; _ = b; return [_, 1]; _ = @; _ * c", true);
32
-
35
+ test('a * a && await b*c', "_ = a * a; if (!_) return [2, 0]; _ = b; return [_, 1];\r\n _ = @; _ * c", true);
33
36
  test("await a", "_ = a; return [_, 1]", true);
34
- test("yield a", "_ = a; return [_, 3]", true);
37
+ test("yield a", "return [a, 3]", true);
35
38
  test("await a()", "_ = a(); return [_, 1]", true);
36
39
  test("yield a()", "_ = a(); return [_, 3]", true);
37
40
  test("(1+ +1)", "_ = +1, _ = 1 + _; (_)", true);
38
- test("await a(await b)", "_ = b; return [_, 1]; _ = @; _ = a(_); return [_, 1]", true);
39
- test("await a(await b).s(await c)", "_ = b; return [_, 1]; _ = @; _ = a(_); _0 = c; return [_0, 1]; _0 = @; _ = _.s(_0); return [_, 1]", true);
40
- test("a*a + await a(await b).s(await c)", "_ = a * a; _0 = b; return [_0, 1]; _0 = @; _0 = a(_0); _1 = c; return [_1, 1]; _1 = @; _0 = _0.s(_1); return [_0, 1]; _0 = @; _ + _0", true);
41
- test("a*a + await a(await b(await c)).s(await c)", "_ = a * a; _0 = c; return [_0, 1]; _0 = @; _0 = b(_0); return [_0, 1]; _0 = @; _0 = a(_0); _1 = c; return [_1, 1]; _1 = @; _0 = _0.s(_1); return [_0, 1]; _0 = @; _ + _0", true);
42
- test("await a, await b", "_ = a; return [_, 1]; _ = b; return [_, 1]", true);
43
- test("await a * b, await b", "_ = a; return [_, 1]; _ = @; _ * b; _ = b; return [_, 1]", true);
44
- test("if(a);", "", true);
45
- test("if(a) await b", "if (!a) return [1, 0]; _ = b; return [_, 1]", true);
46
- test("if(a) await b; else await c", "if (!a) return [2, 0]; _ = b; return [_, 1]; return [2, 0]; _ = c; return [_, 1]", true);
47
- test("if(a) b; else await c", "if (!a) return [1, 0]; _ = b; return [2, 0]; _ = c; return [_, 1]", true);
48
- test("if(a) await b; else if(e) await c", "if (!a) return [2, 0]; _ = b; return [_, 1]; return [2, 0]; if (!e) return [1, 0]; _ = c; return [_, 1]", true);
49
- test("if(a) await b; else if(e) await c else await d", "if (!a) return [2, 0]; _ = b; return [_, 1]; return [4, 0]; if (!e) return [2, 0]; _ = c; return [_, 1]; return [2, 0]; _ = d; return [_, 1]", true);
50
- test("if(await a) await b", "_ = a; return [_, 1]; if (!@) return [1, 0]; _ = b; return [_, 1]", true);
51
- test("for(a=0;a<10;a++) await a", "a = 0; return [1, 0]; _ = a < 10; if (!_) return [3, 0]; _ = a; return [_, 1]; _ = a++; return [-2, 0]", true);
52
- test("for(a=0;a<10;a++) await a, await b", "a = 0; return [1, 0]; _ = a < 10; if (!_) return [4, 0]; _ = a; return [_, 1]; _ = b; return [_, 1]; _ = a++; return [-3, 0]", true);
53
- test("for(a=0;b=2,a<10;a++) await a, await b", "a = 0; return [1, 0]; b = 2; _ = a < 10; if (!_) return [4, 0]; _ = a; return [_, 1]; _ = b; return [_, 1]; _ = a++; return [-3, 0]", true);
54
- test("while(a) await b", "if (!a) return [3, 0]; _ = b; return [_, 1]; return [-2, 0]", true);
55
- test("do{await b}while(a)", "_ = b; return [_, 1]; _ = @; if (a) return [-1, 0]; return [1, 0]", true);
56
- test("switch(a){case 1:}", "_ = a; _0 = 1; if (_ === _0) return [1, 0]", true);
57
- test("switch(a){case 1:break;}", "_ = a; _0 = 1; if (_ === _0) return [1, 0]; return [1, 0]", true);
58
- test("switch(a){case 1:break;case 2:break;}", "_ = a; _0 = 1; if (_ === _0) return [1, 0]; _0 = 2; if (_ === _0) return [2, 0]; return [2, 0]; return [1, 0]", true);
59
- test("switch(a){case 1:case 2:break;}", "_ = a; _0 = 1; if (_ === _0) return [1, 0]; _0 = 2; if (_ === _0) return [1, 0]; return [1, 0]", true);
60
- test("switch(a){case 1:case 2:x=1;}", "_ = a; _0 = 1; if (_ === _0) return [1, 0]; _0 = 2; if (_ === _0) return [1, 0]; x = 1", true);
61
- test("switch(a){case 1:case 2:x=1;}", "_ = a; _0 = 1; if (_ === _0) return [1, 0]; _0 = 2; if (_ === _0) return [1, 0]; x = 1", true);
62
- test("with(a){ a = 1}", `_ = a; if (_0 = with_("a", [_])) _0.a = 1; else a = 1;`, true);
63
- test("try{a=2+1}catch(e){}", 'return [65536, 7]; _ = 2 + 1, a = _; return [0, 9]; e = @; return [1, 9]', true);
64
- test("try{a=2+1}catch(e){a=3}", 'return [65536, 7]; _ = 2 + 1, a = _; return [0, 9]; e = @; a = 3; return [1, 9]', true);
41
+ test("await a(await b)", "_ = b; return [_, 1];\r\n _ = @; _ = a(_); return [_, 1]", true);
42
+ test("await a(await b).s(await c)", "_ = b; return [_, 1];\r\n _ = @; _ = a(_); _0 = c; return [_0, 1];\r\n _0 = @; _ = _.s(_0); return [_, 1]", true);
43
+ test("a*a + await a(await b).s(await c)", "_ = a * a, _0 = b; return [_0, 1];\r\n _0 = @; _0 = a(_0); _1 = c; return [_1, 1];\r\n _1 = @; _0 = _0.s(_1); return [_0, 1];\r\n _0 = @; _ + _0", true);
44
+ test("a*a + await a(await b(await c)).s(await c)", "_ = a * a, _0 = c; return [_0, 1];\r\n _0 = @; _0 = b(_0); return [_0, 1];\r\n _0 = @; _0 = a(_0); _1 = c; return [_1, 1];\r\n _1 = @; _0 = _0.s(_1); return [_0, 1];\r\n _0 = @; _ + _0", true);
45
+ test("await a, await b", "_ = a; return [_, 1];\r\n _ = @; _ = b; return [_, 1]", true);
46
+ test("await a * b, await b", "_ = a; return [_, 1];\r\n _ = @; _ * b; _ = b; return [_, 1]", true);
47
+ test("if(a);", "if (!a) return [1, 0]; return [1, 0]", true);
48
+ test("if(a) return a;", "if (a) return [a, 2]", true);
49
+ test("if(a) { if(b) return a;} else return d", "if (!a) return [2, 0]; if (b) return [a, 2]; return [1, 0];\r\n return [2, 0];\r\n return [d, 2]", true);
50
+ test("if(a) return a; else return b", "if (a) return [a, 2]; return [b, 2]", true);
51
+ test("if(a) await b", "if (!a) return [2, 0]; _ = b; return [_, 1];\r\n _ = @; return [1, 0]", true);
52
+ test("if(a) await b; else await c", "if (!a) return [2, 0]; _ = b; return [_, 1];\r\n _ = @; return [3, 0];\r\n _ = c; return [_, 1];\r\n _ = @; return [1, 0]", true);
53
+ test("if(a) b; else await c", "if (!a) return [1, 0]; b; return [3, 0];\r\n _ = c; return [_, 1];\r\n _ = @; return [1, 0]", true);
54
+ test("if(a) await b; else if(e) await c", "if (!a) return [2, 0]; _ = b; return [_, 1];\r\n _ = @; return [3, 0];\r\n if (!e) return [2, 0]; _ = c; return [_, 1];\r\n _ = @; return [1, 0]", true);
55
+ test("if(a) await b; else if(e) await c else await d", "if (!a) return [2, 0]; _ = b; return [_, 1];\r\n _ = @; return [5, 0];\r\n if (!e) return [2, 0]; _ = c; return [_, 1];\r\n _ = @; return [3, 0];\r\n _ = d; return [_, 1];\r\n _ = @; return [1, 0]", true);
56
+ test("if(await a) await b", "_ = a; return [_, 1];\r\n if (!@) return [2, 0]; _ = b; return [_, 1];\r\n _ = @; return [1, 0]", true);
57
+ test("for(a in b)", "for (a in b)", true);
58
+ test("for(var a in b) a.push()", "for (var a in b) a.push()", true);
59
+ test("for(;;)", "return [0, 0]", true);
60
+ test("for(a = os[Symbol.iterator] || os[Symbol.asyncIterator] || Array.prototype[Symbol.iterator], a = a.call(os), b = a.next(); !b.done && (o = b.value, true); b = a.next())", "_0 = Symbol.iterator; _ = os[_0]; if (_) return [1, 0]; _0 = Symbol.asyncIterator; _ = os[_0]; if (_) return [1, 0]; _0 = Symbol.iterator; _ = Array.prototype[_0];\r\n a = _; _ = a.call(os); a = _; _ = a.next(); b = _; return [1, 0];\r\n _ = !b.done; if (!_) return [1, 0]; _0 = b.value; o = _0; _ = (_0, true);\r\n if (!_) return [1, 0]; _ = a.next(); b = _; return [-1, 0]", true);
61
+ test("for(a=0;a<1;a++)if(a==0)continue", `a = 0; return [1, 0];\r\n _ = a < 1; if (!_) return [2, 0]; _ = a == 0; if (_) return [1, 0]; return [1, 0];\r\n _ = a++; return [-1, 0]`, true);
62
+ test("for(a=0;a<10;a++) await a", "a = 0; return [1, 0];\r\n _ = a < 10; if (!_) return [2, 0]; _ = a; return [_, 1];\r\n _ = @; _ = a++; return [-1, 0]", true);
63
+ test("for(a=0;a<10;a++) await a, await b", "a = 0; return [1, 0];\r\n _ = a < 10; if (!_) return [3, 0]; _ = a; return [_, 1];\r\n _ = @; _ = b; return [_, 1];\r\n _ = @; _ = a++; return [-2, 0]", true);
64
+ test("for(a=0;b=2,a<10;a++) await a, await b", "a = 0; return [1, 0];\r\n b = 2; _ = a < 10; if (!_) return [3, 0]; _ = a; return [_, 1];\r\n _ = @; _ = b; return [_, 1];\r\n _ = @; _ = a++; return [-2, 0]", true);
65
+ test("while(a) await b", "if (!a) return [2, 0]; _ = b; return [_, 1];\r\n _ = @; return [-1, 0]", true);
66
+ test("do{await b}while(a)", "_ = b; return [_, 1];\r\n _ = @; if (a) return [-1, 0]", true);
67
+ test("switch(a){case 1:}", "if (a === 1) return [1, 0]; return [1, 0]", true);
68
+ test("switch(a){case 1: default:}", "if (a === 1) return [1, 0]; return [1, 0]", true);
69
+ test("switch(a.a){case 1:}", "_ = a.a; if (_ === 1) return [1, 0]; return [1, 0]", true);
70
+ test("switch(a){case 1:break;}", "if (a === 1) return [1, 0]; return [1, 0]", true);
71
+ test("switch(a){case 1:break;case 2:break;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]; return [1, 0]", true);
72
+ test("switch(a){case 1:case 2:break;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]; return [1, 0]", true);
73
+ test("switch(a){case 1:case 2:x=1;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]; return [2, 0];\r\n x = 1; return [1, 0]", true);
74
+ test("switch(a){case 1:case 2:x=1;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]; return [2, 0];\r\n x = 1; return [1, 0]", true);
75
+ test("with(a){ a = 1}", `if (_ = with_("a", [a])) _.a = 1; else a = 1;`, true);
76
+ test("try{a=2+1}catch(e){}", 'return [1, 7];\r\n _ = 2 + 1; a = _; return [0, 9];\r\n return [1, 9]', true);
77
+ test("try{a=2+1}catch(e){a=3}", 'return [65537, 7];\r\n _ = 2 + 1; a = _; return [0, 9];\r\n e = @; a = 3; return [0, 9];\r\n return [1, 9]', true);
78
+ test("(function(){})", '_ = function () {}; (_)', true);
79
+ test("(1+2*function(){}())", '_ = 2 * function () {}(), _ = 1 + _; (_)', true);
80
+ test("function a(){}", 'function a() {}', true);
81
+ test("await new Promise(function(){})", '_ = function () {}; _ = new Promise(_); return [_, 1]', true);
82
+ test(`onerror({ status: xhr.status, response: "Cookie解析异常!", toString: toResponse })`, '_ = { status: xhr.status, response: "Cookie解析异常!", toString: toResponse }; onerror(_)', true);
83
+ test(`if (!/^https\\:\\/\\/|^s\\/\\//.test(url)) console.warn("请使用https访问如下路径:" + url)`, '_ = /^https\\:\\/\\/|^s\\/\\//.test(url); if (_) return [1, 0]; _ = "请使用https访问如下路径:" + url; _ = console.warn(_); return [1, 0]', true);
84
+ test(`url += (/\\?/.test(url) ? "&" : "?") + datas;`, '_ = /\\?/.test(url); if (!_) return [1, 0]; _ = "&"; return [2, 0];\r\n _ = "?"; return [1, 0];\r\n _ = (_); _ = _ + datas; _ = url + _; url = _', true);
85
+ test(`a = newname.querySelector("input,textarea").value = c.name.replace(/\\/$/, '')`, `_ = c.name.replace(/\\/$/, ''); newname.querySelector("input,textarea").value = _; a = _`, true);
86
+ test(`if (selected[f.url]) f.selected = true;`, `_ = f.url; _ = selected[_]; if (!_) return [1, 0]; f.selected = true; return [1, 0]`, true);
87
+ test(`location.protocol + parseURL(a.b).host `, `_ = a.b; _ = parseURL(_); location.protocol + _.host`, true);
88
+ test("yield a", 'return [a, 3]', true);
89
+ test("throw a", 'throw a', true);
90
+ test("debugger", 'debugger', true);
@@ -156,14 +156,14 @@ var formatRows = function (arg, rows, deep, entry, leave) {
156
156
  if (isArray) {
157
157
  for (var cx = 0, dx = rows.length; cx < dx; cx += itemcount) {
158
158
  res.push(rows.slice(cx, cx + itemcount).map((r, i) => {
159
- return Array(maxLength[i] - lens[cx + i]).join(" ") + r;
159
+ return Array(maxLength[i] - lens[cx + i] + 1).join(" ") + r;
160
160
  }).join(', '));
161
161
  }
162
162
  }
163
163
  else {
164
164
  for (var cx = 0, dx = rows.length; cx < dx; cx += itemcount) {
165
165
  res.push([rows[cx], ...rows.slice(cx + 1, cx + itemcount).map((r, i) => {
166
- return Array(maxLength[i] - lens[cx + i]).join(" ") + r;
166
+ return Array(maxLength[i] - lens[cx + i] + 1).join(" ") + r;
167
167
  })].join(', '));
168
168
  }
169
169
  }
@@ -10,8 +10,8 @@ function hasEnterStyle(e) {
10
10
 
11
11
  function _onappend(node, append = createEvent("append"), mount = createEvent("mounted")) {
12
12
  if (node.isMounted) return;
13
- node.isMounted = true;
14
13
  if (node.nodeType !== 1 && node.nodeType !== 8) return;
14
+ node.isMounted = true;
15
15
  dispatch(node, append);
16
16
  var children = Array.apply(null, node.childNodes);
17
17
  for (var c of children) {
@@ -156,6 +156,7 @@ var cssTargetSelector = function (targetSelector, oStyle, oValue) {
156
156
  };
157
157
 
158
158
  function cssTargetStyleSheet(stylesheet, innerCss) {
159
+ if (isObject(innerCss)) innerCss = serialize(innerCss, ';', ':');
159
160
  var styleSheet = stylesheet.styleSheet;
160
161
  if (styleSheet) {
161
162
  //IE
@@ -26,8 +26,8 @@ var checkUnEqual = function (deepEqual) {
26
26
  && !deepEqual({ b: 0 }, { a: 0 })
27
27
  && !deepEqual({ b: 0 }, { a: 0 })
28
28
  && !deepEqual(new Date(1), new Date(2))
29
- && !deepEqual(document.createElement("a"), document.createElement("b"))
30
- && !deepEqual(window, document)
29
+ // && !deepEqual(document.createElement("a"), document.createElement("b"))
30
+ // && !deepEqual(window, document)
31
31
  && !deepEqual(function () { }, function (a) { return a })
32
32
  && !deepEqual({ a: {} }, { a: new Date() })
33
33
  && !deepEqual({ a: { c: {} } }, { a: { b: {} } })
@@ -687,6 +687,7 @@ zimoli.clearHistory = function () {
687
687
  history = {};
688
688
  };
689
689
  zimoli.getCurrentHistory = function () {
690
+ if (!history[current_history]) history[current_history] = [];
690
691
  return history[current_history];
691
692
  };
692
693
  zimoli.inithash = locationInitHash;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "3.37.0",
3
+ "version": "3.38.2",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {