Skip to content

Commit

Permalink
Merge pull request ember-cli#86 from kratiahuja/do-not-push-same-pend…
Browse files Browse the repository at this point in the history
…ing-modules

Do not put modules that are already in the pending queue
  • Loading branch information
stefanpenner committed Jun 22, 2016
2 parents afd4ab2 + e2b7724 commit 4f7be5f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/loader/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var loader, define, requireModule, require, requirejs;
this.isAlias = alias;
this.reified = new Array(deps.length);
this._foundDeps = false;
this.isPending = false;
}

Module.prototype.makeDefaultExport = function() {
Expand All @@ -110,6 +111,7 @@ var loader, define, requireModule, require, requirejs;
stats.exports++;

this.finalized = true;
this.isPending = false;

if (loader.wrapModules) {
this.callback = loader.wrapModules(this.name, this.callback);
Expand All @@ -129,6 +131,7 @@ var loader, define, requireModule, require, requirejs;
Module.prototype.unsee = function() {
this.finalized = false;
this._foundDeps = false;
this.isPending = false;
this.module = { exports: {}};
};

Expand All @@ -148,6 +151,7 @@ var loader, define, requireModule, require, requirejs;

stats.findDeps++;
this._foundDeps = true;
this.isPending = true;

var deps = this.deps;

Expand Down Expand Up @@ -224,7 +228,7 @@ var loader, define, requireModule, require, requirejs;

if (!mod) { missingModule(name, referrer); }

if (pending && !mod.finalized) {
if (pending && !mod.finalized && !mod.isPending) {
mod.findDeps(pending);
pending.push(mod);
stats.pendingQueueLength++;
Expand Down
34 changes: 31 additions & 3 deletions tests/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ test('runtime cycles', function() {
require: 2,
resolve: 2,
resolveRelative: 0,
pendingQueueLength: 3
pendingQueueLength: 2
});

ok(foo.quz());
Expand Down Expand Up @@ -471,7 +471,7 @@ test('already evaluated modules are not pushed into the queue', function() {
require: 1,
resolve: 2,
resolveRelative: 0,
pendingQueueLength: 3
pendingQueueLength: 2
});

var foo = require('foo');
Expand All @@ -485,10 +485,38 @@ test('already evaluated modules are not pushed into the queue', function() {
require: 2,
resolve: 2,
resolveRelative: 0,
pendingQueueLength: 3
pendingQueueLength: 2
});
});

test('same pending modules should not be pushed to the queue more than once', function() {
define('foo', ['bar', 'exports'], function(bar, __exports__) {
__exports__.quz = function() {
return bar.baz;
};
});

define('bar', ['foo', 'exports'], function(foo, __exports__) {
__exports__.baz = function() {
return foo.quz;
};
});

var bar = require('bar');
deepEqual(require._stats, {
findDeps: 2,
define: 2,
exports: 2,
findModule: 3,
modules: 2,
reify: 2,
require: 1,
resolve: 2,
resolveRelative: 0,
pendingQueueLength: 2
});
})

test('basic CJS mode', function() {
define('a/foo', ['require', 'exports', 'module'], function(require, exports, module) {
module.exports = {
Expand Down

0 comments on commit 4f7be5f

Please sign in to comment.