import * as rp from "regexp-tree"; import * as ast from "regexp-tree/ast"; declare module "regexp-tree/ast" { type AstNode = AstTypes[keyof AstTypes]; interface AstTypes { "RegExp": AstRegExp; "Disjunction": Disjunction; "Alternative": Alternative; "Assertion": Assertion; "Char": Char; "CharacterClass": CharacterClass; "ClassRange": ClassRange; "Backreference": Backreference; "Group": Group; "Repetition": Repetition; "Quantifier": Quantifier; } namespace AstPath { interface RegExp { node: ast.AstRegExp; parentPath: null; parent: null; property: null; index: null; getParent(): null; setChild(node: T, index: null | undefined, property: "body"): AstPath; setChild(node: null, index: null | undefined, property: "body"): null; setChild(node: T | null, index: null | undefined, property: "body"): AstPath | null; getChild(n?: number): AstPath | null; getPreviousSibling(): null; getNextSibling(): null; update(nodeProps: Partial): void; remove(): void; isRemoved(): boolean; hasEqualSource(path: AstPath): boolean; jsonEncode(options?: { format?: string | number, useLoc?: boolean }): string; } interface Disjunction { node: ast.Disjunction; parent: ast.AstRegExp | ast.Disjunction | ast.Alternative | ast.Assertion | ast.Group | ast.Repetition | null; parentPath: AstPath | null; property: string | null; index: number | null; getParent(): AstPath | null; setChild(node: T, index: number, property?: "expressions"): AstPath; setChild(node: null, index: number, property?: "expressions"): null; setChild(node: T | null, index: number, property?: "expressions"): AstPath | null; appendChild(node: T, property?: "expressions"): AstPath; appendChild(node: null, property?: "expressions"): null; appendChild(node: T | null, property?: "expressions"): AstPath | null; insertChildAt(node: T | null, index: number, property?: "expressions"): void; getChild(n?: number): AstPath | null; getPreviousSibling(): AstPath | null; getNextSibling(): AstPath | null; replace(node: T): AstPath | null; update(nodeProps: Partial): void; remove(): void; isRemoved(): boolean; hasEqualSource(path: AstPath): boolean; jsonEncode(options?: { format?: string | number, useLoc?: boolean }): string; } interface Alternative { node: ast.Alternative; parent: ast.AstRegExp | ast.Disjunction | ast.Alternative | ast.Assertion | ast.Group | ast.Repetition | null; parentPath: AstPath | null; property: string | null; index: number | null; getParent(): AstPath | null; setChild(node: T, index: number, property?: "expressions"): AstPath; appendChild(node: T, property?: "expressions"): AstPath; getChild(n?: number): AstPath; getPreviousSibling(): AstPath | null; getNextSibling(): AstPath | null; replace(node: T): AstPath | null; update(nodeProps: Partial): void; remove(): void; isRemoved(): boolean; hasEqualSource(path: AstPath): boolean; jsonEncode(options?: { format?: string | number, useLoc?: boolean }): string; } interface Assertion { node: ast.Assertion; parent: ast.AstRegExp | ast.Disjunction | ast.Alternative | ast.Assertion | ast.Group | ast.Repetition | null; parentPath: AstPath | null; property: string | null; index: number | null; getParent(): AstPath | null; setChild(node: T, index: null | undefined, property: "assertion"): AstPath; setChild(node: null, index: null | undefined, property: "assertion"): null; setChild(node: T | null, index: null | undefined, property: "assertion"): AstPath | null; getPreviousSibling(): AstPath | null; getNextSibling(): AstPath | null; replace(node: T): AstPath | null; update(nodeProps: Partial): void; remove(): void; isRemoved(): boolean; hasEqualSource(path: AstPath): boolean; jsonEncode(options?: { format?: string | number, useLoc?: boolean }): string; } interface Char { node: ast.Char; parent: ast.AstRegExp | ast.Disjunction | ast.Alternative | ast.Assertion | ast.Group | ast.Repetition | ast.CharacterClass | ast.ClassRange | null; parentPath: AstPath | null; property: string | null; index: number | null; getParent(): AstPath | null; getPreviousSibling(): AstPath | null; getNextSibling(): AstPath | null; replace(node: T): AstPath | null; update(nodeProps: Partial): void; remove(): void; isRemoved(): boolean; hasEqualSource(path: AstPath): boolean; jsonEncode(options?: { format?: string | number, useLoc?: boolean }): string; } interface CharacterClass { node: ast.CharacterClass; parent: ast.AstRegExp | ast.Disjunction | ast.Alternative | ast.Assertion | ast.Group | ast.Repetition | null; parentPath: AstPath | null; property: string | null; index: number | null; getParent(): AstPath | null; setChild(node: T, index: number, property?: "expressions"): AstPath; appendChild(node: T, property?: "expressions"): AstPath; insertChildAt(node: T, index: number, property?: "expressions"): void; getChild(n?: number): AstPath; getPreviousSibling(): AstPath | null; getNextSibling(): AstPath | null; replace(node: T): AstPath | null; update(nodeProps: Partial): void; remove(): void; isRemoved(): boolean; hasEqualSource(path: AstPath): boolean; jsonEncode(options?: { format?: string | number, useLoc?: boolean }): string; } interface ClassRange { node: ast.ClassRange; parent: ast.CharacterClass | null; parentPath: AstPath | null; property: string | null; index: number | null; getParent(): AstPath | null; setChild(node: ast.Char, index: null | undefined, property: "from" | "to"): AstPath; getPreviousSibling(): AstPath | null; getNextSibling(): AstPath | null; replace(node: T): AstPath | null; update(nodeProps: Partial): void; remove(): void; isRemoved(): boolean; hasEqualSource(path: AstPath): boolean; jsonEncode(options?: { format?: string | number, useLoc?: boolean }): string; } interface Backreference { node: ast.Backreference; parent: ast.AstRegExp | ast.Disjunction | ast.Alternative | ast.Assertion | ast.Group | ast.Repetition | null; parentPath: AstPath | null; property: string | null; index: number | null; getParent(): AstPath | null; getPreviousSibling(): AstPath | null; getNextSibling(): AstPath | null; replace(node: T): AstPath | null; update(nodeProps: Partial): void; remove(): void; isRemoved(): boolean; hasEqualSource(path: AstPath): boolean; jsonEncode(options?: { format?: string | number, useLoc?: boolean }): string; } interface Group { node: ast.Group; parent: ast.AstRegExp | ast.Disjunction | ast.Alternative | ast.Assertion | ast.Group | ast.Repetition | null; parentPath: AstPath | null; property: string | null; index: number | null; getParent(): AstPath | null; setChild(node: T, index: null | undefined, property?: "expression"): AstPath; setChild(node: null, index: null | undefined, property?: "expression"): null; setChild(node: T | null, index: null | undefined, property?: "expression"): AstPath | null; getChild(n?: 0): AstPath | null; getPreviousSibling(): AstPath | null; getNextSibling(): AstPath | null; replace(node: T): AstPath | null; update(nodeProps: Partial): void; remove(): void; isRemoved(): boolean; hasEqualSource(path: AstPath): boolean; jsonEncode(options?: { format?: string | number, useLoc?: boolean }): string; } interface Repetition { node: ast.Repetition; parent: ast.AstRegExp | ast.Disjunction | ast.Alternative | ast.Assertion | ast.Group | ast.Repetition | null; parentPath: AstPath | null; property: string | null; index: number | null; getParent(): AstPath | null; setChild(node: T, index: null | undefined, property?: "expression"): AstPath; setChild(node: T, index: null | undefined, property: "quantifier"): AstPath; getChild(n?: 0): AstPath | null; getPreviousSibling(): AstPath | null; getNextSibling(): AstPath | null; replace(node: T): AstPath | null; update(nodeProps: Partial): void; remove(): void; isRemoved(): boolean; hasEqualSource(path: AstPath): boolean; jsonEncode(options?: { format?: string | number, useLoc?: boolean }): string; } interface Quantifier { node: ast.Quantifier; parent: ast.Repetition | null; parentPath: AstPath | null; property: string | null; index: number | null; getParent(): AstPath | null; getPreviousSibling(): null; getNextSibling(): null; replace(node: T): AstPath | null; update(nodeProps: Partial): void; remove(): void; isRemoved(): boolean; hasEqualSource(path: AstPath): boolean; jsonEncode(options?: { format?: string | number, useLoc?: boolean }): string; } } interface AstPathTypes { "RegExp": AstPath.RegExp; "Disjunction": AstPath.Disjunction; "Alternative": AstPath.Alternative; "Assertion": AstPath.Assertion; "Char": AstPath.Char; "CharacterClass": AstPath.CharacterClass; "ClassRange": AstPath.ClassRange; "Backreference": AstPath.Backreference; "Group": AstPath.Group; "Repetition": AstPath.Repetition; "Quantifier": AstPath.Quantifier; } type AstPath = AstPathTypes[T["type"]]; } declare module "regexp-tree" { type TraversalCallback = { Ast: (node: T, parent: ast.AstPath["parent"] | null, prop?: string, index?: number) => void | boolean; AstPath: (path: ast.AstPath) => void | boolean; }[TraversalKind]; type TraversalCallbacks = { pre?: TraversalCallback; post?: TraversalCallback; }; type Traversal = TraversalCallback | TraversalCallbacks; type CommonTraversalHandlers = { "*"?: TraversalCallback; shouldRun?(ast: T): boolean; init?(ast: T): void; }; type SpecificTraversalHandlers = { [N in keyof ast.AstTypes]?: Traversal; }; type TraversalHandlers = & CommonTraversalHandlers & SpecificTraversalHandlers; type TransformHandlers = TraversalHandlers; class TransformResult { private _ast; private _source; private _string; private _regexp; private _extra; constructor(ast: T, extra?: E); getAST(): T; setExtra(extra: E): void; getExtra(): E; toRegExp(): RegExp; getSource(): string; getFlags(): string; toString(): string; } function traverse(ast: T, handlers: TraversalHandlers | ReadonlyArray>, options: { TraversalKind: true }): void; function traverse(ast: T, handlers: TraversalHandlers | ReadonlyArray>, options?: { TraversalKind?: false }): void; function transform(ast: T, handlers: TransformHandlers | ReadonlyArray>): TransformResult; function transform(regexp: string | RegExp, handlers: TransformHandlers | ReadonlyArray>): TransformResult; }