efront 4.21.2 → 4.21.4

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,9 @@ const {
11
11
  /* 512 */LABEL,
12
12
  /*1024 */PROPERTY,
13
13
  /*2048 */ELEMENT,
14
+ pickAssignment,
14
15
  createString,
16
+ setqueue,
15
17
  number_reg,
16
18
  digit_reg,
17
19
  } = require("./common");
@@ -53,6 +55,16 @@ var stringsFromRegExp = function (reg) {
53
55
  var res = combine(...queue).map(a => a.join(""));
54
56
  return res;
55
57
  }
58
+
59
+ var trimDulp = function (list) {
60
+ var dist = [];
61
+ for (var a of list) {
62
+ if (dist.indexOf(a) >= 0) continue;
63
+ dist.push(a);
64
+ }
65
+ return dist;
66
+ }
67
+
56
68
  var spaceDefined = require("../basic/spaces");
57
69
 
58
70
  var powermap = require("./powermap");
@@ -64,7 +76,7 @@ class Program {
64
76
  ["`", "`", /\\[\s\S]/, ["${", "}"]],
65
77
  ]
66
78
  tags = [
67
- [["<", "</"], /\/?>/, /\\[\s\S]|\=\>/, "'", '"', "<!--", ["${", "}"]]
79
+ [["<", "</"], /\/?>/, /\\[\s\S]/, "'", '"', "<!--", ["${", "}"]]
68
80
  ];
69
81
  scriptTags = [];
70
82
  ignoreTags = ["STYLE", "SCRIPT"];
@@ -323,10 +335,10 @@ class Program {
323
335
  var scriptTags = this.scriptTags;
324
336
  var ignoreTags = this.ignoreTags;
325
337
  var structstrap_reg = this.structstrap_reg;
338
+ var mindpath = this.mindpath;
326
339
  var openTag = function () {
327
340
  var m1 = text.slice(start, match.index);
328
341
  var s = space_exp.exec(m1);
329
-
330
342
  if (s) var tag = m1.slice(0, s.index);
331
343
  else {
332
344
  tag = m1;
@@ -373,7 +385,10 @@ class Program {
373
385
  if (scope) queue = scope;
374
386
  return true;
375
387
  }
376
-
388
+ if (s && !tag) {
389
+ undefTag();
390
+ return;
391
+ }
377
392
  queue.inTag = true;
378
393
  queue.tag = tag;
379
394
  var tagName = tag.toUpperCase();
@@ -386,7 +401,8 @@ class Program {
386
401
  }
387
402
  if (s) {
388
403
  m = m1.slice(s[0].length + s.index);
389
- if (m) save(PIECE);
404
+ start += s[0].length + s.index;
405
+ push_piece();
390
406
  }
391
407
  queue.first = null;
392
408
  queue.last = null;
@@ -405,12 +421,60 @@ class Program {
405
421
  }
406
422
  }
407
423
  return istype;
424
+ };
425
+ var undefTag = () => {
426
+ var scope = {
427
+ type: STAMP,
428
+ text: queue.entry,
429
+ col: queue.col,
430
+ row: queue.row,
431
+ start: queue.start,
432
+ };
433
+ if (queue[0]) {
434
+ queue.splice(0, queue.length);
435
+ start = index = queue[0].start;
436
+ }
437
+ else {
438
+ queue = parents.pop();
439
+ start = index = scope.start + scope.text.length;
440
+ }
441
+ var last = queue.last;
442
+ if (last.type === PIECE) {
443
+ this.lastIndex = 0;
444
+ var thist = this.type;
445
+ this.type = undefined;
446
+ var res = this.exec(last.text);
447
+ this.type = thist;
448
+ this.lastIndex = index;
449
+ var prev = last.prev;
450
+ if (prev) {
451
+ prev.next = res.first;
452
+ }
453
+ if (res.first) {
454
+ res.first.prev = prev;
455
+ }
456
+ queue.last = res.last;
457
+ queue.splice(queue.length - 1, 1, ...res);
458
+ setqueue(res, queue);
459
+
460
+ }
461
+ queue_push(scope);
462
+
408
463
  }
409
464
  var closeTag = function () {
410
465
  queue.inTag = false;
466
+ if (text.charAt(index) === m) {
467
+ if ((m + m) in powermap) {
468
+ if (!parents[parents.length - 1].tag) {
469
+ undefTag();
470
+ return false;
471
+ }
472
+ }
473
+ }
411
474
  if (queue.closed) return;
412
475
  if (queue.length) queue.attributes = queue.splice(0, queue.length);
413
476
  if (/^\//.test(m) || queue.istype) return queue.short = true, queue.closed = true;
477
+ queue.tag_leave = m;
414
478
  return false;
415
479
  };
416
480
  var push_quote = function () {
@@ -506,10 +570,8 @@ class Program {
506
570
  start = index = match.index;
507
571
  }
508
572
  else queue.inTag = false;
509
-
510
- continue;
573
+ continue loop;
511
574
  }
512
-
513
575
  if (quote.end.test(m)) {
514
576
  end = match.index;
515
577
  if (queue.tag) {
@@ -517,7 +579,6 @@ class Program {
517
579
  if (!queue.inTag) continue;
518
580
  if (closeTag() === false) {
519
581
  start = index;
520
- queue.tag_leave = m;
521
582
  continue loop;
522
583
  }
523
584
  queue.type = ELEMENT;
@@ -542,7 +603,7 @@ class Program {
542
603
  scope.entry = m;
543
604
  scope.type = QUOTED;
544
605
  if (queue.istype) scope.istype = queue.istype;
545
- scope.start = index;
606
+ scope.start = match.index;
546
607
  scope.isExpress = queue.inExpress;
547
608
  push_parents(scope);
548
609
  queue.inTag = 0;
@@ -708,7 +769,7 @@ class Program {
708
769
  }
709
770
  queue.inExpress = true;
710
771
  queue.end = index;
711
- queue.text = text.slice(queue.start, index);
772
+ queue.text = text.slice(start, index);
712
773
  pop_parents();
713
774
  continue;
714
775
  }
@@ -746,13 +807,15 @@ class Program {
746
807
  }
747
808
  save(STRAP);
748
809
  var last = queue.last;
749
- if (last.type === STRAP && structstrap_reg.test(last.text) && !queue.classed) {
750
- queue.classed = [last.text];
810
+ m = last.text;
811
+ if (last.type === STRAP && structstrap_reg.test(m) && !queue.classed) {
812
+ queue.classed = [m];
751
813
  }
752
814
  else if (queue.classed) {
753
- if (last.type === STRAP && funcstrap_reg.test(last.text)) queue.classed.push(last.text);
815
+ if (last.type === STRAP && funcstrap_reg.test(m)) queue.classed.push(m);
754
816
  }
755
817
  if (funcstrap_reg.test(m)) {
818
+ last.isExpress = queue.inExpress;
756
819
  last.isargl = true;
757
820
  }
758
821
  else if (type_reg.test(m)) {
@@ -874,7 +937,7 @@ class Program {
874
937
  scope.istype = true;
875
938
  }
876
939
  }
877
- if (!last || (last.type !== STRAP && (!last.isObject || m === '(') || last.transive)) queue.inExpress = true;
940
+ if (!last || last.type !== STRAP && last.isExpress || last.transive) queue.inExpress = true;
878
941
  scope.isExpress = queue.inExpress;
879
942
  scope.inExpress = true;
880
943
  }
@@ -893,7 +956,16 @@ class Program {
893
956
  pop_parents();
894
957
  continue;
895
958
  }
896
- if (this.scope_leave[m]) console.warn(i18n`标记不匹配`, queue.entry, m, "queue-start:", queue.start, "position:", `${row}:${index - colstart}\r\n`, index - queue.start < 200 ? text.slice(queue.start, index) : text.slice(queue.start, queue.start + 100) + "..." + text.slice(index - 97, index));
959
+ if (this.scope_leave[m]) {
960
+ console.warn(
961
+ i18n`标记不匹配:`, queue.entry, m,
962
+ i18n`\r\n文件位置:`, this.mindpath + ":" + `${row}:${index - colstart}`,
963
+ i18n`\r\n摘要:\r\n`,
964
+ index - queue.start < 200
965
+ ? text.slice(queue.start, index)
966
+ : text.slice(queue.start, queue.start + 100) + "..." + text.slice(index - 97, index)
967
+ );
968
+ }
897
969
  save(STAMP);
898
970
  }
899
971
  while (queue.tag && parents.length) {
@@ -912,16 +984,12 @@ class Program {
912
984
  if (cache_stamp) push_stamp();
913
985
  this.lastIndex = index;
914
986
  if (queue !== origin) {
915
- console.log(
916
- "代码异常结束",
917
- createString(origin.slice(0, 30)),
918
- `\r\n ----- deep: ${parents.length}`,
919
- `\r\n ---- enrty: ${queue.entry}`,
920
- `\r\n --- length: ${queue.length}`,
921
- `\r\n ----- last: ${queue.last ? createString([queue.last]).slice(0, 30) : createString(queue).slice(0, 30)}`,
922
- `\r\n -- parents: ${parents.map(p => `${p.row}:${p.col}-${p.tag || p.text || p.entry} `).join('-)> ')}`,
923
- `\r\n ----- snap: ${createString([queue]).slice(-200)}`,
924
- `\r\n ------ end. `
987
+ var last = queue.last || queue;
988
+ console.warn(
989
+ "代码异常结束", createString(origin.slice(0, 30)),
990
+ `\r\n - 祖先标记: ${parents.slice(1).map(p => `<red2>${p.tag || p.text || ""}${p.entry || ""}</red2><gray>${p.row}:${p.col}</gray>`).join('')}`,
991
+ `\r\n - 内层入口: <yellow>${this.mindpath}</yellow>:${last.row}:${last.col} ${last.text || last.entry}`,
992
+ `\r\n ----- 快照: ${createString(pickAssignment(queue.last || queue))}`,
925
993
  );
926
994
  while (queue !== origin) {
927
995
  queue.error = "代码异常结束";
@@ -957,24 +1025,6 @@ class Program {
957
1025
  }
958
1026
  });
959
1027
  quoteslike.forEach(q => {
960
- var ts = [];
961
- var r = q.slice(q[2] ? 2 : 3).concat(q[1]).map(q => {
962
- if (q instanceof Array) {
963
- if (q.length > 2) {
964
- ts.push(...q.slice(0, q.length - 2));
965
- }
966
- else if (q.length !== 2) throw new Error(i18n`配置错误!`);
967
- q = q[q.length - 2];
968
- }
969
- if (q instanceof RegExp) {
970
- return q.source;
971
- }
972
- return this.compile(q);
973
- });
974
- if (q.tag) r = r.concat(q.tag);
975
- r = r.concat(ts.map(this.compile));
976
- r = sortRegster(r).join("|");
977
- q.reg = new RegExp(r, 'g');
978
1028
  q.end = this.createRegExp([q[1]]);
979
1029
  if (q.length >= 4) {
980
1030
  var entry = q.slice(3);
@@ -1019,6 +1069,32 @@ class Program {
1019
1069
  for (var k in this.powermap) if (k.length === 1 && stamps.indexOf(k) < 0) stamps.push(k);
1020
1070
  stamps.push.apply(stamps, powers);
1021
1071
  this.stamp_reg = new RegExp(`^(${stamps.map(this.compile).join('|')})$`);
1072
+ quoteslike.forEach(q => {
1073
+ var ts = [];
1074
+ var r = q.slice(q[2] ? 2 : 3).concat(q[1]).map(q => {
1075
+ if (q instanceof Array) {
1076
+ if (q.length > 2) {
1077
+ ts.push(...q.slice(0, q.length - 2));
1078
+ }
1079
+ else if (q.length !== 2) throw new Error(i18n`配置错误!`);
1080
+ q = q[q.length - 2];
1081
+ }
1082
+ if (q instanceof RegExp) {
1083
+ return q.source;
1084
+ }
1085
+ return this.compile(q);
1086
+ });
1087
+ if (q.tag) r = r.concat(q.tag, powers.filter(p => {
1088
+ var tagentries = q.tag[0];
1089
+ for (var t of tagentries) {
1090
+ if (p.indexOf(t) >= 0) return true;
1091
+ }
1092
+ return false;
1093
+ }).map(this.compile));
1094
+ r = r.concat(ts.map(this.compile));
1095
+ r = sortRegster(trimDulp(r)).join("|");
1096
+ q.reg = new RegExp(r, 'g');
1097
+ })
1022
1098
  }
1023
1099
  }
1024
1100
  module.exports = Program;
@@ -1233,7 +1233,13 @@ var getSemicolonBetween = function (prev, next) {
1233
1233
  if (
1234
1234
  (EXPRESS | VALUE | QUOTED) & prev.type
1235
1235
  || prev.type === STAMP && /^(\+\+|\-\-)$/.test(prev.text)
1236
- || prev.type === SCOPED && (prev.isExpress || prev.isObject)
1236
+ || prev.type === SCOPED && (prev.isExpress || prev.isObject || prev.entry === '(' && (
1237
+ // 这两种分号不存在时efront的解析器可以识别,v8的识别不了,为了兼容追加分号
1238
+ // do{}while(); return
1239
+ // =function(){}(); return
1240
+ prev.perv?.type === STRAP && prev.prev.text === 'while' || prev.prev?.type === SCOPED
1241
+ )
1242
+ )
1237
1243
  ) {
1238
1244
  if ((EXPRESS | VALUE | QUOTED | LABEL) & next.type) return ";";
1239
1245
  if (next.type === STRAP) {
@@ -203,17 +203,62 @@ class Code extends Array {
203
203
 
204
204
  var avoidMap = null;
205
205
  var typeMap = Object.create(null);
206
- function scan() {
207
- var [text, type = "js", lastIndex = 0] = arguments;
208
- if (isFinite(type)) lastIndex = +type, type = arguments[2] || type;
209
- var program = typeMap[type];
206
+ function scan(text) {
207
+ var fullpath, type, lastIndex = 0, program;
208
+ for (var cx = 1, dx = arguments.length; cx < dx; cx++) {
209
+ var a = arguments[cx];
210
+ switch (typeof a) {
211
+ case "number":
212
+ lastIndex = a;
213
+ break;
214
+ case "string":
215
+ if (!fullpath) {
216
+ fullpath = a;
217
+ break;
218
+ }
219
+ else if (!type) {
220
+ type = a;
221
+ break;
222
+ }
223
+ case "object":
224
+ case "function":
225
+ type = a;
226
+ break;
227
+ default:
228
+ throw new Error('无效参数: ' + type);
229
+ }
230
+ }
231
+ if (!type) {
232
+ if (/\.[^\.\/\\]+$/i.test(fullpath)) {
233
+ type = /[^\.\/\\]+$/.exec(fullpath)[0].toLowerCase();
234
+ }
235
+ else {
236
+ type = fullpath || 'js';
237
+ }
238
+ }
210
239
  if (!program) switch (type) {
211
240
  case "html":
212
- program = typeMap[type] = new Html;
241
+ case "xht":
242
+ case "htm":
243
+ case "jsp":
244
+ case "asp":
245
+ case "php":
246
+ case "hta":
247
+ case "vue":
248
+ type = 'html';
249
+ program = typeMap[type];
250
+ if (!program) program = typeMap[type] = new Html;
213
251
  break;
214
252
  case "js":
253
+ case "ts":
254
+ case "jsx":
255
+ case "tsx":
256
+ case "mjs":
257
+ case "cjs":
215
258
  case "javascript":
216
- program = typeMap[type] = new Javascript;
259
+ type = "js";
260
+ program = typeMap[type];
261
+ if (!program) program = typeMap[type] = new Javascript;
217
262
  break;
218
263
  default:
219
264
  if (type instanceof Function) {
@@ -223,12 +268,13 @@ function scan() {
223
268
  program = type;
224
269
  }
225
270
  else {
226
- console.log(i18n`类型不支持`, type)
271
+ throw new Error(i18n`类型不支持: ${console.format(`<red2>${type}</red2>`)}`);
227
272
  }
228
273
  break;
229
274
  }
230
275
  program.Code = Code;
231
276
  program.lastIndex = lastIndex;
277
+ program.mindpath = fullpath;
232
278
  var res = program.exec(text);
233
279
  res.autospace = !program.keepspace;
234
280
  Object.defineProperty(res, "program", { value: program, enumerable: false })
@@ -100,7 +100,7 @@ function translate([imap, supports], code) {
100
100
  return 0;
101
101
  });
102
102
  var getm = function (tt, nodup, warn) {
103
- var mq = /^(\s*)([\s\S]*?)(\s*)$/.exec(tt);
103
+ var mq = /^(\s*)([\s\S]*?)([\:\:]?\s*)$/.exec(tt);
104
104
  var mq = [mq[1] || '', mq[2], mq[3] || ''];
105
105
  var tt = mq[1];
106
106
  var wrap = m => {
@@ -1,4 +1,4 @@
1
- if (this.XMLHttpRequest) return this.XMLHttpRequest;
1
+ if (this.XMLHttpRequest?.prototype && "onreadystatechange" in this.XMLHttpRequest.prototype) return this.XMLHttpRequest;
2
2
  if (this.ActiveXObject) return this.ActiveXObject.bind(null, 'Microsoft.XMLHTTP');
3
3
  if (!this.fetch) return;
4
4
  var window = this;
@@ -17,18 +17,21 @@ XMLHttpRequest.prototype.open = function (method, url) {
17
17
  XMLHttpRequest.prototype.send = function (data) {
18
18
  var params = { method: this.method, headers: { referer: document.location.href.replace(/^#[\s\S]*$/g, '') } };
19
19
  if (data != null) params.body = data;
20
- this.fetch(this.url, params).then(function (d) {
21
- this.fetched = d;
22
- this.readyState = 4;
23
- this.status = d.status;
20
+ var fetched = this.fetch(this.url, params);
21
+ var xhr = this;
22
+ fetched.then(function (d) {
23
+ xhr.fetched = d;
24
+ xhr.readyState = 4;
25
+ xhr.status = d.status;
24
26
  return d.text();
25
27
  }).then(function (d) {
26
- this.responseText = d;
27
- if (this.onreadystatechange) this.onreadystatechange({ target: this });
28
- if (this.onload) this.onload({ target: this });
29
- }, function (e) {
30
- this.readyState = 4;
31
- if (this.onreadystatechange) this.onreadystatechange({ target: this });
32
- if (this.onerror) this.onerror({ target: this });
28
+ xhr.responseText = d;
29
+ if (xhr.onreadystatechange) xhr.onreadystatechange({ target: xhr });
30
+ if (xhr.onload) xhr.onload({ target: xhr });
31
+ }).catch(function (e) {
32
+ xhr.readyState = 4;
33
+ if (xhr.onreadystatechange) xhr.onreadystatechange({ target: xhr });
34
+ if (xhr.onerror) xhr.onerror({ target: xhr });
33
35
  });
34
- }
36
+ }
37
+ return XMLHttpRequest;
@@ -20,7 +20,7 @@
20
20
  <mask></mask>
21
21
  <model -if="!isEmpty(f.key)" :field=f :data=d readonly></model>
22
22
  <template -else>&nbsp;</template>
23
- <a on-click="o.do(d)" -if="isEmpty(f.key)&&f.options&&(!o.when||o.when(d))"
23
+ <a on-click="o.do(d,event)" -if="isEmpty(f.key)&&f.options&&(!o.when||o.when(d))"
24
24
  _type="o.type instanceof Function?o.type(d):o.type" -repeat="o in f.options">
25
25
  <span -text="o.name instanceof Function?o.name(d):o.name"></span>
26
26
  </a>
@@ -136,9 +136,6 @@ function go(pagepath, args, history_name, oldpagepath) {
136
136
  if (realpath.length > 1) var [pgpath, args0] = realpath;
137
137
  else pgpath = pagepath;
138
138
  setZimoliParams(pagepath, { data: args, from: oldpagepath, options, roles, id });
139
- prepare(pgpath, function (res) {
140
- if (!res.roles || res.roles === true) res.roles = !!roles;
141
- });
142
139
  if (!page_generators[pgpath]) {
143
140
  return zimoli(pagepath, args, history_name, oldpagepath);
144
141
  }
@@ -349,36 +346,27 @@ function prepare(pgpath, ok) {
349
346
  }
350
347
  };
351
348
  var emit = function (pg) {
352
- if (pg) {
353
- page_generators[pgpath] = {
354
- pg,
355
- roles,
356
- state,
357
- with: _with_elements,
358
- onback: _pageback_listener,
359
- prepares
360
- };
361
- }
349
+ page_generators[pgpath] = {
350
+ pg,
351
+ roles,
352
+ state,
353
+ with: _with_elements,
354
+ onback: _pageback_listener,
355
+ prepares
356
+ };
362
357
  var res = page_generators[pgpath];
363
358
  var emiters = loading_tree[pgpath];
364
359
  delete loading_tree[pgpath];
365
- if (emiters) {
366
- var noRoles = !res.roles;
367
- if (noRoles && res.roles) {
368
- prepare(user.loginPath, () => emit());
369
- return;
370
- }
371
- while (emiters.length) {
372
- var ok = emiters.shift();
373
- if (isFunction(ok)) {
374
- ok(res);
375
- }
360
+ if (emiters) while (emiters.length) {
361
+ var ok = emiters.shift();
362
+ if (isFunction(ok)) {
363
+ ok(res);
376
364
  }
377
365
  }
366
+
378
367
  };
379
368
  return init(pgpath, function (pg) {
380
- if (!pg) return;
381
- extendIfNeeded(pg, state);
369
+ if (pg) extendIfNeeded(pg, state);
382
370
  if (roles) return prepare(user.loginPath, () => emit(pg));
383
371
  emit(pg);
384
372
  }, state, true);
@@ -402,6 +390,7 @@ function create(pagepath, args, from, needroles) {
402
390
  }
403
391
  return alert(i18n`没有权限!`, 0);
404
392
  }
393
+ if (!pg) return;
405
394
  var _with_length = _with_elements.length;
406
395
  state.onback = function (handler) {
407
396
  _pageback_listener = handler;
@@ -442,7 +431,7 @@ function create(pagepath, args, from, needroles) {
442
431
  var zimoliid = 0, zimoliad = 0;
443
432
  function zimoli(pagepath, args, history_name, oldpagepath) {
444
433
  if (arguments.length === 0) {
445
- if (zimoliid !== zimoliad) return;
434
+ if (zimoliid !== zimoliad && zimoli.caller === go) return;
446
435
  history_name = current_history;
447
436
  var _history = history[history_name] || [];
448
437
  root_path = _history[0] || "/main";
@@ -616,6 +616,7 @@
616
616
  已找到的字符串.is_loading = true;
617
617
  var addTranslate = function (translate) {
618
618
  if (!isHandled(translate)) return;
619
+ translate = translate.replace(/^\s*([\s\S]*?)([:\:]?\s*)$/, '$1');
619
620
  var tmap = textMap[translate];
620
621
  if (!tmap) tmap = textMap[translate] = Object.create(null), tmap["#count"] = 0;
621
622
  if (!tmap[e.path]) tmap[e.path] = [];
@@ -646,6 +647,9 @@
646
647
  var data = await readText(e);
647
648
  data = parseYML(data);
648
649
  loop: for (var d of data) {
650
+ for (var k in d) {
651
+ d[k] = d[k].replace(/^\s*([\s\S]*?)([:\:]?\s*)$/, '$1');
652
+ }
649
653
  var liang = 0, fanyi = {};
650
654
  for (var { lang: k, id } of supports) {
651
655
  if (!d[k]) continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "4.21.2",
3
+ "version": "4.21.4",
4
4
  "description": "一个开发环境,提供一种自由的前端开发模式,也可作为辅助工具使用。",
5
5
  "main": "public/efront.js",
6
6
  "directories": {