Skip to content

Commit f73fd3a

Browse files
committed
Embed source file content in source map
Depends on latest css-stringify git master
1 parent a7fe6de commit f73fd3a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/source-map-support.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ exports.updatePosition = function(str) {
5050
*/
5151

5252
exports.emit = function(str, pos, startOnly) {
53+
var sourceFile = pos && pos.source || 'source.css';
54+
5355
if (pos && pos.start) {
5456
this.map.addMapping({
55-
source: pos.source || 'source.css',
57+
source: sourceFile,
5658
generated: {
5759
line: this.position.line,
5860
column: Math.max(this.position.column - 1, 0)
@@ -62,13 +64,15 @@ exports.emit = function(str, pos, startOnly) {
6264
column: pos.start.column - 1
6365
}
6466
});
67+
68+
this.map.setSourceContent(sourceFile, pos.content || '');
6569
}
6670

6771
this.updatePosition(str);
6872

6973
if (!startOnly && pos && pos.end) {
7074
this.map.addMapping({
71-
source: pos.source || 'source.css',
75+
source: sourceFile,
7276
generated: {
7377
line: this.position.line,
7478
column: Math.max(this.position.column - 1, 0)
@@ -78,6 +82,8 @@ exports.emit = function(str, pos, startOnly) {
7882
column: pos.end.column - 1
7983
}
8084
});
85+
86+
this.map.setSourceContent(sourceFile, pos.content || '');
8187
}
8288

8389
return str;

test/css-stringify.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe('stringify(obj, {sourcemap: true})', function(){
5454
map.originalPositionFor({ line: 11, column: 0 }).should.eql(locs.mediaBlock);
5555
map.originalPositionFor({ line: 12, column: 2 }).should.eql(locs.mediaOnly);
5656
map.originalPositionFor({ line: 17, column: 0 }).should.eql(locs.comment);
57+
map.sourceContentFor('rules.css').should.eql(src);
5758
});
5859

5960
it('should generate source maps alongside when using compress compiler', function(){
@@ -66,5 +67,6 @@ describe('stringify(obj, {sourcemap: true})', function(){
6667
map.originalPositionFor({ line: 1, column: 10 }).should.eql(locs.tobiNameValue);
6768
map.originalPositionFor({ line: 1, column: 50 }).should.eql(locs.mediaBlock);
6869
map.originalPositionFor({ line: 1, column: 64 }).should.eql(locs.mediaOnly);
70+
map.sourceContentFor('rules.css').should.eql(src);
6971
});
7072
});

0 commit comments

Comments
 (0)