@opencode/codemode 0.0.0-dev-20144 → 0.0.0-dev-20146

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.
@@ -884,20 +884,20 @@ class Frame {
884
884
  return;
885
885
  }
886
886
  if (pattern.type === "ObjectPattern") {
887
- if (!(value instanceof Obj)) {
888
- throw typeError(`Object destructuring requires a data object or array value, received ${describeValue(value)}.`, pattern);
887
+ if (value === null || value === undefined) {
888
+ throw typeError(`Cannot destructure ${describeValue(value)} as it is ${value}.`, pattern);
889
889
  }
890
890
  const consumed = new Set();
891
891
  for (const property of pattern.properties) {
892
892
  if (property.type === "RestElement") {
893
893
  const rest = new Obj(self.ctx.builtins.Object);
894
- assign(rest, value, consumed);
894
+ assign(rest, enumerableSource(self.ctx, "Object destructuring", value, pattern), consumed);
895
895
  yield* self.declarePattern(property.argument, rest, mutable, property, initialize);
896
896
  continue;
897
897
  }
898
898
  const key = yield* self.destructuringPropertyKey(property);
899
899
  consumed.add(typeof key === "symbol" ? key : String(key));
900
- yield* self.declarePattern(property.value, self.readProperty(value, key, property), mutable, property, initialize);
900
+ yield* self.declarePattern(property.value, self.destructuredProperty(value, key, property), mutable, property, initialize);
901
901
  }
902
902
  return;
903
903
  }
@@ -924,20 +924,20 @@ class Frame {
924
924
  return;
925
925
  }
926
926
  if (pattern.type === "ObjectPattern") {
927
- if (!(value instanceof Obj)) {
928
- throw invalidData(`Object destructuring requires a data object or array value, received ${describeValue(value)}.`, pattern);
927
+ if (value === null || value === undefined) {
928
+ throw typeError(`Cannot destructure ${describeValue(value)} as it is ${value}.`, pattern);
929
929
  }
930
930
  const consumed = new Set();
931
931
  for (const property of pattern.properties) {
932
932
  if (property.type === "RestElement") {
933
933
  const rest = new Obj(self.ctx.builtins.Object);
934
- assign(rest, value, consumed);
934
+ assign(rest, enumerableSource(self.ctx, "Object destructuring", value, pattern), consumed);
935
935
  yield* self.assignPattern(property.argument, rest, property);
936
936
  continue;
937
937
  }
938
938
  const key = yield* self.destructuringPropertyKey(property);
939
939
  consumed.add(typeof key === "symbol" ? key : String(key));
940
- yield* self.assignPattern(property.value, self.readProperty(value, key, property), property);
940
+ yield* self.assignPattern(property.value, self.destructuredProperty(value, key, property), property);
941
941
  }
942
942
  return;
943
943
  }
@@ -1825,31 +1825,43 @@ class Frame {
1825
1825
  : propertyNode.type === "Identifier"
1826
1826
  ? propertyNode.name
1827
1827
  : self.toPropertyKey(yield* self.evaluateExpression(propertyNode));
1828
- if (objectValue instanceof ToolReference) {
1829
- if (typeof key !== "string") {
1830
- throw typeError("Tool paths must use string property names.", propertyNode);
1831
- }
1832
- return new ToolReference([...objectValue.path, key]);
1833
- }
1834
- if (objectValue instanceof Obj)
1835
- return { target: objectValue, key, receiver: objectValue };
1836
- // Strings own length and indexes; every other primitive property reads through the wrapper prototype.
1837
- if (typeof objectValue === "string") {
1838
- if (key === "length")
1839
- return { value: objectValue.length };
1840
- const index = typeof key === "symbol" ? undefined : parseArrayIndex(key);
1841
- if (index !== undefined)
1842
- return { value: objectValue[index] };
1843
- }
1844
- const proto = primitivePrototype(self.ctx.builtins, objectValue);
1845
- if (proto !== undefined)
1846
- return { target: proto, key, receiver: objectValue };
1847
- if (objectValue === null || objectValue === undefined) {
1848
- throw typeError(`Cannot read properties of ${objectValue} (reading '${String(key)}').`, objectNode);
1849
- }
1850
- throw typeError("Cannot access a property on a non-object value.", objectNode);
1828
+ return self.resolveProperty(objectValue, key, objectNode, propertyNode);
1851
1829
  });
1852
1830
  }
1831
+ resolveProperty(objectValue, key, objectNode, propertyNode) {
1832
+ if (objectValue instanceof ToolReference) {
1833
+ if (typeof key !== "string") {
1834
+ throw typeError("Tool paths must use string property names.", propertyNode);
1835
+ }
1836
+ return new ToolReference([...objectValue.path, key]);
1837
+ }
1838
+ if (objectValue instanceof Obj)
1839
+ return { target: objectValue, key, receiver: objectValue };
1840
+ // Strings own length and indexes; every other primitive property reads through the wrapper prototype.
1841
+ if (typeof objectValue === "string") {
1842
+ if (key === "length")
1843
+ return { value: objectValue.length };
1844
+ const index = typeof key === "symbol" ? undefined : parseArrayIndex(key);
1845
+ if (index !== undefined)
1846
+ return { value: objectValue[index] };
1847
+ }
1848
+ const proto = primitivePrototype(this.ctx.builtins, objectValue);
1849
+ if (proto !== undefined)
1850
+ return { target: proto, key, receiver: objectValue };
1851
+ if (objectValue === null || objectValue === undefined) {
1852
+ throw typeError(`Cannot read properties of ${objectValue} (reading '${String(key)}').`, objectNode);
1853
+ }
1854
+ throw typeError("Cannot access a property on a non-object value.", objectNode);
1855
+ }
1856
+ // One destructured property, read the way a member expression would read it (primitives use their prototype).
1857
+ destructuredProperty(source, key, node) {
1858
+ const reference = this.resolveProperty(source, key, node, node);
1859
+ if (reference instanceof ToolReference)
1860
+ return reference;
1861
+ if ("value" in reference)
1862
+ return reference.value;
1863
+ return this.readProperty(reference.target, reference.key, node, reference.receiver);
1864
+ }
1853
1865
  readReference(reference, node) {
1854
1866
  // Reject unknown promise properties so a missing await cannot hide.
1855
1867
  if (reference.target instanceof PromiseObj && !has(reference.target, reference.key)) {
@@ -14,8 +14,8 @@ const constructDate = (ctx, args, proto) => {
14
14
  ? new DateObj(proto, Date.parse(value))
15
15
  : new DateObj(proto, new Date(coerceToNumber(value)).getTime()));
16
16
  }
17
- const parts = args.map((arg) => coerceToNumber(arg));
18
- return Effect.succeed(new DateObj(proto, new Date(...parts).getTime()));
17
+ // The spec converts at most seven components, in order, so extra arguments never run program code.
18
+ return Effect.map(Effect.forEach(args.slice(0, 7), (arg) => toPrimitiveNumber(ctx, arg), { concurrency: 1 }), (parts) => new DateObj(proto, new Date(...parts).getTime()));
19
19
  };
20
20
  const getters = [
21
21
  "getFullYear",
@@ -66,7 +66,11 @@ export const dateGlobal = (ctx) => {
66
66
  methods(builtins, date, [
67
67
  ["now", 0, () => Date.now()],
68
68
  ["parse", 1, (_, args) => Date.parse(coerceToString(args[0]))],
69
- ["UTC", 7, (_, args) => Date.UTC(...args.map((arg) => coerceToNumber(arg)))],
69
+ [
70
+ "UTC",
71
+ 7,
72
+ (_, args) => Effect.map(Effect.forEach(args.slice(0, 7), (arg) => toPrimitiveNumber(ctx, arg), { concurrency: 1 }), (parts) => Date.UTC(...parts)),
73
+ ],
70
74
  ]);
71
75
  const self = (thisValue, name) => receiver(DateObj, thisValue, `Date.prototype.${name}`);
72
76
  const iso = (value) => {
@@ -107,6 +111,9 @@ export const dateGlobal = (ctx) => {
107
111
  return Effect.map(Effect.forEach(args.slice(0, length), (arg) => toPrimitiveNumber(ctx, arg), {
108
112
  concurrency: 1,
109
113
  }), (values) => {
114
+ // Every setter but setTime and setFullYear leaves an invalid Date untouched and answers NaN.
115
+ if (Number.isNaN(hosted.getTime()) && name !== "setTime" && !name.endsWith("FullYear"))
116
+ return NaN;
110
117
  target.time = hosted[name](...values);
111
118
  return target.time;
112
119
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/codemode",
4
- "version": "0.0.0-dev-20144",
4
+ "version": "0.0.0-dev-20146",
5
5
  "description": "Effect-native confined code execution over schema-described tools",
6
6
  "type": "module",
7
7
  "license": "MIT",