@poe-platform/safe-js 0.1.198 → 0.1.200
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/dist/safe-js/chunks/{chunk-4WIZV3GZ.js → chunk-6HCV5BAA.js} +2 -2
- package/dist/safe-js/chunks/{chunk-T43UKNMF.js → chunk-OX7524JW.js} +314 -36
- package/dist/safe-js/chunks/chunk-OX7524JW.js.map +7 -0
- package/dist/safe-js/cli.js +2 -2
- package/dist/safe-js/core.js +1 -1
- package/dist/safe-js/index.js +2 -2
- package/dist/safe-js/interp/regex/parse.d.ts +21 -4
- package/package.json +2 -2
- package/dist/safe-js/chunks/chunk-T43UKNMF.js.map +0 -7
- /package/dist/safe-js/chunks/{chunk-4WIZV3GZ.js.map → chunk-6HCV5BAA.js.map} +0 -0
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
validateMigrationSemantics,
|
|
28
28
|
validateSnapshotData,
|
|
29
29
|
validateSnapshotMigration
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-OX7524JW.js";
|
|
31
31
|
|
|
32
32
|
// packages/safe-js/src/migrate.ts
|
|
33
33
|
import { createHash } from "node:crypto";
|
|
@@ -8249,4 +8249,4 @@ export {
|
|
|
8249
8249
|
parseMcpConfig,
|
|
8250
8250
|
makeMcpModule
|
|
8251
8251
|
};
|
|
8252
|
-
//# sourceMappingURL=chunk-
|
|
8252
|
+
//# sourceMappingURL=chunk-6HCV5BAA.js.map
|
|
@@ -753,8 +753,10 @@ function measureNode(node) {
|
|
|
753
753
|
return 3;
|
|
754
754
|
case "characterClass": {
|
|
755
755
|
let usage = 5 + node.items.length;
|
|
756
|
+
if (node.operation !== void 0) usage += 1 + node.operation.length;
|
|
757
|
+
if (node.strings !== void 0) usage += 1;
|
|
756
758
|
for (const item of node.items) {
|
|
757
|
-
usage += item.type === "character" ? 3 + item.value.length : item.type === "range" ? 4 + item.from.length + item.to.length : 4;
|
|
759
|
+
usage += item.type === "character" ? 3 + item.value.length : item.type === "range" ? 4 + item.from.length + item.to.length : item.type === "property" ? 4 + item.value.length + (item.strings === void 0 ? 0 : 1) : item.type === "set" ? 3 + measureNode({ type: "characterClass", ...item.value }) : item.type === "strings" ? 4 + item.values.reduce((total, value) => total + 1 + value.length, 0) : 4;
|
|
758
760
|
}
|
|
759
761
|
return usage;
|
|
760
762
|
}
|
|
@@ -2068,7 +2070,7 @@ function parseRegex(source, flags = "", compilation, valueUnits = 0) {
|
|
|
2068
2070
|
guard.checkLength(flags.length, true);
|
|
2069
2071
|
guard.allocate(5 + valueUnits);
|
|
2070
2072
|
const parsedFlags = parseFlags(flags, guard);
|
|
2071
|
-
const parser = new RegexParser(source, guard);
|
|
2073
|
+
const parser = new RegexParser(source, guard, parsedFlags.unicode || parsedFlags.unicodeSets, parsedFlags.unicodeSets);
|
|
2072
2074
|
const body = parser.parse();
|
|
2073
2075
|
guard.allocate(5 + source.length);
|
|
2074
2076
|
const pattern = { source, flags: parsedFlags, captureCount: parser.captureCount, body };
|
|
@@ -2080,12 +2082,16 @@ function parseRegex(source, flags = "", compilation, valueUnits = 0) {
|
|
|
2080
2082
|
}
|
|
2081
2083
|
}
|
|
2082
2084
|
var RegexParser = class {
|
|
2083
|
-
constructor(source, guard) {
|
|
2085
|
+
constructor(source, guard, unicode, unicodeSets) {
|
|
2084
2086
|
this.source = source;
|
|
2085
2087
|
this.guard = guard;
|
|
2088
|
+
this.unicode = unicode;
|
|
2089
|
+
this.unicodeSets = unicodeSets;
|
|
2086
2090
|
}
|
|
2087
2091
|
source;
|
|
2088
2092
|
guard;
|
|
2093
|
+
unicode;
|
|
2094
|
+
unicodeSets;
|
|
2089
2095
|
captureCount = 0;
|
|
2090
2096
|
cursor = 0;
|
|
2091
2097
|
totalCaptureCount;
|
|
@@ -2106,7 +2112,7 @@ var RegexParser = class {
|
|
|
2106
2112
|
}
|
|
2107
2113
|
this.fail(`Unexpected character '${this.peek()}'`);
|
|
2108
2114
|
}
|
|
2109
|
-
if (Object.keys(this.namedGroups).length > 0) this.validateNamedGroups(body);
|
|
2115
|
+
if (this.unicode || Object.keys(this.namedGroups).length > 0) this.validateNamedGroups(body);
|
|
2110
2116
|
return body;
|
|
2111
2117
|
}
|
|
2112
2118
|
parseAlternation() {
|
|
@@ -2148,7 +2154,7 @@ var RegexParser = class {
|
|
|
2148
2154
|
if (quantifier === void 0) {
|
|
2149
2155
|
return body;
|
|
2150
2156
|
}
|
|
2151
|
-
if (body.type === "anchor" || body.type === "wordBoundary" || body.type === "lookbehind") {
|
|
2157
|
+
if (body.type === "anchor" || body.type === "wordBoundary" || body.type === "lookbehind" || this.unicode && body.type === "lookahead") {
|
|
2152
2158
|
this.fail("Invalid quantifier target", quantifierStart);
|
|
2153
2159
|
}
|
|
2154
2160
|
const greedy = this.peek() !== "?";
|
|
@@ -2159,7 +2165,7 @@ var RegexParser = class {
|
|
|
2159
2165
|
return { type: "quantifier", body, ...quantifier, greedy };
|
|
2160
2166
|
}
|
|
2161
2167
|
parseAtom() {
|
|
2162
|
-
const character = this.
|
|
2168
|
+
const character = this.takeCharacter();
|
|
2163
2169
|
switch (character) {
|
|
2164
2170
|
case ".":
|
|
2165
2171
|
this.guard.allocate(2);
|
|
@@ -2177,6 +2183,7 @@ var RegexParser = class {
|
|
|
2177
2183
|
case "\\":
|
|
2178
2184
|
return this.parseEscape(false, this.position - 1);
|
|
2179
2185
|
default:
|
|
2186
|
+
if (this.unicode && (character === "]" || character === "}")) this.fail("Invalid Unicode pattern character");
|
|
2180
2187
|
this.guard.allocate(3 + character.length);
|
|
2181
2188
|
return { type: "literal", value: character };
|
|
2182
2189
|
}
|
|
@@ -2236,6 +2243,7 @@ var RegexParser = class {
|
|
|
2236
2243
|
return { type: "group", capturing, index, body, ...name === void 0 ? {} : { name } };
|
|
2237
2244
|
}
|
|
2238
2245
|
parseCharacterClass(start) {
|
|
2246
|
+
if (this.unicodeSets) return { type: "characterClass", ...this.parseUnicodeSet(start) };
|
|
2239
2247
|
const negated = this.peek() === "^";
|
|
2240
2248
|
if (negated) {
|
|
2241
2249
|
this.position += 1;
|
|
@@ -2257,7 +2265,7 @@ var RegexParser = class {
|
|
|
2257
2265
|
if (left.type !== "character" || right.type !== "character") {
|
|
2258
2266
|
this.fail("Character class ranges require literal endpoints", rangePosition);
|
|
2259
2267
|
}
|
|
2260
|
-
if (left.value.
|
|
2268
|
+
if (left.value.codePointAt(0) > right.value.codePointAt(0)) {
|
|
2261
2269
|
this.fail("Character class range is out of order", rangePosition);
|
|
2262
2270
|
}
|
|
2263
2271
|
this.guard.allocate(4 + left.value.length + right.value.length);
|
|
@@ -2286,7 +2294,96 @@ var RegexParser = class {
|
|
|
2286
2294
|
this.fail("Unsupported character class escape", escapeStart);
|
|
2287
2295
|
}
|
|
2288
2296
|
this.guard.allocate(4);
|
|
2289
|
-
return { type: "character", value: this.
|
|
2297
|
+
return { type: "character", value: this.takeCharacter() };
|
|
2298
|
+
}
|
|
2299
|
+
parseUnicodeSet(start) {
|
|
2300
|
+
this.guard.enterGroup();
|
|
2301
|
+
try {
|
|
2302
|
+
const negated = this.peek() === "^";
|
|
2303
|
+
if (negated) this.position++;
|
|
2304
|
+
this.guard.allocate(5);
|
|
2305
|
+
const items = [];
|
|
2306
|
+
let operation;
|
|
2307
|
+
while (!this.atEnd() && this.peek() !== "]") {
|
|
2308
|
+
this.guard.array(items.length + 1);
|
|
2309
|
+
let item = this.parseUnicodeSetItem(start);
|
|
2310
|
+
if (this.peek() === "-" && this.source[this.position + 1] !== "-") {
|
|
2311
|
+
this.position++;
|
|
2312
|
+
const right = this.parseUnicodeSetItem(start);
|
|
2313
|
+
if (item.type !== "character" || right.type !== "character") this.fail("Invalid set range", start);
|
|
2314
|
+
if (item.value.codePointAt(0) > right.value.codePointAt(0)) this.fail("Set range is out of order", start);
|
|
2315
|
+
this.guard.allocate(4 + item.value.length + right.value.length);
|
|
2316
|
+
item = { type: "range", from: item.value, to: right.value };
|
|
2317
|
+
}
|
|
2318
|
+
if (operation !== void 0 && item.type === "range") this.fail("Set operations require nested ranges", start);
|
|
2319
|
+
items.push(item);
|
|
2320
|
+
const operator = this.source.slice(this.position, this.position + 2);
|
|
2321
|
+
if (operator === "&&" || operator === "--") {
|
|
2322
|
+
const next = operator === "&&" ? "intersection" : "subtraction";
|
|
2323
|
+
if (operation === void 0 && (items.length !== 1 || item.type === "range") || operation !== void 0 && operation !== next) this.fail("Mixed set operations", start);
|
|
2324
|
+
if (operation === void 0) this.guard.allocate(1 + next.length);
|
|
2325
|
+
operation = next;
|
|
2326
|
+
this.position += 2;
|
|
2327
|
+
if (this.peek() === "]" || this.atEnd()) this.fail("Missing set operand", start);
|
|
2328
|
+
} else if (operation !== void 0 && this.peek() !== "]") this.fail("Missing set operator", start);
|
|
2329
|
+
}
|
|
2330
|
+
if (this.take() !== "]") this.fail("Unterminated character set", start);
|
|
2331
|
+
const mayContainStrings = (item) => {
|
|
2332
|
+
if (item.type === "set") return item.value.strings === true;
|
|
2333
|
+
if (item.type === "property") return item.strings === true;
|
|
2334
|
+
if (item.type === "strings") return item.values.some((value) => value.length !== ((value.codePointAt(0) ?? 0) > 65535 ? 2 : 1));
|
|
2335
|
+
return false;
|
|
2336
|
+
};
|
|
2337
|
+
const strings = operation === "intersection" ? items.every(mayContainStrings) : operation === "subtraction" ? mayContainStrings(items[0]) : items.some(mayContainStrings);
|
|
2338
|
+
if (negated && strings) this.fail("Cannot complement a set containing strings", start);
|
|
2339
|
+
if (strings) this.guard.allocate(1);
|
|
2340
|
+
return { negated, items, ...operation === void 0 ? {} : { operation }, ...strings ? { strings: true } : {} };
|
|
2341
|
+
} finally {
|
|
2342
|
+
this.guard.leaveGroup();
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
parseUnicodeSetItem(start) {
|
|
2346
|
+
if (this.peek() === "[") {
|
|
2347
|
+
this.position++;
|
|
2348
|
+
this.guard.allocate(3);
|
|
2349
|
+
return { type: "set", value: this.parseUnicodeSet(start) };
|
|
2350
|
+
}
|
|
2351
|
+
if (this.source.startsWith("\\q{", this.position)) {
|
|
2352
|
+
this.position += 3;
|
|
2353
|
+
this.guard.allocate(4);
|
|
2354
|
+
const values = [];
|
|
2355
|
+
let value2 = "";
|
|
2356
|
+
while (!this.atEnd()) {
|
|
2357
|
+
if (this.peek() === "|" || this.peek() === "}") {
|
|
2358
|
+
this.guard.array(values.length + 1);
|
|
2359
|
+
this.guard.allocate(1);
|
|
2360
|
+
values.push(value2);
|
|
2361
|
+
value2 = "";
|
|
2362
|
+
if (this.take() === "}") return { type: "strings", values };
|
|
2363
|
+
} else {
|
|
2364
|
+
const item = this.parseSetCharacter(start);
|
|
2365
|
+
this.guard.allocate(item.length);
|
|
2366
|
+
value2 += item;
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
this.fail("Unterminated class string", start);
|
|
2370
|
+
}
|
|
2371
|
+
if (this.peek() === "\\") return this.parseClassItem(start);
|
|
2372
|
+
const value = this.parseSetCharacter(start);
|
|
2373
|
+
this.guard.allocate(3 + value.length);
|
|
2374
|
+
return { type: "character", value };
|
|
2375
|
+
}
|
|
2376
|
+
parseSetCharacter(start) {
|
|
2377
|
+
if (this.peek() === "\\") {
|
|
2378
|
+
this.position++;
|
|
2379
|
+
const node = this.parseEscape(true, start);
|
|
2380
|
+
if (node.type !== "literal") this.fail("Class strings require literal characters", start);
|
|
2381
|
+
return node.value;
|
|
2382
|
+
}
|
|
2383
|
+
const character = this.takeCharacter();
|
|
2384
|
+
if (!character || "()[]{}/-|".includes(character) || "!#$%&*+,.:;<=>?@^`~".includes(character) && this.peek() === character)
|
|
2385
|
+
this.fail("Invalid character in Unicode set", start);
|
|
2386
|
+
return character;
|
|
2290
2387
|
}
|
|
2291
2388
|
parseEscape(inCharacterClass, start) {
|
|
2292
2389
|
if (this.atEnd()) {
|
|
@@ -2295,7 +2392,7 @@ var RegexParser = class {
|
|
|
2295
2392
|
const escaped = this.take();
|
|
2296
2393
|
if (escaped === "k") {
|
|
2297
2394
|
this.totalCaptureCount ??= this.countAllCaptures();
|
|
2298
|
-
if (this.hasNamedCaptures) {
|
|
2395
|
+
if (this.unicode || this.hasNamedCaptures) {
|
|
2299
2396
|
if (inCharacterClass || this.take() !== "<") this.fail("Invalid named backreference", start);
|
|
2300
2397
|
const name = this.parseGroupName(start);
|
|
2301
2398
|
this.guard.allocate(3 + name.length);
|
|
@@ -2317,6 +2414,8 @@ var RegexParser = class {
|
|
|
2317
2414
|
return { type: "backreference", index };
|
|
2318
2415
|
}
|
|
2319
2416
|
}
|
|
2417
|
+
if (this.unicode && (escaped !== "0" || isDecimalDigit2(this.peek())))
|
|
2418
|
+
this.fail("Invalid decimal escape", start);
|
|
2320
2419
|
this.guard.allocate(4);
|
|
2321
2420
|
if (escaped === "8" || escaped === "9") return { type: "literal", value: escaped };
|
|
2322
2421
|
let code = Number(escaped);
|
|
@@ -2327,7 +2426,32 @@ var RegexParser = class {
|
|
|
2327
2426
|
return { type: "literal", value: String.fromCharCode(code) };
|
|
2328
2427
|
}
|
|
2329
2428
|
if (escaped === "p" || escaped === "P") {
|
|
2330
|
-
this.fail("Unicode property escapes are not supported", start);
|
|
2429
|
+
if (!this.unicode) this.fail("Unicode property escapes are not supported", start);
|
|
2430
|
+
if (this.take() !== "{") this.fail("Invalid Unicode property escape", start);
|
|
2431
|
+
const begin = this.position;
|
|
2432
|
+
while (!this.atEnd() && this.peek() !== "}") {
|
|
2433
|
+
const character = this.take();
|
|
2434
|
+
if (!isDecimalDigit2(character) && !(character >= "a" && character <= "z") && !(character >= "A" && character <= "Z") && character !== "_" && character !== "=")
|
|
2435
|
+
this.fail("Invalid Unicode property escape", start);
|
|
2436
|
+
}
|
|
2437
|
+
this.guard.allocate(this.position - begin + 9);
|
|
2438
|
+
const value = this.source.slice(begin, this.position);
|
|
2439
|
+
if (this.take() !== "}") this.fail("Unterminated Unicode property escape", start);
|
|
2440
|
+
try {
|
|
2441
|
+
new RegExp(`\\${escaped}{${value}}`, this.unicodeSets ? "v" : "u");
|
|
2442
|
+
} catch {
|
|
2443
|
+
this.fail("Unknown Unicode property", start);
|
|
2444
|
+
}
|
|
2445
|
+
let strings = false;
|
|
2446
|
+
if (this.unicodeSets) {
|
|
2447
|
+
try {
|
|
2448
|
+
new RegExp(`\\p{${value}}`, "u");
|
|
2449
|
+
} catch {
|
|
2450
|
+
strings = true;
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
this.guard.array(1);
|
|
2454
|
+
return { type: "characterClass", negated: false, items: [{ type: "property", value, negated: escaped === "P", ...strings ? { strings: true } : {} }] };
|
|
2331
2455
|
}
|
|
2332
2456
|
if (escaped === "x") {
|
|
2333
2457
|
this.guard.allocate(4);
|
|
@@ -2335,7 +2459,29 @@ var RegexParser = class {
|
|
|
2335
2459
|
}
|
|
2336
2460
|
if (escaped === "u") {
|
|
2337
2461
|
this.guard.allocate(4);
|
|
2338
|
-
|
|
2462
|
+
if (this.unicode && this.peek() === "{") {
|
|
2463
|
+
this.position++;
|
|
2464
|
+
const begin = this.position;
|
|
2465
|
+
while (!this.atEnd() && this.peek() !== "}") this.position++;
|
|
2466
|
+
this.guard.allocate(this.position - begin);
|
|
2467
|
+
const digits = this.source.slice(begin, this.position);
|
|
2468
|
+
const point = Number.parseInt(digits, 16);
|
|
2469
|
+
if (this.take() !== "}" || digits.length === 0 || !allHexDigits(digits) || point > 1114111)
|
|
2470
|
+
this.fail("Invalid Unicode escape", start);
|
|
2471
|
+
return { type: "literal", value: String.fromCodePoint(point) };
|
|
2472
|
+
}
|
|
2473
|
+
let value = this.parseHexEscape(4, "Unicode", start);
|
|
2474
|
+
if (this.unicode && value.charCodeAt(0) >= 55296 && value.charCodeAt(0) <= 56319 && this.source.startsWith("\\u", this.position)) {
|
|
2475
|
+
const digits = this.source.slice(this.position + 2, this.position + 6);
|
|
2476
|
+
const point = Number.parseInt(digits, 16);
|
|
2477
|
+
this.guard.work(digits.length);
|
|
2478
|
+
this.guard.allocate(digits.length);
|
|
2479
|
+
if (digits.length === 4 && allHexDigits(digits) && point >= 56320 && point <= 57343) {
|
|
2480
|
+
value += String.fromCharCode(point);
|
|
2481
|
+
this.position += 6;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
return { type: "literal", value };
|
|
2339
2485
|
}
|
|
2340
2486
|
this.guard.allocate(25);
|
|
2341
2487
|
const kinds = {
|
|
@@ -2366,6 +2512,15 @@ var RegexParser = class {
|
|
|
2366
2512
|
v: "\v",
|
|
2367
2513
|
"0": "\0"
|
|
2368
2514
|
};
|
|
2515
|
+
if (escaped === "c" && this.unicode) {
|
|
2516
|
+
const letter = this.take();
|
|
2517
|
+
if (!(letter >= "a" && letter <= "z") && !(letter >= "A" && letter <= "Z"))
|
|
2518
|
+
this.fail("Invalid control escape", start);
|
|
2519
|
+
this.guard.allocate(4);
|
|
2520
|
+
return { type: "literal", value: String.fromCharCode(letter.charCodeAt(0) % 32) };
|
|
2521
|
+
}
|
|
2522
|
+
if (this.unicode && controls[escaped] === void 0 && !"^$\\.*+?()[]{}|/".includes(escaped) && !(inCharacterClass && (escaped === "-" || this.unicodeSets && "!#$%&+,.:;<=>?@`~".includes(escaped))))
|
|
2523
|
+
this.fail("Invalid identity escape", start);
|
|
2369
2524
|
this.guard.allocate(4);
|
|
2370
2525
|
return { type: "literal", value: controls[escaped] ?? escaped };
|
|
2371
2526
|
}
|
|
@@ -2518,6 +2673,12 @@ var RegexParser = class {
|
|
|
2518
2673
|
this.position += 1;
|
|
2519
2674
|
return character;
|
|
2520
2675
|
}
|
|
2676
|
+
takeCharacter() {
|
|
2677
|
+
if (!this.unicode || this.atEnd()) return this.take();
|
|
2678
|
+
const character = String.fromCodePoint(this.source.codePointAt(this.position));
|
|
2679
|
+
this.position += character.length;
|
|
2680
|
+
return character;
|
|
2681
|
+
}
|
|
2521
2682
|
atEnd() {
|
|
2522
2683
|
return this.position >= this.source.length;
|
|
2523
2684
|
}
|
|
@@ -2531,6 +2692,8 @@ function parseFlags(flags, guard) {
|
|
|
2531
2692
|
hasIndices: false,
|
|
2532
2693
|
global: false,
|
|
2533
2694
|
sticky: false,
|
|
2695
|
+
unicode: false,
|
|
2696
|
+
unicodeSets: false,
|
|
2534
2697
|
ignoreCase: false,
|
|
2535
2698
|
multiline: false,
|
|
2536
2699
|
dotAll: false
|
|
@@ -2541,7 +2704,9 @@ function parseFlags(flags, guard) {
|
|
|
2541
2704
|
i: "ignoreCase",
|
|
2542
2705
|
m: "multiline",
|
|
2543
2706
|
s: "dotAll",
|
|
2544
|
-
y: "sticky"
|
|
2707
|
+
y: "sticky",
|
|
2708
|
+
u: "unicode",
|
|
2709
|
+
v: "unicodeSets"
|
|
2545
2710
|
};
|
|
2546
2711
|
for (let position = 0; position < flags.length; position += 1) {
|
|
2547
2712
|
guard.work(1);
|
|
@@ -2555,6 +2720,7 @@ function parseFlags(flags, guard) {
|
|
|
2555
2720
|
}
|
|
2556
2721
|
parsed[name] = true;
|
|
2557
2722
|
}
|
|
2723
|
+
if (parsed.unicode && parsed.unicodeSets) throw new SyntaxError("Unicode flags u and v cannot be combined");
|
|
2558
2724
|
return parsed;
|
|
2559
2725
|
}
|
|
2560
2726
|
function isDecimalDigit2(character) {
|
|
@@ -9457,7 +9623,9 @@ function matchRegexFrom(pattern, input, startIndex) {
|
|
|
9457
9623
|
if (startIndex > input.length) {
|
|
9458
9624
|
return null;
|
|
9459
9625
|
}
|
|
9460
|
-
|
|
9626
|
+
const unicode = pattern.flags.unicode || pattern.flags.unicodeSets;
|
|
9627
|
+
if (unicode && startIndex > 0 && startIndex < input.length && input.charCodeAt(startIndex) >= 56320 && input.charCodeAt(startIndex) <= 57343 && input.charCodeAt(startIndex - 1) >= 55296 && input.charCodeAt(startIndex - 1) <= 56319) startIndex--;
|
|
9628
|
+
for (let attempt = startIndex; attempt <= input.length; attempt = advanceStringIndex(input, attempt, unicode)) {
|
|
9461
9629
|
const context = { input, flags: pattern.flags, groups: pattern.groups, direction: 1, work: { steps: 0 } };
|
|
9462
9630
|
charge(context);
|
|
9463
9631
|
const initialState = {
|
|
@@ -9474,14 +9642,15 @@ function matchRegexFrom(pattern, input, startIndex) {
|
|
|
9474
9642
|
}
|
|
9475
9643
|
function* matchNode(node, state, context) {
|
|
9476
9644
|
charge(context);
|
|
9477
|
-
const
|
|
9645
|
+
const unicode = context.flags.unicode || context.flags.unicodeSets;
|
|
9646
|
+
const character = readCharacter(context.input, state.position, context.direction, unicode);
|
|
9478
9647
|
switch (node.type) {
|
|
9479
9648
|
case "empty":
|
|
9480
9649
|
yield state;
|
|
9481
9650
|
return;
|
|
9482
9651
|
case "literal":
|
|
9483
|
-
if (charactersEqual(
|
|
9484
|
-
yield { ...state, position: state.position + context.direction };
|
|
9652
|
+
if (charactersEqual(character, node.value, context.flags.ignoreCase, unicode)) {
|
|
9653
|
+
yield { ...state, position: state.position + context.direction * character.length };
|
|
9485
9654
|
}
|
|
9486
9655
|
return;
|
|
9487
9656
|
case "backreference":
|
|
@@ -9501,19 +9670,23 @@ function* matchNode(node, state, context) {
|
|
|
9501
9670
|
yield state;
|
|
9502
9671
|
return;
|
|
9503
9672
|
}
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9673
|
+
let position = state.position;
|
|
9674
|
+
let reference = context.direction === 1 ? capture.start : capture.end;
|
|
9675
|
+
const end = context.direction === 1 ? capture.end : capture.start;
|
|
9676
|
+
while (reference !== end) {
|
|
9508
9677
|
charge(context);
|
|
9509
|
-
|
|
9678
|
+
const expected = readCharacter(context.input, reference, context.direction, unicode);
|
|
9679
|
+
const actual = readCharacter(context.input, position, context.direction, unicode);
|
|
9680
|
+
if (!charactersEqual(actual, expected, context.flags.ignoreCase, unicode)) return;
|
|
9681
|
+
reference += context.direction * expected.length;
|
|
9682
|
+
position += context.direction * actual.length;
|
|
9510
9683
|
}
|
|
9511
|
-
yield { ...state, position
|
|
9684
|
+
yield { ...state, position };
|
|
9512
9685
|
return;
|
|
9513
9686
|
}
|
|
9514
9687
|
case "dot":
|
|
9515
|
-
if (
|
|
9516
|
-
yield { ...state, position: state.position + context.direction };
|
|
9688
|
+
if (character !== void 0 && (context.flags.dotAll || !isLineTerminator(character))) {
|
|
9689
|
+
yield { ...state, position: state.position + context.direction * character.length };
|
|
9517
9690
|
}
|
|
9518
9691
|
return;
|
|
9519
9692
|
case "anchor":
|
|
@@ -9522,17 +9695,24 @@ function* matchNode(node, state, context) {
|
|
|
9522
9695
|
}
|
|
9523
9696
|
return;
|
|
9524
9697
|
case "wordBoundary": {
|
|
9525
|
-
const previousWord = state.position > 0 &&
|
|
9526
|
-
const nextWord = state.position < context.input.length &&
|
|
9698
|
+
const previousWord = state.position > 0 && matchesCharacterClassItem(context.input[state.position - 1], { type: "kind", kind: "word", negated: false }, context.flags.ignoreCase, unicode);
|
|
9699
|
+
const nextWord = state.position < context.input.length && matchesCharacterClassItem(context.input[state.position], { type: "kind", kind: "word", negated: false }, context.flags.ignoreCase, unicode);
|
|
9527
9700
|
if (previousWord !== nextWord !== node.negated) {
|
|
9528
9701
|
yield state;
|
|
9529
9702
|
}
|
|
9530
9703
|
return;
|
|
9531
9704
|
}
|
|
9532
9705
|
case "characterClass": {
|
|
9533
|
-
|
|
9534
|
-
|
|
9535
|
-
|
|
9706
|
+
if (context.flags.unicodeSets) {
|
|
9707
|
+
const lengths = [...matchUnicodeSet(node, state.position, context)].sort((a, b) => b - a);
|
|
9708
|
+
for (const length of lengths) {
|
|
9709
|
+
charge(context);
|
|
9710
|
+
yield { ...state, position: state.position + context.direction * length };
|
|
9711
|
+
}
|
|
9712
|
+
return;
|
|
9713
|
+
}
|
|
9714
|
+
if (character !== void 0 && matchesCharacterClass(character, node.items, node.negated, context)) {
|
|
9715
|
+
yield { ...state, position: state.position + context.direction * character.length };
|
|
9536
9716
|
}
|
|
9537
9717
|
return;
|
|
9538
9718
|
}
|
|
@@ -9615,11 +9795,28 @@ function matchesAnchor(kind, position, context) {
|
|
|
9615
9795
|
}
|
|
9616
9796
|
return position === context.input.length || context.flags.multiline && position < context.input.length && isLineTerminator(context.input[position]);
|
|
9617
9797
|
}
|
|
9618
|
-
function matchesCharacterClass(character, items, negated,
|
|
9619
|
-
const matched = items.some((item) =>
|
|
9798
|
+
function matchesCharacterClass(character, items, negated, context) {
|
|
9799
|
+
const matched = items.some((item) => {
|
|
9800
|
+
if (context.flags.unicode) charge(context);
|
|
9801
|
+
return matchesCharacterClassItem(character, item, context.flags.ignoreCase, context.flags.unicode);
|
|
9802
|
+
});
|
|
9620
9803
|
return negated ? !matched : matched;
|
|
9621
9804
|
}
|
|
9622
|
-
function matchesCharacterClassItem(character, item, ignoreCase) {
|
|
9805
|
+
function matchesCharacterClassItem(character, item, ignoreCase, unicode, unicodeSets = false) {
|
|
9806
|
+
if (item.type === "strings" || item.type === "set") return false;
|
|
9807
|
+
if (unicode) {
|
|
9808
|
+
const hex = (value) => `\\u{${value.codePointAt(0).toString(16)}}`;
|
|
9809
|
+
let atom;
|
|
9810
|
+
if (item.type === "character") atom = hex(item.value);
|
|
9811
|
+
else if (item.type === "range") atom = `[${hex(item.from)}-${hex(item.to)}]`;
|
|
9812
|
+
else if (item.type === "property") atom = `\\${item.negated ? "P" : "p"}{${item.value}}`;
|
|
9813
|
+
else {
|
|
9814
|
+
const kind = item.kind === "digit" ? "d" : item.kind === "word" ? "w" : "s";
|
|
9815
|
+
atom = `\\${item.negated ? kind.toUpperCase() : kind}`;
|
|
9816
|
+
}
|
|
9817
|
+
return new RegExp(`^(?:${atom})$`, (ignoreCase ? "i" : "") + (unicodeSets ? "v" : "u")).test(character);
|
|
9818
|
+
}
|
|
9819
|
+
if (item.type === "property") return false;
|
|
9623
9820
|
if (item.type === "character") {
|
|
9624
9821
|
return charactersEqual(character, item.value, ignoreCase);
|
|
9625
9822
|
}
|
|
@@ -9641,6 +9838,76 @@ function matchesCharacterClassItem(character, item, ignoreCase) {
|
|
|
9641
9838
|
const matched = item.kind === "digit" ? isDigit(character) : item.kind === "word" ? isWordCharacter(character) : isSpaceCharacter(character);
|
|
9642
9839
|
return item.negated ? !matched : matched;
|
|
9643
9840
|
}
|
|
9841
|
+
function matchUnicodeSet(set, position, context) {
|
|
9842
|
+
charge(context);
|
|
9843
|
+
let lengths = /* @__PURE__ */ new Set();
|
|
9844
|
+
for (let index = 0; index < set.items.length; index++) {
|
|
9845
|
+
const next = matchUnicodeSetItem(set.items[index], position, context);
|
|
9846
|
+
if (index === 0) lengths = next;
|
|
9847
|
+
else if (set.operation === void 0) {
|
|
9848
|
+
for (const length of next) {
|
|
9849
|
+
charge(context);
|
|
9850
|
+
lengths.add(length);
|
|
9851
|
+
}
|
|
9852
|
+
} else {
|
|
9853
|
+
for (const length of lengths) {
|
|
9854
|
+
charge(context);
|
|
9855
|
+
if (set.operation === "intersection" ? !next.has(length) : next.has(length)) lengths.delete(length);
|
|
9856
|
+
}
|
|
9857
|
+
}
|
|
9858
|
+
}
|
|
9859
|
+
if (set.negated) {
|
|
9860
|
+
const character = readCharacter(context.input, position, context.direction, true);
|
|
9861
|
+
return new Set(character !== void 0 && !lengths.has(character.length) ? [character.length] : []);
|
|
9862
|
+
}
|
|
9863
|
+
return lengths;
|
|
9864
|
+
}
|
|
9865
|
+
function matchUnicodeSetItem(item, position, context) {
|
|
9866
|
+
charge(context);
|
|
9867
|
+
if (item.type === "set") return matchUnicodeSet(item.value, position, context);
|
|
9868
|
+
const lengths = /* @__PURE__ */ new Set();
|
|
9869
|
+
if (item.type === "strings") {
|
|
9870
|
+
for (const value of item.values) {
|
|
9871
|
+
charge(context);
|
|
9872
|
+
let reference = context.direction === 1 ? 0 : value.length;
|
|
9873
|
+
let cursor = position;
|
|
9874
|
+
const end = context.direction === 1 ? value.length : 0;
|
|
9875
|
+
while (reference !== end) {
|
|
9876
|
+
charge(context);
|
|
9877
|
+
const expected = readCharacter(value, reference, context.direction, true);
|
|
9878
|
+
const actual = readCharacter(context.input, cursor, context.direction, true);
|
|
9879
|
+
if (!charactersEqual(actual, expected, context.flags.ignoreCase, true)) break;
|
|
9880
|
+
reference += context.direction * expected.length;
|
|
9881
|
+
cursor += context.direction * actual.length;
|
|
9882
|
+
}
|
|
9883
|
+
if (reference === end) lengths.add(Math.abs(cursor - position));
|
|
9884
|
+
}
|
|
9885
|
+
return lengths;
|
|
9886
|
+
}
|
|
9887
|
+
if (item.type === "property" && item.strings) {
|
|
9888
|
+
const atom = `\\p{${item.value}}`;
|
|
9889
|
+
const flags = (context.flags.ignoreCase ? "i" : "") + "v";
|
|
9890
|
+
const matcher = new RegExp(context.direction === 1 ? atom : `(?<=(${atom}))`, flags + "y");
|
|
9891
|
+
matcher.lastIndex = position;
|
|
9892
|
+
const match = matcher.exec(context.input);
|
|
9893
|
+
if (match === null) return lengths;
|
|
9894
|
+
const longest = context.direction === 1 ? match[0] : match[1];
|
|
9895
|
+
const member = new RegExp(`^(?:${atom})$`, flags);
|
|
9896
|
+
let consumed = 0;
|
|
9897
|
+
while (consumed < longest.length) {
|
|
9898
|
+
charge(context);
|
|
9899
|
+
const cursor = context.direction === 1 ? consumed : longest.length - consumed;
|
|
9900
|
+
consumed += readCharacter(longest, cursor, context.direction, true).length;
|
|
9901
|
+
const candidate = context.direction === 1 ? longest.slice(0, consumed) : longest.slice(longest.length - consumed);
|
|
9902
|
+
if (member.test(candidate)) lengths.add(consumed);
|
|
9903
|
+
}
|
|
9904
|
+
return lengths;
|
|
9905
|
+
}
|
|
9906
|
+
const character = readCharacter(context.input, position, context.direction, true);
|
|
9907
|
+
if (character !== void 0 && matchesCharacterClassItem(character, item, context.flags.ignoreCase, true, true))
|
|
9908
|
+
lengths.add(character.length);
|
|
9909
|
+
return lengths;
|
|
9910
|
+
}
|
|
9644
9911
|
function toRegexMatch(input, start, state, hasIndices, groups) {
|
|
9645
9912
|
const match = {
|
|
9646
9913
|
index: start,
|
|
@@ -9705,9 +9972,20 @@ function normalizeLastIndex(lastIndex) {
|
|
|
9705
9972
|
}
|
|
9706
9973
|
return Math.min(Math.floor(lastIndex), Number.MAX_SAFE_INTEGER);
|
|
9707
9974
|
}
|
|
9708
|
-
function charactersEqual(left, right, ignoreCase) {
|
|
9975
|
+
function charactersEqual(left, right, ignoreCase, unicode = false) {
|
|
9976
|
+
if (unicode && ignoreCase && left !== void 0)
|
|
9977
|
+
return new RegExp(`^\\u{${right.codePointAt(0).toString(16)}}$`, "iu").test(left);
|
|
9709
9978
|
return left !== void 0 && foldCharacter(left, ignoreCase) === foldCharacter(right, ignoreCase);
|
|
9710
9979
|
}
|
|
9980
|
+
function advanceStringIndex(input, index, unicode) {
|
|
9981
|
+
return index + (unicode && (input.codePointAt(index) ?? 0) > 65535 ? 2 : 1);
|
|
9982
|
+
}
|
|
9983
|
+
function readCharacter(input, position, direction, unicode) {
|
|
9984
|
+
let index = direction === 1 ? position : position - 1;
|
|
9985
|
+
if (index < 0 || index >= input.length) return void 0;
|
|
9986
|
+
if (unicode && direction === -1 && index > 0 && input.charCodeAt(index) >= 56320 && input.charCodeAt(index) <= 57343 && input.charCodeAt(index - 1) >= 55296 && input.charCodeAt(index - 1) <= 56319) index--;
|
|
9987
|
+
return unicode ? String.fromCodePoint(input.codePointAt(index)) : input[index];
|
|
9988
|
+
}
|
|
9711
9989
|
function foldCharacter(character, ignoreCase) {
|
|
9712
9990
|
if (!ignoreCase) {
|
|
9713
9991
|
return character;
|
|
@@ -10548,7 +10826,7 @@ function splitNormalized(value, separator, limit, budget, parent) {
|
|
|
10548
10826
|
while (result2.length < limit) {
|
|
10549
10827
|
const match = executeRegex(splitter, value, Number(splitter.lastIndex));
|
|
10550
10828
|
if (match === null) break;
|
|
10551
|
-
if (match.text.length === 0) splitter.lastIndex = match.index
|
|
10829
|
+
if (match.text.length === 0) splitter.lastIndex = advanceStringIndex(value, match.index, splitter.flags.includes("u") || splitter.flags.includes("v"));
|
|
10552
10830
|
endedWithZeroWidthMatch = match.text.length === 0 && match.index === value.length;
|
|
10553
10831
|
if (match.text.length === 0 && (match.index === copiedThrough || match.index === value.length))
|
|
10554
10832
|
continue;
|
|
@@ -10723,7 +11001,7 @@ function collectRegexMatches(regex, value, all, budget, lastIndex = 0) {
|
|
|
10723
11001
|
budget?.allocateArrayLength(matches.length + 1);
|
|
10724
11002
|
matches.push(match);
|
|
10725
11003
|
lastIndex = match.index + match.text.length;
|
|
10726
|
-
if (all && match.text.length === 0) regex.lastIndex =
|
|
11004
|
+
if (all && match.text.length === 0) regex.lastIndex = lastIndex = advanceStringIndex(value, lastIndex, regex.flags.includes("u") || regex.flags.includes("v"));
|
|
10727
11005
|
} while (all);
|
|
10728
11006
|
return matches;
|
|
10729
11007
|
}
|
|
@@ -37289,4 +37567,4 @@ export {
|
|
|
37289
37567
|
FileSnapshotBackend,
|
|
37290
37568
|
run
|
|
37291
37569
|
};
|
|
37292
|
-
//# sourceMappingURL=chunk-
|
|
37570
|
+
//# sourceMappingURL=chunk-OX7524JW.js.map
|