angular / angular-hint

run-time hinting for AngularJS applications
362 stars 45 forks source link

Inaccurate occurrences of "multiple modules being created" error #67

Closed mattlavallee closed 9 years ago

mattlavallee commented 9 years ago

When including angular-hint in my project, it logs that several of my modules are being created multiple times. Searching the code base (fairly small at this point) for the module name, there is only one instance of using angular.module() with the setter parameter. Setting a breakpoint on my webpage, this line is also only hit once.

I'm attempting to figure out why angular-hint thinks it's being created more than once.

Any suggestions you can offer would be very helpful

mattlavallee commented 9 years ago

Debugging angular-hint-modules, I found that the first occurrence of a "duplicate module creation" is coming from this line image

My entire call stack at this point is: image

The second occurrence is happening from this line: image

Again, a very simple call stack: image

I believe that this is a bug and is registering a "Multiple modules with name are being create" message in error

mattlavallee commented 9 years ago

Upon further debugging, it looks like the problem can be solved with 2 lines in angular-hint-modules by checking the arguments for more than one parameter (indicating it's a module setter rather than a getter)

angular.module = function(name, requiresOriginal) {
  var module = originalAngularModule.apply(this, arguments),
      name = module.name;

  module.requiresOriginal = requiresOriginal;
  modules[name] = module;
  hasNameSpace(module);
  var modToCheck = getModule(name, true);
  var modlIsSetter = arguments.length > 1; //check arguments to determine if angular.module() is called as a setter or a getter

  if(modToCheck && modToCheck.requiresOriginal !== module.requiresOriginal && modIsSetter) { //add new modIsSetter boolean to the conditional
    if(!modData.createdMulti[name]) {
      modData.createdMulti[name] = [getModule(name,true)];
    }
    modData.createdMulti[name].push(module);
  }
  modData.createdModules[name] = module;
  return module;
};

Please let me know if you would like me to submit this as a pull request

SomeKittens commented 9 years ago

@mattlavallee wow, nice debugging. Thanks for finding/reporting the bug and we'd love a PR!

SomeKittens commented 9 years ago

Matt's PR https://github.com/angular/angular-hint/pull/86 fixed this.