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 9, 2017
1 parent d4ac0e0 commit a2b85d7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "css-loader",
"version": "0.26.2",
"version": "0.26.3",
"author": "Tobias Koppers @sokra",
"description": "css loader module for webpack",
"engines": {
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
22 changes: 5 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,7 @@ [email protected]:
version "1.3.0"
resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f"

browserslist@^1.0.1, browserslist@^1.5.2:
version "1.6.0"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-1.6.0.tgz#85fb7c993540d3fda31c282baf7f5aee698ac9ee"
dependencies:
caniuse-db "^1.0.30000613"
electron-to-chromium "^1.2.0"

browserslist@~1.5.1:
browserslist@^1.0.1, browserslist@^1.5.2, browserslist@~1.5.1:
version "1.5.2"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-1.5.2.tgz#1c82fde0ee8693e6d15c49b7bff209dc06298c56"
dependencies:
Expand Down Expand Up @@ -206,7 +199,7 @@ caniuse-api@^1.5.2:
lodash.uniq "^4.3.0"
shelljs "^0.7.0"

caniuse-db@^1.0.30000346, caniuse-db@^1.0.30000604, caniuse-db@^1.0.30000613:
caniuse-db@^1.0.30000346, caniuse-db@^1.0.30000604:
version "1.0.30000613"
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000613.tgz#639133b7a5380c1416f9701d23d54d093dd68299"

Expand Down Expand Up @@ -493,10 +486,6 @@ ecc-jsbn@~0.1.1:
dependencies:
jsbn "~0.1.0"

electron-to-chromium@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.2.0.tgz#3bd7761f85bd4163602259ae6c7ed338050b17e7"

emojis-list@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"
Expand Down Expand Up @@ -1107,14 +1096,13 @@ levn@^0.3.0, levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"

loader-utils@~0.2.2:
version "0.2.16"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.16.tgz#f08632066ed8282835dff88dfb52704765adee6d"
loader-utils@^1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.0.3.tgz#566c320c24c33cb3f02db4df83f3dbf60b253de3"
dependencies:
big.js "^3.1.3"
emojis-list "^2.0.0"
json5 "^0.5.0"
object-assign "^4.0.1"

lodash._baseassign@^3.0.0:
version "3.2.0"
Expand Down

0 comments on commit a2b85d7

Please sign in to comment.