From 73d9876b0c327d745205a9554129b187d39c9a06 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Fri, 12 May 2017 18:18:19 +0300 Subject: [PATCH] fix: source maps path on `windows`. --- lib/loader.js | 2 +- test/sourceMapTest.js | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index 58fa52237..ca856cd3d 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/test/sourceMapTest.js b/test/sourceMapTest.js index c1c407d04..faf7578c0 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",