Skip to content

Commit

Permalink
#9 Add ability to take sourceMap as simple object (without SouceMapGe…
Browse files Browse the repository at this point in the history
…nerator wrapper)
  • Loading branch information
tormozz48 committed Sep 8, 2015
1 parent 96bf82d commit e8dff3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ module.exports = {
* @return {String}
*/
joinContentAndSourceMap: function (content, sourceMap, opts) {
if (!(sourceMap instanceof SourceMapGenerator)) {
throw new Error('sourceMap should be an instance of SourceMapGenerator');
}
sourceMap = sourceMap instanceof SourceMapGenerator
? sourceMap.toString()
: JSON.stringify(sourceMap);

opts = opts || {};
opts.comment = opts.comment || 'inline';
Expand Down
8 changes: 4 additions & 4 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ describe('Utils', function() {
result.should.be.equal(['line1', 'line2', SOURCE_MAP_LINE].join(os.EOL));
});

it('should throw if not a SourceMapGenerator passed', function() {
(function() {
return utils.joinContentAndSourceMap('some-content', SOURCE_MAP_CONSUMER);
}).should.throw();
it('should be able to take sourceMap without SouceMapGenerator wrapper', function () {
var sourceMap = JSON.parse(SOURCE_MAP_GENERATOR.toString());
var result = utils.joinContentAndSourceMap(['line1', 'line2'].join(os.EOL), sourceMap);
result.should.be.equal(['line1', 'line2', SOURCE_MAP_LINE].join(os.EOL));
});

it('should throw if source map not passed', function() {
Expand Down

0 comments on commit e8dff3a

Please sign in to comment.