Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 478650c

Browse files
author
robertmirro
committed
fix(loader): module.decorator order of operations irrelevant
module.decorator() is now processed via the configBlocks order of operations and: - no longer throws if declared before the provider being decorated - guarantees the correct provider will be decorated when multiple, same-name providers are defined Closes: #12382
1 parent 1964620 commit 478650c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/loader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function setupModuleLoader(window) {
203203
* @description
204204
* See {@link auto.$provide#decorator $provide.decorator()}.
205205
*/
206-
decorator: invokeLaterAndSetModuleName('$provide', 'decorator'),
206+
decorator: invokeLaterAndSetModuleName('$provide', 'decorator', configBlocks),
207207

208208
/**
209209
* @ngdoc method
@@ -349,10 +349,11 @@ function setupModuleLoader(window) {
349349
* @param {string} method
350350
* @returns {angular.Module}
351351
*/
352-
function invokeLaterAndSetModuleName(provider, method) {
352+
function invokeLaterAndSetModuleName(provider, method, queue) {
353+
if (!queue) queue = invokeQueue;
353354
return function(recipeName, factoryFunction) {
354355
if (factoryFunction && isFunction(factoryFunction)) factoryFunction.$$moduleName = name;
355-
invokeQueue.push([provider, method, arguments]);
356+
queue.push([provider, method, arguments]);
356357
return moduleInstance;
357358
};
358359
}

test/loaderSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ describe('module loader', function() {
4848
expect(myModule.requires).toEqual(['other']);
4949
expect(myModule._invokeQueue).toEqual([
5050
['$provide', 'constant', jasmine.objectContaining(['abc', 123])],
51-
['$provide', 'decorator', jasmine.objectContaining(['dk', 'dv'])],
5251
['$provide', 'provider', jasmine.objectContaining(['sk', 'sv'])],
5352
['$provide', 'factory', jasmine.objectContaining(['fk', 'fv'])],
5453
['$provide', 'service', jasmine.objectContaining(['a', 'aa'])],
@@ -60,6 +59,7 @@ describe('module loader', function() {
6059
]);
6160
expect(myModule._configBlocks).toEqual([
6261
['$injector', 'invoke', jasmine.objectContaining(['config'])],
62+
['$provide', 'decorator', jasmine.objectContaining(['dk', 'dv'])],
6363
['$injector', 'invoke', jasmine.objectContaining(['init2'])]
6464
]);
6565
expect(myModule._runBlocks).toEqual(['runBlock']);

0 commit comments

Comments
 (0)