@poe-platform/safe-js 0.1.163 → 0.1.165

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.
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-AW3IBVVD.js";
30
+ } from "./chunk-IHPQO2HC.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8249,4 +8249,4 @@ export {
8249
8249
  parseMcpConfig,
8250
8250
  makeMcpModule
8251
8251
  };
8252
- //# sourceMappingURL=chunk-ZXBZUJHU.js.map
8252
+ //# sourceMappingURL=chunk-4JKST34C.js.map
@@ -2567,6 +2567,7 @@ var Parser = class {
2567
2567
  loopDepth = 0;
2568
2568
  scopes = [/* @__PURE__ */ new Map()];
2569
2569
  functionScopes = /* @__PURE__ */ new WeakSet();
2570
+ parenthesizedNodes = /* @__PURE__ */ new WeakSet();
2570
2571
  varNames = /* @__PURE__ */ new WeakMap();
2571
2572
  withFunctionSource(node) {
2572
2573
  functionSources.set(node, {
@@ -3941,13 +3942,12 @@ var Parser = class {
3941
3942
  parseAssignmentObjectPatternProperty() {
3942
3943
  if (this.consumePunctuator("...") !== void 0) {
3943
3944
  const start = this.previousToken().start;
3944
- const token2 = this.currentToken();
3945
- if (token2.type !== "identifier") {
3945
+ const argument = this.parseAssignmentTarget();
3946
+ if (argument.type !== "Identifier" && (argument.type !== "MemberExpression" || this.hasOptionalAssignmentChain(argument))) {
3946
3947
  throw new Error(
3947
- `Object rest element must bind to an identifier at line ${token2.start.line}, column ${token2.start.column}.`
3948
+ `Object rest assignment requires an identifier or member target at line ${argument.span.start.line}, column ${argument.span.start.column}.`
3948
3949
  );
3949
3950
  }
3950
- const argument = this.parseBindingIdentifier();
3951
3951
  return {
3952
3952
  type: "RestElement",
3953
3953
  argument,
@@ -4427,6 +4427,7 @@ var Parser = class {
4427
4427
  const expression = this.parseExpression({ allowSequence: true });
4428
4428
  const end = this.expectPunctuator(")");
4429
4429
  expression.node.span = createSpan2(start.start, end.end);
4430
+ this.parenthesizedNodes.add(expression.node);
4430
4431
  return {
4431
4432
  node: expression.node,
4432
4433
  parenthesized: true
@@ -4963,9 +4964,9 @@ var Parser = class {
4963
4964
  }
4964
4965
  toObjectPatternProperty(property) {
4965
4966
  if (property.type === "SpreadElement") {
4966
- if (property.argument.type !== "Identifier") {
4967
+ if (property.argument.type !== "Identifier" && (property.argument.type !== "MemberExpression" || this.hasOptionalAssignmentChain(property.argument))) {
4967
4968
  throw new Error(
4968
- `Object rest element must bind to an identifier at line ${property.argument.span.start.line}, column ${property.argument.span.start.column}.`
4969
+ `Object rest assignment requires an identifier or member target at line ${property.argument.span.start.line}, column ${property.argument.span.start.column}.`
4969
4970
  );
4970
4971
  }
4971
4972
  return {
@@ -4984,6 +4985,15 @@ var Parser = class {
4984
4985
  span: property.span
4985
4986
  };
4986
4987
  }
4988
+ hasOptionalAssignmentChain(node) {
4989
+ while (node.type === "MemberExpression" || node.type === "CallExpression") {
4990
+ if (node.optional) return true;
4991
+ const base = node.type === "MemberExpression" ? node.object : node.callee;
4992
+ if (this.parenthesizedNodes.has(base)) return false;
4993
+ node = base;
4994
+ }
4995
+ return false;
4996
+ }
4987
4997
  toObjectPropertyValue(value) {
4988
4998
  if (value.type === "AssignmentExpression" && value.operator === "=") {
4989
4999
  return {
@@ -9476,7 +9486,7 @@ function syncIterator(iterator) {
9476
9486
  }
9477
9487
 
9478
9488
  // packages/safe-js/src/interp/patterns.ts
9479
- async function bindPattern(pattern, value, target, scope, context) {
9489
+ async function bindPattern(pattern, value, target, scope, context, reference) {
9480
9490
  switch (pattern.type) {
9481
9491
  case "Identifier":
9482
9492
  bindIdentifier(pattern, value, target, scope);
@@ -9485,15 +9495,15 @@ async function bindPattern(pattern, value, target, scope, context) {
9485
9495
  if ("kind" in target) {
9486
9496
  throw new TypeError("Destructuring declarations cannot bind to member expressions.");
9487
9497
  }
9488
- return bindMemberExpression(pattern, value, scope, context);
9498
+ return bindMemberExpression(pattern, value, context, reference);
9489
9499
  case "AssignmentPattern":
9490
- return bindAssignmentPattern(pattern, value, target, scope, context);
9500
+ return bindAssignmentPattern(pattern, value, target, scope, context, reference);
9491
9501
  case "ArrayPattern":
9492
9502
  return bindArrayPattern(pattern, value, target, scope, context);
9493
9503
  case "ObjectPattern":
9494
9504
  return bindObjectPattern(pattern, value, target, scope, context);
9495
9505
  case "RestElement":
9496
- return bindPattern(pattern.argument, value, target, scope, context);
9506
+ return bindPattern(pattern.argument, value, target, scope, context, reference);
9497
9507
  }
9498
9508
  }
9499
9509
  function bindIdentifier(pattern, value, target, scope) {
@@ -9512,9 +9522,9 @@ function bindIdentifier(pattern, value, target, scope) {
9512
9522
  }
9513
9523
  scope.declare(pattern.name, target.kind, value);
9514
9524
  }
9515
- async function bindAssignmentPattern(pattern, value, target, scope, context) {
9525
+ async function bindAssignmentPattern(pattern, value, target, scope, context, reference) {
9516
9526
  if (value !== void 0) {
9517
- return bindPattern(pattern.left, value, target, scope, context);
9527
+ return bindPattern(pattern.left, value, target, scope, context, reference);
9518
9528
  }
9519
9529
  const defaultValue = await context.evaluate(
9520
9530
  pattern.right,
@@ -9523,7 +9533,26 @@ async function bindAssignmentPattern(pattern, value, target, scope, context) {
9523
9533
  if (defaultValue.kind !== "normal") {
9524
9534
  return { ok: false, result: defaultValue };
9525
9535
  }
9526
- return bindPattern(pattern.left, defaultValue.value, target, scope, context);
9536
+ return bindPattern(pattern.left, defaultValue.value, target, scope, context, reference);
9537
+ }
9538
+ async function bindPatternValue(pattern, readValue, target, scope, context) {
9539
+ let member = pattern;
9540
+ while (member.type === "AssignmentPattern" || member.type === "RestElement")
9541
+ member = member.type === "AssignmentPattern" ? member.left : member.argument;
9542
+ let reference;
9543
+ if ("assign" in target && member.type === "MemberExpression") {
9544
+ const prepared = await prepareMemberReference(member, context);
9545
+ if (!prepared.ok) return prepared;
9546
+ reference = prepared.reference;
9547
+ }
9548
+ let value;
9549
+ const release = context.budget === void 0 ? () => void 0 : retainValues(context.budget, () => [reference?.object, reference?.key, value]);
9550
+ try {
9551
+ value = (await readValue()).value;
9552
+ return await bindPattern(pattern, value, target, scope, context, reference);
9553
+ } finally {
9554
+ release();
9555
+ }
9527
9556
  }
9528
9557
  async function bindArrayPattern(pattern, value, target, scope, context) {
9529
9558
  const budget = context.budget ?? new Budget();
@@ -9560,20 +9589,22 @@ async function bindArrayPattern(pattern, value, target, scope, context) {
9560
9589
  await next(false);
9561
9590
  continue;
9562
9591
  }
9563
- let elementValue;
9564
- if (element.type === "RestElement") {
9565
- const rest = [];
9566
- retained = rest;
9567
- for (let entry = await next(); !done; entry = await next()) {
9568
- budget.allocateArrayLength(rest.length + 1);
9569
- rest.push(entry.value);
9570
- }
9571
- elementValue = rest;
9572
- } else {
9573
- elementValue = (await next()).value;
9574
- }
9575
- retained = elementValue;
9576
- const binding = await bindPattern(element, elementValue, target, scope, context);
9592
+ const binding = await bindPatternValue(
9593
+ element,
9594
+ async () => {
9595
+ if (element.type !== "RestElement") return next();
9596
+ const rest = [];
9597
+ retained = rest;
9598
+ for (let entry = await next(); !done; entry = await next()) {
9599
+ budget.allocateArrayLength(rest.length + 1);
9600
+ rest.push(entry.value);
9601
+ }
9602
+ return { value: rest };
9603
+ },
9604
+ target,
9605
+ scope,
9606
+ context
9607
+ );
9577
9608
  if (!binding.ok) {
9578
9609
  if (!done) {
9579
9610
  done = true;
@@ -9595,15 +9626,15 @@ async function bindArrayPattern(pattern, value, target, scope, context) {
9595
9626
  }
9596
9627
  }
9597
9628
  async function bindObjectPattern(pattern, value, target, scope, context) {
9598
- if (typeof value !== "object" || value === null) {
9599
- throw new TypeError("Object destructuring declarations require a non-null object value.");
9629
+ if (value === void 0 || value === null) {
9630
+ throw new TypeError("Object destructuring requires a non-nullish value.");
9600
9631
  }
9601
9632
  const excludedKeys = /* @__PURE__ */ new Set();
9602
9633
  for (const property of pattern.properties) {
9603
9634
  if (property.type === "RestElement") {
9604
- const binding2 = await bindPattern(
9635
+ const binding2 = await bindPatternValue(
9605
9636
  property,
9606
- await copyObjectRestValue(value, excludedKeys, context),
9637
+ async () => ({ value: await copyObjectRestValue(value, excludedKeys, context) }),
9607
9638
  target,
9608
9639
  scope,
9609
9640
  context
@@ -9618,9 +9649,9 @@ async function bindObjectPattern(pattern, value, target, scope, context) {
9618
9649
  return key;
9619
9650
  }
9620
9651
  excludedKeys.add(typeof key.value === "symbol" ? key.value : String(key.value));
9621
- const binding = await bindPattern(
9652
+ const binding = await bindPatternValue(
9622
9653
  property.value,
9623
- await context.getProperty(value, key.value),
9654
+ async () => ({ value: await context.getProperty(value, key.value) }),
9624
9655
  target,
9625
9656
  scope,
9626
9657
  context
@@ -9631,7 +9662,22 @@ async function bindObjectPattern(pattern, value, target, scope, context) {
9631
9662
  }
9632
9663
  return { ok: true };
9633
9664
  }
9634
- async function bindMemberExpression(pattern, value, scope, context) {
9665
+ async function bindMemberExpression(pattern, value, context, reference) {
9666
+ if (reference === void 0) {
9667
+ const prepared = await prepareMemberReference(pattern, context);
9668
+ if (!prepared.ok) return prepared;
9669
+ reference = prepared.reference;
9670
+ }
9671
+ if (reference.object === null || reference.object === void 0) {
9672
+ throw new TypeError("Cannot assign properties of null or undefined.");
9673
+ }
9674
+ if (!isIndexableValue(reference.object)) {
9675
+ throw new TypeError("Assignment expressions require a sandbox object property.");
9676
+ }
9677
+ await context.setProperty(reference.object, reference.key, value);
9678
+ return { ok: true };
9679
+ }
9680
+ async function prepareMemberReference(pattern, context) {
9635
9681
  const object = await context.evaluate(pattern.object);
9636
9682
  if (object.kind !== "normal") {
9637
9683
  return { ok: false, result: object };
@@ -9640,14 +9686,10 @@ async function bindMemberExpression(pattern, value, scope, context) {
9640
9686
  if (property.kind !== "normal") {
9641
9687
  return { ok: false, result: property };
9642
9688
  }
9643
- if (object.value === null || object.value === void 0) {
9644
- throw new TypeError("Cannot assign properties of null or undefined.");
9645
- }
9646
- if (!isIndexableValue(object.value)) {
9647
- throw new TypeError("Assignment expressions require a sandbox object property.");
9648
- }
9649
- await context.setProperty(object.value, await context.toPropertyKey(property.value), value);
9650
- return { ok: true };
9689
+ return {
9690
+ ok: true,
9691
+ reference: { object: object.value, key: await context.toPropertyKey(property.value) }
9692
+ };
9651
9693
  }
9652
9694
  async function evaluatePatternKey(property, context) {
9653
9695
  return property.computed ? evaluateProperty(property.key, context) : { ok: true, value: getStaticPropertyName(property.key) };
@@ -35886,4 +35928,4 @@ export {
35886
35928
  FileSnapshotBackend,
35887
35929
  run
35888
35930
  };
35889
- //# sourceMappingURL=chunk-AW3IBVVD.js.map
35931
+ //# sourceMappingURL=chunk-IHPQO2HC.js.map