Skip to content

Commit

Permalink
Remove "best guess" logic from options
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyganch committed Jun 9, 2014
1 parent 8e75dd5 commit 5dbf402
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
7 changes: 5 additions & 2 deletions lib/csscomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,11 @@ Comb.prototype = (function() {

var nodeType = node.shift();
var detected = handler.detect(nodeType, node, level);
if (detected !== undefined) {
detectedOptions[handler.name].push(detected);
var variants = detectedOptions[handler.name];
if (typeof detected === 'object') {
variants.push.apply(variants, detected);
} else if (typeof detected !== 'undefined') {
variants.push(detected);
}
node.unshift(nodeType);

Expand Down
38 changes: 10 additions & 28 deletions lib/options/element-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,18 @@ module.exports = {
* @param {node} node
*/
detect: function(nodeType, node) {
if (nodeType === 'simpleselector') {
var variants = {};
var bestGuess = null;
var maximum = 0;
for (var i = node.length; i--;) {
var nodeItem = node[i];
if (nodeItem[0] === 'ident') {
var result;
if (nodeItem[1].match(/^[a-z]+$/)) {
result = 'lower';
} else if (nodeItem[1].match(/^[A-Z]+$/)) {
result = 'upper';
}
if (nodeType !== 'simpleselector') return;

if (result) {
if (variants[result]) {
variants[result]++;
} else {
variants[result] = 1;
}
if (variants[result] > maximum) {
maximum = variants[result];
bestGuess = result;
}
}
}
}
if (bestGuess) {
return bestGuess;
var variants = [];
for (var i = node.length; i--;) {
var nodeItem = node[i];
if (nodeItem[0] !== 'ident') continue;
if (nodeItem[1].match(/^[a-z]+$/)) {
variants.push('lower');
} else if (nodeItem[1].match(/^[A-Z]+$/)) {
variants.push('upper');
}
}
return variants;
}
};

0 comments on commit 5dbf402

Please sign in to comment.