efront 4.0.17 → 4.0.19

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.
@@ -34,9 +34,14 @@ function encode(str, q = "\"", escapeUnicode = true) {
34
34
  function decode(s) {
35
35
  var r = /^(['"`])([\s\S]*)\1$/.exec(s);
36
36
  if (!r) return s;
37
- return r[2].replace(/\\u[0-9a-f]{4}|\\x[0-9a-f]{2}|\\([0-7]{1,3}|[\s\S])/ig, (a, b) => {
37
+ return r[2].replace(/\\u\{[0-9a-f]+\}|\\u[0-9a-f]{4}|\\x[0-9a-f]{2}|\\([0-7]{1,3}|[\s\S])/ig, (a, b) => {
38
38
  if (!b) {
39
- return String.fromCharCode(parseInt(a.slice(2), 16));
39
+ a = parseInt(a.slice(2).replace(/^\{(.*)\}$/, '$1'), 16);
40
+ if (a > 0xffff) {
41
+ a -= 0x10000;
42
+ return String.fromCharCode((0b11011000 | a >> 18) << 8 | a >> 10 & 0xff, (0b11011100 | a >> 8 & 0b00000011) << 8 | a & 0xff);
43
+ }
44
+ return String.fromCharCode(a);
40
45
  }
41
46
  if (unescapeMap.hasOwnProperty(a)) return unescapeMap[a];
42
47
  if (/^[0-7]+$/.test(b)) return String.fromCharCode(parseInt(b, 8));
@@ -30,6 +30,8 @@ var Symbol = this.Symbol || function () {
30
30
  };
31
31
  try {
32
32
  Object.defineProperty(Array.prototype, Symbol.iterator, { value: iterator, enumerable: false })
33
- } catch { }
33
+ } catch {
34
+ Array.prototype[Symbol.iterator] = iterator;
35
+ }
34
36
  return Symbol;
35
37
  }();
@@ -1,7 +1,10 @@
1
1
  class Generator {
2
2
  constructor(f) {
3
3
  this.state = "suspended";
4
- this.exec = f;
4
+ this.exec = f.bind(this, this.return, this.throw, function (value, next) {
5
+ this.exec = next;
6
+ this.value = value;
7
+ });
5
8
  };
6
9
  throw(e) {
7
10
  delete this.exec;
@@ -13,15 +16,12 @@ class Generator {
13
16
  this.state = "closed";
14
17
  return { value: undefined, done: true };
15
18
  }
16
- next() {
19
+ next(arg) {
17
20
  if (this.exec) {
18
21
  var exec = this.exec;
19
22
  delete this.exec;
20
23
  delete this.value;
21
- exec(this.return, this.throw, (value, exec) => {
22
- this.value = value;
23
- this.exec = exec;
24
- });
24
+ exec(arg);
25
25
  }
26
26
  return { value: this.value, done: !this.exec };
27
27
  }
@@ -1,7 +1,11 @@
1
1
  class AsyncGenerator {
2
2
  constructor(f) {
3
3
  this.state = "suspended";
4
- this.exec = f;
4
+ this.exec = f.bind(this, this.return, this.throw, (value, next) => {
5
+ this.exec = next;
6
+ delete this.promise;
7
+ this.resolve({ value, done: false });
8
+ })
5
9
  };
6
10
  throw(e) {
7
11
  delete this.exec;
@@ -13,30 +17,20 @@ class AsyncGenerator {
13
17
  this.state = "closed";
14
18
  return Promise.resolve({ value: undefined, done: true });
15
19
  }
16
- next() {
20
+ next(a) {
17
21
  if (this.exec) {
18
22
  var exec = this.exec;
19
23
  delete this.exec;
20
24
  delete this.value;
21
- return this.promise = new Promise(function (ok, oh) {
22
- exec(function (result) {
23
- delete this.promise;
24
- ok(result);
25
- this.return(result);
26
- }, function (error) {
27
- delete this.promise;
28
- oh(error);
29
- this.throw(error);
30
- }, (value, exec) => {
31
- delete this.promise;
32
- ok({ value: value, done: !this.exec })
33
- this.value = value;
34
- this.exec = exec;
35
- });
36
- })
25
+ this.promise = new Promise(ok => {
26
+ this.resolve = ok;
27
+ exec(a);
28
+ });
29
+ return this.promise;
37
30
  }
38
31
  else if (this.promise) {
39
- return this.promise.then(this.next, this.next);
32
+ var next = () => this.next(a);
33
+ return this.promise.then(next, next);
40
34
  }
41
35
  return Promise.resolve({ value: undefined, done: true });
42
36
  }
@@ -1,22 +1,23 @@
1
1
  var exec_ = function (args, ok, oh, int) {
2
- var p = null, index = 0, r, finished = false, t = this;
2
+ var p = null, index = 0, r, e, finished = false, t = this;
3
3
  var next = function (arg) {
4
4
  p = arg;
5
5
  run();
6
6
  };
7
- var catches = [], catch_;
7
+ var catches = [], catch_, throwed;
8
8
  var thro = function (err) {
9
9
  if (catch_) {
10
10
  fina();
11
11
  }
12
12
  else if (catches.length) {
13
13
  catch_ = catches.pop();
14
- [index, p] = catch_;
14
+ [index, p, throwed] = catch_;
15
15
  index += p & 0xffff;
16
16
  if (p >>> 16) {
17
17
  next(err);
18
18
  }
19
19
  else {
20
+ e = err;
20
21
  fina();
21
22
  }
22
23
  }
@@ -44,7 +45,10 @@ var exec_ = function (args, ok, oh, int) {
44
45
  }
45
46
  var run = function () {
46
47
  var args_length = args.length, i;
47
- if (finished && !catch_ || index >= args_length) return ok(r);
48
+ if (!catch_ || index >= args_length) {
49
+ if (throwed) return oh();
50
+ if (finished) return ok(r);
51
+ }
48
52
  while (index < args_length) {
49
53
  try {
50
54
  [p, i] = args[index].call(t, p) || [1, 0];
@@ -61,7 +65,8 @@ var exec_ = function (args, ok, oh, int) {
61
65
  else return next(p);
62
66
  case 2: return finished = true, retn(p); // return p;
63
67
  case 3: return index++, int(p, next); // yield p;
64
- case 7: index++; catches.push([index, p]); break; // try start
68
+ case 7: index++; catches.push([index, p]); break; // try catch finally?
69
+ case 8: index++; catches.push([index, p, 1]); break; // try finally
65
70
  case 9: return p ? fine() : fina(); // finally
66
71
  default: throw "代码异常!";
67
72
  }
@@ -75,12 +75,6 @@ Javascript.prototype.fixType = function (o) {
75
75
  if (m === 'yield') {
76
76
  var temp = queue;
77
77
  var type = STRAP;
78
- if (queue.entry === '[' || queue.isClass || queue.isObject || last && (last.type === STAMP && (
79
- queue[queue.length - 1].type !== SPACE && /^(\+\+|\-\-)$/.test(last.text)
80
- || !/^(>>>?=|<<=|[^><!=]=|[,;])/.test(last.text)
81
- ) || last.type === STRAP)) {
82
- type = EXPRESS;
83
- }
84
78
  if (type === STRAP) while (temp) {
85
79
  if (temp.entry != "{" || !temp.prev || temp.prev.type !== SCOPED || temp.prev.entry !== '(') {
86
80
  temp = temp.queue;
@@ -195,9 +189,16 @@ Javascript.prototype.setType = function (o) {
195
189
  if (o.type & (VALUE | QUOTED | STRAP)) {
196
190
  o.isprop = this.isProperty(o);
197
191
  }
198
- else if (o.type === SCOPED && o.entry === '[') {
199
- if (queue.isObject) o.isprop = this.isProperty(o);
200
- if (queue.isClass) o.isprop = !last || last.isprop || last.type === STAMP && last.text === ';';
192
+ else if (o.type === SCOPED) {
193
+ if (o.entry === '[') {
194
+ if (queue.isObject) o.isprop = this.isProperty(o);
195
+ if (queue.isClass) o.isprop = !last || last.isprop || last.type === STAMP && last.text === ';';
196
+ }
197
+ else if (o.entry === "{") {
198
+ if (last && last.type === PROPERTY && last.text === 'static') {
199
+ last.type = STRAP;
200
+ }
201
+ }
201
202
  }
202
203
  else if (o.type === STAMP) {
203
204
  o.isprop = o.text === "*" && (!last || /^[,;]$/.test(last.text) || queue.isClass && isShortMethodEnd(last));
@@ -76,14 +76,9 @@ var skipAssignment = function (o, cx) {
76
76
  needpunc = false;
77
77
  break;
78
78
  default:
79
- if (/^[!~\+\-]+$/.test(o.text)) {
80
- needpunc = false;
81
- next();
82
- break;
83
- }
84
- if (!needpunc) break loop;
85
79
  needpunc = false;
86
80
  next();
81
+ break;
87
82
  }
88
83
  break;
89
84
  case SCOPED:
@@ -200,6 +195,20 @@ function skipSentenceQueue(o) {
200
195
  } while (o && o.type === STAMP && o.text === ',' ? o = o.next : false);
201
196
  return o;
202
197
  }
198
+ function skipFunction(o) {
199
+ if (o.type === STRAP && o.text === 'async') o = o.next;
200
+ if (o.type !== STRAP) return skipAssignment(o);
201
+ if (o.text === 'function') {
202
+ while (o && (o.type !== SCOPED || o.entry !== '{')) o = o.next;
203
+ return o.next;
204
+ }
205
+ if (o.text === 'class') {
206
+ while (!o.isClass) o = o.next;
207
+ while (o.isClass) o = o.next;
208
+ return o;
209
+ }
210
+ return o;
211
+ }
203
212
  function snapSentenceHead(o) {
204
213
  // 只检查一级
205
214
  while (o && o.prev) {
@@ -364,6 +373,19 @@ var snapExpressFoot = function (o) {
364
373
  }
365
374
  return o;
366
375
  };
376
+ var mustBeYield = function (o) {
377
+ if (!o.next) return;
378
+ var mustyield = false;
379
+ if (o.next.type === STRAP && !/^(?:instanceof|in|of|from|as)$/.test(o.next.text)
380
+ || o.next.type === STAMP && /[!~]/.test(o.next.text)
381
+ || o.next.type === EXPRESS && !/^[\.\[]/.test(o.next.text)
382
+ || o.next.type & (VALUE | QUOTED | SCOPED)
383
+ ) {
384
+ mustyield = true;
385
+ }
386
+ return mustyield;
387
+
388
+ }
367
389
  var createScoped = function (parsed, wash) {
368
390
  var used = Object.create(null); var vars = Object.create(null), lets = vars;
369
391
  var scoped = [], funcbody = scoped, argscope = scoped, thisscope = scoped;
@@ -430,11 +452,11 @@ var createScoped = function (parsed, wash) {
430
452
  o.type = STRAP;
431
453
  continue;
432
454
  }
433
- if ((!o.prev || o.prev.type !== STAMP || o.prev.text === ';') && (!o.next || o.next.type !== STAMP || o.next.text === '*')) {
455
+ if (mustBeYield(o)) {
434
456
  o.type = STRAP;
435
457
  funcbody.aster = true;
436
- continue;
437
458
  }
459
+ continue;
438
460
  }
439
461
  if (o.next && o.next.type === STAMP && o.next.text === "=>") {
440
462
  isScope = true;
@@ -487,17 +509,8 @@ var createScoped = function (parsed, wash) {
487
509
  break;
488
510
  };
489
511
  }
490
- if (mustyield !== false && o.next) {
491
- if (o.next.type === STRAP && !/^(?:instanceof|in|of|from|as)$/.test(o.next.text)
492
- || o.next.type === STAMP && /[!~]/.test(o.next.text)
493
- || o.next.type === EXPRESS && !/^[\.\[]/.test(o.next.text)
494
- || o.next.type & (VALUE | QUOTED | SCOPED)
495
- ) {
496
- mustyield = true;
497
- }
498
- }
512
+ if (mustyield !== false) mustyield = mustBeYield(o);
499
513
  if (mustyield) funcbody.aster = true;
500
- else o.type = EXPRESS;
501
514
  continue;
502
515
  }
503
516
  funcbody.yield = true;
@@ -522,6 +535,7 @@ var createScoped = function (parsed, wash) {
522
535
  mergeTo(used, used0);
523
536
  mapDeclared(m, declared);
524
537
  continue loop;
538
+ case "static":
525
539
  case "function":
526
540
  isFunction = true;
527
541
 
@@ -548,7 +562,6 @@ var createScoped = function (parsed, wash) {
548
562
  o = o.next;
549
563
  }
550
564
  }
551
-
552
565
  isScope = true;
553
566
  break;
554
567
  case "for":
@@ -1187,6 +1200,24 @@ var createExpressList = function (code) {
1187
1200
  }
1188
1201
  return list;
1189
1202
  };
1203
+ var isHalfSentence = function (body, i) {
1204
+ var a = body[i];
1205
+ while (a && a.type & (SPACE | COMMENT)) a = body[--i];
1206
+ if (!a) return false;
1207
+ if (a.type === STRAP && a.text === 'else') return true;
1208
+ if (a.type !== SCOPED || a.entry !== "(") return false;
1209
+ a = a.prev;
1210
+ if (!a || a.type !== STRAP) return false;
1211
+ if (a.text === 'while') {
1212
+ var p = a.prev;
1213
+ if (!p || p.type !== SCOPED || p.entry !== '{' || !p.prev) return true;
1214
+ p = p.prev;
1215
+ if (p.type !== STRAP || p.text !== 'do') return true;
1216
+ return false;
1217
+ }
1218
+ return /^(if|for|with)$/.test(a.text);
1219
+ };
1220
+
1190
1221
  var splice = function (queue, index, size, ...args) {
1191
1222
  if (index < 0) index += queue.length;
1192
1223
  var p = queue[index];
@@ -1245,6 +1276,8 @@ module.exports = {
1245
1276
  relink,
1246
1277
  setqueue,
1247
1278
  replace,
1279
+ skipFunction,
1280
+ isHalfSentence,
1248
1281
  splice,
1249
1282
  mergeTo
1250
1283
  };
@@ -1,7 +1,7 @@
1
1
  var scanner2 = require("./scanner2");
2
2
  var strings = require("../basic/strings");
3
3
  var Program = scanner2.Program;
4
- var { STAMP, SCOPED, STRAP, EXPRESS, COMMENT, SPACE, PROPERTY, VALUE, LABEL, QUOTED, rename, getDeclared, skipAssignment, createScoped, createString, splice, relink, snapExpressHead, needBreakBetween } = require("./common");
4
+ var { STAMP, SCOPED, STRAP, EXPRESS, COMMENT, SPACE, PROPERTY, VALUE, LABEL, QUOTED, rename, isHalfSentence, skipFunction, getDeclared, skipAssignment, skipSentenceQueue, createScoped, createString, splice, relink, snapExpressHead, needBreakBetween } = require("./common");
5
5
  var splice2 = function (q, from, to, ...a) {
6
6
  var cx = q.indexOf(from);
7
7
  if (cx < 0) throw console.log(splice2.caller, console.format('\r\n<red2>自</red2>'), from && createString([from]), console.format('\r\n<yellow>至</yellow>'), to && createString([to]), console.format(`\r\n<cyan>码列</cyan>`), createString(q)), '结构异常';
@@ -446,6 +446,7 @@ var rootenvs = null, rootHyper;
446
446
  var killcls = function (body, i, getname_) {
447
447
  var extends_ = [];
448
448
  var o = body[i];
449
+ var ishalf = isHalfSentence(body, i - 1);
449
450
  var start = o;
450
451
  var decName = !o.isExpress && o.next.type === EXPRESS && o.next.text;
451
452
  while (o) {
@@ -494,7 +495,14 @@ var killcls = function (body, i, getname_) {
494
495
  var k = prop.static ? clz.name : `${clz.name}["prototype"]`;
495
496
  var d = prop.static ? static_ : define_;
496
497
  if (prop.get || prop.set || prop.static) {
497
- setprop(prop, k, d, defines);
498
+ if (prop.name) {
499
+ setprop(prop, k, d, defines);
500
+ }
501
+ else if (prop.static) {
502
+ var value = scanner2(`(function(){}())`);
503
+ splice(value[0], 2, 1, ...prop.value)
504
+ splice(foot, 0, foot.length, value[0]);
505
+ }
498
506
  }
499
507
  else if (/^(?:\.constructor|\[(['"`])constructor\1\])$/.test(prop.name)) {
500
508
  constructor = prop.value;
@@ -561,7 +569,7 @@ var killcls = function (body, i, getname_) {
561
569
  var s = i;
562
570
  i = body.indexOf(o, i);
563
571
  if (i < 0) i = body.length;
564
- if (head.length > 1 || start.isExpress) {
572
+ if (head.length > 1 || start.isExpress || ishalf && defines.length) {
565
573
  splice(defines, defines.length, 0, ...scanner2(`\r\nreturn ${clz.name}`))
566
574
  if (decName) splice(func, 0, 0, ...scanner2(`var ${decName}=`));
567
575
  splice(body, s, i - s, ...func);
@@ -571,7 +579,7 @@ var killcls = function (body, i, getname_) {
571
579
  splice(invokes, invokes.length, 0, { text: ';', type: STAMP }, ...defines);
572
580
  }
573
581
  splice(body, s, i - s, ...invokes);
574
- if (o) insert1(body, o, { type: SPACE, text: '\r\n' });
582
+ if (o && o.type & ~(SPACE | STAMP) && invokes.length) insert1(body, o, { type: SPACE, text: '\r\n' });
575
583
  }
576
584
  return i;
577
585
  };
@@ -747,7 +755,7 @@ var killobj = function (body, getobjname, getletname, getname_, letname_, deep =
747
755
  var y = scanner2(`for(var ${name} of) yield ${name};`);
748
756
  y[2].type = STRAP;
749
757
  splice(y[1], y[1].length, 0, ...splice(body, i, n - i));
750
- unforof(y[1], getname_.bind(null, '_'), y.used);
758
+ unforof(y[0], getname_.bind(null, '_'), y.used);
751
759
  splice(body, i - 1, 1, ...y);
752
760
  }
753
761
  i++;
@@ -918,7 +926,7 @@ var unforin = function (o, getnewname_, killobj) {
918
926
  if (n.type !== STRAP || n.text !== 'in') {
919
927
  return false;
920
928
  }
921
- if (ises3(o, killobj) && ises3(o.next, killobj)) return;
929
+ if (ises3(o.first, killobj) && ises3(o.next, killobj)) return;
922
930
  var prev = o.prev;
923
931
  while (prev && prev.type === LABEL) prev = prev.prev;
924
932
  var pp = prev && prev.prev;
@@ -947,6 +955,8 @@ var unforin = function (o, getnewname_, killobj) {
947
955
 
948
956
  var unforof = function (o, getnewname, used) {
949
957
  var hasawait = false;
958
+ var r = o;
959
+ o = o.next;
950
960
  if (o.type === STRAP && o.text === 'await') {
951
961
  hasawait = true;
952
962
  splice2(o.queue, o, o.next);
@@ -986,7 +996,14 @@ var unforof = function (o, getnewname, used) {
986
996
  splice(o, o.length, 0, { type: STAMP, text: ',' });
987
997
  }
988
998
  if (useSimpleLoop) splice(o, o.length, 0, ...scanner2(`${iname}=0,${gname}=${oname}["length"];${iname}<${gname}&&(${createString([p])}=${oname}[${iname}],true);${iname}++`));
989
- else rootenvs.Symbol = true, splice(o, o.length, 0, ...scanner2(`${gname}=${hasawait ? `${oname}[Symbol["asyncIterator"]]||${oname}[Symbol["iterator"]]` : `${oname}[Symbol["iterator"]]||${oname}[Symbol["asyncIterator"]]`}||Array["prototype"][Symbol["iterator"]],${gname}=${gname}["call"](${oname}),${iname}=${hasawait ? "await " : ''}${gname}["next"]();!${iname}["done"]&&(${createString([p])}=${iname}["value"],true);${iname}=${hasawait ? 'await ' : ''}${gname}["next"]()`));
999
+ else {
1000
+ rootenvs.Symbol = true, splice(o, o.length, 0, ...scanner2(`${gname}=${hasawait ? `${oname}[Symbol["asyncIterator"]]||${oname}[Symbol["iterator"]]` : `${oname}[Symbol["iterator"]]`}||Array["prototype"][Symbol["iterator"]],${gname}=${gname}["call"](${oname}),${iname}=${hasawait ? "await " : ''}${gname}["next"]();!${iname}["done"]&&(${createString([p])}=${iname}["value"],true);${iname}=${hasawait ? 'await ' : ''}${gname}["next"]()`));
1001
+ var n = o.next;
1002
+ n = skipSentenceQueue(n);
1003
+ var tf = scanner2(`try{}finally{if(${iname}&&!${iname}["done"]&&isFunction(${gname}["return"]))${gname}["return"]()}`);
1004
+ splice(tf[1], 0, 0, ...splice2(r.queue, r, n, ...tf));
1005
+ rootenvs.isFunction = true;
1006
+ }
990
1007
  relink(o);
991
1008
  };
992
1009
  var unarrow = function (body, i, killobj, letname_) {
@@ -1146,9 +1163,10 @@ var killret = function (body, labels = Object.create(null), gettmpname) {
1146
1163
  lbls.push(lbl);
1147
1164
  }
1148
1165
  }
1149
- else if (o.type === SCOPED) {
1150
- killret(o, labels, gettmpname);
1151
- if (o.entry === '{') unlabel = true;
1166
+ else if (o.type === SCOPED && o.entry === "{") {
1167
+ if (o.isClass || o.isObject);
1168
+ else killret(o, labels, gettmpname);
1169
+ unlabel = true;
1152
1170
  }
1153
1171
  else if (o.type === STAMP && o.text === ';') {
1154
1172
  unlabel = true;
@@ -1157,16 +1175,22 @@ var killret = function (body, labels = Object.create(null), gettmpname) {
1157
1175
  for (var lbl of lbls) delete labels[lbl];
1158
1176
  lbls = [];
1159
1177
  }
1178
+ if (o.type === STAMP && o.text === "=>") {
1179
+ o = skipFunction(o);
1180
+ continue;
1181
+ }
1160
1182
  if (o.type !== STRAP) {
1161
1183
  o = o.next;
1162
1184
  continue;
1163
1185
  }
1164
1186
  switch (o.text) {
1187
+ case "async":
1188
+ case "class":
1165
1189
  case "function":
1166
- while (o && o.type !== SCOPED || o.entry !== '{') o = o.next;
1167
- break;
1190
+ o = skipFunction(o);
1191
+ continue;
1168
1192
  case "return":
1169
- if (o.next && !o.isend) insert1(body, o.next, ...scanner2(`${gettmp()}=1,`));
1193
+ if (o.next && !o.isend) insert1(body, o.next, ...scanner2(`${gettmp(1, o.next)}=1,`));
1170
1194
  else insert1(body, o.next, ...scanner2(`${gettmp()}=1,void 0`)), o.isend = false;
1171
1195
  breakmap[o.text] = 1;
1172
1196
  break;
@@ -1206,6 +1230,7 @@ var killret = function (body, labels = Object.create(null), gettmpname) {
1206
1230
  }
1207
1231
  return breakmap;
1208
1232
  }
1233
+
1209
1234
  var down = function (scoped) {
1210
1235
  var inAsync = scoped.async;
1211
1236
  var inAster = scoped.yield;
@@ -1361,7 +1386,7 @@ var down = function (scoped) {
1361
1386
  if (hp && hp.type === STRAP && hp.text === 'await') hp = hp.prev;
1362
1387
  if (!hp) break a;
1363
1388
  if (hp.text === 'for') {
1364
- unforof(hp.next, getdeepname, scoped.used);
1389
+ unforof(hp, getdeepname, scoped.used);
1365
1390
  if (funcMark) killed = unforin(scoped.head, getdeepname, _killobj.bind(null, _getlocal)) !== false;
1366
1391
  // unforcx(scoped.head, getdeepname);
1367
1392
  }
@@ -1436,7 +1461,7 @@ var downcode = downLevel.code = function (code) {
1436
1461
  code.keepcolor = false;
1437
1462
  if (rootenvs.slice_) {
1438
1463
  delete rootenvs.slice_;
1439
- if (!code.vars.slice_) splice(code.scoped.body, 0, 0, ...scanner2('var slice_ = Array["prototype"]["slice"];\r\n'));
1464
+ if (!code.vars.slice_) splice(code, 0, 0, ...scanner2('var slice_ = Array["prototype"]["slice"];\r\n'));
1440
1465
  }
1441
1466
  rootenvs = null;
1442
1467
  return code;
@@ -53,6 +53,14 @@ assert(downLevel(`function (a=b,[c],d,e=f){}`), "function (a, arg1, d, e) { if (
53
53
  assert(downLevel(`function (arg1=b,[c],d,e=f){}`), "function (arg1, arg2, d, e) { if (arg1 === undefined) arg1 = b; var c = arg2[0]; if (e === undefined) e = f; }")
54
54
  i++// class降级
55
55
  assert(downLevel(`class a {}`), "function a() {}")
56
+ assert(downLevel(`class a { static{ a.a=1}}`), "function a() {}; (function () { a.a = 1 }())")
57
+ assert(downLevel(`if(a) a = 1; class a {}`), "if (a) a = 1; function a() {}")
58
+ assert(downLevel(`async function(){if(a) a = 1; class a {}}`), `function () { return async_(
59
+ function () {
60
+ a = function a() {}; if (!a) return [1, 0]; a = 1; return [1, 0]
61
+ })
62
+ var a, _0 }`)
63
+ assert(downLevel(`if(a) class b{ c(){}};`), `if (a) var b = function (b) { b["prototype"].c = function () {}\r\nreturn b }(function b() {});`)
56
64
  assert(downLevel(`class a {a=1}`), "function a() { this.a = 1 }")
57
65
  assert(downLevel(`class a {a=1; b(){}}`), `function a() { this.a = 1; }; a["prototype"].b = function () {}`)
58
66
  assert(downLevel(`=class a {a=1; b(){}}`), `= function (a) { a["prototype"].b = function () {}\r\nreturn a }(function a() { this.a = 1; })`)
@@ -188,6 +196,9 @@ assert(downLevel(`function (a,...,c){}`), `function (a, c) { c = arguments["leng
188
196
  assert(downLevel(`(...a) => k`), `var slice_ = Array["prototype"]["slice"];\r\nfunction () { var a = slice_["call"](arguments, 0); return k }`)
189
197
  assert(downLevel(`for await(o of os) noSymbol`), `return async_(
190
198
  function () {
199
+ return [7, 8]
200
+ },
201
+ function () {
191
202
  _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
203
  },
193
204
  function () {
@@ -204,10 +215,25 @@ if (!_2) return [2, 0]; noSymbol; _2 = _0["next"](); return [_2, 1]
204
215
  },
205
216
  function (_1) {
206
217
  _2 = _1; _ = _2; return [-2, 0]
218
+ },
219
+ function () {
220
+ return [0, 9]
221
+ },
222
+ function () {
223
+ _2 = _ &&! _["done"]; if (!_2) return [1, 0]; _2 = _0["return"]; _2 = isFunction(_2)
224
+ },
225
+ function () {
226
+ if (!_2) return [1, 0]; _2 = _0["return"](); return [1, 0]
227
+ },
228
+ function () {
229
+ return [1, 9]
207
230
  })
208
231
  var _, _0, _2`)
209
232
  assert(downLevel(`for await(var [o,s] of os) noSymbol`), `return async_(
210
233
  function () {
234
+ return [7, 8]
235
+ },
236
+ function () {
211
237
  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
238
  },
213
239
  function () {
@@ -224,14 +250,26 @@ if (!_3) return [2, 0]; noSymbol; _3 = _0["next"](); return [_3, 1]
224
250
  },
225
251
  function (_2) {
226
252
  _3 = _2; _ = _3; return [-2, 0]
253
+ },
254
+ function () {
255
+ return [0, 9]
256
+ },
257
+ function () {
258
+ _3 = _ &&! _["done"]; if (!_3) return [1, 0]; _3 = _0["return"]; _3 = isFunction(_3)
259
+ },
260
+ function () {
261
+ if (!_3) return [1, 0]; _3 = _0["return"](); return [1, 0]
262
+ },
263
+ function () {
264
+ return [1, 9]
227
265
  })
228
266
  var o, s, _, _0, _1, _3`)
229
267
  assert(downLevel(`for(o of os) noSymbol`), `for (_ = 0, _0 = os["length"]; _ < _0 && (o = os[_], true); _++) noSymbol\r\nvar _, _0`)
230
- assert(downLevel(`for(var o of os) Symbol`), `for (var o, _0 = os[Symbol["iterator"]] || os[Symbol["asyncIterator"]] || Array["prototype"][Symbol["iterator"]], _0 = _0["call"](os), _ = _0["next"](); !_["done"] && (o = _["value"], true); _ = _0["next"]()) Symbol\r\nvar _, _0`)
231
- assert(downLevel(`for(var o of os) Symbol`), `for (var o, _0 = os[Symbol["iterator"]] || os[Symbol["asyncIterator"]] || Array["prototype"][Symbol["iterator"]], _0 = _0["call"](os), _ = _0["next"](); !_["done"] && (o = _["value"], true); _ = _0["next"]()) Symbol\r\nvar _, _0`)
232
- assert(downLevel(`for(var o of o)Symbol`), `for (var o, _1 = o, _0 = _1[Symbol["iterator"]] || _1[Symbol["asyncIterator"]] || Array["prototype"][Symbol["iterator"]], _0 = _0["call"](_1), _ = _0["next"](); !_["done"] && (o = _["value"], true); _ = _0["next"]()) Symbol\r\nvar _, _0, _1`)
233
- assert(downLevel(`for(var [a] of os)Symbol`), `for (var a, _0 = os[Symbol["iterator"]] || os[Symbol["asyncIterator"]] || Array["prototype"][Symbol["iterator"]], _0 = _0["call"](os), _ = _0["next"](); !_["done"] && (a = _["value"][0], true); _ = _0["next"]()) Symbol\r\nvar _, _0`)
234
- assert(downLevel(`for(var [a,b] of os)Symbol`), `for (var a, b, _0 = os[Symbol["iterator"]] || os[Symbol["asyncIterator"]] || Array["prototype"][Symbol["iterator"]], _0 = _0["call"](os), _ = _0["next"](); !_["done"] && (_1 = _["value"], a = _1[0], b = _1[1], true); _ = _0["next"]()) Symbol\r\nvar _, _0, _1`)
268
+ assert(downLevel(`for(var o of os) Symbol`), `try { for (var o, _0 = os[Symbol["iterator"]] || Array["prototype"][Symbol["iterator"]], _0 = _0["call"](os), _ = _0["next"](); !_["done"] && (o = _["value"], true); _ = _0["next"]()) Symbol } finally { if (_ &&! _["done"] && isFunction(_0["return"])) _0["return"]() }\r\nvar _, _0`)
269
+ assert(downLevel(`for(var o of os) Symbol`), `try { for (var o, _0 = os[Symbol["iterator"]] || Array["prototype"][Symbol["iterator"]], _0 = _0["call"](os), _ = _0["next"](); !_["done"] && (o = _["value"], true); _ = _0["next"]()) Symbol } finally { if (_ &&! _["done"] && isFunction(_0["return"])) _0["return"]() }\r\nvar _, _0`)
270
+ assert(downLevel(`for(var o of o)Symbol`), `try { for (var o, _1 = o, _0 = _1[Symbol["iterator"]] || Array["prototype"][Symbol["iterator"]], _0 = _0["call"](_1), _ = _0["next"](); !_["done"] && (o = _["value"], true); _ = _0["next"]()) Symbol } finally { if (_ &&! _["done"] && isFunction(_0["return"])) _0["return"]() }\r\nvar _, _0, _1`)
271
+ assert(downLevel(`for(var [a] of os)Symbol`), `try { for (var a, _0 = os[Symbol["iterator"]] || Array["prototype"][Symbol["iterator"]], _0 = _0["call"](os), _ = _0["next"](); !_["done"] && (a = _["value"][0], true); _ = _0["next"]()) Symbol } finally { if (_ &&! _["done"] && isFunction(_0["return"])) _0["return"]() }\r\nvar _, _0`)
272
+ assert(downLevel(`for(var [a,b] of os)Symbol`), `try { for (var a, b, _0 = os[Symbol["iterator"]] || Array["prototype"][Symbol["iterator"]], _0 = _0["call"](os), _ = _0["next"](); !_["done"] && (_1 = _["value"], a = _1[0], b = _1[1], true); _ = _0["next"]()) Symbol } finally { if (_ &&! _["done"] && isFunction(_0["return"])) _0["return"]() }\r\nvar _, _0, _1`)
235
273
  assert(downLevel(`[...a]=a`), `var slice_ = Array["prototype"]["slice"];\r\na = slice_["call"](a, 0)`)
236
274
  assert(downLevel(`[c,...a]=a`), `var slice_ = Array["prototype"]["slice"];\r\nc = a[0], a = slice_["call"](a, 1)`)
237
275
  assert(downLevel(`[...a]=a`), `var slice_ = Array["prototype"]["slice"];\r\na = slice_["call"](a, 0)`)
@@ -242,9 +280,9 @@ assert(downLevel("if(a){}[r, g, b] = rgb4s(r, g, b, s)"), "if (a) {} _ = rgb4s(r
242
280
  assert(downLevel(`{c,[c]:b,...a}=a`), `c = a.c, b = a[c], a = rest_(a, ["c", c])`)
243
281
  assert(downLevel(`async()=>name = require("./$split")(name)["join"]("/");`), `function () { return async_(
244
282
  function () {
245
- name = require("./$split")(name)["join"]("/"); return [name, 2]
283
+ _0 = require("./$split"); _1 = _0(name); name = _1["join"]("/"); return [name, 2]
246
284
  })
247
- var _0 };`);
285
+ var _0, _1 };`);
248
286
  i++//异步或步进函数
249
287
  assert(downLevel(`function *(){yield *a}`), `function () { return aster_(
250
288
  function () {
@@ -263,7 +301,10 @@ var _, _0, _1, _3 }`)
263
301
  assert(downLevel(`async function(){}`), `function () { return async_() }`)
264
302
  assert(downLevel(`async function(){for(var a of b){Symbol}}`), `function () { return async_(
265
303
  function () {
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]
304
+ return [5, 8]
305
+ },
306
+ function () {
307
+ a; _2 = Symbol["iterator"]; _2 = b[_2]; if (_2) return [1, 0]; _2 = Symbol["iterator"]; _2 = Array["prototype"][_2]
267
308
  },
268
309
  function () {
269
310
  _0 = _2; _0 = _0["call"](b); _ = _0["next"](); return [1, 0]
@@ -273,6 +314,18 @@ _2 = !_["done"]; if (!_2) return [1, 0]; a = _["value"]; _2 = (true)
273
314
  },
274
315
  function () {
275
316
  if (!_2) return [1, 0]; Symbol; _ = _0["next"](); return [-1, 0]
317
+ },
318
+ function () {
319
+ return [0, 9]
320
+ },
321
+ function () {
322
+ _2 = _ &&! _["done"]; if (!_2) return [1, 0]; _2 = _0["return"]; _2 = isFunction(_2)
323
+ },
324
+ function () {
325
+ if (!_2) return [1, 0]; _2 = _0["return"](); return [1, 0]
326
+ },
327
+ function () {
328
+ return [1, 9]
276
329
  })
277
330
  var a, _, _0, _2 }`)
278
331
  assert(downLevel(`a={async a(){var b =c;return 1}}`), `a = (_ = {},
@@ -308,6 +361,6 @@ function () {
308
361
  if (!a) return [1, 0]; return [2, 0]
309
362
  },
310
363
  function () {
311
- _0 = getRequestProtocol(url) + "//", location = _0 + location; return [1, 0]
364
+ _1 = getRequestProtocol(url); _0 = _1 + "//", location = _0 + location; return [1, 0]
312
365
  })
313
- var _0 }`);
366
+ var _0, _1 }`);
@@ -4,7 +4,7 @@ var powermap = {};
4
4
  '&&,||,^^,??'/* 4 */, '&,|,^'/* 5 */,
5
5
  'instanceof,in,==,>=,<=,>,<,!=,!==,===,!in,!instanceof'/* 6 */,
6
6
  '>>,>>>,<<'/* 7 */, '+,-'/* 8 */, '*,/,%'/* 9 */, '**'/* 10 */,
7
- 'typeof,await,new,delete,void,!,~'/* 11 */, '++,--'/* 12 */,
7
+ 'typeof,await,yield,new,delete,void,!,~'/* 11 */, '++,--'/* 12 */,
8
8
  ].forEach((pp, i) => {
9
9
  pp.split(",").forEach(p => {
10
10
  powermap[p] = i + 1;