0

Is there a way to find all the places across a project where a particular function is invoked? In particular, taking into account any times that the file is imported.

For example, if we're looking for where library.js's function foobar() is used, this example in another file would be included:

var library = require('./myfile.js')
library.foobar()

(The reason simply searching for foobar across all files won't work is if the function is a common name used in multiple modules.)

This would be the opposite of something like Webstorm's Jump to Definition feature.

One of the use-cases is to help refactor a legacy codebase where it's unclear where certain exported functions are being used, or if they're being used at all.

I saw similar questions like this one, but these seem to be for client-side javascript and don't take exports into account.

Community
  • 1
  • 1
David
  • 540
  • 4
  • 14

2 Answers2

0

Sometime I use callsite module in the function I want to check for log the absolute link to file use this function.

David
  • 540
  • 4
  • 14
trquoccuong
  • 2,857
  • 2
  • 20
  • 26
0

You can add console.trace(); inside your function and you will know where does it called.

Ezzat
  • 931
  • 6
  • 13
  • Thank you for the suggestion, but this doesn't exactly work in this case because the function might not be called at all. I'm looking for a static analyzer, instead of needing to execute over the whole codebase at runtime. – David Sep 01 '15 at 16:45