efront 4.0.45 → 4.0.48
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.
- package/coms/basic/Table.js +13 -2
- package/coms/basic/concatByte.js +2 -4
- package/coms/compile/Javascript.js +21 -9
- package/coms/compile/downLevel.js +20 -3
- package/coms/compile/downLevel_test.js +16 -13
- package/coms/compile/scanner2.js +4 -2
- package/coms/compile/unstruct.js +67 -29
- package/coms/compile/unstruct_test.js +11 -5
- package/package.json +1 -1
- package/public/efront.js +1 -1
- package/readme-en.md +3 -4
- package/readme.md +2 -2
- package/data/mime.json +0 -848
package/coms/basic/Table.js
CHANGED
|
@@ -92,14 +92,25 @@ class Table extends Array {
|
|
|
92
92
|
this.update();
|
|
93
93
|
}
|
|
94
94
|
async update() {
|
|
95
|
-
var origin = this.
|
|
95
|
+
var origin = this.splice(0, this.length)
|
|
96
|
+
if (this.searched && this.source && this.searched !== this.source.length) {
|
|
97
|
+
origin = origin.map(o => o.$origin);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
origin = [];
|
|
101
|
+
}
|
|
96
102
|
this.searched = 0;
|
|
97
103
|
var source = this.sorted ? this.sorted : this.source;
|
|
98
104
|
if (!source) return;
|
|
99
105
|
var searchid = ++this.searchid;
|
|
100
106
|
this.complete = false;
|
|
101
107
|
this.coverCount = 0;
|
|
102
|
-
if (
|
|
108
|
+
if (origin.length) {
|
|
109
|
+
if (origin.length >= 160) origin = origin.slice(0, 80);
|
|
110
|
+
source = source.filter(a => origin.indexOf(a) < 0);
|
|
111
|
+
source = origin.concat(source);
|
|
112
|
+
}
|
|
113
|
+
if (this.searchText) for (var o of source) {
|
|
103
114
|
this.addItem(o);
|
|
104
115
|
if (++this.searched % 600 === 0) {
|
|
105
116
|
if (isFunction(this.callback)) this.callback();
|
package/coms/basic/concatByte.js
CHANGED
|
@@ -6,10 +6,8 @@ function concatTypedArray(buffs) {
|
|
|
6
6
|
while (offset < total) {
|
|
7
7
|
var b = buffs[inc++];
|
|
8
8
|
if (b.buffer) b = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
offset += dx;
|
|
9
|
+
res.set(b, offset);
|
|
10
|
+
offset += b.length;
|
|
13
11
|
}
|
|
14
12
|
return res;
|
|
15
13
|
}
|
|
@@ -312,6 +312,7 @@ var scan = function (data) {
|
|
|
312
312
|
var detourTemplate = function (raw, params) {
|
|
313
313
|
var spliter = { text: ",", type: STAMP };
|
|
314
314
|
var template = scan(`extend([],{["raw"]:[]})`);
|
|
315
|
+
rootenvs.extend = true;
|
|
315
316
|
var str0 = template[1].first;
|
|
316
317
|
var str1 = template[1][2][2];
|
|
317
318
|
for (var r of raw) {
|
|
@@ -364,19 +365,27 @@ var removeQuote = function (o, c, i) {
|
|
|
364
365
|
if (c.next) c.next.prev = cf;
|
|
365
366
|
}
|
|
366
367
|
|
|
367
|
-
Javascript.prototype.detour = function
|
|
368
|
-
|
|
368
|
+
Javascript.prototype.detour = function (o, ie) {
|
|
369
|
+
context = this;
|
|
370
|
+
var envs = rootenvs = Object.create(null);
|
|
371
|
+
detour(o, ie);
|
|
372
|
+
rootenvs = null;
|
|
373
|
+
context = null;
|
|
374
|
+
return envs;
|
|
375
|
+
}
|
|
376
|
+
var context = null, rootenvs = null;
|
|
377
|
+
function detour(o, ie) {
|
|
369
378
|
while (o) {
|
|
370
379
|
switch (o.type) {
|
|
371
380
|
case SCOPED:
|
|
372
|
-
|
|
381
|
+
detour(o.first, ie);
|
|
373
382
|
break;
|
|
374
383
|
case EXPRESS:
|
|
375
384
|
var text = o.text.replace(/^\.\.\./, '');
|
|
376
385
|
var hasdot = o.text.length !== text.length;
|
|
377
|
-
if (avoidMap) {
|
|
386
|
+
if (context.avoidMap) {
|
|
378
387
|
var m = /^[^\.\[\]]+/.exec(o.text);
|
|
379
|
-
if (m) { avoidMap[m[0]] = true; }
|
|
388
|
+
if (m) { context.avoidMap[m[0]] = true; }
|
|
380
389
|
}
|
|
381
390
|
if (/\?\./.test(text)) {
|
|
382
391
|
text = renderExpress(text);
|
|
@@ -384,7 +393,7 @@ Javascript.prototype.detour = function detour(o, ie) {
|
|
|
384
393
|
o = replace(o, ...scan(text));
|
|
385
394
|
continue;
|
|
386
395
|
}
|
|
387
|
-
text = text.replace(/\.([^\.\[\!\=\:]+)/g, (_, a) => ie === undefined ||
|
|
396
|
+
text = text.replace(/\.([^\.\[\!\=\:]+)/g, (_, a) => ie === undefined || context.strap_reg.test(a) || /#/.test(a) ? `[${strings.recode(a)}]` : _);
|
|
388
397
|
if (hasdot) text = "..." + text;
|
|
389
398
|
o.text = text;
|
|
390
399
|
break;
|
|
@@ -404,7 +413,7 @@ Javascript.prototype.detour = function detour(o, ie) {
|
|
|
404
413
|
else {
|
|
405
414
|
c.entry = "(";
|
|
406
415
|
c.leave = ")";
|
|
407
|
-
|
|
416
|
+
detour(c.first, ie);
|
|
408
417
|
splice(o, cx + 1, 0, { type: STAMP, text: ',' });
|
|
409
418
|
removeQuote(o, c);
|
|
410
419
|
}
|
|
@@ -424,7 +433,7 @@ Javascript.prototype.detour = function detour(o, ie) {
|
|
|
424
433
|
} else {
|
|
425
434
|
c.entry = '(';
|
|
426
435
|
c.leave = ")";
|
|
427
|
-
|
|
436
|
+
detour(c.first, ie);
|
|
428
437
|
params.push(c);
|
|
429
438
|
}
|
|
430
439
|
}
|
|
@@ -460,7 +469,7 @@ Javascript.prototype.detour = function detour(o, ie) {
|
|
|
460
469
|
if (/^\[/.test(o.text)) break;
|
|
461
470
|
if (o.queue.isObject) {
|
|
462
471
|
var text = strings.recode(o.text);
|
|
463
|
-
if (ie === undefined || o.prev && (o.prev.type !== STAMP || o.prev.text !== ",") ||
|
|
472
|
+
if (ie === undefined || o.prev && (o.prev.type !== STAMP || o.prev.text !== ",") || context.strap_reg.test(o.text)) {
|
|
464
473
|
text = `[${text}]`;
|
|
465
474
|
}
|
|
466
475
|
else if (ie !== false) {
|
|
@@ -612,6 +621,7 @@ var removeExport = function (c, i, code) {
|
|
|
612
621
|
o = n && n.next;
|
|
613
622
|
var exp = scan(`\r\nexports.${prop}=`);
|
|
614
623
|
exp.push(name);
|
|
624
|
+
name.isExpress = true;
|
|
615
625
|
allexports.push(exp);
|
|
616
626
|
}
|
|
617
627
|
var ni = skipAssignment(code, i);
|
|
@@ -627,6 +637,7 @@ var removeExport = function (c, i, code) {
|
|
|
627
637
|
n.type = STAMP;
|
|
628
638
|
c.text = `exports.default`;
|
|
629
639
|
code.exportDefault = true;
|
|
640
|
+
n.next.isExpress = true;
|
|
630
641
|
c.type = EXPRESS;
|
|
631
642
|
return;
|
|
632
643
|
}
|
|
@@ -638,6 +649,7 @@ var removeExport = function (c, i, code) {
|
|
|
638
649
|
}
|
|
639
650
|
c.text = `exports.${dec[0]}`;
|
|
640
651
|
c.type = EXPRESS;
|
|
652
|
+
n.isExpress = true;
|
|
641
653
|
code.splice(i + 1, 0, ...scan(`=`));
|
|
642
654
|
var nn = n.next;
|
|
643
655
|
var d = nn.text;
|
|
@@ -733,13 +733,13 @@ var killspr = function (body, i, _getobjname, killobj) {
|
|
|
733
733
|
var index = 0;
|
|
734
734
|
var spr = function () {
|
|
735
735
|
var s = m;
|
|
736
|
-
s.text = s.text.replace(/^\.\.\./, '');
|
|
737
736
|
m = skipAssignment(m);
|
|
738
|
-
|
|
739
|
-
rootenvs.slice_ = true;
|
|
737
|
+
s.text = s.text.replace(/^\.\.\./, '');
|
|
740
738
|
var v = splice2(o, s, m);
|
|
741
739
|
if (m) splice2(o, m, m = m.next);
|
|
742
740
|
killobj(v);
|
|
741
|
+
var q = scanner2(`slice_["call"]()`);
|
|
742
|
+
rootenvs.slice_ = true;
|
|
743
743
|
insert1(q[q.length - 1], null, ...v);
|
|
744
744
|
return q;
|
|
745
745
|
};
|
|
@@ -760,6 +760,23 @@ var killspr = function (body, i, _getobjname, killobj) {
|
|
|
760
760
|
var next = o.next;
|
|
761
761
|
if (o.entry === '(') {
|
|
762
762
|
var r = snapExpressHead(o);
|
|
763
|
+
if (r.type === STRAP && r.text === "new") {
|
|
764
|
+
var qt = scanner2(`()`)[0];
|
|
765
|
+
r = r.next;
|
|
766
|
+
var b = body.lastIndexOf(r, i);
|
|
767
|
+
var ct = splice(body, b, i - b + 1, qt);
|
|
768
|
+
var qq = ct[ct.length - 1];
|
|
769
|
+
var qb = scanner2("[null,]")[0];
|
|
770
|
+
qb.push(...splice(qq, 0, qq.length, qb));
|
|
771
|
+
ct[ct.length - 1].unshift({ type: STAMP, text: ',' });
|
|
772
|
+
ct[ct.length - 1].unshift(...ct.slice(0, ct.length - 1).map(a => extend({}, a)));
|
|
773
|
+
ct.splice(ct.length - 1, 0, ...scanner2("['bind']['apply']"));
|
|
774
|
+
qt.push(...ct);
|
|
775
|
+
relink(qq)
|
|
776
|
+
relink(qb)
|
|
777
|
+
relink(qt)
|
|
778
|
+
return b;
|
|
779
|
+
}
|
|
763
780
|
var rt = r.type === EXPRESS && r.text.replace(/^\.\.\./, '');
|
|
764
781
|
var p = o.prev;
|
|
765
782
|
if (r === o);
|
|
@@ -19,7 +19,7 @@ assert(downLevel(`a(c**=d)`), 'a(c = power_(c, d))', true);
|
|
|
19
19
|
assert(downLevel(`a(c.b.d**=d)`), 'a((_ = c.b, _.d = power_(_.d, d)))\r\nvar _', true);
|
|
20
20
|
assert(downLevel(`a(c.b[a.b]**=d)`), 'a((_ = c.b, _[_0 = a.b] = power_(_[_0], d)))\r\nvar _, _0', true);
|
|
21
21
|
assert(downLevel(`c.b[a.b]**=d`), '_ = c.b, _[_0 = a.b] = power_(_[_0], d)\r\nvar _, _0', true);
|
|
22
|
-
|
|
22
|
+
i++// 声明及解构
|
|
23
23
|
assert(downLevel(`var [data, args, strs] = breakcode(data, occurs), strs = []`), 'var _ = breakcode(data, occurs), data = _[0], args = _[1], strs = _[2], strs = []\r\nvar _');
|
|
24
24
|
assert(downLevel(`var [name, type, options] = piece, key, repeat;`), 'var name = piece[0], type = piece[1], options = piece[2], key, repeat;');
|
|
25
25
|
assert(downLevel(`var [] = piece, key,[]= repeat;`), 'var key;');
|
|
@@ -80,6 +80,7 @@ assert(downLevel(`function (a=b,[c],d,e=f){}`), "function (a, arg1, d, e) { if (
|
|
|
80
80
|
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; }")
|
|
81
81
|
i++// class降级
|
|
82
82
|
assert(downLevel(`class a {}`), "function a() {}")
|
|
83
|
+
var tmp = scanner2('export class a{a(){}}'); tmp.fix(); assert(downLevel.code(tmp).toString(), `exports.a = function (a) { a["prototype"].a = function () {}\r\nreturn a }(function a() {})`);
|
|
83
84
|
assert(downLevel(`class a { static{ a.a=1}}`), "function a() {}; (function () { a.a = 1 }())")
|
|
84
85
|
assert(downLevel(`if(a) a = 1; class a {}`), "if (a) a = 1; function a() {}")
|
|
85
86
|
assert(downLevel(`async function(){if(a) a = 1; class a {}}`), `function () { return async_(
|
|
@@ -192,6 +193,8 @@ assert(downLevel(`=[a,b,...c,d,e,f]`), `var slice_ = Array["prototype"]["slice"]
|
|
|
192
193
|
assert(downLevel(`=[a,b,...c,d,e,f,...g]`), `var slice_ = Array["prototype"]["slice"];\r\n= [a, b]["concat"](slice_["call"](c), [d, e, f], slice_["call"](g))`)
|
|
193
194
|
assert(downLevel(`=[a,b,...c,d,...e]`), `var slice_ = Array["prototype"]["slice"];\r\n= [a, b]["concat"](slice_["call"](c), [d], slice_["call"](e))`)
|
|
194
195
|
assert(downLevel(`a(...b)`), `a["apply"](null, b)`)
|
|
196
|
+
assert(downLevel(`a(..."b,c".split(","))`), `a["apply"](null, "b,c".split(","))`)
|
|
197
|
+
assert(downLevel(`new a(...args)`), `var slice_ = Array["prototype"]["slice"];\r\nnew (a['bind']['apply'](a, [null]["concat"](slice_["call"](args))))`)
|
|
195
198
|
assert(downLevel(`a(c,d,e,...b(...c))`), `var slice_ = Array["prototype"]["slice"];\r\na["apply"](null, [c, d, e]["concat"](slice_["call"](b["apply"](null, c))))`)
|
|
196
199
|
assert(downLevel(`a(c,d,e,...b.a(...c))`), `var slice_ = Array["prototype"]["slice"];\r\na["apply"](null, [c, d, e]["concat"](slice_["call"](b.a["apply"](b, c))))`)
|
|
197
200
|
assert(downLevel(`a(c,d,e,...b.a.c(...c))`), `var slice_ = Array["prototype"]["slice"];\r\na["apply"](null, [c, d, e]["concat"](slice_["call"]((_ = b.a).c["apply"](_, c))))\r\nvar _`)
|
|
@@ -226,7 +229,7 @@ function () {
|
|
|
226
229
|
return [8, 8]
|
|
227
230
|
},
|
|
228
231
|
function () {
|
|
229
|
-
_2 = Symbol["asyncIterator"]; _2 = os[_2]; if (_2) return [1, 0]; _2 = Symbol["iterator"]; _2 = os[_2]; if (_2) return [1, 0]; _2 =
|
|
232
|
+
_2 = Symbol["asyncIterator"]; _2 = os[_2]; if (_2) return [1, 0]; _2 = Symbol["iterator"]; _2 = os[_2]; if (_2) return [1, 0]; _2 = Array["prototype"]; _3 = Symbol["iterator"]; _2 = _2[_3]
|
|
230
233
|
},
|
|
231
234
|
function () {
|
|
232
235
|
_0 = _2; _0 = _0["call"](os); _2 = _0["next"](); return [_2, 1]
|
|
@@ -258,13 +261,13 @@ if (!_2) return [1, 0]; _2 = _0["return"](); return [1, 0]
|
|
|
258
261
|
function () {
|
|
259
262
|
return [1, 9]
|
|
260
263
|
})
|
|
261
|
-
var _, _0, _2`)
|
|
264
|
+
var _, _0, _2, _3`)
|
|
262
265
|
assert(downLevel(`for await(var [o,s] of os) noSymbol`), `return async_(
|
|
263
266
|
function () {
|
|
264
267
|
return [11, 8]
|
|
265
268
|
},
|
|
266
269
|
function () {
|
|
267
|
-
o; s; _5 = Symbol["asyncIterator"]; _5 = os[_5]; if (_5) return [1, 0]; _5 = Symbol["iterator"]; _5 = os[_5]; if (_5) return [1, 0]; _5 =
|
|
270
|
+
o; s; _5 = Symbol["asyncIterator"]; _5 = os[_5]; if (_5) return [1, 0]; _5 = Symbol["iterator"]; _5 = os[_5]; if (_5) return [1, 0]; _5 = Array["prototype"]; _6 = Symbol["iterator"]; _5 = _5[_6]
|
|
268
271
|
},
|
|
269
272
|
function () {
|
|
270
273
|
_0 = _5; _0 = _0["call"](os); _5 = _0["next"](); return [_5, 1]
|
|
@@ -276,16 +279,16 @@ function () {
|
|
|
276
279
|
_5 = !_["done"]; if (!_5) return [5, 0]; _5 = _["value"]; return [_5, 1]
|
|
277
280
|
},
|
|
278
281
|
function (_4) {
|
|
279
|
-
_5 = _4; _1 = _5; _6 = Symbol["iterator"]; _6 = _1[_6]; if (_6) return [1, 0]; _6 =
|
|
282
|
+
_5 = _4; _1 = _5; _6 = Symbol["iterator"]; _6 = _1[_6]; if (_6) return [1, 0]; _6 = Array["prototype"]; _7 = Symbol["iterator"]; _6 = _6[_7]
|
|
280
283
|
},
|
|
281
284
|
function () {
|
|
282
|
-
_6 = (_6); _2 = _6["call"](_1); _3 = undefined; _3 = _2["next"](); o = _3["value"]; _3 = _2["next"](); s = _3["value"];
|
|
285
|
+
_6 = (_6); _2 = _6["call"](_1); _3 = undefined; _3 = _2["next"](); o = _3["value"]; _3 = _2["next"](); s = _3["value"]; _10 = !_3; if (_10) return [1, 0]; _10 = !_3["done"]
|
|
283
286
|
},
|
|
284
287
|
function () {
|
|
285
|
-
|
|
288
|
+
_10 = (_10); if (!_10) return [1, 0]; _10 = _2["return"]; _10 = isFunction(_10); if (!_10) return [1, 0]; _10 = _2["return"]()
|
|
286
289
|
},
|
|
287
290
|
function () {
|
|
288
|
-
_3 =
|
|
291
|
+
_3 = _10; _5 = (true)
|
|
289
292
|
},
|
|
290
293
|
function () {
|
|
291
294
|
if (!_5) return [2, 0]; noSymbol; _5 = _0["next"](); return [_5, 1]
|
|
@@ -305,7 +308,7 @@ if (!_5) return [1, 0]; _5 = _0["return"](); return [1, 0]
|
|
|
305
308
|
function () {
|
|
306
309
|
return [1, 9]
|
|
307
310
|
})
|
|
308
|
-
var o, s, _, _0, _1, _2, _3, _5, _6, _7, _8, _9`);
|
|
311
|
+
var o, s, _, _0, _1, _2, _3, _5, _6, _7, _8, _9, _10`);
|
|
309
312
|
assert(downLevel(`for(o of os) noSymbol`), `for (_ = 0; _ < os["length"] && (o = os[_], true); _++) noSymbol\r\nvar _, _0`)
|
|
310
313
|
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`)
|
|
311
314
|
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`)
|
|
@@ -324,9 +327,9 @@ assert(downLevel("if(a){}[r, g, b] = rgb4s(r, g, b, s)"), "if (a) {} _ = rgb4s(r
|
|
|
324
327
|
assert(downLevel(`{c,[c]:b,...a}=a`), `c = a.c, b = a[c], a = rest_(a, ["c", c])`)
|
|
325
328
|
assert(downLevel(`async()=>name = require("./$split")(name)["join"]("/");`), `function () { return async_(
|
|
326
329
|
function () {
|
|
327
|
-
_0 = require("./$split");
|
|
330
|
+
_0 = require("./$split"); _0 = _0(name); name = _0["join"]("/"); return [name, 2]
|
|
328
331
|
})
|
|
329
|
-
var _0
|
|
332
|
+
var _0 };`);
|
|
330
333
|
i++//异步或步进函数
|
|
331
334
|
assert(downLevel(`function *(){yield *a}`), `function () { return aster_(
|
|
332
335
|
function () {
|
|
@@ -348,7 +351,7 @@ function () {
|
|
|
348
351
|
return [5, 8]
|
|
349
352
|
},
|
|
350
353
|
function () {
|
|
351
|
-
a; _2 = Symbol["iterator"]; _2 = b[_2]; if (_2) return [1, 0]; _2 =
|
|
354
|
+
a; _2 = Symbol["iterator"]; _2 = b[_2]; if (_2) return [1, 0]; _2 = Array["prototype"]; _3 = Symbol["iterator"]; _2 = _2[_3]
|
|
352
355
|
},
|
|
353
356
|
function () {
|
|
354
357
|
_0 = _2; _0 = _0["call"](b); _ = _0["next"](); return [1, 0]
|
|
@@ -371,7 +374,7 @@ if (!_2) return [1, 0]; _2 = _0["return"](); return [1, 0]
|
|
|
371
374
|
function () {
|
|
372
375
|
return [1, 9]
|
|
373
376
|
})
|
|
374
|
-
var a, _, _0, _2 }`)
|
|
377
|
+
var a, _, _0, _2, _3 }`)
|
|
375
378
|
assert(downLevel(`a={async a(){var b =c;return 1}}`), `a = (_ = {},
|
|
376
379
|
_.a = function () { return async_(\r\nfunction () {\r\nb = c; return [1, 2]\r\n})\r\nvar b }, _)\r\nvar _`)
|
|
377
380
|
assert(downLevel(`async function(){return 1}`), `function () { return async_(\r\nfunction () {\r\nreturn [1, 2]\r\n}) }`)
|
package/coms/compile/scanner2.js
CHANGED
|
@@ -154,13 +154,15 @@ class Code extends Array {
|
|
|
154
154
|
// 提前处理属性
|
|
155
155
|
break() {
|
|
156
156
|
this.program.avoidMap = avoidMap;
|
|
157
|
-
this.program.detour(this.first);
|
|
157
|
+
var envs = this.program.detour(this.first);
|
|
158
|
+
if (this._scoped) extend(this.envs, envs);
|
|
158
159
|
return this;
|
|
159
160
|
}
|
|
160
161
|
// 绕开低版本ie的异常属性
|
|
161
162
|
detour(ie) {
|
|
162
163
|
this.program.avoidMap = avoidMap;
|
|
163
|
-
this.program.detour(this.first, ie !== false);
|
|
164
|
+
var envs = this.program.detour(this.first, ie !== false);
|
|
165
|
+
if (this._scoped) extend(this.envs, envs);
|
|
164
166
|
return this;
|
|
165
167
|
}
|
|
166
168
|
// 压缩
|
package/coms/compile/unstruct.js
CHANGED
|
@@ -7,9 +7,7 @@ var RETURN = { type: STRAP, text: "@ret" };// return;
|
|
|
7
7
|
var THROW = { type: STRAP, text: "@throw" };// return;
|
|
8
8
|
var YIELD = { type: STRAP, text: "@yield" };// return;
|
|
9
9
|
var NEXT = { type: STRAP, text: "@next" };// return;
|
|
10
|
-
var
|
|
11
|
-
var re = result[result.length - 1];
|
|
12
|
-
if (!result.length || re.ret_ && !re.await_ && re.ret_ !== -2) return;
|
|
10
|
+
var mount_break = function (body, cx, b1s, iscontinue) {
|
|
13
11
|
var label;
|
|
14
12
|
do {
|
|
15
13
|
var o = body[++cx];
|
|
@@ -24,11 +22,11 @@ var _break = function (body, cx, result, iscontinue) {
|
|
|
24
22
|
if (b.type === LABEL && b.text === label + ":") {
|
|
25
23
|
if (!s) s = b;
|
|
26
24
|
if (!b.breaks) b.breaks = [];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
if (iscontinue) s.continue = true;
|
|
26
|
+
b1s.forEach(b1 => {
|
|
27
|
+
if (iscontinue) b1.continue = s
|
|
28
|
+
b.breaks.push(b1);
|
|
29
|
+
});
|
|
32
30
|
break;
|
|
33
31
|
}
|
|
34
32
|
else {
|
|
@@ -41,16 +39,24 @@ var _break = function (body, cx, result, iscontinue) {
|
|
|
41
39
|
var b = labels[cx];
|
|
42
40
|
if (b.type !== LABEL && (!iscontinue || b.text !== 'switch')) {
|
|
43
41
|
if (!b.breaks) b.breaks = [];
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
if (iscontinue) b.continue = true;
|
|
43
|
+
b1s.forEach(b1 => {
|
|
44
|
+
if (iscontinue) b1.continue = b;
|
|
45
|
+
b.breaks.push(b1);
|
|
46
|
+
})
|
|
49
47
|
break;
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
51
|
return bx;
|
|
52
|
+
}
|
|
53
|
+
var _break = function (body, cx, result, iscontinue) {
|
|
54
|
+
var re = result[result.length - 1];
|
|
55
|
+
if (!result.length || re.ret_ && !re.await_ && re.ret_ !== -2) return;
|
|
56
|
+
var _b = scanner2('return []');
|
|
57
|
+
_b.ret_ = -1;
|
|
58
|
+
mount_break(body, cx, [_b[1]], iscontinue);
|
|
59
|
+
pushstep(result, _b);
|
|
54
60
|
};
|
|
55
61
|
var _try = function (body, cx, unblock, result, getname) {
|
|
56
62
|
var o = body[cx];
|
|
@@ -140,11 +146,13 @@ var _switch = function (body, cx, unblock, result, getname) {
|
|
|
140
146
|
var tmp = [];
|
|
141
147
|
while (o[cy] !== m) cy++;
|
|
142
148
|
var default_ = null, case_ = null;
|
|
149
|
+
var cbindex = 0, cblength = 0;
|
|
143
150
|
while (cy < o.length) {
|
|
144
151
|
var block = getblock(o, ++cy);
|
|
145
152
|
cy += block.length;
|
|
146
153
|
while (cy < o.length && o[cy].type & (SPACE | COMMENT)) cy++;
|
|
147
154
|
cy++;
|
|
155
|
+
while (cy < o.length && o[cy].type & (SPACE | COMMENT)) cy++;
|
|
148
156
|
var getnextname = function (deep) {
|
|
149
157
|
return getname(deep + 1);
|
|
150
158
|
};
|
|
@@ -152,18 +160,43 @@ var _switch = function (body, cx, unblock, result, getname) {
|
|
|
152
160
|
for (var q of q) if (q.length) pushstep(result, q);
|
|
153
161
|
var qe = q;
|
|
154
162
|
if (qe.name) case_ = scanner2(`if(${qn}===${qe.name})return[]`), pushstep(result, case_);
|
|
155
|
-
else default_ = case_ = scanner2(`return[]`), default_.ret_ = -
|
|
163
|
+
else default_ = case_ = scanner2(`return[]`), default_.ret_ = -2;
|
|
156
164
|
var by = cy;
|
|
157
165
|
m = o[cy];
|
|
158
166
|
while (m && (m.type !== STRAP || !/^(default|case)$/i.test(m.text))) m = o[++cy];
|
|
159
|
-
|
|
167
|
+
var cbody = o.slice(by, cy);
|
|
168
|
+
var cb0 = cbody[0];
|
|
169
|
+
if (cb0 && cb0.type === STRAP && (cb0.text === "break" || cb0.text === 'continue')) {
|
|
170
|
+
if (!cblength) {
|
|
171
|
+
var brks = [case_[case_.length - 1]];
|
|
172
|
+
while (tmp.length > cbindex) {
|
|
173
|
+
tmp.pop();
|
|
174
|
+
brks.push(tmp.pop());
|
|
175
|
+
tmp.pop();
|
|
176
|
+
};
|
|
177
|
+
mount_break(cbody, 0, brks, cb0.text === 'continue');
|
|
178
|
+
cblength = 0;
|
|
179
|
+
cbindex = tmp.length;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
cbindex = tmp.length + 3;
|
|
183
|
+
cblength = 0;
|
|
184
|
+
}
|
|
185
|
+
while (cbody.length) {
|
|
186
|
+
var cbe = cbody[cbody.length - 1];
|
|
187
|
+
if (cbe.type === SPACE) cbody.pop();
|
|
188
|
+
else if (cbe.type === STAMP && cbe.text === ';') cbody.pop();
|
|
189
|
+
else break;
|
|
190
|
+
}
|
|
191
|
+
cblength += cbody.length;
|
|
192
|
+
tmp.push(result.length - 1, case_[case_.length - 1], cbody);
|
|
160
193
|
}
|
|
161
194
|
if (!default_) {
|
|
162
|
-
default_ = scanner2(`return[]`), default_.ret_ = -
|
|
163
|
-
tmp.push(result.length - 1, default_[default_.length - 1], []);
|
|
195
|
+
default_ = scanner2(`return[]`), default_.ret_ = -2;
|
|
196
|
+
if (tmp.length) tmp.push(result.length - 1, default_[default_.length - 1], []);
|
|
164
197
|
}
|
|
165
198
|
var default_r = default_[default_.length - 1];
|
|
166
|
-
pushstep(result, default_);
|
|
199
|
+
if (tmp.length) pushstep(result, default_);
|
|
167
200
|
default_r.index = result.length - 1;
|
|
168
201
|
while (tmp.length) {
|
|
169
202
|
cy = tmp.shift();
|
|
@@ -441,7 +474,7 @@ var remove_end_comma = function (o) {
|
|
|
441
474
|
};
|
|
442
475
|
var ispropcall = function (o) {
|
|
443
476
|
var n = o.next;
|
|
444
|
-
if (!n || n.type !== SCOPED
|
|
477
|
+
if (!n || n.type !== SCOPED || n.entry !== '(') return false;
|
|
445
478
|
if (o.type === EXPRESS && snapExpressHead(o) !== o) return true;
|
|
446
479
|
if (o.type === SCOPED && o.entry === '[' && snapExpressHead(o) !== o) return true;
|
|
447
480
|
return false;
|
|
@@ -457,6 +490,7 @@ var _invoke = function (t, getname) {
|
|
|
457
490
|
queue.name = t.name;
|
|
458
491
|
var qname = t.name;
|
|
459
492
|
var bx = 0;
|
|
493
|
+
var lastlink = false;
|
|
460
494
|
for (var cx = 0; cx < t.length; cx++) {
|
|
461
495
|
var o = t[cx];
|
|
462
496
|
a: if (o.type === STRAP) {
|
|
@@ -482,6 +516,7 @@ var _invoke = function (t, getname) {
|
|
|
482
516
|
}
|
|
483
517
|
if (o.type === SCOPED && (o.entry === '[' || o.entry === "(")) {
|
|
484
518
|
var _nameindex = nameindex;
|
|
519
|
+
nameindex += lastlink;
|
|
485
520
|
remove_end_comma(o);
|
|
486
521
|
var iseval = o.iseval = isEval(o);
|
|
487
522
|
var constStart = 0;
|
|
@@ -532,16 +567,19 @@ var _invoke = function (t, getname) {
|
|
|
532
567
|
for (var c of cache) pushstep(result, c);
|
|
533
568
|
cache = [];
|
|
534
569
|
var n = o.next;
|
|
535
|
-
if (n && !needbreak(n)
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
570
|
+
if (n && !needbreak(n)) {
|
|
571
|
+
lastlink = n.type === SCOPED;
|
|
572
|
+
if (!ispropcall(o)) {
|
|
573
|
+
var h = snapExpressHead(o);
|
|
574
|
+
var hx = t.lastIndexOf(h, cx);
|
|
575
|
+
var fs = splice(t, hx, cx + 1 - hx, { type: EXPRESS, text: getname(nameindex) });
|
|
576
|
+
fs.unshift(...scanner2(`${getname(nameindex)}=`));
|
|
577
|
+
relink(fs);
|
|
578
|
+
fs.name = getname(nameindex);
|
|
579
|
+
pushstep(result, fs);
|
|
580
|
+
cx = hx - 1;
|
|
581
|
+
}
|
|
582
|
+
if (!lastlink) nameindex++;
|
|
545
583
|
}
|
|
546
584
|
}
|
|
547
585
|
}
|
|
@@ -77,9 +77,9 @@ test("do{await b}while(a)", "_ = b; return [_, 1];\r\n _ = @; if (a) return [-1,
|
|
|
77
77
|
test("switch(a){case 1:}", "if (a === 1) return [1, 0]; return [1, 0]", true);
|
|
78
78
|
test("switch(a){case 1: default:}", "if (a === 1) return [1, 0]; return [1, 0]", true);
|
|
79
79
|
test("switch(a.a){case 1:}", "_ = a.a; if (_ === 1) return [1, 0]; return [1, 0]", true);
|
|
80
|
-
test("switch(a){case 1:break;}", "if (a === 1) return [1, 0]
|
|
81
|
-
test("switch(a){case 1:break;case 2:break;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]
|
|
82
|
-
test("switch(a){case 1:case 2:break;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]
|
|
80
|
+
test("switch(a){case 1:break;}", "if (a === 1) return [1, 0]", true);
|
|
81
|
+
test("switch(a){case 1:break;case 2:break;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]", true);
|
|
82
|
+
test("switch(a){case 1:case 2:break;}", "if (a === 1) return [1, 0]; if (a === 2) return [1, 0]", true);
|
|
83
83
|
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);
|
|
84
84
|
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);
|
|
85
85
|
test("with(a){ a = 1}", `if (_ = with_("a", [a])) _.a = 1; else a = 1;`, true);
|
|
@@ -121,5 +121,11 @@ test("menus[a+b].name+='aaa'", "_ = a + b; _ = menus[_]; _0 = _.name + 'aaa'; _.
|
|
|
121
121
|
test("menus[a+b]()", "_ = a + b; menus[_]()", true);
|
|
122
122
|
test(`switch(a){default: a;case 1:b;}`, 'if (a === 1) return [2, 0]; return [1, 0];\r\n a; return [1, 0];\r\n b; return [1, 0]', true);
|
|
123
123
|
test("loop:{a=b;if(a) continue loop}", "a = b; if (a) return [0, 0]", true);
|
|
124
|
-
test("if(a)try{}finally{}else a;", 'if (!a) return [4, 0]; return [1, 8];\r\
|
|
125
|
-
test("if(a)try{}finally{}else;", 'if (!a) return [4, 0]; return [1, 8];\r\
|
|
124
|
+
test("if(a)try{}finally{}else a;", 'if (!a) return [4, 0]; return [1, 8];\r\n return [0, 9];\r\n return [1, 9];\r\n return [2, 0];\r\n a; return [1, 0]')
|
|
125
|
+
test("if(a)try{}finally{}else;", 'if (!a) return [4, 0]; return [1, 8];\r\n return [0, 9];\r\n return [1, 9];\r\n return [1, 0]');
|
|
126
|
+
test("b:while(t){switch(a){case c:break b;}}", 'if (!t) return [1, 0]; if (a === c) return [1, 0]; return [0, 0]');
|
|
127
|
+
test("predef[key[1]](r.slice(key[0].length).trim())", '_ = key[1]; _0 = key[0].length; _0 = r.slice(_0); _0 = _0.trim(); predef[_](_0)');
|
|
128
|
+
test("predef[key[1]](r.slice())(r.slice())", '_ = key[1]; _0 = r.slice(); _ = predef[_](_0); _0 = r.slice(); _(_0)');
|
|
129
|
+
test("predef[key[1]][key[2]][key[3]]", '_ = key[1]; _ = predef[_]; _0 = key[2]; _ = _[_0]; _0 = key[3]; _[_0]');
|
|
130
|
+
test("[key[1]][key[2]][key[3]]", '_ = key[1]; _ = [_]; _0 = key[2]; _ = _[_0]; _0 = key[3]; _[_0]');
|
|
131
|
+
test("[key[1]][key[2]]+[key[3]][key[4]]", '_ = key[1]; _ = [_]; _0 = key[2]; _ = _[_0]; _0 = key[3]; _0 = [_0]; _1 = key[4]; _ + _0[_1]');
|