summaryrefslogtreecommitdiffstats
path: root/node_modules/regexpu-core
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/regexpu-core')
-rw-r--r--node_modules/regexpu-core/LICENSE-MIT.txt20
-rw-r--r--node_modules/regexpu-core/README.md62
-rw-r--r--node_modules/regexpu-core/data/character-class-escape-sets.js101
-rw-r--r--node_modules/regexpu-core/data/iu-mappings.json296
-rw-r--r--node_modules/regexpu-core/package.json88
-rw-r--r--node_modules/regexpu-core/rewrite-pattern.js193
6 files changed, 760 insertions, 0 deletions
diff --git a/node_modules/regexpu-core/LICENSE-MIT.txt b/node_modules/regexpu-core/LICENSE-MIT.txt
new file mode 100644
index 0000000..a41e0a7
--- /dev/null
+++ b/node_modules/regexpu-core/LICENSE-MIT.txt
@@ -0,0 +1,20 @@
+Copyright Mathias Bynens <https://mathiasbynens.be/>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/regexpu-core/README.md b/node_modules/regexpu-core/README.md
new file mode 100644
index 0000000..1f80cd8
--- /dev/null
+++ b/node_modules/regexpu-core/README.md
@@ -0,0 +1,62 @@
+# regexpu-core [![Build status](https://travis-ci.org/mathiasbynens/regexpu-core.svg?branch=master)](https://travis-ci.org/mathiasbynens/regexpu-core) [![Code coverage status](http://img.shields.io/coveralls/mathiasbynens/regexpu-core/master.svg)](https://coveralls.io/r/mathiasbynens/regexpu-core) [![Dependency status](https://gemnasium.com/mathiasbynens/regexpu-core.svg)](https://gemnasium.com/mathiasbynens/regexpu-core)
+
+_regexpu_ is a source code transpiler that enables the use of ES6 Unicode regular expressions in JavaScript-of-today (ES5).
+
+_regexpu-core_ contains _regexpu_’s core functionality, i.e. `rewritePattern(pattern, flag)`, which enables rewriting regular expressions that make use of [the ES6 `u` flag](https://mathiasbynens.be/notes/es6-unicode-regex) into equivalent ES5-compatible regular expression patterns.
+
+## Installation
+
+To use _regexpu-core_ programmatically, install it as a dependency via [npm](https://www.npmjs.com/):
+
+```bash
+npm install regexpu-core --save-dev
+```
+
+Then, `require` it:
+
+```js
+const rewritePattern = require('regexpu-core');
+```
+
+## API
+
+This module exports a single function named `rewritePattern`.
+
+### `rewritePattern(pattern, flags)`
+
+This function takes a string that represents a regular expression pattern as well as a string representing its flags, and returns an ES5-compatible version of the pattern.
+
+```js
+rewritePattern('foo.bar', 'u');
+// → 'foo(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\uDC00-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF])bar'
+
+rewritePattern('[\\u{1D306}-\\u{1D308}a-z]', 'u');
+// → '(?:[a-z]|\\uD834[\\uDF06-\\uDF08])'
+
+rewritePattern('[\\u{1D306}-\\u{1D308}a-z]', 'ui');
+// → '(?:[a-z\\u017F\\u212A]|\\uD834[\\uDF06-\\uDF08])'
+```
+
+_regexpu-core_ can rewrite non-ES6 regular expressions too, which is useful to demonstrate how their behavior changes once the `u` and `i` flags are added:
+
+```js
+// In ES5, the dot operator only matches BMP symbols:
+rewritePattern('foo.bar');
+// → 'foo(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uFFFF])bar'
+
+// But with the ES6 `u` flag, it matches astral symbols too:
+rewritePattern('foo.bar', 'u');
+// → 'foo(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\uDC00-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF])bar'
+```
+
+`rewritePattern` uses [regjsgen](https://github.com/d10/regjsgen), [regjsparser](https://github.com/jviereck/regjsparser), and [regenerate](https://github.com/mathiasbynens/regenerate) as internal dependencies.
+
+## Author
+
+| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
+|---|
+| [Mathias Bynens](https://mathiasbynens.be/) |
+
+## License
+
+_regexpu-core_ is available under the [MIT](https://mths.be/mit) license.
diff --git a/node_modules/regexpu-core/data/character-class-escape-sets.js b/node_modules/regexpu-core/data/character-class-escape-sets.js
new file mode 100644
index 0000000..fcc482e
--- /dev/null
+++ b/node_modules/regexpu-core/data/character-class-escape-sets.js
@@ -0,0 +1,101 @@
+// Generated by `/scripts/character-class-escape-sets.js`. Do not edit.
+var regenerate = require('regenerate');
+
+exports.REGULAR = {
+ 'd': regenerate()
+ .addRange(0x30, 0x39),
+ 'D': regenerate()
+ .addRange(0x0, 0x2F)
+ .addRange(0x3A, 0xFFFF),
+ 's': regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
+ .addRange(0x9, 0xD)
+ .addRange(0x2000, 0x200A)
+ .addRange(0x2028, 0x2029),
+ 'S': regenerate()
+ .addRange(0x0, 0x8)
+ .addRange(0xE, 0x1F)
+ .addRange(0x21, 0x9F)
+ .addRange(0xA1, 0x167F)
+ .addRange(0x1681, 0x1FFF)
+ .addRange(0x200B, 0x2027)
+ .addRange(0x202A, 0x202E)
+ .addRange(0x2030, 0x205E)
+ .addRange(0x2060, 0x2FFF)
+ .addRange(0x3001, 0xFEFE)
+ .addRange(0xFF00, 0xFFFF),
+ 'w': regenerate(0x5F)
+ .addRange(0x30, 0x39)
+ .addRange(0x41, 0x5A)
+ .addRange(0x61, 0x7A),
+ 'W': regenerate(0x60)
+ .addRange(0x0, 0x2F)
+ .addRange(0x3A, 0x40)
+ .addRange(0x5B, 0x5E)
+ .addRange(0x7B, 0xFFFF)
+};
+
+exports.UNICODE = {
+ 'd': regenerate()
+ .addRange(0x30, 0x39),
+ 'D': regenerate()
+ .addRange(0x0, 0x2F)
+ .addRange(0x3A, 0x10FFFF),
+ 's': regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
+ .addRange(0x9, 0xD)
+ .addRange(0x2000, 0x200A)
+ .addRange(0x2028, 0x2029),
+ 'S': regenerate()
+ .addRange(0x0, 0x8)
+ .addRange(0xE, 0x1F)
+ .addRange(0x21, 0x9F)
+ .addRange(0xA1, 0x167F)
+ .addRange(0x1681, 0x1FFF)
+ .addRange(0x200B, 0x2027)
+ .addRange(0x202A, 0x202E)
+ .addRange(0x2030, 0x205E)
+ .addRange(0x2060, 0x2FFF)
+ .addRange(0x3001, 0xFEFE)
+ .addRange(0xFF00, 0x10FFFF),
+ 'w': regenerate(0x5F)
+ .addRange(0x30, 0x39)
+ .addRange(0x41, 0x5A)
+ .addRange(0x61, 0x7A),
+ 'W': regenerate(0x60)
+ .addRange(0x0, 0x2F)
+ .addRange(0x3A, 0x40)
+ .addRange(0x5B, 0x5E)
+ .addRange(0x7B, 0x10FFFF)
+};
+
+exports.UNICODE_IGNORE_CASE = {
+ 'd': regenerate()
+ .addRange(0x30, 0x39),
+ 'D': regenerate()
+ .addRange(0x0, 0x2F)
+ .addRange(0x3A, 0x10FFFF),
+ 's': regenerate(0x20, 0xA0, 0x1680, 0x202F, 0x205F, 0x3000, 0xFEFF)
+ .addRange(0x9, 0xD)
+ .addRange(0x2000, 0x200A)
+ .addRange(0x2028, 0x2029),
+ 'S': regenerate()
+ .addRange(0x0, 0x8)
+ .addRange(0xE, 0x1F)
+ .addRange(0x21, 0x9F)
+ .addRange(0xA1, 0x167F)
+ .addRange(0x1681, 0x1FFF)
+ .addRange(0x200B, 0x2027)
+ .addRange(0x202A, 0x202E)
+ .addRange(0x2030, 0x205E)
+ .addRange(0x2060, 0x2FFF)
+ .addRange(0x3001, 0xFEFE)
+ .addRange(0xFF00, 0x10FFFF),
+ 'w': regenerate(0x5F, 0x17F, 0x212A)
+ .addRange(0x30, 0x39)
+ .addRange(0x41, 0x5A)
+ .addRange(0x61, 0x7A),
+ 'W': regenerate(0x4B, 0x53, 0x60)
+ .addRange(0x0, 0x2F)
+ .addRange(0x3A, 0x40)
+ .addRange(0x5B, 0x5E)
+ .addRange(0x7B, 0x10FFFF)
+};
diff --git a/node_modules/regexpu-core/data/iu-mappings.json b/node_modules/regexpu-core/data/iu-mappings.json
new file mode 100644
index 0000000..dbf36a2
--- /dev/null
+++ b/node_modules/regexpu-core/data/iu-mappings.json
@@ -0,0 +1,296 @@
+{
+ "75": 8490,
+ "83": 383,
+ "107": 8490,
+ "115": 383,
+ "181": 924,
+ "197": 8491,
+ "383": 83,
+ "452": 453,
+ "453": 452,
+ "455": 456,
+ "456": 455,
+ "458": 459,
+ "459": 458,
+ "497": 498,
+ "498": 497,
+ "837": 8126,
+ "914": 976,
+ "917": 1013,
+ "920": 1012,
+ "921": 8126,
+ "922": 1008,
+ "924": 181,
+ "928": 982,
+ "929": 1009,
+ "931": 962,
+ "934": 981,
+ "937": 8486,
+ "962": 931,
+ "976": 914,
+ "977": 1012,
+ "981": 934,
+ "982": 928,
+ "1008": 922,
+ "1009": 929,
+ "1012": [
+ 920,
+ 977
+ ],
+ "1013": 917,
+ "7776": 7835,
+ "7835": 7776,
+ "8126": [
+ 837,
+ 921
+ ],
+ "8486": 937,
+ "8490": 75,
+ "8491": 197,
+ "66560": 66600,
+ "66561": 66601,
+ "66562": 66602,
+ "66563": 66603,
+ "66564": 66604,
+ "66565": 66605,
+ "66566": 66606,
+ "66567": 66607,
+ "66568": 66608,
+ "66569": 66609,
+ "66570": 66610,
+ "66571": 66611,
+ "66572": 66612,
+ "66573": 66613,
+ "66574": 66614,
+ "66575": 66615,
+ "66576": 66616,
+ "66577": 66617,
+ "66578": 66618,
+ "66579": 66619,
+ "66580": 66620,
+ "66581": 66621,
+ "66582": 66622,
+ "66583": 66623,
+ "66584": 66624,
+ "66585": 66625,
+ "66586": 66626,
+ "66587": 66627,
+ "66588": 66628,
+ "66589": 66629,
+ "66590": 66630,
+ "66591": 66631,
+ "66592": 66632,
+ "66593": 66633,
+ "66594": 66634,
+ "66595": 66635,
+ "66596": 66636,
+ "66597": 66637,
+ "66598": 66638,
+ "66599": 66639,
+ "66600": 66560,
+ "66601": 66561,
+ "66602": 66562,
+ "66603": 66563,
+ "66604": 66564,
+ "66605": 66565,
+ "66606": 66566,
+ "66607": 66567,
+ "66608": 66568,
+ "66609": 66569,
+ "66610": 66570,
+ "66611": 66571,
+ "66612": 66572,
+ "66613": 66573,
+ "66614": 66574,
+ "66615": 66575,
+ "66616": 66576,
+ "66617": 66577,
+ "66618": 66578,
+ "66619": 66579,
+ "66620": 66580,
+ "66621": 66581,
+ "66622": 66582,
+ "66623": 66583,
+ "66624": 66584,
+ "66625": 66585,
+ "66626": 66586,
+ "66627": 66587,
+ "66628": 66588,
+ "66629": 66589,
+ "66630": 66590,
+ "66631": 66591,
+ "66632": 66592,
+ "66633": 66593,
+ "66634": 66594,
+ "66635": 66595,
+ "66636": 66596,
+ "66637": 66597,
+ "66638": 66598,
+ "66639": 66599,
+ "68736": 68800,
+ "68737": 68801,
+ "68738": 68802,
+ "68739": 68803,
+ "68740": 68804,
+ "68741": 68805,
+ "68742": 68806,
+ "68743": 68807,
+ "68744": 68808,
+ "68745": 68809,
+ "68746": 68810,
+ "68747": 68811,
+ "68748": 68812,
+ "68749": 68813,
+ "68750": 68814,
+ "68751": 68815,
+ "68752": 68816,
+ "68753": 68817,
+ "68754": 68818,
+ "68755": 68819,
+ "68756": 68820,
+ "68757": 68821,
+ "68758": 68822,
+ "68759": 68823,
+ "68760": 68824,
+ "68761": 68825,
+ "68762": 68826,
+ "68763": 68827,
+ "68764": 68828,
+ "68765": 68829,
+ "68766": 68830,
+ "68767": 68831,
+ "68768": 68832,
+ "68769": 68833,
+ "68770": 68834,
+ "68771": 68835,
+ "68772": 68836,
+ "68773": 68837,
+ "68774": 68838,
+ "68775": 68839,
+ "68776": 68840,
+ "68777": 68841,
+ "68778": 68842,
+ "68779": 68843,
+ "68780": 68844,
+ "68781": 68845,
+ "68782": 68846,
+ "68783": 68847,
+ "68784": 68848,
+ "68785": 68849,
+ "68786": 68850,
+ "68800": 68736,
+ "68801": 68737,
+ "68802": 68738,
+ "68803": 68739,
+ "68804": 68740,
+ "68805": 68741,
+ "68806": 68742,
+ "68807": 68743,
+ "68808": 68744,
+ "68809": 68745,
+ "68810": 68746,
+ "68811": 68747,
+ "68812": 68748,
+ "68813": 68749,
+ "68814": 68750,
+ "68815": 68751,
+ "68816": 68752,
+ "68817": 68753,
+ "68818": 68754,
+ "68819": 68755,
+ "68820": 68756,
+ "68821": 68757,
+ "68822": 68758,
+ "68823": 68759,
+ "68824": 68760,
+ "68825": 68761,
+ "68826": 68762,
+ "68827": 68763,
+ "68828": 68764,
+ "68829": 68765,
+ "68830": 68766,
+ "68831": 68767,
+ "68832": 68768,
+ "68833": 68769,
+ "68834": 68770,
+ "68835": 68771,
+ "68836": 68772,
+ "68837": 68773,
+ "68838": 68774,
+ "68839": 68775,
+ "68840": 68776,
+ "68841": 68777,
+ "68842": 68778,
+ "68843": 68779,
+ "68844": 68780,
+ "68845": 68781,
+ "68846": 68782,
+ "68847": 68783,
+ "68848": 68784,
+ "68849": 68785,
+ "68850": 68786,
+ "71840": 71872,
+ "71841": 71873,
+ "71842": 71874,
+ "71843": 71875,
+ "71844": 71876,
+ "71845": 71877,
+ "71846": 71878,
+ "71847": 71879,
+ "71848": 71880,
+ "71849": 71881,
+ "71850": 71882,
+ "71851": 71883,
+ "71852": 71884,
+ "71853": 71885,
+ "71854": 71886,
+ "71855": 71887,
+ "71856": 71888,
+ "71857": 71889,
+ "71858": 71890,
+ "71859": 71891,
+ "71860": 71892,
+ "71861": 71893,
+ "71862": 71894,
+ "71863": 71895,
+ "71864": 71896,
+ "71865": 71897,
+ "71866": 71898,
+ "71867": 71899,
+ "71868": 71900,
+ "71869": 71901,
+ "71870": 71902,
+ "71871": 71903,
+ "71872": 71840,
+ "71873": 71841,
+ "71874": 71842,
+ "71875": 71843,
+ "71876": 71844,
+ "71877": 71845,
+ "71878": 71846,
+ "71879": 71847,
+ "71880": 71848,
+ "71881": 71849,
+ "71882": 71850,
+ "71883": 71851,
+ "71884": 71852,
+ "71885": 71853,
+ "71886": 71854,
+ "71887": 71855,
+ "71888": 71856,
+ "71889": 71857,
+ "71890": 71858,
+ "71891": 71859,
+ "71892": 71860,
+ "71893": 71861,
+ "71894": 71862,
+ "71895": 71863,
+ "71896": 71864,
+ "71897": 71865,
+ "71898": 71866,
+ "71899": 71867,
+ "71900": 71868,
+ "71901": 71869,
+ "71902": 71870,
+ "71903": 71871
+}
diff --git a/node_modules/regexpu-core/package.json b/node_modules/regexpu-core/package.json
new file mode 100644
index 0000000..d46c3b2
--- /dev/null
+++ b/node_modules/regexpu-core/package.json
@@ -0,0 +1,88 @@
+{
+ "_from": "regexpu-core@^2.0.0",
+ "_id": "regexpu-core@2.0.0",
+ "_inBundle": false,
+ "_integrity": "sha1-SdA4g3uNz4v6W5pCE5k45uoq4kA=",
+ "_location": "/regexpu-core",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "regexpu-core@^2.0.0",
+ "name": "regexpu-core",
+ "escapedName": "regexpu-core",
+ "rawSpec": "^2.0.0",
+ "saveSpec": null,
+ "fetchSpec": "^2.0.0"
+ },
+ "_requiredBy": [
+ "/babel-plugin-transform-es2015-unicode-regex"
+ ],
+ "_resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-2.0.0.tgz",
+ "_shasum": "49d038837b8dcf8bfa5b9a42139938e6ea2ae240",
+ "_spec": "regexpu-core@^2.0.0",
+ "_where": "/home/pruss/Dev/3-minute-website/node_modules/babel-plugin-transform-es2015-unicode-regex",
+ "author": {
+ "name": "Mathias Bynens",
+ "url": "https://mathiasbynens.be/"
+ },
+ "bugs": {
+ "url": "https://github.com/mathiasbynens/regexpu-core/issues"
+ },
+ "bundleDependencies": false,
+ "dependencies": {
+ "regenerate": "^1.2.1",
+ "regjsgen": "^0.2.0",
+ "regjsparser": "^0.1.4"
+ },
+ "deprecated": false,
+ "description": "regexpu’s core functionality (i.e. `rewritePattern(pattern, flag)`), capable of translating ES6 Unicode regular expressions to ES5.",
+ "devDependencies": {
+ "coveralls": "^2.11.2",
+ "istanbul": "^0.4.0",
+ "jsesc": "^0.5.0",
+ "lodash": "^3.6.0",
+ "mocha": "^2.2.1",
+ "regexpu-fixtures": "^2.0.0",
+ "unicode-8.0.0": "^0.1.5"
+ },
+ "files": [
+ "LICENSE-MIT.txt",
+ "rewrite-pattern.js",
+ "data/character-class-escape-sets.js",
+ "data/iu-mappings.json"
+ ],
+ "homepage": "https://mths.be/regexpu",
+ "keywords": [
+ "codegen",
+ "desugaring",
+ "ecmascript",
+ "es5",
+ "es6",
+ "harmony",
+ "javascript",
+ "refactoring",
+ "regex",
+ "regexp",
+ "regular expressions",
+ "rewriting",
+ "syntax",
+ "transformation",
+ "transpile",
+ "transpiler",
+ "unicode"
+ ],
+ "license": "MIT",
+ "main": "rewrite-pattern.js",
+ "name": "regexpu-core",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/mathiasbynens/regexpu-core.git"
+ },
+ "scripts": {
+ "build": "node scripts/iu-mappings.js && node scripts/character-class-escape-sets.js",
+ "coverage": "istanbul cover --report html node_modules/.bin/_mocha tests/tests.js -- -u exports -R spec",
+ "test": "mocha tests"
+ },
+ "version": "2.0.0"
+}
diff --git a/node_modules/regexpu-core/rewrite-pattern.js b/node_modules/regexpu-core/rewrite-pattern.js
new file mode 100644
index 0000000..47a7854
--- /dev/null
+++ b/node_modules/regexpu-core/rewrite-pattern.js
@@ -0,0 +1,193 @@
+var generate = require('regjsgen').generate;
+var parse = require('regjsparser').parse;
+var regenerate = require('regenerate');
+var iuMappings = require('./data/iu-mappings.json');
+var ESCAPE_SETS = require('./data/character-class-escape-sets.js');
+
+function getCharacterClassEscapeSet(character) {
+ if (unicode) {
+ if (ignoreCase) {
+ return ESCAPE_SETS.UNICODE_IGNORE_CASE[character];
+ }
+ return ESCAPE_SETS.UNICODE[character];
+ }
+ return ESCAPE_SETS.REGULAR[character];
+}
+
+var object = {};
+var hasOwnProperty = object.hasOwnProperty;
+function has(object, property) {
+ return hasOwnProperty.call(object, property);
+}
+
+// Prepare a Regenerate set containing all code points, used for negative
+// character classes (if any).
+var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF);
+// Without the `u` flag, the range stops at 0xFFFF.
+// https://mths.be/es6#sec-pattern-semantics
+var BMP_SET = regenerate().addRange(0x0, 0xFFFF);
+
+// Prepare a Regenerate set containing all code points that are supposed to be
+// matched by `/./u`. https://mths.be/es6#sec-atom
+var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points
+ .remove(
+ // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators):
+ 0x000A, // Line Feed <LF>
+ 0x000D, // Carriage Return <CR>
+ 0x2028, // Line Separator <LS>
+ 0x2029 // Paragraph Separator <PS>
+ );
+// Prepare a Regenerate set containing all code points that are supposed to be
+// matched by `/./` (only BMP code points).
+var DOT_SET = DOT_SET_UNICODE.clone()
+ .intersection(BMP_SET);
+
+// Add a range of code points + any case-folded code points in that range to a
+// set.
+regenerate.prototype.iuAddRange = function(min, max) {
+ var $this = this;
+ do {
+ var folded = caseFold(min);
+ if (folded) {
+ $this.add(folded);
+ }
+ } while (++min <= max);
+ return $this;
+};
+
+function assign(target, source) {
+ for (var key in source) {
+ // Note: `hasOwnProperty` is not needed here.
+ target[key] = source[key];
+ }
+}
+
+function update(item, pattern) {
+ // TODO: Test if memoizing `pattern` here is worth the effort.
+ if (!pattern) {
+ return;
+ }
+ var tree = parse(pattern, '');
+ switch (tree.type) {
+ case 'characterClass':
+ case 'group':
+ case 'value':
+ // No wrapping needed.
+ break;
+ default:
+ // Wrap the pattern in a non-capturing group.
+ tree = wrap(tree, pattern);
+ }
+ assign(item, tree);
+}
+
+function wrap(tree, pattern) {
+ // Wrap the pattern in a non-capturing group.
+ return {
+ 'type': 'group',
+ 'behavior': 'ignore',
+ 'body': [tree],
+ 'raw': '(?:' + pattern + ')'
+ };
+}
+
+function caseFold(codePoint) {
+ return has(iuMappings, codePoint) ? iuMappings[codePoint] : false;
+}
+
+var ignoreCase = false;
+var unicode = false;
+function processCharacterClass(characterClassItem) {
+ var set = regenerate();
+ var body = characterClassItem.body.forEach(function(item) {
+ switch (item.type) {
+ case 'value':
+ set.add(item.codePoint);
+ if (ignoreCase && unicode) {
+ var folded = caseFold(item.codePoint);
+ if (folded) {
+ set.add(folded);
+ }
+ }
+ break;
+ case 'characterClassRange':
+ var min = item.min.codePoint;
+ var max = item.max.codePoint;
+ set.addRange(min, max);
+ if (ignoreCase && unicode) {
+ set.iuAddRange(min, max);
+ }
+ break;
+ case 'characterClassEscape':
+ set.add(getCharacterClassEscapeSet(item.value));
+ break;
+ // The `default` clause is only here as a safeguard; it should never be
+ // reached. Code coverage tools should ignore it.
+ /* istanbul ignore next */
+ default:
+ throw Error('Unknown term type: ' + item.type);
+ }
+ });
+ if (characterClassItem.negative) {
+ set = (unicode ? UNICODE_SET : BMP_SET).clone().remove(set);
+ }
+ update(characterClassItem, set.toString());
+ return characterClassItem;
+}
+
+function processTerm(item) {
+ switch (item.type) {
+ case 'dot':
+ update(
+ item,
+ (unicode ? DOT_SET_UNICODE : DOT_SET).toString()
+ );
+ break;
+ case 'characterClass':
+ item = processCharacterClass(item);
+ break;
+ case 'characterClassEscape':
+ update(
+ item,
+ getCharacterClassEscapeSet(item.value).toString()
+ );
+ break;
+ case 'alternative':
+ case 'disjunction':
+ case 'group':
+ case 'quantifier':
+ item.body = item.body.map(processTerm);
+ break;
+ case 'value':
+ var codePoint = item.codePoint;
+ var set = regenerate(codePoint);
+ if (ignoreCase && unicode) {
+ var folded = caseFold(codePoint);
+ if (folded) {
+ set.add(folded);
+ }
+ }
+ update(item, set.toString());
+ break;
+ case 'anchor':
+ case 'empty':
+ case 'group':
+ case 'reference':
+ // Nothing to do here.
+ break;
+ // The `default` clause is only here as a safeguard; it should never be
+ // reached. Code coverage tools should ignore it.
+ /* istanbul ignore next */
+ default:
+ throw Error('Unknown term type: ' + item.type);
+ }
+ return item;
+};
+
+module.exports = function(pattern, flags) {
+ var tree = parse(pattern, flags);
+ ignoreCase = flags ? flags.indexOf('i') > -1 : false;
+ unicode = flags ? flags.indexOf('u') > -1 : false;
+ assign(tree, processTerm(tree));
+ return generate(tree);
+};