rs-module-lexer is an ES module parser built with Rust, offering a drop-in compatible output data structure with `es-module-lexer`. Currently at version 2.8.0, it maintains an active release cadence with frequent minor updates. Its key differentiator is the ability to directly parse TypeScript (TS/TSX) and JSX files, unlike `es-module-lexer` which necessitates a prior transformation step. Powered by SWC, this library collapses the transform and parse steps into a single API call, streamlining module analysis in bundlers and build tools. It's designed for scenarios requiring fast and accurate identification of imports and exports across various JavaScript and TypeScript syntaxes, providing a consistent API and data format.
npm install rs-module-lexerVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing multiple TypeScript and JavaScript files asynchronously, showcasing import and export extraction.
Change `const [imports, exports] = parse(code)` to `const { output } = await parseAsync({ input: [{ filename, code }] }); const { imports, exports } = output[0];`Always provide a `filename` with the correct extension in the input object: `parseAsync({ input: [{ filename: 'component.tsx', code: '...' }] })`No direct fix needed, but be aware of parsing behavior changes if upgrading from pre-2.0.0 versions and using these specific syntaxes.
Remove any `await init` or `init()` calls when migrating from `es-module-lexer` to `rs-module-lexer`.
Ensure you are using `import { parse, parseAsync } from 'rs-module-lexer'` for ES modules, or verify your environment supports top-level await for dynamic imports.The result of `parseAsync` is an object `{ output: [...] }`. You need to access `result.output[index]` to get the parsing details for a specific file. For a single input file, use `const { output: [firstFileResult] } = await parseAsync(...)`.Always provide a `filename` with the accurate extension (e.g., `.ts`, `.tsx`, `.jsx`) in the input object passed to `parseAsync` or `parse`.
No dependency data recorded yet.