import type { Comment as BaseComment, Options as ParseOptions, Statement as BaseStatement } from 'parse-statements'; export type { CommentPair, OnCommentError, OnGlobalError, OnParse, Parse } from 'parse-statements'; /** * Type of comment for parse options. */ export type Comment = BaseComment; /** * Internal context in `MutableImportsExports`. */ export type Context = { lineColumnCache: Record | undefined; linesIndexes: readonly number[] | undefined; readonly options: Options | undefined; readonly source: string; }; /** * Type of `Context` key. */ export type ContextKey = typeof CONTEXT_KEY; /** * Parsed JSON presentation of `import(...)` statement. */ export type DynamicImport = Position & { with?: With; }; /** * Excludes `undefined` from some `Type`. */ export type ExcludeUndefined = Exclude; /** * Parsed JSON presentation of imports, exports and reexports of ECMAScript/TypeScript module. */ export type ImportsExports = DeepReadonly; /** * Parsed JSON presentation of `export interface ...` statement. */ export type InterfaceExport = Position & { isDeclare?: true; }; /** * Kind of exported declaration. */ export type Kind = 'abstract class' | 'async function' | 'async function*' | 'class' | 'const' | 'const enum' | 'declare abstract class' | 'declare class' | 'declare const' | 'declare const enum' | 'declare destructuring const' | 'declare destructuring let' | 'declare destructuring var' | 'declare enum' | 'declare function' | 'declare let' | 'declare var' | 'destructuring const' | 'destructuring let' | 'destructuring var' | 'enum' | 'function' | 'function*' | 'let' | 'var'; /** * String with position of symbol in source, like `3:12` -- line 3, column 12. */ export type LineColumn = Brand; /** * Internal presentation of imports, exports and reexports of module. */ export type MutableImportsExports = MutableImportsExportsWithoutContext & Readonly<{ [CONTEXT_KEY]: Context; }>; /** * Imported or exported name (identifier). */ export type Name = Brand; /** * Parsed JSON presentation of `export {...}` statement. */ export type NamedExport = Position & { names?: Names; types?: Names; }; /** * Parsed JSON presentation of `import {...} from ...` statement. */ export type NamedImport = Position & { default?: Name; names?: Names; types?: Names; with?: With; }; /** * Parsed JSON presentation of `export {...} from ...` statement. */ export type NamedReexport = Position & { names?: Names; types?: Names; with?: With; }; /** * Parsed JSON presentation of names in `import`/`export` statements. */ export type Names = Record; /** * Parsed JSON presentation of `import * as ...` statement. */ export type NamespaceImport = Position & { default?: Name; namespace: Name; with?: With; }; /** * Parsed JSON presentation of `export * as ... from ...` statement. */ export type NamespaceReexport = Position & { namespace: Name; with?: With; }; /** * Options of `parseImportsExports` function. */ export type Options = Readonly<{ /** * If `true`, then we ignore `module.exports = ...`/`(module.)exports.foo = ...` expressions * during parsing (maybe a little faster). * By default (if `false` or skipped option), `module.exports = ...`/`(module.)exports.foo = ...` * expressions are parsed. */ ignoreCommonJsExports?: boolean; /** * If `true`, then we ignore `import(...)` expressions during parsing (maybe a little faster). * By default (if `false` or skipped option), `import(...)` expressions are parsed. */ ignoreDynamicImports?: boolean; /** * If `true`, then we ignore regular expression literals (`/.../`) * during parsing (maybe a little faster). * By default (if `false` or skipped option), regular expression literals are parsed. */ ignoreRegexpLiterals?: boolean; /** * If `true`, then we ignore `require(...)` expressions during parsing (maybe a little faster). * By default (if `false` or skipped option), `require(...)` expressions are parsed. */ ignoreRequires?: boolean; /** * If `true`, then we ignore string literals during parsing (maybe a little faster). * By default (if `false` or skipped option), string literals are parsed, that is, * the text inside them cannot be interpreted as another expression. */ ignoreStringLiterals?: boolean; /** * If `true`, then we include the token's start line-column and the token's end line-column * in the token's position in source file. * By default (if `false` or skipped option), the position includes only * the token's start index and the token end index. */ includeLineColumn?: boolean; }>; /** * Parsed JSON presentation of `export namespace ...` statement. */ export type NamespaceExport = Position & { isDeclare?: true; }; export type { ParseOptions }; /** * Path to a module or package after the `from` keyword. */ export type Path = Brand; /** * Position of import, export or reexport statement in source file. */ export type Position = { start: number; startLineColumn?: LineColumn; end: number; endLineColumn?: LineColumn; }; /** * Parsed JSON presentation of `require(...)` statement. */ export type Require = Position; /** * Parsed JSON presentation of `export * from ...` statement. */ export type StarReexport = Position & { with?: With; }; /** * Type of statement for parse options. */ export type Statement = BaseStatement; /** * Parsed JSON presentation of `export type {...}` statement. */ export type TypeNamedExport = Position & { names?: Names; }; /** * Parsed JSON presentation of `export type {...} from ...` statement. */ export type TypeNamedReexport = Position & { names?: Names; }; /** * Import/reexport attributes in `with`-part of import/reexport (like `with { type: "json" }`). */ export type With = Record; /** * Parsed JSON presentation of `(module.)exports.foo = ...` statement. */ type CommonJsExport = Position & { startsWithModule?: true; }; /** * Inner key for brand types. */ declare const BRAND: unique symbol; /** * Creates brand (nominal) type from regular type. */ type Brand = Type & { readonly [BRAND]: Key; }; /** * Parsed JSON presentation of `module.exports = ...` statement. */ type CommonJsNamespaceExport = Position; /** * Symbol for generation type of `Context` key. */ declare const CONTEXT_KEY: unique symbol; /** * Parsed JSON presentation of `export (class|const|function|var...) ...` statement. */ type DeclarationExport = Position & { kind: Kind; }; /** * Parsed JSON presentation of `export default ...` statement. */ type DefaultExport = Position; /** * Readonly type with recursive applying. * `DeepReadonly<{foo: {bar: 0}}>` = `{readonly foo: {readonly bar: 0}}`. */ type DeepReadonly = Type extends Brand ? Type : { readonly [Key in keyof Type]: DeepReadonly; }; /** * Mutable parsed JSON presentation of imports, exports and reexports of module. */ type MutableImportsExportsWithoutContext = { /** * Imports. */ /** * `import {...} from ...`. */ namedImports: Record> | undefined; /** * `import * as ...`. */ namespaceImports: Record> | undefined; /** * `import(...)`. */ dynamicImports: Record> | undefined; /** * `require(...)`. */ requires: Record> | undefined; /** * `import type {...} from ...`. */ typeNamedImports: Record> | undefined; /** * `import type * as ...`. */ typeNamespaceImports: Record> | undefined; /** * `typeof import(...)`. */ typeDynamicImports: Record> | undefined; /** * Reexports. */ /** * `export {...} from ...`. */ namedReexports: Record> | undefined; /** * `export * as ... from ...`. */ namespaceReexports: Record> | undefined; /** * `export * from ...`. */ starReexports: Record> | undefined; /** * `export type {...} from ...`. */ typeNamedReexports: Record> | undefined; /** * `export type * as ... from ...`. */ typeNamespaceReexports: Record> | undefined; /** * `export type * from ...`. */ typeStarReexports: Record> | undefined; /** * Exports. */ /** * `export default ...`. */ defaultExport: DefaultExport | undefined; /** * `export {...}`. */ namedExports: NotEmptyArray | undefined; /** * `export (class|const|function|var...) ...`. */ declarationExports: Record | undefined; /** * `export type {...}`. */ typeNamedExports: NotEmptyArray | undefined; /** * `export type ...`. */ typeExports: Record | undefined; /** * `export interface ...`. */ interfaceExports: Record> | undefined; /** * `export namespace ...`. */ namespaceExports: Record> | undefined; /** * `module.exports = ...`. */ commonJsNamespaceExport: CommonJsNamespaceExport | undefined; /** * `(module.)exports.foo = ...`. */ commonJsExports: Record | undefined; /** * Syntax errors of module. */ errors: Record | undefined; }; /** * Readonly array with at least one element. */ type NotEmptyArray = readonly [Element, ...Element[]]; /** * Parsed JSON presentation of `export type ...` statement. */ type TypeExport = Position & { isDeclare?: true; }; /** * Parsed JSON presentation of `import type {...} from ...` statement. */ type TypeNamedImport = Position & { default?: Name; names?: Names; }; /** * Parsed JSON presentation of `import type * as ...` statement. */ type TypeNamespaceImport = Position & { namespace: Name; }; /** * Parsed JSON presentation of `export type * as ... from ...` statement. */ type TypeNamespaceReexport = Position & { namespace: Name; }; /** * Parsed JSON presentation of `export type * from ...` statement. */ type TypeStarReexport = Position;