poe-code 11.0.3 → 11.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-code",
3
- "version": "11.0.3",
3
+ "version": "11.0.4",
4
4
  "description": "CLI tool to configure Poe API for developer workflows.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25107,7 +25107,7 @@ async function replaceRegex(value, regex, replacement, replaceAll, budget, callC
25107
25107
  let copiedThrough = 0;
25108
25108
  for (const match of matches) {
25109
25109
  result += value.slice(copiedThrough, match.index);
25110
- result += typeof replacement === "string" ? expandReplacement(replacement, match.text, match.captures) : String(
25110
+ result += typeof replacement === "string" ? expandReplacement(replacement, match.text, match.captures, value, match.index) : String(
25111
25111
  await callClosure(replacement, [match.text, ...match.captures, match.index, value])
25112
25112
  );
25113
25113
  copiedThrough = match.index + match.text.length;
@@ -25115,12 +25115,45 @@ async function replaceRegex(value, regex, replacement, replaceAll, budget, callC
25115
25115
  result += value.slice(copiedThrough);
25116
25116
  return budget.allocateString(result);
25117
25117
  }
25118
- function expandReplacement(replacement, match, captures) {
25119
- return replacement.replace(/\$([$&]|[1-9][0-9]?)/g, (token, part) => {
25120
- if (part === "$") return "$";
25121
- if (part === "&") return match;
25122
- return captures[Number(part) - 1] ?? token;
25123
- });
25118
+ function expandReplacement(replacement, match, captures, input, matchIndex) {
25119
+ let result = "";
25120
+ for (let index = 0; index < replacement.length; index += 1) {
25121
+ const character = replacement.charAt(index);
25122
+ if (character !== "$") {
25123
+ result += character;
25124
+ continue;
25125
+ }
25126
+ const token = replacement.charAt(index + 1);
25127
+ if (token === "$") {
25128
+ result += "$";
25129
+ } else if (token === "&") {
25130
+ result += match;
25131
+ } else if (token === "`") {
25132
+ result += input.slice(0, matchIndex);
25133
+ } else if (token === "'") {
25134
+ result += input.slice(matchIndex + match.length);
25135
+ } else if (token >= "0" && token <= "9") {
25136
+ let captureIndex = Number(token);
25137
+ const nextDigit = replacement.charAt(index + 2);
25138
+ if (nextDigit >= "0" && nextDigit <= "9") {
25139
+ const twoDigitIndex = Number(token + nextDigit);
25140
+ if (twoDigitIndex > 0 && twoDigitIndex <= captures.length) {
25141
+ captureIndex = twoDigitIndex;
25142
+ index += 1;
25143
+ }
25144
+ }
25145
+ if (captureIndex === 0 || captureIndex > captures.length) {
25146
+ result += "$";
25147
+ continue;
25148
+ }
25149
+ result += captures[captureIndex - 1] ?? "";
25150
+ } else {
25151
+ result += "$";
25152
+ continue;
25153
+ }
25154
+ index += 1;
25155
+ }
25156
+ return result;
25124
25157
  }
25125
25158
  async function replaceWithClosure(value, searchValue, replacer, replaceAll, budget, callClosure) {
25126
25159
  const offsets = findReplacementOffsets(value, searchValue, replaceAll);
@@ -28881,4 +28914,4 @@ export {
28881
28914
  FileSnapshotBackend,
28882
28915
  run
28883
28916
  };
28884
- //# sourceMappingURL=chunk-YETLO7L5.js.map
28917
+ //# sourceMappingURL=chunk-CA342J7E.js.map