Skip to content

Commit 9f383cd

Browse files
authored
chore: refactor for unicode property of strings (#140)
1 parent 8c2965e commit 9f383cd

File tree

5 files changed

+46
-17
lines changed

5 files changed

+46
-17
lines changed

scripts/update-unicode-properties.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const DATA_SOURCES = [
5454
binProperties: "#table-binary-unicode-properties",
5555
gcValues: getLatestUnicodeGeneralCategoryValues,
5656
scValues: getLatestUnicodeScriptValues,
57+
binPropertiesOfStrings: "#table-binary-unicode-properties-of-strings",
5758
},
5859
]
5960
const FILE_PATH = "src/unicode/properties.ts"
@@ -63,6 +64,7 @@ type Datum = {
6364
binProperties: string[]
6465
gcValues: string[]
6566
scValues: string[]
67+
binPropertiesOfStrings: string[]
6668
}
6769

6870
// Main
@@ -72,12 +74,14 @@ type Datum = {
7274
binProperties: new Set<string>(),
7375
gcValues: new Set<string>(),
7476
scValues: new Set<string>(),
77+
binPropertiesOfStrings: new Set<string>(),
7578
}
7679

7780
for (const {
7881
binProperties,
7982
gcValues,
8083
scValues,
84+
binPropertiesOfStrings,
8185
url,
8286
version,
8387
} of DATA_SOURCES) {
@@ -86,6 +90,7 @@ type Datum = {
8690
binProperties: [],
8791
gcValues: [],
8892
scValues: [],
93+
binPropertiesOfStrings: [],
8994
}
9095
data[version] = datum
9196

@@ -120,6 +125,13 @@ type Datum = {
120125
scValues,
121126
existing.scValues,
122127
)
128+
if (binPropertiesOfStrings) {
129+
datum.binPropertiesOfStrings = await collectValues(
130+
window,
131+
binPropertiesOfStrings,
132+
existing.binPropertiesOfStrings,
133+
)
134+
}
123135

124136
logger.log("Done")
125137
}
@@ -140,6 +152,9 @@ const scValueSets = new DataSet(${Object.values(data)
140152
const binPropertySets = new DataSet(${Object.values(data)
141153
.map((d) => makeDataCode(d.binProperties))
142154
.join(",")})
155+
const binPropertyOfStringsSets = new DataSet(${Object.values(data)
156+
.map((d) => makeDataCode(d.binPropertiesOfStrings))
157+
.join(",")})
143158
144159
export function isValidUnicodeProperty(version: number, name: string, value: string): boolean {
145160
if (gcNameSet.has(name)) {
@@ -169,6 +184,19 @@ export function isValidLoneUnicodeProperty(version: number, value: string): bool
169184
.filter(Boolean)
170185
.join(" || ")}
171186
}
187+
188+
export function isValidLoneUnicodePropertyOfString(version: number, value: string): boolean {
189+
return ${Object.entries(data)
190+
.map(([version, { binPropertiesOfStrings }]) =>
191+
makeVerificationCode(
192+
version,
193+
"binPropertyOfStringsSets",
194+
binPropertiesOfStrings,
195+
),
196+
)
197+
.filter(Boolean)
198+
.join(" || ")}
199+
}
172200
`
173201

174202
logger.log("Formatting code...")

src/unicode/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export { isIdContinue, isIdStart } from "./ids"
22
export {
33
isValidLoneUnicodeProperty,
44
isValidUnicodeProperty,
5+
isValidLoneUnicodePropertyOfString,
56
} from "./properties"
67

78
export const NULL = 0x00

src/unicode/properties-of-strings.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/unicode/properties.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ const binPropertySets = new DataSet(
119119
"",
120120
"",
121121
)
122+
const binPropertyOfStringsSets = new DataSet(
123+
"",
124+
"",
125+
"",
126+
"",
127+
"",
128+
"",
129+
"Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji RGI_Emoji_Flag_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence",
130+
)
122131

123132
export function isValidUnicodeProperty(
124133
version: number,
@@ -151,3 +160,10 @@ export function isValidLoneUnicodeProperty(
151160
(version >= 2021 && binPropertySets.es2021.has(value))
152161
)
153162
}
163+
164+
export function isValidLoneUnicodePropertyOfString(
165+
version: number,
166+
value: string,
167+
): boolean {
168+
return version >= 2024 && binPropertyOfStringsSets.es2024.has(value)
169+
}

src/validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import {
7373
isTrailSurrogate,
7474
isValidLoneUnicodeProperty,
7575
isValidUnicodeProperty,
76+
isValidLoneUnicodePropertyOfString,
7677
isValidUnicode,
7778
AMPERSAND,
7879
NUMBER_SIGN,
@@ -83,7 +84,6 @@ import {
8384
TILDE,
8485
LATIN_SMALL_LETTER_Q,
8586
} from "./unicode"
86-
import { isValidLoneUnicodePropertyOfString } from "./unicode/properties-of-strings"
8787

8888
// ^ $ \ . * + ? ( ) [ ] { } |
8989
const SYNTAX_CHARACTER = new Set([

0 commit comments

Comments
 (0)