efront 4.0.20 → 4.0.23

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.
@@ -11,7 +11,7 @@ function queue(list, count = 1, context = null) {
11
11
  context = temp;
12
12
  }
13
13
  return new Promise(function (ok, oh) {
14
- var cx = 0;
14
+ var cx = list.skip || 0;
15
15
  var result = [];
16
16
  var promised = false;
17
17
  var error_count = 0;
@@ -22,8 +22,9 @@ function queue(list, count = 1, context = null) {
22
22
  var next = function () {
23
23
  run();
24
24
  };
25
+ var _count = count;
25
26
  var run = function () {
26
- if (error_count && count === 1) return promised = null;
27
+ if (error_count >= _count) return promised = null;
27
28
  if (cx >= list.length) return promised = null, count = 0, Promise.all(result).then(ok, oh);
28
29
  var saved_cx = cx;
29
30
  var args = list[cx];
@@ -20,10 +20,10 @@ var Symbol = this.Symbol || function () {
20
20
  Symbol.iterator = Symbol('iterator');
21
21
  Symbol.asyncIterator = Symbol('asyncIterator');
22
22
  var iterator = function () {
23
- var arr = this, cx = 0, dx = arr.length;
23
+ var arr = this, cx = 0;
24
24
  return {
25
25
  next() {
26
- if (cx < dx) return { value: arr[cx++], done: false };
26
+ if (cx < arr.length) return { value: arr[cx++], done: false };
27
27
  return { value: undefined, done: true };
28
28
  }
29
29
  }
@@ -1,7 +1,7 @@
1
1
  class Generator {
2
2
  constructor(f) {
3
3
  this.state = "suspended";
4
- this.exec = f.bind(this, this.return, this.throw, function (value, next) {
4
+ this.exec = f.bind(this, this.return.bind(this), this.throw.bind(this), function (value, next) {
5
5
  this.exec = next;
6
6
  this.value = value;
7
7
  });
@@ -14,21 +14,21 @@ class Generator {
14
14
  return(value) {
15
15
  delete this.exec;
16
16
  this.state = "closed";
17
- return { value: undefined, done: true };
17
+ this.value = value;
18
18
  }
19
19
  next(arg) {
20
+ delete this.value;
20
21
  if (this.exec) {
21
22
  var exec = this.exec;
22
23
  delete this.exec;
23
- delete this.value;
24
24
  exec(arg);
25
25
  }
26
26
  return { value: this.value, done: !this.exec };
27
27
  }
28
+ [Symbol.iterator]() {
29
+ return this;
30
+ }
28
31
  }
29
- Generator.prototype[Symbol.iterator] = function () {
30
- return this;
31
- };
32
32
 
33
33
  function aster_() {
34
34
  return new Generator(exec_.bind(this, arguments));
@@ -1,30 +1,37 @@
1
1
  class AsyncGenerator {
2
2
  constructor(f) {
3
3
  this.state = "suspended";
4
- this.exec = f.bind(this, this.return, this.throw, (value, next) => {
5
- this.exec = next;
4
+ this.exec = f.bind(this, this.return.bind(this), this.throw.bind(this), (value, next) => {
6
5
  delete this.promise;
7
- this.resolve({ value, done: false });
6
+ this.exec = next;
7
+ this.resolve(value);
8
8
  })
9
9
  };
10
10
  throw(e) {
11
11
  delete this.exec;
12
12
  this.state = "closed";
13
- return Promise.reject(e);
13
+ this.reject(e);
14
14
  }
15
- return(value) {
15
+ return(v) {
16
16
  delete this.exec;
17
17
  this.state = "closed";
18
- return Promise.resolve({ value: undefined, done: true });
18
+ this.value = v;
19
+ this.resolve(v);
19
20
  }
20
21
  next(a) {
22
+ delete this.value;
21
23
  if (this.exec) {
22
24
  var exec = this.exec;
23
25
  delete this.exec;
24
- delete this.value;
25
- this.promise = new Promise(ok => {
26
+ this.promise = new Promise((ok, oh) => {
26
27
  this.resolve = ok;
28
+ this.reject = oh;
27
29
  exec(a);
30
+ }).then((v) => {
31
+ return {
32
+ value: v,
33
+ done: !!this.exec
34
+ }
28
35
  });
29
36
  return this.promise;
30
37
  }
@@ -32,12 +39,11 @@ class AsyncGenerator {
32
39
  var next = () => this.next(a);
33
40
  return this.promise.then(next, next);
34
41
  }
35
- return Promise.resolve({ value: undefined, done: true });
42
+ return Promise.resolve({ value: this.value, done: true });
43
+ }
44
+ [Symbol.asyncIterator]() {
45
+ return this;
36
46
  }
37
-
38
- }
39
- Generator.prototype[Symbol.asyncIterator] = function () {
40
- return this;
41
47
  }
42
48
  function asyncAster_() {
43
49
  return new AsyncGenerator(exec_.bind(this, arguments));
@@ -1,3 +1,4 @@
1
+ var tick = Promise.resolve();
1
2
  var exec_ = function (args, ok, oh, int) {
2
3
  var p = null, index = 0, r, e, finished = false, t = this;
3
4
  var next = function (arg) {
@@ -46,12 +47,17 @@ var exec_ = function (args, ok, oh, int) {
46
47
  var run = function () {
47
48
  var args_length = args.length, i;
48
49
  if (!catch_ || index >= args_length) {
49
- if (throwed) return oh();
50
+ if (throwed) {
51
+ return oh(e);
52
+ }
50
53
  if (finished) return ok(r);
51
54
  }
55
+ catch_ = null;
52
56
  while (index < args_length) {
53
57
  try {
54
- [p, i] = args[index].call(t, p) || [1, 0];
58
+ var a = args[index].call(t, p) || [1, 0];
59
+ p = a[0];
60
+ i = a[1];
55
61
  } catch (e) {
56
62
  p = null;
57
63
  thro(e);
@@ -61,18 +67,28 @@ var exec_ = function (args, ok, oh, int) {
61
67
  case 0: index += p; break; // reflow
62
68
  case 1:
63
69
  index++; // await p;
64
- if (p && isFunction(p.then)) return p.then(next, thro);
70
+ if (p && isFunction(p.then)) {
71
+ try {
72
+ return p.then(next, thro);
73
+ } catch (e) {
74
+ return Promise.reject(e).then(next, thro);
75
+ }
76
+ }
65
77
  else return next(p);
66
78
  case 2: return finished = true, retn(p); // return p;
67
79
  case 3: return index++, int(p, next); // yield p;
68
80
  case 7: index++; catches.push([index, p]); break; // try catch finally?
69
81
  case 8: index++; catches.push([index, p, 1]); break; // try finally
70
82
  case 9: return p ? fine() : fina(); // finally
71
- default: throw "代码异常!";
83
+ default: throw console.log(a), "代码异常!";
72
84
  }
73
85
  }
74
- catch_ = null;
75
86
  retn();
76
87
  };
88
+ var ticked = false;
89
+ tick.then(() => {
90
+ if (ticked) return oh(e);
91
+ ticked = true;
92
+ })
77
93
  next();
78
94
  };
@@ -39,6 +39,7 @@ class Javascript extends Program {
39
39
  strapexp_reg = /^(new|void|typeof|delete|class|function|await)/;
40
40
  forceend_reg = /^(return|yield|break|continue|debugger)$/;
41
41
  classstrap_reg = /^(class|function|async)$/;
42
+ defaultType = EXPRESS;
42
43
  }
43
44
  var propresolve_reg = /^(static|get|set|async)$/;
44
45
 
@@ -67,38 +68,70 @@ Javascript.prototype.isProperty = function (o) {
67
68
  }
68
69
  return false;
69
70
  };
70
- Javascript.prototype.fixType = function (o) {
71
+ var setStrapExpress = function (mark_type, mark_text, prop, o, default_type) {
72
+ var temp = o.queue;
71
73
  var type = o.type;
72
- var queue = o.queue;
73
- var m = o.text;
74
- var last = o.prev;
75
- if (m === 'yield') {
76
- var temp = queue;
77
- var type = STRAP;
78
- if (type === STRAP) while (temp) {
79
- if (temp.entry != "{" || !temp.prev || temp.prev.type !== SCOPED || temp.prev.entry !== '(') {
80
- temp = temp.queue;
81
- continue;
82
- }
83
- var pp = temp.prev.prev;
84
- var isprop = pp.isprop;
85
- if (pp && pp.type === EXPRESS || pp.isprop) pp = pp.prev;
86
- if (!pp || pp.type === STRAP && pp.text !== 'function') {
74
+ var prev = o.prev;
75
+ if (prev && prev.type === STRAP && /^(?:function|class|let|const|var)$/.test(prev.text)) {
76
+ o.type = EXPRESS;
77
+ return;
78
+ }
79
+ if (type === STRAP) while (temp) {
80
+ if (temp.entry === '(') var pp = temp.prev;
81
+ else if (temp.entry === "{") {
82
+ if (!temp.prev || temp.prev.type !== SCOPED || temp.prev.entry !== '(') {
87
83
  temp = temp.queue;
88
84
  continue;
89
85
  }
90
- if (pp.type === STAMP && pp.text === "*" && (pp.isprop || pp.prev && pp.prev.type === STRAP && pp.prev.text === "function")) {
86
+ temp = temp.prev;
87
+ pp = temp.prev;
88
+ }
89
+ else {
90
+ temp = temp.queue;
91
+ continue;
92
+ }
93
+ if (pp && pp.isprop) {
94
+ pp = pp.prev;
95
+ if (pp && pp.type === mark_type && pp.text === mark_text) {
91
96
  type = STRAP;
92
97
  break;
93
98
  }
94
- if (isprop || pp.type === STRAP && pp.text === "function") {
95
- type = EXPRESS;
96
- break;
99
+ if (pp && pp.type === STAMP && pp.text === '*') pp = pp.prev;
100
+ type = pp && pp.type === mark_type && pp.text === mark_text ? STRAP : EXPRESS;
101
+ break;
102
+ }
103
+ var tn = temp.next;
104
+ var isfunc = false;
105
+ if (tn && tn.type === STAMP && tn.text === '=>') isfunc = true;
106
+ if (!isfunc) {
107
+ if (pp && pp.type === EXPRESS) pp = pp.prev;
108
+ if (pp && pp.prev && pp.prev.type === STRAP && pp.prev.text === "function") {
109
+ pp = pp.prev;
110
+ isfunc = true;
111
+ }
112
+ else {
113
+ isfunc = pp && pp.type === STRAP && pp.text === 'function';
97
114
  }
98
- temp = temp.queue;
99
115
  }
116
+ if (isfunc) {
117
+ var chk = pp[prop];
118
+ type = (chk && chk.type === mark_type && chk.text === mark_text) ? STRAP : EXPRESS;
119
+ break;
120
+ }
121
+ temp = temp.queue;
100
122
  }
101
-
123
+ if (!temp) type = default_type;
124
+ o.type = type;
125
+ }
126
+ var setYieldExpress = setStrapExpress.bind(null, STAMP, "*", 'next');
127
+ var setAwaitExpress = setStrapExpress.bind(null, STRAP, "async", 'prev');
128
+ Javascript.prototype.fixType = function (o) {
129
+ var m = o.text;
130
+ if (m === 'yield') setYieldExpress(o, this.defaultType);
131
+ else if (m === 'await') setAwaitExpress(o, this.defaultType);
132
+ var last = o.prev;
133
+ var type = o.type;
134
+ var queue = o.queue;
102
135
  switch (type) {
103
136
  case QUOTED:
104
137
  if (this.isProperty(o)) type = PROPERTY;
@@ -230,7 +263,7 @@ Javascript.prototype.setType = function (o) {
230
263
  }
231
264
  if (o.type === STAMP) {
232
265
  if (!last || last.type & (STAMP | STRAP)) {
233
- o.unary = /^[^=;,\*]$|.[^\=]$/.test(o.text);
266
+ o.unary = /^[^=;,\*]$|.[^\=\>\<\|\&\^]$/.test(o.text);
234
267
  }
235
268
  }
236
269
  };
@@ -240,11 +273,12 @@ var insertBefore = function (o) {
240
273
  var os = [].slice.call(arguments, 1);
241
274
  queue.splice.apply(queue, [index, 0].concat(os));
242
275
  var prev = o && o.prev, next = o;
276
+ var desc = { value: queue, configurable: true, enumerable: false }
243
277
  for (var o of os) {
244
278
  if (prev) prev.next = o;
245
279
  else queue.first = o;
246
280
  o.prev = prev;
247
- Object.defineProperty(o, 'queue', { value: queue });
281
+ Object.defineProperty(o, 'queue', desc);
248
282
  prev = o;
249
283
  }
250
284
  o.next = next;
@@ -257,11 +291,12 @@ var insertAfter = function (o) {
257
291
  var os = [].slice.call(arguments, 1);
258
292
  queue.splice.apply(queue, [index, 0].concat(os));
259
293
  var prev = o, next = o && o.next;
294
+ var desc = { value: queue, configurable: true, enumerable: false }
260
295
  for (var o of os) {
261
296
  if (prev) prev.next = o;
262
297
  else queue.first = o;
263
298
  o.prev = prev;
264
- Object.defineProperty(o, 'queue', { value: queue });
299
+ Object.defineProperty(o, 'queue', desc);
265
300
  prev = o;
266
301
  }
267
302
  o.next = next;
@@ -464,10 +499,14 @@ Javascript.prototype.detour = function detour(o, ie) {
464
499
  };
465
500
 
466
501
  var removeImport = function (c, i, code) {
467
- var { used, envs, vars } = code;
468
- var [dec, map, o] = getDeclared(c.next);
469
- if (dec.length !== 1 || !o) throw new Error("代码结构异常!");
470
- if (o.type !== STRAP || o.text !== 'from') throw new Error("缺少from语句");
502
+ var next = c.next;
503
+ if (next && next.type !== QUOTED) {
504
+ var { used, envs, vars } = code;
505
+ var [dec, map, o] = getDeclared(c.next);
506
+ if (dec.length !== 1 || !o) throw new Error("代码结构异常!");
507
+ if (o.type !== STRAP || o.text !== 'from') throw new Error("缺少from语句");
508
+ }
509
+ else o = c;
471
510
  var n = o.next;
472
511
  if (!n || n.type !== QUOTED) throw new Error("缺少导入路径!");
473
512
  var oi = code.indexOf(o, i);
@@ -478,7 +517,8 @@ var removeImport = function (c, i, code) {
478
517
  used.require.push(q[0]);
479
518
  var cs = code.splice(oi + 1, nsi - oi - 1, ...q);
480
519
  q[1].push.apply(q[1], cs);
481
- relink(q[1])
520
+ relink(q[1]);
521
+ if (!dec) return;
482
522
  var name = dec[0];
483
523
  var na = dec.attributes[0];
484
524
  o.type = STAMP;
@@ -190,7 +190,7 @@ class Program {
190
190
  var program = this;
191
191
  var queue_push = function (scope) {
192
192
  var last = queue.last;
193
- Object.defineProperty(scope, 'queue', { value: queue, enumerable: false });
193
+ Object.defineProperty(scope, 'queue', { value: queue, enumerable: false, configurable: true });
194
194
  scope.prev = last;
195
195
  if (scope.type !== COMMENT && scope.type !== SPACE) {
196
196
  var keeplast = program.setType(scope) === false;
@@ -200,6 +200,7 @@ class Program {
200
200
  while (queue[queue.length - 1] !== last) queue.pop();
201
201
  last.end = scope.end;
202
202
  last.text = text.slice(last.start, last.end);
203
+ queue.last = last;
203
204
  return;
204
205
  }
205
206
  if (queue.last !== last && queue.last !== o) {
@@ -227,7 +228,7 @@ class Program {
227
228
  /[=>]$/.test(scope.text) && /[^>=]/.test(m) ||
228
229
  /[?]$/.test(scope.text) && /[^?\.=\:]/.test(m) ||
229
230
  /[,;]$/.test(scope.text) ||
230
- scope.end !== start) {
231
+ /^[!~]$/.test(m) || scope.text !== m && /^[\+\-]$/.test(m)) {
231
232
  } else {
232
233
  scope.end = end;
233
234
  scope.text = text.slice(scope.start, scope.end);
@@ -254,6 +255,7 @@ class Program {
254
255
  else queue.question++;
255
256
  break;
256
257
  case "=":
258
+ queue.inExpress = true;
257
259
  if (last.type === SCOPED && last.entry === "{") {
258
260
  if (!last.isObject) {
259
261
  setObject(last);
@@ -293,7 +295,7 @@ class Program {
293
295
  temp = temp.prev;
294
296
  }
295
297
  queue.inExpress = false;
296
- if (last.type === EXPRESS) {
298
+ if (last.type & (EXPRESS | STRAP | VALUE | QUOTED)) {
297
299
  // label
298
300
  last.type = LABEL;
299
301
  last.text += ":";
@@ -315,8 +317,8 @@ class Program {
315
317
  text: m
316
318
  }
317
319
  if (type === STRAP) {
318
- if (forceend_reg.test(m)) scope.isend = false;
319
- if (this.transive_reg.test(m)) scope.transive = true;
320
+ if (forceend_reg.test(m)) scope.isend = false, queue.inExpress = false;
321
+ if (this.transive_reg.test(m)) scope.transive = true, queue.inExpress = true;
320
322
  }
321
323
  if (isdigit) scope.isdigit = true;
322
324
  lasttype = type;
@@ -430,6 +432,7 @@ class Program {
430
432
  scope.entry = m;
431
433
  scope.type = QUOTED;
432
434
  scope.start = index;
435
+ scope.isExpress = queue.inExpress;
433
436
  push_parents(scope);
434
437
  queue.inTag = 0;
435
438
  start = index;
@@ -467,6 +470,7 @@ class Program {
467
470
  var scope = [];
468
471
  var quote = this.quote_map[m];
469
472
  scope.type = this.comment_entry.test(m) ? COMMENT : QUOTED;
473
+ scope.isExpress = queue.inExpress;
470
474
  scope.start = start;
471
475
  push_parents(scope);
472
476
  if (quote.tag) {
@@ -592,7 +596,10 @@ class Program {
592
596
  if (last.text === ':') {
593
597
  scope.isObject = queue.inExpress;
594
598
  }
595
- else scope.isObject = !/^(;|\+\+|\-\-|=>)$/.test(last.text);
599
+ else queue.inExpress = scope.isObject = !/^(;|\+\+|\-\-|=>)$/.test(last.text);
600
+ }
601
+ else if (last.type === EXPRESS && last.text === '...') {
602
+ scope.isObject = true;
596
603
  }
597
604
  else if (last.type === STRAP) {
598
605
  if (last.isend);