Skip to content

Commit

Permalink
Fix handling of mixins for modules with no dependencies defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Krzeszowiak committed Apr 10, 2020
1 parent 87b7cba commit 97f0a1f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
26 changes: 26 additions & 0 deletions dev/tests/js/jasmine/tests/lib/mage/requirejs/mixins.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,31 @@ define(['rjsResolver', 'mixins'], function (resolver, mixins) {

require([name], function () {});
});

it('applies mixins for modules that have no dependencies', function (done) {
var name = 'tests/assets/mixins/mixins-applied-no-dependencies',
mixinName = 'tests/assets/mixins/mixins-applied-no-dependencies-ext';

mixins.hasMixins.and.returnValue(true);
mixins.getMixins.and.returnValue([mixinName]);

define(name, {
value: 'original'
});

define(mixinName, [], function () {
return function (module) {
module.value = 'changed';

return module;
};
});

require([name], function (module) {
expect(module.value).toBe('changed');

done();
});
});
});
});
7 changes: 5 additions & 2 deletions lib/web/mage/requirejs/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,12 @@ require([
* from it every time require call happens.
*/
defContext.defQueue.shift = function () {
var queueItem = Array.prototype.shift.call(this);
var queueItem = Array.prototype.shift.call(this),
lastDeps = queueItem && queueItem[1];

queueItem[1] = processNames(queueItem[1], defContext);
if (Array.isArray(lastDeps)) {
queueItem[1] = processNames(queueItem[1], defContext);
}

return queueItem;
};
Expand Down

0 comments on commit 97f0a1f

Please sign in to comment.