Skip to content

Commit 0d3084e

Browse files
committed
refactor: finish rebase
1 parent 7d10173 commit 0d3084e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/constructs/unicode.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type CharacterClass, encodeCharacterClass } from './character-class';
1+
import type { CharacterEscape } from '../types';
22

33
/**
44
* Unicode character escape.
@@ -12,7 +12,7 @@ import { type CharacterClass, encodeCharacterClass } from './character-class';
1212
* @param codePoint The code point of the character to escape.
1313
* @returns A character class representing the unicode escape.
1414
*/
15-
export function unicodeChar(codePoint: number): CharacterClass {
15+
export function unicodeChar(codePoint: number): CharacterEscape {
1616
if (!Number.isInteger(codePoint)) {
1717
throw new TypeError('Expected an integer code point but got: ' + codePoint);
1818
}
@@ -27,9 +27,9 @@ export function unicodeChar(codePoint: number): CharacterClass {
2727
: `\\u{${codePoint.toString(16)}}`; // 1-6 digit hex (requires unicode-aware mode)
2828

2929
return {
30-
type: 'characterClass',
31-
escape,
32-
encode: encodeCharacterClass,
30+
precedence: 'atom',
31+
pattern: escape,
32+
chars: [escape],
3333
};
3434
}
3535

@@ -43,10 +43,12 @@ export function unicodeChar(codePoint: number): CharacterClass {
4343
* @param value Unicode property value (optional).
4444
* @returns A character class representing the unicode property escape.
4545
*/
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+
4749
return {
48-
type: 'characterClass',
49-
escape: `\\p{${prop}${value ? `=${value}` : ''}}`,
50-
encode: encodeCharacterClass,
50+
precedence: 'atom',
51+
pattern: escape,
52+
chars: [escape],
5153
};
5254
}

0 commit comments

Comments
 (0)