|
| 1 | +"use strict" |
| 2 | + |
| 3 | +const fs = require("fs") |
| 4 | +const path = require("path") |
| 5 | + |
| 6 | +import("../acorn/src/unicode-property-data.js") |
| 7 | + .then(m => { |
| 8 | + return m.default[13].nonBinary.Script |
| 9 | + }) |
| 10 | + .then(async(reScriptValuesAddedInES) => { |
| 11 | + const scriptValues = new Set() |
| 12 | + for await (const value of getLatestUnicodeScriptValues()) { |
| 13 | + scriptValues.add(value) |
| 14 | + } |
| 15 | + const scriptValuesAddedInUnicode = "export default " + |
| 16 | + JSON.stringify( |
| 17 | + [...scriptValues] |
| 18 | + // The unicode script values now follow the Unicode spec as of ES2023, |
| 19 | + // but prior to ES2022 they were listed in the ES2022 spec. |
| 20 | + // The generated file lists all the unicode script values except those listed before ES2022. |
| 21 | + .filter(value => !reScriptValuesAddedInES.test(value)) |
| 22 | + .sort() |
| 23 | + .join(" ") |
| 24 | + ) |
| 25 | + |
| 26 | + writeGeneratedFile("scriptValuesAddedInUnicode", scriptValuesAddedInUnicode) |
| 27 | + |
| 28 | + console.log("Done. The generated files must be committed.") |
| 29 | + }) |
| 30 | + |
| 31 | +function writeGeneratedFile(filename, content) { |
| 32 | + const comment = "// This file was generated by \"bin/" + path.basename(__filename) + "\". Do not modify manually!" |
| 33 | + fs.writeFileSync(path.resolve("./acorn/src/generated", filename + ".js"), comment + "\n" + content + "\n", "utf8") |
| 34 | +} |
| 35 | + |
| 36 | +/** |
| 37 | + * Gets the all unicode script values from the latest PropertyValueAliases. |
| 38 | + */ |
| 39 | +async function * getLatestUnicodeScriptValues() { |
| 40 | + const response = await fetch("https://unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt") |
| 41 | + const lines = (await response.text()).split("\n") |
| 42 | + for (const line of lines) { |
| 43 | + if (!line || line.startsWith("#")) { |
| 44 | + continue |
| 45 | + } |
| 46 | + const [propertyAlias, alias, canonical, ...remaining] = line |
| 47 | + .split("#")[0] // strip comments |
| 48 | + .split(";") // split by semicolon |
| 49 | + .map((x) => x.trim()) // trim |
| 50 | + |
| 51 | + if (propertyAlias !== "sc") { |
| 52 | + continue |
| 53 | + } |
| 54 | + |
| 55 | + yield canonical |
| 56 | + yield alias |
| 57 | + yield * remaining |
| 58 | + } |
| 59 | +} |
0 commit comments