diff --git a/lib/loader.js b/lib/loader.js index e3b28600..cbaaa4bc 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -14,7 +14,7 @@ module.exports = function(content, map) { var root = query.root; var moduleMode = query.modules || query.module; - if(typeof map !== "string") { + if(map !== null && typeof map !== "string") { map = JSON.stringify(map); } diff --git a/test/helpers.js b/test/helpers.js index 1dd7bfee..b080bb43 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -52,6 +52,26 @@ exports.test = function test(name, input, result, query, modules) { }); }; +exports.testWithMap = function test(name, input, map, result, query, modules) { + it(name, function() { + var output = cssLoader.call({ + options: { + context: "" + }, + loaders: [{request: "loader"}], + loaderIndex: 0, + context: "", + resource: "test.css", + request: "css-loader!test.css", + query: query, + emitError: function(message) { + throw new Error(message); + } + }, input, map); + assetEvaluated(output, result, modules); + }); +}; + exports.testLocals = function testLocals(name, input, result, query, modules) { it(name, function() { var output = cssLoaderLocals.call({ diff --git a/test/sourceMapTest.js b/test/sourceMapTest.js new file mode 100644 index 00000000..c955abf8 --- /dev/null +++ b/test/sourceMapTest.js @@ -0,0 +1,12 @@ +/*globals describe */ + +var testWithMap = require("./helpers").testWithMap; + +describe("falsy source maps", function() { + testWithMap("null map doesn't cause an error", ".class { a: b c d; }", null, [ + [1, ".class { a: b c d; }", ""] + ]); + testWithMap("undefined map doesn't cause an error", ".class { a: b c d; }", undefined, [ + [1, ".class { a: b c d; }", ""] + ]); +});