efront 4.4.0 → 4.4.2
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.
|
@@ -1,19 +1,72 @@
|
|
|
1
|
-
function
|
|
2
|
-
var dist;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
dist
|
|
8
|
-
} else {
|
|
9
|
-
dist = search;
|
|
1
|
+
function splitSeek(express) {
|
|
2
|
+
var dist = [];
|
|
3
|
+
var x = 0;
|
|
4
|
+
express.forEach((e, i) => {
|
|
5
|
+
if (i > x && /\?/.test(e)) {
|
|
6
|
+
var exp = express.slice(x, x = i);
|
|
7
|
+
dist.push(exp);
|
|
10
8
|
}
|
|
11
9
|
});
|
|
10
|
+
if (x < express.length) dist.push(express.slice(x, express.length));
|
|
11
|
+
dist.forEach(d => d[0] = d[0].replace(/^\?/, ''))
|
|
12
12
|
return dist;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function getTmpvar(explist) {
|
|
15
|
+
var varset = {};
|
|
16
|
+
explist.forEach(e => {
|
|
17
|
+
e = e[0].replace(/^([^\.\[]]+)[\s\S]*$/, "$1");
|
|
18
|
+
varset[e] = true;
|
|
19
|
+
});
|
|
20
|
+
var tmpvar = 'b', n = 0;
|
|
21
|
+
while (tmpvar in varset) {
|
|
22
|
+
tmpvar = 'b' + n++;
|
|
23
|
+
}
|
|
24
|
+
return tmpvar;
|
|
25
|
+
}
|
|
26
|
+
var autoDefine = false;
|
|
27
|
+
function createSeek(express, split = true) {
|
|
28
|
+
var tmpvar = 'a', undef = '_', _null = '$';
|
|
29
|
+
if (express.length <= 1) return express[0];
|
|
30
|
+
var notmp = !/[\.\[\(\{]/.test(express[0]);
|
|
31
|
+
if (express.length === 2) {
|
|
32
|
+
if (split && /^\?/.test(express[1])) {
|
|
33
|
+
if (notmp) return `typeof ${tmpvar}!=='undefined'&&${tmpvar}!==null?${tmpvar}:${express[1].slice(1)}`;
|
|
34
|
+
return `function(${tmpvar},${undef}){return ${tmpvar}===${undef}||${tmpvar}===null?${express[1].slice(1)}:${tmpvar}}(${express[0]})`;
|
|
35
|
+
}
|
|
36
|
+
if (notmp) {
|
|
37
|
+
tmpvar = express[0];
|
|
38
|
+
if (autoDefine) {
|
|
39
|
+
return `typeof ${tmpvar}==='undefined'||${tmpvar}===null?void 0:${tmpvar}${express[1]}`;
|
|
40
|
+
}
|
|
41
|
+
return `${tmpvar}===void 0||${tmpvar}===null?void 0:${tmpvar}${express[1]}`;
|
|
42
|
+
};
|
|
43
|
+
return `function(${tmpvar},${undef}){return ${tmpvar}===${undef}||${tmpvar}===null?${undef}:${tmpvar}${express[1]}}(${express[0]})`;
|
|
44
|
+
}
|
|
45
|
+
if (!split) {
|
|
46
|
+
var dist = express.slice(1).map((search, i, a) => {
|
|
47
|
+
return `if(${tmpvar}===${undef}||${tmpvar}===${_null})return;${tmpvar}=${tmpvar}${search};`;
|
|
48
|
+
}).join('');
|
|
49
|
+
dist = `function(${tmpvar},${_null},${undef}){${dist}return ${tmpvar}}(${express[0]},null)`;
|
|
50
|
+
if (notmp && autoDefine) {
|
|
51
|
+
dist = `typeof ${express[0]}==='undefined'&&${express[0]}===null?void 0:${dist}`;
|
|
52
|
+
}
|
|
53
|
+
return dist;
|
|
54
|
+
}
|
|
55
|
+
var explist = splitSeek(express);
|
|
56
|
+
if (explist.length === 1) {
|
|
57
|
+
return createSeek(explist[0], false);
|
|
58
|
+
}
|
|
59
|
+
tmpvar = getTmpvar(explist);
|
|
60
|
+
var dist = explist.slice(0, explist.length - 1).map(express => {
|
|
61
|
+
var dist = createSeek(express, false);
|
|
62
|
+
return `${tmpvar}=${dist};if(${tmpvar}!==void 0&&${tmpvar}!==null)return ${tmpvar};`;
|
|
63
|
+
}).join("") + `return ${createSeek(explist[explist.length - 1], false)}`;
|
|
64
|
+
return `function(${tmpvar}){${dist}}()`;
|
|
65
|
+
}
|
|
66
|
+
function main(express, autodef = true) {
|
|
67
|
+
autoDefine = autodef;
|
|
15
68
|
if (!/\?\s*\.(?=[^\d])|\?\s*[\?\]\}\)\:\,=|%&;\>\<]|\?\s*$/.test(express)) return express;
|
|
16
|
-
var reg = /\\[\s\S]|\?\s*(\.(?!\d)
|
|
69
|
+
var reg = /\\[\s\S]|\?\s*([\.](?!\d)|\?|$|(?=[\?\]\}\)\:\,=|%&;\>\<\*\/]))|[\:\,\+\=\-\!%\^\|\/\&\*\!\;\?\>\<~\{\}\[\]\(\)'"`\s]/g;
|
|
17
70
|
var cache = [], queue = [];
|
|
18
71
|
var exp = [];
|
|
19
72
|
var instr = false;
|
|
@@ -22,7 +75,7 @@ function main(express) {
|
|
|
22
75
|
if (!exp.length) exp.push(s);
|
|
23
76
|
else {
|
|
24
77
|
var e = exp[exp.length - 1];
|
|
25
|
-
if (!/[
|
|
78
|
+
if (!/[\.\?]\s*$/.test(e) && !/^\s*[\.'"`\[\(]/.test(s)) {
|
|
26
79
|
queue.push(createSeek(exp));
|
|
27
80
|
exp.splice(0, exp.length, '');
|
|
28
81
|
e = '';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
assert(renderExpress("[].a"), "[].a")
|
|
2
|
+
assert(renderExpress("a?b:c"), "a?b:c")
|
|
3
|
+
assert(renderExpress("a?"), "(typeof a==='undefined'||a===null?void 0:a)")
|
|
4
|
+
assert(renderExpress("[].a?.()"), "(function(a,_){return a===_||a===null?_:a()}([].a))")// 暂不支持在?.()的函数中访问this,此为临时方案
|
|
5
|
+
assert(renderExpress("[].a?.b?.c?.()"), "(function(a,$,_){if(a===_||a===$)return;a=a.b;if(a===_||a===$)return;a=a.c;if(a===_||a===$)return;a=a();return a}([].a,null))")
|
|
6
|
+
assert(renderExpress("a??b"), "(typeof a!=='undefined'&&a!==null?a:b)")
|
|
7
|
+
assert(renderExpress("a?.b??b?.c", false), "(function(b0){b0=a===void 0||a===null?void 0:a.b;if(b0!==void 0&&b0!==null)return b0;return b===void 0||b===null?void 0:b.c}())")
|
|
8
|
+
|
|
9
|
+
assert(renderExpress("[]?.a"), "(function(a,_){return a===_||a===null?_:a.a}([]))")
|
|
10
|
+
assert(renderExpress("[]?.()"), "(function(a,_){return a===_||a===null?_:a()}([]))")
|
|
11
|
+
assert(renderExpress("[]?.[]"), "(function(a,_){return a===_||a===null?_:a[]}([]))")
|
package/coms/compile/Html.js
CHANGED
|
@@ -20,8 +20,10 @@ const {
|
|
|
20
20
|
getDeclared,
|
|
21
21
|
createScoped,
|
|
22
22
|
snapExpressHead,
|
|
23
|
+
snapExpressFoot,
|
|
23
24
|
splice,
|
|
24
25
|
relink,
|
|
26
|
+
remove,
|
|
25
27
|
setqueue,
|
|
26
28
|
replace,
|
|
27
29
|
skipAssignment,
|
|
@@ -521,7 +523,18 @@ function detour(o, ie) {
|
|
|
521
523
|
if (m) { context.avoidMap[m[0]] = true; }
|
|
522
524
|
}
|
|
523
525
|
if (/\?\./.test(text)) {
|
|
524
|
-
|
|
526
|
+
if (/\?\.$/.test(text)) {
|
|
527
|
+
o = snapExpressHead(o);
|
|
528
|
+
var f = snapExpressFoot(o);
|
|
529
|
+
var rest = [o];
|
|
530
|
+
remove(o, f.prev);
|
|
531
|
+
while (o !== f) {
|
|
532
|
+
o = o.next;
|
|
533
|
+
rest.push(o);
|
|
534
|
+
}
|
|
535
|
+
text = createString(rest);
|
|
536
|
+
}
|
|
537
|
+
text = renderExpress(text, false);
|
|
525
538
|
if (hasdot) text = "..." + text;
|
|
526
539
|
o = replace(o, ...scan(text));
|
|
527
540
|
continue;
|
package/coms/compile/common.js
CHANGED
|
@@ -1323,10 +1323,16 @@ var splice = function (queue, index, size, ...args) {
|
|
|
1323
1323
|
setqueue(args, queue);
|
|
1324
1324
|
return res;
|
|
1325
1325
|
};
|
|
1326
|
-
var remove = function (o) {
|
|
1326
|
+
var remove = function (o, end) {
|
|
1327
1327
|
var q = o.queue;
|
|
1328
1328
|
var i = q.indexOf(o);
|
|
1329
|
-
|
|
1329
|
+
var length = 1;
|
|
1330
|
+
if (arguments.length === 2) {
|
|
1331
|
+
end = q.indexOf(end, i) + 1;
|
|
1332
|
+
if (end < 0) end = i;
|
|
1333
|
+
length = end - i;
|
|
1334
|
+
}
|
|
1335
|
+
if (i >= 0) splice(q, i, length);
|
|
1330
1336
|
};
|
|
1331
1337
|
var replace = function (o, ...args) {
|
|
1332
1338
|
var queue = o.queue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "efront",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.2",
|
|
4
4
|
"description": "简化前端开发,优化web性能",
|
|
5
5
|
"main": "public/efront.js",
|
|
6
6
|
"directories": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"efront": "public/efront.js"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"prepack": "node tools/build-efront.js --
|
|
13
|
+
"prepack": "node tools/build-efront.js --node --deno --no-target",
|
|
14
14
|
"start": "efront ./efront/ --libs=typescript,esprima,escodegen,esmangle,pngjs,less-node"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|