starlight-cli 1.0.31 → 1.0.33
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/index.js +26 -7
- package/package.json +1 -1
- package/src/evaluator.js +26 -7
package/dist/index.js
CHANGED
|
@@ -1497,14 +1497,33 @@ async evaluate(node, env = this.global) {
|
|
|
1497
1497
|
return val;
|
|
1498
1498
|
}
|
|
1499
1499
|
case 'NewExpression': {
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1500
|
+
const callee = await this.evaluate(node.callee, env);
|
|
1501
|
+
|
|
1502
|
+
if (typeof callee === 'object' && callee.body) {
|
|
1503
|
+
const evaluator = this; // <- capture the current evaluator
|
|
1504
|
+
const Constructor = function(...args) {
|
|
1505
|
+
const newEnv = new Environment(callee.env);
|
|
1506
|
+
newEnv.define('this', this);
|
|
1507
|
+
for (let i = 0; i < callee.params.length; i++) {
|
|
1508
|
+
newEnv.define(callee.params[i], args[i]);
|
|
1503
1509
|
}
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1510
|
+
return evaluator.evaluate(callee.body, newEnv); // use captured evaluator
|
|
1511
|
+
};
|
|
1512
|
+
|
|
1513
|
+
const args = [];
|
|
1514
|
+
for (const a of node.arguments) args.push(await this.evaluate(a, env));
|
|
1515
|
+
return new Constructor(...args);
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
if (typeof callee !== 'function') {
|
|
1519
|
+
throw new Error('NewExpression callee is not a function');
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
const args = [];
|
|
1523
|
+
for (const a of node.arguments) args.push(await this.evaluate(a, env));
|
|
1524
|
+
return new callee(...args);
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1508
1527
|
default:
|
|
1509
1528
|
throw new Error(`Unknown node type in evaluator: ${node.type}`);
|
|
1510
1529
|
}
|
package/package.json
CHANGED
package/src/evaluator.js
CHANGED
|
@@ -154,14 +154,33 @@ async evaluate(node, env = this.global) {
|
|
|
154
154
|
return val;
|
|
155
155
|
}
|
|
156
156
|
case 'NewExpression': {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
const callee = await this.evaluate(node.callee, env);
|
|
158
|
+
|
|
159
|
+
if (typeof callee === 'object' && callee.body) {
|
|
160
|
+
const evaluator = this; // <- capture the current evaluator
|
|
161
|
+
const Constructor = function(...args) {
|
|
162
|
+
const newEnv = new Environment(callee.env);
|
|
163
|
+
newEnv.define('this', this);
|
|
164
|
+
for (let i = 0; i < callee.params.length; i++) {
|
|
165
|
+
newEnv.define(callee.params[i], args[i]);
|
|
160
166
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
167
|
+
return evaluator.evaluate(callee.body, newEnv); // use captured evaluator
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const args = [];
|
|
171
|
+
for (const a of node.arguments) args.push(await this.evaluate(a, env));
|
|
172
|
+
return new Constructor(...args);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (typeof callee !== 'function') {
|
|
176
|
+
throw new Error('NewExpression callee is not a function');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const args = [];
|
|
180
|
+
for (const a of node.arguments) args.push(await this.evaluate(a, env));
|
|
181
|
+
return new callee(...args);
|
|
182
|
+
}
|
|
183
|
+
|
|
165
184
|
default:
|
|
166
185
|
throw new Error(`Unknown node type in evaluator: ${node.type}`);
|
|
167
186
|
}
|