-
Notifications
You must be signed in to change notification settings - Fork 1
/
idgrep.js
37 lines (31 loc) · 957 Bytes
/
idgrep.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Generated by CoffeeScript 1.4.0
(function() {
var esprima, estraverse, idgrep, parseOptions;
esprima = require('esprima');
estraverse = require('estraverse');
idgrep = function(pattern, code, filename) {
var ast, lines;
lines = code.split('\n');
ast = esprima.parse(code, parseOptions);
estraverse.traverse(ast, {
enter: function(node, parent) {
var line, loc;
if (node.type === 'Identifier' && node.name.indexOf(pattern) >= 0) {
loc = node.loc.start;
line = loc.line - 1;
console.log("" + line + ":" + loc.column + ": " + lines[line]);
}
}
});
};
parseOptions = {
loc: true,
range: true
};
idgrep('hack', `
// This is a hack!
function hacky_function() {
var hack = 3;
return 'hacky string';
}`);
}).call(this);