re2js 2.2.1 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +2 -0
- package/build/index.cjs.cjs +83 -54
- package/build/index.cjs.cjs.map +1 -1
- package/build/index.esm.d.ts +0 -1
- package/build/index.esm.d.ts.map +1 -1
- package/build/index.esm.js +83 -54
- package/build/index.esm.js.map +1 -1
- package/build/index.umd.js +83 -54
- package/build/index.umd.js.map +1 -1
- package/package.json +5 -3
package/build/index.esm.d.ts
CHANGED
package/build/index.esm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.d.ts","sourceRoot":"","sources":["index.esm.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.esm.d.ts","sourceRoot":"","sources":["index.esm.js"],"names":[],"mappings":"AA6xCA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;IACE;;;;;;;OAOG;IACH,6BAJW,MAAM,aACN,OAAO,GACL,MAAM,CA2BlB;IACD;;;;OAIG;IACH,qBAHW,KAAK,SACL,gBAAgB,GAAC,iBAAiB,GAAC,MAAM,EAAE,GAAC,MAAM,EA0B5D;IAnBC,oBAA2B;IAG3B,qBAAqB;IACrB,mBADW,MAAM,CACqC;IAEtD,uBAAuB;IACvB,QADW,MAAM,EAAE,CACH;IAChB,qCAAqC;IACrC,aADW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CACC;IAClC,qBAAqB;IACrB,sBADW,MAAM,CACqC;IAUxD;;;OAGG;IACH,WAFa,KAAK,CAIjB;IAED;;;;OAIG;IACH,SAFa,OAAO,CAiBnB;IAbC,qBAAqB;IACrB,uCAAoD;IAEpD,qBAAqB;IACrB,8BAAkB;IAElB,8BAAqB;IAGrB,+BAAsB;IAEtB,+BAAmB;IAIrB;;;;OAIG;IACH,yBAHW,gBAAgB,GAAC,iBAAiB,GAChC,OAAO,CASnB;IAHC,+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;IAGD,yDA+CC;IAGD,0DAwCC;CACF;AAn+DD;;GAEG;AACH;IACE,qBAAkD;IAClD,oBAEC;IAED;;;OAGG;IACH,kBAFa,OAAO,CAInB;IAED;;;OAGG;IACH,mBAFa,OAAO,CAInB;CACF"}
|
package/build/index.esm.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* re2js
|
|
3
3
|
* RE2JS is the JavaScript port of RE2, a regular expression engine that provides linear time matching
|
|
4
4
|
*
|
|
5
|
-
* @version v2.2.
|
|
6
|
-
* @author
|
|
5
|
+
* @version v2.2.3
|
|
6
|
+
* @author Oleksii Vasyliev
|
|
7
7
|
* @homepage https://github.com/le0pard/re2js#readme
|
|
8
8
|
* @repository github:le0pard/re2js
|
|
9
9
|
* @license MIT
|
|
@@ -94,7 +94,7 @@ for (let i = 0; i < ASCII_SIZE; i++) {
|
|
|
94
94
|
}
|
|
95
95
|
class Codepoint {
|
|
96
96
|
// codePointAt(0)
|
|
97
|
-
static CODES = new Map([['\x07', 7], ['\b', 8], ['\t', 9], ['\n', 10], ['\v', 11], ['\f', 12], ['\r', 13], [' ', 32], ['"', 34], ['$', 36], ['&', 38], ['(', 40], [')', 41], ['*', 42], ['+', 43], ['-', 45], ['.', 46], ['0', 48], ['1', 49], ['2', 50], ['3', 51], ['4', 52], ['5', 53], ['6', 54], ['7', 55], ['8', 56], ['9', 57], [':', 58], ['<', 60], ['>', 62], ['?', 63], ['A', 65], ['B', 66], ['C', 67], ['F', 70], ['P', 80], ['Q', 81], ['U', 85], ['Z', 90], ['[', 91], ['\\', 92], [']', 93], ['^', 94], ['_', 95], ['a', 97], ['b', 98], ['f', 102], ['i', 105], ['m', 109], ['n', 110], ['r', 114], ['s', 115], ['t', 116], ['v', 118], ['x', 120], ['z', 122], ['{', 123], ['|', 124], ['}', 125]]);
|
|
97
|
+
static CODES = new Map([['\x07', 7], ['\b', 8], ['\t', 9], ['\n', 10], ['\v', 11], ['\f', 12], ['\r', 13], [' ', 32], ['"', 34], ['$', 36], ['&', 38], ["'", 39], ['(', 40], [')', 41], ['*', 42], ['+', 43], ['-', 45], ['.', 46], ['0', 48], ['1', 49], ['2', 50], ['3', 51], ['4', 52], ['5', 53], ['6', 54], ['7', 55], ['8', 56], ['9', 57], [':', 58], ['<', 60], ['>', 62], ['?', 63], ['A', 65], ['B', 66], ['C', 67], ['F', 70], ['P', 80], ['Q', 81], ['U', 85], ['Z', 90], ['[', 91], ['\\', 92], [']', 93], ['^', 94], ['_', 95], ['`', 96], ['a', 97], ['b', 98], ['f', 102], ['i', 105], ['m', 109], ['n', 110], ['r', 114], ['s', 115], ['t', 116], ['v', 118], ['x', 120], ['z', 122], ['{', 123], ['|', 124], ['}', 125]]);
|
|
98
98
|
|
|
99
99
|
// convert unicode codepoint to upper case codepoint
|
|
100
100
|
// return same codepoint, if cannot do it (or codepoint not have upper variation)
|
|
@@ -148,10 +148,6 @@ class UnicodeRangeTable {
|
|
|
148
148
|
getStride(index) {
|
|
149
149
|
return this.isStride1 ? 1 : this.data[index * this.SIZE + 2];
|
|
150
150
|
}
|
|
151
|
-
get(index) {
|
|
152
|
-
const i = index * this.SIZE;
|
|
153
|
-
return [this.data[i], this.data[i + 1], this.getStride(index)];
|
|
154
|
-
}
|
|
155
151
|
get length() {
|
|
156
152
|
return this.data.length / this.SIZE;
|
|
157
153
|
}
|
|
@@ -648,6 +644,9 @@ class Utils {
|
|
|
648
644
|
static emptyInts() {
|
|
649
645
|
return [];
|
|
650
646
|
}
|
|
647
|
+
static isByteArray(input) {
|
|
648
|
+
return Array.isArray(input) || input instanceof Uint8Array;
|
|
649
|
+
}
|
|
651
650
|
|
|
652
651
|
// Returns true iff |c| is an ASCII letter or decimal digit.
|
|
653
652
|
static isalnum(c) {
|
|
@@ -949,7 +948,7 @@ class Utf16MatcherInput extends MatcherInputBase {
|
|
|
949
948
|
* @returns {number[]}
|
|
950
949
|
*/
|
|
951
950
|
asBytes() {
|
|
952
|
-
return this.charSequence.toString()
|
|
951
|
+
return Utils.stringToUtf8ByteArray(this.charSequence.toString());
|
|
953
952
|
}
|
|
954
953
|
|
|
955
954
|
/**
|
|
@@ -974,7 +973,7 @@ class MatcherInput {
|
|
|
974
973
|
* @returns {Utf8MatcherInput}
|
|
975
974
|
*/
|
|
976
975
|
static utf8(input) {
|
|
977
|
-
if (
|
|
976
|
+
if (Utils.isByteArray(input)) {
|
|
978
977
|
return new Utf8MatcherInput(input);
|
|
979
978
|
}
|
|
980
979
|
return new Utf8MatcherInput(Utils.stringToUtf8ByteArray(input));
|
|
@@ -1106,10 +1105,10 @@ class MachineUTF8Input extends MachineInputBase {
|
|
|
1106
1105
|
if (start < this.start) {
|
|
1107
1106
|
start = this.start;
|
|
1108
1107
|
}
|
|
1109
|
-
r1 = this.step(start) >> 3;
|
|
1108
|
+
r1 = this.step(start - this.start) >> 3;
|
|
1110
1109
|
}
|
|
1111
1110
|
}
|
|
1112
|
-
const r2 = pos < this.end ? this.step(pos) >> 3 : -1;
|
|
1111
|
+
const r2 = pos < this.end ? this.step(pos - this.start) >> 3 : -1;
|
|
1113
1112
|
return Utils.emptyOpContext(r1, r2);
|
|
1114
1113
|
}
|
|
1115
1114
|
|
|
@@ -1191,14 +1190,17 @@ class MachineUTF16Input extends MachineInputBase {
|
|
|
1191
1190
|
index(re2, pos) {
|
|
1192
1191
|
pos += this.start;
|
|
1193
1192
|
const i = this.charSequence.indexOf(re2.prefix, pos);
|
|
1194
|
-
|
|
1193
|
+
if (i < 0 || i > this.end - re2.prefix.length) {
|
|
1194
|
+
return -1;
|
|
1195
|
+
}
|
|
1196
|
+
return i - pos;
|
|
1195
1197
|
}
|
|
1196
1198
|
|
|
1197
1199
|
// Returns a bitmask of EMPTY_* flags.
|
|
1198
1200
|
context(pos) {
|
|
1199
1201
|
pos += this.start;
|
|
1200
|
-
const r1 = pos >
|
|
1201
|
-
const r2 = pos < this.
|
|
1202
|
+
const r1 = pos > this.start && pos <= this.end ? this.charSequence.codePointAt(pos - 1) : -1;
|
|
1203
|
+
const r2 = pos < this.end ? this.charSequence.codePointAt(pos) : -1;
|
|
1202
1204
|
return Utils.emptyOpContext(r1, r2);
|
|
1203
1205
|
}
|
|
1204
1206
|
prefixLength(re2) {
|
|
@@ -1386,7 +1388,7 @@ class Matcher {
|
|
|
1386
1388
|
this.numberOfInstructions = re2.numberOfInstructions();
|
|
1387
1389
|
if (input instanceof MatcherInputBase) {
|
|
1388
1390
|
this.resetMatcherInput(input);
|
|
1389
|
-
} else if (
|
|
1391
|
+
} else if (Utils.isByteArray(input)) {
|
|
1390
1392
|
this.resetMatcherInput(MatcherInput.utf8(input));
|
|
1391
1393
|
} else {
|
|
1392
1394
|
this.resetMatcherInput(MatcherInput.utf16(input));
|
|
@@ -1548,10 +1550,7 @@ class Matcher {
|
|
|
1548
1550
|
if (group === 0 || this.hasGroups) {
|
|
1549
1551
|
return;
|
|
1550
1552
|
}
|
|
1551
|
-
|
|
1552
|
-
if (end > this.matcherInputLength) {
|
|
1553
|
-
end = this.matcherInputLength;
|
|
1554
|
-
}
|
|
1553
|
+
const end = this.matcherInputLength;
|
|
1555
1554
|
const res = this.patternInput.re2().matchMachineInput(this.matcherInput, this.groups[0], end, this.anchorFlag, 1 + this.patternGroupCount);
|
|
1556
1555
|
const ok = res[0];
|
|
1557
1556
|
if (!ok) {
|
|
@@ -1747,7 +1746,10 @@ class Matcher {
|
|
|
1747
1746
|
throw new RE2JSGroupException("named capture group is missing trailing '}'");
|
|
1748
1747
|
}
|
|
1749
1748
|
const groupName = replacement.substring(i + 1, j);
|
|
1750
|
-
|
|
1749
|
+
const groupVal = this.group(groupName);
|
|
1750
|
+
if (groupVal !== null) {
|
|
1751
|
+
res += groupVal;
|
|
1752
|
+
}
|
|
1751
1753
|
last = j + 1;
|
|
1752
1754
|
i = j;
|
|
1753
1755
|
continue;
|
|
@@ -1793,6 +1795,22 @@ class Matcher {
|
|
|
1793
1795
|
i++;
|
|
1794
1796
|
last = i + 1;
|
|
1795
1797
|
continue;
|
|
1798
|
+
} else if (Codepoint.CODES.get('`') === c) {
|
|
1799
|
+
if (last < i) {
|
|
1800
|
+
res += replacement.substring(last, i);
|
|
1801
|
+
}
|
|
1802
|
+
res += this.substring(0, this.start(0));
|
|
1803
|
+
i++;
|
|
1804
|
+
last = i + 1;
|
|
1805
|
+
continue;
|
|
1806
|
+
} else if (Codepoint.CODES.get("'") === c) {
|
|
1807
|
+
if (last < i) {
|
|
1808
|
+
res += replacement.substring(last, i);
|
|
1809
|
+
}
|
|
1810
|
+
res += this.substring(this.end(0), this.matcherInputLength);
|
|
1811
|
+
i++;
|
|
1812
|
+
last = i + 1;
|
|
1813
|
+
continue;
|
|
1796
1814
|
} else if (Codepoint.CODES.get('1') <= c && c <= Codepoint.CODES.get('9')) {
|
|
1797
1815
|
let n = c - Codepoint.CODES.get('0');
|
|
1798
1816
|
if (last < i) {
|
|
@@ -1835,7 +1853,10 @@ class Matcher {
|
|
|
1835
1853
|
}
|
|
1836
1854
|
const groupName = replacement.substring(i + 1, j);
|
|
1837
1855
|
if (Object.prototype.hasOwnProperty.call(this.namedGroups, groupName)) {
|
|
1838
|
-
|
|
1856
|
+
const groupVal = this.group(groupName);
|
|
1857
|
+
if (groupVal !== null) {
|
|
1858
|
+
res += groupVal;
|
|
1859
|
+
}
|
|
1839
1860
|
} else {
|
|
1840
1861
|
res += `$<${groupName}>`;
|
|
1841
1862
|
}
|
|
@@ -3341,7 +3362,9 @@ const makeOnePass = p => {
|
|
|
3341
3362
|
}
|
|
3342
3363
|
runes.sort((a, b) => a - b);
|
|
3343
3364
|
} else {
|
|
3344
|
-
|
|
3365
|
+
for (let j = 0; j < inst.runes.length; j++) {
|
|
3366
|
+
runes.push(inst.runes[j]);
|
|
3367
|
+
}
|
|
3345
3368
|
}
|
|
3346
3369
|
onePassRunes[pc] = runes;
|
|
3347
3370
|
inst.next = new Uint32Array(Math.floor(runes.length / 2) + 1).fill(inst.out);
|
|
@@ -4168,7 +4191,9 @@ class PrefilterTree {
|
|
|
4168
4191
|
return new Prefilter(Prefilter.Type.NONE);
|
|
4169
4192
|
}
|
|
4170
4193
|
if (s.type === Prefilter.Type.OR) {
|
|
4171
|
-
|
|
4194
|
+
for (let j = 0; j < s.subs.length; j++) {
|
|
4195
|
+
newSubs.push(s.subs[j]);
|
|
4196
|
+
}
|
|
4172
4197
|
} else {
|
|
4173
4198
|
newSubs.push(s);
|
|
4174
4199
|
}
|
|
@@ -4333,13 +4358,6 @@ class Prog {
|
|
|
4333
4358
|
// start every program with a fail instruction, so we'll never want to point
|
|
4334
4359
|
// at its output link.
|
|
4335
4360
|
|
|
4336
|
-
next(l) {
|
|
4337
|
-
const i = this.inst[l >> 1];
|
|
4338
|
-
if ((l & 1) === 0) {
|
|
4339
|
-
return i.out;
|
|
4340
|
-
}
|
|
4341
|
-
return i.arg;
|
|
4342
|
-
}
|
|
4343
4361
|
patch(l, val) {
|
|
4344
4362
|
let head = l.head;
|
|
4345
4363
|
while (head !== 0) {
|
|
@@ -5669,6 +5687,7 @@ class Parser {
|
|
|
5669
5687
|
case Codepoint.CODES.get('6'):
|
|
5670
5688
|
case Codepoint.CODES.get('7'):
|
|
5671
5689
|
{
|
|
5690
|
+
// Single non-zero digit is a backreference; not supported
|
|
5672
5691
|
if (!t.more() || t.peek() < Codepoint.CODES.get('0') || t.peek() > Codepoint.CODES.get('7')) {
|
|
5673
5692
|
break;
|
|
5674
5693
|
}
|
|
@@ -5676,6 +5695,7 @@ class Parser {
|
|
|
5676
5695
|
// eslint-disable-next-line no-fallthrough
|
|
5677
5696
|
case Codepoint.CODES.get('0'):
|
|
5678
5697
|
{
|
|
5698
|
+
// Consume up to three octal digits; already have one.
|
|
5679
5699
|
let r = c - Codepoint.CODES.get('0');
|
|
5680
5700
|
for (let i = 1; i < 3; i++) {
|
|
5681
5701
|
if (!t.more() || t.peek() < Codepoint.CODES.get('0') || t.peek() > Codepoint.CODES.get('7')) {
|
|
@@ -7456,7 +7476,11 @@ class RE2 {
|
|
|
7456
7476
|
*/
|
|
7457
7477
|
matchWithGroup(input, start, end, anchor, ngroup) {
|
|
7458
7478
|
if (!(input instanceof MatcherInputBase)) {
|
|
7459
|
-
|
|
7479
|
+
if (Utils.isByteArray(input)) {
|
|
7480
|
+
input = MatcherInput.utf8(input);
|
|
7481
|
+
} else {
|
|
7482
|
+
input = MatcherInput.utf16(input);
|
|
7483
|
+
}
|
|
7460
7484
|
}
|
|
7461
7485
|
return this.matchMachineInput(input, start, end, anchor, ngroup);
|
|
7462
7486
|
}
|
|
@@ -7962,7 +7986,7 @@ class RE2Set {
|
|
|
7962
7986
|
}
|
|
7963
7987
|
match(input) {
|
|
7964
7988
|
if (!this.prog) this.compile();
|
|
7965
|
-
const machineInput =
|
|
7989
|
+
const machineInput = Utils.isByteArray(input) ? MachineInput.fromUTF8(input) : MachineInput.fromUTF16(input);
|
|
7966
7990
|
let internalAnchor = RE2Flags.UNANCHORED;
|
|
7967
7991
|
if (this.anchor === RE2Set.ANCHOR_START) {
|
|
7968
7992
|
internalAnchor = RE2Flags.ANCHOR_START;
|
|
@@ -8019,45 +8043,50 @@ class TranslateRegExpString {
|
|
|
8019
8043
|
{
|
|
8020
8044
|
if (i + 2 < size) {
|
|
8021
8045
|
let nextCh = data[i + 2];
|
|
8022
|
-
|
|
8046
|
+
let code = nextCh.charCodeAt(0);
|
|
8047
|
+
if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
|
|
8048
|
+
let val = code % 32;
|
|
8023
8049
|
result += '\\x';
|
|
8024
|
-
result += (
|
|
8025
|
-
result += (
|
|
8050
|
+
result += (val >> 4).toString(16).toUpperCase();
|
|
8051
|
+
result += (val & 15).toString(16).toUpperCase();
|
|
8026
8052
|
i += 3;
|
|
8027
8053
|
changed = true;
|
|
8028
8054
|
continue;
|
|
8029
8055
|
}
|
|
8030
8056
|
}
|
|
8031
|
-
result += '
|
|
8057
|
+
result += 'c';
|
|
8032
8058
|
i += 2;
|
|
8059
|
+
changed = true;
|
|
8033
8060
|
continue;
|
|
8034
8061
|
}
|
|
8035
8062
|
case 'u':
|
|
8036
8063
|
{
|
|
8037
8064
|
if (i + 2 < size) {
|
|
8038
8065
|
let nextCh = data[i + 2];
|
|
8039
|
-
if (
|
|
8040
|
-
result += '\\x{' + nextCh;
|
|
8041
|
-
i += 3;
|
|
8042
|
-
for (let j = 0; j < 3 && i < size; ++i, ++j) {
|
|
8043
|
-
nextCh = data[i];
|
|
8044
|
-
if (!TranslateRegExpString.isHexadecimal(nextCh)) {
|
|
8045
|
-
break;
|
|
8046
|
-
}
|
|
8047
|
-
result += nextCh;
|
|
8048
|
-
}
|
|
8049
|
-
result += '}';
|
|
8050
|
-
changed = true;
|
|
8051
|
-
continue;
|
|
8052
|
-
} else if (nextCh === '{') {
|
|
8066
|
+
if (nextCh === '{') {
|
|
8053
8067
|
result += '\\x';
|
|
8054
8068
|
i += 2;
|
|
8055
8069
|
changed = true;
|
|
8056
8070
|
continue;
|
|
8071
|
+
} else if (i + 5 < size) {
|
|
8072
|
+
let isHex4 = true;
|
|
8073
|
+
for (let j = 0; j < 4; j++) {
|
|
8074
|
+
if (!TranslateRegExpString.isHexadecimal(data[i + 2 + j])) {
|
|
8075
|
+
isHex4 = false;
|
|
8076
|
+
break;
|
|
8077
|
+
}
|
|
8078
|
+
}
|
|
8079
|
+
if (isHex4) {
|
|
8080
|
+
result += '\\x{' + data.substring(i + 2, i + 6) + '}';
|
|
8081
|
+
i += 6;
|
|
8082
|
+
changed = true;
|
|
8083
|
+
continue;
|
|
8084
|
+
}
|
|
8057
8085
|
}
|
|
8058
8086
|
}
|
|
8059
|
-
result += '
|
|
8087
|
+
result += 'u';
|
|
8060
8088
|
i += 2;
|
|
8089
|
+
changed = true;
|
|
8061
8090
|
continue;
|
|
8062
8091
|
}
|
|
8063
8092
|
default:
|
|
@@ -8292,7 +8321,7 @@ class RE2JS {
|
|
|
8292
8321
|
* @returns {Matcher}
|
|
8293
8322
|
*/
|
|
8294
8323
|
matcher(input) {
|
|
8295
|
-
if (
|
|
8324
|
+
if (Utils.isByteArray(input)) {
|
|
8296
8325
|
input = MatcherInput.utf8(input);
|
|
8297
8326
|
}
|
|
8298
8327
|
return new Matcher(this, input);
|
|
@@ -8308,7 +8337,7 @@ class RE2JS {
|
|
|
8308
8337
|
* @returns {boolean} `true` if the pattern is found anywhere in the input, `false` otherwise.
|
|
8309
8338
|
*/
|
|
8310
8339
|
test(input) {
|
|
8311
|
-
if (
|
|
8340
|
+
if (Utils.isByteArray(input)) {
|
|
8312
8341
|
// Reuse the existing UTF-8 fast-path method
|
|
8313
8342
|
return this.re2Input.matchUTF8(input);
|
|
8314
8343
|
}
|
|
@@ -8327,7 +8356,7 @@ class RE2JS {
|
|
|
8327
8356
|
* @returns {boolean} `true` if the exact input string fully matches the pattern, `false` otherwise.
|
|
8328
8357
|
*/
|
|
8329
8358
|
testExact(input) {
|
|
8330
|
-
const machineInput =
|
|
8359
|
+
const machineInput = Utils.isByteArray(input) ? MachineInput.fromUTF8(input) : MachineInput.fromUTF16(input);
|
|
8331
8360
|
return this.re2Input.executeEngine(machineInput, 0, RE2Flags.ANCHOR_BOTH, 0) !== null;
|
|
8332
8361
|
}
|
|
8333
8362
|
|