Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Fix #2394: sourceMap option should have consistent behaviour
Browse files Browse the repository at this point in the history
render() and renderSync() should return "map" property in the results
only if source map has been enabled.
  • Loading branch information
saper committed Oct 17, 2019
1 parent 8d0acca commit bc6e11a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,11 @@ Used to determine how many digits after the decimal will be allowed. For instanc
* Type: `Boolean | String | 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
Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,11 @@ module.exports.render = function(opts, cb) {
var stats = endStats(result.stats);
var payload = {
css: result.css,
map: result.map,
stats: stats
};
if (result.map) {
payload.map = result.map;
};

if (cb) {
options.context.callback.call(options.context, null, payload);
Expand Down
40 changes: 40 additions & 0 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
sass.render({
file: fixture('simple/index.scss'),
Expand Down Expand Up @@ -1348,6 +1368,26 @@ describe('api', function() {
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) {
var result = sass.renderSync({
file: fixture('simple/index.scss'),
Expand Down

0 comments on commit bc6e11a

Please sign in to comment.