@@ -87,36 +87,36 @@ function addCommonElement(
87
87
}
88
88
89
89
class RegExpParserState {
90
- readonly strict : boolean
91
- readonly ecmaVersion : 5 | 2015 | 2016 | 2017 | 2018
90
+ public readonly strict : boolean
91
+ public readonly ecmaVersion : 5 | 2015 | 2016 | 2017 | 2018
92
92
private _node : AppendableNode = DummyPattern
93
93
private _flags : Flags = DummyFlags
94
94
private _disjunctionStartStack : number [ ] = [ ]
95
95
private _backreferences : Backreference [ ] = [ ]
96
96
private _capturingGroups : CapturingGroup [ ] = [ ]
97
97
98
- source : string = ""
98
+ public source = ""
99
99
100
- constructor ( options ?: RegExpParser . Options ) {
100
+ public constructor ( options ?: RegExpParser . Options ) {
101
101
this . strict = Boolean ( options && options . strict )
102
102
this . ecmaVersion = ( options && options . ecmaVersion ) || 2018
103
103
}
104
104
105
- get pattern ( ) : Pattern {
105
+ public get pattern ( ) : Pattern {
106
106
if ( this . _node . type !== "Pattern" ) {
107
107
throw new Error ( "UnknownError" )
108
108
}
109
109
return this . _node
110
110
}
111
111
112
- get flags ( ) : Flags {
112
+ public get flags ( ) : Flags {
113
113
if ( this . _flags . type !== "Flags" ) {
114
114
throw new Error ( "UnknownError" )
115
115
}
116
116
return this . _flags
117
117
}
118
118
119
- onFlags (
119
+ public onFlags (
120
120
start : number ,
121
121
end : number ,
122
122
global : boolean ,
@@ -141,7 +141,7 @@ class RegExpParserState {
141
141
}
142
142
}
143
143
144
- onPatternEnter ( start : number ) : void {
144
+ public onPatternEnter ( start : number ) : void {
145
145
this . _node = {
146
146
type : "Pattern" ,
147
147
parent : null ,
@@ -154,7 +154,7 @@ class RegExpParserState {
154
154
this . _capturingGroups . length = 0
155
155
}
156
156
157
- onPatternLeave ( start : number , end : number ) : void {
157
+ public onPatternLeave ( start : number , end : number ) : void {
158
158
this . _node . end = end
159
159
this . _node . raw = this . source . slice ( start , end )
160
160
@@ -169,15 +169,15 @@ class RegExpParserState {
169
169
}
170
170
}
171
171
172
- onDisjunctionEnter ( start : number ) : void {
172
+ public onDisjunctionEnter ( start : number ) : void {
173
173
this . _disjunctionStartStack . push ( start )
174
174
}
175
175
176
- onDisjunctionLeave ( start : number , end : number ) : void {
176
+ public onDisjunctionLeave ( start : number , end : number ) : void {
177
177
this . _disjunctionStartStack . pop ( )
178
178
}
179
179
180
- onAlternativeEnter ( start : number , index : number ) : void {
180
+ public onAlternativeEnter ( start : number , index : number ) : void {
181
181
if ( index === 0 ) {
182
182
return
183
183
}
@@ -212,7 +212,7 @@ class RegExpParserState {
212
212
}
213
213
}
214
214
215
- onAlternativeLeave ( start : number , end : number , index : number ) : void {
215
+ public onAlternativeLeave ( start : number , end : number , index : number ) : void {
216
216
if ( index === 0 ) {
217
217
return
218
218
}
@@ -221,7 +221,7 @@ class RegExpParserState {
221
221
this . _node = this . _node . parent as AppendableNode
222
222
}
223
223
224
- onGroupEnter ( start : number ) : void {
224
+ public onGroupEnter ( start : number ) : void {
225
225
const parentNode = this . _node
226
226
if ( parentNode . type === "CharacterClass" ) {
227
227
throw new Error ( "UnknownError" )
@@ -238,13 +238,13 @@ class RegExpParserState {
238
238
addAlternativeElement ( parentNode , this . _node )
239
239
}
240
240
241
- onGroupLeave ( start : number , end : number ) : void {
241
+ public onGroupLeave ( start : number , end : number ) : void {
242
242
this . _node . end = end
243
243
this . _node . raw = this . source . slice ( start , end )
244
244
this . _node = this . _node . parent as AppendableNode
245
245
}
246
246
247
- onCapturingGroupEnter ( start : number , name : string | null ) : void {
247
+ public onCapturingGroupEnter ( start : number , name : string | null ) : void {
248
248
const parentNode = this . _node
249
249
if ( parentNode . type === "CharacterClass" ) {
250
250
throw new Error ( "UnknownError" )
@@ -264,7 +264,7 @@ class RegExpParserState {
264
264
this . _capturingGroups . push ( this . _node )
265
265
}
266
266
267
- onCapturingGroupLeave (
267
+ public onCapturingGroupLeave (
268
268
start : number ,
269
269
end : number ,
270
270
name : string | null ,
@@ -274,7 +274,7 @@ class RegExpParserState {
274
274
this . _node = this . _node . parent as AppendableNode
275
275
}
276
276
277
- onQuantifier (
277
+ public onQuantifier (
278
278
start : number ,
279
279
end : number ,
280
280
min : number ,
@@ -307,7 +307,7 @@ class RegExpParserState {
307
307
prevNode . parent = node
308
308
}
309
309
310
- onLookaroundAssertionEnter (
310
+ public onLookaroundAssertionEnter (
311
311
start : number ,
312
312
kind : "lookahead" | "lookbehind" ,
313
313
negate : boolean ,
@@ -330,7 +330,7 @@ class RegExpParserState {
330
330
addAlternativeElement ( parentNode , this . _node )
331
331
}
332
332
333
- onLookaroundAssertionLeave (
333
+ public onLookaroundAssertionLeave (
334
334
start : number ,
335
335
end : number ,
336
336
kind : "lookahead" | "lookbehind" ,
@@ -341,7 +341,11 @@ class RegExpParserState {
341
341
this . _node = this . _node . parent as AppendableNode
342
342
}
343
343
344
- onEdgeAssertion ( start : number , end : number , kind : "start" | "end" ) : void {
344
+ public onEdgeAssertion (
345
+ start : number ,
346
+ end : number ,
347
+ kind : "start" | "end" ,
348
+ ) : void {
345
349
const parentNode = this . _node
346
350
if ( parentNode . type === "CharacterClass" ) {
347
351
throw new Error ( "UnknownError" )
@@ -357,7 +361,7 @@ class RegExpParserState {
357
361
} )
358
362
}
359
363
360
- onWordBoundaryAssertion (
364
+ public onWordBoundaryAssertion (
361
365
start : number ,
362
366
end : number ,
363
367
kind : "word" ,
@@ -379,7 +383,7 @@ class RegExpParserState {
379
383
} )
380
384
}
381
385
382
- onAnyCharacterSet ( start : number , end : number , kind : "any" ) : void {
386
+ public onAnyCharacterSet ( start : number , end : number , kind : "any" ) : void {
383
387
const parentNode = this . _node
384
388
if ( parentNode . type === "CharacterClass" ) {
385
389
throw new Error ( "UnknownError" )
@@ -395,7 +399,7 @@ class RegExpParserState {
395
399
} )
396
400
}
397
401
398
- onEscapeCharacterSet (
402
+ public onEscapeCharacterSet (
399
403
start : number ,
400
404
end : number ,
401
405
kind : "digit" | "space" | "word" ,
@@ -412,7 +416,7 @@ class RegExpParserState {
412
416
} )
413
417
}
414
418
415
- onUnicodePropertyCharacterSet (
419
+ public onUnicodePropertyCharacterSet (
416
420
start : number ,
417
421
end : number ,
418
422
kind : "property" ,
@@ -433,7 +437,7 @@ class RegExpParserState {
433
437
} )
434
438
}
435
439
436
- onCharacter ( start : number , end : number , value : number ) : void {
440
+ public onCharacter ( start : number , end : number , value : number ) : void {
437
441
addCommonElement ( this . _node , {
438
442
type : "Character" ,
439
443
parent : this . _node ,
@@ -444,7 +448,11 @@ class RegExpParserState {
444
448
} )
445
449
}
446
450
447
- onBackreference ( start : number , end : number , ref : number | string ) : void {
451
+ public onBackreference (
452
+ start : number ,
453
+ end : number ,
454
+ ref : number | string ,
455
+ ) : void {
448
456
const parentNode = this . _node
449
457
if ( parentNode . type === "CharacterClass" ) {
450
458
throw new Error ( "UnknownError" )
@@ -463,7 +471,7 @@ class RegExpParserState {
463
471
this . _backreferences . push ( node )
464
472
}
465
473
466
- onCharacterClassEnter ( start : number , negate : boolean ) : void {
474
+ public onCharacterClassEnter ( start : number , negate : boolean ) : void {
467
475
const parentNode = this . _node
468
476
if ( parentNode . type === "CharacterClass" ) {
469
477
throw new Error ( "UnknownError" )
@@ -481,13 +489,17 @@ class RegExpParserState {
481
489
addAlternativeElement ( parentNode , this . _node )
482
490
}
483
491
484
- onCharacterClassLeave ( start : number , end : number , negate : boolean ) : void {
492
+ public onCharacterClassLeave (
493
+ start : number ,
494
+ end : number ,
495
+ negate : boolean ,
496
+ ) : void {
485
497
this . _node . end = end
486
498
this . _node . raw = this . source . slice ( start , end )
487
499
this . _node = this . _node . parent as AppendableNode
488
500
}
489
501
490
- onCharacterClassRange (
502
+ public onCharacterClassRange (
491
503
start : number ,
492
504
end : number ,
493
505
min : number ,
@@ -548,7 +560,7 @@ export class RegExpParser {
548
560
* Initialize this parser.
549
561
* @param options The options of parser.
550
562
*/
551
- constructor ( options ?: RegExpParser . Options ) {
563
+ public constructor ( options ?: RegExpParser . Options ) {
552
564
this . _state = new RegExpParserState ( options )
553
565
this . _validator = new RegExpValidator ( this . _state )
554
566
}
@@ -560,9 +572,9 @@ export class RegExpParser {
560
572
* @param end The end index in the source code.
561
573
* @returns The AST of the given regular expression.
562
574
*/
563
- parseLiteral (
575
+ public parseLiteral (
564
576
source : string ,
565
- start : number = 0 ,
577
+ start = 0 ,
566
578
end : number = source . length ,
567
579
) : RegExpLiteral {
568
580
this . _state . source = source
@@ -590,9 +602,9 @@ export class RegExpParser {
590
602
* @param end The end index in the source code.
591
603
* @returns The AST of the given flags.
592
604
*/
593
- parseFlags (
605
+ public parseFlags (
594
606
source : string ,
595
- start : number = 0 ,
607
+ start = 0 ,
596
608
end : number = source . length ,
597
609
) : Flags {
598
610
this . _state . source = source
@@ -608,11 +620,11 @@ export class RegExpParser {
608
620
* @param uFlag The flag to set unicode mode.
609
621
* @returns The AST of the given pattern.
610
622
*/
611
- parsePattern (
623
+ public parsePattern (
612
624
source : string ,
613
- start : number = 0 ,
625
+ start = 0 ,
614
626
end : number = source . length ,
615
- uFlag : boolean = false ,
627
+ uFlag = false ,
616
628
) : Pattern {
617
629
this . _state . source = source
618
630
this . _validator . validatePattern ( source , start , end , uFlag )
0 commit comments