@poe-platform/safe-js 0.1.193 → 0.1.195

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.
@@ -756,6 +756,9 @@ function measureNode(node) {
756
756
  }
757
757
  case "group":
758
758
  return 5 + measureNode(node.body);
759
+ case "lookahead":
760
+ case "lookbehind":
761
+ return 4 + measureNode(node.body);
759
762
  case "quantifier":
760
763
  return (Object.hasOwn(node, "max") ? 6 : 5) + measureNode(node.body);
761
764
  }
@@ -2127,7 +2130,7 @@ var RegexParser = class {
2127
2130
  if (quantifier === void 0) {
2128
2131
  return body;
2129
2132
  }
2130
- if (body.type === "anchor" || body.type === "wordBoundary") {
2133
+ if (body.type === "anchor" || body.type === "wordBoundary" || body.type === "lookbehind") {
2131
2134
  this.fail("Invalid quantifier target", quantifierStart);
2132
2135
  }
2133
2136
  const greedy = this.peek() !== "?";
@@ -2162,6 +2165,8 @@ var RegexParser = class {
2162
2165
  }
2163
2166
  parseGroup(start) {
2164
2167
  let capturing = true;
2168
+ let assertionNegated;
2169
+ let lookbehind = false;
2165
2170
  if (this.peek() === "?") {
2166
2171
  this.guard.allocate(Math.min(3, this.source.length - this.position));
2167
2172
  this.guard.work(Math.min(3, this.source.length - this.position));
@@ -2170,9 +2175,14 @@ var RegexParser = class {
2170
2175
  capturing = false;
2171
2176
  this.position += 2;
2172
2177
  } else if (extension.startsWith("?=") || extension.startsWith("?!")) {
2173
- this.fail("Lookahead is not supported", start);
2178
+ capturing = false;
2179
+ assertionNegated = extension.startsWith("?!");
2180
+ this.position += 2;
2174
2181
  } else if (extension.startsWith("?<=") || extension.startsWith("?<!")) {
2175
- this.fail("Lookbehind is not supported", start);
2182
+ capturing = false;
2183
+ assertionNegated = extension.startsWith("?<!");
2184
+ lookbehind = true;
2185
+ this.position += 3;
2176
2186
  } else if (extension.startsWith("?<")) {
2177
2187
  this.fail("Named groups are not supported", start);
2178
2188
  } else {
@@ -2192,6 +2202,10 @@ var RegexParser = class {
2192
2202
  this.fail("Unterminated group", start);
2193
2203
  }
2194
2204
  this.position += 1;
2205
+ if (assertionNegated !== void 0) {
2206
+ this.guard.allocate(4);
2207
+ return { type: lookbehind ? "lookbehind" : "lookahead", negated: assertionNegated, body };
2208
+ }
2195
2209
  this.guard.allocate(5);
2196
2210
  return { type: "group", capturing, index, body };
2197
2211
  }
@@ -9311,7 +9325,7 @@ function matchRegexFrom(pattern, input, startIndex) {
9311
9325
  return null;
9312
9326
  }
9313
9327
  for (let attempt = startIndex; attempt <= input.length; attempt += 1) {
9314
- const context = { input, flags: pattern.flags, steps: 0 };
9328
+ const context = { input, flags: pattern.flags, direction: 1, work: { steps: 0 } };
9315
9329
  charge(context);
9316
9330
  const initialState = {
9317
9331
  position: attempt,
@@ -9327,18 +9341,19 @@ function matchRegexFrom(pattern, input, startIndex) {
9327
9341
  }
9328
9342
  function* matchNode(node, state, context) {
9329
9343
  charge(context);
9344
+ const characterIndex = context.direction === 1 ? state.position : state.position - 1;
9330
9345
  switch (node.type) {
9331
9346
  case "empty":
9332
9347
  yield state;
9333
9348
  return;
9334
9349
  case "literal":
9335
- if (charactersEqual(context.input[state.position], node.value, context.flags.ignoreCase)) {
9336
- yield { ...state, position: state.position + 1 };
9350
+ if (charactersEqual(context.input[characterIndex], node.value, context.flags.ignoreCase)) {
9351
+ yield { ...state, position: state.position + context.direction };
9337
9352
  }
9338
9353
  return;
9339
9354
  case "dot":
9340
- if (state.position < context.input.length && (context.flags.dotAll || !isLineTerminator(context.input[state.position]))) {
9341
- yield { ...state, position: state.position + 1 };
9355
+ if (characterIndex >= 0 && characterIndex < context.input.length && (context.flags.dotAll || !isLineTerminator(context.input[characterIndex]))) {
9356
+ yield { ...state, position: state.position + context.direction };
9342
9357
  }
9343
9358
  return;
9344
9359
  case "anchor":
@@ -9355,9 +9370,9 @@ function* matchNode(node, state, context) {
9355
9370
  return;
9356
9371
  }
9357
9372
  case "characterClass": {
9358
- const character = context.input[state.position];
9373
+ const character = context.input[characterIndex];
9359
9374
  if (character !== void 0 && matchesCharacterClass(character, node.items, node.negated, context.flags.ignoreCase)) {
9360
- yield { ...state, position: state.position + 1 };
9375
+ yield { ...state, position: state.position + context.direction };
9361
9376
  }
9362
9377
  return;
9363
9378
  }
@@ -9369,6 +9384,19 @@ function* matchNode(node, state, context) {
9369
9384
  yield* matchNode(alternative, cloneState(state), context);
9370
9385
  }
9371
9386
  return;
9387
+ case "lookahead":
9388
+ case "lookbehind": {
9389
+ const result = matchNode(node.body, cloneState(state), {
9390
+ ...context,
9391
+ direction: node.type === "lookbehind" ? -1 : 1
9392
+ }).next();
9393
+ if (node.negated) {
9394
+ if (result.done) yield state;
9395
+ } else if (!result.done) {
9396
+ yield { position: state.position, captures: result.value.captures };
9397
+ }
9398
+ return;
9399
+ }
9372
9400
  case "group":
9373
9401
  for (const result of matchNode(node.body, cloneState(state), context)) {
9374
9402
  if (!node.capturing || node.index === void 0) {
@@ -9376,7 +9404,7 @@ function* matchNode(node, state, context) {
9376
9404
  continue;
9377
9405
  }
9378
9406
  const captures = result.captures.slice();
9379
- captures[node.index - 1] = { start: state.position, end: result.position };
9407
+ captures[node.index - 1] = { start: Math.min(state.position, result.position), end: Math.max(state.position, result.position) };
9380
9408
  yield { position: result.position, captures };
9381
9409
  }
9382
9410
  return;
@@ -9390,7 +9418,8 @@ function* matchSequence(elements, index, state, context) {
9390
9418
  yield state;
9391
9419
  return;
9392
9420
  }
9393
- for (const result of matchNode(elements[index], state, context)) {
9421
+ const element = elements[context.direction === 1 ? index : elements.length - 1 - index];
9422
+ for (const result of matchNode(element, state, context)) {
9394
9423
  yield* matchSequence(elements, index + 1, result, context);
9395
9424
  }
9396
9425
  }
@@ -9493,13 +9522,13 @@ function clearNodeCaptures(node, captures) {
9493
9522
  }
9494
9523
  return;
9495
9524
  }
9496
- if (node.type === "quantifier") {
9525
+ if (node.type === "quantifier" || node.type === "lookahead" || node.type === "lookbehind") {
9497
9526
  clearNodeCaptures(node.body, captures);
9498
9527
  }
9499
9528
  }
9500
9529
  function charge(context) {
9501
- context.steps += 1;
9502
- allocateRegexSteps(context.steps);
9530
+ context.work.steps += 1;
9531
+ allocateRegexSteps(context.work.steps);
9503
9532
  }
9504
9533
  function normalizeLastIndex(lastIndex) {
9505
9534
  if (Number.isNaN(lastIndex) || lastIndex <= 0) {
@@ -37083,4 +37112,4 @@ export {
37083
37112
  FileSnapshotBackend,
37084
37113
  run
37085
37114
  };
37086
- //# sourceMappingURL=chunk-IBLBXKUC.js.map
37115
+ //# sourceMappingURL=chunk-37QJBJ72.js.map