escomplex-coffee
Version:
Software complexity analysis for CoffeeScript projects. CoffeeScript-specific wrapper around escomplex.
58 lines (53 loc) • 1.71 kB
JavaScript
// Generated by CoffeeScript 1.9.0
(function() {
var syntaxDefinitions, util;
syntaxDefinitions = require("./syntax");
util = require("./util");
module.exports = {
walk: function(tree, settings, callbacks) {
var syntaxes, visitChildren, visitNode;
syntaxes = syntaxDefinitions(settings);
visitNode = function(node, assignedName) {
var lines, syntax;
if (Array.isArray(node)) {
return node.forEach(function(n) {
return visitNode(n, assignedName);
});
} else if (typeof node === "object" && node) {
syntax = syntaxes[util.getName(node)];
if (!syntax) {
return;
}
callbacks.processNode(node, syntax);
if (syntax.newScope) {
lines = {
start: {
line: node.locationData.first_line
},
end: {
line: node.locationData.last_line
}
};
callbacks.createScope(util.safeName(node, assignedName), lines, node.params.length);
}
visitChildren(syntax, node);
if (syntax.newScope) {
return callbacks.popScope();
}
}
};
visitChildren = function(syntax, node) {
var children;
children = syntax.children[0](node);
if (Array.isArray(children)) {
return children.forEach(function(child) {
var name;
name = typeof syntax.assignableName === 'function' ? syntax.assignableName(node) : null;
return visitNode(node[child], name);
});
}
};
return visitNode(tree);
}
};
}).call(this);