1
- import { type CharacterClass , encodeCharacterClass } from './character-class ' ;
1
+ import type { CharacterEscape } from '../types ' ;
2
2
3
3
/**
4
4
* Unicode character escape.
@@ -12,7 +12,7 @@ import { type CharacterClass, encodeCharacterClass } from './character-class';
12
12
* @param codePoint The code point of the character to escape.
13
13
* @returns A character class representing the unicode escape.
14
14
*/
15
- export function unicodeChar ( codePoint : number ) : CharacterClass {
15
+ export function unicodeChar ( codePoint : number ) : CharacterEscape {
16
16
if ( ! Number . isInteger ( codePoint ) ) {
17
17
throw new TypeError ( 'Expected an integer code point but got: ' + codePoint ) ;
18
18
}
@@ -27,9 +27,9 @@ export function unicodeChar(codePoint: number): CharacterClass {
27
27
: `\\u{${ codePoint . toString ( 16 ) } }` ; // 1-6 digit hex (requires unicode-aware mode)
28
28
29
29
return {
30
- type : 'characterClass ' ,
31
- escape,
32
- encode : encodeCharacterClass ,
30
+ precedence : 'atom ' ,
31
+ pattern : escape ,
32
+ chars : [ escape ] ,
33
33
} ;
34
34
}
35
35
@@ -43,10 +43,12 @@ export function unicodeChar(codePoint: number): CharacterClass {
43
43
* @param value Unicode property value (optional).
44
44
* @returns A character class representing the unicode property escape.
45
45
*/
46
- export function unicodeProp ( prop : string , value ?: string ) : CharacterClass {
46
+ export function unicodeProp ( prop : string , value ?: string ) : CharacterEscape {
47
+ const escape = `\\p{${ prop } ${ value ? `=${ value } ` : '' } }` ;
48
+
47
49
return {
48
- type : 'characterClass ' ,
49
- escape : `\\p{ ${ prop } ${ value ? `= ${ value } ` : '' } }` ,
50
- encode : encodeCharacterClass ,
50
+ precedence : 'atom ' ,
51
+ pattern : escape ,
52
+ chars : [ escape ] ,
51
53
} ;
52
54
}
0 commit comments