@opencode/codemode 0.0.0-beta-19507 → 0.0.0-dev-19276
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/README.md +0 -6
- package/dist/codemode.d.ts +12 -9
- package/dist/codemode.js +9 -5
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/interpreter/errors.d.ts +6 -4
- package/dist/interpreter/errors.js +10 -25
- package/dist/interpreter/execute.d.ts +3 -4
- package/dist/interpreter/execute.js +18 -11
- package/dist/interpreter/iterator.d.ts +13 -0
- package/dist/interpreter/iterator.js +4 -0
- package/dist/interpreter/methods.d.ts +16 -3
- package/dist/interpreter/methods.js +290 -101
- package/dist/interpreter/model.d.ts +79 -10
- package/dist/interpreter/model.js +102 -2
- package/dist/interpreter/promises.d.ts +13 -15
- package/dist/interpreter/promises.js +52 -70
- package/dist/interpreter/references.d.ts +0 -1
- package/dist/interpreter/references.js +77 -57
- package/dist/interpreter/runtime.d.ts +95 -16
- package/dist/interpreter/runtime.js +960 -549
- package/dist/openapi/spec.js +6 -3
- package/dist/stdlib/collections.d.ts +1 -6
- package/dist/stdlib/collections.js +1 -117
- package/dist/stdlib/console.d.ts +2 -3
- package/dist/stdlib/console.js +28 -39
- package/dist/stdlib/date.d.ts +4 -5
- package/dist/stdlib/date.js +12 -34
- package/dist/stdlib/json.d.ts +6 -3
- package/dist/stdlib/json.js +63 -40
- package/dist/stdlib/math.d.ts +7 -3
- package/dist/stdlib/math.js +153 -85
- package/dist/stdlib/number.d.ts +4 -2
- package/dist/stdlib/number.js +37 -30
- package/dist/stdlib/object.d.ts +6 -6
- package/dist/stdlib/object.js +87 -84
- package/dist/stdlib/promise.d.ts +2 -0
- package/dist/stdlib/promise.js +1 -0
- package/dist/stdlib/regexp.d.ts +7 -6
- package/dist/stdlib/regexp.js +34 -48
- package/dist/stdlib/string.d.ts +3 -1
- package/dist/stdlib/string.js +17 -20
- package/dist/stdlib/url.d.ts +6 -10
- package/dist/stdlib/url.js +25 -102
- package/dist/stdlib/value.d.ts +7 -8
- package/dist/stdlib/value.js +56 -56
- package/dist/tool-runtime.d.ts +15 -16
- package/dist/tool-runtime.js +150 -13
- package/dist/values.d.ts +16 -22
- package/dist/values.js +17 -23
- package/package.json +1 -1
- package/dist/data.d.ts +0 -25
- package/dist/data.js +0 -153
- package/dist/interpreter/globals.d.ts +0 -13
- package/dist/interpreter/globals.js +0 -63
- package/dist/interpreter/host.d.ts +0 -41
- package/dist/interpreter/host.js +0 -44
- package/dist/interpreter/objects.d.ts +0 -37
- package/dist/interpreter/objects.js +0 -151
- package/dist/interpreter/runner.d.ts +0 -24
- package/dist/interpreter/runner.js +0 -45
- package/dist/stdlib/array.d.ts +0 -3
- package/dist/stdlib/array.js +0 -68
- package/dist/stdlib/web.d.ts +0 -4
- package/dist/stdlib/web.js +0 -20
package/dist/stdlib/math.js
CHANGED
|
@@ -1,89 +1,157 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import {
|
|
3
|
-
import { preserveConsumerError } from "../interpreter/runner.js";
|
|
2
|
+
import { preserveConsumerError } from "../interpreter/iterator.js";
|
|
4
3
|
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
export const mathConstants = new Set(["PI", "E", "LN2", "LN10", "LOG2E", "LOG10E", "SQRT2", "SQRT1_2"]);
|
|
5
|
+
export const mathMethods = new Set([
|
|
6
|
+
"random",
|
|
7
|
+
"max",
|
|
8
|
+
"min",
|
|
9
|
+
"abs",
|
|
10
|
+
"acos",
|
|
11
|
+
"acosh",
|
|
12
|
+
"asin",
|
|
13
|
+
"asinh",
|
|
14
|
+
"atan",
|
|
15
|
+
"atan2",
|
|
16
|
+
"atanh",
|
|
17
|
+
"floor",
|
|
18
|
+
"ceil",
|
|
19
|
+
"round",
|
|
20
|
+
"trunc",
|
|
21
|
+
"sign",
|
|
22
|
+
"sqrt",
|
|
23
|
+
"cbrt",
|
|
24
|
+
"pow",
|
|
25
|
+
"hypot",
|
|
26
|
+
"cos",
|
|
27
|
+
"cosh",
|
|
28
|
+
"sin",
|
|
29
|
+
"sinh",
|
|
30
|
+
"tan",
|
|
31
|
+
"tanh",
|
|
32
|
+
"log",
|
|
33
|
+
"log2",
|
|
34
|
+
"log10",
|
|
35
|
+
"log1p",
|
|
36
|
+
"exp",
|
|
37
|
+
"expm1",
|
|
38
|
+
"f16round",
|
|
39
|
+
"fround",
|
|
40
|
+
"clz32",
|
|
41
|
+
"imul",
|
|
42
|
+
"sumPrecise",
|
|
43
|
+
]);
|
|
44
|
+
export const invokeMathMethod = (name, args, node) => {
|
|
45
|
+
if (!mathMethods.has(name))
|
|
46
|
+
throw new InterpreterRuntimeError(`Math.${name} is not available.`, node);
|
|
47
|
+
if (name === "random")
|
|
48
|
+
return Math.random();
|
|
49
|
+
// Validate only the arguments the method consumes; like JS, extras are ignored
|
|
50
|
+
// (so built-ins work as callbacks receiving (element, index, array)).
|
|
51
|
+
const num = (index) => {
|
|
52
|
+
if (index >= args.length)
|
|
53
|
+
return Number.NaN;
|
|
54
|
+
const arg = args[index];
|
|
55
|
+
if (typeof arg !== "number")
|
|
56
|
+
throw new InterpreterRuntimeError(`Math.${name} expects number arguments.`, node);
|
|
57
|
+
return arg;
|
|
58
|
+
};
|
|
59
|
+
const nums = () => args.map((arg) => {
|
|
60
|
+
if (typeof arg !== "number")
|
|
61
|
+
throw new InterpreterRuntimeError(`Math.${name} expects number arguments.`, node);
|
|
62
|
+
return arg;
|
|
63
|
+
});
|
|
64
|
+
const a = num(0);
|
|
65
|
+
const b = () => num(1);
|
|
66
|
+
switch (name) {
|
|
67
|
+
case "max":
|
|
68
|
+
return Math.max(...nums());
|
|
69
|
+
case "min":
|
|
70
|
+
return Math.min(...nums());
|
|
71
|
+
case "abs":
|
|
72
|
+
return Math.abs(a);
|
|
73
|
+
case "acos":
|
|
74
|
+
return Math.acos(a);
|
|
75
|
+
case "acosh":
|
|
76
|
+
return Math.acosh(a);
|
|
77
|
+
case "asin":
|
|
78
|
+
return Math.asin(a);
|
|
79
|
+
case "asinh":
|
|
80
|
+
return Math.asinh(a);
|
|
81
|
+
case "atan":
|
|
82
|
+
return Math.atan(a);
|
|
83
|
+
case "atan2":
|
|
84
|
+
return Math.atan2(a, b());
|
|
85
|
+
case "atanh":
|
|
86
|
+
return Math.atanh(a);
|
|
87
|
+
case "floor":
|
|
88
|
+
return Math.floor(a);
|
|
89
|
+
case "ceil":
|
|
90
|
+
return Math.ceil(a);
|
|
91
|
+
case "round":
|
|
92
|
+
return Math.round(a);
|
|
93
|
+
case "trunc":
|
|
94
|
+
return Math.trunc(a);
|
|
95
|
+
case "sign":
|
|
96
|
+
return Math.sign(a);
|
|
97
|
+
case "sqrt":
|
|
98
|
+
return Math.sqrt(a);
|
|
99
|
+
case "cbrt":
|
|
100
|
+
return Math.cbrt(a);
|
|
101
|
+
case "pow":
|
|
102
|
+
return Math.pow(a, b());
|
|
103
|
+
case "hypot":
|
|
104
|
+
return Math.hypot(...nums());
|
|
105
|
+
case "cos":
|
|
106
|
+
return Math.cos(a);
|
|
107
|
+
case "cosh":
|
|
108
|
+
return Math.cosh(a);
|
|
109
|
+
case "sin":
|
|
110
|
+
return Math.sin(a);
|
|
111
|
+
case "sinh":
|
|
112
|
+
return Math.sinh(a);
|
|
113
|
+
case "tan":
|
|
114
|
+
return Math.tan(a);
|
|
115
|
+
case "tanh":
|
|
116
|
+
return Math.tanh(a);
|
|
117
|
+
case "log":
|
|
118
|
+
return Math.log(a);
|
|
119
|
+
case "log2":
|
|
120
|
+
return Math.log2(a);
|
|
121
|
+
case "log10":
|
|
122
|
+
return Math.log10(a);
|
|
123
|
+
case "log1p":
|
|
124
|
+
return Math.log1p(a);
|
|
125
|
+
case "exp":
|
|
126
|
+
return Math.exp(a);
|
|
127
|
+
case "expm1":
|
|
128
|
+
return Math.expm1(a);
|
|
129
|
+
case "f16round":
|
|
130
|
+
return Math.f16round(a);
|
|
131
|
+
case "fround":
|
|
132
|
+
return Math.fround(a);
|
|
133
|
+
case "clz32":
|
|
134
|
+
return Math.clz32(a);
|
|
135
|
+
case "imul":
|
|
136
|
+
return Math.imul(a, b());
|
|
137
|
+
}
|
|
138
|
+
throw new InterpreterRuntimeError(`Math.${name} is not available.`, node);
|
|
14
139
|
};
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (step.done)
|
|
33
|
-
return Math.sumPrecise(numbers);
|
|
34
|
-
yield* preserveConsumerError(cursor, Effect.sync(() => {
|
|
35
|
-
if (typeof step.value !== "number") {
|
|
36
|
-
throw new InterpreterRuntimeError("Math.sumPrecise expects an iterable of numbers.", node).as("TypeError");
|
|
37
|
-
}
|
|
38
|
-
numbers.push(step.value);
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
41
|
-
}),
|
|
42
|
-
});
|
|
43
|
-
export const mathGlobal = (runner) => new HostNamespace("Math", {
|
|
44
|
-
PI: Math.PI,
|
|
45
|
-
E: Math.E,
|
|
46
|
-
LN2: Math.LN2,
|
|
47
|
-
LN10: Math.LN10,
|
|
48
|
-
LOG2E: Math.LOG2E,
|
|
49
|
-
LOG10E: Math.LOG10E,
|
|
50
|
-
SQRT2: Math.SQRT2,
|
|
51
|
-
SQRT1_2: Math.SQRT1_2,
|
|
52
|
-
random: sync("Math.random", () => Math.random()),
|
|
53
|
-
max: variadic("max", Math.max),
|
|
54
|
-
min: variadic("min", Math.min),
|
|
55
|
-
hypot: variadic("hypot", Math.hypot),
|
|
56
|
-
abs: unary("abs", Math.abs),
|
|
57
|
-
acos: unary("acos", Math.acos),
|
|
58
|
-
acosh: unary("acosh", Math.acosh),
|
|
59
|
-
asin: unary("asin", Math.asin),
|
|
60
|
-
asinh: unary("asinh", Math.asinh),
|
|
61
|
-
atan: unary("atan", Math.atan),
|
|
62
|
-
atan2: binary("atan2", Math.atan2),
|
|
63
|
-
atanh: unary("atanh", Math.atanh),
|
|
64
|
-
floor: unary("floor", Math.floor),
|
|
65
|
-
ceil: unary("ceil", Math.ceil),
|
|
66
|
-
round: unary("round", Math.round),
|
|
67
|
-
trunc: unary("trunc", Math.trunc),
|
|
68
|
-
sign: unary("sign", Math.sign),
|
|
69
|
-
sqrt: unary("sqrt", Math.sqrt),
|
|
70
|
-
cbrt: unary("cbrt", Math.cbrt),
|
|
71
|
-
pow: binary("pow", Math.pow),
|
|
72
|
-
cos: unary("cos", Math.cos),
|
|
73
|
-
cosh: unary("cosh", Math.cosh),
|
|
74
|
-
sin: unary("sin", Math.sin),
|
|
75
|
-
sinh: unary("sinh", Math.sinh),
|
|
76
|
-
tan: unary("tan", Math.tan),
|
|
77
|
-
tanh: unary("tanh", Math.tanh),
|
|
78
|
-
log: unary("log", Math.log),
|
|
79
|
-
log2: unary("log2", Math.log2),
|
|
80
|
-
log10: unary("log10", Math.log10),
|
|
81
|
-
log1p: unary("log1p", Math.log1p),
|
|
82
|
-
exp: unary("exp", Math.exp),
|
|
83
|
-
expm1: unary("expm1", Math.expm1),
|
|
84
|
-
f16round: unary("f16round", Math.f16round),
|
|
85
|
-
fround: unary("fround", Math.fround),
|
|
86
|
-
clz32: unary("clz32", Math.clz32),
|
|
87
|
-
imul: binary("imul", Math.imul),
|
|
88
|
-
sumPrecise: sumPrecise(runner),
|
|
140
|
+
export const invokeMathSumPrecise = (runner, source, node) => Effect.gen(function* () {
|
|
141
|
+
const cursor = yield* runner.syncIterator(source, node);
|
|
142
|
+
if (cursor === undefined) {
|
|
143
|
+
throw new InterpreterRuntimeError("Math.sumPrecise expects a synchronous iterable.", node).as("TypeError");
|
|
144
|
+
}
|
|
145
|
+
const numbers = [];
|
|
146
|
+
while (true) {
|
|
147
|
+
const step = yield* cursor.next;
|
|
148
|
+
if (step.done)
|
|
149
|
+
return Math.sumPrecise(numbers);
|
|
150
|
+
yield* preserveConsumerError(cursor, Effect.sync(() => {
|
|
151
|
+
if (typeof step.value !== "number") {
|
|
152
|
+
throw new InterpreterRuntimeError("Math.sumPrecise expects an iterable of numbers.", node).as("TypeError");
|
|
153
|
+
}
|
|
154
|
+
numbers.push(step.value);
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
89
157
|
});
|
package/dist/stdlib/number.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { type AstNode } from "../interpreter/model.js";
|
|
2
1
|
export declare const numberMethods: Set<string>;
|
|
2
|
+
export declare const numberConstants: Set<string>;
|
|
3
|
+
export declare const numberStatics: Set<string>;
|
|
3
4
|
export declare const invokeNumberMethod: (value: number, name: string, args: Array<unknown>, node: AstNode) => unknown;
|
|
4
|
-
export declare const
|
|
5
|
+
export declare const invokeNumberStatic: (name: string, args: Array<unknown>, node: AstNode) => unknown;
|
|
6
|
+
import { type AstNode } from "../interpreter/model.js";
|
package/dist/stdlib/number.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { toProgram } from "../data.js";
|
|
2
|
-
import { sync } from "../interpreter/host.js";
|
|
3
|
-
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
4
|
-
import { coercion, coerceToString } from "./value.js";
|
|
5
1
|
export const numberMethods = new Set(["toFixed", "toPrecision", "toExponential", "toString", "valueOf"]);
|
|
2
|
+
export const numberConstants = new Set([
|
|
3
|
+
"MAX_SAFE_INTEGER",
|
|
4
|
+
"MIN_SAFE_INTEGER",
|
|
5
|
+
"MAX_VALUE",
|
|
6
|
+
"MIN_VALUE",
|
|
7
|
+
"EPSILON",
|
|
8
|
+
"NaN",
|
|
9
|
+
"POSITIVE_INFINITY",
|
|
10
|
+
"NEGATIVE_INFINITY",
|
|
11
|
+
]);
|
|
12
|
+
export const numberStatics = new Set(["isInteger", "isFinite", "isNaN", "isSafeInteger", "parseInt", "parseFloat"]);
|
|
6
13
|
export const invokeNumberMethod = (value, name, args, node) => {
|
|
7
14
|
const optNum = (index) => {
|
|
8
15
|
const arg = args[index];
|
|
@@ -39,31 +46,31 @@ export const invokeNumberMethod = (value, name, args, node) => {
|
|
|
39
46
|
default:
|
|
40
47
|
throw new InterpreterRuntimeError(`Number method '${name}' is not available.`, node);
|
|
41
48
|
}
|
|
42
|
-
return
|
|
49
|
+
return boundedData(result, `Number.${name} result`);
|
|
43
50
|
};
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
export const invokeNumberStatic = (name, args, node) => {
|
|
52
|
+
const value = args[0];
|
|
53
|
+
switch (name) {
|
|
54
|
+
case "isInteger":
|
|
55
|
+
return Number.isInteger(value);
|
|
56
|
+
case "isFinite":
|
|
57
|
+
return Number.isFinite(value);
|
|
58
|
+
case "isNaN":
|
|
59
|
+
return Number.isNaN(value);
|
|
60
|
+
case "isSafeInteger":
|
|
61
|
+
return Number.isSafeInteger(value);
|
|
62
|
+
case "parseInt": {
|
|
63
|
+
const radix = args[1];
|
|
64
|
+
if (radix !== undefined && typeof radix !== "number") {
|
|
65
|
+
throw new InterpreterRuntimeError("Number.parseInt expects a numeric radix.", node);
|
|
66
|
+
}
|
|
67
|
+
return parseInt(coerceToString(value), radix);
|
|
68
|
+
}
|
|
69
|
+
case "parseFloat":
|
|
70
|
+
return parseFloat(coerceToString(value));
|
|
71
|
+
default:
|
|
72
|
+
throw new InterpreterRuntimeError(`Number.${name} is not available.`, node);
|
|
48
73
|
}
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
instanceOf: () => false,
|
|
53
|
-
members: {
|
|
54
|
-
MAX_SAFE_INTEGER: Number.MAX_SAFE_INTEGER,
|
|
55
|
-
MIN_SAFE_INTEGER: Number.MIN_SAFE_INTEGER,
|
|
56
|
-
MAX_VALUE: Number.MAX_VALUE,
|
|
57
|
-
MIN_VALUE: Number.MIN_VALUE,
|
|
58
|
-
EPSILON: Number.EPSILON,
|
|
59
|
-
NaN: Number.NaN,
|
|
60
|
-
POSITIVE_INFINITY: Number.POSITIVE_INFINITY,
|
|
61
|
-
NEGATIVE_INFINITY: Number.NEGATIVE_INFINITY,
|
|
62
|
-
isInteger: sync("Number.isInteger", (args) => Number.isInteger(args[0])),
|
|
63
|
-
isFinite: sync("Number.isFinite", (args) => Number.isFinite(args[0])),
|
|
64
|
-
isNaN: sync("Number.isNaN", (args) => Number.isNaN(args[0])),
|
|
65
|
-
isSafeInteger: sync("Number.isSafeInteger", (args) => Number.isSafeInteger(args[0])),
|
|
66
|
-
parseInt: parseIntStatic,
|
|
67
|
-
parseFloat: sync("Number.parseFloat", (args) => parseFloat(coerceToString(args[0]))),
|
|
68
|
-
},
|
|
69
|
-
});
|
|
74
|
+
};
|
|
75
|
+
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
76
|
+
import { boundedData, coerceToString } from "./value.js";
|
package/dist/stdlib/object.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect } from "effect";
|
|
2
2
|
import { type AstNode } from "../interpreter/model.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
3
|
+
import { type SyncIteratorRunner } from "../interpreter/iterator.js";
|
|
4
|
+
export declare const objectMethodsPreservingIdentity: Set<string>;
|
|
5
|
+
export declare const objectStatics: Set<string>;
|
|
6
|
+
export declare const invokeObjectMethod: (name: string, args: Array<unknown>, node: AstNode) => unknown;
|
|
7
|
+
export declare const invokeObjectFromEntries: <R>(runner: SyncIteratorRunner<R>, source: unknown, node: AstNode) => Effect.Effect<Record<string, unknown>, unknown, R>;
|
package/dist/stdlib/object.js
CHANGED
|
@@ -1,55 +1,85 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { toProgram } from "../data.js";
|
|
3
|
-
import { HostFunction, sync, syncCall } from "../interpreter/host.js";
|
|
4
2
|
import { AsyncIteratorSymbol, InterpreterRuntimeError, IteratorSymbol } from "../interpreter/model.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
rejectCircularInsertion(target, getOwn(from, key), "Object.assign result", node, seen);
|
|
44
|
-
if (!set(target, key, getOwn(from, key))) {
|
|
45
|
-
throw new InterpreterRuntimeError("Invalid array length", node).as("RangeError");
|
|
3
|
+
import { containsOpaqueReference, rejectCircularInsertion } from "../interpreter/references.js";
|
|
4
|
+
import { isBlockedMember } from "../tool-runtime.js";
|
|
5
|
+
import { isCodeModeValue, CodeModePromise } from "../values.js";
|
|
6
|
+
import { boundedData, coerceToString } from "./value.js";
|
|
7
|
+
import { preserveConsumerError } from "../interpreter/iterator.js";
|
|
8
|
+
export const objectMethodsPreservingIdentity = new Set(["assign", "values", "entries", "fromEntries"]);
|
|
9
|
+
export const objectStatics = new Set(["keys", "values", "entries", "hasOwn", "is", "assign", "fromEntries", "groupBy"]);
|
|
10
|
+
export const invokeObjectMethod = (name, args, node) => {
|
|
11
|
+
const requireObject = () => {
|
|
12
|
+
const input = args[0];
|
|
13
|
+
if (Array.isArray(input))
|
|
14
|
+
return input;
|
|
15
|
+
if (isCodeModeValue(input))
|
|
16
|
+
return {};
|
|
17
|
+
if (input instanceof CodeModePromise) {
|
|
18
|
+
throw new InterpreterRuntimeError(`Object.${name} received an un-awaited Promise; await it before inspecting the result.`, node, "InvalidDataValue");
|
|
19
|
+
}
|
|
20
|
+
if (input === null || typeof input !== "object") {
|
|
21
|
+
throw new InterpreterRuntimeError(`Object.${name} expects a data object or array.`, node, "InvalidDataValue");
|
|
22
|
+
}
|
|
23
|
+
const prototype = Object.getPrototypeOf(input);
|
|
24
|
+
if (prototype !== null && prototype !== Object.prototype) {
|
|
25
|
+
throw new InterpreterRuntimeError(`Object.${name} expects a data object or array.`, node, "InvalidDataValue");
|
|
26
|
+
}
|
|
27
|
+
return input;
|
|
28
|
+
};
|
|
29
|
+
switch (name) {
|
|
30
|
+
case "keys":
|
|
31
|
+
return Object.keys(requireObject());
|
|
32
|
+
case "values":
|
|
33
|
+
return Object.values(requireObject());
|
|
34
|
+
case "entries":
|
|
35
|
+
return Object.entries(requireObject()).map(([key, item]) => [key, item]);
|
|
36
|
+
case "hasOwn":
|
|
37
|
+
return Object.hasOwn(requireObject(), args[1] === AsyncIteratorSymbol || args[1] === IteratorSymbol ? args[1] : String(args[1]));
|
|
38
|
+
case "is":
|
|
39
|
+
if (containsOpaqueReference(args[0]) || containsOpaqueReference(args[1])) {
|
|
40
|
+
throw new InterpreterRuntimeError("Object.is requires data values.", node, "InvalidDataValue");
|
|
46
41
|
}
|
|
42
|
+
return Object.is(args[0], args[1]);
|
|
43
|
+
case "assign": {
|
|
44
|
+
const target = args[0];
|
|
45
|
+
if (target === null || typeof target !== "object" || Array.isArray(target) || isCodeModeValue(target)) {
|
|
46
|
+
throw new InterpreterRuntimeError("Object.assign expects a data object target.", node);
|
|
47
|
+
}
|
|
48
|
+
const out = target;
|
|
49
|
+
const seen = new Set();
|
|
50
|
+
const guardedSet = (key, item) => {
|
|
51
|
+
if (typeof key === "string" && isBlockedMember(key))
|
|
52
|
+
throw new InterpreterRuntimeError(`Property '${key}' is not available.`, node);
|
|
53
|
+
rejectCircularInsertion(out, item, "Object.assign result", node, seen);
|
|
54
|
+
if (!Reflect.set(out, key, item))
|
|
55
|
+
throw new InterpreterRuntimeError(`Object.assign could not assign property '${String(key)}'.`, node).as("TypeError");
|
|
56
|
+
};
|
|
57
|
+
for (const source of args.slice(1)) {
|
|
58
|
+
if (source === null || source === undefined || isCodeModeValue(source))
|
|
59
|
+
continue;
|
|
60
|
+
if (typeof source !== "object" || Array.isArray(source)) {
|
|
61
|
+
throw new InterpreterRuntimeError("Object.assign expects data objects.", node);
|
|
62
|
+
}
|
|
63
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
64
|
+
if (typeof key === "string") {
|
|
65
|
+
if (Object.prototype.propertyIsEnumerable.call(source, key))
|
|
66
|
+
guardedSet(key, Reflect.get(source, key));
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (key !== AsyncIteratorSymbol && key !== IteratorSymbol)
|
|
70
|
+
continue;
|
|
71
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key))
|
|
72
|
+
continue;
|
|
73
|
+
guardedSet(key, Reflect.get(source, key));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
47
77
|
}
|
|
48
78
|
}
|
|
49
|
-
|
|
79
|
+
throw new InterpreterRuntimeError(`Object.${name} is not available.`, node);
|
|
50
80
|
};
|
|
51
|
-
const
|
|
52
|
-
const out =
|
|
81
|
+
export const invokeObjectFromEntries = (runner, source, node) => {
|
|
82
|
+
const out = Object.create(null);
|
|
53
83
|
return Effect.gen(function* () {
|
|
54
84
|
const cursor = yield* runner.syncIterator(source, node);
|
|
55
85
|
if (cursor === undefined) {
|
|
@@ -60,47 +90,20 @@ const objectFromEntries = (runner, source, node) => {
|
|
|
60
90
|
if (step.done)
|
|
61
91
|
return out;
|
|
62
92
|
yield* preserveConsumerError(cursor, Effect.sync(() => {
|
|
63
|
-
if (
|
|
93
|
+
if (step.value === null ||
|
|
94
|
+
typeof step.value !== "object" ||
|
|
95
|
+
isCodeModeValue(step.value) ||
|
|
96
|
+
containsOpaqueReference(step.value)) {
|
|
64
97
|
throw new InterpreterRuntimeError("Object.fromEntries expects [key, value] entry objects.", node).as("TypeError");
|
|
65
98
|
}
|
|
66
|
-
|
|
99
|
+
const entry = step.value;
|
|
100
|
+
boundedData(entry[0], "Object.fromEntries key");
|
|
101
|
+
boundedData(entry[1], "Object.fromEntries value");
|
|
102
|
+
const key = coerceToString(entry[0]);
|
|
103
|
+
if (isBlockedMember(key))
|
|
104
|
+
throw new InterpreterRuntimeError(`Property '${key}' is not available.`, node);
|
|
105
|
+
out[key] = entry[1];
|
|
67
106
|
}));
|
|
68
107
|
}
|
|
69
108
|
});
|
|
70
109
|
};
|
|
71
|
-
const constructObject = (args, node) => {
|
|
72
|
-
const first = args[0];
|
|
73
|
-
if (first === null || first === undefined)
|
|
74
|
-
return new ProgramObject();
|
|
75
|
-
if (typeof first === "object")
|
|
76
|
-
return first;
|
|
77
|
-
throw new InterpreterRuntimeError(`Object(${typeof first}) wrapper objects are not supported; use the primitive value directly.`, node);
|
|
78
|
-
};
|
|
79
|
-
// Object constructs identically with or without new, like JS. Only `keys` copies its result into the
|
|
80
|
-
// program; `values`, `entries`, `assign`, and `fromEntries` hand back the program's own values.
|
|
81
|
-
export const objectGlobal = (runner, toolKeys) => new HostFunction({
|
|
82
|
-
name: "Object",
|
|
83
|
-
call: syncCall(constructObject),
|
|
84
|
-
construct: syncCall(constructObject),
|
|
85
|
-
instanceOf: (value) => value !== null && (typeof value === "object" || typeofValue(value) === "function"),
|
|
86
|
-
members: {
|
|
87
|
-
keys: sync("Object.keys", (args, node) => toProgram(args[0] instanceof ToolReference
|
|
88
|
-
? [...toolKeys(args[0].path)]
|
|
89
|
-
: ownKeys(enumerableSource("Object.keys(...)", args[0], node)).filter((key) => typeof key === "string"), "Object.keys result")),
|
|
90
|
-
values: sync("Object.values", (args, node) => new ProgramArray(ownEntries(enumerableSource("Object.values(...)", args[0], node)).map((entry) => entry[1]))),
|
|
91
|
-
entries: sync("Object.entries", (args, node) => new ProgramArray(ownEntries(enumerableSource("Object.entries(...)", args[0], node)).map((entry) => new ProgramArray(entry)))),
|
|
92
|
-
hasOwn: sync("Object.hasOwn", (args, node) => hasOwn(enumerableSource("Object.hasOwn(...)", args[0], node), args[1] === AsyncIteratorSymbol || args[1] === IteratorSymbol ? args[1] : String(args[1]))),
|
|
93
|
-
is: sync("Object.is", (args, node) => {
|
|
94
|
-
if (containsOpaqueReference(args[0]) || containsOpaqueReference(args[1])) {
|
|
95
|
-
throw new InterpreterRuntimeError("Object.is requires data values.", node, "InvalidDataValue");
|
|
96
|
-
}
|
|
97
|
-
return Object.is(args[0], args[1]);
|
|
98
|
-
}),
|
|
99
|
-
assign: sync("Object.assign", objectAssign),
|
|
100
|
-
fromEntries: new HostFunction({
|
|
101
|
-
name: "Object.fromEntries",
|
|
102
|
-
call: (args, node) => Effect.suspend(() => objectFromEntries(runner, args[0], node)),
|
|
103
|
-
}),
|
|
104
|
-
groupBy: groupBy(runner, "Object"),
|
|
105
|
-
},
|
|
106
|
-
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const promiseStatics = new Set(["all", "allSettled", "race", "any", "resolve", "reject"]);
|
package/dist/stdlib/regexp.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type AstNode } from "../interpreter/model.js";
|
|
2
|
-
import {
|
|
3
|
-
import { Values } from "../values.js";
|
|
2
|
+
import { CodeModeRegExp } from "../values.js";
|
|
4
3
|
export declare const regexpMethods: Set<string>;
|
|
4
|
+
export declare const regexpStatics: Set<string>;
|
|
5
5
|
export declare const regexpProperties: Set<string>;
|
|
6
|
+
export declare const regexFailureReason: (error: unknown) => string;
|
|
7
|
+
export declare const escapeRegexHint = "To match special characters like ( ) [ ] { } + * ? . literally, escape them with a backslash (e.g. \"\\\\(\") or test for them with String.includes instead.";
|
|
6
8
|
export declare const toHostRegex: (arg: unknown, method: string, node: AstNode, extraFlags?: string) => RegExp;
|
|
7
|
-
export declare const matchToValue: (match: RegExpMatchArray) =>
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const invokeRegExpMethod: (value: Values.RegExp, name: string, args: Array<unknown>, node: AstNode) => unknown;
|
|
9
|
+
export declare const matchToValue: (match: RegExpMatchArray) => Array<unknown>;
|
|
10
|
+
export declare const invokeRegExpStatic: (name: string, args: Array<unknown>, node: AstNode) => string;
|
|
11
|
+
export declare const invokeRegExpMethod: (value: CodeModeRegExp, name: string, args: Array<unknown>, node: AstNode) => unknown;
|