@poe-platform/safe-bash 0.1.438 → 0.1.440

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.
@@ -7202,6 +7202,57 @@ async function matchesPattern(pattern, value2, work) {
7202
7202
  reservation?.release();
7203
7203
  }
7204
7204
  }
7205
+ async function compilePatternBoundaries(pattern, work) {
7206
+ work.signal.throwIfAborted();
7207
+ const { patternTokens } = await tokens(pattern, work);
7208
+ return async (value2, shortest = false, suffix2 = false) => {
7209
+ let rowReservation;
7210
+ let resultReservation;
7211
+ try {
7212
+ const rowSize = patternTokens.length + 1;
7213
+ const resultSize = value2.length + 1;
7214
+ const initialized = stringCheckpoint(work, rowSize + resultSize);
7215
+ if (initialized) await initialized;
7216
+ rowReservation = work.allocation?.reserve(64 + rowSize * 8, 0);
7217
+ resultReservation = work.allocation?.reserve(64 + resultSize * 8, 0);
7218
+ const row = new Float64Array(rowSize).fill(-1);
7219
+ const ends = new Float64Array(resultSize).fill(-1);
7220
+ let position = value2.length;
7221
+ while (true) {
7222
+ const advanced = stringCheckpoint(work);
7223
+ if (advanced) await advanced;
7224
+ const point = position < value2.length ? value2.codePointAt(position) : void 0;
7225
+ let diagonal = row[patternTokens.length];
7226
+ row[patternTokens.length] = !suffix2 || position === value2.length ? position : -1;
7227
+ for (let index = patternTokens.length - 1; index >= 0; index--) {
7228
+ const pending = stringCheckpoint(work);
7229
+ if (pending) await pending;
7230
+ const previous = row[index];
7231
+ const token = patternTokens[index];
7232
+ if (token.kind === "star") {
7233
+ const skip = row[index + 1];
7234
+ const consume = point === void 0 ? -1 : previous;
7235
+ row[index] = skip < 0 ? consume : consume < 0 ? skip : shortest ? Math.min(skip, consume) : Math.max(skip, consume);
7236
+ } else {
7237
+ const accepts = point !== void 0 && (token.kind === "any" || (token.kind === "literal" ? token.value.codePointAt(0) === point : token.expression.test(String.fromCodePoint(point))));
7238
+ row[index] = accepts ? diagonal : -1;
7239
+ }
7240
+ diagonal = previous;
7241
+ }
7242
+ ends[position] = row[0];
7243
+ if (position === 0) break;
7244
+ position = previousCodePointOffset(value2, position);
7245
+ }
7246
+ work.signal.throwIfAborted();
7247
+ return ends;
7248
+ } catch (error) {
7249
+ resultReservation?.release();
7250
+ throw error;
7251
+ } finally {
7252
+ rowReservation?.release();
7253
+ }
7254
+ };
7255
+ }
7205
7256
  async function matchTokens(patternTokens, value2, work, start, end) {
7206
7257
  work.signal.throwIfAborted();
7207
7258
  let position = start;
@@ -16783,19 +16834,17 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
16783
16834
  scratch.reserve(patternUnits * 2, 0);
16784
16835
  const pattern = patternFields.join("");
16785
16836
  const size = (await scanString(text, work)).count;
16786
- const matches = await compilePattern(pattern, work);
16787
- const match = async (start, end, length) => {
16788
- const pending = stringCheckpoint(work, length + 1);
16789
- if (pending) await pending;
16790
- return matches(text, start, end);
16791
- };
16837
+ const boundaries = await compilePatternBoundaries(pattern, work);
16792
16838
  const operator = part.operator;
16793
16839
  if (!operator.startsWith("/")) {
16794
16840
  const longest = operator.length === 2;
16795
16841
  const prefix2 = operator.startsWith("#");
16842
+ const ends2 = await boundaries(text, !longest && prefix2, !prefix2);
16796
16843
  let boundary = longest === prefix2 ? text.length : 0;
16797
16844
  for (let length = longest ? size : 0; longest ? length >= 0 : length <= size; length += longest ? -1 : 1) {
16798
- if (await match(prefix2 ? 0 : boundary, prefix2 ? boundary : text.length, length)) {
16845
+ const pending = stringCheckpoint(work);
16846
+ if (pending) await pending;
16847
+ if (ends2[prefix2 ? 0 : boundary] === (prefix2 ? boundary : text.length)) {
16799
16848
  const start = prefix2 ? boundary : 0;
16800
16849
  const end = prefix2 ? text.length : boundary;
16801
16850
  scratch.reserve((end - start) * 2, 0);
@@ -16838,49 +16887,49 @@ ${prefix2} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
16838
16887
  retained?.release();
16839
16888
  retained = next;
16840
16889
  };
16890
+ const ends = await boundaries(text, false, operator === "/%");
16841
16891
  let position = 0;
16842
- let positionIndex = 0;
16843
- while (positionIndex <= size) {
16892
+ while (position <= text.length) {
16844
16893
  let found = false;
16845
- for (let start = position, startIndex = positionIndex; startIndex <= size; startIndex++, start = nextCodePointOffset(text, start)) {
16894
+ for (let start = position; start <= text.length; start = nextCodePointOffset(text, start)) {
16846
16895
  if (operator === "/#" && start !== 0) break;
16847
- for (let end = text.length, endIndex = size; endIndex >= startIndex; endIndex--, end = previousCodePointOffset(text, end)) {
16848
- if (operator === "/%" && end !== text.length) break;
16849
- if (!await match(start, end, endIndex - startIndex)) continue;
16850
- await append(text, position, start);
16851
- for (const replacement of replacements) {
16852
- if (replacement.quoted) await append(replacement.value);
16853
- else {
16854
- let fragment = 0;
16855
- for (let cursor = 0; cursor < replacement.value.length; cursor++) {
16856
- const pending = stringCheckpoint(work);
16857
- if (pending) await pending;
16858
- if (replacement.value[cursor] !== "&") continue;
16859
- await append(replacement.value, fragment, cursor);
16860
- await append(text, start, end);
16861
- fragment = cursor + 1;
16862
- }
16863
- await append(replacement.value, fragment);
16896
+ const pending = stringCheckpoint(work);
16897
+ if (pending) await pending;
16898
+ const end = ends[start];
16899
+ if (end < 0) {
16900
+ if (start === text.length) break;
16901
+ continue;
16902
+ }
16903
+ await append(text, position, start);
16904
+ for (const replacement of replacements) {
16905
+ if (replacement.quoted) await append(replacement.value);
16906
+ else {
16907
+ let fragment = 0;
16908
+ for (let cursor = 0; cursor < replacement.value.length; cursor++) {
16909
+ const pending2 = stringCheckpoint(work);
16910
+ if (pending2) await pending2;
16911
+ if (replacement.value[cursor] !== "&") continue;
16912
+ await append(replacement.value, fragment, cursor);
16913
+ await append(text, start, end);
16914
+ fragment = cursor + 1;
16864
16915
  }
16916
+ await append(replacement.value, fragment);
16865
16917
  }
16866
- position = end;
16867
- positionIndex = endIndex;
16868
- found = true;
16869
- if (operator !== "//" || end === text.length) {
16870
- await append(text, end);
16871
- return result;
16872
- }
16873
- if (end === start) {
16874
- position = nextCodePointOffset(text, end);
16875
- positionIndex++;
16876
- await append(text, end, position);
16877
- }
16878
- break;
16879
16918
  }
16880
- if (found) break;
16919
+ position = end;
16920
+ found = true;
16921
+ if (operator !== "//" || end === text.length) {
16922
+ await append(text, end);
16923
+ return result;
16924
+ }
16925
+ if (end === start) {
16926
+ position = nextCodePointOffset(text, end);
16927
+ await append(text, end, position);
16928
+ }
16929
+ break;
16881
16930
  }
16882
16931
  if (!found) {
16883
- if (positionIndex === 0) return text;
16932
+ if (position === 0) return text;
16884
16933
  await append(text, position);
16885
16934
  break;
16886
16935
  }