react / wstein / node_modules / browserify / node_modules / syntax-error / node_modules / acorn / bin / generate-identifier-regex.js
80551 views// Note: run `npm install unicode-7.0.0` first.12// Which Unicode version should be used?3var version = '7.0.0';45var start = require('unicode-' + version + '/properties/ID_Start/code-points')6.filter(function(ch) { return ch > 127; });7var cont = [0x200c, 0x200d].concat(require('unicode-' + version + '/properties/ID_Continue/code-points')8.filter(function(ch) { return ch > 127 && start.indexOf(ch) == -1; }));910function pad(str, width) {11while (str.length < width) str = "0" + str;12return str;13}1415function esc(code) {16var hex = code.toString(16);17if (hex.length <= 2) return "\\x" + pad(hex, 2);18else return "\\u" + pad(hex, 4);19}2021function generate(chars) {22var astral = [], re = "";23for (var i = 0, at = 0x10000; i < chars.length; i++) {24var from = chars[i], to = from;25while (i < chars.length - 1 && chars[i + 1] == to + 1) {26i++;27to++;28}29if (to <= 0xffff) {30if (from == to) re += esc(from);31else if (from + 1 == to) re += esc(from) + esc(to);32else re += esc(from) + "-" + esc(to);33} else {34astral.push(from - at, to - from);35at = to;36}37}38return {nonASCII: re, astral: astral};39}4041var startData = generate(start), contData = generate(cont);4243console.log(" var nonASCIIidentifierStartChars = \"" + startData.nonASCII + "\";");44console.log(" var nonASCIIidentifierChars = \"" + contData.nonASCII + "\";");45console.log(" var astralIdentifierStartCodes = " + JSON.stringify(startData.astral) + ";");46console.log(" var astralIdentifierCodes = " + JSON.stringify(contData.astral) + ";");474849