Repository navigation
Expand file tree
/
Copy pathcodecensus-generator.edits.json
More file actions
1186 lines (1186 loc) · 45.9 KB
/
Copy pathcodecensus-generator.edits.json
File metadata and controls
1186 lines (1186 loc) · 45.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"schema": "codecensus/anchored-edits-v1",
"about": "Edits that turn CodeGraph-Bench's TypeScript generator (base.path, after scripts/restore_identifiers.py) into CodeCensus's generator (result.path). Only our own text is stored. Positions: 1-based line, 0-based column in the base file; anchor = first 16 hex of sha256(line text without line ending). delete = characters removed at the position (sha256 of the removed text, not the text). insert = segments joined with CRLF; a string is our line, {\"base\": N} copies base line N. Apply with: python3 -I scripts/apply_edits.py apply",
"base": {
"path": "scripts/eval/code-graph/oracle/ts-typechecker.oracle.ts",
"sha256": "9adadf453ea5930e75bd015f5379831dc296873cbef3322383b91e58df164b0c",
"lines": 1245
},
"result": {
"path": "scripts/eval/code-graph/oracle/ts-typechecker-r2.oracle.ts",
"sha256": "3712aa99e00637218f38f98308afe80b6d7dd7d9e4555b066f55bf5f07e4f268",
"lines": 2045
},
"eol": "CRLF",
"stats": {
"edits": 31,
"literal_lines_or_fragments": 736,
"lines_copied_by_reference": 51,
"chars_deleted": 359,
"literal_segments_equal_to_an_upstream_line": 0
},
"edits": [
{
"line": 19,
"col": 0,
"anchor": "533a9f1155720e5e",
"insert": [
" */",
"",
"/*",
" * ═══ ORACLE r2 (2026-10-18) ═══════════════════════════════════════════════",
" * This file is a verbatim copy of the r1 generator ts-typechecker.oracle.ts",
" * (sha256 9adadf453ea5930e75bd015f5379831dc296873cbef3322383b91e58df164b0c)",
" * with additive deltas, each marked `R2 Δ<item>` (item = the r2 rule item it",
" * implements). The unchanged r1 pass runs first for every file; the r2 pass",
" * then adds rows. r1 rows are emitted first and in r1 order, r2 rows are",
" * appended after them, so (path, localId) de-duplication in the scorer always",
" * keeps the r1 row. Every added row carries `r2Rule`.",
" *",
" * r2 = r1 plus:",
" * 1a FunctionDeclaration with a name, any depth (Function).",
" * 1b VariableDeclaration, Identifier name, initializer directly an arrow /",
" * function expression, any depth (Function).",
" * 1c ClassDeclaration and named ClassExpression, any depth (Class), members",
" * exactly as r1 emits top-level class members; members of unnamed class",
" * expressions with localId = member name.",
" * 1d Object-literal members named by Identifier/StringLiteral/NumericLiteral:",
" * methods and get:/set: accessors (Method), property assignments whose",
" * initializer is directly an arrow / function expression (Function).",
" * 1e `a.b = <arrow|function>` (Function, localId = property name).",
" * 1f Interface / type alias / enum declarations nested in blocks (r1 kinds).",
" * 2 CALLS: every call site is credited to the innermost enclosing r2",
" * callable or class-member container (anonymous callbacks, IIFEs and",
" * unnamed function expressions stay transparent), else the File. Sites r1",
" * dropped are added (`r2Rule: \"2\"`); r1 rows whose site lies inside a",
" * narrower r2 container (object-literal methods, class-expression members)",
" * keep every field except fromLocalId, which moves to that container",
" * (`r2Rule: \"2-reattributed\"`, original in `r1FromLocalId`).",
" * 3 EXTENDS / IMPLEMENTS for every new class / interface symbol, r1 logic.",
" * 4 Module-level IMPORTS: one row per module dependency the compiler",
" * resolves to an in-repo file (import declaration, import-equals require,",
" * dynamic import(), require() in JS). The rows carry targetPath (the",
" * resolved module file) for the module-level table and scoreable:false so",
" * they never enter the symbol-level IMPORTS table.",
" * 5 TS/JS files no project program loads are analysed (r1 pass + r2 pass) in",
" * one extra inferred program (allowJs, checkJs off, r1's fallback options).",
" *",
" * Revision 2 (2026-10-18, review fixes, each marked `R2 rev2`):",
" * U Unique identity: an added symbol whose localId would repeat a localId",
" * already used in its file (by an r1 row or an earlier added row) for a",
" * DIFFERENT declared entity gets `<localId>@L<startLine>` (then",
" * `@L<line>:<col>`, then `#n`), so the scorer's unchanged (path, localId)",
" * dedupe no longer merges distinct declarations. Overload signatures and",
" * merged interface / enum declarations (one binder symbol) keep one shared",
" * localId, as r1 does. `name` stays the declared name. Container regions,",
" * CALLS fromLocalId, heritage rows and members of a renamed class use the",
" * final localId, and any row (r1 or added) whose resolved target is a",
" * renamed declaration and still carries its base localId is pointed at the",
" * final one (`r1TargetLocalId` keeps the previous value).",
" * Q 1d member names come from the literal's value (`.text`), so a quoted key",
" * 'x' is the member x (r1-style getText() is kept for class members, 1c).",
" * J Rule-4 module rows of a JS importer name the JS file Node loads: when",
" * the compiler resolves the specifier to a TypeScript file (.ts/.tsx/.mts/",
" * .cts or a .d.ts) that has a same-stem JS sibling (.js/.jsx/.mjs/.cjs),",
" * the row targets the sibling (`r2ResolvedTs` keeps the compiler's file).",
" * ══════════════════════════════════════════════════════════════════════════",
""
]
},
{
"line": 53,
"col": 0,
"anchor": "e3b0c44298fc1c14",
"insert": [
"",
"/** R2: per-rule row counters (written into ORACLE-SUMMARY.json as r2RuleRows). */",
"interface R2Stats {",
" symbols: Record<string, number>;",
" symbolKinds: Record<string, number>;",
" edges: Record<string, number>;",
" notes: Record<string, number>;",
"}",
"function newR2Stats(): R2Stats {",
" return { symbols: {}, symbolKinds: {}, edges: {}, notes: {} };",
"}",
"function bump(counter: Record<string, number>, key: string, by = 1): void {",
" counter[key] = (counter[key] ?? 0) + by;",
"}",
"function mergeR2Stats(into: R2Stats, from: R2Stats): void {",
" for (const k of ['symbols', 'symbolKinds', 'edges', 'notes'] as const) {",
" for (const [key, n] of Object.entries(from[k])) {",
" bump(into[k], key, n);",
" }",
" }",
"}",
""
]
},
{
"line": 96,
"col": 53,
"anchor": "4b744e1e331f7acb",
"insert": [
"; decl: ts.Declaration"
]
},
{
"line": 97,
"col": 0,
"anchor": "8c26b6c72f0c11a8",
"insert": [
" // R2 rev2 U: `decl` is returned as well (bookkeeping for target re-pointing only).",
""
]
},
{
"line": 124,
"col": 44,
"anchor": "460991a7ede4823f",
"insert": [
", decl"
]
},
{
"line": 452,
"col": 0,
"anchor": "5eb61e7608c3d355",
"delete": 80,
"delete_sha256": "256573a6da3b3cf09ffa5efca978a5b23000ac199944cf33d9e8a4075f21e8c0",
"insert": [
" ): {",
" edges: OracleEdge[];",
" resolvedCount: number;",
" symbols: OracleSymbol[];",
" // R2 Δ1-4: r2 rows are returned separately so r1 rows keep their order.",
" r2Edges: OracleEdge[];",
" r2Symbols: OracleSymbol[];",
" r2Stats: R2Stats;",
" // R2 Δ5: which owned files this project's program actually analysed.",
" analysedFiles: string[];",
" } {",
""
]
},
{
"line": 465,
"col": 0,
"anchor": "e3b0c44298fc1c14",
"insert": [
" const r2Symbols: OracleSymbol[] = []; // R2",
" const r2Edges: OracleEdge[] = []; // R2",
" const r2Stats = newR2Stats(); // R2",
" const analysedFiles: string[] = []; // R2 Δ5",
" const deferredR2: (() => { r2Edges: OracleEdge[]; r2Symbols: OracleSymbol[] })[] = []; // R2",
""
]
},
{
"line": 474,
"col": 0,
"anchor": "e3b0c44298fc1c14",
"insert": [
" analysedFiles.push(ownedPath); // R2 Δ5",
""
]
},
{
"line": 475,
"col": 78,
"anchor": "3a88a556238d75b6",
"insert": [
", program, r2Stats"
]
},
{
"line": 479,
"col": 0,
"anchor": "28d86778615f6af4",
"insert": [
" deferredR2.push(result.runR2); // R2: runs after the whole r1 pass below",
""
]
},
{
"line": 481,
"col": 0,
"anchor": "0237b54e9625629e",
"insert": [
" // R2: the r2 pass, file by file in the same order, once every r1 row exists.",
" // Not spread — a minified JS file can carry more rows than the engine's",
" // argument-count limit.",
" for (const runR2 of deferredR2) {",
" const result = runR2();",
" for (const s of result.r2Symbols) {",
" r2Symbols.push(s);",
" }",
" for (const e of result.r2Edges) {",
" r2Edges.push(e);",
" }",
" }",
"",
""
]
},
{
"line": 481,
"col": 42,
"anchor": "0237b54e9625629e",
"insert": [
", r2Edges, r2Symbols, r2Stats, analysedFiles"
]
},
{
"line": 483,
"col": 0,
"anchor": "e3b0c44298fc1c14",
"insert": [
"",
" /** R2 Δ5: analyse one file of the extra coverage program (r1 pass + r2 pass, unchanged). */",
" analyzeCoverageFile(",
{
"base": 485
},
{
"base": 486
},
{
"base": 449
},
{
"base": 916
},
" program: ts.Program,",
" r2Stats: R2Stats",
" ) {",
" return this.analyzeFile(sourceFile, checker, repoPath, relPath, program, r2Stats);",
" }",
"",
" /** R2 Δ2: r1 call sites → the container r1 credited and the rows it pushed (per file). */",
" private r1CallSites: Map<ts.Node, { container: string; edges: OracleEdge[] }[]> | null = null;",
"",
" /** R2 rev2 U: every resolved row's target declaration, as `${path}\\0${declStart}` (bookkeeping). */",
" readonly edgeTargetDecl = new Map<OracleEdge, string>();",
" /** R2 rev2 U: added declarations whose localId was made unique: `${path}\\0${declStart}` → base / final. */",
" readonly r2Renamed = new Map<string, { base: string; final: string }>();",
""
]
},
{
"line": 488,
"col": 19,
"anchor": "b2518fc5eeb6945a",
"insert": [
","
]
},
{
"line": 489,
"col": 0,
"anchor": "5eb61e7608c3d355",
"insert": [
" // R2 Δ4: module resolution; R2: per-rule row counters.",
" program: ts.Program,",
" r2Stats: R2Stats",
" ): {",
" edges: OracleEdge[];",
" resolvedCount: number;",
" symbols: OracleSymbol[];",
""
]
},
{
"line": 489,
"col": 2,
"anchor": "5eb61e7608c3d355",
"delete": 76,
"delete_sha256": "14a1be9e1a1a10a15ddf95f317a392e1d41d780d727bd7c8ea0137df0a753f30",
"insert": [
" runR2: () => { r2Edges: OracleEdge[]; r2Symbols: OracleSymbol[] };"
]
},
{
"line": 490,
"col": 0,
"anchor": "dd3177755785d014",
"insert": [
" } {",
""
]
},
{
"line": 493,
"col": 0,
"anchor": "e3b0c44298fc1c14",
"insert": [
" // R2 Δ1: statements the unchanged r1 visit() handled (their symbols are r1 rows).",
" const r1Visited = new Set<ts.Node>();",
" // R2 Δ2: record where r1 credits each call site.",
" this.r1CallSites = new Map();",
""
]
},
{
"line": 529,
"col": 0,
"anchor": "2a44168318e224e1",
"insert": [
" // R2 rev2 U (bookkeeping only): which declaration this row's target is.",
" this.edgeTargetDecl.set(edge, `${loc.path}\\0${loc.decl.getStart(loc.decl.getSourceFile())}`);",
""
]
},
{
"line": 540,
"col": 0,
"anchor": "06cdc8c18e22df96",
"insert": [
" r1Visited.add(node); // R2 Δ1 (bookkeeping only)",
""
]
},
{
"line": 820,
"col": 0,
"anchor": "0237b54e9625629e",
"insert": [
" // ── R2 pass: rows added on top of the unchanged r1 pass above ─────────",
" // Deferred: the caller runs it only after EVERY file of the program has had",
" // its r1 pass, so the type checker sees exactly r1's query sequence while r1",
" // rows are produced (type ids, hence union-constituent order, depend on it).",
" const r1SymbolCount = symbols.length;",
" const r1EdgeCount = edges.length;",
" const r1CallSites = this.r1CallSites;",
" this.r1CallSites = null;",
" const runR2 = () => {",
" this.r2Pass(sourceFile, checker, repoPath, relPath, program, r2Stats, pushSym, pushEdge, symbols, edges, r1Visited, r1CallSites);",
" return { r2Symbols: symbols.splice(r1SymbolCount), r2Edges: edges.splice(r1EdgeCount) };",
" };",
"",
""
]
},
{
"line": 820,
"col": 42,
"anchor": "0237b54e9625629e",
"insert": [
", runR2"
]
},
{
"line": 821,
"col": 0,
"anchor": "737db166c79ae98e",
"insert": [
" }",
"",
" /**",
" * R2 Δ1-4 — one walk over the whole file:",
" * - emits every named declaration r1's visit() did not reach (1a-1f), with",
" * r1's localId/kind conventions, and EXTENDS/IMPLEMENTS for new classes",
" * and interfaces (3);",
" * - credits every call site to its innermost r2 container (2);",
" * - emits module-level IMPORTS rows for compiler-resolved module files (4).",
" * Rows are pushed through the same pushSym/pushEdge as r1 (same resolution,",
" * same line conventions) and tagged with `r2Rule`.",
" */",
" private r2Pass(",
{
"base": 485
},
{
"base": 486
},
{
"base": 449
},
{
"base": 916
},
" program: ts.Program,",
" stats: R2Stats,",
" pushSym: (localId: string, name: string, kind: SymbolType, parentLocalId: string | null, node: ts.Node) => void,",
" pushEdge: PushEdgeFn,",
" symbols: OracleSymbol[],",
" edges: OracleEdge[],",
" r1Visited: Set<ts.Node>,",
" r1CallSites: Map<ts.Node, { container: string; edges: OracleEdge[] }[]> | null",
{
"base": 860
},
" // Container regions for rule 2: node → localId of the r1 or r2 symbol.",
" const containers = new Map<ts.Node, string>();",
" // Which r2 rule created a container (absent = an r1 container).",
" const containerRule = new Map<ts.Node, string>();",
"",
" // R2 rev2 U — localIds unique per file across distinct declared entities.",
" // `symbols` holds exactly this file's r1 rows here (the r2 rows are spliced off after).",
" const usedLocalIds = new Set<string>(symbols.map((s) => s.localId));",
" const entityLocalIds = new Map<object, Map<string, string>>();",
" const hasBody = (d: ts.Node) => ts.isFunctionLike(d) && !!(d as ts.FunctionLikeDeclaration).body;",
" // The declared entity a declaration belongs to: its binder symbol when several declarations",
" // form one entity (overload signatures, merged interface / enum / class declarations), else",
" // the declaration itself. Variable bindings (1b), object-literal members (1d) and assignments",
" // (1e) are each their own declaration; so are re-declared bodies (JS `function f` twice).",
" const entityOf = (n: ts.Node): object => {",
" if (ts.isVariableDeclaration(n) || ts.isPropertyAssignment(n) || ts.isBinaryExpression(n)) {",
" return n;",
" }",
" const sym = (n as { symbol?: ts.Symbol }).symbol;",
" const decls = sym?.declarations ?? [];",
" if (!sym || decls.length < 2) {",
" return n;",
" }",
" if (hasBody(n) && decls.some((d) => d !== n && d.kind === n.kind && hasBody(d))) {",
" return n;",
" }",
" if (n.parent && ts.isObjectLiteralExpression(n.parent)) {",
" return n;",
" }",
" return sym;",
" };",
" const finalLocalId = (base: string, idNode: ts.Node, lineNode: ts.Node): string => {",
" const entity = entityOf(idNode);",
" let perEntity = entityLocalIds.get(entity);",
" let id = perEntity?.get(base);",
" if (id === undefined) {",
" id = base;",
" if (usedLocalIds.has(id)) {",
" const lc = sourceFile.getLineAndCharacterOfPosition(lineNode.getStart(sourceFile));",
" id = `${base}@L${lc.line + 1}`;",
" if (usedLocalIds.has(id)) {",
" id = `${base}@L${lc.line + 1}:${lc.character + 1}`;",
" }",
" for (let k = 2; usedLocalIds.has(id); k++) {",
" id = `${base}@L${lc.line + 1}:${lc.character + 1}#${k}`;",
" }",
" }",
" usedLocalIds.add(id);",
" if (!perEntity) {",
" perEntity = new Map();",
" entityLocalIds.set(entity, perEntity);",
" }",
" perEntity.set(base, id);",
" }",
" if (id !== base) {",
" this.r2Renamed.set(`${relPath}\\0${idNode.getStart(sourceFile)}`, { base, final: id });",
" }",
" return id;",
" };",
"",
" const addSym = (",
" rule: string,",
" baseLocalId: string,",
{
"base": 499
},
{
"base": 500
},
{
"base": 501
},
" node: ts.Node,",
" idNode: ts.Node = node // R2 rev2 U: the declaration whose identity the row carries",
" ): string => {",
" const localId = finalLocalId(baseLocalId, idNode, node); // R2 rev2 U",
" pushSym(localId, name, kind, parentLocalId, node);",
" (symbols[symbols.length - 1] as OracleSymbol & { r2Rule?: string }).r2Rule = rule;",
" bump(stats.symbols, rule);",
" bump(stats.symbolKinds, `${rule}:${kind}`);",
" if (localId !== baseLocalId) {",
" bump(stats.notes, `U:${rule}: localId made unique (${kind})`);",
" }",
" return localId;",
" };",
" const tagEdge = (edge: OracleEdge, rule: string) => {",
" (edge as OracleEdge & { r2Rule?: string }).r2Rule = rule;",
" bump(stats.edges, `${rule}:${edge.type}`);",
" };",
"",
" // r1 member localId / region conventions (class-member loop in visit()).",
" const memberName = (m: ts.ClassElement | ts.ObjectLiteralElementLike): string =>",
" (m.name as ts.PropertyName).getText(sourceFile);",
" // R2 rev2 Q: an object-literal member's name is the key's value (Identifier /",
" // StringLiteral / NumericLiteral `.text`), not its source spelling with quotes.",
" const objectMemberName = (m: ts.ObjectLiteralElementLike): string =>",
" (m.name as ts.Identifier | ts.StringLiteral | ts.NumericLiteral).text;",
"",
" // R2 Δ1c/Δ3 — a class not emitted by r1 (nested declaration or class expression).",
" const emitClass = (node: ts.ClassLikeDeclaration) => {",
" const cname = node.name ? node.name.text : null;",
" const rule = '1c';",
" // R2 rev2 U: the class's final localId qualifies its members and its heritage rows.",
" const cid = cname ? addSym(rule, cname, cname, 'Class', null, node) : null;",
" // R2 Δ3: heritage, exactly r1's logic (only for class symbols, i.e. named).",
" const implementedTypes: ts.Type[] = [];",
" if (cid) {",
{
"base": 553
},
{
"base": 554
},
" const baseName = ts.isIdentifier(typeRef.expression) ? typeRef.expression.text : '[expr]';",
{
"base": 558
},
{
"base": 559
},
{
"base": 560
},
" const edge = pushEdge(cid, baseName, edgeType, baseSymbol);",
{
"base": 562
},
" edge.scoreable = false; // F12, as r1",
" }",
" tagEdge(edge, '3');",
" if (clause.token !== ts.SyntaxKind.ExtendsKeyword) {",
" try {",
" implementedTypes.push(checker.getTypeAtLocation(typeRef));",
" } catch {",
" // as r1: leave unresolved",
" }",
" }",
" }",
" }",
" }",
" // Members exactly as r1's class-member loop; unnamed class: localId = member name.",
" const qual = (n: string) => (cid ? `${cid}.${n}` : n);",
" for (const member of node.members) {",
" if (ts.isConstructorDeclaration(member)) {",
" const localId = addSym(rule, qual('constructor'), 'constructor', 'Constructor', cid, member);",
" containers.set(member, localId);",
" containerRule.set(member, rule);",
" } else if (ts.isMethodDeclaration(member) && member.name) {",
" const mname = memberName(member);",
" const localId = addSym(rule, qual(mname), mname, 'Method', cid, member);",
" containers.set(member, localId);",
" containerRule.set(member, rule);",
" // R2 Δ3: member-level IMPLEMENTS (r1 F8), for class symbols only.",
" if (cid) {",
{
"base": 608
},
" const before = edges.length;",
{
"base": 609
},
" for (let i = before; i < edges.length; i++) {",
" tagEdge(edges[i], '3');",
" }",
" }",
" }",
" } else if (ts.isGetAccessor(member)) {",
" const aname = memberName(member);",
" const localId = addSym(rule, qual(`get:${aname}`), `get:${aname}`, 'Method', cid, member);",
" containers.set(member, localId);",
" containerRule.set(member, rule);",
" } else if (ts.isSetAccessor(member)) {",
" const aname = memberName(member);",
" const localId = addSym(rule, qual(`set:${aname}`), `set:${aname}`, 'Method', cid, member);",
" containers.set(member, localId);",
" containerRule.set(member, rule);",
" } else if (ts.isPropertyDeclaration(member) && member.name) {",
" const pname = memberName(member);",
" const localId = addSym(rule, qual(pname), pname, 'Property', cid, member);",
" containers.set(member, localId);",
" containerRule.set(member, rule);",
" }",
" }",
" };",
"",
" // Register the member containers of a class r1 already emitted (same localIds as r1).",
" const registerR1Class = (node: ts.ClassDeclaration) => {",
" const cname = node.name!.text;",
" for (const member of node.members) {",
" if (ts.isConstructorDeclaration(member)) {",
" containers.set(member, `${cname}.constructor`);",
" } else if (ts.isMethodDeclaration(member) && member.name) {",
" containers.set(member, `${cname}.${memberName(member)}`);",
" } else if (ts.isGetAccessor(member)) {",
" containers.set(member, `${cname}.get:${memberName(member)}`);",
" } else if (ts.isSetAccessor(member)) {",
" containers.set(member, `${cname}.set:${memberName(member)}`);",
" } else if (ts.isPropertyDeclaration(member) && member.name) {",
" containers.set(member, `${cname}.${memberName(member)}`);",
" }",
" }",
" };",
"",
" const isFnExpr = (n: ts.Node | undefined): n is ts.ArrowFunction | ts.FunctionExpression =>",
" !!n && (ts.isArrowFunction(n) || ts.isFunctionExpression(n));",
" const isEligibleObjectMemberName = (n: ts.PropertyName) =>",
" ts.isIdentifier(n) || ts.isStringLiteral(n) || ts.isNumericLiteral(n);",
"",
" const callSites: (ts.CallExpression | ts.NewExpression)[] = [];",
" const moduleSpecifiers: ts.StringLiteralLike[] = [];",
" const isJs = /\\.(jsx?|mjs|cjs)$/i.test(sourceFile.fileName);",
"",
" const walk = (node: ts.Node): void => {",
" // ── 1a: function declarations ──",
" if (ts.isFunctionDeclaration(node) && node.name) {",
{
"base": 713
},
" if (!r1Visited.has(node)) {",
" containers.set(node, addSym('1a', fname, fname, 'Function', null, node)); // R2 rev2 U: final localId",
" containerRule.set(node, '1a');",
{
"base": 779
},
" containers.set(node, fname);",
" }",
" }",
" // ── 1b: variable-bound arrow / function expressions ──",
" else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && isFnExpr(node.initializer)) {",
" const vname = node.name.text;",
" const stmt =",
" node.parent && ts.isVariableDeclarationList(node.parent) && ts.isVariableStatement(node.parent.parent)",
" ? node.parent.parent",
" : null;",
" if (!(stmt && r1Visited.has(stmt))) {",
" // R2 rev2 U: lines from the statement (as r1), identity from the binding itself.",
" containers.set(node.initializer, addSym('1b', vname, vname, 'Function', null, stmt ?? node, node));",
" containerRule.set(node.initializer, '1b');",
{
"base": 779
},
" containers.set(node.initializer, vname);",
" }",
" }",
" // ── 1c: classes ──",
" else if (ts.isClassDeclaration(node) && node.name) {",
" if (r1Visited.has(node)) {",
" registerR1Class(node);",
{
"base": 779
},
" emitClass(node);",
" }",
" } else if (ts.isClassExpression(node)) {",
" emitClass(node); // named → Class + qualified members; unnamed → members by name",
" } else if (ts.isClassDeclaration(node) && !node.name) {",
" bump(stats.notes, 'unnamed ClassDeclaration (export default class): no symbols, transparent');",
" }",
" // ── 1f: interfaces / aliases / enums r1 did not reach ──",
" else if (ts.isInterfaceDeclaration(node) && node.name && !r1Visited.has(node)) {",
{
"base": 658
},
" const iid = addSym('1f', iname, iname, 'Interface', null, node); // R2 rev2 U: final localId",
" // R2 Δ3: interface EXTENDS, r1 logic.",
{
"base": 553
},
{
"base": 554
},
" const baseName = ts.isIdentifier(typeRef.expression) ? typeRef.expression.text : '[expr]';",
{
"base": 558
},
" const edge = pushEdge(iid, baseName, 'EXTENDS', baseSymbol);",
{
"base": 562
},
{
"base": 671
},
" }",
" tagEdge(edge, '3');",
" }",
" }",
{
"base": 587
},
{
"base": 680
},
{
"base": 598
},
" addSym('1f', `${iid}.${mname}`, mname, 'Method', iid, member);",
{
"base": 685
},
{
"base": 640
},
" addSym('1f', `${iid}.${pname}`, pname, 'Property', iid, member);",
" }",
" }",
" } else if (ts.isEnumDeclaration(node) && node.name && !r1Visited.has(node)) {",
{
"base": 697
},
" const eid = addSym('1f', ename, ename, 'Enum', null, node); // R2 rev2 U: final localId",
{
"base": 587
},
{
"base": 700
},
" addSym('1f', `${eid}.${mname}`, mname, 'Property', eid, member);",
" }",
" } else if (ts.isTypeAliasDeclaration(node) && node.name && !r1Visited.has(node)) {",
{
"base": 706
},
" addSym('1f', tname, tname, 'Alias', null, node);",
" }",
" // ── 1d: object-literal members ──",
" else if (ts.isObjectLiteralExpression(node)) {",
" for (const p of node.properties) {",
" if (!p.name || !isEligibleObjectMemberName(p.name as ts.PropertyName)) {",
" continue; // computed / shorthand / spread: skipped",
" }",
" const n = objectMemberName(p); // R2 rev2 Q",
" if (ts.isMethodDeclaration(p)) {",
" containers.set(p, addSym('1d', n, n, 'Method', null, p)); // R2 rev2 U: final localId",
" containerRule.set(p, '1d');",
" } else if (ts.isGetAccessor(p)) {",
" containers.set(p, addSym('1d', `get:${n}`, `get:${n}`, 'Method', null, p));",
" containerRule.set(p, '1d');",
" } else if (ts.isSetAccessor(p)) {",
" containers.set(p, addSym('1d', `set:${n}`, `set:${n}`, 'Method', null, p));",
" containerRule.set(p, '1d');",
" } else if (ts.isPropertyAssignment(p) && isFnExpr(p.initializer)) {",
" containers.set(p.initializer, addSym('1d', n, n, 'Function', null, p));",
" containerRule.set(p.initializer, '1d');",
" }",
" }",
" }",
" // ── 1e: `a.b = <arrow|function>` ──",
" else if (",
" ts.isBinaryExpression(node) &&",
" node.operatorToken.kind === ts.SyntaxKind.EqualsToken &&",
" ts.isPropertyAccessExpression(node.left) &&",
" isFnExpr(node.right)",
" ) {",
" const pname = node.left.name.getText(sourceFile);",
" containers.set(node.right, addSym('1e', pname, pname, 'Function', null, node)); // R2 rev2 U",
" containerRule.set(node.right, '1e');",
" }",
"",
" // ── collect call sites (2) and module specifiers (4) ──",
" if (ts.isCallExpression(node) || ts.isNewExpression(node)) {",
" callSites.push(node);",
" if (ts.isCallExpression(node)) {",
" const arg0 = node.arguments[0];",
" const isDynamicImport = node.expression.kind === ts.SyntaxKind.ImportKeyword;",
" const isJsRequire =",
" isJs &&",
" ts.isIdentifier(node.expression) &&",
" node.expression.text === 'require' &&",
" node.arguments.length === 1;",
" if ((isDynamicImport || isJsRequire) && arg0 && ts.isStringLiteralLike(arg0)) {",
" moduleSpecifiers.push(arg0);",
" }",
" }",
" } else if (ts.isImportDeclaration(node) && ts.isStringLiteralLike(node.moduleSpecifier)) {",
" moduleSpecifiers.push(node.moduleSpecifier);",
" } else if (",
" ts.isImportEqualsDeclaration(node) &&",
" ts.isExternalModuleReference(node.moduleReference) &&",
" ts.isStringLiteralLike(node.moduleReference.expression)",
" ) {",
" moduleSpecifiers.push(node.moduleReference.expression);",
" }",
"",
" ts.forEachChild(node, walk);",
" };",
" ts.forEachChild(sourceFile, walk);",
"",
" // ── R2 Δ2: credit every call site to its innermost container ──────────",
" for (const site of callSites) {",
" const calleeName = this.getCalleeName(site); // r1 convention: only Identifier / PropertyAccess callees",
" if (!calleeName) {",
{
"base": 415
},
" }",
" let container: string = relPath;",
" let rule: string | undefined;",
" for (let a: ts.Node | undefined = site.parent; a; a = a.parent) {",
" const c = containers.get(a);",
" if (c !== undefined) {",
" container = c;",
" rule = containerRule.get(a);",
" break;",
" }",
" }",
" const r1 = r1CallSites?.get(site);",
" if (r1) {",
" for (const rec of r1) {",
" if (rec.container === container) {",
{
"base": 727
},
" }",
" for (const e of rec.edges) {",
" (e as OracleEdge & { r1FromLocalId?: string }).r1FromLocalId = e.fromLocalId;",
" e.fromLocalId = container;",
" (e as OracleEdge & { r2Rule?: string }).r2Rule = '2-reattributed';",
" bump(stats.edges, `2-reattributed:${rule ?? 'r1-container'}:CALLS`);",
" }",
" }",
{
"base": 415
},
" }",
" const { symbols: targets, tier } = resolveCalleeSymbols(checker, site);",
" const label = `2:${rule ?? (container === relPath ? 'file' : 'r1-container')}`;",
" if (targets.length > 0) {",
" for (const sym of targets) {",
" tagEdge(pushEdge(container, calleeName, 'CALLS', sym, tier), label);",
" }",
" } else {",
" tagEdge(pushEdge(container, calleeName, 'CALLS', null, tier), label);",
" }",
" }",
"",
" // ── R2 Δ4: module-level IMPORTS to the resolved module file ───────────",
" const resolveModule = (spec: ts.StringLiteralLike): string | null => {",
" try {",
" const r = (",
" program as ts.Program & {",
" getResolvedModuleFromModuleSpecifier(",
" s: ts.StringLiteralLike,",
" f?: ts.SourceFile",
" ): { resolvedModule?: { resolvedFileName: string } } | undefined;",
" }",
" ).getResolvedModuleFromModuleSpecifier(spec, sourceFile);",
" const fileName = r?.resolvedModule?.resolvedFileName;",
" return fileName ? getRelPath(repoPath, fileName) : null;",
" } catch {",
" return null;",
" }",
" };",
" // R2 rev2 J: the same-stem JS file a TypeScript file stands for (.ts/.d.ts → .js,",
" // .tsx → .jsx/.js, .mts/.d.mts → .mjs, .cts/.d.cts → .cjs), if it exists in the repo.",
" const jsSiblingOf = (rel: string): string | null => {",
" const m = /^(.*?)(\\.d)?\\.(ts|tsx|mts|cts)$/i.exec(rel);",
" if (!m) {",
" return null;",
" }",
" const ext = m[3].toLowerCase();",
" const candidates = ext === 'mts' ? ['.mjs'] : ext === 'cts' ? ['.cjs'] : ext === 'tsx' ? ['.jsx', '.js'] : ['.js'];",
" for (const c of candidates) {",
" if (ts.sys.fileExists(join(repoPath, m[1] + c))) {",
" return m[1] + c;",
" }",
" }",
" return null;",
" };",
" for (const spec of moduleSpecifiers) {",
" const resolved = resolveModule(spec);",
" if (!resolved) {",
" bump(stats.notes, 'module specifier not resolved to an in-repo file (no row)');",
{
"base": 415
},
" }",
" // R2 rev2 J: a JS importer loads the JS sibling, not the TypeScript file the",
" // compiler prefers (TypeScript extensions win its lookup), unless the specifier",
" // names a TypeScript extension itself.",
" let target = resolved;",
" if (isJs && !/\\.(d\\.)?[mc]?tsx?$/i.test(spec.text)) {",
" const sibling = jsSiblingOf(resolved);",
" if (sibling) {",
" target = sibling;",
" bump(stats.notes, `J: JS importer module row re-pointed from ${/\\.d\\.[mc]?ts$/i.test(resolved) ? '.d.ts' : 'TS source'} to its JS sibling`);",
" }",
" }",
" const edge: OracleEdge = {",
" fromLocalId: relPath,",
" fromPath: relPath,",
" targetName: spec.text,",
" type: 'IMPORTS',",
" targetLocalId: target,",
" targetPath: target,",
" targetStartLine: 1,",
" scoreable: false,",
" };",
" if (target !== resolved) {",
" (edge as OracleEdge & { r2ResolvedTs?: string }).r2ResolvedTs = resolved; // R2 rev2 J",
" }",
{
"base": 532
},
" tagEdge(edge, '4');",
" }",
""
]
},
{
"line": 888,
"col": 0,
"anchor": "43fbc699e1b9099a",
"insert": [
" const pushed: OracleEdge[] = []; // R2 Δ2 (bookkeeping only)",
""
]
},
{
"line": 890,
"col": 18,
"anchor": "3f31fbc4ff64eac4",
"delete": 53,
"delete_sha256": "556d5b712b38c52ae69374f963b66ebaa698e3acf7f7c5e850fec4e4437dd1e1",
"insert": [
"ed.push(pushEdge(containerLocalId, calleeName, 'CALLS', sym, tier)"
]
},
{
"line": 893,
"col": 16,
"anchor": "8bb956e0379a988d",
"delete": 54,
"delete_sha256": "cce5a04d35fe5e8e99cad69a1370391208dd901fc3f37cc1bf74e3585809b427",
"insert": [
"ed.push(pushEdge(containerLocalId, calleeName, 'CALLS', null, tier)"
]
},
{
"line": 894,
"col": 0,
"anchor": "9726a7494bd555db",
"insert": [
" }",
" // R2 Δ2: remember where r1 credited this site.",
" if (this.r1CallSites) {",
" const list = this.r1CallSites.get(n) ?? [];",
" list.push({ container: containerLocalId, edges: pushed });",
" this.r1CallSites.set(n, list);",
""
]
},
{
"line": 1188,
"col": 0,
"anchor": "e3b0c44298fc1c14",
"insert": [
" // R2: added rows (appended after every r1 row), counters, analysed-file set.",
" if (opts.useCache) {",
" throw new Error('[typechecker-oracle r2] the per-project cache holds r1 rows only; run with useCache=false');",
" }",
" const allR2Symbols: OracleSymbol[] = [];",
" const allR2Edges: OracleEdge[] = [];",
" const r2Stats = newR2Stats();",
" const analysed = new Set<string>();",
""
]
},
{
"line": 1219,
"col": 0,
"anchor": "bb3562d429057937",
"insert": [
" // R2: collect the project's added rows and counters.",
" for (const s of result.r2Symbols) {",
" allR2Symbols.push(s);",
" }",
" for (const e of deriveScoreable(result.r2Edges)) {",
" allR2Edges.push(e);",
" }",
" mergeR2Stats(r2Stats, result.r2Stats);",
" for (const f of result.analysedFiles) {",
" analysed.add(f);",
" }",
""
]
},
{
"line": 1236,
"col": 0,