How can I detect all dependencies of a function in Node.js?

前端 未结 4 919
你的背包
你的背包 2021-02-01 07:19

I\'m trying to give a broad picture of my problem. I need to write a program with Node.js that should be able to detect all dependencies a function.

E.g.



        
4条回答
  •  逝去的感伤
    2021-02-01 07:37

    1. Get code of a function as a string: a.toString()
    2. Check with RegEx for possible function calls like possiblefuncname( and possiblefuncname.call( and possiblefuncname.apply(
    3. Check if `typeof possiblefuncname == 'function'
    4. IF 3 is TRUE, Recursively check possiblefuncname for dependencies
    5. Set your dependency.

提交回复
热议问题