Commit 8498f709 by Marcin Cieślak

Fix #2394: sourceMap option should have consistent behaviour

render() and renderSync() should return "map" property in the results
only if source map has been enabled.
parent 8d0accab
...@@ -310,9 +310,11 @@ Used to determine how many digits after the decimal will be allowed. For instanc ...@@ -310,9 +310,11 @@ Used to determine how many digits after the decimal will be allowed. For instanc
* Type: `Boolean | String | undefined` * Type: `Boolean | String | undefined`
* Default: `undefined` * Default: `undefined`
**Special:** Setting the `sourceMap` option requires also setting the `outFile` option Enables source map generation during `render` and `renderSync`.
Enables the outputting of a source map during `render` and `renderSync`. When `sourceMap === true`, the value of `outFile` is used as the target output location for the source map. When `typeof sourceMap === "string"`, the value of `sourceMap` will be used as the writing location for the file. When `sourceMap === true`, the value of `outFile` is used as the target output location for the source map with the suffix `.map` appended. If no `outFile` is set, `sourceMap` parameter is ignored.
When `typeof sourceMap === "string"`, the value of `sourceMap` will be used as the writing location for the file.
### sourceMapContents ### sourceMapContents
......
...@@ -300,9 +300,11 @@ module.exports.render = function(opts, cb) { ...@@ -300,9 +300,11 @@ module.exports.render = function(opts, cb) {
var stats = endStats(result.stats); var stats = endStats(result.stats);
var payload = { var payload = {
css: result.css, css: result.css,
map: result.map,
stats: stats stats: stats
}; };
if (result.map) {
payload.map = result.map;
}
if (cb) { if (cb) {
options.context.callback.call(options.context, null, payload); options.context.callback.call(options.context, null, payload);
......
...@@ -63,6 +63,26 @@ describe('api', function() { ...@@ -63,6 +63,26 @@ describe('api', function() {
}); });
}); });
it('should not generate source map when not requested', function(done) {
sass.render({
file: fixture('simple/index.scss'),
sourceMap: false
}, function(error, result) {
assert.strictEqual(result.hasOwnProperty('map'), false, 'result has a map property');
done();
});
});
it('should not generate source map without outFile and no explicit path given', function(done) {
sass.render({
file: fixture('simple/index.scss'),
sourceMap: true
}, function(error, result) {
assert.strictEqual(result.hasOwnProperty('map'), false, 'result has a map property');
done();
});
});
it('should compile generate map with sourceMapRoot pass-through option', function(done) { it('should compile generate map with sourceMapRoot pass-through option', function(done) {
sass.render({ sass.render({
file: fixture('simple/index.scss'), file: fixture('simple/index.scss'),
...@@ -1348,6 +1368,26 @@ describe('api', function() { ...@@ -1348,6 +1368,26 @@ describe('api', function() {
done(); done();
}); });
it('should not generate source map when not requested', function(done) {
var result = sass.renderSync({
file: fixture('simple/index.scss'),
sourceMap: false
});
assert.strictEqual(result.hasOwnProperty('map'), false, 'result has a map property');
done();
});
it('should not generate source map without outFile and no explicit path given', function(done) {
var result = sass.renderSync({
file: fixture('simple/index.scss'),
sourceMap: true
});
assert.strictEqual(result.hasOwnProperty('map'), false, 'result has a map property');
done();
});
it('should compile generate map with sourceMapRoot pass-through option', function(done) { it('should compile generate map with sourceMapRoot pass-through option', function(done) {
var result = sass.renderSync({ var result = sass.renderSync({
file: fixture('simple/index.scss'), file: fixture('simple/index.scss'),
......
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