efront 4.0.10 → 4.0.11

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.
@@ -26,7 +26,7 @@ class Item extends Array {
26
26
  this.extended = mark !== false;
27
27
  if (value && value.constructor === Item) this.value = value.value;
28
28
  else this.value = value;
29
- if (value.children instanceof Array) {
29
+ if (value && value.children instanceof Array) {
30
30
  var children = value.children.map(item => new Item(item));
31
31
  children.forEach(item => item.parent = item);
32
32
  this.push.apply(this, children);
@@ -347,7 +347,7 @@ Javascript.prototype.detour = function detour(o, ie) {
347
347
  o = replace(o, ...scan(text));
348
348
  continue;
349
349
  }
350
- text = text.replace(/\.([^\.\[\!\=\:]+)/g, (_, a) => ie === undefined || this.strap_reg.test(a) ? `[${strings.recode(a)}]` : _);
350
+ text = text.replace(/\.([^\.\[\!\=\:]+)/g, (_, a) => ie === undefined || this.strap_reg.test(a) || /#/.test(a) ? `[${strings.recode(a)}]` : _);
351
351
  if (hasdot) text = "..." + text;
352
352
  o.text = text;
353
353
  break;
@@ -979,10 +979,11 @@ var needBreakBetween = function (prev, next) {
979
979
  };
980
980
  var relink = function (list) {
981
981
  var pi = 0, p = null;
982
+ list.first = p;
982
983
  for (var cx = 0, dx = list.length; cx < dx; cx++) {
983
984
  var o = list[cx];
984
985
  o.prev = p;
985
- if (o.type === COMMENT || o.type === SPACE) continue;
986
+ if (o.type & (COMMENT | SPACE)) continue;
986
987
  if (!p) list.first = o;
987
988
  while (pi < cx) list[pi++].next = o;
988
989
  p = o;
@@ -1395,7 +1395,9 @@ var down = function (scoped) {
1395
1395
  });
1396
1396
  splice(scoped.body, 0, scoped.body.length);
1397
1397
  if (markcodes.length || argcodes.length) {
1398
- splice(scoped.body, 0, 0, ...scanner2(markcodes.concat(argcodes).join(';') + ";\r\n"));
1398
+ argcodes = scanner2(markcodes.concat(argcodes).join(';') + ";\r\n");
1399
+ _killobj(_getname, argcodes);
1400
+ splice(scoped.body, 0, 0, ...argcodes);
1399
1401
  }
1400
1402
  splice(scoped.body, scoped.body.length, 0, ...body);
1401
1403
  for (var k in envs) if (!(k in scoped.envs)) vars[k] = true;
@@ -120,7 +120,7 @@ textSpan: highlightSpan.textSpan,
120
120
  isWriteAccess: highlightSpan.kind === "writtenReference" /* writtenReference */ }, highlightSpan.isInString && { isInString: true }, highlightSpan.contextSpan && { contextSpan: highlightSpan.contextSpan })) }`);
121
121
  assert(downLevel(`async()=>({ [argitem.sort ? argitem.sort : 'date']: "desc" })`), `function () { return async_(
122
122
  function () {
123
- _0 = {}; _ = _0; if (!argitem.sort) return [1, 0]; _1 = argitem.sort; return [2, 0]
123
+ _ = {}; if (!argitem.sort) return [1, 0]; _1 = argitem.sort; return [2, 0]
124
124
  },
125
125
  function () {
126
126
  _1 = 'date'; return [1, 0]
@@ -191,7 +191,7 @@ function () {
191
191
  _2 = Symbol["asyncIterator"]; _2 = os[_2]; if (_2) return [1, 0]; _2 = Symbol["iterator"]; _2 = os[_2]; if (_2) return [1, 0]; _2 = Symbol["iterator"]; _2 = Array["prototype"][_2]
192
192
  },
193
193
  function () {
194
- _0 = _2; _2 = _0["call"](os); _0 = _2; _2 = _0["next"](); return [_2, 1]
194
+ _0 = _2; _0 = _0["call"](os); _2 = _0["next"](); return [_2, 1]
195
195
  },
196
196
  function (_1) {
197
197
  _2 = _1; _ = _2; return [1, 0]
@@ -211,7 +211,7 @@ function () {
211
211
  o; s; _3 = Symbol["asyncIterator"]; _3 = os[_3]; if (_3) return [1, 0]; _3 = Symbol["iterator"]; _3 = os[_3]; if (_3) return [1, 0]; _3 = Symbol["iterator"]; _3 = Array["prototype"][_3]
212
212
  },
213
213
  function () {
214
- _0 = _3; _3 = _0["call"](os); _0 = _3; _3 = _0["next"](); return [_3, 1]
214
+ _0 = _3; _0 = _0["call"](os); _3 = _0["next"](); return [_3, 1]
215
215
  },
216
216
  function (_2) {
217
217
  _3 = _2; _ = _3; return [1, 0]
@@ -242,13 +242,13 @@ assert(downLevel("if(a){}[r, g, b] = rgb4s(r, g, b, s)"), "if (a) {} _ = rgb4s(r
242
242
  assert(downLevel(`{c,[c]:b,...a}=a`), `c = a.c, b = a[c], a = rest_(a, ["c", c])`)
243
243
  assert(downLevel(`async()=>name = require("./$split")(name)["join"]("/");`), `function () { return async_(
244
244
  function () {
245
- _0 = require("./$split")(name)["join"]("/"); name = _0; return [_0, 2]
245
+ name = require("./$split")(name)["join"]("/"); return [name, 2]
246
246
  })
247
247
  var _0 };`);
248
248
  i++//异步或步进函数
249
249
  assert(downLevel(`function *(){yield *a}`), `function () { return aster_(
250
250
  function () {
251
- _; _0 = 0; _3 = a["length"]; _1 = _3; return [1, 0]
251
+ _; _0 = 0; _1 = a["length"]; return [1, 0]
252
252
  },
253
253
  function () {
254
254
  _3 = _0 < _1; if (!_3) return [1, 0]; _ = a[_0]; _3 = (true)
@@ -266,13 +266,13 @@ function () {
266
266
  a; _2 = Symbol["iterator"]; _2 = b[_2]; if (_2) return [1, 0]; _2 = Symbol["asyncIterator"]; _2 = b[_2]; if (_2) return [1, 0]; _2 = Symbol["iterator"]; _2 = Array["prototype"][_2]
267
267
  },
268
268
  function () {
269
- _0 = _2; _2 = _0["call"](b); _0 = _2; _2 = _0["next"](); _ = _2; return [1, 0]
269
+ _0 = _2; _0 = _0["call"](b); _ = _0["next"](); return [1, 0]
270
270
  },
271
271
  function () {
272
272
  _2 = !_["done"]; if (!_2) return [1, 0]; a = _["value"]; _2 = (true)
273
273
  },
274
274
  function () {
275
- if (!_2) return [1, 0]; Symbol; _2 = _0["next"](); _ = _2; return [-1, 0]
275
+ if (!_2) return [1, 0]; Symbol; _ = _0["next"](); return [-1, 0]
276
276
  })
277
277
  var a, _, _0, _2 }`)
278
278
  assert(downLevel(`a={async a(){var b =c;return 1}}`), `a = (_ = {},
@@ -308,6 +308,6 @@ function () {
308
308
  if (!a) return [1, 0]; return [2, 0]
309
309
  },
310
310
  function () {
311
- _0 = getRequestProtocol(url) + "//", _0 = _0 + location; location = _0; return [1, 0]
311
+ _0 = getRequestProtocol(url) + "//", location = _0 + location; return [1, 0]
312
312
  })
313
313
  var _0 }`);
@@ -577,6 +577,32 @@ var patchname = function (d, getname) {
577
577
  splice(de, 0, 0, { type: EXPRESS, text: getname(0) }, { type: STAMP, text: "=" });
578
578
  de.name = getname(0);
579
579
  }
580
+ };
581
+ var clone = function (o) {
582
+ return Object.assign({}, o, { prev: null, next: null });
583
+ };
584
+ var popexp = function (explist) {
585
+ var asn = explist[explist.length - 1];
586
+ var n;
587
+ if (!asn.ret_) {
588
+ explist.pop();
589
+ }
590
+ if (!asn.ret_ && asn.length) {
591
+ if (asn.name) {
592
+ asn = createExpressList(asn);
593
+ if (asn.length > 1) {
594
+ explist.push(...asn.slice(0, asn.length - 1));
595
+ }
596
+ asn = asn.pop();
597
+ asn.shift();
598
+ asn.shift();
599
+ }
600
+ }
601
+ else {
602
+ n = asn.name;
603
+ asn = [{ type: EXPRESS, text: n }];
604
+ }
605
+ return [asn, n];
580
606
  }
581
607
  var ternary = function (body, getname, ret) {
582
608
  var getnextname = function (i) {
@@ -587,6 +613,7 @@ var ternary = function (body, getname, ret) {
587
613
  var equalsend = 0;
588
614
  var skip = 0;
589
615
  var equcount = 0;
616
+ var hascalcequ = false;
590
617
  for (var cx = 0, dx = body.length; cx < dx; cx++) {
591
618
  var o = body[cx];
592
619
  if (o.type === STRAP && /^(var|let|const)$/.test(o.text)) {
@@ -626,12 +653,13 @@ var ternary = function (body, getname, ret) {
626
653
  }
627
654
  }
628
655
  else if (powermap[o.text] === powermap["="]) {
629
- if (!question.length) equalsend = cx + 1, equcount += o.text.length;
656
+ if (!question.length) equalsend = cx + 1, equcount++;
657
+ if (o.text.length > 1) hascalcequ = true;
630
658
  }
631
659
  }
632
660
  if (!res.length) {
633
661
  var bd = equalsend ? body.slice(equalsend) : body;
634
- if (!ret && equcount === 1 && canbeOnce(bd)) {
662
+ if (!ret && equcount === 1 && !hascalcequ && canbeOnce(bd)) {
635
663
  res = [bd];
636
664
  }
637
665
  else if (ret === 1 && !equcount && canbeOnce(bd)) {
@@ -653,6 +681,7 @@ var ternary = function (body, getname, ret) {
653
681
  // if (!q) throw `语法错误: <red>${createString(body)}</red> \r\n行列位置: ${equals[0].row}:${equals[0].col}`
654
682
  var n = q.name;
655
683
  var i = equals.length - 1;
684
+ var isSimpleAssign = true;
656
685
  while (i >= 0) {
657
686
  var p = equals[i];
658
687
  while (p && p.type & (SPACE | COMMENT)) p = equals[--i];
@@ -667,7 +696,12 @@ var ternary = function (body, getname, ret) {
667
696
  }
668
697
  if (ai < 0) ai = 0;
669
698
  var ass = equals.slice(ai, i);
670
- if (n) var asn = [{ type: EXPRESS, text: n }];
699
+ var eq = equals[i];
700
+ if (isSimpleAssign) isSimpleAssign = ret !== 1 && canbeTemp(ass);
701
+ if (isSimpleAssign && eq.text === '=') {
702
+ [asn, n = createString(ass)] = popexp(explist);
703
+ }
704
+ else if (n) var asn = [{ type: EXPRESS, text: n }];
671
705
  else asn = explist.pop();
672
706
  for (var a of ass) {
673
707
  if (a.type === SCOPED) {
@@ -684,16 +718,21 @@ var ternary = function (body, getname, ret) {
684
718
  }
685
719
  }
686
720
  var an = '';
687
- var eq = equals[i];
688
721
  if (eq.text.length > 1) {
689
722
  var punc = eq.text.slice(0, eq.text.length - 1);
690
- var bdtmp = ass.concat({ type: STAMP, text: punc }, ...asn);
723
+ var bdtmp = [...ass.map(clone), { type: STAMP, text: punc }, ...asn];
724
+ relink(bdtmp);
691
725
  var explist2 = _express(bdtmp, getname, true);
726
+ if (isSimpleAssign) {
727
+ [asn, an = createString(ass)] = popexp(explist2);
728
+ }
729
+ else {
730
+ var q2 = explist2[explist2.length - 1];
731
+ an = q2.name;
732
+ asn = scanner2(an);
733
+ }
692
734
  for (var e of explist2) pushstep(explist, e);
693
735
  eq.text = "=";
694
- var q2 = explist2[explist2.length - 1];
695
- an = q2.name;
696
- asn = scanner2(an);
697
736
  }
698
737
  else an = n;
699
738
  ass.push(equals[i], ...asn);
@@ -702,6 +741,7 @@ var ternary = function (body, getname, ret) {
702
741
  ass.name = an;
703
742
  patchstep(ass, ass.length, 0);
704
743
  pushstep(explist, ass);
744
+ isSimpleAssign = false;
705
745
  i = ai - 1;
706
746
  n = an;
707
747
  }
@@ -989,6 +1029,12 @@ function toqueue(body, getname, ret = false, result = []) {
989
1029
  do {
990
1030
  var o = body[cx];
991
1031
  while (o && (o.type & (SPACE | COMMENT) || o.type === STAMP && /^[,;]$/.test(o.text))) o = body[++cx];
1032
+ if (bx < cx) {
1033
+ var b = body.slice(bx, cx);
1034
+ relink(b);
1035
+ pushstep(result, b);
1036
+ bx = cx;
1037
+ }
992
1038
  if (!o) break;
993
1039
  while (labels.length) {
994
1040
  var e = labels[labels.length - 1];
@@ -20,13 +20,14 @@ test('a * a || b * c || c * d', "_ = a * a @re _ = b * c @re c * d");
20
20
  test('a || b || c', "_ = a; if (_) return [1, 0]; _ = b; if (_) return [1, 0]; c", true);
21
21
  test('a?b:c', "if (!a) return [1, 0]; _ = b; return [2, 0];\r\n _ = c; return [1, 0]");
22
22
  test('a * a && b * c * c ** d', "_ = a * a @rz _ = b * c, _0 = c ** d, _ * _0");
23
- test('a = 1 + 2', "_ = 1 + 2; a = _", true);
23
+ test('a = 1 + 2', "a = 1 + 2", true);
24
24
  test('a = b', "a = b", true);
25
25
  test('a.a = b', "a.a = b", true);
26
26
  test('loaded[f.name] = a', "_ = f.name; loaded[_] = a", true);
27
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);
28
+ test('a = b.b = c.c', "_ = c.c; b.b = _; a = _", true);
29
+ test('a = b = c + d', "b = c + d; a = b", true);
30
+ test('a = b = c + d * 1', "_ = d * 1, b = c + _; a = b", true);
30
31
  test('return a = b', "a = b; return [b, 2]", true);
31
32
  test('a*a', "a * a", true);
32
33
  test('a * a && b * c * c ** d', "_ = a * a; if (!_) return [1, 0]; _ = b * c, _0 = c ** d, _ * _0", true);
@@ -57,7 +58,7 @@ test("if(await a) await b", "_ = a; return [_, 1];\r\n if (!@) return [2, 0]; _
57
58
  test("for(a in b)", "for (a in b)", true);
58
59
  test("for(var a in b) a.push()", "for (var a in b) a.push()", true);
59
60
  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())", "_ = Symbol.iterator; _ = os[_]; if (_) return [1, 0]; _ = Symbol.asyncIterator; _ = os[_]; if (_) return [1, 0]; _ = Symbol.iterator; _ = Array.prototype[_];\r\n a = _; _ = a.call(os); a = _; _ = a.next(); b = _; return [1, 0];\r\n _ = !b.done; if (!_) return [1, 0]; o = b.value; _ = (true);\r\n if (!_) return [1, 0]; _ = a.next(); b = _; return [-1, 0]", true);
61
+ 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())", "_ = Symbol.iterator; _ = os[_]; if (_) return [1, 0]; _ = Symbol.asyncIterator; _ = os[_]; if (_) return [1, 0]; _ = Symbol.iterator; _ = Array.prototype[_];\r\n a = _; a = a.call(os); b = a.next(); return [1, 0];\r\n _ = !b.done; if (!_) return [1, 0]; o = b.value; _ = (true);\r\n if (!_) return [1, 0]; b = a.next(); return [-1, 0]", true);
61
62
  test("for(a=0;a<1;a++)if(a==0)continue\r\n else a=1", `a = 0; return [1, 0];\r\n _ = a < 1; if (!_) return [3, 0]; _ = a == 0; if (_) return [2, 0]; return [1, 0];\r\n a = 1; return [1, 0];\r\n _ = a++; return [-2, 0]`, true);
62
63
  test("for(a=0;a<1;a++)if(a==0){continue} else {a=1}", `a = 0; return [1, 0];\r\n _ = a < 1; if (!_) return [3, 0]; _ = a == 0; if (!_) return [1, 0]; return [2, 0];\r\n a = 1; return [1, 0];\r\n _ = a++; return [-2, 0]`, true);
63
64
  test("for(a=0;a<1;a++){if(a==0){a=2;continue} else if(b) {a=1;continue} c=3}", `a = 0; return [1, 0];\r\n _ = a < 1; if (!_) return [4, 0]; _ = a == 0; if (!_) return [1, 0]; a = 2; return [3, 0];\r\n if (!b) return [1, 0]; a = 1; return [2, 0];\r\n c = 3; return [1, 0];\r\n _ = a++; return [-3, 0]`, true);
@@ -75,24 +76,26 @@ test("switch(a){case 1:case 2:break;}", "if (a === 1) return [1, 0]; if (a === 2
75
76
  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);
76
77
  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);
77
78
  test("with(a){ a = 1}", `if (_ = with_("a", [a])) _.a = 1; else a = 1;`, true);
78
- test("try{a=2+1}catch(e){return;}", 'return [65537, 7];\r\n _ = 2 + 1; a = _; return [0, 9];\r\n e = @; return [undefined, 2];\r\n return [1, 9]', true);
79
- test("try{a=2+1}catch(e){}", 'return [1, 7];\r\n _ = 2 + 1; a = _; return [0, 9];\r\n return [1, 9]', true);
80
- 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);
79
+ test("try{a=2+1}catch(e){return;}", 'return [65537, 7];\r\n a = 2 + 1; return [0, 9];\r\n e = @; return [undefined, 2];\r\n return [1, 9]', true);
80
+ test("try{a=2+1}catch(e){}", 'return [1, 7];\r\n a = 2 + 1; return [0, 9];\r\n return [1, 9]', true);
81
+ test("try{a=2+1}catch(e){a=3}", 'return [65537, 7];\r\n a = 2 + 1; return [0, 9];\r\n e = @; a = 3; return [0, 9];\r\n return [1, 9]', true);
81
82
  test("(function(){})", '_ = function () {}; (_)', true);
82
83
  test("(1+2*function(){}())", '_ = 2 * function () {}(), _ = 1 + _; (_)', true);
83
84
  test("function a(){}", 'function a() {}', true);
84
85
  test("await new Promise(function(){})", '_ = function () {}; _ = new Promise(_); return [_, 1]', true);
85
86
  test(`onerror({ status: xhr.status, response: "Cookie解析异常!", toString: toResponse })`, '_ = { status: xhr.status, response: "Cookie解析异常!", toString: toResponse }; onerror(_)', true);
86
87
  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);
87
- 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);
88
+ 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);
88
89
  test(`a = newname.querySelector("input,textarea").value = c.name.replace(/\\/$/, '')`, `_ = c.name.replace(/\\/$/, ''); newname.querySelector("input,textarea").value = _; a = _`, true);
89
90
  test(`if (selected[f.url]) f.selected = true;`, `_ = f.url; _ = selected[_]; if (!_) return [1, 0]; f.selected = true; return [1, 0]`, true);
90
91
  test(`location.protocol + parseURL(a.b).host `, `_ = a.b; _ = parseURL(_); location.protocol + _.host`, true);
91
- test(`var base = location.protocol + "//" + parseURL(this.$scope.data.host).host + "/";`, `_ = location.protocol + "//", _0 = this.$scope.data.host; _0 = parseURL(_0); _ = _ + _0.host, _ = _ + "/"; base = _`, true);
92
- test(`a=a+b*c+c*d`, `_ = b * c, _ = a + _, _0 = c * d, _ = _ + _0; a = _`, true);
92
+ test(`var base = location.protocol + "//" + parseURL(this.$scope.data.host).host + "/";`, `_ = location.protocol + "//", _0 = this.$scope.data.host; _0 = parseURL(_0); _ = _ + _0.host, base = _ + "/"`, true);
93
+ test(`a=a+b*c+c*d`, `_ = b * c, _ = a + _, _0 = c * d, a = _ + _0`, true);
93
94
  test(`cc.name += "<f test></f>"`, `_ = cc.name + "<f test></f>"; cc.name = _`, true);
94
95
  test("yield a", 'return [a, 3]', true);
95
96
  test("throw a", 'throw a', true);
96
97
  test("debugger", 'debugger', true);
97
98
  test("a(b,b+=1)", '_ = b; _0 = b + 1; b = _0; a(_, _0)', true);
98
- test("while(a){if(b){if(c);else d;continue;}}", 'if (!a) return [4, 0]; if (!b) return [3, 0]; if (!c) return [1, 0]; return [2, 0];\r\n d; return [1, 0];\r\n return [-2, 0];\r\n return [-3, 0]', true);
99
+ test("while(a){if(b){if(c);else d;continue;}}", 'if (!a) return [4, 0]; if (!b) return [3, 0]; if (!c) return [1, 0]; return [2, 0];\r\n d; return [1, 0];\r\n return [-2, 0];\r\n return [-3, 0]', true);
100
+ test("/*abc*/", '/*abc*/', true);
101
+ test("//aaa", '//aaa', true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "4.0.10",
3
+ "version": "4.0.11",
4
4
  "description": "简化前端开发,优化web性能",
5
5
  "main": "public/efront.js",
6
6
  "directories": {