Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Update to Unicode v9 #45

Merged
merged 1 commit into from
Jun 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions bin/generate-identifier-regex.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
"use strict";

// Which Unicode version should be used?
var version = '8.0.0';
const version = "9.0.0";

var start = require('unicode-' + version + '/properties/ID_Start/code-points')
.filter(function(ch) { return ch > 127; });
var last = -1;
var cont = [0x200c, 0x200d].concat(require('unicode-' + version + '/properties/ID_Continue/code-points')
.filter(function(ch) { return ch > 127 && search(start, ch, last + 1) == -1; }));
const start = require("unicode-" + version + "/Binary_Property/ID_Start/code-points.js")
.filter(function(ch) { return ch > 0x7f; });
let last = -1;
const cont = [0x200c, 0x200d].concat(
require("unicode-" + version + "/Binary_Property/ID_Continue/code-points.js")
.filter(function(ch) {
return ch > 0x7f && search(start, ch, last + 1) == -1;
})
);

function search(arr, ch, starting) {
for (var i = starting; arr[i] <= ch && i < arr.length; last = i++)
for (let i = starting; arr[i] <= ch && i < arr.length; last = i++)
if (arr[i] === ch)
return i;
return -1;
Expand All @@ -20,15 +26,17 @@ function pad(str, width) {
}

function esc(code) {
var hex = code.toString(16);
const hex = code.toString(16);
if (hex.length <= 2) return "\\x" + pad(hex, 2);
else return "\\u" + pad(hex, 4);
}

function generate(chars) {
var astral = [], re = "";
for (var i = 0, at = 0x10000; i < chars.length; i++) {
var from = chars[i], to = from;
const astral = [];
let re = "";
for (let i = 0, at = 0x10000; i < chars.length; i++) {
const from = chars[i];
let to = from;
while (i < chars.length - 1 && chars[i + 1] == to + 1) {
i++;
to++;
Expand All @@ -45,9 +53,10 @@ function generate(chars) {
return {nonASCII: re, astral: astral};
}

var startData = generate(start), contData = generate(cont);
const startData = generate(start);
const contData = generate(cont);

console.log("let nonASCIIidentifierStartChars = \"" + startData.nonASCII + "\"");
console.log("let nonASCIIidentifierChars = \"" + contData.nonASCII + "\"");
console.log("const astralIdentifierStartCodes = " + JSON.stringify(startData.astral));
console.log("const astralIdentifierCodes = " + JSON.stringify(contData.astral));
console.log("let nonASCIIidentifierStartChars = \"" + startData.nonASCII + "\";");
console.log("let nonASCIIidentifierChars = \"" + contData.nonASCII + "\";");
console.log("const astralIdentifierStartCodes = " + JSON.stringify(startData.astral) + ";");
console.log("const astralIdentifierCodes = " + JSON.stringify(contData.astral) + ";");
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"babel-preset-stage-0": "^6.5.0",
"kcheck": "^2.0.1",
"lodash": "^4.6.1",
"unicode-7.0.0": "~0.1.5"
"unicode-9.0.0": "~0.7.0"
},
"bin": {
"babylon": "./bin/babylon.js"
Expand Down
Loading