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

Fix #2394: sourceMap option should have consistent behaviour #2754

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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