Skip to content

Commit a2b85d7

Browse files
joschajoshwiens
authored andcommitted
fix: do not export duplicate keys (#420)
1 parent d4ac0e0 commit a2b85d7

File tree

5 files changed

+39
-22
lines changed

5 files changed

+39
-22
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

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "css-loader",
3-
"version": "0.26.2",
3+
"version": "0.26.3",
44
"author": "Tobias Koppers @sokra",
55
"description": "css loader module for webpack",
66
"engines": {

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

yarn.lock

+5-17
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,7 @@ browser-stdout@1.3.0:
165165
version "1.3.0"
166166
resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f"
167167

168-
browserslist@^1.0.1, browserslist@^1.5.2:
169-
version "1.6.0"
170-
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-1.6.0.tgz#85fb7c993540d3fda31c282baf7f5aee698ac9ee"
171-
dependencies:
172-
caniuse-db "^1.0.30000613"
173-
electron-to-chromium "^1.2.0"
174-
175-
browserslist@~1.5.1:
168+
browserslist@^1.0.1, browserslist@^1.5.2, browserslist@~1.5.1:
176169
version "1.5.2"
177170
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-1.5.2.tgz#1c82fde0ee8693e6d15c49b7bff209dc06298c56"
178171
dependencies:
@@ -206,7 +199,7 @@ caniuse-api@^1.5.2:
206199
lodash.uniq "^4.3.0"
207200
shelljs "^0.7.0"
208201

209-
caniuse-db@^1.0.30000346, caniuse-db@^1.0.30000604, caniuse-db@^1.0.30000613:
202+
caniuse-db@^1.0.30000346, caniuse-db@^1.0.30000604:
210203
version "1.0.30000613"
211204
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000613.tgz#639133b7a5380c1416f9701d23d54d093dd68299"
212205

@@ -493,10 +486,6 @@ ecc-jsbn@~0.1.1:
493486
dependencies:
494487
jsbn "~0.1.0"
495488

496-
electron-to-chromium@^1.2.0:
497-
version "1.2.0"
498-
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.2.0.tgz#3bd7761f85bd4163602259ae6c7ed338050b17e7"
499-
500489
emojis-list@^2.0.0:
501490
version "2.1.0"
502491
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"
@@ -1107,14 +1096,13 @@ levn@^0.3.0, levn@~0.3.0:
11071096
prelude-ls "~1.1.2"
11081097
type-check "~0.3.2"
11091098

1110-
loader-utils@~0.2.2:
1111-
version "0.2.16"
1112-
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.16.tgz#f08632066ed8282835dff88dfb52704765adee6d"
1099+
loader-utils@^1.0.2:
1100+
version "1.0.3"
1101+
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.0.3.tgz#566c320c24c33cb3f02db4df83f3dbf60b253de3"
11131102
dependencies:
11141103
big.js "^3.1.3"
11151104
emojis-list "^2.0.0"
11161105
json5 "^0.5.0"
1117-
object-assign "^4.0.1"
11181106

11191107
lodash._baseassign@^3.0.0:
11201108
version "3.2.0"

0 commit comments

Comments
 (0)