starlight-cli 1.0.32 → 1.0.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/evaluator.js CHANGED
@@ -157,19 +157,18 @@ async evaluate(node, env = this.global) {
157
157
  const callee = await this.evaluate(node.callee, env);
158
158
 
159
159
  if (typeof callee === 'object' && callee.body) {
160
- // This is a Starlight "func" object wrap it in JS function
160
+ const evaluator = this; // <- capture the current evaluator
161
161
  const Constructor = function(...args) {
162
162
  const newEnv = new Environment(callee.env);
163
- newEnv.define('this', this); // bind 'this' for the constructor
163
+ newEnv.define('this', this);
164
164
  for (let i = 0; i < callee.params.length; i++) {
165
165
  newEnv.define(callee.params[i], args[i]);
166
166
  }
167
- return this.evaluate(callee.body, newEnv);
168
- }.bind(this);
167
+ return evaluator.evaluate(callee.body, newEnv); // use captured evaluator
168
+ };
169
169
 
170
170
  const args = [];
171
171
  for (const a of node.arguments) args.push(await this.evaluate(a, env));
172
-
173
172
  return new Constructor(...args);
174
173
  }
175
174