β οΈ Work In Progress - This project is under active development. Do not use in production environments.
π¦ A Rust implementation of es-module-lexer with Node.js bindings via napi-rs.
Fast JavaScript ES module lexer that outputs the list of exports and locations of import specifiers, including dynamic import and import meta handling. Built with Rust for memory safety and maintainability.
This library provides a memory-safe, maintainable alternative to the original es-module-lexer:
- π Memory Safety: Rust's ownership system prevents segfaults and memory leaks
- π Type Safety: Full TypeScript definitions with compile-time guarantees
- π οΈ Maintainability: Modern Rust codebase with cargo, clippy, rustfmt
- π― API Compatible: Drop-in replacement for es-module-lexer
- π§ͺ Well Tested: Unit tests, integration tests, and property-based tests
- β Static and dynamic import/export parsing
- β Import attributes (with syntax)
- β Source phase imports
- β Import meta detection
- β Facade module detection
- β Cross-platform pre-built binaries
- β Zero runtime dependencies
npm install es-module-lexer-rsPre-built binaries are provided for Linux, macOS, Windows, and FreeBSD (x64, ARM64).
interface ImportSpecifier {
n?: string; // module specifier
t: number; // import type (1=static, 2=dynamic, 3=import.meta, etc.)
s: number; // module specifier start
e: number; // module specifier end
ss: number; // statement start
se: number; // statement end
d: number; // dynamic import position (-1 if not dynamic)
a: number; // assert/with clause position (-1 if none)
at?: [string, string][] | null; // parsed import attributes
}
interface ExportSpecifier {
n: string; // export name
ln?: string; // local name (for re-exports)
s: number; // export name start
e: number; // export name end
ls: number; // local name start (-1 if none)
le: number; // local name end (-1 if none)
}
interface ParseResult {
imports: ImportSpecifier[];
exports: ExportSpecifier[];
facade: boolean; // true if module only contains imports/exports
hasModuleSyntax: boolean; // true if module has any import/export
}
function parse(source: string): ParseResult;For detailed usage examples, see the documentation.
- Static and dynamic imports/exports
- Import attributes (
withsyntax) - Source phase imports
- Import meta
- String export names
- Re-exports
- All ES module syntax variations
MIT
Inspired by es-module-lexer by Guy Bedford.
Built with Rust π¦ and napi-rs