re2js 2.2.2 → 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.
@@ -557,7 +557,6 @@ declare class Prog {
557
557
  skipNop(pc: any): any;
558
558
  prefix(): (string | boolean)[];
559
559
  startCond(): number;
560
- next(l: any): any;
561
560
  patch(l: any, val: any): void;
562
561
  append(l1: any, l2: any): any;
563
562
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.d.ts","sourceRoot":"","sources":["index.esm.js"],"names":[],"mappings":"AA2xCA;;;;;;;;;;;;;;;;;;;;;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,+DAAyB;IAK3B;;;;;OAKG;IACH,cAHW,MAAM,GAAC,MAAM,GACX,MAAM,CAYlB;IAED;;;;;OAKG;IACH,YAHW,MAAM,GAAC,MAAM,GACX,MAAM,CAYlB;IAED;;;;;;;;;OASG;IACH,eAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,cAHW,MAAM,GA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ACH,kBAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,WAFa,MAAM,EAAE,CAIpB;IAED;;;OAGG;IACH,UAFa,MAAM,CAIlB;CACF;AACD;IACE,iCAGC;IADC,kBAAgC;IAElC,mBAEC;IAED;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,WAFa,MAAM,EAAE,CAIpB;IAED;;;OAGG;IACH,UAFa,MAAM,CAIlB;CACF;AAyuGD;;GAEG;AACH;IAEI,YAAc;IACd,cAAc;IAGd,eAAe;IACf,gBAAkB;IAClB,cAAc;IAKhB,sBAEC;IAGD,kBAEC;IAID,uBAEC;IAID,sBAOC;IAKD,+BAWC;IAID,oBAoBC;IAeD,8BAYC;IACD,8BAYC;IACD;;;OAGG;IACH,YAFa,MAAM,CAelB;CACF;AArxDD;IACE,gCAA4B;IAC5B,uBASC;IARC,UAAgB;IAChB,0BAA2B;IAC3B,mBAAmB;IACnB,gBAAsB;IACtB,mBAAuB;IACvB,oBAAoB;IACpB,gBAAmB;IACnB,cAAc;IAIhB;;;;aAuCC;IAGD,wBAyDC;IACD,mBAyCC;IAGD,kDA+CC;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"}
@@ -2,7 +2,7 @@
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.2
5
+ * @version v2.2.3
6
6
  * @author Oleksii Vasyliev
7
7
  * @homepage https://github.com/le0pard/re2js#readme
8
8
  * @repository github:le0pard/re2js
@@ -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().split('').map(s => s.codePointAt(0));
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 (Array.isArray(input)) {
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
- return i < 0 ? i : i - pos;
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 > 0 && pos <= this.charSequence.length ? this.charSequence.codePointAt(pos - 1) : -1;
1201
- const r2 = pos < this.charSequence.length ? this.charSequence.codePointAt(pos) : -1;
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 (Array.isArray(input)) {
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
- let end = this.groups[1] + 1;
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
- res += this.group(groupName);
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
- res += this.group(groupName);
1856
+ const groupVal = this.group(groupName);
1857
+ if (groupVal !== null) {
1858
+ res += groupVal;
1859
+ }
1839
1860
  } else {
1840
1861
  res += `$<${groupName}>`;
1841
1862
  }
@@ -4337,13 +4358,6 @@ class Prog {
4337
4358
  // start every program with a fail instruction, so we'll never want to point
4338
4359
  // at its output link.
4339
4360
 
4340
- next(l) {
4341
- const i = this.inst[l >> 1];
4342
- if ((l & 1) === 0) {
4343
- return i.out;
4344
- }
4345
- return i.arg;
4346
- }
4347
4361
  patch(l, val) {
4348
4362
  let head = l.head;
4349
4363
  while (head !== 0) {
@@ -5673,6 +5687,7 @@ class Parser {
5673
5687
  case Codepoint.CODES.get('6'):
5674
5688
  case Codepoint.CODES.get('7'):
5675
5689
  {
5690
+ // Single non-zero digit is a backreference; not supported
5676
5691
  if (!t.more() || t.peek() < Codepoint.CODES.get('0') || t.peek() > Codepoint.CODES.get('7')) {
5677
5692
  break;
5678
5693
  }
@@ -5680,6 +5695,7 @@ class Parser {
5680
5695
  // eslint-disable-next-line no-fallthrough
5681
5696
  case Codepoint.CODES.get('0'):
5682
5697
  {
5698
+ // Consume up to three octal digits; already have one.
5683
5699
  let r = c - Codepoint.CODES.get('0');
5684
5700
  for (let i = 1; i < 3; i++) {
5685
5701
  if (!t.more() || t.peek() < Codepoint.CODES.get('0') || t.peek() > Codepoint.CODES.get('7')) {
@@ -7460,7 +7476,11 @@ class RE2 {
7460
7476
  */
7461
7477
  matchWithGroup(input, start, end, anchor, ngroup) {
7462
7478
  if (!(input instanceof MatcherInputBase)) {
7463
- input = MatcherInput.utf16(input);
7479
+ if (Utils.isByteArray(input)) {
7480
+ input = MatcherInput.utf8(input);
7481
+ } else {
7482
+ input = MatcherInput.utf16(input);
7483
+ }
7464
7484
  }
7465
7485
  return this.matchMachineInput(input, start, end, anchor, ngroup);
7466
7486
  }
@@ -7966,7 +7986,7 @@ class RE2Set {
7966
7986
  }
7967
7987
  match(input) {
7968
7988
  if (!this.prog) this.compile();
7969
- const machineInput = Array.isArray(input) ? MachineInput.fromUTF8(input) : MachineInput.fromUTF16(input);
7989
+ const machineInput = Utils.isByteArray(input) ? MachineInput.fromUTF8(input) : MachineInput.fromUTF16(input);
7970
7990
  let internalAnchor = RE2Flags.UNANCHORED;
7971
7991
  if (this.anchor === RE2Set.ANCHOR_START) {
7972
7992
  internalAnchor = RE2Flags.ANCHOR_START;
@@ -8023,45 +8043,50 @@ class TranslateRegExpString {
8023
8043
  {
8024
8044
  if (i + 2 < size) {
8025
8045
  let nextCh = data[i + 2];
8026
- if (TranslateRegExpString.isUpperCaseAlpha(nextCh)) {
8046
+ let code = nextCh.charCodeAt(0);
8047
+ if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
8048
+ let val = code % 32;
8027
8049
  result += '\\x';
8028
- result += (nextCh.charCodeAt(0) - 64 >> 4).toString(16).toUpperCase();
8029
- result += (nextCh.charCodeAt(0) - 64 & 15).toString(16).toUpperCase();
8050
+ result += (val >> 4).toString(16).toUpperCase();
8051
+ result += (val & 15).toString(16).toUpperCase();
8030
8052
  i += 3;
8031
8053
  changed = true;
8032
8054
  continue;
8033
8055
  }
8034
8056
  }
8035
- result += '\\c';
8057
+ result += 'c';
8036
8058
  i += 2;
8059
+ changed = true;
8037
8060
  continue;
8038
8061
  }
8039
8062
  case 'u':
8040
8063
  {
8041
8064
  if (i + 2 < size) {
8042
8065
  let nextCh = data[i + 2];
8043
- if (TranslateRegExpString.isHexadecimal(nextCh)) {
8044
- result += '\\x{' + nextCh;
8045
- i += 3;
8046
- for (let j = 0; j < 3 && i < size; ++i, ++j) {
8047
- nextCh = data[i];
8048
- if (!TranslateRegExpString.isHexadecimal(nextCh)) {
8049
- break;
8050
- }
8051
- result += nextCh;
8052
- }
8053
- result += '}';
8054
- changed = true;
8055
- continue;
8056
- } else if (nextCh === '{') {
8066
+ if (nextCh === '{') {
8057
8067
  result += '\\x';
8058
8068
  i += 2;
8059
8069
  changed = true;
8060
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
+ }
8061
8085
  }
8062
8086
  }
8063
- result += '\\u';
8087
+ result += 'u';
8064
8088
  i += 2;
8089
+ changed = true;
8065
8090
  continue;
8066
8091
  }
8067
8092
  default:
@@ -8296,7 +8321,7 @@ class RE2JS {
8296
8321
  * @returns {Matcher}
8297
8322
  */
8298
8323
  matcher(input) {
8299
- if (Array.isArray(input)) {
8324
+ if (Utils.isByteArray(input)) {
8300
8325
  input = MatcherInput.utf8(input);
8301
8326
  }
8302
8327
  return new Matcher(this, input);
@@ -8312,7 +8337,7 @@ class RE2JS {
8312
8337
  * @returns {boolean} `true` if the pattern is found anywhere in the input, `false` otherwise.
8313
8338
  */
8314
8339
  test(input) {
8315
- if (Array.isArray(input)) {
8340
+ if (Utils.isByteArray(input)) {
8316
8341
  // Reuse the existing UTF-8 fast-path method
8317
8342
  return this.re2Input.matchUTF8(input);
8318
8343
  }
@@ -8331,7 +8356,7 @@ class RE2JS {
8331
8356
  * @returns {boolean} `true` if the exact input string fully matches the pattern, `false` otherwise.
8332
8357
  */
8333
8358
  testExact(input) {
8334
- const machineInput = Array.isArray(input) ? MachineInput.fromUTF8(input) : MachineInput.fromUTF16(input);
8359
+ const machineInput = Utils.isByteArray(input) ? MachineInput.fromUTF8(input) : MachineInput.fromUTF16(input);
8335
8360
  return this.re2Input.executeEngine(machineInput, 0, RE2Flags.ANCHOR_BOTH, 0) !== null;
8336
8361
  }
8337
8362