我有香草js文件的行号,我需要找到特定行的源代码,然后是父函数。我使用node.js并想知道是否有方法来提取源代码,并可能知道该特定行的父功能。如何在javascript中查找特定行号的源代码?
function helloworld(){
var a=5;
var b=6; //line number 3
}
对于上述功能,我需要函数helloworld只有行号?
编辑更加清晰:
当代码被压入式回购,我们可以得到的行号,其中变化有occured.Using这些行号,我想在寻父的功能正如我所说的above.I想要找到父函数的名字,所以我只能运行特定的茉莉花测试文件。
例: 可以说我有一个茉莉花规范文件是这样的:
describe("helloworld",function(){
it("test1",function(){
expect(true).toBe(true)
});
});
describe("someotherfun",function(){
it("test2",function(){
expect(true).toBe(true)
})
})
说有这样一个脚本文件:
function helloworld(){ . //line 1
console.log('hi') . //line 2
}
function someotherfun(){
console.log('hi')
} . //line 6
比方说某一个编辑第2行,我想获取helloworld的名称,以便我稍后可以解析茉莉花spec文件,并将x添加到除改变的所有规格外。此示例将解释我的意思:
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)
})
})
现在我可以添加解析我的茉莉花文件并在描述之前添加x,但是我想知道的是被修改的特定行的父函数。
我不知道你在做什么,但这可能有帮助http://stackoverflow.com/a/280396/5515745 –
我想获得函数名,所以我可以使用它们在茉莉花中只运行特定的测试spec文件。我不想运行整个测试文件在源代码中的单行更改。我可以解析茉莉花文件并添加xdescribe并跳过我不想运行的规格。 –
你在问什么?如何解析脚本?有什么条件可以找到代码?这太模糊了。为清晰起见 –