efront 4.0.31 → 4.0.33
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/wait.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
async function wait(call, time = 80, step = +time >>> 4 | 1) {
|
|
2
2
|
var res;
|
|
3
|
-
while (!(res = await call()) && time > 0) await new Promise(ok => setTimeout(ok, step)), time -= step;
|
|
3
|
+
if (isFunction(call)) while (!(res = await call()) && time > 0) await new Promise(ok => setTimeout(ok, step)), time -= step;
|
|
4
|
+
else res = new Promise(ok => setTimeout(ok, call));
|
|
4
5
|
return res;
|
|
5
6
|
}
|
|
@@ -21,6 +21,7 @@ const {
|
|
|
21
21
|
snapExpressHead,
|
|
22
22
|
splice,
|
|
23
23
|
relink,
|
|
24
|
+
setqueue,
|
|
24
25
|
replace,
|
|
25
26
|
skipAssignment,
|
|
26
27
|
} = require("./common");
|
|
@@ -354,7 +355,7 @@ var hasComma = function (c) {
|
|
|
354
355
|
var removeQuote = function (o, c, i) {
|
|
355
356
|
if (hasComma(c)) return;
|
|
356
357
|
if (!isFinite(i)) i = o.indexOf(c);
|
|
357
|
-
|
|
358
|
+
splice(o, i, 1, ...c);
|
|
358
359
|
var ch = c[0];
|
|
359
360
|
var cf = c[c.length - 1];
|
|
360
361
|
ch.prev = c.prev;
|
|
@@ -500,13 +501,13 @@ Javascript.prototype.detour = function detour(o, ie) {
|
|
|
500
501
|
|
|
501
502
|
var removeImport = function (c, i, code) {
|
|
502
503
|
var next = c.next;
|
|
504
|
+
var { used, envs, vars } = code;
|
|
503
505
|
if (next && next.type !== QUOTED) {
|
|
504
|
-
var { used, envs, vars } = code;
|
|
505
506
|
var [dec, map, o] = getDeclared(c.next);
|
|
506
507
|
if (dec.length !== 1 || !o) throw new Error("代码结构异常!");
|
|
507
508
|
if (o.type !== STRAP || o.text !== 'from') throw new Error("缺少from语句");
|
|
508
509
|
}
|
|
509
|
-
else o = c;
|
|
510
|
+
else code.splice(i, 1), o = c;
|
|
510
511
|
var n = o.next;
|
|
511
512
|
var t = null;
|
|
512
513
|
if (n && n.type === EXPRESS) {
|
|
@@ -523,7 +524,7 @@ var removeImport = function (c, i, code) {
|
|
|
523
524
|
if (!n || n.type !== QUOTED) throw new Error("缺少导入路径!");
|
|
524
525
|
var oi = code.indexOf(o, i);
|
|
525
526
|
var ns = skipAssignment(n);
|
|
526
|
-
var nsi = code.indexOf(ns, i);
|
|
527
|
+
var nsi = ns ? code.indexOf(ns, i) : code.length;
|
|
527
528
|
var q = scan(`require()`);
|
|
528
529
|
if (!used.require) used.require = [], envs.require = true;
|
|
529
530
|
used.require.push(q[0]);
|
|
@@ -531,6 +532,7 @@ var removeImport = function (c, i, code) {
|
|
|
531
532
|
var cs = code.splice(oi + 1, nsi - oi - 1, ...q);
|
|
532
533
|
q[1].push.apply(q[1], cs);
|
|
533
534
|
relink(q[1]);
|
|
535
|
+
setqueue(q[1]);
|
|
534
536
|
if (!dec) return;
|
|
535
537
|
var name = dec[0];
|
|
536
538
|
var na = dec.attributes[0];
|
|
@@ -695,6 +697,7 @@ Javascript.prototype.fix = function (code) {
|
|
|
695
697
|
});
|
|
696
698
|
}
|
|
697
699
|
relink(code);
|
|
700
|
+
setqueue(code);
|
|
698
701
|
}
|
|
699
702
|
Javascript.prototype.createString = createString;
|
|
700
703
|
Javascript.prototype.createScoped = createScoped;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// 导入
|
|
2
|
+
var testFix = function (a, e) {
|
|
3
|
+
var c = scanner2(a);
|
|
4
|
+
c.fix();
|
|
5
|
+
assert(c.toString(), e);
|
|
6
|
+
}
|
|
7
|
+
testFix(`import a from "a";console.log(a)`, 'var a = require("a"); console.log(a.default)');
|
|
8
|
+
testFix(`import {a} from "a";console.log(a)`, 'var a1 = require("a"); console.log(a1.a)');
|
|
9
|
+
testFix(`console.log(import("a"))`, 'console.log(require("a"))');
|
|
10
|
+
testFix(`import("a")`, 'require("a")');
|
|
11
|
+
testFix(`import "windows.inc"`, 'require("windows.inc")');
|