diff --git a/lib/loader/loader.js b/lib/loader/loader.js index 549a4201..7beef31a 100644 --- a/lib/loader/loader.js +++ b/lib/loader/loader.js @@ -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() { @@ -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); @@ -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: {}}; }; @@ -148,6 +151,7 @@ var loader, define, requireModule, require, requirejs; stats.findDeps++; this._foundDeps = true; + this.isPending = true; var deps = this.deps; @@ -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++; diff --git a/tests/all.js b/tests/all.js index e72e06c1..8a82875e 100644 --- a/tests/all.js +++ b/tests/all.js @@ -437,7 +437,7 @@ test('runtime cycles', function() { require: 2, resolve: 2, resolveRelative: 0, - pendingQueueLength: 3 + pendingQueueLength: 2 }); ok(foo.quz()); @@ -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'); @@ -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 = {