@@ -16,7 +16,6 @@ import type {
1616 ClassSubtraction ,
1717 UnicodeSetsCharacterClassElement ,
1818 ClassSetOperand ,
19- UnicodePropertyCharacterSet ,
2019 UnicodeSetsCharacterClass ,
2120 ExpressionCharacterClass ,
2221 StringAlternative ,
@@ -413,45 +412,31 @@ class RegExpParserState {
413412 strings : boolean ,
414413 ) : void {
415414 const parent = this . _node
416- if (
417- ( parent . type !== "Alternative" &&
418- parent . type !== "CharacterClass" ) ||
419- ( strings && ( negate || value ) )
420- ) {
415+ if ( parent . type !== "Alternative" && parent . type !== "CharacterClass" ) {
421416 throw new Error ( "UnknownError" )
422417 }
423418
424419 const base = {
425420 type : "CharacterSet" ,
426- parent,
427421 start,
428422 end,
429423 raw : this . source . slice ( start , end ) ,
430424 kind,
431- strings,
432425 key,
433426 } as const
434- const node : UnicodePropertyCharacterSet = strings
435- ? {
436- ...base ,
437- value : null ,
438- negate : false ,
439- strings : true ,
440- }
441- : {
442- ...base ,
443- value,
444- negate,
445- strings : false ,
446- }
447427
448- if ( node . strings ) {
449- if ( parent . type === "CharacterClass" && ! parent . unicodeSets ) {
428+ if ( strings ) {
429+ if (
430+ ( parent . type === "CharacterClass" && ! parent . unicodeSets ) ||
431+ negate ||
432+ value !== null
433+ ) {
450434 throw new Error ( "UnknownError" )
451435 }
452- parent . elements . push ( node )
436+
437+ parent . elements . push ( { ...base , parent, strings, value, negate } )
453438 } else {
454- parent . elements . push ( node )
439+ parent . elements . push ( { ... base , parent , strings , value , negate } )
455440 }
456441 }
457442
0 commit comments