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/dist/index.js CHANGED
@@ -138743,12 +138743,10 @@ function getSandboxIterator(value) {
138743
138743
  return syncIterator(value[Symbol.iterator]());
138744
138744
  }
138745
138745
  if (isSandboxMap(value)) {
138746
- return syncIterator(
138747
- Array.from(value.entries, ([key3, entry]) => [key3, entry])[Symbol.iterator]()
138748
- );
138746
+ return collectionIterator(value.entries);
138749
138747
  }
138750
138748
  if (isSandboxSet(value)) {
138751
- return syncIterator(value.values[Symbol.iterator]());
138749
+ return collectionIterator(value.values);
138752
138750
  }
138753
138751
  if (typeof value !== "object" && typeof value !== "function" || value === null) {
138754
138752
  return void 0;
@@ -138759,6 +138757,29 @@ function getSandboxIterator(value) {
138759
138757
  }
138760
138758
  return syncIterator(Reflect.apply(iteratorMethod, value, []));
138761
138759
  }
138760
+ function collectionIterator(collection) {
138761
+ let iterator = collection[Symbol.iterator]();
138762
+ let exhausted = false;
138763
+ return {
138764
+ ...syncIterator({
138765
+ next: () => {
138766
+ if (exhausted) return { done: true, value: void 0 };
138767
+ const result = iterator.next();
138768
+ exhausted = result.done === true;
138769
+ return result;
138770
+ }
138771
+ }),
138772
+ snapshotIndex: () => {
138773
+ if (exhausted) return collection.size;
138774
+ let remaining = 0;
138775
+ while (!iterator.next().done) remaining += 1;
138776
+ const index = collection.size - remaining;
138777
+ iterator = collection[Symbol.iterator]();
138778
+ for (let skipped = 0; skipped < index; skipped += 1) iterator.next();
138779
+ return index;
138780
+ }
138781
+ };
138782
+ }
138762
138783
  function generatorIterator(generator) {
138763
138784
  const invoke2 = async (method, value) => {
138764
138785
  const leaveRunning = enterRunningState(generator);
@@ -144253,7 +144274,7 @@ async function replaceRegex(value, regex, replacement, replaceAll2, budget, call
144253
144274
  let copiedThrough = 0;
144254
144275
  for (const match of matches) {
144255
144276
  result += value.slice(copiedThrough, match.index);
144256
- result += typeof replacement === "string" ? expandReplacement(replacement, match.text, match.captures) : String(
144277
+ result += typeof replacement === "string" ? expandReplacement(replacement, match.text, match.captures, value, match.index) : String(
144257
144278
  await callClosure(replacement, [match.text, ...match.captures, match.index, value])
144258
144279
  );
144259
144280
  copiedThrough = match.index + match.text.length;
@@ -144261,12 +144282,45 @@ async function replaceRegex(value, regex, replacement, replaceAll2, budget, call
144261
144282
  result += value.slice(copiedThrough);
144262
144283
  return budget.allocateString(result);
144263
144284
  }
144264
- function expandReplacement(replacement, match, captures) {
144265
- return replacement.replace(/\$([$&]|[1-9][0-9]?)/g, (token, part) => {
144266
- if (part === "$") return "$";
144267
- if (part === "&") return match;
144268
- return captures[Number(part) - 1] ?? token;
144269
- });
144285
+ function expandReplacement(replacement, match, captures, input, matchIndex) {
144286
+ let result = "";
144287
+ for (let index = 0; index < replacement.length; index += 1) {
144288
+ const character2 = replacement.charAt(index);
144289
+ if (character2 !== "$") {
144290
+ result += character2;
144291
+ continue;
144292
+ }
144293
+ const token = replacement.charAt(index + 1);
144294
+ if (token === "$") {
144295
+ result += "$";
144296
+ } else if (token === "&") {
144297
+ result += match;
144298
+ } else if (token === "`") {
144299
+ result += input.slice(0, matchIndex);
144300
+ } else if (token === "'") {
144301
+ result += input.slice(matchIndex + match.length);
144302
+ } else if (token >= "0" && token <= "9") {
144303
+ let captureIndex = Number(token);
144304
+ const nextDigit = replacement.charAt(index + 2);
144305
+ if (nextDigit >= "0" && nextDigit <= "9") {
144306
+ const twoDigitIndex = Number(token + nextDigit);
144307
+ if (twoDigitIndex > 0 && twoDigitIndex <= captures.length) {
144308
+ captureIndex = twoDigitIndex;
144309
+ index += 1;
144310
+ }
144311
+ }
144312
+ if (captureIndex === 0 || captureIndex > captures.length) {
144313
+ result += "$";
144314
+ continue;
144315
+ }
144316
+ result += captures[captureIndex - 1] ?? "";
144317
+ } else {
144318
+ result += "$";
144319
+ continue;
144320
+ }
144321
+ index += 1;
144322
+ }
144323
+ return result;
144270
144324
  }
144271
144325
  async function replaceWithClosure(value, searchValue, replacer, replaceAll2, budget, callClosure) {
144272
144326
  const offsets = findReplacementOffsets(value, searchValue, replaceAll2);
@@ -145339,19 +145393,35 @@ async function evaluateVariableDeclaration(node, context) {
145339
145393
  value: void 0
145340
145394
  };
145341
145395
  }
145342
- function isRestorableBindingValue(value) {
145343
- if (Array.isArray(value)) {
145344
- return value.every(isRestorableBindingValue);
145345
- }
145396
+ function isRestorableBindingValue(value, seen = /* @__PURE__ */ new WeakSet()) {
145346
145397
  if (typeof value !== "object" || value === null) {
145347
145398
  return true;
145348
145399
  }
145400
+ if (seen.has(value)) return true;
145401
+ seen.add(value);
145402
+ if (isSandboxMap(value)) {
145403
+ for (const [key3, entry] of value.entries) {
145404
+ if (!isRestorableBindingValue(key3, seen) || !isRestorableBindingValue(entry, seen)) {
145405
+ return false;
145406
+ }
145407
+ }
145408
+ return true;
145409
+ }
145410
+ if (isSandboxSet(value)) {
145411
+ for (const entry of value.values) {
145412
+ if (!isRestorableBindingValue(entry, seen)) return false;
145413
+ }
145414
+ return true;
145415
+ }
145416
+ if (Array.isArray(value)) {
145417
+ return value.every((entry) => isRestorableBindingValue(entry, seen));
145418
+ }
145349
145419
  if (Object.hasOwn(value, "kind")) {
145350
145420
  return !["fn", "generator", "map", "promise", "regex", "set"].includes(
145351
145421
  String(value.kind)
145352
145422
  );
145353
145423
  }
145354
- return Object.values(value).every(isRestorableBindingValue);
145424
+ return Object.values(value).every((entry) => isRestorableBindingValue(entry, seen));
145355
145425
  }
145356
145426
  function predeclareDeclarationBindings(node, scope) {
145357
145427
  for (const name of getDeclarationBindingNames2(node)) {
@@ -145565,13 +145635,24 @@ async function evaluateIfStatement(node, context) {
145565
145635
  return evaluateNode2(branch, context);
145566
145636
  }
145567
145637
  async function evaluateForOfStatement(node, context) {
145638
+ const restoredIteration = context.restoredLoopIterations.get(node.nodeId ?? -1);
145639
+ let restoredEntry;
145640
+ if (typeof restoredIteration === "object" && typeof restoredIteration.values[0] === "string") {
145641
+ const restored = context.scope.consumeRestoredBinding(restoredIteration.values[0]);
145642
+ if (restored.found && Array.isArray(restored.value)) {
145643
+ restoredEntry = { done: false, value: restored.value[1] };
145644
+ if (isSandboxMap(restored.value[0]) || isSandboxSet(restored.value[0])) {
145645
+ return evaluateForOfIterator(node, restored.value[0], context, restoredEntry);
145646
+ }
145647
+ }
145648
+ }
145568
145649
  const iterable = await evaluateNode2(node.right, context);
145569
145650
  if (iterable.kind !== "normal") {
145570
145651
  return iterable;
145571
145652
  }
145572
145653
  const values = snapshotableIterationValues(iterable.value);
145573
145654
  if (values === void 0) {
145574
- return evaluateForOfIterator(node, iterable.value, context);
145655
+ return evaluateForOfIterator(node, iterable.value, context, restoredEntry);
145575
145656
  }
145576
145657
  const restoredIndex = consumeRestoredLoopIterationIndex(node, context);
145577
145658
  for (let index = restoredIndex; index < values.length; index += 1) {
@@ -145607,7 +145688,7 @@ async function evaluateForOfStatement(node, context) {
145607
145688
  value: void 0
145608
145689
  };
145609
145690
  }
145610
- async function evaluateForOfIterator(node, value, context) {
145691
+ async function evaluateForOfIterator(node, value, context, restoredEntry) {
145611
145692
  const iterator = getSandboxIterator(value);
145612
145693
  if (iterator === void 0) {
145613
145694
  throw new TypeError(`${String(value)} is not a supported iterable`);
@@ -145624,7 +145705,8 @@ async function evaluateForOfIterator(node, value, context) {
145624
145705
  }
145625
145706
  }
145626
145707
  while (true) {
145627
- const iteration = await iterator.next();
145708
+ const iteration = restoredEntry ?? await iterator.next();
145709
+ restoredEntry = void 0;
145628
145710
  if (typeof iteration !== "object" || iteration === null) {
145629
145711
  throw new TypeError("Iterator result must be an object.");
145630
145712
  }
@@ -145632,7 +145714,15 @@ async function evaluateForOfIterator(node, value, context) {
145632
145714
  context.activeLoopIterations.delete(nodeId);
145633
145715
  return normalEmptyResult();
145634
145716
  }
145635
- context.activeLoopIterations.set(nodeId, index);
145717
+ context.activeLoopIterations.set(
145718
+ nodeId,
145719
+ iterator.snapshotIndex === void 0 ? index : {
145720
+ get index() {
145721
+ return iterator.snapshotIndex();
145722
+ },
145723
+ values: [value, iteration.value]
145724
+ }
145725
+ );
145636
145726
  const scope = context.scope.child();
145637
145727
  const binding = await bindForOfLoopVariable(node.left, iteration.value, scope, context);
145638
145728
  if (!binding.ok) {
@@ -145871,10 +145961,21 @@ function createLoopIterationContext(context, scope) {
145871
145961
  return {
145872
145962
  ...context,
145873
145963
  scope,
145874
- snapshot: (currentScope) => ({
145875
- ...currentScope.snapshot(),
145876
- ...context.activeLoopIterations.size === 0 ? {} : { loopIterations: Object.fromEntries(context.activeLoopIterations) }
145877
- })
145964
+ snapshot: (currentScope) => {
145965
+ const snapshot2 = currentScope.snapshot();
145966
+ if (context.activeLoopIterations.size === 0) return snapshot2;
145967
+ snapshot2.loopIterations = {};
145968
+ for (const [nodeId, iteration] of context.activeLoopIterations) {
145969
+ if (typeof iteration !== "number" && (isSandboxMap(iteration.values[0]) || isSandboxSet(iteration.values[0]))) {
145970
+ const bindingName = `#for-of:${nodeId}`;
145971
+ snapshot2.bindings[bindingName] = iteration.values;
145972
+ snapshot2.loopIterations[nodeId] = { index: iteration.index, values: [bindingName] };
145973
+ } else {
145974
+ snapshot2.loopIterations[nodeId] = iteration;
145975
+ }
145976
+ }
145977
+ return snapshot2;
145978
+ }
145878
145979
  };
145879
145980
  }
145880
145981
  function consumeRestoredLoopIteration(node, context) {
@@ -145894,12 +145995,6 @@ function snapshotableIterationValues(value) {
145894
145995
  if (Array.isArray(value)) {
145895
145996
  return value;
145896
145997
  }
145897
- if (isSandboxMap(value)) {
145898
- return Array.from(value.entries, ([key3, entry]) => [key3, entry]);
145899
- }
145900
- if (isSandboxSet(value)) {
145901
- return Array.from(value.values);
145902
- }
145903
145998
  return void 0;
145904
145999
  }
145905
146000
  function isMatchingBreak(result, labels) {
@@ -155459,7 +155554,7 @@ var init_package2 = __esm({
155459
155554
  "package.json"() {
155460
155555
  package_default2 = {
155461
155556
  name: "poe-code",
155462
- version: "11.0.3",
155557
+ version: "11.0.5",
155463
155558
  description: "CLI tool to configure Poe API for developer workflows.",
155464
155559
  license: "MIT",
155465
155560
  type: "module",