Skip to content

Commit

Permalink
scopes in usage data should not affect classes
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Mar 20, 2016
1 parent aca7ff4 commit 76a821f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/compressor/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function buildMap(list) {
}

function buildIndex(data) {
var classes = buildMap(data.classes);
var scopes = false;

if (data.scopes && Array.isArray(data.scopes)) {
Expand All @@ -36,17 +35,14 @@ function buildIndex(data) {
}

scopes[name] = i + 1;
if (classes) {
classes[name] = true;
}
}
}
}

return {
tags: buildMap(data.tags),
ids: buildMap(data.ids),
classes: classes,
classes: buildMap(data.classes),
scopes: scopes
};
}
Expand Down
23 changes: 23 additions & 0 deletions test/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ describe('compress with usage', function() {
assert.equal(compressed, '*{p:1}');
});

describe('shouldn\'t affect classes whitelist', function() {
it('when "classes" is defined', function() {
var compressed = csso.minify('.a, .b { p: 1 }', {
usage: {
classes: ['a'],
scopes: [['a'], ['b']]
}
});

assert.equal(compressed, '.a{p:1}');
});

it('when "classes" isn\'t defined', function() {
var compressed = csso.minify('.a, .b { p: 1 }', {
usage: {
scopes: [['a'], ['b']]
}
});

assert.equal(compressed, '.a,.b{p:1}');
});
});

it('should throw exception when selector has classes from different scopes', function() {
assert.throws(function() {
csso.minify('.a.b { p: 1 }', {
Expand Down

0 comments on commit 76a821f

Please sign in to comment.