Unused local var -- misidentified? (phpstorm 9.0.2, JS file)

I'm not a JS expert by any means, but the js files in my project share a common structure. It's something like this:

var ModuleName = function () {

  return {init: init};

  // other code

  function init() {
  };

}();

$(function () {
  ModuleName.init();
});

I think this is called the "module pattern" or IIFE. Anyway, the PHPStorm tokenizer/editor seems fine with this layout while writing a new file, but loading a file in this format results in "ModuleName" (in the var decl) being flagged as unused (i.e. it's grey in my scheme and has a note in the right margin). Interestingly, the invocation of ModuleName.init() is not flagged at all.

Is this a coding error on my part? Am I doing something wrong that's throwing off the tokenizer?

Thanks,
Dave

4 comments
Comment actions Permalink

Works fine for me using provided example:

unused.png
Please try invalidating caches - does the problem persist? If yes, try creating a sample project that shows it up

0
Comment actions Permalink

Yes, the simple case like that works for me as well, but I have a lot more code in there. I wonder if there might be some construct within the JS that confuses it. I'll have to try to remove things until I can't get it to reproduce any more. The problem is that it's often fine during editing - and requires some set of circumstances to trigger the condition I reported, which I'm not 100% sure of yet. Typically, when I notice it, I've opened the file and switched to it, but haven't been editing it. But once it's wrong, only forcing it to reparse (i.e. changing the var name, then scrolling around) will get it to correct itself again.

Anyway, I'll see if I can narrow it down. I was sorta hoping someone else might have seen it before.

0
Comment actions Permalink

only forcing it to reparse (i.e. changing the var name, then scrolling around) will get it to correct itself again.

such problems usually indicate broken indexes. Did you try invalidating caches?

0
Comment actions Permalink

I just tried that and it seemed to load that file fine now!

Thank you!

0

Please sign in to leave a comment.