index.d.ts 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. // Generated by dts-bundle v0.7.3
  2. declare module "@eslint-community/regexpp" {
  3. import * as AST from "@eslint-community/regexpp/ast";
  4. import { RegExpParser } from "@eslint-community/regexpp/parser";
  5. import { RegExpValidator } from "@eslint-community/regexpp/validator";
  6. import { RegExpVisitor } from "@eslint-community/regexpp/visitor";
  7. export { AST, RegExpParser, RegExpValidator };
  8. /**
  9. * Parse a given regular expression literal then make AST object.
  10. * @param source The source code to parse.
  11. * @param options The options to parse.
  12. * @returns The AST of the regular expression.
  13. */
  14. export function parseRegExpLiteral(
  15. source: RegExp | string,
  16. options?: RegExpParser.Options
  17. ): AST.RegExpLiteral;
  18. /**
  19. * Validate a given regular expression literal.
  20. * @param source The source code to validate.
  21. * @param options The options to validate.
  22. */
  23. export function validateRegExpLiteral(
  24. source: string,
  25. options?: RegExpValidator.Options
  26. ): void;
  27. export function visitRegExpAST(
  28. node: AST.Node,
  29. handlers: RegExpVisitor.Handlers
  30. ): void;
  31. }
  32. declare module "@eslint-community/regexpp/ast" {
  33. /**
  34. * The type which includes all nodes.
  35. */
  36. export type Node = BranchNode | LeafNode;
  37. /**
  38. * The type which includes all branch nodes.
  39. */
  40. export type BranchNode =
  41. | Alternative
  42. | CapturingGroup
  43. | CharacterClass
  44. | CharacterClassRange
  45. | ClassIntersection
  46. | ClassStringDisjunction
  47. | ClassSubtraction
  48. | ExpressionCharacterClass
  49. | Group
  50. | LookaroundAssertion
  51. | Pattern
  52. | Quantifier
  53. | RegExpLiteral
  54. | StringAlternative;
  55. /**
  56. * The type which includes all leaf nodes.
  57. */
  58. export type LeafNode =
  59. | Backreference
  60. | BoundaryAssertion
  61. | Character
  62. | CharacterSet
  63. | Flags;
  64. /**
  65. * The type which includes all atom nodes.
  66. */
  67. export type Element = Assertion | QuantifiableElement | Quantifier;
  68. /**
  69. * The type which includes all atom nodes that Quantifier node can have as children.
  70. */
  71. export type QuantifiableElement =
  72. | Backreference
  73. | CapturingGroup
  74. | Character
  75. | CharacterClass
  76. | CharacterSet
  77. | ExpressionCharacterClass
  78. | Group
  79. | LookaheadAssertion;
  80. /**
  81. * The type which includes all character class atom nodes.
  82. */
  83. export type CharacterClassElement =
  84. | ClassRangesCharacterClassElement
  85. | UnicodeSetsCharacterClassElement;
  86. export type ClassRangesCharacterClassElement =
  87. | Character
  88. | CharacterClassRange
  89. | EscapeCharacterSet
  90. | UnicodePropertyCharacterSet;
  91. export type UnicodeSetsCharacterClassElement =
  92. | Character
  93. | CharacterClassRange
  94. | ClassStringDisjunction
  95. | EscapeCharacterSet
  96. | ExpressionCharacterClass
  97. | UnicodePropertyCharacterSet
  98. | UnicodeSetsCharacterClass;
  99. /**
  100. * The type which defines common properties for all node types.
  101. */
  102. export interface NodeBase {
  103. /** The node type. */
  104. type: Node["type"];
  105. /** The parent node. */
  106. parent: Node["parent"];
  107. /** The 0-based index that this node starts. */
  108. start: number;
  109. /** The 0-based index that this node ends. */
  110. end: number;
  111. /** The raw text of this node. */
  112. raw: string;
  113. }
  114. /**
  115. * The root node.
  116. */
  117. export interface RegExpLiteral extends NodeBase {
  118. type: "RegExpLiteral";
  119. parent: null;
  120. pattern: Pattern;
  121. flags: Flags;
  122. }
  123. /**
  124. * The pattern.
  125. */
  126. export interface Pattern extends NodeBase {
  127. type: "Pattern";
  128. parent: RegExpLiteral | null;
  129. alternatives: Alternative[];
  130. }
  131. /**
  132. * The alternative.
  133. * E.g. `a|b`
  134. */
  135. export interface Alternative extends NodeBase {
  136. type: "Alternative";
  137. parent: CapturingGroup | Group | LookaroundAssertion | Pattern;
  138. elements: Element[];
  139. }
  140. /**
  141. * The uncapturing group.
  142. * E.g. `(?:ab)`
  143. */
  144. export interface Group extends NodeBase {
  145. type: "Group";
  146. parent: Alternative | Quantifier;
  147. alternatives: Alternative[];
  148. }
  149. /**
  150. * The capturing group.
  151. * E.g. `(ab)`, `(?<name>ab)`
  152. */
  153. export interface CapturingGroup extends NodeBase {
  154. type: "CapturingGroup";
  155. parent: Alternative | Quantifier;
  156. name: string | null;
  157. alternatives: Alternative[];
  158. references: Backreference[];
  159. }
  160. /**
  161. * The lookaround assertion.
  162. */
  163. export type LookaroundAssertion = LookaheadAssertion | LookbehindAssertion;
  164. /**
  165. * The lookahead assertion.
  166. * E.g. `(?=ab)`, `(?!ab)`
  167. */
  168. export interface LookaheadAssertion extends NodeBase {
  169. type: "Assertion";
  170. parent: Alternative | Quantifier;
  171. kind: "lookahead";
  172. negate: boolean;
  173. alternatives: Alternative[];
  174. }
  175. /**
  176. * The lookbehind assertion.
  177. * E.g. `(?<=ab)`, `(?<!ab)`
  178. */
  179. export interface LookbehindAssertion extends NodeBase {
  180. type: "Assertion";
  181. parent: Alternative;
  182. kind: "lookbehind";
  183. negate: boolean;
  184. alternatives: Alternative[];
  185. }
  186. /**
  187. * The quantifier.
  188. * E.g. `a?`, `a*`, `a+`, `a{1,2}`, `a??`, `a*?`, `a+?`, `a{1,2}?`
  189. */
  190. export interface Quantifier extends NodeBase {
  191. type: "Quantifier";
  192. parent: Alternative;
  193. min: number;
  194. max: number;
  195. greedy: boolean;
  196. element: QuantifiableElement;
  197. }
  198. /**
  199. * The character class.
  200. * E.g. `[ab]`, `[^ab]`
  201. */
  202. export type CharacterClass =
  203. | ClassRangesCharacterClass
  204. | UnicodeSetsCharacterClass;
  205. interface BaseCharacterClass extends NodeBase {
  206. type: "CharacterClass";
  207. parent:
  208. | Alternative
  209. | ExpressionCharacterClass
  210. | Quantifier
  211. | UnicodeSetsCharacterClass;
  212. unicodeSets: boolean;
  213. negate: boolean;
  214. elements: CharacterClassElement[];
  215. }
  216. export interface ClassRangesCharacterClass extends BaseCharacterClass {
  217. parent: Alternative | Quantifier;
  218. unicodeSets: false;
  219. elements: ClassRangesCharacterClassElement[];
  220. }
  221. /** UnicodeSetsCharacterClass is the CharacterClass when in Unicode sets mode. So it may contain strings. */
  222. export interface UnicodeSetsCharacterClass extends BaseCharacterClass {
  223. parent:
  224. | Alternative
  225. | ExpressionCharacterClass
  226. | Quantifier
  227. | UnicodeSetsCharacterClass;
  228. unicodeSets: true;
  229. elements: UnicodeSetsCharacterClassElement[];
  230. }
  231. /**
  232. * The character class.
  233. * E.g. `[a-b]`
  234. */
  235. export interface CharacterClassRange extends NodeBase {
  236. type: "CharacterClassRange";
  237. parent: CharacterClass;
  238. min: Character;
  239. max: Character;
  240. }
  241. /**
  242. * The assertion.
  243. */
  244. export type Assertion = BoundaryAssertion | LookaroundAssertion;
  245. /**
  246. * The boundary assertion.
  247. */
  248. export type BoundaryAssertion = EdgeAssertion | WordBoundaryAssertion;
  249. /**
  250. * The edge boundary assertion.
  251. * E.g. `^`, `$`
  252. */
  253. export interface EdgeAssertion extends NodeBase {
  254. type: "Assertion";
  255. parent: Alternative | Quantifier;
  256. kind: "end" | "start";
  257. }
  258. /**
  259. * The word bondary assertion.
  260. * E.g. `\b`, `\B`
  261. */
  262. export interface WordBoundaryAssertion extends NodeBase {
  263. type: "Assertion";
  264. parent: Alternative | Quantifier;
  265. kind: "word";
  266. negate: boolean;
  267. }
  268. /**
  269. * The character set.
  270. */
  271. export type CharacterSet =
  272. | AnyCharacterSet
  273. | EscapeCharacterSet
  274. | UnicodePropertyCharacterSet;
  275. /**
  276. * The dot.
  277. * E.g. `.`
  278. */
  279. export interface AnyCharacterSet extends NodeBase {
  280. type: "CharacterSet";
  281. parent: Alternative | Quantifier;
  282. kind: "any";
  283. }
  284. /**
  285. * The character class escape.
  286. * E.g. `\d`, `\s`, `\w`, `\D`, `\S`, `\W`
  287. */
  288. export interface EscapeCharacterSet extends NodeBase {
  289. type: "CharacterSet";
  290. parent:
  291. | Alternative
  292. | CharacterClass
  293. | ClassIntersection
  294. | ClassSubtraction
  295. | Quantifier;
  296. kind: "digit" | "space" | "word";
  297. negate: boolean;
  298. }
  299. /**
  300. * The unicode property escape.
  301. * E.g. `\p{ASCII}`, `\P{ASCII}`, `\p{Script=Hiragana}`
  302. */
  303. export type UnicodePropertyCharacterSet =
  304. | CharacterUnicodePropertyCharacterSet
  305. | StringsUnicodePropertyCharacterSet;
  306. interface BaseUnicodePropertyCharacterSet extends NodeBase {
  307. type: "CharacterSet";
  308. parent:
  309. | Alternative
  310. | CharacterClass
  311. | ClassIntersection
  312. | ClassSubtraction
  313. | Quantifier;
  314. kind: "property";
  315. strings: boolean;
  316. key: string;
  317. value: string | null;
  318. negate: boolean;
  319. }
  320. export interface CharacterUnicodePropertyCharacterSet
  321. extends BaseUnicodePropertyCharacterSet {
  322. strings: false;
  323. value: string | null;
  324. negate: boolean;
  325. }
  326. /** StringsUnicodePropertyCharacterSet is Unicode property escape with property of strings. */
  327. export interface StringsUnicodePropertyCharacterSet
  328. extends BaseUnicodePropertyCharacterSet {
  329. strings: true;
  330. value: null;
  331. negate: false;
  332. }
  333. /**
  334. * The expression character class.
  335. * E.g. `[a--b]`, `[a&&b]`,`[^a--b]`, `[^a&&b]`
  336. */
  337. export interface ExpressionCharacterClass extends NodeBase {
  338. type: "ExpressionCharacterClass";
  339. parent:
  340. | Alternative
  341. | ExpressionCharacterClass
  342. | Quantifier
  343. | UnicodeSetsCharacterClass;
  344. negate: boolean;
  345. expression: ClassIntersection | ClassSubtraction;
  346. }
  347. export type ClassSetOperand =
  348. | Character
  349. | ClassStringDisjunction
  350. | EscapeCharacterSet
  351. | ExpressionCharacterClass
  352. | UnicodePropertyCharacterSet
  353. | UnicodeSetsCharacterClass;
  354. /**
  355. * The character class intersection.
  356. * E.g. `a&&b`
  357. */
  358. export interface ClassIntersection extends NodeBase {
  359. type: "ClassIntersection";
  360. parent: ClassIntersection | ExpressionCharacterClass;
  361. left: ClassIntersection | ClassSetOperand;
  362. right: ClassSetOperand;
  363. }
  364. /**
  365. * The character class subtraction.
  366. * E.g. `a--b`
  367. */
  368. export interface ClassSubtraction extends NodeBase {
  369. type: "ClassSubtraction";
  370. parent: ClassSubtraction | ExpressionCharacterClass;
  371. left: ClassSetOperand | ClassSubtraction;
  372. right: ClassSetOperand;
  373. }
  374. /**
  375. * The character class string disjunction.
  376. * E.g. `\q{a|b}`
  377. */
  378. export interface ClassStringDisjunction extends NodeBase {
  379. type: "ClassStringDisjunction";
  380. parent: ClassIntersection | ClassSubtraction | UnicodeSetsCharacterClass;
  381. alternatives: StringAlternative[];
  382. }
  383. /** StringAlternative is only used for `\q{alt}`({@link ClassStringDisjunction}). */
  384. export interface StringAlternative extends NodeBase {
  385. type: "StringAlternative";
  386. parent: ClassStringDisjunction;
  387. elements: Character[];
  388. }
  389. /**
  390. * The character.
  391. * This includes escape sequences which mean a character.
  392. * E.g. `a`, `あ`, `✿`, `\x65`, `\u0065`, `\u{65}`, `\/`
  393. */
  394. export interface Character extends NodeBase {
  395. type: "Character";
  396. parent:
  397. | Alternative
  398. | CharacterClass
  399. | CharacterClassRange
  400. | ClassIntersection
  401. | ClassSubtraction
  402. | Quantifier
  403. | StringAlternative;
  404. value: number;
  405. }
  406. /**
  407. * The backreference.
  408. * E.g. `\1`, `\k<name>`
  409. */
  410. export interface Backreference extends NodeBase {
  411. type: "Backreference";
  412. parent: Alternative | Quantifier;
  413. ref: number | string;
  414. resolved: CapturingGroup;
  415. }
  416. /**
  417. * The flags.
  418. */
  419. export interface Flags extends NodeBase {
  420. type: "Flags";
  421. parent: RegExpLiteral | null;
  422. dotAll: boolean;
  423. global: boolean;
  424. hasIndices: boolean;
  425. ignoreCase: boolean;
  426. multiline: boolean;
  427. sticky: boolean;
  428. unicode: boolean;
  429. unicodeSets: boolean;
  430. }
  431. export {};
  432. }
  433. declare module "@eslint-community/regexpp/parser" {
  434. import type {
  435. Flags,
  436. RegExpLiteral,
  437. Pattern,
  438. } from "@eslint-community/regexpp/ast";
  439. import type { EcmaVersion } from "@eslint-community/regexpp/ecma-versions";
  440. export namespace RegExpParser {
  441. /**
  442. * The options for RegExpParser construction.
  443. */
  444. interface Options {
  445. /**
  446. * The flag to disable Annex B syntax. Default is `false`.
  447. */
  448. strict?: boolean;
  449. /**
  450. * ECMAScript version. Default is `2024`.
  451. * - `2015` added `u` and `y` flags.
  452. * - `2018` added `s` flag, Named Capturing Group, Lookbehind Assertion,
  453. * and Unicode Property Escape.
  454. * - `2019`, `2020`, and `2021` added more valid Unicode Property Escapes.
  455. * - `2022` added `d` flag.
  456. * - `2023` added more valid Unicode Property Escapes.
  457. * - `2024` added `v` flag.
  458. */
  459. ecmaVersion?: EcmaVersion;
  460. }
  461. }
  462. export class RegExpParser {
  463. /**
  464. * Initialize this parser.
  465. * @param options The options of parser.
  466. */
  467. constructor(options?: RegExpParser.Options);
  468. /**
  469. * Parse a regular expression literal. E.g. "/abc/g"
  470. * @param source The source code to parse.
  471. * @param start The start index in the source code.
  472. * @param end The end index in the source code.
  473. * @returns The AST of the given regular expression.
  474. */
  475. parseLiteral(source: string, start?: number, end?: number): RegExpLiteral;
  476. /**
  477. * Parse a regular expression flags. E.g. "gim"
  478. * @param source The source code to parse.
  479. * @param start The start index in the source code.
  480. * @param end The end index in the source code.
  481. * @returns The AST of the given flags.
  482. */
  483. parseFlags(source: string, start?: number, end?: number): Flags;
  484. /**
  485. * Parse a regular expression pattern. E.g. "abc"
  486. * @param source The source code to parse.
  487. * @param start The start index in the source code.
  488. * @param end The end index in the source code.
  489. * @param flags The flags.
  490. * @returns The AST of the given pattern.
  491. */
  492. parsePattern(
  493. source: string,
  494. start?: number,
  495. end?: number,
  496. flags?: {
  497. unicode?: boolean;
  498. unicodeSets?: boolean;
  499. }
  500. ): Pattern;
  501. /**
  502. * @deprecated Backward compatibility
  503. * Use object `flags` instead of boolean `uFlag`.
  504. *
  505. * @param source The source code to parse.
  506. * @param start The start index in the source code.
  507. * @param end The end index in the source code.
  508. * @param uFlag The flag to set unicode mode.
  509. * @returns The AST of the given pattern.
  510. */
  511. parsePattern(
  512. source: string,
  513. start?: number,
  514. end?: number,
  515. uFlag?: boolean
  516. ): Pattern;
  517. }
  518. }
  519. declare module "@eslint-community/regexpp/validator" {
  520. import type { EcmaVersion } from "@eslint-community/regexpp/ecma-versions";
  521. export type RegExpValidatorSourceContext = {
  522. readonly source: string;
  523. readonly start: number;
  524. readonly end: number;
  525. readonly kind: "flags" | "literal" | "pattern";
  526. };
  527. export namespace RegExpValidator {
  528. /**
  529. * The options for RegExpValidator construction.
  530. */
  531. interface Options {
  532. /**
  533. * The flag to disable Annex B syntax. Default is `false`.
  534. */
  535. strict?: boolean;
  536. /**
  537. * ECMAScript version. Default is `2024`.
  538. * - `2015` added `u` and `y` flags.
  539. * - `2018` added `s` flag, Named Capturing Group, Lookbehind Assertion,
  540. * and Unicode Property Escape.
  541. * - `2019`, `2020`, and `2021` added more valid Unicode Property Escapes.
  542. * - `2022` added `d` flag.
  543. * - `2023` added more valid Unicode Property Escapes.
  544. * - `2024` added `v` flag.
  545. */
  546. ecmaVersion?: EcmaVersion;
  547. /**
  548. * A function that is called when the validator entered a RegExp literal.
  549. * @param start The 0-based index of the first character.
  550. */
  551. onLiteralEnter?: (start: number) => void;
  552. /**
  553. * A function that is called when the validator left a RegExp literal.
  554. * @param start The 0-based index of the first character.
  555. * @param end The next 0-based index of the last character.
  556. */
  557. onLiteralLeave?: (start: number, end: number) => void;
  558. /**
  559. * A function that is called when the validator found flags.
  560. * @param start The 0-based index of the first character.
  561. * @param end The next 0-based index of the last character.
  562. * @param flags.global `g` flag.
  563. * @param flags.ignoreCase `i` flag.
  564. * @param flags.multiline `m` flag.
  565. * @param flags.unicode `u` flag.
  566. * @param flags.sticky `y` flag.
  567. * @param flags.dotAll `s` flag.
  568. * @param flags.hasIndices `d` flag.
  569. * @param flags.unicodeSets `v` flag.
  570. */
  571. onRegExpFlags?: (
  572. start: number,
  573. end: number,
  574. flags: {
  575. global: boolean;
  576. ignoreCase: boolean;
  577. multiline: boolean;
  578. unicode: boolean;
  579. sticky: boolean;
  580. dotAll: boolean;
  581. hasIndices: boolean;
  582. unicodeSets: boolean;
  583. }
  584. ) => void;
  585. /**
  586. * A function that is called when the validator found flags.
  587. * @param start The 0-based index of the first character.
  588. * @param end The next 0-based index of the last character.
  589. * @param global `g` flag.
  590. * @param ignoreCase `i` flag.
  591. * @param multiline `m` flag.
  592. * @param unicode `u` flag.
  593. * @param sticky `y` flag.
  594. * @param dotAll `s` flag.
  595. * @param hasIndices `d` flag.
  596. *
  597. * @deprecated Use `onRegExpFlags` instead.
  598. */
  599. onFlags?: (
  600. start: number,
  601. end: number,
  602. global: boolean,
  603. ignoreCase: boolean,
  604. multiline: boolean,
  605. unicode: boolean,
  606. sticky: boolean,
  607. dotAll: boolean,
  608. hasIndices: boolean
  609. ) => void;
  610. /**
  611. * A function that is called when the validator entered a pattern.
  612. * @param start The 0-based index of the first character.
  613. */
  614. onPatternEnter?: (start: number) => void;
  615. /**
  616. * A function that is called when the validator left a pattern.
  617. * @param start The 0-based index of the first character.
  618. * @param end The next 0-based index of the last character.
  619. */
  620. onPatternLeave?: (start: number, end: number) => void;
  621. /**
  622. * A function that is called when the validator entered a disjunction.
  623. * @param start The 0-based index of the first character.
  624. */
  625. onDisjunctionEnter?: (start: number) => void;
  626. /**
  627. * A function that is called when the validator left a disjunction.
  628. * @param start The 0-based index of the first character.
  629. * @param end The next 0-based index of the last character.
  630. */
  631. onDisjunctionLeave?: (start: number, end: number) => void;
  632. /**
  633. * A function that is called when the validator entered an alternative.
  634. * @param start The 0-based index of the first character.
  635. * @param index The 0-based index of alternatives in a disjunction.
  636. */
  637. onAlternativeEnter?: (start: number, index: number) => void;
  638. /**
  639. * A function that is called when the validator left an alternative.
  640. * @param start The 0-based index of the first character.
  641. * @param end The next 0-based index of the last character.
  642. * @param index The 0-based index of alternatives in a disjunction.
  643. */
  644. onAlternativeLeave?: (start: number, end: number, index: number) => void;
  645. /**
  646. * A function that is called when the validator entered an uncapturing group.
  647. * @param start The 0-based index of the first character.
  648. */
  649. onGroupEnter?: (start: number) => void;
  650. /**
  651. * A function that is called when the validator left an uncapturing group.
  652. * @param start The 0-based index of the first character.
  653. * @param end The next 0-based index of the last character.
  654. */
  655. onGroupLeave?: (start: number, end: number) => void;
  656. /**
  657. * A function that is called when the validator entered a capturing group.
  658. * @param start The 0-based index of the first character.
  659. * @param name The group name.
  660. */
  661. onCapturingGroupEnter?: (start: number, name: string | null) => void;
  662. /**
  663. * A function that is called when the validator left a capturing group.
  664. * @param start The 0-based index of the first character.
  665. * @param end The next 0-based index of the last character.
  666. * @param name The group name.
  667. */
  668. onCapturingGroupLeave?: (
  669. start: number,
  670. end: number,
  671. name: string | null
  672. ) => void;
  673. /**
  674. * A function that is called when the validator found a quantifier.
  675. * @param start The 0-based index of the first character.
  676. * @param end The next 0-based index of the last character.
  677. * @param min The minimum number of repeating.
  678. * @param max The maximum number of repeating.
  679. * @param greedy The flag to choose the longest matching.
  680. */
  681. onQuantifier?: (
  682. start: number,
  683. end: number,
  684. min: number,
  685. max: number,
  686. greedy: boolean
  687. ) => void;
  688. /**
  689. * A function that is called when the validator entered a lookahead/lookbehind assertion.
  690. * @param start The 0-based index of the first character.
  691. * @param kind The kind of the assertion.
  692. * @param negate The flag which represents that the assertion is negative.
  693. */
  694. onLookaroundAssertionEnter?: (
  695. start: number,
  696. kind: "lookahead" | "lookbehind",
  697. negate: boolean
  698. ) => void;
  699. /**
  700. * A function that is called when the validator left a lookahead/lookbehind assertion.
  701. * @param start The 0-based index of the first character.
  702. * @param end The next 0-based index of the last character.
  703. * @param kind The kind of the assertion.
  704. * @param negate The flag which represents that the assertion is negative.
  705. */
  706. onLookaroundAssertionLeave?: (
  707. start: number,
  708. end: number,
  709. kind: "lookahead" | "lookbehind",
  710. negate: boolean
  711. ) => void;
  712. /**
  713. * A function that is called when the validator found an edge boundary assertion.
  714. * @param start The 0-based index of the first character.
  715. * @param end The next 0-based index of the last character.
  716. * @param kind The kind of the assertion.
  717. */
  718. onEdgeAssertion?: (
  719. start: number,
  720. end: number,
  721. kind: "end" | "start"
  722. ) => void;
  723. /**
  724. * A function that is called when the validator found a word boundary assertion.
  725. * @param start The 0-based index of the first character.
  726. * @param end The next 0-based index of the last character.
  727. * @param kind The kind of the assertion.
  728. * @param negate The flag which represents that the assertion is negative.
  729. */
  730. onWordBoundaryAssertion?: (
  731. start: number,
  732. end: number,
  733. kind: "word",
  734. negate: boolean
  735. ) => void;
  736. /**
  737. * A function that is called when the validator found a dot.
  738. * @param start The 0-based index of the first character.
  739. * @param end The next 0-based index of the last character.
  740. * @param kind The kind of the character set.
  741. */
  742. onAnyCharacterSet?: (start: number, end: number, kind: "any") => void;
  743. /**
  744. * A function that is called when the validator found a character set escape.
  745. * @param start The 0-based index of the first character.
  746. * @param end The next 0-based index of the last character.
  747. * @param kind The kind of the character set.
  748. * @param negate The flag which represents that the character set is negative.
  749. */
  750. onEscapeCharacterSet?: (
  751. start: number,
  752. end: number,
  753. kind: "digit" | "space" | "word",
  754. negate: boolean
  755. ) => void;
  756. /**
  757. * A function that is called when the validator found a Unicode proerty escape.
  758. * @param start The 0-based index of the first character.
  759. * @param end The next 0-based index of the last character.
  760. * @param kind The kind of the character set.
  761. * @param key The property name.
  762. * @param value The property value.
  763. * @param negate The flag which represents that the character set is negative.
  764. * @param strings If true, the given property is property of strings.
  765. */
  766. onUnicodePropertyCharacterSet?: (
  767. start: number,
  768. end: number,
  769. kind: "property",
  770. key: string,
  771. value: string | null,
  772. negate: boolean,
  773. strings: boolean
  774. ) => void;
  775. /**
  776. * A function that is called when the validator found a character.
  777. * @param start The 0-based index of the first character.
  778. * @param end The next 0-based index of the last character.
  779. * @param value The code point of the character.
  780. */
  781. onCharacter?: (start: number, end: number, value: number) => void;
  782. /**
  783. * A function that is called when the validator found a backreference.
  784. * @param start The 0-based index of the first character.
  785. * @param end The next 0-based index of the last character.
  786. * @param ref The key of the referred capturing group.
  787. */
  788. onBackreference?: (
  789. start: number,
  790. end: number,
  791. ref: number | string
  792. ) => void;
  793. /**
  794. * A function that is called when the validator entered a character class.
  795. * @param start The 0-based index of the first character.
  796. * @param negate The flag which represents that the character class is negative.
  797. * @param unicodeSets `true` if unicodeSets mode.
  798. */
  799. onCharacterClassEnter?: (
  800. start: number,
  801. negate: boolean,
  802. unicodeSets: boolean
  803. ) => void;
  804. /**
  805. * A function that is called when the validator left a character class.
  806. * @param start The 0-based index of the first character.
  807. * @param end The next 0-based index of the last character.
  808. * @param negate The flag which represents that the character class is negative.
  809. */
  810. onCharacterClassLeave?: (
  811. start: number,
  812. end: number,
  813. negate: boolean
  814. ) => void;
  815. /**
  816. * A function that is called when the validator found a character class range.
  817. * @param start The 0-based index of the first character.
  818. * @param end The next 0-based index of the last character.
  819. * @param min The minimum code point of the range.
  820. * @param max The maximum code point of the range.
  821. */
  822. onCharacterClassRange?: (
  823. start: number,
  824. end: number,
  825. min: number,
  826. max: number
  827. ) => void;
  828. /**
  829. * A function that is called when the validator found a class intersection.
  830. * @param start The 0-based index of the first character.
  831. * @param end The next 0-based index of the last character.
  832. */
  833. onClassIntersection?: (start: number, end: number) => void;
  834. /**
  835. * A function that is called when the validator found a class subtraction.
  836. * @param start The 0-based index of the first character.
  837. * @param end The next 0-based index of the last character.
  838. */
  839. onClassSubtraction?: (start: number, end: number) => void;
  840. /**
  841. * A function that is called when the validator entered a class string disjunction.
  842. * @param start The 0-based index of the first character.
  843. */
  844. onClassStringDisjunctionEnter?: (start: number) => void;
  845. /**
  846. * A function that is called when the validator left a class string disjunction.
  847. * @param start The 0-based index of the first character.
  848. * @param end The next 0-based index of the last character.
  849. */
  850. onClassStringDisjunctionLeave?: (start: number, end: number) => void;
  851. /**
  852. * A function that is called when the validator entered a string alternative.
  853. * @param start The 0-based index of the first character.
  854. * @param index The 0-based index of alternatives in a disjunction.
  855. */
  856. onStringAlternativeEnter?: (start: number, index: number) => void;
  857. /**
  858. * A function that is called when the validator left a string alternative.
  859. * @param start The 0-based index of the first character.
  860. * @param end The next 0-based index of the last character.
  861. * @param index The 0-based index of alternatives in a disjunction.
  862. */
  863. onStringAlternativeLeave?: (
  864. start: number,
  865. end: number,
  866. index: number
  867. ) => void;
  868. }
  869. }
  870. /**
  871. * The regular expression validator.
  872. */
  873. export class RegExpValidator {
  874. /**
  875. * Initialize this validator.
  876. * @param options The options of validator.
  877. */
  878. constructor(options?: RegExpValidator.Options);
  879. /**
  880. * Validate a regular expression literal. E.g. "/abc/g"
  881. * @param source The source code to validate.
  882. * @param start The start index in the source code.
  883. * @param end The end index in the source code.
  884. */
  885. validateLiteral(source: string, start?: number, end?: number): void;
  886. /**
  887. * Validate a regular expression flags. E.g. "gim"
  888. * @param source The source code to validate.
  889. * @param start The start index in the source code.
  890. * @param end The end index in the source code.
  891. */
  892. validateFlags(source: string, start?: number, end?: number): void;
  893. /**
  894. * Validate a regular expression pattern. E.g. "abc"
  895. * @param source The source code to validate.
  896. * @param start The start index in the source code.
  897. * @param end The end index in the source code.
  898. * @param flags The flags.
  899. */
  900. validatePattern(
  901. source: string,
  902. start?: number,
  903. end?: number,
  904. flags?: {
  905. unicode?: boolean;
  906. unicodeSets?: boolean;
  907. }
  908. ): void;
  909. /**
  910. * @deprecated Backward compatibility
  911. * Use object `flags` instead of boolean `uFlag`.
  912. * @param source The source code to validate.
  913. * @param start The start index in the source code.
  914. * @param end The end index in the source code.
  915. * @param uFlag The flag to set unicode mode.
  916. */
  917. validatePattern(
  918. source: string,
  919. start?: number,
  920. end?: number,
  921. uFlag?: boolean
  922. ): void;
  923. }
  924. }
  925. declare module "@eslint-community/regexpp/visitor" {
  926. import type {
  927. Alternative,
  928. Assertion,
  929. Backreference,
  930. CapturingGroup,
  931. Character,
  932. CharacterClass,
  933. CharacterClassRange,
  934. CharacterSet,
  935. ClassIntersection,
  936. ClassStringDisjunction,
  937. ClassSubtraction,
  938. ExpressionCharacterClass,
  939. Flags,
  940. Group,
  941. Node,
  942. Pattern,
  943. Quantifier,
  944. RegExpLiteral,
  945. StringAlternative,
  946. } from "@eslint-community/regexpp/ast";
  947. /**
  948. * The visitor to walk on AST.
  949. */
  950. export class RegExpVisitor {
  951. /**
  952. * Initialize this visitor.
  953. * @param handlers Callbacks for each node.
  954. */
  955. constructor(handlers: RegExpVisitor.Handlers);
  956. /**
  957. * Visit a given node and descendant nodes.
  958. * @param node The root node to visit tree.
  959. */
  960. visit(node: Node): void;
  961. }
  962. export namespace RegExpVisitor {
  963. interface Handlers {
  964. onAlternativeEnter?: (node: Alternative) => void;
  965. onAlternativeLeave?: (node: Alternative) => void;
  966. onAssertionEnter?: (node: Assertion) => void;
  967. onAssertionLeave?: (node: Assertion) => void;
  968. onBackreferenceEnter?: (node: Backreference) => void;
  969. onBackreferenceLeave?: (node: Backreference) => void;
  970. onCapturingGroupEnter?: (node: CapturingGroup) => void;
  971. onCapturingGroupLeave?: (node: CapturingGroup) => void;
  972. onCharacterEnter?: (node: Character) => void;
  973. onCharacterLeave?: (node: Character) => void;
  974. onCharacterClassEnter?: (node: CharacterClass) => void;
  975. onCharacterClassLeave?: (node: CharacterClass) => void;
  976. onCharacterClassRangeEnter?: (node: CharacterClassRange) => void;
  977. onCharacterClassRangeLeave?: (node: CharacterClassRange) => void;
  978. onCharacterSetEnter?: (node: CharacterSet) => void;
  979. onCharacterSetLeave?: (node: CharacterSet) => void;
  980. onClassIntersectionEnter?: (node: ClassIntersection) => void;
  981. onClassIntersectionLeave?: (node: ClassIntersection) => void;
  982. onClassStringDisjunctionEnter?: (node: ClassStringDisjunction) => void;
  983. onClassStringDisjunctionLeave?: (node: ClassStringDisjunction) => void;
  984. onClassSubtractionEnter?: (node: ClassSubtraction) => void;
  985. onClassSubtractionLeave?: (node: ClassSubtraction) => void;
  986. onExpressionCharacterClassEnter?: (
  987. node: ExpressionCharacterClass
  988. ) => void;
  989. onExpressionCharacterClassLeave?: (
  990. node: ExpressionCharacterClass
  991. ) => void;
  992. onFlagsEnter?: (node: Flags) => void;
  993. onFlagsLeave?: (node: Flags) => void;
  994. onGroupEnter?: (node: Group) => void;
  995. onGroupLeave?: (node: Group) => void;
  996. onPatternEnter?: (node: Pattern) => void;
  997. onPatternLeave?: (node: Pattern) => void;
  998. onQuantifierEnter?: (node: Quantifier) => void;
  999. onQuantifierLeave?: (node: Quantifier) => void;
  1000. onRegExpLiteralEnter?: (node: RegExpLiteral) => void;
  1001. onRegExpLiteralLeave?: (node: RegExpLiteral) => void;
  1002. onStringAlternativeEnter?: (node: StringAlternative) => void;
  1003. onStringAlternativeLeave?: (node: StringAlternative) => void;
  1004. }
  1005. }
  1006. }
  1007. declare module "@eslint-community/regexpp/ecma-versions" {
  1008. export type EcmaVersion =
  1009. | 5
  1010. | 2015
  1011. | 2016
  1012. | 2017
  1013. | 2018
  1014. | 2019
  1015. | 2020
  1016. | 2021
  1017. | 2022
  1018. | 2023
  1019. | 2024;
  1020. export const latestEcmaVersion = 2024;
  1021. }