mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-10-25 12:00:02 +08:00
fix(dead-code): a type that declare module or declare global merges outward is not dead (#2418)
The viewer's Dead code screen listed TypeScript interfaces that augment a
type declared outside the project: chart.js's `PluginOptionsByType` in
`declare module 'chart.js' { … }` (ghostfolio), `interface Window` in
`declare global { … }` (angular-realworld). The library or the runtime
reads them through the type they merge into, so nothing in the repository
names them, and the index recorded them as unexported file-level
interfaces.
TypeScript exports what such a body declares without the keyword. The
binder makes an ambient module body an export context unless it holds an
export declaration (`export {}`, `export =`, `export default x`), and a
namespace nested in one is ambient too. Both extractors now set isExported
that way: isAmbientExport in languages/typescript.ts, shared by TSX and
ArkTS, and is_ambient_export in the kernel's tsjs walker. The exported rule
then drops them, counted under `exported`, and that count's label now
names them. `declare namespace X` is unchanged: in a module file X belongs
to that file.
The resolver sees them as exported too. A file holding `declare global`
was already treated as exporting, so nothing moves there. A `declare
module` member becomes reachable across files by name.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d8a7f868b3
commit
e0bbb6620f
@@ -95,7 +95,7 @@ export interface WireDeadCode {
|
||||
const EXCLUSION_LABELS: Record<keyof DeadCodeExclusions, string> = {
|
||||
tests: 'in test files',
|
||||
generated: 'in generated files',
|
||||
exported: 'exported, or declared in a header',
|
||||
exported: 'exported, declared in a header, or merged into a library or global type',
|
||||
exportsUnknown: 'in languages this index records no exports for',
|
||||
declarations: 'abstract, or declared on an interface',
|
||||
decorated: 'carrying a decorator, so a framework registers them',
|
||||
|
||||
Reference in New Issue
Block a user