Skip to content

fix(scanner): ignore type-only imports and exports - #31

Open
adelbeke wants to merge 1 commit into
callstackincubator:masterfrom
adelbeke:skip-type-only-imports
Open

adelbeke wants to merge 1 commit into
callstackincubator:masterfrom
adelbeke:skip-type-only-imports

Conversation

@adelbeke

@adelbeke adelbeke commented Nov 7, 2026

Copy link
Copy Markdown

Why

TypeScript type-only imports and re-exports are erased at build time by tsc, Babel and Metro. They cannot change what runs, so they should not be dependency edges for E2E impact analysis.

Sniffler 0.5.0 skips the type keyword and still records the edge. On typed apps this links modules that never depend on each other at runtime. A common case in React Native apps is a navigation params file that does import type { XStackParamList } from "<each feature>": every feature then looks like it depends on every other feature through that one file, and almost any change selects almost every test.

Measured on a React Native app of about 1,700 modules, replaying real pull requests with a patched scanner:

Metric (median per PR) Before After
Affected modules 1,443 156
Selected E2E tests (out of 33) 29 17

What changes

The scanner (src/scanner/scan-file.ts) no longer records:

  • import type X from "x", import type { A } from "x", import type * as N from "x"
  • export type { A } from "x", export type * from "x", export type * as N from "x"
  • import { type A, type B } from "x" (every specifier is inline type)

Mixed lists such as import { type A, b } from "x" and export { type A, b } from "x" keep the edge, and only the runtime specifiers (b) go into the entity selection.

It also fixes two parsing cases around the type keyword that 0.5.0 got wrong:

  • import type from "x" (a default import named type) was dropped; it is now a runtime default import. import type, { a } from "x" keeps working.
  • import { type as alias } from "x" was read as a type-only import of alias; it is now the binding type aliased to alias.

Local export type { A } (no from) still emits local exports, as before.

Other changes:

  • SCANNER_VERSION is bumped from scan-file-v1 to scan-file-v2, so caches written by the old scanner are invalidated instead of reusing type-only edges. tests/impact-cache.test.ts now uses the constant instead of the literal.
  • src/scanner/scan-file.js (the committed compiled copy that tests import) is regenerated from the .ts source with tsc -p tsconfig.build.json; it matches the build output byte for byte, minus the source map comment.
  • README and CONTRIBUTING mention the new scanner behavior.

Tests

  • tests/scanner.test.ts: new type-only imports and exports suite covering all the forms above, the non-regressions (import type from, import type, { a } from, import { type }, import { type as alias }, import {} from, side-effect imports), mixed inline specifiers, and inline type in re-exports. The existing first test expected import type { Value } to produce an edge; that expectation is removed.
  • tests/graph.test.ts: a graph and traversal test showing a change to a module imported only through type-only imports affects only that module.

pnpm test: 33 files, 228 tests passing. pnpm lint and pnpm build pass.

pnpm benchmark (synthetic graph, 1,441 files), master vs this branch, in hz:

Scenario master branch
shared-root 88.85 89.36
deep-branch 122.64 126.93

No regression, within noise.

Notes for review

  • Under verbatimModuleSyntax (or Babel onlyRemoveTypeImports), import { type A } from "x" is kept as a side-effect import import "x". This PR follows the default tsc and Babel behavior (the whole import is removed). If you want to support that mode, a config flag could keep the edge for all-inline-type imports. Happy to add it if useful.
  • I did not run pnpm benchmark:app.

🤖 Generated with Claude Code

TypeScript type-only imports and re-exports are erased by tsc, Babel and
Metro, so they can never change runtime behavior. Recording them as
dependency edges made impact analysis select far more modules than a
change can actually reach, especially through shared route/params type
files that import a type from every feature.

The scanner now skips:
- import type X / import type { A } / import type * as N from "x"
- export type { A } from "x" / export type * (as N) from "x"
- import { type A, type B } from "x" (all specifiers type-only)

Mixed lists such as import { type A, b } keep the edge and only select
the runtime specifiers. A default import named type (import type from
"x", import type, { a } from "x") and bindings named type
(import { type }, import { type as alias }) are now parsed correctly.

Bump SCANNER_VERSION to scan-file-v2 so cached scan results produced by
the old scanner are invalidated.
@adelbeke
adelbeke marked this pull request as ready for review November 7, 2026 11:43

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant