source: imaps-frontend/node_modules/@babel/helper-validator-identifier/scripts/generate-identifier-regex.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.0 KB
Line 
1"use strict";
2
3// Always use the latest available version of Unicode!
4// https://tc39.github.io/ecma262/#sec-conformance
5const version = "15.1.0";
6
7const start = require(
8 "@unicode/unicode-" + version + "/Binary_Property/ID_Start/code-points.js"
9).filter(function (ch) {
10 return ch > 0x7f;
11});
12let last = -1;
13const 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
19function 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
26function pad(str, width) {
27 while (str.length < width) str = "0" + str;
28 return str;
29}
30
31function 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
37function 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
59const startData = generate(start);
60const contData = generate(cont);
61
62console.log("/* prettier-ignore */");
63console.log('let nonASCIIidentifierStartChars = "' + startData.nonASCII + '";');
64console.log("/* prettier-ignore */");
65console.log('let nonASCIIidentifierChars = "' + contData.nonASCII + '";');
66console.log("/* prettier-ignore */");
67console.log(
68 "const astralIdentifierStartCodes = " + JSON.stringify(startData.astral) + ";"
69);
70console.log("/* prettier-ignore */");
71console.log(
72 "const astralIdentifierCodes = " + JSON.stringify(contData.astral) + ";"
73);
Note: See TracBrowser for help on using the repository browser.