yuku-analyzer 0.5.35 → 0.5.37
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.
- package/README.md +1 -15
- package/decode.js +354 -426
- package/index.d.ts +6 -32
- package/module.js +9 -56
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ And node-level queries that work directly on AST nodes:
|
|
|
62
62
|
module.symbolOf(node) // the symbol a node declares or references
|
|
63
63
|
module.referenceOf(node) // the reference recorded for an identifier
|
|
64
64
|
module.scopeOf(node) // the innermost scope containing the node
|
|
65
|
+
module.parentOf(node) // the node that structurally contains it, or null
|
|
65
66
|
module.resolve("name") // scope-chain lookup, like the engine does at runtime
|
|
66
67
|
```
|
|
67
68
|
|
|
@@ -88,21 +89,6 @@ module.walk({
|
|
|
88
89
|
|
|
89
90
|
The walk mutates in place: `ctx.replace(node)`, `ctx.remove()`, `ctx.insertBefore(node)`, `ctx.insertAfter(node)`, plus `ctx.skip()` and `ctx.stop()`. Transform the AST during the walk and print it with [`yuku-codegen`](https://www.npmjs.com/package/yuku-codegen).
|
|
90
91
|
|
|
91
|
-
## Scanning without building the AST
|
|
92
|
-
|
|
93
|
-
`module.scan` visits the parsed node records directly in the binary buffer. Nothing is materialized unless you ask for it, and symbols and references resolve in index space:
|
|
94
|
-
|
|
95
|
-
```js
|
|
96
|
-
const writes = [];
|
|
97
|
-
module.scan({
|
|
98
|
-
Identifier(cursor) {
|
|
99
|
-
if (cursor.reference?.isWrite) writes.push(cursor.reference.name);
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
This answers questions like "every write to an imported binding across 10,000 files" without constructing a single AST object. For semantic queries like this, scanning runs about 4x faster than the equivalent walk, since it never builds the AST. Scan to find, walk to change.
|
|
105
|
-
|
|
106
92
|
## Closure analysis
|
|
107
93
|
|
|
108
94
|
`capturesOf` reports the free variables of any function: every outer binding it closes over, with the capturing reference sites and whether the function writes to the binding. Shadowing and aliasing are handled by the resolved reference table, not by name matching:
|
package/decode.js
CHANGED
|
@@ -231,7 +231,7 @@ const SymbolFlags = Object.freeze({
|
|
|
231
231
|
ValueSpace: 127,
|
|
232
232
|
TypeSpace: 952,
|
|
233
233
|
});
|
|
234
|
-
const
|
|
234
|
+
const CHILD_SLOTS = [
|
|
235
235
|
[2, 2],
|
|
236
236
|
[0, 2],
|
|
237
237
|
[0, 2, 0, 3, 0, 4, 0, 5],
|
|
@@ -239,6 +239,7 @@ const SCAN_CHILDREN = [
|
|
|
239
239
|
[2, 2],
|
|
240
240
|
[2, 2],
|
|
241
241
|
[2, 2, 0, 3],
|
|
242
|
+
[0, 2],
|
|
242
243
|
[0, 2, 0, 3],
|
|
243
244
|
[0, 2, 0, 3],
|
|
244
245
|
[0, 2, 0, 3, 0, 4],
|
|
@@ -403,184 +404,179 @@ const SCAN_CHILDREN = [
|
|
|
403
404
|
[],
|
|
404
405
|
[0, 2],
|
|
405
406
|
];
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
407
|
+
const IS_NODE = [
|
|
408
|
+
true,
|
|
409
|
+
true,
|
|
410
|
+
true,
|
|
411
|
+
true,
|
|
412
|
+
true,
|
|
413
|
+
true,
|
|
414
|
+
false,
|
|
415
|
+
false,
|
|
416
|
+
true,
|
|
417
|
+
true,
|
|
418
|
+
true,
|
|
419
|
+
true,
|
|
420
|
+
true,
|
|
421
|
+
true,
|
|
422
|
+
true,
|
|
423
|
+
true,
|
|
424
|
+
true,
|
|
425
|
+
true,
|
|
426
|
+
true,
|
|
427
|
+
true,
|
|
428
|
+
true,
|
|
429
|
+
true,
|
|
430
|
+
true,
|
|
431
|
+
true,
|
|
432
|
+
true,
|
|
433
|
+
true,
|
|
434
|
+
true,
|
|
435
|
+
true,
|
|
436
|
+
true,
|
|
437
|
+
true,
|
|
438
|
+
true,
|
|
439
|
+
true,
|
|
440
|
+
true,
|
|
441
|
+
true,
|
|
442
|
+
true,
|
|
443
|
+
true,
|
|
444
|
+
true,
|
|
445
|
+
true,
|
|
446
|
+
true,
|
|
447
|
+
true,
|
|
448
|
+
true,
|
|
449
|
+
true,
|
|
450
|
+
true,
|
|
451
|
+
true,
|
|
452
|
+
true,
|
|
453
|
+
true,
|
|
454
|
+
true,
|
|
455
|
+
true,
|
|
456
|
+
true,
|
|
457
|
+
true,
|
|
458
|
+
true,
|
|
459
|
+
true,
|
|
460
|
+
true,
|
|
461
|
+
true,
|
|
462
|
+
true,
|
|
463
|
+
true,
|
|
464
|
+
true,
|
|
465
|
+
true,
|
|
466
|
+
true,
|
|
467
|
+
true,
|
|
468
|
+
true,
|
|
469
|
+
true,
|
|
470
|
+
true,
|
|
471
|
+
true,
|
|
472
|
+
true,
|
|
473
|
+
true,
|
|
474
|
+
true,
|
|
475
|
+
true,
|
|
476
|
+
true,
|
|
477
|
+
true,
|
|
478
|
+
true,
|
|
479
|
+
true,
|
|
480
|
+
true,
|
|
481
|
+
true,
|
|
482
|
+
true,
|
|
483
|
+
true,
|
|
484
|
+
true,
|
|
485
|
+
true,
|
|
486
|
+
true,
|
|
487
|
+
true,
|
|
488
|
+
true,
|
|
489
|
+
true,
|
|
490
|
+
true,
|
|
491
|
+
true,
|
|
492
|
+
true,
|
|
493
|
+
true,
|
|
494
|
+
true,
|
|
495
|
+
true,
|
|
496
|
+
true,
|
|
497
|
+
true,
|
|
498
|
+
true,
|
|
499
|
+
true,
|
|
500
|
+
true,
|
|
501
|
+
true,
|
|
502
|
+
true,
|
|
503
|
+
true,
|
|
504
|
+
true,
|
|
505
|
+
true,
|
|
506
|
+
true,
|
|
507
|
+
true,
|
|
508
|
+
true,
|
|
509
|
+
true,
|
|
510
|
+
true,
|
|
511
|
+
true,
|
|
512
|
+
true,
|
|
513
|
+
true,
|
|
514
|
+
true,
|
|
515
|
+
true,
|
|
516
|
+
true,
|
|
517
|
+
true,
|
|
518
|
+
true,
|
|
519
|
+
true,
|
|
520
|
+
true,
|
|
521
|
+
true,
|
|
522
|
+
true,
|
|
523
|
+
true,
|
|
524
|
+
true,
|
|
525
|
+
true,
|
|
526
|
+
true,
|
|
527
|
+
true,
|
|
528
|
+
true,
|
|
529
|
+
true,
|
|
530
|
+
true,
|
|
531
|
+
true,
|
|
532
|
+
true,
|
|
533
|
+
true,
|
|
534
|
+
true,
|
|
535
|
+
true,
|
|
536
|
+
true,
|
|
537
|
+
true,
|
|
538
|
+
true,
|
|
539
|
+
true,
|
|
540
|
+
true,
|
|
541
|
+
true,
|
|
542
|
+
true,
|
|
543
|
+
true,
|
|
544
|
+
true,
|
|
545
|
+
true,
|
|
546
|
+
true,
|
|
547
|
+
true,
|
|
548
|
+
true,
|
|
549
|
+
true,
|
|
550
|
+
true,
|
|
551
|
+
true,
|
|
552
|
+
true,
|
|
553
|
+
true,
|
|
554
|
+
true,
|
|
555
|
+
true,
|
|
556
|
+
true,
|
|
557
|
+
true,
|
|
558
|
+
true,
|
|
559
|
+
true,
|
|
560
|
+
true,
|
|
561
|
+
true,
|
|
562
|
+
true,
|
|
563
|
+
true,
|
|
564
|
+
true,
|
|
565
|
+
true,
|
|
566
|
+
true,
|
|
567
|
+
true,
|
|
568
|
+
true,
|
|
569
|
+
true,
|
|
570
|
+
true,
|
|
571
|
+
true,
|
|
572
|
+
true,
|
|
573
|
+
true,
|
|
574
|
+
true,
|
|
575
|
+
true,
|
|
576
|
+
true,
|
|
577
|
+
true,
|
|
578
|
+
true,
|
|
577
579
|
];
|
|
578
|
-
const TAG_CHOICES = new Map([
|
|
579
|
-
[3, ["FunctionDeclaration", "FunctionExpression", "TSDeclareFunction", "TSEmptyBodyFunctionExpression"]],
|
|
580
|
-
[26, ["ClassDeclaration", "ClassExpression"]],
|
|
581
|
-
[28, ["MethodDefinition", "TSAbstractMethodDefinition"]],
|
|
582
|
-
[29, ["PropertyDefinition", "AccessorProperty", "TSAbstractPropertyDefinition", "TSAbstractAccessorProperty"]],
|
|
583
|
-
]);
|
|
584
580
|
function buildPosMap(src, byteLen, startByte) {
|
|
585
581
|
const m = new Uint32Array(byteLen - startByte + 1);
|
|
586
582
|
const len = src.length;
|
|
@@ -774,30 +770,31 @@ function decode(buffer, source) {
|
|
|
774
770
|
case 4: return { type: "BlockStatement", start, end, body: nodeArr(f1, f0) };
|
|
775
771
|
case 5: return { type: "BlockStatement", start, end, body: nodeArr(f1, f0) };
|
|
776
772
|
case 6: return { params: fnParams(i) };
|
|
777
|
-
case 7: return
|
|
778
|
-
case 8: return { type: "
|
|
779
|
-
case 9: return { type: "
|
|
780
|
-
case 10: return {
|
|
773
|
+
case 7: return node(f1);
|
|
774
|
+
case 8: return { type: "BinaryExpression", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, operator: BINARY_OPS[flags & 31] };
|
|
775
|
+
case 9: return { type: "LogicalExpression", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, operator: LOGICAL_OPS[flags & 3] };
|
|
776
|
+
case 10: return { type: "ConditionalExpression", start, end, test: f1 !== NULL ? node(f1) : null, consequent: f2 !== NULL ? node(f2) : null, alternate: f3 !== NULL ? node(f3) : null };
|
|
777
|
+
case 11: return {
|
|
781
778
|
type: "UnaryExpression", start, end,
|
|
782
779
|
operator: UNARY_OPS[flags & 7], prefix: true,
|
|
783
780
|
argument: f1 !== NULL ? node(f1) : null,
|
|
784
781
|
};
|
|
785
|
-
case
|
|
786
|
-
case
|
|
787
|
-
case
|
|
788
|
-
case
|
|
789
|
-
case
|
|
790
|
-
case
|
|
791
|
-
case
|
|
792
|
-
case
|
|
793
|
-
case
|
|
794
|
-
case
|
|
795
|
-
case
|
|
796
|
-
case
|
|
797
|
-
case
|
|
798
|
-
case
|
|
799
|
-
case
|
|
800
|
-
case
|
|
782
|
+
case 12: return { type: "UpdateExpression", start, end, argument: f1 !== NULL ? node(f1) : null, operator: UPDATE_OPS[flags & 1], prefix: !!(flags & 2) };
|
|
783
|
+
case 13: return { type: "AssignmentExpression", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, operator: ASSIGNMENT_OPS[flags & 15] };
|
|
784
|
+
case 14: return { type: "ArrayExpression", start, end, elements: nodeArrHoles(f1, f0) };
|
|
785
|
+
case 15: return { type: "ObjectExpression", start, end, properties: nodeArr(f1, f0) };
|
|
786
|
+
case 16: return { type: "SpreadElement", start, end, argument: f1 !== NULL ? node(f1) : null };
|
|
787
|
+
case 17: { const r = { type: "Property", start, end, key: f1 !== NULL ? node(f1) : null, value: f2 !== NULL ? node(f2) : null, kind: PROPERTY_KINDS[flags & 3], method: !!(flags & 4), shorthand: !!(flags & 8), computed: !!(flags & 16) }; if (_isTs) { r.optional = false; } return r; }
|
|
788
|
+
case 18: return { type: "MemberExpression", start, end, object: f1 !== NULL ? node(f1) : null, property: f2 !== NULL ? node(f2) : null, computed: !!(flags & 1), optional: !!(flags & 2) };
|
|
789
|
+
case 19: { const r = { type: "CallExpression", start, end, callee: f1 !== NULL ? node(f1) : null, arguments: nodeArr(f2, f0), optional: !!(flags & 1) }; if (_isTs) { r.typeArguments = f3 !== NULL ? node(f3) : null; } return r; }
|
|
790
|
+
case 20: return { type: "ChainExpression", start, end, expression: f1 !== NULL ? node(f1) : null };
|
|
791
|
+
case 21: { const r = { type: "TaggedTemplateExpression", start, end, tag: f1 !== NULL ? node(f1) : null, quasi: f2 !== NULL ? node(f2) : null }; if (_isTs) { r.typeArguments = f3 !== NULL ? node(f3) : null; } return r; }
|
|
792
|
+
case 22: { const r = { type: "NewExpression", start, end, callee: f1 !== NULL ? node(f1) : null, arguments: nodeArr(f2, f0) }; if (_isTs) { r.typeArguments = f3 !== NULL ? node(f3) : null; } return r; }
|
|
793
|
+
case 23: return { type: "AwaitExpression", start, end, argument: f1 !== NULL ? node(f1) : null };
|
|
794
|
+
case 24: return { type: "YieldExpression", start, end, argument: f1 !== NULL ? node(f1) : null, delegate: !!(flags & 1) };
|
|
795
|
+
case 25: return { type: "MetaProperty", start, end, meta: f1 !== NULL ? node(f1) : null, property: f2 !== NULL ? node(f2) : null };
|
|
796
|
+
case 26: return { type: "Decorator", start, end, expression: f1 !== NULL ? node(f1) : null };
|
|
797
|
+
case 27: {
|
|
801
798
|
const r = {
|
|
802
799
|
type: CLASS_TYPES[flags & 1], start, end,
|
|
803
800
|
decorators: nodeArr(f1, f0),
|
|
@@ -814,8 +811,8 @@ function decode(buffer, source) {
|
|
|
814
811
|
}
|
|
815
812
|
return r;
|
|
816
813
|
}
|
|
817
|
-
case
|
|
818
|
-
case
|
|
814
|
+
case 28: return { type: "ClassBody", start, end, body: nodeArr(f1, f0) };
|
|
815
|
+
case 29: {
|
|
819
816
|
const r = {
|
|
820
817
|
type: "MethodDefinition", start, end,
|
|
821
818
|
decorators: nodeArr(f1, f0),
|
|
@@ -832,7 +829,7 @@ function decode(buffer, source) {
|
|
|
832
829
|
}
|
|
833
830
|
return r;
|
|
834
831
|
}
|
|
835
|
-
case
|
|
832
|
+
case 30: {
|
|
836
833
|
const _acc = !!(flags & 4);
|
|
837
834
|
const r = {
|
|
838
835
|
type: _acc ? "AccessorProperty" : "PropertyDefinition",
|
|
@@ -858,13 +855,13 @@ function decode(buffer, source) {
|
|
|
858
855
|
}
|
|
859
856
|
return r;
|
|
860
857
|
}
|
|
861
|
-
case
|
|
862
|
-
case
|
|
863
|
-
case
|
|
858
|
+
case 31: return { type: "StaticBlock", start, end, body: nodeArr(f1, f0) };
|
|
859
|
+
case 32: return { type: "Super", start, end };
|
|
860
|
+
case 33: return {
|
|
864
861
|
type: "Literal", start, end,
|
|
865
862
|
value: str(f1, f2), raw: _src.slice(start, end),
|
|
866
863
|
};
|
|
867
|
-
case
|
|
864
|
+
case 34: {
|
|
868
865
|
const r = _src.slice(start, end);
|
|
869
866
|
const s = r.indexOf("_") === -1 ? r : r.replace(/_/g, "");
|
|
870
867
|
const v = (flags & 3) === 2 && s[1] !== "o" && s[1] !== "O"
|
|
@@ -876,7 +873,7 @@ function decode(buffer, source) {
|
|
|
876
873
|
raw: r,
|
|
877
874
|
};
|
|
878
875
|
}
|
|
879
|
-
case
|
|
876
|
+
case 35: {
|
|
880
877
|
const r = _src.slice(start, end);
|
|
881
878
|
const d = str(f1, f2).replace(/_/g, "");
|
|
882
879
|
const v = BigInt(d);
|
|
@@ -885,16 +882,16 @@ function decode(buffer, source) {
|
|
|
885
882
|
value: v, raw: r, bigint: v.toString(),
|
|
886
883
|
};
|
|
887
884
|
}
|
|
888
|
-
case
|
|
885
|
+
case 36: {
|
|
889
886
|
const v = !!(flags & 1);
|
|
890
887
|
return {
|
|
891
888
|
type: "Literal", start, end,
|
|
892
889
|
value: v, raw: v ? "true" : "false",
|
|
893
890
|
};
|
|
894
891
|
}
|
|
895
|
-
case
|
|
896
|
-
case
|
|
897
|
-
case
|
|
892
|
+
case 37: return { type: "Literal", start, end, value: null, raw: "null" };
|
|
893
|
+
case 38: return { type: "ThisExpression", start, end };
|
|
894
|
+
case 39: {
|
|
898
895
|
const p = str(f1, f2), fl = str(f3, f4);
|
|
899
896
|
let v = null;
|
|
900
897
|
try { v = new RegExp(p, fl); } catch {}
|
|
@@ -904,8 +901,8 @@ function decode(buffer, source) {
|
|
|
904
901
|
regex: { pattern: p, flags: fl.split("").sort().join("") },
|
|
905
902
|
};
|
|
906
903
|
}
|
|
907
|
-
case
|
|
908
|
-
case
|
|
904
|
+
case 40: return { type: "TemplateLiteral", start, end, quasis: nodeArr(f1, f0), expressions: nodeArr(f2, f3) };
|
|
905
|
+
case 41: {
|
|
909
906
|
const raw = _src.slice(start, end).replace(/\r\n?/g, "\n");
|
|
910
907
|
const tl = !!(flags & 1);
|
|
911
908
|
const s = _isTs ? start - 1 : start;
|
|
@@ -919,39 +916,39 @@ function decode(buffer, source) {
|
|
|
919
916
|
tail: tl,
|
|
920
917
|
};
|
|
921
918
|
}
|
|
922
|
-
case
|
|
923
|
-
case
|
|
924
|
-
case
|
|
925
|
-
case 44: { const r = { type: "Identifier", start, end, name: str(f1, f2) }; if (_isTs) { r.decorators = []; r.optional = false; r.typeAnnotation = null; } return r; }
|
|
919
|
+
case 42: { const r = { type: "Identifier", start, end, name: str(f1, f2) }; if (_isTs) { r.decorators = []; r.optional = false; r.typeAnnotation = null; } return r; }
|
|
920
|
+
case 43: return { type: "PrivateIdentifier", start, end, name: str(f1, f2) };
|
|
921
|
+
case 44: { const r = { type: "Identifier", start, end, name: str(f1, f2) }; if (_isTs) { r.decorators = nodeArr(f3, f0); r.typeAnnotation = f4 !== NULL ? node(f4) : null; r.optional = !!(flags & 1); } return r; }
|
|
926
922
|
case 45: { const r = { type: "Identifier", start, end, name: str(f1, f2) }; if (_isTs) { r.decorators = []; r.optional = false; r.typeAnnotation = null; } return r; }
|
|
927
|
-
case 46: { const r = { type: "
|
|
928
|
-
case 47:
|
|
929
|
-
case 48: return { type: "
|
|
930
|
-
case 49: return { type: "
|
|
931
|
-
case 50: return { type: "
|
|
932
|
-
case 51: return { type: "
|
|
933
|
-
case 52: return { type: "
|
|
934
|
-
case 53: return { type: "
|
|
935
|
-
case 54: return { type: "
|
|
936
|
-
case 55: return { type: "
|
|
937
|
-
case 56: return { type: "
|
|
938
|
-
case 57: return { type: "
|
|
939
|
-
case 58: return { type: "
|
|
940
|
-
case 59: return { type: "
|
|
941
|
-
case 60: return { type: "
|
|
942
|
-
case 61: return { type: "
|
|
943
|
-
case 62: return { type: "
|
|
944
|
-
case 63: return { type: "
|
|
945
|
-
case 64: return { type: "
|
|
946
|
-
case 65:
|
|
947
|
-
case 66: { const r = { type: "
|
|
948
|
-
case 67: return
|
|
923
|
+
case 46: { const r = { type: "Identifier", start, end, name: str(f1, f2) }; if (_isTs) { r.decorators = []; r.optional = false; r.typeAnnotation = null; } return r; }
|
|
924
|
+
case 47: { const r = { type: "ExpressionStatement", start, end, expression: f1 !== NULL ? node(f1) : null }; if (_isTs) { r.directive = null; } return r; }
|
|
925
|
+
case 48: return { type: "IfStatement", start, end, test: f1 !== NULL ? node(f1) : null, consequent: f2 !== NULL ? node(f2) : null, alternate: f3 !== NULL ? node(f3) : null };
|
|
926
|
+
case 49: return { type: "SwitchStatement", start, end, discriminant: f1 !== NULL ? node(f1) : null, cases: nodeArr(f2, f0) };
|
|
927
|
+
case 50: return { type: "SwitchCase", start, end, test: f1 !== NULL ? node(f1) : null, consequent: nodeArr(f2, f0) };
|
|
928
|
+
case 51: return { type: "ForStatement", start, end, init: f1 !== NULL ? node(f1) : null, test: f2 !== NULL ? node(f2) : null, update: f3 !== NULL ? node(f3) : null, body: f4 !== NULL ? node(f4) : null };
|
|
929
|
+
case 52: return { type: "ForInStatement", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, body: f3 !== NULL ? node(f3) : null };
|
|
930
|
+
case 53: return { type: "ForOfStatement", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null, body: f3 !== NULL ? node(f3) : null, await: !!(flags & 1) };
|
|
931
|
+
case 54: return { type: "WhileStatement", start, end, test: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
|
|
932
|
+
case 55: return { type: "DoWhileStatement", start, end, body: f1 !== NULL ? node(f1) : null, test: f2 !== NULL ? node(f2) : null };
|
|
933
|
+
case 56: return { type: "BreakStatement", start, end, label: f1 !== NULL ? node(f1) : null };
|
|
934
|
+
case 57: return { type: "ContinueStatement", start, end, label: f1 !== NULL ? node(f1) : null };
|
|
935
|
+
case 58: return { type: "LabeledStatement", start, end, label: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
|
|
936
|
+
case 59: return { type: "WithStatement", start, end, object: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
|
|
937
|
+
case 60: return { type: "ReturnStatement", start, end, argument: f1 !== NULL ? node(f1) : null };
|
|
938
|
+
case 61: return { type: "ThrowStatement", start, end, argument: f1 !== NULL ? node(f1) : null };
|
|
939
|
+
case 62: return { type: "TryStatement", start, end, block: f1 !== NULL ? node(f1) : null, handler: f2 !== NULL ? node(f2) : null, finalizer: f3 !== NULL ? node(f3) : null };
|
|
940
|
+
case 63: return { type: "CatchClause", start, end, param: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null };
|
|
941
|
+
case 64: return { type: "DebuggerStatement", start, end };
|
|
942
|
+
case 65: return { type: "EmptyStatement", start, end };
|
|
943
|
+
case 66: { const r = { type: "VariableDeclaration", start, end, kind: VAR_KINDS[flags & 7], declarations: nodeArr(f1, f0) }; if (_isTs) { r.declare = !!(flags & 8); } return r; }
|
|
944
|
+
case 67: { const r = { type: "VariableDeclarator", start, end, id: f1 !== NULL ? node(f1) : null, init: f2 !== NULL ? node(f2) : null }; if (_isTs) { r.definite = !!(flags & 1); } return r; }
|
|
945
|
+
case 68: return {
|
|
949
946
|
type: "ExpressionStatement", start, end,
|
|
950
947
|
expression: node(f1), directive: str(f2, f3),
|
|
951
948
|
};
|
|
952
|
-
case
|
|
953
|
-
case
|
|
954
|
-
case
|
|
949
|
+
case 69: { const r = { type: "AssignmentPattern", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null }; if (_isTs) { r.decorators = nodeArr(f3, f0); r.typeAnnotation = f4 !== NULL ? node(f4) : null; r.optional = !!(flags & 1); } return r; }
|
|
950
|
+
case 70: { const r = { type: "RestElement", start, end, argument: f1 !== NULL ? node(f1) : null }; if (_isTs) { r.decorators = nodeArr(f2, f0); r.typeAnnotation = f3 !== NULL ? node(f3) : null; r.optional = !!(flags & 1); r.value = null; } return r; }
|
|
951
|
+
case 71: {
|
|
955
952
|
const el = nodeArrHoles(f1, f0);
|
|
956
953
|
if (f2 !== NULL) el.push(node(f2));
|
|
957
954
|
const r = { type: "ArrayPattern", start, end, elements: el };
|
|
@@ -962,7 +959,7 @@ function decode(buffer, source) {
|
|
|
962
959
|
}
|
|
963
960
|
return r;
|
|
964
961
|
}
|
|
965
|
-
case
|
|
962
|
+
case 72: {
|
|
966
963
|
const pr = nodeArr(f1, f0);
|
|
967
964
|
if (f2 !== NULL) pr.push(node(f2));
|
|
968
965
|
const r = { type: "ObjectPattern", start, end, properties: pr };
|
|
@@ -973,7 +970,7 @@ function decode(buffer, source) {
|
|
|
973
970
|
}
|
|
974
971
|
return r;
|
|
975
972
|
}
|
|
976
|
-
case
|
|
973
|
+
case 73: {
|
|
977
974
|
const r = {
|
|
978
975
|
type: "Property", start, end,
|
|
979
976
|
kind: "init",
|
|
@@ -982,7 +979,7 @@ function decode(buffer, source) {
|
|
|
982
979
|
shorthand: !!(flags & 1),
|
|
983
980
|
computed: !!(flags & 2),
|
|
984
981
|
}; if (_isTs) { r.optional = false; } return r; }
|
|
985
|
-
case
|
|
982
|
+
case 74: return {
|
|
986
983
|
type: "Program", start, end,
|
|
987
984
|
sourceType: (flags & 1) ? "module" : "script",
|
|
988
985
|
hashbang: (flags & 2) ? {
|
|
@@ -992,71 +989,71 @@ function decode(buffer, source) {
|
|
|
992
989
|
} : null,
|
|
993
990
|
body: nodeArr(f1, f0),
|
|
994
991
|
};
|
|
995
|
-
case
|
|
996
|
-
case
|
|
997
|
-
case
|
|
998
|
-
case
|
|
999
|
-
case
|
|
1000
|
-
case
|
|
1001
|
-
case
|
|
1002
|
-
case
|
|
1003
|
-
case
|
|
1004
|
-
case
|
|
1005
|
-
case
|
|
1006
|
-
case
|
|
1007
|
-
case
|
|
1008
|
-
case
|
|
1009
|
-
case
|
|
1010
|
-
case
|
|
1011
|
-
case
|
|
1012
|
-
case
|
|
1013
|
-
case
|
|
1014
|
-
case
|
|
1015
|
-
case
|
|
1016
|
-
case
|
|
1017
|
-
case
|
|
1018
|
-
case
|
|
1019
|
-
case
|
|
1020
|
-
case
|
|
1021
|
-
case
|
|
1022
|
-
case
|
|
1023
|
-
case
|
|
1024
|
-
case
|
|
1025
|
-
case
|
|
1026
|
-
case
|
|
1027
|
-
case
|
|
1028
|
-
case
|
|
1029
|
-
case
|
|
1030
|
-
case
|
|
1031
|
-
case
|
|
1032
|
-
case
|
|
1033
|
-
case
|
|
1034
|
-
case
|
|
1035
|
-
case
|
|
1036
|
-
case
|
|
1037
|
-
case
|
|
1038
|
-
case
|
|
1039
|
-
case
|
|
1040
|
-
case
|
|
1041
|
-
case
|
|
1042
|
-
case
|
|
1043
|
-
case
|
|
1044
|
-
case
|
|
992
|
+
case 75: return { type: "ImportExpression", start, end, source: f1 !== NULL ? node(f1) : null, options: f2 !== NULL ? node(f2) : null, phase: (flags & 1) ? ["source", "defer"][(flags >> 1) & 1] : null };
|
|
993
|
+
case 76: { const r = { type: "ImportDeclaration", start, end, specifiers: nodeArr(f1, f0), source: f2 !== NULL ? node(f2) : null, attributes: nodeArr(f3, f4), phase: (flags & 1) ? ["source", "defer"][(flags >> 1) & 1] : null }; if (_isTs) { r.importKind = IMPORT_EXPORT_KINDS[(flags >> 2) & 1]; } return r; }
|
|
994
|
+
case 77: { const r = { type: "ImportSpecifier", start, end, imported: f1 !== NULL ? node(f1) : null, local: f2 !== NULL ? node(f2) : null }; if (_isTs) { r.importKind = IMPORT_EXPORT_KINDS[flags & 1]; } return r; }
|
|
995
|
+
case 78: return { type: "ImportDefaultSpecifier", start, end, local: f1 !== NULL ? node(f1) : null };
|
|
996
|
+
case 79: return { type: "ImportNamespaceSpecifier", start, end, local: f1 !== NULL ? node(f1) : null };
|
|
997
|
+
case 80: return { type: "ImportAttribute", start, end, key: f1 !== NULL ? node(f1) : null, value: f2 !== NULL ? node(f2) : null };
|
|
998
|
+
case 81: { const r = { type: "ExportNamedDeclaration", start, end, declaration: f1 !== NULL ? node(f1) : null, specifiers: nodeArr(f2, f0), source: f3 !== NULL ? node(f3) : null, attributes: nodeArr(f4, f5) }; if (_isTs) { r.exportKind = IMPORT_EXPORT_KINDS[flags & 1]; } return r; }
|
|
999
|
+
case 82: { const r = { type: "ExportDefaultDeclaration", start, end, declaration: f1 !== NULL ? node(f1) : null }; if (_isTs) { r.exportKind = "value"; } return r; }
|
|
1000
|
+
case 83: { const r = { type: "ExportAllDeclaration", start, end, exported: f1 !== NULL ? node(f1) : null, source: f2 !== NULL ? node(f2) : null, attributes: nodeArr(f3, f0) }; if (_isTs) { r.exportKind = IMPORT_EXPORT_KINDS[flags & 1]; } return r; }
|
|
1001
|
+
case 84: { const r = { type: "ExportSpecifier", start, end, local: f1 !== NULL ? node(f1) : null, exported: f2 !== NULL ? node(f2) : null }; if (_isTs) { r.exportKind = IMPORT_EXPORT_KINDS[flags & 1]; } return r; }
|
|
1002
|
+
case 85: return { type: "TSTypeAnnotation", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null };
|
|
1003
|
+
case 86: return { type: "TSAnyKeyword", start, end };
|
|
1004
|
+
case 87: return { type: "TSUnknownKeyword", start, end };
|
|
1005
|
+
case 88: return { type: "TSNeverKeyword", start, end };
|
|
1006
|
+
case 89: return { type: "TSVoidKeyword", start, end };
|
|
1007
|
+
case 90: return { type: "TSNullKeyword", start, end };
|
|
1008
|
+
case 91: return { type: "TSUndefinedKeyword", start, end };
|
|
1009
|
+
case 92: return { type: "TSStringKeyword", start, end };
|
|
1010
|
+
case 93: return { type: "TSNumberKeyword", start, end };
|
|
1011
|
+
case 94: return { type: "TSBigIntKeyword", start, end };
|
|
1012
|
+
case 95: return { type: "TSBooleanKeyword", start, end };
|
|
1013
|
+
case 96: return { type: "TSSymbolKeyword", start, end };
|
|
1014
|
+
case 97: return { type: "TSObjectKeyword", start, end };
|
|
1015
|
+
case 98: return { type: "TSIntrinsicKeyword", start, end };
|
|
1016
|
+
case 99: return { type: "TSThisType", start, end };
|
|
1017
|
+
case 100: return { type: "TSTypeReference", start, end, typeName: f1 !== NULL ? node(f1) : null, typeArguments: f2 !== NULL ? node(f2) : null };
|
|
1018
|
+
case 101: return { type: "TSQualifiedName", start, end, left: f1 !== NULL ? node(f1) : null, right: f2 !== NULL ? node(f2) : null };
|
|
1019
|
+
case 102: return { type: "TSTypeQuery", start, end, exprName: f1 !== NULL ? node(f1) : null, typeArguments: f2 !== NULL ? node(f2) : null };
|
|
1020
|
+
case 103: return { type: "TSImportType", start, end, source: f1 !== NULL ? node(f1) : null, options: f2 !== NULL ? node(f2) : null, qualifier: f3 !== NULL ? node(f3) : null, typeArguments: f4 !== NULL ? node(f4) : null };
|
|
1021
|
+
case 104: return { type: "TSTypeParameter", start, end, name: f1 !== NULL ? node(f1) : null, constraint: f2 !== NULL ? node(f2) : null, default: f3 !== NULL ? node(f3) : null, in: !!(flags & 1), out: !!(flags & 2), const: !!(flags & 4) };
|
|
1022
|
+
case 105: return { type: "TSTypeParameterDeclaration", start, end, params: nodeArr(f1, f0) };
|
|
1023
|
+
case 106: return { type: "TSTypeParameterInstantiation", start, end, params: nodeArr(f1, f0) };
|
|
1024
|
+
case 107: return { type: "TSLiteralType", start, end, literal: f1 !== NULL ? node(f1) : null };
|
|
1025
|
+
case 108: return { type: "TSTemplateLiteralType", start, end, quasis: nodeArr(f1, f0), types: nodeArr(f2, f3) };
|
|
1026
|
+
case 109: return { type: "TSArrayType", start, end, elementType: f1 !== NULL ? node(f1) : null };
|
|
1027
|
+
case 110: return { type: "TSIndexedAccessType", start, end, objectType: f1 !== NULL ? node(f1) : null, indexType: f2 !== NULL ? node(f2) : null };
|
|
1028
|
+
case 111: return { type: "TSTupleType", start, end, elementTypes: nodeArr(f1, f0) };
|
|
1029
|
+
case 112: return { type: "TSNamedTupleMember", start, end, label: f1 !== NULL ? node(f1) : null, elementType: f2 !== NULL ? node(f2) : null, optional: !!(flags & 1) };
|
|
1030
|
+
case 113: return { type: "TSOptionalType", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null };
|
|
1031
|
+
case 114: return { type: "TSRestType", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null };
|
|
1032
|
+
case 115: return { type: "TSJSDocNullableType", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null, postfix: !!(flags & 1) };
|
|
1033
|
+
case 116: return { type: "TSJSDocNonNullableType", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null, postfix: !!(flags & 1) };
|
|
1034
|
+
case 117: return { type: "TSJSDocUnknownType", start, end };
|
|
1035
|
+
case 118: return { type: "TSUnionType", start, end, types: nodeArr(f1, f0) };
|
|
1036
|
+
case 119: return { type: "TSIntersectionType", start, end, types: nodeArr(f1, f0) };
|
|
1037
|
+
case 120: return { type: "TSConditionalType", start, end, checkType: f1 !== NULL ? node(f1) : null, extendsType: f2 !== NULL ? node(f2) : null, trueType: f3 !== NULL ? node(f3) : null, falseType: f4 !== NULL ? node(f4) : null };
|
|
1038
|
+
case 121: return { type: "TSInferType", start, end, typeParameter: f1 !== NULL ? node(f1) : null };
|
|
1039
|
+
case 122: return { type: "TSTypeOperator", start, end, operator: TS_TYPE_OPERATORS[flags & 3], typeAnnotation: f1 !== NULL ? node(f1) : null };
|
|
1040
|
+
case 123: return { type: "TSParenthesizedType", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null };
|
|
1041
|
+
case 124: return {
|
|
1045
1042
|
type: "TSFunctionType", start, end,
|
|
1046
1043
|
typeParameters: f1 !== NULL ? node(f1) : null,
|
|
1047
1044
|
params: f2 !== NULL ? fnParams(f2) : [],
|
|
1048
1045
|
returnType: f3 !== NULL ? node(f3) : null,
|
|
1049
1046
|
};
|
|
1050
|
-
case
|
|
1047
|
+
case 125: return {
|
|
1051
1048
|
type: "TSConstructorType", start, end,
|
|
1052
1049
|
abstract: !!(flags & 1),
|
|
1053
1050
|
typeParameters: f1 !== NULL ? node(f1) : null,
|
|
1054
1051
|
params: f2 !== NULL ? fnParams(f2) : [],
|
|
1055
1052
|
returnType: f3 !== NULL ? node(f3) : null,
|
|
1056
1053
|
};
|
|
1057
|
-
case
|
|
1058
|
-
case
|
|
1059
|
-
case
|
|
1054
|
+
case 126: return { type: "TSTypePredicate", start, end, parameterName: f1 !== NULL ? node(f1) : null, typeAnnotation: f2 !== NULL ? node(f2) : null, asserts: !!(flags & 1) };
|
|
1055
|
+
case 127: return { type: "TSTypeLiteral", start, end, members: nodeArr(f1, f0) };
|
|
1056
|
+
case 128: return {
|
|
1060
1057
|
type: "TSMappedType", start, end,
|
|
1061
1058
|
key: node(f1),
|
|
1062
1059
|
constraint: node(f2),
|
|
@@ -1065,8 +1062,8 @@ function decode(buffer, source) {
|
|
|
1065
1062
|
optional: TS_MAPPED_OPTIONAL[(flags >> 0) & 3],
|
|
1066
1063
|
readonly: TS_MAPPED_READONLY[(flags >> 2) & 3],
|
|
1067
1064
|
};
|
|
1068
|
-
case
|
|
1069
|
-
case
|
|
1065
|
+
case 129: { const r = { type: "TSPropertySignature", start, end, key: f1 !== NULL ? node(f1) : null, typeAnnotation: f2 !== NULL ? node(f2) : null, computed: !!(flags & 1), optional: !!(flags & 2), readonly: !!(flags & 4) }; if (_isTs) { r.accessibility = null; r.static = false; } return r; }
|
|
1066
|
+
case 130: return {
|
|
1070
1067
|
type: "TSMethodSignature", start, end,
|
|
1071
1068
|
key: node(f1),
|
|
1072
1069
|
computed: !!(flags & 4),
|
|
@@ -1077,28 +1074,28 @@ function decode(buffer, source) {
|
|
|
1077
1074
|
returnType: f4 !== NULL ? node(f4) : null,
|
|
1078
1075
|
accessibility: null, readonly: false, static: false,
|
|
1079
1076
|
};
|
|
1080
|
-
case
|
|
1077
|
+
case 131: return {
|
|
1081
1078
|
type: "TSCallSignatureDeclaration", start, end,
|
|
1082
1079
|
typeParameters: f1 !== NULL ? node(f1) : null,
|
|
1083
1080
|
params: f2 !== NULL ? fnParams(f2) : [],
|
|
1084
1081
|
returnType: f3 !== NULL ? node(f3) : null,
|
|
1085
1082
|
};
|
|
1086
|
-
case
|
|
1083
|
+
case 132: return {
|
|
1087
1084
|
type: "TSConstructSignatureDeclaration", start, end,
|
|
1088
1085
|
typeParameters: f1 !== NULL ? node(f1) : null,
|
|
1089
1086
|
params: f2 !== NULL ? fnParams(f2) : [],
|
|
1090
1087
|
returnType: f3 !== NULL ? node(f3) : null,
|
|
1091
1088
|
};
|
|
1092
|
-
case
|
|
1093
|
-
case
|
|
1094
|
-
case
|
|
1095
|
-
case
|
|
1096
|
-
case
|
|
1097
|
-
case
|
|
1098
|
-
case
|
|
1099
|
-
case
|
|
1100
|
-
case
|
|
1101
|
-
case
|
|
1089
|
+
case 133: { const r = { type: "TSIndexSignature", start, end, parameters: nodeArr(f1, f0), typeAnnotation: f2 !== NULL ? node(f2) : null, readonly: !!(flags & 1) }; if (_isTs) { r.static = !!(flags & 2); r.accessibility = null; } return r; }
|
|
1090
|
+
case 134: return { type: "TSTypeAliasDeclaration", start, end, id: f1 !== NULL ? node(f1) : null, typeParameters: f2 !== NULL ? node(f2) : null, typeAnnotation: f3 !== NULL ? node(f3) : null, declare: !!(flags & 1) };
|
|
1091
|
+
case 135: return { type: "TSInterfaceDeclaration", start, end, id: f1 !== NULL ? node(f1) : null, typeParameters: f2 !== NULL ? node(f2) : null, extends: nodeArr(f3, f0), body: f4 !== NULL ? node(f4) : null, declare: !!(flags & 1) };
|
|
1092
|
+
case 136: return { type: "TSInterfaceBody", start, end, body: nodeArr(f1, f0) };
|
|
1093
|
+
case 137: return { type: "TSInterfaceHeritage", start, end, expression: f1 !== NULL ? node(f1) : null, typeArguments: f2 !== NULL ? node(f2) : null };
|
|
1094
|
+
case 138: return { type: "TSClassImplements", start, end, expression: f1 !== NULL ? node(f1) : null, typeArguments: f2 !== NULL ? node(f2) : null };
|
|
1095
|
+
case 139: return { type: "TSEnumDeclaration", start, end, id: f1 !== NULL ? node(f1) : null, body: f2 !== NULL ? node(f2) : null, const: !!(flags & 1), declare: !!(flags & 2) };
|
|
1096
|
+
case 140: return { type: "TSEnumBody", start, end, members: nodeArr(f1, f0) };
|
|
1097
|
+
case 141: return { type: "TSEnumMember", start, end, id: f1 !== NULL ? node(f1) : null, initializer: f2 !== NULL ? node(f2) : null, computed: !!(flags & 1) };
|
|
1098
|
+
case 142: {
|
|
1102
1099
|
const r = {
|
|
1103
1100
|
type: "TSModuleDeclaration", start, end,
|
|
1104
1101
|
id: node(f1),
|
|
@@ -1109,48 +1106,48 @@ function decode(buffer, source) {
|
|
|
1109
1106
|
if (f2 !== NULL) r.body = node(f2);
|
|
1110
1107
|
return r;
|
|
1111
1108
|
}
|
|
1112
|
-
case
|
|
1113
|
-
case
|
|
1109
|
+
case 143: return { type: "TSModuleBlock", start, end, body: nodeArr(f1, f0) };
|
|
1110
|
+
case 144: return {
|
|
1114
1111
|
type: "TSModuleDeclaration", start, end,
|
|
1115
1112
|
id: node(f1), body: node(f2),
|
|
1116
1113
|
kind: "global",
|
|
1117
1114
|
declare: !!(flags & 1),
|
|
1118
1115
|
global: true,
|
|
1119
1116
|
};
|
|
1120
|
-
case
|
|
1121
|
-
case
|
|
1117
|
+
case 145: { const r = { type: "TSParameterProperty", start, end, decorators: nodeArr(f1, f0), parameter: f2 !== NULL ? node(f2) : null, override: !!(flags & 1), readonly: !!(flags & 2), accessibility: ACCESSIBILITY[(flags >> 2) & 3] }; if (_isTs) { r.static = false; } return r; }
|
|
1118
|
+
case 146: return {
|
|
1122
1119
|
type: "Identifier", start, end,
|
|
1123
1120
|
decorators: [],
|
|
1124
1121
|
name: "this", optional: false,
|
|
1125
1122
|
typeAnnotation: f1 !== NULL ? node(f1) : null,
|
|
1126
1123
|
};
|
|
1127
|
-
case
|
|
1128
|
-
case
|
|
1129
|
-
case
|
|
1130
|
-
case
|
|
1131
|
-
case
|
|
1132
|
-
case
|
|
1133
|
-
case
|
|
1134
|
-
case
|
|
1135
|
-
case
|
|
1136
|
-
case
|
|
1137
|
-
case
|
|
1138
|
-
case
|
|
1139
|
-
case
|
|
1140
|
-
case
|
|
1141
|
-
case
|
|
1142
|
-
case
|
|
1143
|
-
case
|
|
1144
|
-
case
|
|
1145
|
-
case
|
|
1146
|
-
case
|
|
1147
|
-
case
|
|
1148
|
-
case
|
|
1149
|
-
case
|
|
1124
|
+
case 147: return { type: "TSAsExpression", start, end, expression: f1 !== NULL ? node(f1) : null, typeAnnotation: f2 !== NULL ? node(f2) : null };
|
|
1125
|
+
case 148: return { type: "TSSatisfiesExpression", start, end, expression: f1 !== NULL ? node(f1) : null, typeAnnotation: f2 !== NULL ? node(f2) : null };
|
|
1126
|
+
case 149: return { type: "TSTypeAssertion", start, end, typeAnnotation: f1 !== NULL ? node(f1) : null, expression: f2 !== NULL ? node(f2) : null };
|
|
1127
|
+
case 150: return { type: "TSNonNullExpression", start, end, expression: f1 !== NULL ? node(f1) : null };
|
|
1128
|
+
case 151: return { type: "TSInstantiationExpression", start, end, expression: f1 !== NULL ? node(f1) : null, typeArguments: f2 !== NULL ? node(f2) : null };
|
|
1129
|
+
case 152: return { type: "TSExportAssignment", start, end, expression: f1 !== NULL ? node(f1) : null };
|
|
1130
|
+
case 153: return { type: "TSNamespaceExportDeclaration", start, end, id: f1 !== NULL ? node(f1) : null };
|
|
1131
|
+
case 154: return { type: "TSImportEqualsDeclaration", start, end, id: f1 !== NULL ? node(f1) : null, moduleReference: f2 !== NULL ? node(f2) : null, importKind: IMPORT_EXPORT_KINDS[flags & 1] };
|
|
1132
|
+
case 155: return { type: "TSExternalModuleReference", start, end, expression: f1 !== NULL ? node(f1) : null };
|
|
1133
|
+
case 156: return { type: "JSXElement", start, end, openingElement: f1 !== NULL ? node(f1) : null, children: nodeArr(f2, f0), closingElement: f3 !== NULL ? node(f3) : null };
|
|
1134
|
+
case 157: { const r = { type: "JSXOpeningElement", start, end, name: f1 !== NULL ? node(f1) : null, attributes: nodeArr(f2, f0), selfClosing: !!(flags & 1) }; if (_isTs) { r.typeArguments = f3 !== NULL ? node(f3) : null; } return r; }
|
|
1135
|
+
case 158: return { type: "JSXClosingElement", start, end, name: f1 !== NULL ? node(f1) : null };
|
|
1136
|
+
case 159: return { type: "JSXFragment", start, end, openingFragment: f1 !== NULL ? node(f1) : null, children: nodeArr(f2, f0), closingFragment: f3 !== NULL ? node(f3) : null };
|
|
1137
|
+
case 160: return { type: "JSXOpeningFragment", start, end };
|
|
1138
|
+
case 161: return { type: "JSXClosingFragment", start, end };
|
|
1139
|
+
case 162: return { type: "JSXIdentifier", start, end, name: str(f1, f2) };
|
|
1140
|
+
case 163: return { type: "JSXNamespacedName", start, end, namespace: f1 !== NULL ? node(f1) : null, name: f2 !== NULL ? node(f2) : null };
|
|
1141
|
+
case 164: return { type: "JSXMemberExpression", start, end, object: f1 !== NULL ? node(f1) : null, property: f2 !== NULL ? node(f2) : null };
|
|
1142
|
+
case 165: return { type: "JSXAttribute", start, end, name: f1 !== NULL ? node(f1) : null, value: f2 !== NULL ? node(f2) : null };
|
|
1143
|
+
case 166: return { type: "JSXSpreadAttribute", start, end, argument: f1 !== NULL ? node(f1) : null };
|
|
1144
|
+
case 167: return { type: "JSXExpressionContainer", start, end, expression: f1 !== NULL ? node(f1) : null };
|
|
1145
|
+
case 168: return { type: "JSXEmptyExpression", start, end };
|
|
1146
|
+
case 169: {
|
|
1150
1147
|
const t = str(f1, f2);
|
|
1151
1148
|
return { type: "JSXText", start, end, value: t, raw: t };
|
|
1152
1149
|
}
|
|
1153
|
-
case
|
|
1150
|
+
case 170: return { type: "JSXSpreadChild", start, end, expression: f1 !== NULL ? node(f1) : null };
|
|
1154
1151
|
}
|
|
1155
1152
|
}
|
|
1156
1153
|
const _inner = _attached ? nodeWithComments : _decode;
|
|
@@ -1161,7 +1158,7 @@ function decode(buffer, source) {
|
|
|
1161
1158
|
if (m !== undefined) return m;
|
|
1162
1159
|
const r = _inner(i);
|
|
1163
1160
|
_nodes[i] = r;
|
|
1164
|
-
if (r !== null && typeof r === "object") _nodeIndexes.set(r, i);
|
|
1161
|
+
if (r !== null && typeof r === "object" && !_nodeIndexes.has(r)) _nodeIndexes.set(r, i);
|
|
1165
1162
|
return r;
|
|
1166
1163
|
}
|
|
1167
1164
|
const _nodesU32 = _nodesOff >> 2;
|
|
@@ -1233,103 +1230,34 @@ function decode(buffer, source) {
|
|
|
1233
1230
|
}
|
|
1234
1231
|
return out;
|
|
1235
1232
|
}
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
return _isTs && (flags & 64)
|
|
1242
|
-
? "TSAbstractMethodDefinition"
|
|
1243
|
-
: "MethodDefinition";
|
|
1244
|
-
default: {
|
|
1245
|
-
const acc = (flags & 4) !== 0;
|
|
1246
|
-
if (_isTs && (flags & 256)) {
|
|
1247
|
-
return acc ? "TSAbstractAccessorProperty" : "TSAbstractPropertyDefinition";
|
|
1248
|
-
}
|
|
1249
|
-
return acc ? "AccessorProperty" : "PropertyDefinition";
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
function scan(visitors) {
|
|
1254
|
-
const handlers = new Map();
|
|
1255
|
-
let every = null;
|
|
1256
|
-
for (const k of Object.keys(visitors)) {
|
|
1257
|
-
const v = visitors[k];
|
|
1258
|
-
if (typeof v !== "function") continue;
|
|
1259
|
-
if (k === "enter") every = v;
|
|
1260
|
-
else handlers.set(k, v);
|
|
1261
|
-
}
|
|
1262
|
-
const wanted = new Array(TAG_TYPES.length).fill(null);
|
|
1263
|
-
for (let t = 0; t < TAG_TYPES.length; t++) {
|
|
1264
|
-
const tt = TAG_TYPES[t];
|
|
1265
|
-
if (tt === null) continue;
|
|
1266
|
-
if (tt === 0) {
|
|
1267
|
-
for (const c of TAG_CHOICES.get(t)) {
|
|
1268
|
-
if (handlers.has(c)) { wanted[t] = 0; break; }
|
|
1269
|
-
}
|
|
1270
|
-
} else {
|
|
1271
|
-
const h = handlers.get(tt);
|
|
1272
|
-
if (h !== undefined) wanted[t] = h;
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
let stopFlag = false, skipFlag = false;
|
|
1276
|
-
let curIndex = 0, curO = 0, curTag = 0;
|
|
1277
|
-
const cursor = {
|
|
1278
|
-
get index() { return curIndex; },
|
|
1279
|
-
get type() {
|
|
1280
|
-
const t = TAG_TYPES[curTag];
|
|
1281
|
-
return t !== 0 ? t : _scanType(curTag, _u8[curO + 2] | (_u8[curO + 3] << 8));
|
|
1282
|
-
},
|
|
1283
|
-
get start() { return startOf(curIndex); },
|
|
1284
|
-
get end() { return endOf(curIndex); },
|
|
1285
|
-
node() { return node(curIndex); },
|
|
1286
|
-
skip() { skipFlag = true; },
|
|
1287
|
-
stop() { stopFlag = true; },
|
|
1288
|
-
};
|
|
1289
|
-
(function visit(i) {
|
|
1233
|
+
let _parentArr;
|
|
1234
|
+
function _parents() {
|
|
1235
|
+
if (_parentArr !== undefined) return _parentArr;
|
|
1236
|
+
const p = new Int32Array(nodeCount).fill(-1);
|
|
1237
|
+
(function visit(i, parent) {
|
|
1290
1238
|
const o = _nodesOff + i * 48;
|
|
1291
1239
|
const tag = _u8[o];
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
curIndex = i; curO = o; curTag = tag;
|
|
1295
|
-
if (h === 0) {
|
|
1296
|
-
h = handlers.get(_scanType(tag, _u8[o + 2] | (_u8[o + 3] << 8))) ?? null;
|
|
1297
|
-
}
|
|
1298
|
-
if (every !== null && TAG_TYPES[tag] !== null) {
|
|
1299
|
-
every(cursor);
|
|
1300
|
-
if (stopFlag) return;
|
|
1301
|
-
}
|
|
1302
|
-
if (h !== null) {
|
|
1303
|
-
h(cursor);
|
|
1304
|
-
if (stopFlag) return;
|
|
1305
|
-
}
|
|
1306
|
-
if (skipFlag) { skipFlag = false; return; }
|
|
1307
|
-
}
|
|
1308
|
-
const ops = SCAN_CHILDREN[tag];
|
|
1240
|
+
if (IS_NODE[tag]) { p[i] = parent; parent = i; }
|
|
1241
|
+
const ops = CHILD_SLOTS[tag];
|
|
1309
1242
|
const b = o >> 2;
|
|
1310
|
-
for (let
|
|
1311
|
-
const slot = ops[
|
|
1312
|
-
if (ops[
|
|
1243
|
+
for (let q = 0; q < ops.length; q += 2) {
|
|
1244
|
+
const slot = ops[q + 1];
|
|
1245
|
+
if (ops[q] === 0) {
|
|
1313
1246
|
const c = _u32[b + slot];
|
|
1314
|
-
if (c !== NULL)
|
|
1315
|
-
visit(c);
|
|
1316
|
-
if (stopFlag) return;
|
|
1317
|
-
}
|
|
1247
|
+
if (c !== NULL) visit(c, parent);
|
|
1318
1248
|
} else {
|
|
1319
1249
|
const s = _u32[b + slot];
|
|
1320
|
-
const len = ops[
|
|
1250
|
+
const len = ops[q] === 1
|
|
1321
1251
|
? _u32[b + slot + 1]
|
|
1322
1252
|
: _u8[o + 4] | (_u8[o + 5] << 8);
|
|
1323
1253
|
for (let j = 0; j < len; j++) {
|
|
1324
1254
|
const c = _u32[_extraBase + s + j];
|
|
1325
|
-
if (c !== NULL)
|
|
1326
|
-
visit(c);
|
|
1327
|
-
if (stopFlag) return;
|
|
1328
|
-
}
|
|
1255
|
+
if (c !== NULL) visit(c, parent);
|
|
1329
1256
|
}
|
|
1330
1257
|
}
|
|
1331
1258
|
}
|
|
1332
|
-
})(progIdx);
|
|
1259
|
+
})(progIdx, -1);
|
|
1260
|
+
return (_parentArr = p);
|
|
1333
1261
|
}
|
|
1334
1262
|
let _semView;
|
|
1335
1263
|
function _semantic() {
|
|
@@ -1456,9 +1384,9 @@ function decode(buffer, source) {
|
|
|
1456
1384
|
}
|
|
1457
1385
|
return { line: lo, column: offset - ls[lo - 1] };
|
|
1458
1386
|
},
|
|
1459
|
-
scan,
|
|
1460
1387
|
nodeOf: node,
|
|
1461
1388
|
indexOf: (n) => _nodeIndexes.get(n),
|
|
1389
|
+
parentIndex: (i) => _parents()[i],
|
|
1462
1390
|
startOf, endOf, str,
|
|
1463
1391
|
get semantic() { return _semantic(); },
|
|
1464
1392
|
};
|
package/index.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
NodeOfType,
|
|
13
13
|
NodeType,
|
|
14
14
|
Program,
|
|
15
|
-
ScanCursor as BaseScanCursor,
|
|
16
15
|
SourceLang,
|
|
17
16
|
SourceLocation,
|
|
18
17
|
SourceType,
|
|
@@ -271,27 +270,6 @@ type Visitors = {
|
|
|
271
270
|
leave?: WalkHandler;
|
|
272
271
|
};
|
|
273
272
|
|
|
274
|
-
/**
|
|
275
|
-
* The semantic scan cursor: the toolchain's {@link BaseScanCursor} plus
|
|
276
|
-
* symbol and reference lookups. Both are index-keyed, so a scan can
|
|
277
|
-
* resolve semantics without materializing any AST nodes.
|
|
278
|
-
*/
|
|
279
|
-
interface ScanCursor<T extends Node = Node> extends BaseScanCursor<T> {
|
|
280
|
-
/** The module being scanned. */
|
|
281
|
-
readonly module: Module;
|
|
282
|
-
/** Shorthand for `module.symbolOf(node)`, without materializing. */
|
|
283
|
-
readonly symbol: Symbol | null;
|
|
284
|
-
/** Shorthand for `module.referenceOf(node)`, without materializing. */
|
|
285
|
-
readonly reference: Reference | null;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/** Scan handlers keyed by node `type`, plus the universal `enter`. */
|
|
289
|
-
type ScanVisitors = {
|
|
290
|
-
[K in NodeType]?: (cursor: ScanCursor<NodeOfType<K>>) => void;
|
|
291
|
-
} & {
|
|
292
|
-
enter?: (cursor: ScanCursor) => void;
|
|
293
|
-
};
|
|
294
|
-
|
|
295
273
|
/** A free variable of a function, as reported by {@link Module.capturesOf}. */
|
|
296
274
|
interface Capture {
|
|
297
275
|
/** The outer binding being closed over. */
|
|
@@ -412,6 +390,12 @@ interface Module {
|
|
|
412
390
|
referenceOf(node: Node): Reference | null;
|
|
413
391
|
/** The innermost scope whose extent contains `node`. */
|
|
414
392
|
scopeOf(node: Node): Scope;
|
|
393
|
+
/**
|
|
394
|
+
* The node that structurally contains `node`. Null at the program
|
|
395
|
+
* root and for a node not part of this module's AST. Lets you walk
|
|
396
|
+
* upward from a node you already hold, with no ancestor stack.
|
|
397
|
+
*/
|
|
398
|
+
parentOf(node: Node): Node | null;
|
|
415
399
|
/**
|
|
416
400
|
* Walks the scope chain from `from` (default: the root scope) to
|
|
417
401
|
* find the nearest binding of `name`.
|
|
@@ -446,14 +430,6 @@ interface Module {
|
|
|
446
430
|
*/
|
|
447
431
|
walk(visitors: Visitors, root?: Node): void;
|
|
448
432
|
|
|
449
|
-
/**
|
|
450
|
-
* Readonly buffer scan with semantic context: visits the parsed node
|
|
451
|
-
* records directly without materializing AST objects, and resolves
|
|
452
|
-
* symbols and references in index space. Many times faster than
|
|
453
|
-
* {@link walk} for sparse queries; call {@link ScanCursor.node} to
|
|
454
|
-
* materialize a matched node (identity-shared with the walked AST).
|
|
455
|
-
*/
|
|
456
|
-
scan(visitors: ScanVisitors): void;
|
|
457
433
|
/** Collects every node of the given type(s), in source order. */
|
|
458
434
|
findAll<K extends NodeType>(type: K): NodeOfType<K>[];
|
|
459
435
|
findAll<K extends NodeType>(types: readonly K[]): NodeOfType<K>[];
|
|
@@ -566,8 +542,6 @@ export {
|
|
|
566
542
|
type NodeOfType,
|
|
567
543
|
type NodeType,
|
|
568
544
|
type Reference,
|
|
569
|
-
type ScanCursor,
|
|
570
|
-
type ScanVisitors,
|
|
571
545
|
type Scope,
|
|
572
546
|
type ScopeKind,
|
|
573
547
|
type Symbol,
|
package/module.js
CHANGED
|
@@ -213,46 +213,6 @@ class Export {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
// The semantic scan cursor, the generated buffer cursor plus symbol and
|
|
217
|
-
// reference lookups, which are index-keyed and so need no AST nodes.
|
|
218
|
-
class ScanCursor {
|
|
219
|
-
_raw = null;
|
|
220
|
-
#module;
|
|
221
|
-
constructor(module) {
|
|
222
|
-
this.#module = module;
|
|
223
|
-
}
|
|
224
|
-
get module() {
|
|
225
|
-
return this.#module;
|
|
226
|
-
}
|
|
227
|
-
get index() {
|
|
228
|
-
return this._raw.index;
|
|
229
|
-
}
|
|
230
|
-
get type() {
|
|
231
|
-
return this._raw.type;
|
|
232
|
-
}
|
|
233
|
-
get start() {
|
|
234
|
-
return this._raw.start;
|
|
235
|
-
}
|
|
236
|
-
get end() {
|
|
237
|
-
return this._raw.end;
|
|
238
|
-
}
|
|
239
|
-
get symbol() {
|
|
240
|
-
return this.#module._symbolByIndex(this._raw.index);
|
|
241
|
-
}
|
|
242
|
-
get reference() {
|
|
243
|
-
return this.#module._referenceByIndex(this._raw.index);
|
|
244
|
-
}
|
|
245
|
-
node() {
|
|
246
|
-
return this._raw.node();
|
|
247
|
-
}
|
|
248
|
-
skip() {
|
|
249
|
-
this._raw.skip();
|
|
250
|
-
}
|
|
251
|
-
stop() {
|
|
252
|
-
this._raw.stop();
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
216
|
export class Module {
|
|
257
217
|
#r;
|
|
258
218
|
#sem;
|
|
@@ -356,6 +316,15 @@ export class Module {
|
|
|
356
316
|
return this.scopes[this.#sem.nodeScope(index)];
|
|
357
317
|
}
|
|
358
318
|
|
|
319
|
+
// the node that structurally contains `node`, or null at the program
|
|
320
|
+
// root or for a node not part of this module's AST.
|
|
321
|
+
parentOf(node) {
|
|
322
|
+
const index = this.#r.indexOf(node);
|
|
323
|
+
if (index === undefined) return null;
|
|
324
|
+
const parent = this.#r.parentIndex(index);
|
|
325
|
+
return parent < 0 ? null : this.#r.nodeOf(parent);
|
|
326
|
+
}
|
|
327
|
+
|
|
359
328
|
resolve(name, from = this.rootScope) {
|
|
360
329
|
for (let s = from; s; s = s.parent) {
|
|
361
330
|
const found = s.find(name);
|
|
@@ -431,22 +400,6 @@ export class Module {
|
|
|
431
400
|
walkModule(this, visitor, root);
|
|
432
401
|
}
|
|
433
402
|
|
|
434
|
-
// readonly buffer scan with a semantic cursor, resolving symbols and
|
|
435
|
-
// references in index space, materializing no AST nodes.
|
|
436
|
-
scan(visitors) {
|
|
437
|
-
const cursor = new ScanCursor(this);
|
|
438
|
-
const wrapped = {};
|
|
439
|
-
for (const key of Object.keys(visitors)) {
|
|
440
|
-
const fn = visitors[key];
|
|
441
|
-
if (typeof fn !== "function") continue;
|
|
442
|
-
wrapped[key] = (raw) => {
|
|
443
|
-
cursor._raw = raw;
|
|
444
|
-
fn(cursor);
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
this.#r.scan(wrapped);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
403
|
findAll(types) {
|
|
451
404
|
const single = typeof types === "string" ? types : null;
|
|
452
405
|
const set = single === null ? new Set(types) : null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuku-analyzer",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.37",
|
|
4
4
|
"description": "High-performance JavaScript/TypeScript semantic analyzer: per-file scopes, symbols, references, and cross-file module linking",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -21,17 +21,17 @@
|
|
|
21
21
|
"decode.js"
|
|
22
22
|
],
|
|
23
23
|
"optionalDependencies": {
|
|
24
|
-
"@yuku-analyzer/binding-linux-x64-gnu": "0.5.
|
|
25
|
-
"@yuku-analyzer/binding-linux-arm64-gnu": "0.5.
|
|
26
|
-
"@yuku-analyzer/binding-linux-arm-gnu": "0.5.
|
|
27
|
-
"@yuku-analyzer/binding-linux-x64-musl": "0.5.
|
|
28
|
-
"@yuku-analyzer/binding-linux-arm64-musl": "0.5.
|
|
29
|
-
"@yuku-analyzer/binding-linux-arm-musl": "0.5.
|
|
30
|
-
"@yuku-analyzer/binding-darwin-x64": "0.5.
|
|
31
|
-
"@yuku-analyzer/binding-darwin-arm64": "0.5.
|
|
32
|
-
"@yuku-analyzer/binding-win32-x64": "0.5.
|
|
33
|
-
"@yuku-analyzer/binding-win32-arm64": "0.5.
|
|
34
|
-
"@yuku-analyzer/binding-freebsd-x64": "0.5.
|
|
24
|
+
"@yuku-analyzer/binding-linux-x64-gnu": "0.5.37",
|
|
25
|
+
"@yuku-analyzer/binding-linux-arm64-gnu": "0.5.37",
|
|
26
|
+
"@yuku-analyzer/binding-linux-arm-gnu": "0.5.37",
|
|
27
|
+
"@yuku-analyzer/binding-linux-x64-musl": "0.5.37",
|
|
28
|
+
"@yuku-analyzer/binding-linux-arm64-musl": "0.5.37",
|
|
29
|
+
"@yuku-analyzer/binding-linux-arm-musl": "0.5.37",
|
|
30
|
+
"@yuku-analyzer/binding-darwin-x64": "0.5.37",
|
|
31
|
+
"@yuku-analyzer/binding-darwin-arm64": "0.5.37",
|
|
32
|
+
"@yuku-analyzer/binding-win32-x64": "0.5.37",
|
|
33
|
+
"@yuku-analyzer/binding-win32-arm64": "0.5.37",
|
|
34
|
+
"@yuku-analyzer/binding-freebsd-x64": "0.5.37"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"analyzer",
|