Skip to content

Commit 7dfedc7

Browse files
joschajoshwiens
authored andcommitted
fix: do not export duplicate keys (#420)
1 parent e02e7a2 commit 7dfedc7

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

lib/compile-exports.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,23 @@ module.exports = function compileExports(result, importItemMatcher, camelCaseKey
1414
var exportJs = Object.keys(result.exports).reduce(function(res, key) {
1515
var valueAsString = JSON.stringify(result.exports[key]);
1616
valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher);
17-
res.push("\t" + JSON.stringify(key) + ": " + valueAsString);
17+
function addEntry(k) {
18+
res.push("\t" + JSON.stringify(k) + ": " + valueAsString);
19+
}
20+
addEntry(key);
1821

22+
var targetKey;
1923
if (camelCaseKeys === true) {
20-
res.push("\t" + JSON.stringify(camelCase(key)) + ": " + valueAsString);
24+
targetKey = camelCase(key);
25+
if (targetKey !== key) {
26+
addEntry(targetKey);
27+
}
2128
} else if (camelCaseKeys === 'dashes') {
22-
res.push("\t" + JSON.stringify(dashesCamelCase(key)) + ": " + valueAsString);
29+
targetKey = dashesCamelCase(key);
30+
if (targetKey !== key) {
31+
addEntry(targetKey);
32+
}
2333
}
24-
2534
return res;
2635
}, []).join(",\n");
2736

test/camelCaseTest.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*globals describe */
22

33
var test = require("./helpers").test;
4+
var testRaw = require("./helpers").testRaw;
45

56
describe("camelCase", function() {
67
var css = ".btn-info_is-disabled { color: blue; }";
@@ -21,4 +22,7 @@ describe("camelCase", function() {
2122
test("with", css, exports.with, "?modules");
2223
test("without", css, exports.without, "?modules&camelCase");
2324
test("dashes", css, exports.dashes, "?modules&camelCase=dashes");
25+
26+
testRaw("withoutRaw", '.a {}', 'exports.locals = {\n\t"a": "_1buUQJccBRS2-2i27LCoDf"\n};', "?modules&camelCase");
27+
testRaw("dashesRaw", '.a {}', 'exports.locals = {\n\t"a": "_1buUQJccBRS2-2i27LCoDf"\n};', "?modules&camelCase=dashes");
2428
});

test/helpers.js

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ function assetEvaluated(output, result, modules) {
3232
exports.should.be.eql(result);
3333
}
3434

35+
function assertRaw(output, result) {
36+
output.should.containEql(result);
37+
}
38+
3539
function runLoader(loader, input, map, addOptions, callback) {
3640
var opt = {
3741
options: {
@@ -69,6 +73,18 @@ exports.test = function test(name, input, result, query, modules) {
6973
});
7074
};
7175

76+
exports.testRaw = function testRaw(name, input, result, query, modules) {
77+
it(name, function(done) {
78+
runLoader(cssLoader, input, undefined, !query || typeof query === "string" ? {
79+
query: query
80+
} : query, function(err, output) {
81+
if(err) return done(err);
82+
assertRaw(output, result, modules);
83+
done();
84+
});
85+
});
86+
}
87+
7288
exports.testError = function test(name, input, onError) {
7389
it(name, function(done) {
7490
runLoader(cssLoader, input, undefined, {}, function(err, output) { // eslint-disable-line no-unused-vars

0 commit comments

Comments
 (0)