diff --git a/lib/loader.js b/lib/loader.js index 58fa5223..ca856cd3 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -21,7 +21,7 @@ module.exports = function(content, map) { if(sourceMap) { if (map) { - if (typeof map !== "string") { + if (typeof map === "string") { map = JSON.stringify(map); } diff --git a/lib/processCss.js b/lib/processCss.js index 585d37d0..5468fc79 100644 --- a/lib/processCss.js +++ b/lib/processCss.js @@ -48,7 +48,7 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) { url = url.url; } else if(url.type === "string") { url = url.value; - } else throw rule.error("Unexpected format" + rule.params); + } else throw rule.error("Unexpected format " + rule.params); if (!url.replace(/\s/g, '').length) { return; } diff --git a/test/sourceMapTest.js b/test/sourceMapTest.js index c1c407d0..faf7578c 100644 --- a/test/sourceMapTest.js +++ b/test/sourceMapTest.js @@ -10,7 +10,7 @@ describe("source maps", function() { testWithMap("falsy: undefined map doesn't cause an error", ".class { a: b c d; }", undefined, [ [1, ".class { a: b c d; }", ""] ]); - testWithMap("should don't generate sourceMap when `sourceMap: false` and map exist", + testWithMap("should don't generate sourceMap when `sourceMap: false` and map exists", ".class { a: b c d; }", { file: 'test.css', @@ -28,7 +28,7 @@ describe("source maps", function() { sourceMap: false } ); - testWithMap("should don't generate sourceMap when `sourceMap: true` and map exist", + testWithMap("should don't generate sourceMap when `sourceMap: true` and map exists", ".class { a: b c d; }", { file: 'test.css', @@ -54,6 +54,32 @@ describe("source maps", function() { sourceMap: true } ); + testWithMap("should don't generate sourceMap when `sourceMap: true` and map exists and string", + ".class { a: b c d; }", + JSON.stringify({ + file: 'test.css', + mappings: 'AAAA,SAAS,SAAS,EAAE', + names: [], + sourceRoot: '', + sources: [ '/folder/test.css' ], + sourcesContent: [ '.class { a: b c d; }' ], + version: 3 + }), + [ + [1, ".class { a: b c d; }", "", { + file: 'test.css', + mappings: 'AAAA,SAAS,SAAS,EAAE', + names: [], + sourceRoot: '', + sources: [ '/folder/test.css' ], + sourcesContent: [ '.class { a: b c d; }' ], + version: 3 + }] + ], + { + sourceMap: true + } + ); testMap("generate sourceMap (1 loader)", ".class { a: b c d; }", undefined, { loaders: [{request: "/path/css-loader"}], resource: "/folder/test.css",