Skip to content

Commit

Permalink
Merge pull request #281 from jtangelder/fix/wrong-ctx-custom-importer
Browse files Browse the repository at this point in the history
Fix wrong context in customImporters
  • Loading branch information
jhnns authored Sep 7, 2016
2 parents 9e87532 + d894345 commit 6be7eff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var SassError = {
};

// libsass uses this precedence when importing files without extension
var slice = Array.prototype.slice;
var extPrecedence = ['.scss', '.sass', '.css'];
var matchCss = /\.css$/;

Expand Down Expand Up @@ -409,7 +410,13 @@ function getLoaderConfig(loaderContext) {
function proxyCustomImporters(importer, resourcePath) {
return [].concat(importer).map(function (importer) {
return function (url, prev, done) {
return importer(url, prev === 'stdin' ? resourcePath : prev, done);
var args = slice.call(arguments);

if (args[1] === 'stdin') {
args[1] = resourcePath;
}

return importer.apply(this, args);
};
});
}
5 changes: 5 additions & 0 deletions test/tools/customImporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
var should = require('should');

function customImporter(path, prev) {
/*jshint validthis: true */

path.should.equal('import-with-custom-logic');
prev.should.match(/(sass|scss)[/\\]custom-importer\.(scss|sass)/);

this.should.have.property('options');

return customImporter.returnValue;
}
customImporter.returnValue = {
Expand Down

0 comments on commit 6be7eff

Please sign in to comment.