agsamantha/node_modules/jintr/dist/nodes/ForStatement.js
2024-10-02 15:15:21 -05:00

32 lines
931 B
JavaScript

import BaseJSNode from './BaseJSNode.js';
export default class ForStatement extends BaseJSNode {
run() {
if (this.node.init) {
this.visitor.visitNode(this.node.init);
}
const test = () => {
return this.node.test
? this.visitor.visitNode(this.node.test)
: true;
};
for (;;) {
const _test = test();
if (!_test) {
break;
}
const body = this.visitor.visitNode(this.node.body);
if (body === 'continue') {
continue;
}
if (body === 'break') {
break;
}
if (this.node.update) {
this.visitor.visitNode(this.node.update);
}
if (body && this.node.body.type !== 'ExpressionStatement') {
return body;
}
}
}
}