UNPKG

1.51 kBTypeScriptView Raw
1// Type definitions for es-module-lexer 0.3
2// Project: https://github.com/guybedford/es-module-lexer
3// Definitions by: Tiger Oakes <https://github.com/NotWoods>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6export interface ImportSpecifier {
7 /**
8 * Start of module specifier
9 * @example
10 * const source = `import { a } from 'asdf'`;
11 * const [imports, exports] = parse(source);
12 * source.substring(imports[0].s, imports[0].e);
13 * // Returns "asdf"
14 */
15 s: number;
16 /**
17 * End of module specifier
18 */
19 e: number;
20
21 /**
22 * Start of import statement
23 * @example
24 * const source = `import { a } from 'asdf'`;
25 * const [imports, exports] = parse(source);
26 * source.substring(imports[0].s, imports[0].e);
27 * // Returns "import { a } from 'asdf';"
28 */
29 ss: number;
30 /**
31 * End of import statement
32 */
33 se: number;
34
35 /**
36 * If this import statement is a dynamic import, this is the start value.
37 * Otherwise this is `-1`.
38 */
39 d: number;
40}
41
42/**
43 * Wait for init to resolve before calling `parse`.
44 */
45export const init: Promise<void>;
46
47/**
48 * Outputs the list of exports and locations of import specifiers,
49 * including dynamic import and import meta handling.
50 * @param source Source code to parser
51 * @param name Optional sourcename
52 * @returns Tuple contaning imports list and exports list.
53 */
54export function parse(source: string, name?: string): [ImportSpecifier[], string[]];