agsamantha/node_modules/jintr/dist/nodes/FunctionExpression.js

23 lines
769 B
JavaScript
Raw Normal View History

2024-10-02 15:15:21 -05:00
import { namedFunction } from '../utils/index.js';
import BaseJSNode from './BaseJSNode.js';
export default class FunctionExpression extends BaseJSNode {
run() {
const { params, body } = this.node;
const fn = namedFunction('anonymous function', (args) => {
let index = 0;
for (const param of params) {
this.visitor.visitNode(param);
if (param.type === 'Identifier') {
this.visitor.scope.set(param.name, args[index]);
}
else {
console.warn('Unhandled param type', param.type);
}
index++;
}
return this.visitor.visitNode(body);
});
return fn;
}
}