efront 4.10.0 → 4.10.2

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.
@@ -1,7 +1,11 @@
1
- var shallowClone = function (origin, deep) {
2
- if (--deep < 0) return origin;
1
+ var shallowClone = function (origin, deep = /^[^\$\_]/) {
3
2
  if (!isObject(origin)) return origin;
4
3
  var temp = origin instanceof Array ? [] : {};
4
+ if (deep instanceof RegExp) {
5
+ for (var k in origin) if (deep.test(k)) temp[k] = origin[k];
6
+ return temp;
7
+ }
8
+ if (--deep < 0) return origin;
5
9
  if (deep > 0) for (var k in origin) temp[k] = shallowClone(origin[k], deep);
6
10
  else for (var k in origin) temp[k] = origin[k];
7
11
  return temp;
@@ -0,0 +1,16 @@
1
+ var sortRegister = function (list) {
2
+ var found = 0;
3
+ a: for (var cx = 0, dx = list.length; cx < dx; cx++) {
4
+ for (var cy = found + 1, dy = dx; cy < dy; cy++) {
5
+ if (cy !== cx && list[cy].indexOf(list[cx]) >= 0) continue a;
6
+ }
7
+ if (found !== cx) {
8
+ var temp = list[found];
9
+ list[found] = list[cx];
10
+ list[cx] = temp;
11
+ }
12
+ cx = found++;
13
+ }
14
+ return list;
15
+ }
16
+ module.exports = sortRegister;
@@ -1,3 +1,3 @@
1
1
  function nullish_(a, b) {
2
- return a === null || a === undefined ? b : a;
2
+ return a == null ? b : a;
3
3
  }
@@ -83,7 +83,7 @@ class Html extends Javascript {
83
83
  }
84
84
  var property = new Program;
85
85
  property.stamps = "=".split('');
86
- var p = new Program;
86
+ var p = new Javascript;
87
87
  var replaceISO8859 = function (data) {
88
88
  return String(data).replace(/<\!--([\s\S]*)--\>$/g, '$1').replace(/&\w+;/g, a => iso8859[a] || a).replace(/&#(\d+);/g, (_, a) => String.fromCodePoint(a))
89
89
  };
@@ -109,6 +109,7 @@ Html.prototype.createScoped = function (code) {
109
109
  var inScript = false;
110
110
  var noTag = true;
111
111
  var run = function (c) {
112
+
112
113
  switch (c.type) {
113
114
  case ELEMENT:
114
115
  var v = toCamelCase(c.tag);
@@ -155,6 +156,7 @@ Html.prototype.createScoped = function (code) {
155
156
  break;
156
157
  case QUOTED:
157
158
  case PIECE:
159
+
158
160
  if (c.length) {
159
161
  c.forEach(run);
160
162
  break;
@@ -181,6 +183,7 @@ Html.prototype.createScoped = function (code) {
181
183
  break;
182
184
  }
183
185
  };
186
+
184
187
  code.forEach(run);
185
188
  var envs = Object.create(null);
186
189
  for (var k in used) {
@@ -227,6 +230,7 @@ Html.prototype.createScoped = function (code) {
227
230
  scoped.envs = envs;
228
231
  scoped.vars = vars;
229
232
  scoped.used = used;
233
+
230
234
  return scoped;
231
235
  };
232
236
  Html.prototype.createString = common.createString;
@@ -30,3 +30,8 @@ test('<div>\\${${`<div></div>`}</div>');
30
30
  test('<div>$\\{${`<div></div>`}</div>');
31
31
  test('<div>$\\{${typeof `<div></div>`}</div>');
32
32
  test('<div>$\\{${\\a+typeof`<div></div>`}</div>', '<div>$\\{${\\a + typeof `<div></div>`}</div>');
33
+ test('${i18n`加载中..`}<div class="loader"></div>');
34
+ test('${a +typeof i18n`加载中..`}<div class="loader"></div>','${a + typeof i18n`加载中..`}<div class="loader"></div>');
35
+ test('${a > 1}');
36
+ test('a>1','a > 1');
37
+ test('a><a></a>','a > <a></a>');
@@ -40,31 +40,32 @@ return,typeof,delete,switch,export,import,static
40
40
  default,finally,extends
41
41
  function,continue,debugger
42
42
  instanceof`.trim().split(/[,\s]+/);
43
+ var colonstrap_reg = /^(case|default)$/;
43
44
  class Javascript extends Program {
44
45
  straps = straps;
45
46
  value_reg = /^(false|true|null|Infinity|NaN|undefined|eval)$/
46
47
  transive_reg = /^(new|var|let|const|yield|void|in|of|typeof|delete|case|return|await|default|instanceof|throw|extends|import|from)$/
47
48
  strapexp_reg = /^(new|void|typeof|delete|class|function|await)/;
48
49
  forceend_reg = /^(return|yield|break|continue|debugger|async)$/;
49
- classstrap_reg = /^(class|function|async)$/;
50
- colonstrap_reg = /^(case|default)$/;
51
-
52
50
  defaultType = EXPRESS;
53
51
  }
54
- var propresolve_reg = /^(static|get|set|async)$/;
52
+ var propresolve_reg = /^(static|get|set|async|readonly|private|pub)$/;
55
53
 
56
- Javascript.prototype.isProperty = function (o) {
54
+ var isProperty = function (o) {
57
55
  var queue = o.queue;
58
56
  var prev = o.prev;
59
57
  if (queue.isObject) {
60
- if (!prev || prev.type === STAMP && prev.text === ",") return true;
58
+ if (!prev || prev.type === STAMP && /^[,;]$/.test(prev.text)) return true;
61
59
  if (prev.type === STAMP && prev.isprop) return true;
62
60
  }
63
61
  if (queue.isClass) {
64
62
  if (!prev) return true;
63
+ if (o.type === SCOPED && o.entry !== '{') {
64
+ return prev.isprop || prev.type === STAMP && prev.text === ';' || isShortMethodEnd(prev);
65
+ }
65
66
  if (prev.type === STAMP) {
66
67
  if (prev.isprop) return true;
67
- return /^(\+\+|\-\-|;)$/.test(prev.text);
68
+ return /^(\+\+|\-\-|[,;])$/.test(prev.text) && (o.type !== STAMP || !/^[,;\=\:]$/.test(o.text));
68
69
  }
69
70
  if (prev.type === EXPRESS && !/\.$/.test(prev.text)) {
70
71
  return prev.text !== 'async' || o.text !== 'function';
@@ -81,13 +82,7 @@ Javascript.prototype.isProperty = function (o) {
81
82
  return false;
82
83
  };
83
84
  var setStrapExpress = function (mark_type, mark_text, prop, o, default_type) {
84
- var prev = o.prev;
85
- if (prev && prev.type === STRAP && /^(?:function|class|let|const|var)$/.test(prev.text)) {
86
- o.type = EXPRESS;
87
- return;
88
- }
89
85
  var type = o.type;
90
- if (type !== STRAP) return;
91
86
  var h = snapExpressHead(o);
92
87
  var isfunc = h?.prev?.type === STAMP && h.prev.text === '=>';
93
88
  var q = o.queue;
@@ -102,7 +97,7 @@ var setStrapExpress = function (mark_type, mark_text, prop, o, default_type) {
102
97
  if (q.entry === '(') {
103
98
  var pp = q.prev;
104
99
  }
105
- else if (q.entry === "{") a: {
100
+ else if (q.brace) a: {
106
101
  var p = q.prev;
107
102
  if (p) {
108
103
  if (p.type === STAMP && p.text === "=>") {
@@ -154,16 +149,14 @@ var setStrapExpress = function (mark_type, mark_text, prop, o, default_type) {
154
149
  }
155
150
  var setYieldExpress = setStrapExpress.bind(null, STAMP, "*", 'next');
156
151
  var setAwaitExpress = setStrapExpress.bind(null, STRAP, "async", 'prev');
157
- Javascript.prototype.fixType = function (o) {
152
+ var fixType = function (o) {
158
153
  var m = o.text;
159
- if (m === 'yield') setYieldExpress(o, this.defaultType);
160
- else if (m === 'await') setAwaitExpress(o, this.defaultType);
161
154
  var last = o.prev;
162
155
  var type = o.type;
163
156
  var queue = o.queue;
164
157
  switch (type) {
165
158
  case QUOTED:
166
- if (this.isProperty(o)) type = PROPERTY;
159
+ if (isProperty(o)) o.isprop = true;
167
160
  break;
168
161
  case SCOPED:
169
162
  if (o.entry === '(') {
@@ -173,14 +166,14 @@ Javascript.prototype.fixType = function (o) {
173
166
  }
174
167
  break;
175
168
  case EXPRESS:
176
- if ((!/^\./.test(m)) && this.isProperty(o)) type = PROPERTY;
169
+ if ((!/^\./.test(m)) && isProperty(o)) type = PROPERTY;
177
170
  break;
178
171
  case STRAP:
179
172
  case VALUE:
180
173
  if (last && last.type === EXPRESS && /[^\.]\.$/.test(last.text)) {
181
174
  type = EXPRESS;
182
175
  }
183
- else if (this.isProperty(o)) type = PROPERTY;
176
+ else if (isProperty(o)) type = PROPERTY;
184
177
  else if (m === 'from') {
185
178
  if (!last || last.type === STRAP && !/^(im|ex)port$/.test(last.text)) {
186
179
  type = EXPRESS;
@@ -218,12 +211,7 @@ Javascript.prototype.fixType = function (o) {
218
211
  }
219
212
  break;
220
213
  }
221
- if (type === STRAP && m === "class" && !queue.classed) {
222
- queue.classed = 1;
223
- }
224
- else if (queue.classed > 0) {
225
- if (type === STRAP && /^(class|function)$/.test(m)) queue.classed++;
226
- }
214
+ if (type === PROPERTY) o.isprop = true;
227
215
  o.type = type;
228
216
 
229
217
  };
@@ -278,12 +266,11 @@ var setObject = function (o) {
278
266
  }
279
267
  }
280
268
  };
281
- Javascript.prototype.detectLabel = function (o) {
269
+ var detectLabel = function (o) {
282
270
  var queue = o.queue;
283
271
  var last = queue.last;
284
272
  var m = o.text;
285
273
  var type = o.type;
286
- var colonstrap_reg = this.colonstrap_reg;
287
274
  var end = o.end;
288
275
  var inExpress = queue.inExpress;
289
276
  if (type === SPACE);
@@ -294,17 +281,25 @@ Javascript.prototype.detectLabel = function (o) {
294
281
  }
295
282
  else if (last) check: switch (m) {
296
283
  case "?":
284
+ if (last.isprop) {
285
+ o.type = EXPRESS;
286
+ o.isprop = true;
287
+ break;
288
+ }
297
289
  inExpress = true;
298
290
  if (!queue.question) queue.question = 1;
299
291
  else queue.question++;
300
292
  break;
301
293
  case "=":
302
- inExpress = true;
303
- if (last.type === SCOPED && last.entry === "{") {
294
+ if (last.type === SCOPED && last.brace) {
304
295
  if (!last.isObject) {
305
296
  setObject(last);
306
297
  }
307
298
  }
299
+ var lp = last.prev;
300
+ if (lp?.type === STRAP && lp.text === 'type') {
301
+ o.istype = true;
302
+ }
308
303
  case ",":
309
304
  if (queue.isObject) {
310
305
  if (last.type === PROPERTY) {
@@ -314,38 +309,52 @@ Javascript.prototype.detectLabel = function (o) {
314
309
  inExpress = true;
315
310
  break;
316
311
  case ":":
312
+
317
313
  if (queue.question) {
318
314
  queue.question--;
319
- inExpress = true;
315
+ if (last.type === STAMP && last.text === '?') {
316
+ inExpress = false;
317
+ o.istype = true;
318
+ last.istype = true;
319
+ last.type = EXPRESS;
320
+ }
321
+ else {
322
+ inExpress = true;
323
+ }
320
324
  break;
321
325
  }
322
326
  if (queue.isObject) {
323
- if (last.type === PROPERTY || last.isprop) {
324
- inExpress = true;
325
- break;
326
- }
327
- if (last.type === SCOPED && (!last.prev || !last.prev.type === STAMP && last.prev.text === ",")) {
328
- inExpress = true;
327
+ if (last.isprop) {
328
+ o.isExpress = false;
329
+ queue.inExpress = true;
330
+ return;
329
331
  }
332
+ }
333
+ inExpress = false;
334
+ if (queue.entry && (!queue.brace || queue.isClass)) {
335
+ o.istype = true;
330
336
  break;
331
337
  }
332
338
  var temp = last;
333
339
  while (temp) {
334
340
  if (temp.type === STRAP && colonstrap_reg.test(temp.text)) {
335
- inExpress = false;
336
341
  break check;
337
342
  }
338
343
  if (!temp.isExpress) break;
339
344
  temp = temp.prev;
340
345
  }
341
- inExpress = false;
342
- if (last.type & (EXPRESS | STRAP | VALUE | QUOTED)) {
346
+ if (!queue.isargl && last.type & (EXPRESS | STRAP | VALUE | QUOTED)) {
343
347
  // label
344
- last.type = LABEL;
345
- last.text += ":";
346
- last.end = end;
347
- return o;
348
+ var lp = last.prev;
349
+ if (!lp || lp.type !== STRAP || lp.isend) {
350
+ last.type = LABEL;
351
+ last.text += ":";
352
+ last.end = end;
353
+ queue.inExpress = false;
354
+ return o;
355
+ }
348
356
  }
357
+ o.istype = true;
349
358
  break;
350
359
  default:
351
360
  inExpress = true;
@@ -359,31 +368,58 @@ Javascript.prototype.detectLabel = function (o) {
359
368
  }
360
369
 
361
370
  Javascript.prototype.setType = function (o) {
362
- if (this.detectLabel(o)) return false;
371
+ if (detectLabel(o)) return false;
363
372
  var last = o.prev;
364
- if (o.type === EXPRESS && /^\.[^\.]|^\.$/.test(o.text) && last && last.type === STAMP && last.text === "?") {
365
- last.type = EXPRESS;
366
- var q = o.queue;
367
- q.question--;
368
- return false;
373
+ if (last?.type === STRAP && o.type === STRAP && this.type_reg.test(last.text)) {
374
+ if (/^(yield|await|async)$/.test(o.text)) o.type = EXPRESS;
375
+ }
376
+ if (o.type === STRAP) switch (o.text) {
377
+ case "yield": setYieldExpress(o, this.defaultType); break;
378
+ case "await": setAwaitExpress(o, this.defaultType); break;
379
+ }
380
+ if (o.type === EXPRESS && last?.type === EXPRESS && !last.isend && /^(async|await|yield)$/.test(last.text)) {
381
+ last.type = STRAP;
369
382
  }
383
+ var queue = o.queue;
384
+
370
385
  if (last) {
371
386
  if (o.type === STRAP && o.text === "function") {
372
387
  if (last.text === 'async' && !last.isend) last.type = STRAP;
373
388
  }
389
+ if ((o.type & (EXPRESS | STRAP) && last.type === STAMP || o.type === STAMP && /^([\|\&]|\=\>)$/.test(o.text)) && (last.istype || last.isargl)) {
390
+ o.istype = true;
391
+ }
392
+ if (queue.isargl) {
393
+ if (last.type === STAMP && /^[,;]$/.test(last.text)) {
394
+ o.isarg = true;
395
+ };
396
+ }
397
+ if (o.type === STAMP && o.needle) {
398
+ // o.type = EXPRESS;
399
+ }
374
400
  }
375
- this.fixType(o);
376
- var queue = o.queue;
401
+ else {
402
+ if (queue.isargl) {
403
+ o.isarg = true;
404
+ }
405
+ else if (queue.istype) {
406
+ o.istype = true;
407
+ }
408
+ }
409
+ if (o.isarg && o.type === STRAP) {
410
+ o.type = EXPRESS;
411
+ }
412
+
413
+ fixType(o);
377
414
  if (queue.isObject || queue.isClass) {
378
- if (o.type & (VALUE | QUOTED | STRAP)) {
379
- o.isprop = this.isProperty(o);
415
+ if (o.type & (VALUE | QUOTED | STRAP | ELEMENT)) {
416
+ o.isprop = isProperty(o);
380
417
  }
381
418
  else if (o.type === SCOPED) {
382
- if (o.entry === '[') {
383
- if (queue.isObject) o.isprop = this.isProperty(o);
384
- if (queue.isClass) o.isprop = !last || last.isprop || last.type === STAMP && last.text === ';' || isShortMethodEnd(last);
419
+ if (o.entry === '[' || o.entry === '(') {
420
+ o.isprop = isProperty(o);
385
421
  }
386
- else if (o.entry === "{") {
422
+ else if (o.brace) {
387
423
  if (last && last.type === PROPERTY && last.text === 'static') {
388
424
  last.type = STRAP;
389
425
  }
@@ -396,40 +432,30 @@ Javascript.prototype.setType = function (o) {
396
432
  o.isprop = true;
397
433
  }
398
434
  if (o.isprop) {
399
- if (last && last.type === PROPERTY && propresolve_reg.test(last.text)) {
435
+ if (last && last.type === PROPERTY && propresolve_reg.test(last.text) && (o.type !== SCOPED || o.entry === "[")) {
400
436
  last.type = STRAP;
401
437
  }
402
- if (queue.isClass) o.isend = false;
403
438
  }
404
439
  }
405
- if (o.type === PROPERTY || o.isprop);
406
- else if (o.type === STRAP && /^(get|set|static|async)$/.test(o.text)) {
407
- o.type = EXPRESS;
440
+ if (o.isprop);
441
+ else if (o.type === STRAP) {
442
+ if (this.type_reg.test(o.text) && !this.funcstrap_reg.test(o.text)) {
443
+ if (last) {
444
+ if (last.type === STRAP && last.transive && !last.isend || last.type === STAMP && queue.inExpress) {
445
+ o.type = EXPRESS;
446
+ }
447
+ }
448
+ }
449
+ if (propresolve_reg.test(o.text)) o.type = EXPRESS;
408
450
  }
409
451
  if (last) {
410
452
  if (o.type === STAMP && o.text === "=>") {
411
453
  var pp = last.prev;
412
- if (pp && pp.type === EXPRESS && pp.text === 'async') {
454
+ if (pp?.type === EXPRESS && pp.text === 'async') {
413
455
  if (!pp.isend) pp.type = STRAP;
414
456
  }
415
457
  }
416
458
  }
417
- if (o.type === STAMP) {
418
- if (!last || last.type & (STAMP | STRAP) && !/^(\+\+|\-\-)$/.test(last.text) || last.type === SCOPED && /^[\{\[]$/.test(last.entry) && !last.isExpress) {
419
- o.unary = /^[^=;,\*]$|.[^\=\>\<\|\&\^]$/.test(o.text);
420
- if (o.unary && /^(\+|\-)$/.test(o.text) && last && last.type === STAMP && /^(\+\+|\-\-)$/.test(last.text)) o.unary = !!last.unary;
421
- }
422
- if (last && /^(\+\+|\-\-)$/.test(o.text)) {
423
- var i = 1;
424
- var p = queue[queue.length - i];
425
- if (p === o) p = queue[queue.length - ++i];
426
- while (p && p.type & (SPACE | COMMENT)) {
427
- if (p.type === SPACE && /[\r\n\u2028\u2029]/.test(p.text)) break;
428
- p = queue[queue.length - ++i];
429
- }
430
- o.unary = !p || p.type & (SPACE | STAMP | STRAP) || p.type === EXPRESS && p.prev && p.prev.type === STAMP && /^(\+\+|\-\-)$/.test(p.prev.text) && p.prev.unary;
431
- }
432
- }
433
459
  };
434
460
 
435
461
  var js = new Javascript;
@@ -508,23 +534,18 @@ function detour(o, ie) {
508
534
  case SCOPED:
509
535
  detour(o.first, ie);
510
536
  break;
511
- case EXPRESS:
512
- var text = o.text.replace(/^\.\.\./, '');
513
- var hasdot = o.text.length !== text.length;
514
- if (context.avoidMap) {
515
- var m = /^[^\.\[\]]+/.exec(o.text);
516
- if (m) { context.avoidMap[m[0]] = true; }
517
- }
518
- if (/\?\.|\?\?/.test(text)) {
519
- o = snapExpressHead(o);
537
+ case STAMP:
538
+ if (o.text === "?.") {
539
+ var h = snapExpressHead(o);
520
540
  var f = snapExpressFoot(o);
541
+ o = h;
521
542
  var rest = [o];
522
- remove(o, f.prev);
523
543
  while (o !== f) {
524
544
  o = o.next;
525
545
  rest.push(o);
526
546
  }
527
547
  text = createString(rest);
548
+ remove(h, f.prev);
528
549
  text = renderExpress(text, false);
529
550
  if (hasdot) text = "..." + text;
530
551
  var o1 = scan(text);
@@ -534,6 +555,23 @@ function detour(o, ie) {
534
555
  o = o1.last;
535
556
  continue;
536
557
  }
558
+ else if (o.text === '.') {
559
+ var n = o.next;
560
+ remove(o);
561
+ if (n.type === EXPRESS) {
562
+ n.text = `[${strings.recode(n.text)}]`;
563
+ }
564
+ o = n;
565
+ continue;
566
+ }
567
+ break;
568
+ case EXPRESS:
569
+ var text = o.text.replace(/^\.\.\./, '');
570
+ var hasdot = o.text.length !== text.length;
571
+ if (context.avoidMap) {
572
+ var m = /^[^\.\[\]]+/.exec(o.text);
573
+ if (m) { context.avoidMap[m[0]] = true; }
574
+ }
537
575
  text = text.replace(/\.([^\.\[\!\=\:]+)/g, (_, a) => ie === undefined || context.strap_reg.test(a) || /#/.test(a) ? `[${strings.recode(a)}]` : _);
538
576
  if (hasdot) text = "..." + text;
539
577
  o.text = text;
@@ -614,7 +652,7 @@ function detour(o, ie) {
614
652
  }
615
653
  if (!o.isprop) break;
616
654
  case PROPERTY:
617
- if (!o.isend && /^(get|set|async|static)$/.test(o.text) && o.next && (o.next.type === PROPERTY || o.next.isprop)) break;
655
+ if (!o.isend && propresolve_reg.test(o.text) && o.next && (o.next.type === PROPERTY || o.next.isprop)) break;
618
656
  if (o.text === 'static' && o.next && o.next.type === SCOPED && o.next.entry === '{') break;
619
657
  if (/^\[/.test(o.text)) break;
620
658
  if (o.queue.isObject) {
@@ -637,7 +675,7 @@ function detour(o, ie) {
637
675
  var text = strings.recode(o.text);
638
676
  if (o.prev) {
639
677
  var prev = o.prev;
640
- if (prev && prev.isprop && !prev.isend && /^(get|set|static|async)$/.test(prev.text)) {
678
+ if (prev && prev.isprop && !prev.isend && propresolve_reg.test(prev.text)) {
641
679
  prev = prev.prev;
642
680
  }
643
681
  if (prev && prev.type === STAMP && prev.isprop) prev = prev.prev;
@@ -870,6 +908,17 @@ Javascript.prototype.fix = function (code) {
870
908
  }
871
909
  var requires = code.used.require;
872
910
  imports = imports.filter(m => {
911
+ if (m.next?.text === '.') {
912
+ var o = m;
913
+ var s = snapExpressFoot(o);
914
+ var a = [o];
915
+ while (o !== s) {
916
+ o = o.next;
917
+ a.push(o);
918
+ }
919
+ m.text = createString(a);
920
+ remove(m.next, s);
921
+ }
873
922
  if (/^import\.meta($|\.)/.test(m.text)) {
874
923
  m.text = m.text.replace(/\./, '_');
875
924
  return true;
@@ -1,9 +1,11 @@
1
1
  // 导入
2
+ var js = new Javascript;
2
3
  var testFix = function (a, e) {
3
- var c = scanner2(a);
4
+ var c = scanner2(a, js);
4
5
  c.fix();
5
6
  assert(c.toString(), e);
6
7
  }
8
+ js.debug = true;
7
9
  testFix(`import a from "a";console.log(a)`, 'var a = require("a"); console.log(a.default)');
8
10
  testFix(`import {a} from "a";console.log(a)`, 'var a1 = require("a"); console.log(a1.a)');
9
11
  testFix(`import a,{a as b} from "a";console.log(a,b)`, 'var a = require("a"); console.log(a.default, a.a)');
@@ -33,7 +35,7 @@ testDetour('1.e+10.a', '1e+10["a"]')
33
35
  testDetour('0x1.a', '0x1["a"]')
34
36
  testDetour('0b1.a', '0b1["a"]')
35
37
  testDetour('01.a', '0o1["a"]')
36
- testDetour('08.a', '08 a')
38
+ testDetour('08.a', '08["a"]')
37
39
  testDetour('0o1.a', '0o1["a"]')
38
40
  testDetour('0o1n.a', '0o1n["a"]')
39
41
  testDetour('0o1m.a', '0o1m["a"]')
@@ -41,4 +43,72 @@ testDetour('0o1i.a', '0o1i["a"]')
41
43
  testDetour('0o1j.a', '0o1j["a"]')
42
44
  testDetour('0o1k.a', '0o1k["a"]')
43
45
  testDetour('0o1l.a', '0o1l["a"]')
44
- testDetour('0o1ll.a', '0o1ll["a"]')
46
+ testDetour('0o1ll.a', '0o1ll["a"]')
47
+ var ts = new Javascript;
48
+ ts.straps.push('interface', 'implements', "declare", "module", "readonly", "enum", 'type');
49
+ ts.tags[0].push("{")
50
+ var testTypescript = function (text) {
51
+ var s = scanner2(text, ts);
52
+ return assert(s.toString(), text);
53
+ }
54
+ testTypescript(`const strict: Omit<typeof assert, 'equal' | 'notEqual' | 'deepEqual' | 'notDeepEqual' | 'ok' | 'strictEqual' | 'deepStrictEqual' | 'ifError' | 'strict'> & {
55
+ (value: unknown, message?: string | Error): asserts value;
56
+ equal: typeof strictEqual;
57
+ notEqual: typeof notStrictEqual;
58
+ deepEqual: typeof deepStrictEqual;
59
+ notDeepEqual: typeof notDeepStrictEqual;
60
+ // Mapped types and assertion functions are incompatible?
61
+ // TS2775: Assertions require every name in the call target
62
+ // to be declared with an explicit type annotation.
63
+ ok: typeof ok;
64
+ strictEqual: typeof strictEqual;
65
+ deepStrictEqual: typeof deepStrictEqual;
66
+ ifError: typeof ifError;
67
+ strict: typeof strict;
68
+ };`);
69
+ testTypescript(`
70
+ type ExecFileException =
71
+ & Omit<ExecException, 'code'>
72
+ & Omit<NodeJS.ErrnoException, 'code'>
73
+ & { code?: string | number | undefined | null };
74
+ function rejects(block: (() => Promise<unknown>) | Promise<unknown>, message?: string | Error): Promise<void>;
75
+ const exit<R, TArgs extends any[]>(callback: (...args: TArgs) => R, ...args: TArgs): R;
76
+ `)
77
+ testTypescript(`class AsyncLocalStorage<T> {
78
+ static snapshot(): (<R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs) => R) & {
79
+ asyncResource: AsyncResource;
80
+ };
81
+ }`);
82
+
83
+ testTypescript(`interface AsyncResourceOptions {
84
+ triggerAsyncId?: number | undefined;
85
+ requireManualDestroy?: boolean | undefined;
86
+ arrayBuffer(): Promise<ArrayBuffer>;
87
+ from(data: WithImplicitCoercion<Uint8Array | ReadonlyArray<number> | string>): Buffer;
88
+ getRandomValues<T extends Exclude<NodeJS.TypedArray, Float32Array | Float64Array>>(typedArray: T): T;
89
+ preopens?: NodeJS.Dict<string> | undefined;
90
+ function rejects(block: (() => Promise<unknown>) | Promise<unknown>, message?: string | Error): Promise<void>;
91
+ }`);
92
+
93
+ testTypescript(`
94
+ interface WritableOptions extends StreamOptions<Writable> {
95
+ decodeStrings?: boolean | undefined;
96
+ defaultEncoding?: BufferEncoding | undefined;
97
+ write?(this: Writable, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
98
+ writev?(
99
+ this: Writable,
100
+ chunks: Array<{
101
+ chunk: any;
102
+ encoding: BufferEncoding;
103
+ }>,
104
+ callback: (error?: Error | null) => void
105
+ ): void;
106
+ final?(this: Writable, callback: (error?: Error | null) => void): void;
107
+ }`);
108
+ common.debug = true;
109
+ testTypescript(`
110
+ while (++i < 2) {}
111
+ a ? function () {} : function () {}
112
+ declare module 'buffer' {}
113
+ a <= 1;
114
+ `)