Skip to content

Commit

Permalink
Merge pull request #133 from tmquinn/find-alias-modules-with-index
Browse files Browse the repository at this point in the history
Find aliases whose target is at index
  • Loading branch information
stefanpenner committed Jan 25, 2018
2 parents 933c7c8 + ffacdb4 commit d5fb086
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/loader/loader.js
Expand Up @@ -286,7 +286,7 @@ var loader, define, requireModule, require, requirejs;
var mod = registry[id] || registry[id + '/index'];

while (mod && mod.isAlias) {
mod = registry[mod.id];
mod = registry[mod.id] || registry[mod.id + '/index'];
}

if (!mod) { missingModule(id, referrer); }
Expand Down
66 changes: 66 additions & 0 deletions tests/all.js
Expand Up @@ -1374,6 +1374,35 @@ test('alias chain (simple)', function() {
});
});

test('alias chain (simple) with implicit /index', function() {
define('bar/index', [], function() {
return 'I AM BAR';
});

define('quz', define.alias('foo'));
define('foo', define.alias('bar'));

equal(require('quz'), 'I AM BAR');
throws(function() {
require('quz/index');
}, 'Could not find module `quz/index` imported from `(require)`');

var stats = statsForMonitor('loaderjs', tree);

deepEqual(stats, {
findDeps: 1,
define: 3,
exports: 1,
findModule: 1,
modules: 3,
reify: 1,
require: 1,
resolve: 0,
resolveRelative: 0,
pendingQueueLength: 1
});
});

test('alias chain (long)', function() {
define('bar', [], function() {
return 'I AM BAR';
Expand Down Expand Up @@ -1477,6 +1506,43 @@ test('alias chains propogate unsee', function() {
});
});

test('alias chains propogate unsee with implicit /index', function() {
var counter = 0;

define('bar/index', [], function() {
counter++;
return 'I AM BAR';
});

define('a', define.alias('bar'));
define('b', define.alias('a'));

equal(counter, 0);
equal(require('b'), 'I AM BAR');
equal(counter, 1);
equal(require('b'), 'I AM BAR');
equal(counter, 1);
require.unsee('b');
equal(counter, 1);
equal(require('b'), 'I AM BAR');
equal(counter, 2);

var stats = statsForMonitor('loaderjs', tree);

deepEqual(stats, {
findDeps: 2,
define: 3,
exports: 2,
findModule: 4,
modules: 3,
reify: 2,
require: 3,
resolve: 0,
resolveRelative: 0,
pendingQueueLength: 2
});
});

test('alias chaining with relative deps works', function() {
define('foo/baz', [], function() {
return 'I AM baz';
Expand Down

0 comments on commit d5fb086

Please sign in to comment.