Skip to content

Commit

Permalink
Fix how parent directory references are treated when finding other `.…
Browse files Browse the repository at this point in the history
…` indexes Resolves #48
  • Loading branch information
Alfredo-Delgado committed Jul 7, 2017
1 parent f89f4e9 commit f40fec2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions conditional.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ define(['module'], function(module) {
conditionalMatch[0].substr(2);

var conditionExport = "default";
var conditionExportIndex = conditionModule
.replace(/^(?:\.+\/)+./g, "") // removes './' or '../' in relative names
.indexOf(".");
var conditionExportParts = conditionModule
.match(/^(?:\.\/|\.\.\/)+/); // split './' or '../' in relative names

var conditionExportIndex = conditionModule.indexOf(".",
conditionExportParts && conditionExportParts[0].length); // only look for export

if (conditionExportIndex !== -1) {
conditionExport = conditionModule.substr(conditionExportIndex + 1);
Expand Down
2 changes: 2 additions & 0 deletions test/relative-conditions/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ QUnit.test("works", function(assert) {
assert.notOk(foo === "polyfill", "should not load polyfill");
});

require("~/some/deep/folder/test");

QUnit.start();
7 changes: 7 additions & 0 deletions test/relative-conditions/some/deep/folder/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var dotdotSlashX3 = require("~/some/deep/#{../../../some/deep/folder/which}");
var dotdotSlashX3AndExport = require("~/some/deep/#{../../../some/deep/folder/which.foo}");

QUnit.test("works with relative condition module reference", function(assert) {
assert.equal(dotdotSlashX3, "bar", "should load '~/some/deep/foo'");
assert.equal(dotdotSlashX3AndExport, "bar", "should load '~/some/deep/foo'");
});
1 change: 1 addition & 0 deletions test/relative-conditions/some/deep/folder/which.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = "foo";
module.exports.foo = module.exports;

0 comments on commit f40fec2

Please sign in to comment.