re2js 2.8.2 → 2.8.4
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/README.md +10 -5
- package/build/index.cjs +17 -12
- package/build/index.d.cts +5 -2
- package/build/index.d.ts +5 -2
- package/build/index.js +17 -12
- package/build/index.umd.js +17 -12
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -264,7 +264,7 @@ This is incredibly powerful for profanity filters, routing engines, or log parse
|
|
|
264
264
|
```js
|
|
265
265
|
import { RE2Set } from 're2js'
|
|
266
266
|
|
|
267
|
-
// Create a new set. You can optionally pass an anchor
|
|
267
|
+
// Create a new set. You can optionally pass an anchor, public RE2JS flags, and a max memory limit for the DFA.
|
|
268
268
|
// Default anchor: RE2Set.UNANCHORED
|
|
269
269
|
const set = new RE2Set()
|
|
270
270
|
|
|
@@ -286,17 +286,22 @@ console.log(set.match('All systems operational.'))
|
|
|
286
286
|
// Outputs: []
|
|
287
287
|
```
|
|
288
288
|
|
|
289
|
-
#### Anchoring a Set
|
|
289
|
+
#### Anchoring a Set and Memory Limits
|
|
290
290
|
|
|
291
291
|
You can strictly anchor the entire set by passing an anchor constant to the constructor (`RE2Set.UNANCHORED`, `RE2Set.ANCHOR_START`, or `RE2Set.ANCHOR_BOTH`).
|
|
292
292
|
|
|
293
|
-
|
|
293
|
+
You can pass standard public `RE2JS` flags (like `CASE_INSENSITIVE` or `LOOKBEHINDS`) as the second argument to apply them to all patterns in the set.
|
|
294
|
+
|
|
295
|
+
Additionally, the third argument allows you to specify a `maxMem` limit (in bytes) to prevent the underlying DFA from exploding and consuming too much memory on highly ambiguous patterns.
|
|
296
|
+
The default is 8 * 1024 * 1024 (8MB).
|
|
294
297
|
|
|
295
298
|
```js
|
|
296
299
|
import { RE2Set, RE2JS } from 're2js'
|
|
297
300
|
|
|
298
|
-
// Anchor the set to match the entire string,
|
|
299
|
-
|
|
301
|
+
// Anchor the set to match the entire string, make it case-insensitive,
|
|
302
|
+
// and limit the DFA memory usage to ~4MB (default is 8MB).
|
|
303
|
+
const maxMem = 4 * 1024 * 1024;
|
|
304
|
+
const set = new RE2Set(RE2Set.ANCHOR_BOTH, RE2JS.CASE_INSENSITIVE, maxMem)
|
|
300
305
|
|
|
301
306
|
set.add('foo') // ID: 0
|
|
302
307
|
set.add('bar') // ID: 1
|
package/build/index.cjs
CHANGED
|
@@ -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.8.
|
|
5
|
+
* @version v2.8.4
|
|
6
6
|
* @author Oleksii Vasyliev
|
|
7
7
|
* @homepage https://github.com/le0pard/re2js#readme
|
|
8
8
|
* @repository github:le0pard/re2js
|
|
@@ -57,7 +57,7 @@ for (let i = 0; i < ASCII_SIZE; i++) {
|
|
|
57
57
|
else ASCII_TO_LOWER[i] = i;
|
|
58
58
|
}
|
|
59
59
|
var Codepoint = class {
|
|
60
|
-
static CODES = new Map([
|
|
60
|
+
static CODES = /* @__PURE__ */ new Map([
|
|
61
61
|
["\x07", 7],
|
|
62
62
|
["\b", 8],
|
|
63
63
|
[" ", 9],
|
|
@@ -168,7 +168,7 @@ var UnicodeRangeTable = class {
|
|
|
168
168
|
};
|
|
169
169
|
//#endregion
|
|
170
170
|
//#region src/UnicodeTables.js
|
|
171
|
-
const B64_MAP = new Uint8Array(256);
|
|
171
|
+
const B64_MAP = /* @__PURE__ */ new Uint8Array(256);
|
|
172
172
|
for (let i = 0, b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-"; i < 64; i++) B64_MAP[b.charCodeAt(i)] = i;
|
|
173
173
|
const decodeVLQ = (str) => {
|
|
174
174
|
const res = [];
|
|
@@ -1251,6 +1251,8 @@ var Matcher = class Matcher {
|
|
|
1251
1251
|
*/
|
|
1252
1252
|
resetMatcherInput(input) {
|
|
1253
1253
|
if (input === null) throw new Error("input is null");
|
|
1254
|
+
if (!(input instanceof MatcherInputBase)) if (Utils.isByteArray(input)) input = MatcherInput.utf8(input);
|
|
1255
|
+
else input = MatcherInput.utf16(input);
|
|
1254
1256
|
this.matcherInput = input;
|
|
1255
1257
|
this.reset();
|
|
1256
1258
|
return this;
|
|
@@ -2208,12 +2210,13 @@ var DFAState = class {
|
|
|
2208
2210
|
};
|
|
2209
2211
|
var DFA = class DFA {
|
|
2210
2212
|
static MAX_CACHE_CLEARS = 5;
|
|
2211
|
-
|
|
2213
|
+
static STATE_MEMORY_ESTIMATE = 838;
|
|
2214
|
+
constructor(prog, maxMem = 8388608) {
|
|
2212
2215
|
this.prog = prog;
|
|
2213
2216
|
this.stateCache = /* @__PURE__ */ new Map();
|
|
2214
2217
|
this.stateCount = 0;
|
|
2215
2218
|
this.startState = null;
|
|
2216
|
-
this.stateLimit =
|
|
2219
|
+
this.stateLimit = Math.max(1, Math.floor(maxMem / DFA.STATE_MEMORY_ESTIMATE));
|
|
2217
2220
|
this.cacheClears = 0;
|
|
2218
2221
|
this.failed = false;
|
|
2219
2222
|
this.clock = 0;
|
|
@@ -2425,14 +2428,14 @@ const MAX_BACKTRACK_VECTOR = 256 * 1024;
|
|
|
2425
2428
|
var BitState = class {
|
|
2426
2429
|
constructor() {
|
|
2427
2430
|
this.end = 0;
|
|
2428
|
-
this.cap = new Int32Array(0);
|
|
2429
|
-
this.matchcap = new Int32Array(0);
|
|
2431
|
+
this.cap = /* @__PURE__ */ new Int32Array(0);
|
|
2432
|
+
this.matchcap = /* @__PURE__ */ new Int32Array(0);
|
|
2430
2433
|
this.ncap = 0;
|
|
2431
2434
|
this.jobPc = new Int32Array(INITIAL_JOB_CAPACITY);
|
|
2432
2435
|
this.jobArg = new Uint8Array(INITIAL_JOB_CAPACITY);
|
|
2433
2436
|
this.jobPos = new Int32Array(INITIAL_JOB_CAPACITY);
|
|
2434
2437
|
this.jobLen = 0;
|
|
2435
|
-
this.visited = new Uint32Array(0);
|
|
2438
|
+
this.visited = /* @__PURE__ */ new Uint32Array(0);
|
|
2436
2439
|
}
|
|
2437
2440
|
reset(prog, end, ncap) {
|
|
2438
2441
|
this.end = end;
|
|
@@ -3942,7 +3945,7 @@ const code3 = [
|
|
|
3942
3945
|
97,
|
|
3943
3946
|
122
|
|
3944
3947
|
];
|
|
3945
|
-
const PERL_GROUPS = new Map([
|
|
3948
|
+
const PERL_GROUPS = /* @__PURE__ */ new Map([
|
|
3946
3949
|
["\\d", new CharGroup(1, code1)],
|
|
3947
3950
|
["\\D", new CharGroup(-1, code1)],
|
|
3948
3951
|
["\\s", new CharGroup(1, code2)],
|
|
@@ -4016,7 +4019,7 @@ const code17 = [
|
|
|
4016
4019
|
97,
|
|
4017
4020
|
102
|
|
4018
4021
|
];
|
|
4019
|
-
const POSIX_GROUPS = new Map([
|
|
4022
|
+
const POSIX_GROUPS = /* @__PURE__ */ new Map([
|
|
4020
4023
|
["[:alnum:]", new CharGroup(1, code4)],
|
|
4021
4024
|
["[:^alnum:]", new CharGroup(-1, code4)],
|
|
4022
4025
|
["[:alpha:]", new CharGroup(1, code5)],
|
|
@@ -5900,10 +5903,12 @@ var RE2Set = class RE2Set {
|
|
|
5900
5903
|
* Constructs a new RE2Set with the specified anchor mode and flags.
|
|
5901
5904
|
* @param {number} [anchor=RE2Set.UNANCHORED] - The anchoring mode (e.g., RE2Set.UNANCHORED).
|
|
5902
5905
|
* @param {number} [flags=0] - The public flags to apply to all patterns in the set.
|
|
5906
|
+
* @param {number} [maxMem=8388608] - The maximum memory in bytes to use for the DFA (default 8MB).
|
|
5903
5907
|
*/
|
|
5904
|
-
constructor(anchor = RE2Set.UNANCHORED, flags = 0) {
|
|
5908
|
+
constructor(anchor = RE2Set.UNANCHORED, flags = 0, maxMem = 8388608) {
|
|
5905
5909
|
this.anchor = anchor;
|
|
5906
5910
|
this.jsFlags = flags;
|
|
5911
|
+
this.maxMem = maxMem;
|
|
5907
5912
|
let re2Flags = RE2Flags.PERL;
|
|
5908
5913
|
if ((flags & PublicFlags.DISABLE_UNICODE_GROUPS) !== 0) re2Flags &= ~RE2Flags.UNICODE_GROUPS;
|
|
5909
5914
|
if ((flags & PublicFlags.LOOKBEHINDS) !== 0) re2Flags |= RE2Flags.LOOKBEHIND;
|
|
@@ -5938,7 +5943,7 @@ var RE2Set = class RE2Set {
|
|
|
5938
5943
|
compile() {
|
|
5939
5944
|
if (this.prog) return;
|
|
5940
5945
|
this.prog = Compiler.compileSet(this.regexps);
|
|
5941
|
-
this.dfa = new DFA(this.prog);
|
|
5946
|
+
this.dfa = new DFA(this.prog, this.maxMem);
|
|
5942
5947
|
this.dummyRe2 = {
|
|
5943
5948
|
prog: this.prog,
|
|
5944
5949
|
cond: this.prog.startCond(),
|
package/build/index.d.cts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
declare class DFA {
|
|
4
4
|
static MAX_CACHE_CLEARS: number;
|
|
5
|
-
|
|
5
|
+
static STATE_MEMORY_ESTIMATE: number;
|
|
6
|
+
constructor(prog: any, maxMem?: number);
|
|
6
7
|
prog: any;
|
|
7
8
|
stateCache: Map<any, any>;
|
|
8
9
|
stateCount: number;
|
|
@@ -53,10 +54,12 @@ export class RE2Set {
|
|
|
53
54
|
* Constructs a new RE2Set with the specified anchor mode and flags.
|
|
54
55
|
* @param {number} [anchor=RE2Set.UNANCHORED] - The anchoring mode (e.g., RE2Set.UNANCHORED).
|
|
55
56
|
* @param {number} [flags=0] - The public flags to apply to all patterns in the set.
|
|
57
|
+
* @param {number} [maxMem=8388608] - The maximum memory in bytes to use for the DFA (default 8MB).
|
|
56
58
|
*/
|
|
57
|
-
constructor(anchor?: number, flags?: number);
|
|
59
|
+
constructor(anchor?: number, flags?: number, maxMem?: number);
|
|
58
60
|
anchor: number;
|
|
59
61
|
jsFlags: number;
|
|
62
|
+
maxMem: number;
|
|
60
63
|
re2Flags: number;
|
|
61
64
|
regexps: any[];
|
|
62
65
|
prog: Prog;
|
package/build/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
declare class DFA {
|
|
4
4
|
static MAX_CACHE_CLEARS: number;
|
|
5
|
-
|
|
5
|
+
static STATE_MEMORY_ESTIMATE: number;
|
|
6
|
+
constructor(prog: any, maxMem?: number);
|
|
6
7
|
prog: any;
|
|
7
8
|
stateCache: Map<any, any>;
|
|
8
9
|
stateCount: number;
|
|
@@ -53,10 +54,12 @@ export class RE2Set {
|
|
|
53
54
|
* Constructs a new RE2Set with the specified anchor mode and flags.
|
|
54
55
|
* @param {number} [anchor=RE2Set.UNANCHORED] - The anchoring mode (e.g., RE2Set.UNANCHORED).
|
|
55
56
|
* @param {number} [flags=0] - The public flags to apply to all patterns in the set.
|
|
57
|
+
* @param {number} [maxMem=8388608] - The maximum memory in bytes to use for the DFA (default 8MB).
|
|
56
58
|
*/
|
|
57
|
-
constructor(anchor?: number, flags?: number);
|
|
59
|
+
constructor(anchor?: number, flags?: number, maxMem?: number);
|
|
58
60
|
anchor: number;
|
|
59
61
|
jsFlags: number;
|
|
62
|
+
maxMem: number;
|
|
60
63
|
re2Flags: number;
|
|
61
64
|
regexps: any[];
|
|
62
65
|
prog: Prog;
|
package/build/index.js
CHANGED
|
@@ -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.8.
|
|
5
|
+
* @version v2.8.4
|
|
6
6
|
* @author Oleksii Vasyliev
|
|
7
7
|
* @homepage https://github.com/le0pard/re2js#readme
|
|
8
8
|
* @repository github:le0pard/re2js
|
|
@@ -56,7 +56,7 @@ for (let i = 0; i < ASCII_SIZE; i++) {
|
|
|
56
56
|
else ASCII_TO_LOWER[i] = i;
|
|
57
57
|
}
|
|
58
58
|
var Codepoint = class {
|
|
59
|
-
static CODES = new Map([
|
|
59
|
+
static CODES = /* @__PURE__ */ new Map([
|
|
60
60
|
["\x07", 7],
|
|
61
61
|
["\b", 8],
|
|
62
62
|
[" ", 9],
|
|
@@ -167,7 +167,7 @@ var UnicodeRangeTable = class {
|
|
|
167
167
|
};
|
|
168
168
|
//#endregion
|
|
169
169
|
//#region src/UnicodeTables.js
|
|
170
|
-
const B64_MAP = new Uint8Array(256);
|
|
170
|
+
const B64_MAP = /* @__PURE__ */ new Uint8Array(256);
|
|
171
171
|
for (let i = 0, b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-"; i < 64; i++) B64_MAP[b.charCodeAt(i)] = i;
|
|
172
172
|
const decodeVLQ = (str) => {
|
|
173
173
|
const res = [];
|
|
@@ -1250,6 +1250,8 @@ var Matcher = class Matcher {
|
|
|
1250
1250
|
*/
|
|
1251
1251
|
resetMatcherInput(input) {
|
|
1252
1252
|
if (input === null) throw new Error("input is null");
|
|
1253
|
+
if (!(input instanceof MatcherInputBase)) if (Utils.isByteArray(input)) input = MatcherInput.utf8(input);
|
|
1254
|
+
else input = MatcherInput.utf16(input);
|
|
1253
1255
|
this.matcherInput = input;
|
|
1254
1256
|
this.reset();
|
|
1255
1257
|
return this;
|
|
@@ -2207,12 +2209,13 @@ var DFAState = class {
|
|
|
2207
2209
|
};
|
|
2208
2210
|
var DFA = class DFA {
|
|
2209
2211
|
static MAX_CACHE_CLEARS = 5;
|
|
2210
|
-
|
|
2212
|
+
static STATE_MEMORY_ESTIMATE = 838;
|
|
2213
|
+
constructor(prog, maxMem = 8388608) {
|
|
2211
2214
|
this.prog = prog;
|
|
2212
2215
|
this.stateCache = /* @__PURE__ */ new Map();
|
|
2213
2216
|
this.stateCount = 0;
|
|
2214
2217
|
this.startState = null;
|
|
2215
|
-
this.stateLimit =
|
|
2218
|
+
this.stateLimit = Math.max(1, Math.floor(maxMem / DFA.STATE_MEMORY_ESTIMATE));
|
|
2216
2219
|
this.cacheClears = 0;
|
|
2217
2220
|
this.failed = false;
|
|
2218
2221
|
this.clock = 0;
|
|
@@ -2424,14 +2427,14 @@ const MAX_BACKTRACK_VECTOR = 256 * 1024;
|
|
|
2424
2427
|
var BitState = class {
|
|
2425
2428
|
constructor() {
|
|
2426
2429
|
this.end = 0;
|
|
2427
|
-
this.cap = new Int32Array(0);
|
|
2428
|
-
this.matchcap = new Int32Array(0);
|
|
2430
|
+
this.cap = /* @__PURE__ */ new Int32Array(0);
|
|
2431
|
+
this.matchcap = /* @__PURE__ */ new Int32Array(0);
|
|
2429
2432
|
this.ncap = 0;
|
|
2430
2433
|
this.jobPc = new Int32Array(INITIAL_JOB_CAPACITY);
|
|
2431
2434
|
this.jobArg = new Uint8Array(INITIAL_JOB_CAPACITY);
|
|
2432
2435
|
this.jobPos = new Int32Array(INITIAL_JOB_CAPACITY);
|
|
2433
2436
|
this.jobLen = 0;
|
|
2434
|
-
this.visited = new Uint32Array(0);
|
|
2437
|
+
this.visited = /* @__PURE__ */ new Uint32Array(0);
|
|
2435
2438
|
}
|
|
2436
2439
|
reset(prog, end, ncap) {
|
|
2437
2440
|
this.end = end;
|
|
@@ -3941,7 +3944,7 @@ const code3 = [
|
|
|
3941
3944
|
97,
|
|
3942
3945
|
122
|
|
3943
3946
|
];
|
|
3944
|
-
const PERL_GROUPS = new Map([
|
|
3947
|
+
const PERL_GROUPS = /* @__PURE__ */ new Map([
|
|
3945
3948
|
["\\d", new CharGroup(1, code1)],
|
|
3946
3949
|
["\\D", new CharGroup(-1, code1)],
|
|
3947
3950
|
["\\s", new CharGroup(1, code2)],
|
|
@@ -4015,7 +4018,7 @@ const code17 = [
|
|
|
4015
4018
|
97,
|
|
4016
4019
|
102
|
|
4017
4020
|
];
|
|
4018
|
-
const POSIX_GROUPS = new Map([
|
|
4021
|
+
const POSIX_GROUPS = /* @__PURE__ */ new Map([
|
|
4019
4022
|
["[:alnum:]", new CharGroup(1, code4)],
|
|
4020
4023
|
["[:^alnum:]", new CharGroup(-1, code4)],
|
|
4021
4024
|
["[:alpha:]", new CharGroup(1, code5)],
|
|
@@ -5899,10 +5902,12 @@ var RE2Set = class RE2Set {
|
|
|
5899
5902
|
* Constructs a new RE2Set with the specified anchor mode and flags.
|
|
5900
5903
|
* @param {number} [anchor=RE2Set.UNANCHORED] - The anchoring mode (e.g., RE2Set.UNANCHORED).
|
|
5901
5904
|
* @param {number} [flags=0] - The public flags to apply to all patterns in the set.
|
|
5905
|
+
* @param {number} [maxMem=8388608] - The maximum memory in bytes to use for the DFA (default 8MB).
|
|
5902
5906
|
*/
|
|
5903
|
-
constructor(anchor = RE2Set.UNANCHORED, flags = 0) {
|
|
5907
|
+
constructor(anchor = RE2Set.UNANCHORED, flags = 0, maxMem = 8388608) {
|
|
5904
5908
|
this.anchor = anchor;
|
|
5905
5909
|
this.jsFlags = flags;
|
|
5910
|
+
this.maxMem = maxMem;
|
|
5906
5911
|
let re2Flags = RE2Flags.PERL;
|
|
5907
5912
|
if ((flags & PublicFlags.DISABLE_UNICODE_GROUPS) !== 0) re2Flags &= ~RE2Flags.UNICODE_GROUPS;
|
|
5908
5913
|
if ((flags & PublicFlags.LOOKBEHINDS) !== 0) re2Flags |= RE2Flags.LOOKBEHIND;
|
|
@@ -5937,7 +5942,7 @@ var RE2Set = class RE2Set {
|
|
|
5937
5942
|
compile() {
|
|
5938
5943
|
if (this.prog) return;
|
|
5939
5944
|
this.prog = Compiler.compileSet(this.regexps);
|
|
5940
|
-
this.dfa = new DFA(this.prog);
|
|
5945
|
+
this.dfa = new DFA(this.prog, this.maxMem);
|
|
5941
5946
|
this.dummyRe2 = {
|
|
5942
5947
|
prog: this.prog,
|
|
5943
5948
|
cond: this.prog.startCond(),
|
package/build/index.umd.js
CHANGED
|
@@ -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.8.
|
|
5
|
+
* @version v2.8.4
|
|
6
6
|
* @author Oleksii Vasyliev
|
|
7
7
|
* @homepage https://github.com/le0pard/re2js#readme
|
|
8
8
|
* @repository github:le0pard/re2js
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
else ASCII_TO_LOWER[i] = i;
|
|
61
61
|
}
|
|
62
62
|
var Codepoint = class {
|
|
63
|
-
static CODES = new Map([
|
|
63
|
+
static CODES = /* @__PURE__ */ new Map([
|
|
64
64
|
["\x07", 7],
|
|
65
65
|
["\b", 8],
|
|
66
66
|
[" ", 9],
|
|
@@ -171,7 +171,7 @@
|
|
|
171
171
|
};
|
|
172
172
|
//#endregion
|
|
173
173
|
//#region src/UnicodeTables.js
|
|
174
|
-
const B64_MAP = new Uint8Array(256);
|
|
174
|
+
const B64_MAP = /* @__PURE__ */ new Uint8Array(256);
|
|
175
175
|
for (let i = 0, b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-"; i < 64; i++) B64_MAP[b.charCodeAt(i)] = i;
|
|
176
176
|
const decodeVLQ = (str) => {
|
|
177
177
|
const res = [];
|
|
@@ -1254,6 +1254,8 @@
|
|
|
1254
1254
|
*/
|
|
1255
1255
|
resetMatcherInput(input) {
|
|
1256
1256
|
if (input === null) throw new Error("input is null");
|
|
1257
|
+
if (!(input instanceof MatcherInputBase)) if (Utils.isByteArray(input)) input = MatcherInput.utf8(input);
|
|
1258
|
+
else input = MatcherInput.utf16(input);
|
|
1257
1259
|
this.matcherInput = input;
|
|
1258
1260
|
this.reset();
|
|
1259
1261
|
return this;
|
|
@@ -2211,12 +2213,13 @@
|
|
|
2211
2213
|
};
|
|
2212
2214
|
var DFA = class DFA {
|
|
2213
2215
|
static MAX_CACHE_CLEARS = 5;
|
|
2214
|
-
|
|
2216
|
+
static STATE_MEMORY_ESTIMATE = 838;
|
|
2217
|
+
constructor(prog, maxMem = 8388608) {
|
|
2215
2218
|
this.prog = prog;
|
|
2216
2219
|
this.stateCache = /* @__PURE__ */ new Map();
|
|
2217
2220
|
this.stateCount = 0;
|
|
2218
2221
|
this.startState = null;
|
|
2219
|
-
this.stateLimit =
|
|
2222
|
+
this.stateLimit = Math.max(1, Math.floor(maxMem / DFA.STATE_MEMORY_ESTIMATE));
|
|
2220
2223
|
this.cacheClears = 0;
|
|
2221
2224
|
this.failed = false;
|
|
2222
2225
|
this.clock = 0;
|
|
@@ -2428,14 +2431,14 @@
|
|
|
2428
2431
|
var BitState = class {
|
|
2429
2432
|
constructor() {
|
|
2430
2433
|
this.end = 0;
|
|
2431
|
-
this.cap = new Int32Array(0);
|
|
2432
|
-
this.matchcap = new Int32Array(0);
|
|
2434
|
+
this.cap = /* @__PURE__ */ new Int32Array(0);
|
|
2435
|
+
this.matchcap = /* @__PURE__ */ new Int32Array(0);
|
|
2433
2436
|
this.ncap = 0;
|
|
2434
2437
|
this.jobPc = new Int32Array(INITIAL_JOB_CAPACITY);
|
|
2435
2438
|
this.jobArg = new Uint8Array(INITIAL_JOB_CAPACITY);
|
|
2436
2439
|
this.jobPos = new Int32Array(INITIAL_JOB_CAPACITY);
|
|
2437
2440
|
this.jobLen = 0;
|
|
2438
|
-
this.visited = new Uint32Array(0);
|
|
2441
|
+
this.visited = /* @__PURE__ */ new Uint32Array(0);
|
|
2439
2442
|
}
|
|
2440
2443
|
reset(prog, end, ncap) {
|
|
2441
2444
|
this.end = end;
|
|
@@ -3945,7 +3948,7 @@
|
|
|
3945
3948
|
97,
|
|
3946
3949
|
122
|
|
3947
3950
|
];
|
|
3948
|
-
const PERL_GROUPS = new Map([
|
|
3951
|
+
const PERL_GROUPS = /* @__PURE__ */ new Map([
|
|
3949
3952
|
["\\d", new CharGroup(1, code1)],
|
|
3950
3953
|
["\\D", new CharGroup(-1, code1)],
|
|
3951
3954
|
["\\s", new CharGroup(1, code2)],
|
|
@@ -4019,7 +4022,7 @@
|
|
|
4019
4022
|
97,
|
|
4020
4023
|
102
|
|
4021
4024
|
];
|
|
4022
|
-
const POSIX_GROUPS = new Map([
|
|
4025
|
+
const POSIX_GROUPS = /* @__PURE__ */ new Map([
|
|
4023
4026
|
["[:alnum:]", new CharGroup(1, code4)],
|
|
4024
4027
|
["[:^alnum:]", new CharGroup(-1, code4)],
|
|
4025
4028
|
["[:alpha:]", new CharGroup(1, code5)],
|
|
@@ -5903,10 +5906,12 @@
|
|
|
5903
5906
|
* Constructs a new RE2Set with the specified anchor mode and flags.
|
|
5904
5907
|
* @param {number} [anchor=RE2Set.UNANCHORED] - The anchoring mode (e.g., RE2Set.UNANCHORED).
|
|
5905
5908
|
* @param {number} [flags=0] - The public flags to apply to all patterns in the set.
|
|
5909
|
+
* @param {number} [maxMem=8388608] - The maximum memory in bytes to use for the DFA (default 8MB).
|
|
5906
5910
|
*/
|
|
5907
|
-
constructor(anchor = RE2Set.UNANCHORED, flags = 0) {
|
|
5911
|
+
constructor(anchor = RE2Set.UNANCHORED, flags = 0, maxMem = 8388608) {
|
|
5908
5912
|
this.anchor = anchor;
|
|
5909
5913
|
this.jsFlags = flags;
|
|
5914
|
+
this.maxMem = maxMem;
|
|
5910
5915
|
let re2Flags = RE2Flags.PERL;
|
|
5911
5916
|
if ((flags & PublicFlags.DISABLE_UNICODE_GROUPS) !== 0) re2Flags &= ~RE2Flags.UNICODE_GROUPS;
|
|
5912
5917
|
if ((flags & PublicFlags.LOOKBEHINDS) !== 0) re2Flags |= RE2Flags.LOOKBEHIND;
|
|
@@ -5941,7 +5946,7 @@
|
|
|
5941
5946
|
compile() {
|
|
5942
5947
|
if (this.prog) return;
|
|
5943
5948
|
this.prog = Compiler.compileSet(this.regexps);
|
|
5944
|
-
this.dfa = new DFA(this.prog);
|
|
5949
|
+
this.dfa = new DFA(this.prog, this.maxMem);
|
|
5945
5950
|
this.dummyRe2 = {
|
|
5946
5951
|
prog: this.prog,
|
|
5947
5952
|
cond: this.prog.startCond(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "re2js",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.4",
|
|
4
4
|
"description": "RE2JS is the JavaScript port of RE2, a regular expression engine that provides linear time matching",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -56,24 +56,24 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@eslint/js": "^9.39.4",
|
|
59
|
-
"@unicode/unicode-17.0.0": "^1.6.
|
|
60
|
-
"@vitest/browser": "^4.1.
|
|
61
|
-
"@vitest/browser-playwright": "^4.1.
|
|
62
|
-
"@vitest/coverage-v8": "^4.1.
|
|
59
|
+
"@unicode/unicode-17.0.0": "^1.6.17",
|
|
60
|
+
"@vitest/browser": "^4.1.9",
|
|
61
|
+
"@vitest/browser-playwright": "^4.1.9",
|
|
62
|
+
"@vitest/coverage-v8": "^4.1.9",
|
|
63
63
|
"@yarnpkg/pnpify": "^4.1.6",
|
|
64
64
|
"dts-bundle-generator": "^9.5.1",
|
|
65
65
|
"eslint": "9.39.4",
|
|
66
66
|
"eslint-config-prettier": "^10.1.8",
|
|
67
|
-
"eslint-import-resolver-node": "^0.
|
|
67
|
+
"eslint-import-resolver-node": "^0.4.0",
|
|
68
68
|
"eslint-plugin-import": "^2.32.0",
|
|
69
|
-
"globals": "^17.
|
|
69
|
+
"globals": "^17.7.0",
|
|
70
70
|
"lodash": "^4.18.1",
|
|
71
|
-
"playwright": "^1.
|
|
72
|
-
"prettier": "^3.8.
|
|
73
|
-
"rolldown": "^1.
|
|
71
|
+
"playwright": "^1.61.1",
|
|
72
|
+
"prettier": "^3.8.4",
|
|
73
|
+
"rolldown": "^1.1.3",
|
|
74
74
|
"typescript": "^6.0.3",
|
|
75
75
|
"unicode-property-value-aliases": "^3.9.0",
|
|
76
|
-
"vitest": "^4.1.
|
|
76
|
+
"vitest": "^4.1.9"
|
|
77
77
|
},
|
|
78
|
-
"packageManager": "yarn@4.
|
|
78
|
+
"packageManager": "yarn@4.17.0"
|
|
79
79
|
}
|