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