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

Commit fbc9ff5

Browse files
authored
Merge pull request #2754 from saper/no-map-if-not-requested
Fix #2394: sourceMap option should have consistent behaviour
2 parents 60fad5f + 8498f70 commit fbc9ff5

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,11 @@ Used to determine how many digits after the decimal will be allowed. For instanc
311311
* Type: `Boolean | String | undefined`
312312
* Default: `undefined`
313313

314-
**Special:** Setting the `sourceMap` option requires also setting the `outFile` option
314+
Enables source map generation during `render` and `renderSync`.
315315

316-
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.
316+
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.
317+
318+
When `typeof sourceMap === "string"`, the value of `sourceMap` will be used as the writing location for the file.
317319

318320
### sourceMapContents
319321

lib/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,11 @@ module.exports.render = function(opts, cb) {
300300
var stats = endStats(result.stats);
301301
var payload = {
302302
css: result.css,
303-
map: result.map,
304303
stats: stats
305304
};
305+
if (result.map) {
306+
payload.map = result.map;
307+
}
306308

307309
if (cb) {
308310
options.context.callback.call(options.context, null, payload);

test/api.js

+40
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ describe('api', function() {
6363
});
6464
});
6565

66+
it('should not generate source map when not requested', function(done) {
67+
sass.render({
68+
file: fixture('simple/index.scss'),
69+
sourceMap: false
70+
}, function(error, result) {
71+
assert.strictEqual(result.hasOwnProperty('map'), false, 'result has a map property');
72+
done();
73+
});
74+
});
75+
76+
it('should not generate source map without outFile and no explicit path given', function(done) {
77+
sass.render({
78+
file: fixture('simple/index.scss'),
79+
sourceMap: true
80+
}, function(error, result) {
81+
assert.strictEqual(result.hasOwnProperty('map'), false, 'result has a map property');
82+
done();
83+
});
84+
});
85+
6686
it('should compile generate map with sourceMapRoot pass-through option', function(done) {
6787
sass.render({
6888
file: fixture('simple/index.scss'),
@@ -1348,6 +1368,26 @@ describe('api', function() {
13481368
done();
13491369
});
13501370

1371+
it('should not generate source map when not requested', function(done) {
1372+
var result = sass.renderSync({
1373+
file: fixture('simple/index.scss'),
1374+
sourceMap: false
1375+
});
1376+
1377+
assert.strictEqual(result.hasOwnProperty('map'), false, 'result has a map property');
1378+
done();
1379+
});
1380+
1381+
it('should not generate source map without outFile and no explicit path given', function(done) {
1382+
var result = sass.renderSync({
1383+
file: fixture('simple/index.scss'),
1384+
sourceMap: true
1385+
});
1386+
1387+
assert.strictEqual(result.hasOwnProperty('map'), false, 'result has a map property');
1388+
done();
1389+
});
1390+
13511391
it('should compile generate map with sourceMapRoot pass-through option', function(done) {
13521392
var result = sass.renderSync({
13531393
file: fixture('simple/index.scss'),

0 commit comments

Comments
 (0)