jslike 1.7.2 → 1.7.3
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/esm/interpreter/interpreter.js +120 -51
- package/dist/index.cjs +90 -39
- package/dist/index.d.cts +120 -51
- package/dist/index.d.ts +120 -51
- package/dist/index.js +90 -39
- package/package.json +1 -1
|
@@ -39,6 +39,121 @@ export class Interpreter {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
async evaluateAsyncRawValue(node, env) {
|
|
43
|
+
if (!node) return { value: undefined };
|
|
44
|
+
|
|
45
|
+
if (node.type === 'CallExpression') {
|
|
46
|
+
return await this.evaluateCallExpressionAsyncRawValue(node, env);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (node.type === 'MemberExpression') {
|
|
50
|
+
const obj = (await this.evaluateAsyncRawValue(node.object, env)).value;
|
|
51
|
+
|
|
52
|
+
if (node.optional && (obj === null || obj === undefined)) {
|
|
53
|
+
return { value: undefined };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (obj === null || obj === undefined) {
|
|
57
|
+
throw new TypeError(`Cannot read property of ${obj}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const prop = node.computed
|
|
61
|
+
? await this.evaluateAsync(node.property, env)
|
|
62
|
+
: node.property.name;
|
|
63
|
+
|
|
64
|
+
return { value: obj[prop] };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (node.type === 'ChainExpression') {
|
|
68
|
+
return await this.evaluateAsyncRawValue(node.expression, env);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (node.type === 'ConditionalExpression') {
|
|
72
|
+
const test = await this.evaluateAsync(node.test, env);
|
|
73
|
+
return await this.evaluateAsyncRawValue(test ? node.consequent : node.alternate, env);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (node.type === 'LogicalExpression') {
|
|
77
|
+
const left = await this.evaluateAsync(node.left, env);
|
|
78
|
+
if (node.operator === '&&') {
|
|
79
|
+
return left ? await this.evaluateAsyncRawValue(node.right, env) : { value: left };
|
|
80
|
+
}
|
|
81
|
+
if (node.operator === '||') {
|
|
82
|
+
return left ? { value: left } : await this.evaluateAsyncRawValue(node.right, env);
|
|
83
|
+
}
|
|
84
|
+
if (node.operator === '??') {
|
|
85
|
+
return left !== null && left !== undefined
|
|
86
|
+
? { value: left }
|
|
87
|
+
: await this.evaluateAsyncRawValue(node.right, env);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (node.type === 'SequenceExpression') {
|
|
92
|
+
for (let i = 0; i < node.expressions.length - 1; i++) {
|
|
93
|
+
await this.evaluateAsync(node.expressions[i], env);
|
|
94
|
+
}
|
|
95
|
+
return await this.evaluateAsyncRawValue(node.expressions[node.expressions.length - 1], env);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (node.type === 'NewExpression') {
|
|
99
|
+
return { value: this.evaluateNewExpression(node, env) };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (['Literal', 'Identifier', 'ThisExpression', 'Super'].includes(node.type)) {
|
|
103
|
+
return { value: this.evaluate(node, env) };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return { value: await this.evaluateAsync(node, env) };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async evaluateCallExpressionAsyncRawValue(node, env) {
|
|
110
|
+
let thisContext = undefined;
|
|
111
|
+
let callee;
|
|
112
|
+
let objectName = null;
|
|
113
|
+
let methodName = null;
|
|
114
|
+
|
|
115
|
+
if (node.callee.type === 'MemberExpression') {
|
|
116
|
+
thisContext = (await this.evaluateAsyncRawValue(node.callee.object, env)).value;
|
|
117
|
+
if (node.callee.optional && (thisContext === null || thisContext === undefined)) {
|
|
118
|
+
return { value: undefined };
|
|
119
|
+
}
|
|
120
|
+
const prop = node.callee.computed
|
|
121
|
+
? await this.evaluateAsync(node.callee.property, env)
|
|
122
|
+
: node.callee.property.name;
|
|
123
|
+
callee = thisContext[prop];
|
|
124
|
+
|
|
125
|
+
methodName = prop;
|
|
126
|
+
objectName = this.getExpressionName(node.callee.object);
|
|
127
|
+
} else {
|
|
128
|
+
callee = await this.evaluateAsync(node.callee, env);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (node.optional && (callee === null || callee === undefined)) {
|
|
132
|
+
return { value: undefined };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const rawArgs = [];
|
|
136
|
+
for (const arg of node.arguments) {
|
|
137
|
+
rawArgs.push(await this.evaluateAsync(arg, env));
|
|
138
|
+
}
|
|
139
|
+
const args = this.flattenSpreadArgs(rawArgs);
|
|
140
|
+
|
|
141
|
+
if (typeof callee === 'function') {
|
|
142
|
+
const value = thisContext !== undefined
|
|
143
|
+
? callee.call(thisContext, ...args)
|
|
144
|
+
: callee(...args);
|
|
145
|
+
return { value };
|
|
146
|
+
} else if (callee && callee.__isFunction) {
|
|
147
|
+
return { value: this.callUserFunction(callee, args, env, thisContext) };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (objectName && methodName) {
|
|
151
|
+
throw createMethodNotFoundError(objectName, methodName, thisContext);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
throw new TypeError(`${node.callee.name || 'Expression'} is not a function`);
|
|
155
|
+
}
|
|
156
|
+
|
|
42
157
|
// Async evaluation for async functions - handles await expressions
|
|
43
158
|
async evaluateAsync(node, env) {
|
|
44
159
|
if (!node) return undefined;
|
|
@@ -77,7 +192,7 @@ export class Interpreter {
|
|
|
77
192
|
if (node.type === 'VariableDeclaration') {
|
|
78
193
|
for (const declarator of node.declarations) {
|
|
79
194
|
const value = declarator.init
|
|
80
|
-
? await this.
|
|
195
|
+
? (await this.evaluateAsyncRawValue(declarator.init, env)).value
|
|
81
196
|
: undefined;
|
|
82
197
|
|
|
83
198
|
const isConst = node.kind === 'const';
|
|
@@ -134,54 +249,8 @@ export class Interpreter {
|
|
|
134
249
|
|
|
135
250
|
// For call expressions (might be calling async functions)
|
|
136
251
|
if (node.type === 'CallExpression') {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
let objectName = null;
|
|
140
|
-
let methodName = null;
|
|
141
|
-
|
|
142
|
-
if (node.callee.type === 'MemberExpression') {
|
|
143
|
-
thisContext = await this.evaluateAsync(node.callee.object, env);
|
|
144
|
-
if (node.callee.optional && (thisContext === null || thisContext === undefined)) {
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
147
|
-
const prop = node.callee.computed
|
|
148
|
-
? await this.evaluateAsync(node.callee.property, env)
|
|
149
|
-
: node.callee.property.name;
|
|
150
|
-
callee = thisContext[prop];
|
|
151
|
-
|
|
152
|
-
// Capture names for enhanced error messages
|
|
153
|
-
methodName = prop;
|
|
154
|
-
objectName = this.getExpressionName(node.callee.object);
|
|
155
|
-
} else {
|
|
156
|
-
callee = await this.evaluateAsync(node.callee, env);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Handle optional call - if optional and callee is null/undefined, return undefined
|
|
160
|
-
if (node.optional && (callee === null || callee === undefined)) {
|
|
161
|
-
return undefined;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const rawArgs = [];
|
|
165
|
-
for (const arg of node.arguments) {
|
|
166
|
-
rawArgs.push(await this.evaluateAsync(arg, env));
|
|
167
|
-
}
|
|
168
|
-
const args = this.flattenSpreadArgs(rawArgs);
|
|
169
|
-
|
|
170
|
-
if (typeof callee === 'function') {
|
|
171
|
-
if (thisContext !== undefined) {
|
|
172
|
-
return await callee.call(thisContext, ...args);
|
|
173
|
-
}
|
|
174
|
-
return await callee(...args);
|
|
175
|
-
} else if (callee && callee.__isFunction) {
|
|
176
|
-
return await this.callUserFunction(callee, args, env, thisContext);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Throw enhanced error for member expression calls
|
|
180
|
-
if (objectName && methodName) {
|
|
181
|
-
throw createMethodNotFoundError(objectName, methodName, thisContext);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
throw new TypeError(`${node.callee.name || 'Expression'} is not a function`);
|
|
252
|
+
const result = (await this.evaluateCallExpressionAsyncRawValue(node, env)).value;
|
|
253
|
+
return await result;
|
|
185
254
|
}
|
|
186
255
|
|
|
187
256
|
// For chain expressions (optional chaining)
|
|
@@ -191,7 +260,7 @@ export class Interpreter {
|
|
|
191
260
|
|
|
192
261
|
// For member expressions in async context
|
|
193
262
|
if (node.type === 'MemberExpression') {
|
|
194
|
-
const obj = await this.
|
|
263
|
+
const obj = (await this.evaluateAsyncRawValue(node.object, env)).value;
|
|
195
264
|
|
|
196
265
|
// Handle optional chaining
|
|
197
266
|
if (node.optional && (obj === null || obj === undefined)) {
|
|
@@ -513,7 +582,7 @@ export class Interpreter {
|
|
|
513
582
|
|
|
514
583
|
// For AssignmentExpression with async value
|
|
515
584
|
if (node.type === 'AssignmentExpression') {
|
|
516
|
-
const value = await this.
|
|
585
|
+
const value = (await this.evaluateAsyncRawValue(node.right, env)).value;
|
|
517
586
|
|
|
518
587
|
if (node.left.type === 'Identifier') {
|
|
519
588
|
const name = node.left.name;
|
package/dist/index.cjs
CHANGED
|
@@ -6507,6 +6507,91 @@ var Interpreter = class _Interpreter {
|
|
|
6507
6507
|
return null;
|
|
6508
6508
|
}
|
|
6509
6509
|
}
|
|
6510
|
+
async evaluateAsyncRawValue(node, env) {
|
|
6511
|
+
if (!node) return { value: void 0 };
|
|
6512
|
+
if (node.type === "CallExpression") {
|
|
6513
|
+
return await this.evaluateCallExpressionAsyncRawValue(node, env);
|
|
6514
|
+
}
|
|
6515
|
+
if (node.type === "MemberExpression") {
|
|
6516
|
+
const obj = (await this.evaluateAsyncRawValue(node.object, env)).value;
|
|
6517
|
+
if (node.optional && (obj === null || obj === void 0)) {
|
|
6518
|
+
return { value: void 0 };
|
|
6519
|
+
}
|
|
6520
|
+
if (obj === null || obj === void 0) {
|
|
6521
|
+
throw new TypeError(`Cannot read property of ${obj}`);
|
|
6522
|
+
}
|
|
6523
|
+
const prop = node.computed ? await this.evaluateAsync(node.property, env) : node.property.name;
|
|
6524
|
+
return { value: obj[prop] };
|
|
6525
|
+
}
|
|
6526
|
+
if (node.type === "ChainExpression") {
|
|
6527
|
+
return await this.evaluateAsyncRawValue(node.expression, env);
|
|
6528
|
+
}
|
|
6529
|
+
if (node.type === "ConditionalExpression") {
|
|
6530
|
+
const test = await this.evaluateAsync(node.test, env);
|
|
6531
|
+
return await this.evaluateAsyncRawValue(test ? node.consequent : node.alternate, env);
|
|
6532
|
+
}
|
|
6533
|
+
if (node.type === "LogicalExpression") {
|
|
6534
|
+
const left = await this.evaluateAsync(node.left, env);
|
|
6535
|
+
if (node.operator === "&&") {
|
|
6536
|
+
return left ? await this.evaluateAsyncRawValue(node.right, env) : { value: left };
|
|
6537
|
+
}
|
|
6538
|
+
if (node.operator === "||") {
|
|
6539
|
+
return left ? { value: left } : await this.evaluateAsyncRawValue(node.right, env);
|
|
6540
|
+
}
|
|
6541
|
+
if (node.operator === "??") {
|
|
6542
|
+
return left !== null && left !== void 0 ? { value: left } : await this.evaluateAsyncRawValue(node.right, env);
|
|
6543
|
+
}
|
|
6544
|
+
}
|
|
6545
|
+
if (node.type === "SequenceExpression") {
|
|
6546
|
+
for (let i = 0; i < node.expressions.length - 1; i++) {
|
|
6547
|
+
await this.evaluateAsync(node.expressions[i], env);
|
|
6548
|
+
}
|
|
6549
|
+
return await this.evaluateAsyncRawValue(node.expressions[node.expressions.length - 1], env);
|
|
6550
|
+
}
|
|
6551
|
+
if (node.type === "NewExpression") {
|
|
6552
|
+
return { value: this.evaluateNewExpression(node, env) };
|
|
6553
|
+
}
|
|
6554
|
+
if (["Literal", "Identifier", "ThisExpression", "Super"].includes(node.type)) {
|
|
6555
|
+
return { value: this.evaluate(node, env) };
|
|
6556
|
+
}
|
|
6557
|
+
return { value: await this.evaluateAsync(node, env) };
|
|
6558
|
+
}
|
|
6559
|
+
async evaluateCallExpressionAsyncRawValue(node, env) {
|
|
6560
|
+
let thisContext = void 0;
|
|
6561
|
+
let callee;
|
|
6562
|
+
let objectName = null;
|
|
6563
|
+
let methodName = null;
|
|
6564
|
+
if (node.callee.type === "MemberExpression") {
|
|
6565
|
+
thisContext = (await this.evaluateAsyncRawValue(node.callee.object, env)).value;
|
|
6566
|
+
if (node.callee.optional && (thisContext === null || thisContext === void 0)) {
|
|
6567
|
+
return { value: void 0 };
|
|
6568
|
+
}
|
|
6569
|
+
const prop = node.callee.computed ? await this.evaluateAsync(node.callee.property, env) : node.callee.property.name;
|
|
6570
|
+
callee = thisContext[prop];
|
|
6571
|
+
methodName = prop;
|
|
6572
|
+
objectName = this.getExpressionName(node.callee.object);
|
|
6573
|
+
} else {
|
|
6574
|
+
callee = await this.evaluateAsync(node.callee, env);
|
|
6575
|
+
}
|
|
6576
|
+
if (node.optional && (callee === null || callee === void 0)) {
|
|
6577
|
+
return { value: void 0 };
|
|
6578
|
+
}
|
|
6579
|
+
const rawArgs = [];
|
|
6580
|
+
for (const arg of node.arguments) {
|
|
6581
|
+
rawArgs.push(await this.evaluateAsync(arg, env));
|
|
6582
|
+
}
|
|
6583
|
+
const args = this.flattenSpreadArgs(rawArgs);
|
|
6584
|
+
if (typeof callee === "function") {
|
|
6585
|
+
const value = thisContext !== void 0 ? callee.call(thisContext, ...args) : callee(...args);
|
|
6586
|
+
return { value };
|
|
6587
|
+
} else if (callee && callee.__isFunction) {
|
|
6588
|
+
return { value: this.callUserFunction(callee, args, env, thisContext) };
|
|
6589
|
+
}
|
|
6590
|
+
if (objectName && methodName) {
|
|
6591
|
+
throw createMethodNotFoundError(objectName, methodName, thisContext);
|
|
6592
|
+
}
|
|
6593
|
+
throw new TypeError(`${node.callee.name || "Expression"} is not a function`);
|
|
6594
|
+
}
|
|
6510
6595
|
// Async evaluation for async functions - handles await expressions
|
|
6511
6596
|
async evaluateAsync(node, env) {
|
|
6512
6597
|
if (!node) return void 0;
|
|
@@ -6532,7 +6617,7 @@ var Interpreter = class _Interpreter {
|
|
|
6532
6617
|
}
|
|
6533
6618
|
if (node.type === "VariableDeclaration") {
|
|
6534
6619
|
for (const declarator of node.declarations) {
|
|
6535
|
-
const value = declarator.init ? await this.
|
|
6620
|
+
const value = declarator.init ? (await this.evaluateAsyncRawValue(declarator.init, env)).value : void 0;
|
|
6536
6621
|
const isConst = node.kind === "const";
|
|
6537
6622
|
if (declarator.id.type === "Identifier") {
|
|
6538
6623
|
env.define(declarator.id.name, value, isConst);
|
|
@@ -6573,48 +6658,14 @@ var Interpreter = class _Interpreter {
|
|
|
6573
6658
|
return this.evaluateBinaryExpressionValues(node.operator, left, right);
|
|
6574
6659
|
}
|
|
6575
6660
|
if (node.type === "CallExpression") {
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
let objectName = null;
|
|
6579
|
-
let methodName = null;
|
|
6580
|
-
if (node.callee.type === "MemberExpression") {
|
|
6581
|
-
thisContext = await this.evaluateAsync(node.callee.object, env);
|
|
6582
|
-
if (node.callee.optional && (thisContext === null || thisContext === void 0)) {
|
|
6583
|
-
return void 0;
|
|
6584
|
-
}
|
|
6585
|
-
const prop = node.callee.computed ? await this.evaluateAsync(node.callee.property, env) : node.callee.property.name;
|
|
6586
|
-
callee = thisContext[prop];
|
|
6587
|
-
methodName = prop;
|
|
6588
|
-
objectName = this.getExpressionName(node.callee.object);
|
|
6589
|
-
} else {
|
|
6590
|
-
callee = await this.evaluateAsync(node.callee, env);
|
|
6591
|
-
}
|
|
6592
|
-
if (node.optional && (callee === null || callee === void 0)) {
|
|
6593
|
-
return void 0;
|
|
6594
|
-
}
|
|
6595
|
-
const rawArgs = [];
|
|
6596
|
-
for (const arg of node.arguments) {
|
|
6597
|
-
rawArgs.push(await this.evaluateAsync(arg, env));
|
|
6598
|
-
}
|
|
6599
|
-
const args = this.flattenSpreadArgs(rawArgs);
|
|
6600
|
-
if (typeof callee === "function") {
|
|
6601
|
-
if (thisContext !== void 0) {
|
|
6602
|
-
return await callee.call(thisContext, ...args);
|
|
6603
|
-
}
|
|
6604
|
-
return await callee(...args);
|
|
6605
|
-
} else if (callee && callee.__isFunction) {
|
|
6606
|
-
return await this.callUserFunction(callee, args, env, thisContext);
|
|
6607
|
-
}
|
|
6608
|
-
if (objectName && methodName) {
|
|
6609
|
-
throw createMethodNotFoundError(objectName, methodName, thisContext);
|
|
6610
|
-
}
|
|
6611
|
-
throw new TypeError(`${node.callee.name || "Expression"} is not a function`);
|
|
6661
|
+
const result = (await this.evaluateCallExpressionAsyncRawValue(node, env)).value;
|
|
6662
|
+
return await result;
|
|
6612
6663
|
}
|
|
6613
6664
|
if (node.type === "ChainExpression") {
|
|
6614
6665
|
return await this.evaluateAsync(node.expression, env);
|
|
6615
6666
|
}
|
|
6616
6667
|
if (node.type === "MemberExpression") {
|
|
6617
|
-
const obj = await this.
|
|
6668
|
+
const obj = (await this.evaluateAsyncRawValue(node.object, env)).value;
|
|
6618
6669
|
if (node.optional && (obj === null || obj === void 0)) {
|
|
6619
6670
|
return void 0;
|
|
6620
6671
|
}
|
|
@@ -6872,7 +6923,7 @@ var Interpreter = class _Interpreter {
|
|
|
6872
6923
|
return test ? await this.evaluateAsync(node.consequent, env) : await this.evaluateAsync(node.alternate, env);
|
|
6873
6924
|
}
|
|
6874
6925
|
if (node.type === "AssignmentExpression") {
|
|
6875
|
-
const value = await this.
|
|
6926
|
+
const value = (await this.evaluateAsyncRawValue(node.right, env)).value;
|
|
6876
6927
|
if (node.left.type === "Identifier") {
|
|
6877
6928
|
const name = node.left.name;
|
|
6878
6929
|
if (node.operator === "=") {
|
package/dist/index.d.cts
CHANGED
|
@@ -7204,6 +7204,121 @@ class Interpreter {
|
|
|
7204
7204
|
}
|
|
7205
7205
|
}
|
|
7206
7206
|
|
|
7207
|
+
async evaluateAsyncRawValue(node, env) {
|
|
7208
|
+
if (!node) return { value: undefined };
|
|
7209
|
+
|
|
7210
|
+
if (node.type === 'CallExpression') {
|
|
7211
|
+
return await this.evaluateCallExpressionAsyncRawValue(node, env);
|
|
7212
|
+
}
|
|
7213
|
+
|
|
7214
|
+
if (node.type === 'MemberExpression') {
|
|
7215
|
+
const obj = (await this.evaluateAsyncRawValue(node.object, env)).value;
|
|
7216
|
+
|
|
7217
|
+
if (node.optional && (obj === null || obj === undefined)) {
|
|
7218
|
+
return { value: undefined };
|
|
7219
|
+
}
|
|
7220
|
+
|
|
7221
|
+
if (obj === null || obj === undefined) {
|
|
7222
|
+
throw new TypeError(`Cannot read property of ${obj}`);
|
|
7223
|
+
}
|
|
7224
|
+
|
|
7225
|
+
const prop = node.computed
|
|
7226
|
+
? await this.evaluateAsync(node.property, env)
|
|
7227
|
+
: node.property.name;
|
|
7228
|
+
|
|
7229
|
+
return { value: obj[prop] };
|
|
7230
|
+
}
|
|
7231
|
+
|
|
7232
|
+
if (node.type === 'ChainExpression') {
|
|
7233
|
+
return await this.evaluateAsyncRawValue(node.expression, env);
|
|
7234
|
+
}
|
|
7235
|
+
|
|
7236
|
+
if (node.type === 'ConditionalExpression') {
|
|
7237
|
+
const test = await this.evaluateAsync(node.test, env);
|
|
7238
|
+
return await this.evaluateAsyncRawValue(test ? node.consequent : node.alternate, env);
|
|
7239
|
+
}
|
|
7240
|
+
|
|
7241
|
+
if (node.type === 'LogicalExpression') {
|
|
7242
|
+
const left = await this.evaluateAsync(node.left, env);
|
|
7243
|
+
if (node.operator === '&&') {
|
|
7244
|
+
return left ? await this.evaluateAsyncRawValue(node.right, env) : { value: left };
|
|
7245
|
+
}
|
|
7246
|
+
if (node.operator === '||') {
|
|
7247
|
+
return left ? { value: left } : await this.evaluateAsyncRawValue(node.right, env);
|
|
7248
|
+
}
|
|
7249
|
+
if (node.operator === '??') {
|
|
7250
|
+
return left !== null && left !== undefined
|
|
7251
|
+
? { value: left }
|
|
7252
|
+
: await this.evaluateAsyncRawValue(node.right, env);
|
|
7253
|
+
}
|
|
7254
|
+
}
|
|
7255
|
+
|
|
7256
|
+
if (node.type === 'SequenceExpression') {
|
|
7257
|
+
for (let i = 0; i < node.expressions.length - 1; i++) {
|
|
7258
|
+
await this.evaluateAsync(node.expressions[i], env);
|
|
7259
|
+
}
|
|
7260
|
+
return await this.evaluateAsyncRawValue(node.expressions[node.expressions.length - 1], env);
|
|
7261
|
+
}
|
|
7262
|
+
|
|
7263
|
+
if (node.type === 'NewExpression') {
|
|
7264
|
+
return { value: this.evaluateNewExpression(node, env) };
|
|
7265
|
+
}
|
|
7266
|
+
|
|
7267
|
+
if (['Literal', 'Identifier', 'ThisExpression', 'Super'].includes(node.type)) {
|
|
7268
|
+
return { value: this.evaluate(node, env) };
|
|
7269
|
+
}
|
|
7270
|
+
|
|
7271
|
+
return { value: await this.evaluateAsync(node, env) };
|
|
7272
|
+
}
|
|
7273
|
+
|
|
7274
|
+
async evaluateCallExpressionAsyncRawValue(node, env) {
|
|
7275
|
+
let thisContext = undefined;
|
|
7276
|
+
let callee;
|
|
7277
|
+
let objectName = null;
|
|
7278
|
+
let methodName = null;
|
|
7279
|
+
|
|
7280
|
+
if (node.callee.type === 'MemberExpression') {
|
|
7281
|
+
thisContext = (await this.evaluateAsyncRawValue(node.callee.object, env)).value;
|
|
7282
|
+
if (node.callee.optional && (thisContext === null || thisContext === undefined)) {
|
|
7283
|
+
return { value: undefined };
|
|
7284
|
+
}
|
|
7285
|
+
const prop = node.callee.computed
|
|
7286
|
+
? await this.evaluateAsync(node.callee.property, env)
|
|
7287
|
+
: node.callee.property.name;
|
|
7288
|
+
callee = thisContext[prop];
|
|
7289
|
+
|
|
7290
|
+
methodName = prop;
|
|
7291
|
+
objectName = this.getExpressionName(node.callee.object);
|
|
7292
|
+
} else {
|
|
7293
|
+
callee = await this.evaluateAsync(node.callee, env);
|
|
7294
|
+
}
|
|
7295
|
+
|
|
7296
|
+
if (node.optional && (callee === null || callee === undefined)) {
|
|
7297
|
+
return { value: undefined };
|
|
7298
|
+
}
|
|
7299
|
+
|
|
7300
|
+
const rawArgs = [];
|
|
7301
|
+
for (const arg of node.arguments) {
|
|
7302
|
+
rawArgs.push(await this.evaluateAsync(arg, env));
|
|
7303
|
+
}
|
|
7304
|
+
const args = this.flattenSpreadArgs(rawArgs);
|
|
7305
|
+
|
|
7306
|
+
if (typeof callee === 'function') {
|
|
7307
|
+
const value = thisContext !== undefined
|
|
7308
|
+
? callee.call(thisContext, ...args)
|
|
7309
|
+
: callee(...args);
|
|
7310
|
+
return { value };
|
|
7311
|
+
} else if (callee && callee.__isFunction) {
|
|
7312
|
+
return { value: this.callUserFunction(callee, args, env, thisContext) };
|
|
7313
|
+
}
|
|
7314
|
+
|
|
7315
|
+
if (objectName && methodName) {
|
|
7316
|
+
throw createMethodNotFoundError(objectName, methodName, thisContext);
|
|
7317
|
+
}
|
|
7318
|
+
|
|
7319
|
+
throw new TypeError(`${node.callee.name || 'Expression'} is not a function`);
|
|
7320
|
+
}
|
|
7321
|
+
|
|
7207
7322
|
// Async evaluation for async functions - handles await expressions
|
|
7208
7323
|
async evaluateAsync(node, env) {
|
|
7209
7324
|
if (!node) return undefined;
|
|
@@ -7242,7 +7357,7 @@ class Interpreter {
|
|
|
7242
7357
|
if (node.type === 'VariableDeclaration') {
|
|
7243
7358
|
for (const declarator of node.declarations) {
|
|
7244
7359
|
const value = declarator.init
|
|
7245
|
-
? await this.
|
|
7360
|
+
? (await this.evaluateAsyncRawValue(declarator.init, env)).value
|
|
7246
7361
|
: undefined;
|
|
7247
7362
|
|
|
7248
7363
|
const isConst = node.kind === 'const';
|
|
@@ -7299,54 +7414,8 @@ class Interpreter {
|
|
|
7299
7414
|
|
|
7300
7415
|
// For call expressions (might be calling async functions)
|
|
7301
7416
|
if (node.type === 'CallExpression') {
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
let objectName = null;
|
|
7305
|
-
let methodName = null;
|
|
7306
|
-
|
|
7307
|
-
if (node.callee.type === 'MemberExpression') {
|
|
7308
|
-
thisContext = await this.evaluateAsync(node.callee.object, env);
|
|
7309
|
-
if (node.callee.optional && (thisContext === null || thisContext === undefined)) {
|
|
7310
|
-
return undefined;
|
|
7311
|
-
}
|
|
7312
|
-
const prop = node.callee.computed
|
|
7313
|
-
? await this.evaluateAsync(node.callee.property, env)
|
|
7314
|
-
: node.callee.property.name;
|
|
7315
|
-
callee = thisContext[prop];
|
|
7316
|
-
|
|
7317
|
-
// Capture names for enhanced error messages
|
|
7318
|
-
methodName = prop;
|
|
7319
|
-
objectName = this.getExpressionName(node.callee.object);
|
|
7320
|
-
} else {
|
|
7321
|
-
callee = await this.evaluateAsync(node.callee, env);
|
|
7322
|
-
}
|
|
7323
|
-
|
|
7324
|
-
// Handle optional call - if optional and callee is null/undefined, return undefined
|
|
7325
|
-
if (node.optional && (callee === null || callee === undefined)) {
|
|
7326
|
-
return undefined;
|
|
7327
|
-
}
|
|
7328
|
-
|
|
7329
|
-
const rawArgs = [];
|
|
7330
|
-
for (const arg of node.arguments) {
|
|
7331
|
-
rawArgs.push(await this.evaluateAsync(arg, env));
|
|
7332
|
-
}
|
|
7333
|
-
const args = this.flattenSpreadArgs(rawArgs);
|
|
7334
|
-
|
|
7335
|
-
if (typeof callee === 'function') {
|
|
7336
|
-
if (thisContext !== undefined) {
|
|
7337
|
-
return await callee.call(thisContext, ...args);
|
|
7338
|
-
}
|
|
7339
|
-
return await callee(...args);
|
|
7340
|
-
} else if (callee && callee.__isFunction) {
|
|
7341
|
-
return await this.callUserFunction(callee, args, env, thisContext);
|
|
7342
|
-
}
|
|
7343
|
-
|
|
7344
|
-
// Throw enhanced error for member expression calls
|
|
7345
|
-
if (objectName && methodName) {
|
|
7346
|
-
throw createMethodNotFoundError(objectName, methodName, thisContext);
|
|
7347
|
-
}
|
|
7348
|
-
|
|
7349
|
-
throw new TypeError(`${node.callee.name || 'Expression'} is not a function`);
|
|
7417
|
+
const result = (await this.evaluateCallExpressionAsyncRawValue(node, env)).value;
|
|
7418
|
+
return await result;
|
|
7350
7419
|
}
|
|
7351
7420
|
|
|
7352
7421
|
// For chain expressions (optional chaining)
|
|
@@ -7356,7 +7425,7 @@ class Interpreter {
|
|
|
7356
7425
|
|
|
7357
7426
|
// For member expressions in async context
|
|
7358
7427
|
if (node.type === 'MemberExpression') {
|
|
7359
|
-
const obj = await this.
|
|
7428
|
+
const obj = (await this.evaluateAsyncRawValue(node.object, env)).value;
|
|
7360
7429
|
|
|
7361
7430
|
// Handle optional chaining
|
|
7362
7431
|
if (node.optional && (obj === null || obj === undefined)) {
|
|
@@ -7678,7 +7747,7 @@ class Interpreter {
|
|
|
7678
7747
|
|
|
7679
7748
|
// For AssignmentExpression with async value
|
|
7680
7749
|
if (node.type === 'AssignmentExpression') {
|
|
7681
|
-
const value = await this.
|
|
7750
|
+
const value = (await this.evaluateAsyncRawValue(node.right, env)).value;
|
|
7682
7751
|
|
|
7683
7752
|
if (node.left.type === 'Identifier') {
|
|
7684
7753
|
const name = node.left.name;
|
package/dist/index.d.ts
CHANGED
|
@@ -7204,6 +7204,121 @@ class Interpreter {
|
|
|
7204
7204
|
}
|
|
7205
7205
|
}
|
|
7206
7206
|
|
|
7207
|
+
async evaluateAsyncRawValue(node, env) {
|
|
7208
|
+
if (!node) return { value: undefined };
|
|
7209
|
+
|
|
7210
|
+
if (node.type === 'CallExpression') {
|
|
7211
|
+
return await this.evaluateCallExpressionAsyncRawValue(node, env);
|
|
7212
|
+
}
|
|
7213
|
+
|
|
7214
|
+
if (node.type === 'MemberExpression') {
|
|
7215
|
+
const obj = (await this.evaluateAsyncRawValue(node.object, env)).value;
|
|
7216
|
+
|
|
7217
|
+
if (node.optional && (obj === null || obj === undefined)) {
|
|
7218
|
+
return { value: undefined };
|
|
7219
|
+
}
|
|
7220
|
+
|
|
7221
|
+
if (obj === null || obj === undefined) {
|
|
7222
|
+
throw new TypeError(`Cannot read property of ${obj}`);
|
|
7223
|
+
}
|
|
7224
|
+
|
|
7225
|
+
const prop = node.computed
|
|
7226
|
+
? await this.evaluateAsync(node.property, env)
|
|
7227
|
+
: node.property.name;
|
|
7228
|
+
|
|
7229
|
+
return { value: obj[prop] };
|
|
7230
|
+
}
|
|
7231
|
+
|
|
7232
|
+
if (node.type === 'ChainExpression') {
|
|
7233
|
+
return await this.evaluateAsyncRawValue(node.expression, env);
|
|
7234
|
+
}
|
|
7235
|
+
|
|
7236
|
+
if (node.type === 'ConditionalExpression') {
|
|
7237
|
+
const test = await this.evaluateAsync(node.test, env);
|
|
7238
|
+
return await this.evaluateAsyncRawValue(test ? node.consequent : node.alternate, env);
|
|
7239
|
+
}
|
|
7240
|
+
|
|
7241
|
+
if (node.type === 'LogicalExpression') {
|
|
7242
|
+
const left = await this.evaluateAsync(node.left, env);
|
|
7243
|
+
if (node.operator === '&&') {
|
|
7244
|
+
return left ? await this.evaluateAsyncRawValue(node.right, env) : { value: left };
|
|
7245
|
+
}
|
|
7246
|
+
if (node.operator === '||') {
|
|
7247
|
+
return left ? { value: left } : await this.evaluateAsyncRawValue(node.right, env);
|
|
7248
|
+
}
|
|
7249
|
+
if (node.operator === '??') {
|
|
7250
|
+
return left !== null && left !== undefined
|
|
7251
|
+
? { value: left }
|
|
7252
|
+
: await this.evaluateAsyncRawValue(node.right, env);
|
|
7253
|
+
}
|
|
7254
|
+
}
|
|
7255
|
+
|
|
7256
|
+
if (node.type === 'SequenceExpression') {
|
|
7257
|
+
for (let i = 0; i < node.expressions.length - 1; i++) {
|
|
7258
|
+
await this.evaluateAsync(node.expressions[i], env);
|
|
7259
|
+
}
|
|
7260
|
+
return await this.evaluateAsyncRawValue(node.expressions[node.expressions.length - 1], env);
|
|
7261
|
+
}
|
|
7262
|
+
|
|
7263
|
+
if (node.type === 'NewExpression') {
|
|
7264
|
+
return { value: this.evaluateNewExpression(node, env) };
|
|
7265
|
+
}
|
|
7266
|
+
|
|
7267
|
+
if (['Literal', 'Identifier', 'ThisExpression', 'Super'].includes(node.type)) {
|
|
7268
|
+
return { value: this.evaluate(node, env) };
|
|
7269
|
+
}
|
|
7270
|
+
|
|
7271
|
+
return { value: await this.evaluateAsync(node, env) };
|
|
7272
|
+
}
|
|
7273
|
+
|
|
7274
|
+
async evaluateCallExpressionAsyncRawValue(node, env) {
|
|
7275
|
+
let thisContext = undefined;
|
|
7276
|
+
let callee;
|
|
7277
|
+
let objectName = null;
|
|
7278
|
+
let methodName = null;
|
|
7279
|
+
|
|
7280
|
+
if (node.callee.type === 'MemberExpression') {
|
|
7281
|
+
thisContext = (await this.evaluateAsyncRawValue(node.callee.object, env)).value;
|
|
7282
|
+
if (node.callee.optional && (thisContext === null || thisContext === undefined)) {
|
|
7283
|
+
return { value: undefined };
|
|
7284
|
+
}
|
|
7285
|
+
const prop = node.callee.computed
|
|
7286
|
+
? await this.evaluateAsync(node.callee.property, env)
|
|
7287
|
+
: node.callee.property.name;
|
|
7288
|
+
callee = thisContext[prop];
|
|
7289
|
+
|
|
7290
|
+
methodName = prop;
|
|
7291
|
+
objectName = this.getExpressionName(node.callee.object);
|
|
7292
|
+
} else {
|
|
7293
|
+
callee = await this.evaluateAsync(node.callee, env);
|
|
7294
|
+
}
|
|
7295
|
+
|
|
7296
|
+
if (node.optional && (callee === null || callee === undefined)) {
|
|
7297
|
+
return { value: undefined };
|
|
7298
|
+
}
|
|
7299
|
+
|
|
7300
|
+
const rawArgs = [];
|
|
7301
|
+
for (const arg of node.arguments) {
|
|
7302
|
+
rawArgs.push(await this.evaluateAsync(arg, env));
|
|
7303
|
+
}
|
|
7304
|
+
const args = this.flattenSpreadArgs(rawArgs);
|
|
7305
|
+
|
|
7306
|
+
if (typeof callee === 'function') {
|
|
7307
|
+
const value = thisContext !== undefined
|
|
7308
|
+
? callee.call(thisContext, ...args)
|
|
7309
|
+
: callee(...args);
|
|
7310
|
+
return { value };
|
|
7311
|
+
} else if (callee && callee.__isFunction) {
|
|
7312
|
+
return { value: this.callUserFunction(callee, args, env, thisContext) };
|
|
7313
|
+
}
|
|
7314
|
+
|
|
7315
|
+
if (objectName && methodName) {
|
|
7316
|
+
throw createMethodNotFoundError(objectName, methodName, thisContext);
|
|
7317
|
+
}
|
|
7318
|
+
|
|
7319
|
+
throw new TypeError(`${node.callee.name || 'Expression'} is not a function`);
|
|
7320
|
+
}
|
|
7321
|
+
|
|
7207
7322
|
// Async evaluation for async functions - handles await expressions
|
|
7208
7323
|
async evaluateAsync(node, env) {
|
|
7209
7324
|
if (!node) return undefined;
|
|
@@ -7242,7 +7357,7 @@ class Interpreter {
|
|
|
7242
7357
|
if (node.type === 'VariableDeclaration') {
|
|
7243
7358
|
for (const declarator of node.declarations) {
|
|
7244
7359
|
const value = declarator.init
|
|
7245
|
-
? await this.
|
|
7360
|
+
? (await this.evaluateAsyncRawValue(declarator.init, env)).value
|
|
7246
7361
|
: undefined;
|
|
7247
7362
|
|
|
7248
7363
|
const isConst = node.kind === 'const';
|
|
@@ -7299,54 +7414,8 @@ class Interpreter {
|
|
|
7299
7414
|
|
|
7300
7415
|
// For call expressions (might be calling async functions)
|
|
7301
7416
|
if (node.type === 'CallExpression') {
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
let objectName = null;
|
|
7305
|
-
let methodName = null;
|
|
7306
|
-
|
|
7307
|
-
if (node.callee.type === 'MemberExpression') {
|
|
7308
|
-
thisContext = await this.evaluateAsync(node.callee.object, env);
|
|
7309
|
-
if (node.callee.optional && (thisContext === null || thisContext === undefined)) {
|
|
7310
|
-
return undefined;
|
|
7311
|
-
}
|
|
7312
|
-
const prop = node.callee.computed
|
|
7313
|
-
? await this.evaluateAsync(node.callee.property, env)
|
|
7314
|
-
: node.callee.property.name;
|
|
7315
|
-
callee = thisContext[prop];
|
|
7316
|
-
|
|
7317
|
-
// Capture names for enhanced error messages
|
|
7318
|
-
methodName = prop;
|
|
7319
|
-
objectName = this.getExpressionName(node.callee.object);
|
|
7320
|
-
} else {
|
|
7321
|
-
callee = await this.evaluateAsync(node.callee, env);
|
|
7322
|
-
}
|
|
7323
|
-
|
|
7324
|
-
// Handle optional call - if optional and callee is null/undefined, return undefined
|
|
7325
|
-
if (node.optional && (callee === null || callee === undefined)) {
|
|
7326
|
-
return undefined;
|
|
7327
|
-
}
|
|
7328
|
-
|
|
7329
|
-
const rawArgs = [];
|
|
7330
|
-
for (const arg of node.arguments) {
|
|
7331
|
-
rawArgs.push(await this.evaluateAsync(arg, env));
|
|
7332
|
-
}
|
|
7333
|
-
const args = this.flattenSpreadArgs(rawArgs);
|
|
7334
|
-
|
|
7335
|
-
if (typeof callee === 'function') {
|
|
7336
|
-
if (thisContext !== undefined) {
|
|
7337
|
-
return await callee.call(thisContext, ...args);
|
|
7338
|
-
}
|
|
7339
|
-
return await callee(...args);
|
|
7340
|
-
} else if (callee && callee.__isFunction) {
|
|
7341
|
-
return await this.callUserFunction(callee, args, env, thisContext);
|
|
7342
|
-
}
|
|
7343
|
-
|
|
7344
|
-
// Throw enhanced error for member expression calls
|
|
7345
|
-
if (objectName && methodName) {
|
|
7346
|
-
throw createMethodNotFoundError(objectName, methodName, thisContext);
|
|
7347
|
-
}
|
|
7348
|
-
|
|
7349
|
-
throw new TypeError(`${node.callee.name || 'Expression'} is not a function`);
|
|
7417
|
+
const result = (await this.evaluateCallExpressionAsyncRawValue(node, env)).value;
|
|
7418
|
+
return await result;
|
|
7350
7419
|
}
|
|
7351
7420
|
|
|
7352
7421
|
// For chain expressions (optional chaining)
|
|
@@ -7356,7 +7425,7 @@ class Interpreter {
|
|
|
7356
7425
|
|
|
7357
7426
|
// For member expressions in async context
|
|
7358
7427
|
if (node.type === 'MemberExpression') {
|
|
7359
|
-
const obj = await this.
|
|
7428
|
+
const obj = (await this.evaluateAsyncRawValue(node.object, env)).value;
|
|
7360
7429
|
|
|
7361
7430
|
// Handle optional chaining
|
|
7362
7431
|
if (node.optional && (obj === null || obj === undefined)) {
|
|
@@ -7678,7 +7747,7 @@ class Interpreter {
|
|
|
7678
7747
|
|
|
7679
7748
|
// For AssignmentExpression with async value
|
|
7680
7749
|
if (node.type === 'AssignmentExpression') {
|
|
7681
|
-
const value = await this.
|
|
7750
|
+
const value = (await this.evaluateAsyncRawValue(node.right, env)).value;
|
|
7682
7751
|
|
|
7683
7752
|
if (node.left.type === 'Identifier') {
|
|
7684
7753
|
const name = node.left.name;
|
package/dist/index.js
CHANGED
|
@@ -6473,6 +6473,91 @@ var Interpreter = class _Interpreter {
|
|
|
6473
6473
|
return null;
|
|
6474
6474
|
}
|
|
6475
6475
|
}
|
|
6476
|
+
async evaluateAsyncRawValue(node, env) {
|
|
6477
|
+
if (!node) return { value: void 0 };
|
|
6478
|
+
if (node.type === "CallExpression") {
|
|
6479
|
+
return await this.evaluateCallExpressionAsyncRawValue(node, env);
|
|
6480
|
+
}
|
|
6481
|
+
if (node.type === "MemberExpression") {
|
|
6482
|
+
const obj = (await this.evaluateAsyncRawValue(node.object, env)).value;
|
|
6483
|
+
if (node.optional && (obj === null || obj === void 0)) {
|
|
6484
|
+
return { value: void 0 };
|
|
6485
|
+
}
|
|
6486
|
+
if (obj === null || obj === void 0) {
|
|
6487
|
+
throw new TypeError(`Cannot read property of ${obj}`);
|
|
6488
|
+
}
|
|
6489
|
+
const prop = node.computed ? await this.evaluateAsync(node.property, env) : node.property.name;
|
|
6490
|
+
return { value: obj[prop] };
|
|
6491
|
+
}
|
|
6492
|
+
if (node.type === "ChainExpression") {
|
|
6493
|
+
return await this.evaluateAsyncRawValue(node.expression, env);
|
|
6494
|
+
}
|
|
6495
|
+
if (node.type === "ConditionalExpression") {
|
|
6496
|
+
const test = await this.evaluateAsync(node.test, env);
|
|
6497
|
+
return await this.evaluateAsyncRawValue(test ? node.consequent : node.alternate, env);
|
|
6498
|
+
}
|
|
6499
|
+
if (node.type === "LogicalExpression") {
|
|
6500
|
+
const left = await this.evaluateAsync(node.left, env);
|
|
6501
|
+
if (node.operator === "&&") {
|
|
6502
|
+
return left ? await this.evaluateAsyncRawValue(node.right, env) : { value: left };
|
|
6503
|
+
}
|
|
6504
|
+
if (node.operator === "||") {
|
|
6505
|
+
return left ? { value: left } : await this.evaluateAsyncRawValue(node.right, env);
|
|
6506
|
+
}
|
|
6507
|
+
if (node.operator === "??") {
|
|
6508
|
+
return left !== null && left !== void 0 ? { value: left } : await this.evaluateAsyncRawValue(node.right, env);
|
|
6509
|
+
}
|
|
6510
|
+
}
|
|
6511
|
+
if (node.type === "SequenceExpression") {
|
|
6512
|
+
for (let i = 0; i < node.expressions.length - 1; i++) {
|
|
6513
|
+
await this.evaluateAsync(node.expressions[i], env);
|
|
6514
|
+
}
|
|
6515
|
+
return await this.evaluateAsyncRawValue(node.expressions[node.expressions.length - 1], env);
|
|
6516
|
+
}
|
|
6517
|
+
if (node.type === "NewExpression") {
|
|
6518
|
+
return { value: this.evaluateNewExpression(node, env) };
|
|
6519
|
+
}
|
|
6520
|
+
if (["Literal", "Identifier", "ThisExpression", "Super"].includes(node.type)) {
|
|
6521
|
+
return { value: this.evaluate(node, env) };
|
|
6522
|
+
}
|
|
6523
|
+
return { value: await this.evaluateAsync(node, env) };
|
|
6524
|
+
}
|
|
6525
|
+
async evaluateCallExpressionAsyncRawValue(node, env) {
|
|
6526
|
+
let thisContext = void 0;
|
|
6527
|
+
let callee;
|
|
6528
|
+
let objectName = null;
|
|
6529
|
+
let methodName = null;
|
|
6530
|
+
if (node.callee.type === "MemberExpression") {
|
|
6531
|
+
thisContext = (await this.evaluateAsyncRawValue(node.callee.object, env)).value;
|
|
6532
|
+
if (node.callee.optional && (thisContext === null || thisContext === void 0)) {
|
|
6533
|
+
return { value: void 0 };
|
|
6534
|
+
}
|
|
6535
|
+
const prop = node.callee.computed ? await this.evaluateAsync(node.callee.property, env) : node.callee.property.name;
|
|
6536
|
+
callee = thisContext[prop];
|
|
6537
|
+
methodName = prop;
|
|
6538
|
+
objectName = this.getExpressionName(node.callee.object);
|
|
6539
|
+
} else {
|
|
6540
|
+
callee = await this.evaluateAsync(node.callee, env);
|
|
6541
|
+
}
|
|
6542
|
+
if (node.optional && (callee === null || callee === void 0)) {
|
|
6543
|
+
return { value: void 0 };
|
|
6544
|
+
}
|
|
6545
|
+
const rawArgs = [];
|
|
6546
|
+
for (const arg of node.arguments) {
|
|
6547
|
+
rawArgs.push(await this.evaluateAsync(arg, env));
|
|
6548
|
+
}
|
|
6549
|
+
const args = this.flattenSpreadArgs(rawArgs);
|
|
6550
|
+
if (typeof callee === "function") {
|
|
6551
|
+
const value = thisContext !== void 0 ? callee.call(thisContext, ...args) : callee(...args);
|
|
6552
|
+
return { value };
|
|
6553
|
+
} else if (callee && callee.__isFunction) {
|
|
6554
|
+
return { value: this.callUserFunction(callee, args, env, thisContext) };
|
|
6555
|
+
}
|
|
6556
|
+
if (objectName && methodName) {
|
|
6557
|
+
throw createMethodNotFoundError(objectName, methodName, thisContext);
|
|
6558
|
+
}
|
|
6559
|
+
throw new TypeError(`${node.callee.name || "Expression"} is not a function`);
|
|
6560
|
+
}
|
|
6476
6561
|
// Async evaluation for async functions - handles await expressions
|
|
6477
6562
|
async evaluateAsync(node, env) {
|
|
6478
6563
|
if (!node) return void 0;
|
|
@@ -6498,7 +6583,7 @@ var Interpreter = class _Interpreter {
|
|
|
6498
6583
|
}
|
|
6499
6584
|
if (node.type === "VariableDeclaration") {
|
|
6500
6585
|
for (const declarator of node.declarations) {
|
|
6501
|
-
const value = declarator.init ? await this.
|
|
6586
|
+
const value = declarator.init ? (await this.evaluateAsyncRawValue(declarator.init, env)).value : void 0;
|
|
6502
6587
|
const isConst = node.kind === "const";
|
|
6503
6588
|
if (declarator.id.type === "Identifier") {
|
|
6504
6589
|
env.define(declarator.id.name, value, isConst);
|
|
@@ -6539,48 +6624,14 @@ var Interpreter = class _Interpreter {
|
|
|
6539
6624
|
return this.evaluateBinaryExpressionValues(node.operator, left, right);
|
|
6540
6625
|
}
|
|
6541
6626
|
if (node.type === "CallExpression") {
|
|
6542
|
-
|
|
6543
|
-
|
|
6544
|
-
let objectName = null;
|
|
6545
|
-
let methodName = null;
|
|
6546
|
-
if (node.callee.type === "MemberExpression") {
|
|
6547
|
-
thisContext = await this.evaluateAsync(node.callee.object, env);
|
|
6548
|
-
if (node.callee.optional && (thisContext === null || thisContext === void 0)) {
|
|
6549
|
-
return void 0;
|
|
6550
|
-
}
|
|
6551
|
-
const prop = node.callee.computed ? await this.evaluateAsync(node.callee.property, env) : node.callee.property.name;
|
|
6552
|
-
callee = thisContext[prop];
|
|
6553
|
-
methodName = prop;
|
|
6554
|
-
objectName = this.getExpressionName(node.callee.object);
|
|
6555
|
-
} else {
|
|
6556
|
-
callee = await this.evaluateAsync(node.callee, env);
|
|
6557
|
-
}
|
|
6558
|
-
if (node.optional && (callee === null || callee === void 0)) {
|
|
6559
|
-
return void 0;
|
|
6560
|
-
}
|
|
6561
|
-
const rawArgs = [];
|
|
6562
|
-
for (const arg of node.arguments) {
|
|
6563
|
-
rawArgs.push(await this.evaluateAsync(arg, env));
|
|
6564
|
-
}
|
|
6565
|
-
const args = this.flattenSpreadArgs(rawArgs);
|
|
6566
|
-
if (typeof callee === "function") {
|
|
6567
|
-
if (thisContext !== void 0) {
|
|
6568
|
-
return await callee.call(thisContext, ...args);
|
|
6569
|
-
}
|
|
6570
|
-
return await callee(...args);
|
|
6571
|
-
} else if (callee && callee.__isFunction) {
|
|
6572
|
-
return await this.callUserFunction(callee, args, env, thisContext);
|
|
6573
|
-
}
|
|
6574
|
-
if (objectName && methodName) {
|
|
6575
|
-
throw createMethodNotFoundError(objectName, methodName, thisContext);
|
|
6576
|
-
}
|
|
6577
|
-
throw new TypeError(`${node.callee.name || "Expression"} is not a function`);
|
|
6627
|
+
const result = (await this.evaluateCallExpressionAsyncRawValue(node, env)).value;
|
|
6628
|
+
return await result;
|
|
6578
6629
|
}
|
|
6579
6630
|
if (node.type === "ChainExpression") {
|
|
6580
6631
|
return await this.evaluateAsync(node.expression, env);
|
|
6581
6632
|
}
|
|
6582
6633
|
if (node.type === "MemberExpression") {
|
|
6583
|
-
const obj = await this.
|
|
6634
|
+
const obj = (await this.evaluateAsyncRawValue(node.object, env)).value;
|
|
6584
6635
|
if (node.optional && (obj === null || obj === void 0)) {
|
|
6585
6636
|
return void 0;
|
|
6586
6637
|
}
|
|
@@ -6838,7 +6889,7 @@ var Interpreter = class _Interpreter {
|
|
|
6838
6889
|
return test ? await this.evaluateAsync(node.consequent, env) : await this.evaluateAsync(node.alternate, env);
|
|
6839
6890
|
}
|
|
6840
6891
|
if (node.type === "AssignmentExpression") {
|
|
6841
|
-
const value = await this.
|
|
6892
|
+
const value = (await this.evaluateAsyncRawValue(node.right, env)).value;
|
|
6842
6893
|
if (node.left.type === "Identifier") {
|
|
6843
6894
|
const name = node.left.name;
|
|
6844
6895
|
if (node.operator === "=") {
|