Skip to content

Commit 0bd73e5

Browse files
committed
Fixed client-side resolution of current and parent indexes
1 parent e1930c9 commit 0bd73e5

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

lib/webmake.tpl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
isDir = true;
1313
name = path.pop();
1414
}
15+
if ((name === '.') || (name === '..')) {
16+
path.push(name);
17+
name = '';
18+
}
1519
while ((dir = path.shift())) {
1620
if (dir === '..') {
1721
scope = tree.pop();
@@ -20,12 +24,16 @@
2024
scope = scope[dir];
2125
}
2226
}
23-
if (!isDir && scope[name + '.js']) {
24-
name += '.js';
25-
}
26-
if (typeof scope[name] === 'object') {
27-
tree.push(scope);
28-
scope = scope[name];
27+
if (name) {
28+
if (!isDir && scope[name + '.js']) {
29+
name += '.js';
30+
}
31+
if (typeof scope[name] === 'object') {
32+
tree.push(scope);
33+
scope = scope[name];
34+
name = 'index.js';
35+
}
36+
} else {
2937
name = 'index.js';
3038
}
3139
fn = scope[name];

test/__playground/lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'main.index';

test/__playground/lib/path/other.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
'use strict';
22

3-
exports.name = 'path/other';
3+
exports.name = 'path/other';
4+
exports.index = require('.');
5+
exports.indexSlash = require('./');
6+
exports.parentIndex = require('..');
7+
exports.parentIndexSlash = require('../');

test/webmake.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ module.exports = {
3636
a(program.pathDir.name, 'path', "Dir/file collision: dir");
3737
a(program.pathIndex.name, 'path', "Dir/file collision: dir/index");
3838
a(program.pathOther.name, 'path/other', "Dir/file collision: other");
39+
a(program.pathOther.index.name, 'path', "'.' - index require");
40+
a(program.pathOther.indexSlash.name, 'path',
41+
"'./' - index require (slash)");
42+
a(program.pathOther.parentIndex, 'main.index', "'..' - parent index");
43+
a(program.pathOther.parentIndexSlash,
44+
'main.index', "'../' - parent index (slash)");
3945
a(program.nlComment, 'nlComment', "New line / Comment");
4046
a(program.external.other.name, 'external-other',
4147
"Require module from other package");

0 commit comments

Comments
 (0)