Skip to content

Commit 0eedd9f

Browse files
joschabebraw
authored andcommitted
fix: incorrect handling of non-mutated class names (webpack-contrib#448)
1 parent 9504ea5 commit 0eedd9f

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

lib/compile-exports.js

+24-13
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,32 @@ module.exports = function compileExports(result, importItemMatcher, camelCaseKey
1717
function addEntry(k) {
1818
res.push("\t" + JSON.stringify(k) + ": " + valueAsString);
1919
}
20-
if (camelCaseKeys !== 'only' && camelCaseKeys !== 'dashesOnly') {
21-
addEntry(key);
22-
}
2320

2421
var targetKey;
25-
if (camelCaseKeys === true || camelCaseKeys === 'only') {
26-
targetKey = camelCase(key);
27-
if (targetKey !== key) {
28-
addEntry(targetKey);
29-
}
30-
} else if (camelCaseKeys === 'dashes' || camelCaseKeys === 'dashesOnly') {
31-
targetKey = dashesCamelCase(key);
32-
if (targetKey !== key) {
33-
addEntry(targetKey);
34-
}
22+
switch(camelCaseKeys) {
23+
case true:
24+
addEntry(key);
25+
targetKey = camelCase(key);
26+
if (targetKey !== key) {
27+
addEntry(targetKey);
28+
}
29+
break;
30+
case 'dashes':
31+
addEntry(key);
32+
targetKey = dashesCamelCase(key);
33+
if (targetKey !== key) {
34+
addEntry(targetKey);
35+
}
36+
break;
37+
case 'only':
38+
addEntry(camelCase(key));
39+
break;
40+
case 'dashesOnly':
41+
addEntry(dashesCamelCase(key));
42+
break;
43+
default:
44+
addEntry(key);
45+
break;
3546
}
3647
return res;
3748
}, []).join(",\n");

test/camelCaseTest.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var testRaw = require("./helpers").testRaw;
55

66
describe("camelCase", function() {
77
var css = ".btn-info_is-disabled { color: blue; }";
8+
var mixedCss = ".btn-info_is-disabled { color: blue; } .simple { color: red; }";
89
var exports = {
910
with: [
1011
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
@@ -16,24 +17,24 @@ describe("camelCase", function() {
1617
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
1718
],
1819
withoutOnly: [
19-
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
20+
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; } .KKtodWG-IuEaequFjAsoJ { color: red; }", ""]
2021
],
2122
dashesOnly: [
22-
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
23+
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; } .KKtodWG-IuEaequFjAsoJ { color: red; }", ""]
2324
]
2425
};
2526
exports.with.locals = {'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
2627
exports.without.locals = {btnInfoIsDisabled: '_1L-rnCOXCE_7H94L5XT4uB', 'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
2728
exports.dashes.locals = {btnInfo_isDisabled: '_1L-rnCOXCE_7H94L5XT4uB', 'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
28-
exports.withoutOnly.locals = {btnInfoIsDisabled: '_1L-rnCOXCE_7H94L5XT4uB'};
29-
exports.dashesOnly.locals = {btnInfo_isDisabled: '_1L-rnCOXCE_7H94L5XT4uB'};
29+
exports.withoutOnly.locals = {btnInfoIsDisabled: '_1L-rnCOXCE_7H94L5XT4uB', simple: 'KKtodWG-IuEaequFjAsoJ'};
30+
exports.dashesOnly.locals = {btnInfo_isDisabled: '_1L-rnCOXCE_7H94L5XT4uB', simple: 'KKtodWG-IuEaequFjAsoJ'};
3031
test("with", css, exports.with, "?modules");
3132
test("without", css, exports.without, "?modules&camelCase");
3233
test("dashes", css, exports.dashes, "?modules&camelCase=dashes");
3334
// Remove this option in v1.0.0 and make the removal of the original classname the default behaviour. See #440.
34-
test("withoutOnly", css, exports.withoutOnly, "?modules&camelCase=only");
35+
test("withoutOnly", mixedCss, exports.withoutOnly, "?modules&camelCase=only");
3536
// Remove this option in v1.0.0 and make the removal of the original classname the default behaviour. See #440.
36-
test("dashesOnly", css, exports.dashesOnly, "?modules&camelCase=dashesOnly");
37+
test("dashesOnly", mixedCss, exports.dashesOnly, "?modules&camelCase=dashesOnly");
3738

3839
testRaw("withoutRaw", '.a {}', 'exports.locals = {\n\t"a": "_1buUQJccBRS2-2i27LCoDf"\n};', "?modules&camelCase");
3940
testRaw("dashesRaw", '.a {}', 'exports.locals = {\n\t"a": "_1buUQJccBRS2-2i27LCoDf"\n};', "?modules&camelCase=dashes");

0 commit comments

Comments
 (0)