Inaccurate occurrences of "multiple modules being created" error
mattlavallee opened this issue · 4 comments
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
Debugging angular-hint-modules, I found that the first occurrence of a "duplicate module creation" is coming from this line
My entire call stack at this point is:
The second occurrence is happening from this line:
Again, a very simple call stack:
I believe that this is a bug and is registering a "Multiple modules with name are being create" message in error
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
@mattlavallee wow, nice debugging. Thanks for finding/reporting the bug and we'd love a PR!
Matt's PR #86 fixed this.