efront 4.1.0 → 4.1.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.
- package/coms/compile/autoenum.js +91 -55
- package/coms/compile/autoenum_test.js +1 -0
- package/coms/compile/common.js +34 -6
- package/coms/compile/unstruct.js +2 -1
- package/coms/compile/unstruct_test.js +3 -1
- package/coms/compile//347/264/240/351/246/250.js +7 -7
- package/coms/compile//347/264/240/351/246/250_test.js +3 -1
- package/coms/docs/codetext.xht +1 -0
- package/package.json +1 -1
- package/public/efront.js +1 -1
package/coms/compile/autoenum.js
CHANGED
|
@@ -61,30 +61,38 @@ var maplist = function (u) {
|
|
|
61
61
|
map[r].ccount = 0;
|
|
62
62
|
}
|
|
63
63
|
var m = map[r];
|
|
64
|
-
m.
|
|
64
|
+
if (!o.equal && o.kind) m.unshift(o);
|
|
65
|
+
else m.push(o);
|
|
65
66
|
if (o.equal || o.kind) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
typeref
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
if (enumtype & REFTYPE) {
|
|
68
|
+
var typeref = o.typeref;
|
|
69
|
+
if (typeref && typeof typeref === 'object') {
|
|
70
|
+
typeref = typeref.typeref;
|
|
71
|
+
o.typeref = typeref;
|
|
72
|
+
}
|
|
73
|
+
if (typeref) {
|
|
74
|
+
if (m.typeref !== typeref) {
|
|
75
|
+
m.typeref = typeref;
|
|
76
|
+
m.wcount++;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (m.typeref) {
|
|
80
|
+
var n = o.next;
|
|
81
|
+
o[ignore] = true;
|
|
82
|
+
if (n.type === STAMP && /^(\+\+|\-\-)$/.test(n.text)) continue;
|
|
83
|
+
if (/^[\+\-]\=$/.test(n.text)) {
|
|
84
|
+
var nn = n.next;
|
|
85
|
+
if (nn && snapExpressFoot(nn) == nn && nn.isdigit && (nn.text & 0x1ff) === +nn.text) continue;
|
|
86
|
+
}
|
|
87
|
+
else if (!n || !/[^=!]?=$/.test(n.text)) continue;
|
|
88
|
+
o[ignore] = false;
|
|
89
|
+
m.wcount++;
|
|
90
|
+
}
|
|
74
91
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (n.type === STAMP && /^(\+\+|\-\-)$/.test(n.text)) continue;
|
|
79
|
-
if (/^[\+\-]\=$/.test(n.text)) {
|
|
80
|
-
var nn = n.next;
|
|
81
|
-
if (nn && snapExpressFoot(nn) == nn && nn.isdigit && (nn.text & 0x1ff) === +nn.text) continue;
|
|
82
|
-
}
|
|
83
|
-
else if (!n || !/=$/.test(n.text)) continue;
|
|
84
|
-
o[ignore] = false;
|
|
85
|
-
m.wcount++;
|
|
92
|
+
if (enumtype & (REFSTRC | REFMOVE)) {
|
|
93
|
+
if (o.property) o[ignore] = true;
|
|
94
|
+
else m.wcount++;
|
|
86
95
|
}
|
|
87
|
-
else m.wcount++;
|
|
88
96
|
}
|
|
89
97
|
if (o.called) m.ccount++;
|
|
90
98
|
}
|
|
@@ -140,6 +148,10 @@ function inCondition(o) {
|
|
|
140
148
|
}
|
|
141
149
|
if (p.type === STAMP) {
|
|
142
150
|
if (p.text === ";") break;
|
|
151
|
+
if (/^[\?\:]$/i.test(p.text)) {
|
|
152
|
+
incondition = true;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
143
155
|
o = p.prev;
|
|
144
156
|
continue;
|
|
145
157
|
}
|
|
@@ -149,62 +161,79 @@ function inCondition(o) {
|
|
|
149
161
|
|
|
150
162
|
}
|
|
151
163
|
|
|
152
|
-
function enumref(scoped) {
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (f.type === STAMP && f.text === ";") {
|
|
175
|
-
fc++;
|
|
176
|
-
if (fc > 1) break loop;
|
|
177
|
-
}
|
|
178
|
-
f = f.next;
|
|
164
|
+
function enumref(refitem, scoped) {
|
|
165
|
+
for (var rk in refitem) {
|
|
166
|
+
var os = refitem[rk];
|
|
167
|
+
if (os.wcount !== 1 || os.length < 2) continue;
|
|
168
|
+
var eq = null, em = null, tp = null;
|
|
169
|
+
loop: for (var o of os) {
|
|
170
|
+
if (o.equal && !o[ignore]) {
|
|
171
|
+
if (o.equal.text !== '=') break;
|
|
172
|
+
if (o.queue.kind) break;
|
|
173
|
+
var q = o.queue;
|
|
174
|
+
if (q !== scoped.body) {
|
|
175
|
+
if (q.entry === '(' && q.queue === scoped.body) {
|
|
176
|
+
var qp = q.prev;
|
|
177
|
+
if (qp.type === EXPRESS) qp = qp.prev;
|
|
178
|
+
if (qp && qp.type === STRAP && qp.text === "await") qp = qp.prev;
|
|
179
|
+
if (qp && qp.type === STRAP && qp.text === 'for') {
|
|
180
|
+
var f = q.first;
|
|
181
|
+
var fc = 0;
|
|
182
|
+
while (f && f !== o) {
|
|
183
|
+
if (f.type === STAMP && f.text === ";") {
|
|
184
|
+
fc++;
|
|
185
|
+
if (fc > 1) break loop;
|
|
179
186
|
}
|
|
187
|
+
f = f.next;
|
|
180
188
|
}
|
|
181
189
|
}
|
|
182
|
-
else break;
|
|
183
190
|
}
|
|
184
|
-
|
|
191
|
+
else break;
|
|
192
|
+
}
|
|
193
|
+
if (inCondition(o)) break;
|
|
194
|
+
if (enumtype & REFTYPE) {
|
|
185
195
|
if (o.typeref) {
|
|
186
196
|
tp = o.typeref;
|
|
187
197
|
if (isObject(tp)) tp = tp.typeref;
|
|
188
198
|
continue;
|
|
189
199
|
}
|
|
200
|
+
}
|
|
201
|
+
if (enumtype & REFSTRC) {
|
|
190
202
|
if (o.enumref) {
|
|
191
203
|
em = o.enumref;
|
|
192
204
|
continue;
|
|
193
205
|
}
|
|
206
|
+
}
|
|
207
|
+
if (enumtype & REFMOVE) {
|
|
194
208
|
o = o.equal.next;
|
|
195
209
|
var n = skipAssignment(o);
|
|
196
210
|
if (!o || n !== o.next) break loop;
|
|
197
211
|
if (o.type === VALUE && o.isdigit) eq = o;
|
|
198
212
|
}
|
|
199
|
-
|
|
213
|
+
}
|
|
214
|
+
else if (o.kind) {
|
|
215
|
+
if (enumtype & REFTYPE) {
|
|
216
|
+
if (o.typeref) {
|
|
217
|
+
tp = o.typeref;
|
|
218
|
+
if (isObject(tp)) tp = tp.typeref;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
if (enumtype & REFTYPE) {
|
|
200
225
|
if (tp) {
|
|
201
226
|
o.typeref = tp;
|
|
202
227
|
continue;
|
|
203
228
|
}
|
|
229
|
+
}
|
|
230
|
+
if (enumtype & REFSTRC) {
|
|
204
231
|
if (em) {
|
|
205
232
|
o.enumref = em;
|
|
206
233
|
continue;
|
|
207
234
|
}
|
|
235
|
+
}
|
|
236
|
+
if (enumtype & REFMOVE) {
|
|
208
237
|
if (!eq) break;
|
|
209
238
|
if (o.short) continue;
|
|
210
239
|
o.type = eq.type;
|
|
@@ -216,13 +245,17 @@ function enumref(scoped) {
|
|
|
216
245
|
}
|
|
217
246
|
}
|
|
218
247
|
}
|
|
219
|
-
|
|
220
248
|
function atuoenum(scoped) {
|
|
221
|
-
|
|
222
|
-
|
|
249
|
+
var { used } = scoped;
|
|
250
|
+
for (var k in used) {
|
|
251
|
+
var rs = maplist(used[k]);
|
|
252
|
+
enumref(rs, scoped);
|
|
253
|
+
}
|
|
223
254
|
}
|
|
224
|
-
var
|
|
255
|
+
var enumtype = 0;
|
|
256
|
+
var exports = module.exports = function main(code, type = REFMOVE) {
|
|
225
257
|
var rest = [code.scoped];
|
|
258
|
+
enumtype = type;
|
|
226
259
|
while (rest.length) {
|
|
227
260
|
var s = rest.pop();
|
|
228
261
|
if (s.length) rest.push(...s);
|
|
@@ -230,6 +263,9 @@ var exports = module.exports = function main(code) {
|
|
|
230
263
|
}
|
|
231
264
|
return code;
|
|
232
265
|
}
|
|
266
|
+
var REFMOVE = exports.REFMOVE = 1;
|
|
267
|
+
var REFSTRC = exports.REFSTRC = 2;
|
|
268
|
+
var REFTYPE = exports.REFTYPE = 4;
|
|
233
269
|
exports.createRefId = createRefId;
|
|
234
270
|
exports.createRefMap = createRefMap;
|
|
235
271
|
exports.enumscoped = atuoenum;
|
|
@@ -31,4 +31,5 @@ t("var a=-1; console.log(--a)", "var a = -1; console.log(--a)");
|
|
|
31
31
|
t("var a=-1; return ++a", "var a = -1; return ++a");
|
|
32
32
|
t("var a=-1; typeof ++a", "var a = -1; typeof ++a");
|
|
33
33
|
t("var a=-1; ++a", "var a = -1; ++a");
|
|
34
|
+
t("b?a=1:b=2;console.log(a)", "b ? a = 1 : b = 2; console.log(a)");
|
|
34
35
|
// t(fs.readFileSync(path.join(__dirname,"../zimoli/spacechar_test.js")).toString())
|
package/coms/compile/common.js
CHANGED
|
@@ -259,9 +259,15 @@ function snapSentenceHead(o) {
|
|
|
259
259
|
break;
|
|
260
260
|
}
|
|
261
261
|
if (p.type === STAMP) {
|
|
262
|
-
if (/=>|[,;]/.test(p.text)
|
|
262
|
+
if (/=>|[,;]/.test(p.text)) {
|
|
263
263
|
break;
|
|
264
264
|
}
|
|
265
|
+
if (/^[\?\:]$/.test(p.text)) {
|
|
266
|
+
if (o) {
|
|
267
|
+
var e = snapExpressFoot(o).next;
|
|
268
|
+
if (e.type === STAMP && equal_reg.test(e.text)) break;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
265
271
|
if (/^(?:[!~]|\+\+|\-\-)$/.test(p.text)) {
|
|
266
272
|
o = p;
|
|
267
273
|
continue;
|
|
@@ -496,6 +502,7 @@ var createScoped = function (parsed, wash) {
|
|
|
496
502
|
case "var":
|
|
497
503
|
m = m || vars;
|
|
498
504
|
var [declared, used0, o0, skiped] = getDeclared(o.next, s);
|
|
505
|
+
mergeTo(used, used0);
|
|
499
506
|
while (skiped.length) {
|
|
500
507
|
var o1 = run(skiped[0], 0);
|
|
501
508
|
let sindex = skiped.indexOf(o1);
|
|
@@ -503,7 +510,6 @@ var createScoped = function (parsed, wash) {
|
|
|
503
510
|
skiped.splice(0, sindex + 1);
|
|
504
511
|
}
|
|
505
512
|
o = o0;
|
|
506
|
-
mergeTo(used, used0);
|
|
507
513
|
mapDeclared(m, declared);
|
|
508
514
|
continue loop;
|
|
509
515
|
case "static":
|
|
@@ -1222,16 +1228,16 @@ var splice = function (queue, index, size, ...args) {
|
|
|
1222
1228
|
var res = queue.splice(index, size, ...args);
|
|
1223
1229
|
var previ = queue.lastIndexOf(prev, index);
|
|
1224
1230
|
var nexti = queue.indexOf(next, index + args.length);
|
|
1225
|
-
if (previ < 0) previ = 0;
|
|
1226
|
-
if (nexti < 0) nexti = queue.length;
|
|
1231
|
+
if (previ < 0) previ = 0, prev = null;
|
|
1232
|
+
if (nexti < 0) nexti = queue.length, next = null;
|
|
1227
1233
|
else nexti++;
|
|
1228
1234
|
var changedargs = queue.slice(previ, nexti);
|
|
1229
1235
|
var pp = prev && prev.prev;
|
|
1230
1236
|
var nn = next && next.next;
|
|
1231
1237
|
relink(changedargs);
|
|
1232
|
-
if (
|
|
1238
|
+
if (pp) changedargs.first.prev = pp, pp.next = changedargs.first;
|
|
1233
1239
|
else queue.first = changedargs.first;
|
|
1234
|
-
if (
|
|
1240
|
+
if (nn) changedargs.last.next = nn, nn.prev = changedargs.last;
|
|
1235
1241
|
else queue.last = changedargs.last;
|
|
1236
1242
|
setqueue(args, queue);
|
|
1237
1243
|
return res;
|
|
@@ -1276,6 +1282,27 @@ var canbeTemp = function (body, strip = false) {
|
|
|
1276
1282
|
return o.type === EXPRESS && (strip || !/[\.\[]/.test(o.text)) || o.type === VALUE || o.type === QUOTED && !o.length;
|
|
1277
1283
|
};
|
|
1278
1284
|
|
|
1285
|
+
var pickSentence = function (o) {
|
|
1286
|
+
if (!o) return [];
|
|
1287
|
+
if (o && o.type & (SPACE | COMMENT) && o.prev) o = o.prev;
|
|
1288
|
+
if (o && o.type === STAMP && o.prev) o = o.prev;
|
|
1289
|
+
if (o.type === STRAP && /^(in|instanceof|as|of)$/.test(o.text) && o.prev) o = o.prev;
|
|
1290
|
+
var h = snapSentenceHead(o);
|
|
1291
|
+
var e = skipAssignment(o);
|
|
1292
|
+
var q = o.queue;
|
|
1293
|
+
if (q) {
|
|
1294
|
+
var qh = q.indexOf(h);
|
|
1295
|
+
var qe = e ? q.indexOf(e) : q.length;
|
|
1296
|
+
if (qh >= 0 && qe >= 0) return q.slice(qh, qe);
|
|
1297
|
+
}
|
|
1298
|
+
var res = [];
|
|
1299
|
+
do {
|
|
1300
|
+
res.push(h);
|
|
1301
|
+
h = h.next;
|
|
1302
|
+
} while (h !== e);
|
|
1303
|
+
return res;
|
|
1304
|
+
};
|
|
1305
|
+
|
|
1279
1306
|
module.exports = {
|
|
1280
1307
|
/* 1 */COMMENT,
|
|
1281
1308
|
/* 2 */SPACE,
|
|
@@ -1297,6 +1324,7 @@ module.exports = {
|
|
|
1297
1324
|
createScoped,
|
|
1298
1325
|
createExpressList,
|
|
1299
1326
|
snapSentenceHead,
|
|
1327
|
+
pickSentence,
|
|
1300
1328
|
snapExpressHead,
|
|
1301
1329
|
snapExpressFoot,
|
|
1302
1330
|
skipSentenceQueue,
|
package/coms/compile/unstruct.js
CHANGED
|
@@ -335,6 +335,7 @@ var _while = function (body, cx, unblock, result) {
|
|
|
335
335
|
pushstep(result, wend);
|
|
336
336
|
we[0].text = String(1 + i - result.length);
|
|
337
337
|
be.push(...scanner2(`${result.length - i}, 0`));
|
|
338
|
+
relink(be);
|
|
338
339
|
return cx;
|
|
339
340
|
};
|
|
340
341
|
var pushstep = function (result, step) {
|
|
@@ -607,7 +608,7 @@ var _invoke = function (t, getname) {
|
|
|
607
608
|
else if (t.length) {
|
|
608
609
|
var t0 = t[0];
|
|
609
610
|
if (t0.type === EXPRESS && /^[\.\[]/.test(t0.text) || t0.type & (STAMP | STRAP) && powermap[t0.text] < powermap.new) {
|
|
610
|
-
t.unshift(...
|
|
611
|
+
t.unshift(...rescan(`${qname}=${qname}`));
|
|
611
612
|
relink(t);
|
|
612
613
|
}
|
|
613
614
|
pushstep(result, t);
|
|
@@ -132,4 +132,6 @@ test("predef[key[1]](r.slice())(r.slice())", '_ = key[1]; _0 = r.slice(); _ = pr
|
|
|
132
132
|
test("predef[key[1]][key[2]][key[3]]", '_ = key[1]; _ = predef[_]; _0 = key[2]; _ = _[_0]; _0 = key[3]; _[_0]');
|
|
133
133
|
test("[key[1]][key[2]][key[3]]", '_ = key[1]; _ = [_]; _0 = key[2]; _ = _[_0]; _0 = key[3]; _[_0]');
|
|
134
134
|
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]');
|
|
135
|
-
test("if(a)a:{break a}", "if (!a) return [2, 0]; return [1, 0];\r\n return [1, 0]", true);
|
|
135
|
+
test("if(a)a:{break a}", "if (!a) return [2, 0]; return [1, 0];\r\n return [1, 0]", true);
|
|
136
|
+
unstruct.debug = true;
|
|
137
|
+
test("rgb=(rgb<<8|rgb>>16)&0xffffff", "_ = rgb << 8, _0 = rgb >> 16, _ = _ | _0; _ = (_); rgb = _ & 0xffffff", true);
|
|
@@ -431,11 +431,15 @@ function evalscoped(scoped, base = '') {
|
|
|
431
431
|
var vlist = [vars];
|
|
432
432
|
var mlist = [macros];
|
|
433
433
|
var clist = [smaps];
|
|
434
|
+
var calcvars = function (v) {
|
|
435
|
+
return v.replace(/(^|\s|[\]\)\(\[\-\+\*\/,;])(?:var\s*\(([\s\S]*?)\)|(--\S+|@[^\s\{\}\(\)\[\]\:\+\*\/,;\!\>\$\=\&\%\#\@'"`\?\.\/\|~#]+|@\{[^\}@]*\}))/g, function (m, q, a, b) {
|
|
436
|
+
return q + getFromScopeList(b || a.trim(), vlist, m.slice(q.length));
|
|
437
|
+
});
|
|
438
|
+
};
|
|
434
439
|
var initvars = function (vars) {
|
|
435
440
|
for (var k in vars) {
|
|
436
441
|
var v = vars[k];
|
|
437
|
-
|
|
438
|
-
vars[k] = v;
|
|
442
|
+
vars[k] = replace_punc(calcvars(v));
|
|
439
443
|
}
|
|
440
444
|
};
|
|
441
445
|
initvars(vars);
|
|
@@ -453,11 +457,6 @@ function evalscoped(scoped, base = '') {
|
|
|
453
457
|
base = temp;
|
|
454
458
|
return res;
|
|
455
459
|
};
|
|
456
|
-
var calcvars = function (v) {
|
|
457
|
-
return v.replace(/(^|\s|[\]\)\(\[\-\+\*\/,;])(?:var\s*\(([\s\S]*?)\)|(--\S+|@[^\s\{\(\:\+\*\/,;\!\[\>\$\=\&\%\#\@\+'"`\?\.\/\|~]+|@\{[^\}@]*\}))/g, function (m, q, a, b) {
|
|
458
|
-
return q + getFromScopeList(b || a.trim(), vlist, m.slice(q.length));
|
|
459
|
-
});
|
|
460
|
-
};
|
|
461
460
|
var evalproc = function (k, retnoparam) {
|
|
462
461
|
var match = (retnoparam !== false ? /^([^\(\)\s,;:]*)(?:\s*\(([\s\S]*)\))$/ : /^([^\(\)\s,;:]+)(?:\s*\(([\s\S]*)\))?$/).exec(k);
|
|
463
462
|
if (!match) return calcvars(k);
|
|
@@ -536,6 +535,7 @@ function evalscoped(scoped, base = '') {
|
|
|
536
535
|
if (base && !p.rooted) p.base = fixBase(base, k);
|
|
537
536
|
else p.base = presets.test(k) ? `@{${k}}` : k;
|
|
538
537
|
if (p.vars) vlist.push(p.vars);
|
|
538
|
+
initvars(p.vars);
|
|
539
539
|
var value = evalthis(p);
|
|
540
540
|
if (p.vars) vlist.pop();
|
|
541
541
|
if (value.rest.length) rest = rest.concat(value.rest);
|
|
@@ -65,4 +65,6 @@ assert(素馨(`&{&:not(a):not(b){c:d}}`, 'abc'), `abc:not(a):not(b){c:d;}`);
|
|
|
65
65
|
assert(素馨(`:root>a{&:not(a):not(b){c:d}}`, '.abc-'), `.abc->a:not(a):not(b){c:d;}`);
|
|
66
66
|
assert(素馨(`a>:root{&:not(a):not(b){c:d}}`, '.abc-'), `a>.abc-:not(a):not(b){c:d;}`);
|
|
67
67
|
|
|
68
|
-
assert(素馨(`.a (){ &:after{abc:1}} .b{.a();}`, '.abc-'), `.abc- .b:after{abc:1;}`);
|
|
68
|
+
assert(素馨(`.a (){ &:after{abc:1}} .b{.a();}`, '.abc-'), `.abc- .b:after{abc:1;}`);
|
|
69
|
+
assert(素馨(`@a:1px;@margin-x:@a+10px; a{m:-@margin-x}`), `a{m:-11px;}`);
|
|
70
|
+
assert(素馨(`a{@a:1px;@margin-x:@a+10px;m:-@margin-x}`), `a{m:-11px;}`);
|
package/coms/docs/codetext.xht
CHANGED
|
@@ -173,6 +173,7 @@
|
|
|
173
173
|
javascript(a, blink) {
|
|
174
174
|
if (blink) var index = a.indexOf(blink);
|
|
175
175
|
if (index >= 0) a = a.slice(0, index) + a.slice(index + 1);
|
|
176
|
+
js.keepspace = !!blink;
|
|
176
177
|
var c = compile$scanner2(a, js);
|
|
177
178
|
if (index >= 0) {
|
|
178
179
|
var patched = patchBlink(c, index, blink);
|