index.d.ts 34 KB

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