@eslint-community/regexpp 4.5.1 → 4.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -79,7 +79,7 @@ Parse a regular expression literal.
79
79
  - **Return:**
80
80
  - The AST of the regular expression.
81
81
 
82
- #### parser.parsePattern(source, start?, end?, uFlag?)
82
+ #### parser.parsePattern(source, start?, end?, flags?)
83
83
 
84
84
  Parse a regular expression pattern.
85
85
 
@@ -87,7 +87,7 @@ Parse a regular expression pattern.
87
87
  - `source` (`string`) The source code to parse. E.g. `"abc"`.
88
88
  - `start?` (`number`) The start index in the source code. Default is `0`.
89
89
  - `end?` (`number`) The end index in the source code. Default is `source.length`.
90
- - `uFlag?` (`boolean`) The flag to enable Unicode mode.
90
+ - `flags?` (`{ unicode?: boolean, unicodeSets?: boolean }`) The flags to enable Unicode mode, and Unicode Set mode.
91
91
  - **Return:**
92
92
  - The AST of the regular expression pattern.
93
93
 
@@ -118,7 +118,7 @@ Validate a regular expression literal.
118
118
  - `start?` (`number`) The start index in the source code. Default is `0`.
119
119
  - `end?` (`number`) The end index in the source code. Default is `source.length`.
120
120
 
121
- #### validator.validatePattern(source, start, end, uFlag)
121
+ #### validator.validatePattern(source, start, end, flags)
122
122
 
123
123
  Validate a regular expression pattern.
124
124
 
@@ -126,7 +126,7 @@ Validate a regular expression pattern.
126
126
  - `source` (`string`) The source code to validate.
127
127
  - `start?` (`number`) The start index in the source code. Default is `0`.
128
128
  - `end?` (`number`) The end index in the source code. Default is `source.length`.
129
- - `uFlag?` (`boolean`) The flag to enable Unicode mode.
129
+ - `flags?` (`{ unicode?: boolean, unicodeSets?: boolean }`) The flags to enable Unicode mode, and Unicode Set mode.
130
130
 
131
131
  #### validator.validateFlags(source, start, end)
132
132
 
@@ -172,6 +172,6 @@ Please use GitHub's Issues/PRs.
172
172
  - `npm run watch` runs tests with `--watch` option.
173
173
 
174
174
  [`AST.Node`]: src/ast.ts#L4
175
- [`RegExpParser.Options`]: src/parser.ts#L539
176
- [`RegExpValidator.Options`]: src/validator.ts#L127
177
- [`RegExpVisitor.Handlers`]: src/visitor.ts#L204
175
+ [`RegExpParser.Options`]: src/parser.ts#L743
176
+ [`RegExpValidator.Options`]: src/validator.ts#L220
177
+ [`RegExpVisitor.Handlers`]: src/visitor.ts#L291
package/index.d.ts CHANGED
@@ -44,11 +44,16 @@ declare module "@eslint-community/regexpp/ast" {
44
44
  | CapturingGroup
45
45
  | CharacterClass
46
46
  | CharacterClassRange
47
+ | ClassIntersection
48
+ | ClassStringDisjunction
49
+ | ClassSubtraction
50
+ | ExpressionCharacterClass
47
51
  | Group
48
52
  | LookaroundAssertion
49
53
  | Pattern
50
54
  | Quantifier
51
- | RegExpLiteral;
55
+ | RegExpLiteral
56
+ | StringAlternative;
52
57
  /**
53
58
  * The type which includes all leaf nodes.
54
59
  */
@@ -71,16 +76,28 @@ declare module "@eslint-community/regexpp/ast" {
71
76
  | Character
72
77
  | CharacterClass
73
78
  | CharacterSet
79
+ | ExpressionCharacterClass
74
80
  | Group
75
81
  | LookaheadAssertion;
76
82
  /**
77
83
  * The type which includes all character class atom nodes.
78
84
  */
79
85
  export type CharacterClassElement =
86
+ | ClassRangesCharacterClassElement
87
+ | UnicodeSetsCharacterClassElement;
88
+ export type ClassRangesCharacterClassElement =
80
89
  | Character
81
90
  | CharacterClassRange
82
91
  | EscapeCharacterSet
83
92
  | UnicodePropertyCharacterSet;
93
+ export type UnicodeSetsCharacterClassElement =
94
+ | Character
95
+ | CharacterClassRange
96
+ | ClassStringDisjunction
97
+ | EscapeCharacterSet
98
+ | ExpressionCharacterClass
99
+ | UnicodePropertyCharacterSet
100
+ | UnicodeSetsCharacterClass;
84
101
  /**
85
102
  * The type which defines common properties for all node types.
86
103
  */
@@ -184,12 +201,35 @@ declare module "@eslint-community/regexpp/ast" {
184
201
  * The character class.
185
202
  * E.g. `[ab]`, `[^ab]`
186
203
  */
187
- export interface CharacterClass extends NodeBase {
204
+ export type CharacterClass =
205
+ | ClassRangesCharacterClass
206
+ | UnicodeSetsCharacterClass;
207
+ interface BaseCharacterClass extends NodeBase {
188
208
  type: "CharacterClass";
189
- parent: Alternative | Quantifier;
209
+ parent:
210
+ | Alternative
211
+ | ExpressionCharacterClass
212
+ | Quantifier
213
+ | UnicodeSetsCharacterClass;
214
+ unicodeSets: boolean;
190
215
  negate: boolean;
191
216
  elements: CharacterClassElement[];
192
217
  }
218
+ export interface ClassRangesCharacterClass extends BaseCharacterClass {
219
+ parent: Alternative | Quantifier;
220
+ unicodeSets: false;
221
+ elements: ClassRangesCharacterClassElement[];
222
+ }
223
+ /** UnicodeSetsCharacterClass is the CharacterClass when in Unicode sets mode. So it may contain strings. */
224
+ export interface UnicodeSetsCharacterClass extends BaseCharacterClass {
225
+ parent:
226
+ | Alternative
227
+ | ExpressionCharacterClass
228
+ | Quantifier
229
+ | UnicodeSetsCharacterClass;
230
+ unicodeSets: true;
231
+ elements: UnicodeSetsCharacterClassElement[];
232
+ }
193
233
  /**
194
234
  * The character class.
195
235
  * E.g. `[a-b]`
@@ -249,7 +289,12 @@ declare module "@eslint-community/regexpp/ast" {
249
289
  */
250
290
  export interface EscapeCharacterSet extends NodeBase {
251
291
  type: "CharacterSet";
252
- parent: Alternative | CharacterClass | Quantifier;
292
+ parent:
293
+ | Alternative
294
+ | CharacterClass
295
+ | ClassIntersection
296
+ | ClassSubtraction
297
+ | Quantifier;
253
298
  kind: "digit" | "space" | "word";
254
299
  negate: boolean;
255
300
  }
@@ -257,14 +302,92 @@ declare module "@eslint-community/regexpp/ast" {
257
302
  * The unicode property escape.
258
303
  * E.g. `\p{ASCII}`, `\P{ASCII}`, `\p{Script=Hiragana}`
259
304
  */
260
- export interface UnicodePropertyCharacterSet extends NodeBase {
305
+ export type UnicodePropertyCharacterSet =
306
+ | CharacterUnicodePropertyCharacterSet
307
+ | StringsUnicodePropertyCharacterSet;
308
+ interface BaseUnicodePropertyCharacterSet extends NodeBase {
261
309
  type: "CharacterSet";
262
- parent: Alternative | CharacterClass | Quantifier;
310
+ parent:
311
+ | Alternative
312
+ | CharacterClass
313
+ | ClassIntersection
314
+ | ClassSubtraction
315
+ | Quantifier;
263
316
  kind: "property";
317
+ strings: boolean;
264
318
  key: string;
265
319
  value: string | null;
266
320
  negate: boolean;
267
321
  }
322
+ export interface CharacterUnicodePropertyCharacterSet
323
+ extends BaseUnicodePropertyCharacterSet {
324
+ strings: false;
325
+ value: string | null;
326
+ negate: boolean;
327
+ }
328
+ /** StringsUnicodePropertyCharacterSet is Unicode property escape with property of strings. */
329
+ export interface StringsUnicodePropertyCharacterSet
330
+ extends BaseUnicodePropertyCharacterSet {
331
+ strings: true;
332
+ value: null;
333
+ negate: false;
334
+ }
335
+ /**
336
+ * The expression character class.
337
+ * E.g. `[a--b]`, `[a&&b]`,`[^a--b]`, `[^a&&b]`
338
+ */
339
+ export interface ExpressionCharacterClass extends NodeBase {
340
+ type: "ExpressionCharacterClass";
341
+ parent:
342
+ | Alternative
343
+ | ExpressionCharacterClass
344
+ | Quantifier
345
+ | UnicodeSetsCharacterClass;
346
+ negate: boolean;
347
+ expression: ClassIntersection | ClassSubtraction;
348
+ }
349
+ export type ClassSetOperand =
350
+ | Character
351
+ | ClassStringDisjunction
352
+ | EscapeCharacterSet
353
+ | ExpressionCharacterClass
354
+ | UnicodePropertyCharacterSet
355
+ | UnicodeSetsCharacterClass;
356
+ /**
357
+ * The character class intersection.
358
+ * E.g. `a&&b`
359
+ */
360
+ export interface ClassIntersection extends NodeBase {
361
+ type: "ClassIntersection";
362
+ parent: ClassIntersection | ExpressionCharacterClass;
363
+ left: ClassIntersection | ClassSetOperand;
364
+ right: ClassSetOperand;
365
+ }
366
+ /**
367
+ * The character class subtraction.
368
+ * E.g. `a--b`
369
+ */
370
+ export interface ClassSubtraction extends NodeBase {
371
+ type: "ClassSubtraction";
372
+ parent: ClassSubtraction | ExpressionCharacterClass;
373
+ left: ClassSetOperand | ClassSubtraction;
374
+ right: ClassSetOperand;
375
+ }
376
+ /**
377
+ * The character class string disjunction.
378
+ * E.g. `\q{a|b}`
379
+ */
380
+ export interface ClassStringDisjunction extends NodeBase {
381
+ type: "ClassStringDisjunction";
382
+ parent: ClassIntersection | ClassSubtraction | UnicodeSetsCharacterClass;
383
+ alternatives: StringAlternative[];
384
+ }
385
+ /** StringAlternative is only used for `\q{alt}`({@link ClassStringDisjunction}). */
386
+ export interface StringAlternative extends NodeBase {
387
+ type: "StringAlternative";
388
+ parent: ClassStringDisjunction;
389
+ elements: Character[];
390
+ }
268
391
  /**
269
392
  * The character.
270
393
  * This includes escape sequences which mean a character.
@@ -272,7 +395,14 @@ declare module "@eslint-community/regexpp/ast" {
272
395
  */
273
396
  export interface Character extends NodeBase {
274
397
  type: "Character";
275
- parent: Alternative | CharacterClass | CharacterClassRange | Quantifier;
398
+ parent:
399
+ | Alternative
400
+ | CharacterClass
401
+ | CharacterClassRange
402
+ | ClassIntersection
403
+ | ClassSubtraction
404
+ | Quantifier
405
+ | StringAlternative;
276
406
  value: number;
277
407
  }
278
408
  /**
@@ -298,7 +428,9 @@ declare module "@eslint-community/regexpp/ast" {
298
428
  multiline: boolean;
299
429
  sticky: boolean;
300
430
  unicode: boolean;
431
+ unicodeSets: boolean;
301
432
  }
433
+ export {};
302
434
  }
303
435
 
304
436
  declare module "@eslint-community/regexpp/parser" {
@@ -318,13 +450,14 @@ declare module "@eslint-community/regexpp/parser" {
318
450
  */
319
451
  strict?: boolean;
320
452
  /**
321
- * ECMAScript version. Default is `2023`.
453
+ * ECMAScript version. Default is `2024`.
322
454
  * - `2015` added `u` and `y` flags.
323
455
  * - `2018` added `s` flag, Named Capturing Group, Lookbehind Assertion,
324
456
  * and Unicode Property Escape.
325
457
  * - `2019`, `2020`, and `2021` added more valid Unicode Property Escapes.
326
458
  * - `2022` added `d` flag.
327
459
  * - `2023` added more valid Unicode Property Escapes.
460
+ * - `2024` added `v` flag.
328
461
  */
329
462
  ecmaVersion?: EcmaVersion;
330
463
  }
@@ -356,6 +489,25 @@ declare module "@eslint-community/regexpp/parser" {
356
489
  * @param source The source code to parse.
357
490
  * @param start The start index in the source code.
358
491
  * @param end The end index in the source code.
492
+ * @param flags The flags.
493
+ * @returns The AST of the given pattern.
494
+ */
495
+ parsePattern(
496
+ source: string,
497
+ start?: number,
498
+ end?: number,
499
+ flags?: {
500
+ unicode?: boolean;
501
+ unicodeSets?: boolean;
502
+ }
503
+ ): Pattern;
504
+ /**
505
+ * @deprecated Backward compatibility
506
+ * Use object `flags` instead of boolean `uFlag`.
507
+ *
508
+ * @param source The source code to parse.
509
+ * @param start The start index in the source code.
510
+ * @param end The end index in the source code.
359
511
  * @param uFlag The flag to set unicode mode.
360
512
  * @returns The AST of the given pattern.
361
513
  */
@@ -380,13 +532,14 @@ declare module "@eslint-community/regexpp/validator" {
380
532
  */
381
533
  strict?: boolean;
382
534
  /**
383
- * ECMAScript version. Default is `2023`.
535
+ * ECMAScript version. Default is `2024`.
384
536
  * - `2015` added `u` and `y` flags.
385
537
  * - `2018` added `s` flag, Named Capturing Group, Lookbehind Assertion,
386
538
  * and Unicode Property Escape.
387
539
  * - `2019`, `2020`, and `2021` added more valid Unicode Property Escapes.
388
540
  * - `2022` added `d` flag.
389
541
  * - `2023` added more valid Unicode Property Escapes.
542
+ * - `2024` added `v` flag.
390
543
  */
391
544
  ecmaVersion?: EcmaVersion;
392
545
  /**
@@ -411,6 +564,7 @@ declare module "@eslint-community/regexpp/validator" {
411
564
  * @param flags.sticky `y` flag.
412
565
  * @param flags.dotAll `s` flag.
413
566
  * @param flags.hasIndices `d` flag.
567
+ * @param flags.unicodeSets `v` flag.
414
568
  */
415
569
  onRegExpFlags?: (
416
570
  start: number,
@@ -423,6 +577,7 @@ declare module "@eslint-community/regexpp/validator" {
423
577
  sticky: boolean;
424
578
  dotAll: boolean;
425
579
  hasIndices: boolean;
580
+ unicodeSets: boolean;
426
581
  }
427
582
  ) => void;
428
583
  /**
@@ -604,6 +759,7 @@ declare module "@eslint-community/regexpp/validator" {
604
759
  * @param key The property name.
605
760
  * @param value The property value.
606
761
  * @param negate The flag which represents that the character set is negative.
762
+ * @param strings If true, the given property is property of strings.
607
763
  */
608
764
  onUnicodePropertyCharacterSet?: (
609
765
  start: number,
@@ -611,7 +767,8 @@ declare module "@eslint-community/regexpp/validator" {
611
767
  kind: "property",
612
768
  key: string,
613
769
  value: string | null,
614
- negate: boolean
770
+ negate: boolean,
771
+ strings: boolean
615
772
  ) => void;
616
773
  /**
617
774
  * A function that is called when the validator found a character.
@@ -635,8 +792,13 @@ declare module "@eslint-community/regexpp/validator" {
635
792
  * A function that is called when the validator entered a character class.
636
793
  * @param start The 0-based index of the first character.
637
794
  * @param negate The flag which represents that the character class is negative.
795
+ * @param unicodeSets `true` if unicodeSets mode.
638
796
  */
639
- onCharacterClassEnter?: (start: number, negate: boolean) => void;
797
+ onCharacterClassEnter?: (
798
+ start: number,
799
+ negate: boolean,
800
+ unicodeSets: boolean
801
+ ) => void;
640
802
  /**
641
803
  * A function that is called when the validator left a character class.
642
804
  * @param start The 0-based index of the first character.
@@ -661,6 +823,46 @@ declare module "@eslint-community/regexpp/validator" {
661
823
  min: number,
662
824
  max: number
663
825
  ) => void;
826
+ /**
827
+ * A function that is called when the validator found a class intersection.
828
+ * @param start The 0-based index of the first character.
829
+ * @param end The next 0-based index of the last character.
830
+ */
831
+ onClassIntersection?: (start: number, end: number) => void;
832
+ /**
833
+ * A function that is called when the validator found a class subtraction.
834
+ * @param start The 0-based index of the first character.
835
+ * @param end The next 0-based index of the last character.
836
+ */
837
+ onClassSubtraction?: (start: number, end: number) => void;
838
+ /**
839
+ * A function that is called when the validator entered a class string disjunction.
840
+ * @param start The 0-based index of the first character.
841
+ */
842
+ onClassStringDisjunctionEnter?: (start: number) => void;
843
+ /**
844
+ * A function that is called when the validator left a class string disjunction.
845
+ * @param start The 0-based index of the first character.
846
+ * @param end The next 0-based index of the last character.
847
+ */
848
+ onClassStringDisjunctionLeave?: (start: number, end: number) => void;
849
+ /**
850
+ * A function that is called when the validator entered a string alternative.
851
+ * @param start The 0-based index of the first character.
852
+ * @param index The 0-based index of alternatives in a disjunction.
853
+ */
854
+ onStringAlternativeEnter?: (start: number, index: number) => void;
855
+ /**
856
+ * A function that is called when the validator left a string alternative.
857
+ * @param start The 0-based index of the first character.
858
+ * @param end The next 0-based index of the last character.
859
+ * @param index The 0-based index of alternatives in a disjunction.
860
+ */
861
+ onStringAlternativeLeave?: (
862
+ start: number,
863
+ end: number,
864
+ index: number
865
+ ) => void;
664
866
  }
665
867
  }
666
868
  /**
@@ -691,6 +893,23 @@ declare module "@eslint-community/regexpp/validator" {
691
893
  * @param source The source code to validate.
692
894
  * @param start The start index in the source code.
693
895
  * @param end The end index in the source code.
896
+ * @param flags The flags.
897
+ */
898
+ validatePattern(
899
+ source: string,
900
+ start?: number,
901
+ end?: number,
902
+ flags?: {
903
+ unicode?: boolean;
904
+ unicodeSets?: boolean;
905
+ }
906
+ ): void;
907
+ /**
908
+ * @deprecated Backward compatibility
909
+ * Use object `flags` instead of boolean `uFlag`.
910
+ * @param source The source code to validate.
911
+ * @param start The start index in the source code.
912
+ * @param end The end index in the source code.
694
913
  * @param uFlag The flag to set unicode mode.
695
914
  */
696
915
  validatePattern(
@@ -712,12 +931,17 @@ declare module "@eslint-community/regexpp/visitor" {
712
931
  CharacterClass,
713
932
  CharacterClassRange,
714
933
  CharacterSet,
934
+ ClassIntersection,
935
+ ClassStringDisjunction,
936
+ ClassSubtraction,
937
+ ExpressionCharacterClass,
715
938
  Flags,
716
939
  Group,
717
940
  Node,
718
941
  Pattern,
719
942
  Quantifier,
720
943
  RegExpLiteral,
944
+ StringAlternative,
721
945
  } from "@eslint-community/regexpp/ast";
722
946
  /**
723
947
  * The visitor to walk on AST.
@@ -752,6 +976,18 @@ declare module "@eslint-community/regexpp/visitor" {
752
976
  onCharacterClassRangeLeave?: (node: CharacterClassRange) => void;
753
977
  onCharacterSetEnter?: (node: CharacterSet) => void;
754
978
  onCharacterSetLeave?: (node: CharacterSet) => void;
979
+ onClassIntersectionEnter?: (node: ClassIntersection) => void;
980
+ onClassIntersectionLeave?: (node: ClassIntersection) => void;
981
+ onClassStringDisjunctionEnter?: (node: ClassStringDisjunction) => void;
982
+ onClassStringDisjunctionLeave?: (node: ClassStringDisjunction) => void;
983
+ onClassSubtractionEnter?: (node: ClassSubtraction) => void;
984
+ onClassSubtractionLeave?: (node: ClassSubtraction) => void;
985
+ onExpressionCharacterClassEnter?: (
986
+ node: ExpressionCharacterClass
987
+ ) => void;
988
+ onExpressionCharacterClassLeave?: (
989
+ node: ExpressionCharacterClass
990
+ ) => void;
755
991
  onFlagsEnter?: (node: Flags) => void;
756
992
  onFlagsLeave?: (node: Flags) => void;
757
993
  onGroupEnter?: (node: Group) => void;
@@ -762,6 +998,8 @@ declare module "@eslint-community/regexpp/visitor" {
762
998
  onQuantifierLeave?: (node: Quantifier) => void;
763
999
  onRegExpLiteralEnter?: (node: RegExpLiteral) => void;
764
1000
  onRegExpLiteralLeave?: (node: RegExpLiteral) => void;
1001
+ onStringAlternativeEnter?: (node: StringAlternative) => void;
1002
+ onStringAlternativeLeave?: (node: StringAlternative) => void;
765
1003
  }
766
1004
  }
767
1005
  }
@@ -777,5 +1015,7 @@ declare module "@eslint-community/regexpp/ecma-versions" {
777
1015
  | 2020
778
1016
  | 2021
779
1017
  | 2022
780
- | 2023;
1018
+ | 2023
1019
+ | 2024;
1020
+ export const latestEcmaVersion = 2024;
781
1021
  }