poe-code 11.0.3 → 11.0.5

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.5",
4
4
  "description": "CLI tool to configure Poe API for developer workflows.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-YETLO7L5.js";
30
+ } from "./chunk-WC2N7PM5.js";
31
31
 
32
32
  // packages/safejs/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8048,4 +8048,4 @@ export {
8048
8048
  parseMcpConfig,
8049
8049
  makeMcpModule
8050
8050
  };
8051
- //# sourceMappingURL=chunk-7AGANI6L.js.map
8051
+ //# sourceMappingURL=chunk-EWC7GLGM.js.map
@@ -18514,12 +18514,10 @@ function getSandboxIterator(value) {
18514
18514
  return syncIterator(value[Symbol.iterator]());
18515
18515
  }
18516
18516
  if (isSandboxMap(value)) {
18517
- return syncIterator(
18518
- Array.from(value.entries, ([key, entry]) => [key, entry])[Symbol.iterator]()
18519
- );
18517
+ return collectionIterator(value.entries);
18520
18518
  }
18521
18519
  if (isSandboxSet(value)) {
18522
- return syncIterator(value.values[Symbol.iterator]());
18520
+ return collectionIterator(value.values);
18523
18521
  }
18524
18522
  if (typeof value !== "object" && typeof value !== "function" || value === null) {
18525
18523
  return void 0;
@@ -18530,6 +18528,29 @@ function getSandboxIterator(value) {
18530
18528
  }
18531
18529
  return syncIterator(Reflect.apply(iteratorMethod, value, []));
18532
18530
  }
18531
+ function collectionIterator(collection) {
18532
+ let iterator = collection[Symbol.iterator]();
18533
+ let exhausted = false;
18534
+ return {
18535
+ ...syncIterator({
18536
+ next: () => {
18537
+ if (exhausted) return { done: true, value: void 0 };
18538
+ const result = iterator.next();
18539
+ exhausted = result.done === true;
18540
+ return result;
18541
+ }
18542
+ }),
18543
+ snapshotIndex: () => {
18544
+ if (exhausted) return collection.size;
18545
+ let remaining = 0;
18546
+ while (!iterator.next().done) remaining += 1;
18547
+ const index = collection.size - remaining;
18548
+ iterator = collection[Symbol.iterator]();
18549
+ for (let skipped = 0; skipped < index; skipped += 1) iterator.next();
18550
+ return index;
18551
+ }
18552
+ };
18553
+ }
18533
18554
  function generatorIterator(generator) {
18534
18555
  const invoke = async (method, value) => {
18535
18556
  const leaveRunning = enterRunningState(generator);
@@ -25107,7 +25128,7 @@ async function replaceRegex(value, regex, replacement, replaceAll, budget, callC
25107
25128
  let copiedThrough = 0;
25108
25129
  for (const match of matches) {
25109
25130
  result += value.slice(copiedThrough, match.index);
25110
- result += typeof replacement === "string" ? expandReplacement(replacement, match.text, match.captures) : String(
25131
+ result += typeof replacement === "string" ? expandReplacement(replacement, match.text, match.captures, value, match.index) : String(
25111
25132
  await callClosure(replacement, [match.text, ...match.captures, match.index, value])
25112
25133
  );
25113
25134
  copiedThrough = match.index + match.text.length;
@@ -25115,12 +25136,45 @@ async function replaceRegex(value, regex, replacement, replaceAll, budget, callC
25115
25136
  result += value.slice(copiedThrough);
25116
25137
  return budget.allocateString(result);
25117
25138
  }
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
- });
25139
+ function expandReplacement(replacement, match, captures, input, matchIndex) {
25140
+ let result = "";
25141
+ for (let index = 0; index < replacement.length; index += 1) {
25142
+ const character = replacement.charAt(index);
25143
+ if (character !== "$") {
25144
+ result += character;
25145
+ continue;
25146
+ }
25147
+ const token = replacement.charAt(index + 1);
25148
+ if (token === "$") {
25149
+ result += "$";
25150
+ } else if (token === "&") {
25151
+ result += match;
25152
+ } else if (token === "`") {
25153
+ result += input.slice(0, matchIndex);
25154
+ } else if (token === "'") {
25155
+ result += input.slice(matchIndex + match.length);
25156
+ } else if (token >= "0" && token <= "9") {
25157
+ let captureIndex = Number(token);
25158
+ const nextDigit = replacement.charAt(index + 2);
25159
+ if (nextDigit >= "0" && nextDigit <= "9") {
25160
+ const twoDigitIndex = Number(token + nextDigit);
25161
+ if (twoDigitIndex > 0 && twoDigitIndex <= captures.length) {
25162
+ captureIndex = twoDigitIndex;
25163
+ index += 1;
25164
+ }
25165
+ }
25166
+ if (captureIndex === 0 || captureIndex > captures.length) {
25167
+ result += "$";
25168
+ continue;
25169
+ }
25170
+ result += captures[captureIndex - 1] ?? "";
25171
+ } else {
25172
+ result += "$";
25173
+ continue;
25174
+ }
25175
+ index += 1;
25176
+ }
25177
+ return result;
25124
25178
  }
25125
25179
  async function replaceWithClosure(value, searchValue, replacer, replaceAll, budget, callClosure) {
25126
25180
  const offsets = findReplacementOffsets(value, searchValue, replaceAll);
@@ -26188,19 +26242,35 @@ async function evaluateVariableDeclaration(node, context) {
26188
26242
  value: void 0
26189
26243
  };
26190
26244
  }
26191
- function isRestorableBindingValue(value) {
26192
- if (Array.isArray(value)) {
26193
- return value.every(isRestorableBindingValue);
26194
- }
26245
+ function isRestorableBindingValue(value, seen = /* @__PURE__ */ new WeakSet()) {
26195
26246
  if (typeof value !== "object" || value === null) {
26196
26247
  return true;
26197
26248
  }
26249
+ if (seen.has(value)) return true;
26250
+ seen.add(value);
26251
+ if (isSandboxMap(value)) {
26252
+ for (const [key, entry] of value.entries) {
26253
+ if (!isRestorableBindingValue(key, seen) || !isRestorableBindingValue(entry, seen)) {
26254
+ return false;
26255
+ }
26256
+ }
26257
+ return true;
26258
+ }
26259
+ if (isSandboxSet(value)) {
26260
+ for (const entry of value.values) {
26261
+ if (!isRestorableBindingValue(entry, seen)) return false;
26262
+ }
26263
+ return true;
26264
+ }
26265
+ if (Array.isArray(value)) {
26266
+ return value.every((entry) => isRestorableBindingValue(entry, seen));
26267
+ }
26198
26268
  if (Object.hasOwn(value, "kind")) {
26199
26269
  return !["fn", "generator", "map", "promise", "regex", "set"].includes(
26200
26270
  String(value.kind)
26201
26271
  );
26202
26272
  }
26203
- return Object.values(value).every(isRestorableBindingValue);
26273
+ return Object.values(value).every((entry) => isRestorableBindingValue(entry, seen));
26204
26274
  }
26205
26275
  function predeclareDeclarationBindings(node, scope) {
26206
26276
  for (const name of getDeclarationBindingNames2(node)) {
@@ -26414,13 +26484,24 @@ async function evaluateIfStatement(node, context) {
26414
26484
  return evaluateNode(branch, context);
26415
26485
  }
26416
26486
  async function evaluateForOfStatement(node, context) {
26487
+ const restoredIteration = context.restoredLoopIterations.get(node.nodeId ?? -1);
26488
+ let restoredEntry;
26489
+ if (typeof restoredIteration === "object" && typeof restoredIteration.values[0] === "string") {
26490
+ const restored = context.scope.consumeRestoredBinding(restoredIteration.values[0]);
26491
+ if (restored.found && Array.isArray(restored.value)) {
26492
+ restoredEntry = { done: false, value: restored.value[1] };
26493
+ if (isSandboxMap(restored.value[0]) || isSandboxSet(restored.value[0])) {
26494
+ return evaluateForOfIterator(node, restored.value[0], context, restoredEntry);
26495
+ }
26496
+ }
26497
+ }
26417
26498
  const iterable = await evaluateNode(node.right, context);
26418
26499
  if (iterable.kind !== "normal") {
26419
26500
  return iterable;
26420
26501
  }
26421
26502
  const values = snapshotableIterationValues(iterable.value);
26422
26503
  if (values === void 0) {
26423
- return evaluateForOfIterator(node, iterable.value, context);
26504
+ return evaluateForOfIterator(node, iterable.value, context, restoredEntry);
26424
26505
  }
26425
26506
  const restoredIndex = consumeRestoredLoopIterationIndex(node, context);
26426
26507
  for (let index = restoredIndex; index < values.length; index += 1) {
@@ -26456,7 +26537,7 @@ async function evaluateForOfStatement(node, context) {
26456
26537
  value: void 0
26457
26538
  };
26458
26539
  }
26459
- async function evaluateForOfIterator(node, value, context) {
26540
+ async function evaluateForOfIterator(node, value, context, restoredEntry) {
26460
26541
  const iterator = getSandboxIterator(value);
26461
26542
  if (iterator === void 0) {
26462
26543
  throw new TypeError(`${String(value)} is not a supported iterable`);
@@ -26473,7 +26554,8 @@ async function evaluateForOfIterator(node, value, context) {
26473
26554
  }
26474
26555
  }
26475
26556
  while (true) {
26476
- const iteration = await iterator.next();
26557
+ const iteration = restoredEntry ?? await iterator.next();
26558
+ restoredEntry = void 0;
26477
26559
  if (typeof iteration !== "object" || iteration === null) {
26478
26560
  throw new TypeError("Iterator result must be an object.");
26479
26561
  }
@@ -26481,7 +26563,15 @@ async function evaluateForOfIterator(node, value, context) {
26481
26563
  context.activeLoopIterations.delete(nodeId);
26482
26564
  return normalEmptyResult();
26483
26565
  }
26484
- context.activeLoopIterations.set(nodeId, index);
26566
+ context.activeLoopIterations.set(
26567
+ nodeId,
26568
+ iterator.snapshotIndex === void 0 ? index : {
26569
+ get index() {
26570
+ return iterator.snapshotIndex();
26571
+ },
26572
+ values: [value, iteration.value]
26573
+ }
26574
+ );
26485
26575
  const scope = context.scope.child();
26486
26576
  const binding = await bindForOfLoopVariable(node.left, iteration.value, scope, context);
26487
26577
  if (!binding.ok) {
@@ -26720,10 +26810,21 @@ function createLoopIterationContext(context, scope) {
26720
26810
  return {
26721
26811
  ...context,
26722
26812
  scope,
26723
- snapshot: (currentScope) => ({
26724
- ...currentScope.snapshot(),
26725
- ...context.activeLoopIterations.size === 0 ? {} : { loopIterations: Object.fromEntries(context.activeLoopIterations) }
26726
- })
26813
+ snapshot: (currentScope) => {
26814
+ const snapshot = currentScope.snapshot();
26815
+ if (context.activeLoopIterations.size === 0) return snapshot;
26816
+ snapshot.loopIterations = {};
26817
+ for (const [nodeId, iteration] of context.activeLoopIterations) {
26818
+ if (typeof iteration !== "number" && (isSandboxMap(iteration.values[0]) || isSandboxSet(iteration.values[0]))) {
26819
+ const bindingName = `#for-of:${nodeId}`;
26820
+ snapshot.bindings[bindingName] = iteration.values;
26821
+ snapshot.loopIterations[nodeId] = { index: iteration.index, values: [bindingName] };
26822
+ } else {
26823
+ snapshot.loopIterations[nodeId] = iteration;
26824
+ }
26825
+ }
26826
+ return snapshot;
26827
+ }
26727
26828
  };
26728
26829
  }
26729
26830
  function consumeRestoredLoopIteration(node, context) {
@@ -26743,12 +26844,6 @@ function snapshotableIterationValues(value) {
26743
26844
  if (Array.isArray(value)) {
26744
26845
  return value;
26745
26846
  }
26746
- if (isSandboxMap(value)) {
26747
- return Array.from(value.entries, ([key, entry]) => [key, entry]);
26748
- }
26749
- if (isSandboxSet(value)) {
26750
- return Array.from(value.values);
26751
- }
26752
26847
  return void 0;
26753
26848
  }
26754
26849
  function isMatchingBreak(result, labels) {
@@ -28881,4 +28976,4 @@ export {
28881
28976
  FileSnapshotBackend,
28882
28977
  run
28883
28978
  };
28884
- //# sourceMappingURL=chunk-YETLO7L5.js.map
28979
+ //# sourceMappingURL=chunk-WC2N7PM5.js.map