diff --git a/lib/compile-exports.js b/lib/compile-exports.js index 06904fac..318743ce 100644 --- a/lib/compile-exports.js +++ b/lib/compile-exports.js @@ -14,14 +14,23 @@ module.exports = function compileExports(result, importItemMatcher, camelCaseKey var exportJs = Object.keys(result.exports).reduce(function(res, key) { var valueAsString = JSON.stringify(result.exports[key]); valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher); - res.push("\t" + JSON.stringify(key) + ": " + valueAsString); + function addEntry(k) { + res.push("\t" + JSON.stringify(k) + ": " + valueAsString); + } + addEntry(key); + var targetKey; if (camelCaseKeys === true) { - res.push("\t" + JSON.stringify(camelCase(key)) + ": " + valueAsString); + targetKey = camelCase(key); + if (targetKey !== key) { + addEntry(targetKey); + } } else if (camelCaseKeys === 'dashes') { - res.push("\t" + JSON.stringify(dashesCamelCase(key)) + ": " + valueAsString); + targetKey = dashesCamelCase(key); + if (targetKey !== key) { + addEntry(targetKey); + } } - return res; }, []).join(",\n"); diff --git a/test/camelCaseTest.js b/test/camelCaseTest.js index 86803005..c8be53b3 100644 --- a/test/camelCaseTest.js +++ b/test/camelCaseTest.js @@ -1,6 +1,7 @@ /*globals describe */ var test = require("./helpers").test; +var testRaw = require("./helpers").testRaw; describe("camelCase", function() { var css = ".btn-info_is-disabled { color: blue; }"; @@ -21,4 +22,7 @@ describe("camelCase", function() { test("with", css, exports.with, "?modules"); test("without", css, exports.without, "?modules&camelCase"); test("dashes", css, exports.dashes, "?modules&camelCase=dashes"); + + testRaw("withoutRaw", '.a {}', 'exports.locals = {\n\t"a": "_1buUQJccBRS2-2i27LCoDf"\n};', "?modules&camelCase"); + testRaw("dashesRaw", '.a {}', 'exports.locals = {\n\t"a": "_1buUQJccBRS2-2i27LCoDf"\n};', "?modules&camelCase=dashes"); }); diff --git a/test/helpers.js b/test/helpers.js index f50941f2..ba7f72be 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -32,6 +32,10 @@ function assetEvaluated(output, result, modules) { exports.should.be.eql(result); } +function assertRaw(output, result) { + output.should.containEql(result); +} + function runLoader(loader, input, map, addOptions, callback) { var opt = { options: { @@ -69,6 +73,18 @@ exports.test = function test(name, input, result, query, modules) { }); }; +exports.testRaw = function testRaw(name, input, result, query, modules) { + it(name, function(done) { + runLoader(cssLoader, input, undefined, !query || typeof query === "string" ? { + query: query + } : query, function(err, output) { + if(err) return done(err); + assertRaw(output, result, modules); + done(); + }); + }); +} + exports.testError = function test(name, input, onError) { it(name, function(done) { runLoader(cssLoader, input, undefined, {}, function(err, output) { // eslint-disable-line no-unused-vars