es-module-lexer
Version:
Lexes ES modules returning their import/export metadata
80 lines (75 loc) • 2.72 kB
TypeScript
// Type definitions for the es-module-lexer minimal build (es-module-lexer/minimal).
// Auto-generated by build/gen-min-dts.mjs — do not edit.
import type { ImportType, ParseError } from './lexer.js';
export type {
ImportType, StaticImportType, DynamicImportType, ImportMetaType,
StaticSourcePhaseType, DynamicSourcePhaseType, StaticDeferPhaseType,
DynamicDeferPhaseType, StaticReexportStarType, ParseError
} from './lexer.js';
/**
* Import specifier — minimal build.
*
* The minimal build keeps the v2 flat import shape; the full build's
* string-discriminated Import union does not apply.
*/
export interface ImportSpecifier {
/**
* Module specifier, handling escape sequences where possible; undefined
* when not statically analyzable. Template glob specifiers are not
* reported (always undefined for interpolated templates).
*/
readonly n: string | undefined;
/** Numeric type of the import */
readonly t: ImportType;
/** Start of module specifier */
readonly s: number;
/** End of module specifier */
readonly e: number;
/** Start of import statement */
readonly ss: number;
/** End of import statement */
readonly se: number;
/** Dynamic import expression start, -1 for static, -2 for import.meta */
readonly d: number;
/** Start of import attributes, or -1 (read via source.slice(a, se - 1)) */
readonly a: number;
}
/**
* Export specifier — minimal build.
*
* The minimal build keeps the v2 flat export shape. It does not classify
* exports, track origins or statement starts, or emit bare star exports.
*/
export interface ExportSpecifier {
/** Exported name */
readonly n: string;
/** Local name, or undefined (reexports have no local binding) */
readonly ln: string | undefined;
/** Start of exported name */
readonly s: number;
/** End of exported name */
readonly e: number;
/** Start of local name, or -1 */
readonly ls: number;
/** End of local name, or -1 */
readonly le: number;
}
/**
* Outputs the lexical analysis of the source — minimal build.
*
* Returns a 2-tuple of imports and exports. Unlike the full build, the minimal
* build does not emit the facade / hasModuleSyntax flags or a parsed
* attribute list (read attributes via `source.slice(a, se - 1)`).
*
* @param source Source code to parse
* @param name Optional sourcename
*/
export declare function parse(source: string, name?: string): readonly [
imports: ReadonlyArray<ImportSpecifier>,
exports: ReadonlyArray<ExportSpecifier>
];
/**
* Asynchronously compile the lexer. Await the returned promise before
* calling `parse`. Idempotent: repeated calls share the same promise.
*/
export declare const init: () => Promise<void>;