You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
920 B
JavaScript

'use strict';
const createAstWalker = require("./walker");
let processors = [
require("./processors/add-parent"),
require("./processors/mark-scopes"),
require("./processors/add-variable-declarator-kind"),
require("./processors/utility-methods"),
];
module.exports = function processAst(ast) {
let initializedProcessors = processors.map((processor) => {
return processor();
});
let walker = createAstWalker(ast);
let finishedWalking = false;
walker.on("enterNode", function processNode(node) {
for (let processor of initializedProcessors) {
if (processor.onEnter != null) {
processor.onEnter(node);
}
}
});
walker.on("exitNode", function processNode(node) {
for (let processor of initializedProcessors) {
if (processor.onExit != null) {
processor.onExit(node);
}
}
});
while (finishedWalking === false) {
walker.step();
finishedWalking = walker.done;
}
return;
};