• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"use strict";
2
3// Always use the latest available version of Unicode!
4// https://tc39.github.io/ecma262/#sec-conformance
5const version = "13.0.0";
6
7const start = require("unicode-" +
8  version +
9  "/Binary_Property/ID_Start/code-points.js").filter(function(ch) {
10  return ch > 0x7f;
11});
12let last = -1;
13const cont = [0x200c, 0x200d].concat(
14  require("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
21function 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
28function pad(str, width) {
29  while (str.length < width) str = "0" + str;
30  return str;
31}
32
33function 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
39function 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
61const startData = generate(start);
62const contData = generate(cont);
63
64console.log("/* prettier-ignore */");
65console.log('let nonASCIIidentifierStartChars = "' + startData.nonASCII + '";');
66console.log("/* prettier-ignore */");
67console.log('let nonASCIIidentifierChars = "' + contData.nonASCII + '";');
68console.log("/* prettier-ignore */");
69console.log(
70  "const astralIdentifierStartCodes = " + JSON.stringify(startData.astral) + ";"
71);
72console.log("/* prettier-ignore */");
73console.log(
74  "const astralIdentifierCodes = " + JSON.stringify(contData.astral) + ";"
75);
76