@poe-platform/safe-js 0.1.233 → 0.1.235

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.
@@ -9865,17 +9865,24 @@ function bindIdentifier(pattern, value, target, scope) {
9865
9865
  scope.declare(pattern.name, target.kind, value);
9866
9866
  }
9867
9867
  async function bindAssignmentPattern2(pattern, value, target, scope, context, reference) {
9868
- if (value !== void 0) {
9869
- return bindPattern2(pattern.left, value, target, scope, context, reference);
9868
+ const saved = pattern.nodeId === void 0 ? void 0 : context.restoredPatternState?.(pattern.nodeId);
9869
+ if (saved !== void 0 && saved.kind !== "pattern-source") throw new TypeError("Invalid pattern default continuation.");
9870
+ if (saved !== void 0) value = saved.value;
9871
+ else if (value === void 0) {
9872
+ const defaultValue = await context.evaluate(
9873
+ pattern.right,
9874
+ pattern.left.type === "Identifier" ? pattern.left.name : void 0
9875
+ );
9876
+ if (defaultValue.kind !== "normal") return { ok: false, result: defaultValue };
9877
+ value = defaultValue.value;
9870
9878
  }
9871
- const defaultValue = await context.evaluate(
9872
- pattern.right,
9873
- pattern.left.type === "Identifier" ? pattern.left.name : void 0
9874
- );
9875
- if (defaultValue.kind !== "normal") {
9876
- return { ok: false, result: defaultValue };
9879
+ const bindingContext = pattern.nodeId === void 0 || pattern.left.type !== "ArrayPattern" && pattern.left.type !== "ObjectPattern" ? context : context.withPatternState?.(pattern.nodeId, { kind: "pattern-source", value }) ?? context;
9880
+ const release = context.budget === void 0 ? () => void 0 : retainValues(context.budget, () => [value]);
9881
+ try {
9882
+ return await bindPattern2(pattern.left, value, target, scope, bindingContext, reference);
9883
+ } finally {
9884
+ release();
9877
9885
  }
9878
- return bindPattern2(pattern.left, defaultValue.value, target, scope, context, reference);
9879
9886
  }
9880
9887
  async function bindPatternValue(pattern, readValue, target, scope, context, onRead) {
9881
9888
  let member = pattern;
@@ -10011,38 +10018,65 @@ async function bindObjectPattern2(pattern, value, target, scope, context) {
10011
10018
  if (value === void 0 || value === null) {
10012
10019
  throw new TypeError("Object destructuring requires a non-nullish value.");
10013
10020
  }
10014
- const excludedKeys = /* @__PURE__ */ new Set();
10015
- for (const property of pattern.properties) {
10016
- if (property.type === "RestElement") {
10017
- const binding2 = await bindPatternValue(
10018
- property,
10019
- async () => ({ value: await copyObjectRestValue(value, excludedKeys, context) }),
10021
+ const saved = pattern.nodeId === void 0 ? void 0 : context.restoredPatternState?.(pattern.nodeId);
10022
+ if (saved !== void 0 && saved.kind !== "object-pattern") throw new TypeError("Invalid object pattern continuation.");
10023
+ const excludedKeys = new Set(saved?.excludedKeys);
10024
+ const excludedKeyValues = [...excludedKeys];
10025
+ let state;
10026
+ const release = context.budget === void 0 ? () => void 0 : retainValues(
10027
+ context.budget,
10028
+ () => [value, state?.current, state?.key, state?.referenceObject, state?.referenceKey, ...state?.excludedKeys ?? []]
10029
+ );
10030
+ try {
10031
+ for (let index = saved?.index ?? 0; index < pattern.properties.length; index++) {
10032
+ const property = pattern.properties[index];
10033
+ state = saved !== void 0 && index === saved.index ? { ...saved, excludedKeys: excludedKeyValues } : {
10034
+ kind: "object-pattern",
10035
+ phase: property.type === "RestElement" ? "reference" : "key",
10036
+ index,
10037
+ excludedKeys: excludedKeyValues,
10038
+ key: void 0,
10039
+ current: void 0
10040
+ };
10041
+ const currentState = state;
10042
+ const propertyContext = pattern.nodeId === void 0 ? context : context.withPatternState?.(pattern.nodeId, state) ?? context;
10043
+ if (property.type !== "RestElement" && state.phase === "key") {
10044
+ const key = await evaluatePatternKey(property, propertyContext);
10045
+ if (!key.ok) return key;
10046
+ state.key = typeof key.value === "symbol" ? key.value : String(key.value);
10047
+ if (!excludedKeys.has(state.key)) excludedKeyValues.push(state.key);
10048
+ excludedKeys.add(state.key);
10049
+ state.phase = "reference";
10050
+ }
10051
+ const element = property.type === "RestElement" ? property : property.value;
10052
+ const binding = state.phase === "binding" ? await bindPattern2(
10053
+ element,
10054
+ state.current,
10020
10055
  target,
10021
10056
  scope,
10022
- context
10057
+ propertyContext,
10058
+ Object.hasOwn(state, "referenceObject") ? { object: state.referenceObject, key: state.referenceKey } : void 0
10059
+ ) : await bindPatternValue(
10060
+ element,
10061
+ async () => ({ value: property.type === "RestElement" ? await copyObjectRestValue(value, excludedKeys, propertyContext) : await propertyContext.getProperty(value, currentState.key) }),
10062
+ target,
10063
+ scope,
10064
+ propertyContext,
10065
+ (current, reference) => {
10066
+ currentState.current = current;
10067
+ currentState.phase = "binding";
10068
+ if (reference !== void 0) {
10069
+ currentState.referenceObject = reference.object;
10070
+ currentState.referenceKey = reference.key;
10071
+ }
10072
+ }
10023
10073
  );
10024
- if (!binding2.ok) {
10025
- return binding2;
10026
- }
10027
- continue;
10028
- }
10029
- const key = await evaluatePatternKey(property, context);
10030
- if (!key.ok) {
10031
- return key;
10032
- }
10033
- excludedKeys.add(typeof key.value === "symbol" ? key.value : String(key.value));
10034
- const binding = await bindPatternValue(
10035
- property.value,
10036
- async () => ({ value: await context.getProperty(value, key.value) }),
10037
- target,
10038
- scope,
10039
- context
10040
- );
10041
- if (!binding.ok) {
10042
- return binding;
10074
+ if (!binding.ok) return binding;
10043
10075
  }
10076
+ return { ok: true };
10077
+ } finally {
10078
+ release();
10044
10079
  }
10045
- return { ok: true };
10046
10080
  }
10047
10081
  async function bindMemberExpression(pattern, value, context, reference) {
10048
10082
  if (reference === void 0) {
@@ -20984,7 +21018,15 @@ function captureGuestHeapNode(value, encode) {
20984
21018
  ...value.state !== "suspended" || origin2.expressionStates === void 0 ? {} : {
20985
21019
  expressionStates: Object.fromEntries([...origin2.expressionStates].map(([id, expression]) => [
20986
21020
  String(id),
20987
- expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : expression.kind === "pattern-source" ? { kind: "pattern-source", value: encode(expression.value) } : expression.kind === "array-pattern" ? {
21021
+ expression.kind === "binary" ? { kind: "binary", left: encode(expression.left) } : expression.kind === "pattern-source" ? { kind: "pattern-source", value: encode(expression.value) } : expression.kind === "object-pattern" ? {
21022
+ kind: "object-pattern",
21023
+ phase: expression.phase,
21024
+ index: expression.index,
21025
+ excludedKeys: expression.excludedKeys.map(encode),
21026
+ key: encode(expression.key),
21027
+ current: encode(expression.current),
21028
+ ...Object.hasOwn(expression, "referenceObject") ? { referenceObject: encode(expression.referenceObject), referenceKey: encode(expression.referenceKey) } : {}
21029
+ } : expression.kind === "array-pattern" ? {
20988
21030
  kind: "array-pattern",
20989
21031
  phase: expression.phase,
20990
21032
  index: expression.index,
@@ -22644,6 +22686,14 @@ function validateGuestHeapNode(raw, heap, maxArrayLength = 4294967295) {
22644
22686
  fields(expression, ["kind", "left"]);
22645
22687
  } else if (expression.kind === "pattern-source") {
22646
22688
  fields(expression, ["kind", "value"]);
22689
+ } else if (expression.kind === "object-pattern") {
22690
+ fields(expression, ["kind", "phase", "index", "excludedKeys", "key", "current"], ["referenceObject", "referenceKey"]);
22691
+ integer(expression.index);
22692
+ if (!["key", "reference", "binding"].includes(String(expression.phase)) || Object.hasOwn(expression, "referenceObject") !== Object.hasOwn(expression, "referenceKey")) throw new TypeError("Invalid object pattern state.");
22693
+ for (const key of array(expression.excludedKeys)) if (typeof key !== "string") reference(key, ["symbol"]);
22694
+ if (!absent(expression.key) && typeof expression.key !== "string") reference(expression.key, ["symbol"]);
22695
+ if (Object.hasOwn(expression, "referenceObject") && expression.phase !== "binding") throw new TypeError("Invalid prepared object pattern reference.");
22696
+ if (Object.hasOwn(expression, "referenceKey") && typeof expression.referenceKey !== "string") reference(expression.referenceKey, ["symbol"]);
22647
22697
  } else if (expression.kind === "for-of-array" || expression.kind === "for-of-iterator" || expression.kind === "array-pattern") {
22648
22698
  if (expression.kind === "array-pattern") {
22649
22699
  fields(expression, ["kind", "phase", "index", "done", "current", "iterator"], ["referenceObject", "referenceKey"]);
@@ -22853,6 +22903,20 @@ function validateGuestFunctionAst(record3, origin) {
22853
22903
  });
22854
22904
  continue;
22855
22905
  }
22906
+ if (node.type === "ObjectPattern" && key === "properties" && typeof node.nodeId === "number" && Array.isArray(value)) {
22907
+ const id = node.nodeId;
22908
+ value.forEach((property, index) => {
22909
+ for (const part of property.type === "RestElement" ? ["argument"] : ["key", "value"]) {
22910
+ pending.push({
22911
+ value: property[part],
22912
+ blocks,
22913
+ finalizers: frame.finalizers,
22914
+ expressions: new Map([...frame.expressions, [id, { kind: "object-pattern", index, key: part === "key" }]])
22915
+ });
22916
+ }
22917
+ });
22918
+ continue;
22919
+ }
22856
22920
  if (node.type === "ObjectExpression" && key === "properties" && typeof node.nodeId === "number" && Array.isArray(value)) {
22857
22921
  const id = node.nodeId;
22858
22922
  value.forEach((property, index) => {
@@ -22891,7 +22955,7 @@ function validateGuestFunctionAst(record3, origin) {
22891
22955
  pending.push({
22892
22956
  value,
22893
22957
  blocks,
22894
- expressions: (node.type === "VariableDeclarator" && key === "id" && node.init !== void 0 || node.type === "AssignmentExpression" && key === "left") && typeof node.nodeId === "number" && ["ArrayPattern", "ObjectPattern"].includes(String(value?.type)) ? new Map([...frame.expressions, [node.nodeId, { kind: "pattern-source" }]]) : node.type === "ForOfStatement" && ["left", "body"].includes(key) && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "for-of", phase: key, async: node.await === true }]]) : node.type === "ForInStatement" && ["left", "body"].includes(key) && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "for-in", phase: key }]]) : node.type === "ForStatement" && ["init", "test", "body", "update"].includes(key) && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "for", phase: key }]]) : node.type === "BinaryExpression" && key === "right" && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "binary" }]]) : node.type === "AssignmentExpression" && key === "right" && typeof node.nodeId === "number" && node.left.type === "Identifier" ? new Map([...frame.expressions, [node.nodeId, { kind: "identifier-assignment" }]]) : node.type === "AssignmentExpression" && key === "right" && typeof node.nodeId === "number" && node.left.type === "MemberExpression" ? new Map([...frame.expressions, [node.nodeId, {
22958
+ expressions: (node.type === "VariableDeclarator" && key === "id" && node.init !== void 0 || (node.type === "AssignmentExpression" || node.type === "AssignmentPattern") && key === "left") && typeof node.nodeId === "number" && ["ArrayPattern", "ObjectPattern"].includes(String(value?.type)) ? new Map([...frame.expressions, [node.nodeId, { kind: "pattern-source" }]]) : node.type === "ForOfStatement" && ["left", "body"].includes(key) && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "for-of", phase: key, async: node.await === true }]]) : node.type === "ForInStatement" && ["left", "body"].includes(key) && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "for-in", phase: key }]]) : node.type === "ForStatement" && ["init", "test", "body", "update"].includes(key) && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "for", phase: key }]]) : node.type === "BinaryExpression" && key === "right" && typeof node.nodeId === "number" ? new Map([...frame.expressions, [node.nodeId, { kind: "binary" }]]) : node.type === "AssignmentExpression" && key === "right" && typeof node.nodeId === "number" && node.left.type === "Identifier" ? new Map([...frame.expressions, [node.nodeId, { kind: "identifier-assignment" }]]) : node.type === "AssignmentExpression" && key === "right" && typeof node.nodeId === "number" && node.left.type === "MemberExpression" ? new Map([...frame.expressions, [node.nodeId, {
22895
22959
  kind: "member-assignment",
22896
22960
  key: node.operator !== "=",
22897
22961
  superReceiver: node.left.object.type === "Super"
@@ -22921,7 +22985,7 @@ function validateGuestFunctionAst(record3, origin) {
22921
22985
  for (const [id, expression] of expressions) {
22922
22986
  const expected = yieldExpressions?.get(Number(id));
22923
22987
  const compatibleKind = expected?.kind === expression.kind || expected?.kind === "for-of" && (expression.kind === "for-of-iterator" || !expected.async && expression.kind === "for-of-array") || expected?.kind === "call" && expected.member === true && expression.kind === "array-call";
22924
- if (expected === void 0 || !compatibleKind || expected.kind !== "binary" && expected.kind !== "pattern-source" && expected.kind !== "identifier-assignment" && expected.kind !== "member" && expected.kind !== "member-assignment" && expected.kind !== "for" && expected.kind !== "for-in" && expected.kind !== "for-of" && expected.index !== expression.index || (expected.kind === "for" || expected.kind === "for-of") && expected.phase !== expression.phase || expected.kind === "for-in" && expected.phase !== (expression.phase ?? "body") || expected.kind === "for-of" && expression.kind === "for-of-iterator" && expected.async !== expression.async || expected.kind === "member-assignment" && (expected.key !== Object.hasOwn(expression, "key") || expected.superReceiver !== Object.hasOwn(expression, "superReceiver")) || expected.kind === "member" && expected.superReceiver !== Object.hasOwn(expression, "superReceiver") || expected.kind === "object" && expected.key !== Object.hasOwn(expression, "key"))
22988
+ if (expected === void 0 || !compatibleKind || expected.kind !== "binary" && expected.kind !== "pattern-source" && expected.kind !== "identifier-assignment" && expected.kind !== "member" && expected.kind !== "member-assignment" && expected.kind !== "for" && expected.kind !== "for-in" && expected.kind !== "for-of" && expected.index !== expression.index || (expected.kind === "for" || expected.kind === "for-of") && expected.phase !== expression.phase || expected.kind === "for-in" && expected.phase !== (expression.phase ?? "body") || expected.kind === "object-pattern" && expected.key !== (expression.phase === "key") || expected.kind === "for-of" && expression.kind === "for-of-iterator" && expected.async !== expression.async || expected.kind === "member-assignment" && (expected.key !== Object.hasOwn(expression, "key") || expected.superReceiver !== Object.hasOwn(expression, "superReceiver")) || expected.kind === "member" && expected.superReceiver !== Object.hasOwn(expression, "superReceiver") || expected.kind === "object" && expected.key !== Object.hasOwn(expression, "key"))
22925
22989
  throw new TypeError("Invalid generator AST identity: unrelated expression continuation");
22926
22990
  }
22927
22991
  }
@@ -39167,4 +39231,4 @@ export {
39167
39231
  FileSnapshotBackend,
39168
39232
  run
39169
39233
  };
39170
- //# sourceMappingURL=chunk-4EKZGMNU.js.map
39234
+ //# sourceMappingURL=chunk-63CXQYH2.js.map