Skip to content

Embed source file content in source map #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2014
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
10 changes: 8 additions & 2 deletions lib/source-map-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ exports.updatePosition = function(str) {
*/

exports.emit = function(str, pos, startOnly) {
var sourceFile = pos && pos.source || 'source.css';

if (pos && pos.start) {
this.map.addMapping({
source: pos.source || 'source.css',
source: sourceFile,
generated: {
line: this.position.line,
column: Math.max(this.position.column - 1, 0)
Expand All @@ -62,13 +64,15 @@ exports.emit = function(str, pos, startOnly) {
column: pos.start.column - 1
}
});

this.map.setSourceContent(sourceFile, pos.content || '');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn’t it better to:

if (pos.content) {
  this.map.setSourceContent(sourceFile, pos.content);
}

There’s nothing wrong with setting source content just for a few sources. The rest could be fetched by a browser’s developer tools, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 87d6994

}

this.updatePosition(str);

if (!startOnly && pos && pos.end) {
this.map.addMapping({
source: pos.source || 'source.css',
source: sourceFile,
generated: {
line: this.position.line,
column: Math.max(this.position.column - 1, 0)
Expand All @@ -78,6 +82,8 @@ exports.emit = function(str, pos, startOnly) {
column: pos.end.column - 1
}
});

this.map.setSourceContent(sourceFile, pos.content || '');
}

return str;
Expand Down
2 changes: 2 additions & 0 deletions test/css-stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('stringify(obj, {sourcemap: true})', function(){
map.originalPositionFor({ line: 11, column: 0 }).should.eql(locs.mediaBlock);
map.originalPositionFor({ line: 12, column: 2 }).should.eql(locs.mediaOnly);
map.originalPositionFor({ line: 17, column: 0 }).should.eql(locs.comment);
map.sourceContentFor('rules.css').should.eql(src);
});

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