Skip to content

Commit

Permalink
Merge pull request #1318 from xzyfer/fix/importer-async-null
Browse files Browse the repository at this point in the history
Handle sass.NULL returned from the importer via done()
  • Loading branch information
xzyfer committed Dec 27, 2015
2 parents 31d54cb + 99dc18c commit 162091e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
16 changes: 8 additions & 8 deletions lib/index.js
Expand Up @@ -301,27 +301,27 @@ module.exports.render = function(options, cb) {
if (Array.isArray(importer)) {
importer.forEach(function(subject, index) {
options.importer[index] = function(file, prev, bridge) {
function done(data) {
bridge.success(data);
function done(result) {
bridge.success(result === module.exports.NULL ? null : result);
}

var result = subject.call(options.context, file, prev, done);

if (result) {
done(result === module.exports.NULL ? null : result);
if (result !== undefined) {
done(result);
}
};
});
} else {
options.importer = function(file, prev, bridge) {
function done(data) {
bridge.success(data);
function done(result) {
bridge.success(result === module.exports.NULL ? null : result);
}

var result = importer.call(options.context, file, prev, done);

if (result) {
done(result === module.exports.NULL ? null : result);
if (result !== undefined) {
done(result);
}
};
}
Expand Down
13 changes: 12 additions & 1 deletion test/api.js
Expand Up @@ -325,6 +325,17 @@ describe('api', function() {
});
});

it('should fallback to default import behaviour if importer returns sass.NULL', function(done) {
sass.render({
file: fixture('include-files/index.scss'),
importer: function(url, prev, done) {
done(sass.NULL);
}
}, function(error, result) {
assert.equal(result.css.toString().trim(), '/* foo.scss */\n/* bar.scss */');
done();
});
});

it('should fallback to default import behaviour if importer returns null for backwards compatibility', function(done) {
sass.render({
Expand Down Expand Up @@ -1010,7 +1021,7 @@ describe('api', function() {
return sass.types.String('foo');
},
bar: function(a) {
assert.strictEqual(a, sass.NULL,
assert.strictEqual(a, sass.NULL,
'Supplied value should be the same instance as sass.NULL');

assert.throws(function() {
Expand Down

0 comments on commit 162091e

Please sign in to comment.