[Pkg-javascript-commits] [node-acorn-jsx] 194/484: Add a script that generates the regular expressions for identifiers

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:26 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-acorn-jsx.

commit df9eda514ad804258ec84ee437b88493b41be299
Author: Mathias Bynens <mathias at qiwi.be>
Date:   Mon Jun 23 18:22:25 2014 +0200

    Add a script that generates the regular expressions for identifiers
---
 .gitignore                         |  3 ++-
 acorn.js                           |  5 ++--
 package.json                       |  4 ++-
 tools/generate-identifier-regex.js | 51 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore
index 59210b1..7a9d2aa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-/.tern-port
\ No newline at end of file
+/node_modules
+/.tern-port
diff --git a/acorn.js b/acorn.js
index 03ef0e5..ecbd18c 100644
--- a/acorn.js
+++ b/acorn.js
@@ -433,10 +433,11 @@
   // whitespace, identifier, and identifier-start categories. These
   // are only applied when a character is found to actually have a
   // code point above 128.
+  // Generated by `tools/generate-identifier-regex.js`.
 
   var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
-  var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u [...]
-  var nonASCIIidentifierChars = "\u0300-\u036f\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u0620-\u0649\u0672-\u06d3\u06e7-\u06e8\u06fb-\u06fc\u0730-\u074a\u0800-\u0814\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0840-\u0857\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962-\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09d7\u09df-\u09e0\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a8 [...]
+  var nonASCIIidentifierStartChars = "\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u [...]
+  var nonASCIIidentifierChars = "\u0300-\u036F\u0483-\u0487\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u0669\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u06F0-\u06F9\u0711\u0730-\u074A\u07A6-\u07B0\u07C0-\u07C9\u07EB-\u07F3\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08E4-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0966-\u096F\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09E6-\u09EF [...]
   var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
   var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
 
diff --git a/package.json b/package.json
index 8a30e97..b5d573c 100644
--- a/package.json
+++ b/package.json
@@ -13,5 +13,7 @@
     "licenses": [{"type": "MIT",
                   "url": "http://marijnhaverbeke.nl/acorn/LICENSE"}],
     "scripts": {"test": "node test/run.js"},
-    "bin": {"acorn": "./bin/acorn"}
+    "bin": {"acorn": "./bin/acorn"},
+    "devDependencies": {"regenerate": "~0.6.2",
+                        "unicode-7.0.0": "~0.1.5"}
 }
diff --git a/tools/generate-identifier-regex.js b/tools/generate-identifier-regex.js
new file mode 100644
index 0000000..88146e2
--- /dev/null
+++ b/tools/generate-identifier-regex.js
@@ -0,0 +1,51 @@
+// Based on https://gist.github.com/mathiasbynens/6334847 by @mathias
+
+var regenerate = require('regenerate');
+
+// Which Unicode version should be used?
+var version = '7.0.0'; // note: also update `package.json` when this changes
+
+// Shorthand function
+var get = function(what) {
+    return require('unicode-' + version + '/' + what + '/code-points');
+};
+
+// Unicode categories needed to construct the ES5 regex
+var Lu = get('categories/Lu');
+var Ll = get('categories/Ll');
+var Lt = get('categories/Lt');
+var Lm = get('categories/Lm');
+var Lo = get('categories/Lo');
+var Nl = get('categories/Nl');
+var Mn = get('categories/Mn');
+var Mc = get('categories/Mc');
+var Nd = get('categories/Nd');
+var Pc = get('categories/Pc');
+
+var generateES5Regex = function() { // ES 5.1
+    // http://mathiasbynens.be/notes/javascript-identifiers#valid-identifier-names
+    var identifierStart = regenerate('$', '_')
+        .add(Lu, Ll, Lt, Lm, Lo, Nl)
+        .removeRange(0x010000, 0x10FFFF) // remove astral symbols
+        .removeRange(0x0, 0x7F); // remove ASCII symbols (Acorn-specific)
+    var identifierPart = regenerate('\u200C', '\u200D', Mn, Mc, Nd, Pc)
+        .removeRange(0x010000, 0x10FFFF) // remove astral symbols
+        .remove(identifierStart) // (Acorn-specific)
+        .removeRange(0x0, 0x7F); // remove ASCII symbols (Acorn-specific)
+    return {
+        'NonAsciiIdentifierStart': identifierStart.toString(),
+        'NonAsciiIdentifierPart': identifierPart.toString()
+    };
+};
+
+var result = generateES5Regex();
+console.log(
+    '// ECMAScript 5.1/Unicode v%s `nonASCIIidentifierStart`:\n\n%s\n',
+    version,
+    result.NonAsciiIdentifierStart
+);
+console.log(
+    '// ECMAScript 5.1/Unicode v%s `nonASCIIidentifier`:\n\n%s',
+    version,
+    result.NonAsciiIdentifierPart
+);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git



More information about the Pkg-javascript-commits mailing list