-
Notifications
You must be signed in to change notification settings - Fork 886
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// This file was generated by "bin/generate-unicode-script-values.js". Do not modify manually! | ||
export default "Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sunu Sunuwar Todhri Todr Tulu_Tigalari Tutg Unknown Zzzz" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"use strict" | ||
|
||
const fs = require("fs") | ||
const path = require("path") | ||
|
||
import("../acorn/src/unicode-property-data.js") | ||
.then(m => { | ||
return m.default[13].nonBinary.Script | ||
}) | ||
.then(async(reScriptValuesAddedInES) => { | ||
const scriptValues = new Set() | ||
for await (const value of getLatestUnicodeScriptValues()) { | ||
scriptValues.add(value) | ||
} | ||
const scriptValuesAddedInUnicode = "export default " + | ||
JSON.stringify( | ||
[...scriptValues] | ||
// The unicode script values now follow the Unicode spec as of ES2023, | ||
// but prior to ES2022 they were listed in the ES2022 spec. | ||
// The generated file lists all the unicode script values except those listed before ES2022. | ||
.filter(value => !reScriptValuesAddedInES.test(value)) | ||
.sort() | ||
.join(" ") | ||
) | ||
|
||
writeGeneratedFile("scriptValuesAddedInUnicode", scriptValuesAddedInUnicode) | ||
|
||
console.log("Done. The generated files must be committed.") | ||
}) | ||
|
||
function writeGeneratedFile(filename, content) { | ||
const comment = "// This file was generated by \"bin/" + path.basename(__filename) + "\". Do not modify manually!" | ||
fs.writeFileSync(path.resolve("./acorn/src/generated", filename + ".js"), comment + "\n" + content + "\n", "utf8") | ||
} | ||
|
||
/** | ||
* Gets the all unicode script values from the latest PropertyValueAliases. | ||
*/ | ||
async function * getLatestUnicodeScriptValues() { | ||
const response = await fetch("https://unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt") | ||
const lines = (await response.text()).split("\n") | ||
for (const line of lines) { | ||
if (!line || line.startsWith("#")) { | ||
continue | ||
} | ||
const [propertyAlias, alias, canonical, ...remaining] = line | ||
.split("#")[0] // strip comments | ||
.split(";") // split by semicolon | ||
.map((x) => x.trim()) // trim | ||
|
||
if (propertyAlias !== "sc") { | ||
continue | ||
} | ||
|
||
yield canonical | ||
yield alias | ||
yield * remaining | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters