Skip to content

Commit

Permalink
fix: do not export duplicate keys (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
joscha authored and joshwiens committed Mar 8, 2017
1 parent e02e7a2 commit 7dfedc7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/compile-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
4 changes: 4 additions & 0 deletions test/camelCaseTest.js
Original file line number Diff line number Diff line change
@@ -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; }";
Expand All @@ -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");
});
16 changes: 16 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7dfedc7

Please sign in to comment.