[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | // Always use the latest available version of Unicode!
|
---|
| 4 | // https://tc39.github.io/ecma262/#sec-conformance
|
---|
| 5 | const version = "14.0.0";
|
---|
| 6 |
|
---|
| 7 | const start = require("@unicode/unicode-" +
|
---|
| 8 | version +
|
---|
| 9 | "/Binary_Property/ID_Start/code-points.js").filter(function (ch) {
|
---|
| 10 | return ch > 0x7f;
|
---|
| 11 | });
|
---|
| 12 | let last = -1;
|
---|
| 13 | const cont = [0x200c, 0x200d].concat(
|
---|
| 14 | require("@unicode/unicode-" +
|
---|
| 15 | version +
|
---|
| 16 | "/Binary_Property/ID_Continue/code-points.js").filter(function (ch) {
|
---|
| 17 | return ch > 0x7f && search(start, ch, last + 1) == -1;
|
---|
| 18 | })
|
---|
| 19 | );
|
---|
| 20 |
|
---|
| 21 | function search(arr, ch, starting) {
|
---|
| 22 | for (let i = starting; arr[i] <= ch && i < arr.length; last = i++) {
|
---|
| 23 | if (arr[i] === ch) return i;
|
---|
| 24 | }
|
---|
| 25 | return -1;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | function pad(str, width) {
|
---|
| 29 | while (str.length < width) str = "0" + str;
|
---|
| 30 | return str;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | function esc(code) {
|
---|
| 34 | const hex = code.toString(16);
|
---|
| 35 | if (hex.length <= 2) return "\\x" + pad(hex, 2);
|
---|
| 36 | else return "\\u" + pad(hex, 4);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | function generate(chars) {
|
---|
| 40 | const astral = [];
|
---|
| 41 | let re = "";
|
---|
| 42 | for (let i = 0, at = 0x10000; i < chars.length; i++) {
|
---|
| 43 | const from = chars[i];
|
---|
| 44 | let to = from;
|
---|
| 45 | while (i < chars.length - 1 && chars[i + 1] == to + 1) {
|
---|
| 46 | i++;
|
---|
| 47 | to++;
|
---|
| 48 | }
|
---|
| 49 | if (to <= 0xffff) {
|
---|
| 50 | if (from == to) re += esc(from);
|
---|
| 51 | else if (from + 1 == to) re += esc(from) + esc(to);
|
---|
| 52 | else re += esc(from) + "-" + esc(to);
|
---|
| 53 | } else {
|
---|
| 54 | astral.push(from - at, to - from);
|
---|
| 55 | at = to;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | return { nonASCII: re, astral: astral };
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | const startData = generate(start);
|
---|
| 62 | const contData = generate(cont);
|
---|
| 63 |
|
---|
| 64 | console.log("/* prettier-ignore */");
|
---|
| 65 | console.log('let nonASCIIidentifierStartChars = "' + startData.nonASCII + '";');
|
---|
| 66 | console.log("/* prettier-ignore */");
|
---|
| 67 | console.log('let nonASCIIidentifierChars = "' + contData.nonASCII + '";');
|
---|
| 68 | console.log("/* prettier-ignore */");
|
---|
| 69 | console.log(
|
---|
| 70 | "const astralIdentifierStartCodes = " + JSON.stringify(startData.astral) + ";"
|
---|
| 71 | );
|
---|
| 72 | console.log("/* prettier-ignore */");
|
---|
| 73 | console.log(
|
---|
| 74 | "const astralIdentifierCodes = " + JSON.stringify(contData.astral) + ";"
|
---|
| 75 | );
|
---|