Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect handling of non-mutated class names #448

Merged
merged 1 commit into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions lib/compile-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,32 @@ module.exports = function compileExports(result, importItemMatcher, camelCaseKey
function addEntry(k) {
res.push("\t" + JSON.stringify(k) + ": " + valueAsString);
}
if (camelCaseKeys !== 'only' && camelCaseKeys !== 'dashesOnly') {
addEntry(key);
}

var targetKey;
if (camelCaseKeys === true || camelCaseKeys === 'only') {
targetKey = camelCase(key);
if (targetKey !== key) {
addEntry(targetKey);
}
} else if (camelCaseKeys === 'dashes' || camelCaseKeys === 'dashesOnly') {
targetKey = dashesCamelCase(key);
if (targetKey !== key) {
addEntry(targetKey);
}
switch(camelCaseKeys) {
case true:
addEntry(key);
targetKey = camelCase(key);
if (targetKey !== key) {
addEntry(targetKey);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line was the culprit, as it would prevent the camelcased key to be added to the locals only if it was different from the default key. However with the only and dashesOnly options the default key would not have been added -> empty locals.

}
break;
case 'dashes':
addEntry(key);
targetKey = dashesCamelCase(key);
if (targetKey !== key) {
addEntry(targetKey);
}
break;
case 'only':
addEntry(camelCase(key));
break;
case 'dashesOnly':
addEntry(dashesCamelCase(key));
break;
default:
addEntry(key);
break;
}
return res;
}, []).join(",\n");
Expand Down
13 changes: 7 additions & 6 deletions test/camelCaseTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var testRaw = require("./helpers").testRaw;

describe("camelCase", function() {
var css = ".btn-info_is-disabled { color: blue; }";
var mixedCss = ".btn-info_is-disabled { color: blue; } .simple { color: red; }";
var exports = {
with: [
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
Expand All @@ -16,24 +17,24 @@ describe("camelCase", function() {
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
],
withoutOnly: [
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; } .KKtodWG-IuEaequFjAsoJ { color: red; }", ""]
],
dashesOnly: [
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; } .KKtodWG-IuEaequFjAsoJ { color: red; }", ""]
]
};
exports.with.locals = {'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
exports.without.locals = {btnInfoIsDisabled: '_1L-rnCOXCE_7H94L5XT4uB', 'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
exports.dashes.locals = {btnInfo_isDisabled: '_1L-rnCOXCE_7H94L5XT4uB', 'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
exports.withoutOnly.locals = {btnInfoIsDisabled: '_1L-rnCOXCE_7H94L5XT4uB'};
exports.dashesOnly.locals = {btnInfo_isDisabled: '_1L-rnCOXCE_7H94L5XT4uB'};
exports.withoutOnly.locals = {btnInfoIsDisabled: '_1L-rnCOXCE_7H94L5XT4uB', simple: 'KKtodWG-IuEaequFjAsoJ'};
exports.dashesOnly.locals = {btnInfo_isDisabled: '_1L-rnCOXCE_7H94L5XT4uB', simple: 'KKtodWG-IuEaequFjAsoJ'};
test("with", css, exports.with, "?modules");
test("without", css, exports.without, "?modules&camelCase");
test("dashes", css, exports.dashes, "?modules&camelCase=dashes");
// Remove this option in v1.0.0 and make the removal of the original classname the default behaviour. See #440.
test("withoutOnly", css, exports.withoutOnly, "?modules&camelCase=only");
test("withoutOnly", mixedCss, exports.withoutOnly, "?modules&camelCase=only");
// Remove this option in v1.0.0 and make the removal of the original classname the default behaviour. See #440.
test("dashesOnly", css, exports.dashesOnly, "?modules&camelCase=dashesOnly");
test("dashesOnly", mixedCss, exports.dashesOnly, "?modules&camelCase=dashesOnly");

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");
Expand Down