Skip to content

Commit

Permalink
Fix other issues related to partial path match
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Aug 21, 2013
1 parent 3bcae42 commit ad5d042
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,21 +317,17 @@ parser = {
if (path.length !== index) {
if (dirpath.length === index) {
if (path[index] !== sep) {
index = path.slice(0, index).lastIndexOf(sep);
index = path.slice(0, index).lastIndexOf(sep) + 1;
}
} else if (path[index - 1] !== sep) {
index = path.slice(0, index - 1).lastIndexOf(sep);
index = path.slice(0, index - 1).lastIndexOf(sep) + 1;
}
} else if (dirpath[index] !== sep) {
index = dirpath.slice(0, index).lastIndexOf(sep);
}

if (!path[index] || !dirpath[index]) {
index += 1;
} else if (dirpath[index - 1] !== sep) {
index = dirpath.slice(0, index).lastIndexOf(sep) + 1;
}

if (!path[index] || !dirpath[index]) index += 1;

dirpath = dirpath.slice(index);
path = path.slice(index);

Expand Down
1 change: 1 addition & 0 deletions test/__playground/lib/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports.pathFile = require('./path');
exports.pathDir = require('./path/');
exports.pathIndex = require('./path/index');
exports.commonPathPart = require('./sub-longer/bar');
exports.commonRootPathPart = require('../sub-longer/bar');
exports.pathOther = require('./path/other');
exports.nodeshim = require('path');
exports.json = require('./mario');
Expand Down
1 change: 1 addition & 0 deletions test/__playground/lib/sub-longer/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

exports.id = 'sub-longer-bar';
exports.sub = require('../sub/foo');
exports.subInner = require('../sub/inner/inner');
4 changes: 4 additions & 0 deletions test/__playground/lib/sub-longer/inner/other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

exports.id = 'sub-longer-inner-other';
exports.outer = require('../../sub/inner/other');
3 changes: 3 additions & 0 deletions test/__playground/lib/sub-longer/other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

exports.id = 'sub-longer-other';
1 change: 1 addition & 0 deletions test/__playground/lib/sub/foo.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';

exports.id = 'sub-foo';
exports.subOuter = require('../sub-longer/inner/other');
4 changes: 4 additions & 0 deletions test/__playground/lib/sub/inner/inner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

exports.id = 'sub-inner-inner';
exports.outer = require('../../sub-longer/other');
3 changes: 3 additions & 0 deletions test/__playground/lib/sub/inner/other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

exports.id = 'sub-inner-other';
5 changes: 5 additions & 0 deletions test/__playground/sub-longer/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

exports.id = 'sub-longer-bar';
exports.sub = require('../sub/foo');
exports.subInner = require('../sub/inner/inner');
4 changes: 4 additions & 0 deletions test/__playground/sub-longer/inner/other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

exports.id = 'sub-longer-inner-other';
exports.outer = require('../../sub/inner/other');
3 changes: 3 additions & 0 deletions test/__playground/sub-longer/other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

exports.id = 'sub-longer-other';
4 changes: 4 additions & 0 deletions test/__playground/sub/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

exports.id = 'sub-foo';
exports.subOuter = require('../sub-longer/inner/other');
4 changes: 4 additions & 0 deletions test/__playground/sub/inner/inner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

exports.id = 'sub-inner-inner';
exports.outer = require('../../sub-longer/other');
3 changes: 3 additions & 0 deletions test/__playground/sub/inner/other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

exports.id = 'sub-inner-other';
23 changes: 23 additions & 0 deletions test/webmake.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,31 @@ module.exports = {
a(program.pathFile.name, 'path.js', "Dir/file collision: file");
a(program.pathDir.name, 'path', "Dir/file collision: dir");
a(program.pathIndex.name, 'path', "Dir/file collision: dir/index");

a(program.commonPathPart.id, 'sub-longer-bar', "Common path part: main");
a(program.commonPathPart.sub.id, 'sub-foo', "Common path part: outer");
a(program.commonPathPart.subInner.id, 'sub-inner-inner',
"Common path part: outer #2");
a(program.commonPathPart.subInner.outer.id, 'sub-longer-other',
"Common path part: outer #3");
a(program.commonPathPart.sub.subOuter.id, 'sub-longer-inner-other',
"Common path part: outer #5");
a(program.commonPathPart.sub.subOuter.outer.id, 'sub-inner-other',
"Common path part: outer #4");

a(program.commonRootPathPart.id, 'sub-longer-bar',
"Common path part: main");
a(program.commonRootPathPart.sub.id, 'sub-foo',
"Common path part: outer");
a(program.commonRootPathPart.subInner.id, 'sub-inner-inner',
"Common root path part: outer #2");
a(program.commonRootPathPart.subInner.outer.id, 'sub-longer-other',
"Common root path part: outer #3");
a(program.commonRootPathPart.sub.subOuter.id, 'sub-longer-inner-other',
"Common root path part: outer #5");
a(program.commonRootPathPart.sub.subOuter.outer.id, 'sub-inner-other',
"Common root path part: outer #4");

a(program.pathOther.name, 'path/other', "Dir/file collision: other");
a(program.pathOther.index.name, 'path', "'.' - index require");
a(program.pathOther.indexSlash.name, 'path',
Expand Down

0 comments on commit ad5d042

Please sign in to comment.