Commit 162091e7 by Michael Mifsud

Merge pull request #1318 from xzyfer/fix/importer-async-null

Handle sass.NULL returned from the importer via done()
parents 31d54cb9 99dc18c4
...@@ -301,27 +301,27 @@ module.exports.render = function(options, cb) { ...@@ -301,27 +301,27 @@ module.exports.render = function(options, cb) {
if (Array.isArray(importer)) { if (Array.isArray(importer)) {
importer.forEach(function(subject, index) { importer.forEach(function(subject, index) {
options.importer[index] = function(file, prev, bridge) { options.importer[index] = function(file, prev, bridge) {
function done(data) { function done(result) {
bridge.success(data); bridge.success(result === module.exports.NULL ? null : result);
} }
var result = subject.call(options.context, file, prev, done); var result = subject.call(options.context, file, prev, done);
if (result) { if (result !== undefined) {
done(result === module.exports.NULL ? null : result); done(result);
} }
}; };
}); });
} else { } else {
options.importer = function(file, prev, bridge) { options.importer = function(file, prev, bridge) {
function done(data) { function done(result) {
bridge.success(data); bridge.success(result === module.exports.NULL ? null : result);
} }
var result = importer.call(options.context, file, prev, done); var result = importer.call(options.context, file, prev, done);
if (result) { if (result !== undefined) {
done(result === module.exports.NULL ? null : result); done(result);
} }
}; };
} }
......
...@@ -325,6 +325,17 @@ describe('api', function() { ...@@ -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) { it('should fallback to default import behaviour if importer returns null for backwards compatibility', function(done) {
sass.render({ sass.render({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment