Skip to content

Dead symbol detector should trace re-exports through barrel files #37

@fixcik

Description

@fixcik

Problem

When a symbol is re-exported through a barrel file (index.ts), the dead_code detector considers the originating file as "alive" because it is re-exported by an entry point. However, the re-exported symbol itself may never be imported by any consumer.

This means symbols that are only used in tests but re-exported through barrel files are invisible to both:

  • dead_code detector (file is re-exported → not dead)
  • count_test_imports: false option (file-level check bypassed by re-export)

Example

packages/utils/src/
  index.ts          ← entry point, barrel: export * from './payload-sanitizer.js'
  payload-sanitizer.ts  ← exports sanitizePayload()
  payload-sanitizer.spec.ts ← only consumer of sanitizePayload()

sanitizePayload is never imported by any production code, only by the test file. But the dead_code detector sees that payload-sanitizer.ts is re-exported through index.ts (an entry point) and considers it alive.

Current Behavior

  • dead_code detector works at file level
  • is_reexported() returns true because index.ts re-exports payload-sanitizer.ts
  • File is not flagged, even though no consumer ever imports sanitizePayload from the barrel

Expected Behavior

The dead symbol detector (dead_symbols) should trace re-exports through barrel files and verify that the re-exported symbol is actually imported by at least one consumer downstream. If no consumer imports the symbol (only tests do), it should be flagged.

Possible Approaches

  1. Enhance dead_symbols detector — when a symbol is re-exported through a barrel, check if any file imports that symbol from the barrel (not just that the barrel re-exports it)
  2. Transitive usage analysis — follow re-export chains and verify end-to-end usage
  3. Combine with count_test_imports — if the only downstream consumers are test files, flag the symbol

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions