function-names-at-line
I was working on this run test by line number
feature for
teenytest, and needed a way to tell
what functions might be described by a given line number.
For example, say you have this file:
var foo = function () {
var baz = 'lol'
function bar () {}
}
And read the file into a string named someSource
, then you can:
var functionNamesAtLine = require('function-names-at-line')
functionNamesAtLine(someSource, 1)
functionNamesAtLine(someSource, 2)
functionNamesAtLine(someSource, 3)
functionNamesAtLine(someSource, 4)
functionNamesAtLine(someSource, 5)
functionNamesAtLine(someSource, 6)
This is a pretty naive implementation, focused just on getting basic (not nested)
names of functions.