Skip to content

Commit

Permalink
fix: support deduplication of string module ids (optimization.namedMo…
Browse files Browse the repository at this point in the history
…dules) (#789)
  • Loading branch information
princed authored and evilebottnawi committed Nov 23, 2018
1 parent 10c3bc3 commit e3bb83a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/css-base.js
Expand Up @@ -25,7 +25,7 @@ module.exports = function(useSourceMap) {
var alreadyImportedModules = {};
for(var i = 0; i < this.length; i++) {
var id = this[i][0];
if(typeof id === "number")
if(id != null)
alreadyImportedModules[id] = true;
}
for(i = 0; i < modules.length; i++) {
Expand All @@ -34,7 +34,7 @@ module.exports = function(useSourceMap) {
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)
if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
if(item[0] == null || !alreadyImportedModules[item[0]]) {
if(mediaQuery && !item[2]) {
item[2] = mediaQuery;
} else if(mediaQuery) {
Expand Down
15 changes: 15 additions & 0 deletions test/cssBaseTest.js
Expand Up @@ -52,6 +52,21 @@ describe("css-base", function() {
"@media print{body { d: 4; }}" +
"@media screen{body { a: 1; }}");
});
it("should import named modules", function() {
var m = base();
var m1 = ["./module1", "body { a: 1; }", "screen"];
var m2 = ["./module2", "body { b: 2; }", ""];
var m3 = ["./module3", "body { c: 3; }", ""];
var m4 = ["./module4", "body { d: 4; }", ""];
m.i([m2, m3], "");
m.i([m2], "");
m.i([m2, m4], "print");
m.push(m1);
m.toString().should.be.eql("body { b: 2; }" +
"body { c: 3; }" +
"@media print{body { d: 4; }}" +
"@media screen{body { a: 1; }}");
});
it("should toString with source mapping", function() {
var m = base(true);
m.push([1, "body { a: 1; }", "", {
Expand Down

0 comments on commit e3bb83a

Please sign in to comment.