Babel visitor that simplifies working with import and require calls in AST traversal. Version 2.1.0 provides ImportDefinition objects for each imported symbol, supporting both ESM imports and CJS require, dynamic imports, type imports, and re-exports. Designed for use in babel plugins or with @babel/traverse, it offers methods like remove() and fork() to modify import statements. Differentiates from higher-level tools like transform-imports by giving direct access to the underlying AST nodes with a minimal, focused API. Actively maintained with peer dependencies on @babel/core, @babel/runtime, and @babel/types (compatible with Babel 7+).
npm install imports-visitorVerified import paths — ran on the pinned version, not inferred.
Demonstrates using importsVisitor in a Babel plugin to collect ImportDefinition objects and log them.
Use require('imports-visitor').default or import importsVisitor from 'imports-visitor' instead of destructuring.Use import type { ImportDefinition } from 'imports-visitor' for TypeScript, or omit completely in plain JS.Always pass a fresh array (e.g., { imports: [] }) on each traverse call.Use fork({ insert: 'after' }) for the common case. Check documentation for full options.Use: const importsVisitor = require('imports-visitor').default; OR import importsVisitor from 'imports-visitor';Run: npm install --save-dev @babel/core @babel/runtime @babel/types
Change to: import type { ImportDefinition } from 'imports-visitor';