efront 4.31.1 → 4.32.1

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.
@@ -254,7 +254,7 @@ var hasOwnProperty = {}.hasOwnProperty;
254
254
  "use ./#decrypt.js";
255
255
  var loadModule = function (url, then, prebuilds = {}) {
256
256
  var name = url.replace(/[\*~][\s\S]*$/, '');
257
- if (/^(?:module|exports|define|import_meta|require|window|global|undefined)$/.test(name)) return then();
257
+ if (/^(?:module|exports|define|\\import|require|window|global|undefined)$/.test(name)) return then();
258
258
  if ((hasOwnProperty.call(prebuilds, url)) || hasOwnProperty.call(modules, url) || (!hasOwnProperty.call(forceRequest, name) && !/^on/.test(name) && window[name] !== null && window[name] !== void 0)
259
259
  ) return then();
260
260
  preLoad(url);
@@ -310,7 +310,7 @@ var loadModule = function (url, then, prebuilds = {}) {
310
310
  mod.args = args;
311
311
  mod.argNames = argNames;
312
312
  mod.strs = strs;
313
- var loadingCount = 0;
313
+ var loadedCount = 0;
314
314
  if (required) {
315
315
  required = required.split(';').filter(a => !!a);
316
316
  if (afterfix) required = required.map(r => r + afterfix);
@@ -321,13 +321,13 @@ var loadModule = function (url, then, prebuilds = {}) {
321
321
  args = args.concat(required);
322
322
  var _errored = [];
323
323
  var response = function (error) {
324
- loadingCount++;
324
+ loadedCount++;
325
325
  if (error) {
326
326
  if (!errored[error]) errored[error] = [];
327
327
  errored[error].push(key);
328
328
  if (_errored.indexOf(error) < 0) _errored.push(error);
329
329
  }
330
- if (loadingCount === args.length) {
330
+ if (loadedCount === args.length) {
331
331
  if (_errored.length) loadedModules[key].error = _errored;
332
332
  flushTree(loadedModules, key, mod);
333
333
  }
@@ -338,6 +338,13 @@ var loadModule = function (url, then, prebuilds = {}) {
338
338
  loadedModules[key].args = mod.args;
339
339
  loadedModules[key].mod = mod;
340
340
  for (var moduleName of args) {
341
+ if (moduleName === url) {
342
+ // <!--
343
+ // console.log(`检查到自我引用的代码 %c>> ${url} <<%c `, "color:#c46", 'color:');
344
+ // -->
345
+ response();
346
+ continue;
347
+ }
341
348
  loadModule(moduleName, response, prebuilds);
342
349
  }
343
350
  }
@@ -432,17 +439,21 @@ function resolve(r1, base, prefix = '') {
432
439
  return r2;
433
440
 
434
441
  }
435
- function Meta(url) {
436
- this.url = url;
442
+
443
+ function Meta(url, fix) {
444
+ this.path = url;
445
+ this.url = url + fix;
437
446
  }
438
447
  Meta.prototype.resolve = function (url) {
439
- return resolve(url, this.url);
448
+ return resolve(url, this.path);
440
449
  }
441
-
442
- var createModule = function (exec, originNames, compiledNames, prebuilds = {}) {
450
+ function Exports() { }
451
+ var createModule = function (exec, originNames, compiledNames, prebuilds = {}, argfix) {
452
+ if (argfix in exec) return exec[argfix];
443
453
  var module = {};
444
- var exports = module.exports = {};
445
- var isModuleInit = false;
454
+ var exports = module.exports = exec[argfix] || new Exports;
455
+ var isModuleInit = originNames.indexOf('module') >= 0 || originNames.indexOf("exports") >= 0;
456
+ if (isModuleInit) if (argfix != null) exec[argfix] = exports;
446
457
  var required = exec.required;
447
458
  if (required) required = required.map(a => loadedModules[keyprefix + a]);
448
459
  var argsList = originNames.map(function (aName) {
@@ -451,24 +462,27 @@ var createModule = function (exec, originNames, compiledNames, prebuilds = {}) {
451
462
  return prebuilds[argName];
452
463
  }
453
464
  if (argName === "module") {
454
- isModuleInit = true;
455
465
  return module;
456
466
  }
457
467
  if (argName === "exports") {
458
- isModuleInit = true;
459
468
  return exports;
460
469
  }
461
- if (argName === 'import_meta') {
462
- return new Meta(exec.file);
470
+ if (argName === exec.file) {
471
+ return isModuleInit ? exports : exec;
472
+ }
473
+ if (argName === '\\import') {
474
+ return new Meta(exec.file, argfix);
463
475
  }
464
476
  if (/^(?:window|global(This)?|undefined)$/.test(argName)) return window[argName];
465
477
  if (argName === "require") {
466
478
  var r1 = window.require;
467
- let r = function (refer) {
479
+ let r = function (refer, argfix) {
468
480
  if (refer.length) return r1(refer);
469
481
  var mod = required[refer];
470
- if ("created" in mod) return mod.created;
471
- var c = mod.created = createModule(mod, mod.args || [], mod.argNames, prebuilds);
482
+ argfix = argfix || '';
483
+ if (argfix in mod) return mod[argfix];
484
+ if (mod === exec) return exports;
485
+ var c = mod[argfix] = createModule(mod, mod.args || [], mod.argNames, prebuilds, argfix);
472
486
  return c;
473
487
  };
474
488
  for (let k in r1) r[k] = r1[k];
@@ -514,7 +528,7 @@ var createModule = function (exec, originNames, compiledNames, prebuilds = {}) {
514
528
  if (!argsPromises.length) {
515
529
  return exec.apply(_this, argsList);
516
530
  }
517
- return Promise.all(argsList).then(function (args) {
531
+ else return Promise.all(argsList).then(function (args) {
518
532
  return exec.apply(_this, args);
519
533
  });
520
534
  };
@@ -630,13 +644,13 @@ var init = function (url, then, prebuilds, keeppage) {
630
644
 
631
645
  if (!args || !args.length) {
632
646
  var created = module.call(window);
633
- then(module.created = modules[url] = created);
647
+ then(modules[url] = module[''] = created);
634
648
  return;
635
649
  }
636
650
  var filteredArgs = prebuilds ? args.filter(a => !hasOwnProperty.call(prebuilds, a)) : args;
637
651
 
638
- var saveAsModule = keeppage || filteredArgs.length === args.length;
639
- if (saveAsModule) {
652
+ keeppage = keeppage || filteredArgs.length === args.length;
653
+ if (keeppage) {
640
654
  if (penddings[key]) {
641
655
  penddings[key].then(then);
642
656
  return;
@@ -652,18 +666,18 @@ var init = function (url, then, prebuilds, keeppage) {
652
666
  then(created);
653
667
  return;
654
668
  }
655
- var created = createModule(module, args, module.argNames, prebuilds);
669
+ var created = createModule(module, args, module.argNames, prebuilds, keeppage ? '' : null);
656
670
  if (isThenable(created)) {
657
- if (saveAsModule) {
671
+ if (keeppage) {
658
672
  penddings[key] = created;
659
673
  created.then(function (res) {
660
674
  delete penddings[key];
661
- then(modules[url] = res);
675
+ then(modules[url] = module[""] = res);
662
676
  });
663
677
  return;
664
678
  }
665
679
  } else {
666
- if (saveAsModule) module.created = modules[url] = created;
680
+ if (keeppage) module[''] = modules[url] = created;
667
681
  }
668
682
  then(created);
669
683
  }, prebuilds);
@@ -0,0 +1 @@
1
+ basic$extendIfNeeded;
@@ -857,8 +857,9 @@ var wrapRequire = function (n, i, code) {
857
857
  used.require.push(q[0]);
858
858
  var cs = code.splice(ni, nsi - ni, ...q);
859
859
  q[1].push.apply(q[1], cs);
860
- relink(q[1]);
861
- setqueue(q[1]);
860
+ cs = q[1];
861
+ relink(cs);
862
+ setqueue(cs);
862
863
  return q;
863
864
  };
864
865
 
@@ -888,10 +889,20 @@ Javascript.prototype.fix = function (code) {
888
889
  }, this);
889
890
  if (code.exportStars) {
890
891
  var exportStars = code.exportStars;
891
- if (!code.exportDefault) code.push(...scan(`\r\nexports.default=undefined`));
892
+ if (code.last.type !== STAMP || code.last.text !== ";") code.push({ text: ",", type: STAMP });
893
+ if (!code.exportDefault) code.push(...scan(`\r\nexports.default=undefined;`));
894
+ var extused = [];
892
895
  exportStars.forEach(u => {
893
- code.push(...scan(`\r\nextendIfNeeded(exports,${u.text})`));
896
+ var a = scan(`\r\n&extendIfNeeded(exports,${u.text});`)
897
+ extused.push(a[1]);
898
+ code.push(a[0], a[1], a[2], a[3]);
899
+ code.used[u.text].push(a[2][2]);
900
+ code.used.exports.push(a[2][0]);
894
901
  });
902
+ if (extused.length) {
903
+ code.used["&extendIfNeeded"] = extused;
904
+ code.envs["&extendIfNeeded"] = true;
905
+ }
895
906
  delete code.exportStars;
896
907
  delete code.exportDefault;
897
908
  }
@@ -915,7 +926,7 @@ Javascript.prototype.fix = function (code) {
915
926
  remove(m.next, s);
916
927
  }
917
928
  if (/^import\.meta($|\.)/.test(m.text)) {
918
- m.text = m.text.replace(/\./, '_');
929
+ m.text = m.text.replace(/^import\.meta/, '\\import');
919
930
  return true;
920
931
  }
921
932
  m.text = m.text.replace(/^import/g, 'require');
@@ -923,7 +934,7 @@ Javascript.prototype.fix = function (code) {
923
934
  });
924
935
  delete code.used.import;
925
936
  delete code.envs.import;
926
- if (imports.length) code.used["import_meta"] = imports, code.envs["import_meta"] = true;
937
+ if (imports.length) code.used["\\import"] = imports, code.envs["\\import"] = true;
927
938
  }
928
939
  if (code.exportDecs) {
929
940
  var exportDecs = code.exportDecs;
@@ -8,7 +8,7 @@ var testFix = function (a, e) {
8
8
  js.debug = true;
9
9
  assert(scanner2("/a/g", js)[0].type, common.QUOTED);
10
10
  testFix(`export default function a(){} a.a=1`, `exports.default = function a() {} exports.default.a = 1`);
11
- testFix(`export * from "a";`, 'var a = require("a");\r\nexports.default = undefined\r\nextendIfNeeded(exports, a)');
11
+ testFix(`export * from "a";`, 'var a = require("a");\r\nexports.default = undefined;\r\n&extendIfNeeded(exports, a);');
12
12
  testFix(`export {A} from "a";`, 'var a = require("a")\r\nexports.A = a.A;');
13
13
  testFix(`import a from "a";console.log(a)`, 'var a = require("a"); console.log(a.default)');
14
14
  testFix(`import {a} from "a";console.log(a)`, 'var a1 = require("a"); console.log(a1.a)');
@@ -20,7 +20,7 @@ testFix(`import("a")`, 'require("a")');
20
20
  testFix(`import "windows.inc"`, 'require("windows.inc")');
21
21
  testFix(`import "windows.inc";import "abc.inc";`, 'require("windows.inc"); require("abc.inc");');
22
22
  testFix(`import "windows.inc";\r\nimport "abc.inc";`, 'require("windows.inc");\r\nrequire("abc.inc");');
23
- testFix(`console.log(import.meta)`, `console.log(import_meta)`);
23
+ testFix(`console.log(import.meta)`, `console.log(\\import)`);
24
24
  testFix(`export async function a(){}`, 'exports.a = async function a() {}');
25
25
  testFix(`export async function *a(){}`, 'exports.a = async function *a() {}');
26
26
  testFix(`export function *a(){}`, 'exports.a = function *a() {}');
@@ -15,7 +15,7 @@ function Node(o) {
15
15
  });
16
16
  t[types[o.type]] = o.text;
17
17
  }
18
- else Object.assign(t, o);
18
+ Object.assign(t, o);
19
19
  return t;
20
20
  }
21
21
  var node_props = [
@@ -41,16 +41,25 @@ defineProperty(Node, 'debug', {
41
41
  node_props.forEach(debug ? def : del, Node.prototype);
42
42
  }
43
43
  });
44
+
44
45
  var def = function (k) {
45
46
  var k1 = Symbol(k);
47
+ var set = function (v) {
48
+ defineProperty(this, k1, { configurable: true, writable: true, enumerable: false, value: v });
49
+ };
46
50
  defineProperty(this, k, {
47
51
  configurable: true, enumerable: false,
48
52
  get() {
49
53
  return this[k1];
50
54
  },
51
- set(v) {
52
- defineProperty(this, k1, { configurable: true, writable: true, enumerable: false, value: v })
53
- }
55
+ set: k === 'type' ? function (v) {
56
+ delete this[types[this[k1]]];
57
+ set.call(this, v);
58
+ this[types[v]] = this.text;
59
+ } : k === 'text' ? function (v) {
60
+ set.call(this, v);
61
+ this[types[this.type]] = v;
62
+ } : set,
54
63
  });
55
64
  };
56
65
  var del = function (k) {
@@ -1,10 +1,11 @@
1
1
  var { VALUE, QUOTED, EXPRESS, STRAP, relink } = require("./common");
2
2
  var Node = require("./Node");
3
+ var cloneChild = o => cloneNode(o);
3
4
  var cloneNode = function (o, keep) {
4
5
  var c = o;
5
6
  if (c instanceof Array && !c.text) {
6
7
  if (keep) return c;
7
- c = c.map(cloneNode);
8
+ c = c.map(cloneChild);
8
9
  c.entry = o.entry;
9
10
  c.leave = o.leave;
10
11
  c.type = o.type;
@@ -710,6 +710,11 @@ var createScoped = function (parsed, wash) {
710
710
  o = getnext(o);
711
711
  o.isExpress = p?.isExpress;
712
712
  }
713
+ if (n.isprop) {
714
+ var nn = n.next;
715
+ if (nn.type === STAMP && /^[\:\=]$/.test(nn.text)) break;
716
+ }
717
+
713
718
  case "catch":
714
719
  if (s === 'catch') isCatch = true;
715
720
  case "class":
@@ -788,7 +793,6 @@ var createScoped = function (parsed, wash) {
788
793
  vars = Object.create(null);
789
794
  scoped = [];
790
795
  var isExpress = o.isExpress;
791
-
792
796
  if (isFunction || isArraw) {
793
797
  scoped.used = used;
794
798
  scoped.vars = vars;
@@ -44,3 +44,9 @@ assert(common.createString(common.pickArgument(scanner2(`a={a:1,c:d}`)[2][4])),
44
44
  assert(common.createString(common.pickArgument(scanner2(`a=class{a=1\r\nc=d}`)[3][4])), 'c = d')
45
45
  assert(common.createString(common.pickArgument(scanner2(`(a=1,c=d)`)[0][4])), 'c = d')
46
46
  assert(scanner2(`for (let len of codeLengths) if (len) count[len]++;`).envs, { len: undefined })
47
+ function testCreateScope(code) {
48
+ code = scanner2(code);
49
+ common.createScoped(code);
50
+ }
51
+
52
+ testCreateScope(`class a{ static barch = new arch('b')}`)
@@ -1,6 +1,6 @@
1
1
  function till(n) {
2
- if (/^[&\^%\?@#]/.test(n)) {
3
- var s = n = n.replace(/[&\^%\?@#]/g, '_');
2
+ if (/^[&\^%\?@#\\]/.test(n)) {
3
+ var s = n = n.replace(/[&\^%\?@#\\]/g, '_');
4
4
  var i = 0;
5
5
  while (n in this) {
6
6
  n = s + i++;
@@ -226,7 +226,7 @@ var _switch = function (body, cx, unblock, result, getname) {
226
226
  q = tmp.shift();
227
227
  block = tmp.shift();
228
228
  if (default_r === q) cy = default_r.index;
229
- q.push({ type: VALUE, text: String(result.length - cy) }, { type: STAMP, text: "," }, { type: VALUE, text: '0' });
229
+ q.push({ type: VALUE, isdigit: true, text: String(result.length - cy) }, { type: STAMP, text: "," }, { type: VALUE, isdigit: true, text: '0' });
230
230
  relink(q);
231
231
  unblock(block);
232
232
  ifpatch(result);
@@ -305,13 +305,29 @@ var getCondition = function (o, unblock, not_) {
305
305
  if (not_) not = !not;
306
306
  if (f && f === o.last) {
307
307
  if (f.type & (EXPRESS | VALUE)) {
308
- n = cloneNode(f);
308
+ n = f;
309
309
  }
310
310
  if (not && n) {
311
311
  if (f.type === VALUE) {
312
- n = String(eval("!" + f.text));
312
+ if (f.isdigit) {
313
+ n = cloneNode(String(eval("!" + f.text)));
314
+ }
315
+ else switch (f.text) {
316
+ case "true":
317
+ case "Infinity":
318
+ case "-Infinity":
319
+ n = cloneNode("false");
320
+ break;
321
+ case "NaN":
322
+ case "null":
323
+ case "undefined":
324
+ n = cloneNode("true");
325
+ break;
326
+ default:
327
+ n = rescan.keep`!${f}`;
328
+ }
313
329
  }
314
- else n = rescan`!${n}`;
330
+ else n = rescan.keep`!${n}`;
315
331
  }
316
332
  }
317
333
  if (!n) {
@@ -323,9 +339,9 @@ var getCondition = function (o, unblock, not_) {
323
339
  n = ret_;
324
340
  }
325
341
  else n = n.name;
326
- if (not) n = rescan`!${n}`;
342
+ if (not) n = rescan.keep`!${n}`;
327
343
  }
328
- return cloneNode(n);
344
+ return n;
329
345
  }
330
346
  var _while = function (body, cx, unblock, result) {
331
347
  var o = body[cx];
@@ -1175,7 +1191,7 @@ var poplabel = function (result) {
1175
1191
  if (r.indexOf(b) >= 0) { break }
1176
1192
  }
1177
1193
  if (cx < 0) throw console.log(result.map(r => createString(r)), e.text, createString([b.prev, b])), i18n`break语句异常`;
1178
- end.push({ type: VALUE, text: b.continue ? b.continue.contat - cx : result.length - cx }, { type: STAMP, text: "," }, { type: VALUE, text: "0" });
1194
+ end.push({ type: VALUE, isdigit: true, text: String(b.continue ? b.continue.contat - cx : result.length - cx) }, { type: STAMP, text: "," }, { type: VALUE, isdigit: true, text: "0" });
1179
1195
  relink(end);
1180
1196
  }
1181
1197
  }
@@ -12,6 +12,9 @@ function test(codetext, expect, ret = false) {
12
12
  test('var o = loaded[f.name] = f.isFile() ? new File(p, rebuild, limit) : new Directory(p, rebuild, limit)', "_ = f.name; _0 = f.isFile(); if (!_0) return [1, 0]; _0 = new File(p, rebuild, limit); loaded[_] = _0; o = _0; return [2, 0];\r\n _0 = new Directory(p, rebuild, limit); loaded[_] = _0; o = _0; return [1, 0]");
13
13
  test('a+b', "a + b");
14
14
  test('var a = b', "a = b");
15
+ test('if(this){}',`if (!this) return [1, 0]; return [1, 0]`);
16
+ test('if(!this){}',`if (this) return [1, 0]; return [1, 0]`);
17
+ test('if(arguments){}',`if (!arguments) return [1, 0]; return [1, 0]`);
15
18
  test('a | c & b', "_ = c & b, a | _");
16
19
  test('a + !c', "_ = !c, a + _");
17
20
  test('a + b * c', "_ = b * c, a + _");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efront",
3
- "version": "4.31.1",
3
+ "version": "4.32.1",
4
4
  "description": "一个开发环境,提供一种自由的前端开发模式,也可作为辅助工具使用。",
5
5
  "main": "public/efront.js",
6
6
  "directories": {