efront 4.34.1 → 4.35.0

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.
Files changed (65) hide show
  1. package/coms/basic/Matrix.js +3 -1
  2. package/coms/basic/color.js +258 -78
  3. package/coms/basic/color_test.js +23 -2
  4. package/coms/basic/crc.js +6 -2
  5. package/coms/basic/data.js +3 -3
  6. package/coms/basic/decodeASN1.js +2 -2
  7. package/coms/basic/math.js +321 -0
  8. package/coms/basic/math.md +265 -0
  9. package/coms/basic/math_test.xht +56 -0
  10. package/coms/basic/pinyin.js +40 -0
  11. package/coms/basic/pinyin_test.js +40 -0
  12. package/coms/basic/wait.js +1 -1
  13. package/coms/basic_/JSON.js +24 -4
  14. package/coms/compile/Html.js +1 -0
  15. package/coms/compile/Javascript.js +14 -0
  16. package/coms/compile/Javascript_test.js +4 -3
  17. package/coms/compile/Program.js +82 -45
  18. package/coms/compile/autoenum.js +498 -138
  19. package/coms/compile/autoenum_test.js +70 -4
  20. package/coms/compile/autoeval.js +616 -18
  21. package/coms/compile/autoeval_test.js +55 -2
  22. package/coms/compile/common.js +27 -15
  23. package/coms/compile/common_test.js +12 -2
  24. package/coms/compile/downLevel.js +60 -7
  25. package/coms/compile/downLevel_test.js +22 -8
  26. package/coms/compile/powermap.js +2 -2
  27. package/coms/compile/rescan.js +2 -2
  28. package/coms/compile/scanner2.js +25 -1
  29. package/coms/compile/translate.js +18 -7
  30. package/coms/compile/unstruct.js +44 -2
  31. package/coms/compile/unstruct_test.js +14 -9
  32. package/coms/compile//347/256/227/345/274/217.js +276 -0
  33. package/coms/compile//347/256/227/345/274/217_test.js +26 -0
  34. package/coms/compile//347/264/240/351/246/250.js +60 -23
  35. package/coms/compile//347/264/240/351/246/250_test.js +8 -3
  36. package/coms/docs/markdown.js +4 -0
  37. package/coms/frame/ChatRTC.js +60 -18
  38. package/coms/frame/chat-rtc.xht +20 -18
  39. package/coms/frame/chat.js +38 -21
  40. package/coms/frame/chat.less +8 -3
  41. package/coms/reptile/colors.js +1 -0
  42. package/coms/zimoli/prompt.js +12 -2
  43. package/coms/zimoli/render.js +0 -1
  44. package/coms//350/214/250/350/217/260//344/270/212/350/211/262.xht +4 -0
  45. package/coms//350/214/250/350/217/260//346/240/207/347/255/276/345/214/226.js +14 -4
  46. package/package.json +24 -24
  47. package/public/efront.js +1 -2
  48. package/public//346/226/207/344/273/266/347/263/273/347/273/237//344/270/273/351/241/265.jsp +2 -2
  49. package/tools/build-efront +22 -0
  50. package/tools/build-efront.bat +22 -0
  51. package/tools/build-efront.js +64 -0
  52. package/tools/build-setup.bat +9 -0
  53. package/tools/buildEmoji.js +17 -0
  54. package/tools/electron.js +37 -0
  55. package/tools/empty.js +11 -0
  56. package/tools/fixBuffer.js +41 -0
  57. package/tools/install-all.js +46 -0
  58. package/tools/makeUseStrict.js +35 -0
  59. package/tools/readHelpersFromTypescript.js +82 -0
  60. package/tools/reload.js +20 -0
  61. package/tools/run-efront.bat +14 -0
  62. package/tools/toCRLF.js +30 -0
  63. package/tools/unwrap-typescript.js +28 -0
  64. package/tools/update-libs.bat +86 -0
  65. package/tools/write-utf8.js +39 -0
@@ -9,8 +9,33 @@ var t = function (str, want) {
9
9
  var result = createString(code);
10
10
  assert(result, want);
11
11
  };
12
+
13
+ var tc = function (str, want) {
14
+ var parseColor = color.parse4;
15
+ var toRGBA = color.stringify;
16
+ var macros = Object.create(null);
17
+ var color4 = function (name, a) {
18
+ if (a.length === 1) a = a[0].split(/[\s\,]+/);
19
+ var c = parseColor(name, ...a);
20
+ if (!c) return a;
21
+ return toRGBA(c);
22
+ };
23
+ macros.calc = a => a;
24
+ ["oklch", 'oklab', 'lch', 'lab', 'hwb', 'hsl', 'rgb'].forEach(n => {
25
+ macros[n] = function (from) {
26
+ console.log(n, arguments)
27
+ return color4(n, arguments);
28
+ }
29
+ });
30
+ var css = new Javascript;
31
+ css.number_reg = 素馨.number_reg;
32
+ var code = scanner2(str, css);
33
+ code = autoeval(code, macros);
34
+ var result = createString(code);
35
+ assert(result, want);
36
+ }
12
37
  var tf = function (fullpath) {
13
- var data = fs.readFileSync(fullpath).toString()
38
+ var data = require("fs").readFileSync(fullpath).toString()
14
39
  t(data, data);
15
40
  }
16
41
  t("1+1", "2");
@@ -26,7 +51,35 @@ t("(1+3,5,3+4)", "(4, 5, 7)");
26
51
  t("(1>>3,5,3+4)", "(0, 5, 7)");
27
52
  t("a=1,b=2;(a|b)&c", "a = 1, b = 2; 3 & c");
28
53
  t("(1+2).toString()", "3 .toString()");
29
- t("(1n+2n).toString()", "3n .toString()");
54
+ t("(1n+2n).toString()", "3n.toString()");
55
+ t("Math.log2(2)", "1");
56
+ t("Math.log2(4)>Math.E", "false");
57
+ t("[1,2,3,4][2]", "3");
58
+ t("var log2=Math.log2;console.log(log2(4))", "var log2 = Math.log2; console.log(2)");
59
+ t("var {log2}=Math; console.log(log2(4))", "var { log2 } = Math; console.log(2)");
30
60
  t("(-1).toString()", "(-1).toString()");
31
61
  t("(-(2n*324n)).toString()", "(-648n).toString()");
62
+ t("a+ 2*3", "a + 6");
63
+ t("a+ 2*3**2", "a + 18");
64
+ t("a+ b*3**2", "a + b * 9");
65
+ t("a+ 2*3**b", "a + 2 * 3 ** b");
66
+ t("a+ 2*3 +c", "a + 6 + c");
67
+ t("a+ 2*3 +4+c", "a + 10 + c");
68
+ autoeval.debug = true;
69
+ t("a- 2*3 +4+c", "a - 2 + c");
70
+ t("a- 1 +4", "a + 3");
71
+ t("a / 6 * 3", "a * 0.5");
72
+ t("a * 6 / 3", "a * 2");
73
+ t("a >>> 1 << 1", "a >>> 1 << 1");
74
+ t("a >> 1 << 1", "a >> 1 << 1");
75
+ t("a << 1 >>> 1", "a << 1 >>> 1");
76
+ t("a = 1 >>> 1", "a = 0");
77
+ t("a+ b*Math.sqrt(3**2)", "a + b * 3");
78
+ t("Math.sqrt", "Math.sqrt");
79
+ t("rgb(0xff 0xff 0xff)", "rgb(255 255 255)");
80
+ tc("rgb(0xff 0xff 0xff)", "#fff");
81
+ tc("hwb(120 0 0)", "#0f0");
82
+ tc("hwb(120turn 0 0)", "#f00");
83
+ tc("calc(10 / 20)", "0.5");
84
+ tc("calc(10 / 20)", "0.5");
32
85
  // tf(path.join(__dirname, "../zimoli/spacechar_test.js"))
@@ -13,8 +13,8 @@ import {
13
13
  /*1024 */PROPERTY,
14
14
  /*2048 */ELEMENT,
15
15
  } from "./const.mjs";
16
- // --------------//1//2/////////////////////////22/////////////2//2//3//4/////4////////3/////3//////3//3//////3///////211/////////////2//////2//////1///
17
- var number_reg = /^(?:(?:0x[0-9a-f]+|0b[01]+|0o?[0-7]+)(?:_[0-9a-f]+)*|(?:(?:(?:\d+_)*\d+|\d*)\.\d+(?:_\d+)*|(?:\d+_)*\d+\.?))(?:e[\+\-]?\d+(?:_\d+)*|[hijklmnu]+)?/i;
16
+ // --------------//1//2//////////////////////////////////////////////////22////////////2//2//3//4//////4////////3/////3//////3//3//////3///////211/////////////2//////2/////////////1//
17
+ var number_reg = /^(?:(?:0x[0-9a-f]+|\d[0-9a-f]*h|0b[01]+|0o[0-7]+)(?:_[0-9a-f]+)*|(?:(?:(?:\d+_)*\d+|\d*)\.\d+(?:_\d+)*|(?:\d+_)*\d+\.?))(?:e[\+\-]?\d+(?:_\d+)*)?(?:[ijklmnufl]+)?/i;
18
18
  var equal_reg = /^(?:[\+\-\*\/~\^&\|%]|\*\*|>>>?|<<)?\=$|^(?:\+\+|\-\-)$/;
19
19
  var needhead_reg = /^\?|^\.(?:[^\.]|$)|^\[/;
20
20
  var needfoot_reg = /(\:\:|\.)$/;
@@ -173,16 +173,17 @@ var skipAssignment = function (o, cx) {
173
173
  else condition = true;
174
174
  }
175
175
  else if (o.text === 'do') {
176
- skipLabel();
177
- next();
178
- next();
179
176
  next();
177
+ skipLabel();
178
+ next();// {}
179
+ next();// while
180
+ next();// ()
180
181
  }
181
182
  else if (o.text === 'for') {
182
183
  next();
183
184
  if (o.type === STRAP && o.text === 'await') next();
185
+ next();// ()
184
186
  skipLabel();
185
- next();
186
187
  }
187
188
  else if (o.text === "class") {
188
189
  next();
@@ -239,9 +240,15 @@ function skipFunction(o) {
239
240
  }
240
241
  return o;
241
242
  }
243
+ var snapLabel = function (o) {
244
+ var p = getprev(o);
245
+ while (p && p.type === LABEL) o = p, p = getprev(o);
246
+ return o;
247
+ }
242
248
  var getDoBeforeWhile = function (while_) {
243
249
  var p = getprev(while_);
244
250
  if (!p || p.type !== SCOPED || p.entry !== '{') return;
251
+ p = snapLabel(p);
245
252
  p = getprev(p);
246
253
  if (p.type === STRAP && p.text === "do") return p;
247
254
  };
@@ -251,7 +258,7 @@ var getIfElseHead = function (if_) {
251
258
  if_ = p;
252
259
  p = getprev(if_);
253
260
  if (!p || p.type !== STRAP || p.text !== 'else') {
254
- return if_;
261
+ return snapLabel(if_);
255
262
  }
256
263
  while (p && (p.type !== STRAP || p.text !== 'if')) p = getprev(p);
257
264
  } while (p);
@@ -262,20 +269,20 @@ var getContitionHeadBeforeScoped = function (p, nodo) {
262
269
  if (pp.text === 'await') {
263
270
  pp = getprev(pp);
264
271
  if (pp?.type === STRAP && pp.text === "for") {
265
- return pp;
272
+ return snapLabel(pp);
266
273
  };
267
274
  }
268
275
  else switch (pp.text) {
269
276
  case "with":
270
277
  case "for":
271
- return pp;
278
+ return snapLabel(pp);
272
279
  case "while":
273
280
  p = getDoBeforeWhile(pp);
274
281
  if (p) {
275
282
  if (nodo) return;
276
- return p;
283
+ return snapLabel(p);
277
284
  }
278
- return pp;
285
+ return snapLabel(pp);
279
286
  case "if":
280
287
  return getIfElseHead(pp);
281
288
  }
@@ -303,6 +310,10 @@ function snapAssignmentHead(o) {
303
310
  // 只检查一级
304
311
  while (o && getprev(o)) {
305
312
  var p = getprev(o);
313
+ while (p.type === LABEL) {
314
+ p = getprev(p);
315
+ if (!p) return o;
316
+ }
306
317
  if (o.entry === '(') {
307
318
  if (p.type & ~(STAMP | STRAP)) {
308
319
  o = p;
@@ -344,7 +355,7 @@ function snapAssignmentHead(o) {
344
355
  o = p;
345
356
  continue;
346
357
  }
347
- if (p.entry === "(" && o.type === SCOPED) {
358
+ if (p.entry === "(" && o.type & (SCOPED | LABEL)) {
348
359
  var pp = getContitionHeadBeforeScoped(p, true);
349
360
  if (pp) { o = pp; break; }
350
361
  var pp = getFunctionHeadBeforeScoped(p);
@@ -358,7 +369,7 @@ function snapAssignmentHead(o) {
358
369
  break;
359
370
  }
360
371
  if (p.type === STRAP) {
361
- if (/^(?:new|void|typeof|delete|await|class|function|async)$/.test(p.text)) {
372
+ if (/^(?:new|void|do|typeof|delete|await|class|function|async)$/.test(p.text)) {
362
373
  o = p;
363
374
  continue;
364
375
  }
@@ -906,7 +917,7 @@ var createScoped = function (parsed, wash) {
906
917
  }
907
918
  }
908
919
  var map = isFunction ? vars : lets;
909
- var keepscope = !!scoped.body || !!scoped.head;
920
+ var keepscope = isFunction || !!scoped.body || !!scoped.head;
910
921
  if (!keepscope) for (var k in map) {
911
922
  keepscope = true;
912
923
  break;
@@ -1524,7 +1535,7 @@ var createString = function (parsed) {
1524
1535
  ) result.push(";");
1525
1536
  }
1526
1537
  }
1527
-
1538
+ else if (o.ion);
1528
1539
  else if (!/^(\+\+|\-\-)$/.test(o.text) || p.type & (STAMP | STRAP)) {
1529
1540
  if (patchspace && lasttype !== SPACE && !o.needle) result.push(" ");
1530
1541
  }
@@ -1718,6 +1729,7 @@ var pickArgument = function (o) {
1718
1729
  p = t;
1719
1730
  t = getprev(t);
1720
1731
  }
1732
+ res.reverse();
1721
1733
  while (o && (o.type !== STAMP || !/^[,;]$/.test(o.text))) {
1722
1734
  res.push(o);
1723
1735
  var n = o;
@@ -21,6 +21,12 @@ testPickSentence(`if(a)return a=yield 1`, 6, "return a = yield 1")
21
21
  testPickSentence(`if(a)return\r\na=yield 1`, 6, "a = yield 1")
22
22
  testPickSentence(`if(a)return\r\na=yield 1`, 3, "return\r\n")
23
23
  testPickSentence(`if(a)import(a)`, 3, "import(a)")
24
+ testPickSentence(`for(;;) a:{import(a)}`, 2, "for (;;) a: { import(a) }")
25
+ testPickSentence(`for(;;) a:{import(a)}`, 3, "for (;;) a: { import(a) }")
26
+ testPickSentence(`while() a:{import(a)}`, 3, "while () a: { import(a) }")
27
+ testPickSentence(`do a:{}while() a:{import(a)}`, 2, "do a: {} while ()")
28
+ testPickSentence(`do a:{}while() a:{import(a)}`, 4, "do a: {} while ()")
29
+ testPickSentence(`do a:{}while() a:{import(a)}`, 5, "a: { import(a) }")
24
30
  testPickSentence(`import(b)import(a)`, 3, "import(a)")
25
31
  testPickSentence(`1+import(a)`, 3, "1 + import(a)")
26
32
  testPickSentence(`1+await import(a)`, 3, "1 + await import(a)")
@@ -48,5 +54,9 @@ function testCreateScope(code) {
48
54
  code = scanner2(code);
49
55
  common.createScoped(code);
50
56
  }
51
-
52
- testCreateScope(`class a{ static barch = new arch('b')}`)
57
+ testCreateScope(`class a{ static barch = new arch('b')}`)
58
+ assert(common.number_reg.test("00080000h"), true)
59
+ assert(common.number_reg.test("1.1920928955078125e-07F"), true)
60
+ assert(new RegExp(common.number_reg.source.replace(/^\^|\$$/g, ''), 'ig').exec("00080000h"), ["00080000h"])
61
+ assert(new RegExp(common.number_reg.source.replace(/^\^|\$$/g, ''), 'ig').exec("2A3h"), ["2A3h"])
62
+ assert(new RegExp(common.number_reg.source.replace(/^\^|\$$/g, ''), 'ig').exec("1.1920928955078125e-07F"), ["1.1920928955078125e-07F"])
@@ -1,7 +1,11 @@
1
1
  var scanner2 = require("./scanner2");
2
2
  var strings = require("../basic/strings");
3
3
  var Program = scanner2.Program;
4
- var { STAMP, SCOPED, STRAP, EXPRESS, mergeTo, pickAssignment, COMMENT, SPACE, PROPERTY, VALUE, LABEL, QUOTED, snapExpressFoot, isEval, canbeTemp, rename, isHalfSentence, skipFunction, getDeclared, skipAssignment, skipSentenceQueue, createScoped, createString, splice, relink, rolink, pickSentence, snapExpressHead, needBreakBetween } = require("./common");
4
+ var {
5
+ STAMP, SCOPED, STRAP, EXPRESS,
6
+ mergeTo, pickAssignment,
7
+ COMMENT, SPACE, PROPERTY, VALUE, LABEL, QUOTED,
8
+ snapExpressFoot, isEval, canbeTemp, rename, isHalfSentence, skipFunction, getDeclared, skipAssignment, skipSentenceQueue, createScoped, createString, splice, relink, rolink, pickSentence, snapExpressHead, needBreakBetween } = require("./common");
5
9
  var splice2 = function (q, from, to, ...a) {
6
10
  var cx = q.indexOf(from);
7
11
  if (cx < 0) throw console.log(splice2.caller, console.format(`\r\n<red2>${i18n`自`}</red2>`), from && createString([from]), console.format(`\r\n<yellow>${i18n`至`}</yellow>`), to && createString([to]), console.format(`\r\n<cyan>${i18n`码列`}</cyan>`), createString(pickSentence(from))), i18n`结构异常`;
@@ -538,6 +542,7 @@ var getprop = function (o, m) {
538
542
  prop.value = scanner2(prop.name);
539
543
  if (m.next) insert1(prop.value, null, { type: STAMP, text: ',' });
540
544
  }
545
+ if (m.hidden) prop.hidden = true;
541
546
  if (prop.get || prop.set) {
542
547
  if (!/^[\d\.'"\[]/.test(prop.name)) prop.name = strings.encode(prop.name);
543
548
  }
@@ -604,7 +609,6 @@ var killcls = function (body, i, letname_, getname_, killobj) {
604
609
  var o = body[i];
605
610
  var ishalf = isHalfSentence(body, i - 1);
606
611
  var hasnew = o.prev && o.prev.type === STRAP && o.prev.text === 'new';
607
- var start = o;
608
612
  var decName = !o.isExpress && o.next.type === EXPRESS && o.next.text;
609
613
  var isExpress = o.isExpress;
610
614
  while (o) {
@@ -628,6 +632,7 @@ var killcls = function (body, i, letname_, getname_, killobj) {
628
632
  var func = scanner2("(function(){}())")[0];
629
633
  var [, head, defines, invokes] = func;
630
634
  var foot = [];
635
+ var hiddens = null;
631
636
  var base = '';
632
637
  if (o) {
633
638
  var next = o;
@@ -648,15 +653,50 @@ var killcls = function (body, i, letname_, getname_, killobj) {
648
653
  var clz = { name };
649
654
  if (!clz.name) clz.name = letname_("cls" + index);
650
655
  var tempname = null;
656
+ var hiddens = null;
657
+ var staticHidden = null;
651
658
  while (m) {
652
659
  var [prop, m] = getprop(o, m);
653
- if (!prop.value.length) prop.value = scanner2('undefined;');
660
+ var pvalue = prop.value;
661
+ if (!pvalue.length || pvalue.length === 1 && pvalue[0].text === ';') prop.value = scanner2('undefined;');
654
662
  else if (!prop.sfunc) killobj(prop.value);
663
+ if (!tempname && (prop.get || prop.set)) tempname = getname_("tmp");
664
+ if (prop.hidden) {
665
+ if (!rootenvs["#"]) {
666
+ rootenvs["#"] = true;
667
+ }
668
+ if (prop.static) {
669
+ if (!staticHidden) {
670
+ clz.hidden = letname_('hiden' + index);
671
+ staticHidden = [];
672
+ insert1(foot, null, ...scanner2(`#["set"](${clz.name},{});`));
673
+ }
674
+ setprop(prop, `#["get"](${clz.name})`, static_, foot, tempname);
675
+ }
676
+ else {
677
+ if (!hiddens) {
678
+ hiddens = [];
679
+ insert1(assign, null, ...scanner2(`#["set"](this,{});`));
680
+ }
681
+ if (!hiddens[prop.name]) {
682
+ hiddens[prop.name] = prop.name;
683
+ }
684
+ if (prop.get || prop.set) {
685
+ setprop(prop, `#["get"](this)`, define_, assign, tempname);
686
+ }
687
+ else if (prop.sfunc !== false) {
688
+ setprop(prop, `#["get"](this)`, define_, assign);
689
+ }
690
+ else {
691
+ insert1(assign, null, ...scanner2(`#["get"](this)${prop.name}=`), ...prop.value);
692
+ }
693
+ }
694
+ continue;
695
+ }
655
696
  var k = prop.static ? clz.name : `${clz.name}["prototype"]`;
656
697
  var d = prop.static ? static_ : define_;
657
698
  if (prop.get || prop.set || prop.static) {
658
699
  if (prop.name) {
659
- if ((prop.get || prop.set) && !tempname) tempname = getname_("tmp");
660
700
  setprop(prop, k, d, defines, tempname);
661
701
  }
662
702
  else if (prop.static) {
@@ -732,11 +772,11 @@ var killcls = function (body, i, letname_, getname_, killobj) {
732
772
  if (clz.name) insert1(head, null, ...scanner2(`${head.length ? ',' : ''}${clz.name}`));
733
773
  index++;
734
774
  }
735
- insert1(defines, null, ...foot);
775
+ if (foot.length) insert1(defines, null, ...foot);
736
776
  var s = i;
737
777
  i = body.indexOf(o, i);
738
778
  if (i < 0) i = body.length;
739
- if (head.length > 1 || start.isExpress && (defines.length) || ishalf && defines.length) {
779
+ if ((ishalf || head.length > 1 || decName !== clz.name) && defines.length) {
740
780
  splice(defines, defines.length, 0, ...scanner2(`\r\nreturn ${clz.name}`))
741
781
  if (decName) splice(func, 0, 0, ...scanner2(`var ${decName}=`));
742
782
  if (hasnew) splice(body, s, i - s, func);
@@ -1080,7 +1120,15 @@ var killobj = function (body, getobjname, getletname, getname_, letname_, deep =
1080
1120
  }
1081
1121
  }
1082
1122
  else if (o.type === EXPRESS) {
1083
- if (o.text === 'new.target') o.text = 'undefined';
1123
+ if (o.hidden) {
1124
+ if (!rootenvs["#"]) {
1125
+ rootenvs["#"] = true;
1126
+ }
1127
+ var varname = o.hidden;
1128
+ o.text = o.text.slice(varname.length);
1129
+ insert1(body, o, ...scanner2(`#["get"](${varname})`));
1130
+ i = body.indexOf(o, i);
1131
+ }
1084
1132
  }
1085
1133
  i++;
1086
1134
  }
@@ -1923,6 +1971,11 @@ var downcode = downLevel.code = function (code) {
1923
1971
  if (!code.vars[slice_]) splice(code, 0, 0, ...scanner2(`var ${slice_} = Array["prototype"]["slice"];\r\n`));
1924
1972
  code.vars[slice_] = true;
1925
1973
  }
1974
+ if (rootenvs["#"]) {
1975
+ delete rootenvs["#"];
1976
+ if (!code.vars["#"]) splice(code, 0, 0, ...scanner2(`var # = new WeakMap`));
1977
+ if (!rootenvs.WeakMap) rootenvs.WeakMap = true;
1978
+ }
1926
1979
  rootenvs = null;
1927
1980
  patchMark = patchMark_;
1928
1981
  return code;
@@ -27,7 +27,8 @@ assert(downLevel(`var [] = piece, key,[]`), 'var key');
27
27
  assert(downLevel(`const`), 'const');
28
28
  assert(downLevel(`let`), 'let');
29
29
  assert(downLevel(`var`), '');
30
- assert(downLevel(`new.target`), 'undefined');
30
+ assert(downLevel(`new.target`), 'new.target');
31
+ assert((tmp = scanner2(`new.target`), tmp.detour(), downLevel.code(tmp).toString()), 'undefined');
31
32
  assert(downLevel(`{let a; function b(){a};return;}`), `if (tmp = 0, tmp0 =function (a) { a; function b() { a }; return tmp = 1, void 0; }(a)) { if (tmp === 1) return tmp0; }
32
33
  var tmp, a, tmp0`);
33
34
  assert(downLevel(`const a,b,c`), 'var a, b, c');
@@ -90,6 +91,7 @@ a = function () {}; if (!a) return [1, 0]; a = 1; return [1, 0]
90
91
  var a, _0 }`)
91
92
  assert(downLevel(`if(a) class b{ c(){}};`), `if (a) var b = function (b) { b["prototype"].c = function () {}\r\nreturn b }(function b() {});`)
92
93
  assert(downLevel(`class a {a=1}`), "function a() { this.a = 1 }")
94
+ assert(downLevel(`class a {#a=1}`), "function a() { this.#a = 1 }")
93
95
  assert(downLevel(`class a {a=1; b(){}}`), `function a() { this.a = 1; }; a["prototype"].b = function () {}`)
94
96
  assert(downLevel(`=class a {a=1; b(){}}`), `= function (a) { a["prototype"].b = function () {}\r\nreturn a }(function a() { this.a = 1; })`)
95
97
  assert(downLevel(`var a=class {a=1; static b=2 b(){}};`), `var a = function (cls0) { cls0.b = 2\r\ncls0["prototype"].b = function () {}\r\nreturn cls0 }(function () { this.a = 1; });`)
@@ -98,7 +100,8 @@ assert(downLevel(`class a {static b(){}}`), "function a() {}; a.b = function ()
98
100
  assert(downLevel(`class a extends b{}`), `function a() {
99
101
  var this_ = b["apply"](this, arguments) || this;
100
102
  return this_ }; &extends(a, b)`);
101
- assert(downLevel(`class a extends class b{}{}`), `var a = function (b, a) { &extends(a, b)\r\nreturn a }(function b() {}, function a() {
103
+ assert(downLevel(`class a extends class b{}{}`), `var a = function (b, a) { &extends(a, b)
104
+ return a }(function b() {}, function a() {
102
105
  var this_ = b["apply"](this, arguments) || this;
103
106
  return this_ })`);
104
107
  assert(downLevel(`class a {get a(){}}`), `function a() {};
@@ -430,7 +433,7 @@ function (_) {
430
433
  _0 = _; return [1, 0]
431
434
  })
432
435
  var _0 }`)
433
- assert(downLevel(`async function(a){ for(var i=1;i<2;i++) await 1 }`), `function (a) { return &async(\r\nfunction () {\r\ni = 1; return [1, 0]\r\n},\r\nfunction () {\r\n_0 = i < 2; if (!_0) return [2, 0]; _0 = 1; return [_0, 1]\r\n},\r\nfunction (_) {\r\n_0 = _; _0 = i++; return [-1, 0]\r\n})\r\nvar i, _0 }`)
436
+ assert(downLevel(`async function(a){ for(var i=1;i<2;i++) await 1 }`), `function (a) { return &async(\r\nfunction () {\r\ni = 1; return [1, 0]\r\n},\r\nfunction () {\r\n_0 = i < 2; if (!_0) return [2, 0]; _0 = 1; return [_0, 1]\r\n},\r\nfunction (_) {\r\n_0 = _; i++; return [-1, 0]\r\n})\r\nvar i, _0 }`)
434
437
  assert(downLevel('async function(){ if(b); else {if (a){}else{location = getRequestProtocol(url) + "//" + location;}}}'), `function () { return &async(
435
438
  function () {
436
439
  if (!b) return [1, 0]; return [3, 0]
@@ -470,7 +473,6 @@ c.fix(); i++
470
473
  c.break(); i++
471
474
  assert(c.toString(), `\r\n if (search["length"]) return null;\r\n return path["join"](...pathlist);\r\n`);
472
475
  assert(downLevel.code(c).toString(), `\r\n if (search["length"]) return null;\r\n return path["join"]["apply"](path, pathlist);\r\n`);
473
- downLevel.debug = true; i++;
474
476
  assert(downLevel(`Symbol;var c = (a.data || (a.data = {})).transition = no(this);`), 'Symbol; var c = (a.data || (a.data = {})).transition = no(this);', true);
475
477
  assert(downLevel(`[a.b]=[1]`), 'a.b = [1][0]')
476
478
  assert(downLevel(`[a[b]]=[1]`), 'a[b] = [1][0]')
@@ -516,15 +518,27 @@ assert(downLevel(`a(a,)`), `a(a)`);
516
518
  assert(downLevel(`class{a=[...presets.source]}`), `var &slice = Array["prototype"]["slice"];
517
519
  function () { this.a = &slice["call"](presets.source) }`);
518
520
  assert(downLevel(`class{a=a=>a}`), `function () { this.a = function (a) { return a } }`);
521
+ downLevel.debug = true; i++;
522
+ assert(downLevel(`class{a}`), "function () { this.a = undefined; }");
523
+ assert(downLevel(`class{a;}`), "function () { this.a = undefined; }");
524
+ assert(downLevel(`class{#a;a(){a=this.#a}}`), `function (cls0) { cls0["prototype"].a = function () { a = this.#a }
525
+ return cls0 }(function () { this.#a = undefined; })`);
526
+ tmp = scanner2(`class{#a;a(){a=this.#a}}`), tmp.detour(), i++;
527
+ assert(downLevel.code(tmp).toString(), `var # = new WeakMap function (cls0) { cls0["prototype"]["a"] = function () { a = #["get"](this)["#a"] }
528
+ return cls0 }(function () { #["set"](this, {}); #["get"](this)["#a"] = undefined; })`);
529
+ downLevel.debug = false; i++;
519
530
  assert(downLevel(`class{ get a(){[...a]}}`), `var &slice = Array["prototype"]["slice"];
520
- function () {};
531
+ function (cls0) {
521
532
  Object["defineProperty"](cls0["prototype"], "a", (tmp = {}, tmp["get"] = function () { &slice["call"](a) }, tmp))
533
+ return cls0 }(function () {})
522
534
  var tmp`);
523
535
  assert(downLevel(`class{ get (){[...a]}}`), `var &slice = Array["prototype"]["slice"];
524
- function () {}; cls0["prototype"].get = function () { &slice["call"](a) }`);
525
- assert(downLevel(`class{ async get a(){[...a]}}`), `var &slice = Array["prototype"]["slice"];
526
- function () {};
536
+ function (cls0) { cls0["prototype"].get = function () { &slice["call"](a) }
537
+ return cls0 }(function () {})`);
538
+ assert(downLevel(`class{ async get a(){[...a]}}`), `var &slice = Array["prototype"]["slice"];
539
+ function (cls0) {
527
540
  Object["defineProperty"](cls0["prototype"], "a", (tmp = {}, tmp["get"] = function () { &slice["call"](a) }, tmp))
541
+ return cls0 }(function () {})
528
542
  var tmp`);
529
543
  assert(downLevel(`a=class{ static a(){[...a]}}`), `var &slice = Array["prototype"]["slice"];
530
544
  a = function (cls0) { cls0.a = function () { &slice["call"](a) }
@@ -10,10 +10,10 @@ var powermap = {
10
10
  '=,+=,-=,*=,/=,%=,|=,&=,^=,||=,&&=,??=,<<=,>>=,>>>=,**=,~=,:=,?,:,=>'/* 1 */,
11
11
  '&&,||,^^,??'/* 3 */, '|,^'/* 4 */, '&'/*5*/,
12
12
  'instanceof,in,==,>=,<=,>,<,!=,!==,===,!in,!instanceof'/* 6 */,
13
- '>>,>>>,<<'/* 7 */, '+,-'/* 8 */, '*,/,%'/* 9 */, '**'/* 10 */,
13
+ '>>,>>>,<<'/* 7 */, '+,-'/* 8 */, '*,/,%,\\'/* 9 */, '**'/* 10 */,
14
14
  '++,--'/* 11 */,
15
15
  "typeof,await,yield,delete,void,..."/*12*/,
16
- '!,~,#,new'/* 13 */,
16
+ "',!,~,#,new"/* 13 */,
17
17
  "::,?.,->,."/*14*/,
18
18
  ].forEach((pp, i) => {
19
19
  pp.split(",").forEach(p => {
@@ -11,7 +11,7 @@ var patchObject = function (code, objs) {
11
11
  continue;
12
12
  }
13
13
  if (c.type === EXPRESS) {
14
- if (m = /^&(\d+)$/.exec(c.text)) {
14
+ if (m = /^\\(\d+)$/.exec(c.text)) {
15
15
  var o = cloneNode(objs[+m[1]], keep);
16
16
  if (o instanceof Array) replace(c, ...o);
17
17
  else replace(c, o);
@@ -25,7 +25,7 @@ function rescan(strs, ...args) {
25
25
  var i = 0;
26
26
  for (var s of strs) {
27
27
  if (s) dist.push(s, ' ');
28
- dist.push('&' + i++, " ");
28
+ dist.push('\\' + i++, " ");
29
29
  }
30
30
  dist.pop();
31
31
  if (i > args.length) dist.pop();
@@ -197,13 +197,37 @@ class Code extends Array {
197
197
  compress(this.scoped);
198
198
  return this;
199
199
  }
200
+ getNodeAt(row, col) {
201
+ return getNodeAt(this, row, col);
202
+ }
200
203
  relink(list = this) {
201
204
  relink(list);
202
205
  setqueue(list);
203
206
  return list;
204
207
  }
205
208
  }
206
-
209
+ function getNodeAt(code, row, col) {
210
+ for (var cx = 0, dx = code.length; cx < dx;) {
211
+ var ci = cx + dx >>> 1;
212
+ var o = code[ci];
213
+ var r = o.row;
214
+ if (r < row || r === row && o.col < col) cx = ci + 1;
215
+ else dx = ci;
216
+ }
217
+ if (cx > 0) cx--;
218
+ dx = code.length;
219
+ while (cx < dx) {
220
+ var o = code[cx];
221
+ if (o.row === row && o.col === col) return o;
222
+ var n = code[++cx];
223
+ if (n?.row === row) {
224
+ if (n.col === col) return n;
225
+ if (n.col < col) continue;
226
+ }
227
+ if (o.length) return getNodeAt(o, row, col);
228
+ return o;
229
+ }
230
+ }
207
231
  var avoidMap = null;
208
232
  var typeMap = Object.create(null);
209
233
  function scan(text) {
@@ -17,6 +17,7 @@ var patchTranslate = function (c, raw) {
17
17
  var text = raw ? c.text.slice(1, c.text.length - 1) : strings.decode(c.text).replace(/\r\n|\r|\n/g, '\r\n');
18
18
  c.translate = text;
19
19
  }
20
+ else c.translate = '';
20
21
  }
21
22
 
22
23
  }
@@ -46,7 +47,7 @@ function getAllText(code, dest = []) {
46
47
  return dest;
47
48
  }
48
49
 
49
- var [手动, 字段名] = Array(2).fill(0).map((_, i) => i + 1);
50
+ var [手动, 字段名, 公式] = Array(3).fill(0).map((_, i) => i + 1);
50
51
  function getI18nPrefixedText(code, dist = []) {
51
52
  var { used, envs } = code;
52
53
  var get = function (arr, f, t) {
@@ -54,7 +55,7 @@ function getI18nPrefixedText(code, dist = []) {
54
55
  if (!n || n.type !== QUOTED || n.length && n.entry !== '`') continue;
55
56
  var c = n;
56
57
  c.transtype = t;
57
- patchTranslate(c, t === 字段名);
58
+ patchTranslate(c, t >= 字段名);
58
59
  f(c);
59
60
  }
60
61
  };
@@ -72,6 +73,10 @@ function getI18nPrefixedText(code, dist = []) {
72
73
  c.warn = false;
73
74
  dist.push(c);
74
75
  }, 字段名);
76
+ if (envs.math) get(used.math.filter(o => o.text === 'math').map(o => o.next), c => {
77
+ c.formula = 算式(c.translate);
78
+ dist.push(c);
79
+ }, 公式);
75
80
  return dist;
76
81
  }
77
82
  var ctn = function (tt, t) {
@@ -120,8 +125,8 @@ function translate([imap, supports], code) {
120
125
  return m;
121
126
  };
122
127
  var used = code.used;
123
- for (var t of texts) {
124
- if (t.transtype === 手动) {
128
+ for (var t of texts) switch (t.transtype) {
129
+ case 手动:
125
130
  var p = t.prev;
126
131
  if (p.type === SCOPED) {
127
132
  p.prev.text = 'i18n.lang';
@@ -131,8 +136,8 @@ function translate([imap, supports], code) {
131
136
  var tt = t.translate;
132
137
  var tn = ctn(getm(tt, t.nodup), t);
133
138
  replace(t, ...tn);
134
- }
135
- else if (t.transtype === 字段名) {
139
+ break;
140
+ case 字段名:
136
141
  var i = t.queue.indexOf(t.prev);
137
142
  var e = t.queue.indexOf(t, i);
138
143
  if (t.warn === false) {
@@ -204,7 +209,13 @@ function translate([imap, supports], code) {
204
209
  relink(tn);
205
210
  Object.defineProperty(tn, 'queue', { value: t.queue });
206
211
  splice(t.queue, i, e + 1 - i, tn);
207
- }
212
+ break;
213
+ case 公式:
214
+ var JJSON = require('../basic_/JSON');
215
+ var formula = t.formula.iscup ? t.formula.map(a => JJSON.toJS(a)).join(",") : JJSON.toJS(t.formula);
216
+ var node = scanner2(`(${formula})`)[0];
217
+ replace(t, node);
218
+ break;
208
219
  }
209
220
  if (used.refilm && !used.refilm.length) {
210
221
  delete code.envs.refilm;
@@ -259,7 +259,7 @@ var _for = function (body, cx, unblock, result) {
259
259
  while (cy < o.length && o[cy] !== m) cy++;
260
260
  var block = getblock(o, cy);// init
261
261
  cy += block.length + 1;
262
- unblock(block);
262
+ unblock(block, false);
263
263
  if (result.length) pushstep(result, stepReturn(1, 0));
264
264
  var block1 = getblock(o, cy);// condition
265
265
  cy += block1.length + 1;
@@ -280,7 +280,7 @@ var _for = function (body, cx, unblock, result) {
280
280
  var i = result.length;
281
281
  unblock(block_);
282
282
  if (label.continue) ifpatch(result), label.contat = result.length;
283
- unblock(block2);
283
+ unblock(block2, false);
284
284
  var loopback = stepReturn(0, 0);
285
285
  var le = loopback[loopback.length - 1];
286
286
  pushstep(result, loopback);
@@ -783,6 +783,19 @@ var uncurve = function (c) {
783
783
  }
784
784
  return c;
785
785
  };
786
+ var getChanged = function (bd) {
787
+ var changed = Object.create(null);
788
+ var rest = [bd];
789
+ while (rest.length) {
790
+ var o = rest.pop();
791
+ if (o.length) rest.push.apply(rest, o);
792
+ else if (o.type === EXPRESS) {
793
+ if (o.equal) changed[o.text] = true;
794
+ }
795
+ }
796
+ return changed;
797
+ };
798
+
786
799
  var ternary = function (body, getname, ret) {
787
800
  var eqused = 0;
788
801
  var getnextname = function (i) {
@@ -867,6 +880,35 @@ var ternary = function (body, getname, ret) {
867
880
  explist = [r];
868
881
  }
869
882
  else {
883
+ if (equalsend > skip) {
884
+ var subs = [];
885
+ for (var cx = 0, dx = equals.length; cx < dx; cx++) {
886
+ var h = equals[cx];
887
+ if (h.type === EXPRESS) {
888
+ var n = h.next;
889
+ if (n?.type === SCOPED && n.entry === '[') {
890
+ var f = n.first;
891
+ if (f && f === n.last) {
892
+ subs.push(n);
893
+ }
894
+ }
895
+ }
896
+ }
897
+ if (subs.length) {
898
+ var changed = getChanged(bd);
899
+ for (var n of subs) {
900
+ var f = n.first;
901
+ if (f.type === EXPRESS && f.text in changed) {
902
+ var name = getnextname(0);
903
+ ++eqused;
904
+ var o = n.first = n.last = { type: EXPRESS, text: name };
905
+ o.queue = n;
906
+ n.splice(0, n.length, o);
907
+ exphead.push([{ type: EXPRESS, text: name }, { type: STAMP, text: "=" }, f, { type: STAMP, text: ';' }]);
908
+ }
909
+ }
910
+ }
911
+ }
870
912
  explist = _express(bd, getnextname, equalsend > skip || ret);
871
913
  }
872
914
  }