@opencode/codemode 0.0.0-dev-19937 → 0.0.0-dev-19941
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/data.d.ts +5 -4
- package/dist/interpreter/callback.d.ts +8 -8
- package/dist/interpreter/callback.js +1 -2
- package/dist/interpreter/errors.d.ts +3 -3
- package/dist/interpreter/errors.js +1 -2
- package/dist/interpreter/execute.d.ts +2 -1
- package/dist/interpreter/extensions.d.ts +2 -1
- package/dist/interpreter/extensions.js +7 -35
- package/dist/interpreter/globals.d.ts +2 -1
- package/dist/interpreter/interpreter.d.ts +8 -14
- package/dist/interpreter/interpreter.js +25 -52
- package/dist/interpreter/intrinsics.d.ts +2 -2
- package/dist/interpreter/model.d.ts +7 -8
- package/dist/interpreter/model.js +0 -1
- package/dist/interpreter/native.d.ts +5 -5
- package/dist/interpreter/objects.d.ts +127 -42
- package/dist/interpreter/objects.js +207 -25
- package/dist/interpreter/promises.d.ts +7 -7
- package/dist/interpreter/references.d.ts +8 -7
- package/dist/interpreter/references.js +10 -46
- package/dist/interpreter/scope.d.ts +5 -4
- package/dist/stdlib/array.d.ts +2 -1
- package/dist/stdlib/array.js +1 -2
- package/dist/stdlib/bytes.js +1 -2
- package/dist/stdlib/collections.js +6 -13
- package/dist/stdlib/console.d.ts +2 -2
- package/dist/stdlib/console.js +6 -50
- package/dist/stdlib/date.js +1 -2
- package/dist/stdlib/headers.js +8 -11
- package/dist/stdlib/iterator.js +1 -1
- package/dist/stdlib/number.js +2 -1
- package/dist/stdlib/object.d.ts +3 -4
- package/dist/stdlib/object.js +4 -15
- package/dist/stdlib/regexp.d.ts +3 -3
- package/dist/stdlib/regexp.js +1 -2
- package/dist/stdlib/string.js +8 -13
- package/dist/stdlib/url.d.ts +2 -1
- package/dist/stdlib/url.js +2 -12
- package/dist/stdlib/value.d.ts +0 -3
- package/dist/stdlib/value.js +1 -68
- package/dist/stdlib/web.js +1 -2
- package/package.json +1 -1
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import { ToolReference } from "../tool-runtime.js";
|
|
2
2
|
import { invalidData } from "./model.js";
|
|
3
|
-
import { Callable, getOwn,
|
|
4
|
-
/**
|
|
5
|
-
export const
|
|
6
|
-
value instanceof GeneratorObj ||
|
|
7
|
-
value instanceof IteratorObj ||
|
|
8
|
-
value instanceof ToolReference ||
|
|
9
|
-
value instanceof PromiseObj ||
|
|
10
|
-
isWrapper(value);
|
|
11
|
-
function* childValues(value) {
|
|
12
|
-
if (!(value instanceof Obj))
|
|
13
|
-
return;
|
|
14
|
-
for (const key of ownKeys(value))
|
|
15
|
-
yield getOwn(value, key);
|
|
16
|
-
}
|
|
3
|
+
import { Callable, getOwn, isRuntimeReference, Obj, Opaque, ownKeys } from "./objects.js";
|
|
4
|
+
/** Interpreter machinery that is never data, unlike a Date or Map, which cross some boundaries as copies. */
|
|
5
|
+
export const isOpaque = (value) => value instanceof Opaque || value instanceof ToolReference;
|
|
17
6
|
// Depth-first search over a value tree. `match` stops the walk; `skip` prunes a subtree without matching it.
|
|
18
7
|
const find = (value, match, skip, seen) => {
|
|
19
8
|
const pending = [[value].values()];
|
|
@@ -26,17 +15,18 @@ const find = (value, match, skip, seen) => {
|
|
|
26
15
|
const current = next.value;
|
|
27
16
|
if (match(current))
|
|
28
17
|
return true;
|
|
29
|
-
if (current
|
|
18
|
+
if (!(current instanceof Obj) || skip(current) || seen.has(current))
|
|
30
19
|
continue;
|
|
31
20
|
seen.add(current);
|
|
32
|
-
pending.push(
|
|
21
|
+
pending.push(ownKeys(current)
|
|
22
|
+
.map((key) => getOwn(current, key))
|
|
23
|
+
.values());
|
|
33
24
|
}
|
|
34
25
|
return false;
|
|
35
26
|
};
|
|
36
27
|
const never = () => false;
|
|
37
28
|
export const containsRuntimeReference = (value) => find(value, isRuntimeReference, never, new Set());
|
|
38
|
-
|
|
39
|
-
export const containsOpaqueReference = (value) => find(value, (current) => !isWrapper(current) && isRuntimeReference(current), isWrapper, new Set());
|
|
29
|
+
export const containsOpaqueReference = (value) => find(value, isOpaque, (current) => isRuntimeReference(current) && !isOpaque(current), new Set());
|
|
40
30
|
// Reject cycles before mutation so later boundary walks remain safe.
|
|
41
31
|
export const rejectCircularInsertion = (container, value, label, seen = new Set()) => {
|
|
42
32
|
if (find(value, (current) => current === container, isRuntimeReference, seen)) {
|
|
@@ -46,36 +36,10 @@ export const rejectCircularInsertion = (container, value, label, seen = new Set(
|
|
|
46
36
|
export const describeValue = (value) => {
|
|
47
37
|
if (value === null || value === undefined)
|
|
48
38
|
return String(value);
|
|
49
|
-
if (value instanceof
|
|
50
|
-
return
|
|
51
|
-
if (value instanceof PromiseObj)
|
|
52
|
-
return "an un-awaited Promise";
|
|
39
|
+
if (value instanceof Obj)
|
|
40
|
+
return value.describe;
|
|
53
41
|
if (value instanceof ToolReference)
|
|
54
42
|
return "a tool reference";
|
|
55
|
-
if (value instanceof DateObj)
|
|
56
|
-
return "a Date";
|
|
57
|
-
if (value instanceof RegExpObj)
|
|
58
|
-
return "a RegExp";
|
|
59
|
-
if (value instanceof MapObj)
|
|
60
|
-
return "a Map";
|
|
61
|
-
if (value instanceof SetObj)
|
|
62
|
-
return "a Set";
|
|
63
|
-
if (value instanceof URLObj)
|
|
64
|
-
return "a URL";
|
|
65
|
-
if (value instanceof URLSearchParamsObj)
|
|
66
|
-
return "a URLSearchParams";
|
|
67
|
-
if (value instanceof HeadersObj)
|
|
68
|
-
return "a Headers";
|
|
69
|
-
if (value instanceof Bytes)
|
|
70
|
-
return "a Uint8Array";
|
|
71
|
-
if (value instanceof GeneratorObj)
|
|
72
|
-
return "a generator";
|
|
73
|
-
if (value instanceof IteratorObj)
|
|
74
|
-
return "an iterator";
|
|
75
|
-
if (isRuntimeReference(value))
|
|
76
|
-
return "a function";
|
|
77
|
-
if (typeof value === "object")
|
|
78
|
-
return "a data object";
|
|
79
43
|
return `a ${typeof value}`;
|
|
80
44
|
};
|
|
81
45
|
export const typeofValue = (value) => {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { type AstNode, type Binding } from "./model.js";
|
|
2
|
+
import type { Value } from "./objects.js";
|
|
2
3
|
export declare class ScopeStack {
|
|
3
4
|
private readonly scopes;
|
|
4
5
|
constructor(scopes: Array<Map<string, Binding>>);
|
|
5
6
|
reserve(name: string, mutable: boolean, node: AstNode): void;
|
|
6
|
-
initialize(name: string, value:
|
|
7
|
-
declare(name: string, value:
|
|
8
|
-
get(name: string, node: AstNode):
|
|
9
|
-
set(name: string, value:
|
|
7
|
+
initialize(name: string, value: Value, node: AstNode): void;
|
|
8
|
+
declare(name: string, value: Value, mutable: boolean, node: AstNode): void;
|
|
9
|
+
get(name: string, node: AstNode): Value;
|
|
10
|
+
set(name: string, value: Value, node: AstNode): Value;
|
|
10
11
|
resolve(name: string): Binding | undefined;
|
|
11
12
|
current(): Map<string, Binding>;
|
|
12
13
|
push(scope?: Map<string, Binding>): void;
|
package/dist/stdlib/array.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
+
import { type Value } from "../interpreter/objects.js";
|
|
2
3
|
import type { Interpreter } from "../interpreter/interpreter.js";
|
|
3
|
-
export declare const sortArray: <R>(ctx: Interpreter<R>, target: Array<
|
|
4
|
+
export declare const sortArray: <R>(ctx: Interpreter<R>, target: Array<Value>, comparator: Value, name: string) => Effect.Effect<Array<Value>, unknown, R>;
|
|
4
5
|
export declare const arrayGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;
|
package/dist/stdlib/array.js
CHANGED
|
@@ -2,11 +2,10 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { constructor, methods, prototypeFrom, receiver } from "../interpreter/native.js";
|
|
3
3
|
import { checkArrayLength, checkStringLength, MAX_ARRAY_LENGTH } from "../interpreter/limits.js";
|
|
4
4
|
import { invalidData, IteratorSymbol, rangeError, typeError } from "../interpreter/model.js";
|
|
5
|
-
import { define, get, hidden, Arr, GeneratorObj, IteratorObj, Obj } from "../interpreter/objects.js";
|
|
5
|
+
import { define, get, hidden, Arr, GeneratorObj, IteratorObj, Obj, coerceToNumber, coerceToString, } from "../interpreter/objects.js";
|
|
6
6
|
import { describeValue, rejectCircularInsertion } from "../interpreter/references.js";
|
|
7
7
|
import { applyCollectionCallback, invoke, preserveConsumerError } from "../interpreter/callback.js";
|
|
8
8
|
import { compareText } from "../tool-runtime.js";
|
|
9
|
-
import { coerceToNumber, coerceToString } from "./value.js";
|
|
10
9
|
const arrayLikeSource = (source) => {
|
|
11
10
|
if (source instanceof Obj && typeof get(source, "length") === "number") {
|
|
12
11
|
const length = get(source, "length");
|
package/dist/stdlib/bytes.js
CHANGED
|
@@ -2,9 +2,8 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { checkArrayLength, checkStringLength } from "../interpreter/limits.js";
|
|
3
3
|
import { constructor, methods, prototypeFrom, receiver, requiresNew } from "../interpreter/native.js";
|
|
4
4
|
import { IteratorSymbol, rangeError, syntaxError, typeError } from "../interpreter/model.js";
|
|
5
|
-
import { define, defineAccessor, get, hidden, Arr, Bytes, IteratorObj, Obj } from "../interpreter/objects.js";
|
|
5
|
+
import { define, defineAccessor, get, hidden, Arr, Bytes, IteratorObj, Obj, coerceToNumber, coerceToString, } from "../interpreter/objects.js";
|
|
6
6
|
import { describeValue } from "../interpreter/references.js";
|
|
7
|
-
import { coerceToNumber, coerceToString } from "./value.js";
|
|
8
7
|
/** The bytes a Uint8Array, array, or other iterable of numbers describes; the host array clamps each value. */
|
|
9
8
|
const collectBytes = (ctx, source, name) => {
|
|
10
9
|
if (source instanceof Bytes)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { constructor, fn, methods, prototypeFrom, receiver, requiresNew } from "../interpreter/native.js";
|
|
3
3
|
import { invalidData, IteratorSymbol, typeError } from "../interpreter/model.js";
|
|
4
|
-
import { define, defineAccessor, get, getOwn, hidden,
|
|
5
|
-
import { describeValue,
|
|
4
|
+
import { define, defineAccessor, get, getOwn, hidden, Arr, coerceToString, IteratorObj, MapObj, Obj, PromiseObj, SetObj, } from "../interpreter/objects.js";
|
|
5
|
+
import { describeValue, isOpaque } from "../interpreter/references.js";
|
|
6
6
|
import { applyCollectionCallback, isSupportedCallback, preserveConsumerError, toPrimitiveNumber, toPrimitiveString, } from "../interpreter/callback.js";
|
|
7
7
|
const coerceGroupByPropertyKey = (ctx, value) => {
|
|
8
8
|
if (value instanceof PromiseObj)
|
|
9
|
-
return Effect.succeed(
|
|
10
|
-
if (
|
|
9
|
+
return Effect.succeed(coerceToString(value));
|
|
10
|
+
if (isOpaque(value)) {
|
|
11
11
|
throw invalidData(`Object.groupBy callback must return a data value, received ${describeValue(value)}.`);
|
|
12
12
|
}
|
|
13
13
|
return toPrimitiveString(ctx, value);
|
|
@@ -109,7 +109,6 @@ export const mapGlobal = (ctx) => {
|
|
|
109
109
|
});
|
|
110
110
|
define(map, "groupBy", groupBy(ctx, "Map"), hidden);
|
|
111
111
|
const self = (thisValue, name) => receiver(MapObj, thisValue, `Map.prototype.${name}`);
|
|
112
|
-
const wrap = (items) => new Arr(builtins.Array, items);
|
|
113
112
|
defineAccessor(proto, "size", (thisValue) => receiver(MapObj, thisValue, "Map.prototype.size").map.size);
|
|
114
113
|
methods(builtins, proto, [
|
|
115
114
|
["get", 1, (thisValue, args) => self(thisValue, "get").map.get(args[0])],
|
|
@@ -159,13 +158,7 @@ export const mapGlobal = (ctx) => {
|
|
|
159
158
|
],
|
|
160
159
|
["keys", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "keys").map.keys())],
|
|
161
160
|
["values", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "values").map.values())],
|
|
162
|
-
[
|
|
163
|
-
"entries",
|
|
164
|
-
0,
|
|
165
|
-
(thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "entries")
|
|
166
|
-
.map.entries()
|
|
167
|
-
.map(([key, item]) => wrap([key, item]))),
|
|
168
|
-
],
|
|
161
|
+
["entries", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "entries").iterator(builtins))],
|
|
169
162
|
[
|
|
170
163
|
"forEach",
|
|
171
164
|
1,
|
|
@@ -216,7 +209,7 @@ const loadSetRecord = (ctx, source, name) => {
|
|
|
216
209
|
has: (item) => Effect.map(ctx.call(has, source, [item]), Boolean),
|
|
217
210
|
keys: () => Effect.flatMap(ctx.call(keys, source, []), (result) => {
|
|
218
211
|
if (result instanceof IteratorObj)
|
|
219
|
-
return Effect.succeed(result.
|
|
212
|
+
return Effect.succeed(result.source);
|
|
220
213
|
if (result instanceof Arr)
|
|
221
214
|
return Effect.succeed(result.items);
|
|
222
215
|
throw typeError(`Set.${name} expected 'keys' to return an iterator.`);
|
package/dist/stdlib/console.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Obj } from "../interpreter/objects.js";
|
|
1
|
+
import { Obj, type Value } from "../interpreter/objects.js";
|
|
2
2
|
import type { Interpreter } from "../interpreter/interpreter.js";
|
|
3
3
|
/** Captured console: every method appends one formatted line to `logs`. */
|
|
4
4
|
export declare const consoleGlobal: <R>(ctx: Interpreter<R>) => Obj;
|
|
5
5
|
/** One value as `console.log` shows it. */
|
|
6
|
-
export declare const formatValue: (value:
|
|
6
|
+
export declare const formatValue: (value: Value) => string;
|
package/dist/stdlib/console.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { methods } from "../interpreter/native.js";
|
|
2
|
-
import { entries, get, Arr,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { entries, get, Arr, Obj } from "../interpreter/objects.js";
|
|
3
|
+
import { ToolReference } from "../tool-runtime.js";
|
|
4
|
+
import { containsOpaqueReference } from "../interpreter/references.js";
|
|
5
5
|
const consoleMethods = ["log", "info", "debug", "warn", "error", "dir", "table"];
|
|
6
6
|
/** Captured console: every method appends one formatted line to `logs`. */
|
|
7
7
|
export const consoleGlobal = (ctx) => {
|
|
@@ -39,64 +39,20 @@ const formatConsoleValue = (value, seen, depth) => {
|
|
|
39
39
|
return "null";
|
|
40
40
|
if (typeof value === "string")
|
|
41
41
|
return JSON.stringify(value);
|
|
42
|
-
if (
|
|
43
|
-
return String(value);
|
|
44
|
-
if (typeof value !== "object")
|
|
45
|
-
return String(value);
|
|
46
|
-
if (value instanceof PromiseObj)
|
|
47
|
-
return "[Promise (await it to get its value)]";
|
|
48
|
-
if (value instanceof DateObj)
|
|
49
|
-
return coerceToString(value);
|
|
50
|
-
if (value instanceof RegExpObj)
|
|
51
|
-
return coerceToString(value);
|
|
52
|
-
if (value instanceof URLObj)
|
|
53
|
-
return coerceToString(value);
|
|
54
|
-
if (value instanceof URLSearchParamsObj)
|
|
55
|
-
return coerceToString(value);
|
|
56
|
-
if (value instanceof HeadersObj)
|
|
57
|
-
return `Headers ${JSON.stringify(Object.fromEntries(value.headers))}`;
|
|
58
|
-
if (value instanceof Bytes)
|
|
59
|
-
return `Uint8Array(${value.bytes.length}) [${value.bytes.join(",")}]`;
|
|
42
|
+
if (!(value instanceof Obj))
|
|
43
|
+
return value instanceof ToolReference ? "[opaque reference]" : String(value);
|
|
60
44
|
if (depth > MAX_CONSOLE_DEPTH)
|
|
61
45
|
return "...";
|
|
62
46
|
if (seen.has(value))
|
|
63
47
|
return "[Circular]";
|
|
64
|
-
if (value instanceof MapObj) {
|
|
65
|
-
seen.add(value);
|
|
66
|
-
try {
|
|
67
|
-
const items = Array.from(value.map.entries(), ([key, item]) => `[${formatItems([key, item], seen, depth + 1)}]`);
|
|
68
|
-
return `Map(${value.map.size}) [${items.join(",")}]`;
|
|
69
|
-
}
|
|
70
|
-
finally {
|
|
71
|
-
seen.delete(value);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (value instanceof SetObj) {
|
|
75
|
-
seen.add(value);
|
|
76
|
-
try {
|
|
77
|
-
return `Set(${value.set.size}) [${formatItems([...value.set.values()], seen, depth + 1)}]`;
|
|
78
|
-
}
|
|
79
|
-
finally {
|
|
80
|
-
seen.delete(value);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (isRuntimeReference(value))
|
|
84
|
-
return "[opaque reference]";
|
|
85
48
|
seen.add(value);
|
|
86
49
|
try {
|
|
87
|
-
|
|
88
|
-
return `[${formatItems(value.items, seen, depth + 1)}]`;
|
|
89
|
-
if (!(value instanceof Obj))
|
|
90
|
-
return "[object Object]";
|
|
91
|
-
return `{${entries(value)
|
|
92
|
-
.map(([key, item]) => `${JSON.stringify(key)}:${formatConsoleValue(item, seen, depth + 1)}`)
|
|
93
|
-
.join(",")}}`;
|
|
50
|
+
return value.inspect((item) => formatConsoleValue(item, seen, depth + 1));
|
|
94
51
|
}
|
|
95
52
|
finally {
|
|
96
53
|
seen.delete(value);
|
|
97
54
|
}
|
|
98
55
|
};
|
|
99
|
-
const formatItems = (items, seen, depth) => items.map((item) => formatConsoleValue(item, seen, depth)).join(",");
|
|
100
56
|
const formatConsoleTable = (value, columnsArgument) => {
|
|
101
57
|
if (value === undefined)
|
|
102
58
|
return "undefined";
|
package/dist/stdlib/date.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { constructor, methods, prototypeFrom, receiver } from "../interpreter/native.js";
|
|
3
3
|
import { rangeError } from "../interpreter/model.js";
|
|
4
|
-
import { DateObj, Obj } from "../interpreter/objects.js";
|
|
4
|
+
import { DateObj, Obj, coerceToNumber, coerceToString } from "../interpreter/objects.js";
|
|
5
5
|
import { toPrimitive, toPrimitiveNumber } from "../interpreter/callback.js";
|
|
6
|
-
import { coerceToNumber, coerceToString } from "./value.js";
|
|
7
6
|
const constructDate = (ctx, args, proto) => {
|
|
8
7
|
if (args.length === 0)
|
|
9
8
|
return Effect.succeed(new DateObj(proto, Date.now()));
|
package/dist/stdlib/headers.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { constructor, methods, prototypeFrom, receiver, requiresNew } from "../interpreter/native.js";
|
|
3
3
|
import { IteratorSymbol, typeError } from "../interpreter/model.js";
|
|
4
|
-
import { define, entries, get, hidden, Arr, HeadersObj, IteratorObj, Obj } from "../interpreter/objects.js";
|
|
4
|
+
import { define, entries, get, hidden, Arr, HeadersObj, IteratorObj, Obj, coerceToString, isRuntimeReference, } from "../interpreter/objects.js";
|
|
5
5
|
import { applyCollectionCallback } from "../interpreter/callback.js";
|
|
6
|
-
import { isRuntimeReference } from "../interpreter/references.js";
|
|
7
|
-
import { coerceToString } from "./value.js";
|
|
8
6
|
import { readPairs } from "./url.js";
|
|
9
7
|
// The host validates header names and values and throws its own TypeError; the program gets one of its own.
|
|
10
8
|
const attempt = (run) => {
|
|
@@ -51,7 +49,8 @@ export const headersGlobal = (ctx) => {
|
|
|
51
49
|
(thisValue, args) => {
|
|
52
50
|
requireArgs("append", args, 2);
|
|
53
51
|
const target = self(thisValue, "append").headers;
|
|
54
|
-
|
|
52
|
+
attempt(() => target.append(arg(args, 0), arg(args, 1)));
|
|
53
|
+
return undefined;
|
|
55
54
|
},
|
|
56
55
|
],
|
|
57
56
|
[
|
|
@@ -60,7 +59,8 @@ export const headersGlobal = (ctx) => {
|
|
|
60
59
|
(thisValue, args) => {
|
|
61
60
|
requireArgs("delete", args, 1);
|
|
62
61
|
const target = self(thisValue, "delete").headers;
|
|
63
|
-
|
|
62
|
+
attempt(() => target.delete(arg(args, 0)));
|
|
63
|
+
return undefined;
|
|
64
64
|
},
|
|
65
65
|
],
|
|
66
66
|
[
|
|
@@ -88,7 +88,8 @@ export const headersGlobal = (ctx) => {
|
|
|
88
88
|
(thisValue, args) => {
|
|
89
89
|
requireArgs("set", args, 2);
|
|
90
90
|
const target = self(thisValue, "set").headers;
|
|
91
|
-
|
|
91
|
+
attempt(() => target.set(arg(args, 0), arg(args, 1)));
|
|
92
|
+
return undefined;
|
|
92
93
|
},
|
|
93
94
|
],
|
|
94
95
|
// Iterator.from because Bun's Headers typings predate iterator helpers; the runtime iterators already have them.
|
|
@@ -102,11 +103,7 @@ export const headersGlobal = (ctx) => {
|
|
|
102
103
|
0,
|
|
103
104
|
(thisValue) => new IteratorObj(builtins.Iterator, Iterator.from(self(thisValue, "values").headers.values())),
|
|
104
105
|
],
|
|
105
|
-
[
|
|
106
|
-
"entries",
|
|
107
|
-
0,
|
|
108
|
-
(thisValue) => new IteratorObj(builtins.Iterator, Iterator.from(self(thisValue, "entries").headers.entries()).map(([key, value]) => wrap([key, value]))),
|
|
109
|
-
],
|
|
106
|
+
["entries", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "entries").iterator(builtins))],
|
|
110
107
|
[
|
|
111
108
|
"forEach",
|
|
112
109
|
1,
|
package/dist/stdlib/iterator.js
CHANGED
|
@@ -9,7 +9,7 @@ export const iteratorGlobals = (ctx) => {
|
|
|
9
9
|
"next",
|
|
10
10
|
0,
|
|
11
11
|
(thisValue) => {
|
|
12
|
-
const step = receiver(IteratorObj, thisValue, "Iterator.prototype.next").
|
|
12
|
+
const step = receiver(IteratorObj, thisValue, "Iterator.prototype.next").source.next();
|
|
13
13
|
return record(builtins.Object, { value: step.value, done: Boolean(step.done) });
|
|
14
14
|
},
|
|
15
15
|
],
|
package/dist/stdlib/number.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { constructor, constants, methods } from "../interpreter/native.js";
|
|
2
|
+
import { coerceToString } from "../interpreter/objects.js";
|
|
2
3
|
import { rangeError, typeError } from "../interpreter/model.js";
|
|
3
|
-
import { coercion
|
|
4
|
+
import { coercion } from "./value.js";
|
|
4
5
|
export const numberGlobal = (ctx) => {
|
|
5
6
|
const builtins = ctx.builtins;
|
|
6
7
|
const number = constructor(builtins, builtins.Number, {
|
package/dist/stdlib/object.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type AstNode } from "../interpreter/model.js";
|
|
2
|
-
import { Obj } from "../interpreter/objects.js";
|
|
2
|
+
import { Obj, type Value } from "../interpreter/objects.js";
|
|
3
3
|
import type { Interpreter } from "../interpreter/interpreter.js";
|
|
4
|
-
export declare const enumerableSource: <R>(ctx: Interpreter<R>, label: string, value:
|
|
5
|
-
export declare const objectAssign: <R>(ctx: Interpreter<R>, args: Array<
|
|
6
|
-
export declare const classTag: (value: unknown) => string;
|
|
4
|
+
export declare const enumerableSource: <R>(ctx: Interpreter<R>, label: string, value: Value, node?: AstNode) => Obj;
|
|
5
|
+
export declare const objectAssign: <R>(ctx: Interpreter<R>, args: Array<Value>) => Value;
|
|
7
6
|
export declare const objectGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;
|
package/dist/stdlib/object.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { constructor, methods, receiver } from "../interpreter/native.js";
|
|
3
3
|
import { AsyncIteratorSymbol, invalidData, IteratorSymbol, rangeError, typeError, } from "../interpreter/model.js";
|
|
4
|
-
import {
|
|
4
|
+
import { define, entries, enumerableKeys, getOwn, hasOwn, hasPrototype, hidden, keys, own, Arr, Obj, PromiseObj, set, coerceToString, } from "../interpreter/objects.js";
|
|
5
5
|
import { containsOpaqueReference, describeValue, rejectCircularInsertion } from "../interpreter/references.js";
|
|
6
6
|
import { invoke, preserveConsumerError } from "../interpreter/callback.js";
|
|
7
7
|
import { ToolReference } from "../tool-runtime.js";
|
|
8
8
|
import { groupBy } from "./collections.js";
|
|
9
|
-
import { coerceToString } from "./value.js";
|
|
10
9
|
// ToObject for enumeration.
|
|
11
10
|
export const enumerableSource = (ctx, label, value, node) => {
|
|
12
11
|
if (value === null || value === undefined) {
|
|
@@ -66,23 +65,13 @@ const objectFromEntries = (ctx, source) => {
|
|
|
66
65
|
}
|
|
67
66
|
});
|
|
68
67
|
};
|
|
69
|
-
|
|
68
|
+
const classTag = (value) => {
|
|
70
69
|
if (value === null)
|
|
71
70
|
return "Null";
|
|
72
71
|
if (value === undefined)
|
|
73
72
|
return "Undefined";
|
|
74
|
-
if (value instanceof
|
|
75
|
-
return
|
|
76
|
-
if (value instanceof Callable)
|
|
77
|
-
return "Function";
|
|
78
|
-
if (value instanceof ErrorObj)
|
|
79
|
-
return "Error";
|
|
80
|
-
if (value instanceof DateObj)
|
|
81
|
-
return "Date";
|
|
82
|
-
if (value instanceof RegExpObj)
|
|
83
|
-
return "RegExp";
|
|
84
|
-
if (value instanceof Bytes)
|
|
85
|
-
return "Uint8Array";
|
|
73
|
+
if (value instanceof Obj)
|
|
74
|
+
return value.tag;
|
|
86
75
|
if (typeof value === "string")
|
|
87
76
|
return "String";
|
|
88
77
|
if (typeof value === "number")
|
package/dist/stdlib/regexp.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Builtins } from "../interpreter/intrinsics.js";
|
|
2
|
-
import { Arr, Obj, RegExpObj } from "../interpreter/objects.js";
|
|
2
|
+
import { Arr, Obj, RegExpObj, type Value } from "../interpreter/objects.js";
|
|
3
3
|
import type { Interpreter } from "../interpreter/interpreter.js";
|
|
4
|
-
export declare const toHostRegex: (arg:
|
|
4
|
+
export declare const toHostRegex: (arg: Value, method: string, extraFlags?: string) => RegExp;
|
|
5
5
|
export declare const matchToValue: (builtins: Builtins, match: RegExpMatchArray) => Arr;
|
|
6
|
-
export declare const constructRegExp: (builtins: Builtins, args: Array<
|
|
6
|
+
export declare const constructRegExp: (builtins: Builtins, args: Array<Value>, proto?: Obj) => RegExpObj;
|
|
7
7
|
export declare const regexpGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;
|
package/dist/stdlib/regexp.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { constructor, methods, prototypeFrom, receiver } from "../interpreter/native.js";
|
|
3
3
|
import { syntaxError, typeError } from "../interpreter/model.js";
|
|
4
|
-
import { define, defineAccessor, Arr, Obj, RegExpObj, record } from "../interpreter/objects.js";
|
|
5
|
-
import { coerceToNumber, coerceToString } from "./value.js";
|
|
4
|
+
import { define, defineAccessor, Arr, Obj, RegExpObj, record, coerceToNumber, coerceToString, } from "../interpreter/objects.js";
|
|
6
5
|
const flagProperties = [
|
|
7
6
|
"hasIndices",
|
|
8
7
|
"global",
|
package/dist/stdlib/string.js
CHANGED
|
@@ -2,11 +2,11 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { constructor, fn, methods } from "../interpreter/native.js";
|
|
3
3
|
import { checkArrayLength, checkStringLength } from "../interpreter/limits.js";
|
|
4
4
|
import { invalidData, IteratorSymbol, rangeError, typeError } from "../interpreter/model.js";
|
|
5
|
-
import { define, hidden, Arr, IteratorObj,
|
|
5
|
+
import { define, hidden, Arr, IteratorObj, RegExpObj, record, coerceToNumber, coerceToString, } from "../interpreter/objects.js";
|
|
6
6
|
import { containsOpaqueReference, typeofValue } from "../interpreter/references.js";
|
|
7
7
|
import { applyCollectionCallback, isSupportedCallback } from "../interpreter/callback.js";
|
|
8
8
|
import { matchToValue, toHostRegex } from "./regexp.js";
|
|
9
|
-
import {
|
|
9
|
+
import { coercion } from "./value.js";
|
|
10
10
|
// console is intercepted by the interpreter before reaching here.
|
|
11
11
|
const requireDataArgument = (name, index, arg) => {
|
|
12
12
|
if (containsOpaqueReference(arg)) {
|
|
@@ -23,17 +23,16 @@ const replaceWithCallback = (ctx, value, name, args) => {
|
|
|
23
23
|
const builtins = ctx.builtins;
|
|
24
24
|
const apply = applyCollectionCallback(ctx, args[1], `String.${name}`);
|
|
25
25
|
const matches = [];
|
|
26
|
+
// The host calls back with (match, ...captures, offset, string, groups?); only groups is not already a Value.
|
|
26
27
|
const collect = (...callbackArgs) => {
|
|
27
28
|
const match = callbackArgs[0];
|
|
28
|
-
const
|
|
29
|
-
const hasGroups = groups !== null && typeof groups === "object";
|
|
29
|
+
const hasGroups = typeof callbackArgs.at(-1) === "object";
|
|
30
30
|
const offset = callbackArgs[callbackArgs.length - (hasGroups ? 3 : 2)];
|
|
31
31
|
if (typeof match !== "string" || typeof offset !== "number") {
|
|
32
32
|
throw typeError(`String.${name} produced an invalid replacement match.`);
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
matches.push({ match, offset, args: callbackArgs });
|
|
34
|
+
const args = callbackArgs.map((arg) => (typeof arg === "object" ? record(builtins.Object, arg) : arg));
|
|
35
|
+
matches.push({ match, offset, args });
|
|
37
36
|
return match;
|
|
38
37
|
};
|
|
39
38
|
const pattern = args[0];
|
|
@@ -57,7 +56,7 @@ const replaceWithCallback = (ctx, value, name, args) => {
|
|
|
57
56
|
let end = 0;
|
|
58
57
|
for (const match of matches) {
|
|
59
58
|
const replacement = yield* apply(match.args);
|
|
60
|
-
output.push(value.slice(end, match.offset),
|
|
59
|
+
output.push(value.slice(end, match.offset), coerceToString(replacement));
|
|
61
60
|
end = match.offset + match.match.length;
|
|
62
61
|
}
|
|
63
62
|
output.push(value.slice(end));
|
|
@@ -103,11 +102,7 @@ export const stringGlobal = (ctx) => {
|
|
|
103
102
|
throw typeError(`String.${name} cannot take a regular expression; use regex.test(string) or String.search instead.`);
|
|
104
103
|
}
|
|
105
104
|
};
|
|
106
|
-
const simple = (name, length, op) => [
|
|
107
|
-
name,
|
|
108
|
-
length,
|
|
109
|
-
(thisValue, args) => op(self(thisValue, name), args),
|
|
110
|
-
];
|
|
105
|
+
const simple = (name, length, op) => [name, length, (thisValue, args) => op(self(thisValue, name), args)];
|
|
111
106
|
const replace = (name) => simple(name, 2, (value, args) => {
|
|
112
107
|
if (isSupportedCallback(args[1]))
|
|
113
108
|
return replaceWithCallback(ctx, value, name, args);
|
package/dist/stdlib/url.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
+
import { type Value } from "../interpreter/objects.js";
|
|
2
3
|
import type { Interpreter } from "../interpreter/interpreter.js";
|
|
3
4
|
type UriFunction = "encodeURI" | "encodeURIComponent" | "decodeURI" | "decodeURIComponent";
|
|
4
5
|
export declare const uriGlobal: <R>(ctx: Interpreter<R>, name: UriFunction) => import("../interpreter/objects.js").Native<R>;
|
|
@@ -7,6 +8,6 @@ export declare const urlGlobal: <R>(ctx: Interpreter<R>) => import("../interpret
|
|
|
7
8
|
* Reads a synchronous iterable of `[name, value]` pairs as strings; `undefined` when `init` is not iterable. As in
|
|
8
9
|
* WebIDL, the whole sequence is converted before any pair's length is checked.
|
|
9
10
|
*/
|
|
10
|
-
export declare const readPairs: <R>(ctx: Interpreter<R>, init:
|
|
11
|
+
export declare const readPairs: <R>(ctx: Interpreter<R>, init: Value, label: string) => Effect.Effect<Array<[string, string]> | undefined, unknown, R>;
|
|
11
12
|
export declare const urlSearchParamsGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native<R>;
|
|
12
13
|
export {};
|
package/dist/stdlib/url.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { constructor, fn, methods, prototypeFrom, receiver, requiresNew } from "../interpreter/native.js";
|
|
3
3
|
import { IteratorSymbol, PendingThrow, typeError, uriError } from "../interpreter/model.js";
|
|
4
|
-
import { define, defineAccessor, entries, get, hidden,
|
|
5
|
-
import { isRuntimeReference } from "../interpreter/references.js";
|
|
4
|
+
import { define, defineAccessor, entries, get, hidden, Arr, IteratorObj, Obj, URLObj, URLSearchParamsObj, coerceToString, isRuntimeReference, } from "../interpreter/objects.js";
|
|
6
5
|
import { applyCollectionCallback, preserveConsumerError } from "../interpreter/callback.js";
|
|
7
|
-
import { coerceToString } from "./value.js";
|
|
8
6
|
const urlProperties = [
|
|
9
7
|
"href",
|
|
10
8
|
"origin",
|
|
@@ -147,8 +145,6 @@ const constructURLSearchParams = (ctx, init, proto) => {
|
|
|
147
145
|
if (isRuntimeReference(init)) {
|
|
148
146
|
throw typeError("new URLSearchParams(...) expects a query string, data object, or synchronous iterable pairs.");
|
|
149
147
|
}
|
|
150
|
-
if (isWrapper(init))
|
|
151
|
-
return wrap(new URLSearchParams());
|
|
152
148
|
if (!(init instanceof Obj)) {
|
|
153
149
|
throw typeError("new URLSearchParams(...) expects a query string, data object, iterable pairs, or URLSearchParams.");
|
|
154
150
|
}
|
|
@@ -239,13 +235,7 @@ export const urlSearchParamsGlobal = (ctx) => {
|
|
|
239
235
|
],
|
|
240
236
|
["keys", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "keys").params.keys())],
|
|
241
237
|
["values", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "values").params.values())],
|
|
242
|
-
[
|
|
243
|
-
"entries",
|
|
244
|
-
0,
|
|
245
|
-
(thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "entries")
|
|
246
|
-
.params.entries()
|
|
247
|
-
.map(([key, value]) => wrap([key, value]))),
|
|
248
|
-
],
|
|
238
|
+
["entries", 0, (thisValue) => new IteratorObj(builtins.Iterator, self(thisValue, "entries").iterator(builtins))],
|
|
249
239
|
["toString", 0, (thisValue) => self(thisValue, "toString").params.toString()],
|
|
250
240
|
[
|
|
251
241
|
"forEach",
|
package/dist/stdlib/value.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { type Native } from "../interpreter/objects.js";
|
|
2
2
|
import type { Interpreter } from "../interpreter/interpreter.js";
|
|
3
3
|
export declare const compoundOperators: Set<string>;
|
|
4
|
-
/** The built-in string form of a value, without consulting program-defined `toString` methods. */
|
|
5
|
-
export declare const coerceToString: (value: unknown) => string;
|
|
6
|
-
export declare const coerceToNumber: (value: unknown) => number;
|
|
7
4
|
export type Coercion = "Number" | "String" | "Boolean" | "parseInt" | "parseFloat" | "isFinite" | "isNaN";
|
|
8
5
|
/** A global coercion function such as `Number` or `parseInt`. */
|
|
9
6
|
export declare const coercion: <R>(ctx: Interpreter<R>, name: Coercion, length?: number) => Native<R>;
|