From e8dff3ac5d8bfe8da1a2dc988232558b0c24585c Mon Sep 17 00:00:00 2001 From: tormozz48 Date: Fri, 4 Sep 2015 17:39:04 +0300 Subject: [PATCH] #9 Add ability to take sourceMap as simple object (without SouceMapGenerator wrapper) --- lib/utils.js | 6 +++--- tests/utils.test.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 15e1a00..48324d4 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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'; diff --git a/tests/utils.test.js b/tests/utils.test.js index 4db3260..b1d1acc 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -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() {