@poe-platform/safe-js 0.1.195 → 0.1.196

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.
@@ -739,6 +739,7 @@ function measureNode(node) {
739
739
  return 3 + node.value.length;
740
740
  case "anchor":
741
741
  case "wordBoundary":
742
+ case "backreference":
742
743
  return 3;
743
744
  case "characterClass": {
744
745
  let usage = 5 + node.items.length;
@@ -2074,6 +2075,7 @@ var RegexParser = class {
2074
2075
  guard;
2075
2076
  captureCount = 0;
2076
2077
  cursor = 0;
2078
+ totalCaptureCount;
2077
2079
  get position() {
2078
2080
  return this.cursor;
2079
2081
  }
@@ -2267,8 +2269,29 @@ var RegexParser = class {
2267
2269
  this.fail("Trailing escape", start);
2268
2270
  }
2269
2271
  const escaped = this.take();
2270
- if (escaped >= "1" && escaped <= "9") {
2271
- this.fail("Backreferences are not supported", start);
2272
+ if (isDecimalDigit2(escaped)) {
2273
+ if (!inCharacterClass && escaped !== "0") {
2274
+ let end = this.position;
2275
+ let index = Number(escaped);
2276
+ while (isDecimalDigit2(this.source[end] ?? "")) {
2277
+ this.guard.work(1);
2278
+ index = index * 10 + Number(this.source[end++]);
2279
+ }
2280
+ this.totalCaptureCount ??= this.countAllCaptures();
2281
+ if (index <= this.totalCaptureCount) {
2282
+ this.position = end;
2283
+ this.guard.allocate(3);
2284
+ return { type: "backreference", index };
2285
+ }
2286
+ }
2287
+ this.guard.allocate(4);
2288
+ if (escaped === "8" || escaped === "9") return { type: "literal", value: escaped };
2289
+ let code = Number(escaped);
2290
+ const maximum = escaped <= "3" ? 3 : 2;
2291
+ for (let digits = 1; digits < maximum && this.peek() >= "0" && this.peek() <= "7"; digits++) {
2292
+ code = code * 8 + Number(this.take());
2293
+ }
2294
+ return { type: "literal", value: String.fromCharCode(code) };
2272
2295
  }
2273
2296
  if (escaped === "p" || escaped === "P") {
2274
2297
  this.fail("Unicode property escapes are not supported", start);
@@ -2324,6 +2347,21 @@ var RegexParser = class {
2324
2347
  this.position = end;
2325
2348
  return String.fromCharCode(Number.parseInt(digits, 16));
2326
2349
  }
2350
+ countAllCaptures() {
2351
+ let count = 0;
2352
+ let escaped = false;
2353
+ let characterClass = false;
2354
+ for (let index = 0; index < this.source.length; index++) {
2355
+ this.guard.work(1);
2356
+ const character = this.source[index];
2357
+ if (escaped) escaped = false;
2358
+ else if (character === "\\") escaped = true;
2359
+ else if (character === "[") characterClass = true;
2360
+ else if (character === "]") characterClass = false;
2361
+ else if (!characterClass && character === "(" && this.source[index + 1] !== "?") count++;
2362
+ }
2363
+ return count;
2364
+ }
2327
2365
  parseQuantifier() {
2328
2366
  const character = this.peek();
2329
2367
  if (character === "*") {
@@ -9351,6 +9389,22 @@ function* matchNode(node, state, context) {
9351
9389
  yield { ...state, position: state.position + context.direction };
9352
9390
  }
9353
9391
  return;
9392
+ case "backreference": {
9393
+ const capture = state.captures[node.index - 1];
9394
+ if (capture === void 0) {
9395
+ yield state;
9396
+ return;
9397
+ }
9398
+ const length = capture.end - capture.start;
9399
+ const start = context.direction === 1 ? state.position : state.position - length;
9400
+ if (start < 0 || start + length > context.input.length) return;
9401
+ for (let offset = 0; offset < length; offset++) {
9402
+ charge(context);
9403
+ if (!charactersEqual(context.input[start + offset], context.input[capture.start + offset], context.flags.ignoreCase)) return;
9404
+ }
9405
+ yield { ...state, position: state.position + context.direction * length };
9406
+ return;
9407
+ }
9354
9408
  case "dot":
9355
9409
  if (characterIndex >= 0 && characterIndex < context.input.length && (context.flags.dotAll || !isLineTerminator(context.input[characterIndex]))) {
9356
9410
  yield { ...state, position: state.position + context.direction };
@@ -37112,4 +37166,4 @@ export {
37112
37166
  FileSnapshotBackend,
37113
37167
  run
37114
37168
  };
37115
- //# sourceMappingURL=chunk-37QJBJ72.js.map
37169
+ //# sourceMappingURL=chunk-KMQUDIYF.js.map