fallow-core 2.40.1

Core analysis engine for the fallow TypeScript/JavaScript codebase analyzer
Documentation
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
use rustc_hash::{FxHashMap, FxHashSet};

use fallow_config::ResolvedConfig;

use crate::discover::FileId;
use crate::graph::{ModuleGraph, ModuleNode};
use crate::results::{
    DuplicateExport, DuplicateLocation, ExportUsage, ReferenceLocation, StaleSuppression,
    SuppressionOrigin, UnusedExport,
};
use crate::suppress::{IssueKind, SuppressionContext};

use super::{LineOffsetsMap, byte_offset_to_line_col, read_source};

/// Pre-compiled glob matchers for config ignore_exports rules.
type IgnoreMatchers<'a> = Vec<(globset::GlobMatcher, &'a [String])>;

/// Pre-compiled glob matchers for plugin/framework used_exports rules.
type PluginMatchers<'a> = Vec<CompiledUsedExportRule<'a>>;

/// Compile config ignore_exports rules into glob matchers.
fn compile_ignore_matchers(config: &ResolvedConfig) -> IgnoreMatchers<'_> {
    config
        .ignore_export_rules
        .iter()
        .filter_map(|rule| match globset::Glob::new(&rule.file) {
            Ok(g) => Some((g.compile_matcher(), rule.exports.as_slice())),
            Err(e) => {
                tracing::warn!("invalid ignoreExports pattern '{}': {e}", rule.file);
                None
            }
        })
        .collect()
}

/// Compile plugin-discovered used_exports rules (includes framework preset rules).
fn compile_plugin_matchers(
    plugin_result: Option<&crate::plugins::AggregatedPluginResult>,
) -> PluginMatchers<'_> {
    let Some(pr) = plugin_result else {
        return Vec::new();
    };
    pr.used_exports
        .iter()
        .filter_map(compile_used_export_rule)
        .collect()
}

struct CompiledUsedExportRule<'a> {
    path: crate::plugins::CompiledPathRule,
    exports: Vec<&'a str>,
}

impl CompiledUsedExportRule<'_> {
    fn matches(&self, path: &str) -> bool {
        self.path.matches(path)
    }
}

fn compile_used_export_rule(
    rule: &crate::plugins::PluginUsedExportRule,
) -> Option<CompiledUsedExportRule<'_>> {
    Some(CompiledUsedExportRule {
        path: crate::plugins::CompiledPathRule::for_used_export_rule(
            &rule.rule.path,
            "used_exports pattern",
        )?,
        exports: rule.rule.exports.iter().map(String::as_str).collect(),
    })
}

/// Check whether a module should be skipped for unused-export analysis.
///
/// Skips entry points that do not have framework/plugin `used_exports` handling,
/// CJS-only modules, Svelte files (whose `export let` declarations are component
/// props), and fully-unreachable modules where every export has zero references
/// (those are already caught by `find_unused_files`). Unreachable modules with
/// *some* referenced exports are NOT skipped — their individually unused exports
/// would otherwise slip through both detectors.
fn should_skip_module(
    module: &ModuleNode,
    has_plugin_used_exports: bool,
    include_entry_exports: bool,
) -> bool {
    if module.is_entry_point() && !has_plugin_used_exports && !include_entry_exports {
        return true;
    }
    if !module.is_reachable() {
        // Completely unreachable with no references at all → caught by find_unused_files
        return module.exports.iter().all(|e| e.references.is_empty());
    }
    // CJS modules with module.exports but no named exports: hard to track individually
    if module.has_cjs_exports() && module.exports.is_empty() {
        return true;
    }
    // Svelte `export let`/`export const` are component props consumed by the runtime;
    // unreachable Svelte files are still caught by `find_unused_files`.
    module.path.extension().is_some_and(|ext| ext == "svelte")
}

/// Check whether an export name is covered by config ignore rules or plugin/framework rules.
fn is_export_ignored(
    export_name: &str,
    matching_ignore: &[&[String]],
    matching_plugin: &[&[&str]],
) -> bool {
    matching_ignore
        .iter()
        .any(|exports| exports.iter().any(|e| e == "*" || e == export_name))
        || matching_plugin
            .iter()
            .any(|exports| exports.contains(&export_name))
}

/// Find exports that are never imported by other files.
pub fn find_unused_exports(
    graph: &ModuleGraph,
    config: &ResolvedConfig,
    plugin_result: Option<&crate::plugins::AggregatedPluginResult>,
    suppressions: &SuppressionContext<'_>,
    line_offsets_by_file: &LineOffsetsMap<'_>,
) -> (Vec<UnusedExport>, Vec<UnusedExport>, Vec<StaleSuppression>) {
    let mut unused_exports = Vec::new();
    let mut unused_types = Vec::new();
    let mut stale_expected_unused = Vec::new();

    let ignore_matchers = compile_ignore_matchers(config);
    let plugin_matchers = compile_plugin_matchers(plugin_result);

    // Precompute reachable FileIds so we can distinguish meaningful references
    // (from reachable modules) from unreachable-to-unreachable references.
    let reachable_files: FxHashSet<u32> = graph
        .modules
        .iter()
        .filter(|m| m.is_reachable())
        .map(|m| m.file_id.0)
        .collect();

    for module in &graph.modules {
        // Compute relative path once per module for glob matching
        let relative_path = module
            .path
            .strip_prefix(&config.root)
            .unwrap_or(&module.path);
        let file_str = relative_path.to_string_lossy();

        // Collect ignore/plugin matchers that apply to this file
        let matching_ignore: Vec<&[String]> = ignore_matchers
            .iter()
            .filter(|(m, _)| m.is_match(file_str.as_ref()))
            .map(|(_, exports)| *exports)
            .collect();

        let matching_plugin: Vec<&[&str]> = plugin_matchers
            .iter()
            .filter(|rule| rule.matches(file_str.as_ref()))
            .map(|rule| rule.exports.as_slice())
            .collect();

        if should_skip_module(
            module,
            !matching_plugin.is_empty(),
            config.include_entry_exports,
        ) {
            continue;
        }

        // Namespace imports are now handled with member-access narrowing in graph.rs:
        // only specific accessed members get references populated. No blanket skip needed.

        // Pre-compute the set of re-exported names for O(1) is_re_export lookups
        // inside the export loop. Barrel files synthesize one ExportSymbol per
        // ReExportEdge, so the naive iter().any() check would be O(N²).
        let re_export_names: FxHashSet<&str> = module
            .re_exports
            .iter()
            .map(|re| re.exported_name.as_str())
            .collect();

        for export in &module.exports {
            // For unreachable modules, only references from reachable files count —
            // references from other unreachable modules don't save an export.
            let is_referenced = if module.is_reachable() {
                !export.references.is_empty()
            } else {
                export
                    .references
                    .iter()
                    .any(|r| reachable_files.contains(&r.from_file.0))
            };
            // Handle @expected-unused: if the export IS used (has references from
            // reachable modules), report as stale. If it's NOT used, suppress it
            // silently (the tag is working as intended). Note: re-exports through
            // barrel files DO count as references here, since the reference list
            // is already filtered to reachable modules above.
            if matches!(
                export.visibility,
                fallow_types::extract::VisibilityTag::ExpectedUnused
            ) {
                if is_referenced {
                    let (line, col) = byte_offset_to_line_col(
                        line_offsets_by_file,
                        module.file_id,
                        export.span.start,
                    );
                    stale_expected_unused.push(StaleSuppression {
                        path: module.path.clone(),
                        line,
                        col,
                        origin: SuppressionOrigin::JsdocTag {
                            export_name: export.name.to_string(),
                        },
                    });
                }
                continue;
            }

            // Other visibility tags (@public, @internal, @alpha, @beta) permanently suppress
            if export.visibility.suppresses_unused() || is_referenced {
                continue;
            }

            let export_str = export.name.to_string();

            if is_export_ignored(&export_str, &matching_ignore, &matching_plugin) {
                continue;
            }

            let (line, col) =
                byte_offset_to_line_col(line_offsets_by_file, module.file_id, export.span.start);

            // Detect re-exports semantically by looking up the export name in the
            // module's re_exports set, rather than relying on a span sentinel.
            // This catches both synthesized re-exports (which still use Span::default()
            // for narrowing/star cases) and real re-exports (which carry the visitor's
            // span for accurate line-number reporting).
            let is_re_export = re_export_names.contains(export_str.as_str());

            // Check inline suppression
            let issue_kind = if export.is_type_only {
                IssueKind::UnusedType
            } else {
                IssueKind::UnusedExport
            };
            if suppressions.is_suppressed(module.file_id, line, issue_kind) {
                continue;
            }

            let unused = UnusedExport {
                path: module.path.clone(),
                export_name: export_str,
                is_type_only: export.is_type_only,
                line,
                col,
                span_start: export.span.start,
                is_re_export,
            };

            if export.is_type_only {
                unused_types.push(unused);
            } else {
                unused_exports.push(unused);
            }
        }
    }

    (unused_exports, unused_types, stale_expected_unused)
}

/// Find exports that appear with the same name in multiple files (potential duplicates).
///
/// Barrel re-exports (files that only re-export from other modules via `export { X } from './source'`)
/// are excluded — having an index.ts re-export the same name as the source module is the normal
/// barrel file pattern, not a true duplicate.
pub fn find_duplicate_exports(
    graph: &ModuleGraph,
    suppressions: &SuppressionContext<'_>,
    line_offsets_by_file: &LineOffsetsMap<'_>,
) -> Vec<DuplicateExport> {
    // Build a set of re-export relationships: (re-exporting module idx) -> set of (source module idx)
    let mut re_export_sources: FxHashMap<usize, FxHashSet<usize>> = FxHashMap::default();
    for (idx, module) in graph.modules.iter().enumerate() {
        for re in &module.re_exports {
            re_export_sources
                .entry(idx)
                .or_default()
                .insert(re.source_file.0 as usize);
        }
    }

    struct ExportEntry {
        module_idx: usize,
        path: std::path::PathBuf,
        file_id: FileId,
        span_start: u32,
        is_type_only: bool,
    }

    let mut export_locations: FxHashMap<String, Vec<ExportEntry>> = FxHashMap::default();

    for (idx, module) in graph.modules.iter().enumerate() {
        if !module.is_reachable() || module.is_entry_point() {
            continue;
        }

        // Skip files with file-wide duplicate-export suppression
        if suppressions.is_file_suppressed(module.file_id, IssueKind::DuplicateExport) {
            continue;
        }

        for export in &module.exports {
            if matches!(export.name, crate::extract::ExportName::Default) {
                continue; // Skip default exports
            }
            // Skip synthetic re-export entries (span 0..0) — these are generated by
            // graph construction for re-exports, not real local declarations
            if export.span.start == 0 && export.span.end == 0 {
                continue;
            }
            let name = export.name.to_string();
            export_locations.entry(name).or_default().push(ExportEntry {
                module_idx: idx,
                path: module.path.clone(),
                file_id: module.file_id,
                span_start: export.span.start,
                is_type_only: export.is_type_only,
            });
        }
    }

    // Filter: only keep truly independent duplicates (not re-export chains)
    // Sort by export name for deterministic output order
    let mut sorted_locations: Vec<_> = export_locations.into_iter().collect();
    sorted_locations.sort_by(|a, b| a.0.cmp(&b.0));

    sorted_locations
        .into_iter()
        .filter_map(|(name, locations)| {
            if locations.len() <= 1 {
                return None;
            }

            // TypeScript declaration merging: a value export (`export const X`) and
            // a type export (`export type X`) sharing the same name are distinct in
            // TS's value/type namespace split. This is idiomatic with Zod, Prisma,
            // class+interface merging, etc. Skip groups that mix value and type exports.
            let has_value = locations.iter().any(|e| !e.is_type_only);
            let has_type = locations.iter().any(|e| e.is_type_only);
            if has_value && has_type {
                // Deduplicate within each namespace: keep only value-only or type-only
                // entries and check if either namespace alone has duplicates.
                let value_modules: FxHashSet<usize> = locations
                    .iter()
                    .filter(|e| !e.is_type_only)
                    .map(|e| e.module_idx)
                    .collect();
                let type_modules: FxHashSet<usize> = locations
                    .iter()
                    .filter(|e| e.is_type_only)
                    .map(|e| e.module_idx)
                    .collect();
                // If neither namespace alone has cross-file duplicates, skip entirely
                if value_modules.len() <= 1 && type_modules.len() <= 1 {
                    return None;
                }
            }

            // Remove entries where one module re-exports from another in the set.
            // For each pair (A, B), if A re-exports from B or B re-exports from A,
            // they are part of the same export chain, not true duplicates.
            let module_indices: FxHashSet<usize> = locations.iter().map(|e| e.module_idx).collect();
            let independent: Vec<DuplicateLocation> = locations
                .into_iter()
                .filter(|e| {
                    let sources = re_export_sources.get(&e.module_idx);
                    let has_source_in_set =
                        sources.is_some_and(|s| s.iter().any(|src| module_indices.contains(src)));
                    !has_source_in_set
                })
                .map(|e| {
                    let (line, col) =
                        byte_offset_to_line_col(line_offsets_by_file, e.file_id, e.span_start);
                    DuplicateLocation {
                        path: e.path,
                        line,
                        col,
                    }
                })
                .collect();

            if independent.len() <= 1 {
                return None;
            }

            // Filter: only report duplicates where at least two files share a common
            // importer in the module graph. Unrelated leaf files (e.g., SvelteKit route
            // modules in different directories) that happen to export the same name
            // are not actionable duplicates since they can never be confused at an
            // import site.
            let has_shared_importer = has_common_importer(&independent, graph);
            if has_shared_importer {
                Some(DuplicateExport {
                    export_name: name,
                    locations: independent,
                })
            } else {
                None
            }
        })
        .collect()
}

/// Check if any two files in the duplicate set share a common importer.
///
/// Two files "share a common importer" if there exists a third file that imports
/// from both. This filters out false positives from unrelated leaf modules (e.g.,
/// SvelteKit route files in different directories) that coincidentally export the
/// same name but are never imported together.
fn has_common_importer(locations: &[DuplicateLocation], graph: &ModuleGraph) -> bool {
    if locations.len() <= 1 {
        return false;
    }

    // Collect FileIds for the duplicate locations by matching paths
    let file_ids: Vec<FileId> = locations
        .iter()
        .filter_map(|loc| {
            graph
                .modules
                .iter()
                .find(|m| m.path == loc.path)
                .map(|m| m.file_id)
        })
        .collect();

    if file_ids.len() <= 1 {
        return false;
    }

    // For each pair, check if they share a common importer via reverse_deps
    for i in 0..file_ids.len() {
        let idx_i = file_ids[i].0 as usize;
        if idx_i >= graph.reverse_deps.len() {
            continue;
        }
        let importers_i: FxHashSet<FileId> = graph.reverse_deps[idx_i].iter().copied().collect();
        for j in (i + 1)..file_ids.len() {
            let idx_j = file_ids[j].0 as usize;
            if idx_j >= graph.reverse_deps.len() {
                continue;
            }
            // Check if any importer of file j also imports file i
            if graph.reverse_deps[idx_j]
                .iter()
                .any(|imp| importers_i.contains(imp))
            {
                return true;
            }
            // Also check if one directly imports the other
            if importers_i.contains(&file_ids[j])
                || graph.reverse_deps[idx_j].contains(&file_ids[i])
            {
                return true;
            }
        }
    }
    false
}

/// Collect usage counts for all exports in the module graph.
///
/// Iterates every module and every export, producing an `ExportUsage` entry with the
/// reference count and reference locations. This data is used by the LSP server to show
/// Code Lens annotations (e.g., "3 references") above export declarations, with
/// click-to-navigate support via `editor.action.showReferences`.
pub fn collect_export_usages(
    graph: &ModuleGraph,
    line_offsets_by_file: &LineOffsetsMap<'_>,
) -> Vec<ExportUsage> {
    let mut usages = Vec::new();

    // Build FileId -> path index for resolving reference locations
    let file_paths: FxHashMap<FileId, &std::path::Path> = graph
        .modules
        .iter()
        .map(|m| (m.file_id, m.path.as_path()))
        .collect();

    // Fallback source + line-offset cache for reference locations not in the line offsets map.
    // Only populated when a referencing file's line offsets are unavailable.
    // Caches both source and computed offsets to avoid redundant recomputation.
    let mut source_cache: FxHashMap<FileId, (String, Vec<u32>)> = FxHashMap::default();

    for module in &graph.modules {
        // Skip unreachable modules — no point showing Code Lens for files
        // that aren't reachable from any entry point
        if !module.is_reachable() {
            continue;
        }

        for export in &module.exports {
            // Skip synthetic re-export entries (span 0..0) — these are generated
            // by graph construction, not real local declarations in the source
            if export.span.start == 0 && export.span.end == 0 {
                continue;
            }

            let (line, col) =
                byte_offset_to_line_col(line_offsets_by_file, module.file_id, export.span.start);

            // Resolve reference locations for Code Lens navigation
            let reference_locations: Vec<ReferenceLocation> = export
                .references
                .iter()
                .filter_map(|r| {
                    // Skip references with no span (e.g. from dynamic import patterns)
                    if r.import_span.start == 0 && r.import_span.end == 0 {
                        return None;
                    }
                    let ref_path = file_paths.get(&r.from_file)?;
                    // Use pre-computed line offsets when available, fall back to disk read
                    let (ref_line, ref_col) = if line_offsets_by_file.contains_key(&r.from_file) {
                        byte_offset_to_line_col(
                            line_offsets_by_file,
                            r.from_file,
                            r.import_span.start,
                        )
                    } else {
                        let (_, offsets) = source_cache.entry(r.from_file).or_insert_with(|| {
                            let src = read_source(ref_path);
                            let ofs = fallow_types::extract::compute_line_offsets(&src);
                            (src, ofs)
                        });
                        fallow_types::extract::byte_offset_to_line_col(offsets, r.import_span.start)
                    };
                    Some(ReferenceLocation {
                        path: ref_path.to_path_buf(),
                        line: ref_line,
                        col: ref_col,
                    })
                })
                .collect();

            usages.push(ExportUsage {
                path: module.path.clone(),
                export_name: export.name.to_string(),
                line,
                col,
                reference_count: export.references.len(),
                reference_locations,
            });
        }
    }

    usages
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::discover::{DiscoveredFile, EntryPoint, EntryPointSource, FileId};
    use crate::extract::{ExportName, VisibilityTag};
    use crate::graph::{ExportSymbol, ModuleGraph, ReExportEdge, SymbolReference};
    use crate::resolve::ResolvedModule;
    use crate::suppress::Suppression;
    use oxc_span::Span;
    use std::path::PathBuf;

    /// Build a minimal ModuleGraph via the build() constructor.
    #[expect(
        clippy::cast_possible_truncation,
        reason = "test file counts are trivially small"
    )]
    fn build_graph(file_specs: &[(&str, bool)]) -> ModuleGraph {
        let files: Vec<DiscoveredFile> = file_specs
            .iter()
            .enumerate()
            .map(|(i, (path, _))| DiscoveredFile {
                id: FileId(i as u32),
                path: PathBuf::from(path),
                size_bytes: 0,
            })
            .collect();

        let entry_points: Vec<EntryPoint> = file_specs
            .iter()
            .filter(|(_, is_entry)| *is_entry)
            .map(|(path, _)| EntryPoint {
                path: PathBuf::from(path),
                source: EntryPointSource::ManualEntry,
            })
            .collect();

        let resolved_modules: Vec<ResolvedModule> = files
            .iter()
            .map(|f| ResolvedModule {
                file_id: f.id,
                path: f.path.clone(),
                exports: vec![],
                re_exports: vec![],
                resolved_imports: vec![],
                resolved_dynamic_imports: vec![],
                resolved_dynamic_patterns: vec![],
                member_accesses: vec![],
                whole_object_uses: vec![],
                has_cjs_exports: false,
                unused_import_bindings: FxHashSet::default(),
            })
            .collect();

        ModuleGraph::build(&resolved_modules, &entry_points, &files)
    }

    /// Build a default ResolvedConfig for tests.
    fn test_config() -> ResolvedConfig {
        fallow_config::FallowConfig::default().resolve(
            PathBuf::from("/tmp/test"),
            fallow_config::OutputFormat::Human,
            1,
            true,
            true,
        )
    }

    fn make_export(name: &str, span_start: u32, span_end: u32) -> ExportSymbol {
        ExportSymbol {
            name: ExportName::Named(name.to_string()),
            is_type_only: false,
            visibility: VisibilityTag::None,
            span: Span::new(span_start, span_end),
            references: vec![],
            members: vec![],
        }
    }

    fn make_referenced_export(
        name: &str,
        span_start: u32,
        span_end: u32,
        from: u32,
    ) -> ExportSymbol {
        ExportSymbol {
            name: ExportName::Named(name.to_string()),
            is_type_only: false,
            visibility: VisibilityTag::None,
            span: Span::new(span_start, span_end),
            references: vec![SymbolReference {
                from_file: FileId(from),
                kind: crate::graph::ReferenceKind::NamedImport,
                import_span: Span::new(0, 10),
            }],
            members: vec![],
        }
    }

    // ---- find_duplicate_exports tests ----

    #[test]
    fn duplicate_exports_empty_graph() {
        let graph = build_graph(&[]);
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert!(result.is_empty());
    }

    #[test]
    fn duplicate_exports_no_duplicates_single_module() {
        let mut graph = build_graph(&[("/src/entry.ts", true), ("/src/utils.ts", false)]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("foo", 10, 20), make_export("bar", 30, 40)];
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert!(result.is_empty());
    }

    #[test]
    fn duplicate_exports_detects_same_name_in_two_modules() {
        let mut graph = build_graph(&[
            ("/src/entry.ts", true),
            ("/src/a.ts", false),
            ("/src/b.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("helper", 10, 20)];
        graph.modules[2].set_reachable(true);
        graph.modules[2].exports = vec![make_export("helper", 10, 20)];
        // entry.ts imports both a.ts and b.ts — they share a common importer
        graph.reverse_deps[1] = vec![FileId(0)];
        graph.reverse_deps[2] = vec![FileId(0)];
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert_eq!(result.len(), 1);
        assert_eq!(result[0].export_name, "helper");
        assert_eq!(result[0].locations.len(), 2);
    }

    #[test]
    fn duplicate_exports_skips_default_exports() {
        let mut graph = build_graph(&[
            ("/src/entry.ts", true),
            ("/src/a.ts", false),
            ("/src/b.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![ExportSymbol {
            name: ExportName::Default,
            is_type_only: false,
            visibility: VisibilityTag::None,
            span: Span::new(10, 20),
            references: vec![],
            members: vec![],
        }];
        graph.modules[2].set_reachable(true);
        graph.modules[2].exports = vec![ExportSymbol {
            name: ExportName::Default,
            is_type_only: false,
            visibility: VisibilityTag::None,
            span: Span::new(10, 20),
            references: vec![],
            members: vec![],
        }];
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert!(result.is_empty());
    }

    #[test]
    fn duplicate_exports_skips_synthetic_re_export_entries() {
        let mut graph = build_graph(&[
            ("/src/entry.ts", true),
            ("/src/a.ts", false),
            ("/src/b.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("helper", 0, 0)]; // synthetic
        graph.modules[2].set_reachable(true);
        graph.modules[2].exports = vec![make_export("helper", 10, 20)]; // real
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert!(result.is_empty());
    }

    #[test]
    fn duplicate_exports_skips_unreachable_modules() {
        let mut graph = build_graph(&[
            ("/src/entry.ts", true),
            ("/src/a.ts", false),
            ("/src/b.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("helper", 10, 20)];
        // Module 2 stays unreachable
        graph.modules[2].exports = vec![make_export("helper", 10, 20)];
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert!(result.is_empty());
    }

    #[test]
    fn duplicate_exports_skips_entry_points() {
        let mut graph = build_graph(&[("/src/entry.ts", true), ("/src/b.ts", false)]);
        graph.modules[0].exports = vec![make_export("helper", 10, 20)];
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("helper", 10, 20)];
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert!(result.is_empty());
    }

    #[test]
    fn duplicate_exports_filters_re_export_chains() {
        let mut graph = build_graph(&[
            ("/src/entry.ts", true),
            ("/src/index.ts", false),
            ("/src/helper.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("helper", 10, 20)];
        graph.modules[1].re_exports = vec![ReExportEdge {
            source_file: FileId(2),
            imported_name: "helper".to_string(),
            exported_name: "helper".to_string(),
            is_type_only: false,
            span: oxc_span::Span::default(),
        }];
        graph.modules[2].set_reachable(true);
        graph.modules[2].exports = vec![make_export("helper", 5, 15)];
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert!(result.is_empty());
    }

    #[test]
    fn duplicate_exports_suppressed_file_wide() {
        let mut graph = build_graph(&[
            ("/src/entry.ts", true),
            ("/src/a.ts", false),
            ("/src/b.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("helper", 10, 20)];
        graph.modules[2].set_reachable(true);
        graph.modules[2].exports = vec![make_export("helper", 10, 20)];

        let supp = vec![Suppression {
            line: 0,
            comment_line: 1,
            kind: Some(IssueKind::DuplicateExport),
        }];
        let mut supp_map: FxHashMap<FileId, &[Suppression]> = FxHashMap::default();
        supp_map.insert(FileId(2), &supp);
        let suppressions = SuppressionContext::from_map(supp_map);

        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert!(result.is_empty());
    }

    #[test]
    fn duplicate_exports_three_modules_same_name() {
        let mut graph = build_graph(&[
            ("/src/entry.ts", true),
            ("/src/a.ts", false),
            ("/src/b.ts", false),
            ("/src/c.ts", false),
        ]);
        for i in 1..=3 {
            graph.modules[i].set_reachable(true);
            graph.modules[i].exports = vec![make_export("sharedFn", 10, 20)];
        }
        // entry.ts imports all three — they share a common importer
        graph.reverse_deps[1] = vec![FileId(0)];
        graph.reverse_deps[2] = vec![FileId(0)];
        graph.reverse_deps[3] = vec![FileId(0)];
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert_eq!(result.len(), 1);
        assert_eq!(result[0].export_name, "sharedFn");
        assert_eq!(result[0].locations.len(), 3);
    }

    #[test]
    fn duplicate_exports_unrelated_leaf_files_not_flagged() {
        // Two route files exporting the same name but with no common importer
        // (e.g., SvelteKit routes in different directories)
        let mut graph = build_graph(&[
            ("/src/entry.ts", true),
            ("/src/routes/foo/page.ts", false),
            ("/src/routes/bar/page.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("Area", 10, 20)];
        graph.modules[2].set_reachable(true);
        graph.modules[2].exports = vec![make_export("Area", 10, 20)];
        // No shared importer: each is imported by a different parent
        // (or not imported at all — just reachable via framework routing)
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert!(
            result.is_empty(),
            "unrelated leaf files should not be flagged as duplicates"
        );
    }

    #[test]
    fn duplicate_exports_direct_import_still_flagged() {
        // Two files where one imports the other — they are connected
        let mut graph = build_graph(&[
            ("/src/entry.ts", true),
            ("/src/a.ts", false),
            ("/src/b.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("helper", 10, 20)];
        graph.modules[2].set_reachable(true);
        graph.modules[2].exports = vec![make_export("helper", 10, 20)];
        // a.ts imports b.ts directly
        graph.reverse_deps[2] = vec![FileId(1)];
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert_eq!(
            result.len(),
            1,
            "directly connected files should still be flagged"
        );
    }

    #[test]
    fn duplicate_exports_different_names_not_duplicated() {
        let mut graph = build_graph(&[
            ("/src/entry.ts", true),
            ("/src/a.ts", false),
            ("/src/b.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("foo", 10, 20)];
        graph.modules[2].set_reachable(true);
        graph.modules[2].exports = vec![make_export("bar", 10, 20)];
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert!(result.is_empty());
    }

    #[test]
    fn duplicate_exports_value_type_merging_not_flagged() {
        // `export const Status = z.enum([...])` + `export type Status = z.infer<typeof Status>`
        // in the same file is TypeScript declaration merging, not a duplicate.
        let mut graph = build_graph(&[("/src/entry.ts", true), ("/src/schema.ts", false)]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![
            make_export("Status", 10, 20),      // value export
            make_type_export("Status", 50, 60), // type export
        ];
        graph.reverse_deps[1] = vec![FileId(0)];
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert!(
            result.is_empty(),
            "value+type merging should not be flagged as duplicate"
        );
    }

    #[test]
    fn duplicate_exports_value_type_cross_file_not_flagged() {
        // File A exports `const Status` and file B exports `type Status`.
        // These are in different TS namespaces and should not be flagged.
        let mut graph = build_graph(&[
            ("/src/entry.ts", true),
            ("/src/a.ts", false),
            ("/src/b.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("Status", 10, 20)];
        graph.modules[2].set_reachable(true);
        graph.modules[2].exports = vec![make_type_export("Status", 10, 20)];
        graph.reverse_deps[1] = vec![FileId(0)];
        graph.reverse_deps[2] = vec![FileId(0)];
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert!(
            result.is_empty(),
            "cross-file value+type should not be flagged"
        );
    }

    #[test]
    fn duplicate_exports_same_namespace_still_flagged() {
        // Two files both export `const helper` (both value exports) — this IS a duplicate.
        let mut graph = build_graph(&[
            ("/src/entry.ts", true),
            ("/src/a.ts", false),
            ("/src/b.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("helper", 10, 20)];
        graph.modules[2].set_reachable(true);
        graph.modules[2].exports = vec![make_export("helper", 10, 20)];
        graph.reverse_deps[1] = vec![FileId(0)];
        graph.reverse_deps[2] = vec![FileId(0)];
        let suppressions = SuppressionContext::empty();
        let result = find_duplicate_exports(&graph, &suppressions, &FxHashMap::default());
        assert_eq!(
            result.len(),
            1,
            "same-namespace duplicates should still be flagged"
        );
    }

    // ---- find_unused_exports tests (exercises compile_ignore_matchers, compile_plugin_matchers,
    //       should_skip_module, is_export_ignored) ----

    /// Helper: build a config with ignore_exports rules.
    fn test_config_with_ignore_exports(
        rules: Vec<fallow_config::IgnoreExportRule>,
    ) -> ResolvedConfig {
        fallow_config::FallowConfig {
            ignore_exports: rules,
            ..Default::default()
        }
        .resolve(
            PathBuf::from("/tmp/test"),
            fallow_config::OutputFormat::Human,
            1,
            true,
            true,
        )
    }

    /// Helper: build a minimal AggregatedPluginResult with used_exports.
    fn make_plugin_result(
        used_exports: Vec<(String, Vec<String>)>,
    ) -> crate::plugins::AggregatedPluginResult {
        crate::plugins::AggregatedPluginResult {
            entry_patterns: vec![],
            config_patterns: vec![],
            always_used: vec![],
            used_exports: used_exports
                .into_iter()
                .map(|(pattern, exports)| {
                    crate::plugins::PluginUsedExportRule::new(
                        "test-plugin",
                        crate::plugins::UsedExportRule::new(pattern, exports),
                    )
                })
                .collect(),
            used_class_members: vec![],
            scss_include_paths: vec![],
            entry_point_roles: FxHashMap::default(),
            referenced_dependencies: vec![],
            discovered_always_used: vec![],
            setup_files: vec![],
            tooling_dependencies: vec![],
            script_used_packages: FxHashSet::default(),
            virtual_module_prefixes: vec![],
            generated_import_patterns: vec![],
            path_aliases: vec![],
            active_plugins: vec![],
            fixture_patterns: vec![],
        }
    }

    fn make_type_export(name: &str, span_start: u32, span_end: u32) -> ExportSymbol {
        ExportSymbol {
            name: ExportName::Named(name.to_string()),
            is_type_only: true,
            visibility: VisibilityTag::None,
            span: Span::new(span_start, span_end),
            references: vec![],
            members: vec![],
        }
    }

    // -- find_unused_exports: basic behavior --

    #[test]
    fn unused_exports_empty_graph() {
        let graph = build_graph(&[]);
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(exports.is_empty());
        assert!(types.is_empty());
    }

    #[test]
    fn unused_exports_detects_unreferenced_export() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("helper", 10, 20)];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert_eq!(exports.len(), 1);
        assert_eq!(exports[0].export_name, "helper");
        assert!(types.is_empty());
    }

    #[test]
    fn unused_exports_skips_referenced_export() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_referenced_export("helper", 10, 20, 0)];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(exports.is_empty());
        assert!(types.is_empty());
    }

    #[test]
    fn unused_exports_skips_public_export() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![ExportSymbol {
            name: ExportName::Named("publicFn".to_string()),
            is_type_only: false,
            visibility: VisibilityTag::Public,
            span: Span::new(10, 20),
            references: vec![],
            members: vec![],
        }];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(exports.is_empty());
        assert!(types.is_empty());
    }

    #[test]
    fn unused_exports_separates_types_from_values() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![
            make_export("valueFn", 10, 20),
            make_type_export("MyType", 30, 40),
        ];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert_eq!(exports.len(), 1);
        assert_eq!(exports[0].export_name, "valueFn");
        assert_eq!(types.len(), 1);
        assert_eq!(types[0].export_name, "MyType");
    }

    // -- should_skip_module: unreachable --

    #[test]
    fn unused_exports_skips_unreachable_module() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/dead.ts", false),
        ]);
        // Module stays unreachable (default)
        graph.modules[1].exports = vec![make_export("orphan", 10, 20)];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(exports.is_empty());
        assert!(types.is_empty());
    }

    // -- should_skip_module: entry point --

    #[test]
    fn unused_exports_skips_entry_point() {
        let mut graph = build_graph(&[("/tmp/test/src/entry.ts", true)]);
        graph.modules[0].exports = vec![make_export("main", 10, 20)];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(exports.is_empty());
        assert!(types.is_empty());
    }

    #[test]
    fn unused_exports_reports_non_framework_exports_in_entry_point_with_plugin_rules() {
        let mut graph = build_graph(&[("/tmp/test/src/app/page.tsx", true)]);
        graph.modules[0].set_reachable(true);
        graph.modules[0].exports = vec![
            make_export("default", 10, 20),
            make_export("generateMetadata", 30, 40),
            make_export("helper", 50, 60),
        ];

        let plugin = make_plugin_result(vec![(
            "src/app/**/page.{ts,tsx,js,jsx}".to_string(),
            vec!["default".to_string(), "generateMetadata".to_string()],
        )]);
        let config = test_config();
        let suppressions = SuppressionContext::empty();

        let (exports, types, _stale) = find_unused_exports(
            &graph,
            &config,
            Some(&plugin),
            &suppressions,
            &FxHashMap::default(),
        );

        assert_eq!(exports.len(), 1);
        assert_eq!(exports[0].export_name, "helper");
        assert!(types.is_empty());
    }

    // -- should_skip_module: CJS-only --

    #[test]
    fn unused_exports_skips_cjs_only_module() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/legacy.js", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].set_cjs_exports(true);
        // No named exports, only module.exports
        graph.modules[1].exports = vec![];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(exports.is_empty());
        assert!(types.is_empty());
    }

    #[test]
    fn unused_exports_does_not_skip_cjs_module_with_named_exports() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/mixed.js", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].set_cjs_exports(true);
        graph.modules[1].exports = vec![make_export("namedFn", 10, 20)];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, _, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert_eq!(exports.len(), 1);
        assert_eq!(exports[0].export_name, "namedFn");
    }

    // -- should_skip_module: Svelte files --

    #[test]
    fn unused_exports_skips_svelte_files() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/Component.svelte", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("count", 10, 20)];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(exports.is_empty());
        assert!(types.is_empty());
    }

    // -- should_skip_module: module passes all checks --

    #[test]
    fn unused_exports_reports_reachable_non_entry_non_cjs_non_svelte() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].set_cjs_exports(false);
        graph.modules[1].exports = vec![make_export("helper", 10, 20)];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, _, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert_eq!(exports.len(), 1);
        assert_eq!(exports[0].export_name, "helper");
    }

    // -- compile_ignore_matchers: empty config --

    #[test]
    fn unused_exports_empty_ignore_config() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("foo", 10, 20)];
        let config = test_config(); // no ignore_exports rules
        let suppressions = SuppressionContext::empty();
        let (exports, _, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert_eq!(
            exports.len(),
            1,
            "no ignore rules, export should be reported"
        );
    }

    // -- compile_ignore_matchers: multiple patterns --

    #[test]
    fn unused_exports_ignore_multiple_patterns() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/types.ts", false),
            ("/tmp/test/src/constants.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("MyType", 10, 20)];
        graph.modules[2].set_reachable(true);
        graph.modules[2].exports = vec![make_export("MY_CONST", 10, 20)];

        let config = test_config_with_ignore_exports(vec![
            fallow_config::IgnoreExportRule {
                file: "src/types.ts".to_string(),
                exports: vec!["*".to_string()],
            },
            fallow_config::IgnoreExportRule {
                file: "src/constants.ts".to_string(),
                exports: vec!["MY_CONST".to_string()],
            },
        ]);
        let suppressions = SuppressionContext::empty();
        let (exports, _, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(
            exports.is_empty(),
            "both exports should be ignored by config rules"
        );
    }

    // -- compile_ignore_matchers: invalid glob handled gracefully --

    #[test]
    fn unused_exports_invalid_ignore_glob_skipped() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("foo", 10, 20)];

        // Invalid glob pattern with unclosed bracket
        let config = test_config_with_ignore_exports(vec![fallow_config::IgnoreExportRule {
            file: "[invalid".to_string(),
            exports: vec!["*".to_string()],
        }]);
        let suppressions = SuppressionContext::empty();
        // Should not panic — invalid globs are silently skipped
        let (exports, _, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert_eq!(
            exports.len(),
            1,
            "invalid glob should be skipped, export still reported"
        );
    }

    // -- is_export_ignored: config wildcard match --

    #[test]
    fn unused_exports_ignore_wildcard_matches_all() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/types.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("TypeA", 10, 20), make_export("TypeB", 30, 40)];

        let config = test_config_with_ignore_exports(vec![fallow_config::IgnoreExportRule {
            file: "src/types.ts".to_string(),
            exports: vec!["*".to_string()],
        }]);
        let suppressions = SuppressionContext::empty();
        let (exports, _, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(
            exports.is_empty(),
            "wildcard * should ignore all exports in matching file"
        );
    }

    // -- is_export_ignored: config specific name match --

    #[test]
    fn unused_exports_ignore_specific_name_only() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![
            make_export("ignored", 10, 20),
            make_export("reported", 30, 40),
        ];

        let config = test_config_with_ignore_exports(vec![fallow_config::IgnoreExportRule {
            file: "src/utils.ts".to_string(),
            exports: vec!["ignored".to_string()],
        }]);
        let suppressions = SuppressionContext::empty();
        let (exports, _, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert_eq!(exports.len(), 1);
        assert_eq!(exports[0].export_name, "reported");
    }

    // -- is_export_ignored: no match --

    #[test]
    fn unused_exports_ignore_rule_wrong_file_no_effect() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("foo", 10, 20)];

        let config = test_config_with_ignore_exports(vec![fallow_config::IgnoreExportRule {
            file: "src/other.ts".to_string(),
            exports: vec!["*".to_string()],
        }]);
        let suppressions = SuppressionContext::empty();
        let (exports, _, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert_eq!(
            exports.len(),
            1,
            "ignore rule for different file should not suppress"
        );
    }

    // -- compile_plugin_matchers: no plugin result --

    #[test]
    fn unused_exports_no_plugin_result() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("foo", 10, 20)];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, _, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert_eq!(
            exports.len(),
            1,
            "None plugin_result means no plugin matchers"
        );
    }

    // -- compile_plugin_matchers: plugin with empty used_exports --

    #[test]
    fn unused_exports_plugin_no_used_exports() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("foo", 10, 20)];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let pr = make_plugin_result(vec![]);
        let (exports, _, _stale) = find_unused_exports(
            &graph,
            &config,
            Some(&pr),
            &suppressions,
            &FxHashMap::default(),
        );
        assert_eq!(
            exports.len(),
            1,
            "plugin with no used_exports should not suppress"
        );
    }

    // -- compile_plugin_matchers / is_export_ignored: plugin used_exports match --

    #[test]
    fn unused_exports_plugin_used_exports_suppresses() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/pages/index.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![
            make_export("getStaticProps", 10, 20),
            make_export("unusedHelper", 30, 40),
        ];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let pr = make_plugin_result(vec![(
            "src/pages/**".to_string(),
            vec!["getStaticProps".to_string()],
        )]);
        let (exports, _, _stale) = find_unused_exports(
            &graph,
            &config,
            Some(&pr),
            &suppressions,
            &FxHashMap::default(),
        );
        assert_eq!(exports.len(), 1);
        assert_eq!(exports[0].export_name, "unusedHelper");
    }

    // -- is_export_ignored: matching both config and plugin --

    #[test]
    fn unused_exports_both_config_and_plugin_ignore() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/api/handler.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("handler", 10, 20)];

        let config = test_config_with_ignore_exports(vec![fallow_config::IgnoreExportRule {
            file: "src/api/*.ts".to_string(),
            exports: vec!["handler".to_string()],
        }]);
        let suppressions = SuppressionContext::empty();
        let pr = make_plugin_result(vec![(
            "src/api/**".to_string(),
            vec!["handler".to_string()],
        )]);
        let (exports, _, _stale) = find_unused_exports(
            &graph,
            &config,
            Some(&pr),
            &suppressions,
            &FxHashMap::default(),
        );
        assert!(
            exports.is_empty(),
            "export matching both config and plugin should be ignored"
        );
    }

    // -- compile_plugin_matchers: invalid plugin glob handled gracefully --

    #[test]
    fn unused_exports_invalid_plugin_glob_skipped() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("foo", 10, 20)];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let pr = make_plugin_result(vec![("[invalid".to_string(), vec!["foo".to_string()])]);
        // Should not panic
        let (exports, _, _stale) = find_unused_exports(
            &graph,
            &config,
            Some(&pr),
            &suppressions,
            &FxHashMap::default(),
        );
        assert_eq!(exports.len(), 1, "invalid plugin glob should be skipped");
    }

    // -- find_unused_exports: re-export semantic detection --

    #[test]
    fn unused_exports_marks_re_export_semantically() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/barrel.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![make_export("reexported", 100, 120)];
        // The export must have a matching ReExportEdge for the unused-export
        // detector to classify it as a re-export. This mirrors how the graph
        // builder synthesizes ExportSymbol entries from ReExportInfo.
        graph.modules[1].re_exports = vec![ReExportEdge {
            source_file: FileId(0),
            imported_name: "reexported".to_string(),
            exported_name: "reexported".to_string(),
            is_type_only: false,
            span: oxc_span::Span::default(),
        }];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, _, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert_eq!(exports.len(), 1);
        assert!(
            exports[0].is_re_export,
            "export with matching ReExportEdge should be flagged as re-export"
        );
        // span_start carries the original byte offset (100), not the (0,0) sentinel
        // — confirms that the re-export reporting uses the visitor's real span.
        assert_eq!(exports[0].span_start, 100);
    }

    // ---- collect_export_usages tests ----

    #[test]
    fn collect_usages_empty_graph() {
        let graph = build_graph(&[]);
        let result = collect_export_usages(&graph, &FxHashMap::default());
        assert!(result.is_empty());
    }

    #[test]
    fn collect_usages_skips_unreachable_modules() {
        let mut graph = build_graph(&[("/src/dead.ts", false)]);
        graph.modules[0].exports = vec![make_export("unused", 10, 20)];
        let result = collect_export_usages(&graph, &FxHashMap::default());
        assert!(result.is_empty());
    }

    #[test]
    fn collect_usages_skips_synthetic_exports() {
        let mut graph = build_graph(&[("/src/barrel.ts", true)]);
        graph.modules[0].exports = vec![make_export("reexported", 0, 0)];
        let result = collect_export_usages(&graph, &FxHashMap::default());
        assert!(result.is_empty());
    }

    #[test]
    fn collect_usages_counts_references() {
        let mut graph = build_graph(&[("/src/utils.ts", true), ("/src/app.ts", false)]);
        graph.modules[0].exports = vec![make_referenced_export("helper", 10, 20, 1)];
        let result = collect_export_usages(&graph, &FxHashMap::default());
        assert_eq!(result.len(), 1);
        assert_eq!(result[0].export_name, "helper");
        assert_eq!(result[0].reference_count, 1);
    }

    #[test]
    fn collect_usages_zero_references_still_reported() {
        let mut graph = build_graph(&[("/src/utils.ts", true)]);
        graph.modules[0].exports = vec![make_export("unused", 10, 20)];
        let result = collect_export_usages(&graph, &FxHashMap::default());
        assert_eq!(result.len(), 1);
        assert_eq!(result[0].export_name, "unused");
        assert_eq!(result[0].reference_count, 0);
        assert!(result[0].reference_locations.is_empty());
    }

    #[test]
    fn collect_usages_multiple_exports_same_module() {
        let mut graph = build_graph(&[("/src/utils.ts", true)]);
        graph.modules[0].exports = vec![make_export("alpha", 10, 20), make_export("beta", 30, 40)];
        let result = collect_export_usages(&graph, &FxHashMap::default());
        assert_eq!(result.len(), 2);
        let names: FxHashSet<&str> = result.iter().map(|u| u.export_name.as_str()).collect();
        assert!(names.contains("alpha"));
        assert!(names.contains("beta"));
    }

    // -- unreachable module with mixed references (blindspot fix) --

    #[test]
    fn unused_exports_checks_unreachable_module_with_mixed_references() {
        // Unreachable module with 2 exports:
        // - "usedByUnreachable" referenced by another unreachable module (should still be flagged)
        // - "totallyUnused" referenced by nobody (should be flagged)
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/helpers.ts", false),
            ("/tmp/test/src/setup.ts", false),
        ]);
        // helpers.ts is unreachable, has one export referenced by setup.ts (also unreachable)
        graph.modules[1].exports = vec![
            ExportSymbol {
                name: ExportName::Named("usedByUnreachable".to_string()),
                is_type_only: false,
                visibility: VisibilityTag::None,
                span: Span::new(10, 30),
                references: vec![SymbolReference {
                    from_file: FileId(2), // setup.ts — also unreachable
                    kind: crate::graph::ReferenceKind::NamedImport,
                    import_span: Span::new(0, 10),
                }],
                members: vec![],
            },
            make_export("totallyUnused", 40, 55),
        ];
        // setup.ts is also unreachable
        graph.modules[2].exports = vec![];

        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        // Both exports should be flagged: the unreachable-to-unreachable reference doesn't count
        let names: FxHashSet<&str> = exports.iter().map(|e| e.export_name.as_str()).collect();
        assert!(
            names.contains("usedByUnreachable"),
            "reference from unreachable module should not save an export"
        );
        assert!(
            names.contains("totallyUnused"),
            "completely unreferenced export should be flagged"
        );
        assert_eq!(exports.len(), 2);
        assert!(types.is_empty());
    }

    #[test]
    fn unused_exports_skips_export_referenced_by_reachable() {
        // Unreachable module with 1 export referenced by a REACHABLE module.
        // The export should NOT be flagged as unused.
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/helpers.ts", false),
        ]);
        // helpers.ts is unreachable but has an export referenced by entry.ts (reachable)
        graph.modules[1].exports = vec![ExportSymbol {
            name: ExportName::Named("usedByReachable".to_string()),
            is_type_only: false,
            visibility: VisibilityTag::None,
            span: Span::new(10, 28),
            references: vec![SymbolReference {
                from_file: FileId(0), // entry.ts — reachable (entry point)
                kind: crate::graph::ReferenceKind::NamedImport,
                import_span: Span::new(0, 10),
            }],
            members: vec![],
        }];

        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(
            exports.is_empty(),
            "export referenced by reachable module should not be flagged"
        );
        assert!(types.is_empty());
    }

    // -- VisibilityTag suppression --

    #[test]
    fn unused_exports_skips_internal_visibility() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![ExportSymbol {
            name: ExportName::Named("internalHelper".to_string()),
            is_type_only: false,
            visibility: VisibilityTag::Internal,
            span: Span::new(10, 30),
            references: vec![],
            members: vec![],
        }];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(
            exports.is_empty(),
            "@internal export should not be flagged as unused"
        );
        assert!(types.is_empty());
    }

    #[test]
    fn unused_exports_skips_beta_visibility() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![ExportSymbol {
            name: ExportName::Named("betaFeature".to_string()),
            is_type_only: false,
            visibility: VisibilityTag::Beta,
            span: Span::new(10, 30),
            references: vec![],
            members: vec![],
        }];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(
            exports.is_empty(),
            "@beta export should not be flagged as unused"
        );
        assert!(types.is_empty());
    }

    #[test]
    fn unused_exports_skips_alpha_visibility() {
        let mut graph = build_graph(&[
            ("/tmp/test/src/entry.ts", true),
            ("/tmp/test/src/utils.ts", false),
        ]);
        graph.modules[1].set_reachable(true);
        graph.modules[1].exports = vec![ExportSymbol {
            name: ExportName::Named("alphaFeature".to_string()),
            is_type_only: false,
            visibility: VisibilityTag::Alpha,
            span: Span::new(10, 30),
            references: vec![],
            members: vec![],
        }];
        let config = test_config();
        let suppressions = SuppressionContext::empty();
        let (exports, types, _stale) =
            find_unused_exports(&graph, &config, None, &suppressions, &FxHashMap::default());
        assert!(
            exports.is_empty(),
            "@alpha export should not be flagged as unused"
        );
        assert!(types.is_empty());
    }

    // -- include_entry_exports --

    #[test]
    fn unused_exports_include_entry_exports_flag() {
        // With include_entry_exports = false (default), entry point exports are skipped
        let mut graph = build_graph(&[("/tmp/test/src/entry.ts", true)]);
        graph.modules[0].exports = vec![make_export("main", 10, 20)];

        let config_off = test_config();
        assert!(!config_off.include_entry_exports);
        let suppressions = SuppressionContext::empty();
        let (exports_off, _, _stale) = find_unused_exports(
            &graph,
            &config_off,
            None,
            &suppressions,
            &FxHashMap::default(),
        );
        assert!(
            exports_off.is_empty(),
            "entry export should be skipped when include_entry_exports is false"
        );

        // With include_entry_exports = true, entry point exports ARE checked
        let mut config_on = test_config();
        config_on.include_entry_exports = true;
        let (exports_on, _, _stale) = find_unused_exports(
            &graph,
            &config_on,
            None,
            &suppressions,
            &FxHashMap::default(),
        );
        assert_eq!(
            exports_on.len(),
            1,
            "entry export should be flagged when include_entry_exports is true"
        );
        assert_eq!(exports_on[0].export_name, "main");
    }
}