I have line numbers for vanilla js files for which i need to find the source code at that particular line and subsequently the parent function.I am using node.js and was wondering if there was a way to extract the source code and possibly know the parent function of that particular line.
function helloworld(){
var a=5;
var b=6; //line number 3
}
For the above function i need the function helloworld from only having the line number?
Editing for more clarity:
When code is pushed into the repo we can get the line numbers where the changes have occured.Using these line numbers i want to the find the parent functions as i said above.I want to find the name of the parent function so i can run only the particular jasmine test file.
Example: Lets say i have a jasmine spec file like this:
describe("helloworld",function(){
it("test1",function(){
expect(true).toBe(true)
});
});
describe("someotherfun",function(){
it("test2",function(){
expect(true).toBe(true)
})
})
say there is a script file like this:
function helloworld(){ . //line 1
console.log('hi') . //line 2
}
function someotherfun(){
console.log('hi')
} . //line 6
Lets say some one edits line 2 i want to get the name of helloworld so i can later parse the jasmine spec file and add x to all the specs except the one that is changed.This example will explain what i mean:
describe("helloworld",function(){
it("test1",function(){
expect(true).toBe(true)
});
});
xdescribe("someotherfun",function(){ //wont run this test because this function was not modified
it("test2",function(){
expect(true).toBe(true)
})
})
Now i can add parse my jasmine files and add the x before describe but i what i want to know is the parent function for the particular line that was modified.