ctags-patterns-for-javascript icon indicating copy to clipboard operation
ctags-patterns-for-javascript copied to clipboard

module.exports is not matched

Open ghost opened this issue 7 years ago • 5 comments

The following function is not matched:

module.exports = function sum (a, b) {
  return a + b
}

I've done a rule to match that case as a function, but don't know if you didn't want to support on purpose since this is also the case for export default function name1(…) { … } as you pointed out on issue https://github.com/romainl/ctags-patterns-for-javascript/issues/7. Wouldn't make sense to create an default export tag type and put them together on that new tag type? What do you think? (We could try to create a rule only for default named exports with body definition once the ones that doesn't have definition would be already taken by another rules)

ghost avatar Jun 27 '18 22:06 ghost

This could be an extension of the function rules, I think. Something like:

--regex-javascript=/^[ \t]*module\.exports[ \t]*=[ \t]*function[ \t]\{1,\}\([a-z][A-Za-z0-9_$]\{1,\}\)/\1/F,Function,Functions/b

romainl avatar Jun 28 '18 06:06 romainl

nice! I think this could work. Any plans to update the master branch?

ghost avatar Jul 02 '18 11:07 ghost

I don't think I'll be able to do it in the short term. Could you give it a try on your side?

romainl avatar Jul 02 '18 13:07 romainl

So I added the following to the bottom of my ~/.ctags file as @romainl recommended, right after the options file import, so my ~/.ctags looks like:

➜ cat ~/.ctags
--exclude=.git
--exclude=.hg
--exclude=log
--exclude=tmp
--exclude=node_modules
--exclude=gulp
--options=/Users/maj/src/dotfiles/ctags-patterns-for-javascript/ctagsrc
--regex-javascript=/^[ \t]*module\.exports[ \t]*=[ \t]*function[ \t]\{1,\}\([a-z][A-Za-z0-9_$]\{1,\}\)/\1/F,Function,Functions/b

... and can confirm it works well! This was the one thing missing for me to have full tag support, as far as I can tell, for JS in my vim. Thanks! I'll send a PR to add to the file in case that's helpful.

filmaj avatar Apr 21 '19 18:04 filmaj

Thanks for this - tossing in another possible scenario for the module.exports:

exports = module.exports = /*<function or object>*/;

LMK if there's anything I can do

cilindrox avatar May 08 '20 12:05 cilindrox