efront 4.10.0 → 4.10.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.
@@ -16,7 +16,7 @@ const [
16
16
  // --------------//1//2/////////////////////////22/////////////2//2//3//4/////4////////3/////3//////3//3//////3///////211/////////////2//////2//////1///
17
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;
18
18
  var equal_reg = /^(?:[\+\-\*\/~\^&\|%]|\*\*|>>>?|<<)?\=$|^(?:\+\+|\-\-)$/;
19
- var needhead_reg = /^\?\.|^\.(?:[^\.]|$)|^\[/;
19
+ var needhead_reg = /^\?|^\.(?:[^\.]|$)|^\[/;
20
20
  var skipAssignment = function (o, cx) {
21
21
  if (!o) return;
22
22
  var next = arguments.length === 1 ? function () {
@@ -96,7 +96,7 @@ var skipAssignment = function (o, cx) {
96
96
  }
97
97
  break;
98
98
  case SCOPED:
99
- if (needpunc && o.entry === "{") break loop;
99
+ if (needpunc && o.brace) break loop;
100
100
  next();
101
101
  needpunc = true;
102
102
  break;
@@ -104,6 +104,11 @@ var skipAssignment = function (o, cx) {
104
104
  if (needpunc) break loop;
105
105
  next();
106
106
  break;
107
+ case ELEMENT:
108
+ if (o.istype) {
109
+ next();
110
+ break;
111
+ }
107
112
  case EXPRESS:
108
113
  if (needhead_reg.test(o.text)) {
109
114
  next();
@@ -299,7 +304,7 @@ function snapSentenceHead(o) {
299
304
  while (o && o.prev) {
300
305
  var p = o.prev;
301
306
  if (o.entry === '(') {
302
- if (!(p.type & (STAMP | STRAP))) {
307
+ if (p.type & ~(STAMP | STRAP)) {
303
308
  o = p;
304
309
  p = o.prev;
305
310
  if (!p) break;
@@ -314,7 +319,7 @@ function snapSentenceHead(o) {
314
319
  continue
315
320
  };
316
321
  }
317
- var maybeprop = o.type === SCOPED && o.entry !== "{" || o.type === EXPRESS && /^[\.\[]/.test(o.text);
322
+ var maybeprop = o.type === SCOPED && !o.brace || o.type === EXPRESS && /^[\.\[]/.test(o.text);
318
323
  if (p.type === EXPRESS) {
319
324
  if (maybeprop || /\.$/.test(p.text)) {
320
325
  o = p;
@@ -329,7 +334,7 @@ function snapSentenceHead(o) {
329
334
  if (p.type & (VALUE | QUOTED)) {
330
335
  if (maybeprop) {
331
336
  o = p;
332
- if (p.entry === '`' && p.prev && !(p.prev.type & (STAMP | STRAP))) o = p.prev;
337
+ if (p.entry === '`' && p.prev && p.prev.type & ~(STAMP | STRAP)) o = p.prev;
333
338
  continue;
334
339
  }
335
340
  break;
@@ -516,6 +521,18 @@ var createScoped = function (parsed, wash) {
516
521
  funcbody.isroot = true;
517
522
  scoped.body = parsed;
518
523
  scoped.isfunc = true;
524
+ var dec = function (m, o) {
525
+ var [declared, used0, o0, skiped] = getDeclared(o.next, o.text);
526
+ mergeTo(used, used0);
527
+ while (skiped.length) {
528
+ var o1 = run(skiped[0], 0);
529
+ let sindex = skiped.indexOf(o1);
530
+ if (sindex < 0) break;
531
+ skiped.splice(0, sindex + 1);
532
+ }
533
+ mapDeclared(m, declared);
534
+ return o0;
535
+ };
519
536
  var run = function (o, id, body) {
520
537
  loop: while (o) {
521
538
  var isCatch = false;
@@ -560,9 +577,18 @@ var createScoped = function (parsed, wash) {
560
577
  if (o.isdigit || /^(null|false|true)$/.test(o.text)) break;
561
578
  case EXPRESS:
562
579
  if (needhead_reg.test(o.text)) break;
563
- // if (o.text === 'readFileAsync') console.log(o)
564
- if (o.prev && o.prev.type === EXPRESS) {
565
- if (/\.$/.test(o.prev.text)) break;
580
+ var prev = o.prev;
581
+ if (prev) {
582
+ if (prev.type === EXPRESS && /\.$/.test(o.prev.text)) break;
583
+ if (prev.istype) {
584
+ o = dec(lets, prev);
585
+ if (o && o.type === SCOPED && o.entry === "(") {
586
+ isFunction = true;
587
+ isScope = true;
588
+ break;
589
+ }
590
+ continue;
591
+ }
566
592
  }
567
593
  if (o.next && o.next.type === STAMP && o.next.text === "=>") {
568
594
  isScope = true;
@@ -625,16 +651,7 @@ var createScoped = function (parsed, wash) {
625
651
  if (!o.next || o.next.type === QUOTED) break;
626
652
  case "var":
627
653
  m = m || vars;
628
- var [declared, used0, o0, skiped] = getDeclared(o.next, s);
629
- mergeTo(used, used0);
630
- while (skiped.length) {
631
- var o1 = run(skiped[0], 0);
632
- let sindex = skiped.indexOf(o1);
633
- if (sindex < 0) break;
634
- skiped.splice(0, sindex + 1);
635
- }
636
- o = o0;
637
- mapDeclared(m, declared);
654
+ o = dec(m, o);
638
655
  continue loop;
639
656
  case "static":
640
657
  case "function":
@@ -653,7 +670,8 @@ var createScoped = function (parsed, wash) {
653
670
  case "catch":
654
671
  if (s === 'catch') isCatch = true;
655
672
  case "class":
656
- if (s === 'class') isClass = true;
673
+ case "interface":
674
+ if (/^interface|class$/.test(s)) isClass = true;
657
675
  if (!o.isExpress) {
658
676
  o = o.next;
659
677
 
@@ -662,6 +680,7 @@ var createScoped = function (parsed, wash) {
662
680
  o.kind = isFunction ? 'function' : 'class';
663
681
  saveTo(used, o.text, o);
664
682
  o = o.next;
683
+ if (o?.type === ELEMENT) o = o.next;
665
684
  }
666
685
  }
667
686
  isScope = true;
@@ -680,14 +699,15 @@ var createScoped = function (parsed, wash) {
680
699
  break;
681
700
  case SCOPED:
682
701
  if (o.entry === "(") {
702
+ var prev = o.prev;
683
703
  if (o.next && o.next.type === STAMP && o.next.text === "=>") {
684
704
  isArrow = true;
685
705
  isScope = true;
686
- if (o.prev?.type === STRAP && o.prev.text === 'async') {
706
+ if (prev?.type === STRAP && prev.text === 'async') {
687
707
  isAsync = true;
688
708
  }
689
709
  }
690
- else if (o.prev && (o.prev.type === PROPERTY || o.prev.isprop)) {
710
+ else if (prev?.isprop) {
691
711
  isFunction = true;
692
712
  isScope = true;
693
713
  var pp = o.prev.prev;
@@ -702,7 +722,7 @@ var createScoped = function (parsed, wash) {
702
722
  run(o.first);
703
723
  }
704
724
  }
705
- else if (o.entry === "{" && !o.isObject) {
725
+ else if (o.brace && !o.isObject) {
706
726
  isScope = true;
707
727
  }
708
728
  else {
@@ -799,7 +819,7 @@ var createScoped = function (parsed, wash) {
799
819
  o = o.next.next;
800
820
  }
801
821
  if (!o);
802
- else if (o.type === SCOPED && o.entry === "{") {
822
+ else if (o.type === SCOPED && o.brace) {
803
823
  scoped.body = o;
804
824
  o.scoped = scoped;
805
825
  o.isExpress = isExpress;
@@ -842,7 +862,7 @@ var createScoped = function (parsed, wash) {
842
862
  || EXPRESS === o.type && !/\.$/.test(o.text)) {
843
863
  if ((VALUE | QUOTED | PROPERTY | LABEL) & next.type) break;
844
864
  if (EXPRESS === next.type && !/^[\.\[]/.test(next.text)) break;
845
- if (next.type === SCOPED && next.entry === "{") break;
865
+ if (next.type === SCOPED && next.brace) break;
846
866
  if (next.type === STRAP && !next.isExpress) break;
847
867
  }
848
868
  o = next;
@@ -1006,7 +1026,7 @@ var getDeclared = function (o, kind, queue) {
1006
1026
  }
1007
1027
  else prop = declared["..."] ? declared["..."][1] - index : `[${index}]`;
1008
1028
  }
1009
- var f = snapExpressFoot(o);
1029
+ var f = o.isprop || prop ? snapExpressFoot(o) : o;
1010
1030
  if (k) saveTo(used, k, o);
1011
1031
  var s = [o];
1012
1032
  while (o !== f) o = o.next, s.push(o);
@@ -1042,6 +1062,14 @@ var getDeclared = function (o, kind, queue) {
1042
1062
  break;
1043
1063
  }
1044
1064
  break;
1065
+ case EXPRESS:
1066
+ if (o.text === '?') o = o.next;
1067
+ break;
1068
+ }
1069
+ if (o?.type === STAMP) {
1070
+ while (o?.istype) {
1071
+ o = o.next;
1072
+ }
1045
1073
  }
1046
1074
  if (!o) break;
1047
1075
  if (o.type !== STAMP) break;
@@ -1104,7 +1132,7 @@ var getSemicolonBetween = function (prev, next) {
1104
1132
  ) {
1105
1133
  if ((EXPRESS | VALUE | QUOTED | LABEL) & next.type) return ";";
1106
1134
  if (next.type === STRAP) {
1107
- if (!/^(in|of|extends|instanceof|as)$/.test(next.text)) return ";";
1135
+ if (!/^(in|of|extends|implements|instanceof|as|is|from)$/.test(next.text)) return ";";
1108
1136
  return " ";
1109
1137
  }
1110
1138
  if (next.type === SCOPED && next.entry === '{') {
@@ -1185,12 +1213,12 @@ var createString = function (parsed) {
1185
1213
  var intag = false;
1186
1214
  var run = (o, i, a) => {
1187
1215
  var prev = o.prev;
1188
- a: if (!((SPACE | COMMENT | STAMP | PIECE | SCOPED) & o.type) && prev && lasttype !== SPACE && patchspace) {
1189
- if ((QUOTED | SCOPED | STRAP | LABEL | COMMENT | ELEMENT) & lasttype
1216
+ a: if (prev && lasttype !== SPACE && patchspace && ~(SPACE | COMMENT | STAMP | PIECE | SCOPED) & o.type) {
1217
+ if ((QUOTED | SCOPED | STRAP | LABEL | COMMENT | ELEMENT | PROPERTY) & lasttype
1190
1218
  || prev.type === STAMP && !prev.unary
1191
1219
  ) {
1192
1220
  if (intag || prev.type === ELEMENT && o.type === ELEMENT) break a;
1193
- if (o.type !== EXPRESS || !needhead_reg.test(o.text) && !prev.tag && !o.tag) {
1221
+ if ((o.type & ~(EXPRESS | PROPERTY) || !needhead_reg.test(o.text)) && (!prev.tag && !o.tag || prev.type === STAMP || o.type === STAMP)) {
1194
1222
  result.push(" ");
1195
1223
  lasttype = SPACE
1196
1224
  }
@@ -1245,6 +1273,7 @@ var createString = function (parsed) {
1245
1273
  result.push(o.entry);
1246
1274
  result.push(o.tag);
1247
1275
  if (o.attributes) {
1276
+ var _intag = intag;
1248
1277
  intag = 0;
1249
1278
  var attributes = o.attributes;
1250
1279
  var needvalue = false;
@@ -1256,14 +1285,14 @@ var createString = function (parsed) {
1256
1285
  }
1257
1286
  else {
1258
1287
  if (a.type === PIECE && !a.text) continue;
1259
- if (!needvalue && (a.type !== PIECE || !/^\=/.test(a.text))) result.push(" ");
1288
+ if (!needvalue && !/\s$/.test(result[result.length - 1]) && a.type !== ELEMENT && (a.type !== PIECE || !/^[\=\s]/.test(a.text))) result.push(" ");
1260
1289
  run(a);
1261
1290
  needvalue = a.type === PIECE && /[\=]$/.test(a.text);
1262
1291
  }
1263
1292
  }
1264
- intag = 0;
1265
- if (o.short && attributes.length > 0 && !(lasttype & (SPACE | QUOTED))) {
1266
- if (!/[\s'"]$/.test(result[result.length - 1])) result.push(' ');
1293
+ intag = _intag;
1294
+ if (o.short && attributes.length > 0 && lasttype & ~(SPACE | QUOTED)) {
1295
+ if (!o.istype && !/[\s'"]$/.test(result[result.length - 1])) result.push(' ');
1267
1296
  }
1268
1297
  }
1269
1298
  if (o.closed) {
@@ -1289,14 +1318,15 @@ var createString = function (parsed) {
1289
1318
  break;
1290
1319
  }
1291
1320
  case SCOPED:
1292
- if (patchspace && o.type !== QUOTED && (lasttype & (STRAP | COMMENT | STAMP)
1293
- && (!o.prev || !/[\+\-\~\!]$/.test(o.prev.text) || /[\+\-]$/.test(o.prev.text) && (!o.prev.prev || !((STAMP | STRAP) & o.prev.prev.type)))
1294
- || lasttype === SCOPED && o.entry === "{"
1321
+ var prev = o.prev;
1322
+ if (patchspace && prev && o.type !== QUOTED && (lasttype === STAMP && !prev.unary
1323
+ || lasttype & ~(SPACE | STAMP | COMMENT) && o.brace
1324
+ || lasttype === STRAP && !/^(this|arguments|import)$/.test(prev.text)
1295
1325
  )) result.push(" ");
1296
1326
  result.push(o.entry);
1297
1327
  if (o.length > 0) {
1298
1328
  var fillspace = patchspace && lasttype !== PIECE && !intag;
1299
- if (o.entry === "{" && o[0].type !== SPACE) {
1329
+ if (o.brace && o[0].type !== SPACE) {
1300
1330
  if (fillspace) {
1301
1331
  result.push(" ");
1302
1332
  }
@@ -1314,7 +1344,7 @@ var createString = function (parsed) {
1314
1344
  else result.pop();
1315
1345
  }
1316
1346
  }
1317
- if (o.leave === "}" && o.entry === "{" && o[o.length - 1].type !== SPACE) {
1347
+ if (o.brace && o[o.length - 1].type !== SPACE) {
1318
1348
  if (fillspace) result.push(" ");
1319
1349
  }
1320
1350
  }
@@ -1322,11 +1352,11 @@ var createString = function (parsed) {
1322
1352
  break;
1323
1353
  default:
1324
1354
  if (o && typeof o === "object") {
1325
- if (intag || o.type === EXPRESS && (needhead_reg.test(o.text) || o.prev?.type === EXPRESS && /\.$/.test(o.prev.text))) {
1326
- if (o.prev?.isdigit && /^\./.test(o.text) && !/^0[\dxbo]|[mni]$|[e\.]/.test(o.prev.text)) result.push(" ");
1355
+ if (intag || o.type & (EXPRESS | PROPERTY) && (needhead_reg.test(o.text) || lasttype & EXPRESS && /\.$/.test(o.prev?.text))) {
1356
+ if (o.prev?.isdigit && !/^0[\dxbo]|[mni]$|[e\.]/.test(o.prev.text) && lasttype & ~(SPACE | COMMENT)) result.push(" ");
1327
1357
  }
1328
1358
  else if ((STRAP | EXPRESS | PROPERTY | COMMENT | VALUE) & lasttype && (STRAP | EXPRESS | PROPERTY | VALUE | LABEL) & o.type) {
1329
- if (autospace) result.push(" ");
1359
+ if (autospace || o.prev?.isdigit) result.push(" ");
1330
1360
  }
1331
1361
  else if (o.prev && o.type === STAMP && !/^[,;]/.test(o.text)) {
1332
1362
  if (result[result.length - 1] === " " || (lasttype === PROPERTY || !o.isExpress && o.prev && o.prev.type !== LABEL) && o.text === ':') { }
@@ -1632,7 +1662,7 @@ var unshort = function (o, text) {
1632
1662
  };
1633
1663
  var getFuncBody = function (o) {
1634
1664
  var q = o.queue;
1635
- while (q && !(q.scoped?.isfunc)) q = q.queue;
1665
+ while (q && !q.scoped?.isfunc) q = q.queue;
1636
1666
  return q;
1637
1667
  };
1638
1668
  var getBodyWith = function (o, k) {
@@ -1710,6 +1740,7 @@ module.exports = {
1710
1740
  /*2048 */ELEMENT,
1711
1741
  number_reg,
1712
1742
  equal_reg,
1743
+ needhead_reg,
1713
1744
  unshort,
1714
1745
  skipAssignment,
1715
1746
  getDeclared,
@@ -510,7 +510,7 @@ var getprop = function (o, m) {
510
510
  prop[m.text] = true;
511
511
  m = m.next;
512
512
  }
513
- if (m && (m.type === PROPERTY || m.isprop)) {
513
+ if (m && (m.isprop)) {
514
514
  prop.name = createString([m]);
515
515
  if (m.short) {
516
516
  prop.short = true;
@@ -539,7 +539,7 @@ var getprop = function (o, m) {
539
539
  var s = m;
540
540
  if (m && prop.sfunc !== false && m.type === SCOPED && m.entry === '(') {
541
541
  m = m.next;
542
- if (m && m.type === SCOPED && m.entry === "{") m = m.next;
542
+ if (m && m.type === SCOPED && m.brace) m = m.next;
543
543
  }
544
544
  else m = skipAssignment(m);
545
545
  if (m && !m.isprop) m = m.next;
@@ -1058,7 +1058,7 @@ var hasbreak = function (body) {
1058
1058
  return false;
1059
1059
  };
1060
1060
  var ises3 = function (o, killobj) {
1061
- if (o && o.type === SCOPED && o.entry === "{") {
1061
+ if (o && o.type === SCOPED && o.brace) {
1062
1062
  killobj(o);
1063
1063
  if (o.await_) return false;
1064
1064
  if (hasbreak(o)) return false;
@@ -1210,7 +1210,7 @@ var unarrow = function (body, i, killobj, letname_) {
1210
1210
  h = scanner2("()")[0];
1211
1211
  splice(h, 0, 0, ...splice(body, i, 1, h));
1212
1212
  }
1213
- if (n.type !== SCOPED || n.entry !== "{") {
1213
+ if (n.type !== SCOPED || !n.brace) {
1214
1214
  var nni = skipAssignment(body, ni);
1215
1215
  b = scanner2('{}')[0];
1216
1216
  splice(b, 0, 0, { type: STRAP, transive: true, text: "return" }, ...splice(body, ni, nni - ni, b));
@@ -1376,7 +1376,7 @@ var killret = function (body, labels = Object.create(null), gettmpname) {
1376
1376
  lbls.push(lbl);
1377
1377
  }
1378
1378
  }
1379
- else if (o.type === SCOPED && o.entry === "{") {
1379
+ else if (o.type === SCOPED && o.brace) {
1380
1380
  if (o.isClass || o.isObject);
1381
1381
  else killret(o, labels, gettmpname);
1382
1382
  unlabel = true;
@@ -1721,7 +1721,7 @@ var down = function (scoped) {
1721
1721
  fordeep = saveddeep;
1722
1722
  };
1723
1723
  if (scoped.isfunc) {
1724
- if (!scoped.body && scoped.head?.next?.type === SCOPED && scoped.head.next.entry === "{") scoped.body = scoped.head.next;
1724
+ if (!scoped.body && scoped.head?.next?.brace) scoped.body = scoped.head.next;
1725
1725
  if (scoped.head) var [argsmap, argcodes] = killarg(scoped.head, scoped.body, _letname, false);
1726
1726
  else argcodes = [];
1727
1727
  if ((markcodes.length || argcodes.length) && !funcMark) precode(markcodes.concat(argcodes).join(";") + ";");
@@ -431,4 +431,8 @@ _0 = a; return [_0, 1]
431
431
  })
432
432
  var a, _0 }`)
433
433
 
434
- assert(downLevel(`function(a=b=>b,c){c}`), 'function (a, c) { if (a === undefined) a = function (b) { return b }; c }')
434
+ assert(downLevel(`function(a=b=>b,c){c}`), 'function (a, c) { if (a === undefined) a = function (b) { return b }; c }')
435
+ assert(downLevel(`Object.defineProperty(dis, f.key, {get() {}, set(v) {}})`), `Object.defineProperty(dis, f.key, (_ = {},
436
+ _.get = function () {},
437
+ _.set = function (v) {}, _))
438
+ var _`)
@@ -20,7 +20,7 @@ function format(code, step) {
20
20
  var space = lowspace + step;
21
21
  if (code.length === 0) continue;
22
22
  var explist = createExpressList(code);
23
- var breakline = explist.length > 1 && (code.isObject || !code.entry || code.entry === "{");
23
+ var breakline = explist.length > 1 && (code.isObject || !code.entry || code.brace);
24
24
  code.splice(0, code.length);
25
25
  if (breakline) code.push({ type: SPACE, text: space });
26
26
  if (breakline) var deepspace = space + step;
@@ -23,7 +23,7 @@ var powermap = new class {
23
23
  };
24
24
 
25
25
  [
26
- '=,+=,-=,*=,/=,%=,|=,&=,^=,||=,&&=,??=,<<=,>>=,>>>=,**=,~=,?,:,=>'/* 1 */,
26
+ '=,+=,-=,*=,/=,%=,|=,&=,^=,||=,&&=,??=,<<=,>>=,>>>=,**=,~=,:=,?,:,=>'/* 1 */,
27
27
  '&&,||,^^,??'/* 4 */, '&,|,^'/* 5 */,
28
28
  'instanceof,in,==,>=,<=,>,<,!=,!==,===,!in,!instanceof'/* 6 */,
29
29
  '>>,>>>,<<'/* 7 */, '+,-'/* 8 */, '*,/,%'/* 9 */, '**'/* 10 */,
@@ -529,7 +529,7 @@ var _invoke = function (t, getname) {
529
529
  for (var cx = 0; cx < t.length; cx++) {
530
530
  var o = t[cx];
531
531
  a: if (o.type === STRAP) {
532
- if (/^(async|function)/.test(o.text)) while (o && o.entry !== "{") o = o.next;
532
+ if (/^(async|function)/.test(o.text)) while (o && !o.brace) o = o.next;
533
533
  else if (o.text === 'class') {
534
534
  while (o && !o.isClass) o = o.next;
535
535
  var n = o.next;
@@ -898,7 +898,7 @@ var isFunctionOnly = function (body) {
898
898
  var o = body[cx];
899
899
  if (!o) return false;
900
900
  if (o.type === STRAP) {
901
- if (/^(async|function)$/.test(o.text)) while (o && o.entry !== "{") o = body[cx++];
901
+ if (/^(async|function)$/.test(o.text)) while (o && !o.brace) o = body[cx++];
902
902
  else if (o.text === 'class') {
903
903
  while (o && !o.isClass) o = body[cx++];
904
904
  while (o && (o.type & (SPACE | COMMENT) || o.isClass)) o = body[cx++];
@@ -1,5 +1,5 @@
1
1
 
2
- var { STRAP, SCOPED, ELEMENT, QUOTED, LABEL, COMMENT, STAMP, VALUE, EXPRESS, PROPERTY, PIECE } = compile$common;
2
+ var { STRAP, SCOPED, ELEMENT, QUOTED, LABEL, COMMENT, STAMP, VALUE, EXPRESS, PROPERTY, PIECE, needhead_reg } = compile$common;
3
3
  var predefs = Object.create(null);
4
4
  predefs.module = true;
5
5
  predefs.exports = true;
@@ -10,36 +10,49 @@ var codecolor = function (c, encode) {
10
10
  var envs = c.envs;
11
11
  var deep = 0;
12
12
  var used = c.used;
13
+ var isConstValue = () => false;
14
+ if (c.program) {
15
+ var { strap_reg, value_reg } = c.program;
16
+ isConstValue = a => strap_reg.test(a) || value_reg.test(a);
17
+ };
18
+ var isInvoke = function (o) {
19
+ var o = o.next;
20
+ if (o?.type === EXPRESS && needhead_reg.test(o.text)) o = o.next;
21
+ if (o?.type === ELEMENT && o.istype) o = o.next;
22
+ if (o?.type === SCOPED && o.entry === "(") return true;
23
+ return false;
24
+ }
13
25
  var setExpress = function (o, label) {
14
26
  if (!o.text) return;
15
27
  var keys = o.text.split(".");
16
- var next = o.next;
17
- if (next && next.type === SCOPED && next.entry === '(') {
18
- if (!/^\</.test(keys[keys.length - 1])) keys[keys.length - 1] = `<invoke>${keys[keys.length - 1]}</invoke>`;
28
+ if (isInvoke(o)) {
29
+ if (!/^[\<\?]/.test(keys[keys.length - 1])) keys[keys.length - 1] = `<invoke>${keys[keys.length - 1]}</invoke>`;
19
30
  }
20
31
  var [name] = keys;
21
32
  if (/^[\<\?]/.test(name) || !name);
22
- else if (c.program?.strap_reg.test(name) || c.program?.value_reg.test(name) || /^(this|arguments)$/.test(name)) name = `<strap>${name}</strap>`;
33
+ else if (!o.isprop && isConstValue(name)) name = `<strap>${name}</strap>`;
23
34
  else name = `<${label}>${name}</${label}>`;
24
35
  keys[0] = name;
25
- o.text = keys.map(k => /^\</.test(k) || !k ? k : `<express>${k}</express>`).join(".");
36
+ o.text = keys.map(k => /^[\<\?]/.test(k) || !k ? k : `<express>${k}</express>`).join(".");
26
37
  }
27
38
  var setPredef = o => setExpress(o, 'predef');
28
39
  var setOutside = o => setExpress(o, 'outside');
29
40
  if (used) for (var k in envs) {
30
41
  used[k].forEach(k in predefs ? setPredef : setOutside);
31
42
  }
32
- var spaceReg = c.program.space_exp;
43
+ if (c.program) var { space_exp: spaceReg, control_reg } = c.program;
33
44
  var unspaceReg = new RegExp(spaceReg.source.replace(/^\[/, "[^"), spaceReg.flags + 'g');
34
45
  var wraptext = function (t, l) {
35
- t = t.replace(unspaceReg, a => {
46
+ if (unspaceReg) t = t.replace(unspaceReg, a => {
36
47
  a = encode(a);
37
48
  return `<${l}>${a}</${l}>`
38
49
  });
39
50
  return t;
40
51
  }
41
-
52
+ c.colored = true;
42
53
  var setcolor = function (o) {
54
+ if (o.colored) return;
55
+ o.colored = true;
43
56
  var text = o.text;
44
57
  switch (o.type) {
45
58
  case LABEL:
@@ -94,17 +107,16 @@ var codecolor = function (c, encode) {
94
107
  case PROPERTY:
95
108
  var next = o.next;
96
109
  if (next && next.type === SCOPED && next.entry === '(') {
97
- o.text = `<method>${o.text}</method>`;
110
+ setExpress(o, 'method');
98
111
  }
99
- else o.text = `<property>${o.text}</property>`;
112
+ else setExpress(o, 'property');
100
113
 
101
114
  break;
102
115
  case EXPRESS:
103
- setExpress(o, 'express');
116
+ setExpress(o, o.istype ? 'predef' : 'express');
104
117
  break;
105
118
  case STRAP:
106
- if (/^(if|else|switch|case|do|while|for|break|continue|default|import|from|as|export|try|catch|finally|throw|await|yield|return)$/.test(text))
107
- o.text = `<flow>${o.text}</flow>`;
119
+ if (control_reg?.test(text)) o.text = `<flow>${o.text}</flow>`;
108
120
  else o.text = `<strap>${o.text}</strap>`;
109
121
  break;
110
122
  case STAMP:
@@ -1,6 +1,8 @@
1
1
  <style>
2
2
  :scope {
3
- white-space: pre;
3
+ white-space: pre-wrap;
4
+ line-height: 1.36;
5
+ word-break: break-all;
4
6
  padding: 10px 20px;
5
7
  border-radius: 3px;
6
8
  display: inline-block;
@@ -92,10 +94,48 @@
92
94
  return text.replace(/[\<\>\|]/g, a => `&#${a.charCodeAt()};`);
93
95
  };
94
96
  var typescript = new compile$Javascript;
95
- typescript.straps = typescript.straps.concat("interface", "implements", "declare", "module", "readonly", "enum");
96
- typescript.tags[0].push(["{", "}"]);
97
+ typescript.straps = typescript.straps.concat(
98
+ "interface", "implements", "declare", "module", "namespace",
99
+ "readonly", "private", "asserts", "is",
100
+ "enum", "type");
101
+ typescript.tags[0].push("{");
97
102
  var js = new compile$Javascript;
98
- js.tags[0].push(["{", "}"]);
103
+ js.tags[0].push("{");
104
+ var json = new compile$Javascript;
105
+ json.inExpress = true;
106
+ var gl = new compile$Javascript;
107
+ gl.straps = gl.straps.concat(
108
+ "in", "out", "inout", "uniform", "buffer", "shared",
109
+ "highp", "mediump", "lowp",
110
+ "invariant", "const", "varying", "attribute",
111
+ "sampler2D", "texture2D",
112
+ "sampler3D", "texture3D",
113
+ "coherent", "volatile", "restrict", "readonly", "writeonly",
114
+ "flat", "noperspective", "smooth",
115
+ "packed", "shared", "std140", "std340", "row_major", "colum_major",
116
+ "location", "set", "binding", "offset", "index", "xfb_buffer", "xfb_offset", "local_size",
117
+ "void",
118
+ 'require', 'enable', 'disable', 'warn',
119
+ 'struct',
120
+ 'float', 'int',
121
+ 'vec4', 'vec3', 'vec2',
122
+ 'mat4', 'mat3', 'mat2',
123
+ 'bool', 'const', 'precision',
124
+ "step", "smoothstep",
125
+ "mix", "clamp"
126
+ );
127
+ var struct_reg = /^(while|do|for|with|switch|case|default|if|else|try|catch|finally)$/;
128
+
129
+ gl.setType = function (o) {
130
+ var { type } = o;
131
+ var queue = o.queue;
132
+ var last = o.prev;
133
+ if (type & (SCOPED | EXPRESS | PROPERTY)) {
134
+ if (last && last === queue[queue.length - 1] && last.type & (EXPRESS | STRAP | PROPERTY)) {
135
+ last.istype = !struct_reg.test(last.text);
136
+ }
137
+ }
138
+ }
99
139
  var codesupports = {
100
140
  javascript(a, blink) {
101
141
  if (blink) var index = a.indexOf(blink);
@@ -115,17 +155,41 @@
115
155
  codecolor(c, encode);
116
156
  return c.toString();
117
157
  },
158
+ json(a) {
159
+ var c = compile$scanner2(a, json);
160
+ codecolor(c, encode);
161
+ return c.toString();
162
+ },
163
+ glsl(a) {
164
+ var c = compile$scanner2(a, gl);
165
+ codecolor(c, encode);
166
+ return c.toString();
167
+ },
118
168
  html(a) {
119
169
  var code = compile$scanner2(a, 'html');
120
170
  var scoped = code.scoped;
121
- codecolor(code, encode);
122
171
  backEach(scoped.richNodes, n => {
123
172
  if (n.isScript) {
124
- var js = compile$scanner2(compile$common.createString(n));
125
- codecolor(js, encode);
173
+ var js = [];
174
+ compile$common.createString(n).replace(/^(\s*\<\!--)([\s\S]*)(--\!?\>\s*)$|^[\s\S]*$/, (m, p, a, f) => {
175
+ if (!a) {
176
+ js = compile$scanner2(m);
177
+ }
178
+ else {
179
+ js = compile$scanner2(a);
180
+ js.unshift(
181
+ { type: compile$common.COMMENT, text: p },
182
+ );
183
+ js.push(
184
+ { type: compile$common.COMMENT, text: f }
185
+ );
186
+ }
187
+ codecolor(js, encode);
188
+ });
126
189
  n.splice(0, n.length, ...js);
127
190
  }
128
191
  })
192
+ codecolor(code, encode);
129
193
  return code.toString();
130
194
  },
131
195
  css(a) {
@@ -134,11 +198,12 @@
134
198
  return c.toString();
135
199
  }
136
200
  };
201
+ codesupports.gl = codesupports.glsl;
137
202
  codesupports.cmd = codesupports.bat;
138
203
  codesupports.jsx = codesupports.js = codesupports.javascript;
139
204
  codesupports.tsx = codesupports.ts = codesupports.typescript;
140
- codesupports.xml = codesupports.html;
141
- var { SCOPED, QUOTED, SPACE, EXPRESS } = compile$common;
205
+ codesupports.jsp = codesupports.asp = codesupports.php = codesupports.xml = codesupports.html;
206
+ var { SCOPED, QUOTED, SPACE, STRAP, EXPRESS, PROPERTY } = compile$common;
142
207
  var patchBlink = function (code, index, blink) {
143
208
  for (var cx = 0, dx = code.length; cx < dx; cx++) {
144
209
  var c = code[cx];
@@ -209,7 +274,7 @@
209
274
  var minSpace = 0;
210
275
  for (var c of codes) {
211
276
  var m = /^\s*/.exec(c);
212
- if (m && m[0].length < c.length) {
277
+ if (m && m[0].length < minSpace) {
213
278
  minSpace = m[0].length;
214
279
  }
215
280
  }