@eslint-community/regexpp 4.2.0 → 4.3.0
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/index.d.ts +9 -0
- package/index.js +254 -235
- package/index.js.map +1 -1
- package/index.mjs +254 -235
- package/index.mjs.map +1 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -125,105 +125,105 @@ function isValidLoneUnicodeProperty(version, value) {
|
|
|
125
125
|
(version >= 2021 && binPropertySets.es2021.has(value)));
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
const
|
|
128
|
+
const BACKSPACE = 0x08;
|
|
129
|
+
const CHARACTER_TABULATION = 0x09;
|
|
130
|
+
const LINE_FEED = 0x0a;
|
|
131
|
+
const LINE_TABULATION = 0x0b;
|
|
132
|
+
const FORM_FEED = 0x0c;
|
|
133
|
+
const CARRIAGE_RETURN = 0x0d;
|
|
134
|
+
const EXCLAMATION_MARK = 0x21;
|
|
135
|
+
const DOLLAR_SIGN = 0x24;
|
|
136
|
+
const LEFT_PARENTHESIS = 0x28;
|
|
137
|
+
const RIGHT_PARENTHESIS = 0x29;
|
|
138
|
+
const ASTERISK = 0x2a;
|
|
139
|
+
const PLUS_SIGN = 0x2b;
|
|
140
|
+
const COMMA = 0x2c;
|
|
141
|
+
const HYPHEN_MINUS = 0x2d;
|
|
142
|
+
const FULL_STOP = 0x2e;
|
|
143
|
+
const SOLIDUS = 0x2f;
|
|
144
|
+
const DIGIT_ZERO = 0x30;
|
|
145
|
+
const DIGIT_ONE = 0x31;
|
|
146
|
+
const DIGIT_SEVEN = 0x37;
|
|
147
|
+
const DIGIT_NINE = 0x39;
|
|
148
|
+
const COLON = 0x3a;
|
|
149
|
+
const LESS_THAN_SIGN = 0x3c;
|
|
150
|
+
const EQUALS_SIGN = 0x3d;
|
|
151
|
+
const GREATER_THAN_SIGN = 0x3e;
|
|
152
|
+
const QUESTION_MARK = 0x3f;
|
|
153
|
+
const LATIN_CAPITAL_LETTER_A = 0x41;
|
|
154
|
+
const LATIN_CAPITAL_LETTER_B = 0x42;
|
|
155
|
+
const LATIN_CAPITAL_LETTER_D = 0x44;
|
|
156
|
+
const LATIN_CAPITAL_LETTER_F = 0x46;
|
|
157
|
+
const LATIN_CAPITAL_LETTER_P = 0x50;
|
|
158
|
+
const LATIN_CAPITAL_LETTER_S = 0x53;
|
|
159
|
+
const LATIN_CAPITAL_LETTER_W = 0x57;
|
|
160
|
+
const LATIN_CAPITAL_LETTER_Z = 0x5a;
|
|
161
|
+
const LOW_LINE = 0x5f;
|
|
162
|
+
const LATIN_SMALL_LETTER_A = 0x61;
|
|
163
|
+
const LATIN_SMALL_LETTER_B = 0x62;
|
|
164
|
+
const LATIN_SMALL_LETTER_C = 0x63;
|
|
165
|
+
const LATIN_SMALL_LETTER_D = 0x64;
|
|
166
|
+
const LATIN_SMALL_LETTER_F = 0x66;
|
|
167
|
+
const LATIN_SMALL_LETTER_G = 0x67;
|
|
168
|
+
const LATIN_SMALL_LETTER_I = 0x69;
|
|
169
|
+
const LATIN_SMALL_LETTER_K = 0x6b;
|
|
170
|
+
const LATIN_SMALL_LETTER_M = 0x6d;
|
|
171
|
+
const LATIN_SMALL_LETTER_N = 0x6e;
|
|
172
|
+
const LATIN_SMALL_LETTER_P = 0x70;
|
|
173
|
+
const LATIN_SMALL_LETTER_R = 0x72;
|
|
174
|
+
const LATIN_SMALL_LETTER_S = 0x73;
|
|
175
|
+
const LATIN_SMALL_LETTER_T = 0x74;
|
|
176
|
+
const LATIN_SMALL_LETTER_U = 0x75;
|
|
177
|
+
const LATIN_SMALL_LETTER_V = 0x76;
|
|
178
|
+
const LATIN_SMALL_LETTER_W = 0x77;
|
|
179
|
+
const LATIN_SMALL_LETTER_X = 0x78;
|
|
180
|
+
const LATIN_SMALL_LETTER_Y = 0x79;
|
|
181
|
+
const LATIN_SMALL_LETTER_Z = 0x7a;
|
|
182
|
+
const LEFT_SQUARE_BRACKET = 0x5b;
|
|
183
|
+
const REVERSE_SOLIDUS = 0x5c;
|
|
184
|
+
const RIGHT_SQUARE_BRACKET = 0x5d;
|
|
185
|
+
const CIRCUMFLEX_ACCENT = 0x5e;
|
|
186
|
+
const LEFT_CURLY_BRACKET = 0x7b;
|
|
187
|
+
const VERTICAL_LINE = 0x7c;
|
|
188
|
+
const RIGHT_CURLY_BRACKET = 0x7d;
|
|
189
|
+
const ZERO_WIDTH_NON_JOINER = 0x200c;
|
|
190
|
+
const ZERO_WIDTH_JOINER = 0x200d;
|
|
191
|
+
const LINE_SEPARATOR = 0x2028;
|
|
192
|
+
const PARAGRAPH_SEPARATOR = 0x2029;
|
|
193
|
+
const MIN_CODE_POINT = 0x00;
|
|
194
|
+
const MAX_CODE_POINT = 0x10ffff;
|
|
195
195
|
function isLatinLetter(code) {
|
|
196
|
-
return ((code >=
|
|
197
|
-
(code >=
|
|
196
|
+
return ((code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_Z) ||
|
|
197
|
+
(code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_Z));
|
|
198
198
|
}
|
|
199
199
|
function isDecimalDigit(code) {
|
|
200
|
-
return code >=
|
|
200
|
+
return code >= DIGIT_ZERO && code <= DIGIT_NINE;
|
|
201
201
|
}
|
|
202
202
|
function isOctalDigit(code) {
|
|
203
|
-
return code >=
|
|
203
|
+
return code >= DIGIT_ZERO && code <= DIGIT_SEVEN;
|
|
204
204
|
}
|
|
205
205
|
function isHexDigit(code) {
|
|
206
|
-
return ((code >=
|
|
207
|
-
(code >=
|
|
208
|
-
(code >=
|
|
206
|
+
return ((code >= DIGIT_ZERO && code <= DIGIT_NINE) ||
|
|
207
|
+
(code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_F) ||
|
|
208
|
+
(code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_F));
|
|
209
209
|
}
|
|
210
210
|
function isLineTerminator(code) {
|
|
211
|
-
return (code ===
|
|
212
|
-
code ===
|
|
213
|
-
code ===
|
|
214
|
-
code ===
|
|
211
|
+
return (code === LINE_FEED ||
|
|
212
|
+
code === CARRIAGE_RETURN ||
|
|
213
|
+
code === LINE_SEPARATOR ||
|
|
214
|
+
code === PARAGRAPH_SEPARATOR);
|
|
215
215
|
}
|
|
216
216
|
function isValidUnicode(code) {
|
|
217
|
-
return code >=
|
|
217
|
+
return code >= MIN_CODE_POINT && code <= MAX_CODE_POINT;
|
|
218
218
|
}
|
|
219
219
|
function digitToInt(code) {
|
|
220
|
-
if (code >=
|
|
221
|
-
return code -
|
|
220
|
+
if (code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_F) {
|
|
221
|
+
return code - LATIN_SMALL_LETTER_A + 10;
|
|
222
222
|
}
|
|
223
|
-
if (code >=
|
|
224
|
-
return code -
|
|
223
|
+
if (code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_F) {
|
|
224
|
+
return code - LATIN_CAPITAL_LETTER_A + 10;
|
|
225
225
|
}
|
|
226
|
-
return code -
|
|
226
|
+
return code - DIGIT_ZERO;
|
|
227
227
|
}
|
|
228
228
|
function isLeadSurrogate(code) {
|
|
229
229
|
return code >= 0xd800 && code <= 0xdbff;
|
|
@@ -353,33 +353,33 @@ class RegExpSyntaxError extends SyntaxError {
|
|
|
353
353
|
}
|
|
354
354
|
|
|
355
355
|
function isSyntaxCharacter(cp) {
|
|
356
|
-
return (cp ===
|
|
357
|
-
cp ===
|
|
358
|
-
cp ===
|
|
359
|
-
cp ===
|
|
360
|
-
cp ===
|
|
361
|
-
cp ===
|
|
362
|
-
cp ===
|
|
363
|
-
cp ===
|
|
364
|
-
cp ===
|
|
365
|
-
cp ===
|
|
366
|
-
cp ===
|
|
367
|
-
cp ===
|
|
368
|
-
cp ===
|
|
369
|
-
cp ===
|
|
356
|
+
return (cp === CIRCUMFLEX_ACCENT ||
|
|
357
|
+
cp === DOLLAR_SIGN ||
|
|
358
|
+
cp === REVERSE_SOLIDUS ||
|
|
359
|
+
cp === FULL_STOP ||
|
|
360
|
+
cp === ASTERISK ||
|
|
361
|
+
cp === PLUS_SIGN ||
|
|
362
|
+
cp === QUESTION_MARK ||
|
|
363
|
+
cp === LEFT_PARENTHESIS ||
|
|
364
|
+
cp === RIGHT_PARENTHESIS ||
|
|
365
|
+
cp === LEFT_SQUARE_BRACKET ||
|
|
366
|
+
cp === RIGHT_SQUARE_BRACKET ||
|
|
367
|
+
cp === LEFT_CURLY_BRACKET ||
|
|
368
|
+
cp === RIGHT_CURLY_BRACKET ||
|
|
369
|
+
cp === VERTICAL_LINE);
|
|
370
370
|
}
|
|
371
371
|
function isRegExpIdentifierStart(cp) {
|
|
372
|
-
return isIdStart(cp) || cp ===
|
|
372
|
+
return isIdStart(cp) || cp === DOLLAR_SIGN || cp === LOW_LINE;
|
|
373
373
|
}
|
|
374
374
|
function isRegExpIdentifierPart(cp) {
|
|
375
375
|
return (isIdContinue(cp) ||
|
|
376
|
-
cp ===
|
|
377
|
-
cp ===
|
|
378
|
-
cp ===
|
|
379
|
-
cp ===
|
|
376
|
+
cp === DOLLAR_SIGN ||
|
|
377
|
+
cp === LOW_LINE ||
|
|
378
|
+
cp === ZERO_WIDTH_NON_JOINER ||
|
|
379
|
+
cp === ZERO_WIDTH_JOINER);
|
|
380
380
|
}
|
|
381
381
|
function isUnicodePropertyNameCharacter(cp) {
|
|
382
|
-
return isLatinLetter(cp) || cp ===
|
|
382
|
+
return isLatinLetter(cp) || cp === LOW_LINE;
|
|
383
383
|
}
|
|
384
384
|
function isUnicodePropertyValueCharacter(cp) {
|
|
385
385
|
return isUnicodePropertyNameCharacter(cp) || isDecimalDigit(cp);
|
|
@@ -405,7 +405,7 @@ class RegExpValidator {
|
|
|
405
405
|
this._uFlag = this._nFlag = false;
|
|
406
406
|
this.reset(source, start, end);
|
|
407
407
|
this.onLiteralEnter(start);
|
|
408
|
-
if (this.eat(
|
|
408
|
+
if (this.eat(SOLIDUS) && this.eatRegExpBody() && this.eat(SOLIDUS)) {
|
|
409
409
|
const flagStart = this.index;
|
|
410
410
|
const uFlag = source.includes("u", flagStart);
|
|
411
411
|
this.validateFlags(source, flagStart, end);
|
|
@@ -435,32 +435,44 @@ class RegExpValidator {
|
|
|
435
435
|
this.raise(`Duplicated flag '${source[i]}'`);
|
|
436
436
|
}
|
|
437
437
|
existingFlags.add(flag);
|
|
438
|
-
if (flag ===
|
|
438
|
+
if (flag === LATIN_SMALL_LETTER_G) {
|
|
439
439
|
global = true;
|
|
440
440
|
}
|
|
441
|
-
else if (flag ===
|
|
441
|
+
else if (flag === LATIN_SMALL_LETTER_I) {
|
|
442
442
|
ignoreCase = true;
|
|
443
443
|
}
|
|
444
|
-
else if (flag ===
|
|
444
|
+
else if (flag === LATIN_SMALL_LETTER_M) {
|
|
445
445
|
multiline = true;
|
|
446
446
|
}
|
|
447
|
-
else if (flag ===
|
|
447
|
+
else if (flag === LATIN_SMALL_LETTER_U &&
|
|
448
|
+
this.ecmaVersion >= 2015) {
|
|
448
449
|
unicode = true;
|
|
449
450
|
}
|
|
450
|
-
else if (flag ===
|
|
451
|
+
else if (flag === LATIN_SMALL_LETTER_Y &&
|
|
452
|
+
this.ecmaVersion >= 2015) {
|
|
451
453
|
sticky = true;
|
|
452
454
|
}
|
|
453
|
-
else if (flag ===
|
|
455
|
+
else if (flag === LATIN_SMALL_LETTER_S &&
|
|
456
|
+
this.ecmaVersion >= 2018) {
|
|
454
457
|
dotAll = true;
|
|
455
458
|
}
|
|
456
|
-
else if (flag ===
|
|
459
|
+
else if (flag === LATIN_SMALL_LETTER_D &&
|
|
460
|
+
this.ecmaVersion >= 2022) {
|
|
457
461
|
hasIndices = true;
|
|
458
462
|
}
|
|
459
463
|
else {
|
|
460
464
|
this.raise(`Invalid flag '${source[i]}'`);
|
|
461
465
|
}
|
|
462
466
|
}
|
|
463
|
-
this.
|
|
467
|
+
this.onRegExpFlags(start, end, {
|
|
468
|
+
global,
|
|
469
|
+
ignoreCase,
|
|
470
|
+
multiline,
|
|
471
|
+
unicode,
|
|
472
|
+
sticky,
|
|
473
|
+
dotAll,
|
|
474
|
+
hasIndices,
|
|
475
|
+
});
|
|
464
476
|
}
|
|
465
477
|
validatePattern(source, start = 0, end = source.length, uFlag = false) {
|
|
466
478
|
this._uFlag = uFlag && this.ecmaVersion >= 2015;
|
|
@@ -492,9 +504,12 @@ class RegExpValidator {
|
|
|
492
504
|
this._options.onLiteralLeave(start, end);
|
|
493
505
|
}
|
|
494
506
|
}
|
|
495
|
-
|
|
507
|
+
onRegExpFlags(start, end, flags) {
|
|
508
|
+
if (this._options.onRegExpFlags) {
|
|
509
|
+
this._options.onRegExpFlags(start, end, flags);
|
|
510
|
+
}
|
|
496
511
|
if (this._options.onFlags) {
|
|
497
|
-
this._options.onFlags(start, end, global, ignoreCase, multiline, unicode, sticky, dotAll, hasIndices);
|
|
512
|
+
this._options.onFlags(start, end, flags.global, flags.ignoreCase, flags.multiline, flags.unicode, flags.sticky, flags.dotAll, flags.hasIndices);
|
|
498
513
|
}
|
|
499
514
|
}
|
|
500
515
|
onPatternEnter(start) {
|
|
@@ -664,17 +679,17 @@ class RegExpValidator {
|
|
|
664
679
|
if (escaped) {
|
|
665
680
|
escaped = false;
|
|
666
681
|
}
|
|
667
|
-
else if (cp ===
|
|
682
|
+
else if (cp === REVERSE_SOLIDUS) {
|
|
668
683
|
escaped = true;
|
|
669
684
|
}
|
|
670
|
-
else if (cp ===
|
|
685
|
+
else if (cp === LEFT_SQUARE_BRACKET) {
|
|
671
686
|
inClass = true;
|
|
672
687
|
}
|
|
673
|
-
else if (cp ===
|
|
688
|
+
else if (cp === RIGHT_SQUARE_BRACKET) {
|
|
674
689
|
inClass = false;
|
|
675
690
|
}
|
|
676
|
-
else if ((cp ===
|
|
677
|
-
(cp ===
|
|
691
|
+
else if ((cp === SOLIDUS && !inClass) ||
|
|
692
|
+
(cp === ASTERISK && this.index === start)) {
|
|
678
693
|
break;
|
|
679
694
|
}
|
|
680
695
|
this.advance();
|
|
@@ -690,13 +705,13 @@ class RegExpValidator {
|
|
|
690
705
|
this.consumeDisjunction();
|
|
691
706
|
const cp = this.currentCodePoint;
|
|
692
707
|
if (this.currentCodePoint !== -1) {
|
|
693
|
-
if (cp ===
|
|
708
|
+
if (cp === RIGHT_PARENTHESIS) {
|
|
694
709
|
this.raise("Unmatched ')'");
|
|
695
710
|
}
|
|
696
|
-
if (cp ===
|
|
711
|
+
if (cp === REVERSE_SOLIDUS) {
|
|
697
712
|
this.raise("\\ at end of pattern");
|
|
698
713
|
}
|
|
699
|
-
if (cp ===
|
|
714
|
+
if (cp === RIGHT_SQUARE_BRACKET || cp === RIGHT_CURLY_BRACKET) {
|
|
700
715
|
this.raise("Lone quantifier brackets");
|
|
701
716
|
}
|
|
702
717
|
const c = String.fromCodePoint(cp);
|
|
@@ -719,21 +734,21 @@ class RegExpValidator {
|
|
|
719
734
|
if (escaped) {
|
|
720
735
|
escaped = false;
|
|
721
736
|
}
|
|
722
|
-
else if (cp ===
|
|
737
|
+
else if (cp === REVERSE_SOLIDUS) {
|
|
723
738
|
escaped = true;
|
|
724
739
|
}
|
|
725
|
-
else if (cp ===
|
|
740
|
+
else if (cp === LEFT_SQUARE_BRACKET) {
|
|
726
741
|
inClass = true;
|
|
727
742
|
}
|
|
728
|
-
else if (cp ===
|
|
743
|
+
else if (cp === RIGHT_SQUARE_BRACKET) {
|
|
729
744
|
inClass = false;
|
|
730
745
|
}
|
|
731
|
-
else if (cp ===
|
|
746
|
+
else if (cp === LEFT_PARENTHESIS &&
|
|
732
747
|
!inClass &&
|
|
733
|
-
(this.nextCodePoint !==
|
|
734
|
-
(this.nextCodePoint2 ===
|
|
735
|
-
this.nextCodePoint3 !==
|
|
736
|
-
this.nextCodePoint3 !==
|
|
748
|
+
(this.nextCodePoint !== QUESTION_MARK ||
|
|
749
|
+
(this.nextCodePoint2 === LESS_THAN_SIGN &&
|
|
750
|
+
this.nextCodePoint3 !== EQUALS_SIGN &&
|
|
751
|
+
this.nextCodePoint3 !== EXCLAMATION_MARK))) {
|
|
737
752
|
count += 1;
|
|
738
753
|
}
|
|
739
754
|
this.advance();
|
|
@@ -747,11 +762,11 @@ class RegExpValidator {
|
|
|
747
762
|
this.onDisjunctionEnter(start);
|
|
748
763
|
do {
|
|
749
764
|
this.consumeAlternative(i++);
|
|
750
|
-
} while (this.eat(
|
|
765
|
+
} while (this.eat(VERTICAL_LINE));
|
|
751
766
|
if (this.consumeQuantifier(true)) {
|
|
752
767
|
this.raise("Nothing to repeat");
|
|
753
768
|
}
|
|
754
|
-
if (this.eat(
|
|
769
|
+
if (this.eat(LEFT_CURLY_BRACKET)) {
|
|
755
770
|
this.raise("Lone quantifier brackets");
|
|
756
771
|
}
|
|
757
772
|
this.onDisjunctionLeave(start, this.index);
|
|
@@ -780,30 +795,31 @@ class RegExpValidator {
|
|
|
780
795
|
consumeAssertion() {
|
|
781
796
|
const start = this.index;
|
|
782
797
|
this._lastAssertionIsQuantifiable = false;
|
|
783
|
-
if (this.eat(
|
|
798
|
+
if (this.eat(CIRCUMFLEX_ACCENT)) {
|
|
784
799
|
this.onEdgeAssertion(start, this.index, "start");
|
|
785
800
|
return true;
|
|
786
801
|
}
|
|
787
|
-
if (this.eat(
|
|
802
|
+
if (this.eat(DOLLAR_SIGN)) {
|
|
788
803
|
this.onEdgeAssertion(start, this.index, "end");
|
|
789
804
|
return true;
|
|
790
805
|
}
|
|
791
|
-
if (this.eat2(
|
|
806
|
+
if (this.eat2(REVERSE_SOLIDUS, LATIN_CAPITAL_LETTER_B)) {
|
|
792
807
|
this.onWordBoundaryAssertion(start, this.index, "word", true);
|
|
793
808
|
return true;
|
|
794
809
|
}
|
|
795
|
-
if (this.eat2(
|
|
810
|
+
if (this.eat2(REVERSE_SOLIDUS, LATIN_SMALL_LETTER_B)) {
|
|
796
811
|
this.onWordBoundaryAssertion(start, this.index, "word", false);
|
|
797
812
|
return true;
|
|
798
813
|
}
|
|
799
|
-
if (this.eat2(
|
|
800
|
-
const lookbehind = this.ecmaVersion >= 2018 && this.eat(
|
|
814
|
+
if (this.eat2(LEFT_PARENTHESIS, QUESTION_MARK)) {
|
|
815
|
+
const lookbehind = this.ecmaVersion >= 2018 && this.eat(LESS_THAN_SIGN);
|
|
801
816
|
let negate = false;
|
|
802
|
-
if (this.eat(
|
|
817
|
+
if (this.eat(EQUALS_SIGN) ||
|
|
818
|
+
(negate = this.eat(EXCLAMATION_MARK))) {
|
|
803
819
|
const kind = lookbehind ? "lookbehind" : "lookahead";
|
|
804
820
|
this.onLookaroundAssertionEnter(start, kind, negate);
|
|
805
821
|
this.consumeDisjunction();
|
|
806
|
-
if (!this.eat(
|
|
822
|
+
if (!this.eat(RIGHT_PARENTHESIS)) {
|
|
807
823
|
this.raise("Unterminated group");
|
|
808
824
|
}
|
|
809
825
|
this._lastAssertionIsQuantifiable = !lookbehind && !this.strict;
|
|
@@ -819,15 +835,15 @@ class RegExpValidator {
|
|
|
819
835
|
let min = 0;
|
|
820
836
|
let max = 0;
|
|
821
837
|
let greedy = false;
|
|
822
|
-
if (this.eat(
|
|
838
|
+
if (this.eat(ASTERISK)) {
|
|
823
839
|
min = 0;
|
|
824
840
|
max = Number.POSITIVE_INFINITY;
|
|
825
841
|
}
|
|
826
|
-
else if (this.eat(
|
|
842
|
+
else if (this.eat(PLUS_SIGN)) {
|
|
827
843
|
min = 1;
|
|
828
844
|
max = Number.POSITIVE_INFINITY;
|
|
829
845
|
}
|
|
830
|
-
else if (this.eat(
|
|
846
|
+
else if (this.eat(QUESTION_MARK)) {
|
|
831
847
|
min = 0;
|
|
832
848
|
max = 1;
|
|
833
849
|
}
|
|
@@ -838,7 +854,7 @@ class RegExpValidator {
|
|
|
838
854
|
else {
|
|
839
855
|
return false;
|
|
840
856
|
}
|
|
841
|
-
greedy = !this.eat(
|
|
857
|
+
greedy = !this.eat(QUESTION_MARK);
|
|
842
858
|
if (!noConsume) {
|
|
843
859
|
this.onQuantifier(start, this.index, min, max, greedy);
|
|
844
860
|
}
|
|
@@ -846,17 +862,17 @@ class RegExpValidator {
|
|
|
846
862
|
}
|
|
847
863
|
eatBracedQuantifier(noError) {
|
|
848
864
|
const start = this.index;
|
|
849
|
-
if (this.eat(
|
|
865
|
+
if (this.eat(LEFT_CURLY_BRACKET)) {
|
|
850
866
|
this._lastMinValue = 0;
|
|
851
867
|
this._lastMaxValue = Number.POSITIVE_INFINITY;
|
|
852
868
|
if (this.eatDecimalDigits()) {
|
|
853
869
|
this._lastMinValue = this._lastMaxValue = this._lastIntValue;
|
|
854
|
-
if (this.eat(
|
|
870
|
+
if (this.eat(COMMA)) {
|
|
855
871
|
this._lastMaxValue = this.eatDecimalDigits()
|
|
856
872
|
? this._lastIntValue
|
|
857
873
|
: Number.POSITIVE_INFINITY;
|
|
858
874
|
}
|
|
859
|
-
if (this.eat(
|
|
875
|
+
if (this.eat(RIGHT_CURLY_BRACKET)) {
|
|
860
876
|
if (!noError && this._lastMaxValue < this._lastMinValue) {
|
|
861
877
|
this.raise("numbers out of order in {} quantifier");
|
|
862
878
|
}
|
|
@@ -879,7 +895,7 @@ class RegExpValidator {
|
|
|
879
895
|
this.consumeCapturingGroup());
|
|
880
896
|
}
|
|
881
897
|
consumeDot() {
|
|
882
|
-
if (this.eat(
|
|
898
|
+
if (this.eat(FULL_STOP)) {
|
|
883
899
|
this.onAnyCharacterSet(this.index - 1, this.index, "any");
|
|
884
900
|
return true;
|
|
885
901
|
}
|
|
@@ -887,7 +903,7 @@ class RegExpValidator {
|
|
|
887
903
|
}
|
|
888
904
|
consumeReverseSolidusAtomEscape() {
|
|
889
905
|
const start = this.index;
|
|
890
|
-
if (this.eat(
|
|
906
|
+
if (this.eat(REVERSE_SOLIDUS)) {
|
|
891
907
|
if (this.consumeAtomEscape()) {
|
|
892
908
|
return true;
|
|
893
909
|
}
|
|
@@ -897,10 +913,10 @@ class RegExpValidator {
|
|
|
897
913
|
}
|
|
898
914
|
consumeUncapturingGroup() {
|
|
899
915
|
const start = this.index;
|
|
900
|
-
if (this.eat3(
|
|
916
|
+
if (this.eat3(LEFT_PARENTHESIS, QUESTION_MARK, COLON)) {
|
|
901
917
|
this.onGroupEnter(start);
|
|
902
918
|
this.consumeDisjunction();
|
|
903
|
-
if (!this.eat(
|
|
919
|
+
if (!this.eat(RIGHT_PARENTHESIS)) {
|
|
904
920
|
this.raise("Unterminated group");
|
|
905
921
|
}
|
|
906
922
|
this.onGroupLeave(start, this.index);
|
|
@@ -910,19 +926,19 @@ class RegExpValidator {
|
|
|
910
926
|
}
|
|
911
927
|
consumeCapturingGroup() {
|
|
912
928
|
const start = this.index;
|
|
913
|
-
if (this.eat(
|
|
929
|
+
if (this.eat(LEFT_PARENTHESIS)) {
|
|
914
930
|
let name = null;
|
|
915
931
|
if (this.ecmaVersion >= 2018) {
|
|
916
932
|
if (this.consumeGroupSpecifier()) {
|
|
917
933
|
name = this._lastStrValue;
|
|
918
934
|
}
|
|
919
935
|
}
|
|
920
|
-
else if (this.currentCodePoint ===
|
|
936
|
+
else if (this.currentCodePoint === QUESTION_MARK) {
|
|
921
937
|
this.raise("Invalid group");
|
|
922
938
|
}
|
|
923
939
|
this.onCapturingGroupEnter(start, name);
|
|
924
940
|
this.consumeDisjunction();
|
|
925
|
-
if (!this.eat(
|
|
941
|
+
if (!this.eat(RIGHT_PARENTHESIS)) {
|
|
926
942
|
this.raise("Unterminated group");
|
|
927
943
|
}
|
|
928
944
|
this.onCapturingGroupLeave(start, this.index, name);
|
|
@@ -942,11 +958,11 @@ class RegExpValidator {
|
|
|
942
958
|
}
|
|
943
959
|
consumeReverseSolidusFollowedByC() {
|
|
944
960
|
const start = this.index;
|
|
945
|
-
if (this.currentCodePoint ===
|
|
946
|
-
this.nextCodePoint ===
|
|
961
|
+
if (this.currentCodePoint === REVERSE_SOLIDUS &&
|
|
962
|
+
this.nextCodePoint === LATIN_SMALL_LETTER_C) {
|
|
947
963
|
this._lastIntValue = this.currentCodePoint;
|
|
948
964
|
this.advance();
|
|
949
|
-
this.onCharacter(start, this.index,
|
|
965
|
+
this.onCharacter(start, this.index, REVERSE_SOLIDUS);
|
|
950
966
|
return true;
|
|
951
967
|
}
|
|
952
968
|
return false;
|
|
@@ -971,17 +987,17 @@ class RegExpValidator {
|
|
|
971
987
|
const start = this.index;
|
|
972
988
|
const cp = this.currentCodePoint;
|
|
973
989
|
if (cp !== -1 &&
|
|
974
|
-
cp !==
|
|
975
|
-
cp !==
|
|
976
|
-
cp !==
|
|
977
|
-
cp !==
|
|
978
|
-
cp !==
|
|
979
|
-
cp !==
|
|
980
|
-
cp !==
|
|
981
|
-
cp !==
|
|
982
|
-
cp !==
|
|
983
|
-
cp !==
|
|
984
|
-
cp !==
|
|
990
|
+
cp !== CIRCUMFLEX_ACCENT &&
|
|
991
|
+
cp !== DOLLAR_SIGN &&
|
|
992
|
+
cp !== REVERSE_SOLIDUS &&
|
|
993
|
+
cp !== FULL_STOP &&
|
|
994
|
+
cp !== ASTERISK &&
|
|
995
|
+
cp !== PLUS_SIGN &&
|
|
996
|
+
cp !== QUESTION_MARK &&
|
|
997
|
+
cp !== LEFT_PARENTHESIS &&
|
|
998
|
+
cp !== RIGHT_PARENTHESIS &&
|
|
999
|
+
cp !== LEFT_SQUARE_BRACKET &&
|
|
1000
|
+
cp !== VERTICAL_LINE) {
|
|
985
1001
|
this.advance();
|
|
986
1002
|
this.onCharacter(start, this.index, cp);
|
|
987
1003
|
return true;
|
|
@@ -989,7 +1005,7 @@ class RegExpValidator {
|
|
|
989
1005
|
return false;
|
|
990
1006
|
}
|
|
991
1007
|
consumeGroupSpecifier() {
|
|
992
|
-
if (this.eat(
|
|
1008
|
+
if (this.eat(QUESTION_MARK)) {
|
|
993
1009
|
if (this.eatGroupName()) {
|
|
994
1010
|
if (!this._groupNames.has(this._lastStrValue)) {
|
|
995
1011
|
this._groupNames.add(this._lastStrValue);
|
|
@@ -1030,32 +1046,32 @@ class RegExpValidator {
|
|
|
1030
1046
|
}
|
|
1031
1047
|
consumeCharacterClassEscape() {
|
|
1032
1048
|
const start = this.index;
|
|
1033
|
-
if (this.eat(
|
|
1049
|
+
if (this.eat(LATIN_SMALL_LETTER_D)) {
|
|
1034
1050
|
this._lastIntValue = -1;
|
|
1035
1051
|
this.onEscapeCharacterSet(start - 1, this.index, "digit", false);
|
|
1036
1052
|
return true;
|
|
1037
1053
|
}
|
|
1038
|
-
if (this.eat(
|
|
1054
|
+
if (this.eat(LATIN_CAPITAL_LETTER_D)) {
|
|
1039
1055
|
this._lastIntValue = -1;
|
|
1040
1056
|
this.onEscapeCharacterSet(start - 1, this.index, "digit", true);
|
|
1041
1057
|
return true;
|
|
1042
1058
|
}
|
|
1043
|
-
if (this.eat(
|
|
1059
|
+
if (this.eat(LATIN_SMALL_LETTER_S)) {
|
|
1044
1060
|
this._lastIntValue = -1;
|
|
1045
1061
|
this.onEscapeCharacterSet(start - 1, this.index, "space", false);
|
|
1046
1062
|
return true;
|
|
1047
1063
|
}
|
|
1048
|
-
if (this.eat(
|
|
1064
|
+
if (this.eat(LATIN_CAPITAL_LETTER_S)) {
|
|
1049
1065
|
this._lastIntValue = -1;
|
|
1050
1066
|
this.onEscapeCharacterSet(start - 1, this.index, "space", true);
|
|
1051
1067
|
return true;
|
|
1052
1068
|
}
|
|
1053
|
-
if (this.eat(
|
|
1069
|
+
if (this.eat(LATIN_SMALL_LETTER_W)) {
|
|
1054
1070
|
this._lastIntValue = -1;
|
|
1055
1071
|
this.onEscapeCharacterSet(start - 1, this.index, "word", false);
|
|
1056
1072
|
return true;
|
|
1057
1073
|
}
|
|
1058
|
-
if (this.eat(
|
|
1074
|
+
if (this.eat(LATIN_CAPITAL_LETTER_W)) {
|
|
1059
1075
|
this._lastIntValue = -1;
|
|
1060
1076
|
this.onEscapeCharacterSet(start - 1, this.index, "word", true);
|
|
1061
1077
|
return true;
|
|
@@ -1063,12 +1079,12 @@ class RegExpValidator {
|
|
|
1063
1079
|
let negate = false;
|
|
1064
1080
|
if (this._uFlag &&
|
|
1065
1081
|
this.ecmaVersion >= 2018 &&
|
|
1066
|
-
(this.eat(
|
|
1067
|
-
(negate = this.eat(
|
|
1082
|
+
(this.eat(LATIN_SMALL_LETTER_P) ||
|
|
1083
|
+
(negate = this.eat(LATIN_CAPITAL_LETTER_P)))) {
|
|
1068
1084
|
this._lastIntValue = -1;
|
|
1069
|
-
if (this.eat(
|
|
1085
|
+
if (this.eat(LEFT_CURLY_BRACKET) &&
|
|
1070
1086
|
this.eatUnicodePropertyValueExpression() &&
|
|
1071
|
-
this.eat(
|
|
1087
|
+
this.eat(RIGHT_CURLY_BRACKET)) {
|
|
1072
1088
|
this.onUnicodePropertyCharacterSet(start - 1, this.index, "property", this._lastKeyValue, this._lastValValue || null, negate);
|
|
1073
1089
|
return true;
|
|
1074
1090
|
}
|
|
@@ -1094,7 +1110,7 @@ class RegExpValidator {
|
|
|
1094
1110
|
}
|
|
1095
1111
|
consumeKGroupName() {
|
|
1096
1112
|
const start = this.index;
|
|
1097
|
-
if (this.eat(
|
|
1113
|
+
if (this.eat(LATIN_SMALL_LETTER_K)) {
|
|
1098
1114
|
if (this.eatGroupName()) {
|
|
1099
1115
|
const groupName = this._lastStrValue;
|
|
1100
1116
|
this._backreferenceNames.add(groupName);
|
|
@@ -1107,11 +1123,11 @@ class RegExpValidator {
|
|
|
1107
1123
|
}
|
|
1108
1124
|
consumeCharacterClass() {
|
|
1109
1125
|
const start = this.index;
|
|
1110
|
-
if (this.eat(
|
|
1111
|
-
const negate = this.eat(
|
|
1126
|
+
if (this.eat(LEFT_SQUARE_BRACKET)) {
|
|
1127
|
+
const negate = this.eat(CIRCUMFLEX_ACCENT);
|
|
1112
1128
|
this.onCharacterClassEnter(start, negate);
|
|
1113
1129
|
this.consumeClassRanges();
|
|
1114
|
-
if (!this.eat(
|
|
1130
|
+
if (!this.eat(RIGHT_SQUARE_BRACKET)) {
|
|
1115
1131
|
this.raise("Unterminated character class");
|
|
1116
1132
|
}
|
|
1117
1133
|
this.onCharacterClassLeave(start, this.index, negate);
|
|
@@ -1127,10 +1143,10 @@ class RegExpValidator {
|
|
|
1127
1143
|
break;
|
|
1128
1144
|
}
|
|
1129
1145
|
const min = this._lastIntValue;
|
|
1130
|
-
if (!this.eat(
|
|
1146
|
+
if (!this.eat(HYPHEN_MINUS)) {
|
|
1131
1147
|
continue;
|
|
1132
1148
|
}
|
|
1133
|
-
this.onCharacter(this.index - 1, this.index,
|
|
1149
|
+
this.onCharacter(this.index - 1, this.index, HYPHEN_MINUS);
|
|
1134
1150
|
if (!this.consumeClassAtom()) {
|
|
1135
1151
|
break;
|
|
1136
1152
|
}
|
|
@@ -1150,18 +1166,21 @@ class RegExpValidator {
|
|
|
1150
1166
|
consumeClassAtom() {
|
|
1151
1167
|
const start = this.index;
|
|
1152
1168
|
const cp = this.currentCodePoint;
|
|
1153
|
-
if (cp !== -1 &&
|
|
1169
|
+
if (cp !== -1 &&
|
|
1170
|
+
cp !== REVERSE_SOLIDUS &&
|
|
1171
|
+
cp !== RIGHT_SQUARE_BRACKET) {
|
|
1154
1172
|
this.advance();
|
|
1155
1173
|
this._lastIntValue = cp;
|
|
1156
1174
|
this.onCharacter(start, this.index, this._lastIntValue);
|
|
1157
1175
|
return true;
|
|
1158
1176
|
}
|
|
1159
|
-
if (this.eat(
|
|
1177
|
+
if (this.eat(REVERSE_SOLIDUS)) {
|
|
1160
1178
|
if (this.consumeClassEscape()) {
|
|
1161
1179
|
return true;
|
|
1162
1180
|
}
|
|
1163
|
-
if (!this.strict &&
|
|
1164
|
-
this.
|
|
1181
|
+
if (!this.strict &&
|
|
1182
|
+
this.currentCodePoint === LATIN_SMALL_LETTER_C) {
|
|
1183
|
+
this._lastIntValue = REVERSE_SOLIDUS;
|
|
1165
1184
|
this.onCharacter(start, this.index, this._lastIntValue);
|
|
1166
1185
|
return true;
|
|
1167
1186
|
}
|
|
@@ -1174,21 +1193,21 @@ class RegExpValidator {
|
|
|
1174
1193
|
}
|
|
1175
1194
|
consumeClassEscape() {
|
|
1176
1195
|
const start = this.index;
|
|
1177
|
-
if (this.eat(
|
|
1178
|
-
this._lastIntValue =
|
|
1196
|
+
if (this.eat(LATIN_SMALL_LETTER_B)) {
|
|
1197
|
+
this._lastIntValue = BACKSPACE;
|
|
1179
1198
|
this.onCharacter(start - 1, this.index, this._lastIntValue);
|
|
1180
1199
|
return true;
|
|
1181
1200
|
}
|
|
1182
|
-
if (this._uFlag && this.eat(
|
|
1183
|
-
this._lastIntValue =
|
|
1201
|
+
if (this._uFlag && this.eat(HYPHEN_MINUS)) {
|
|
1202
|
+
this._lastIntValue = HYPHEN_MINUS;
|
|
1184
1203
|
this.onCharacter(start - 1, this.index, this._lastIntValue);
|
|
1185
1204
|
return true;
|
|
1186
1205
|
}
|
|
1187
1206
|
let cp = 0;
|
|
1188
1207
|
if (!this.strict &&
|
|
1189
1208
|
!this._uFlag &&
|
|
1190
|
-
this.currentCodePoint ===
|
|
1191
|
-
(isDecimalDigit((cp = this.nextCodePoint)) || cp ===
|
|
1209
|
+
this.currentCodePoint === LATIN_SMALL_LETTER_C &&
|
|
1210
|
+
(isDecimalDigit((cp = this.nextCodePoint)) || cp === LOW_LINE)) {
|
|
1192
1211
|
this.advance();
|
|
1193
1212
|
this.advance();
|
|
1194
1213
|
this._lastIntValue = cp % 0x20;
|
|
@@ -1198,8 +1217,8 @@ class RegExpValidator {
|
|
|
1198
1217
|
return (this.consumeCharacterClassEscape() || this.consumeCharacterEscape());
|
|
1199
1218
|
}
|
|
1200
1219
|
eatGroupName() {
|
|
1201
|
-
if (this.eat(
|
|
1202
|
-
if (this.eatRegExpIdentifierName() && this.eat(
|
|
1220
|
+
if (this.eat(LESS_THAN_SIGN)) {
|
|
1221
|
+
if (this.eatRegExpIdentifierName() && this.eat(GREATER_THAN_SIGN)) {
|
|
1203
1222
|
return true;
|
|
1204
1223
|
}
|
|
1205
1224
|
this.raise("Invalid capture group name");
|
|
@@ -1221,7 +1240,7 @@ class RegExpValidator {
|
|
|
1221
1240
|
const forceUFlag = !this._uFlag && this.ecmaVersion >= 2020;
|
|
1222
1241
|
let cp = this.currentCodePoint;
|
|
1223
1242
|
this.advance();
|
|
1224
|
-
if (cp ===
|
|
1243
|
+
if (cp === REVERSE_SOLIDUS &&
|
|
1225
1244
|
this.eatRegExpUnicodeEscapeSequence(forceUFlag)) {
|
|
1226
1245
|
cp = this._lastIntValue;
|
|
1227
1246
|
}
|
|
@@ -1245,7 +1264,7 @@ class RegExpValidator {
|
|
|
1245
1264
|
const forceUFlag = !this._uFlag && this.ecmaVersion >= 2020;
|
|
1246
1265
|
let cp = this.currentCodePoint;
|
|
1247
1266
|
this.advance();
|
|
1248
|
-
if (cp ===
|
|
1267
|
+
if (cp === REVERSE_SOLIDUS &&
|
|
1249
1268
|
this.eatRegExpUnicodeEscapeSequence(forceUFlag)) {
|
|
1250
1269
|
cp = this._lastIntValue;
|
|
1251
1270
|
}
|
|
@@ -1266,7 +1285,7 @@ class RegExpValidator {
|
|
|
1266
1285
|
}
|
|
1267
1286
|
eatCControlLetter() {
|
|
1268
1287
|
const start = this.index;
|
|
1269
|
-
if (this.eat(
|
|
1288
|
+
if (this.eat(LATIN_SMALL_LETTER_C)) {
|
|
1270
1289
|
if (this.eatControlLetter()) {
|
|
1271
1290
|
return true;
|
|
1272
1291
|
}
|
|
@@ -1275,7 +1294,7 @@ class RegExpValidator {
|
|
|
1275
1294
|
return false;
|
|
1276
1295
|
}
|
|
1277
1296
|
eatZero() {
|
|
1278
|
-
if (this.currentCodePoint ===
|
|
1297
|
+
if (this.currentCodePoint === DIGIT_ZERO &&
|
|
1279
1298
|
!isDecimalDigit(this.nextCodePoint)) {
|
|
1280
1299
|
this._lastIntValue = 0;
|
|
1281
1300
|
this.advance();
|
|
@@ -1284,24 +1303,24 @@ class RegExpValidator {
|
|
|
1284
1303
|
return false;
|
|
1285
1304
|
}
|
|
1286
1305
|
eatControlEscape() {
|
|
1287
|
-
if (this.eat(
|
|
1288
|
-
this._lastIntValue =
|
|
1306
|
+
if (this.eat(LATIN_SMALL_LETTER_F)) {
|
|
1307
|
+
this._lastIntValue = FORM_FEED;
|
|
1289
1308
|
return true;
|
|
1290
1309
|
}
|
|
1291
|
-
if (this.eat(
|
|
1292
|
-
this._lastIntValue =
|
|
1310
|
+
if (this.eat(LATIN_SMALL_LETTER_N)) {
|
|
1311
|
+
this._lastIntValue = LINE_FEED;
|
|
1293
1312
|
return true;
|
|
1294
1313
|
}
|
|
1295
|
-
if (this.eat(
|
|
1296
|
-
this._lastIntValue =
|
|
1314
|
+
if (this.eat(LATIN_SMALL_LETTER_R)) {
|
|
1315
|
+
this._lastIntValue = CARRIAGE_RETURN;
|
|
1297
1316
|
return true;
|
|
1298
1317
|
}
|
|
1299
|
-
if (this.eat(
|
|
1300
|
-
this._lastIntValue =
|
|
1318
|
+
if (this.eat(LATIN_SMALL_LETTER_T)) {
|
|
1319
|
+
this._lastIntValue = CHARACTER_TABULATION;
|
|
1301
1320
|
return true;
|
|
1302
1321
|
}
|
|
1303
|
-
if (this.eat(
|
|
1304
|
-
this._lastIntValue =
|
|
1322
|
+
if (this.eat(LATIN_SMALL_LETTER_V)) {
|
|
1323
|
+
this._lastIntValue = LINE_TABULATION;
|
|
1305
1324
|
return true;
|
|
1306
1325
|
}
|
|
1307
1326
|
return false;
|
|
@@ -1318,7 +1337,7 @@ class RegExpValidator {
|
|
|
1318
1337
|
eatRegExpUnicodeEscapeSequence(forceUFlag = false) {
|
|
1319
1338
|
const start = this.index;
|
|
1320
1339
|
const uFlag = forceUFlag || this._uFlag;
|
|
1321
|
-
if (this.eat(
|
|
1340
|
+
if (this.eat(LATIN_SMALL_LETTER_U)) {
|
|
1322
1341
|
if ((uFlag && this.eatRegExpUnicodeSurrogatePairEscape()) ||
|
|
1323
1342
|
this.eatFixedHexDigits(4) ||
|
|
1324
1343
|
(uFlag && this.eatRegExpUnicodeCodePointEscape())) {
|
|
@@ -1336,8 +1355,8 @@ class RegExpValidator {
|
|
|
1336
1355
|
if (this.eatFixedHexDigits(4)) {
|
|
1337
1356
|
const lead = this._lastIntValue;
|
|
1338
1357
|
if (isLeadSurrogate(lead) &&
|
|
1339
|
-
this.eat(
|
|
1340
|
-
this.eat(
|
|
1358
|
+
this.eat(REVERSE_SOLIDUS) &&
|
|
1359
|
+
this.eat(LATIN_SMALL_LETTER_U) &&
|
|
1341
1360
|
this.eatFixedHexDigits(4)) {
|
|
1342
1361
|
const trail = this._lastIntValue;
|
|
1343
1362
|
if (isTrailSurrogate(trail)) {
|
|
@@ -1351,9 +1370,9 @@ class RegExpValidator {
|
|
|
1351
1370
|
}
|
|
1352
1371
|
eatRegExpUnicodeCodePointEscape() {
|
|
1353
1372
|
const start = this.index;
|
|
1354
|
-
if (this.eat(
|
|
1373
|
+
if (this.eat(LEFT_CURLY_BRACKET) &&
|
|
1355
1374
|
this.eatHexDigits() &&
|
|
1356
|
-
this.eat(
|
|
1375
|
+
this.eat(RIGHT_CURLY_BRACKET) &&
|
|
1357
1376
|
isValidUnicode(this._lastIntValue)) {
|
|
1358
1377
|
return true;
|
|
1359
1378
|
}
|
|
@@ -1374,32 +1393,32 @@ class RegExpValidator {
|
|
|
1374
1393
|
return false;
|
|
1375
1394
|
}
|
|
1376
1395
|
if (this._uFlag) {
|
|
1377
|
-
return isSyntaxCharacter(cp) || cp ===
|
|
1396
|
+
return isSyntaxCharacter(cp) || cp === SOLIDUS;
|
|
1378
1397
|
}
|
|
1379
1398
|
if (this.strict) {
|
|
1380
1399
|
return !isIdContinue(cp);
|
|
1381
1400
|
}
|
|
1382
1401
|
if (this._nFlag) {
|
|
1383
|
-
return !(cp ===
|
|
1402
|
+
return !(cp === LATIN_SMALL_LETTER_C || cp === LATIN_SMALL_LETTER_K);
|
|
1384
1403
|
}
|
|
1385
|
-
return cp !==
|
|
1404
|
+
return cp !== LATIN_SMALL_LETTER_C;
|
|
1386
1405
|
}
|
|
1387
1406
|
eatDecimalEscape() {
|
|
1388
1407
|
this._lastIntValue = 0;
|
|
1389
1408
|
let cp = this.currentCodePoint;
|
|
1390
|
-
if (cp >=
|
|
1409
|
+
if (cp >= DIGIT_ONE && cp <= DIGIT_NINE) {
|
|
1391
1410
|
do {
|
|
1392
|
-
this._lastIntValue = 10 * this._lastIntValue + (cp -
|
|
1411
|
+
this._lastIntValue = 10 * this._lastIntValue + (cp - DIGIT_ZERO);
|
|
1393
1412
|
this.advance();
|
|
1394
|
-
} while ((cp = this.currentCodePoint) >=
|
|
1395
|
-
cp <=
|
|
1413
|
+
} while ((cp = this.currentCodePoint) >= DIGIT_ZERO &&
|
|
1414
|
+
cp <= DIGIT_NINE);
|
|
1396
1415
|
return true;
|
|
1397
1416
|
}
|
|
1398
1417
|
return false;
|
|
1399
1418
|
}
|
|
1400
1419
|
eatUnicodePropertyValueExpression() {
|
|
1401
1420
|
const start = this.index;
|
|
1402
|
-
if (this.eatUnicodePropertyName() && this.eat(
|
|
1421
|
+
if (this.eatUnicodePropertyName() && this.eat(EQUALS_SIGN)) {
|
|
1403
1422
|
this._lastKeyValue = this._lastStrValue;
|
|
1404
1423
|
if (this.eatUnicodePropertyValue()) {
|
|
1405
1424
|
this._lastValValue = this._lastStrValue;
|
|
@@ -1447,7 +1466,7 @@ class RegExpValidator {
|
|
|
1447
1466
|
}
|
|
1448
1467
|
eatHexEscapeSequence() {
|
|
1449
1468
|
const start = this.index;
|
|
1450
|
-
if (this.eat(
|
|
1469
|
+
if (this.eat(LATIN_SMALL_LETTER_X)) {
|
|
1451
1470
|
if (this.eatFixedHexDigits(2)) {
|
|
1452
1471
|
return true;
|
|
1453
1472
|
}
|
|
@@ -1501,7 +1520,7 @@ class RegExpValidator {
|
|
|
1501
1520
|
const cp = this.currentCodePoint;
|
|
1502
1521
|
if (isOctalDigit(cp)) {
|
|
1503
1522
|
this.advance();
|
|
1504
|
-
this._lastIntValue = cp -
|
|
1523
|
+
this._lastIntValue = cp - DIGIT_ZERO;
|
|
1505
1524
|
return true;
|
|
1506
1525
|
}
|
|
1507
1526
|
this._lastIntValue = 0;
|
|
@@ -1523,14 +1542,14 @@ class RegExpValidator {
|
|
|
1523
1542
|
}
|
|
1524
1543
|
}
|
|
1525
1544
|
|
|
1526
|
-
const
|
|
1527
|
-
const
|
|
1528
|
-
const
|
|
1545
|
+
const DUMMY_PATTERN = {};
|
|
1546
|
+
const DUMMY_FLAGS = {};
|
|
1547
|
+
const DUMMY_CAPTURING_GROUP = {};
|
|
1529
1548
|
class RegExpParserState {
|
|
1530
1549
|
constructor(options) {
|
|
1531
1550
|
var _a;
|
|
1532
|
-
this._node =
|
|
1533
|
-
this._flags =
|
|
1551
|
+
this._node = DUMMY_PATTERN;
|
|
1552
|
+
this._flags = DUMMY_FLAGS;
|
|
1534
1553
|
this._backreferences = [];
|
|
1535
1554
|
this._capturingGroups = [];
|
|
1536
1555
|
this.source = "";
|
|
@@ -1549,7 +1568,7 @@ class RegExpParserState {
|
|
|
1549
1568
|
}
|
|
1550
1569
|
return this._flags;
|
|
1551
1570
|
}
|
|
1552
|
-
|
|
1571
|
+
onRegExpFlags(start, end, { global, ignoreCase, multiline, unicode, sticky, dotAll, hasIndices, }) {
|
|
1553
1572
|
this._flags = {
|
|
1554
1573
|
type: "Flags",
|
|
1555
1574
|
parent: null,
|
|
@@ -1820,7 +1839,7 @@ class RegExpParserState {
|
|
|
1820
1839
|
end,
|
|
1821
1840
|
raw: this.source.slice(start, end),
|
|
1822
1841
|
ref,
|
|
1823
|
-
resolved:
|
|
1842
|
+
resolved: DUMMY_CAPTURING_GROUP,
|
|
1824
1843
|
};
|
|
1825
1844
|
parent.elements.push(node);
|
|
1826
1845
|
this._backreferences.push(node);
|
|
@@ -1866,7 +1885,7 @@ class RegExpParserState {
|
|
|
1866
1885
|
min.type !== "Character" ||
|
|
1867
1886
|
max.type !== "Character" ||
|
|
1868
1887
|
hyphen.type !== "Character" ||
|
|
1869
|
-
hyphen.value !==
|
|
1888
|
+
hyphen.value !== HYPHEN_MINUS) {
|
|
1870
1889
|
throw new Error("UnknownError");
|
|
1871
1890
|
}
|
|
1872
1891
|
const node = {
|