poe-code 11.0.4 → 11.0.6

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
@@ -119097,7 +119097,6 @@ var init_tokenizer2 = __esm({
119097
119097
  "await",
119098
119098
  "yield",
119099
119099
  "import",
119100
- "from",
119101
119100
  "as",
119102
119101
  "true",
119103
119102
  "false",
@@ -122298,7 +122297,13 @@ var init_parser3 = __esm({
122298
122297
  }
122299
122298
  ];
122300
122299
  }
122301
- this.expectKeyword("from");
122300
+ const fromToken = this.currentToken();
122301
+ if (fromToken.type !== "identifier" || fromToken.value !== "from" || fromToken.end.offset - fromToken.start.offset !== fromToken.value.length) {
122302
+ throw new Error(
122303
+ `Expected 'from' at line ${fromToken.start.line}, column ${fromToken.start.column}.`
122304
+ );
122305
+ }
122306
+ this.index += 1;
122302
122307
  const sourceToken = this.currentToken();
122303
122308
  if (sourceToken.type !== "string") {
122304
122309
  throw unexpectedTokenError(sourceToken);
@@ -138743,12 +138748,10 @@ function getSandboxIterator(value) {
138743
138748
  return syncIterator(value[Symbol.iterator]());
138744
138749
  }
138745
138750
  if (isSandboxMap(value)) {
138746
- return syncIterator(
138747
- Array.from(value.entries, ([key3, entry]) => [key3, entry])[Symbol.iterator]()
138748
- );
138751
+ return collectionIterator(value.entries);
138749
138752
  }
138750
138753
  if (isSandboxSet(value)) {
138751
- return syncIterator(value.values[Symbol.iterator]());
138754
+ return collectionIterator(value.values);
138752
138755
  }
138753
138756
  if (typeof value !== "object" && typeof value !== "function" || value === null) {
138754
138757
  return void 0;
@@ -138759,6 +138762,29 @@ function getSandboxIterator(value) {
138759
138762
  }
138760
138763
  return syncIterator(Reflect.apply(iteratorMethod, value, []));
138761
138764
  }
138765
+ function collectionIterator(collection) {
138766
+ let iterator = collection[Symbol.iterator]();
138767
+ let exhausted = false;
138768
+ return {
138769
+ ...syncIterator({
138770
+ next: () => {
138771
+ if (exhausted) return { done: true, value: void 0 };
138772
+ const result = iterator.next();
138773
+ exhausted = result.done === true;
138774
+ return result;
138775
+ }
138776
+ }),
138777
+ snapshotIndex: () => {
138778
+ if (exhausted) return collection.size;
138779
+ let remaining = 0;
138780
+ while (!iterator.next().done) remaining += 1;
138781
+ const index = collection.size - remaining;
138782
+ iterator = collection[Symbol.iterator]();
138783
+ for (let skipped = 0; skipped < index; skipped += 1) iterator.next();
138784
+ return index;
138785
+ }
138786
+ };
138787
+ }
138762
138788
  function generatorIterator(generator) {
138763
138789
  const invoke2 = async (method, value) => {
138764
138790
  const leaveRunning = enterRunningState(generator);
@@ -145372,19 +145398,35 @@ async function evaluateVariableDeclaration(node, context) {
145372
145398
  value: void 0
145373
145399
  };
145374
145400
  }
145375
- function isRestorableBindingValue(value) {
145376
- if (Array.isArray(value)) {
145377
- return value.every(isRestorableBindingValue);
145378
- }
145401
+ function isRestorableBindingValue(value, seen = /* @__PURE__ */ new WeakSet()) {
145379
145402
  if (typeof value !== "object" || value === null) {
145380
145403
  return true;
145381
145404
  }
145405
+ if (seen.has(value)) return true;
145406
+ seen.add(value);
145407
+ if (isSandboxMap(value)) {
145408
+ for (const [key3, entry] of value.entries) {
145409
+ if (!isRestorableBindingValue(key3, seen) || !isRestorableBindingValue(entry, seen)) {
145410
+ return false;
145411
+ }
145412
+ }
145413
+ return true;
145414
+ }
145415
+ if (isSandboxSet(value)) {
145416
+ for (const entry of value.values) {
145417
+ if (!isRestorableBindingValue(entry, seen)) return false;
145418
+ }
145419
+ return true;
145420
+ }
145421
+ if (Array.isArray(value)) {
145422
+ return value.every((entry) => isRestorableBindingValue(entry, seen));
145423
+ }
145382
145424
  if (Object.hasOwn(value, "kind")) {
145383
145425
  return !["fn", "generator", "map", "promise", "regex", "set"].includes(
145384
145426
  String(value.kind)
145385
145427
  );
145386
145428
  }
145387
- return Object.values(value).every(isRestorableBindingValue);
145429
+ return Object.values(value).every((entry) => isRestorableBindingValue(entry, seen));
145388
145430
  }
145389
145431
  function predeclareDeclarationBindings(node, scope) {
145390
145432
  for (const name of getDeclarationBindingNames2(node)) {
@@ -145598,13 +145640,24 @@ async function evaluateIfStatement(node, context) {
145598
145640
  return evaluateNode2(branch, context);
145599
145641
  }
145600
145642
  async function evaluateForOfStatement(node, context) {
145643
+ const restoredIteration = context.restoredLoopIterations.get(node.nodeId ?? -1);
145644
+ let restoredEntry;
145645
+ if (typeof restoredIteration === "object" && typeof restoredIteration.values[0] === "string") {
145646
+ const restored = context.scope.consumeRestoredBinding(restoredIteration.values[0]);
145647
+ if (restored.found && Array.isArray(restored.value)) {
145648
+ restoredEntry = { done: false, value: restored.value[1] };
145649
+ if (isSandboxMap(restored.value[0]) || isSandboxSet(restored.value[0])) {
145650
+ return evaluateForOfIterator(node, restored.value[0], context, restoredEntry);
145651
+ }
145652
+ }
145653
+ }
145601
145654
  const iterable = await evaluateNode2(node.right, context);
145602
145655
  if (iterable.kind !== "normal") {
145603
145656
  return iterable;
145604
145657
  }
145605
145658
  const values = snapshotableIterationValues(iterable.value);
145606
145659
  if (values === void 0) {
145607
- return evaluateForOfIterator(node, iterable.value, context);
145660
+ return evaluateForOfIterator(node, iterable.value, context, restoredEntry);
145608
145661
  }
145609
145662
  const restoredIndex = consumeRestoredLoopIterationIndex(node, context);
145610
145663
  for (let index = restoredIndex; index < values.length; index += 1) {
@@ -145640,7 +145693,7 @@ async function evaluateForOfStatement(node, context) {
145640
145693
  value: void 0
145641
145694
  };
145642
145695
  }
145643
- async function evaluateForOfIterator(node, value, context) {
145696
+ async function evaluateForOfIterator(node, value, context, restoredEntry) {
145644
145697
  const iterator = getSandboxIterator(value);
145645
145698
  if (iterator === void 0) {
145646
145699
  throw new TypeError(`${String(value)} is not a supported iterable`);
@@ -145657,7 +145710,8 @@ async function evaluateForOfIterator(node, value, context) {
145657
145710
  }
145658
145711
  }
145659
145712
  while (true) {
145660
- const iteration = await iterator.next();
145713
+ const iteration = restoredEntry ?? await iterator.next();
145714
+ restoredEntry = void 0;
145661
145715
  if (typeof iteration !== "object" || iteration === null) {
145662
145716
  throw new TypeError("Iterator result must be an object.");
145663
145717
  }
@@ -145665,7 +145719,15 @@ async function evaluateForOfIterator(node, value, context) {
145665
145719
  context.activeLoopIterations.delete(nodeId);
145666
145720
  return normalEmptyResult();
145667
145721
  }
145668
- context.activeLoopIterations.set(nodeId, index);
145722
+ context.activeLoopIterations.set(
145723
+ nodeId,
145724
+ iterator.snapshotIndex === void 0 ? index : {
145725
+ get index() {
145726
+ return iterator.snapshotIndex();
145727
+ },
145728
+ values: [value, iteration.value]
145729
+ }
145730
+ );
145669
145731
  const scope = context.scope.child();
145670
145732
  const binding = await bindForOfLoopVariable(node.left, iteration.value, scope, context);
145671
145733
  if (!binding.ok) {
@@ -145904,10 +145966,21 @@ function createLoopIterationContext(context, scope) {
145904
145966
  return {
145905
145967
  ...context,
145906
145968
  scope,
145907
- snapshot: (currentScope) => ({
145908
- ...currentScope.snapshot(),
145909
- ...context.activeLoopIterations.size === 0 ? {} : { loopIterations: Object.fromEntries(context.activeLoopIterations) }
145910
- })
145969
+ snapshot: (currentScope) => {
145970
+ const snapshot2 = currentScope.snapshot();
145971
+ if (context.activeLoopIterations.size === 0) return snapshot2;
145972
+ snapshot2.loopIterations = {};
145973
+ for (const [nodeId, iteration] of context.activeLoopIterations) {
145974
+ if (typeof iteration !== "number" && (isSandboxMap(iteration.values[0]) || isSandboxSet(iteration.values[0]))) {
145975
+ const bindingName = `#for-of:${nodeId}`;
145976
+ snapshot2.bindings[bindingName] = iteration.values;
145977
+ snapshot2.loopIterations[nodeId] = { index: iteration.index, values: [bindingName] };
145978
+ } else {
145979
+ snapshot2.loopIterations[nodeId] = iteration;
145980
+ }
145981
+ }
145982
+ return snapshot2;
145983
+ }
145911
145984
  };
145912
145985
  }
145913
145986
  function consumeRestoredLoopIteration(node, context) {
@@ -145927,12 +146000,6 @@ function snapshotableIterationValues(value) {
145927
146000
  if (Array.isArray(value)) {
145928
146001
  return value;
145929
146002
  }
145930
- if (isSandboxMap(value)) {
145931
- return Array.from(value.entries, ([key3, entry]) => [key3, entry]);
145932
- }
145933
- if (isSandboxSet(value)) {
145934
- return Array.from(value.values);
145935
- }
145936
146003
  return void 0;
145937
146004
  }
145938
146005
  function isMatchingBreak(result, labels) {
@@ -155492,7 +155559,7 @@ var init_package2 = __esm({
155492
155559
  "package.json"() {
155493
155560
  package_default2 = {
155494
155561
  name: "poe-code",
155495
- version: "11.0.4",
155562
+ version: "11.0.6",
155496
155563
  description: "CLI tool to configure Poe API for developer workflows.",
155497
155564
  license: "MIT",
155498
155565
  type: "module",