efront 3.37.0 → 3.38.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.
@@ -91,18 +91,27 @@ var skipAssignment = function (o, cx) {
91
91
  next();
92
92
  needpunc = true;
93
93
  break;
94
+ case PROPERTY:
95
+ if (needpunc) break loop;
96
+ next();
97
+ break;
94
98
  case EXPRESS:
95
- if (/^\.|\.$/.test(o.text)) {
99
+ if (/^\.[^\.]/.test(o.text)) {
100
+ next();
101
+ break;
102
+ }
103
+ if (/\.$/.test(o.text)) {
104
+ needpunc = false;
96
105
  next();
97
106
  break;
98
107
  }
99
- else if (/^\[/.test(o.text)) {
108
+ if (/^\[/.test(o.text)) {
100
109
  needpunc = true;
101
110
  next();
102
111
  break;
103
112
  }
104
113
  case QUOTED:
105
- if (needpunc && /^`/.test(o.text || o.entry)) {
114
+ if (needpunc && /^`/.test(o.entry || o.text)) {
106
115
  needpunc = false;
107
116
  }
108
117
  case VALUE:
@@ -127,7 +136,7 @@ var skipAssignment = function (o, cx) {
127
136
  next();
128
137
  needpunc = false;
129
138
  }
130
- else if (/^(do|if|while|for|switch|with)/.test(o.text)) {
139
+ else if (/^(do|if|while|for|switch|with)$/.test(o.text)) {
131
140
  if (o.text === 'if') ifdeep++;
132
141
  next();
133
142
  next();
@@ -218,7 +227,7 @@ function snapSentenceHead(o) {
218
227
  o = p;
219
228
  continue;
220
229
  }
221
- if (/^(in|instanceof)/.test(p.text)) {
230
+ if (/^(in|instanceof)$/.test(p.text)) {
222
231
  o = p.prev;
223
232
  continue;
224
233
  }
@@ -241,28 +250,88 @@ function snapSentenceHead(o) {
241
250
  }
242
251
 
243
252
  var snapExpressHead = function (o) {
244
- if (!o || o.type !== EXPRESS) return;
253
+ if (!o || o.type & ~(EXPRESS | SCOPED | QUOTED)) return o;
254
+ var a = o;
245
255
  while (o && o.prev) {
246
256
  var p = o.prev;
247
- if (p.type & (EXPRESS | VALUE)) {
248
- if (o.type === SCOPED && o.entry === '[' || o.type === EXPRESS && /^\??\.[^\.]/.test(o.text) || /\.$/.test(p.text) && !p.isdigit) {
257
+ if (p && p.type === STRAP && p.text === 'new') return p;
258
+ if (o.type === SCOPED && o.entry !== '{'
259
+ || o.type === EXPRESS && /^(\??\.[^\.]|\[)/.test(o.text)
260
+ || /\.$/.test(p.text) && !p.isdigit
261
+ || o.type === QUOTED && (o.length || /^\`/.test(o.text))
262
+ ) {
263
+ if (p.type === SCOPED && p.entry === '(') {
264
+ var pp = p.prev;
265
+ if (pp && pp.type === STRAP && !p.transive) return o;
266
+ }
267
+ if (p.type & (EXPRESS | VALUE | QUOTED | SCOPED)) {
268
+ a = o;
249
269
  o = p;
250
270
  continue;
251
271
  }
252
272
  }
273
+ else if (o.type === SCOPED) {
274
+ var isclass = 0;
275
+ if (o.isObject) return o;
276
+ if (!o.isClass) {
277
+ if (p.type === SCOPED && p.entry === "(") {
278
+ p = p.prev;
279
+ if (p && p.type === EXPRESS) p = p.prev;
280
+ if (p && p.type === STAMP && p.text === '*') p = p.prev;
281
+ if (!p || p.type !== STRAP || !/^function$/.test(p.text)) return a;
282
+ if (p && p.type === STRAP && p.text === "new") p = p.prev;
283
+ return p;
284
+ }
285
+ return a;
286
+ }
287
+ while (o.isClass) {
288
+ isclass++;
289
+ o = o.prev;
290
+ }
291
+ var p = o;
292
+ while (o && isclass > 0) {
293
+ var p = o;
294
+ if (o.type === STRAP && o.text === 'class') {
295
+ isclass--;
296
+ }
297
+ o = o.prev;
298
+ }
299
+ if (p && p.type === STRAP && p.text === 'new') return p;
300
+ return p;
301
+ }
253
302
  break;
254
303
  }
255
304
  return o;
256
305
  };
306
+
257
307
  var snapExpressFoot = function (o) {
258
- if (!o || !(o.type & (EXPRESS | VALUE))) return;
259
308
  while (o && o.next) {
260
- var n = o.next;
261
- if (n.type === SCOPED && o.entry === '[' || /\.$/.test(o.text) && !o.isdigit || n.type === EXPRESS && /^\??\.[^\.]/.test(n.text)) {
262
- if (n.type & (EXPRESS | SCOPED)) {
263
- o = n;
264
- continue;
309
+ var n = null;
310
+ if (o.type & STRAP) {
311
+ n = o;
312
+ if (n.text === 'new') n = n.next;
313
+ if (n.text === 'function') {
314
+ while (n && n.type !== SCOPED || n.entry !== '{') n = n.next;
315
+ }
316
+ else if (n.text === 'class') {
317
+ var n = o;
318
+ while (n && !n.isClass) n = n.next;
319
+ while (n && n.isClass) n = n.next;
265
320
  }
321
+ else break;
322
+ o = n;
323
+ }
324
+ else if (o.type & (EXPRESS | QUOTED | VALUE | SCOPED)) {
325
+ n = o.next;
326
+ }
327
+ if (!n) break;
328
+ if (n.type === SCOPED && o.entry !== '{'
329
+ || /\.$/.test(o.text) && !o.isdigit
330
+ || n.type === EXPRESS && /^\??\.[^\.]/.test(n.text)
331
+ || n.type === QUOTED && (n.length || /^\`/.test(n.text))
332
+ ) {
333
+ o = n;
334
+ continue;
266
335
  }
267
336
  break;
268
337
  }
@@ -270,7 +339,7 @@ var snapExpressFoot = function (o) {
270
339
  };
271
340
  var createScoped = function (parsed, wash) {
272
341
  var used = Object.create(null); var vars = Object.create(null), lets = vars;
273
- var scoped = [], funcbody = scoped;
342
+ var scoped = [], funcbody = scoped, argscope = scoped, thisscope = scoped;
274
343
  scoped.body = parsed;
275
344
  scoped.isfunc = true;
276
345
  var run = function (o, id, body) {
@@ -324,24 +393,31 @@ var createScoped = function (parsed, wash) {
324
393
  if (o.prev && o.prev.type === EXPRESS) {
325
394
  if (/\.$/.test(o.prev.text)) break;
326
395
  }
327
- var u = o.text;
328
- if (/^\.\.\./.test(u)) u = u.slice(3);
329
- var u = u.replace(/^([^\.\[]*)[\s\S]*$/, '$1');
330
- if (!u) break;
331
- if (u === 'await' && funcbody.async !== false) {
396
+ if (o.text === 'await' && funcbody.async !== false) {
332
397
  o.type = STRAP;
333
398
  funcbody.async = true;
334
399
  continue;
335
400
  }
336
- if (u === 'yield' && funcbody.aster === true) {
337
- o.type = STRAP;
338
- continue;
401
+ if (o.text === 'yield') {
402
+ if (funcbody.aster === true) {
403
+ o.type = STRAP;
404
+ continue;
405
+ }
406
+ if ((!o.prev || o.prev.type !== STAMP || o.prev.text === ';') && (!o.next || o.next.type !== STAMP || o.next.text === '*')) {
407
+ o.type = STRAP;
408
+ funcbody.aster = true;
409
+ continue;
410
+ }
339
411
  }
340
412
  if (o.next && o.next.type === STAMP && o.next.text === "=>") {
341
413
  isScope = true;
342
414
  isArrow = true;
343
415
  }
344
416
  else {
417
+ var u = o.text;
418
+ if (/^\.\.\./.test(u)) u = u.slice(3);
419
+ var u = u.replace(/^([^\.\[]*)[\s\S]*$/, '$1');
420
+ if (!u) break;
345
421
  var prev = o.prev;
346
422
  if (prev && prev.type === STAMP && /^(?:\+\+|\-\-)$/.test(prev.text)) {
347
423
  var pp = prev.prev;
@@ -493,6 +569,8 @@ var createScoped = function (parsed, wash) {
493
569
  var _vars = vars;
494
570
  var _scoped = scoped;
495
571
  var _funcbody = funcbody;
572
+ var _argscope = argscope;
573
+ var _thisscope = thisscope;
496
574
  used = Object.create(null);
497
575
  lets = Object.create(null);
498
576
  vars = Object.create(null);
@@ -506,6 +584,8 @@ var createScoped = function (parsed, wash) {
506
584
  if (isFunction) {
507
585
  vars.this = true, vars.arguments = true;
508
586
  scoped.aster = isAster;
587
+ thisscope = scoped;
588
+ argscope = scoped;
509
589
  }
510
590
  scoped.async = isAsync;
511
591
  scoped.isfunc = true;
@@ -518,6 +598,8 @@ var createScoped = function (parsed, wash) {
518
598
  scoped.used = used;
519
599
  if (isClass) {
520
600
  lets.super = true;
601
+ lets.this = true;
602
+ thisscope = scoped;
521
603
  }
522
604
  }
523
605
  if (isArrow);
@@ -570,6 +652,7 @@ var createScoped = function (parsed, wash) {
570
652
  if (!o);
571
653
  else if (o.type === SCOPED && o.entry === "{") {
572
654
  scoped.body = o;
655
+ o.scoped = scoped;
573
656
  o.isExpress = isExpress;
574
657
  run(o.first);
575
658
  if (isArrow && id >= 0 && o) o = o.next;
@@ -592,7 +675,7 @@ var createScoped = function (parsed, wash) {
592
675
  var u = o;
593
676
  while (o !== next) {
594
677
  var n = run(o, 0);
595
- if (o === n) o = n.next;
678
+ if (o === n || n && n.entry === '{') o = n.next;
596
679
  else o = n;
597
680
  }
598
681
  }
@@ -638,14 +721,20 @@ var createScoped = function (parsed, wash) {
638
721
  mergeTo(_used, used);
639
722
  if (scoped.length) _scoped.push(scoped);
640
723
  }
641
- if (isFunction && vars.this) {
642
- delete vars.this;
643
- delete vars.arguments;
724
+ if (isArrow) {
725
+ if (!thisscope.insett && used.this) thisscope.insett = true;
726
+ if (!argscope.inseta && used.arguments) argscope.inseta = true;
644
727
  }
645
- if (isClass) delete lets.super;
646
- if (scoped.isfunc) {
728
+ if (isClass) delete lets.super, delete lets.this, thisscope = _thisscope;
729
+ if (isFunction) {
647
730
  if (used.yield) _scoped.yield = false;
648
731
  funcbody = _funcbody;
732
+ if (!isArrow) {
733
+ delete vars.this;
734
+ delete vars.arguments;
735
+ thisscope = _thisscope;
736
+ argscope = _argscope;
737
+ }
649
738
  }
650
739
  used = _used;
651
740
  lets = _lets;
@@ -672,6 +761,7 @@ var createScoped = function (parsed, wash) {
672
761
  delete envs.yield;
673
762
  delete used.yield;
674
763
  }
764
+ delete envs.eval;
675
765
  scoped.envs = envs;
676
766
  return scoped;
677
767
  };
@@ -716,13 +806,26 @@ var getDeclared = function (o, kind, queue) {
716
806
  continue;
717
807
  }
718
808
  }
809
+ case EXPRESS:
719
810
  case STRAP:
720
811
  case VALUE:
721
- case EXPRESS:
722
812
  var n = o.text.replace(/^\.\.\.|\.\.\.$/g, '');
723
813
  declared.push(n);
724
- if (!prop) prop = declared["..."] ? declared["..."][1] - index : `[${index}]`;
725
- if (n !== o.text) declared["..."] = [n, index];
814
+ var isdots = n !== o.text;
815
+ if (!isdots && !prop) {
816
+ if (queue && queue.entry === '{') {
817
+ if (o.type & (EXPRESS | STRAP)) {
818
+ if (/^\[/.test(o.text)) prop = o.text;
819
+ else if (!/\./.test(o.text)) prop = '.' + o.text;
820
+ else prop = `[${strings.encode(o.text)}]`;
821
+ }
822
+ else {
823
+ prop = `[${n}]`;
824
+ }
825
+ }
826
+ else prop = declared["..."] ? declared["..."][1] - index : `[${index}]`;
827
+ }
828
+ if (isdots) declared["..."] = [n, index];
726
829
  else attributes.push([prop, n]);
727
830
  o.kind = kind;
728
831
  saveTo(used, n, o);
@@ -856,7 +959,11 @@ var relink = function (list) {
856
959
  while (pi < cx) list[pi++].next = null;
857
960
  list.last = p;
858
961
  return list;
859
- }
962
+ };
963
+ var setqueue = function (list, queue = list) {
964
+ var v = { value: queue }
965
+ for (var o of list) Reflect.deleteProperty(o, 'queue'), Reflect.defineProperty(o, 'queue', v);
966
+ };
860
967
 
861
968
  var createString = function (parsed) {
862
969
  var keepspace = parsed.keepspace !== false;
@@ -870,8 +977,9 @@ var createString = function (parsed) {
870
977
  if ((QUOTED | SCOPED | STRAP | LABEL | COMMENT) & lasttype
871
978
  || prev.type === STAMP && !prev.unary
872
979
  ) {
873
- if (o.type !== EXPRESS || !/^\.[^\.]/.test(o.text) && !prev.tag && !o.tag) {
980
+ if (o.type !== EXPRESS || !/^(\.[^\.]|\[)/.test(o.text) && !prev.tag && !o.tag) {
874
981
  result.push(" ");
982
+ if (createString.debug && !o.text) console.log(o.type, o.text, o)
875
983
  lasttype = SPACE
876
984
  }
877
985
  }
@@ -950,7 +1058,7 @@ var createString = function (parsed) {
950
1058
  else result.pop();
951
1059
  }
952
1060
  }
953
- if (o.leave === "}" && (!o.next || o.next.type !== PIECE) && o[o.length - 1].type !== SPACE) {
1061
+ if (o.leave === "}" && o.entry === "{" && o[o.length - 1].type !== SPACE) {
954
1062
  if (keepspace) result.push(" ");
955
1063
  }
956
1064
  }
@@ -1004,6 +1112,7 @@ var rename = function (used, from, to) {
1004
1112
  if (list) for (var u of list) {
1005
1113
  if (!u) continue;
1006
1114
  var text = u.text;
1115
+ if (!u.origin) u.origin = from;
1007
1116
  var doted = /^\.\.\./.test(text);
1008
1117
  if (doted) text = text.slice(3);
1009
1118
  text = to + text.replace(/^[^\.\:\[]+/i, "");
@@ -1045,25 +1154,33 @@ var createExpressList = function (code) {
1045
1154
  }
1046
1155
  return list;
1047
1156
  };
1157
+ var splice = function (queue, index, size, ...args) {
1158
+ if (index < 0) index += queue.length;
1159
+ var p = queue[index];
1160
+ var n = queue[index + size - 1];
1161
+ var prev = p && p.prev;
1162
+ var next = n && n.next;
1163
+ var res = queue.splice(index, size, ...args);
1164
+ var previ = queue.lastIndexOf(prev, index);
1165
+ var nexti = queue.indexOf(next, index + args.length);
1166
+ if (previ < 0) previ = 0;
1167
+ if (nexti < 0) nexti = queue.length;
1168
+ else nexti++;
1169
+ var changedargs = queue.slice(previ, nexti);
1170
+ var pp = prev && prev.prev;
1171
+ var nn = next && next.next;
1172
+ relink(changedargs);
1173
+ if (prev) prev.prev = pp;
1174
+ else queue.first = changedargs.first;
1175
+ if (next) next.next = nn;
1176
+ else queue.last = changedargs.last;
1177
+ setqueue(args, queue);
1178
+ return res;
1179
+ };
1048
1180
  var replace = function (o, ...args) {
1049
1181
  var queue = o.queue;
1050
1182
  var i = queue.indexOf(o);
1051
- if (i >= 0) queue.splice(i, 1, ...args);
1052
- var prev = o.prev;
1053
- var next = o.next;
1054
- if (!args.length) {
1055
- if (prev) prev.next = next;
1056
- else queue.first = next;
1057
- if (next) next.prev = prev;
1058
- else queue.last = prev;
1059
- }
1060
- else {
1061
- if (prev) prev.next = args[0], args[0].prev = prev;
1062
- else queue.first = args[0];
1063
- if (next) next.prev = args[args.length - 1], args[args.length - 1].next = next;
1064
- else queue.last = args[args.length - 1];
1065
- }
1066
- return args.length ? args[0] : next;
1183
+ if (i >= 0) splice(queue, i, 1, ...args);
1067
1184
  };
1068
1185
 
1069
1186
  module.exports = {
@@ -1093,6 +1210,8 @@ module.exports = {
1093
1210
  saveTo,
1094
1211
  rename,
1095
1212
  relink,
1213
+ setqueue,
1096
1214
  replace,
1215
+ splice,
1097
1216
  mergeTo
1098
1217
  };